utils: bdaddr: Fallback to bootconfig to read serialno am: bd160522bf
Original change: https://android-review.googlesource.com/c/device/linaro/dragonboard/+/2664198
Change-Id: I897bc60e57c3c8589193995f76dd2de57652fd3b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/sepolicy/set_bdaddr.te b/sepolicy/set_bdaddr.te
index e81d6ab..c7fa166 100644
--- a/sepolicy/set_bdaddr.te
+++ b/sepolicy/set_bdaddr.te
@@ -4,6 +4,7 @@
# audit2allow
allow set_bdaddr proc_cmdline:file { open read };
+allow set_bdaddr proc_bootconfig:file { open read };
allow set_bdaddr rootfs:dir { open read };
allow set_bdaddr self:bluetooth_socket { bind create read write };
allow set_bdaddr self:capability net_admin;
diff --git a/shared/utils/bdaddr/bdaddr.rc b/shared/utils/bdaddr/bdaddr.rc
index d4f007d..65706db 100644
--- a/shared/utils/bdaddr/bdaddr.rc
+++ b/shared/utils/bdaddr/bdaddr.rc
@@ -19,6 +19,8 @@
user root
group system
capabilities NET_ADMIN
+ disabled
+ oneshot
on post-fs
start set_bdaddr
diff --git a/shared/utils/bdaddr/set_bdaddr.sh b/shared/utils/bdaddr/set_bdaddr.sh
index 299626d..e59fa39 100644
--- a/shared/utils/bdaddr/set_bdaddr.sh
+++ b/shared/utils/bdaddr/set_bdaddr.sh
@@ -17,17 +17,24 @@
# limitations under the License.
#
-# Get the unique board serial number from /proc/cmdline,
-# prepend '0's to the serial number to fill 5 LSBs of the
-# BT address and prepend "C0" as MSB to prepare a 6 byte
-# Bluetooth Random Static Address. Reference:
+# Get the unique board serial number from /proc/cmdline or
+# /proc/bootconfig, prepend '0's to the serial number to
+# fill 5 LSBs of the BT address and prepend "C0" as MSB to
+# prepare a 6 byte Bluetooth Random Static Address. Reference:
# https://www.bluetooth.com/wp-content/uploads/2022/05/Bluetooth_LE_Primer_Paper.pdf [Page 23]
#
# Format the output in xx:xx:xx:xx:xx:xx format for the
# "bdaddr" command to work.
-BTADDR=`/vendor/bin/cat /proc/cmdline | vendor/bin/grep -o serialno.* |\
- /vendor/bin/cut -f2 -d'=' | /vendor/bin/awk '{printf("C0%010s\n", $1)}' |\
+BTADDR=`/vendor/bin/cat /proc/cmdline | /vendor/bin/grep -o serialno.* |\
+ /vendor/bin/cut -f2 -d'=' | /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\
/vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'`
+if [ -z "${BTADDR}" ]
+then
+ BTADDR=`/vendor/bin/cat /proc/bootconfig | /vendor/bin/grep -o serialno.* |\
+ /vendor/bin/cut -f2 -d'=' | /vendor/bin/cut -c 3-10 |\
+ /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\
+ /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'`
+fi
/vendor/bin/hw/bdaddr "${BTADDR}"