You've already forked Raspberry-Pi-Bluetooth
Initialize Git Repository: 'Raspberry-Pi-Bluetooth'
All checks were successful
Raspberry Pi Bluetooth (Bookworm) / Raspberry Pi Bluetooth [arm64] (push) Successful in 11s
All checks were successful
Raspberry Pi Bluetooth (Bookworm) / Raspberry Pi Bluetooth [arm64] (push) Successful in 11s
This commit is contained in:
41
root/usr/bin/bthelper
Normal file
41
root/usr/bin/bthelper
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env sh
|
||||
# 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
|
||||
/usr/bin/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
|
||||
/usr/bin/hciconfig "${DEV}" up
|
||||
if ! /usr/bin/hciconfig "${DEV}" | /usr/bin/grep --quiet 'Bus: UART'; then
|
||||
/usr/bin/echo 'Not a UART-attached BT Modem'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ( /usr/bin/hcitool -i "${DEV}" dev | /usr/bin/grep --extended-regexp --quiet '\s43:4[35]:|AA:AA:AA:AA:AA:AA' ); then
|
||||
SERIAL=$(< '/proc/device-tree/serial-number' /usr/bin/cut '-c9-')
|
||||
B1=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c3-4')
|
||||
B2=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c5-6')
|
||||
B3=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c7-8')
|
||||
BDADDR=$(/usr/bin/printf '0x%02x 0x%02x 0x%02x 0xeb 0x27 0xb8' $((0x$B3 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B1 ^ 0xaa)))
|
||||
|
||||
/usr/bin/hcitool -i "${DEV}" cmd 0x3f 0x001 "${BDADDR}"
|
||||
/usr/bin/hciconfig "${DEV}" reset
|
||||
else
|
||||
/usr/bin/echo 'Raspberry Pi BDADDR already set'
|
||||
fi
|
||||
|
||||
# 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'
|
||||
|
||||
# Force reinitialisation to allow extra features such as Secure Simple Pairing
|
||||
# to be enabled, for currently unknown reasons. This requires bluetoothd to be
|
||||
# running, which it isn't yet. Use this kludge of forking off another shell
|
||||
# with a delay, pending a complete understanding of the issues.
|
||||
(/usr/bin/sleep '5s'; /usr/bin/bluetoothctl power off; /usr/bin/bluetoothctl power on) &
|
||||
33
root/usr/bin/btuart
Normal file
33
root/usr/bin/btuart
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
HCIATTACH='/usr/bin/hciattach'
|
||||
|
||||
if /usr/bin/grep --quiet 'raspberrypi,4' '/proc/device-tree/compatible'; then
|
||||
BDADDR=''
|
||||
else
|
||||
SERIAL=$(< '/proc/device-tree/serial-number' /usr/bin/cut '-c9-')
|
||||
B1=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c3-4')
|
||||
B2=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c5-6')
|
||||
B3=$(/usr/bin/echo "${SERIAL}" | /usr/bin/cut '-c7-8')
|
||||
BDADDR=$(/usr/bin/printf 'b8:27:eb:%02x:%02x:%02x' $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa)))
|
||||
fi
|
||||
|
||||
# Bail out if the kernel is managing the Bluetooth modem initialisation
|
||||
if ( /usr/bin/dmesg | /usr/bin/grep --extended-regexp --quiet "hci[0-9]+: BCM: chip" ); then
|
||||
# On-board bluetooth is already enabled
|
||||
exit 0
|
||||
fi
|
||||
|
||||
UART0=$(/usr/bin/cat '/proc/device-tree/aliases/uart0')
|
||||
SERIAL1=$(/usr/bin/cat '/proc/device-tree/aliases/serial1')
|
||||
|
||||
if [ "${UART0}" = "${SERIAL1}" ] ; then
|
||||
UART0_PINS=$(/usr/bin/wc --bytes '/proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins' | /usr/bin/cut --delimiter=' ' --fields='1')
|
||||
if [ "${UART0_PINS}" = "16" ] ; then
|
||||
"${HCIATTACH}" '/dev/serial1' bcm43xx 3000000 flow - "${BDADDR}"
|
||||
else
|
||||
"${HCIATTACH}" '/dev/serial1' bcm43xx 921600 noflow - "${BDADDR}"
|
||||
fi
|
||||
else
|
||||
"${HCIATTACH}" '/dev/serial1' bcm43xx 460800 noflow - "${BDADDR}"
|
||||
fi
|
||||
Reference in New Issue
Block a user