/*\r
- * FreeRTOS+TCP V2.0.7\r
+ * FreeRTOS+TCP V2.0.11\r
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a copy of\r
\r
/* Test if a socket it bound which means it is either included in\r
xBoundUDPSocketsList or xBoundTCPSocketsList */\r
-#define socketSOCKET_IS_BOUND( pxSocket ) ( listLIST_ITEM_CONTAINER( & ( pxSocket )->xBoundSocketListItem ) != NULL )\r
+#define socketSOCKET_IS_BOUND( pxSocket ) ( listLIST_ITEM_CONTAINER( & ( pxSocket )->xBoundSocketListItem ) != NULL )\r
\r
/* If FreeRTOS_sendto() is called on a socket that is not bound to a port\r
number then, depending on the FreeRTOSIPConfig.h settings, it might be that a\r
port number is automatically generated for the socket. Automatically generated\r
port numbers will be between socketAUTO_PORT_ALLOCATION_START_NUMBER and\r
-0xffff. \r
+0xffff.\r
\r
Per https://tools.ietf.org/html/rfc6056, "the dynamic ports consist of the range\r
-49152-65535. However, ephemeral port selection algorithms should use the whole \r
+49152-65535. However, ephemeral port selection algorithms should use the whole\r
range 1024-65535" excluding those already in use (inbound or outbound). */\r
#if !defined( socketAUTO_PORT_ALLOCATION_START_NUMBER )\r
#define socketAUTO_PORT_ALLOCATION_START_NUMBER ( ( uint16_t ) 0x0400 )\r
\r
BaseType_t vNetworkSocketsInit( void )\r
{\r
- vListInitialise( &xBoundUDPSocketsList );\r
+ vListInitialise( &xBoundUDPSocketsList );\r
\r
- #if( ipconfigUSE_TCP == 1 )\r
- {\r
- vListInitialise( &xBoundTCPSocketsList );\r
- }\r
- #endif /* ipconfigUSE_TCP == 1 */\r
+ #if( ipconfigUSE_TCP == 1 )\r
+ {\r
+ vListInitialise( &xBoundTCPSocketsList );\r
+ }\r
+ #endif /* ipconfigUSE_TCP == 1 */\r
\r
- return pdTRUE;\r
+ return pdTRUE;\r
}\r
/*-----------------------------------------------------------*/\r
\r
if( xType != FREERTOS_SOCK_DGRAM )\r
{\r
xReturn = pdFAIL;\r
- configASSERT( xReturn );\r
+ configASSERT( xReturn );\r
}\r
/* In case a UDP socket is created, do not allocate space for TCP data. */\r
*pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xUDP );\r
if( xType != FREERTOS_SOCK_STREAM )\r
{\r
xReturn = pdFAIL;\r
- configASSERT( xReturn );\r
+ configASSERT( xReturn );\r
}\r
\r
*pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xTCP );\r
else\r
{\r
xReturn = pdFAIL;\r
- configASSERT( xReturn );\r
+ configASSERT( xReturn );\r
}\r
}\r
/* In case configASSERT() is not used */\r
listSET_LIST_ITEM_OWNER( &( pxSocket->xBoundSocketListItem ), ( void * ) pxSocket );\r
\r
pxSocket->xReceiveBlockTime = ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME;\r
- pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME;\r
+ pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME;\r
pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT;\r
- pxSocket->ucProtocol = ( uint8_t ) xProtocol; /* protocol: UDP or TCP */\r
+ pxSocket->ucProtocol = ( uint8_t ) xProtocol; /* protocol: UDP or TCP */\r
\r
#if( ipconfigUSE_TCP == 1 )\r
{\r
{\r
/* StreamSize is expressed in number of bytes */\r
/* Round up buffer sizes to nearest multiple of MSS */\r
- pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ipconfigTCP_MSS;\r
+ pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ipconfigTCP_MSS;\r
pxSocket->u.xTCP.uxRxStreamSize = ( size_t ) ipconfigTCP_RX_BUFFER_LENGTH;\r
pxSocket->u.xTCP.uxTxStreamSize = ( size_t ) FreeRTOS_round_up( ipconfigTCP_TX_BUFFER_LENGTH, ipconfigTCP_MSS );\r
/* Use half of the buffer size of the TCP windows */\r
{\r
if( pxAddress->sin_port == 0u )\r
{\r
- pxAddress->sin_port = prvGetPrivatePortNumber( ( BaseType_t )pxSocket->ucProtocol ); \r
- if( 0 == pxAddress->sin_port )\r
- {\r
- return -pdFREERTOS_ERRNO_EADDRNOTAVAIL;\r
- }\r
+ pxAddress->sin_port = prvGetPrivatePortNumber( ( BaseType_t )pxSocket->ucProtocol );\r
+ if( 0 == pxAddress->sin_port )\r
+ {\r
+ return -pdFREERTOS_ERRNO_EADDRNOTAVAIL;\r
+ }\r
}\r
\r
/* If vSocketBind() is called from the API FreeRTOS_bind() it has been\r
/* Find an available port number per https://tools.ietf.org/html/rfc6056. */\r
static uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol )\r
{\r
-const uint16_t usEphemeralPortCount = \r
- socketAUTO_PORT_ALLOCATION_MAX_NUMBER - socketAUTO_PORT_ALLOCATION_START_NUMBER + 1;\r
-uint16_t usIterations = usEphemeralPortCount; \r
+const uint16_t usEphemeralPortCount =\r
+ socketAUTO_PORT_ALLOCATION_MAX_NUMBER - socketAUTO_PORT_ALLOCATION_START_NUMBER + 1;\r
+uint16_t usIterations = usEphemeralPortCount;\r
uint32_t ulRandomSeed = 0;\r
uint16_t usResult = 0;\r
BaseType_t xGotZeroOnce = pdFALSE;\r
/* Avoid compiler warnings if ipconfigUSE_TCP is not defined. */\r
( void ) xProtocol;\r
\r
- /* Find the next available port using the random seed as a starting \r
- point. */\r
- do\r
- {\r
- /* Generate a random seed. */\r
- ulRandomSeed = ipconfigRAND32( );\r
-\r
- /* Only proceed if the random number generator succeeded. */\r
- if( 0 == ulRandomSeed )\r
- {\r
- if( pdFALSE == xGotZeroOnce )\r
- {\r
- xGotZeroOnce = pdTRUE;\r
- continue;\r
- }\r
- else\r
- {\r
- break;\r
- }\r
- }\r
-\r
- /* Map the random to a candidate port. */\r
- usResult =\r
- socketAUTO_PORT_ALLOCATION_START_NUMBER +\r
- ( ( ( uint16_t )ulRandomSeed ) % usEphemeralPortCount );\r
-\r
- /* Check if there's already an open socket with the same protocol\r
- and port. */\r
- if( NULL == pxListFindListItemWithValue( \r
- pxList, \r
- ( TickType_t )FreeRTOS_htons( usResult ) ) )\r
- {\r
- usResult = FreeRTOS_htons( usResult );\r
- break;\r
- }\r
- else\r
- {\r
- usResult = 0;\r
- }\r
-\r
- usIterations--;\r
- }\r
- while( usIterations > 0 );\r
- \r
- return usResult;\r
-} \r
+ /* Find the next available port using the random seed as a starting\r
+ point. */\r
+ do\r
+ {\r
+ /* Generate a random seed. */\r
+ ulRandomSeed = ipconfigRAND32( );\r
+\r
+ /* Only proceed if the random number generator succeeded. */\r
+ if( 0 == ulRandomSeed )\r
+ {\r
+ if( pdFALSE == xGotZeroOnce )\r
+ {\r
+ xGotZeroOnce = pdTRUE;\r
+ continue;\r
+ }\r
+ else\r
+ {\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* Map the random to a candidate port. */\r
+ usResult =\r
+ socketAUTO_PORT_ALLOCATION_START_NUMBER +\r
+ ( ( ( uint16_t )ulRandomSeed ) % usEphemeralPortCount );\r
+\r
+ /* Check if there's already an open socket with the same protocol\r
+ and port. */\r
+ if( NULL == pxListFindListItemWithValue(\r
+ pxList,\r
+ ( TickType_t )FreeRTOS_htons( usResult ) ) )\r
+ {\r
+ usResult = FreeRTOS_htons( usResult );\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ usResult = 0;\r
+ }\r
+\r
+ usIterations--;\r
+ }\r
+ while( usIterations > 0 );\r
+\r
+ return usResult;\r
+}\r
/*-----------------------------------------------------------*/\r
\r
/* pxListFindListItemWithValue: find a list item in a bound socket list\r
}\r
else\r
{\r
- FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) );\r
+ FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) );\r
for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );\r
pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList );\r
pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )\r