FreeRTOS+TCP: MISRA rules 10.4, 10.8, & 21.15 (#280)

* Use unsigned types/constants where needed.
* Address MISRA 21.15 violations in FreeRTOS_Sockets.c
* Address MISRA rule violations in code (primarily Rule 2.2)
* Inline had been disabled for Coverity builds, preventing
Coverity from correctly identifying dead code; this change
removes the disabling of inline during Coverity builds.
* Added an explanation for the inline suppression of Rule
11.4 in prvSocketValid().
* Address MISRA Rule Violations (10.4 & 10.8)
* MISRA: Rule 21.15 changes

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
This commit is contained in:
Gary Wicker 2020-09-25 08:47:01 -07:00 committed by GitHub
parent 5d0908b23f
commit 3f21957cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 187 additions and 47 deletions

View file

@ -92,11 +92,21 @@ eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame )
eFrameProcessingResult_t eReturn = eReleaseBuffer; eFrameProcessingResult_t eReturn = eReleaseBuffer;
ARPHeader_t *pxARPHeader; ARPHeader_t *pxARPHeader;
uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress; uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
pxARPHeader = &( pxARPFrame->xARPHeader ); pxARPHeader = &( pxARPFrame->xARPHeader );
/* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */ /* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */
( void ) memcpy( ( void * ) ( &( ulSenderProtocolAddress ) ), ( const void * ) ( pxARPHeader->ucSenderProtocolAddress ), sizeof( ulSenderProtocolAddress ) ); /*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = pxARPHeader->ucSenderProtocolAddress;
pvCopyDest = &ulSenderProtocolAddress;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( ulSenderProtocolAddress ) );
/* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */ /* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */
ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress; ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress;
@ -126,17 +136,41 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
{ {
/* A double IP address is detected! */ /* A double IP address is detected! */
/* Give the sources MAC address the value of the broadcast address, will be swapped later */ /* Give the sources MAC address the value of the broadcast address, will be swapped later */
( void ) memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) ); /*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = xBroadcastMACAddress.ucBytes;
pvCopyDest = pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xBroadcastMACAddress ) );
( void ) memset( pxARPHeader->xTargetHardwareAddress.ucBytes, 0, sizeof( MACAddress_t ) ); ( void ) memset( pxARPHeader->xTargetHardwareAddress.ucBytes, 0, sizeof( MACAddress_t ) );
pxARPHeader->ulTargetProtocolAddress = 0UL; pxARPHeader->ulTargetProtocolAddress = 0UL;
} }
else else
{ {
( void ) memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) ); /*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = pxARPHeader->xSenderHardwareAddress.ucBytes;
pvCopyDest = pxARPHeader->xTargetHardwareAddress.ucBytes;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( MACAddress_t ) );
pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress; pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress;
} }
( void ) memcpy( ( void * ) ( pxARPHeader->xSenderHardwareAddress.ucBytes ), ( const void * ) ( ipLOCAL_MAC_ADDRESS ), sizeof( MACAddress_t ) ); /*
( void ) memcpy( ( void * ) ( pxARPHeader->ucSenderProtocolAddress ), ( const void * ) ( ipLOCAL_IP_ADDRESS_POINTER ), sizeof( pxARPHeader->ucSenderProtocolAddress ) ); * Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = ipLOCAL_MAC_ADDRESS;
pvCopyDest = pxARPHeader->xSenderHardwareAddress.ucBytes;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( MACAddress_t ) );
pvCopySource = ipLOCAL_IP_ADDRESS_POINTER;
pvCopyDest = pxARPHeader->ucSenderProtocolAddress;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
eReturn = eReturnEthernetFrame; eReturn = eReturnEthernetFrame;
} }
@ -650,6 +684,10 @@ static const uint8_t xDefaultPartARPPacketHeader[] =
ARPPacket_t *pxARPPacket; ARPPacket_t *pxARPPacket;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
/* Buffer allocation ensures that buffers always have space /* Buffer allocation ensures that buffers always have space
for an ARP packet. See buffer allocation implementations 1 for an ARP packet. See buffer allocation implementations 1
and 2 under portable/BufferManagement. */ and 2 under portable/BufferManagement. */
@ -669,11 +707,26 @@ ARPPacket_t *pxARPPacket;
xARPHeader.usOperation; xARPHeader.usOperation;
xARPHeader.xTargetHardwareAddress; xARPHeader.xTargetHardwareAddress;
*/ */
( void ) memcpy( ( void * ) pxARPPacket, ( const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) ); /*
( void ) memcpy( ( void * ) ( pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes ) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); * Use helper variables for memcpy() to remain
( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); * compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = xDefaultPartARPPacketHeader;
pvCopyDest = pxARPPacket;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartARPPacketHeader ) );
( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.ucSenderProtocolAddress ), ( const void * ) ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) ); pvCopySource = ipLOCAL_MAC_ADDRESS;
pvCopyDest = pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes;
( void ) memcpy( pvCopyDest, pvCopySource, ipMAC_ADDRESS_LENGTH_BYTES );
pvCopySource = ipLOCAL_MAC_ADDRESS;
pvCopyDest = pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes;
( void ) memcpy( pvCopyDest, pvCopySource, ipMAC_ADDRESS_LENGTH_BYTES );
pvCopySource = ipLOCAL_IP_ADDRESS_POINTER;
pvCopyDest = pxARPPacket->xARPHeader.ucSenderProtocolAddress;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress; pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress;
pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t ); pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t );

View file

@ -642,6 +642,9 @@ uint8_t ucOptionCode;
uint32_t ulProcessed, ulParameter; uint32_t ulProcessed, ulParameter;
BaseType_t xReturn = pdFALSE; BaseType_t xReturn = pdFALSE;
const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct DHCP message type must be present in the options. */ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct DHCP message type must be present in the options. */
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
/* Passing the address of a pointer (pucUDPPayload) because FREERTOS_ZERO_COPY is used. */ /* Passing the address of a pointer (pucUDPPayload) because FREERTOS_ZERO_COPY is used. */
lBytes = FreeRTOS_recvfrom( xDHCPSocket, &pucUDPPayload, 0UL, FREERTOS_ZERO_COPY, NULL, NULL ); lBytes = FreeRTOS_recvfrom( xDHCPSocket, &pucUDPPayload, 0UL, FREERTOS_ZERO_COPY, NULL, NULL );
@ -726,9 +729,14 @@ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct
just get it once here and use later. */ just get it once here and use later. */
if( uxLength >= sizeof( ulParameter ) ) if( uxLength >= sizeof( ulParameter ) )
{ {
( void ) memcpy( ( void * ) ( &( ulParameter ) ), /*
( const void * ) ( &( pucByte[ uxIndex ] ) ), * Use helper variables for memcpy() to remain
( size_t ) sizeof( ulParameter ) ); * compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = &pucByte[ uxIndex ];
pvCopyDest = &ulParameter;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( ulParameter ) );
/* 'uxIndex' will be increased at the end of this loop. */ /* 'uxIndex' will be increased at the end of this loop. */
} }
else else
@ -876,6 +884,9 @@ DHCPMessage_IPv4_t *pxDHCPMessage;
size_t uxRequiredBufferSize = sizeof( DHCPMessage_IPv4_t ) + *pxOptionsArraySize; size_t uxRequiredBufferSize = sizeof( DHCPMessage_IPv4_t ) + *pxOptionsArraySize;
const NetworkBufferDescriptor_t *pxNetworkBuffer; const NetworkBufferDescriptor_t *pxNetworkBuffer;
uint8_t *pucUDPPayloadBuffer; uint8_t *pucUDPPayloadBuffer;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
#if( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) #if( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char *pucHostName = pcApplicationHostnameHook (); const char *pucHostName = pcApplicationHostnameHook ();
@ -931,7 +942,15 @@ uint8_t *pucUDPPayloadBuffer;
pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] ); pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE; pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE;
pucPtr[ 1U ] = ( uint8_t ) uxNameLength; pucPtr[ 1U ] = ( uint8_t ) uxNameLength;
( void ) memcpy( ( void * ) ( &( pucPtr[ 2U ] ) ), ( const void * ) pucHostName, uxNameLength ); /*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = pucHostName;
pvCopyDest = &pucPtr[ 2U ];
( void ) memcpy( pvCopyDest, pvCopySource, uxNameLength );
pucPtr[ 2U + uxNameLength ] = ( uint8_t ) dhcpOPTION_END_BYTE; pucPtr[ 2U + uxNameLength ] = ( uint8_t ) dhcpOPTION_END_BYTE;
*pxOptionsArraySize += ( size_t ) ( 2U + uxNameLength ); *pxOptionsArraySize += ( size_t ) ( 2U + uxNameLength );
} }
@ -965,6 +984,9 @@ static const uint8_t ucDHCPRequestOptions[] =
dhcpOPTION_END_BYTE dhcpOPTION_END_BYTE
}; };
size_t uxOptionsLength = sizeof( ucDHCPRequestOptions ); size_t uxOptionsLength = sizeof( ucDHCPRequestOptions );
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
pucUDPPayloadBuffer = prvCreatePartDHCPMessage( &xAddress, pucUDPPayloadBuffer = prvCreatePartDHCPMessage( &xAddress,
( BaseType_t ) dhcpREQUEST_OPCODE, ( BaseType_t ) dhcpREQUEST_OPCODE,
@ -972,14 +994,19 @@ size_t uxOptionsLength = sizeof( ucDHCPRequestOptions );
&( uxOptionsLength ) ); &( uxOptionsLength ) );
/* Copy in the IP address being requested. */ /* Copy in the IP address being requested. */
( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ] ) ), /*
( const void * ) ( &( EP_DHCPData.ulOfferedIPAddress ) ), * Use helper variables for memcpy() source & dest to remain
sizeof( EP_DHCPData.ulOfferedIPAddress ) ); * compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = &EP_DHCPData.ulOfferedIPAddress;
pvCopyDest = &pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ];
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( EP_DHCPData.ulOfferedIPAddress ) );
/* Copy in the address of the DHCP server being used. */ /* Copy in the address of the DHCP server being used. */
( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ] ) ), pvCopySource = &EP_DHCPData.ulDHCPServerAddress;
( const void * ) ( &( EP_DHCPData.ulDHCPServerAddress ) ), pvCopyDest = &pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ];
sizeof( EP_DHCPData.ulDHCPServerAddress ) ); ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( EP_DHCPData.ulDHCPServerAddress ) );
FreeRTOS_debug_printf( ( "vDHCPProcess: reply %lxip\n", FreeRTOS_ntohl( EP_DHCPData.ulOfferedIPAddress ) ) ); FreeRTOS_debug_printf( ( "vDHCPProcess: reply %lxip\n", FreeRTOS_ntohl( EP_DHCPData.ulOfferedIPAddress ) ) );
iptraceSENDING_DHCP_REQUEST(); iptraceSENDING_DHCP_REQUEST();

View file

@ -843,10 +843,20 @@ static const DNSMessage_t xDefaultPartDNSHeader =
0, /* No authorities. */ 0, /* No authorities. */
0 /* No additional authorities. */ 0 /* No additional authorities. */
}; };
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
/* Copy in the const part of the header. Intentionally using different /* Copy in the const part of the header. Intentionally using different
* pointers with memcpy() to put the information in to correct place. */ * pointers with memcpy() to put the information in to correct place. */
( void ) memcpy( ( void * ) pucUDPPayloadBuffer, ( const void * ) ( &( xDefaultPartDNSHeader ) ), sizeof( xDefaultPartDNSHeader ) ); /*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = &xDefaultPartDNSHeader;
pvCopyDest = pucUDPPayloadBuffer;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartDNSHeader ) );
/* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t /* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t
* to easily access fields of the DNS Message. */ * to easily access fields of the DNS Message. */
@ -1070,7 +1080,7 @@ size_t uxIndex = 0U;
/* The function below will only be called : /* The function below will only be called :
when ipconfigDNS_USE_CALLBACKS == 1 when ipconfigDNS_USE_CALLBACKS == 1
when ipconfigUSE_LLMNR == 1 when ipconfigUSE_LLMNR == 1
for testing purposes, by the module iot_test_freertos_tcp.c for testing purposes, by the module test_freertos_tcp.c
*/ */
uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t *pxNetworkBuffer ) uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t *pxNetworkBuffer )
{ {
@ -1134,6 +1144,9 @@ size_t uxSourceBytesRemaining;
uint16_t x, usDataLength, usQuestions; uint16_t x, usDataLength, usQuestions;
uint16_t usType = 0U; uint16_t usType = 0U;
BaseType_t xReturn = pdTRUE; BaseType_t xReturn = pdTRUE;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
#if( ipconfigUSE_LLMNR == 1 ) #if( ipconfigUSE_LLMNR == 1 )
uint16_t usClass = 0U; uint16_t usClass = 0U;
@ -1314,9 +1327,14 @@ BaseType_t xReturn = pdTRUE;
{ {
/* Copy the IP address out of the record. Using different pointers /* Copy the IP address out of the record. Using different pointers
* to copy only the portion we want is intentional here. */ * to copy only the portion we want is intentional here. */
( void ) memcpy( ( void * ) ( &( ulIPAddress ) ), /*
( const void * ) ( &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ) ), * Use helper variables for memcpy() to remain
sizeof( uint32_t ) ); * compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = &pucByte[ sizeof( DNSAnswerRecord_t ) ];
pvCopyDest = &ulIPAddress;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( uint32_t ) );
#if( ipconfigDNS_USE_CALLBACKS == 1 ) #if( ipconfigDNS_USE_CALLBACKS == 1 )
{ {
@ -1656,7 +1674,7 @@ BaseType_t xReturn;
/* This must be the first time this function has been called. Create /* This must be the first time this function has been called. Create
the socket. */ the socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( prvSocketValid( xSocket ) != pdTRUE ) if( prvSocketValid( xSocket ) != pdTRUE_UNSIGNED )
{ {
/* There was an error, return NULL. */ /* There was an error, return NULL. */
xSocket = NULL; xSocket = NULL;

View file

@ -844,9 +844,9 @@ TickType_t uxBlockTime = uxBlockTimeTicks;
/* Cap the block time. The reason for this is explained where /* Cap the block time. The reason for this is explained where
ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined (assuming an official ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined (assuming an official
FreeRTOSIPConfig.h header file is being used). */ FreeRTOSIPConfig.h header file is being used). */
if( uxBlockTime > ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) ) if( uxBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS )
{ {
uxBlockTime = ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ); uxBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
} }
/* Obtain a network buffer with the required amount of storage. */ /* Obtain a network buffer with the required amount of storage. */
@ -950,7 +950,7 @@ NetworkBufferDescriptor_t *pxResult;
/* The input here is a pointer to a payload buffer. Subtract /* The input here is a pointer to a payload buffer. Subtract
the total size of a UDP/IP header plus the size of the header in the total size of a UDP/IP header plus the size of the header in
the network buffer, usually 8 + 2 bytes. */ the network buffer, usually 8 + 2 bytes. */
pucBuffer -= ( sizeof( UDPPacket_t ) + ( ( size_t ) ipBUFFER_PADDING ) ); pucBuffer -= sizeof( UDPPacket_t ) + ipBUFFER_PADDING;
/* Here a pointer was placed to the network descriptor, /* Here a pointer was placed to the network descriptor,
As a pointer is dereferenced, make sure it is well aligned */ As a pointer is dereferenced, make sure it is well aligned */
@ -1003,7 +1003,7 @@ BaseType_t xReturn = pdFALSE;
} }
#endif #endif
/* Attempt to create the queue used to communicate with the IP task. */ /* Attempt to create the queue used to communicate with the IP task. */
xNetworkEventQueue = xQueueCreate( ( UBaseType_t ) ipconfigEVENT_QUEUE_LENGTH, ( UBaseType_t ) sizeof( IPStackEvent_t ) ); xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) );
configASSERT( xNetworkEventQueue != NULL ); configASSERT( xNetworkEventQueue != NULL );
if( xNetworkEventQueue != NULL ) if( xNetworkEventQueue != NULL )
@ -1057,9 +1057,9 @@ BaseType_t xReturn = pdFALSE;
/* Create the task that processes Ethernet and stack events. */ /* Create the task that processes Ethernet and stack events. */
xReturn = xTaskCreate( prvIPTask, xReturn = xTaskCreate( prvIPTask,
"IP-task", "IP-task",
( uint16_t )ipconfigIP_TASK_STACK_SIZE_WORDS, ipconfigIP_TASK_STACK_SIZE_WORDS,
NULL, NULL,
( UBaseType_t )ipconfigIP_TASK_PRIORITY, ipconfigIP_TASK_PRIORITY,
&( xIPTaskHandle ) ); &( xIPTaskHandle ) );
} }
else else
@ -2564,6 +2564,9 @@ size_t uxDataLengthBytes = uxByteCount;
void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend ) void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, BaseType_t xReleaseAfterSend )
{ {
EthernetHeader_t *pxEthernetHeader; EthernetHeader_t *pxEthernetHeader;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
#if( ipconfigZERO_COPY_TX_DRIVER != 0 ) #if( ipconfigZERO_COPY_TX_DRIVER != 0 )
NetworkBufferDescriptor_t *pxNewBuffer; NetworkBufferDescriptor_t *pxNewBuffer;
@ -2602,9 +2605,19 @@ EthernetHeader_t *pxEthernetHeader;
/* Map the Buffer to Ethernet Header struct for easy access to fields. */ /* Map the Buffer to Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer ); pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer );
/*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
/* Swap source and destination MAC addresses. */ /* Swap source and destination MAC addresses. */
( void ) memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), sizeof( pxEthernetHeader->xDestinationAddress ) ); pvCopySource = &pxEthernetHeader->xSourceAddress;
( void ) memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); pvCopyDest = &pxEthernetHeader->xDestinationAddress;
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxEthernetHeader->xDestinationAddress ) );
pvCopySource = ipLOCAL_MAC_ADDRESS;
pvCopyDest = &pxEthernetHeader->xSourceAddress;
( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
/* Send! */ /* Send! */
( void ) xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend ); ( void ) xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend );

View file

@ -839,8 +839,8 @@ TimeOut_t xTimeOut;
TickType_t xTicksToWait; TickType_t xTicksToWait;
int32_t lReturn = 0; int32_t lReturn = 0;
FreeRTOS_Socket_t const * pxSocket; FreeRTOS_Socket_t const * pxSocket;
const size_t uxMaxPayloadLength = ( size_t ) ipMAX_UDP_PAYLOAD_LENGTH; const size_t uxMaxPayloadLength = ipMAX_UDP_PAYLOAD_LENGTH;
const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4; const size_t uxPayloadOffset = ipUDP_PAYLOAD_OFFSET_IPv4;
pxSocket = ( FreeRTOS_Socket_t * ) xSocket; pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
@ -1450,9 +1450,9 @@ FreeRTOS_Socket_t *pxSocket;
comments where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined comments where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined
in FreeRTOSIPConfig.h (assuming an official configuration file in FreeRTOSIPConfig.h (assuming an official configuration file
is being used. */ is being used. */
if( pxSocket->xSendBlockTime > ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) ) if( pxSocket->xSendBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS )
{ {
pxSocket->xSendBlockTime = ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ); pxSocket->xSendBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
} }
} }
else else

View file

@ -709,6 +709,9 @@ uint32_t ulFrontSpace, ulSpace, ulSourceAddress, ulWinSize;
const TCPWindow_t *pxTCPWindow; const TCPWindow_t *pxTCPWindow;
NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor; NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor;
NetworkBufferDescriptor_t xTempBuffer; NetworkBufferDescriptor_t xTempBuffer;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
/* For sending, a pseudo network buffer will be used, as explained above. */ /* For sending, a pseudo network buffer will be used, as explained above. */
if( pxNetworkBuffer == NULL ) if( pxNetworkBuffer == NULL )
@ -912,8 +915,15 @@ NetworkBufferDescriptor_t xTempBuffer;
( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ),
sizeof( pxEthernetHeader->xDestinationAddress ) ); sizeof( pxEthernetHeader->xDestinationAddress ) );
/*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
/* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */ /* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */
( void ) memcpy( ( void * ) ( &( pxEthernetHeader->xSourceAddress ) ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); pvCopySource = ipLOCAL_MAC_ADDRESS;
pvCopyDest = &pxEthernetHeader->xSourceAddress;
( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
{ {
@ -967,8 +977,8 @@ static void prvTCPCreateWindow( FreeRTOS_Socket_t *pxSocket )
} }
vTCPWindowCreate( vTCPWindowCreate(
&pxSocket->u.xTCP.xTCPWindow, &pxSocket->u.xTCP.xTCPWindow,
( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxRxWinSize, ipconfigTCP_MSS * pxSocket->u.xTCP.uxRxWinSize,
( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxTxWinSize, ipconfigTCP_MSS * pxSocket->u.xTCP.uxTxWinSize,
pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber,
pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber,
( uint32_t ) pxSocket->u.xTCP.usInitMSS ); ( uint32_t ) pxSocket->u.xTCP.usInitMSS );
@ -2335,6 +2345,9 @@ ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t
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;
UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength; UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
#if( ipconfigUSE_TCP_WIN == 1 ) #if( ipconfigUSE_TCP_WIN == 1 )
if( uxOptionsLength != 0U ) if( uxOptionsLength != 0U )
@ -2350,7 +2363,14 @@ UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber, FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) ); FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) );
} }
( void ) memcpy( ( void * ) ( pxTCPHeader->ucOptdata ), ( const void * ) ( pxTCPWindow->ulOptionsData ), ( size_t ) uxOptionsLength ); /*
* Use helper variables for memcpy() source & dest to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = pxTCPWindow->ulOptionsData;
pvCopyDest = pxTCPHeader->ucOptdata;
( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) uxOptionsLength );
/* The header length divided by 4, goes into the higher nibble, /* The header length divided by 4, goes into the higher nibble,
effectively a shift-left 2. */ effectively a shift-left 2. */
@ -2723,7 +2743,7 @@ uint32_t ulRxBufferSpace;
if( ( ulReceiveLength > 0U ) && /* Data was sent to this socket. */ if( ( ulReceiveLength > 0U ) && /* Data was sent to this socket. */
( lRxSpace >= lMinLength ) && /* There is Rx space for more data. */ ( lRxSpace >= lMinLength ) && /* There is Rx space for more data. */
( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) && /* Not in a closure phase. */ ( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) && /* Not in a closure phase. */
( xSendLength == ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER ) ) && /* No Tx data or options to be sent. */ ( xSendLength == uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER ) && /* No Tx data or options to be sent. */
( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eESTABLISHED ) && /* Connection established. */ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eESTABLISHED ) && /* Connection established. */
( pxTCPHeader->ucTCPFlags == tcpTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */ ( pxTCPHeader->ucTCPFlags == tcpTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */
{ {
@ -2870,7 +2890,7 @@ UBaseType_t uxIntermediateResult = 0;
/* Keep track of the highest sequence number that might be expected within /* Keep track of the highest sequence number that might be expected within
this connection. */ this connection. */
if( ( ipNUMERIC_CAST( int32_t, ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulHighestSequenceNumber ) ) > 0L ) if( ( ulSequenceNumber + ulReceiveLength ) > pxTCPWindow->rx.ulHighestSequenceNumber )
{ {
pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + ulReceiveLength; pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + ulReceiveLength;
} }
@ -3023,7 +3043,7 @@ static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNe
{ {
/* 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 = ipCAST_PTR_TO_TYPE_PTR( 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 =
( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */ ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */
pxTCPPacket->xTCPHeader.ucTCPFlags = ucTCPFlags; pxTCPPacket->xTCPHeader.ucTCPFlags = ucTCPFlags;
@ -3235,7 +3255,7 @@ const IPHeader_t *pxIPHeader;
/* Update the copy of the TCP header only (skipping eth and IP /* Update the copy of the TCP header only (skipping eth and IP
headers). It might be used later on, whenever data must be sent headers). It might be used later on, whenever data must be sent
to the peer. */ to the peer. */
const size_t lOffset = ipNUMERIC_CAST( size_t, ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ); const size_t lOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket );
( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ) ), ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ) ),
( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ) ), ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ) ),
ipSIZE_OF_TCP_HEADER ); ipSIZE_OF_TCP_HEADER );

View file

@ -80,6 +80,9 @@ IPHeader_t *pxIPHeader;
eARPLookupResult_t eReturned; eARPLookupResult_t eReturned;
uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress; uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress;
size_t uxPayloadSize; size_t uxPayloadSize;
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void *pvCopySource;
void *pvCopyDest;
/* Map the UDP packet onto the start of the frame. */ /* Map the UDP packet onto the start of the frame. */
pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
@ -152,9 +155,15 @@ size_t uxPayloadSize;
* Offset the memcpy by the size of a MAC address to start at the packet's * Offset the memcpy by the size of a MAC address to start at the packet's
* Ethernet header 'source' MAC address; the preceding 'destination' should not be altered. * Ethernet header 'source' MAC address; the preceding 'destination' should not be altered.
*/ */
/*
* Use helper variables for memcpy() to remain
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = xDefaultPartUDPPacketHeader.ucBytes;
/* The Ethernet source address is at offset 6. */ /* The Ethernet source address is at offset 6. */
char *pxUdpSrcAddrOffset = ( char *) ( &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ] ) ); pvCopyDest = &pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ];
( void ) memcpy( ( void * ) pxUdpSrcAddrOffset, ( const void * ) ( xDefaultPartUDPPacketHeader.ucBytes ), sizeof( xDefaultPartUDPPacketHeader ) ); ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartUDPPacketHeader ) );
#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 )