diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index f775f6cec..19a50bafd 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -118,12 +118,12 @@ /* * Create the DHCP socket, if it has not been created already. */ - _static void prvCreateDHCPSocket( const NetworkEndPoint_t * pxEndPoint ); + _static void prvCreateDHCPSocket( NetworkEndPoint_t * pxEndPoint ); /* * Close the DHCP socket, only when not in use anymore (i.e. xDHCPSocketUserCount = 0). */ - static void prvCloseDHCPSocket( const NetworkEndPoint_t * pxEndPoint ); + static void prvCloseDHCPSocket( NetworkEndPoint_t * pxEndPoint ); static void vDHCPProcessEndPoint( BaseType_t xReset, BaseType_t xDoCheck, @@ -214,20 +214,20 @@ FreeRTOS_debug_printf( ( "DHCP wrong state: expect: %d got: %d : ignore\n", EP_DHCPData.eExpectedState, EP_DHCPData.eDHCPState ) ); } - else if( xDHCPv4Socket != NULL ) /* If there is a socket, check for incoming messages first. */ + else if( EP_DHCPData.xDHCPSocket != NULL ) /* If there is a socket, check for incoming messages first. */ { /* No need to initialise 'pucUDPPayload', it just looks nicer. */ uint8_t * pucUDPPayload = NULL; const DHCPMessage_IPv4_t * pxDHCPMessage; int32_t lBytes; - while( xDHCPv4Socket != NULL ) + while( EP_DHCPData.xDHCPSocket != NULL ) { BaseType_t xRecvFlags = FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK; NetworkEndPoint_t * pxIterator = NULL; /* Peek the next UDP message. */ - lBytes = FreeRTOS_recvfrom( xDHCPv4Socket, &( pucUDPPayload ), 0, xRecvFlags, NULL, NULL ); + lBytes = FreeRTOS_recvfrom( EP_DHCPData.xDHCPSocket, &( pucUDPPayload ), 0, xRecvFlags, NULL, NULL ); if( lBytes < ( ( int32_t ) sizeof( DHCPMessage_IPv4_t ) ) ) { @@ -282,7 +282,7 @@ { /* Target not found, fetch the message and delete it. */ /* PAss the address of a pointer pucUDPPayload, because zero-copy is used. */ - lBytes = FreeRTOS_recvfrom( xDHCPv4Socket, &( pucUDPPayload ), 0, FREERTOS_ZERO_COPY, NULL, NULL ); + lBytes = FreeRTOS_recvfrom( EP_DHCPData.xDHCPSocket, &( pucUDPPayload ), 0, FREERTOS_ZERO_COPY, NULL, NULL ); if( ( lBytes > 0 ) && ( pucUDPPayload != NULL ) ) { @@ -305,6 +305,20 @@ } } +/** + * @brief Stop the DHCP process. Close the DHCP socket when it's no longer used by any end-point. + * + * @param[in] pxEndPoint The end-point for which we want to stop the DHCP process. + */ + void vDHCPStop( struct xNetworkEndPoint * pxEndPoint ) + { + /* Disable the DHCP timer. */ + vIPSetDHCP_RATimerEnableState( pxEndPoint, pdFALSE ); + + /* Close socket to ensure packets don't queue on it. */ + prvCloseDHCPSocket( pxEndPoint ); + } + /** * @brief Called by vDHCPProcessEndPoint(), this function handles the state 'eWaitingOffer'. * If there is a reply, it will be examined, if there is a time-out, there may be a new @@ -564,7 +578,7 @@ #endif /* ipconfigUSE_DHCP_HOOK */ { /* See if prvInitialiseDHCP() has creates a socket. */ - if( xDHCPv4Socket == NULL ) + if( EP_DHCPData.xDHCPSocket == NULL ) { xGivingUp = pdTRUE; } @@ -618,7 +632,7 @@ /* Resend the request at the appropriate time to renew the lease. */ prvCreateDHCPSocket( pxEndPoint ); - if( xDHCPv4Socket != NULL ) + if( EP_DHCPData.xDHCPSocket != NULL ) { uint32_t ulID = 0U; @@ -829,11 +843,13 @@ * using it. * @param[in] pxEndPoint The end-point that stops using the socket. */ - static void prvCloseDHCPSocket( const NetworkEndPoint_t * pxEndPoint ) + void prvCloseDHCPSocket( NetworkEndPoint_t * pxEndPoint ) { - ( void ) pxEndPoint; - - if( ( xDHCPv4Socket != NULL ) && ( xDHCPSocketUserCount > 0 ) ) + if( ( EP_DHCPData.xDHCPSocket == NULL ) || ( EP_DHCPData.xDHCPSocket != xDHCPv4Socket ) ) + { + /* the socket can not be closed. */ + } + else if( xDHCPSocketUserCount > 0 ) { xDHCPSocketUserCount--; @@ -844,6 +860,8 @@ ( void ) vSocketClose( xDHCPv4Socket ); xDHCPv4Socket = NULL; } + + EP_DHCPData.xDHCPSocket = NULL; } else { @@ -862,13 +880,17 @@ * @brief Create a DHCP socket with the defined timeouts. The same socket * will be shared among all end-points that need DHCP. */ - _static void prvCreateDHCPSocket( const NetworkEndPoint_t * pxEndPoint ) + _static void prvCreateDHCPSocket( NetworkEndPoint_t * pxEndPoint ) { struct freertos_sockaddr xAddress; BaseType_t xReturn; TickType_t xTimeoutTime = ( TickType_t ) 0; - if( xDHCPv4Socket == NULL ) /* Create the socket, if it has not already been created. */ + if( ( xDHCPv4Socket != NULL ) && ( EP_DHCPData.xDHCPSocket == xDHCPv4Socket ) ) + { + /* the socket is still valid. */ + } + else if( xDHCPv4Socket == NULL ) /* Create the socket, if it has not already been created. */ { xDHCPv4Socket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); configASSERT( xSocketValid( xDHCPv4Socket ) == pdTRUE ); @@ -883,10 +905,14 @@ ( void ) FreeRTOS_setsockopt( xDHCPv4Socket, 0, FREERTOS_SO_RCVTIMEO, &( xTimeoutTime ), sizeof( TickType_t ) ); ( void ) FreeRTOS_setsockopt( xDHCPv4Socket, 0, FREERTOS_SO_SNDTIMEO, &( xTimeoutTime ), sizeof( TickType_t ) ); + memset( &xAddress, 0, sizeof( xAddress ) ); + xAddress.sin_family = FREERTOS_AF_INET4; + xAddress.sin_len = ( uint8_t ) sizeof( xAddress ); /* Bind to the standard DHCP client port. */ xAddress.sin_port = ( uint16_t ) dhcpCLIENT_PORT_IPv4; xReturn = vSocketBind( xDHCPv4Socket, &xAddress, sizeof( xAddress ), pdFALSE ); xDHCPSocketUserCount = 1; + EP_DHCPData.xDHCPSocket = xDHCPv4Socket; FreeRTOS_printf( ( "DHCP-socket[%02x-%02x]: DHCP Socket Create\n", pxEndPoint->xMACAddress.ucBytes[ 4 ], pxEndPoint->xMACAddress.ucBytes[ 5 ] ) ); @@ -901,11 +927,13 @@ { /* Change to NULL for easier testing. */ xDHCPv4Socket = NULL; + EP_DHCPData.xDHCPSocket = NULL; } } else { xDHCPSocketUserCount++; + EP_DHCPData.xDHCPSocket = xDHCPv4Socket; } FreeRTOS_printf( ( "prvCreateDHCPSocket[%02x-%02x]: %s, user count %d\n", @@ -1248,7 +1276,7 @@ ( void ) memset( &( xSet ), 0, sizeof( xSet ) ); /* Passing the address of a pointer (pucUDPPayload) because FREERTOS_ZERO_COPY is used. */ - lBytes = FreeRTOS_recvfrom( xDHCPv4Socket, &pucUDPPayload, 0U, FREERTOS_ZERO_COPY, NULL, NULL ); + lBytes = FreeRTOS_recvfrom( EP_DHCPData.xDHCPSocket, &pucUDPPayload, 0U, FREERTOS_ZERO_COPY, NULL, NULL ); if( lBytes > 0 ) { @@ -1504,10 +1532,7 @@ &( uxOptionsLength ), pxEndPoint ); - /* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ - /* coverity[misra_c_2012_rule_11_4_violation] */ - if( ( xSocketValid( xDHCPv4Socket ) == pdTRUE ) && ( pucUDPPayloadBuffer != NULL ) ) + if( ( xSocketValid( EP_DHCPData.xDHCPSocket ) == pdTRUE ) && ( pucUDPPayloadBuffer != NULL ) ) { /* Copy in the IP address being requested. */ @@ -1528,9 +1553,9 @@ FreeRTOS_debug_printf( ( "vDHCPProcess: reply %xip\n", ( unsigned ) FreeRTOS_ntohl( EP_DHCPData.ulOfferedIPAddress ) ) ); iptraceSENDING_DHCP_REQUEST(); - xDHCPv4Socket->pxEndPoint = pxEndPoint; + EP_DHCPData.xDHCPSocket->pxEndPoint = pxEndPoint; - if( FreeRTOS_sendto( xDHCPv4Socket, pucUDPPayloadBuffer, sizeof( DHCPMessage_IPv4_t ) + uxOptionsLength, FREERTOS_ZERO_COPY, &xAddress, ( socklen_t ) sizeof( xAddress ) ) == 0 ) + if( FreeRTOS_sendto( EP_DHCPData.xDHCPSocket, pucUDPPayloadBuffer, sizeof( DHCPMessage_IPv4_t ) + uxOptionsLength, FREERTOS_ZERO_COPY, &xAddress, ( socklen_t ) sizeof( xAddress ) ) == 0 ) { /* The packet was not successfully queued for sending and must be * returned to the stack. */ @@ -1579,7 +1604,7 @@ /* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */ /* coverity[misra_c_2012_rule_11_4_violation] */ - if( ( xSocketValid( xDHCPv4Socket ) == pdTRUE ) && ( pucUDPPayloadBuffer != NULL ) ) + if( ( xSocketValid( EP_DHCPData.xDHCPSocket ) == pdTRUE ) && ( pucUDPPayloadBuffer != NULL ) ) { const void * pvCopySource; void * pvCopyDest; @@ -1608,9 +1633,9 @@ uxOptionsLength -= dhcpOPTION_50_SIZE; } - xDHCPv4Socket->pxEndPoint = pxEndPoint; + EP_DHCPData.xDHCPSocket->pxEndPoint = pxEndPoint; - if( FreeRTOS_sendto( xDHCPv4Socket, + if( FreeRTOS_sendto( EP_DHCPData.xDHCPSocket, pucUDPPayloadBuffer, sizeof( DHCPMessage_IPv4_t ) + uxOptionsLength, FREERTOS_ZERO_COPY, diff --git a/source/FreeRTOS_DHCPv6.c b/source/FreeRTOS_DHCPv6.c index a416fedb1..ad946f0a1 100644 --- a/source/FreeRTOS_DHCPv6.c +++ b/source/FreeRTOS_DHCPv6.c @@ -464,6 +464,20 @@ void vDHCPv6Process( BaseType_t xReset, vDHCPv6ProcessEndPoint( xReset, pxEndPoint, pxEndPoint->pxDHCPMessage ); } } + +/** + * @brief Stop the DHCP process. Close the DHCP socket when it's no longer used by any end-point. + * + * @param[in] pxEndPoint The end-point for which we want to stop the DHCP process. + */ +void vDHCPv6Stop( struct xNetworkEndPoint * pxEndPoint ) +{ + /* Disable the DHCP timer. */ + vIPSetDHCP_RATimerEnableState( pxEndPoint, pdFALSE ); + + /* Close socket to ensure packets don't queue on it. */ + prvCloseDHCPv6Socket( pxEndPoint ); +} /*-----------------------------------------------------------*/ /** diff --git a/source/FreeRTOS_IP_Timers.c b/source/FreeRTOS_IP_Timers.c index 709c9e5b8..0e2259ac5 100644 --- a/source/FreeRTOS_IP_Timers.c +++ b/source/FreeRTOS_IP_Timers.c @@ -57,8 +57,8 @@ #include "FreeRTOS_DNS.h" /*-----------------------------------------------------------*/ -/** @brief 'xAllNetworksUp' becomes pdTRUE as soon as all network interfaces have - * been initialised. */ +/** @brief 'xAllNetworksUp' becomes pdTRUE when all network interfaces are initialised + * and becomes pdFALSE when any network interface goes down. */ /* MISRA Ref 8.9.1 [File scoped variables] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-89 */ /* coverity[misra_c_2012_rule_8_9_violation] */ @@ -328,7 +328,7 @@ void vCheckNetworkTimers( void ) } } - xAllNetworksUp = xUp; + vSetAllNetworksUp( xUp ); } } } @@ -604,3 +604,12 @@ void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ) #endif /* ipconfigDNS_USE_CALLBACKS == 1 */ /*-----------------------------------------------------------*/ + +/** + * @brief Mark whether all interfaces are up or at least one interface is down. + * If all interfaces are up, the 'xNetworkTimer' will not be checked. + */ +void vSetAllNetworksUp( BaseType_t xIsAllNetworksUp ) +{ + xAllNetworksUp = xIsAllNetworksUp; +} diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 7c115fe67..f9d50158b 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -861,6 +861,31 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface ) * treat network down as a "delivery problem" and flush the ARP cache for this * interface. */ FreeRTOS_ClearARP( pxEndPoint ); + + #if ( ipconfigUSE_DHCP == 1 ) + if( END_POINT_USES_DHCP( pxEndPoint ) ) + { + #if ( ( ipconfigUSE_DHCPv6 != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) + if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED ) + { + vDHCPv6Stop( pxEndPoint ); + } + else + #endif /* (( ipconfigUSE_DHCPv6 != 0 ) && ( ipconfigUSE_IPv6 != 0 )) */ + { + /* Stop the DHCP process for this end-point. */ + vDHCPStop( pxEndPoint ); + } + } + #endif /* ( ipconfigUSE_DHCP == 1 ) */ + + #if ( ( ipconfigUSE_RA != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) + if( END_POINT_USES_RA( pxEndPoint ) ) + { + /* Stop the RA/SLAAC process for this end-point. */ + vIPSetDHCP_RATimerEnableState( pxEndPoint, pdFALSE ); + } + #endif /* ( (ipconfigUSE_RA != 0) && ( ipconfigUSE_IPv6 != 0 )) */ } /* The network has been disconnected (or is being initialised for the first @@ -936,7 +961,10 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface ) } else { - /* Nothing to do. When the 'xNetworkTimer' expires, all interfaces + /* At least one interface is down. */ + vSetAllNetworksUp( pdFALSE ); + + /* Nothing else to do. When the 'xNetworkTimer' expires, all interfaces * with bits.bInterfaceUp cleared will get a new 'eNetworkDownEvent' */ } } diff --git a/source/include/FreeRTOS_DHCP.h b/source/include/FreeRTOS_DHCP.h index bc1eeb6d6..4dc21daff 100644 --- a/source/include/FreeRTOS_DHCP.h +++ b/source/include/FreeRTOS_DHCP.h @@ -237,6 +237,12 @@ eDHCPState_t eGetDHCPState( const struct xNetworkEndPoint * pxEndPoint ); void vDHCPProcess( BaseType_t xReset, struct xNetworkEndPoint * pxEndPoint ); +/* + * NOT A PUBLIC API FUNCTION. + * It will be called when the network interface, that the endpoint is associated with, goes down. + */ +void vDHCPStop( struct xNetworkEndPoint * pxEndPoint ); + /* Internal call: returns true if socket is the current DHCP socket */ BaseType_t xIsDHCPSocket( const ConstSocket_t xSocket ); diff --git a/source/include/FreeRTOS_DHCPv6.h b/source/include/FreeRTOS_DHCPv6.h index b3537d970..70bbd7ddf 100644 --- a/source/include/FreeRTOS_DHCPv6.h +++ b/source/include/FreeRTOS_DHCPv6.h @@ -152,6 +152,12 @@ void vDHCPv6Process( BaseType_t xReset, struct xNetworkEndPoint * pxEndPoint ); +/* + * NOT A PUBLIC API FUNCTION. + * It will be called when the network interface, that the endpoint is associated with, goes down. + */ + void vDHCPv6Stop( struct xNetworkEndPoint * pxEndPoint ); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/source/include/FreeRTOS_IP_Private.h b/source/include/FreeRTOS_IP_Private.h index 1c97d5c89..3d4ee932d 100644 --- a/source/include/FreeRTOS_IP_Private.h +++ b/source/include/FreeRTOS_IP_Private.h @@ -882,6 +882,9 @@ BaseType_t xIsCallingFromIPTask( void ); /* Send the network-up event and start the ARP timer. */ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint ); +/* Mark whether all interfaces are up or at least one interface is down. */ +void vSetAllNetworksUp( BaseType_t xIsAllNetworksUp ); + /* *INDENT-OFF* */ #ifdef __cplusplus } /* extern "C" */ diff --git a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c index 10021d8c4..db482595c 100644 --- a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c +++ b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c @@ -46,6 +46,8 @@ #include "cbmc.h" +#include "../../utility/memory_assignments.c" + /* Static members defined in FreeRTOS_DHCP.c */ extern DHCPData_t xDHCPData; extern Socket_t xDHCPv4Socket; @@ -135,6 +137,15 @@ void FreeRTOS_ReleaseUDPPayloadBuffer( void * pvBuffer ) free( ( ( ( uint8_t * ) pvBuffer ) - ( ipUDP_PAYLOAD_OFFSET_IPv4 + ipIP_TYPE_OFFSET ) ) ); } +/* Abstraction of FreeRTOS_socket. Return NULL or valid socket handler. */ +Socket_t FreeRTOS_socket( BaseType_t xDomain, + BaseType_t xType, + BaseType_t xProtocol ) +{ + return ensure_FreeRTOS_Socket_t_is_allocated(); +} + + /**************************************************************** * The proof of vDHCPProcess ****************************************************************/ @@ -166,6 +177,7 @@ void harness() NetworkEndPoint_t * pxNetworkEndPoint_Temp = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); __CPROVER_assume( pxNetworkEndPoint_Temp != NULL ); pxNetworkEndPoint_Temp->pxNext = NULL; + pxNetworkEndPoint_Temp->xDHCPData.xDHCPSocket = NULL; /**************************************************************** * Initialize the counter used to bound the number of times @@ -176,6 +188,8 @@ void harness() GetNetworkBuffer_failure_count = 0; #endif + xDHCPv4Socket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); + /**************************************************************** * Assume a valid socket in most states of the DHCP state machine. * @@ -189,7 +203,5 @@ void harness() prvCreateDHCPSocket( pxNetworkEndPoint_Temp ); } - xDHCPv4Socket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - __CPROVER_file_local_FreeRTOS_DHCP_c_vDHCPProcessEndPoint( xReset, xDoCheck, pxNetworkEndPoint_Temp ); } diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c index 3c5f6c870..0ce4d385e 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c @@ -347,6 +347,14 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ socklen_t * pxSourceAddressLength, int callbacks ) { + NetworkEndPoint_t * pxIterator = pxNetworkEndPoints; + + while( pxIterator != NULL ) + { + pxIterator->xDHCPData.xDHCPSocket = NULL; + pxIterator = pxIterator->pxNext; + } + if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; @@ -358,7 +366,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE; ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF ); - xDHCPv4Socket = NULL; return xSizeofUDPBuffer; } @@ -371,8 +378,13 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ int callbacks ) { int32_t lBytes = 0; + NetworkEndPoint_t * pxIterator = pxNetworkEndPoints; - xDHCPv4Socket = NULL; + while( pxIterator != NULL ) + { + pxIterator->xDHCPData.xDHCPSocket = NULL; + pxIterator = pxIterator->pxNext; + } if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) { @@ -402,7 +414,13 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ socklen_t * pxSourceAddressLength, int callbacks ) { - xDHCPv4Socket = NULL; + NetworkEndPoint_t * pxIterator = pxNetworkEndPoints; + + while( pxIterator != NULL ) + { + pxIterator->xDHCPData.xDHCPSocket = NULL; + pxIterator = pxIterator->pxNext; + } if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) { @@ -430,6 +448,14 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ socklen_t * pxSourceAddressLength, int callbacks ) { + NetworkEndPoint_t * pxIterator = pxNetworkEndPoints; + + while( pxIterator != NULL ) + { + pxIterator->xDHCPData.xDHCPSocket = NULL; + pxIterator = pxIterator->pxNext; + } + if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; @@ -441,7 +467,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE; ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF ); - xDHCPv4Socket = NULL; return xSizeofUDPBuffer; } @@ -453,6 +478,14 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ socklen_t * pxSourceAddressLength, int callbacks ) { + NetworkEndPoint_t * pxIterator = pxNetworkEndPoints; + + while( pxIterator != NULL ) + { + pxIterator->xDHCPData.xDHCPSocket = NULL; + pxIterator = pxIterator->pxNext; + } + if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; @@ -464,7 +497,6 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREQUEST_OPCODE; ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF ); - xDHCPv4Socket = NULL; return xSizeofUDPBuffer; } diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c index f6b20ecb9..bba25d176 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c @@ -128,6 +128,7 @@ void test_vDHCPProcess_ResetAndInvalidSocket( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put any state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = 0; @@ -157,6 +158,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithRNGSuccessSocketCreationFail( v { /* This should get assigned to a given value. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put any state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = i; @@ -184,6 +186,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithRNGSuccessSocketCreationFail( v * the DHCP the state machine. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.xUseBroadcast ); /* This should be reset as well */ TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.ulOfferedIPAddress ); @@ -202,6 +205,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithRNGSuccessSocketSuccess( void ) { /* This should get assigned to a given value. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put any state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = i; @@ -235,6 +239,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithRNGSuccessSocketSuccess( void ) * the DHCP the state machine. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.xUseBroadcast ); /* This should be reset as well */ TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.ulOfferedIPAddress ); @@ -253,6 +258,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithRNGSuccessSocketBindFail( void { /* This should remain unchanged. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put any state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = i; @@ -295,6 +301,7 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithSocketAlreadyCreated( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put any state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = i; @@ -321,7 +328,8 @@ void test_vDHCPProcess_ResetAndIncorrectStateWithSocketAlreadyCreated( void ) /* Expected state is incorrect, but we are trying to reset * the DHCP the state machine. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); - TEST_ASSERT_EQUAL( xDHCPv4Socket, &xTestSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.xUseBroadcast ); /* This should be reset as well */ TEST_ASSERT_EQUAL( 0, pxEndPoint->xDHCPData.ulOfferedIPAddress ); @@ -338,6 +346,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookFailsDHCPSocketNULL( void ) /* The DHCP socket is NULL. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -360,6 +369,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookFailsDHCPSocketNULL( void ) /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that the Endpoint IP address pointer indicates that. */ @@ -375,6 +385,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookFailsDHCPSocketNonNULL( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -404,6 +415,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookFailsDHCPSocketNonNULL( void ) /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that the local IP address pointer indicates that. */ @@ -418,6 +430,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookDefaultReturn( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -449,6 +462,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookDefaultReturn( void ) /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that the network addressing struct is updated to show that. */ @@ -466,6 +480,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNotNULLButGNW /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -490,6 +505,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNotNULLButGNW /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); } @@ -502,6 +518,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNotNULLButHos /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -526,6 +543,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNotNULLButHos /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); } @@ -536,6 +554,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNULL( void ) /* This should remain unchanged. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -555,6 +574,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnDHCPSocketNULL( void ) /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we are not using leased address. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); } @@ -567,6 +587,8 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsNoBroadcast( v /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; + xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -599,6 +621,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsNoBroadcast( v /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be as expected. */ @@ -613,6 +636,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsNoBroadcast_NU /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -645,6 +669,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsNoBroadcast_NU /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be as expected. */ @@ -660,6 +685,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsUseBroadCast( /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -692,6 +718,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendFailsUseBroadCast( /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingSendFirstDiscover, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be as expected. */ @@ -707,6 +734,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendSucceedsUseBroadCas /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -738,6 +766,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendSucceedsUseBroadCas /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be as expected. */ @@ -756,6 +785,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendSucceedsUseBroadCas /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingSendFirstDiscover; pxEndPoint->xDHCPData.eExpectedState = eWaitingSendFirstDiscover; @@ -787,6 +817,7 @@ void test_vDHCPProcess_CorrectStateDHCPHookContinueReturnSendSucceedsUseBroadCas /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be as expected. */ @@ -804,6 +835,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWFails( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = eSendDHCPRequest; @@ -822,6 +854,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWFails( void ) /* DHCP socket should be NULL */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eSendDHCPRequest, pxEndPoint->xDHCPData.eDHCPState ); } @@ -834,6 +867,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWSucceedsSendFails( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = eSendDHCPRequest; @@ -856,6 +890,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWSucceedsSendFails( void ) /* DHCP socket should be still allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eSendDHCPRequest, pxEndPoint->xDHCPData.eDHCPState ); } @@ -870,6 +905,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWSucceedsSendSucceeds( void /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eSendDHCPRequest; pxEndPoint->xDHCPData.eExpectedState = eSendDHCPRequest; @@ -892,6 +928,7 @@ void test_vDHCPProcess_eSendDHCPRequestCorrectStateGNWSucceedsSendSucceeds( void /* DHCP socket should be still allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( xTimeValue, pxEndPoint->xDHCPData.xDHCPTxTime ); @@ -907,6 +944,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -927,6 +965,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsNoTimeout( void ) /* DHCP socket should be still allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -940,6 +979,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutGiveUp( void ) /* prvClo /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -977,6 +1017,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutGiveUp( void ) /* prvClo /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eGetLinkLayerAddress, pxEndPoint->xDHCPData.eDHCPState ); } @@ -990,6 +1031,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGFail( void /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1014,6 +1056,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGFail( void /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); /* make sure that the period is increased by a factor of two. */ @@ -1029,6 +1072,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGPassUseBroa /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1065,6 +1109,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGPassUseBroa /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); /* make sure that the period is increased by a factor of two. */ @@ -1080,6 +1125,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGPassNoBroad /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1114,6 +1160,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromFailsTimeoutDontGiveUpRNGPassNoBroad /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eInitialWait, pxEndPoint->xDHCPData.eDHCPState ); /* make sure that the period is increased by a factor of two. */ @@ -1133,6 +1180,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1163,45 +1211,6 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage( void ) TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); } -void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_NullEndPoint( void ) -{ - struct xSOCKET xTestSocket; - NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - uint8_t * pucUDPPayload; - - /* This should remain unchanged. */ - xDHCPv4Socket = &xTestSocket; - xDHCPSocketUserCount = 1; - /* Put the required state. */ - pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; - pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; - pxEndPoint->xDHCPData.ulTransactionId = 0x01ABCDEF; - - /* Make sure that the local IP address is uninitialised. */ - pxEndPoint->ipv4_settings.ulIPAddress = 0; - /* Put a verifiable value. */ - memset( &pxEndPoint->ipv4_settings, 0xAA, sizeof( IPV4Parameters_t ) ); - /* Put a verifiable value. */ - memset( &pxEndPoint->ipv4_defaults, 0xBB, sizeof( IPV4Parameters_t ) ); - - pxNetworkEndPoints = NULL; - - /* Expect these arguments. */ - FreeRTOS_recvfrom_Stub( FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage ); - - FreeRTOS_ReleaseUDPPayloadBuffer_Expect( pucUDPBuffer ); - - FreeRTOS_IsEndPointUp_IgnoreAndReturn( pdFALSE ); - - /* Expect the DHCP timer to be reloaded. */ - vDHCP_RATimerReload_Expect( &xEndPoint, pdMS_TO_TICKS( 5000U ) ); - - vDHCPProcess( pdFALSE, pxEndPoint ); - - /* Still in this phase. */ - TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); -} - void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TransactionIDMismatch( void ) { struct xSOCKET xTestSocket; @@ -1211,6 +1220,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_Transacti /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1252,6 +1262,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TwoFlagOp /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1289,6 +1300,7 @@ void test_vDHCPProcess_eLeasedAddress_CorrectState_ValidBytesInMessage_TwoFlagOp /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1326,6 +1338,7 @@ void test_vDHCPProcess_eLeasedAddress_IncorrectDHCPCookie_ValidBytesInMessage( v /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1365,6 +1378,7 @@ void test_vDHCPProcess_eLeasedAddress_IncorrectOpCode_ValidBytesInMessage( void /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; pxEndPoint->xDHCPData.eExpectedState = eLeasedAddress; @@ -1409,6 +1423,7 @@ void test_vDHCPProcess_eWaitingOffer_CorrectState_ValidBytesInMessage_MatchingEn /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1449,6 +1464,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_CorrectState_ValidBytesInMessage_diff /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1478,6 +1494,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_CorrectState_ValidBytesInMessage_diff memset( &pxEndPoint_2->ipv4_defaults, 0xAA, sizeof( IPV4Parameters_t ) ); pxNetworkEndPoints = pxEndPoint_2; + pxEndPoint_2->pxNext = pxEndPoint; pxEndPoint->xDHCPData.xDHCPTxTime = 100; pxEndPoint->xDHCPData.xDHCPTxPeriod = 100; @@ -1502,6 +1519,7 @@ void test_vDHCPProcessEndPoint_NullEndPoint( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1530,6 +1548,7 @@ void test_vDHCPProcessEndPoint_eWaitingOfferNullUDPBuffer( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1559,6 +1578,7 @@ void test_vDHCPProcessEndPoint_eWaitingOfferDHCPReply_NullUDPmessage( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1588,6 +1608,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsFalseCookieNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1614,6 +1635,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsFalseCookieNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1627,6 +1649,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsFalseOpcodeNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1652,6 +1675,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsFalseOpcodeNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1665,6 +1689,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsCorrectCookieAndOpcodeNoTime /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1692,6 +1717,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSucceedsCorrectCookieAndOpcodeNoTime /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1705,6 +1731,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromLessBytesNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1732,6 +1759,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromLessBytesNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1745,6 +1773,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccessCorrectTxID( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1772,6 +1801,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccessCorrectTxID( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1785,6 +1815,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrType( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1812,6 +1843,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrType( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1825,6 +1857,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_BroadcastAddr /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1850,6 +1883,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_BroadcastAddr /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1863,6 +1897,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_LocalHostAddr /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1890,6 +1925,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_LocalHostAddr /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1903,6 +1939,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_NonLocalHostA /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1930,6 +1967,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_NonLocalHostA /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1944,6 +1982,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_LocalMACNotma /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -1977,6 +2016,7 @@ void test_vDHCPProcess_eWaitingOfferRecvfromSuccess_CorrectAddrLen_LocalMACNotma /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -1999,6 +2039,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageWithoutOptionsNoTimeout( v /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2026,6 +2067,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageWithoutOptionsNoTimeout( v /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2062,6 +2104,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageIncorrectOptionsNoTimeout( /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2089,6 +2132,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageIncorrectOptionsNoTimeout( /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2126,6 +2170,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageMissingLengthByteNoTimeout /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2153,6 +2198,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageMissingLengthByteNoTimeout /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2192,6 +2238,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageIncorrectLengthByteNoTimeo /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2219,6 +2266,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageIncorrectLengthByteNoTimeo /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2260,6 +2308,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetNACKNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2287,6 +2336,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetNACKNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2328,6 +2378,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetNACKNoTimeout_MatchingM /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2357,6 +2408,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetNACKNoTimeout_MatchingM /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2398,6 +2450,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetACKNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2425,6 +2478,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageGetACKNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2466,6 +2520,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageOneOptionNoTimeout( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2494,6 +2549,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageOneOptionNoTimeout( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2535,6 +2591,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageOneOptionNoTimeout2( void /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2562,6 +2619,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageOneOptionNoTimeout2( void /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that we still in the state from where we started. */ TEST_ASSERT_EQUAL( eWaitingOffer, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2619,6 +2677,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendFails( void /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2655,6 +2714,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendFails( void /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that sending failed. */ TEST_ASSERT_EQUAL( eSendDHCPRequest, pxEndPoint->xDHCPData.eDHCPState ); } @@ -2714,6 +2774,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendSucceeds( vo /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2751,6 +2812,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendSucceeds( vo /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that sending failed. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); /* The time should be updated. */ @@ -2814,6 +2876,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnDe /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2848,6 +2911,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnDe /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that sending failed. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL_MEMORY( &( pxEndPoint->ipv4_settings ), &( pxEndPoint->ipv4_defaults ), sizeof( IPV4Parameters_t ) ); @@ -2911,6 +2975,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnEr /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingOffer; pxEndPoint->xDHCPData.eExpectedState = eWaitingOffer; @@ -2946,6 +3011,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnEr /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* The state should indicate that sending failed. */ TEST_ASSERT_EQUAL( eNotUsingLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL_MEMORY( &( pxEndPoint->ipv4_settings ), &( testMemory ), sizeof( IPV4Parameters_t ) ); @@ -3008,6 +3074,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerNoTimeout( vo /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3031,6 +3098,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerNoTimeout( vo /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Still waiting on acknowledge. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL_MEMORY( &( pxEndPoint->ipv4_settings ), &( testMemory ), sizeof( IPV4Parameters_t ) ); @@ -3091,6 +3159,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBfai /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3121,6 +3190,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBfai /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Still waiting on acknowledge. */ TEST_ASSERT_EQUAL( eSendDHCPRequest, pxEndPoint->xDHCPData.eDHCPState ); /* The time value should be stored in the state machine. */ @@ -3180,6 +3250,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBSuc /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3216,6 +3287,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBSuc /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Still waiting on acknowledge. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( xTimeValue, pxEndPoint->xDHCPData.xDHCPTxTime ); @@ -3273,6 +3345,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3298,6 +3371,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Period exceeded. We should now be in initial state. */ TEST_ASSERT_EQUAL( eInitialWait, pxEndPoint->xDHCPData.eDHCPState ); /* Period exceeded, should have initial value */ @@ -3356,6 +3430,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3381,6 +3456,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Period exceeded. We should now be in initial state. */ /* Period exceeded, should have initial value */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); @@ -3440,6 +3516,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeZero( /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3481,6 +3558,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeZero( /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); } @@ -3539,6 +3617,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeLessTh /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3578,6 +3657,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeLessTh /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( dhcpMINIMUM_LEASE_TIME, pxEndPoint->xDHCPData.ulLeaseTime ); @@ -3636,6 +3716,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_CorrectServer_AptLeaseTime /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3673,6 +3754,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_CorrectServer_AptLeaseTime /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -3732,6 +3814,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_NACK( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3760,6 +3843,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_NACK( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be reset after NACK. */ TEST_ASSERT_EQUAL( eInitialWait, pxEndPoint->xDHCPData.eDHCPState ); } @@ -3817,6 +3901,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_OFFER( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3845,6 +3930,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_OFFER( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should not be reset after OFFER. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); } @@ -3949,6 +4035,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -3986,6 +4073,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4093,6 +4181,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4130,6 +4219,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4238,6 +4328,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4275,6 +4366,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4382,6 +4474,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4419,6 +4512,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4526,6 +4620,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4563,6 +4658,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4670,6 +4766,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4707,6 +4804,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4786,6 +4884,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4823,6 +4922,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -4901,6 +5001,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -4938,6 +5039,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -5023,6 +5125,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -5060,6 +5163,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -5155,6 +5259,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -5192,6 +5297,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) /* DHCP socket should be unallocated */ TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should now be using leased address. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); /* Make sure that this is not changed. */ @@ -5286,6 +5392,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -5359,6 +5466,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectLengthOfPacket( void ) /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eWaitingAcknowledge; pxEndPoint->xDHCPData.eExpectedState = eWaitingAcknowledge; @@ -5399,6 +5507,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectLengthOfPacket( void ) /* DHCP socket should be allocated */ TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint->xDHCPData.xDHCPSocket ); /* Should still be stuck in waiting for ack state. */ TEST_ASSERT_EQUAL( eWaitingAcknowledge, pxEndPoint->xDHCPData.eDHCPState ); } @@ -5417,6 +5526,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_NoARPIPClash( void ) xARPHadIPClash = pdFALSE; xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; xTaskGetTickCount_ExpectAndReturn( pxEndPoint->xDHCPData.xDHCPTxPeriod + pxEndPoint->xDHCPData.xDHCPTxTime + 100 ); @@ -5441,6 +5551,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_ARPIPClash( void ) /* prvPre /* This should be nullified. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; xARPHadIPClash = pdTRUE; @@ -5457,6 +5568,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_ARPIPClash( void ) /* prvPre TEST_ASSERT_EQUAL( eGetLinkLayerAddress, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); } void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_ARPIPClash_NoSocketInUse( void ) /* prvPrepareLinkLayerIPLookUp + prvCloseDHCPSocket */ @@ -5473,6 +5585,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_ARPIPClash_NoSocketInUse( vo /* This should be nullified. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 0; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; xARPHadIPClash = pdTRUE; @@ -5503,6 +5616,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_Timeout_ARPIPClash_TwoSocketsInUse( /* This should be nullified. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 2; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; xARPHadIPClash = pdTRUE; @@ -5529,6 +5643,7 @@ void test_vDHCPProcess_eGetLinkLayerAddress_NoTimeout( void ) pxEndPoint->xDHCPData.eDHCPState = eGetLinkLayerAddress; pxEndPoint->xDHCPData.eExpectedState = eGetLinkLayerAddress; xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; xARPHadIPClash = pdTRUE; /* Make it so that there is no timeout. */ @@ -5569,6 +5684,7 @@ void test_vDHCPProcess_eLeasedAddress_NetworkUp_SocketCreated_RNGPass_GNBfail( v /* Socket is already created. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; @@ -5604,6 +5720,7 @@ void test_vDHCPProcess_eLeasedAddress_NetworkUp_SocketCreated_RNGFail( void ) /* Socket is already created. */ xDHCPv4Socket = &xTestSocket; xDHCPSocketUserCount = 1; + pxEndPoint->xDHCPData.xDHCPSocket = &xTestSocket; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; @@ -5639,6 +5756,7 @@ void test_vDHCPProcess_eLeasedAddress_NetworkUp_SocketNotCreated_RNGPass_GNBfail /* Socket not created. */ xDHCPv4Socket = NULL; + pxEndPoint->xDHCPData.xDHCPSocket = NULL; /* Put the required state. */ pxEndPoint->xDHCPData.eDHCPState = eLeasedAddress; @@ -5656,6 +5774,7 @@ void test_vDHCPProcess_eLeasedAddress_NetworkUp_SocketNotCreated_RNGPass_GNBfail /* Still here. */ TEST_ASSERT_EQUAL( eLeasedAddress, pxEndPoint->xDHCPData.eDHCPState ); TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint->xDHCPData.xDHCPSocket ); } void test_vDHCPProcess_eNotUsingLeasedAddress( void ) @@ -5689,6 +5808,104 @@ void test_vDHCPProcess_IncorrectState( void ) TEST_ASSERT_EQUAL( ( eNotUsingLeasedAddress << 1 ), pxEndPoint->xDHCPData.eDHCPState ); } +void test_vDHCPProcess_ResetWithRNGSuccessSocketSuccess_TwoEndPoints( void ) +{ + struct xSOCKET xTestSocket; + NetworkEndPoint_t xEndPoint_1 = { 0 }, * pxEndPoint_1 = &xEndPoint_1; + NetworkEndPoint_t xEndPoint_2 = { 0 }, * pxEndPoint_2 = &xEndPoint_2; + + /* Socket not created. */ + xDHCPv4Socket = NULL; + pxEndPoint_1->xDHCPData.xDHCPSocket = NULL; + pxEndPoint_2->xDHCPData.xDHCPSocket = NULL; + + /* Make random number generation pass. */ + xApplicationGetRandomNumber_ExpectAndReturn( &( pxEndPoint_1->xDHCPData.ulTransactionId ), pdTRUE ); + /* Return a valid socket. */ + FreeRTOS_socket_ExpectAndReturn( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP, &xTestSocket ); + + xSocketValid_ExpectAnyArgsAndReturn( pdTRUE ); + xSocketValid_ExpectAnyArgsAndReturn( pdTRUE ); + + /* Ignore the inputs to setting the socket options. */ + FreeRTOS_setsockopt_ExpectAnyArgsAndReturn( pdPASS ); + FreeRTOS_setsockopt_ExpectAnyArgsAndReturn( pdPASS ); + /* Make sure that binding passes. Return zero. */ + vSocketBind_ExpectAnyArgsAndReturn( 0 ); + /* See if the timer is reloaded. */ + vDHCP_RATimerReload_Expect( &xEndPoint_1, dhcpINITIAL_TIMER_PERIOD ); + + vDHCPProcess( pdTRUE, pxEndPoint_1 ); + + TEST_ASSERT_EQUAL( 1, xDHCPSocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_1->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint_2->xDHCPData.xDHCPSocket ); + + /* Make random number generation pass. */ + xApplicationGetRandomNumber_ExpectAndReturn( &( pxEndPoint_2->xDHCPData.ulTransactionId ), pdTRUE ); + + /* See if the timer is reloaded. */ + vDHCP_RATimerReload_Expect( &xEndPoint_2, dhcpINITIAL_TIMER_PERIOD ); + + vDHCPProcess( pdTRUE, pxEndPoint_2 ); + + TEST_ASSERT_EQUAL( 2, xDHCPSocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_1->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_2->xDHCPData.xDHCPSocket ); +} + +void test_vDHCPStop( void ) +{ + struct xSOCKET xTestSocket; + NetworkEndPoint_t xEndPoint_1 = { 0 }, * pxEndPoint_1 = &xEndPoint_1; + NetworkEndPoint_t xEndPoint_2 = { 0 }, * pxEndPoint_2 = &xEndPoint_2; + NetworkEndPoint_t xEndPoint_3 = { 0 }, * pxEndPoint_3 = &xEndPoint_3; + + /* Socket is already created. */ + xDHCPv4Socket = &xTestSocket; + + /* 2 end-points opened the socket */ + xDHCPSocketUserCount = 2; + pxEndPoint_1->xDHCPData.xDHCPSocket = FREERTOS_INVALID_SOCKET; + pxEndPoint_2->xDHCPData.xDHCPSocket = &xTestSocket; + pxEndPoint_3->xDHCPData.xDHCPSocket = &xTestSocket; + + /* Stop DHCP for end-point 1 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_1, pdFALSE ); + + vDHCPStop( pxEndPoint_1 ); + + TEST_ASSERT_EQUAL( 2, xDHCPSocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( FREERTOS_INVALID_SOCKET, pxEndPoint_1->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_2->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_3->xDHCPData.xDHCPSocket ); + + /* Stop DHCP for end-point 2 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_2, pdFALSE ); + + vDHCPStop( pxEndPoint_2 ); + + TEST_ASSERT_EQUAL( 1, xDHCPSocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint_2->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_3->xDHCPData.xDHCPSocket ); + + /* Stop DHCP for end-point 3 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_3, pdFALSE ); + + /* Expect the socket to be closed. */ + vSocketClose_ExpectAndReturn( &xTestSocket, NULL ); + + vDHCPStop( pxEndPoint_3 ); + + TEST_ASSERT_EQUAL( 0, xDHCPSocketUserCount ); + TEST_ASSERT_EQUAL( NULL, xDHCPv4Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint_3->xDHCPData.xDHCPSocket ); +} + /* * @brief Check static function , in case of malformed packet , where length byte is zero. */ diff --git a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c index 7a1136b5d..86e6a7f00 100644 --- a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c +++ b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c @@ -59,6 +59,8 @@ #define TEST_DHCPv6_DEFAULT_DUID_LENGTH ( 14U ) #define TEST_DHCPv6_DIFFERENT_DUID_LENGTH ( 12U ) +extern BaseType_t xDHCPv6SocketUserCount; + extern void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint ); extern void prvCloseDHCPv6Socket( NetworkEndPoint_t * pxEndPoint ); extern const char * prvStateName( eDHCPState_t eState ); @@ -3994,3 +3996,53 @@ void test_vDHCPv6Process_AdvertiseStatusFail() * Then change the state to eWaitingAcknowledge. */ TEST_ASSERT_EQUAL( eWaitingOffer, xEndPoint.xDHCPData.eDHCPState ); } + +void test_vDHCPv6Stop( void ) +{ + struct xSOCKET xTestSocket; + NetworkEndPoint_t xEndPoint_1 = { 0 }, * pxEndPoint_1 = &xEndPoint_1; + NetworkEndPoint_t xEndPoint_2 = { 0 }, * pxEndPoint_2 = &xEndPoint_2; + NetworkEndPoint_t xEndPoint_3 = { 0 }, * pxEndPoint_3 = &xEndPoint_3; + + /* Socket is already created. */ + xDHCPv6Socket = &xTestSocket; + + /* 2 end-points opened the socket */ + xDHCPv6SocketUserCount = 2; + pxEndPoint_1->xDHCPData.xDHCPSocket = FREERTOS_INVALID_SOCKET; + pxEndPoint_2->xDHCPData.xDHCPSocket = &xTestSocket; + pxEndPoint_3->xDHCPData.xDHCPSocket = &xTestSocket; + + /* Stop DHCP for end-point 1 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_1, pdFALSE ); + + vDHCPv6Stop( pxEndPoint_1 ); + + TEST_ASSERT_EQUAL( 2, xDHCPv6SocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv6Socket ); + TEST_ASSERT_EQUAL( FREERTOS_INVALID_SOCKET, pxEndPoint_1->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_2->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_3->xDHCPData.xDHCPSocket ); + + /* Stop DHCP for end-point 2 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_2, pdFALSE ); + + vDHCPv6Stop( pxEndPoint_2 ); + + TEST_ASSERT_EQUAL( 1, xDHCPv6SocketUserCount ); + TEST_ASSERT_EQUAL( &xTestSocket, xDHCPv6Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint_2->xDHCPData.xDHCPSocket ); + TEST_ASSERT_EQUAL( &xTestSocket, pxEndPoint_3->xDHCPData.xDHCPSocket ); + + /* Stop DHCP for end-point 3 */ + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint_3, pdFALSE ); + + /* Expect the socket to be closed. */ + vSocketClose_ExpectAndReturn( &xTestSocket, NULL ); + + vDHCPv6Stop( pxEndPoint_3 ); + + TEST_ASSERT_EQUAL( 0, xDHCPv6SocketUserCount ); + TEST_ASSERT_EQUAL( NULL, xDHCPv6Socket ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint_3->xDHCPData.xDHCPSocket ); +} diff --git a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c index 24e8df276..2de291f11 100644 --- a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c +++ b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c @@ -482,6 +482,8 @@ void test_prvProcessNetworkDownEvent_Pass( void ) FreeRTOS_ClearARP_ExpectAnyArgs(); + vDHCPStop_Expect( &xEndPoint ); + vDHCPProcess_Expect( pdTRUE, &xEndPoint ); prvProcessNetworkDownEvent( &xInterfaces[ 0 ] ); @@ -497,6 +499,8 @@ void test_prvProcessNetworkDownEvent_Pass( void ) FreeRTOS_ClearARP_Expect( &xEndPoint ); + vDHCPStop_Expect( &xEndPoint ); + vDHCPProcess_Expect( pdTRUE, &xEndPoint ); prvProcessNetworkDownEvent( &xInterfaces[ 0 ] ); @@ -575,6 +579,10 @@ void test_prvProcessNetworkDownEvent_InterfaceInitFail( void ) FreeRTOS_ClearARP_ExpectAnyArgs(); + vDHCPStop_Expect( &xEndPoint ); + + vSetAllNetworksUp_Expect( pdFALSE ); + prvProcessNetworkDownEvent( &xInterface ); } @@ -601,6 +609,8 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void ) FreeRTOS_ClearARP_ExpectAnyArgs(); + vDHCPv6Stop_Expect( &xEndPoint ); + vDHCPv6Process_Expect( pdTRUE, &xEndPoint ); prvProcessNetworkDownEvent( &xInterface ); @@ -629,6 +639,8 @@ void test_prvProcessNetworkDownEvent_PassRA( void ) FreeRTOS_ClearARP_ExpectAnyArgs(); + vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint, pdFALSE ); + vRAProcess_Expect( pdTRUE, &xEndPoint ); prvProcessNetworkDownEvent( &xInterface ); diff --git a/test/unit-test/FreeRTOS_IP_Utils_DiffConfig/FreeRTOS_IP_Utils_DiffConfig_utest.c b/test/unit-test/FreeRTOS_IP_Utils_DiffConfig/FreeRTOS_IP_Utils_DiffConfig_utest.c index bf39c69ae..8a19cad36 100644 --- a/test/unit-test/FreeRTOS_IP_Utils_DiffConfig/FreeRTOS_IP_Utils_DiffConfig_utest.c +++ b/test/unit-test/FreeRTOS_IP_Utils_DiffConfig/FreeRTOS_IP_Utils_DiffConfig_utest.c @@ -104,6 +104,8 @@ void test_prvProcessNetworkDownEvent_Pass_DHCP_Enabled( void ) FreeRTOS_ClearARP_Expect( &xEndPoint ); + vDHCPStop_Expect( &xEndPoint ); + FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL ); xInterface.pfInitialise = xNetworkInterfaceInitialise_test;