lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Changing MAC-ID at Runtime


From: Thuss, Christopher T
Subject: [lwip-users] Changing MAC-ID at Runtime
Date: Tue, 11 Jun 2019 19:35:59 +0000

Hello –

 

I am running into a situation with the latest LWIP source that I am hoping someone can help me with.

 

Specifically I am trying to start LWIP with one MAC-address (factory default), accept a message over TCP to change the MAC address (permanently to a unique value) and bring the network interface back up with the new MAC-ID without restarting the system. Everything I try has failed. I have tried all combinations of brining the network interface down, modifying the MAC-Address, bringing the network interface back up, removing and re-adding the network interface, etc. Everything I have tried has resulted in either the network interface not starting on initial boot or not functioning after the new MAC address is assigned. I though originally it was related to DHCP not restarting – upon further inspection and testing under a static IP this is not the case. Any recommendations on how to properly change the MAC-ID and bring the interface back up is appreciated. The only documentation I have found is from one person saying not to do this located here:

·       http://lwip.100.n7.nabble.com/Changing-MAC-address-of-network-interface-td26131.html

 

I feel I should be able to accomplish this – and I can with a restart of the system. However, I do not want to restart the system – I want to finish my factory tests – which I can’t as the network interface never comes back with the new MAC-ID.

 

Here is the current function I am using to change the MAC (some temp code exists in here):

è Priot to the below code I bring down the network interface (netifapi_netif_set_down( &netif ))

 

void ethernetUpdateMAC()

{

    uint8_t i,tempMacID[ETHERNET_MAC_ADDRESS_DATA_SZ];

   

    // Read the MAC-ID that should be used for Ethernet from the Factory Test Data Flash

    appFtm_getMacID(tempMacID);           

    

    //TEMP REMOVE

    tempMacID[5] = testMac;                

    

    // Update the MAC-ID only if a change in MAC-ID is detected (or this is initial loading)

    if( MEMCMP_EQUAL != memcmp(tempMacID, macID, sizeof(macID)))

    {

        // Release the DHCP lease if it was active

        netifapi_dhcp_release( &netif );

 

        // Stop the DHCP service if it was started

        netifapi_dhcp_stop( &netif );       

        

        // Remove the network interface

        netifapi_netif_remove( &netif );

       

        // Copy the MAC-ID to the internal structure

        memcpy(macID, tempMacID, sizeof(macID));

       

        // Copy the MAC-ID in to the "formatted" variable for other devices to retrieve as needed

        sprintf((char *)macIDFormatted, "%02x:%02x:%02x:%02x:%02x:%02x", macID[0], macID[1], macID[2], macID[3], macID[4], macID[5]);

    

        // Set the MAC-ID in the network interface...

        netif.hwaddr_len = ETHERNET_MAC_ADDRESS_DATA_SZ;

        for( i = 0; i < ETHERNET_MAC_ADDRESS_DATA_SZ; i++)

        {

            netif.hwaddr[i] = macID[i];

        }

       

        // Re-add the network interface so the changes are reflected       

        netifapi_netif_add( &netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, ethernetif_init, tcpip_input );

        netif_set_default( &netif );       

        

        // Log the change

        Debug_printf( ETHERNET_DEBUG, "MAC-ID updated to: %s\r\n", macIDFormatted );

    }   

}

 

After this I enable Static-IP or DHCP depending on user configuration (basically set the netif IP address for the config and then bring up the interface and start DHCP if needed).

 

Thanks & Regards,

-          Chris


reply via email to

[Prev in Thread] Current Thread [Next in Thread]