TCP: Address MISRA rule 11.3 violations (Part 2) (#227)

This commit is contained in:
Aniruddha Kanhere 2020-08-31 09:49:43 -07:00 committed by GitHub
parent bcd5dec6c4
commit 7cb57324fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 41 deletions

View file

@ -618,7 +618,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
now, proceed to send the packet with the SYN flag. now, proceed to send the packet with the SYN flag.
prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if
the Ethernet address of the peer or the gateway is found. */ the Ethernet address of the peer or the gateway is found. */
pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) );
/* About to send a SYN packet. Call prvSetSynAckOptions() to set /* About to send a SYN packet. Call prvSetSynAckOptions() to set
the proper options: The size of MSS and whether SACK's are the proper options: The size of MSS and whether SACK's are
@ -743,7 +743,7 @@ NetworkBufferDescriptor_t xTempBuffer;
#endif #endif
{ {
/* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
pxIPHeader = &pxTCPPacket->xIPHeader; pxIPHeader = &pxTCPPacket->xIPHeader;
pxEthernetHeader = &pxTCPPacket->xEthernetHeader; pxEthernetHeader = &pxTCPPacket->xEthernetHeader;
@ -1051,7 +1051,7 @@ uint32_t ulInitialSequenceNumber = 0;
/* The MAC-address of the peer (or gateway) has been found, /* The MAC-address of the peer (or gateway) has been found,
* now prepare the initial TCP packet and some fields in the socket. Map * now prepare the initial TCP packet and some fields in the socket. Map
* the buffer onto the TCPPacket_t struct to easily access it's field. */ * the buffer onto the TCPPacket_t struct to easily access it's field. */
pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxSocket->u.xTCP.xPacket.u.ucLastPacket );
pxIPHeader = &pxTCPPacket->xIPHeader; pxIPHeader = &pxTCPPacket->xIPHeader;
/* reset the retry counter to zero. */ /* reset the retry counter to zero. */
@ -1145,7 +1145,7 @@ uint32_t ulInitialSequenceNumber = 0;
_static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) _static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{ {
size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer );
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) );
const TCPHeader_t * pxTCPHeader; const TCPHeader_t * pxTCPHeader;
const uint8_t *pucPtr; const uint8_t *pucPtr;
@ -1798,7 +1798,7 @@ int32_t lStreamPos;
} }
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
lDataLen = 0; lDataLen = 0;
lStreamPos = 0; lStreamPos = 0;
@ -1828,7 +1828,7 @@ int32_t lStreamPos;
/* Map the byte stream onto ProtocolHeaders_t struct for easy /* Map the byte stream onto ProtocolHeaders_t struct for easy
* access to the fields. */ * access to the fields. */
pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] ); pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] );
@ -2074,7 +2074,7 @@ int32_t lCount, lLength;
static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{ {
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags; uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
@ -2171,13 +2171,13 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData ) static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData )
{ {
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); const TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength; int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
/* Map the buffer onto an IPHeader_t struct for easy access to fields. */ /* Map the buffer onto an IPHeader_t struct for easy access to fields. */
const IPHeader_t *pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); const IPHeader_t *pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER; const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER;
uint16_t usLength; uint16_t usLength;
@ -2246,7 +2246,7 @@ static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, const uint8_t *pu
NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength ) NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength )
{ {
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@ -2324,7 +2324,7 @@ BaseType_t xResult = 0;
static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{ {
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@ -2387,7 +2387,7 @@ static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, const Netwo
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength ) uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{ {
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@ -2429,7 +2429,7 @@ BaseType_t xSendLength = 0;
if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN ) if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
{ {
/* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxLastHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxLastHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
/* Clear the SYN flag in lastPacket. */ /* Clear the SYN flag in lastPacket. */
@ -2507,7 +2507,7 @@ static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBuff
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength ) uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{ {
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@ -2671,7 +2671,7 @@ static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescrip
uint32_t ulReceiveLength, BaseType_t xByteCount ) uint32_t ulReceiveLength, BaseType_t xByteCount )
{ {
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@ -2816,7 +2816,7 @@ BaseType_t xSendLength = xByteCount;
static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer ) static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer )
{ {
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
BaseType_t xSendLength = 0; BaseType_t xSendLength = 0;
@ -3001,7 +3001,7 @@ static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNe
#else #else
{ {
/* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */
TCPPacket_t *pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); TCPPacket_t *pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
const uint32_t ulSendLength = ( uint32_t ) const uint32_t ulSendLength = ( uint32_t )
( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */ ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */
@ -3065,7 +3065,7 @@ BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxDescriptor )
NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor; NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor;
/* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
FreeRTOS_Socket_t *pxSocket; FreeRTOS_Socket_t *pxSocket;
uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags;
@ -3088,7 +3088,7 @@ const IPHeader_t *pxIPHeader;
else else
{ {
/* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */
pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress );
ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress );
@ -3296,7 +3296,7 @@ const IPHeader_t *pxIPHeader;
static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer ) static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
{ {
/* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
const TCPPacket_t * pxTCPPacket = ipPOINTER_CAST( const TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); const TCPPacket_t * pxTCPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
FreeRTOS_Socket_t *pxReturn = NULL; FreeRTOS_Socket_t *pxReturn = NULL;
uint32_t ulInitialSequenceNumber; uint32_t ulInitialSequenceNumber;
@ -3363,7 +3363,7 @@ uint32_t ulInitialSequenceNumber;
if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) ) if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) )
{ {
/* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */
const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
@ -3529,7 +3529,7 @@ TickType_t uxLocalPort = ( TickType_t ) FreeRTOS_htons( pxSocket->usLocalPort );
const ListItem_t *pxIterator; const ListItem_t *pxIterator;
FreeRTOS_Socket_t *pxFound; FreeRTOS_Socket_t *pxFound;
BaseType_t xResult = pdFALSE; BaseType_t xResult = pdFALSE;
const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); const ListItem_t *pxEndTCP = listGET_END_MARKER( &xBoundTCPSocketsList );
/* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one /* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one
who has access. */ who has access. */
@ -3539,7 +3539,7 @@ const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MAR
{ {
if( listGET_LIST_ITEM_VALUE( pxIterator ) == ( configLIST_VOLATILE TickType_t ) uxLocalPort ) if( listGET_LIST_ITEM_VALUE( pxIterator ) == ( configLIST_VOLATILE TickType_t ) uxLocalPort )
{ {
pxFound = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxFound = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( ( pxFound->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) ) if( ( pxFound->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
{ {
pxSocket->u.xTCP.pxPeerSocket = pxFound; pxSocket->u.xTCP.pxPeerSocket = pxFound;

View file

@ -55,6 +55,12 @@
#define winSRTT_DECREMENT_CURRENT 7 #define winSRTT_DECREMENT_CURRENT 7
#define winSRTT_CAP_mS 50 #define winSRTT_CAP_mS 50
static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPSegment_t )
{
return ( TCPSegment_t *)pvArgument;
}
#if( ipconfigUSE_TCP_WIN == 1 ) #if( ipconfigUSE_TCP_WIN == 1 )
#define xTCPWindowRxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdTRUE ) #define xTCPWindowRxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdTRUE )
@ -309,7 +315,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Insert a new list item into pxList, it does not sort the list, /* Insert a new list item into pxList, it does not sort the list,
but it puts the item just before xListEnd, so it will be the last item but it puts the item just before xListEnd, so it will be the last item
returned by listGET_HEAD_ENTRY() */ returned by listGET_HEAD_ENTRY() */
pxNewListItem->pxNext = ipPOINTER_CAST(struct xLIST_ITEM * configLIST_VOLATILE, pxWhere ); pxNewListItem->pxNext = ( struct xLIST_ITEM * configLIST_VOLATILE )pxWhere;
pxNewListItem->pxPrevious = pxWhere->pxPrevious; pxNewListItem->pxPrevious = pxWhere->pxPrevious;
pxWhere->pxPrevious->pxNext = pxNewListItem; pxWhere->pxPrevious->pxNext = pxNewListItem;
pxWhere->pxPrevious = pxNewListItem; pxWhere->pxPrevious = pxNewListItem;
@ -330,7 +336,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Allocate space for 'xTCPSegments' and store them in 'xSegmentList'. */ /* Allocate space for 'xTCPSegments' and store them in 'xSegmentList'. */
vListInitialise( &xSegmentList ); vListInitialise( &xSegmentList );
xTCPSegments = ipPOINTER_CAST( TCPSegment_t *, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) ); xTCPSegments = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) );
if( xTCPSegments == NULL ) if( xTCPSegments == NULL )
{ {
@ -348,8 +354,8 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
{ {
/* Could call vListInitialiseItem here but all data has been /* Could call vListInitialiseItem here but all data has been
nulled already. Set the owner to a segment descriptor. */ nulled already. Set the owner to a segment descriptor. */
listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) ); listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ),( void * ) &( xTCPSegments[ xIndex ] ) );
listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) ); listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ( void * ) &( xTCPSegments[ xIndex ] ) );
/* And add it to the pool of available segments */ /* And add it to the pool of available segments */
vListInsertFifo( &xSegmentList, &( xTCPSegments[xIndex].xSegmentItem ) ); vListInsertFifo( &xSegmentList, &( xTCPSegments[xIndex].xSegmentItem ) );
@ -374,13 +380,13 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Find a segment with a given sequence number in the list of received /* Find a segment with a given sequence number in the list of received
segments. */ segments. */
pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) ); pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments );
for( pxIterator = listGET_NEXT( pxEnd ); for( pxIterator = listGET_NEXT( pxEnd );
pxIterator != pxEnd; pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) ) pxIterator = listGET_NEXT( pxIterator ) )
{ {
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( pxSegment->ulSequenceNumber == ulSequenceNumber ) if( pxSegment->ulSequenceNumber == ulSequenceNumber )
{ {
@ -416,7 +422,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Pop the item at the head of the list. Semaphore protection is /* Pop the item at the head of the list. Semaphore protection is
not required as only the IP task will call these functions. */ not required as only the IP task will call these functions. */
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( &xSegmentList ); pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( &xSegmentList );
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
configASSERT( pxItem != NULL ); configASSERT( pxItem != NULL );
configASSERT( pxSegment != NULL ); configASSERT( pxSegment != NULL );
@ -512,7 +518,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
else else
{ {
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList ); pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
( void ) uxListRemove( pxItem ); ( void ) uxListRemove( pxItem );
} }
@ -538,7 +544,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
else else
{ {
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList ); pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
pxReturn = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); pxReturn = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
} }
return pxReturn; return pxReturn;
@ -604,7 +610,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
{ {
while( listCURRENT_LIST_LENGTH( pxSegments ) > 0U ) while( listCURRENT_LIST_LENGTH( pxSegments ) > 0U )
{ {
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) );
vTCPWindowFree( pxSegment ); vTCPWindowFree( pxSegment );
} }
} }
@ -741,7 +747,7 @@ const int32_t l500ms = 500;
TCPSegment_t *pxBest = NULL; TCPSegment_t *pxBest = NULL;
const ListItem_t *pxIterator; const ListItem_t *pxIterator;
uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength;
const ListItem_t * pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) ); const ListItem_t * pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments );
TCPSegment_t *pxSegment; TCPSegment_t *pxSegment;
/* A segment has been received with sequence number 'ulSequenceNumber', /* A segment has been received with sequence number 'ulSequenceNumber',
@ -757,7 +763,7 @@ const int32_t l500ms = 500;
pxIterator != pxEnd; pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) ) pxIterator = listGET_NEXT( pxIterator ) )
{ {
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* And see if there is a segment for which: /* And see if there is a segment for which:
'ulSequenceNumber' <= 'pxSegment->ulSequenceNumber' < 'ulNextSequenceNumber' 'ulSequenceNumber' <= 'pxSegment->ulSequenceNumber' < 'ulNextSequenceNumber'
If there are more matching segments, the one with the lowest sequence number If there are more matching segments, the one with the lowest sequence number
@ -1495,7 +1501,7 @@ const int32_t l500ms = 500;
uint32_t ulBytesConfirmed = 0U; uint32_t ulBytesConfirmed = 0U;
uint32_t ulSequenceNumber = ulFirst, ulDataLength; uint32_t ulSequenceNumber = ulFirst, ulDataLength;
const ListItem_t *pxIterator; const ListItem_t *pxIterator;
const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xTxSegments ) ); const ListItem_t *pxEnd = listGET_END_MARKER( &pxWindow->xTxSegments );
BaseType_t xDoUnlink; BaseType_t xDoUnlink;
TCPSegment_t *pxSegment; TCPSegment_t *pxSegment;
/* An acknowledgement or a selective ACK (SACK) was received. See if some outstanding data /* An acknowledgement or a selective ACK (SACK) was received. See if some outstanding data
@ -1523,7 +1529,7 @@ const int32_t l500ms = 500;
while( ( pxIterator != pxEnd ) && ( xSequenceLessThan( ulSequenceNumber, ulLast ) != 0 ) ) while( ( pxIterator != pxEnd ) && ( xSequenceLessThan( ulSequenceNumber, ulLast ) != 0 ) )
{ {
xDoUnlink = pdFALSE; xDoUnlink = pdFALSE;
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* Move to the next item because the current item might get /* Move to the next item because the current item might get
removed. */ removed. */
@ -1650,14 +1656,14 @@ const int32_t l500ms = 500;
/* A higher Tx block has been acknowledged. Now iterate through the /* A higher Tx block has been acknowledged. Now iterate through the
xWaitQueue to find a possible condition for a FAST retransmission. */ xWaitQueue to find a possible condition for a FAST retransmission. */
pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &( pxWindow->xWaitQueue ) ) ); pxEnd = listGET_END_MARKER( &( pxWindow->xWaitQueue ) );
pxIterator = listGET_NEXT( pxEnd ); pxIterator = listGET_NEXT( pxEnd );
while( pxIterator != pxEnd ) while( pxIterator != pxEnd )
{ {
/* Get the owner, which is a TCP segment. */ /* Get the owner, which is a TCP segment. */
pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* Hop to the next item before the current gets unlinked. */ /* Hop to the next item before the current gets unlinked. */
pxIterator = listGET_NEXT( pxIterator ); pxIterator = listGET_NEXT( pxIterator );

View file

@ -82,7 +82,7 @@ uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress;
size_t uxPayloadSize; size_t uxPayloadSize;
/* Map the UDP packet onto the start of the frame. */ /* Map the UDP packet onto the start of the frame. */
pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
#if ipconfigSUPPORT_OUTGOING_PINGS == 1 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA ) if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA )
@ -258,7 +258,7 @@ configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
/* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */ /* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */
const UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( const UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); const UDPPacket_t *pxUDPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
/* Caller must check for minimum packet size. */ /* Caller must check for minimum packet size. */
pxSocket = pxUDPSocketLookup( usPort ); pxSocket = pxUDPSocketLookup( usPort );

View file

@ -129,6 +129,16 @@ struct xIP_HEADER
#include "pack_struct_end.h" #include "pack_struct_end.h"
typedef struct xIP_HEADER IPHeader_t; typedef struct xIP_HEADER IPHeader_t;
static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t )
{
return ( IPHeader_t *)pvArgument;
}
static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t )
{
return ( const IPHeader_t *) pvArgument;
}
#include "pack_struct_start.h" #include "pack_struct_start.h"
struct xICMP_HEADER struct xICMP_HEADER
{ {
@ -269,6 +279,17 @@ struct xTCP_PACKET
#include "pack_struct_end.h" #include "pack_struct_end.h"
typedef struct xTCP_PACKET TCPPacket_t; typedef struct xTCP_PACKET TCPPacket_t;
static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
{
return ( TCPPacket_t *)pvArgument;
}
static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
{
return ( const TCPPacket_t *) pvArgument;
}
typedef union XPROT_PACKET typedef union XPROT_PACKET
{ {
ARPPacket_t xARPPacket; ARPPacket_t xARPPacket;
@ -293,6 +314,15 @@ typedef union xPROT_HEADERS
TCPHeader_t xTCPHeader; TCPHeader_t xTCPHeader;
} ProtocolHeaders_t; } ProtocolHeaders_t;
static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
{
return ( ProtocolHeaders_t *)pvArgument;
}
static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
{
return ( const ProtocolHeaders_t *) pvArgument;
}
/* The maximum UDP payload length. */ /* The maximum UDP payload length. */
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER ) #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )