samples/wifi/scan broken without programmed OTP

The WiFi scan sample is currently broken is several ways when the OTP isn't programmed:
https://github.com/nrfconnect/sdk-nrf/blob/ea31b211be92f0f837cec1a70be665ec6ff712c3/samples/wifi/scan/src/main.c#L297

* net_if_down() fails with -EAGAIN because it fails to come up in the first place without a MAC address

* NET_REQUEST_ETHERNET_SET_MAC_ADDRESS fails because it is trying to pass the MAC address as a string, instead of a struct ethernet_config

Parents
  • Ah, okay. Sorry about the misunderstanding. I have reported this internally now, but if you want to set your MAC address manually without writing a MAC address onto the OTP memory, you can add the following to your main file (where the code snippet goes into the beginning of your main loop.

    #include <zephyr/net/ethernet_mgmt.h>
    #include <zephyr/net/ethernet.h>
    
    		struct net_if *iface = net_if_get_default();
    	char mac_addr_change[]={0x12, 0x34, 0x56, 0x78, 0x90, 0x12};
    	struct ethernet_req_params params;
    	int ret;
    
    	memcpy(params.mac_address.addr, mac_addr_change, 6);
    	net_if_down(iface);
    
    	ret = net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface,
    			&params, sizeof(struct ethernet_req_params));
    	if(ret != 0) {
    		LOG_ERR("unable to change mac address");
    		return;
    	}
    	ret = memcmp(net_if_get_link_addr(iface)->addr, mac_addr_change,
    			sizeof(mac_addr_change));
    	if(ret != 0) {
    		LOG_ERR("mac address change failed");
    		return;
    	}
    	LOG_DBG("MAC changed to %x:%x:%x:%x:%x:%x\n", \
    	mac_addr_change[0], mac_addr_change[1], mac_addr_change[2], \
    	mac_addr_change[3], mac_addr_change[4], mac_addr_change[5]);
    	net_if_up(iface);
    
    

    Best regards,

    Simon

Reply
  • Ah, okay. Sorry about the misunderstanding. I have reported this internally now, but if you want to set your MAC address manually without writing a MAC address onto the OTP memory, you can add the following to your main file (where the code snippet goes into the beginning of your main loop.

    #include <zephyr/net/ethernet_mgmt.h>
    #include <zephyr/net/ethernet.h>
    
    		struct net_if *iface = net_if_get_default();
    	char mac_addr_change[]={0x12, 0x34, 0x56, 0x78, 0x90, 0x12};
    	struct ethernet_req_params params;
    	int ret;
    
    	memcpy(params.mac_address.addr, mac_addr_change, 6);
    	net_if_down(iface);
    
    	ret = net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface,
    			&params, sizeof(struct ethernet_req_params));
    	if(ret != 0) {
    		LOG_ERR("unable to change mac address");
    		return;
    	}
    	ret = memcmp(net_if_get_link_addr(iface)->addr, mac_addr_change,
    			sizeof(mac_addr_change));
    	if(ret != 0) {
    		LOG_ERR("mac address change failed");
    		return;
    	}
    	LOG_DBG("MAC changed to %x:%x:%x:%x:%x:%x\n", \
    	mac_addr_change[0], mac_addr_change[1], mac_addr_change[2], \
    	mac_addr_change[3], mac_addr_change[4], mac_addr_change[5]);
    	net_if_up(iface);
    
    

    Best regards,

    Simon

Children
No Data
Related