Skip to content
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
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ add_compile_options(
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>

# Suppressions required to build clean with GCC.
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-declaration-after-statement>
)

########################################################################
Expand Down
39 changes: 16 additions & 23 deletions source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,20 +1378,14 @@
uint8_t * pucUDPPayloadBuffer = NULL;

#if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char * pucHostName = pcApplicationHostnameHook();
size_t uxNameLength = 0;
const char * pucHostName = pcApplicationHostnameHook();

if( pucHostName != NULL )
{
uxNameLength = strlen( pucHostName );
}

uint8_t * pucPtr;

/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void * pvCopySource;
void * pvCopyDest;

/* Two extra bytes for option code and length. */
uxRequiredBufferSize += ( 2U + uxNameLength );
#endif /* if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) */
Expand All @@ -1402,6 +1396,8 @@

if( pxNetworkBuffer != NULL )
{
uint8_t * pucIPType;

/* Leave space for the UDP header. */
pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );

Expand All @@ -1410,20 +1406,16 @@
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer );

{
uint8_t * pucIPType;

/* Store the IP type at a known location.
* Later the type must be known to translate
* a payload- to a network buffer.
*/
/* Store the IP type at a known location.
* Later the type must be known to translate
* a payload- to a network buffer.
*/

/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
/* coverity[misra_c_2012_rule_18_4_violation] */
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
*pucIPType = ipTYPE_IPv4;
}
/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
/* coverity[misra_c_2012_rule_18_4_violation] */
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
*pucIPType = ipTYPE_IPv4;

/* Most fields need to be zero. */
( void ) memset( pxDHCPMessage, 0x00, sizeof( DHCPMessage_IPv4_t ) );
Expand Down Expand Up @@ -1455,7 +1447,7 @@
* it easier to lookup a device in a router's list of DHCP clients. */

/* Point to where the OPTION_END was stored to add data. */
pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
uint8_t * pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE;
pucPtr[ 1U ] = ( uint8_t ) uxNameLength;

Expand All @@ -1466,8 +1458,9 @@
*/
if( pucHostName != NULL )
{
pvCopySource = pucHostName;
pvCopyDest = &pucPtr[ 2U ];
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void * pvCopySource = pucHostName;
void * pvCopyDest = &pucPtr[ 2U ];

( void ) memcpy( pvCopyDest, pvCopySource, uxNameLength );
}
Expand Down
40 changes: 21 additions & 19 deletions source/FreeRTOS_DHCPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,18 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )

if( ucMessageType != 0U )
{
/* DHCPv6_Option_IA_for_Prefix_Delegation */
uint32_t ulIAID = 0x27fe8f95;
uint32_t ulTime_1 = 3600U;
uint32_t ulTime_2 = 5400U;

/* DHCPv6_Option_IA_Prefix */
uint32_t ulPreferredLifeTime = 4500U;
uint32_t ulPValidLifeTime = 7200U;
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;

struct freertos_sockaddr * pxAddress;

vBitConfig_write_8( &( xMessage ), ucMessageType ); /* 1 Solicit, 3, request */
vBitConfig_write_uc( &( xMessage ), pxDHCPMessage->ucTransactionID, 3 );

Expand Down Expand Up @@ -1040,25 +1052,15 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
}

/* DHCPv6_Option_Elapsed_Time */
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */

/* DHCPv6_Option_IA_for_Prefix_Delegation */
uint32_t ulIAID = 0x27fe8f95;
uint32_t ulTime_1 = 3600U;
uint32_t ulTime_2 = 5400U;

vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */

/* DHCPv6_Option_IA_Prefix */
uint32_t ulPreferredLifeTime = 4500U;
uint32_t ulPValidLifeTime = 7200U;
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */

vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_Prefix ); /* usOption Option is 26 */
vBitConfig_write_16( &( xMessage ), 25 ); /* usLength length is 25 */
Expand All @@ -1085,7 +1087,7 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
xAddress.sin_family = FREERTOS_AF_INET6;
xAddress.sin_port = FreeRTOS_htons( ipDHCPv6_SERVER_PORT );

struct freertos_sockaddr * pxAddress = &( xAddress );
pxAddress = &( xAddress );

FreeRTOS_printf( ( "DHCP Sending request %u.\n", ucMessageType ) );
( void ) FreeRTOS_sendto( EP_DHCPData.xDHCPSocket, ( const void * ) xMessage.ucContents, xMessage.uxIndex, 0, pxAddress, sizeof xAddress );
Expand Down
28 changes: 15 additions & 13 deletions source/FreeRTOS_DNS.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@
{
NetworkEndPoint_t * pxEndPoint = NULL;

/* If LLMNR is being used then determine if the host name includes a '.' -
* if not then LLMNR can be used as the lookup method. */
/* For local resolution, mDNS uses names ending with the string ".local" */
BaseType_t bHasDot = pdFALSE;
BaseType_t bHasLocal = pdFALSE;
const char * pcDot = ( const char * ) strchr( pcHostName, ( int32_t ) '.' );

#if ( ipconfigUSE_MDNS == 1 ) || ( ipconfigUSE_LLMNR == 1 )
BaseType_t xNeed_Endpoint = pdFALSE;
#endif
Expand All @@ -857,13 +864,6 @@
/* Use the DNS port by default, this may be changed later. */
pxAddress->sin_port = dnsDNS_PORT;

/* If LLMNR is being used then determine if the host name includes a '.' -
* if not then LLMNR can be used as the lookup method. */
/* For local resolution, mDNS uses names ending with the string ".local" */
BaseType_t bHasDot = pdFALSE;
BaseType_t bHasLocal = pdFALSE;
const char * pcDot = ( const char * ) strchr( pcHostName, ( int32_t ) '.' );

if( pcDot != NULL )
{
bHasDot = pdTRUE;
Expand Down Expand Up @@ -1007,9 +1007,10 @@

if( pxEndPoint->bits.bIPv6 == 0U )
{
uint32_t ulIPAddress;
uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex;
configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
uint32_t ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ];
ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ];

if( ( ulIPAddress != 0U ) && ( ulIPAddress != ipBROADCAST_IP_ADDRESS ) )
{
Expand All @@ -1027,9 +1028,10 @@

if( pxEndPoint->bits.bIPv6 != 0U )
{
const uint8_t * ucBytes;
uint8_t ucIndex = pxEndPoint->ipv6_settings.ucDNSIndex;
configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
const uint8_t * ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes;
ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes;

/* Test if the DNS entry is in used. */
if( ( ucBytes[ 0 ] != 0U ) && ( ucBytes[ 1 ] != 0U ) )
Expand Down Expand Up @@ -1171,6 +1173,10 @@

if( xDNSBuf.pucPayloadBuffer != NULL )
{
/* A two-step conversion to conform to MISRA. */
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
BaseType_t xIndex = ( BaseType_t ) uxIndex;

#if ( ipconfigUSE_LLMNR == 1 )
{
if( FreeRTOS_ntohs( pxAddress->sin_port ) == ipLLMNR_PORT )
Expand All @@ -1183,10 +1189,6 @@
}
#endif

/* A two-step conversion to conform to MISRA. */
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
BaseType_t xIndex = ( BaseType_t ) uxIndex;

/* Later when translating form UDP payload to a Network Buffer,
* it is important to know whether this is an IPv4 packet. */
if( pxAddress->sin_family == ( uint8_t ) FREERTOS_AF_INET6 )
Expand Down
3 changes: 1 addition & 2 deletions source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,

if( pxNetworkBuffer != NULL )
{
uint8_t * pucIPType;
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
BaseType_t xPayloadIPTypeOffset = ( BaseType_t ) uxIndex;

Expand All @@ -885,8 +886,6 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
/* Skip 3 headers. */
pvReturn = ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ] );

uint8_t * pucIPType;

/* Later a pointer to a UDP payload is used to retrieve a NetworkBuffer.
* Store the packet type at 48 bytes before the start of the UDP payload. */
pucIPType = ( uint8_t * ) pvReturn;
Expand Down
4 changes: 2 additions & 2 deletions source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,10 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer,
{
struct xPacketSummary xSet;

( void ) memset( &( xSet ), 0, sizeof( xSet ) );

DEBUG_DECLARE_TRACE_VARIABLE( BaseType_t, xLocation, 0 );

( void ) memset( &( xSet ), 0, sizeof( xSet ) );

#if ( ipconfigHAS_DEBUG_PRINTF != 0 )
{
xSet.pcType = "???";
Expand Down
3 changes: 2 additions & 1 deletion source/FreeRTOS_IPv4_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ BaseType_t prvChecksumIPv4Checks( uint8_t * pucEthernetBuffer,

if( xReturn == 0 )
{
size_t uxNeeded;
/* xIPHeader.usLength is the total length, minus the Ethernet header. */
pxSet->usPayloadLength = FreeRTOS_ntohs( pxSet->pxIPPacket->xIPHeader.usLength );

size_t uxNeeded = pxSet->usPayloadLength;
uxNeeded = pxSet->usPayloadLength;
uxNeeded += ipSIZE_OF_ETH_HEADER;

if( uxBufferLength < uxNeeded )
Expand Down
4 changes: 3 additions & 1 deletion source/FreeRTOS_IPv6_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ BaseType_t prvChecksumIPv6Checks( uint8_t * pucEthernetBuffer,
}
else
{
size_t uxNeeded;

/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
Expand All @@ -108,7 +110,7 @@ BaseType_t prvChecksumIPv6Checks( uint8_t * pucEthernetBuffer,
/* For IPv6, the number of bytes in the protocol is indicated. */
pxSet->usProtocolBytes = ( uint16_t ) ( pxSet->usPayloadLength - uxExtensionHeaderLength );

size_t uxNeeded = ( size_t ) pxSet->usPayloadLength;
uxNeeded = ( size_t ) pxSet->usPayloadLength;
uxNeeded += ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER;

if( uxBufferLength < uxNeeded )
Expand Down
6 changes: 4 additions & 2 deletions source/FreeRTOS_ND.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,11 @@

if( memcmp( pxIPv6Address->ucBytes, pxIPHeader->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ) == 0 )
{
FreeRTOS_printf( ( "Waiting done\n" ) );
IPStackEvent_t xEventMessage;
const TickType_t xDontBlock = ( TickType_t ) 0;

FreeRTOS_printf( ( "Waiting done\n" ) );

xEventMessage.eEventType = eNetworkRxEvent;
xEventMessage.pvData = ( void * ) pxARPWaitingNetworkBuffer;

Expand Down Expand Up @@ -1269,6 +1270,7 @@

if( xResult == pdPASS )
{
size_t uxIndex;
/* A loopback IP-address has a prefix of 128. */
configASSERT( ( uxPrefixLength > 0U ) && ( uxPrefixLength <= ( 8U * ipSIZE_OF_IPv6_ADDRESS ) ) );

Expand All @@ -1278,7 +1280,7 @@
}

pucSource = ( uint8_t * ) pulRandom;
size_t uxIndex = uxPrefixLength / 8U;
uxIndex = uxPrefixLength / 8U;

if( ( uxPrefixLength % 8U ) != 0U )
{
Expand Down
6 changes: 5 additions & 1 deletion source/FreeRTOS_RA.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,15 @@
{
TickType_t uxReloadTime = pdMS_TO_TICKS( 5000U );

#if ( ipconfigHAS_PRINTF == 1 )
eRAState_t eRAState;
#endif

configASSERT( pxEndPoint != NULL );

#if ( ipconfigHAS_PRINTF == 1 )
/* Remember the initial state, just for logging. */
eRAState_t eRAState = pxEndPoint->xRAData.eRAState;
eRAState = pxEndPoint->xRAData.eRAState;
#endif

if( xDoReset != pdFALSE )
Expand Down
3 changes: 1 addition & 2 deletions source/FreeRTOS_TCP_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,11 @@
{
/* Function might modify the parameter. */
const NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor;
BaseType_t xResult;

configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );

BaseType_t xResult;

/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
Expand Down
27 changes: 17 additions & 10 deletions source/FreeRTOS_TCP_IP_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ BaseType_t xProcessReceivedTCPPacket_IPV6( NetworkBufferDescriptor_t * pxDescrip
{
/* Function might modify the parameter. */
NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor;
const ProtocolHeaders_t * pxProtocolHeaders;
FreeRTOS_Socket_t * pxSocket;
uint16_t ucTCPFlags;
uint16_t usLocalPort;
uint16_t usRemotePort;
IPv46_Address_t xRemoteIP;
uint32_t ulSequenceNumber;
uint32_t ulAckNumber;
BaseType_t xResult = pdPASS;

configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
Expand All @@ -109,16 +118,14 @@ BaseType_t xProcessReceivedTCPPacket_IPV6( NetworkBufferDescriptor_t * pxDescrip
/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * )
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) );
FreeRTOS_Socket_t * pxSocket;
uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags;
uint16_t usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort );
uint16_t usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort );
IPv46_Address_t xRemoteIP;
uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber );
uint32_t ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr );
BaseType_t xResult = pdPASS;
pxProtocolHeaders = ( ( const ProtocolHeaders_t * )
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) );

ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags;
usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort );
usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort );
ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber );
ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr );

/* Check for a minimum packet size. */
if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) )
Expand Down
Loading