MAC address locking does not work for wifi

Hello,

This is about Milk-V Duo S.

The command to lock the MAC address:
echo "pre-up ifconfig eth0 hw ether whatever:mac:address" >> /etc/network/interfaces
works for ethernet (eth0), but does not work for the wlan0 interface:
echo "pre-up ifconfig wlan0 hw ether some:other:MAC:address" >> /etc/network/interfaces

It always gets a new MAC anyway, which is a bit annoying. How to fix this?

Please advise.

Also please make a tag for Duo S. Will make forum search easier

Have the same issue, following.

I can’t find what is bringing up the wlan0 interface. It’s not in /etc/network/interfaces . I’ve tried adding scripts to if-pre-up.d to change the MAC address, but it always fails on boot because there is no wlan0 that early on the boot . I did find a pretty ugly way to get the MAC to be the same. I used the script below and invoked it with /etc/init.d/S99User . The trick to it is to wait until wlan0 is up so we can take it back down and reassign the MAC and bring it back up. It also brings up wpa_supplicant once the MAC is figured out. There should be a better way, but damned if I can find it."

[root@milkv-duo]~# cat /mnt/system/sma.sh 

#! /bin/sh
sleep 15
ifconfig wlan0 down
# Set the new MAC address
ifconfig wlan0 hw ether 78:01:86:75:30:9F
# Bring up the interface
ifconfig wlan0 up

wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf

and add to /etc/init.d/S99user


if [ -f $SYSTEMPATH/sma.sh ]; then
         usleep 30000
         . $SYSTEMPATH/sma.sh &
fi
2 Likes

If someone from milkv could tell us what is bringing up wlan0, this would be over in no time… What the point of open source if there is little communication?

1 Like

Please someone from milkv, is there any way you can help?

1 Like

I’m sorry for the trouble. We’ll look into it.

2 Likes

Loading the aic8800 driver is what brings up wlan0 the interface.
Loading said driver is done by duo-init.sh.

I am not sure if you all are facing the same issue but my mac address changes with every boot. I think that might be a bug in the driver, I am going to experiment with updating the driver with that from radxa.

I think setting up the device beforehand via /etc/network/interfaces could work.

Edit: You can easily deduce this by reading the kernel log. The aic8800 prints a bunch of debug lines starting with AICWFDBG.

2 Likes

I know a bit more.

Loading a config file for the firmware is disabled here:

This causes the module to use a default mac address here instead.

There is also this code here, where it again reverts to the default mac because a call to rwnx_send_get_macaddr_req fails to get an efuse mac address (it returns an empty mac).

There is also CONFIG_USE_COSTUMER_MAC which is seemingly used by the RockPi-S to set a mac. This is worth looking into further.

Basically the RockPi-S has all of their code for generating the mac here:

The default mac address itself can be found here:

It is 88:00:33:77:10:99.

However the last two bytes are random on each boot. I am not sure where or why this is done yet. I know the last bit is XOR’d with the device index but that should’t be random.

1 Like

Here it is:

The built-in default mac value has it’s last two bytes randomized on each boot by this line.

2 Likes

Awesome, so I could just hardcode the MAC address? Gotta learn C now…

1 Like

If you remove that get_random_bytes(&dflt_mac[4], 2); line, and then recompile you should be good to go.

1 Like

This thing will be on every Milk-V Duo S board with WiFi where you flash that image with this fixed MAC Address.

Yes, though you could change it across compilations.

I am working on a patch for the driver that returns its functionality of being able to read the mac address from a file.

1 Like

With this patch I you can create a file /mnt/system/firmware/aic8800/rwnx_settings.ini and place your mac address in it:

MAC_ADDR=...

If you don’t place this file the driver just reverts to the default behaviour of a random mac.

I am also going to look into if there’s an efuse that can be used to get the actual permanent mac address. If I can’t get that to work I will see if carbonfix will merge this.

Edit: Enable the config file for aic8800 by LevitatingBusinessMan · Pull Request #111 · milkv-duo/duo-buildroot-sdk · GitHub

2 Likes

Did you know you’re awesome?

wlan0 is working, but eth0 lock failed for me