-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bthelper: Add the ability to set the Pi BDADDR
If Bluetooth is being enabled via the kernel, hciattach isn't run and we lose the ability to set the BDADDR. Extend bthelper to use the bdaddr utility on Pis that haven't had the BT section of the OTP programmed. Also ensure that btuart doesn't do anything unless necessary. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
- Loading branch information
Showing
2 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
#!/bin/sh | ||
# For on-board BT, route SCO packets to the HCI interface (enables HFP/HSP) | ||
# For on-board BT, configure the BDADDR if necessary and route SCO packets | ||
# to the HCI interface (enables HFP/HSP) | ||
|
||
set -e | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <bluetooth hci device>" | ||
exit 0 | ||
echo "Usage: $0 <bluetooth hci device>" | ||
exit 0 | ||
fi | ||
|
||
dev=$1 | ||
|
||
# Need to bring hci up before looking at MAC as it can be all zeros during init | ||
/bin/hciconfig $dev up | ||
/bin/hciconfig $dev | grep -q "Bus: UART" || | ||
(echo Not a UART-attached BT Modem; exit 0) | ||
|
||
if ( /usr/bin/bdaddr -i "$dev" | grep -q -E '\s(B8:27:EB:|DC:A6:32:)' ); then | ||
echo Raspberry Pi BDADDR already set | ||
else | ||
SERIAL=`cat /proc/device-tree/serial-number | cut -c9-` | ||
B1=`echo $SERIAL | cut -c3-4` | ||
B2=`echo $SERIAL | cut -c5-6` | ||
B3=`echo $SERIAL | cut -c7-8` | ||
BDADDR=`printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa))` | ||
|
||
/usr/bin/bdaddr -i "$dev" $BDADDR | ||
/bin/hciconfig $dev reset | ||
fi | ||
|
||
# Force reinitialisation to allow extra features such as Secure Simple Pairing | ||
# to be enabled | ||
/usr/bin/bluetoothctl power off | ||
/usr/bin/bluetoothctl power on | ||
|
||
dev="$1" | ||
# Need to bring hci up before looking at MAC as it can be all zeros during init | ||
/bin/hciconfig "$dev" up | ||
/bin/hciconfig "$dev" | grep -qE "BD Address: (B8:27:EB|DC:A6:32):" || exit 0 | ||
# Route SCO packets to the HCI interface (enables HFP/HSP) | ||
/usr/bin/hcitool -i "$dev" cmd 0x3f 0x1c 0x01 0x02 0x00 0x01 0x01 > /dev/null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters