00001 00002 00003 00025 /********************************************************************* 00026 * Software License Agreement 00027 * 00028 * Copyright (C) 2002-2008 Microchip Technology Inc. All rights 00029 * reserved. 00030 * 00031 * Microchip licenses to you the right to use, modify, copy, and 00032 * distribute: 00033 * (i) the Software when embedded on a Microchip microcontroller or 00034 * digital signal controller product ("Device") which is 00035 * integrated into Licensee's product; or 00036 * (ii) ONLY the Software driver source files ENC28J60.c and 00037 * ENC28J60.h ported to a non-Microchip device used in 00038 * conjunction with a Microchip ethernet controller for the 00039 * sole purpose of interfacing with the ethernet controller. 00040 * 00041 * You should refer to the license agreement accompanying this 00042 * Software for additional information regarding your rights and 00043 * obligations. 00044 * 00045 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 00046 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 00047 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 00048 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 00049 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 00050 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 00051 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 00052 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 00053 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 00054 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 00055 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. 00056 * 00057 * 00058 * Author Date Comment 00059 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00060 * Nilesh Rajbharti 8/14/01 Original (Rev. 1.0) 00061 * Nilesh Rajbharti 2/9/02 Cleanup 00062 * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail) 00063 * Nilesh Rajbharti 12/5/02 Modified UDPProcess() and TCPProcess() 00064 * to include localIP as third param. 00065 * This was done to allow these functions 00066 * to calculate checksum correctly. 00067 * Nilesh Rajbharti 7/26/04 Added code in StackTask() to not 00068 * clear statically IP address if link is 00069 * removed and DHCP module is disabled 00070 * at runtime. 00071 * Howard Schlunder 03/16/07 Rewrote stack manager to be linear 00072 ********************************************************************/ 00073 #define __STACKTSK_C 00074 00075 #include "TCPIP.h" 00076 #include "Reboot.h" // MODIFIX: added this include. 00077 00078 // MODIFIX: Removed external symbol "myDHCPBindCount" 00079 00080 // Stack FSM states. 00081 typedef enum _SM_STACK 00082 { 00083 SM_STACK_IDLE, 00084 SM_STACK_MAC, 00085 SM_STACK_IP, 00086 SM_STACK_ARP, 00087 SM_STACK_TCP, 00088 SM_STACK_UDP 00089 } SM_STACK; 00090 static SM_STACK smStack; 00091 00092 NODE_INFO remoteNode; 00093 00094 00095 00096 /********************************************************************* 00097 * Function: void StackInit(void) 00098 * 00099 * PreCondition: None 00100 * 00101 * Input: None 00102 * 00103 * Output: Stack and its componets are initialized 00104 * 00105 * Side Effects: None 00106 * 00107 * Note: This function must be called before any of the 00108 * stack or its component routines are used. 00109 * 00110 ********************************************************************/ 00111 void StackInit(void) 00112 { 00113 smStack = SM_STACK_IDLE; 00114 00115 // MODIFIX: Removed IP gleaning functionality. 00116 00117 // Seed the rand() function 00118 srand(GenerateRandomDWORD()); 00119 00120 // MACInit(); 00121 00122 ARPInit(); 00123 00124 UDPInit(); 00125 00126 TCPInit(); 00127 00128 // MODIFIX: Removed Berkeley handling. 00129 00130 // Initialize the HTTP module for the eWicht Webpage. 00131 HTTPInit(); 00132 00133 // MODIFIX: Removed DHCP handling because its handled completely from 00134 // the eWicht application. 00135 00136 // MODIFIX: Removed all other parts not used by the eWicht application. 00137 } 00138 00139 00140 /********************************************************************* 00141 * Function: void StackTask(void) 00142 * 00143 * PreCondition: StackInit() is already called. 00144 * 00145 * Input: None 00146 * 00147 * Output: Stack FSM is executed. 00148 * 00149 * Side Effects: None 00150 * 00151 * Note: This FSM checks for new incoming packets, 00152 * and routes it to appropriate stack components. 00153 * It also performs timed operations. 00154 * 00155 * This function must be called periodically to 00156 * ensure timely responses. 00157 * 00158 ********************************************************************/ 00159 void StackTask(void) 00160 { 00161 WORD dataCount; 00162 IP_ADDR tempLocalIP; 00163 BYTE cFrameType; 00164 BYTE cIPFrameType; 00165 00166 // MODIFIX: Modified DHCP handling because its handled from the eWicht 00167 // application. 00168 if(sPCommonConfig.Flags.bIsDHCPEnabled) 00169 { 00170 // DHCP must be called all the time even after IP configuration is 00171 // discovered. 00172 // DHCP has to account lease expiration time and renew the configuration 00173 // time. 00174 DHCPTask(); 00175 } 00176 00177 00178 // Perform all TCP time related tasks (retransmit, send acknowledge, close connection, etc) 00179 TCPTick(); 00180 00181 UDPTask(); 00182 00183 // Process as many incomming packets as we can 00184 while(1) 00185 { 00186 // MODIFIX: Removed the STACK_USE_RANDOM functionality. 00187 00188 // We are about to fetch a new packet, make sure that the 00189 // UDP module knows that any old RX data it has laying 00190 // around will now be gone. 00191 UDPDiscard(); 00192 00193 // Fetch a packet (throws old one away, if not thrown away 00194 // yet) 00195 if(!MACGetHeader(&remoteNode.MACAddr, &cFrameType)) 00196 break; 00197 00198 // Dispatch the packet to the appropriate handler 00199 switch(cFrameType) 00200 { 00201 case MAC_ARP: 00202 ARPProcess(); 00203 break; 00204 00205 case MAC_IP: 00206 if(!IPGetHeader(&tempLocalIP, &remoteNode, &cIPFrameType, &dataCount)) 00207 break; 00208 00209 if(cIPFrameType == IP_PROT_ICMP) 00210 { 00211 // MODIFIX: Removed IP gleaning functionality. 00212 00213 // Process this ICMP packet if it the destination IP address matches our address or one of the broadcast IP addressees 00214 // MODIFIX: Use the eWicht structure sIPConfig (4 times) 00215 if( (tempLocalIP.Val == sIPConfig.MyIPAddr.Val) || 00216 (tempLocalIP.Val == 0xFFFFFFFF) || 00217 (tempLocalIP.Val == ((sIPConfig.MyIPAddr.Val & sIPConfig.MyMask.Val) | ~sIPConfig.MyMask.Val))) 00218 { 00219 ICMPProcess(&remoteNode, dataCount); 00220 } 00221 break; 00222 } 00223 00224 if(cIPFrameType == IP_PROT_TCP) 00225 { 00226 TCPProcess(&remoteNode, &tempLocalIP, dataCount); 00227 break; 00228 } 00229 00230 if(cIPFrameType == IP_PROT_UDP) 00231 { 00232 // Stop processing packets if we came upon a UDP frame with application data in it 00233 if (UDPProcess(&remoteNode, &tempLocalIP, dataCount)) 00234 return; 00235 } 00236 00237 break; 00238 } 00239 } 00240 } 00241 00242 /********************************************************************* 00243 * Function: void StackApplications(void) 00244 * 00245 * PreCondition: StackInit() is already called. 00246 * 00247 * Input: None 00248 * 00249 * Output: Calls all loaded application modules. 00250 * 00251 * Side Effects: None 00252 * 00253 * Note: This function must be called periodically to 00254 * ensure timely responses. 00255 * 00256 ********************************************************************/ 00257 void StackApplications(void) 00258 { 00259 HTTPServer(); 00260 00261 RebootTask(); 00262 00263 // MODIFIX: Removed unneeded parts. 00264 }
1.5.5