These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
EMAC/Easy_Web/tcpip.h@0:bf7b9fba3924, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 05:38:56 2011 +0000
- Revision:
- 0:bf7b9fba3924
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:bf7b9fba3924 | 1 | /****************************************************************** |
frank26080115 | 0:bf7b9fba3924 | 2 | ***** ***** |
frank26080115 | 0:bf7b9fba3924 | 3 | ***** Name: tcpip.h ***** |
frank26080115 | 0:bf7b9fba3924 | 4 | ***** Ver.: 1.0 ***** |
frank26080115 | 0:bf7b9fba3924 | 5 | ***** Date: 07/05/2001 ***** |
frank26080115 | 0:bf7b9fba3924 | 6 | ***** Auth: Andreas Dannenberg ***** |
frank26080115 | 0:bf7b9fba3924 | 7 | ***** HTWK Leipzig ***** |
frank26080115 | 0:bf7b9fba3924 | 8 | ***** university of applied sciences ***** |
frank26080115 | 0:bf7b9fba3924 | 9 | ***** Germany ***** |
frank26080115 | 0:bf7b9fba3924 | 10 | ***** Func: header-file for tcpip.c ***** |
frank26080115 | 0:bf7b9fba3924 | 11 | ***** ***** |
frank26080115 | 0:bf7b9fba3924 | 12 | ******************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 13 | |
frank26080115 | 0:bf7b9fba3924 | 14 | #ifndef __TCPIP_H |
frank26080115 | 0:bf7b9fba3924 | 15 | #define __TCPIP_H |
frank26080115 | 0:bf7b9fba3924 | 16 | |
frank26080115 | 0:bf7b9fba3924 | 17 | // easyWEB-stack definitions |
frank26080115 | 0:bf7b9fba3924 | 18 | #define MYIP_1 192 // our internet protocol (IP) address |
frank26080115 | 0:bf7b9fba3924 | 19 | #define MYIP_2 168 |
frank26080115 | 0:bf7b9fba3924 | 20 | #define MYIP_3 0 |
frank26080115 | 0:bf7b9fba3924 | 21 | #define MYIP_4 100 |
frank26080115 | 0:bf7b9fba3924 | 22 | |
frank26080115 | 0:bf7b9fba3924 | 23 | #define SUBMASK_1 255 // subnet mask |
frank26080115 | 0:bf7b9fba3924 | 24 | #define SUBMASK_2 255 |
frank26080115 | 0:bf7b9fba3924 | 25 | #define SUBMASK_3 255 |
frank26080115 | 0:bf7b9fba3924 | 26 | #define SUBMASK_4 0 |
frank26080115 | 0:bf7b9fba3924 | 27 | |
frank26080115 | 0:bf7b9fba3924 | 28 | #define GWIP_1 192 // standard gateway (used if remote |
frank26080115 | 0:bf7b9fba3924 | 29 | #define GWIP_2 168 // IP is no part of our subnet) |
frank26080115 | 0:bf7b9fba3924 | 30 | #define GWIP_3 0 |
frank26080115 | 0:bf7b9fba3924 | 31 | #define GWIP_4 254 |
frank26080115 | 0:bf7b9fba3924 | 32 | |
frank26080115 | 0:bf7b9fba3924 | 33 | #define RETRY_TIMEOUT 8 // wait max. 8 x 262ms for an ACK (about 2 sec.) |
frank26080115 | 0:bf7b9fba3924 | 34 | #define FIN_TIMEOUT 2 // max. time to wait for an ACK of a FIN |
frank26080115 | 0:bf7b9fba3924 | 35 | // before closing TCP state-machine (about 0.5 s) |
frank26080115 | 0:bf7b9fba3924 | 36 | #define MAX_RETRYS 4 // nr. of resendings before reset conn. |
frank26080115 | 0:bf7b9fba3924 | 37 | // total nr. of transmissions = MAX_RETRYS + 1 |
frank26080115 | 0:bf7b9fba3924 | 38 | |
frank26080115 | 0:bf7b9fba3924 | 39 | #define MAX_TCP_TX_DATA_SIZE 512 // max. outgoing TCP data size (even!) |
frank26080115 | 0:bf7b9fba3924 | 40 | #define MAX_TCP_RX_DATA_SIZE 256 // max. incoming TCP data size (even!) |
frank26080115 | 0:bf7b9fba3924 | 41 | // (increasing the buffer-size dramatically |
frank26080115 | 0:bf7b9fba3924 | 42 | // increases the transfer-speed!) |
frank26080115 | 0:bf7b9fba3924 | 43 | |
frank26080115 | 0:bf7b9fba3924 | 44 | #define MAX_ETH_TX_DATA_SIZE 60 // 2nd buffer, used for ARP, ICMP, TCP (even!) |
frank26080115 | 0:bf7b9fba3924 | 45 | // enough to echo 32 byte via ICMP |
frank26080115 | 0:bf7b9fba3924 | 46 | |
frank26080115 | 0:bf7b9fba3924 | 47 | #define DEFAULT_TTL 64 // Time To Live sent with packets |
frank26080115 | 0:bf7b9fba3924 | 48 | |
frank26080115 | 0:bf7b9fba3924 | 49 | // Ethernet network layer definitions |
frank26080115 | 0:bf7b9fba3924 | 50 | #define ETH_DA_OFS 0 // Destination MAC address (48 Bit) |
frank26080115 | 0:bf7b9fba3924 | 51 | #define ETH_SA_OFS 6 // Source MAC address (48 Bit) |
frank26080115 | 0:bf7b9fba3924 | 52 | #define ETH_TYPE_OFS 12 // Type field (16 Bit) |
frank26080115 | 0:bf7b9fba3924 | 53 | #define ETH_DATA_OFS 14 // Frame Data |
frank26080115 | 0:bf7b9fba3924 | 54 | #define ETH_HEADER_SIZE 14 |
frank26080115 | 0:bf7b9fba3924 | 55 | |
frank26080115 | 0:bf7b9fba3924 | 56 | #define FRAME_ARP 0x0806 // frame types (stored in Type/Length field) |
frank26080115 | 0:bf7b9fba3924 | 57 | #define FRAME_IP 0x0800 |
frank26080115 | 0:bf7b9fba3924 | 58 | |
frank26080115 | 0:bf7b9fba3924 | 59 | // IPv4 layer definitions |
frank26080115 | 0:bf7b9fba3924 | 60 | #define IP_VER_IHL_TOS_OFS ETH_DATA_OFS + 0 // Version, Header Length, Type of Service |
frank26080115 | 0:bf7b9fba3924 | 61 | #define IP_TOTAL_LENGTH_OFS ETH_DATA_OFS + 2 // IP Frame's Total Length |
frank26080115 | 0:bf7b9fba3924 | 62 | #define IP_IDENT_OFS ETH_DATA_OFS + 4 // Identifying Value |
frank26080115 | 0:bf7b9fba3924 | 63 | #define IP_FLAGS_FRAG_OFS ETH_DATA_OFS + 6 // Flags and Fragment Offset |
frank26080115 | 0:bf7b9fba3924 | 64 | #define IP_TTL_PROT_OFS ETH_DATA_OFS + 8 // Frame's Time to Live, Protocol |
frank26080115 | 0:bf7b9fba3924 | 65 | #define IP_HEAD_CHKSUM_OFS ETH_DATA_OFS + 10 // IP Frame's Header Checksum |
frank26080115 | 0:bf7b9fba3924 | 66 | #define IP_SOURCE_OFS ETH_DATA_OFS + 12 // Source Address (32 Bit) |
frank26080115 | 0:bf7b9fba3924 | 67 | #define IP_DESTINATION_OFS ETH_DATA_OFS + 16 // Destination Address (32 Bit) |
frank26080115 | 0:bf7b9fba3924 | 68 | #define IP_DATA_OFS ETH_DATA_OFS + 20 // Frame Data (if no options) |
frank26080115 | 0:bf7b9fba3924 | 69 | #define IP_HEADER_SIZE 20 // w/o options |
frank26080115 | 0:bf7b9fba3924 | 70 | |
frank26080115 | 0:bf7b9fba3924 | 71 | #define IP_VER_IHL 0x4500 // IPv4, Header Length = 5x32 bit |
frank26080115 | 0:bf7b9fba3924 | 72 | #define IP_TOS_D 0x0010 // TOS low delay |
frank26080115 | 0:bf7b9fba3924 | 73 | #define IP_TOS_T 0x0008 // TOS high throughput |
frank26080115 | 0:bf7b9fba3924 | 74 | #define IP_TOS_R 0x0004 // TOS high reliability |
frank26080115 | 0:bf7b9fba3924 | 75 | |
frank26080115 | 0:bf7b9fba3924 | 76 | #define IP_FLAG_DONTFRAG 0x4000 // don't fragment IP frame |
frank26080115 | 0:bf7b9fba3924 | 77 | #define IP_FLAG_MOREFRAG 0x2000 // more fragments available |
frank26080115 | 0:bf7b9fba3924 | 78 | #define IP_FRAGOFS_MASK 0x1FFF // indicates where this fragment belongs |
frank26080115 | 0:bf7b9fba3924 | 79 | |
frank26080115 | 0:bf7b9fba3924 | 80 | #define PROT_ICMP 1 // Internet Control Message Protocol |
frank26080115 | 0:bf7b9fba3924 | 81 | #define PROT_TCP 6 // Transmission Control Protocol |
frank26080115 | 0:bf7b9fba3924 | 82 | #define PROT_UDP 17 // User Datagram Protocol |
frank26080115 | 0:bf7b9fba3924 | 83 | |
frank26080115 | 0:bf7b9fba3924 | 84 | // ARP definitions |
frank26080115 | 0:bf7b9fba3924 | 85 | #define ARP_HARDW_OFS ETH_DATA_OFS + 0 // Hardware address type |
frank26080115 | 0:bf7b9fba3924 | 86 | #define ARP_PROT_OFS ETH_DATA_OFS + 2 // Protocol |
frank26080115 | 0:bf7b9fba3924 | 87 | #define ARP_HLEN_PLEN_OFS ETH_DATA_OFS + 4 // byte length of each hardw. / prot. address |
frank26080115 | 0:bf7b9fba3924 | 88 | #define ARP_OPCODE_OFS ETH_DATA_OFS + 6 // Opcode |
frank26080115 | 0:bf7b9fba3924 | 89 | #define ARP_SENDER_HA_OFS ETH_DATA_OFS + 8 // Hardw. address of sender of this packet |
frank26080115 | 0:bf7b9fba3924 | 90 | #define ARP_SENDER_IP_OFS ETH_DATA_OFS + 14 // IP address of sender |
frank26080115 | 0:bf7b9fba3924 | 91 | #define ARP_TARGET_HA_OFS ETH_DATA_OFS + 18 // Hardw. address of target of this packet |
frank26080115 | 0:bf7b9fba3924 | 92 | #define ARP_TARGET_IP_OFS ETH_DATA_OFS + 24 // IP address of target |
frank26080115 | 0:bf7b9fba3924 | 93 | #define ARP_FRAME_SIZE 28 |
frank26080115 | 0:bf7b9fba3924 | 94 | |
frank26080115 | 0:bf7b9fba3924 | 95 | #define HARDW_ETH10 1 // hardware-type 10Mbps Ethernet |
frank26080115 | 0:bf7b9fba3924 | 96 | #define IP_HLEN_PLEN 0x0604 // MAC = 6 byte long, IP = 4 byte long |
frank26080115 | 0:bf7b9fba3924 | 97 | #define OP_ARP_REQUEST 1 // operations for ARP-frames |
frank26080115 | 0:bf7b9fba3924 | 98 | #define OP_ARP_ANSWER 2 |
frank26080115 | 0:bf7b9fba3924 | 99 | |
frank26080115 | 0:bf7b9fba3924 | 100 | // ICMP definitions |
frank26080115 | 0:bf7b9fba3924 | 101 | #define ICMP_TYPE_CODE_OFS IP_DATA_OFS + 0 // type of message |
frank26080115 | 0:bf7b9fba3924 | 102 | #define ICMP_CHKSUM_OFS IP_DATA_OFS + 2 // checksum of ICMP-message (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 103 | #define ICMP_DATA_OFS IP_DATA_OFS + 4 |
frank26080115 | 0:bf7b9fba3924 | 104 | #define ICMP_HEADER_SIZE 4 |
frank26080115 | 0:bf7b9fba3924 | 105 | |
frank26080115 | 0:bf7b9fba3924 | 106 | #define ICMP_ECHO 8 // message is an echo request |
frank26080115 | 0:bf7b9fba3924 | 107 | #define ICMP_ECHO_REPLY 0 // message is an echo reply |
frank26080115 | 0:bf7b9fba3924 | 108 | |
frank26080115 | 0:bf7b9fba3924 | 109 | // TCP layer definitions |
frank26080115 | 0:bf7b9fba3924 | 110 | #define TCP_SRCPORT_OFS IP_DATA_OFS + 0 // Source Port (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 111 | #define TCP_DESTPORT_OFS IP_DATA_OFS + 2 // Destination Port (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 112 | #define TCP_SEQNR_OFS IP_DATA_OFS + 4 // Sequence Number (32 bit) |
frank26080115 | 0:bf7b9fba3924 | 113 | #define TCP_ACKNR_OFS IP_DATA_OFS + 8 // Acknowledge Number (32 bit) |
frank26080115 | 0:bf7b9fba3924 | 114 | #define TCP_DATA_CODE_OFS IP_DATA_OFS + 12 // Data Offset and Control Bits (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 115 | #define TCP_WINDOW_OFS IP_DATA_OFS + 14 // Window Size (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 116 | #define TCP_CHKSUM_OFS IP_DATA_OFS + 16 // Checksum Field (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 117 | #define TCP_URGENT_OFS IP_DATA_OFS + 18 // Urgent Pointer (16 bit) |
frank26080115 | 0:bf7b9fba3924 | 118 | #define TCP_DATA_OFS IP_DATA_OFS + 20 // Frame Data (if no options) |
frank26080115 | 0:bf7b9fba3924 | 119 | #define TCP_HEADER_SIZE 20 // size w/o options |
frank26080115 | 0:bf7b9fba3924 | 120 | |
frank26080115 | 0:bf7b9fba3924 | 121 | #define DATA_OFS_MASK 0xF000 // number of 32 bit words in the TCP Header |
frank26080115 | 0:bf7b9fba3924 | 122 | |
frank26080115 | 0:bf7b9fba3924 | 123 | #define TCP_CODE_FIN 0x0001 |
frank26080115 | 0:bf7b9fba3924 | 124 | #define TCP_CODE_SYN 0x0002 |
frank26080115 | 0:bf7b9fba3924 | 125 | #define TCP_CODE_RST 0x0004 |
frank26080115 | 0:bf7b9fba3924 | 126 | #define TCP_CODE_PSH 0x0008 |
frank26080115 | 0:bf7b9fba3924 | 127 | #define TCP_CODE_ACK 0x0010 |
frank26080115 | 0:bf7b9fba3924 | 128 | #define TCP_CODE_URG 0x0020 |
frank26080115 | 0:bf7b9fba3924 | 129 | |
frank26080115 | 0:bf7b9fba3924 | 130 | #define TCP_OPT_MSS 0x0204 // Type 2, Option Length 4 (Max. Segment Size) |
frank26080115 | 0:bf7b9fba3924 | 131 | #define TCP_OPT_MSS_SIZE 4 |
frank26080115 | 0:bf7b9fba3924 | 132 | |
frank26080115 | 0:bf7b9fba3924 | 133 | // define some TCP standard-ports, useful for testing... |
frank26080115 | 0:bf7b9fba3924 | 134 | #define TCP_PORT_ECHO 7 // echo |
frank26080115 | 0:bf7b9fba3924 | 135 | #define TCP_PORT_DISCARD 9 // discard |
frank26080115 | 0:bf7b9fba3924 | 136 | #define TCP_PORT_DAYTIME 13 // daytime |
frank26080115 | 0:bf7b9fba3924 | 137 | #define TCP_PORT_QOTD 17 // quote of the day |
frank26080115 | 0:bf7b9fba3924 | 138 | #define TCP_PORT_CHARGEN 19 // character generator |
frank26080115 | 0:bf7b9fba3924 | 139 | #define TCP_PORT_HTTP 80 // word wide web HTTP |
frank26080115 | 0:bf7b9fba3924 | 140 | |
frank26080115 | 0:bf7b9fba3924 | 141 | // macros |
frank26080115 | 0:bf7b9fba3924 | 142 | #define SWAPB(Word) ((unsigned short)((Word) << 8) | ((Word) >> 8)) |
frank26080115 | 0:bf7b9fba3924 | 143 | // convert little <-> big endian |
frank26080115 | 0:bf7b9fba3924 | 144 | |
frank26080115 | 0:bf7b9fba3924 | 145 | // typedefs |
frank26080115 | 0:bf7b9fba3924 | 146 | typedef enum { // states of the TCP-state machine |
frank26080115 | 0:bf7b9fba3924 | 147 | CLOSED, // according to RFC793 |
frank26080115 | 0:bf7b9fba3924 | 148 | LISTENING, |
frank26080115 | 0:bf7b9fba3924 | 149 | SYN_SENT, |
frank26080115 | 0:bf7b9fba3924 | 150 | SYN_RECD, |
frank26080115 | 0:bf7b9fba3924 | 151 | ESTABLISHED, |
frank26080115 | 0:bf7b9fba3924 | 152 | FIN_WAIT_1, |
frank26080115 | 0:bf7b9fba3924 | 153 | FIN_WAIT_2, |
frank26080115 | 0:bf7b9fba3924 | 154 | CLOSE_WAIT, |
frank26080115 | 0:bf7b9fba3924 | 155 | CLOSING, |
frank26080115 | 0:bf7b9fba3924 | 156 | LAST_ACK, |
frank26080115 | 0:bf7b9fba3924 | 157 | TIME_WAIT |
frank26080115 | 0:bf7b9fba3924 | 158 | } TTCPStateMachine; |
frank26080115 | 0:bf7b9fba3924 | 159 | |
frank26080115 | 0:bf7b9fba3924 | 160 | typedef enum { // type of last frame sent. used |
frank26080115 | 0:bf7b9fba3924 | 161 | ARP_REQUEST, // for retransmissions |
frank26080115 | 0:bf7b9fba3924 | 162 | TCP_SYN_FRAME, |
frank26080115 | 0:bf7b9fba3924 | 163 | TCP_SYN_ACK_FRAME, |
frank26080115 | 0:bf7b9fba3924 | 164 | TCP_FIN_FRAME, |
frank26080115 | 0:bf7b9fba3924 | 165 | TCP_DATA_FRAME |
frank26080115 | 0:bf7b9fba3924 | 166 | } TLastFrameSent; |
frank26080115 | 0:bf7b9fba3924 | 167 | |
frank26080115 | 0:bf7b9fba3924 | 168 | // constants |
frank26080115 | 0:bf7b9fba3924 | 169 | #ifdef extern // Keil: declarations for modular programming |
frank26080115 | 0:bf7b9fba3924 | 170 | const unsigned short MyIP[] = // "MYIP1.MYIP2.MYIP3.MYIP4" |
frank26080115 | 0:bf7b9fba3924 | 171 | { |
frank26080115 | 0:bf7b9fba3924 | 172 | MYIP_1 + (MYIP_2 << 8), // use 'unsigned int' to |
frank26080115 | 0:bf7b9fba3924 | 173 | MYIP_3 + (MYIP_4 << 8) // achieve word alignment |
frank26080115 | 0:bf7b9fba3924 | 174 | }; |
frank26080115 | 0:bf7b9fba3924 | 175 | |
frank26080115 | 0:bf7b9fba3924 | 176 | const unsigned short SubnetMask[] = // "SUBMASK1.SUBMASK2.SUBMASK3.SUBMASK4" |
frank26080115 | 0:bf7b9fba3924 | 177 | { |
frank26080115 | 0:bf7b9fba3924 | 178 | SUBMASK_1 + (SUBMASK_2 << 8), // use 'unsigned int' to |
frank26080115 | 0:bf7b9fba3924 | 179 | SUBMASK_3 + (SUBMASK_4 << 8) // achieve word alignment |
frank26080115 | 0:bf7b9fba3924 | 180 | }; |
frank26080115 | 0:bf7b9fba3924 | 181 | |
frank26080115 | 0:bf7b9fba3924 | 182 | const unsigned short GatewayIP[] = // "GWIP1.GWIP2.GWIP3.GWIP4" |
frank26080115 | 0:bf7b9fba3924 | 183 | { |
frank26080115 | 0:bf7b9fba3924 | 184 | GWIP_1 + (GWIP_2 << 8), // use 'unsigned int' to |
frank26080115 | 0:bf7b9fba3924 | 185 | GWIP_3 + (GWIP_4 << 8) // achieve word alignment |
frank26080115 | 0:bf7b9fba3924 | 186 | }; |
frank26080115 | 0:bf7b9fba3924 | 187 | #else |
frank26080115 | 0:bf7b9fba3924 | 188 | extern const unsigned short MyIP[2]; // "MYIP1.MYIP2.MYIP3.MYIP4" |
frank26080115 | 0:bf7b9fba3924 | 189 | extern const unsigned short SubnetMask[2]; // "SUBMASK1.SUBMASK2.SUBMASK3.SUBMASK4" |
frank26080115 | 0:bf7b9fba3924 | 190 | extern const unsigned short GatewayIP[2]; // "GWIP1.GWIP2.GWIP3.GWIP4" |
frank26080115 | 0:bf7b9fba3924 | 191 | extern const unsigned char MyMAC[6]; // "M1-M2-M3-M4-M5-M6" |
frank26080115 | 0:bf7b9fba3924 | 192 | #endif |
frank26080115 | 0:bf7b9fba3924 | 193 | |
frank26080115 | 0:bf7b9fba3924 | 194 | // easyWEB's internal variables |
frank26080115 | 0:bf7b9fba3924 | 195 | extern TTCPStateMachine TCPStateMachine; // perhaps the most important var at all ;-) |
frank26080115 | 0:bf7b9fba3924 | 196 | extern TLastFrameSent LastFrameSent; // retransmission type |
frank26080115 | 0:bf7b9fba3924 | 197 | |
frank26080115 | 0:bf7b9fba3924 | 198 | extern unsigned short ISNGenHigh; // upper word of our Initial Sequence Number |
frank26080115 | 0:bf7b9fba3924 | 199 | extern unsigned long TCPSeqNr; // next sequence number to send |
frank26080115 | 0:bf7b9fba3924 | 200 | extern unsigned long TCPUNASeqNr; // last unaknowledged sequence number |
frank26080115 | 0:bf7b9fba3924 | 201 | // incremented AFTER sending data |
frank26080115 | 0:bf7b9fba3924 | 202 | extern unsigned long TCPAckNr; // next seq to receive and ack to send |
frank26080115 | 0:bf7b9fba3924 | 203 | // incremented AFTER receiving data |
frank26080115 | 0:bf7b9fba3924 | 204 | extern unsigned char TCPTimer; // inc'd each 262ms |
frank26080115 | 0:bf7b9fba3924 | 205 | extern unsigned char RetryCounter; // nr. of retransmissions |
frank26080115 | 0:bf7b9fba3924 | 206 | |
frank26080115 | 0:bf7b9fba3924 | 207 | // properties of the just received frame |
frank26080115 | 0:bf7b9fba3924 | 208 | extern unsigned short RecdFrameLength; // EMAC reported frame length |
frank26080115 | 0:bf7b9fba3924 | 209 | extern unsigned short RecdFrameMAC[3]; // 48 bit MAC |
frank26080115 | 0:bf7b9fba3924 | 210 | extern unsigned short RecdFrameIP[2]; // 32 bit IP |
frank26080115 | 0:bf7b9fba3924 | 211 | extern unsigned short RecdIPFrameLength; // 16 bit IP packet length |
frank26080115 | 0:bf7b9fba3924 | 212 | |
frank26080115 | 0:bf7b9fba3924 | 213 | // the next 3 buffers must be word-aligned! |
frank26080115 | 0:bf7b9fba3924 | 214 | // (here the 'RecdIPFrameLength' above does that) |
frank26080115 | 0:bf7b9fba3924 | 215 | #if defined ( __CC_ARM ) |
frank26080115 | 0:bf7b9fba3924 | 216 | extern unsigned short __align(4) _TxFrame1[(ETH_HEADER_SIZE + IP_HEADER_SIZE + TCP_HEADER_SIZE + MAX_TCP_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 217 | extern unsigned short __align(4) _TxFrame2[(ETH_HEADER_SIZE + MAX_ETH_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 218 | extern unsigned short __align(4) _RxTCPBuffer[MAX_TCP_RX_DATA_SIZE/2]; // space for incoming TCP-data |
frank26080115 | 0:bf7b9fba3924 | 219 | #elif defined ( __ICCARM__ ) |
frank26080115 | 0:bf7b9fba3924 | 220 | #pragma data_alignment=4 |
frank26080115 | 0:bf7b9fba3924 | 221 | extern unsigned short _TxFrame1[(ETH_HEADER_SIZE + IP_HEADER_SIZE + TCP_HEADER_SIZE + MAX_TCP_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 222 | #pragma data_alignment=4 |
frank26080115 | 0:bf7b9fba3924 | 223 | extern unsigned short _TxFrame2[(ETH_HEADER_SIZE + MAX_ETH_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 224 | #pragma data_alignment=4 |
frank26080115 | 0:bf7b9fba3924 | 225 | extern unsigned short _RxTCPBuffer[MAX_TCP_RX_DATA_SIZE/2]; // space for incoming TCP-data |
frank26080115 | 0:bf7b9fba3924 | 226 | #elif defined ( __GNUC__ ) |
frank26080115 | 0:bf7b9fba3924 | 227 | extern unsigned short __attribute__ ((aligned (4))) _TxFrame1[(ETH_HEADER_SIZE + IP_HEADER_SIZE + TCP_HEADER_SIZE + MAX_TCP_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 228 | extern unsigned short __attribute__ ((aligned (4))) _TxFrame2[(ETH_HEADER_SIZE + MAX_ETH_TX_DATA_SIZE)/2]; |
frank26080115 | 0:bf7b9fba3924 | 229 | extern unsigned short __attribute__ ((aligned (4))) _RxTCPBuffer[MAX_TCP_RX_DATA_SIZE/2]; // space for incoming TCP-data |
frank26080115 | 0:bf7b9fba3924 | 230 | #endif |
frank26080115 | 0:bf7b9fba3924 | 231 | #define TxFrame1 ((unsigned char *)_TxFrame1) |
frank26080115 | 0:bf7b9fba3924 | 232 | #define TxFrame2 ((unsigned char *)_TxFrame2) |
frank26080115 | 0:bf7b9fba3924 | 233 | #define RxTCPBuffer ((unsigned char *)_RxTCPBuffer) |
frank26080115 | 0:bf7b9fba3924 | 234 | |
frank26080115 | 0:bf7b9fba3924 | 235 | extern unsigned short TxFrame1Size; // bytes to send in TxFrame1 |
frank26080115 | 0:bf7b9fba3924 | 236 | extern unsigned char TxFrame2Size; // bytes to send in TxFrame2 |
frank26080115 | 0:bf7b9fba3924 | 237 | |
frank26080115 | 0:bf7b9fba3924 | 238 | extern unsigned char TransmitControl; |
frank26080115 | 0:bf7b9fba3924 | 239 | #define SEND_FRAME1 0x01 |
frank26080115 | 0:bf7b9fba3924 | 240 | #define SEND_FRAME2 0x02 |
frank26080115 | 0:bf7b9fba3924 | 241 | |
frank26080115 | 0:bf7b9fba3924 | 242 | extern unsigned char TCPFlags; |
frank26080115 | 0:bf7b9fba3924 | 243 | #define TCP_ACTIVE_OPEN 0x01 // easyWEB shall initiate a connection |
frank26080115 | 0:bf7b9fba3924 | 244 | #define IP_ADDR_RESOLVED 0x02 // IP sucessfully resolved to MAC |
frank26080115 | 0:bf7b9fba3924 | 245 | #define TCP_TIMER_RUNNING 0x04 |
frank26080115 | 0:bf7b9fba3924 | 246 | #define TIMER_TYPE_RETRY 0x08 |
frank26080115 | 0:bf7b9fba3924 | 247 | #define TCP_CLOSE_REQUESTED 0x10 |
frank26080115 | 0:bf7b9fba3924 | 248 | |
frank26080115 | 0:bf7b9fba3924 | 249 | // prototypes |
frank26080115 | 0:bf7b9fba3924 | 250 | void DoNetworkStuff(void); |
frank26080115 | 0:bf7b9fba3924 | 251 | |
frank26080115 | 0:bf7b9fba3924 | 252 | // Handlers for incoming frames |
frank26080115 | 0:bf7b9fba3924 | 253 | void ProcessEthBroadcastFrame(void); |
frank26080115 | 0:bf7b9fba3924 | 254 | void ProcessEthIAFrame(void); |
frank26080115 | 0:bf7b9fba3924 | 255 | void ProcessICMPFrame(void); |
frank26080115 | 0:bf7b9fba3924 | 256 | void ProcessTCPFrame(void); |
frank26080115 | 0:bf7b9fba3924 | 257 | |
frank26080115 | 0:bf7b9fba3924 | 258 | // fill TX-buffers |
frank26080115 | 0:bf7b9fba3924 | 259 | void PrepareARP_REQUEST(void); |
frank26080115 | 0:bf7b9fba3924 | 260 | void PrepareARP_ANSWER(void); |
frank26080115 | 0:bf7b9fba3924 | 261 | void PrepareICMP_ECHO_REPLY(void); |
frank26080115 | 0:bf7b9fba3924 | 262 | void PrepareTCP_FRAME(unsigned short TCPCode); |
frank26080115 | 0:bf7b9fba3924 | 263 | void PrepareTCP_DATA_FRAME(void); |
frank26080115 | 0:bf7b9fba3924 | 264 | |
frank26080115 | 0:bf7b9fba3924 | 265 | // general help functions |
frank26080115 | 0:bf7b9fba3924 | 266 | void SendFrame1(void); |
frank26080115 | 0:bf7b9fba3924 | 267 | void SendFrame2(void); |
frank26080115 | 0:bf7b9fba3924 | 268 | void TCPStartRetryTimer(void); |
frank26080115 | 0:bf7b9fba3924 | 269 | void TCPStartTimeWaitTimer(void); |
frank26080115 | 0:bf7b9fba3924 | 270 | void TCPRestartTimer(void); |
frank26080115 | 0:bf7b9fba3924 | 271 | void TCPStopTimer(void); |
frank26080115 | 0:bf7b9fba3924 | 272 | void TCPHandleRetransmission(void); |
frank26080115 | 0:bf7b9fba3924 | 273 | void TCPHandleTimeout(void); |
frank26080115 | 0:bf7b9fba3924 | 274 | unsigned short CalcChecksum(void *Start, unsigned short Count, unsigned char IsTCP); |
frank26080115 | 0:bf7b9fba3924 | 275 | |
frank26080115 | 0:bf7b9fba3924 | 276 | // functions to work with big-endian numbers |
frank26080115 | 0:bf7b9fba3924 | 277 | unsigned short SwapBytes(unsigned short Data); |
frank26080115 | 0:bf7b9fba3924 | 278 | void WriteWBE(unsigned char *Add, unsigned short Data); |
frank26080115 | 0:bf7b9fba3924 | 279 | void WriteDWBE(unsigned char *Add, unsigned long Data); |
frank26080115 | 0:bf7b9fba3924 | 280 | |
frank26080115 | 0:bf7b9fba3924 | 281 | // easyWEB-API functions |
frank26080115 | 0:bf7b9fba3924 | 282 | void TCPLowLevelInit(void); // setup timer, LAN-controller, flags... |
frank26080115 | 0:bf7b9fba3924 | 283 | void TCPPassiveOpen(void); // listen for a connection |
frank26080115 | 0:bf7b9fba3924 | 284 | void TCPActiveOpen(void); // open connection |
frank26080115 | 0:bf7b9fba3924 | 285 | void TCPClose(void); // close connection |
frank26080115 | 0:bf7b9fba3924 | 286 | void TCPReleaseRxBuffer(void); // indicate to discard rec'd packet |
frank26080115 | 0:bf7b9fba3924 | 287 | void TCPTransmitTxBuffer(void); // initiate transfer after TxBuffer is filled |
frank26080115 | 0:bf7b9fba3924 | 288 | //void TCPClockHandler(void) __irq; // Keil: interrupt service routine for timer 0 |
frank26080115 | 0:bf7b9fba3924 | 289 | void SysTick_Handler (void); // NXP: System tick timer is replaced for TCPClockHandler() |
frank26080115 | 0:bf7b9fba3924 | 290 | |
frank26080115 | 0:bf7b9fba3924 | 291 | |
frank26080115 | 0:bf7b9fba3924 | 292 | // easyWEB-API global vars and flags |
frank26080115 | 0:bf7b9fba3924 | 293 | extern unsigned short TCPRxDataCount; // nr. of bytes rec'd |
frank26080115 | 0:bf7b9fba3924 | 294 | extern unsigned short TCPTxDataCount; // nr. of bytes to send |
frank26080115 | 0:bf7b9fba3924 | 295 | |
frank26080115 | 0:bf7b9fba3924 | 296 | extern unsigned short TCPLocalPort; // TCP ports |
frank26080115 | 0:bf7b9fba3924 | 297 | extern unsigned short TCPRemotePort; |
frank26080115 | 0:bf7b9fba3924 | 298 | |
frank26080115 | 0:bf7b9fba3924 | 299 | extern unsigned short RemoteMAC[3]; // MAC and IP of current TCP-session |
frank26080115 | 0:bf7b9fba3924 | 300 | extern unsigned short RemoteIP[2]; |
frank26080115 | 0:bf7b9fba3924 | 301 | |
frank26080115 | 0:bf7b9fba3924 | 302 | extern unsigned char SocketStatus; |
frank26080115 | 0:bf7b9fba3924 | 303 | #define SOCK_ACTIVE 0x01 // state machine NOT closed |
frank26080115 | 0:bf7b9fba3924 | 304 | #define SOCK_CONNECTED 0x02 // user may send & receive data |
frank26080115 | 0:bf7b9fba3924 | 305 | #define SOCK_DATA_AVAILABLE 0x04 // new data available |
frank26080115 | 0:bf7b9fba3924 | 306 | #define SOCK_TX_BUF_RELEASED 0x08 // user may fill buffer |
frank26080115 | 0:bf7b9fba3924 | 307 | |
frank26080115 | 0:bf7b9fba3924 | 308 | #define SOCK_ERROR_MASK 0xF0 // bit-mask to check for errors |
frank26080115 | 0:bf7b9fba3924 | 309 | #define SOCK_ERR_OK 0x00 // no error |
frank26080115 | 0:bf7b9fba3924 | 310 | #define SOCK_ERR_ARP_TIMEOUT 0x10 // timeout waiting for an ARP-REPLY |
frank26080115 | 0:bf7b9fba3924 | 311 | #define SOCK_ERR_TCP_TIMEOUT 0x20 // timeout waiting for an ACK |
frank26080115 | 0:bf7b9fba3924 | 312 | #define SOCK_ERR_CONN_RESET 0x30 // connection was reset by the other TCP |
frank26080115 | 0:bf7b9fba3924 | 313 | #define SOCK_ERR_REMOTE 0x40 // remote TCP caused fatal error |
frank26080115 | 0:bf7b9fba3924 | 314 | #define SOCK_ERR_ETHERNET 0x50 // network interface error (timeout) |
frank26080115 | 0:bf7b9fba3924 | 315 | |
frank26080115 | 0:bf7b9fba3924 | 316 | // easyWEB-API buffer-pointers |
frank26080115 | 0:bf7b9fba3924 | 317 | #define TCP_TX_BUF ((unsigned char *)TxFrame1 + ETH_HEADER_SIZE + IP_HEADER_SIZE + TCP_HEADER_SIZE) |
frank26080115 | 0:bf7b9fba3924 | 318 | #define TCP_RX_BUF ((unsigned char *)RxTCPBuffer) |
frank26080115 | 0:bf7b9fba3924 | 319 | |
frank26080115 | 0:bf7b9fba3924 | 320 | #endif |
frank26080115 | 0:bf7b9fba3924 | 321 |