Stephan Gerhold | f70f12a | 2019-01-30 11:15:34 +0100 | [diff] [blame] | 1 | #! /vendor/bin/sh |
| 2 | # Set Bluetooth address (BT_ADDR). |
| 3 | |
| 4 | # |
| 5 | # Copyright (C) 2023 The Android Open Source Project |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | |
Amit Pundir | bd16052 | 2023-07-18 23:05:38 +0530 | [diff] [blame] | 20 | # Get the unique board serial number from /proc/cmdline or |
| 21 | # /proc/bootconfig, prepend '0's to the serial number to |
| 22 | # fill 5 LSBs of the BT address and prepend "C0" as MSB to |
| 23 | # prepare a 6 byte Bluetooth Random Static Address. Reference: |
Stephan Gerhold | f70f12a | 2019-01-30 11:15:34 +0100 | [diff] [blame] | 24 | # https://www.bluetooth.com/wp-content/uploads/2022/05/Bluetooth_LE_Primer_Paper.pdf [Page 23] |
| 25 | # |
| 26 | # Format the output in xx:xx:xx:xx:xx:xx format for the |
| 27 | # "bdaddr" command to work. |
| 28 | |
Yongqin Liu | a565a8f | 2024-01-03 15:48:11 +0800 | [diff] [blame] | 29 | if /vendor/bin/grep -o 'Linux version 5.4.' /proc/version; then |
| 30 | # for 5.4 kernels, setting the bdaddr would cause |
| 31 | # bluetooth::StackManager::StartUp crash like reported here: |
| 32 | # https://issuetracker.google.com/issues/318404233 |
| 33 | # so skipping it here. |
| 34 | # It's possible to not integrate this script at building time, |
| 35 | # but that way would make 5.4 and other kernel versions use different |
| 36 | # super.img files, for development convenience doing the check |
| 37 | # at runtime here, so that only boot.img/vendor_boot.img are |
| 38 | # necessary for different versions |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
Amit Pundir | bd16052 | 2023-07-18 23:05:38 +0530 | [diff] [blame] | 42 | BTADDR=`/vendor/bin/cat /proc/cmdline | /vendor/bin/grep -o serialno.* |\ |
| 43 | /vendor/bin/cut -f2 -d'=' | /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\ |
Stephan Gerhold | f70f12a | 2019-01-30 11:15:34 +0100 | [diff] [blame] | 44 | /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'` |
Amit Pundir | bd16052 | 2023-07-18 23:05:38 +0530 | [diff] [blame] | 45 | if [ -z "${BTADDR}" ] |
| 46 | then |
| 47 | BTADDR=`/vendor/bin/cat /proc/bootconfig | /vendor/bin/grep -o serialno.* |\ |
| 48 | /vendor/bin/cut -f2 -d'=' | /vendor/bin/cut -c 3-10 |\ |
| 49 | /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\ |
| 50 | /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'` |
| 51 | fi |
Stephan Gerhold | f70f12a | 2019-01-30 11:15:34 +0100 | [diff] [blame] | 52 | |
| 53 | /vendor/bin/hw/bdaddr "${BTADDR}" |