www.pudn.com > tcpipstack.rar > TINYTC3.SHA
13 casyncms.h
/* CASYNCMS.H - entry points in casycms
|===================================================================|
| My changes can be considered public domain. Geof's statement |
| will cover everything. |
| - Rick Rodman 09/02/97 |
|===================================================================|
930811 rr orig file
941009 rr change types from char to int
*/
int Far inp_status P(( void ));
void Far inp_flush P(( void ));
void Far init_comm P(( void ));
void Far uninit_comm P(( void ));
int Far inp_char P(( void ));
void Far outp_char P(( int c ));
/* end of casyncms.h */
19 fileio.h
/* FILEIO.H - definitions for simple file I/O
940513 rr initial file
*/
#define MY_OPEN_READ 0
#define MY_OPEN_WRITE 1
/* watch the syntax on this one */
#define FH Void *
FH my_open P(( char *p_filename, int open_mode ));
Void my_close P(( FH fh ));
unsigned short my_read
P(( FH fh, unsigned char *p_buffer, unsigned short u_bytes ));
unsigned short my_write
P(( FH fh, unsigned char *p_buffer, unsigned short u_bytes ));
/* end of fileio.h */
94 options.h
/* OPTIONS.H - Compiling options
940807 rr orig file
940925 rr add Far
Eco-C: 6 character limit; does not have 'unsigned long' or 'unsigned short'.
No typedef.
Function predeclarations cause the compiler to crash, even if they
are ifdef'd out.
Function calls thru pointers apparently don't work ("illegal
function call").
BDS C (1.42): Conditional compilation doesn't appear to work; at least, it
doesn't disable #include directives.
*/
/* ----- Machine type ----------------------------------------------- */
/* This is used in a few places, e.g. for selecting real-time
clock logic */
/* #define PC */
#define XEROX820
/* #define KAYPRO */
/* #define ECO */ /* Eco-C Z-80 compiler */
#define Z80
/* ----- configuration ---------------------------------------------- */
/* define ETHERNET if using Ethernet */
/* #define ETHERNET */
/* define BIG_ENDIAN if using Motorola CPU */
/* #define BIG_ENDIAN */
/* this end's internet address */
#ifdef PC
#define MY_ADDR ADDR( 192, 9, 201, 2 )
#endif
#ifdef XEROX820
#define MY_ADDR ADDR( 192, 9, 201, 3 )
#endif
#ifdef KAYPRO
#define MY_ADDR ADDR( 192, 9, 201, 4 )
#endif
#define HOST_ADDR ADDR( 192, 9, 201, 2 )
/* ----- S8 --------------------------------------------------------- */
#ifdef Z80
#define S8 static
#else
#define S8
#endif
/* ----- Prototype -------------------------------------------------- */
/* uncomment following for compilers allowing prototypes */
#define P(x) x
/* uncomment following for compilers not allowing prototypes */
/* #define P(x) () */
/* ----- Void ------------------------------------------------------- */
/* uncomment following for compilers supporting void datatype */
#define Void void
/* uncomment following for compilers not supporting void datatype */
/* #define Void */
/* ----- Far -------------------------------------------------------- */
#ifdef PC
#define Far far
#else
#define Far
#endif
/* ----- Use typedefs? ---------------------------------------------- */
#define USE_TYPEDEFS
/* end of options.h */
110 proto.h
/* PROTO.H - function prototypes for tiny-tcp
931208 rr orig file
940424 rr minor changes
Notes:
Eco-C doesn't like Void, and having functions predeclared with no type
makes the compiler lock up.
Personally, I'd rather have all the functions return success/failure
anyway. (941010 rr)
*/
/* in arp.c */
int sar_CheckPacket P(( struct arp_Header *ap ));
int sar_MapIn2Eth P(( Longword ina, struct Ethernet_Address *ethap ));
/* in sed.c or sedslip.c */
int sed_Init P(( Void ));
int sed_Deinit P(( Void ));
Byte * sed_FormatPacket P(( Byte *destEAddr, int ethType ));
int sed_Send P(( int pkLengthInOctets ));
int sed_Receive P(( Byte *recBufLocation ));
Byte * sed_IsPacket P(( Void ));
int sed_CheckPacket P(( Word *recBufLocation, Word expectedType ));
/* in tinytcp.c */
Void tcp_Init P(( Void ));
#ifdef USE_TYPEDEFS
Void tcp_Open P(( struct tcp_Socket *s, Word lport, IP_Address ina,
Word port, Procref datahandler ));
#else
Void tcp_Open P(( struct tcp_Socket *s, Word lport, IP_Address ina,
Word port, int ( *datahandler )( void *s, Byte *dp, int len ) ));
#endif
#ifdef USE_TYPEDEFS
Void tcp_Listen P(( struct tcp_Socket *s, Word port, Procref datahandler,
Longword timeout ));
#else
Void tcp_Listen P(( struct tcp_Socket *s, Word port,
int ( *datahandler )( void *s, Byte *dp, int len ),
Longword timeout ));
#endif
Void tcp_Close P(( struct tcp_Socket *s ));
Void tcp_Abort P(( struct tcp_Socket *s ));
#ifdef USE_TYPEDEFS
int tcp P(( Procrefv application ));
#else
int tcp P(( void ( *application )( void ) ));
#endif
int tcp_Write P(( struct tcp_Socket *s, Byte *dp, int len ));
#ifndef ECO
Void tcp_Flush P(( struct tcp_Socket *s ));
#endif
#ifndef BIG_ENDIAN
Word rev_word P(( Word w ));
Longword rev_longword P(( Longword l ));
#endif
/* redefine move as memcpy */
#define Move(s,d,n) memcpy(d,s,n)
/* the following are internal to TCP, but because it was broken
into chunks, they had to become global */
Void tcp_Unthread P(( struct tcp_Socket *ds ));
Void tcp_Retransmitter P(( Void ));
Void tcp_ProcessData P(( struct tcp_Socket *s,
struct tcp_Header *tp, int len ));
Void tcp_Send P(( struct tcp_Socket *s ));
Void tcp_DumpHeader P(( struct in_Header *ip,
struct tcp_Header *tp, char *mesg ));
Void tcp_Handler P(( struct in_Header *ip ));
Word checksum P(( Word *dp, int length ));
Longword lchecksum P(( Word *dp, int length ));
/* in tinyftp.c */
Void ftp_ctlHandler P(( struct tcp_Socket *s, Byte *dp, int len ));
Void ftp_dataHandler P(( struct tcp_Socket *s, Byte *dp, int len ));
Void ftp_commandLine P(( Void ));
Void ftp_Abort P(( Void ));
Void ftp_application P(( Void ));
Void ftp P(( IP_Address host ));
/* in tinyft2.c */
Void ftp_server_handler P(( struct tcp_Socket *s, Byte *dp, int len ));
/* in tinyft4.c */
Void ftp_local_command P(( char *s ));
/* in main.c */
Void main P(( int argc, char **argv ));
Longword MsecClock P(( Void ));
/* end of proto.h */
74 sed.h
/*
* Header file for very simple ethernet driver, based on 3Com Multibus
* board.
*
* Copyright (C) 1986, IMAGEN Corporation
* "This code may be duplicated in whole or in part provided that [1] there
* is no commercial gain involved in the duplication, and [2] that this
* copyright notice is preserved on all copies. Any other duplication
* requires written notice of the author."
*/
#define en10size (8*1024) /* size of interface memory */
#define en10pages ((en10size) >> pageshift)
#define E10P_MIN 60 /* Minimum Ethernet packet size */
/*
* The position of the 3Com interface in virtual memory. If we're
* Running the bootloader function, then it must be in the last 8k
* of virtual addresses.
*/
#ifdef BOOTLOADER
#define SED3CVA vm_3ComAdr /* hack, only need pb68.h if bootloader */
#endif
#ifndef SED3CVA
#define SED3CVA 0x1c000
#endif
/* 10Mb Ethernet interface addresses */
#define MECSR(eth_va) *(word*)(((octet *) eth_va) + 0x0)
#define MEBACK(eth_va) *(word*)(((octet *) eth_va) + 0x2)
#define MEAROM(eth_va) (word*)(((octet *) eth_va) + 0x400)
#define MEARAM(eth_va) (word*)(((octet *) eth_va) + 0x600)
#define MEXHDR(eth_va) *(word*)(((octet *) eth_va) + 0x800)
#define MEXBUF(eth_va) (word*)(((octet *) eth_va) + 0x1000)
#define MEAHDR(eth_va) (word*)(((octet *) eth_va) + 0x1000)
#define MEBHDR(eth_va) (word*)(((octet *) eth_va) + 0x1800)
/* control/status register fields */
#define BBSW 0x8000 /* Buffer B belongs to Network */
#define ABSW 0x4000 /* Buffer A belongs to Network */
#define TBSW 0x2000 /* Transmit buffer belongs to Network */
#define JAM 0x1000 /* Set when transmit collision */
#define AMSW 0x0800
#define RBBA 0x0400 /* Oldest received packet is in B */
/*#define UNUSED 0x0200 */
#define RESET 0x0100 /* Reset the controller */
#define BINT 0x0080 /* Interrupt when BBSW=>0 (packet in B) */
#define AINT 0x0040 /* Interrupt when ABSW=>0 (packet in A) */
#define TINT 0x0020 /* Interrupt when TBSW=>0 (transmit done) */
#define JINT 0x0010 /* Enable interrupts when JAM=>1 */
#define PA 0x000F /* Which packets should be received? */
#define INTENABLS 0x00F0
/*
* Receiver Header Fields:
* The receiver header is the first (short) word of the receive buffer. It
* includes such information as how big the packet is, whether it was a
* broadcast, whether there was an error in receiving it, etc.
*/
#define R_FCS 0x8000 /* fcs error */
#define R_BCAST 0x4000 /* packet was NOT a broadcast */
#define R_RANGE 0x2000 /* range error (size of pkt?) */
#define R_MATCH 0x1000 /* packet is multicast (i.e., address
received is not that of the interface) */
#define R_FRAME 0x0800 /* framing error */
#define R_ERROR 0x8800 /* was there any error */
#define R_OFFSET 0x07FF /* packet length + 1 word */
/* extern octet *sed_FormatPacket(), *sed_WaitPacket(); */
/* end of sed.h */
216 tinytcp.h
/* tinytcp.h - header file for tinytcp.c
Copyright (C) 1986, IMAGEN Corporation
"This code may be duplicated in whole or in part provided that [1] there
is no commercial gain involved in the duplication, and [2] that this
copyright notice is preserved on all copies. Any other duplication
requires written notice of the author."
Note: the structures herein must guarantee that the
code only performs Word fetches, since the
imagenether card doesn't accept byte accesses.
940807 rr minor mods
940925 rr remove all typedefs. NOT TESTED SINCE.
*/
#define True 1
#define False 0
/* ----- address macro ---------------------------------------------- */
#define ADDR(a,b,c,d) (((long)a<<24L)|((long)b<<16L)|((long)c<<8L)|((long)d))
/* ----- options ---------------------------------------------------- */
#include "options.h"
/* ----- overrides -------------------------------------------------- */
#ifdef BIG_ENDIAN
#define rev_word( w ) (w)
#define rev_longword( lw ) (lw)
#endif
/* ----- Canonically-sized data ------------------------------------- */
#ifdef ECO
/* Eco-C has no unsigned long at all, and does not allow unsigned
short either. */
#define Longword long /* 32 bits */
#define Word unsigned int /* 16 bits */
#define Byte unsigned char /* 8 bits */
#else
#define Longword unsigned long /* 32 bits */
#define Word unsigned short /* 16 bits */
#define Byte unsigned char /* 8 bits */
#endif /* eco */
/* The true type of 's' should be 'tcp_Socket *'. But Microsoft C
won't let us do that, because 'Procref' is a type used in
the definition of that structure. */
#ifdef USE_TYPEDEFS
typedef void ( *Procref ) P(( void *s, Byte *dp, int len ));
typedef void ( *Procrefv ) P(( void ));
#endif
/* protocol address definitions */
#define IP_Address Longword
struct Ethernet_Address {
Word w[ 3 ];
};
/* The Ethernet header */
struct eth_Header {
struct Ethernet_Address destination; /* 48 bits = 6 bytes */
struct Ethernet_Address source; /* 48 bits = 6 bytes */
Word type; /* 16 bits = 2 bytes */
}; /* total 14 bytes */
/* The Internet Header: */
struct in_Header {
Word vht; /* version, hdrlen, tos */
/* 2 bytes */
/* version = first nybble = 4. */
/* hdrlen = low nybble of 1st byte =
length of header in dwords = 5 */
Word length; /* 2 bytes */
Word identification; /* 2 bytes */
Word frag; /* 2 bytes */
Word ttlProtocol; /* 2 bytes */
/* first byte is TTL = 'time to lose' */
/* second byte is protocol */
Word checksum; /* 2 bytes */
IP_Address source; /* IP address - 4 bytes */
IP_Address destination; /* IP address - 4 bytes */
}; /* total 20 bytes */
/* macros which parse parts of the ip message */
#define IP_VERSION(ip) (( rev_word((ip)->vht) >> 12) & 0xf)
#define IP_HLEN(ip) (( rev_word((ip)->vht) >> 8) & 0xf)
#define IP_HBYTES(ip) (( rev_word((ip)->vht) >> 6) & 0x3c)
/* #define IP_TOS(ip) ( rev_word((ip)->vht) & 0xff) */
/* #define IP_TTL(ip) ( rev_word((ip)->ttlProtocol) >> 8) */
#define IP_PROTOCOL(ip) ( rev_word((ip)->ttlProtocol) & 0xff)
struct tcp_Header {
Word srcPort;
Word dstPort;
Longword seqnum;
Longword acknum;
Word flags;
Word window;
Word checksum;
Word urgentPointer;
};
#define TCPF_FIN 0x0001
#define TCPF_SYN 0x0002
#define TCPF_RST 0x0004
#define TCPF_PUSH 0x0008
#define TCPF_ACK 0x0010
#define TCPF_URG 0x0020
#define TCPF_DO 0xF000
#define TCP_DATAOFFSET(tp) ( rev_word((tp)->flags) >> 12)
/* UDP header is only 8 bytes */
/* The TCP/UDP Pseudo Header. Used for computing checksum. */
struct tcp_Pseudoheader {
IP_Address src; /* 4 bytes */
IP_Address dst; /* 4 bytes */
Byte mbz; /* must be zero. 1 byte */
Byte protocol; /* 6 = tcp. 1 byte */
Word length; /* 2 bytes */
Word checksum; /* 2 bytes */
}; /* 14 bytes */
/* TCP states, from tcp manual.
Note: close-wait state is bypassed by automatically closing a connection
when a FIN is received. This is easy to undo.
rr 940529 There should not be a state 0 in here. When a socket is unlinked
the state should be set to zero, indicating an invalid socket.
*/
#define TS_LISTEN 1 /* listening for connection */
#define TS_SSYN 2 /* syn sent, active open */
#define TS_RSYN 3 /* syn received, synack+syn sent. */
#define TS_ESTAB 4 /* established */
#define TS_SFIN 5 /* sent FIN */
#define TS_AFIN 6 /* sent FIN, received FINACK */
/* #define TS_CLOSEWT 7 */ /* received FIN waiting for close */
#define TS_RFIN 8 /* (closing) sent FIN, received FIN */
/* (waiting for FINACK) */
#define TS_LASTACK 9 /* fin received, finack+fin sent */
#define TS_TIMEWT 10 /* dally after sending final FINACK */
#define TS_CLOSED 11 /* (closed) finack received */
/* ------ TCP Socket definition ------------------------------------- */
#define TCP_MAXDATA 512 /* maximum bytes to buffer on output */
struct tcp_Socket {
struct tcp_Socket * next; /* pointer to next socket */
short state; /* connection state */
#ifdef USE_TYPEDEFS
Procref dataHandler; /* called with incoming data */
#else
int ( *dataHandler ) P(( void *s, Byte *dp, int len ));
#endif
struct Ethernet_Address hisethaddr; /* ethernet address of peer */
IP_Address hisaddr; /* internet address of peer */
Word myport, hisport; /* tcp ports for this connection */
Longword acknum, seqnum; /* data ack'd and sequence num */
Longword timeout; /* timeout, in milliseconds */
short unhappy; /* flag, retransmitting segt's */
Word flags; /* flags Word for last packet sent */
short dataSize; /* number of bytes of data to send */
Byte data[ TCP_MAXDATA ]; /* data to send */
};
/* ----- ARP definitions -------------------------------------------- */
#define arp_TypeEther 1 /* ARP type of Ethernet address */
/* harp op codes */
#define ARP_REQUEST 1
#define ARP_REPLY 2
struct arp_Header {
Word hwType;
Word protType;
Word hwProtAddrLen; /* hw and prot addr len */
Word opcode;
struct Ethernet_Address srcEthAddr;
IP_Address srcIPAddr;
struct Ethernet_Address dstEthAddr;
IP_Address dstIPAddr;
};
/* ----- Timer definitions ------------------------------------------ */
#ifdef ETHERNET /* ETHERNET VALUES */
#define tcp_RETRANSMITTIME 1000 /* interval at which retransmitter is called */
/* 1 SECOND */
#define tcp_LONGTIMEOUT 31000 /* timeout for opens */
#define tcp_TIMEOUT 10000 /* timeout during a connection */
#else /* GUESSING SLIP VALUES */
#define tcp_RETRANSMITTIME 10000 /* interval at which retransmitter is called */
/* 10 SECONDS */
#define tcp_LONGTIMEOUT 31000 /* timeout for opens */
#define tcp_TIMEOUT 20000 /* timeout during a connection */
#endif
#include "proto.h"
/* end of tinytcp.h */
-1 :BB: