0

UDP Multicast MAC

This is a patch to FreeRTOS_ARP.c for handling the special MAC-Addresses for IPv4 Multicast Addresses using the assigned MAC 01-00-5E-00-00-00 with the least 23 bits copied from the 23 LSBs of the IP-Address.

My first post from this morning was targetet to little endian only, but that makes no sense here ... so this version addresses both big endian and little endian.

--- /cygdrive/c/Users/andi/Downloads/FreeRTOSv9.0.0/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c       2016-09-19 12:47:35.239661700 +0200
+++ ./FreeRTOS_ARP.c    2016-11-28 11:17:35.775596900 +0100
@@ -391,6 +391,12 @@

 /*-----------------------------------------------------------*/

+#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
+#define IP_IS_MCAST(x) (((x) & 0xF0UL) == 0xE0UL)
+#else
+#define IP_IS_MCAST(x) (((x) & 0xF0000000UL) == 0xE0000000UL)
+#endif
+
 eARPLookupResult_t eARPGetCacheEntry( uint32_t *pulIPAddress, MACAddress_t * const pxMACAddress )
 {
 eARPLookupResult_t eReturn;
@@ -412,6 +418,22 @@
                memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
                eReturn = eARPCacheHit;
        }
+       else if( IP_IS_MCAST( *pulIPAddress ) )         /* a class D address beginning with 0b1110 is a multicast */
+       {                                               /* ATTENTION: IP addresses are already in network byte order! */
+               pxMACAddress->ucBytes[0] = 0x01;
+               pxMACAddress->ucBytes[1] = 0x00;
+               pxMACAddress->ucBytes[2] = 0x5E;
+#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
+               pxMACAddress->ucBytes[3] = (*pulIPAddress >> 8) & 0x7F;
+               pxMACAddress->ucBytes[4] = (*pulIPAddress >> 16) & 0xFF;
+               pxMACAddress->ucBytes[5] = (*pulIPAddress >> 24) & 0xFF;
+#else
+               pxMACAddress->ucBytes[3] = (*pulIPAddress >> 16) & 0x7F;
+               pxMACAddress->ucBytes[4] = (*pulIPAddress >> 8) & 0xFF;
+               pxMACAddress->ucBytes[5] = (*pulIPAddress >> 0) & 0xFF;
+#endif
+               eReturn = eARPCacheHit;
+       }
        else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
        {
                /* The IP address has not yet been assigned, so there is nothing that

Hope this helps and can be integrated in the source tree.

Chears

Andreas

0 comments

Please sign in to leave a comment.