diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 3fbb566cd63..eaa2d449e72 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -27,8 +27,9 @@ LOG_MODULE_REGISTER(net_shell, LOG_LEVEL_DBG); #include #include #include -#if defined(CONFIG_NET_L2_ETHERNET) +#if defined(CONFIG_NET_L2_ETHERNET) && defined(CONFIG_NET_L2_ETHERNET_MGMT) #include +#include #endif /* CONFIG_NET_L2_ETHERNET */ #include "route.h" @@ -3568,12 +3569,14 @@ static int cmd_net_iface(const struct shell *sh, size_t argc, char *argv[]) static int cmd_net_set_mac(const struct shell *sh, size_t argc, char *argv[]) { -#if !defined(CONFIG_NET_L2_ETHERNET) - PR_WARNING("Unsupported command, please enable CONFIG_NET_L2_ETHERNET\n"); +#if !defined(CONFIG_NET_L2_ETHERNET) || !defined(CONFIG_NET_L2_ETHERNET_MGMT) + PR_WARNING("Unsupported command, please enable CONFIG_NET_L2_ETHERNET " + "and CONFIG_NET_L2_ETHERNET_MGMT\n"); return -ENOEXEC; #else struct net_if *iface; - struct net_eth_addr mac_addr; + struct ethernet_req_params params; + char *mac_addr = params.mac_address.addr; int idx; int ret; @@ -3598,15 +3601,15 @@ static int cmd_net_set_mac(const struct shell *sh, size_t argc, char *argv[]) goto err; } - if ((net_bytes_from_str(mac_addr.addr, sizeof(mac_addr), argv[2]) < 0) || - !net_eth_is_addr_valid(&mac_addr)) { + if ((net_bytes_from_str(mac_addr, sizeof(params.mac_address), argv[2]) < 0) || + !net_eth_is_addr_valid(¶ms.mac_address)) { PR_WARNING("Invalid MAC address: %s\n", argv[2]); goto err; } - ret = net_if_set_link_addr(iface, mac_addr.addr, sizeof(mac_addr), NET_LINK_ETHERNET); + ret = net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface, ¶ms, sizeof(params)); if (ret < 0) { - if (ret == -EPERM) { + if (ret == -EACCES) { PR_WARNING("MAC address cannot be set when interface is operational\n"); goto err; }