Skip to content

Commit

Permalink
[bt2] Get MAC address from .bt_nv.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
delaya73 committed Jan 17, 2019
1 parent c1b8345 commit 4beef34
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions sparse/usr/bin/droid/macaddrbtsetup.sh
@@ -1,13 +1,30 @@
#!/bin/bash

echo "macaddr: Setting bt MAC address"

mac=$(cat /sys/devices/soc/7570000.uart/tty/ttyHS0/hci0/address)
# Ensure /persist/bluetooth/.bt_nv.bin exists
/system/bin/btnvtool -O

# Convert '1.2a.3b.4c.5d.6d' to '6d:5d:4c:3b:2a:01'
awk_program=' \
/--board-address/ { \
split($2, mac, "."); \
for (i = 1; i <= 6; i++) { \
if (length(mac[i]) == 1) { \
mac[i] = "0" mac[i]; \
} \
} \
printf("%s:%s:%s:%s:%s:%s\n", \
mac[6], mac[5], mac[4], mac[3], mac[2], mac[1]); \
}'

mac=$(/system/bin/btnvtool -p 2>&1 | awk "${awk_program}")

if [ ! -f "/data/misc/bluetooth/bluetooth_bdaddr" ]; then
echo "File not found!"
mkdir -p "/data/misc/bluetooth/"
chmod 0755 "/data/misc/bluetooth/"
echo $mac > "/data/misc/bluetooth/bluetooth_bdaddr"
echo "$mac" > "/data/misc/bluetooth/bluetooth_bdaddr"
fi

if [ -e "/data/misc/bluetooth/bluetooth_bdaddr" ]; then
Expand Down

0 comments on commit 4beef34

Please sign in to comment.