BOOTLOADER
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
ethernetudp.c
Go to the documentation of this file.
1 /******************************************************
2 * Function: etherent udp protocol handler
3 *
4 * File: etherentudp.c
5 * Author: Book Chen
6 * Date: 2008.07.18
7 *******************************************************
8 */
9 #include "includes.h"
10 
11 #if(DEBUG_ETHERNET_UDP==1)
12  #define ETHERNET_UDP_INFO 1
13 #else
14  #define ETHERNET_UDP_INFO 0
15 #endif
16 
17 #define EthernetUdpIdleState 0
18 
20 
21 void F_EthernetUdpInit(void){
22  UdpCtrl.InUse=FALSE;
23  UdpCtrl.Id=ID_ETHERNET_UDP;
25 }
27  UDP_HEAD *pUdpHead;
28 
29 
30  #if(DEBUG_ETHERNET_UDP==1)
31  printf("\n UDP receive");
32  #endif
33  pUdpHead=(UDP_HEAD *)(pBuffer->pData);
34  pBuffer->Length=F_EthernetUnsignedShortN2H(pUdpHead->Length);
35  F_EthernetBufferPull(pBuffer,sizeof(UDP_HEAD)); // point to pBuffer.Data[0+EHTHERNET_HEAD+IP_HEAD+UDP_HEAD]
36  if(F_EthernetUnsignedShortN2H(pUdpHead->Destination)==TFTP) // 0x0045=69
38  //else if(F_EthernetUnsignedShortN2H(pUdpHead->Destination)==SNMP){
39  //
40  //}
41  return TRUE;
42 }
44  INT8U *pIpAddress,
45  INT16U SourcePort,
46  INT16U DestinationPort){
47  UDP_HEAD *pUdpHead;
48 
49  #if(DEBUG_ETHERNET_UDP==1)
50  printf("\n UDP send ");
51  #endif
52  pUdpHead=(UDP_HEAD *)F_EthernetBufferPush(pBuffer,sizeof(UDP_HEAD));
53  pUdpHead->Source=F_EthernetUnsignedShortH2N(SourcePort);
54  pUdpHead->Destination=F_EthernetUnsignedShortH2N(DestinationPort);
55  pUdpHead->Length=F_EthernetUnsignedShortH2N(12); // 12 byte packet length??
56  pUdpHead->Check=0;
57  F_EthernetIpSend(pBuffer,pIpAddress,UDP);
58  return TRUE;
59 }
61  F_EthernetBufferReserve(pBuffer,sizeof(ETHERNET_HEAD));
62  F_EthernetBufferReserve(pBuffer,sizeof(IP_HEAD));
63  F_EthernetBufferReserve(pBuffer,sizeof(UDP_HEAD));
64  return TRUE;
65 }
67  UDP_HEAD *pUdpHead;
68 
69  pUdpHead=(UDP_HEAD *)((INT8U *)pBuffer->Data+ETHERNET_HEAD_LENGTH+IP_HEAD_LENGTH);
70  #if(ETHERNET_UDP_INFO==1)
71  printf("\n pUdpHead->Source %4x",pUdpHead->Source);
72  printf("\n pUdpHead->Destination %4x",pUdpHead->Destination);
73  printf("\n pUdpHead->Length %4x",pUdpHead->Length);
74  printf("\n pUdpHead->Check %4x",pUdpHead->Check);
75  #endif
76  return F_EthernetUnsignedShortN2H(pUdpHead->Source);
77 }
78