2 * FreeRTOS+UDP V1.0.0 (C) 2013 Real Time Engineers ltd.
\r
4 * This file is part of the FreeRTOS+UDP distribution. The FreeRTOS+UDP license
\r
5 * terms are different to the FreeRTOS license terms.
\r
7 * FreeRTOS+UDP uses a dual license model that allows the software to be used
\r
8 * under a pure GPL open source license (as opposed to the modified GPL license
\r
9 * under which FreeRTOS is distributed) or a commercial license. Details of
\r
10 * both license options follow:
\r
12 * - Open source licensing -
\r
13 * FreeRTOS+UDP is a free download and may be used, modified, evaluated and
\r
14 * distributed without charge provided the user adheres to version two of the
\r
15 * GNU General Public License (GPL) and does not remove the copyright notice or
\r
16 * this text. The GPL V2 text is available on the gnu.org web site, and on the
\r
17 * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
\r
19 * - Commercial licensing -
\r
20 * Businesses and individuals that for commercial or other reasons cannot comply
\r
21 * with the terms of the GPL V2 license must obtain a commercial license before
\r
22 * incorporating FreeRTOS+UDP into proprietary software for distribution in any
\r
23 * form. Commercial licenses can be purchased from http://shop.freertos.org/udp
\r
24 * and do not require any source files to be changed.
\r
26 * FreeRTOS+UDP is distributed in the hope that it will be useful. You cannot
\r
27 * use FreeRTOS+UDP unless you agree that you use the software 'as is'.
\r
28 * FreeRTOS+UDP is provided WITHOUT ANY WARRANTY; without even the implied
\r
29 * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
30 * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
\r
31 * implied, expressed, or statutory.
\r
33 * 1 tab == 4 spaces!
\r
35 * http://www.FreeRTOS.org
\r
36 * http://www.FreeRTOS.org/udp
\r
40 #ifndef FREERTOS_IP_PRIVATE_H
\r
41 #define FREERTOS_IP_PRIVATE_H
\r
43 /* Application level configuration options. */
\r
44 #include "FreeRTOSIPConfig.h"
\r
45 #include "IPTraceMacroDefaults.h"
\r
47 typedef struct xNetworkAddressingParameters
\r
49 uint32_t ulDefaultIPAddress;
\r
51 uint32_t ulGatewayAddress;
\r
52 uint32_t ulDNSServerAddress;
\r
53 } xNetworkAddressingParameters_t;
\r
56 /*-----------------------------------------------------------*/
\r
57 /* Protocol headers. */
\r
58 /*-----------------------------------------------------------*/
\r
60 #include "pack_struct_start.h"
\r
63 xMACAddress_t xDestinationAddress;
\r
64 xMACAddress_t xSourceAddress;
\r
65 uint16_t usFrameType;
\r
67 #include "pack_struct_end.h"
\r
68 typedef struct xETH_HEADER xEthernetHeader_t;
\r
70 #include "pack_struct_start.h"
\r
73 uint16_t usHardwareType;
\r
74 uint16_t usProtocolType;
\r
75 uint8_t ucHardwareAddressLength;
\r
76 uint8_t ucProtocolAddressLength;
\r
77 uint16_t usOperation;
\r
78 xMACAddress_t xSenderHardwareAddress;
\r
79 uint32_t ulSenderProtocolAddress;
\r
80 xMACAddress_t xTargetHardwareAddress;
\r
81 uint32_t ulTargetProtocolAddress;
\r
83 #include "pack_struct_end.h"
\r
84 typedef struct xARP_HEADER xARPHeader_t;
\r
86 #include "pack_struct_start.h"
\r
89 uint8_t ucVersionHeaderLength;
\r
90 uint8_t ucDifferentiatedServicesCode;
\r
92 uint16_t usIdentification;
\r
93 uint16_t usFragmentOffset;
\r
94 uint8_t ucTimeToLive;
\r
96 uint16_t usHeaderChecksum;
\r
97 uint32_t ulSourceIPAddress;
\r
98 uint32_t ulDestinationIPAddress;
\r
100 #include "pack_struct_end.h"
\r
101 typedef struct xIP_HEADER xIPHeader_t;
\r
102 #define ipSIZE_OF_IP_HEADER 20
\r
104 #include "pack_struct_start.h"
\r
105 struct xICMP_HEADER
\r
107 uint8_t ucTypeOfMessage;
\r
108 uint8_t ucTypeOfService;
\r
109 uint16_t usChecksum;
\r
110 uint16_t usIdentifier;
\r
111 uint16_t usSequenceNumber;
\r
113 #include "pack_struct_end.h"
\r
114 typedef struct xICMP_HEADER xICMPHeader_t;
\r
116 #include "pack_struct_start.h"
\r
119 uint16_t usSourcePort;
\r
120 uint16_t usDestinationPort;
\r
122 uint16_t usChecksum;
\r
124 #include "pack_struct_end.h"
\r
125 typedef struct xUDP_HEADER xUDPHeader_t;
\r
126 #define ipSIZE_OF_UDP_HEADER 8
\r
128 #include "pack_struct_start.h"
\r
129 struct xPSEUDO_HEADER
\r
131 uint32_t ulSourceAddress;
\r
132 uint32_t ulDestinationAddress;
\r
134 uint8_t ucProtocol;
\r
135 uint16_t usUDPLength;
\r
137 #include "pack_struct_end.h"
\r
138 typedef struct xPSEUDO_HEADER xPseudoHeader_t;
\r
140 /*-----------------------------------------------------------*/
\r
141 /* Nested protocol packets. */
\r
142 /*-----------------------------------------------------------*/
\r
144 #include "pack_struct_start.h"
\r
147 xEthernetHeader_t xEthernetHeader;
\r
148 xARPHeader_t xARPHeader;
\r
150 #include "pack_struct_end.h"
\r
151 typedef struct xARP_PACKET xARPPacket_t;
\r
153 #include "pack_struct_start.h"
\r
156 xEthernetHeader_t xEthernetHeader;
\r
157 xIPHeader_t xIPHeader;
\r
159 #include "pack_struct_end.h"
\r
160 typedef struct xIP_PACKET xIPPacket_t;
\r
162 #include "pack_struct_start.h"
\r
163 struct xICMP_PACKET
\r
165 xEthernetHeader_t xEthernetHeader;
\r
166 xIPHeader_t xIPHeader;
\r
167 xICMPHeader_t xICMPHeader;
\r
169 #include "pack_struct_end.h"
\r
170 typedef struct xICMP_PACKET xICMPPacket_t;
\r
172 #include "pack_struct_start.h"
\r
175 xEthernetHeader_t xEthernetHeader;
\r
176 xIPHeader_t xIPHeader;
\r
177 xUDPHeader_t xUDPHeader;
\r
179 #include "pack_struct_end.h"
\r
180 typedef struct xUDP_PACKET xUDPPacket_t;
\r
182 /* Dimensions the buffers that are filled by received Ethernet frames. */
\r
183 #define ipETHERNET_CRC_BYTES ( 4UL )
\r
184 #define ipETHERNET_OPTIONAL_802_1Q_TAG_BYTES ( 4UL )
\r
185 #define ipTOTAL_ETHERNET_FRAME_SIZE ( ipconfigNETWORK_MTU + sizeof( xEthernetHeader_t ) + ipETHERNET_CRC_BYTES + ipETHERNET_OPTIONAL_802_1Q_TAG_BYTES )
\r
187 /* The maximum UDP payload length. */
\r
188 #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IP_HEADER ) - ipSIZE_OF_UDP_HEADER )
\r
192 eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
\r
193 eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
\r
194 eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
\r
195 eFrameConsumed /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
\r
196 } eFrameProcessingResult_t;
\r
200 eNetworkDownEvent = 0, /* The network interface has been lost and/or needs [re]connecting. */
\r
201 eEthernetRxEvent, /* The network interface has queued a received Ethernet frame. */
\r
202 eARPTimerEvent, /* The ARP timer expired. */
\r
203 eStackTxEvent, /* The software stack has queued a packet to transmit. */
\r
204 eDHCPEvent /* Process the DHCP state machine. */
\r
207 typedef struct IP_TASK_COMMANDS
\r
209 eIPEvent_t eEventType;
\r
213 #define ipBROADCAST_IP_ADDRESS 0xffffffffUL
\r
215 /* Offset into the Ethernet frame that is used to temporarily store information
\r
216 on the fragmentation status of the packet being sent. The value is important,
\r
217 as it is past the location into which the destination address will get placed. */
\r
218 #define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
\r
219 #define ipSOCKET_OPTIONS_OFFSET ( 6 )
\r
221 /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
\r
223 #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET : ipIP_PAYLOAD_OFFSET )
\r
225 /* The offset into a UDP packet at which the UDP data (payload) starts. */
\r
226 #define ipUDP_PAYLOAD_OFFSET ( sizeof( xUDPPacket_t ) )
\r
228 /* The offset into an IP packet into which the IP data (payload) starts. */
\r
229 #define ipIP_PAYLOAD_OFFSET ( sizeof( xIPPacket_t ) )
\r
231 /* Space left at the beginning of a network buffer storage area to store a
\r
232 pointer back to the network buffer. Should be a multiple of 8 to ensure
\r
233 8 byte alignment is maintained on architectures that require it. */
\r
234 #define ipBUFFER_PADDING ( 8 )
\r
236 #include "pack_struct_start.h"
\r
237 struct xUDP_IP_FRACMENT_PARAMETERS
\r
239 uint8_t ucSocketOptions;
\r
240 uint8_t ucPadFor16BitAlignment;
\r
241 uint16_t usFragmentedPacketOffset;
\r
242 uint16_t usFragmentLength;
\r
243 uint16_t usPayloadChecksum;
\r
245 #include "pack_struct_end.h"
\r
246 typedef struct xUDP_IP_FRACMENT_PARAMETERS xIPFragmentParameters_t;
\r
248 #if( ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN )
\r
250 /* Ethernet frame types. */
\r
251 #define ipARP_TYPE ( 0x0608U )
\r
252 #define ipIP_TYPE ( 0x0008U )
\r
254 /* ARP related definitions. */
\r
255 #define ipARP_PROTOCOL_TYPE ( 0x0008U )
\r
256 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
\r
257 #define ipARP_REQUEST ( 0x0100 )
\r
258 #define ipARP_REPLY ( 0x0200 )
\r
262 /* Ethernet frame types. */
\r
263 #define ipARP_TYPE ( 0x0806U )
\r
264 #define ipIP_TYPE ( 0x0800U )
\r
266 /* ARP related definitions. */
\r
267 #define ipARP_PROTOCOL_TYPE ( 0x0800U )
\r
268 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
\r
269 #define ipARP_REQUEST ( 0x0001 )
\r
270 #define ipARP_REPLY ( 0x0002 )
\r
272 #endif /* ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN */
\r
274 /* The structure used to store buffers and pass them around the network stack.
\r
275 Buffers can be in use by the stack, in use by the network interface hardware
\r
276 driver, or free (not in use). */
\r
277 typedef struct xNETWORK_BUFFER
\r
279 xListItem xBufferListItem; /* Used to reference the buffer form the free buffer list or a socket. */
\r
280 uint32_t ulIPAddress; /* Source or destination IP address, depending on usage scenario. */
\r
281 uint8_t *pucEthernetBuffer; /* Pointer to the start of the Ethernet frame. */
\r
282 size_t xDataLength; /* Starts by holding the total Ethernet frame length, then the UDP payload length. */
\r
283 uint16_t usPort; /* Source or destination port, depending on usage scenario. */
\r
284 uint16_t usBoundPort; /* The port to which a transmitting socket is bound. */
\r
285 } xNetworkBufferDescriptor_t;
\r
287 void vNetworkBufferRelease( xNetworkBufferDescriptor_t * const pxNetworkBuffer );
\r
290 * A version of FreeRTOS_GetReleaseNetworkBuffer() that can be called from an
\r
291 * interrupt. If a non zero value is returned, then the calling ISR should
\r
292 * perform a context switch before exiting the ISR.
\r
294 portBASE_TYPE FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );
\r
297 * Create a message that contains a command to initialise the network interface.
\r
298 * This is used during initialisation, and at any time the network interface
\r
299 * goes down thereafter. The network interface hardware driver is responsible
\r
300 * for sending the message that contains the network interface down command/
\r
303 * Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
\r
304 * called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
\r
305 * returns a non-zero value then a context switch should be performed ebfore
\r
306 * the interrupt is exited.
\r
308 void FreeRTOS_NetworkDown( void );
\r
309 portBASE_TYPE FreeRTOS_NetworkDownFromISR( void );
\r
312 * Inspect an Ethernet frame to see if it contains data that the stack needs to
\r
313 * process. eProcessBuffer is returned if the frame should be processed by the
\r
314 * stack. eReleaseBuffer is returned if the frame should be discarded.
\r
316 eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
\r
318 #if( ipconfigINCLUDE_TEST_CODE == 1 )
\r
319 unsigned portBASE_TYPE uxGetNumberOfFreeNetworkBuffers( void );
\r
320 #endif /* ipconfigINCLUDE_TEST_CODE */
\r
322 /* Socket related private functions. */
\r
323 portBASE_TYPE xProcessReceivedUDPPacket( xNetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );
\r
324 void FreeRTOS_SocketsInit( void );
\r
326 /* If FreeRTOS+NABTO is included then include the prototype of the function that
\r
327 creates the Nabto task. */
\r
328 #if( ipconfigFREERTOS_PLUS_NABTO == 1 )
\r
329 void vStartNabtoTask( void );
\r
333 #endif /* FREERTOS_IP_PRIVATE_H */
\r