Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

netstack.c

Go to the documentation of this file.
00001 /*! \file netstack.c \brief Network Stack. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'netstack.c'
00005 // Title        : Network Stack
00006 // Author       : Pascal Stang
00007 // Created      : 6/28/2005
00008 // Revised      : 7/3/2005
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR series
00011 // Editor Tabs  : 4
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     // look for a packet
00028     len = nicPoll(NET_BUFFERSIZE, NetBuffer);
00029 
00030     if(len)
00031     {
00032         ethPacket = (struct netEthHeader*)&NetBuffer[0];
00033 
00034         //rprintf("Received packet #%d, len: %d, type:", i++, len);
00035         //rprintfu16(htons(ethPacket->type));
00036         //rprintfCRLF();
00037         //rprintf("Packet Contents\r\n");
00038         //debugPrintHexTable(len, NetBuffer);
00039         
00040         if(ethPacket->type == htons(ETHTYPE_IP))
00041         {
00042             // process an IP packet
00043             //rprintfProgStrM("IP packet\r\n");
00044             // add the source to the ARP cache
00045             // also correctly set the ethernet packet length before processing?
00046             arpIpIn((struct netEthIpHeader*)&NetBuffer[0]);
00047             //arpPrintTable();
00048             
00049             netstackIPProcess( len-ETH_HEADER_LEN, (ip_hdr*)&NetBuffer[ETH_HEADER_LEN] );
00050         }
00051         else if(ethPacket->type == htons(ETHTYPE_ARP))
00052         {
00053             // process an ARP packet
00054             #ifdef NETSTACK_DEBUG
00055             rprintfProgStrM("NET Rx: ARP packet\r\n");
00056             //arpPrintHeader( ((struct netArpHeader*)&NetBuffer[ETH_HEADER_LEN]) );
00057             #endif
00058             arpArpIn(len, ((struct netEthArpHeader*)&NetBuffer[0]) );
00059         }
00060     }
00061 }
00062 
00063 void netstackIPProcess(unsigned int len, ip_hdr* packet)
00064 {
00065     // check IP addressing, stop processing if not for me and not a broadcast
00066     if( (htonl(packet->destipaddr) != ipGetMyAddress()) &&
00067         (htonl(packet->destipaddr) != (ipGetMyAddress()|0x000000FF)) )
00068         return;
00069 
00070     // handle ICMP packet
00071     if( packet->proto == IP_PROTO_ICMP )
00072     {
00073         #ifdef NETSTACK_DEBUG
00074         rprintfProgStrM("NET Rx: ICMP/IP packet\r\n");
00075         //icmpPrintHeader((icmpip_hdr*)packet);
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         //debugPrintHexTable(NetBufferLen-14, &NetBuffer[14]);
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 }

Generated on Mon Aug 22 04:29:27 2005 for Procyon AVRlib by  doxygen 1.4.2