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