00001 // //////////////////////////////////////////////////////////////////////////// 00002 // //////////////////////////////////////////////////////////////////////////// 00026 /********************************************************************* 00027 * Software License Agreement 00028 * 00029 * Copyright (C) 2002-2008 Microchip Technology Inc. All rights 00030 * reserved. 00031 * 00032 * Microchip licenses to you the right to use, modify, copy, and 00033 * distribute: 00034 * (i) the Software when embedded on a Microchip microcontroller or 00035 * digital signal controller product ("Device") which is 00036 * integrated into Licensee's product; or 00037 * (ii) ONLY the Software driver source files ENC28J60.c and 00038 * ENC28J60.h ported to a non-Microchip device used in 00039 * conjunction with a Microchip ethernet controller for the 00040 * sole purpose of interfacing with the ethernet controller. 00041 * 00042 * You should refer to the license agreement accompanying this 00043 * Software for additional information regarding your rights and 00044 * obligations. 00045 * 00046 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 00047 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 00048 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 00049 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 00050 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 00051 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 00052 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 00053 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 00054 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 00055 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 00056 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. 00057 * 00058 * 00059 * Author Date Comment 00060 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00061 * Howard Schlunder 03/16/07 Original 00062 ********************************************************************/ 00063 #define __ICMP_C 00064 00065 #include "TCPIP.h" 00066 00067 /********************************************************************* 00068 * Function: void ICMPProcess(void) 00069 * 00070 * PreCondition: MAC buffer contains ICMP type packet. 00071 * 00072 * Input: *remote: Pointer to a NODE_INFO structure of the 00073 * ping requester 00074 * len: Count of how many bytes the ping header and 00075 * payload are in this IP packet 00076 * 00077 * Output: Generates an echo reply, if requested 00078 * Validates and sets ICMPFlags.bReplyValid if a 00079 * correct ping response to one of ours is received. 00080 * 00081 * Side Effects: None 00082 * 00083 * Overview: None 00084 * 00085 * Note: None 00086 ********************************************************************/ 00087 void ICMPProcess(NODE_INFO *remote, WORD len) 00088 { 00089 DWORD_VAL dwVal; 00090 00091 // Obtain the ICMP header Type, Code, and Checksum fields 00092 MACGetArray((BYTE*)&dwVal, sizeof(dwVal)); 00093 00094 // See if this is an ICMP echo (ping) request 00095 if(dwVal.w[0] == 0x0008u) 00096 { 00097 // Validate the checksum using the Microchip MAC's DMA module 00098 // The checksum data includes the precomputed checksum in the 00099 // header, so a valid packet will always have a checksum of 00100 // 0x0000 if the packet is not disturbed. 00101 if(MACCalcRxChecksum(0+sizeof(IP_HEADER), len)) 00102 return; 00103 00104 // Calculate new Type, Code, and Checksum values 00105 dwVal.v[0] = 0x00; // Type: 0 (ICMP echo/ping reply) 00106 dwVal.v[2] += 8; // Subtract 0x0800 from the checksum 00107 if(dwVal.v[2] < 8u) 00108 { 00109 dwVal.v[3]++; 00110 if(dwVal.v[3] == 0u) 00111 dwVal.v[2]++; 00112 } 00113 00114 // Position the write pointer for the next IPPutHeader operation 00115 MACSetWritePtr(BASE_TX_ADDR + sizeof(ETHER_HEADER)); 00116 00117 // Wait for TX hardware to become available (finish transmitting 00118 // any previous packet) 00119 while(!IPIsTxReady()); 00120 00121 // Create IP header in TX memory 00122 IPPutHeader(remote, IP_PROT_ICMP, len); 00123 00124 // Copy ICMP response into the TX memory 00125 MACPutArray((BYTE*)&dwVal, sizeof(dwVal)); 00126 MACMemCopyAsync(-1, -1, len-4); 00127 while(!MACIsMemCopyDone()); 00128 00129 // Transmit the echo reply packet 00130 MACFlush(); 00131 } 00132 }
1.5.5