3 Copyright (C) Dean Camera, 2014.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * User Datagram Protocol (UDP) packet handling routines. This protocol handles high throughput, low
34 * reliability packets which are typically used to encapsulate streaming data.
37 #define INCLUDE_FROM_UDP_C
40 /** Processes a UDP packet inside an Ethernet frame, and writes the appropriate response
41 * to the output Ethernet frame if a sub-protocol handler has created a response packet.
43 * \param[in] IPHeaderInStart Pointer to the start of the incoming packet's IP header
44 * \param[in] UDPHeaderInStart Pointer to the start of the incoming packet's UDP header
45 * \param[out] UDPHeaderOutStart Pointer to the start of the outgoing packet's UDP header
47 * \return The number of bytes written to the out Ethernet frame if any, NO_RESPONSE otherwise
49 int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart,
50 void* UDPHeaderInStart,
51 void* UDPHeaderOutStart)
53 UDP_Header_t* UDPHeaderIN = (UDP_Header_t*)UDPHeaderInStart;
54 UDP_Header_t* UDPHeaderOUT = (UDP_Header_t*)UDPHeaderOutStart;
56 int16_t RetSize = NO_RESPONSE;
58 DecodeUDPHeader(UDPHeaderInStart);
60 switch (SwapEndian_16(UDPHeaderIN->DestinationPort))
62 case UDP_PORT_DHCP_REQUEST:
63 RetSize = DHCP_ProcessDHCPPacket(IPHeaderInStart,
64 &((uint8_t*)UDPHeaderInStart)[sizeof(UDP_Header_t)],
65 &((uint8_t*)UDPHeaderOutStart)[sizeof(UDP_Header_t)]);
69 /* Check to see if the protocol processing routine has filled out a response */
72 /* Fill out the response UDP packet header */
73 UDPHeaderOUT->SourcePort = UDPHeaderIN->DestinationPort;
74 UDPHeaderOUT->DestinationPort = UDPHeaderIN->SourcePort;
75 UDPHeaderOUT->Checksum = 0;
76 UDPHeaderOUT->Length = SwapEndian_16(sizeof(UDP_Header_t) + RetSize);
78 /* Return the size of the response so far */
79 return (sizeof(UDP_Header_t) + RetSize);