Go to the source code of this file.
Functions | |
void | F_EthernetIpInit (void) |
INT8U | F_EthernetIpInUseCheck (void) |
INT8U | F_EthernetIpAllocate (INT16U UserId) |
INT8U | F_EthernetIpRelease (INT16U UserId) |
INT8U | F_EthernetIpPacketReceive (ETHBUFFER *pBuffer) |
INT8U | F_EthernetIpSend (ETHBUFFER *pBuffer, INT8U *pIpAddress, INT8U Protocol) |
void | F_EthernetIpBufferReserve (ETHBUFFER *pBuffer) |
INT8U * | F_EthernetIpSourceIpGet (ETHBUFFER *pBuffer) |
INT16U | F_EthernetIpFastCheckSum (INT8U *pIph, INT32U Ihl) |
void | F_EthernetIpSvc (void) |
INT8U | F_EthernetIpIpAddressSet (INT16U UserId, INT8U *pIpAddress) |
Variables | |
IP_CONTROL | IpCtrl |
INT8U F_EthernetIpAllocate | ( | INT16U | UserId | ) |
Definition at line 38 of file ethernetip.c.
00038 { 00039 if(IpCtrl.InUse==FALSE){ 00040 IpCtrl.InUse=TRUE; 00041 IpCtrl.UserId=UserId; 00042 return TRUE; 00043 } 00044 else return FALSE; 00045 }
void F_EthernetIpBufferReserve | ( | ETHBUFFER * | pBuffer | ) |
Definition at line 173 of file ethernetip.c.
00173 { 00174 F_EthernetBufferReserve(pBuffer,sizeof(ETHERNET_HEAD)); 00175 F_EthernetBufferReserve(pBuffer,sizeof(IP_HEAD)); 00176 }
INT16U F_EthernetIpFastCheckSum | ( | INT8U * | pIph, | |
INT32U | Ihl | |||
) |
Definition at line 63 of file ethernetip.c.
00063 { 00064 INT32U Sum; 00065 //INT32U Tmp; 00066 Sum=0; 00067 // ip_fast_csum 00068 /*__asm { 00069 ldr Sum,[pIph],#4 00070 ldr Tmp,[pIph],#4 00071 sub Ihl,Ihl,#5 00072 adds Sum,Sum,Tmp 00073 ldr Tmp,[pIph],#4 00074 adcs Sum,Sum,Tmp 00075 ldr Tmp, [pIph], #4 00076 adcs Sum, Sum, Tmp 00077 l: ldr Tmp, [pIph], #4 00078 adcs Sum, Sum, Tmp 00079 tst Ihl, #15 00080 subne Ihl, Ihl, #1 00081 bne l 00082 adc Sum,Sum,#0 00083 adds Sum,Sum,Sum, lsl #16 00084 addcs Sum,Sum,#0x10000 00085 mvn Sum,Sum 00086 mov Sum,Sum,lsr #16 00087 }; 00088 */ 00089 return Sum; 00090 }
void F_EthernetIpInit | ( | void | ) |
INT8U F_EthernetIpInUseCheck | ( | void | ) |
Definition at line 34 of file ethernetip.c.
00034 { 00035 if(IpCtrl.InUse==TRUE) return TRUE; 00036 else return FALSE; 00037 }
INT8U F_EthernetIpIpAddressSet | ( | INT16U | UserId, | |
INT8U * | pIpAddress | |||
) |
Definition at line 53 of file ethernetip.c.
00053 { 00054 if((IpCtrl.InUse==TRUE)&&(IpCtrl.UserId==UserId)){ 00055 IpCtrl.IpAddress[0]=pIpAddress[0]; 00056 IpCtrl.IpAddress[1]=pIpAddress[1]; 00057 IpCtrl.IpAddress[2]=pIpAddress[2]; 00058 IpCtrl.IpAddress[3]=pIpAddress[3]; 00059 return TRUE; 00060 } 00061 else return FALSE; 00062 }
INT8U F_EthernetIpPacketReceive | ( | ETHBUFFER * | pBuffer | ) |
Definition at line 91 of file ethernetip.c.
00091 { 00092 IP_HEAD *pIpHead=(IP_HEAD *)pBuffer->pData; 00093 00094 #if(DEBUG_ETHERNET_IP==1) 00095 printf("\n IP receive"); 00096 //printf("\n IP address %2x %2x %2x %2x ",pIpHead->DestiAddress[0], 00097 // pIpHead->DestiAddress[1], 00098 // pIpHead->DestiAddress[2], 00099 // pIpHead->DestiAddress[3]); 00100 #endif 00101 if((pIpHead->DestiAddress[0]==IpCtrl.IpAddress[0])&& 00102 (pIpHead->DestiAddress[1]==IpCtrl.IpAddress[1])&& 00103 (pIpHead->DestiAddress[2]==IpCtrl.IpAddress[2])&& 00104 (pIpHead->DestiAddress[3]==IpCtrl.IpAddress[3])){ 00105 pBuffer->Length=F_EthernetUnsignedShortN2H(pIpHead->TotalLength); 00106 #if(DEBUG_ETHERNET_IP==1) 00107 printf("\n data length %4x ",pBuffer->Length); 00108 #endif 00109 F_EthernetBufferPull(pBuffer,sizeof(IP_HEAD)); // point to pBuffer.Data[ETHERNET_HEAD+IP_HEAD] 00110 if(pIpHead->Protocol==UDP){ 00111 #if(DEBUG_ETHERNET_IP==1) 00112 printf(" UDP "); 00113 #endif 00114 F_EthernetUdpPacketReceive(pBuffer); 00115 } 00116 else if(pIpHead->Protocol==ICMP){ 00117 #if(DEBUG_ETHERNET_IP==1) 00118 printf(" ICMP "); 00119 #endif 00120 F_EthernetIcmpPacketReceive(pBuffer); 00121 } 00122 //else if(pIpHead->Protocol==TCP){ 00123 // #if(DEBUG_ETHERNET_IP==1) 00124 // printf("\n IP TCP "); 00125 // #endif 00126 // F_EthernetTcpPacketReceive(pBuffer); 00127 //} 00128 else{ 00129 #if(DEBUG_ETHERNET_IP==1) 00130 printf(" none "); 00131 #endif 00132 } 00133 00134 } 00135 else{ 00136 #if(DEBUG_ETHERNET_IP==1) 00137 printf("\n address no match "); 00138 #endif 00139 } 00140 return TRUE; 00141 }
INT8U F_EthernetIpRelease | ( | INT16U | UserId | ) |
Definition at line 46 of file ethernetip.c.
00046 { 00047 if((IpCtrl.InUse==TRUE)&&(IpCtrl.UserId==UserId)){ 00048 IpCtrl.InUse=FALSE; 00049 return TRUE; 00050 } 00051 else return FALSE; 00052 }
INT8U F_EthernetIpSend | ( | ETHBUFFER * | pBuffer, | |
INT8U * | pIpAddress, | |||
INT8U | Protocol | |||
) |
Definition at line 142 of file ethernetip.c.
00142 { 00143 IP_HEAD *pIpHead; 00144 INT16U Id=32; 00145 INT8U DestiAddress[ETHERNET_MAC_LENGTH]; 00146 00147 if(F_EthernetArpAddressGet(pIpAddress,DestiAddress)==FALSE) return FALSE; // ip is not in arp cache 00148 pIpHead=(IP_HEAD *)F_EthernetBufferPush(pBuffer,sizeof(IP_HEAD)); 00149 pIpHead->Ihl=5; 00150 pIpHead->Version=4; 00151 pIpHead->Tos=0; 00152 pIpHead->TotalLength=F_EthernetUnsignedShortH2N(pBuffer->Length); 00153 pIpHead->Id=F_EthernetUnsignedShortH2N(Id++); //?? 00154 pIpHead->FlagOff=0; 00155 pIpHead->Ttl=20; 00156 pIpHead->Protocol=Protocol; 00157 pIpHead->Checksum=0; 00158 pIpHead->SourceAddress[0]=IpCtrl.IpAddress[0]; 00159 pIpHead->SourceAddress[1]=IpCtrl.IpAddress[1]; 00160 pIpHead->SourceAddress[2]=IpCtrl.IpAddress[2]; 00161 pIpHead->SourceAddress[3]=IpCtrl.IpAddress[3]; 00162 pIpHead->DestiAddress[0]=pIpAddress[0]; 00163 pIpHead->DestiAddress[1]=pIpAddress[1]; 00164 pIpHead->DestiAddress[2]=pIpAddress[2]; 00165 pIpHead->DestiAddress[3]=pIpAddress[3]; 00166 pIpHead->Checksum=F_EthernetIpFastCheckSum((INT8U *)pIpHead,pIpHead->Ihl); 00167 #if(DEBUG_ETHERNET_IP==1) 00168 printf("\n LengthIp %4x",pBuffer->Length); 00169 #endif 00170 F_EthernetSend(pBuffer,DestiAddress,ETHERNET_P_IP); 00171 return TRUE; 00172 }
INT8U * F_EthernetIpSourceIpGet | ( | ETHBUFFER * | pBuffer | ) |
Definition at line 177 of file ethernetip.c.
00177 { 00178 IP_HEAD *pIpHead; 00179 00180 pIpHead=(IP_HEAD *)(pBuffer->Data+ETHERNET_HEAD_LENGTH); 00181 return pIpHead->SourceAddress; 00182 }
void F_EthernetIpSvc | ( | void | ) |
IP_CONTROL IpCtrl |
Definition at line 13 of file ethernetip.c.