mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-20 23:27:39 +08:00
Update after Yuhui's comments
- removed (void) from before memcpy, memset etc. - corrected memcpy style as suggested by Yuhui - Added logging for xNetworkInterfaceOutput. No need to configASSERT
This commit is contained in:

committed by
Yuhui Zheng

parent
4a1148d15b
commit
666c0da366
@ -121,7 +121,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||||||
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 ), ( void * )pxARPHeader->ucSenderProtocolAddress, sizeof( ulSenderProtocolAddress ) );
|
memcpy( ( void *)&( ulSenderProtocolAddress ), ( void * )pxARPHeader->ucSenderProtocolAddress, 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;
|
||||||
|
|
||||||
@ -151,17 +151,17 @@ 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 ) );
|
memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) );
|
||||||
( void ) memset( pxARPHeader->xTargetHardwareAddress.ucBytes, (int)'\0', sizeof( MACAddress_t ) );
|
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 ) );
|
memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||||
pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress;
|
pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress;
|
||||||
}
|
}
|
||||||
( void ) memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
|
memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
|
||||||
( void ) memcpy( ( void* )pxARPHeader->ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
|
memcpy( ( void* )pxARPHeader->ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
|
||||||
|
|
||||||
eReturn = eReturnEthernetFrame;
|
eReturn = eReturnEthernetFrame;
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||||||
if( ulSenderProtocolAddress == *ipLOCAL_IP_ADDRESS_POINTER )
|
if( ulSenderProtocolAddress == *ipLOCAL_IP_ADDRESS_POINTER )
|
||||||
{
|
{
|
||||||
xARPHadIPClash = pdTRUE;
|
xARPHadIPClash = pdTRUE;
|
||||||
( void ) memcpy( xARPClashMacAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( xARPClashMacAddress.ucBytes ) );
|
memcpy( xARPClashMacAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( xARPClashMacAddress.ucBytes ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* ipconfigARP_USE_CLASH_DETECTION */
|
#endif /* ipconfigARP_USE_CLASH_DETECTION */
|
||||||
@ -205,7 +205,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||||||
if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) )
|
if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) )
|
||||||
{
|
{
|
||||||
lResult = xARPCache[ x ].ulIPAddress;
|
lResult = xARPCache[ x ].ulIPAddress;
|
||||||
( void ) memset( &xARPCache[ x ], '\0', sizeof( xARPCache[ x ] ) );
|
memset( &xARPCache[ x ], '\0', sizeof( xARPCache[ x ] ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,8 +326,7 @@ uint8_t ucMinAgeFound = 0U;
|
|||||||
/* Both the MAC address as well as the IP address were found in
|
/* Both the MAC address as well as the IP address were found in
|
||||||
different locations: clear the entry which matches the
|
different locations: clear the entry which matches the
|
||||||
IP-address */
|
IP-address */
|
||||||
/* Silence MISRA warning about unused return value */
|
memset( &xARPCache[ xIpEntry ], (int)'\0', sizeof( xARPCache[ xIpEntry ] ) );
|
||||||
( void ) memset( &xARPCache[ xIpEntry ], (int)'\0', sizeof( xARPCache[ xIpEntry ] ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( xIpEntry >= 0 )
|
else if( xIpEntry >= 0 )
|
||||||
@ -345,7 +344,7 @@ uint8_t ucMinAgeFound = 0U;
|
|||||||
|
|
||||||
if( pxMACAddress != NULL )
|
if( pxMACAddress != NULL )
|
||||||
{
|
{
|
||||||
( void ) memcpy( xARPCache[ xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) );
|
memcpy( xARPCache[ xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) );
|
||||||
|
|
||||||
iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, (*pxMACAddress) );
|
iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, (*pxMACAddress) );
|
||||||
/* And this entry does not need immediate attention */
|
/* And this entry does not need immediate attention */
|
||||||
@ -399,7 +398,7 @@ uint32_t ulAddressToLookup;
|
|||||||
if( *pulIPAddress == ipLLMNR_IP_ADDR ) /* Is in network byte order. */
|
if( *pulIPAddress == ipLLMNR_IP_ADDR ) /* Is in network byte order. */
|
||||||
{
|
{
|
||||||
/* The LLMNR IP-address has a fixed virtual MAC address. */
|
/* The LLMNR IP-address has a fixed virtual MAC address. */
|
||||||
( void ) memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) );
|
memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) );
|
||||||
eReturn = eARPCacheHit;
|
eReturn = eARPCacheHit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -408,7 +407,7 @@ uint32_t ulAddressToLookup;
|
|||||||
( *pulIPAddress == xNetworkAddressing.ulBroadcastAddress ) )/* Or a local broadcast address, eg 192.168.1.255? */
|
( *pulIPAddress == xNetworkAddressing.ulBroadcastAddress ) )/* Or a local broadcast address, eg 192.168.1.255? */
|
||||||
{
|
{
|
||||||
/* This is a broadcast so uses the broadcast MAC address. */
|
/* This is a broadcast so uses the broadcast MAC address. */
|
||||||
( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||||
eReturn = eARPCacheHit;
|
eReturn = eARPCacheHit;
|
||||||
}
|
}
|
||||||
else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
|
else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
|
||||||
@ -501,7 +500,7 @@ eARPLookupResult_t eReturn = eARPCacheMiss;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* A valid entry was found. */
|
/* A valid entry was found. */
|
||||||
( void ) memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||||
eReturn = eARPCacheHit;
|
eReturn = eARPCacheHit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -605,7 +604,11 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
|
|||||||
if( xIsCallingFromIPTask() != 0 )
|
if( xIsCallingFromIPTask() != 0 )
|
||||||
{
|
{
|
||||||
/* Only the IP-task is allowed to call this function directly. */
|
/* Only the IP-task is allowed to call this function directly. */
|
||||||
( void ) xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
|
if( xNetworkInterfaceOutput(pxNetworkBuffer, pdTRUE) != pdTRUE )
|
||||||
|
{
|
||||||
|
/* Not sent? Bad news. Maybe link is down? */
|
||||||
|
FreeRTOS_printf( ("xNetworkInterfaceOutput failed. Link down?\n") );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -651,11 +654,11 @@ ARPPacket_t *pxARPPacket;
|
|||||||
* be a MISRA c2012 rule 11.18 violation.
|
* be a MISRA c2012 rule 11.18 violation.
|
||||||
* Also, for rule 21.15 regarding using same pointer-to-x types for memcpy,
|
* Also, for rule 21.15 regarding using same pointer-to-x types for memcpy,
|
||||||
* below is done intentionally here and thus the rule is relaxed */
|
* below is done intentionally here and thus the rule is relaxed */
|
||||||
( void ) memcpy( ( void * ) pxARPPacket, (const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) );
|
memcpy( ( void * ) pxARPPacket, (const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) );
|
||||||
( void ) memcpy( ( void * ) pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
memcpy( ( void * ) pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||||
( void ) memcpy( ( void * ) pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
memcpy( ( void * ) pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||||
|
|
||||||
( void ) memcpy( ( void* )pxARPPacket->xARPHeader.ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
|
memcpy( ( void* )pxARPPacket->xARPHeader.ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
|
||||||
pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress;
|
pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress;
|
||||||
|
|
||||||
pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t );
|
pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t );
|
||||||
@ -670,7 +673,7 @@ void FreeRTOS_ClearARP( void )
|
|||||||
*
|
*
|
||||||
* MISRA rule 17.7 relaxed. The return value is not
|
* MISRA rule 17.7 relaxed. The return value is not
|
||||||
* required to be used. Also improves readability */
|
* required to be used. Also improves readability */
|
||||||
( void ) memset( xARPCache, (int)'\0', sizeof( xARPCache ) );
|
memset( xARPCache, (int)'\0', sizeof( xARPCache ) );
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user