set_wlan_mac: migrate to shared config
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
diff --git a/shared/bin/set_wlan_mac.sh b/shared/bin/set_wlan_mac.sh
new file mode 100755
index 0000000..0e36bc3
--- /dev/null
+++ b/shared/bin/set_wlan_mac.sh
@@ -0,0 +1,42 @@
+#! /system/bin/sh
+# Set wlan0 mac address.
+#
+# Get the unique board serial number from /proc/cmdline,
+# prepend '0's to the serial number to fill 5 LSBs of the
+# MAC address and prepend "02" as MSB to prepare a 6 byte
+# locally administered unicast MAC address.
+# Format the output in xx:xx:xx:xx:xx:xx format for the
+# "ip" set address command to work.
+
+DEV="wlan0"
+
+SERIALNO=`cat /proc/cmdline | grep -o "serialno.*" | cut -d" " -f1`
+
+# If for some reason the serial number isn't on cmdline, just use random
+if [ -z "$SERIALNO" ]; then
+ SERIALNO="$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM"
+fi
+
+# Do some funky stuff to generate a MAC address from the serial number
+# We sha256 it because some devices use non-base 16 characters in their
+# serial number (*ahem* SHIFT6mq).
+SERIALNO=`echo $SERIALNO | sha256sum | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' | sed '$s/:$//' | cut -d: -f1,2,3,4,5,6`
+
+# If the mac address has already been generated then use that instead
+if [ -f /data/wlan_mac.bin ]; then
+ WLAN_MAC=`cat /data/wlan_mac.bin`
+else
+ WLAN_MAC="$SERIALNO"
+ echo $WLAN_MAC > /data/wlan_mac.bin
+fi
+
+echo "Setting $DEV mac addr to $WLAN_MAC"
+
+while ! ip link show $DEV > /dev/null; do
+ echo "Device not up yet, waiting for it"
+ sleep 1
+done
+
+/system/bin/ip link set dev $DEV down
+/system/bin/ip link set dev $DEV address "${WLAN_MAC}"
+/system/bin/ip link set dev $DEV up
diff --git a/shared/device.mk b/shared/device.mk
index 015419e..44a92dd 100644
--- a/shared/device.mk
+++ b/shared/device.mk
@@ -94,7 +94,7 @@
# Install scripts to set consistent Wifi MAC address
PRODUCT_COPY_FILES += \
- $(LOCAL_PATH)/bin/set_wlan_mac.rc:/system/etc/init/set_wlan_mac.rc \
+ $(LOCAL_PATH)/etc/set_wlan_mac.rc:/system/etc/init/set_wlan_mac.rc \
$(LOCAL_PATH)/bin/set_wlan_mac.sh:/system/bin/set_wlan_mac.sh
PRODUCT_PROPERTY_OVERRIDES += \
diff --git a/shared/etc/set_wlan_mac.rc b/shared/etc/set_wlan_mac.rc
new file mode 100644
index 0000000..72785b6
--- /dev/null
+++ b/shared/etc/set_wlan_mac.rc
@@ -0,0 +1,9 @@
+service set_wlan_mac /system/bin/set_wlan_mac.sh
+ class core
+ user root
+ group system
+ disabled
+ oneshot
+
+on post-fs-data
+ start set_wlan_mac