Initialize Git Repository: 'Raspberry-Pi-Bluetooth'
All checks were successful
Raspberry Pi Bluetooth (Bookworm) / Raspberry Pi Bluetooth [arm64] (push) Successful in 11s

This commit is contained in:
Cantibra
2026-01-26 06:10:30 +01:00
commit a45dcce2be
14 changed files with 585 additions and 0 deletions

10
root/DEBIAN/control Normal file
View File

@@ -0,0 +1,10 @@
Package: raspi-bluetooth
Version: 1.0.0
Architecture:
Installed-Size:
Depends: bluez, bluez-firmware, raspi-firmware
Priority: important
Section: misc
Homepage: http://www.privlab.it
Maintainer: PrivLab <repository@privlab.it>
Description: Raspberry Pi family bluetooth helper

36
root/DEBIAN/postinst Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/sh
set -e
set -u
if [ -d '/run/systemd/system' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
fi
case "${1}" in
configure)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper unmask 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
if /usr/bin/deb-systemd-helper --quiet was-enabled 'hciuart.service'; then
/usr/bin/deb-systemd-helper enable 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
else
/usr/bin/deb-systemd-helper update-state 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
if [ -n "${2}" ]; then
_dh_action='restart'
else
_dh_action='start'
fi
/usr/bin/deb-systemd-invoke "${_dh_action}" 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
esac

26
root/DEBIAN/postrm Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/sh
set -e
set -u
if [ -d '/run/systemd/system' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
fi
case "${1}" in
remove)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper mask 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
purge)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper purge 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper unmask 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
esac

15
root/DEBIAN/prerm Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/sh
set -e
set -u
case "${1}" in
remove)
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
/usr/bin/deb-systemd-invoke stop 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-invoke disable 'hciuart.service' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
esac

View File

@@ -0,0 +1,11 @@
[Unit]
Description=Raspberry Pi family bluetooth helper
After=hciuart.service
Before=bluetooth.service
Requires=hciuart.service
[Service]
Type=oneshot
ExecStart=/usr/bin/bthelper %I
ProtectSystem=full
RemainAfterExit=yes

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionFileNotEmpty=/proc/device-tree/soc/gpio@7e200000/bt_pins/brcm,pins
StartLimitIntervalSec=300
StartLimitBurst=6
After=dev-serial1.device
[Service]
Type=forking
ExecStart=/usr/bin/btuart
ProtectSystem=full
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=dev-serial1.device

View File

@@ -0,0 +1,2 @@
# Raspberry Pi bluetooth module: enable routing of SCO packets to the HCI interface
ACTION=="add", SUBSYSTEM=="bluetooth", KERNEL=="hci[0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}+="bthelper@%k.service"

41
root/usr/bin/bthelper Normal file
View 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
View 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