diff options
author | Davide Garberi <dade.garberi@gmail.com> | 2019-05-16 14:38:48 +0200 |
---|---|---|
committer | Davide Garberi <dade.garberi@gmail.com> | 2019-05-16 15:25:15 +0200 |
commit | 79c2ac14828799f933a3c2f79be83bf09c9380e9 (patch) | |
tree | c7358bd9a24a3845baee6131ec28e14d6d647692 | |
parent | 6df37ecfba588b61bf873ffe933034fb6da5368c (diff) |
msm8996-common: rootdir: Add a mac randomization option
* In case the hardware mac is broken, it'll turn out being "555555555555" for wifi and "666666666666" for bt, so generate a random one in case this happens
* Do the same also in case the current kernel lacks the shenqi_nv driver
Change-Id: Id9247b563adcb287ea97bc4f25bd1d846c852b8f
-rw-r--r-- | rootdir/bin/init.bt.sh | 20 | ||||
-rw-r--r-- | rootdir/bin/init.wlan.sh | 21 |
2 files changed, 32 insertions, 9 deletions
diff --git a/rootdir/bin/init.bt.sh b/rootdir/bin/init.bt.sh index ad4b03e..52d7f8f 100644 --- a/rootdir/bin/init.bt.sh +++ b/rootdir/bin/init.bt.sh @@ -17,11 +17,21 @@ # # Set the proper hardware based BT mac address -bt_mac=$(xxd -p /proc/mac_bt | tr '[:lower:]' '[:upper:]' | sed 's/.\{2\}/&:/g' | sed 's/.$//'); +proc_bt="/proc/mac_bt" bt_mac_path="/data/vendor/bluetooth/bdaddr" -if [[ ! -f $bt_mac_path ]] || [[ $(echo $bt_mac) != $(cat $bt_mac_path) ]]; then +if [[ $(xxd -p $proc_bt) == "000000000000" ]] || [[ $(xxd -p $proc_bt) == "666666666666" ]] || [[ ! -f $proc_bt ]]; then + ran1=$(xxd -l 1 -p /dev/urandom) + ran2=$(xxd -l 1 -p /dev/urandom) + ran3=$(xxd -l 1 -p /dev/urandom) + ran4=$(xxd -l 1 -p /dev/urandom) + ran5=$(xxd -l 1 -p /dev/urandom) + ran6=$(xxd -l 1 -p /dev/urandom) + + bt_mac=$(echo "$ran1$ran2$ran3$ran4$ran5$ran6" | tr '[:lower:]' '[:upper:]' | sed 's/.\{2\}/&:/g' | sed 's/.$//'); +else + bt_mac=$(xxd -p $proc_bt | tr '[:lower:]' '[:upper:]' | sed 's/.\{2\}/&:/g' | sed 's/.$//'); +fi; + +if [[ ! -f $bt_mac_path ]] || [[ $(cat $bt_mac_path) == "" ]] || [[ $(cat $bt_mac_path) == "000000000000" ]] || [ $(cat $bt_mac_path) == "666666666666" ]]; then echo $bt_mac > $bt_mac_path - chmod 0644 $bt_mac_path - chown bluetooth $bt_mac_path - chgrp bluetooth $bt_mac_path fi; diff --git a/rootdir/bin/init.wlan.sh b/rootdir/bin/init.wlan.sh index 6036a75..4f3eb7b 100644 --- a/rootdir/bin/init.wlan.sh +++ b/rootdir/bin/init.wlan.sh @@ -17,8 +17,21 @@ # # Set the proper hardware based wlan mac -wifi_mac=$(xxd -p /proc/mac_wifi | tr '[:lower:]' '[:upper:]'); -if [[ ! -f /persist/wlan_mac.bin ]] || [[ $(cat /persist/wlan_mac.bin | grep Intf0MacAddress | sed 's/Intf0MacAddress=//') != $(echo $wifi_mac) ]]; then -echo "Intf0MacAddress=$wifi_mac -END" > /persist/wlan_mac.bin +proc_wifi="/proc/mac_wifi" +wifi_mac_persist=$(cat /persist/wlan_mac.bin | grep Intf0MacAddress | sed 's/Intf0MacAddress=//') +if [[ $(xxd -p $proc_wifi) == "000000000000" ]] || [[ $(xxd -p $proc_wifi) == "555555555555" ]] || [[ ! -f $proc_wifi ]]; then + ran1=$(xxd -l 1 -p /dev/urandom) + ran2=$(xxd -l 1 -p /dev/urandom) + ran3=$(xxd -l 1 -p /dev/urandom) + ran4=$(xxd -l 1 -p /dev/urandom) + ran5=$(xxd -l 1 -p /dev/urandom) + ran6=$(xxd -l 1 -p /dev/urandom) + + wifi_mac=$(echo "$ran1$ran2$ran3$ran4$ran5$ran6" | tr '[:lower:]' '[:upper:]') +else + wifi_mac=$(xxd -p $proc_wifi | tr '[:lower:]' '[:upper:]'); +fi; +if [[ ! -f /persist/wlan_mac.bin ]] || [[ $(echo $wifi_mac_persist) == "000000000000" ]] || [[ $(echo $wifi_mac_persist) == "555555555555" ]]; then + echo "Intf0MacAddress=$wifi_mac" > /persist/wlan_mac.bin + echo "END" >> /persist/wlan_mac.bin fi; |