1 /*
2  * FreeRTOS+TCP V3.1.0
3  * Copyright (C) 2022 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * http://aws.amazon.com/freertos
25  * http://www.FreeRTOS.org
26  */
27 
28 #ifndef FREERTOS_SOCKETS_H
29     #define FREERTOS_SOCKETS_H
30 
31     #ifdef __cplusplus
32         extern "C" {
33     #endif
34 
35 /* Standard includes. */
36     #include <string.h>
37 
38 /* FreeRTOS includes. */
39     #include "FreeRTOS.h"
40     #include "task.h"
41 
42 /* Application level configuration options. */
43     #include "FreeRTOSIPConfig.h"
44     #include "FreeRTOSIPConfigDefaults.h"
45 
46     #ifndef FREERTOS_IP_CONFIG_H
47         #error FreeRTOSIPConfig.h has not been included yet
48     #endif
49 
50 /* Event bit definitions are required by the select functions. */
51     #include "event_groups.h"
52 
53     #ifndef INC_FREERTOS_H
54         #error FreeRTOS.h must be included before FreeRTOS_Sockets.h.
55     #endif
56 
57     #ifndef INC_TASK_H
58         #ifndef TASK_H /* For compatibility with older FreeRTOS versions. */
59             #error The FreeRTOS header file task.h must be included before FreeRTOS_Sockets.h.
60         #endif
61     #endif
62 
63 /* Assigned to an Socket_t variable when the socket is not valid, probably
64  * because it could not be created. */
65     #define FREERTOS_INVALID_SOCKET          ( ( Socket_t ) ~0U )
66 
67 /* API function error values.  As errno is supported, the FreeRTOS sockets
68  * functions return error codes rather than just a pass or fail indication.
69  *
70  * Like in errno.h, the error codes are defined as positive numbers.
71  * However, in case of an error, API 's will still negative values, e.g.
72  * return -pdFREERTOS_ERRNO_EWOULDBLOCK;
73  * in case an operation would block.
74  *
75  * The following defines are obsolete, please use -pdFREERTOS_ERRNO_Exxx. */
76     #define FREERTOS_SOCKET_ERROR            ( -1 )
77     #define FREERTOS_EWOULDBLOCK             ( -pdFREERTOS_ERRNO_EWOULDBLOCK )
78     #define FREERTOS_EINVAL                  ( -pdFREERTOS_ERRNO_EINVAL )
79     #define FREERTOS_EADDRNOTAVAIL           ( -pdFREERTOS_ERRNO_EADDRNOTAVAIL )
80     #define FREERTOS_EADDRINUSE              ( -pdFREERTOS_ERRNO_EADDRINUSE )
81     #define FREERTOS_ENOBUFS                 ( -pdFREERTOS_ERRNO_ENOBUFS )
82     #define FREERTOS_ENOPROTOOPT             ( -pdFREERTOS_ERRNO_ENOPROTOOPT )
83     #define FREERTOS_ECLOSED                 ( -pdFREERTOS_ERRNO_ENOTCONN )
84 
85 /* Values for the parameters to FreeRTOS_socket(), inline with the Berkeley
86  * standard.  See the documentation of FreeRTOS_socket() for more information. */
87     #define FREERTOS_AF_INET                 ( 2 )
88     #define FREERTOS_AF_INET6                ( 10 )
89     #define FREERTOS_SOCK_DGRAM              ( 2 )
90     #define FREERTOS_IPPROTO_UDP             ( 17 )
91     #define FREERTOS_SOCK_STREAM             ( 1 )
92     #define FREERTOS_IPPROTO_TCP             ( 6 )
93     #define FREERTOS_SOCK_DEPENDENT_PROTO    ( 0 )
94 
95 /* Values for xFlags parameter of Receive/Send functions. */
96     #define FREERTOS_ZERO_COPY               ( 1 )  /* Can be used with recvfrom(), sendto() and recv(),
97                                                      * Indicates that the zero copy interface is being used.
98                                                      * See the documentation for FreeRTOS_sockets() for more information. */
99     #define FREERTOS_MSG_OOB                 ( 2 )  /* Not used. */
100     #define FREERTOS_MSG_PEEK                ( 4 )  /* Can be used with recvfrom() and recv(). */
101     #define FREERTOS_MSG_DONTROUTE           ( 8 )  /* Not used. */
102     #define FREERTOS_MSG_DONTWAIT            ( 16 ) /* Can be used with recvfrom(), sendto(), recv() and send(). */
103 
104 /* Values that can be passed in the option name parameter of calls to
105  * FreeRTOS_setsockopt(). */
106     #define FREERTOS_SO_RCVTIMEO             ( 0 ) /* Used to set the receive time out. */
107     #define FREERTOS_SO_SNDTIMEO             ( 1 ) /* Used to set the send time out. */
108     #define FREERTOS_SO_UDPCKSUM_OUT         ( 2 ) /* Used to turn the use of the UDP checksum
109                                                     * by a socket on or off.  This also doubles
110                                                     * as part of an 8-bit bitwise socket option. */
111     #if ( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
112         #define FREERTOS_SO_SET_SEMAPHORE    ( 3 ) /* Used to set a user's semaphore. */
113     #endif
114 
115     #if ( ipconfigUSE_TCP == 1 )
116         #define FREERTOS_SO_SNDBUF    ( 4 ) /* Set the size of the send buffer (TCP only). */
117         #define FREERTOS_SO_RCVBUF    ( 5 ) /* Set the size of the receive buffer (TCP only). */
118     #endif
119 
120     #if ( ipconfigUSE_CALLBACKS == 1 )
121 
122 /* Supply pointer to 'F_TCP_UDP_Handler_t' for pvOptionValue parameter in
123  * FreeRTOS_setsockopt() */
124         #define FREERTOS_SO_TCP_CONN_HANDLER    ( 6 )  /* Install a callback for (dis) connection events. */
125         #define FREERTOS_SO_TCP_RECV_HANDLER    ( 7 )  /* Install a callback for receiving TCP data. */
126         #define FREERTOS_SO_TCP_SENT_HANDLER    ( 8 )  /* Install a callback for sending TCP data. */
127         #define FREERTOS_SO_UDP_RECV_HANDLER    ( 9 )  /* Install a callback for receiving UDP data. */
128         #define FREERTOS_SO_UDP_SENT_HANDLER    ( 10 ) /* Install a callback for sending UDP data. */
129     #endif
130 
131     #if ( ipconfigUSE_TCP == 1 )
132         #define FREERTOS_SO_REUSE_LISTEN_SOCKET    ( 11 ) /* When a listening socket gets connected, do not create a new one but re-use it. */
133         #define FREERTOS_SO_CLOSE_AFTER_SEND       ( 12 ) /* As soon as the last byte has been transmitted, finalise the connection. */
134         #define FREERTOS_SO_WIN_PROPERTIES         ( 13 ) /* Set all buffer and window properties in one call, parameter is pointer to WinProperties_t. */
135         #define FREERTOS_SO_SET_FULL_SIZE          ( 14 ) /* Refuse to send packets smaller than MSS. */
136         #define FREERTOS_SO_STOP_RX                ( 15 ) /* Temporarily hold up reception, used by streaming client. */
137     #endif
138 
139     #if ( ipconfigUDP_MAX_RX_PACKETS > 0 )
140         #define FREERTOS_SO_UDP_MAX_RX_PACKETS    ( 16 ) /* This option helps to limit the maximum number of packets a UDP socket will buffer. */
141     #endif
142 
143     #if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
144         #define FREERTOS_SO_WAKEUP_CALLBACK    ( 17 )
145     #endif
146 
147     #if ( ipconfigUSE_TCP == 1 )
148         #define FREERTOS_SO_SET_LOW_HIGH_WATER    ( 18 )
149     #endif
150 
151     #if ( 0 ) /* Not Used */
152         #define FREERTOS_NOT_LAST_IN_FRAGMENTED_PACKET    ( 0x80 )
153         #define FREERTOS_FRAGMENTED_PACKET                ( 0x40 )
154     #endif
155 
156     #if ( ipconfigUSE_TCP == 1 )
157 /* Values for 'xHow' flag of FreeRTOS_shutdown(), currently ignored. */
158         #define FREERTOS_SHUT_RD      ( 0 )
159         #define FREERTOS_SHUT_WR      ( 1 )
160         #define FREERTOS_SHUT_RDWR    ( 2 )
161     #endif
162 
163 /* For compatibility with the expected Berkeley sockets naming. */
164     #define socklen_t    uint32_t
165 
166 /**
167  * For this limited implementation, only two members are required in the
168  * Berkeley style sockaddr structure.
169  */
170     struct freertos_sockaddr
171     {
172 /* _HT_ On 32- and 64-bit architectures, the addition of the two uint8_t
173  * fields sin_len and sin_family doesn't make the structure bigger, due to alignment.
174  * These fields are only inserted as a preparation for IPv6
175  * and are not used in the IPv4-only release. */
176         uint8_t sin_len;    /**< length of this structure. */
177         uint8_t sin_family; /**< FREERTOS_AF_INET. */
178         uint16_t sin_port;  /**< The port. */
179         uint32_t sin_addr;  /**< The IP address. */
180     };
181 
182 /* The socket type itself. */
183     struct xSOCKET;
184     typedef struct xSOCKET         * Socket_t;
185     typedef struct xSOCKET const   * ConstSocket_t;
186 
187     extern BaseType_t xSocketValid( const ConstSocket_t xSocket );
188 
189 /**
190  * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
191  * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
192  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html
193  */
194 
195 /* Common Socket Attributes. */
196 
197 /* Create a TCP or UDP socket. */
198     Socket_t FreeRTOS_socket( BaseType_t xDomain,
199                               BaseType_t xType,
200                               BaseType_t xProtocol );
201 
202 /* Binds a socket to a local port number. */
203     BaseType_t FreeRTOS_bind( Socket_t xSocket,
204                               struct freertos_sockaddr const * pxAddress,
205                               socklen_t xAddressLength );
206 
207 /* Sets a socket option. */
208     BaseType_t FreeRTOS_setsockopt( Socket_t xSocket,
209                                     int32_t lLevel,
210                                     int32_t lOptionName,
211                                     const void * pvOptionValue,
212                                     size_t uxOptionLength );
213 
214 /* Close a socket. */
215     BaseType_t FreeRTOS_closesocket( Socket_t xSocket );
216 
217     #if ( ipconfigSUPPORT_SIGNALS != 0 )
218 /* Send a signal to the task which is waiting for a given socket. */
219         BaseType_t FreeRTOS_SignalSocket( Socket_t xSocket );
220 
221 /* Send a signal to the task which reads from this socket (FromISR version). */
222         BaseType_t FreeRTOS_SignalSocketFromISR( Socket_t xSocket,
223                                                  BaseType_t * pxHigherPriorityTaskWoken );
224     #endif
225 
226 /* End Common Socket Attributes */
227 
228 
229 /* UDP Socket Attributes. */
230 
231 /* Send data to a UDP socket. */
232     int32_t FreeRTOS_sendto( Socket_t xSocket,
233                              const void * pvBuffer,
234                              size_t uxTotalDataLength,
235                              BaseType_t xFlags,
236                              const struct freertos_sockaddr * pxDestinationAddress,
237                              socklen_t xDestinationAddressLength );
238 
239 /* Receive data from a UDP socket */
240     int32_t FreeRTOS_recvfrom( const ConstSocket_t xSocket,
241                                void * pvBuffer,
242                                size_t uxBufferLength,
243                                BaseType_t xFlags,
244                                struct freertos_sockaddr * pxSourceAddress,
245                                const socklen_t * pxSourceAddressLength );
246 
247 
248 /* Function to get the local address and IP port. */
249     size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket,
250                                      struct freertos_sockaddr * pxAddress );
251 
252     #if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
253 /* Returns true if an UDP socket exists bound to mentioned port number. */
254         BaseType_t xPortHasUDPSocket( uint16_t usPortNr );
255     #endif
256 
257 /* End UDP Socket Attributes */
258 
259 
260     #if ( ipconfigUSE_TCP == 1 )
261 
262 /* TCP Socket Attributes. */
263 
264 /**
265  * Structure to hold the properties of Tx/Rx buffers and windows.
266  */
267         typedef struct xWIN_PROPS
268         {
269             /* Properties of the Tx buffer and Tx window. */
270             int32_t lTxBufSize; /**< Unit: bytes. */
271             int32_t lTxWinSize; /**< Unit: MSS. */
272 
273             /* Properties of the Rx buffer and Rx window. */
274             int32_t lRxBufSize; /**< Unit: bytes. */
275             int32_t lRxWinSize; /**< Unit: MSS. */
276         } WinProperties_t;
277 
278 /**
279  * Structure to pass for the 'FREERTOS_SO_SET_LOW_HIGH_WATER' option.
280  */
281         typedef struct xLOW_HIGH_WATER
282         {
283             size_t uxLittleSpace; /**< Send a STOP when buffer space drops below X bytes */
284             size_t uxEnoughSpace; /**< Send a GO when buffer space grows above X bytes */
285         } LowHighWater_t;
286 
287 /* Connect a TCP socket to a remote socket. */
288         BaseType_t FreeRTOS_connect( Socket_t xClientSocket,
289                                      const struct freertos_sockaddr * pxAddress,
290                                      socklen_t xAddressLength );
291 
292 /* Places a TCP socket into a state where it is listening for and can accept
293  * incoming connection requests from remote sockets. */
294         BaseType_t FreeRTOS_listen( Socket_t xSocket,
295                                     BaseType_t xBacklog );
296 
297 /* Accept a connection on a TCP socket. */
298         Socket_t FreeRTOS_accept( Socket_t xServerSocket,
299                                   struct freertos_sockaddr * pxAddress,
300                                   socklen_t * pxAddressLength );
301 
302 /* Send data to a TCP socket. */
303         BaseType_t FreeRTOS_send( Socket_t xSocket,
304                                   const void * pvBuffer,
305                                   size_t uxDataLength,
306                                   BaseType_t xFlags );
307 
308 /* Receive data from a TCP socket */
309         BaseType_t FreeRTOS_recv( Socket_t xSocket,
310                                   void * pvBuffer,
311                                   size_t uxBufferLength,
312                                   BaseType_t xFlags );
313 
314 /* Disable reads and writes on a connected TCP socket. */
315         BaseType_t FreeRTOS_shutdown( Socket_t xSocket,
316                                       BaseType_t xHow );
317 
318         #if ( ipconfigUSE_TCP == 1 )
319 
320 /* Release a TCP payload buffer that was obtained by
321  * calling FreeRTOS_recv() with the FREERTOS_ZERO_COPY flag,
322  * and a pointer to a void pointer. */
323             BaseType_t FreeRTOS_ReleaseTCPPayloadBuffer( Socket_t xSocket,
324                                                          void const * pvBuffer,
325                                                          BaseType_t xByteCount );
326         #endif /* ( ipconfigUSE_TCP == 1 ) */
327 
328 /* Returns the number of bytes available in the Rx buffer. */
329         BaseType_t FreeRTOS_rx_size( ConstSocket_t xSocket );
330 
331         #define FreeRTOS_recvcount( xSocket )    FreeRTOS_rx_size( xSocket )
332 
333 /* Returns the free space in the Tx buffer. */
334         BaseType_t FreeRTOS_tx_space( ConstSocket_t xSocket );
335 
336         #define FreeRTOS_outstanding( xSocket )    FreeRTOS_tx_size( xSocket )
337 
338 /* Returns the number of bytes stored in the Tx buffer. */
339         BaseType_t FreeRTOS_tx_size( ConstSocket_t xSocket );
340 
341 /* Returns pdTRUE if TCP socket is connected. */
342         BaseType_t FreeRTOS_issocketconnected( ConstSocket_t xSocket );
343 
344 /* Return the remote address and IP port of a connected TCP Socket. */
345         BaseType_t FreeRTOS_GetRemoteAddress( ConstSocket_t xSocket,
346                                               struct freertos_sockaddr * pxAddress );
347 
348 /* Returns the number of bytes that may be added to txStream. */
349         BaseType_t FreeRTOS_maywrite( ConstSocket_t xSocket );
350 
351 /* Returns the actual size of MSS being used. */
352         BaseType_t FreeRTOS_mss( ConstSocket_t xSocket );
353 
354 /* For internal use only: return the connection status. */
355         BaseType_t FreeRTOS_connstatus( ConstSocket_t xSocket );
356 
357 /* For advanced applications only:
358  * Get a direct pointer to the circular transmit buffer.
359  * '*pxLength' will contain the number of bytes that may be written. */
360         uint8_t * FreeRTOS_get_tx_head( ConstSocket_t xSocket,
361                                         BaseType_t * pxLength );
362 
363 /* For the web server: borrow the circular Rx buffer for inspection
364  * HTML driver wants to see if a sequence of 13/10/13/10 is available. */
365         const struct xSTREAM_BUFFER * FreeRTOS_get_rx_buf( ConstSocket_t xSocket );
366 
367         void FreeRTOS_netstat( void );
368 
369 
370 /* End TCP Socket Attributes. */
371 
372     #endif /* ( ipconfigUSE_TCP == 1 ) */
373 
374     #if ( ipconfigUSE_CALLBACKS == 1 )
375 
376 /*
377  * Callback handlers for a socket
378  * User-provided functions will be called for each sockopt callback defined
379  * For example:
380  * static void xOnTCPConnect( Socket_t xSocket, BaseType_t ulConnected ) {}
381  * static BaseType_t xOnTCPReceive( Socket_t xSocket, void * pData, size_t uxLength )
382  * {
383  *     // handle the message
384  *     return pdFALSE; // Not Used
385  * }
386  * static void xOnTCPSent( Socket_t xSocket, size_t xLength ) {}
387  * static BaseType_t xOnUDPReceive( Socket_t xSocket, void * pData, size_t xLength, const struct freertos_sockaddr * pxFrom, const struct freertos_sockaddr * pxDest )
388  * {
389  *     // handle the message
390  *     return pdTRUE; // message processing is finished, don't store
391  * }
392  * static void xOnUDPSent( Socket_t xSocket, size_t xLength ) {}
393  * F_TCP_UDP_Handler_t xHand = { xOnTCPConnect, xOnTCPReceive, xOnTCPSent, xOnUDPReceive, xOnUDPSent };
394  * FreeRTOS_setsockopt( sock, 0, FREERTOS_SO_TCP_CONN_HANDLER, ( void * ) &xHand, 0 );
395  */
396 
397 /* Connected callback handler for a TCP Socket. */
398         typedef void (* FOnConnected_t )( Socket_t xSocket,
399                                           BaseType_t ulConnected );
400 
401 /* Received callback handler for a TCP Socket.
402  * Return value is not currently used. */
403         typedef BaseType_t (* FOnTCPReceive_t )( Socket_t xSocket,
404                                                  void * pData,
405                                                  size_t xLength );
406 
407 /* Sent callback handler for a TCP Socket. */
408         typedef void (* FOnTCPSent_t )( Socket_t xSocket,
409                                         size_t xLength );
410 
411 /* Received callback handler for a UDP Socket.
412  * If a positive number is returned, the messages will not be stored in
413  * xWaitingPacketsList for later processing by recvfrom(). */
414         typedef BaseType_t (* FOnUDPReceive_t ) ( Socket_t xSocket,
415                                                   void * pData,
416                                                   size_t xLength,
417                                                   const struct freertos_sockaddr * pxFrom,
418                                                   const struct freertos_sockaddr * pxDest );
419 
420 /* Sent callback handler for a UDP Socket */
421         typedef void (* FOnUDPSent_t )( Socket_t xSocket,
422                                         size_t xLength );
423 
424 /* The following values are used in the lOptionName parameter of setsockopt()
425  * to set the callback handlers options. */
426         typedef struct xTCP_UDP_HANDLER
427         {
428             FOnConnected_t pxOnTCPConnected; /* FREERTOS_SO_TCP_CONN_HANDLER */
429             FOnTCPReceive_t pxOnTCPReceive;  /* FREERTOS_SO_TCP_RECV_HANDLER */
430             FOnTCPSent_t pxOnTCPSent;        /* FREERTOS_SO_TCP_SENT_HANDLER */
431             FOnUDPReceive_t pxOnUDPReceive;  /* FREERTOS_SO_UDP_RECV_HANDLER */
432             FOnUDPSent_t pxOnUDPSent;        /* FREERTOS_SO_UDP_SENT_HANDLER */
433         } F_TCP_UDP_Handler_t;
434 
435     #endif /* ( ipconfigUSE_CALLBACKS == 1 ) */
436 
437 /* Conversion Functions */
438 
439 /* Converts an IP address expressed as a 32-bit number in network byte order
440  * to a string in decimal dot notation. */
441     extern const char * FreeRTOS_inet_ntoa( uint32_t ulIPAddress,
442                                             char * pcBuffer );
443 
444     #if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
445 
446 /* Converts an IP address expressed as four separate numeric octets into an
447  * IP address expressed as a 32-bit number in network byte order */
448         #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
449     ( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) |                                  \
450       ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) |                                  \
451       ( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) |                                   \
452       ( ( uint32_t ) ( ucOctet0 ) ) )
453 
454     #else /* ( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN ) */
455 
456         #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
457     ( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) |                                  \
458       ( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) |                                  \
459       ( ( ( uint32_t ) ( ucOctet2 ) ) << 8UL ) |                                   \
460       ( ( uint32_t ) ( ucOctet3 ) ) )
461 
462     #endif /* ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
463 
464 /* Convert a null-terminated string in dot-decimal-notation (d.d.d.d)
465  * to a 32-bit unsigned integer. */
466     uint32_t FreeRTOS_inet_addr( const char * pcIPAddress );
467 
468     BaseType_t FreeRTOS_inet_pton( BaseType_t xAddressFamily,
469                                    const char * pcSource,
470                                    void * pvDestination );
471 
472     const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily,
473                                      const void * pvSource,
474                                      char * pcDestination,
475                                      socklen_t uxSize );
476 
477     BaseType_t FreeRTOS_inet_pton4( const char * pcSource,
478                                     void * pvDestination );
479 
480     const char * FreeRTOS_inet_ntop4( const void * pvSource,
481                                       char * pcDestination,
482                                       socklen_t uxSize );
483 
484 /** @brief This function converts a human readable string, representing an 48-bit MAC address,
485  * into a 6-byte address. Valid inputs are e.g. "62:48:5:83:A0:b2" and "0-12-34-fe-dc-ba". */
486     BaseType_t FreeRTOS_EUI48_pton( const char * pcSource,
487                                     uint8_t * pucTarget );
488 
489 /** @brief This function converts a 48-bit MAC address to a human readable string. */
490     void FreeRTOS_EUI48_ntop( const uint8_t * pucSource,
491                               char * pcTarget,
492                               char cTen,
493                               char cSeparator );
494 
495 /* End Conversion Functions */
496 
497     #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
498 
499 /* The SocketSet_t type is the equivalent to the fd_set type used by the
500  * Berkeley API. */
501         struct xSOCKET_SET;
502         typedef struct xSOCKET_SET         * SocketSet_t;
503         typedef struct xSOCKET_SET const   * ConstSocketSet_t;
504 
505 /* Create a socket set for use with the FreeRTOS_select() function */
506         SocketSet_t FreeRTOS_CreateSocketSet( void );
507 
508         void FreeRTOS_DeleteSocketSet( SocketSet_t xSocketSet );
509 
510 /* Block on a "socket set" until an event of interest occurs on a
511  * socket within the set. */
512         BaseType_t FreeRTOS_select( SocketSet_t xSocketSet,
513                                     TickType_t xBlockTimeTicks );
514 
515 /* For FD_SET and FD_CLR, a combination of the following bits can be used: */
516         typedef enum eSELECT_EVENT
517         {
518             eSELECT_READ = 0x0001,
519             eSELECT_WRITE = 0x0002,
520             eSELECT_EXCEPT = 0x0004,
521             eSELECT_INTR = 0x0008,
522             eSELECT_ALL = 0x000F,
523             /* Reserved for internal use: */
524             eSELECT_CALL_IP = 0x0010,
525             /* end */
526         } eSelectEvent_t;
527 
528 /* Add a socket to a socket set, and set the event bits of interest
529  * for the added socket. */
530         void FreeRTOS_FD_SET( Socket_t xSocket,
531                               SocketSet_t xSocketSet,
532                               EventBits_t xBitsToSet );
533 
534 /* Clear a set event bit of interest for a socket of the socket set.
535  * If all the event bits are clear then the socket will be removed
536  * from the socket set. */
537         void FreeRTOS_FD_CLR( Socket_t xSocket,
538                               SocketSet_t xSocketSet,
539                               EventBits_t xBitsToClear );
540 
541 /* Check if a socket in a socket set has an event bit set. */
542         EventBits_t FreeRTOS_FD_ISSET( const ConstSocket_t xSocket,
543                                        const ConstSocketSet_t xSocketSet );
544 
545     #endif /* ( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) */
546 
547     #ifdef __cplusplus
548         } /* extern "C" */
549     #endif
550 
551 #endif /* FREERTOS_SOCKETS_H */
552