2 * FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.
\r
3 * Authors include Hein Tibosch and Richard Barry
\r
5 *******************************************************************************
\r
6 ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
\r
9 *** FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP ***
\r
10 *** demos have a dependency on FreeRTOS+FAT, which is only in the Labs ***
\r
13 *** FreeRTOS+TCP is functional and has been used in commercial products ***
\r
14 *** for some time. Be aware however that we are still refining its ***
\r
15 *** design, the source code does not yet quite conform to the strict ***
\r
16 *** coding and style standards mandated by Real Time Engineers ltd., and ***
\r
17 *** the documentation and testing is not necessarily complete. ***
\r
19 *** PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE ***
\r
20 *** URL: http://www.FreeRTOS.org/contact Active early adopters may, at ***
\r
21 *** the sole discretion of Real Time Engineers Ltd., be offered versions ***
\r
22 *** under a license other than that described below. ***
\r
25 ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
\r
26 *******************************************************************************
\r
28 * FreeRTOS+TCP can be used under two different free open source licenses. The
\r
29 * license that applies is dependent on the processor on which FreeRTOS+TCP is
\r
30 * executed, as follows:
\r
32 * If FreeRTOS+TCP is executed on one of the processors listed under the Special
\r
33 * License Arrangements heading of the FreeRTOS+TCP license information web
\r
34 * page, then it can be used under the terms of the FreeRTOS Open Source
\r
35 * License. If FreeRTOS+TCP is used on any other processor, then it can be used
\r
36 * under the terms of the GNU General Public License V2. Links to the relevant
\r
39 * The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license
\r
40 * The FreeRTOS Open Source License: http://www.FreeRTOS.org/license
\r
41 * The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt
\r
43 * FreeRTOS+TCP is distributed in the hope that it will be useful. You cannot
\r
44 * use FreeRTOS+TCP unless you agree that you use the software 'as is'.
\r
45 * FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied
\r
46 * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
47 * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
\r
48 * implied, expressed, or statutory.
\r
50 * 1 tab == 4 spaces!
\r
52 * http://www.FreeRTOS.org
\r
53 * http://www.FreeRTOS.org/plus
\r
54 * http://www.FreeRTOS.org/labs
\r
58 #ifndef FREERTOS_IP_PRIVATE_H
\r
59 #define FREERTOS_IP_PRIVATE_H
\r
65 /* Application level configuration options. */
\r
66 #include "FreeRTOSIPConfig.h"
\r
67 #include "FreeRTOSIPConfigDefaults.h"
\r
68 #include "FreeRTOS_Sockets.h"
\r
69 #include "IPTraceMacroDefaults.h"
\r
70 #include "FreeRTOS_Stream_Buffer.h"
\r
71 #if( ipconfigUSE_TCP == 1 )
\r
72 #include "FreeRTOS_TCP_WIN.h"
\r
73 #include "FreeRTOS_TCP_IP.h"
\r
76 #include "event_groups.h"
\r
78 typedef struct xNetworkAddressingParameters
\r
80 uint32_t ulDefaultIPAddress;
\r
82 uint32_t ulGatewayAddress;
\r
83 uint32_t ulDNSServerAddress;
\r
84 uint32_t ulBroadcastAddress;
\r
85 } NetworkAddressingParameters_t;
\r
87 extern BaseType_t xTCPWindowLoggingLevel;
\r
89 /*-----------------------------------------------------------*/
\r
90 /* Protocol headers. */
\r
91 /*-----------------------------------------------------------*/
\r
93 #include "pack_struct_start.h"
\r
96 MACAddress_t xDestinationAddress; /* 0 + 6 = 6 */
\r
97 MACAddress_t xSourceAddress; /* 6 + 6 = 12 */
\r
98 uint16_t usFrameType; /* 12 + 2 = 14 */
\r
100 #include "pack_struct_end.h"
\r
101 typedef struct xETH_HEADER EthernetHeader_t;
\r
103 #include "pack_struct_start.h"
\r
106 uint16_t usHardwareType; /* 0 + 2 = 2 */
\r
107 uint16_t usProtocolType; /* 2 + 2 = 4 */
\r
108 uint8_t ucHardwareAddressLength; /* 4 + 1 = 5 */
\r
109 uint8_t ucProtocolAddressLength; /* 5 + 1 = 6 */
\r
110 uint16_t usOperation; /* 6 + 2 = 8 */
\r
111 MACAddress_t xSenderHardwareAddress; /* 8 + 6 = 14 */
\r
112 uint8_t ucSenderProtocolAddress[ 4 ]; /* 14 + 4 = 18 */
\r
113 MACAddress_t xTargetHardwareAddress; /* 18 + 6 = 24 */
\r
114 uint32_t ulTargetProtocolAddress; /* 24 + 4 = 28 */
\r
116 #include "pack_struct_end.h"
\r
117 typedef struct xARP_HEADER ARPHeader_t;
\r
119 #include "pack_struct_start.h"
\r
122 uint8_t ucVersionHeaderLength; /* 0 + 1 = 1 */
\r
123 uint8_t ucDifferentiatedServicesCode; /* 1 + 1 = 2 */
\r
124 uint16_t usLength; /* 2 + 2 = 4 */
\r
125 uint16_t usIdentification; /* 4 + 2 = 6 */
\r
126 uint16_t usFragmentOffset; /* 6 + 2 = 8 */
\r
127 uint8_t ucTimeToLive; /* 8 + 1 = 9 */
\r
128 uint8_t ucProtocol; /* 9 + 1 = 10 */
\r
129 uint16_t usHeaderChecksum; /* 10 + 2 = 12 */
\r
130 uint32_t ulSourceIPAddress; /* 12 + 4 = 16 */
\r
131 uint32_t ulDestinationIPAddress; /* 16 + 4 = 20 */
\r
133 #include "pack_struct_end.h"
\r
134 typedef struct xIP_HEADER IPHeader_t;
\r
136 #include "pack_struct_start.h"
\r
137 struct xIGMP_HEADER
\r
139 uint8_t ucVersionType; /* 0 + 1 = 1 */
\r
140 uint8_t ucMaxResponseTime; /* 1 + 1 = 2 */
\r
141 uint16_t usChecksum; /* 2 + 2 = 4 */
\r
142 uint32_t usGroupAddress; /* 4 + 4 = 8 */
\r
144 #include "pack_struct_end.h"
\r
145 typedef struct xIGMP_HEADER IGMPHeader_t;
\r
147 #include "pack_struct_start.h"
\r
148 struct xICMP_HEADER
\r
150 uint8_t ucTypeOfMessage; /* 0 + 1 = 1 */
\r
151 uint8_t ucTypeOfService; /* 1 + 1 = 2 */
\r
152 uint16_t usChecksum; /* 2 + 2 = 4 */
\r
153 uint16_t usIdentifier; /* 4 + 2 = 6 */
\r
154 uint16_t usSequenceNumber; /* 6 + 2 = 8 */
\r
156 #include "pack_struct_end.h"
\r
157 typedef struct xICMP_HEADER ICMPHeader_t;
\r
159 #include "pack_struct_start.h"
\r
162 uint16_t usSourcePort; /* 0 + 2 = 2 */
\r
163 uint16_t usDestinationPort; /* 2 + 2 = 4 */
\r
164 uint16_t usLength; /* 4 + 2 = 6 */
\r
165 uint16_t usChecksum; /* 6 + 2 = 8 */
\r
167 #include "pack_struct_end.h"
\r
168 typedef struct xUDP_HEADER UDPHeader_t;
\r
170 #include "pack_struct_start.h"
\r
173 uint16_t usSourcePort; /* + 2 = 2 */
\r
174 uint16_t usDestinationPort; /* + 2 = 4 */
\r
175 uint32_t ulSequenceNumber; /* + 4 = 8 */
\r
176 uint32_t ulAckNr; /* + 4 = 12 */
\r
177 uint8_t ucTCPOffset; /* + 1 = 13 */
\r
178 uint8_t ucTCPFlags; /* + 1 = 14 */
\r
179 uint16_t usWindow; /* + 2 = 15 */
\r
180 uint16_t usChecksum; /* + 2 = 18 */
\r
181 uint16_t usUrgent; /* + 2 = 20 */
\r
182 #if ipconfigUSE_TCP == 1
\r
183 /* the option data is not a part of the TCP header */
\r
184 uint8_t ucOptdata[ipSIZE_TCP_OPTIONS]; /* + 12 = 32 */
\r
187 #include "pack_struct_end.h"
\r
188 typedef struct xTCP_HEADER TCPHeader_t;
\r
190 #include "pack_struct_start.h"
\r
191 struct xPSEUDO_HEADER
\r
193 uint32_t ulSourceAddress;
\r
194 uint32_t ulDestinationAddress;
\r
196 uint8_t ucProtocol;
\r
197 uint16_t usUDPLength;
\r
199 #include "pack_struct_end.h"
\r
200 typedef struct xPSEUDO_HEADER PseudoHeader_t;
\r
202 /*-----------------------------------------------------------*/
\r
203 /* Nested protocol packets. */
\r
204 /*-----------------------------------------------------------*/
\r
206 #include "pack_struct_start.h"
\r
209 EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
\r
210 ARPHeader_t xARPHeader; /* 14 + 28 = 42 */
\r
212 #include "pack_struct_end.h"
\r
213 typedef struct xARP_PACKET ARPPacket_t;
\r
215 #include "pack_struct_start.h"
\r
218 EthernetHeader_t xEthernetHeader;
\r
219 IPHeader_t xIPHeader;
\r
221 #include "pack_struct_end.h"
\r
222 typedef struct xIP_PACKET IPPacket_t;
\r
224 #include "pack_struct_start.h"
\r
225 struct xICMP_PACKET
\r
227 EthernetHeader_t xEthernetHeader;
\r
228 IPHeader_t xIPHeader;
\r
229 ICMPHeader_t xICMPHeader;
\r
231 #include "pack_struct_end.h"
\r
232 typedef struct xICMP_PACKET ICMPPacket_t;
\r
234 #include "pack_struct_start.h"
\r
237 EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
\r
238 IPHeader_t xIPHeader; /* 14 + 20 = 34 */
\r
239 UDPHeader_t xUDPHeader; /* 34 + 8 = 42 */
\r
241 #include "pack_struct_end.h"
\r
242 typedef struct xUDP_PACKET UDPPacket_t;
\r
244 #include "pack_struct_start.h"
\r
247 EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
\r
248 IPHeader_t xIPHeader; /* 14 + 20 = 34 */
\r
249 TCPHeader_t xTCPHeader; /* 34 + 32 = 66 */
\r
251 #include "pack_struct_end.h"
\r
252 typedef struct xTCP_PACKET TCPPacket_t;
\r
254 typedef union XPROT_PACKET
\r
256 ARPPacket_t xARPPacket;
\r
257 TCPPacket_t xTCPPacket;
\r
258 UDPPacket_t xUDPPacket;
\r
259 ICMPPacket_t xICMPPacket;
\r
260 } ProtocolPacket_t;
\r
263 /* The maximum UDP payload length. */
\r
264 #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
\r
268 eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
\r
269 eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
\r
270 eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
\r
271 eFrameConsumed /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
\r
272 } eFrameProcessingResult_t;
\r
277 eNetworkDownEvent, /* 0: The network interface has been lost and/or needs [re]connecting. */
\r
278 eNetworkRxEvent, /* 1: The network interface has queued a received Ethernet frame. */
\r
279 eARPTimerEvent, /* 2: The ARP timer expired. */
\r
280 eStackTxEvent, /* 3: The software stack has queued a packet to transmit. */
\r
281 eDHCPEvent, /* 4: Process the DHCP state machine. */
\r
282 eTCPTimerEvent, /* 5: See if any TCP socket needs attention. */
\r
283 eTCPAcceptEvent, /* 6: Client API FreeRTOS_accept() waiting for client connections. */
\r
284 eTCPNetStat, /* 7: IP-task is asked to produce a netstat listing. */
\r
285 eSocketBindEvent, /* 8: Send a message to the IP-task to bind a socket to a port. */
\r
286 eSocketCloseEvent, /* 9: Send a message to the IP-task to close a socket. */
\r
287 eSocketSelectEvent, /*10: Send a message to the IP-task for select(). */
\r
288 eSocketSignalEvent, /*11: A socket must be signalled. */
\r
291 typedef struct IP_TASK_COMMANDS
\r
293 eIPEvent_t eEventType;
\r
297 #define ipBROADCAST_IP_ADDRESS 0xffffffffUL
\r
299 /* Offset into the Ethernet frame that is used to temporarily store information
\r
300 on the fragmentation status of the packet being sent. The value is important,
\r
301 as it is past the location into which the destination address will get placed. */
\r
302 #define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
\r
303 #define ipSOCKET_OPTIONS_OFFSET ( 6 )
\r
305 /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
\r
307 #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET_IPv4 : ipIP_PAYLOAD_OFFSET )
\r
309 /* The offset into a UDP packet at which the UDP data (payload) starts. */
\r
310 #define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
\r
312 /* The offset into an IP packet into which the IP data (payload) starts. */
\r
313 #define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) )
\r
315 #include "pack_struct_start.h"
\r
316 struct xUDP_IP_FRAGMENT_PARAMETERS
\r
318 uint8_t ucSocketOptions;
\r
319 uint8_t ucPadFor16BitAlignment;
\r
320 uint16_t usFragmentedPacketOffset;
\r
321 uint16_t usFragmentLength;
\r
322 uint16_t usPayloadChecksum;
\r
324 #include "pack_struct_end.h"
\r
325 typedef struct xUDP_IP_FRAGMENT_PARAMETERS IPFragmentParameters_t;
\r
327 #if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
\r
329 /* Ethernet frame types. */
\r
330 #define ipARP_FRAME_TYPE ( 0x0608U )
\r
331 #define ipIPv4_FRAME_TYPE ( 0x0008U )
\r
333 /* ARP related definitions. */
\r
334 #define ipARP_PROTOCOL_TYPE ( 0x0008U )
\r
335 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
\r
336 #define ipARP_REQUEST ( 0x0100U )
\r
337 #define ipARP_REPLY ( 0x0200U )
\r
341 /* Ethernet frame types. */
\r
342 #define ipARP_FRAME_TYPE ( 0x0806U )
\r
343 #define ipIPv4_FRAME_TYPE ( 0x0800U )
\r
345 /* ARP related definitions. */
\r
346 #define ipARP_PROTOCOL_TYPE ( 0x0800U )
\r
347 #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
\r
348 #define ipARP_REQUEST ( 0x0001 )
\r
349 #define ipARP_REPLY ( 0x0002 )
\r
351 #endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */
\r
354 /* For convenience, a MAC address of all zeros and another of all 0xffs are
\r
355 defined const for quick reference. */
\r
356 extern const MACAddress_t xBroadcastMACAddress; /* all 0xff's */
\r
357 extern uint16_t usPacketIdentifier;
\r
359 /* Define a default UDP packet header (declared in FreeRTOS_UDP_IP.c) */
\r
360 typedef union xUDPPacketHeader
\r
362 uint8_t ucBytes[24];
\r
363 uint32_t ulWords[6];
\r
364 } UDPPacketHeader_t;
\r
365 extern UDPPacketHeader_t xDefaultPartUDPPacketHeader;
\r
367 /* Structure that stores the netmask, gateway address and DNS server addresses. */
\r
368 extern NetworkAddressingParameters_t xNetworkAddressing;
\r
370 /* Structure that stores the defaults for netmask, gateway address and DNS.
\r
371 These values will be copied to 'xNetworkAddressing' in case DHCP is not used,
\r
372 and also in case DHCP does not lead to a confirmed request. */
\r
373 extern NetworkAddressingParameters_t xDefaultAddressing;
\r
375 /* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
\r
376 extern const BaseType_t xBufferAllocFixedSize;
\r
378 /* Defined in FreeRTOS_Sockets.c */
\r
379 #if ( ipconfigUSE_TCP == 1 )
\r
380 extern List_t xBoundTCPSocketsList;
\r
383 /* The local IP address is accessed from within xDefaultPartUDPPacketHeader,
\r
384 rather than duplicated in its own variable. */
\r
385 #define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[ 20u / sizeof(uint32_t) ] ) )
\r
387 /* The local MAC address is accessed from within xDefaultPartUDPPacketHeader,
\r
388 rather than duplicated in its own variable. */
\r
389 #define ipLOCAL_MAC_ADDRESS ( &xDefaultPartUDPPacketHeader.ucBytes[0] )
\r
391 /* ICMP packets are sent using the same function as UDP packets. The port
\r
392 number is used to distinguish between the two, as 0 is an invalid UDP port. */
\r
393 #define ipPACKET_CONTAINS_ICMP_DATA ( 0 )
\r
395 /* For now, the lower 8 bits in 'xEventBits' will be reserved for the above
\r
397 #define SOCKET_EVENT_BIT_COUNT 8
\r
399 #define vSetField16( pxBase, xType, xField, usValue ) \
\r
401 ( ( uint8_t* )( pxBase ) ) [ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( usValue ) >> 8 ); \
\r
402 ( ( uint8_t* )( pxBase ) ) [ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( usValue ) & 0xff ); \
\r
405 #define vSetField32( pxBase, xType, xField, ulValue ) \
\r
407 ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( ulValue ) >> 24 ); \
\r
408 ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( ( ulValue ) >> 16 ) & 0xff ); \
\r
409 ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 2 ] = ( uint8_t ) ( ( ( ulValue ) >> 8 ) & 0xff ); \
\r
410 ( (uint8_t*)( pxBase ) ) [ offsetof( xType, xField ) + 3 ] = ( uint8_t ) ( ( ulValue ) & 0xff ); \
\r
413 #define vFlip_16( left, right ) \
\r
415 uint16_t tmp = (left); \
\r
416 (left) = (right); \
\r
420 #define vFlip_32( left, right ) \
\r
422 uint32_t tmp = (left); \
\r
423 (left) = (right); \
\r
428 #define ARRAY_SIZE(x) (BaseType_t)(sizeof(x)/sizeof(x)[0])
\r
432 * A version of FreeRTOS_GetReleaseNetworkBuffer() that can be called from an
\r
433 * interrupt. If a non zero value is returned, then the calling ISR should
\r
434 * perform a context switch before exiting the ISR.
\r
436 BaseType_t FreeRTOS_ReleaseFreeNetworkBufferFromISR( void );
\r
439 * Create a message that contains a command to initialise the network interface.
\r
440 * This is used during initialisation, and at any time the network interface
\r
441 * goes down thereafter. The network interface hardware driver is responsible
\r
442 * for sending the message that contains the network interface down command/
\r
445 * Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
\r
446 * called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
\r
447 * returns a non-zero value then a context switch should be performed ebfore
\r
448 * the interrupt is exited.
\r
450 void FreeRTOS_NetworkDown( void );
\r
451 BaseType_t FreeRTOS_NetworkDownFromISR( void );
\r
454 * Processes incoming ARP packets.
\r
456 eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame );
\r
459 * Inspect an Ethernet frame to see if it contains data that the stack needs to
\r
460 * process. eProcessBuffer is returned if the frame should be processed by the
\r
461 * stack. eReleaseBuffer is returned if the frame should be discarded.
\r
463 eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
\r
466 * Return the checksum generated over xDataLengthBytes from pucNextData.
\r
468 uint16_t usGenerateChecksum( uint32_t ulSum, const uint8_t * pucNextData, size_t uxDataLengthBytes );
\r
470 /* Socket related private functions. */
\r
471 BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer, uint16_t usPort );
\r
472 void vNetworkSocketsInit( void );
\r
475 * Returns pdTRUE if the IP task has been created and is initialised. Otherwise
\r
478 BaseType_t xIPIsNetworkTaskReady( void );
\r
480 #if( ipconfigUSE_TCP == 1 )
\r
483 * Actually a user thing, but because xBoundTCPSocketsList, let it do by the
\r
486 void vTCPNetStat( void );
\r
489 * At least one socket needs to check for timeouts
\r
491 TickType_t xTCPTimerCheck( BaseType_t xWillSleep );
\r
493 /* Every TCP socket has a buffer space just big enough to store
\r
494 the last TCP header received.
\r
495 As a reference of this field may be passed to DMA, force the
\r
496 alignment to 8 bytes. */
\r
501 /* Increase the alignment of this union by adding a 64-bit variable. */
\r
502 uint64_t ullAlignmentWord;
\r
506 /* The next field only serves to give 'ucLastPacket' a correct
\r
507 alignment of 8 + 2. See comments in FreeRTOS_IP.h */
\r
508 uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
\r
509 uint8_t ucLastPacket[ sizeof( TCPPacket_t ) ];
\r
514 * Note that the values of all short and long integers in these structs
\r
515 * are being stored in the native-endian way
\r
516 * Translation should take place when accessing any structure which defines
\r
517 * network packets, such as IPHeader_t and TCPHeader_t
\r
519 typedef struct TCPSOCKET
\r
521 uint32_t ulRemoteIP; /* IP address of remote machine */
\r
522 uint16_t usRemotePort; /* Port on remote machine */
\r
524 /* Most compilers do like bit-flags */
\r
526 bMssChange : 1, /* This socket has seen a change in MSS */
\r
527 bPassAccept : 1, /* when true, this socket may be returned in a call to accept() */
\r
528 bPassQueued : 1, /* when true, this socket is an orphan until it gets connected
\r
529 * Why an orphan? Because it may not be returned in a accept() call until it
\r
530 * gets the state eESTABLISHED */
\r
531 bReuseSocket : 1, /* When a listening socket gets a connection, do not create a new instance but keep on using it */
\r
532 bCloseAfterSend : 1,/* As soon as the last byte has been transmitted, finalise the connection
\r
533 * Useful in e.g. FTP connections, where the last data bytes are sent along with the FIN flag */
\r
534 bUserShutdown : 1, /* User requesting a graceful shutdown */
\r
535 bCloseRequested : 1,/* Request to finalise the connection */
\r
536 bLowWater : 1, /* high-water level has been reached. Cleared as soon as 'rx-count < lo-water' */
\r
537 bWinChange : 1, /* The value of bLowWater has changed, must send a window update */
\r
538 bSendKeepAlive : 1, /* When this flag is true, a TCP keep-alive message must be send */
\r
539 bWaitKeepAlive : 1, /* When this flag is true, a TCP keep-alive reply is expected */
\r
540 bConnPrepared : 1, /* Connecting socket: Message has been prepared */
\r
541 #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
\r
542 bConnPassed : 1, /* Connecting socket: Socket has been passed in a successful select() */
\r
543 #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
\r
544 bFinAccepted : 1, /* This socket has received (or sent) a FIN and accepted it */
\r
545 bFinSent : 1, /* We've sent out a FIN */
\r
546 bFinRecv : 1, /* We've received a FIN from our peer */
\r
547 bFinAcked : 1, /* Our FIN packet has been acked */
\r
548 bFinLast : 1, /* The last ACK (after FIN and FIN+ACK) has been sent or will be sent by the peer */
\r
549 bRxStopped : 1, /* Application asked to temporarily stop reception */
\r
550 bMallocError : 1, /* There was an error allocating a stream */
\r
551 bWinScaling : 1; /* A TCP-Window Scaling option was offered and accepted in the SYN phase. */
\r
553 uint32_t ulHighestRxAllowed;
\r
554 /* The highest sequence number that we can receive at any moment */
\r
555 uint16_t usTimeout; /* Time (in ticks) after which this socket needs attention */
\r
556 uint16_t usCurMSS; /* Current Maximum Segment Size */
\r
557 uint16_t usInitMSS; /* Initial maximum segment Size */
\r
558 uint16_t usChildCount; /* In case of a listening socket: number of connections on this port number */
\r
559 uint16_t usBacklog; /* In case of a listening socket: maximum number of concurrent connections on this port number */
\r
560 uint8_t ucRepCount; /* Send repeat count, for retransmissions
\r
561 * This counter is separate from the xmitCount in the
\r
562 * TCP win segments */
\r
563 uint8_t ucTCPState; /* TCP state: see eTCP_STATE */
\r
564 struct XSOCKET *pxPeerSocket; /* for server socket: child, for child socket: parent */
\r
565 #if( ipconfigTCP_KEEP_ALIVE == 1 )
\r
566 uint8_t ucKeepRepCount;
\r
567 TickType_t xLastAliveTime;
\r
568 #endif /* ipconfigTCP_KEEP_ALIVE */
\r
569 #if( ipconfigTCP_HANG_PROTECTION == 1 )
\r
570 TickType_t xLastActTime;
\r
571 #endif /* ipconfigTCP_HANG_PROTECTION */
\r
572 size_t uxLittleSpace;
\r
573 size_t uxEnoughSpace;
\r
574 size_t uxRxStreamSize;
\r
575 size_t uxTxStreamSize;
\r
576 StreamBuffer_t *rxStream;
\r
577 StreamBuffer_t *txStream;
\r
578 #if( ipconfigUSE_TCP_WIN == 1 )
\r
579 NetworkBufferDescriptor_t *pxAckMessage;
\r
580 #endif /* ipconfigUSE_TCP_WIN */
\r
581 /* Buffer space to store the last TCP header received. */
\r
582 LastTCPPacket_t xPacket;
\r
583 uint8_t tcpflags; /* TCP flags */
\r
584 #if( ipconfigUSE_TCP_WIN != 0 )
\r
585 uint8_t ucMyWinScaleFactor;
\r
586 uint8_t ucPeerWinScaleFactor;
\r
588 #if( ipconfigUSE_CALLBACKS == 1 )
\r
589 FOnTCPReceive_t pxHandleReceive; /*
\r
590 * In case of a TCP socket:
\r
591 * typedef void (* FOnTCPReceive_t) (Socket_t xSocket, void *pData, size_t xLength );
\r
593 FOnTCPSent_t pxHandleSent;
\r
594 FOnConnected_t pxHandleConnected; /* Actually type: typedef void (* FOnConnected_t) (Socket_t xSocket, BaseType_t ulConnected ); */
\r
595 #endif /* ipconfigUSE_CALLBACKS */
\r
596 uint32_t ulWindowSize; /* Current Window size advertised by peer */
\r
597 uint32_t ulRxCurWinSize; /* Constantly changing: this is the current size available for data reception */
\r
598 size_t uxRxWinSize; /* Fixed value: size of the TCP reception window */
\r
599 size_t uxTxWinSize; /* Fixed value: size of the TCP transmit window */
\r
601 TCPWindow_t xTCPWindow;
\r
604 #endif /* ipconfigUSE_TCP */
\r
606 typedef struct UDPSOCKET
\r
608 List_t xWaitingPacketsList; /* Incoming packets */
\r
609 #if( ipconfigUDP_MAX_RX_PACKETS > 0 )
\r
610 UBaseType_t uxMaxPackets; /* Protection: limits the number of packets buffered per socket */
\r
611 #endif /* ipconfigUDP_MAX_RX_PACKETS */
\r
612 #if( ipconfigUSE_CALLBACKS == 1 )
\r
613 FOnUDPReceive_t pxHandleReceive; /*
\r
614 * In case of a UDP socket:
\r
615 * typedef void (* FOnUDPReceive_t) (Socket_t xSocket, void *pData, size_t xLength, struct freertos_sockaddr *pxAddr );
\r
617 FOnUDPSent_t pxHandleSent;
\r
618 #endif /* ipconfigUSE_CALLBACKS */
\r
621 typedef enum eSOCKET_EVENT {
\r
622 eSOCKET_RECEIVE = 0x0001,
\r
623 eSOCKET_SEND = 0x0002,
\r
624 eSOCKET_ACCEPT = 0x0004,
\r
625 eSOCKET_CONNECT = 0x0008,
\r
626 eSOCKET_BOUND = 0x0010,
\r
627 eSOCKET_CLOSED = 0x0020,
\r
628 eSOCKET_INTR = 0x0040,
\r
629 eSOCKET_ALL = 0x007F,
\r
632 typedef struct XSOCKET
\r
634 EventBits_t xEventBits;
\r
635 EventGroupHandle_t xEventGroup;
\r
637 ListItem_t xBoundSocketListItem; /* Used to reference the socket from a bound sockets list. */
\r
638 TickType_t xReceiveBlockTime; /* if recv[to] is called while no data is available, wait this amount of time. Unit in clock-ticks */
\r
639 TickType_t xSendBlockTime; /* if send[to] is called while there is not enough space to send, wait this amount of time. Unit in clock-ticks */
\r
641 uint16_t usLocalPort; /* Local port on this machine */
\r
642 uint8_t ucSocketOptions;
\r
643 uint8_t ucProtocol; /* choice of FREERTOS_IPPROTO_UDP/TCP */
\r
644 #if( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
\r
645 SemaphoreHandle_t pxUserSemaphore;
\r
646 #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
\r
647 #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
\r
648 struct xSOCKET_SET *pxSocketSet;
\r
649 /* User may indicate which bits are interesting for this socket. */
\r
650 EventBits_t xSelectBits;
\r
651 /* These bits indicate the events which have actually occurred.
\r
652 They are maintained by the IP-task */
\r
653 EventBits_t xSocketBits;
\r
654 #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
\r
655 /* TCP/UDP specific fields: */
\r
656 /* Before accessing any member of this structure, it should be confirmed */
\r
657 /* that the protocol corresponds with the type of structure */
\r
661 IPUDPSocket_t xUDP;
\r
662 #if( ipconfigUSE_TCP == 1 )
\r
663 IPTCPSocket_t xTCP;
\r
664 /* Make sure that xTCP is 8-bytes aligned by
\r
665 declaring a 64-bit variable in the same union */
\r
666 uint64_t ullTCPAlignment;
\r
667 #endif /* ipconfigUSE_TCP */
\r
669 } FreeRTOS_Socket_t;
\r
671 #if( ipconfigUSE_TCP == 1 )
\r
673 * Lookup a TCP socket, using a multiple matching: both port numbers and
\r
674 * return IP address.
\r
676 FreeRTOS_Socket_t *pxTCPSocketLookup( uint32_t ulLocalIP, UBaseType_t uxLocalPort, uint32_t ulRemoteIP, UBaseType_t uxRemotePort );
\r
678 #endif /* ipconfigUSE_TCP */
\r
681 * Look up a local socket by finding a match with the local port.
\r
683 FreeRTOS_Socket_t *pxUDPSocketLookup( UBaseType_t uxLocalPort );
\r
686 * Called when the application has generated a UDP packet to send.
\r
688 void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
\r
691 * Calculate the upper-layer checksum
\r
692 * Works both for UDP, ICMP and TCP packages
\r
693 * bOut = true: checksum will be set in outgoing packets
\r
694 * bOut = false: checksum will be calculated for incoming packets
\r
695 * returning 0xffff means: checksum was correct
\r
697 uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, BaseType_t xOutgoingPacket );
\r
700 * An Ethernet frame has been updated (maybe it was an ARP request or a PING
\r
701 * request?) and is to be sent back to its source.
\r
703 void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend );
\r
706 * The internal version of bind()
\r
707 * If 'ulInternal' is true, it is called by the driver
\r
708 * The TCP driver needs to bind a socket at the moment a listening socket
\r
709 * creates a new connected socket
\r
711 BaseType_t vSocketBind( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr * pxAddress, size_t uxAddressLength, BaseType_t xInternal );
\r
714 * Internal function to add streaming data to a TCP socket. If ulIn == true,
\r
715 * data will be added to the rxStream, otherwise to the tXStream. Normally data
\r
716 * will be written with ulOffset == 0, meaning: at the end of the FIFO. When
\r
717 * packet come in out-of-order, an offset will be used to put it in front and
\r
718 * the head will not change yet.
\r
720 int32_t lTCPAddRxdata( FreeRTOS_Socket_t *pxSocket, size_t uxOffset, const uint8_t *pcData, uint32_t ulByteCount );
\r
723 * Currently called for any important event.
\r
725 void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket );
\r
728 * Some helping function, their meaning should be clear
\r
730 static portINLINE uint32_t ulChar2u32 (const uint8_t *apChr);
\r
731 static portINLINE uint32_t ulChar2u32 (const uint8_t *apChr)
\r
733 return ( ( ( uint32_t )apChr[0] ) << 24) |
\r
734 ( ( ( uint32_t )apChr[1] ) << 16) |
\r
735 ( ( ( uint32_t )apChr[2] ) << 8) |
\r
736 ( ( ( uint32_t )apChr[3] ) );
\r
739 static portINLINE uint16_t usChar2u16 (const uint8_t *apChr);
\r
740 static portINLINE uint16_t usChar2u16 (const uint8_t *apChr)
\r
742 return ( uint16_t )
\r
743 ( ( ( ( uint32_t )apChr[0] ) << 8) |
\r
744 ( ( ( uint32_t )apChr[1] ) ) );
\r
747 /* Check a single socket for retransmissions and timeouts */
\r
748 BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t *pxSocket );
\r
750 BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t *pxSocket );
\r
752 /* Defined in FreeRTOS_Sockets.c
\r
755 void *vSocketClose( FreeRTOS_Socket_t *pxSocket );
\r
758 * Send the event eEvent to the IP task event queue, using a block time of
\r
759 * zero. Return pdPASS if the message was sent successfully, otherwise return
\r
762 BaseType_t xSendEventToIPTask( eIPEvent_t eEvent );
\r
765 * The same as above, but a struct as a parameter, containing:
\r
766 * eIPEvent_t eEventType;
\r
769 BaseType_t xSendEventStructToIPTask( const IPStackEvent_t *pxEvent, TickType_t xTimeout );
\r
772 * Returns a pointer to the original NetworkBuffer from a pointer to a UDP
\r
775 NetworkBufferDescriptor_t *pxUDPPayloadBuffer_to_NetworkBuffer( void *pvBuffer );
\r
777 #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
\r
779 * For the case where the network driver passes a buffer directly to a DMA
\r
780 * descriptor, this function can be used to translate a 'network buffer' to
\r
781 * a 'network buffer descriptor'.
\r
783 NetworkBufferDescriptor_t *pxPacketBuffer_to_NetworkBuffer( const void *pvBuffer );
\r
787 * Internal: Sets a new state for a TCP socket and performs the necessary
\r
788 * actions like calling a OnConnected handler to notify the socket owner.
\r
790 #if( ipconfigUSE_TCP == 1 )
\r
791 void vTCPStateChange( FreeRTOS_Socket_t *pxSocket, enum eTCP_STATE eTCPState );
\r
792 #endif /* ipconfigUSE_TCP */
\r
794 /*_RB_ Should this be part of the public API? */
\r
795 void FreeRTOS_netstat( void );
\r
797 /* Returns pdTRUE is this function is called from the IP-task */
\r
798 BaseType_t xIsCallingFromIPTask( void );
\r
800 #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
\r
802 typedef struct xSOCKET_SET
\r
804 EventGroupHandle_t xSelectGroup;
\r
805 BaseType_t bApiCalled; /* True if the API was calling the private vSocketSelect */
\r
806 FreeRTOS_Socket_t *pxSocket;
\r
809 extern void vSocketSelect( SocketSelect_t *pxSocketSelect );
\r
811 #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
\r
813 void vIPSetDHCPTimerEnableState( BaseType_t xEnableState );
\r
814 void vIPReloadDHCPTimer( uint32_t ulLeaseTime );
\r
815 #if( ipconfigDNS_USE_CALLBACKS != 0 )
\r
816 void vIPReloadDNSTimer( uint32_t ulCheckTime );
\r
817 void vIPSetDnsTimerEnableState( BaseType_t xEnableState );
\r
820 /* Send the network-up event and start the ARP timer. */
\r
821 void vIPNetworkUpCalls( void );
\r
827 #endif /* FREERTOS_IP_PRIVATE_H */
\r