+++ /dev/null
-/*******************************************************************************\r
- * (c) Copyright 2009 SLS Corporation,All Rights Reserved.\r
- *\r
- * tcpip.h:header file for TCP/IP implementation.\r
- * Version Author Comment\r
- * 1.0.0 SLS corp. First release\r
- */\r
-/***************************************************************************//**\r
- * This header file contains the definition and datastructures for the TCP/IP \r
- * stack implementation.\r
- */\r
-#ifndef _NETTYPE_H_\r
-#define _NETTYPE_H_\r
-\r
-#define BUF_LEN 1500\r
-\r
-/* IP header length in terms of 16-bit words */\r
-#define IP_HDR_LEN 10\r
-#define IP_HDR_CSUM_OFFSET 5\r
-#define TCP_HDR_CSUM_OFFSET 8\r
-\r
-#define ETH_ADDR_LEN 6\r
-#define IP_ADDR_LEN 4\r
-#define ETH_TYPE_LEN 2\r
-#define ARP_HW_TYPE_LEN 2\r
-#define ARP_PROTO_TYPE_LEN 2\r
-#define ARP_OPCODE_LEN 2\r
-\r
-#define ETH_TYPE_0 0x08 /* both IP and ARP have 08 as the first byte */\r
-#define ETH_TYPE_ARP_1 0x06 /* 0806 is ARP */\r
-#define ETH_TYPE_IP_1 0x00 /* 0800 is IP */\r
-\r
-#define ARP_HW_TYPE_0 0x00 /* 0001 for ethernet */\r
-#define ARP_HW_TYPE_1 0x01 /* 0001 for ethernet */\r
-\r
-#define ARP_PROTO_TYPE_0 0x08 /* 0800 is IP */\r
-#define ARP_PROTO_TYPE_1 0x00 \r
-\r
-#define ARP_OPCODE_0 0x00 /* same for req and reply */\r
-#define ARP_OPCODE_REQ_1 0x01 /* 0001 is Request */\r
-#define ARP_OPCODE_REPLY_1 0x02 /* 0002 is Reply */\r
-\r
-extern unsigned char my_IP_address[IP_ADDR_LEN];\r
-\r
-typedef struct ether_hdr {\r
- unsigned char da[ETH_ADDR_LEN]; /* destination MAC address */\r
- unsigned char sa[ETH_ADDR_LEN]; /* source MAC address */\r
- unsigned char type_code[ETH_TYPE_LEN]; /* type code */\r
-} ether_hdr_t;\r
-\r
-typedef struct arp_pkt {\r
- unsigned char hw_type[ARP_HW_TYPE_LEN]; /* Hardware Type */\r
- unsigned char proto_type[ARP_PROTO_TYPE_LEN]; /* Protocol Type */\r
- unsigned char hw_addr_len; /* Hardware Address Length */\r
- unsigned char proto_addr_len; /* Protocol Address Length */\r
- unsigned char opcode[ARP_OPCODE_LEN]; /* Opcode */\r
- unsigned char mac_sa[ETH_ADDR_LEN]; /* sender MAC address */\r
- unsigned char ip_sa[IP_ADDR_LEN]; /* sender IP address */\r
- unsigned char mac_ta[ETH_ADDR_LEN]; /* target MAC address */\r
- unsigned char ip_ta[IP_ADDR_LEN]; /* target IP address */\r
-} arp_pkt_t;\r
-\r
-#define ICMP_PROTO 0x01\r
-#define TCP_PROTO 0x06\r
-#define UDP_PROTO 0x11\r
-\r
-#define IP_CSUM_LEN 2\r
-#define IP_ID_LEN 2\r
-#define IP_TLEN_LEN 2\r
-#define IP_FRAG_OFF_LEN 2\r
-\r
-typedef struct ip_hdr {\r
- unsigned char ver_hlen; /* version - 4 bits; IP hdr len - 4 bits */\r
- unsigned char tos; /* Type of service */\r
- unsigned char tlen[IP_TLEN_LEN]; /* Size of datagram (header + data) */\r
- unsigned char id[IP_ID_LEN]; /* together with sa, uniequly identifies pkt */\r
- unsigned char frag_off[IP_FRAG_OFF_LEN]; /* flags - 3 bits; fragment offset - 13 bits */\r
- unsigned char ttl; /* time to live */\r
- unsigned char proto; /* protocol */\r
- unsigned char csum[IP_CSUM_LEN]; /* header checksum */\r
- unsigned char sa[IP_ADDR_LEN]; /* IP source address */\r
- unsigned char da[IP_ADDR_LEN]; /* IP dest address */\r
-} ip_hdr_t;\r
-\r
-\r
-#define ICMP_TYPE_ECHO_REQUEST 8\r
-#define ICMP_TYPE_ECHO_REPLY 0\r
-\r
-typedef struct icmp_hdr {\r
- unsigned char type;\r
- unsigned char icode;\r
- unsigned char csum[IP_CSUM_LEN];\r
-} icmp_hdr_t;\r
-\r
-#define TCP_PORT_LEN 2\r
-#define TCP_SEQ_LEN 4\r
-#define TCP_WSIZE_LEN 2\r
-#define TCP_UPTR_LEN 2\r
-#define TCP_CSUM_LEN 2\r
-#define TCP_PLEN_LEN 2\r
-\r
-typedef struct tcp_hdr {\r
- unsigned char sp[TCP_PORT_LEN]; /* Source port */\r
- unsigned char dp[TCP_PORT_LEN]; /* Destination port */\r
- unsigned char seqnum[TCP_SEQ_LEN]; /* Sequence number */\r
- unsigned char acknum[TCP_SEQ_LEN]; /* Acknowledgement number */\r
- unsigned char data_off; /* Data Offset - 4 upper bits are valid */\r
- unsigned char urg_ack_psh_rst_syn_fin; /* 6 lower bits are valid */\r
- unsigned char wsize[TCP_WSIZE_LEN]; /* Window */\r
- unsigned char csum[TCP_CSUM_LEN]; /* Chekcsum */\r
- unsigned char uptr[TCP_UPTR_LEN]; /* Urgent pointer */\r
-} tcp_hdr_t; \r
-\r
-#define UDP_LEN_LEN 2\r
-#define UDP_CSUM_LEN 2\r
-\r
-typedef struct udp_hdr {\r
- unsigned char sp[TCP_PORT_LEN]; /* Source port */\r
- unsigned char dp[TCP_PORT_LEN]; /* Destination port */\r
- unsigned char len[UDP_LEN_LEN]; /* length of packet */\r
- unsigned char csum[UDP_CSUM_LEN]; /* checksum */\r
-} udp_hdr_t;\r
-\r
-#define BOOTP_OPTCODE_DHCP_SUBNET 1 /* Subnet mask */\r
-#define BOOTP_OPTCODE_DHCP_ROUTER 3 /* Router*/\r
-#define BOOTP_OPTCODE_DHCP_DOMAIN 6 /* Domain */\r
-#define BOOTP_OPTCODE_DHCP_LEASE 51 /* Lease time*/ \r
-#define BOOTP_OPTCODE_DHCP_TYPE 53 /* 53, 1, DHCP_TYPE_* */\r
-#define BOOTP_OPTCODE_DHCP_SID 54 /* 54, 4, a.b.c.d, Server ID */\r
-#define BOOTP_OPTCODE_DHCP_RENEW 58 /* Renewal time */\r
-#define BOOTP_OPTCODE_DHCP_REBIND 59 /* Rebinding time */\r
-\r
-#define BOOTP_OPTCODE_END 255 /* last in options */\r
-\r
-#define DHCP_TYPE_DISCOVER 1 \r
-#define DHCP_TYPE_OFFER 2 \r
-#define DHCP_TYPE_REQUEST 3 \r
-#define DHCP_TYPE_DECLINE 4 \r
-#define DHCP_TYPE_ACK 5 \r
-#define DHCP_TYPE_NAK 6 \r
-#define DHCP_TYPE_RELEASE 7 \r
-\r
-\r
-#define BOOTP_OP_REQUEST 1\r
-#define BOOTP_OP_REPLY 2\r
-#define BOOTP_HWTYPE_ETH 1\r
-#define BOOTP_XID_LEN 4\r
-#define BOOTP_SEC_LEN 2\r
-#define BOOTP_CHLEN 16\r
-#define BOOTP_SN_LEN 64\r
-#define BOOTP_FL_LEN 128\r
-#define BOOTP_VEN_LEN 64\r
-\r
-#define BOOTP_CLIENT_PORT 68\r
-#define BOOTP_SERVER_PORT 67\r
-\r
-typedef struct bootp_pkt {\r
- unsigned char op; /* packet op code */\r
- unsigned char hwtype; /* hardware type */\r
- unsigned char hlen; /* hardware address length */\r
- unsigned char hops; /* client sets to zero */\r
- unsigned char xid[BOOTP_XID_LEN]; /* transaction ID, random */\r
- unsigned char secs[BOOTP_SEC_LEN]; /* seconds since boot */\r
- unsigned char flags[2]; /* flags */\r
- unsigned char ciaddr[IP_ADDR_LEN]; /* client IP ADDR */\r
- unsigned char yiaddr[IP_ADDR_LEN]; /* Your IP Addr */\r
- unsigned char siaddr[IP_ADDR_LEN]; /* Server IP ADDR */\r
- unsigned char giaddr[IP_ADDR_LEN]; /* Gateway IP ADDR */\r
- unsigned char chaddr[BOOTP_CHLEN]; /* Client Hardware Addr */\r
- unsigned char sname[BOOTP_SN_LEN]; /* Server Name */\r
- unsigned char file[BOOTP_FL_LEN]; /* File Path */\r
- unsigned char vend[BOOTP_VEN_LEN]; /* Vendor Data */\r
-} bootp_pkt_t;\r
-\r
-typedef struct tcp_pseudo_hdr {\r
- unsigned char sa[IP_ADDR_LEN];\r
- unsigned char da[IP_ADDR_LEN];\r
- unsigned char zero;\r
- unsigned char proto;\r
- unsigned char plen[TCP_PLEN_LEN];\r
-} tcp_pseudo_hdr_t;\r
-\r
-typedef enum tcp_state_e {\r
- TCP_STATE_LISTEN = 0,\r
- TCP_STATE_SYN_RECVD,\r
- TCP_STATE_ESTABLISHED,\r
- TCP_STATE_LAST_ACK,\r
- TCP_STATE_MY_LAST,\r
- TCP_STATE_CLOSED\r
-} tcp_state_t;\r
-\r
-typedef struct tcp_control_block {\r
- unsigned char local_port[TCP_PORT_LEN];\r
- unsigned char remote_port[TCP_PORT_LEN];\r
- unsigned char remote_addr[IP_ADDR_LEN];\r
- tcp_state_t state;\r
- unsigned int local_seq;\r
- unsigned int remote_seq;\r
- unsigned char remote_mac[ETH_ADDR_LEN]; /* this really doesn't belong here */\r
-//<CJ>: \r
- const uint8_t * tx_block_addr;\r
- unsigned short int tx_block_size;\r
- unsigned short int tx_block_idx;\r
- uint8_t * tcp_packet;\r
-} tcp_control_block_t;\r
-\r
-\r
-typedef enum tcp_cntrol_flags_e {\r
- TCP_CNTRL_FIN = 0x01,\r
- TCP_CNTRL_SYN = 0x02,\r
- TCP_CNTRL_RST = 0x04,\r
- TCP_CNTRL_PSH = 0x08,\r
- TCP_CNTRL_ACK = 0x10,\r
- TCP_CNTRL_URG = 0x20\r
-} tcp_control_flags_t;\r
-\r
-\r
-typedef struct arp_entry {\r
- unsigned char mac[ETH_ADDR_LEN]; /* MAC address */\r
- unsigned char ip[IP_ADDR_LEN]; /* IP address */\r
- unsigned char used; /* Is this entry used? */\r
-} arp_entry_t;\r
-\r
-typedef arp_pkt_t *arp_pkt_xp;\r
-typedef ether_hdr_t *eth_hdr_xp;\r
-typedef ip_hdr_t *ip_hdr_xp;\r
-typedef icmp_hdr_t *icmp_hdr_xp;\r
-typedef udp_hdr_t *udp_hdr_xp;\r
-typedef tcp_hdr_t *tcp_hdr_xp;\r
-typedef tcp_pseudo_hdr_t *tcp_pseudo_hdr_xp;\r
-typedef bootp_pkt_t *bootp_pkt_xp;\r
-\r
-#endif /* _NETTYPE_H_ */\r
+++ /dev/null
-/*******************************************************************************\r
- * (c) Copyright 2009 Actel Corporation,All Rights Reserved. \r
- * \r
- * tcpip.c:TCP/IP implementation for webserver.\r
- */\r
-#include "../port_config/cpu_types.h"\r
-#include "nettype.h"\r
-#include "../mss_ethernet_mac/mss_ethernet_mac.h"\r
-#include "../mss_ethernet_mac/mss_ethernet_mac_regs.h"\r
-#include "tcpip.h"\r
-#include <string.h>\r
-#include <stdio.h>\r
-#include <math.h>\r
-#define OK 0\r
-#define ERR 1\r
-#define MAC_BASE_ADDRESS 0x40003000\r
-\r
-\r
-extern char ethAddr[6];\r
-\r
-unsigned char my_ip[IP_ADDR_LEN]={192,168,0,14};\r
-unsigned char my_mac[ETH_ADDR_LEN]={0xAA,0xBB,0xCC,0x11,0x22,0x33};\r
-unsigned char tcp_packet[1532];\r
-unsigned char ip_known;\r
-unsigned char dhcp_ip_found;\r
-unsigned short int ip_id;\r
-unsigned char selected_mode = 0;\r
-unsigned char selectedwaveform = 0;\r
-unsigned char rtc_count[5]={0,0,0,0,0};\r
-unsigned char rtc_match_count[5]={0,5,0,0,0};\r
-unsigned char get_count[5];\r
-unsigned int num_pkt_tx = 0,num_pkt_rx = 0;\r
-#define TCP_START_SEQ 0x10203040\r
-static const unsigned char g_client_ip[IP_ADDR_LEN] = { 192, 168, 1, 10 };\r
-unsigned char oled_string[20];\r
-tcp_control_block_t tcb;\r
-MAC_instance_t g_mac;\r
-\r
-\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char send_arp_reply(unsigned char *buf)\r
-{\r
- /* Modify the packet in place */\r
-\r
- arp_pkt_xp arp_pkt = (arp_pkt_xp )(buf + sizeof(ether_hdr_t));\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) buf;\r
-\r
- memcpy(eth_hdr->da, eth_hdr->sa, ETH_ADDR_LEN);\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN);\r
- arp_pkt->opcode[1] = ARP_OPCODE_REPLY_1;\r
- memcpy(arp_pkt->mac_ta, arp_pkt->mac_sa, ETH_ADDR_LEN);\r
- memcpy(arp_pkt->ip_ta, arp_pkt->ip_sa, IP_ADDR_LEN);\r
- memcpy(arp_pkt->mac_sa, my_mac, ETH_ADDR_LEN);\r
- memcpy(arp_pkt->ip_sa, my_ip, IP_ADDR_LEN);\r
- num_pkt_tx++;\r
- MSS_MAC_tx_packet(buf,42, MSS_MAC_BLOCKING);\r
- return OK;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-void send_gratuitous_arp(unsigned char *buf)\r
-{\r
- arp_pkt_xp arp_pkt = (arp_pkt_xp )(buf + sizeof(ether_hdr_t));\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) buf;\r
- memset(eth_hdr->da, 0xFF, ETH_ADDR_LEN); /* broadcast */\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN);\r
- eth_hdr->type_code[0] = ETH_TYPE_0;\r
- eth_hdr->type_code[1] = ETH_TYPE_ARP_1;\r
- arp_pkt->hw_type[0] = ARP_HW_TYPE_0;\r
- arp_pkt->hw_type[1] = ARP_HW_TYPE_1;\r
- arp_pkt->proto_type[0] = ETH_TYPE_0;\r
- arp_pkt->proto_type[1] = ETH_TYPE_IP_1;\r
- arp_pkt->hw_addr_len = ETH_ADDR_LEN;\r
- arp_pkt->proto_addr_len = IP_ADDR_LEN;\r
- arp_pkt->opcode[0] = ARP_OPCODE_0;\r
- arp_pkt->opcode[1] = ARP_OPCODE_REQ_1;\r
- memcpy(arp_pkt->mac_sa, my_mac, ETH_ADDR_LEN);\r
- memcpy(arp_pkt->ip_sa, my_ip, IP_ADDR_LEN);\r
- memset(arp_pkt->mac_ta, 0x00, ETH_ADDR_LEN);\r
- memcpy(arp_pkt->ip_ta, my_ip, IP_ADDR_LEN);\r
- //mac_tx_send(buf,42,0);\r
- num_pkt_tx++;\r
- MSS_MAC_tx_packet(buf,42, MSS_MAC_BLOCKING);\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- * \r
- */\r
-unsigned short int get_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos)\r
-{\r
- unsigned int sum; /* our accumulated sum */\r
- unsigned short int delta; /* the next 16-bit quantity to add */\r
- unsigned short int i; \r
- unsigned short int ilen; \r
- sum = (unsigned int) 0; \r
- ilen=(len&1)?len-1:len; \r
- for (i = 0; i < ilen; i += 2) { \r
- if (i == pos) continue;\r
- delta = (unsigned short int)buf[i+1] + (unsigned short int)((unsigned short int)buf[i] << 8); \r
- sum += delta; \r
- if (sum & (unsigned int) 0x10000) { /* if there's a carry... */\r
- sum &= 0xffff; /* get rid of the carry bit */\r
- sum++; /* and move it down here */\r
- } \r
- } \r
- if ( len & 1) {\r
- delta = (unsigned short int)((unsigned short int)buf[i] << 8); \r
- sum += delta; \r
- if (sum & (unsigned int) 0x10000) { /* if there's a carry... */\r
- sum &= 0xffff; /* get rid of the carry bit */\r
- sum++; /* and move it down here */\r
- } \r
- }\r
- sum = ~sum; \r
- return sum;\r
- \r
-} //end calc_checksum \r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char fix_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos)\r
-{\r
- unsigned short int sum = get_checksum(buf,len,pos); \r
- buf[pos] = (unsigned char)(sum >> 8);\r
- buf[pos+1] = (unsigned char)sum;\r
- return OK;\r
-}\r
-\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char check_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos, char type)\r
-{\r
- unsigned short int sum = get_checksum(buf,len,pos);\r
- \r
- if ((buf[pos] != (unsigned char)(sum >> 8)) || \r
- (buf[pos+1] != (unsigned char) sum)) {\r
-\r
- type = 0; /* get around compiler warning */\r
- return ERR;\r
- } else {\r
- return OK;\r
- }\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char send_icmp_echo_reply(unsigned char *buf)\r
-{\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) buf;\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (buf + sizeof (ether_hdr_t));\r
- icmp_hdr_xp icmp_hdr = (icmp_hdr_xp ) \r
- (buf + sizeof (ether_hdr_t) + sizeof(ip_hdr_t));\r
- unsigned short int elen = ((unsigned short int)ip_hdr->tlen[0] << 8) + (unsigned short int)ip_hdr->tlen[1] - sizeof(ip_hdr_t);\r
- memcpy(eth_hdr->da, eth_hdr->sa, ETH_ADDR_LEN);\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN);\r
- memcpy(ip_hdr->da, ip_hdr->sa, IP_ADDR_LEN);\r
- memcpy(ip_hdr->sa, my_ip, IP_ADDR_LEN);\r
- ip_hdr->ttl--;\r
- fix_checksum((unsigned char *)ip_hdr, (unsigned short int) 20, (unsigned short int) 10);\r
- icmp_hdr->type = ICMP_TYPE_ECHO_REPLY;\r
- if (elen & 1) {\r
- ((unsigned char *)icmp_hdr)[elen] = 0;\r
- }\r
- fix_checksum((unsigned char *)icmp_hdr, (unsigned short int) elen, (unsigned short int) 2);\r
- num_pkt_tx++;\r
- MSS_MAC_tx_packet(buf,elen + sizeof(ether_hdr_t) + sizeof(ip_hdr_t), MSS_MAC_BLOCKING);\r
- return OK;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-void dtoa_reverse(unsigned short int n, unsigned char *buf)\r
-{\r
- buf--;\r
- if (n == 0) {\r
- *buf = '0';\r
- return;\r
- }\r
- while (n > 0) {\r
- *buf-- = (n % 10) + '0';\r
- n = n / 10;\r
- }\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-void send_bootp_packet (unsigned char *buf)\r
-{\r
- /* output packet */\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) tcp_packet;\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (tcp_packet + sizeof(ether_hdr_t));\r
- udp_hdr_xp udp_hdr = (udp_hdr_xp ) (tcp_packet + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- bootp_pkt_xp bootp_pkt = (bootp_pkt_xp )((unsigned char *)udp_hdr + sizeof(udp_hdr_t));\r
- unsigned char *opts = bootp_pkt->vend;\r
- /* input packet */\r
- // eth_hdr_xp ieth_hdr = (eth_hdr_xp ) buf;\r
- // ip_hdr_xp iip_hdr = (ip_hdr_xp ) (buf + sizeof(ether_hdr_t));\r
- udp_hdr_xp iudp_hdr = (udp_hdr_xp ) (buf + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- bootp_pkt_xp ibootp_pkt = (bootp_pkt_xp )((unsigned char *)iudp_hdr + sizeof(udp_hdr_t));\r
- unsigned short int plen;\r
- /* Set up Bootp */\r
- memset(bootp_pkt, 0, sizeof(bootp_pkt_t));\r
- bootp_pkt->op = BOOTP_OP_REQUEST;\r
- bootp_pkt->hwtype = BOOTP_HWTYPE_ETH;\r
- bootp_pkt->hlen = ETH_ADDR_LEN;\r
- bootp_pkt->secs[1] = 0x64;\r
- memcpy(bootp_pkt->chaddr, my_mac, ETH_ADDR_LEN);\r
- bootp_pkt->flags[0] = 0x80; /* ask for a broadcast */\r
- if (buf) {\r
- if (memcmp(my_mac, ibootp_pkt->chaddr, ETH_ADDR_LEN)) /* not for me ignore */\r
- return;\r
- memcpy(my_ip, ibootp_pkt->yiaddr, IP_ADDR_LEN);\r
- ip_known = 1;\r
- dhcp_ip_found = 1;\r
- memcpy(bootp_pkt->ciaddr, ibootp_pkt->yiaddr, IP_ADDR_LEN);\r
- memcpy(bootp_pkt->xid, ibootp_pkt->xid, BOOTP_XID_LEN);\r
- } else {\r
- bootp_pkt->xid[0] = 0x90;\r
- }\r
- *opts++ = 99; /* magic number */\r
- *opts++ = 130;\r
- *opts++ = 83;\r
- *opts++ = 99;\r
- *opts++ = BOOTP_OPTCODE_DHCP_TYPE;\r
- *opts++ = 1;\r
- if (buf) {\r
- *opts++ = DHCP_TYPE_REQUEST;\r
- *opts++ = BOOTP_OPTCODE_DHCP_SID;\r
- *opts++ = 4;\r
- *opts++ = ibootp_pkt->siaddr[0];\r
- *opts++ = ibootp_pkt->siaddr[1];\r
- *opts++ = ibootp_pkt->siaddr[2];\r
- *opts++ = ibootp_pkt->siaddr[3];\r
- } else {\r
- *opts++ = DHCP_TYPE_DISCOVER;\r
- }\r
- *opts++ = BOOTP_OPTCODE_END;\r
-\r
- /* Set up Udp */\r
- memset(udp_hdr, 0, sizeof(udp_hdr_t));\r
- udp_hdr->sp[1] = BOOTP_CLIENT_PORT;\r
- udp_hdr->dp[1] = BOOTP_SERVER_PORT;\r
- plen = sizeof(udp_hdr_t) + sizeof(bootp_pkt_t);\r
- udp_hdr->len[0] = plen >> 8;\r
- udp_hdr->len[1] = (unsigned char) plen;\r
- /* leave csum 0 */\r
-\r
- /* Set up IP */\r
- memset(ip_hdr, 0, sizeof(ip_hdr_t));\r
- ip_hdr->ver_hlen = 0x45; /* IPv4 with 20 byte header */\r
- plen += sizeof(ip_hdr_t);\r
- ip_hdr->tlen[0] = plen >> 8;\r
- ip_hdr->tlen[1] = (unsigned char) plen;\r
- ip_hdr->id[0] = ip_id >> 8;\r
- ip_hdr->id[1] = (unsigned char) ip_id;\r
- ip_id++;\r
- ip_hdr->ttl = 32; /* max 32 hops */\r
- ip_hdr->proto = UDP_PROTO; \r
- memset(ip_hdr->da, 0xFF, IP_ADDR_LEN);\r
- fix_checksum((unsigned char *)ip_hdr, sizeof(ip_hdr_t), 10);\r
- /* Set up Ethernet */\r
- eth_hdr->type_code[0] = ETH_TYPE_0;\r
- eth_hdr->type_code[1] = ETH_TYPE_IP_1;\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN);\r
- memset(eth_hdr->da, 0xFF, ETH_ADDR_LEN); /* broadcast */\r
- num_pkt_tx++;\r
- MSS_MAC_tx_packet(tcp_packet,plen + sizeof(ether_hdr_t), MSS_MAC_BLOCKING);\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-void send_dhcp_server_packet (unsigned char *buf)\r
-{\r
- unsigned char * tcp_packet = tcp_packet;\r
- /* output packet */\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) tcp_packet;\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (tcp_packet + sizeof(ether_hdr_t));\r
- udp_hdr_xp udp_hdr = (udp_hdr_xp ) (tcp_packet + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- bootp_pkt_xp bootp_pkt = (bootp_pkt_xp )((unsigned char *)udp_hdr + sizeof(udp_hdr_t));\r
- unsigned char *opts = bootp_pkt->vend;\r
-\r
- /* input packet */\r
- eth_hdr_xp ieth_hdr = (eth_hdr_xp ) buf;\r
- // ip_hdr_xp iip_hdr = (ip_hdr_xp ) (buf + sizeof(ether_hdr_t));\r
- udp_hdr_xp iudp_hdr = (udp_hdr_xp ) (buf + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- bootp_pkt_xp ibootp_pkt = (bootp_pkt_xp )((unsigned char *)iudp_hdr + sizeof(udp_hdr_t));\r
- unsigned char *iopts = ibootp_pkt->vend;\r
-\r
- unsigned short int plen;\r
-\r
- /* Set up Bootp */\r
- memset(bootp_pkt, 0, sizeof(bootp_pkt_t));\r
- bootp_pkt->op = BOOTP_OP_REPLY;\r
- bootp_pkt->hwtype = BOOTP_HWTYPE_ETH;\r
- bootp_pkt->hlen = ETH_ADDR_LEN;\r
- bootp_pkt->secs[1] = 0x64;\r
- memcpy(bootp_pkt->chaddr, ieth_hdr->sa, ETH_ADDR_LEN);\r
- bootp_pkt->flags[0] = 0x00;\r
- if (buf) {\r
- memcpy(bootp_pkt->ciaddr, ibootp_pkt->yiaddr, IP_ADDR_LEN);\r
- memcpy(bootp_pkt->yiaddr, g_client_ip, IP_ADDR_LEN);\r
- memcpy(bootp_pkt->xid, ibootp_pkt->xid, BOOTP_XID_LEN);\r
- } else {\r
- bootp_pkt->xid[0] = 0x90;\r
- }\r
- *opts++ = 99; /* magic number */\r
- *opts++ = 130;\r
- *opts++ = 83;\r
- *opts++ = 99;\r
- *opts++ = BOOTP_OPTCODE_DHCP_TYPE;\r
- *opts++ = 1;\r
- if (iopts[6] == DHCP_TYPE_DISCOVER)\r
- {\r
- *opts++ = DHCP_TYPE_OFFER;\r
- }\r
- else\r
- {\r
- *opts++ = DHCP_TYPE_ACK;\r
- } \r
- /* Server ID */\r
- *opts++ = BOOTP_OPTCODE_DHCP_SID;\r
- *opts++ = 4;\r
- *opts++ = my_ip[0];\r
- *opts++ = my_ip[1];\r
- *opts++ = my_ip[2];\r
- *opts++ = my_ip[3];\r
- /* Lease time (1 our) */\r
- *opts++ = BOOTP_OPTCODE_DHCP_LEASE;\r
- *opts++ = 4;\r
- *opts++ = 0x00;\r
- *opts++ = 0x00;\r
- *opts++ = 0x0E;\r
- *opts++ = 0x10;\r
- /* Renewal time */\r
- *opts++ = BOOTP_OPTCODE_DHCP_RENEW;\r
- *opts++ = 4;\r
- *opts++ = 0x00;\r
- *opts++ = 0x00;\r
- *opts++ = 0x07;\r
- *opts++ = 0x08;\r
- /* Rebinding time */\r
- *opts++ = BOOTP_OPTCODE_DHCP_REBIND;\r
- *opts++ = 4;\r
- *opts++ = 0x00;\r
- *opts++ = 0x00;\r
- *opts++ = 0x0C;\r
- *opts++ = 0x4E;\r
- /* Subnet mask */\r
- *opts++ = BOOTP_OPTCODE_DHCP_SUBNET;\r
- *opts++ = 4;\r
- *opts++ = 0xFF;\r
- *opts++ = 0xFF;\r
- *opts++ = 0xFF;\r
- *opts++ = 0x00;\r
- /* Router */\r
- *opts++ = BOOTP_OPTCODE_DHCP_ROUTER;\r
- *opts++ = 4;\r
- *opts++ = my_ip[0];\r
- *opts++ = my_ip[1];\r
- *opts++ = my_ip[2];\r
- *opts++ = my_ip[3];\r
- /* Domain */\r
- *opts++ = BOOTP_OPTCODE_DHCP_DOMAIN;\r
- *opts++ = 4;\r
- *opts++ = my_ip[0];\r
- *opts++ = my_ip[1];\r
- *opts++ = my_ip[2];\r
- *opts++ = my_ip[3];\r
- \r
- *opts++ = BOOTP_OPTCODE_END;\r
-\r
- /* Set up Udp */\r
- memset(udp_hdr, 0, sizeof(udp_hdr_t));\r
- udp_hdr->sp[1] = BOOTP_SERVER_PORT;\r
- udp_hdr->dp[1] = BOOTP_CLIENT_PORT;\r
- plen = sizeof(udp_hdr_t) + sizeof(bootp_pkt_t);\r
- udp_hdr->len[0] = plen >> 8;\r
- udp_hdr->len[1] = (unsigned char) plen;\r
- /* leave csum 0 */\r
-\r
- /* Set up IP */\r
- memset(ip_hdr, 0, sizeof(ip_hdr_t));\r
- ip_hdr->ver_hlen = 0x45; /* IPv4 with 20 byte header */\r
- plen += sizeof(ip_hdr_t);\r
- ip_hdr->tlen[0] = plen >> 8;\r
- ip_hdr->tlen[1] = (unsigned char) plen;\r
- ip_hdr->id[0] = ip_id >> 8;\r
- ip_hdr->id[1] = (unsigned char) ip_id;\r
- ip_id++;\r
- ip_hdr->ttl = 255;\r
- ip_hdr->proto = UDP_PROTO;\r
- memcpy(ip_hdr->sa, my_ip, IP_ADDR_LEN);\r
- memset(ip_hdr->da, 0xFF, IP_ADDR_LEN);\r
- fix_checksum((unsigned char *)ip_hdr, sizeof(ip_hdr_t), 10);\r
- \r
- /* Set up Ethernet */\r
- eth_hdr->type_code[0] = ETH_TYPE_0;\r
- eth_hdr->type_code[1] = ETH_TYPE_IP_1;\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN); \r
- memset(eth_hdr->da, 0xFF, ETH_ADDR_LEN); /* broadcast */\r
- num_pkt_tx++;\r
- MSS_MAC_tx_packet(tcp_packet,plen + sizeof(ether_hdr_t), MSS_MAC_BLOCKING);\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_udp_packet (unsigned char *buf)\r
-{\r
- \r
- udp_hdr_xp udp_hdr = (udp_hdr_xp ) (buf + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- \r
- if (udp_hdr->dp[1] != BOOTP_CLIENT_PORT) {\r
- send_dhcp_server_packet( buf );\r
- return OK;\r
- }\r
- if (ip_known) {\r
- return ERR;\r
- }\r
- /* some more error checking here? */\r
- send_bootp_packet(buf);\r
- return OK;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-\r
-void send_tcp_packet (unsigned char control_bits,unsigned short int buflen) \r
-{\r
- \r
- eth_hdr_xp eth_hdr = (eth_hdr_xp ) tcp_packet;\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (tcp_packet + sizeof(ether_hdr_t));\r
- tcp_hdr_xp tcp_hdr = (tcp_hdr_xp ) \r
- (tcp_packet + sizeof(ether_hdr_t) + sizeof(ip_hdr_t));\r
- tcp_pseudo_hdr_xp tcp_pseudo_hdr = (tcp_pseudo_hdr_xp )\r
- (((unsigned char *)tcp_hdr) - sizeof(tcp_pseudo_hdr_t));\r
- unsigned char *tcp_data = tcp_packet + sizeof(ether_hdr_t) + sizeof(ip_hdr_t) + sizeof (tcp_hdr_t);\r
- unsigned char *seqp = (unsigned char *)(&tcb.local_seq);\r
- unsigned short int plen;\r
- memset(tcp_hdr, 0, sizeof(tcp_hdr_t));\r
- memcpy(tcp_hdr->sp, tcb.local_port, TCP_PORT_LEN);\r
- memcpy(tcp_hdr->dp, tcb.remote_port, TCP_PORT_LEN);\r
- tcp_hdr->seqnum[0] = seqp[3];\r
- tcp_hdr->seqnum[1] = seqp[2];\r
- tcp_hdr->seqnum[2] = seqp[1];\r
- tcp_hdr->seqnum[3] = seqp[0];\r
- tcb.local_seq++;\r
- if (buflen) {\r
- tcb.local_seq += buflen - 1;\r
- }\r
- if (control_bits & TCP_CNTRL_ACK) {\r
- seqp = (unsigned char *)(&tcb.remote_seq);\r
- tcp_hdr->acknum[3] = seqp[0];\r
- tcp_hdr->acknum[2] = seqp[1];\r
- tcp_hdr->acknum[1] = seqp[2];\r
- tcp_hdr->acknum[0] = seqp[3];\r
- }\r
- tcp_hdr->data_off = 0x50; /* always 5 32 bit words for us */\r
- tcp_hdr->urg_ack_psh_rst_syn_fin = control_bits;\r
- tcp_hdr->wsize[0] = 0x08; /* this is 0x0800, which is 2K */\r
- if (buflen & 1) {\r
- tcp_data[buflen] = 0;\r
- }\r
- /* memset(tcp_pseudo_hdr, 0, sizeof(tcp_pseudo_hdr_t)); */\r
- memcpy(tcp_pseudo_hdr->sa, my_ip, IP_ADDR_LEN);\r
- memcpy(tcp_pseudo_hdr->da, tcb.remote_addr, IP_ADDR_LEN);\r
- tcp_pseudo_hdr->zero = 0;\r
- tcp_pseudo_hdr->proto = TCP_PROTO;\r
- plen = buflen + sizeof(tcp_hdr_t);\r
- tcp_pseudo_hdr->plen[0] = plen >> 8;\r
- tcp_pseudo_hdr->plen[1] = (unsigned char)plen;\r
- fix_checksum((unsigned char *)tcp_pseudo_hdr, \r
- (unsigned short int)(plen + sizeof(tcp_pseudo_hdr_t)), (unsigned short int)28);\r
-\r
- memset(ip_hdr, 0, sizeof(ip_hdr_t));\r
-\r
- ip_hdr->ver_hlen = 0x45; /* IPv4 with 20 byte header */\r
- plen += sizeof(ip_hdr_t); /* add the size of the IP Header */\r
- ip_hdr->tlen[0] = plen >> 8;\r
- ip_hdr->tlen[1] = (unsigned char) plen;\r
- ip_hdr->id[0] = ip_id >> 8;\r
- ip_hdr->id[1] = (unsigned char) ip_id;\r
- ip_id++;\r
- ip_hdr->ttl = 32; /* max 32 hops */\r
- ip_hdr->proto = TCP_PROTO;\r
- memcpy(ip_hdr->sa, my_ip, IP_ADDR_LEN);\r
- memcpy(ip_hdr->da, tcb.remote_addr, IP_ADDR_LEN);\r
- fix_checksum((unsigned char *)ip_hdr, sizeof(ip_hdr_t), 10);\r
- /* Fix the Ethernet Header */\r
- eth_hdr->type_code[0] = ETH_TYPE_0;\r
- eth_hdr->type_code[1] = ETH_TYPE_IP_1;\r
- memcpy(eth_hdr->sa, my_mac, ETH_ADDR_LEN);\r
- memcpy(eth_hdr->da, tcb.remote_mac, ETH_ADDR_LEN); /* should be table lookup */\r
- num_pkt_tx++; \r
- MSS_MAC_tx_packet(tcp_packet,plen + sizeof(ether_hdr_t), MSS_MAC_BLOCKING);\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char tcp_init(void)\r
-{\r
- memset(&tcb,0,sizeof(tcp_control_block_t));\r
- tcb.state = TCP_STATE_LISTEN;\r
- ip_id = 0;\r
- ip_known = 0;\r
- return OK;\r
-}\r
-\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char hex_digits_to_byte(unsigned char u, unsigned char l) \r
-{\r
- if (u > '9')\r
- u = u - 'A' + 10;\r
- else\r
- u = u - '0';\r
- if (l > '9')\r
- l = l - 'A' + 10;\r
- else\r
- l = l - '0';\r
- return (u << 4) + l;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_icmp_packet(unsigned char *buf)\r
-{\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (buf + sizeof (ether_hdr_t));\r
- icmp_hdr_xp icmp_hdr = (icmp_hdr_xp ) \r
- (buf + sizeof (ether_hdr_t) + sizeof(ip_hdr_t));\r
- unsigned short int elen = ((unsigned short int)ip_hdr->tlen[0] << 8) + (unsigned short int)ip_hdr->tlen[1] - sizeof(ip_hdr_t);\r
- if (check_checksum((unsigned char *)icmp_hdr, (unsigned short int) elen, (unsigned short int) 2, 'M') != OK) \r
- return ERR;\r
- if (icmp_hdr->type != ICMP_TYPE_ECHO_REQUEST) {\r
- return ERR;\r
- }\r
- return send_icmp_echo_reply(buf);\r
-}\r
-\r
- /* See tcpip.h for more information.\r
- */\r
-\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_tcp_packet(unsigned char *buf)\r
-{\r
- eth_hdr_xp eth_hdr = (eth_hdr_xp )buf;\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (buf + sizeof (ether_hdr_t));\r
- tcp_hdr_xp tcp_hdr = (tcp_hdr_xp ) \r
- (buf + sizeof (ether_hdr_t) + sizeof(ip_hdr_t));\r
- unsigned short int elen = ((unsigned short int)ip_hdr->tlen[0] << 8) + (unsigned short int)ip_hdr->tlen[1] - sizeof(ip_hdr_t);\r
- unsigned char state;\r
- if ( !memcmp(tcb.remote_addr, ip_hdr->sa, IP_ADDR_LEN) && /* same source IP */\r
- !memcmp(tcb.remote_port, tcp_hdr->sp, TCP_PORT_LEN) && /* same source port */\r
- !memcmp(tcb.local_port, tcp_hdr->dp, TCP_PORT_LEN)) { /* same dest port */\r
- state = tcb.state;\r
- } else { /* copy it over, a new IP wants in */\r
- memcpy(tcb.remote_addr, ip_hdr->sa, IP_ADDR_LEN);\r
- memcpy(tcb.remote_port, tcp_hdr->sp, TCP_PORT_LEN);\r
- memcpy(tcb.local_port, tcp_hdr->dp, TCP_PORT_LEN);\r
- memcpy(tcb.remote_mac, eth_hdr->sa, ETH_ADDR_LEN);\r
- state = TCP_STATE_LISTEN;\r
- } \r
- switch (state) {\r
- case TCP_STATE_LISTEN:\r
- if (tcp_hdr->urg_ack_psh_rst_syn_fin & TCP_CNTRL_SYN) {\r
- /* recd SYN : new connection; send SYN+ACK */ \r
- \r
- tcb.local_seq = TCP_START_SEQ;\r
- tcb.remote_seq = 0;\r
- tcb.remote_seq = (tcb.remote_seq | tcp_hdr->seqnum[0]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[1]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[2]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[3]); \r
- tcb.remote_seq++;\r
- send_tcp_packet( TCP_CNTRL_SYN | TCP_CNTRL_ACK, 0);\r
- tcb.state = TCP_STATE_SYN_RECVD;\r
- } \r
- break; \r
- case TCP_STATE_SYN_RECVD: \r
- if (tcp_hdr->urg_ack_psh_rst_syn_fin & TCP_CNTRL_ACK) { \r
- /* recd ack; send nothing */\r
- tcb.state = TCP_STATE_ESTABLISHED;\r
- } \r
- else { \r
- tcb.state = TCP_STATE_LISTEN;\r
- } \r
- break;\r
- case TCP_STATE_ESTABLISHED: \r
- if (tcp_hdr->urg_ack_psh_rst_syn_fin & TCP_CNTRL_FIN) {\r
- /* recd fin; send ack */\r
- /* skip CLOSE_WAIT state; send fin along with ack */\r
- tcb.remote_seq = 0;\r
- tcb.remote_seq = (tcb.remote_seq | tcp_hdr->seqnum[0]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[1]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[2]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[3]); \r
- tcb.remote_seq++;\r
- send_tcp_packet(TCP_CNTRL_ACK | TCP_CNTRL_FIN, 0);\r
- tcb.state = TCP_STATE_LAST_ACK; \r
- /* Default scroll message on OLED */\r
- }\r
- else if (tcp_hdr->dp[0] != 0 || \\r
- tcp_hdr->dp[1] != 80) { /* HTTP Port */\r
- break;\r
- }\r
- else if (elen > sizeof(tcp_hdr_t)) { /* dont respond to empty packets*/\r
- tcb.remote_seq = 0;\r
- tcb.remote_seq = (tcb.remote_seq | tcp_hdr->seqnum[0]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[1]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[2]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[3]); \r
- tcb.remote_seq += (unsigned long) (elen - sizeof(tcp_hdr_t));\r
- //send_http_response(((unsigned char *)(tcp_hdr)) + sizeof (tcp_hdr_t));\r
- tcb.state = TCP_STATE_MY_LAST; \r
- } \r
- break;\r
- case TCP_STATE_MY_LAST: \r
- if (tcp_hdr->urg_ack_psh_rst_syn_fin & TCP_CNTRL_FIN) {\r
- /* sent fin, got fin, ack the fin */\r
- tcb.remote_seq = 0;\r
- tcb.remote_seq = (tcb.remote_seq | tcp_hdr->seqnum[0]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[1]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[2]);\r
- tcb.remote_seq = ((tcb.remote_seq << 8) |tcp_hdr->seqnum[3]); \r
- tcb.remote_seq++;\r
- send_tcp_packet(TCP_CNTRL_ACK, 0);\r
- tcb.state = TCP_STATE_CLOSED;\r
- }\r
- break;\r
- case TCP_STATE_LAST_ACK:\r
- \r
- if (tcp_hdr->urg_ack_psh_rst_syn_fin & TCP_CNTRL_ACK) {\r
- /* recd ack; send nothing */\r
- tcb.state = TCP_STATE_CLOSED;\r
- }\r
- /* no break here... go on to CLOSED directly */\r
- case TCP_STATE_CLOSED: \r
- memset (&tcb, 0, sizeof (tcp_control_block_t));\r
- break; \r
- default:\r
- break;\r
- }\r
- return 0;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_ip_packet(unsigned char *buf)\r
-{\r
- ip_hdr_xp ip_hdr = (ip_hdr_xp ) (buf + sizeof (ether_hdr_t));\r
- /* Is the incoming pkt for me?\r
- (either explicity addressed to me or a broadcast address) */\r
- if (memcmp(my_ip, ip_hdr->da, IP_ADDR_LEN)) /* not my IP */ {\r
- if (ip_known) {\r
- return ERR;\r
- }\r
- if (ip_hdr->da[0] != 0xFF || ip_hdr->da[1] != 0xFF ||\r
- ip_hdr->da[2] != 0xFF || ip_hdr->da[3] != 0xFF) {\r
- return ERR;\r
- }\r
- }\r
- if (check_checksum((unsigned char *)ip_hdr, (unsigned short int) 20, (unsigned short int) 10, 'I') != OK)\r
- return ERR;\r
- switch (ip_hdr->proto) \r
- {\r
- case TCP_PROTO:\r
- return process_tcp_packet(buf);\r
- case ICMP_PROTO:\r
- return process_icmp_packet(buf);\r
- case UDP_PROTO:\r
- return process_udp_packet(buf);\r
- default: {\r
- return ERR;\r
- }\r
- }\r
- return ERR;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_arp_packet(unsigned char *buf)\r
-{\r
- arp_pkt_xp arp_pkt = (arp_pkt_xp )(buf + sizeof(ether_hdr_t));\r
- if (arp_pkt->opcode[1] != ARP_OPCODE_REQ_1) { \r
- if (arp_pkt->opcode[1] == ARP_OPCODE_REPLY_1)\r
- { \r
- if (!memcmp(my_ip, arp_pkt->ip_sa, IP_ADDR_LEN))\r
- { \r
- //printf("IP conflict with MAC");\r
- //printf("%02x:%02x:%02x:%02x:%02x:%02x",arp_pkt->mac_sa[0],arp_pkt->mac_sa[1],arp_pkt->mac_sa[2],arp_pkt->mac_sa[3],arp_pkt->mac_sa[4],arp_pkt->mac_sa[5]);\r
- } \r
- }\r
- return ERR;\r
- } \r
- if (memcmp(my_ip, arp_pkt->ip_ta, IP_ADDR_LEN)) {\r
- return ERR;\r
- } \r
- return send_arp_reply(buf);\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char process_packet( unsigned char * buf )\r
-{\r
- eth_hdr_xp eth_hdr;\r
- unsigned char typ;\r
- eth_hdr = (eth_hdr_xp ) buf;\r
- typ = eth_hdr->type_code[0];\r
- if (typ != ETH_TYPE_0)\r
- {\r
- return ERR;\r
- }\r
- typ = eth_hdr->type_code[1];\r
- if (typ == ETH_TYPE_ARP_1) \r
- {\r
- return process_arp_packet(buf);\r
- }\r
- else if (typ == ETH_TYPE_IP_1) {\r
- return process_ip_packet(buf);\r
- } \r
- else\r
- {\r
- return ERR;\r
- }\r
- return ERR;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-unsigned char *xstrcpy(unsigned char *d, const unsigned char *s)\r
-{\r
- unsigned char c;\r
-\r
- while ((c = *s++)) \r
- (*d++ = c) ;\r
- return d;\r
-}\r
-/***************************************************************************//**\r
- * See tcpip.h for more information.\r
- */\r
-// updated html page with fusion board link on page:\r
-\r
+++ /dev/null
-/*******************************************************************************\r
- * (c) Copyright 2009 SLS Corporation,All Rights Reserved. \r
- * \r
- * tcpip.h:header file of TCP/IP implementation.\r
- * \r
- * Version Author Comment\r
- * 1.0.0 SLS corp. First release,16 Jan 2009\r
- */\r
-#ifndef TCPIP_H_\r
-#define TCPIP_H_\r
-\r
-#define FLASH_CONTEXT_INDICATOR 0x20000000\r
-#define FLASH_SELFWAKEUP_INDICATOR 0x20000001\r
-#define FLASH_CONTEXT_LOCATION 0x20000002\r
-\r
-/***************************************************************************//**\r
- * Replies to ARP requests.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * \r
- */\r
-unsigned char send_arp_reply(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Sends gratuitous arp brodcast message to the LAN.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * \r
- */\r
-void send_gratuitous_arp(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Calculates the checksum for Ethernet data in the header.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @param len Number of bytes.\r
- * @param pos position for the check sum. \r
- * \r
- * @return value of the checksum\r
- */\r
-unsigned short int get_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos);\r
-/***************************************************************************//**\r
- * Calls internally to get_checksum and fixes the value of the checksum to\r
- * position.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @param len Number of bytes.\r
- * @param pos position for the check sum.\r
- * \r
- * @return OK\r
- */\r
-unsigned char fix_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos);\r
-/***************************************************************************//**\r
- * Checks the calculated checksum for the errors.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @param len Number of bytes.\r
- * @param pos position for the check sum.\r
- * \r
- * @return OK If there is no error\r
- * ERR If there is error in the data \r
- */\r
-unsigned char check_checksum(unsigned char *buf, unsigned short int len, unsigned short int pos, char type);\r
-/***************************************************************************//**\r
- * Sends the reply to ICMP request like PING.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- */\r
-unsigned char send_icmp_echo_reply(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Converts the input integer to the ascii char and fills in the buffer. \r
- * \r
- * @param buf To filled in by the ascii value.\r
- * @param n integer number\r
- */\r
-void dtoa_reverse(unsigned short int n, unsigned char *buf);\r
-/***************************************************************************//**\r
- * Sends DHCP request to the server available in LAN.\r
- * \r
- * @param buf Pointer to the recieved data in case of DHCP reply.Zero for request. \r
- */\r
-void send_bootp_packet (unsigned char *buf);\r
-/***************************************************************************//**\r
- * Processes the UDP datagram.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- */\r
-unsigned char process_udp_packet (unsigned char *buf);\r
-/***************************************************************************//**\r
- * Sends TCP packet to the network.\r
- * \r
- * @param buf Pointer to the transmitt buffer to Ethernet MAC.\r
- */\r
-void send_tcp_packet (unsigned char control_bits,unsigned short int buflen);\r
-/***************************************************************************//**\r
- * Initialize TCP for the software TCP/IP stack.\r
- * \r
- * @return OK\r
- */\r
-unsigned char tcp_init(void);\r
-/***************************************************************************//**\r
- * Converts two hex decimal ascii digits into a sigle integer digit.\r
- * \r
- * @param u ascii hex digit \r
- * l ascii hex digit\r
- * @returm converted integer byte\r
- * \r
- */\r
-unsigned char hex_digits_to_byte(unsigned char u, unsigned char l);\r
-/***************************************************************************//**\r
- * Processes ICMP packets\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * \r
- * @return ERR if there is an error in the data\r
- * or calls further necessary functions.\r
- */\r
-unsigned char process_icmp_packet(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Sends logo of ACTEL on the network over HTTP protocol.\r
- * @return OK\r
- */\r
-unsigned char http_send_logo ();\r
-/***************************************************************************//**\r
- * Sends appropriate answer to the different HTTP requests.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @return OK\r
- */\r
-unsigned char send_http_response(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Process incoming TCP requests and handles the TCP state machine.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @return OK\r
- */\r
-unsigned char process_tcp_packet(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Process incoming IP datagrams and handles the TCP state machine.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @return OK\r
- */\r
-unsigned char process_ip_packet(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Processes the ARP packets. \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @return OK \r
- */\r
-unsigned char process_arp_packet(unsigned char *buf);\r
-/***************************************************************************//**\r
- * Processes incoming packets and identifies its type.\r
- * \r
- * @param buf Pointer to the recieved buffer from Ethernet MAC.\r
- * @return call the function for further process\r
- * ERR if any error\r
- */\r
-unsigned char process_packet( unsigned char * buf );\r
-/***************************************************************************//**\r
- * copies source string to destination address.\r
- * \r
- * @param d Pointer to the destination\r
- * @param s Pointer to the source\r
- * @return The last location after copy\r
- * \r
- */\r
-unsigned char *xstrcpy(unsigned char *d, const unsigned char *s);\r
-/***************************************************************************//**\r
- * Sends the home page of the demonstration webserver.\r
- * \r
- */\r
-void http_send_packet();\r
-/***************************************************************************//**\r
- * Sends the packet for waveform mode.\r
- * \r
- */\r
-void http_send_packet_waveform();\r
-/***************************************************************************//**\r
- * Sends the packet for multimeter mode.\r
- * \r
- */\r
-void http_send_packet_multimeter();\r
-/***************************************************************************//**\r
- * Sends the packet for DAC mode.\r
- * \r
- */\r
-void http_send_packet_DAC();\r
-/***************************************************************************//**\r
- * Sends the packet for sleeping stopwatch.\r
- * \r
- */\r
-void http_send_packet_SLEEPING_STOPWATCH();\r
-/***************************************************************************//**\r
- * Sends the packet for text terminal.\r
- * \r
- */\r
-void http_send_packet_textterminal();\r
-/***************************************************************************//**\r
- * Sends the packet for VIT auxiliary mode.\r
- * \r
- */\r
-void http_send_packet_VIT();\r
-/***************************************************************************//**\r
- * Sends the packet for Real Time Data Display.\r
- * \r
- */\r
-void http_send_packet_RTDD();\r
-/***************************************************************************//**\r
- * Sends the packet for Stock Ticker.\r
- * \r
- */\r
-void http_send_packet_Stockticker();\r
-/***************************************************************************//**\r
- * Sends the packet for Gadgets mode.\r
- * \r
- */\r
-void http_send_packet_weatherblog();\r
-/***************************************************************************//**\r
- * Sends the packet for Selfwakeup.\r
- * \r
- */\r
-void http_send_packet_SELFWAKEUP();\r
-/***************************************************************************//**\r
- * Same as above mentioned functions but following functions are applicable\r
- * to Internet Explorer.\r
- * \r
- */\r
-void http_send_packet_IE();\r
-void http_send_packet_SELFWAKEUP_IE();\r
-void http_send_packet_VIT_IE();\r
-void http_send_packet_waveform_IE();\r
-void http_send_packet_SLEEPING_STOPWATCH_IE();\r
-void http_send_packet_DAC_IE();\r
-void http_send_packet_multimeter_IE();\r
-void http_send_packet_RTDD_IE();\r
-#endif /*TCPIP_H_*/\r