⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tinyip.h

📁 ADAM2 sources (modified by Oleg)
💻 H
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------*/
/*                                                                             */
/*   Copyright (C) 2002-2003 by Texas Instruments, Inc.  All rights reserved.  */
/*   Copyright (C) 2002-2003 Telogy Networks.	    						   */
/*                                                                             */
/*   NOTE: THIS VERSION OF CODE IS MAINTAINED BY TELOGY NETWORKS AND NOT TI!   */
/*                                                                             */
/*-----------------------------------------------------------------------------*/

#ifndef _TINYIP_H_
#define _TINYIP_H_

#include "_stdio.h"
#include "mms.h"

extern void t_clear(void);
extern int t_get(void);

/* **************************** MACRO Definitions *************************** */

#define ETH_MSS 1400  /* MSS for Ethernet */

#define tcp_MaxData 	2048   	/* maximum bytes to buffer on output */
#define ftp_MaxData 	1024   	/* maximum bytes to buffer on output */

#define udp_MaxBufSize 	2048	/* maximum UINT8s to buffer on input */
#define icmp_MaxBufSize 2048	/* maximum UINT8s to buffer on input */


#define in_GetHdrlen(ip)  ((wfix((ip)->vht) >> 8) & 0xf)
#define in_GetHdrlenBytes(ip)  ((wfix((ip)->vht) >> 6) & 0x3c)

#define in_GetTTL(ip)      (wfix((ip)->ttlProtocol) >> 8)
#define in_GetProtocol(ip) (wfix((ip)->ttlProtocol) & 0xff)

#define clock_ValueRough() (t_get()/ticdiv)

#define MoveW(s,d,l)  (sys_memcpy(d,s,l))

#ifdef EB
#define wfix(a)    (a)
#define lfix(a)    (a)
#else
#define wfix(a)    ((((a)>>8)&0x0ff)|(((a)<<8)&0x0ff00))
#define lfix(a)    ((((a)>>24)&0x0ff)|(((a)>>8)&0x0ff00)|(((a)<<8)&0x0ff0000)|(((a)<<24)&0xff000000))
#endif

/* ARP definitions */
#define arp_TypeEther  1        /* ARP type of Ethernet address */

/* harp op codes */
#define ARP_REQUEST 1
#define ARP_REPLY   2

#define INADDR_ANY			((unsigned long)0x00000000)
#define INADDR_BROADCAST	((unsigned long)0xFFFFFFFF)
#define INADDR_NONE			((unsigned long)0x00000000)

/* These are Ethernet protocol numbers. */
#define UDP_PROTO  0x11
#define TCP_PROTO  0x06
#define ICMP_PROTO 0x01

#define tcp_MaxBufSize 2048		/* maximum UINT8s to buffer on input */

/* TCP Flags */
#define tcp_FlagFIN     0x0001
#define tcp_FlagSYN     0x0002
#define tcp_FlagRST     0x0004
#define tcp_FlagPUSH    0x0008
#define tcp_FlagACK     0x0010
#define tcp_FlagURG     0x0020
#define tcp_FlagDO      0xF000
#define tcp_GetDataOffset(tp) (wfix((tp)->flags) >> 12)

/* TCP states
 * Note: close-wait state is bypassed by automatically closing a connection
 *       when a FIN is received.  This is easy to undo.*/
#define tcp_StateLISTEN  0      /* listening for connection */
#define tcp_StateSYNSENT 1      /* syn sent, active open */
#define tcp_StateSYNREC  2      /* syn received, synack+syn sent. */
#define tcp_StateESTAB   3      /* established */
#define tcp_StateFINWT1  4      /* sent FIN */
#define tcp_StateFINWT2  5      /* sent FIN, received FINACK */
#define tcp_StateCLOSING 6      /* sent FIN, received FIN (waiting for FINACK) */
#define tcp_StateLASTACK 7      /* fin received, finack+fin sent */
#define tcp_StateTIMEWT  8      /* dally after sending final FINACK */
#define tcp_StateCLOSED  9      /* finack received */

#define SOPEN  1
#define SDATA  2
#define SCLOSE 3
#define SABORT 4

#define UDP_LENGTH ( sizeof( udp_Header ))

/* DHCP */
/* DHCP protocol -- see RFC 2131 */
#define SERVER_PORT     67
#define CLIENT_PORT     68

#define DHCP_MAGIC      0x63825363

/* DHCP option codes (partial list) */
#define DHCP_PADDING        0x00
#define DHCP_SUBNET     	0x01
#define DHCP_TIME_OFFSET    0x02
#define DHCP_ROUTER     	0x03
#define DHCP_TIME_SERVER    0x04
#define DHCP_NAME_SERVER    0x05
#define DHCP_DNS_SERVER     0x06
#define DHCP_LOG_SERVER     0x07
#define DHCP_COOKIE_SERVER  0x08
#define DHCP_LPR_SERVER     0x09
#define DHCP_HOST_NAME      0x0c
#define DHCP_BOOT_SIZE      0x0d
#define DHCP_DOMAIN_NAME    0x0f
#define DHCP_SWAP_SERVER    0x10
#define DHCP_ROOT_PATH      0x11
#define DHCP_IP_TTL     	0x17
#define DHCP_MTU        	0x1a
#define DHCP_BROADCAST      0x1c
#define DHCP_NTP_SERVER     0x2a
#define DHCP_NTP_SERVER     0x2a
#define DHCP_WINS_SERVER    0x2c
#define DHCP_REQUESTED_IP   0x32
#define DHCP_LEASE_TIME     0x33
#define DHCP_OPTION_OVER    0x34
#define DHCP_MESSAGE_TYPE   0x35
#define DHCP_SERVER_ID      0x36
#define DHCP_PARAM_REQ      0x37
#define DHCP_MESSAGE        0x38
#define DHCP_MAX_SIZE       0x39
#define DHCP_T1         	0x3a
#define DHCP_T2         	0x3b
#define DHCP_VENDOR     	0x3c
#define DHCP_CLIENT_ID      0x3d

#define DHCP_END        0xFF


#define BOOTREQUEST     1
#define BOOTREPLY       2

#define ETH_10MB        1
#define ETH_10MB_LEN   	6

#define DHCPDISCOVER    1
#define DHCPOFFER       2
#define DHCPREQUEST     3
#define DHCPDECLINE     4
#define DHCPACK         5
#define DHCPNAK         6
#define DHCPRELEASE     7
#define DHCPINFORM      8

#define BROADCAST_FLAG  0x8000

#define OPTION_FIELD    0
#define FILE_FIELD      1
#define SNAME_FIELD     2

/* miscellaneous defines */
#define MAC_BCAST_ADDR      (unsigned char *) "\xff\xff\xff\xff\xff\xff"
#define OPT_CODE 0
#define OPT_LEN 1
#define OPT_DATA 2

#define TYPE_MASK   0x0F

#define OPTION_REQ  0x10 /* have the client request this option */
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */

/* ***************************** Data Variables **************************** */

/* Useful type definitions */
typedef void (*procref)();

/* protocol address definitions */
extern bit32u emacbase;

typedef longword in_HwAddress;
typedef word eth_HwAddress[3];

extern eth_HwAddress sed_lclEthAddr;
extern eth_HwAddress sed_ethBcastAddr;
extern in_HwAddress  sin_lclINAddr;
extern in_HwAddress  net_Gateway;
extern in_HwAddress  net_IpMask;

extern unsigned int av_cpufreq;
extern unsigned int ticdiv;

extern bit32u rtim;

extern int ip_initialized;

extern int rebootFlag;
extern int ftpServerStatus;

#define INDICATE_WRITE 		(64*1024)

/* ***************************** Data Structures **************************** */

/* The Ethernet header */
typedef struct {
    eth_HwAddress   destination __attribute__ ((packed));
    eth_HwAddress   source __attribute__ ((packed));
    word          	type;
} eth_Header;

/* Arp header */
typedef struct {
    word          	hwType;
    word          	protType;
    word          	hwProtAddrLen;  /* hw and prot addr len */
    word          	opcode;
    eth_HwAddress   srcEthAddr __attribute__ ((packed));
    in_HwAddress    srcIPAddr __attribute__ ((packed));
    eth_HwAddress   dstEthAddr __attribute__ ((packed));
    in_HwAddress    dstIPAddr __attribute__ ((packed));
} arp_Header;

/* The IP Header */
typedef struct {
    word          	vht;    /* version, hdrlen, tos */
    word   			length;
    word          	identification;
    word          	frag;
    word          	ttlProtocol; /* ttl, protocol - UDP / TCP */
    word          	checksum;
    in_HwAddress    source __attribute__ ((packed));
    in_HwAddress    destination __attribute__ ((packed));
} in_Header;

/* TCP Header */
typedef struct {
    word     	srcPort;
    word      	dstPort;
    longword    seqnum;
    longword    acknum;
    word      	flags;
    word      	window;
    word      	checksum;
    word      	urgentPointer;
} tcp_Header;

/* UDP Header */
typedef struct {
    word  		srcPort;
    word      	dstPort;
    word      	length;
    word      	checksum;
} udp_Header;


/* The TCP/UDP Pseudo Header */
typedef struct {
    in_HwAddress    src __attribute__ ((packed));
    in_HwAddress    dst __attribute__ ((packed));
    octet           mbz;
    octet           protocol;
    word          	length;
    word          	checksum;
} tcp_PseudoHeader;

/* TCP Socket definition */
typedef struct _tcp_socket {
    struct _tcp_socket *next;
    word          	ip_type;        /* always set to TCP_PROTO */
    short           state;          /* connection state */
    procref         dataHandler;    /* called with incoming data */
    eth_HwAddress   hisethaddr;     /* ethernet address of peer */
    in_HwAddress    hisaddr;        /* internet address of peer */
    word          	myport, hisport;/* tcp ports for this connection */
    longword       	acknum, seqnum; /* data ack'd and sequence num */
    int             timeout;        /* timeout, in milliseconds */
    BOOL            unhappy;        /* flag, indicates retransmitting segt's */
    word          	flags;          /* tcp flags word for last packet sent */
    short           dataSize;       /* number of bytes of data to send */
    byte            data[tcp_MaxData]; /* data to send */
} tcp_Socket;

/* UDP socket definition */
typedef struct _udp_socket 
{
    struct _udp_socket 	*next;
    word          	ip_type;            /* always set to UDP_PROTO */
    procref         dataHandler;
	procref         appHandler;
    eth_HwAddress   hisethaddr;         /* peer's ethernet address */
    in_HwAddress   	hisaddr;            /* peer's internet address */
    word          	myport, hisport;    /* peer's UDP port */
    word          	locflags;

    int             rdatalen;           /* must be signed */
    word          	maxrdatalen;
    byte           	*rdata;
    byte           	rddata[udp_MaxBufSize + 1];	/* if dataHandler = 0, len == 512 */    
} udp_Socket;

#ifdef FTP_SERVER_SUPPORT
typedef struct _FTPCommand
{
	int tokenId;
	char *commandName;
	byte argFlag;
	//char *commandDescr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -