hi,
I recently "dirty-hacked" together a mechanism to randomize the MAC address of the Wi-Fi adapter (radio0), i.e. the respective VAPs. It works in both sta and ap mode (or simultaneous ap/sta). I currently use it with AA 12.09, Atheros target (modifications may be needed for other OpenWrt releases or platforms; i.e. other physical interface-naming or multiple physical interfaces). I hope it's of some use to the community.
First, we need to introduce some /etc/init.d/spoofmac like this (...). chmod +x this file.
#!/bin/sh /etc/rc.common
START=17
a=`awk 'BEGIN{srand();print(int(rand()*100+1))}'`
b=`printf "c0:c1:c0\n68:7f:74\n58:6d:8f\n00:23:69\nc0:3f:0e\n08:86:3b\n00:25:9c\n00:24:b2\n00:0f:66\n94:44:52\n00:14:bf\ne0:91:f5\n00:13:10\n00:18:39\n00:22:75\n00:22:3f\n00:26:f2\n00:0c:f6\n20:aa:4b\n00:12:17\n20:4e:7f\n98:fc:11\nf4:ca:e5\n00:16:b6\n00:19:70\n00:0c:41\n00:1d:7e\na0:21:b7\n00:18:f8\n00:1c:10\n00:24:01\n00:1b:2f\n00:1f:33\n30:46:9a\n00:1f:90\n00:14:6c\n84:1b:5e\n00:09:5b\n00:1c:df\n00:1e:e5\n00:06:25\n74:44:01\n00:21:29\nd8:c7:c8\n00:26:f3\n2c:b0:5d\n00:26:44\nc8:d7:19\n00:11:50\nec:1a:59\n00:24:17\nbc:05:43\n74:31:70\n00:1a:70\n00:24:fe\n00:1e:2a\n00:7f:28\n84:9c:a6\n00:1a:2b\n5c:35:3b\n00:26:5a\nc0:25:06\n00:18:01\n00:15:70\n00:02:6f\n00:17:3f\n00:26:62\nc4:3d:c7\ne0:46:9a\n7c:4f:b5\n00:24:6c\n90:f6:52\n00:22:6b\n00:0f:b5\n00:18:4d\n40:4a:03\n00:a0:f8\n00:0d:67\n10:0d:7f\nf8:d1:11\n00:15:ff\n1c:af:f7\n00:24:7b\n24:65:11\n64:70:02\n00:12:0e\n00:1f:3f\n88:25:2c\n00:18:e7\n08:76:ff\n28:c6:8e\n00:0b:86\na4:b1:e9\n00:22:b0\n00:23:08\n04:a1:51\ne8:40:f2\nc8:3a:35\n58:98:35\n5c:0e:8b\n"|head -n $a|tail -1`
c=`hexdump -n3 -e'3/1 ":%02x"' /dev/urandom`
echo $b$c > /tmp/macaddress
uci set wireless.radio0.macaddr=$b$c
It uses the Top100 Octet Prefixes (OUI) from https://wigle.net/stats#octetstats (as of June 3rd, 2015; adjust if needed) and randomizes the NIC-specific least-significant 3 bytes (NIC-specific "randomizer" is borrowed from some other OpenWrt forums thread, can't remember the URI).
Now, we need to introduce some "dirty hack" to /lib/wifi/mac80211.sh. That is, search for these two lines of code (...)
[ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] || continue
config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
and replace them with the following two code snippets (...), respectively
[ "$macaddr" = "$(cat /tmp/macaddress)" ] || continue
config_set "$device" macaddr "$(cat /tmp/macaddress)"
Still modifying /lib/wifi/mac80211.sh, find this code block (...)
cat <<EOF
config wifi-device radio$devidx
option type mac80211
option channel ${channel}
option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
option hwmode 11${mode_11n}${mode_band}
$ht_capab
# REMOVE THIS LINE TO ENABLE WIFI:
option disabled 1
config wifi-iface
option device radio$devidx
option network lan
option mode ap
option ssid OpenWrt
option encryption none
EOF
and comment it, like so (...)
<<"COMMENT"
cat <<EOF
config wifi-device radio$devidx
option type mac80211
option channel ${channel}
option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
option hwmode 11${mode_11n}${mode_band}
$ht_capab
# REMOVE THIS LINE TO ENABLE WIFI:
option disabled 1
config wifi-iface
option device radio$devidx
option network lan
option mode ap
option ssid OpenWrt
option encryption none
EOF
COMMENT
Last but not least, we need to enable the mechanism (...)
# /etc/init.d/spoofmac enable && reboot && exit
or test/start it on the fly (...)
# /etc/init.d/spoofmac start
Certainly, I would appreciate some community-testing and feedback.
thanks!
(Last edited by orange on 4 Jun 2015, 11:41)