blob: 299626d1295f14a72d27bb2ef52e9db9b4720e24 [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
20# Get the unique board serial number from /proc/cmdline,
21# prepend '0's to the serial number to fill 5 LSBs of the
22# BT address and prepend "C0" as MSB to prepare a 6 byte
23# Bluetooth Random Static Address. Reference:
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
29BTADDR=`/vendor/bin/cat /proc/cmdline | vendor/bin/grep -o serialno.* |\
30 /vendor/bin/cut -f2 -d'=' | /vendor/bin/awk '{printf("C0%010s\n", $1)}' |\
31 /vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'`
32
33/vendor/bin/hw/bdaddr "${BTADDR}"