BOOTLOADER
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
etherneticmp.c
Go to the documentation of this file.
1 /******************************************************
2 * Function: etherent icmp protocol handler
3 *
4 * File: etherenticmp.c
5 * Author: Book Chen
6 * Date: 2008.07.18
7 *******************************************************
8 */
9 #include "includes.h"
10 
11 #define EthernetIcmpIdleState 0
12 
14 void F_EthernetIcmpInit(void);
18 
19 void F_EthernetIcmpInit(void){
20  IcmpCtrl.ClientIp[0]=0;
21  IcmpCtrl.ClientIp[1]=0;
22  IcmpCtrl.ClientIp[2]=0;
23  IcmpCtrl.ClientIp[3]=0;
24  IcmpCtrl.Status=0;
25  IcmpCtrl.State=EthernetIcmpIdleState;
26 }
28  ICMP_HEAD *pIcmpHead,*pIcmpEcho;
29  INT32U Temp,Sum,Counter,i;
30 
31  Counter=pBuffer->Length; // keep icmp packet data length in Counter
32  if(Counter%2) Counter++; // ?? Counter must be a even number
33  #if(DEBUG_ETHERNET_ICMP==1)
34  printf(" echo length %4x",Counter);
35  #endif
36  pIcmpHead=(ICMP_HEAD *)pBuffer->pData;
37  pBuffer=F_EthernetBufferAllocate();
38  F_EthernetIpBufferReserve(pBuffer); // reserve IP_HEAD space
39  pIcmpEcho=(ICMP_HEAD *)F_EthernetBufferPut(pBuffer,Counter);
40  pIcmpEcho->Type=0;
41  pIcmpEcho->Code=0;
42  Sum=0;
43  for(i=2;i<(Counter/2);i++){
44  Temp=*((INT16U *)(&pIcmpHead->Type)+i);
45  *((INT16U *)(&pIcmpEcho->Type)+i)=Temp;
46  Sum+=Temp;
47  }
48  i=Sum>>16;
49  pIcmpEcho->Check=0x0000ffff-(Sum&0x0000ffff)-i;
50  #if(DEBUG_ETHERNET_ICMP==1)
51  printf(" length2 %4x",pBuffer->Length);
52  #endif
53  F_EthernetIpSend(pBuffer,IcmpCtrl.ClientIp,ICMP);
54  return TRUE;
55 }
58  F_EthernetIcmpEchoSend(pBuffer);
59  return TRUE;
60 }
62  ICMP_HEAD *pIcmpHead=(ICMP_HEAD *)pBuffer->pData;
63 
64  #if(DEBUG_ETHERNET_ICMP==1)
65  printf("\n ICMP rx");
66  #endif
67  switch(pIcmpHead->Type){
68  case 8:
69  F_EthernetIcmpEchoReceive(pBuffer);
70  }
71  return TRUE;
72 }
73