Problems setting up ethernet mac address on STM32H753ZI


Weiberg, Bernd
 

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure (192.168.1.43 is my NUCLEO Board and 192.168.1.200 is my notebook):

1:   192.168.1.43         192.168.1.200        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has 192.168.1.43? Tell 192.168.1.200

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03    192.168.1.43 is at 00:19:28:ab:cd:ef

 

After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).

 

I used the following code for changing the mac address:

/*

* Set mac address

******************************************************************************/

int set_mac(uint8_t *p_mac, uint8_t len)

{

     int result = 0;

     struct net_if *p_iface = net_if_get_default();

 

     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;

     }

 

     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;

     }

     memcpy(mac, p_mac, sizeof(mac));

 

     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;

 

     }

     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)

     {

          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;

     }

 

     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;

     }

     return result;

}

 

As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.

 

Any Ideas?

 

Cheers.

 

 

 

 


Jukka Rissanen
 

Hi Bernd,

when chaning the MAC from the application, you should use the net_mgmt API so that the Ethernet driver knows that the link address is changed.
See for example tests/net/ethernet_mgmt/src/main.c and test_change_mac_when_down() function how it is doing the change.

Cheers,
Jukka


On Fri, 2022-03-04 at 12:10 +0000, Weiberg, Bernd wrote:

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure (192.168.1.43 is my NUCLEO Board and 192.168.1.200 is my notebook):

1:   192.168.1.43         192.168.1.200        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has 192.168.1.43? Tell 192.168.1.200

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03    192.168.1.43 is at 00:19:28:ab:cd:ef

 

After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).

 

I used the following code for changing the mac address:

/*

* Set mac address

******************************************************************************/

int set_mac(uint8_t *p_mac, uint8_t len)

{

     int result = 0;

     struct net_if *p_iface = net_if_get_default();

 

     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;

     }

 

     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;

     }

     memcpy(mac, p_mac, sizeof(mac));

 

     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;

 

     }

     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)

     {

          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;

     }

 

     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;

     }

     return result;

}

 

As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.

 

Any Ideas?

 

Cheers.

 

 

 

 



Weiberg, Bernd
 

Hi Jukka,

thanks for hat good advice!

I have tried to change the mac address using the net_mgmt API as it can be found in the example you suggested.

net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, ..) returns -ENOTSUP (134) in my case.

After some deeper investigations if found out, that there might be a bug in the underlaying driver eth_stm32_hal.c.

The Code of eth_stm32_hal_set_config() always returns -ENOTSUP even if everything is fine.

In my opinion the last return have to be changed from return -ENOTSUP to return ret;

How can I address this error?

See code below:

 

static int eth_stm32_hal_set_config(const struct device *dev,

                                                                   enum ethernet_config_type type,

                                                                   const struct ethernet_config *config)

{

                int ret = -ENOTSUP;

                struct eth_stm32_hal_dev_data *dev_data;

                ETH_HandleTypeDef *heth;

 

                dev_data = dev->data;

                heth = &dev_data->heth;

 

                switch (type) {

                case ETHERNET_CONFIG_TYPE_MAC_ADDRESS:

                               memcpy(dev_data->mac_addr, config->mac_address.addr, 6);

                               heth->Instance->MACA0HR = (dev_data->mac_addr[5] << 8) |

                                               dev_data->mac_addr[4];

                               heth->Instance->MACA0LR = (dev_data->mac_addr[3] << 24) |

                                               (dev_data->mac_addr[2] << 16) |

                                               (dev_data->mac_addr[1] << 8) |

                                               dev_data->mac_addr[0];

                               net_if_set_link_addr(dev_data->iface, dev_data->mac_addr,

                                                                    sizeof(dev_data->mac_addr),

                                                                    NET_LINK_ETHERNET);

                               ret = 0;

                               break;

                case ETHERNET_CONFIG_TYPE_PROMISC_MODE:

#if defined(CONFIG_NET_PROMISCUOUS_MODE)

#if defined(CONFIG_SOC_SERIES_STM32H7X)

                               if (config->promisc_mode) {

                                               heth->Instance->MACPFR |= ETH_MACPFR_PR;

                               } else {

                                               heth->Instance->MACPFR &= ~ETH_MACPFR_PR;

                               }

#else

                               if (config->promisc_mode) {

                                               heth->Instance->MACFFR |= ETH_MACFFR_PM;

                               } else {

                                               heth->Instance->MACFFR &= ~ETH_MACFFR_PM;

                               }

#endif  /* CONFIG_SOC_SERIES_STM32H7X */

                               ret = 0;

#endif /* CONFIG_NET_PROMISCUOUS_MODE */

                               break;

                default:

                               break;

                }

 

                return -ENOTSUP;

}

 

 

Von: Jukka Rissanen <jukka.rissanen@...>
Gesendet: Montag, 7. März 2022 09:57
An: Weiberg, Bernd (SMO RI R&D DF 1) <bernd.weiberg@...>; users@...
Betreff: Re: [Zephyr-users] Problems setting up ethernet mac address on STM32H753ZI

 

Hi Bernd,

 

when chaning the MAC from the application, you should use the net_mgmt API so that the Ethernet driver knows that the link address is changed.

See for example tests/net/ethernet_mgmt/src/main.c and test_change_mac_when_down() function how it is doing the change.

 

Cheers,

Jukka

 

 

On Fri, 2022-03-04 at 12:10 +0000, Weiberg, Bernd wrote:

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure (192.168.1.43 is my NUCLEO Board and 192.168.1.200 is my notebook):

1:   192.168.1.43         192.168.1.200        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has 192.168.1.43? Tell 192.168.1.200

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03    192.168.1.43 is at 00:19:28:ab:cd:ef

 

After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).

 

I used the following code for changing the mac address:

/*

* Set mac address

******************************************************************************/

int set_mac(uint8_t *p_mac, uint8_t len)

{

     int result = 0;

     struct net_if *p_iface = net_if_get_default();

 

     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;

     }

 

     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;

     }

     memcpy(mac, p_mac, sizeof(mac));

 

     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;

 

     }

     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)

     {

          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;

     }

 

     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;

     }

     return result;

}

 

As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.

 

Any Ideas?

 

Cheers.

 

 

 

 

 


Jukka Rissanen
 

Hi Bernd,

Indeed, the code should return the value of "ret" variable. Would you be able to send a PR that fixes the issue?


Cheers,
Jukka


On Tue, 2022-03-08 at 11:21 +0000, Weiberg, Bernd wrote:

Hi Jukka,

thanks for hat good advice!

I have tried to change the mac address using the net_mgmt API as it can be found in the example you suggested.

net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, ..) returns -ENOTSUP (134) in my case.

After some deeper investigations if found out, that there might be a bug in the underlaying driver eth_stm32_hal.c.

The Code of eth_stm32_hal_set_config() always returns -ENOTSUP even if everything is fine.

In my opinion the last return have to be changed from return -ENOTSUP to return ret;

How can I address this error?

See code below:

 

static int eth_stm32_hal_set_config(const struct device *dev,

                                                                   enum ethernet_config_type type,

                                                                   const struct ethernet_config *config)

{

                int ret = -ENOTSUP;

                struct eth_stm32_hal_dev_data *dev_data;

                ETH_HandleTypeDef *heth;

 

                dev_data = dev->data;

                heth = &dev_data->heth;

 

                switch (type) {

                case ETHERNET_CONFIG_TYPE_MAC_ADDRESS:

                               memcpy(dev_data->mac_addr, config->mac_address.addr, 6);

                               heth->Instance->MACA0HR = (dev_data->mac_addr[5] << 8) |

                                               dev_data->mac_addr[4];

                               heth->Instance->MACA0LR = (dev_data->mac_addr[3] << 24) |

                                               (dev_data->mac_addr[2] << 16) |

                                               (dev_data->mac_addr[1] << 8) |

                                               dev_data->mac_addr[0];

                               net_if_set_link_addr(dev_data->iface, dev_data->mac_addr,

                                                                    sizeof(dev_data->mac_addr),

                                                                    NET_LINK_ETHERNET);

                               ret = 0;

                               break;

                case ETHERNET_CONFIG_TYPE_PROMISC_MODE:

#if defined(CONFIG_NET_PROMISCUOUS_MODE)

#if defined(CONFIG_SOC_SERIES_STM32H7X)

                               if (config->promisc_mode) {

                                               heth->Instance->MACPFR |= ETH_MACPFR_PR;

                               } else {

                                               heth->Instance->MACPFR &= ~ETH_MACPFR_PR;

                               }

#else

                               if (config->promisc_mode) {

                                               heth->Instance->MACFFR |= ETH_MACFFR_PM;

                               } else {

                                               heth->Instance->MACFFR &= ~ETH_MACFFR_PM;

                               }

#endif  /* CONFIG_SOC_SERIES_STM32H7X */

                               ret = 0;

#endif /* CONFIG_NET_PROMISCUOUS_MODE */

                               break;

                default:

                               break;

                }

 

                return -ENOTSUP;

}

 

 

Von: Jukka Rissanen <jukka.rissanen@...>
Gesendet: Montag, 7. März 2022 09:57
An: Weiberg, Bernd (SMO RI R&D DF 1) <bernd.weiberg@...>; users@...
Betreff: Re: [Zephyr-users] Problems setting up ethernet mac address on STM32H753ZI

 

Hi Bernd,

 

when chaning the MAC from the application, you should use the net_mgmt API so that the Ethernet driver knows that the link address is changed.

See for example tests/net/ethernet_mgmt/src/main.c and test_change_mac_when_down() function how it is doing the change.

 

Cheers,

Jukka

 

 

On Fri, 2022-03-04 at 12:10 +0000, Weiberg, Bernd wrote:

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure (192.168.1.43 is my NUCLEO Board and 192.168.1.200 is my notebook):

1:   192.168.1.43         192.168.1.200        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has 192.168.1.43? Tell 192.168.1.200

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03    192.168.1.43 is at 00:19:28:ab:cd:ef

 

After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).

 

I used the following code for changing the mac address:

/*

* Set mac address

******************************************************************************/

int set_mac(uint8_t *p_mac, uint8_t len)

{

     int result = 0;

     struct net_if *p_iface = net_if_get_default();

 

     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;

     }

 

     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;

     }

     memcpy(mac, p_mac, sizeof(mac));

 

     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;

 

     }

     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)

     {

          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;

     }

 

     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;

     }

     return result;

}

 

As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.

 

Any Ideas?

 

Cheers.

 

 

 

 

 



Weiberg, Bernd
 

PR has been submitted now.

By the way:

The change of the mac address works fine now and the new one will be used consequently now by the whole network stack.

 

Thanks a lot.

 

Von: Jukka Rissanen <jukka.rissanen@...>
Gesendet: Dienstag, 8. März 2022 13:33
An: Weiberg, Bernd (SMO RI R&D DF 1) <bernd.weiberg@...>; users@...
Betreff: Re: AW: [Zephyr-users] Problems setting up ethernet mac address on STM32H753ZI

 

Hi Bernd,

 

Indeed, the code should return the value of "ret" variable. Would you be able to send a PR that fixes the issue?

 

 

Cheers,

Jukka

 

 

On Tue, 2022-03-08 at 11:21 +0000, Weiberg, Bernd wrote:

Hi Jukka,

thanks for hat good advice!

I have tried to change the mac address using the net_mgmt API as it can be found in the example you suggested.

net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, ..) returns -ENOTSUP (134) in my case.

After some deeper investigations if found out, that there might be a bug in the underlaying driver eth_stm32_hal.c.

The Code of eth_stm32_hal_set_config() always returns -ENOTSUP even if everything is fine.

In my opinion the last return have to be changed from return -ENOTSUP to return ret;

How can I address this error?

See code below:

 

static int eth_stm32_hal_set_config(const struct device *dev,

                                                                   enum ethernet_config_type type,

                                                                   const struct ethernet_config *config)

{

                int ret = -ENOTSUP;

                struct eth_stm32_hal_dev_data *dev_data;

                ETH_HandleTypeDef *heth;

 

                dev_data = dev->data;

                heth = &dev_data->heth;

 

                switch (type) {

                case ETHERNET_CONFIG_TYPE_MAC_ADDRESS:

                               memcpy(dev_data->mac_addr, config->mac_address.addr, 6);

                               heth->Instance->MACA0HR = (dev_data->mac_addr[5] << 8) |

                                               dev_data->mac_addr[4];

                               heth->Instance->MACA0LR = (dev_data->mac_addr[3] << 24) |

                                               (dev_data->mac_addr[2] << 16) |

                                               (dev_data->mac_addr[1] << 8) |

                                               dev_data->mac_addr[0];

                               net_if_set_link_addr(dev_data->iface, dev_data->mac_addr,

                                                                    sizeof(dev_data->mac_addr),

                                                                    NET_LINK_ETHERNET);

                               ret = 0;

                               break;

                case ETHERNET_CONFIG_TYPE_PROMISC_MODE:

#if defined(CONFIG_NET_PROMISCUOUS_MODE)

#if defined(CONFIG_SOC_SERIES_STM32H7X)

                               if (config->promisc_mode) {

                                               heth->Instance->MACPFR |= ETH_MACPFR_PR;

                               } else {

                                               heth->Instance->MACPFR &= ~ETH_MACPFR_PR;

                               }

#else

                               if (config->promisc_mode) {

                                               heth->Instance->MACFFR |= ETH_MACFFR_PM;

                               } else {

                                               heth->Instance->MACFFR &= ~ETH_MACFFR_PM;

                               }

#endif  /* CONFIG_SOC_SERIES_STM32H7X */

                               ret = 0;

#endif /* CONFIG_NET_PROMISCUOUS_MODE */

                               break;

                default:

                               break;

                }

 

                return -ENOTSUP;

}

 

 

Von: Jukka Rissanen <jukka.rissanen@...>
Gesendet: Montag, 7. März 2022 09:57
An: Weiberg, Bernd (SMO RI R&D DF 1) <bernd.weiberg@...>; users@...
Betreff: Re: [Zephyr-users] Problems setting up ethernet mac address on STM32H753ZI

 

Hi Bernd,

 

when chaning the MAC from the application, you should use the net_mgmt API so that the Ethernet driver knows that the link address is changed.

See for example tests/net/ethernet_mgmt/src/main.c and test_change_mac_when_down() function how it is doing the change.

 

Cheers,

Jukka

 

 

On Fri, 2022-03-04 at 12:10 +0000, Weiberg, Bernd wrote:

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure (192.168.1.43 is my NUCLEO Board and 192.168.1.200 is my notebook):

1:   192.168.1.43         192.168.1.200        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has 192.168.1.43? Tell 192.168.1.200

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03    192.168.1.43 is at 00:19:28:ab:cd:ef

 

After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).

 

I used the following code for changing the mac address:

/*

* Set mac address

******************************************************************************/

int set_mac(uint8_t *p_mac, uint8_t len)

{

     int result = 0;

     struct net_if *p_iface = net_if_get_default();

 

     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;

     }

 

     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;

     }

     memcpy(mac, p_mac, sizeof(mac));

 

     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;

 

     }

     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)

     {

          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;

     }

 

     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;

     }

     return result;

}

 

As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.

 

Any Ideas?

 

Cheers.