]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOS_IP_Private.h
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-UDP / include / FreeRTOS_IP_Private.h
1 /*\r
2  * FreeRTOS+UDP V1.0.4\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
15  *\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
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 #ifndef FREERTOS_IP_PRIVATE_H\r
30 #define FREERTOS_IP_PRIVATE_H\r
31 \r
32 /* Application level configuration options. */\r
33 #include "FreeRTOSIPConfig.h"\r
34 #include "IPTraceMacroDefaults.h"\r
35 \r
36 typedef struct xNetworkAddressingParameters\r
37 {\r
38         uint32_t ulDefaultIPAddress;\r
39         uint32_t ulNetMask;\r
40         uint32_t ulGatewayAddress;\r
41         uint32_t ulDNSServerAddress;\r
42 } xNetworkAddressingParameters_t;\r
43 \r
44 \r
45 /*-----------------------------------------------------------*/\r
46 /* Protocol headers.                                         */\r
47 /*-----------------------------------------------------------*/\r
48 \r
49 #include "pack_struct_start.h"\r
50 struct xETH_HEADER\r
51 {\r
52         xMACAddress_t xDestinationAddress;\r
53         xMACAddress_t xSourceAddress;\r
54         uint16_t usFrameType;\r
55 }\r
56 #include "pack_struct_end.h"\r
57 typedef struct xETH_HEADER xEthernetHeader_t;\r
58 \r
59 #include "pack_struct_start.h"\r
60 struct xARP_HEADER\r
61 {\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
71 }\r
72 #include "pack_struct_end.h"\r
73 typedef struct xARP_HEADER xARPHeader_t;\r
74 \r
75 #include "pack_struct_start.h"\r
76 struct xIP_HEADER\r
77 {\r
78         uint8_t ucVersionHeaderLength;\r
79         uint8_t ucDifferentiatedServicesCode;\r
80         uint16_t usLength;\r
81         uint16_t usIdentification;\r
82         uint16_t usFragmentOffset;\r
83         uint8_t ucTimeToLive;\r
84         uint8_t ucProtocol;\r
85         uint16_t usHeaderChecksum;\r
86         uint32_t ulSourceIPAddress;\r
87         uint32_t ulDestinationIPAddress;\r
88 }\r
89 #include "pack_struct_end.h"\r
90 typedef struct xIP_HEADER xIPHeader_t;\r
91 #define ipSIZE_OF_IP_HEADER 20\r
92 \r
93 #include "pack_struct_start.h"\r
94 struct xICMP_HEADER\r
95 {\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
101 }\r
102 #include "pack_struct_end.h"\r
103 typedef struct xICMP_HEADER xICMPHeader_t;\r
104 \r
105 #include "pack_struct_start.h"\r
106 struct xUDP_HEADER\r
107 {\r
108         uint16_t usSourcePort;\r
109         uint16_t usDestinationPort;\r
110         uint16_t usLength;\r
111         uint16_t usChecksum;\r
112 }\r
113 #include "pack_struct_end.h"\r
114 typedef struct xUDP_HEADER xUDPHeader_t;\r
115 #define ipSIZE_OF_UDP_HEADER 8\r
116 \r
117 #include "pack_struct_start.h"\r
118 struct xPSEUDO_HEADER\r
119 {\r
120         uint32_t ulSourceAddress;\r
121         uint32_t ulDestinationAddress;\r
122         uint8_t ucZeros;\r
123         uint8_t ucProtocol;\r
124         uint16_t usUDPLength;\r
125 }\r
126 #include "pack_struct_end.h"\r
127 typedef struct xPSEUDO_HEADER xPseudoHeader_t;\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 /* Nested protocol packets.                                  */\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 #include "pack_struct_start.h"\r
134 struct xARP_PACKET\r
135 {\r
136         xEthernetHeader_t xEthernetHeader;\r
137         xARPHeader_t xARPHeader;\r
138 }\r
139 #include "pack_struct_end.h"\r
140 typedef struct xARP_PACKET xARPPacket_t;\r
141 \r
142 #include "pack_struct_start.h"\r
143 struct xIP_PACKET\r
144 {\r
145         xEthernetHeader_t xEthernetHeader;\r
146         xIPHeader_t xIPHeader;\r
147 }\r
148 #include "pack_struct_end.h"\r
149 typedef struct xIP_PACKET xIPPacket_t;\r
150 \r
151 #include "pack_struct_start.h"\r
152 struct xICMP_PACKET\r
153 {\r
154         xEthernetHeader_t xEthernetHeader;\r
155         xIPHeader_t xIPHeader;\r
156         xICMPHeader_t xICMPHeader;\r
157 }\r
158 #include "pack_struct_end.h"\r
159 typedef struct xICMP_PACKET xICMPPacket_t;\r
160 \r
161 #include "pack_struct_start.h"\r
162 struct xUDP_PACKET\r
163 {\r
164         xEthernetHeader_t xEthernetHeader;\r
165         xIPHeader_t xIPHeader;\r
166         xUDPHeader_t xUDPHeader;\r
167 }\r
168 #include "pack_struct_end.h"\r
169 typedef struct xUDP_PACKET xUDPPacket_t;\r
170 \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
175 \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
178 \r
179 typedef enum\r
180 {\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
186 \r
187 typedef enum\r
188 {\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
194 } eIPEvent_t;\r
195 \r
196 typedef struct IP_TASK_COMMANDS\r
197 {\r
198         eIPEvent_t eEventType;\r
199         void *pvData;\r
200 } xIPStackEvent_t;\r
201 \r
202 #define ipBROADCAST_IP_ADDRESS 0xffffffffUL\r
203 \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
209 \r
210 /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h\r
211 setting. */\r
212 #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET : ipIP_PAYLOAD_OFFSET )\r
213 \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
216 \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
219 \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
224 \r
225 #include "pack_struct_start.h"\r
226 struct xUDP_IP_FRACMENT_PARAMETERS\r
227 {\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
233 }\r
234 #include "pack_struct_end.h"\r
235 typedef struct xUDP_IP_FRACMENT_PARAMETERS xIPFragmentParameters_t;\r
236 \r
237 #if( ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN )\r
238 \r
239         /* Ethernet frame types. */\r
240         #define ipARP_TYPE      ( 0x0608U )\r
241         #define ipIP_TYPE       ( 0x0008U )\r
242 \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
248 \r
249 #else\r
250 \r
251         /* Ethernet frame types. */\r
252         #define ipARP_TYPE      ( 0x0806U )\r
253         #define ipIP_TYPE       ( 0x0800U )\r
254 \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
260 \r
261 #endif /* ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN */\r
262 \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
267 {\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
275 \r
276 void vNetworkBufferRelease( xNetworkBufferDescriptor_t * const pxNetworkBuffer );\r
277 \r
278 /*\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
282  */\r
283 BaseType_t FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );\r
284 \r
285 /*\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
290  * event.\r
291  *\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
296  */\r
297 void FreeRTOS_NetworkDown( void );\r
298 BaseType_t FreeRTOS_NetworkDownFromISR( void );\r
299 \r
300 /*\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
304  */\r
305 eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );\r
306 \r
307 #if( ipconfigINCLUDE_TEST_CODE == 1 )\r
308         UBaseType_t uxGetNumberOfFreeNetworkBuffers( void );\r
309 #endif /* ipconfigINCLUDE_TEST_CODE */\r
310 \r
311 /* Socket related private functions. */\r
312 BaseType_t xProcessReceivedUDPPacket( xNetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );\r
313 void FreeRTOS_SocketsInit( void );\r
314 \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
319 #endif\r
320 \r
321 \r
322 #endif /* FREERTOS_IP_PRIVATE_H */\r
323 \r
324 \r
325 \r
326 \r
327 \r
328 \r
329 \r
330 \r
331 \r
332 \r
333 \r
334 \r
335 \r