2 * FreeRTOS+UDP V1.0.4
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 #ifndef FREERTOS_IP_PRIVATE_H
\r
30 #define FREERTOS_IP_PRIVATE_H
\r
32 /* Application level configuration options. */
\r
33 #include "FreeRTOSIPConfig.h"
\r
34 #include "IPTraceMacroDefaults.h"
\r
36 typedef struct xNetworkAddressingParameters
\r
38 uint32_t ulDefaultIPAddress;
\r
40 uint32_t ulGatewayAddress;
\r
41 uint32_t ulDNSServerAddress;
\r
42 } xNetworkAddressingParameters_t;
\r
45 /*-----------------------------------------------------------*/
\r
46 /* Protocol headers. */
\r
47 /*-----------------------------------------------------------*/
\r
49 #include "pack_struct_start.h"
\r
52 xMACAddress_t xDestinationAddress;
\r
53 xMACAddress_t xSourceAddress;
\r
54 uint16_t usFrameType;
\r
56 #include "pack_struct_end.h"
\r
57 typedef struct xETH_HEADER xEthernetHeader_t;
\r
59 #include "pack_struct_start.h"
\r
62 uint16_t usHardwareType;
\r
63 uint16_t usProtocolType;
\r
64 uint8_t ucHardwareAddressLength;
\r
65 uint8_t ucProtocolAddressLength;
\r
66 uint16_t usOperation;
\r
67 xMACAddress_t xSenderHardwareAddress;
\r
68 uint32_t ulSenderProtocolAddress;
\r
69 xMACAddress_t xTargetHardwareAddress;
\r
70 uint32_t ulTargetProtocolAddress;
\r
72 #include "pack_struct_end.h"
\r
73 typedef struct xARP_HEADER xARPHeader_t;
\r
75 #include "pack_struct_start.h"
\r
78 uint8_t ucVersionHeaderLength;
\r
79 uint8_t ucDifferentiatedServicesCode;
\r
81 uint16_t usIdentification;
\r
82 uint16_t usFragmentOffset;
\r
83 uint8_t ucTimeToLive;
\r
85 uint16_t usHeaderChecksum;
\r
86 uint32_t ulSourceIPAddress;
\r
87 uint32_t ulDestinationIPAddress;
\r
89 #include "pack_struct_end.h"
\r
90 typedef struct xIP_HEADER xIPHeader_t;
\r
91 #define ipSIZE_OF_IP_HEADER 20
\r
93 #include "pack_struct_start.h"
\r
96 uint8_t ucTypeOfMessage;
\r
97 uint8_t ucTypeOfService;
\r
98 uint16_t usChecksum;
\r
99 uint16_t usIdentifier;
\r
100 uint16_t usSequenceNumber;
\r
102 #include "pack_struct_end.h"
\r
103 typedef struct xICMP_HEADER xICMPHeader_t;
\r
105 #include "pack_struct_start.h"
\r
108 uint16_t usSourcePort;
\r
109 uint16_t usDestinationPort;
\r
111 uint16_t usChecksum;
\r
113 #include "pack_struct_end.h"
\r
114 typedef struct xUDP_HEADER xUDPHeader_t;
\r
115 #define ipSIZE_OF_UDP_HEADER 8
\r
117 #include "pack_struct_start.h"
\r
118 struct xPSEUDO_HEADER
\r
120 uint32_t ulSourceAddress;
\r
121 uint32_t ulDestinationAddress;
\r
123 uint8_t ucProtocol;
\r
124 uint16_t usUDPLength;
\r
126 #include "pack_struct_end.h"
\r
127 typedef struct xPSEUDO_HEADER xPseudoHeader_t;
\r
129 /*-----------------------------------------------------------*/
\r
130 /* Nested protocol packets. */
\r
131 /*-----------------------------------------------------------*/
\r
133 #include "pack_struct_start.h"
\r
136 xEthernetHeader_t xEthernetHeader;
\r
137 xARPHeader_t xARPHeader;
\r
139 #include "pack_struct_end.h"
\r
140 typedef struct xARP_PACKET xARPPacket_t;
\r
142 #include "pack_struct_start.h"
\r
145 xEthernetHeader_t xEthernetHeader;
\r
146 xIPHeader_t xIPHeader;
\r
148 #include "pack_struct_end.h"
\r
149 typedef struct xIP_PACKET xIPPacket_t;
\r
151 #include "pack_struct_start.h"
\r
152 struct xICMP_PACKET
\r
154 xEthernetHeader_t xEthernetHeader;
\r
155 xIPHeader_t xIPHeader;
\r
156 xICMPHeader_t xICMPHeader;
\r
158 #include "pack_struct_end.h"
\r
159 typedef struct xICMP_PACKET xICMPPacket_t;
\r
161 #include "pack_struct_start.h"
\r
164 xEthernetHeader_t xEthernetHeader;
\r
165 xIPHeader_t xIPHeader;
\r
166 xUDPHeader_t xUDPHeader;
\r
168 #include "pack_struct_end.h"
\r
169 typedef struct xUDP_PACKET xUDPPacket_t;
\r
171 /* Dimensions the buffers that are filled by received Ethernet frames. */
\r
172 #define ipETHERNET_CRC_BYTES ( 4UL )
\r
173 #define ipETHERNET_OPTIONAL_802_1Q_TAG_BYTES ( 4UL )
\r
174 #define ipTOTAL_ETHERNET_FRAME_SIZE ( ipconfigNETWORK_MTU + sizeof( xEthernetHeader_t ) + ipETHERNET_CRC_BYTES + ipETHERNET_OPTIONAL_802_1Q_TAG_BYTES )
\r
176 /* The maximum UDP payload length. */
\r
177 #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IP_HEADER ) - ipSIZE_OF_UDP_HEADER )
\r
181 eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
\r
182 eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
\r
183 eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
\r
184 eFrameConsumed /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
\r
185 } eFrameProcessingResult_t;
\r
189 eNetworkDownEvent = 0, /* The network interface has been lost and/or needs [re]connecting. */
\r
190 eEthernetRxEvent, /* The network interface has queued a received Ethernet frame. */
\r
191 eARPTimerEvent, /* The ARP timer expired. */
\r
192 eStackTxEvent, /* The software stack has queued a packet to transmit. */
\r
193 eDHCPEvent /* Process the DHCP state machine. */
\r
196 typedef struct IP_TASK_COMMANDS
\r
198 eIPEvent_t eEventType;
\r
202 #define ipBROADCAST_IP_ADDRESS 0xffffffffUL
\r
204 /* Offset into the Ethernet frame that is used to temporarily store information
\r
205 on the fragmentation status of the packet being sent. The value is important,
\r
206 as it is past the location into which the destination address will get placed. */
\r
207 #define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
\r
208 #define ipSOCKET_OPTIONS_OFFSET ( 6 )
\r
210 /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
\r
212 #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET : ipIP_PAYLOAD_OFFSET )
\r
214 /* The offset into a UDP packet at which the UDP data (payload) starts. */
\r
215 #define ipUDP_PAYLOAD_OFFSET ( sizeof( xUDPPacket_t ) )
\r
217 /* The offset into an IP packet into which the IP data (payload) starts. */
\r
218 #define ipIP_PAYLOAD_OFFSET ( sizeof( xIPPacket_t ) )
\r
220 /* Space left at the beginning of a network buffer storage area to store a
\r
221 pointer back to the network buffer. Should be a multiple of 8 to ensure
\r
222 8 byte alignment is maintained on architectures that require it. */
\r
223 #define ipBUFFER_PADDING ( 8 )
\r
225 #include "pack_struct_start.h"
\r
226 struct xUDP_IP_FRACMENT_PARAMETERS
\r
228 uint8_t ucSocketOptions;
\r
229 uint8_t ucPadFor16BitAlignment;
\r
230 uint16_t usFragmentedPacketOffset;
\r
231 uint16_t usFragmentLength;
\r
232 uint16_t usPayloadChecksum;
\r
234 #include "pack_struct_end.h"
\r
235 typedef struct xUDP_IP_FRACMENT_PARAMETERS xIPFragmentParameters_t;
\r
237 #if( ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN )
\r
239 /* Ethernet frame types. */
\r
240 #define ipARP_TYPE ( 0x0608U )
\r
241 #define ipIP_TYPE ( 0x0008U )
\r
243 /* ARP related definitions. */
\r
244 #define ipARP_PROTOCOL_TYPE ( 0x0008U )
\r
245 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
\r
246 #define ipARP_REQUEST ( 0x0100 )
\r
247 #define ipARP_REPLY ( 0x0200 )
\r
251 /* Ethernet frame types. */
\r
252 #define ipARP_TYPE ( 0x0806U )
\r
253 #define ipIP_TYPE ( 0x0800U )
\r
255 /* ARP related definitions. */
\r
256 #define ipARP_PROTOCOL_TYPE ( 0x0800U )
\r
257 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
\r
258 #define ipARP_REQUEST ( 0x0001 )
\r
259 #define ipARP_REPLY ( 0x0002 )
\r
261 #endif /* ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN */
\r
263 /* The structure used to store buffers and pass them around the network stack.
\r
264 Buffers can be in use by the stack, in use by the network interface hardware
\r
265 driver, or free (not in use). */
\r
266 typedef struct xNETWORK_BUFFER
\r
268 xListItem xBufferListItem; /* Used to reference the buffer form the free buffer list or a socket. */
\r
269 uint32_t ulIPAddress; /* Source or destination IP address, depending on usage scenario. */
\r
270 uint8_t *pucEthernetBuffer; /* Pointer to the start of the Ethernet frame. */
\r
271 size_t xDataLength; /* Starts by holding the total Ethernet frame length, then the UDP payload length. */
\r
272 uint16_t usPort; /* Source or destination port, depending on usage scenario. */
\r
273 uint16_t usBoundPort; /* The port to which a transmitting socket is bound. */
\r
274 } xNetworkBufferDescriptor_t;
\r
276 void vNetworkBufferRelease( xNetworkBufferDescriptor_t * const pxNetworkBuffer );
\r
279 * A version of FreeRTOS_GetReleaseNetworkBuffer() that can be called from an
\r
280 * interrupt. If a non zero value is returned, then the calling ISR should
\r
281 * perform a context switch before exiting the ISR.
\r
283 BaseType_t FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );
\r
286 * Create a message that contains a command to initialise the network interface.
\r
287 * This is used during initialisation, and at any time the network interface
\r
288 * goes down thereafter. The network interface hardware driver is responsible
\r
289 * for sending the message that contains the network interface down command/
\r
292 * Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
\r
293 * called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
\r
294 * returns a non-zero value then a context switch should be performed ebfore
\r
295 * the interrupt is exited.
\r
297 void FreeRTOS_NetworkDown( void );
\r
298 BaseType_t FreeRTOS_NetworkDownFromISR( void );
\r
301 * Inspect an Ethernet frame to see if it contains data that the stack needs to
\r
302 * process. eProcessBuffer is returned if the frame should be processed by the
\r
303 * stack. eReleaseBuffer is returned if the frame should be discarded.
\r
305 eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
\r
307 #if( ipconfigINCLUDE_TEST_CODE == 1 )
\r
308 UBaseType_t uxGetNumberOfFreeNetworkBuffers( void );
\r
309 #endif /* ipconfigINCLUDE_TEST_CODE */
\r
311 /* Socket related private functions. */
\r
312 BaseType_t xProcessReceivedUDPPacket( xNetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );
\r
313 void FreeRTOS_SocketsInit( void );
\r
315 /* If FreeRTOS+NABTO is included then include the prototype of the function that
\r
316 creates the Nabto task. */
\r
317 #if( ipconfigFREERTOS_PLUS_NABTO == 1 )
\r
318 void vStartNabtoTask( void );
\r
322 #endif /* FREERTOS_IP_PRIVATE_H */
\r