blob: e59fa39f72aea058012ce25e13fe42bc8f66cc67 [file] [log] [blame]
Stephan Gerholdf70f12a2019-01-30 11:15:34 +01001#! /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 Pundirbd160522023-07-18 23:05:38 +053020# 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 Gerholdf70f12a2019-01-30 11:15:34 +010024# 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 Pundirbd160522023-07-18 23:05:38 +053029BTADDR=`/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 Gerholdf70f12a2019-01-30 11:15:34 +010031 /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'`
Amit Pundirbd160522023-07-18 23:05:38 +053032if [ -z "${BTADDR}" ]
33then
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/:$//'`
38fi
Stephan Gerholdf70f12a2019-01-30 11:15:34 +010039
40/vendor/bin/hw/bdaddr "${BTADDR}"