]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOS_IP_Private.h
7f470043dc9a4fe7d6ff100e9be7eff9c83a5150
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-UDP / include / FreeRTOS_IP_Private.h
1 /*\r
2  * FreeRTOS+UDP V1.0.0 (C) 2013 Real Time Engineers ltd.\r
3  *\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
6  *\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
11  *\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
18  *\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
25  *\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
32  *\r
33  * 1 tab == 4 spaces!\r
34  *\r
35  * http://www.FreeRTOS.org\r
36  * http://www.FreeRTOS.org/udp\r
37  *\r
38  */\r
39 \r
40 #ifndef FREERTOS_IP_PRIVATE_H\r
41 #define FREERTOS_IP_PRIVATE_H\r
42 \r
43 /* Application level configuration options. */\r
44 #include "FreeRTOSIPConfig.h"\r
45 #include "IPTraceMacroDefaults.h"\r
46 \r
47 typedef struct xNetworkAddressingParameters\r
48 {\r
49         uint32_t ulDefaultIPAddress;\r
50         uint32_t ulNetMask;\r
51         uint32_t ulGatewayAddress;\r
52         uint32_t ulDNSServerAddress;\r
53 } xNetworkAddressingParameters_t;\r
54 \r
55 \r
56 /*-----------------------------------------------------------*/\r
57 /* Protocol headers.                                         */\r
58 /*-----------------------------------------------------------*/\r
59 \r
60 #include "pack_struct_start.h"\r
61 struct xETH_HEADER\r
62 {\r
63         xMACAddress_t xDestinationAddress;\r
64         xMACAddress_t xSourceAddress;\r
65         uint16_t usFrameType;\r
66 }\r
67 #include "pack_struct_end.h"\r
68 typedef struct xETH_HEADER xEthernetHeader_t;\r
69 \r
70 #include "pack_struct_start.h"\r
71 struct xARP_HEADER\r
72 {\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
82 }\r
83 #include "pack_struct_end.h"\r
84 typedef struct xARP_HEADER xARPHeader_t;\r
85 \r
86 #include "pack_struct_start.h"\r
87 struct xIP_HEADER\r
88 {\r
89         uint8_t ucVersionHeaderLength;\r
90         uint8_t ucDifferentiatedServicesCode;\r
91         uint16_t usLength;\r
92         uint16_t usIdentification;\r
93         uint16_t usFragmentOffset;\r
94         uint8_t ucTimeToLive;\r
95         uint8_t ucProtocol;\r
96         uint16_t usHeaderChecksum;\r
97         uint32_t ulSourceIPAddress;\r
98         uint32_t ulDestinationIPAddress;\r
99 }\r
100 #include "pack_struct_end.h"\r
101 typedef struct xIP_HEADER xIPHeader_t;\r
102 #define ipSIZE_OF_IP_HEADER 20\r
103 \r
104 #include "pack_struct_start.h"\r
105 struct xICMP_HEADER\r
106 {\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
112 }\r
113 #include "pack_struct_end.h"\r
114 typedef struct xICMP_HEADER xICMPHeader_t;\r
115 \r
116 #include "pack_struct_start.h"\r
117 struct xUDP_HEADER\r
118 {\r
119         uint16_t usSourcePort;\r
120         uint16_t usDestinationPort;\r
121         uint16_t usLength;\r
122         uint16_t usChecksum;\r
123 }\r
124 #include "pack_struct_end.h"\r
125 typedef struct xUDP_HEADER xUDPHeader_t;\r
126 #define ipSIZE_OF_UDP_HEADER 8\r
127 \r
128 #include "pack_struct_start.h"\r
129 struct xPSEUDO_HEADER\r
130 {\r
131         uint32_t ulSourceAddress;\r
132         uint32_t ulDestinationAddress;\r
133         uint8_t ucZeros;\r
134         uint8_t ucProtocol;\r
135         uint16_t usUDPLength;\r
136 }\r
137 #include "pack_struct_end.h"\r
138 typedef struct xPSEUDO_HEADER xPseudoHeader_t;\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 /* Nested protocol packets.                                  */\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 #include "pack_struct_start.h"\r
145 struct xARP_PACKET\r
146 {\r
147         xEthernetHeader_t xEthernetHeader;\r
148         xARPHeader_t xARPHeader;\r
149 }\r
150 #include "pack_struct_end.h"\r
151 typedef struct xARP_PACKET xARPPacket_t;\r
152 \r
153 #include "pack_struct_start.h"\r
154 struct xIP_PACKET\r
155 {\r
156         xEthernetHeader_t xEthernetHeader;\r
157         xIPHeader_t xIPHeader;\r
158 }\r
159 #include "pack_struct_end.h"\r
160 typedef struct xIP_PACKET xIPPacket_t;\r
161 \r
162 #include "pack_struct_start.h"\r
163 struct xICMP_PACKET\r
164 {\r
165         xEthernetHeader_t xEthernetHeader;\r
166         xIPHeader_t xIPHeader;\r
167         xICMPHeader_t xICMPHeader;\r
168 }\r
169 #include "pack_struct_end.h"\r
170 typedef struct xICMP_PACKET xICMPPacket_t;\r
171 \r
172 #include "pack_struct_start.h"\r
173 struct xUDP_PACKET\r
174 {\r
175         xEthernetHeader_t xEthernetHeader;\r
176         xIPHeader_t xIPHeader;\r
177         xUDPHeader_t xUDPHeader;\r
178 }\r
179 #include "pack_struct_end.h"\r
180 typedef struct xUDP_PACKET xUDPPacket_t;\r
181 \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
186 \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
189 \r
190 typedef enum\r
191 {\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
197 \r
198 typedef enum\r
199 {\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
205 } eIPEvent_t;\r
206 \r
207 typedef struct IP_TASK_COMMANDS\r
208 {\r
209         eIPEvent_t eEventType;\r
210         void *pvData;\r
211 } xIPStackEvent_t;\r
212 \r
213 #define ipBROADCAST_IP_ADDRESS 0xffffffffUL\r
214 \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
220 \r
221 /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h\r
222 setting. */\r
223 #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET : ipIP_PAYLOAD_OFFSET )\r
224 \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
227 \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
230 \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
235 \r
236 #include "pack_struct_start.h"\r
237 struct xUDP_IP_FRACMENT_PARAMETERS\r
238 {\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
244 }\r
245 #include "pack_struct_end.h"\r
246 typedef struct xUDP_IP_FRACMENT_PARAMETERS xIPFragmentParameters_t;\r
247 \r
248 #if( ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN )\r
249 \r
250         /* Ethernet frame types. */\r
251         #define ipARP_TYPE      ( 0x0608U )\r
252         #define ipIP_TYPE       ( 0x0008U )\r
253 \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
259 \r
260 #else\r
261 \r
262         /* Ethernet frame types. */\r
263         #define ipARP_TYPE      ( 0x0806U )\r
264         #define ipIP_TYPE       ( 0x0800U )\r
265 \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
271 \r
272 #endif /* ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN */\r
273 \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
278 {\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
286 \r
287 void vNetworkBufferRelease( xNetworkBufferDescriptor_t * const pxNetworkBuffer );\r
288 \r
289 /*\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
293  */\r
294 portBASE_TYPE FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );\r
295 \r
296 /*\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
301  * event.\r
302  *\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
307  */\r
308 void FreeRTOS_NetworkDown( void );\r
309 portBASE_TYPE FreeRTOS_NetworkDownFromISR( void );\r
310 \r
311 /*\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
315  */\r
316 eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );\r
317 \r
318 #if( ipconfigINCLUDE_TEST_CODE == 1 )\r
319         unsigned portBASE_TYPE uxGetNumberOfFreeNetworkBuffers( void );\r
320 #endif /* ipconfigINCLUDE_TEST_CODE */\r
321 \r
322 /* Socket related private functions. */\r
323 portBASE_TYPE xProcessReceivedUDPPacket( xNetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );\r
324 void FreeRTOS_SocketsInit( void );\r
325 \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
330 #endif\r
331 \r
332 \r
333 #endif /* FREERTOS_IP_PRIVATE_H */\r
334 \r
335 \r
336 \r
337 \r
338 \r
339 \r
340 \r
341 \r
342 \r
343 \r
344 \r
345 \r
346 \r