Changing MAC address of network interface?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing MAC address of network interface?

Freddie Chopin
Hello!

I was wondering what is the proper way to change MAC address of network
interface. Can I just change the contents of netif.hwaddr[] and expect
everything to still work correctly (assuming I also change the MAC
address in the driver)? Maybe I have to bring the netif completely
down, remove it, change the configuration (MAC address only), add it
again and bring it up?

Thanks for any help!

Regards,
FCh

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Changing MAC address of network interface?

Noam weissman
Hi,

MAC address should not be changed. This should be a onetime setup per device.
Meaning you set a real MAC address that is assigned to you and that's all.

This is done before calling netif_add function. Here is a portion of the initializing code
I am using:
------------------------------------------------------------------------------------------------------------------
static void prvEthernetConfigureInterface(void * param)
{
  struct ip_addr xIpAddr;
  struct ip_addr xNetMast;
  struct ip_addr xGateway;  
  u8 i, MACadd[6] = {0};
     
   
  /* Parameters are not used - suppress compiler error. */
  ( void ) param;
 
   
       
  /* Create and configure the EMAC interface, IP, GateWay and Mask values. */
  xIpAddr.addr = GetIpAddDword();
  xNetMast.addr = GetIpMaskDword();
  xGateway.addr = GetIpGwDword();        

  /* set MAC hardware address length */
  s_EMAC_if.hwaddr_len = ETHARP_HWADDR_LEN;

  /* Get MAC hardware address */
  GetMACadd(MACadd);
   
  // copy the default MAC address to the netif stracture
  for(i=0; i<ETHARP_HWADDR_LEN; i++)
  {
    s_EMAC_if.hwaddr[i] = MACadd[i];
  }
     
       
  // add the new interface to the list of interfaces after initializing it.  
  netif_add(&s_EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);
   
  // make it the default interface
  netif_set_default(&s_EMAC_if);

       
  // Set the link callback function, this function is called on change of link status
  // ETH_link_callback function is declared in stm32fxxx_eth.c or similar...
  netif_set_link_callback(&s_EMAC_if, ETH_link_callback);  
       
  // When USE_DHCP is not defined or when DHCP is off ...
#ifdef USE_DHCP  
  if(GetTcpIpMode() == FALSE)
#endif    
  {  
    netif_set_up(&s_EMAC_if);
  }
}

------------------------------------------------------------------------------------------------------------------

The above code is loaded once when device is rebooted.

IP address, MAC etc... are loaded from FLASH.

BR,
Noam.

-----Original Message-----
From: lwip-users-bounces+noam=[hidden email] [mailto:lwip-users-bounces+noam=[hidden email]] On Behalf Of Freddie Chopin
Sent: Thursday, April 07, 2016 1:54 PM
To: lwip-users
Subject: [lwip-users] Changing MAC address of network interface?

Hello!

I was wondering what is the proper way to change MAC address of network interface. Can I just change the contents of netif.hwaddr[] and expect everything to still work correctly (assuming I also change the MAC address in the driver)? Maybe I have to bring the netif completely down, remove it, change the configuration (MAC address only), add it again and bring it up?

Thanks for any help!

Regards,
FCh

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users