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