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 | |
Amit Pundir | bd16052 | 2023-07-18 23:05:38 +0530 | [diff] [blame^] | 29 | BTADDR=`/vendor/bin/cat /proc/cmdline | /vendor/bin/grep -o serialno.* |\ |
| 30 | /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] | 31 | /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'` |
Amit Pundir | bd16052 | 2023-07-18 23:05:38 +0530 | [diff] [blame^] | 32 | if [ -z "${BTADDR}" ] |
| 33 | then |
| 34 | BTADDR=`/vendor/bin/cat /proc/bootconfig | /vendor/bin/grep -o serialno.* |\ |
| 35 | /vendor/bin/cut -f2 -d'=' | /vendor/bin/cut -c 3-10 |\ |
| 36 | /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\ |
| 37 | /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'` |
| 38 | fi |
Stephan Gerhold | f70f12a | 2019-01-30 11:15:34 +0100 | [diff] [blame] | 39 | |
| 40 | /vendor/bin/hw/bdaddr "${BTADDR}" |