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