[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Changing MAC address of network interface?
From: |
Noam Weissman |
Subject: |
Re: [lwip-users] Changing MAC address of network interface? |
Date: |
Thu, 7 Apr 2016 14:10:47 +0000 |
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: address@hidden [mailto:address@hidden 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
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Changing MAC address of network interface?, Sergio R. Caprile, 2016/04/08