Fix Bluetooth HID connections in dual-mode BlueZ

ControllerMode=bredr made BlueZ 5.87 reject the LE-only HOGP profile, so discovered BLE keyboards and mice never created input devices. Use dual mode, power/LE preflight, LE bearer selection for HID-over-GATT devices, automatic pairing on Connect Device and a pkill-free daemon stop path. Add scripts/test-bluetooth-hid.py and check-rebuild guards, synchronize docs, and rebuild the 2720 image (09226459...).
This commit is contained in:
Luxferre committed 2026-11-10 17:45:52 +02:00
1 parent ba2f25aa36
commit 20603893e7
9 files changed
+225 -11

No files matched your search

+40 -1
View File
@@ -74,6 +74,10 @@ for path in paths:
print(" %d Python file(s) parsed" % len(paths))
PYEOF
if [ -n "$(find "$BASE_DIR/overlay/rootfs" -type d -name __pycache__ -print -quit 2>/dev/null)" ]; then
fail "overlay/rootfs contains Python bytecode caches"
fi
echo "[check] Rootfs package list..."
PKGS_FILE="$BASE_DIR/scripts/rootfs-packages.txt"
PRUNE_FILE="$BASE_DIR/scripts/rootfs-prune-packages.txt"
@@ -369,7 +373,7 @@ fi
echo "[check] Known-good flashable image set..."
for pair in \
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
"546e5c5f3904384c33a65f3045d862de36ad0c2c254c8dbb984525da55bb73f4 images/bananarchy-nokia-beatles.img" \
"09226459db06615ea97256e4d07573e522c4b40a9f37a6b1fda911f608194225 images/bananarchy-nokia-beatles.img" \
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
set -- $pair
@@ -1262,6 +1266,41 @@ if ! "$BASE_DIR/scripts/test-bluetooth-live-scan.py" >/dev/null 2>&1; then
fail "host live Bluetooth discovery test failed"
fi
echo "[check] Bluetooth HID connections..."
BT_MAIN_CONF="$BASE_DIR/overlay/rootfs/etc/bluetooth/main.conf"
BT_INPUT_CONF="$BASE_DIR/overlay/rootfs/etc/bluetooth/input.conf"
BT_OBEX="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-bt-obex"
BT_HID_TEST="$BASE_DIR/scripts/test-bluetooth-hid.py"
if [ ! -f "$BT_MAIN_CONF" ] || \
! grep -q '^ControllerMode = dual$' "$BT_MAIN_CONF" || \
grep -q '^ControllerMode = bredr$' "$BT_MAIN_CONF"; then
fail "BlueZ main.conf must use dual mode so the HOGP profile can register"
fi
for token in 'UserspaceHID=true' 'LEAutoSecurity=true' \
'ClassicBondedOnly=false' 'IdleTimeout=0'; do
if ! grep -qF "$token" "$BT_INPUT_CONF"; then
fail "BlueZ input.conf is missing the HOGP setting $token"
fi
done
if [ ! -x "$BT_OBEX" ]; then
fail "bananarchy-bt-obex is missing or not executable"
fi
for token in 'prepare_bt_controller()' 'set_hog_preferred_bearer' \
'PreferredBearer' 'if not do_pair and orig_unbonded'; do
if ! grep -qF "$token" "$BT_OBEX"; then
fail "bananarchy-bt-obex is missing the connection fix: $token"
fi
done
if grep -qF '["pkill", "-f"' "$BT_OBEX"; then
fail "bananarchy-bt-obex stop path depends on the missing process killer"
fi
if [ ! -x "$BT_HID_TEST" ]; then
fail "missing host unit test scripts/test-bluetooth-hid.py"
fi
if ! "$BT_HID_TEST" >/dev/null 2>&1; then
fail "host Bluetooth HID connection test failed"
fi
echo "[check] Charger plug/unplug charge icon..."
BATTERY_RULES="$BASE_DIR/overlay/rootfs/etc/udev/rules.d/85-bananarchy-battery.rules"
CHARGE_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-battery-charge-event.sh"
+103
View File
@@ -0,0 +1,103 @@
#!/usr/bin/env python3
"""Host guard for real Bluetooth HID connections.
BlueZ rejects LE-only profiles in BR/EDR-only controller mode, which makes
BLE keyboards and mice discoverable but unusable. This test guards the dual
mode configuration, the HOGP userspace HID settings, and the pair/connect
preflight added to bananarchy-bt-obex.
"""
import ast
import pathlib
import re
BASE = pathlib.Path(__file__).resolve().parent.parent
MAIN_CONF = BASE / "overlay/rootfs/etc/bluetooth/main.conf"
INPUT_CONF = BASE / "overlay/rootfs/etc/bluetooth/input.conf"
BT_OBEX = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-obex"
SCAN_HELPER = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-scan.sh"
LE_HELPER = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-le-enable.sh"
DOAS_RULE = BASE / "overlay/rootfs/etc/doas.d/60-bananarchy-bluetooth.conf"
APPLY_OVERLAY = BASE / "scripts/apply-bananarchy-overlay.sh"
def read(path):
return path.read_text(encoding="utf-8")
def require(condition, message):
if not condition:
raise SystemExit(message)
def main():
for path in (MAIN_CONF, INPUT_CONF, BT_OBEX, SCAN_HELPER, LE_HELPER,
DOAS_RULE, APPLY_OVERLAY):
require(path.is_file(), "missing Bluetooth connection file: %s" % path)
require(BT_OBEX.stat().st_mode & 0o111,
"bananarchy-bt-obex is not executable")
main_conf = read(MAIN_CONF)
modes = re.findall(r"(?m)^\s*ControllerMode\s*=\s*(\S+)\s*$", main_conf)
require(modes == ["dual"],
"BlueZ controller mode must be exactly dual to register LE profiles")
input_conf = read(INPUT_CONF)
for token in ("UserspaceHID=true", "LEAutoSecurity=true",
"ClassicBondedOnly=false", "IdleTimeout=0"):
require(token in input_conf,
"input.conf is missing the HOGP setting %s" % token)
helper_source = read(BT_OBEX)
tree = ast.parse(helper_source, filename=str(BT_OBEX))
functions = {
node.name for node in tree.body
if isinstance(node, ast.FunctionDef)
}
for name in ("prepare_bt_controller", "set_hog_preferred_bearer",
"connect_or_pair_bt_device"):
require(name in functions,
"bananarchy-bt-obex is missing %s()" % name)
for token in ("prepare_bt_controller()",
'["timeout", "3", "bluetoothctl", "power", "on"]',
'"/usr/bin/bananarchy-bt-le-enable.sh"',
'["doas", "-n", helper]',
'"00001812-"',
'"org.bluez.Device1", "PreferredBearer"',
'"s", "le"',
"set_hog_preferred_bearer(nonlocal_conn[0], dpath, p)",
"if not do_pair and orig_unbonded"):
require(token in helper_source,
"pair/connect helper is missing %s" % token)
require('["pkill", "-f"' not in helper_source,
"bananarchy-bt-obex still depends on the missing process killer")
require("/proc/" in helper_source,
"daemon stop path no longer scans /proc for stale processes")
require("bananarchy-bt-le-enable.sh" in read(SCAN_HELPER),
"scan helper no longer enables LE")
require("btmgmt -i hci0 le on" in read(LE_HELPER),
"LE helper no longer enables the LE setting")
require("bananarchy-bt-le-enable.sh" in read(DOAS_RULE),
"doas rule no longer permits the narrow LE helper")
require('cp -af "$BASE_DIR/overlay/rootfs/." "$TARGET_ROOTFS/"' in
read(APPLY_OVERLAY),
"overlay application no longer installs etc/bluetooth configs")
print("[ok] Bluetooth HID profile configuration")
# Mirror BlueZ 5.87 profile.c: an LE bearer is rejected in bredr mode.
def profile_can_register(mode, bearer):
if bearer == "le" and mode == "bredr":
return False
if bearer == "bredr" and mode == "le":
return False
return True
require(profile_can_register(modes[0], "le"),
"dual mode would reject the HOG profile")
require(profile_can_register(modes[0], "bredr"),
"dual mode would reject classic audio profiles")
require(not profile_can_register("bredr", "le"),
"the old bredr mode should reject the HOG profile")
print("[ok] BlueZ dual-mode profile gate")
if __name__ == "__main__":
main()