00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "rprintf.h"
00016 #include "debug.h"
00017
00018 #include "netstack.h"
00019
00020 unsigned char NetBuffer[NET_BUFFERSIZE];
00021
00022 void netstackService(void)
00023 {
00024 int len;
00025 struct netEthHeader* ethPacket;
00026
00027
00028 len = nicPoll(NET_BUFFERSIZE, NetBuffer);
00029
00030 if(len)
00031 {
00032 ethPacket = (struct netEthHeader*)&NetBuffer[0];
00033
00034
00035
00036
00037
00038
00039
00040 if(ethPacket->type == htons(ETHTYPE_IP))
00041 {
00042
00043
00044
00045
00046 arpIpIn((struct netEthIpHeader*)&NetBuffer[0]);
00047
00048
00049 netstackIPProcess( len-ETH_HEADER_LEN, (ip_hdr*)&NetBuffer[ETH_HEADER_LEN] );
00050 }
00051 else if(ethPacket->type == htons(ETHTYPE_ARP))
00052 {
00053
00054 #ifdef NETSTACK_DEBUG
00055 rprintfProgStrM("NET Rx: ARP packet\r\n");
00056
00057 #endif
00058 arpArpIn(len, ((struct netEthArpHeader*)&NetBuffer[0]) );
00059 }
00060 }
00061 }
00062
00063 void netstackIPProcess(unsigned int len, ip_hdr* packet)
00064 {
00065
00066 if( (htonl(packet->destipaddr) != ipGetMyAddress()) &&
00067 (htonl(packet->destipaddr) != (ipGetMyAddress()|0x000000FF)) )
00068 return;
00069
00070
00071 if( packet->proto == IP_PROTO_ICMP )
00072 {
00073 #ifdef NETSTACK_DEBUG
00074 rprintfProgStrM("NET Rx: ICMP/IP packet\r\n");
00075
00076 #endif
00077 icmpIpIn((icmpip_hdr*)packet);
00078 }
00079 else if( packet->proto == IP_PROTO_UDP )
00080 {
00081 #ifdef NETSTACK_DEBUG
00082 rprintfProgStrM("NET Rx: UDP/IP packet\r\n");
00083
00084 #endif
00085 netstackUDPIPProcess(len, ((udpip_hdr*)packet) );
00086 }
00087 else if( packet->proto == IP_PROTO_TCP )
00088 {
00089 #ifdef NETSTACK_DEBUG
00090 rprintfProgStrM("NET Rx: TCP/IP packet\r\n");
00091 #endif
00092 netstackTCPIPProcess(len, ((tcpip_hdr*)packet) );
00093 }
00094 else
00095 {
00096 #ifdef NETSTACK_DEBUG
00097 rprintfProgStrM("NET Rx: IP packet\r\n");
00098 #endif
00099 }
00100 }
00101
00102 void netstackUDPIPProcess(unsigned int len, udpip_hdr* packet)
00103 {
00104 #ifdef NETSTACK_DEBUG
00105 rprintf("NetStack UDP/IP Rx Dummy Handler\r\n");
00106 #endif
00107 }
00108
00109 void netstackTCPIPProcess(unsigned int len, tcpip_hdr* packet)
00110 {
00111 #ifdef NETSTACK_DEBUG
00112 rprintf("NetStack TCP/IP Rx Dummy Handler\r\n");
00113 #endif
00114 }