Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Main to dev/IPv6_integration #931

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ prvtcppreparesend
prvtcpreturnpacket
prvtcpsendchallengeack
prvtcpsendloop
prvtcpsendcheck
prvtcpsendpacket
prvtcpsendrepeated
prvtcpsendreset
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@
}
else
{
/* There was a problem with the randomiser. */
FreeRTOS_debug_printf( ( "prvInitialiseDHCP: failed to generate a random Transaction ID\n" ) );
}
}
/*-----------------------------------------------------------*/
Expand Down
9 changes: 9 additions & 0 deletions source/FreeRTOS_Sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -4550,6 +4550,15 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
/* Go sleeping until a SEND or a CLOSE event is received. */
( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_SEND | ( EventBits_t ) eSOCKET_CLOSED,
pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );

xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength );

if( xByteCount < 0 )
{
/* In a meanwhile, the connection has dropped, stop iterating. */
break;
}

/* See if in a meanwhile there is space in the TX-stream. */
xByteCount = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream );
} /* while( xBytesLeft > 0 ) */
Expand Down
13 changes: 5 additions & 8 deletions source/include/FreeRTOS_IP_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,15 @@ BaseType_t xIPIsNetworkTaskReady( void );
{
struct
{
uint64_t ullAlignmentWord; /**< Increase the alignment of this union by adding a 64-bit variable. */
uint32_t ullAlignmentWord; /**< Increase the alignment of this union by adding a 32-bit variable. */
} a; /**< A struct to increase alignment. */
struct
{
/* The next field only serves to give 'ucLastPacket' a correct
* alignment of 8 + 2. See comments in FreeRTOS_IP.h */
* alignment of 4 + 2. See comments in FreeRTOS_IP.h */
uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
uint8_t ucLastPacket[ TCP_PACKET_SIZE ];
} u; /**< The structure to give an alignment of 8 + 2 */
} u; /**< The structure to give an alignment of 4 + 2 */
} LastTCPPacket_t;

/**
Expand Down Expand Up @@ -721,12 +721,9 @@ struct xSOCKET

union
{
IPUDPSocket_t xUDP; /**< Union member: UDP socket*/
IPUDPSocket_t xUDP; /**< Union member: UDP socket*/
#if ( ipconfigUSE_TCP == 1 )
IPTCPSocket_t xTCP; /**< Union member: TCP socket */

uint64_t ullTCPAlignment; /**< Make sure that xTCP is 8-bytes aligned by
* declaring a 64-bit variable in the same union */
IPTCPSocket_t xTCP; /**< Union member: TCP socket */
#endif /* ipconfigUSE_TCP */
}
u; /**< Union of TCP/UDP socket */
Expand Down
2 changes: 2 additions & 0 deletions source/portable/Compiler/CCS/pack_struct_end.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*
* Contains a semicolon to end the wrapped structure,
* and resets warnings that were supressed in pack_struct_start.h.
* It also pops the previously pushed alignment of 1 byte of the stack.
*/
;
#pragma pack(pop)
#pragma diag_pop
3 changes: 2 additions & 1 deletion source/portable/Compiler/CCS/pack_struct_start.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
*
* Also suppress an incorrect warning from the CCS compiler:
* error #1916-D: definition at end of file not followed by a semicolon or a declarator
* Pushes the struct alignment of packed.
*/
#pragma diag_push
#pragma diag_suppress=1916
#pragma pack(1)
#pragma pack(push, 1)
46 changes: 45 additions & 1 deletion test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ void test_FreeRTOS_send_LessSpaceInStreamBuffer_Timeout( void )
xIsCallingFromIPTask_ExpectAndReturn( pdFALSE );
vTaskSetTimeOutState_ExpectAnyArgs();
xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE );
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );

/* Second Iteration. No space still. */
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 0 );
Expand Down Expand Up @@ -1087,6 +1088,7 @@ void test_FreeRTOS_send_LessSpaceInStreamBuffer_EventuallySpaceAvailable( void )
xIsCallingFromIPTask_ExpectAndReturn( pdFALSE );
vTaskSetTimeOutState_ExpectAnyArgs();
xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE );
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );

/* Second Iteration. */
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 20 );
Expand Down Expand Up @@ -1130,6 +1132,7 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void )
xIsCallingFromIPTask_ExpectAndReturn( pdFALSE );
vTaskSetTimeOutState_ExpectAnyArgs();
xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE );
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );

/* Second Iteration. */
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 10 );
Expand All @@ -1140,6 +1143,7 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void )
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE );

xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE );
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );

/* Third iteration. No space still. */
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 0 );
Expand All @@ -1151,7 +1155,47 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void )
TEST_ASSERT_EQUAL( uxDataLength - 10, xReturn );
}

/**
/*
* @brief While waiting for space, the socket gets disconnected.
*/
void test_FreeRTOS_send_DisconnectionOccursDuringWait( void )
{
BaseType_t xReturn;
FreeRTOS_Socket_t xSocket;
uint8_t pvBuffer[ ipconfigTCP_MSS ];
size_t uxDataLength;
BaseType_t xFlags = 0;
StreamBuffer_t xLocalStreamBuffer;

memset( &xSocket, 0, sizeof( xSocket ) );
memset( pvBuffer, 0, ipconfigTCP_MSS );

xSocket.ucProtocol = FREERTOS_IPPROTO_TCP;
xSocket.u.xTCP.eTCPState = eESTABLISHED;
xSocket.u.xTCP.bits.bFinSent = pdFALSE_UNSIGNED;
xSocket.u.xTCP.txStream = &xLocalStreamBuffer;
xSocket.xSendBlockTime = 100;

uxDataLength = 100;
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, uxDataLength - 20 );
uxStreamBufferAdd_ExpectAndReturn( xSocket.u.xTCP.txStream, 0U, pvBuffer, uxDataLength - 20, uxDataLength - 20 );
xIsCallingFromIPTask_ExpectAndReturn( pdFALSE );
xSendEventToIPTask_ExpectAndReturn( eTCPTimerEvent, pdFALSE );
xIsCallingFromIPTask_ExpectAndReturn( pdFALSE );
vTaskSetTimeOutState_ExpectAnyArgs();
xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE );

/* Let `socketSOCKET_IS_BOUND()` return false, so that prvTCPSendCheck()
* returns en error, so that the loop is stopped. */
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( NULL );

xReturn = FreeRTOS_send( &xSocket, pvBuffer, uxDataLength, xFlags );

TEST_ASSERT_EQUAL( uxDataLength - 20, xReturn );
}

/*
* @brief IP task is calling send function with a NULL buffer. Also there are 20 bytes worth of space
* less in the stream buffer as the data length.
*/
Expand Down