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

+2 -2
View File
@@ -30,7 +30,7 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) with **Adre
- `nokia-beatles` boot chain: `images/boot-lk2nd-nokia-beatles.img` is built from upstream `msm8916-mainline/lk2nd` at pinned commit `cf45aefd22d744b2bf9b39455afae697ce430063` plus `bootloader/lk2nd/nokia-beatles.patch` (see `bootloader/lk2nd/README.md`; rebuild with `scripts/build-lk2nd-beatles.sh`). It keeps the upstream QCDT layout (both `0x14b` entries `0xb/0x100` and `0x1000b/0x100` sharing one `msm8905-qrd-skub` DTB, stock `qcom,board-id` order) with a compact `/lk2nd/nokia-beatles` node injected, and **adds `/cpus` with `cpu@0`..`cpu@3` and 4-byte `device_type` to the common `lk2nd.dtsi` so every QCDT DTB has it**. The 2720's MSM8905 is a partial-goods 2-core part and its aboot `ASSERT`s at `platform/msm_shared/partial_goods.c:80` when `/cpus`, `cpu@2` or `cpu@3` is missing — that was the actual "black screen / no fastboot" crash (Sahara MEMORY_DEBUG RLOG log, see `bootloader/lk2nd/README.md` and `backup/nokia-beatles-2720/crash-20261109/aboot-log.txt`). cmdline `lk2nd lk2nd.compatible=nokia,beatles`, `lk2nd,match-panel` for all three GC9305 panel names the aboot reports, and the single `qcom,mdss_spi_gc9305_v2_qvga_cmd` (the panel the live aboot reports) `lk2nd,panel-init` stream replayed on BLSP1 QUP5 (DC GPIO 110) only when aboot did not leave continuous splash enabled (or when `lk2nd.force-panel-init` is in the cmdline), so the 240x320 RGB565 main panel is initialized even without cont-splash. `spi-display.c` also paints the branded RGB565 boot splash into the framebuffer (without flushing during init): `DISABLE_SPLASH_PARTITION=1` plus `menu.c`'s bottom-only text means upstream lk2nd otherwise pushes a nearly black frame, which is what the "KaiOS logo then blank screen" is. `lk2nd/include/lk2nd/spi-panel-init.h` is shared with the host unit test; the repo copy is `bootloader/lk2nd/spi-panel-init.h` and `check-lk2nd-beatles.py` keeps them in sync and enforces that QCDT shape. Both the normal and diagnostic images carry `lk2nd.no-display` (RAM-only framebuffer, no QUP SPI before USB) because unbounded QUP/clock register polls used to wedge lk2nd with the boot vibrator stuck on. The port now bounds those polls (`QUP_FIFO_TIMEOUT`, `CLK_POLL_TIMEOUT`) and adds `oem display-init` / `oem display-test` / `oem scan-dtb` fastboot probes that run after USB is up, plus `oem screenshot` to verify the framebuffer. Live `oem display-init` confirmed the GC9305 v2 stream and the 240x320 RGB565 frame; a chain-loaded diagnostic falls back to the QCDT panel stream when aboot tags are absent, `oem scan-dtb` stages the final DTB after lk2nd DT updates, `oem ramoops console` validates and bounds pstore data, and the QUP per-word `SPEW` log is removed. The r3 port also makes `oem read-partition` block-safe: it rounds MMC reads up to the eMMC block size, rejects unaligned offsets and stages only the requested byte count. `images/boot-lk2nd-nokia-beatles-display.img` uses `lk2nd.display=on` for boot-time panel init via the downstream GC9305 v2 `lk2nd,panel-init` stream; flash it with `--lk2nd-image`. The diagnostic image additionally has `DEBUG=2 LK2ND_FORCE_FASTBOOT=1`. `check-lk2nd-beatles.py --expect-display` guards the display variant; `scripts/test-lk2nd-beatles-port.py` runs all three. lk2nd is confirmed working over live fastboot (`lk2nd:compatible=nokia,beatles`, `model=Nokia 2720 Flip`, panel `qcom,mdss_spi_gc9305_v2_qvga_cmd`, `unlocked=yes`). `flash-edl.py` defaults to `--method lk2nd` for every target; stock aboot accepts the port and lk2nd boots Bananarchy from `userdata` via `extlinux.conf` (`fdt /qcom-msm8905-nokia-beatles.dtb`). On `nokia-beatles` the default is now the Argon shape: lk2nd in `boot`, the standalone mainline `boot.img` in `recovery` (Volume Up fallback). `--method both` remains as a fallback that writes the standalone mainline `boot.img` to both slots. `--verify` reads back every slot and `--dump-diagnostics` saves small bootloader/config partitions for secure-boot analysis. `scripts/check-lk2nd-beatles.py` validates the boot header, both 2720 QCDT entries, `/cpus` in every QCDT DTB, the device node and the GC9305 v2 panel init stream; `scripts/test-lk2nd-beatles-port.py` adds the host C parser test. The stock 2720 aboot is locked (`devinfo.is_unlocked=0`) and verifies boot images against `Nokia_beatles ROOT CA0`; `flash-edl.py` therefore defaults to setting `devinfo.is_unlocked=1` on `nokia-beatles` via `unlock_devinfo()` before writing any boot image, saves `backup/devinfo-locked-<device>.img`, and supports `--no-unlock-bootloader` to skip. `scripts/make-unlocked-devinfo.py` produces the same patched image offline. Correction: the GPT has `keystore` but no `keymaster`, so `target_get_vb_version()` returns `VB_L=1` while `VB_M=2`; aboot therefore reads `devinfo` from eMMC, not RPMB. The 21:25 dump confirms eMMC `is_unlocked=1`, so the unlock is effective and no stock fastboot / `oem unlock-go` step is required. `--only-unlock`, `enable_oem_unlock()` and `scripts/make-oem-unlock-config.Line truncated
- `bootloader/loaders/`: device-specific signed Firehose programmers; `DEVICE_LOADERS` in `flash-edl.py` maps each target codename to one (`8k.mbn` serves both `nokia-sparkler` and `nokia-leo`), and `DEVICE_LOADER_VARIANTS` maps `--variant us` on `nokia-beatles` to `2720v.mbn` (`Nokia_bts_us`). Never flash a different device's programmer: Sahara rejects the signature and `--list-loaders` shows the embedded attestation identity.
- `vendor/edl/`: vendored, patched EDL client library (MIT) used by `flash-edl.py`; a local `edl/` checkout or `BANANARCHY_EDL_DIR` overrides it.
- `scripts/rootfs-packages.txt`: single source of truth for the `armv7` rootfs package set, read by both `bootstrap-rootfs.sh` and `rebuild-image.sh`. It intentionally contains no `device-*` package; `scripts/apply-bananarchy-overlay.sh` installs the per-device `devices/<device>/modules-initfs` list as `/usr/share/mkinitfs/modules/00-device-<device>.modules` (plus its `initramfs.load` mapping) so a clean-clone bootstrap still builds the correct initramfs. `scripts/check-rebuild.sh` guards this. The package set also includes `msm-firmware-loader`, its OpenRC companion and `msm-firmware-loader-wcnss`; explicit sysinit/boot links are required because packages are installed with `--no-scripts`. This mounts the stock `modem` and `persist` partitions before udev and supplies WCNSS/modem firmware plus factory Wi-Fi NV data, allowing both `wlan0` and `hci0` to enumerate. The package set explicitly contains `glib` and `gsettings-desktop-schemas`; because apk is invoked with `--no-scripts`, `apply-bananarchy-overlay.sh` must run `compile-gsettings-schemas.sh` to generate `gschemas.compiled`, otherwise WebKitGTK's network process aborts with an internal error. The package set also includes `util-linux-misc` for `script(1)` and `bluez-btmgmt` for `btmgmt`, which the live Bluetooth scan wrapper uses to keep a single interactive BlueZ client alive and enable LE discovery on the WCNSS controller.
- `scripts/rootfs-packages.txt`: single source of truth for the `armv7` rootfs package set, read by both `bootstrap-rootfs.sh` and `rebuild-image.sh`. It intentionally contains no `device-*` package; `scripts/apply-bananarchy-overlay.sh` installs the per-device `devices/<device>/modules-initfs` list as `/usr/share/mkinitfs/modules/00-device-<device>.modules` (plus its `initramfs.load` mapping) so a clean-clone bootstrap still builds the correct initramfs. `scripts/check-rebuild.sh` guards this. The package set also includes `msm-firmware-loader`, its OpenRC companion and `msm-firmware-loader-wcnss`; explicit sysinit/boot links are required because packages are installed with `--no-scripts`. This mounts the stock `modem` and `persist` partitions before udev and supplies WCNSS/modem firmware plus factory Wi-Fi NV data, allowing both `wlan0` and `hci0` to enumerate. The package set explicitly contains `glib` and `gsettings-desktop-schemas`; because apk is invoked with `--no-scripts`, `apply-bananarchy-overlay.sh` must run `compile-gsettings-schemas.sh` to generate `gschemas.compiled`, otherwise WebKitGTK's network process aborts with an internal error. The package set also includes `util-linux-misc` for `script(1)` and `bluez-btmgmt` for `btmgmt`, which the live Bluetooth scan wrapper uses to keep a single interactive BlueZ client alive and enable LE discovery on the WCNSS controller. `overlay/rootfs/etc/bluetooth/main.conf` must keep `ControllerMode = dual`: BlueZ 5.87 rejects LE-only HOGP profile registration in `bredr` mode, so BLE HID peripherals would be discoverable but never create an input node. `bananarchy-bt-obex` powers the controller on, enables LE, selects the LE bearer for HID-over-GATT devices and pairs unbonded devices before connecting.
- `scripts/rootfs-prune-packages.txt`: denylist of Wayland-only, Rust-based, and retired packages purged from existing rootfs trees by `bootstrap-rootfs-container.sh` and `rebuild-image.sh`.
- `scripts/prune-rootfs-packages.sh`: two-phase rootfs pruner (`world` before `apk add`, `purge` after) that reads the denylist and pins `install_if` packages with negative `!pkg` world constraints plus `apk fix`; the `world` phase is required so apk can atomically replace Rust `sudo-rs` with C `sudo`.
@@ -60,7 +60,7 @@ All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7`
- `./scripts/build-lk2nd-beatles.sh` — cross-builds all three beatles lk2nd images (normal, diagnostic and display; the display image is the flasher default) from the pinned upstream lk2nd commit plus `bootloader/lk2nd/nokia-beatles.patch` in rootless Docker (`--check` validates all three shipped images, `--only normal|diagnostic|display` builds one, `--force-panel-init` forces the panel replay, `--with-display` enables SPI display during boot). Offline validators: `scripts/check-lk2nd-beatles.py` and `scripts/test-lk2nd-beatles-port.py`.
- `./scripts/build-beatles-cover-panel.py` — builds the opt-in two-panel DTB (and optionally a boot image / `pmOS_boot` patch) for the physical gpio13/reset sign-off.
- `./scripts/build-beatles-no-cover-dtb.py` — builds the verified single-panel rollback DTB (and optionally a boot image / `pmOS_boot` patch).
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-webkit-gsettings.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py`, `./scripts/test-bluetooth-live-scan.py`, `./scripts/test-battery-charge-event.py`, `./scripts/test-gps-time-sync.py`, `./scripts/test-cover-idle.py` and `./scripts/test-cover-dt.py` — host unit/integration tests for the Webarchy renderer profile and GSettings schema build, the idle-blank screenlock wiring, the Bluetooth discovery parser and live PTY wrapper, the charger plug/unplug icon refresh, the GPS-only time source, the cover display state machine and the external-panel DT wiring (all also run by `check-rebuild.sh`).
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-webkit-gsettings.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py`, `./scripts/test-bluetooth-live-scan.py`, `./scripts/test-bluetooth-hid.py`, `./scripts/test-battery-charge-event.py`, `./scripts/test-gps-time-sync.py`, `./scripts/test-cover-idle.py` and `./scripts/test-cover-dt.py` — host unit/integration tests for the Webarchy renderer profile and GSettings schema build, the idle-blank screenlock wiring, the Bluetooth discovery parser, live PTY wrapper and HID connection profile, the charger plug/unplug icon refresh, the GPS-only time source, the cover display state machine and the external-panel DT wiring (all also run by `check-rebuild.sh`).
- `./scripts/check-rebuild.sh` — offline preflight for a clean clone (syntax, package list, plugin artifacts, overlay sync, SMS long-message rendering guard, ignored local agent config, Docker, version helper).
- `./scripts/sync-prebuilt-overlay.sh [--check]` — mirrors `prebuilt/` artifacts into `overlay/rootfs/`; `--check` only reports drift.
- `./scripts/bootstrap-flash-deps.sh` — installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory for `flash-edl.py`.
+2 -2
View File
@@ -252,7 +252,7 @@ Ordered by expected impact, with measured evidence. Regression risks are stated.
| **U2** | **Implement real suspend**: replace no-op `sxmo_autosuspend.sh`/`sxmo_suspend.sh`, set `AllowSuspend=yes`, remove the infinite `sxmo_not_suspendable` wakelock and `sxmo.nosuspend`, and use the existing timed wakelocks (`sxmo_modem.sh`, `sxmo_hook_postwake.sh`) once `CONFIG_PM_WAKELOCKS` exists. `sxmo_hook_block_suspend.sh` already lists the blockers. | Enables K1. `/sys/power/wake_lock` is absent today, so all current wakelocks are no-ops. | Resume latency; must not suspend during calls, SMS, ringtone, active SSH/VPN/tethering. |
| **U3** | **`statusbar_periodics`**: `sxmo_run_aligned.sh 60 sxmo_hook_statusbar.sh periodics` is running and its guard passes. Replace `mmcli -m any -J`, `nmcli -t con show --active`, `nmcli ... device wifi list`, `rfkill list wifi`, `xsetroot -name` with D-Bus `PropertiesChanged` signals, or raise to ≥300 s and only `xsetroot` on change. | Removes a 60 s QMI/D-Bus/process burst and a full dwm bar redraw (SPI frame). | Statusbar icons lag up to the new interval. |
| **U4** | **Battery udev path**: filter `85-bananarchy-battery.rules` to `KERNEL=="pm8916-bms-vm"`/`ENV{POWER_SUPPLY_NAME}`, drop the `(sleep 2; ... recheck)` fork, avoid `su` per event. | Measured 2 uevents/min; removes the `su`/`sleep` forks. Lower priority than previously stated. | Charging icon must still update instantly on plug/unplug (keep the charger event). |
| **U5** | **Bluetooth (latent)**: set `AutoEnable=false`, finite `DiscoverableTimeout`/`PairableTimeout`, `ControllerMode=bredr`, and keep BT out of the default runlevel. | BT is already off (soft-blocked, daemon not running) — **no current saving today**; this prevents a future drain when a user enables BT. | BT must still auto-reconnect when explicitly enabled. |
| **U5** | **Bluetooth (latent)**: set `AutoEnable=false`, finite `DiscoverableTimeout`/`PairableTimeout`, `ControllerMode=dual`, and keep BT out of the default runlevel. | BT is already off (soft-blocked, daemon not running) — **no current saving today**; this prevents a future drain when a user enables BT. | BT must still auto-reconnect when explicitly enabled; dual mode is required for LE HID profiles. |
| **U6** | **chronyd**: remove from the default runlevel or set `minpoll 12 maxpoll 16`; rely on `rtcsync`/RTC (`osclock`, `swclock-offset-boot` are already in the boot runlevel). | Measured running with `pool pool.ntp.org iburst`, but after 43 h uptime it is at ~1024 s polls → **low priority**. Removes a daemon and occasional DNS/NTP Wi-Fi wakeups. | Clock drift without NTP. **Refined in section 16**: removing `iburst` broke the initial sync entirely, so `iburst` was restored and a network-up hook was added; the long steady-state polls are unchanged. |
| **U7** | ~~Duplicate `wpa_supplicant` / respawn storm~~ | **Removed — see C1.** One stable `-u` instance; the `yesno` typo is harmless. Optionally fix the cosmetic typo. | None. |
| **U8** | **NetworkManager**: add `[device] wifi.scan-interval=600` (no override exists today), `ipv6.method=ignore` for Wi-Fi profiles, keep `wifi.powersave=3` and `connectivity.enabled=false`. | Fewer roaming scans and IPv6 ND/MLD wakeups (measured IPv6 active on wlan0). | Roaming responsiveness; IPv6-only networks. |
@@ -366,7 +366,7 @@ few places where the regression checks mandated by the analysis changed the impl
| U2 | `bananarchy-suspend.sh` / `bananarchy-deep-standby.sh` / `sxmo_autosuspend.sh` / `sxmo_suspend.sh`, `AllowSuspend=yes`, doas rule, infinite wakelock removed, `sxmo.nosuspend` removed, `sxmo_hook_screenoff.sh` starts the grace timer, `sxmo_hook_unlock.sh`/`postwake.sh` cancel it. **Shipped disabled** via `/etc/bananarchy-no-deep-standby` until the new kernel has been boot-tested: a broken driver suspend callback must never leave a flashed phone unwakeable. `freeze` (s2idle, any-IRQ wake) is preferred; `mem` requires `/etc/bananarchy-allow-mem-suspend`. |
| U3 | `statusbar_periodics` interval 60 -> 300 s; `sxmo_hook_statusbar.sh periodics` drops `mmcli`/`nmcli`/`rfkill` polls and only calls `xsetroot` when the status string changes. |
| U4 | udev rule filtered to the two PM8916 supplies; `(sleep 2; ... recheck)` fork removed from `sxmo_hook_battery.sh`. |
| U5 | `AutoEnable=false`, finite discoverable/pairable timeouts, `ControllerMode=bredr`, fewer reconnect attempts. BT was already off on the device, so this is a latent fix. |
| U5 | `AutoEnable=false`, finite discoverable/pairable timeouts, `ControllerMode=dual`, fewer reconnect attempts. BT was already off on the device, so this is a latent fix. |
| U6 | `etc/chrony/chrony.conf` uses `minpoll 12 maxpoll 16` with `iburst` restored; `bananarchy-time-sync.sh` refreshes the pool on network-up (section 16). |
| U7 | Withdrawn (C1); the cosmetic `yesno` typo in `etc/init.d/wpa_supplicant` was fixed anyway. |
| U8 | `[device] wifi.scan-interval=600` in `10-power.conf`; IPv6 disabled on new interfaces (K10). |
+8
View File
@@ -13,6 +13,14 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here.
### Real Bluetooth connections and HID-over-GATT
- **Root cause**: the previous image could discover and even bond BLE peripherals, but `ControllerMode = bredr` made BlueZ 5.87's `btd_profile_register()` reject the LE-only `input-hog` profile. `bluetoothd -d` logged `System does not support hog plugin`, so HID-over-GATT keyboards and mice never produced a usable `/dev/input` node.
- **Connection path**: `overlay/rootfs/etc/bluetooth/main.conf` now uses `ControllerMode = dual`, preserving classic A2DP/HSP/HFP profiles while allowing LE HOGP. `input.conf` keeps `UserspaceHID=true`, `LEAutoSecurity=true` and `ClassicBondedOnly=false`. `bananarchy-bt-obex` powers the adapter on, calls the narrow `bananarchy-bt-le-enable.sh` helper, sets `PreferredBearer = le` for devices exposing HID service `00001812-...`, and automatically pairs unbonded peripherals selected through **Connect Device**.
- **Daemon lifecycle**: `bananarchy-bt-obex stop` no longer calls `pkill`, which is absent from the BusyBox-based target rootfs; it now terminates the PID-file daemon and scans `/proc` directly for stale daemon command lines.
- **Guards and live verification**: `scripts/test-bluetooth-hid.py` and `check-rebuild.sh` guard the dual-mode config, HOGP settings, pair/connect preflight, LE bearer selection and auto-pair logic. On the live phone, `bluetoothd -d` showed `Loading hog plugin` with no `System does not support hog plugin` rejection after the change, and `btmgmt info` showed `le` in the controller's current settings immediately after `bluetoothctl power on`.
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu`; the verified raw hash is `09226459db06615ea97256e4d07573e522c4b40a9f37a6b1fda911f608194225`, pinned by `check-rebuild.sh`. `debugfs` confirms the image rootfs has `ControllerMode = dual`, the corrected `0755` `bananarchy-bt-obex` helper and the explicit Bluetooth packages; `e2fsck -fn` passed. This supersedes the discovery-fix image hash `546e5c5f...`.
### Live Bluetooth peripheral discovery
- **Synthetic-only regression**: the previous Bluetooth fix could find an injected `BT_PROBE` line but not real peripherals. Live diagnostics showed non-interactive `bluetoothctl --timeout 15 scan on` emitted only discovery-filter/controller messages, a separate `bluetoothctl devices` query after the scan client exited was empty, and `scan off` from another client failed with `org.bluez.Error.InProgress` while the original client still owned discovery.
+1 -1
View File
@@ -216,7 +216,7 @@ All twenty-five phone applications are compiled as shared-object plugins (`/usr/
- **Three connectivity tabs (`Left`/`Right` or `1`–`3`)**:
- **`1:Wi-Fi`**: toggle Wi-Fi radio, rescan (`*`), toggle **Wi-Fi Hotspot**, and connect to WPA2/open networks with a multi-tap password dialog (`*` toggles password visibility).
- **`2:Cell/APN`**: toggle **Mobile Data** (configuring the QMI `bam-dmux` `wwan0` static IPv4 bearer, default route, and DNS automatically), inspect `wwan0` IPv4 status, edit **APN Configuration**, and toggle **USB Tethering**.
- **`3:Bluetooth`**: toggle **Bluetooth Power** (showing a live `ON (N Active)` badge and starting `/usr/bin/bananarchy-bt-obex`), toggle **Discoverable** (`ON (Visible)` vs `OFF (Hidden)`, persisted in `~/.config/sxmo/bt_discoverable`), edit the **Bluetooth Device Name** (`Name: <Alias> [Edit]`, persisted in `~/.config/sxmo/bt_name` and applied via `bluetoothctl system-alias` independently of the system hostname), monitor the live **OBEX File Receiver** widget (`#` opens `~/Downloads/` in `xfiles`), scan nearby devices (`*` or `Scan`, 15-second discovery scan), and manage paired/discovered devices. The scan now drives one interactive `bluetoothctl` client through `script(1)` (`/usr/local/bin/bluetoothctl` -> `/usr/bin/bananarchy-bt-scan.sh`), sets auto transport and duplicate-data, asks the same client for `devices` three times while discovery is active, parses both `[NEW] Device ...` / `[CHG] Device ...` and `Device <MAC> <Name>` lines, and stops discovery cleanly before the client exits; the controller is also powered on automatically if `bluetoothctl show` reports `Powered: no`. A narrow `doas` helper runs `btmgmt -i hci0 le on` before discovery because this WCNSS controller otherwise starts with LE disabled and only performs BR/EDR inquiry. Active connections are pinned to the top of the device list with a green border and live profile/battery badges (`[ACTIVE: A2DP]`, `[ACTIVE: HSP/HFP]`, `[ACTIVE: HID Gamepad]`, `[ACTIVE: HID Keyboard]`, `[ACTIVE: HID Mouse]`), and the device actions menu (`Center OK`) provides **Connect Device**, **Disconnect Device**, **Pair & Trust Device**, **Switch Audio (A2DP / HSP-HFP)**, and **Forget / Remove Device**. Supports Bluetooth **A2DP** (`sbc_xq`, `aac`, `ldac`, `aptx`, `aptx_hd`) and **HSP/HFP** (`mSBC` / `CVSD`) audio (routable via `xdrawer`, `dmenu Audio`, and `sxmo_audio.sh`), **HID keyboards** (automatically switching `fcitx5-t9` and NeoUI/plugin inputs to `[KBD]` direct QWERTY mode so `0-9`, `*`, `#`, `Shift+0-9`, and letters bypass T9 multi-tap and preedit popups), **HID mice** (automatically showing the X11 mouse cursor whenever a mouse is connected and hiding it when disconnected), and **HID gamepads** (automatically bridged to the phone's D-Pad, softkeys, and action keys via `/dev/uinput`).
- **`3:Bluetooth`**: toggle **Bluetooth Power** (showing a live `ON (N Active)` badge and starting `/usr/bin/bananarchy-bt-obex`), toggle **Discoverable** (`ON (Visible)` vs `OFF (Hidden)`, persisted in `~/.config/sxmo/bt_discoverable`), edit the **Bluetooth Device Name** (`Name: <Alias> [Edit]`, persisted in `~/.config/sxmo/bt_name` and applied via `bluetoothctl system-alias` independently of the system hostname), monitor the live **OBEX File Receiver** widget (`#` opens `~/Downloads/` in `xfiles`), scan nearby devices (`*` or `Scan`, 15-second discovery scan), and manage paired/discovered devices. The scan now drives one interactive `bluetoothctl` client through `script(1)` (`/usr/local/bin/bluetoothctl` -> `/usr/bin/bananarchy-bt-scan.sh`), sets auto transport and duplicate-data, asks the same client for `devices` three times while discovery is active, parses both `[NEW] Device ...` / `[CHG] Device ...` and `Device <MAC> <Name>` lines, and stops discovery cleanly before the client exits; the controller is also powered on automatically if `bluetoothctl show` reports `Powered: no`. A narrow `doas` helper runs `btmgmt -i hci0 le on` before discovery because this WCNSS controller otherwise starts with LE disabled and only performs BR/EDR inquiry. BlueZ keeps `ControllerMode = dual`: `bredr` mode rejects the LE-only HOGP profile, so BLE HID devices would connect at the GATT level but never create a keyboard or mouse input node. **Connect Device** powers the adapter on, enables LE, selects the LE bearer for HID-over-GATT devices and automatically pairs unpaired peripherals; **Pair & Trust Device** still does this explicitly. Active connections are pinned to the top of the device list with a green border and live profile/battery badges (`[ACTIVE: A2DP]`, `[ACTIVE: HSP/HFP]`, `[ACTIVE: HID Gamepad]`, `[ACTIVE: HID Keyboard]`, `[ACTIVE: HID Mouse]`), and the device actions menu (`Center OK`) provides **Connect Device**, **Disconnect Device**, **Pair & Trust Device**, **Switch Audio (A2DP / HSP-HFP)**, and **Forget / Remove Device**. Supports Bluetooth **A2DP** (`sbc_xq`, `aac`, `ldac`, `aptx`, `aptx_hd`) and **HSP/HFP** (`mSBC` / `CVSD`) audio (routable via `xdrawer`, `dmenu Audio`, and `sxmo_audio.sh`), **HID keyboards** (automatically switching `fcitx5-t9` and NeoUI/plugin inputs to `[KBD]` direct QWERTY mode so `0-9`, `*`, `#`, `Shift+0-9`, and letters bypass T9 multi-tap and preedit popups), **HID mice** (automatically showing the X11 mouse cursor whenever a mouse is connected and hiding it when disconnected), and **HID gamepads** (automatically bridged to the phone's D-Pad, softkeys, and action keys via `/dev/uinput`).
13. **Ringtones, notification/SMS sounds, and ringer manager (`ringtones.so` / `xringtones`)**:
- **Open**: select **Ringtones** from the System, Config, or Audio menu, select **Notification Sound** from the **Notifications (`Notifs`)** menu, or run `xringtones [--notif] [file]`.
+1 -1
View File
@@ -40,7 +40,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
- **Phone dialer (`xdialer`), call log (`xcalllog`), and call screen (`xcallscreen`)**: press any digit on the home screen to start dialing with live T9 contact matching, run interactive carrier USSD codes (`*100#`, etc.), or type `*#06#` to inspect both IMEIs. When two SIM cards are active in Dual-SIM Dual Standby (DSDS), placing a call or running a USSD code prompts to choose between `SIM 1` and `SIM 2`. Incoming and active calls on either SIM (as well as incoming/active VoIP calls from `xsip` and `xtox`) open a dedicated call screen with an active `[SIM 1]`/`[SIM 2]`/`[SIP]`/`[TOX]` badge, earpiece/speaker switching, microphone mute, DTMF keypad, and one-key normalized WAV call recording (`~/Recordings/rec_HHMMSS_<caller>.wav`). The call log includes a 5-tab view (`All`, `Miss`, `In`, `Out`, `Spam`) with integrated anti-spam number blocking (`~/.config/sxmo/block.tsv`) that automatically hangs up blocked callers and logs them to the `Spam` tab without triggering missed-call notifications.
- **Contacts (`xcontacts`) and SMS manager (`xsms`)**: full phonebook editor with direct Qualcomm QMI SIM card contact import and export across SIM 1 and SIM 2, paired with a threaded SMS conversation view that renders and scrolls full-length concatenated/Unicode (`UCS-2`) messages line by line, a multi-tap message composer with an encoding-aware GSM-7/UCS-2 segment counter and outgoing `SIM 1` / `SIM 2` selection when two SIMs are active, and built-in anti-spam blocklist / spam folder (`~/.local/share/sxmo/block`) with one-key thread blocking and restoration.
- **Modem and Dual-SIM manager (`xmodem`)**: 4-tab cellular control center (`SIMs`, `Radio`, `AT`, `Log`) supporting Dual-SIM Dual Standby (DSDS) with simultaneous network registration on both SIM slots, instant default SIM switching (`Set as Default SIM (Calls/SMS)`), full Primary/Secondary GW (`4G/Data`) slot swapping (`Make Primary GW (4G/Data Swap)`), SIM PIN unlock and PUK unblock wizards, 2G/3G/4G radio mode selection, interactive USSD sessions, and a live AT command console.
- **Networks and Bluetooth manager (`xnetworks`) with OBEX file transfer (`bananarchy-bt-obex`)**: 3-tab connectivity manager for Wi-Fi networks, WPA2 password entry, Wi-Fi hotspot, USB tethering, 4G/LTE mobile data (`wwan0`) and APN editing, and Bluetooth pairing, with built-in Bluetooth OBEX Object Push file reception (`~/Downloads` status and receiver toggle in the `Bluetooth` tab) and **Send via Bluetooth** in `xfiles`. Bluetooth discovery runs through `/usr/local/bin/bluetoothctl` and `bananarchy-bt-scan.sh`, which keeps one interactive `bluetoothctl` PTY client alive, sets auto transport and duplicate-data, queries `devices` during active discovery, and stops discovery cleanly so unpaired peripherals are not dropped when the scan command exits. A narrow `doas` helper runs `btmgmt -i hci0 le on` before each scan because the WCNSS controller otherwise powers up with LE disabled and only performs BR/EDR inquiry.
- **Networks and Bluetooth manager (`xnetworks`) with OBEX file transfer (`bananarchy-bt-obex`)**: 3-tab connectivity manager for Wi-Fi networks, WPA2 password entry, Wi-Fi hotspot, USB tethering, 4G/LTE mobile data (`wwan0`) and APN editing, and Bluetooth pairing, with built-in Bluetooth OBEX Object Push file reception (`~/Downloads` status and receiver toggle in the `Bluetooth` tab) and **Send via Bluetooth** in `xfiles`. Bluetooth discovery runs through `/usr/local/bin/bluetoothctl` and `bananarchy-bt-scan.sh`, which keeps one interactive `bluetoothctl` PTY client alive, sets auto transport and duplicate-data, queries `devices` during active discovery, and stops discovery cleanly so unpaired peripherals are not dropped when the scan command exits. A narrow `doas` helper runs `btmgmt -i hci0 le on` before each scan because the WCNSS controller otherwise powers up with LE disabled and only performs BR/EDR inquiry. BlueZ runs in `dual` controller mode because `bredr` mode rejects the LE-only HOGP profile, leaving BLE keyboards and mice connected but without a usable input node. Pair/connect actions power the adapter on, enable LE, force the LE bearer for HID-over-GATT devices, and pair unbonded peripherals before connecting.
- **File manager (`xfiles`) with microSD automount (`sxmo_sdcard.sh`), Bluetooth file sharing, music and tracker player (`xmusic`), and camera (`xcamera`)**: keypad directory browser with automatic microSD card (`/dev/mmcblk1`) detection and `/media/sdcard` mounting/unmounting, **Send via Bluetooth** OBEX file push to paired/discovered devices, built-in text viewer, integrated GUI multi-tap text editor (`Edit in Text Editor`, available as an action on any file), image viewer, and dedicated monophonic ringtone viewer (`RingtoneView` for Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` with graphical piano-roll pitch contour, note sequence viewer, live audio preview, and one-key assignment as call ringtone or notification/SMS sound — plus one-click actions to launch `.jar`/`.jad` MIDlets in the **ReMEdy (`remedy`)** J2ME emulator, launch `.gb`/`.gbc` ROMs in the Game Boy emulator, run `.yab` scripts in Yabasic inside the terminal, play audio, preview images, set any image as wallpaper, or install any audio, tracker, or monophonic melody file as call ringtone or notification/SMS sound), a 3-tab music and chiptune tracker module player (`WAV`, `MP3`, `OGG`, `FLAC`, `Opus`, `MOD`, `XM`, `IT`, `S3M`, `NRT`, `RTTTL`, `RTX`, `EMY`, `IMY`, and more), and a live V4L2 camera viewfinder with digital zoom, flash/torch control, self-timer, and photo gallery.
- **Native NeoUI communication and internet suite (`xsip`, `xemail`, `xirc`, `xtox`, `xkopher`, `webarchy`)**:
- **SIP VoIP client (`xsip` / `sip.so`)**: RFC 3261 SIP softphone (`Dialer`, `Accounts`, `History`) supporting both account-registered calling (with Digest MD5 authentication and standby `REGISTER` keepalive) and direct accountless P2P SIP URI calling (`user@host[:port]` or `sip:user@host[:port]`), RFC 3263 DNS `SRV` (`_sip._udp.<domain>`) proxy discovery and dialog routing, RFC 6189 **ZRTP** media-path Diffie-Hellman (`DH3k`/`DH2k`) key agreement and RFC 3711 **SRTP** (`AES-128-CM` + `HMAC-SHA1-80`) voice encryption with a 4-character `SAS` verification code, incoming `INVITE` ringing and call handling integrated with `xcallscreen` (`[SIP/<codec>]` / `[SIP/<codec>:<sas>]`), multi-codec wideband and narrowband RTP/SRTP audio (`Opus` 16 kHz / 48 kHz RTP clock with in-band FEC, `ITU-T G.722` 16 kHz wideband SB-ADPCM, `G.711 PCMU`/`PCMA` 8 kHz, `GSM 06.10` Full Rate 8 kHz, `ITU-T G.726-32` 8 kHz ADPCM, `IMA ADPCM DVI4` 8/16 kHz, and `L16` uncompressed 16-bit PCM 8/16 kHz) with per-account and direct-mode codec preference selection, and RFC 2833 / RFC 4733 DTMF.
+1 -1
View File
@@ -3,7 +3,7 @@
# user enables it, do not leave the controller permanently discoverable.
DiscoverableTimeout = 60
PairableTimeout = 60
ControllerMode = bredr
ControllerMode = dual
MultiProfile = multiple
JustWorksRepairing = always
Experimental = true
+67 -3
View File
@@ -547,6 +547,26 @@ def trust_device_path(conn, dev_path):
pass
def set_hog_preferred_bearer(conn, dev_path, props=None):
"""Force the LE bearer for HID-over-GATT devices before Pair/Connect."""
if not isinstance(dev_path, str) or not dev_path.startswith("/org/bluez/"):
return
uuids = []
if isinstance(props, dict):
uuids = [str(v).lower() for v in (props.get("UUIDs") or [])]
if not any(u.startswith("00001812-") for u in uuids):
return
try:
from jeepney import DBusAddress, new_method_call
prop_addr = DBusAddress(dev_path, bus_name="org.bluez",
interface="org.freedesktop.DBus.Properties")
conn.send(new_method_call(prop_addr, "Set", "ssv",
("org.bluez.Device1", "PreferredBearer",
("s", "le"))))
except Exception:
pass
def handle_agent_method_call(conn, msg, agent_path):
from jeepney import new_method_return, MessageType
if msg is None or msg.header.message_type != MessageType.method_call:
@@ -1006,6 +1026,26 @@ def ensure_daemon_running():
pass
def prepare_bt_controller():
"""Power the adapter and enable LE before DBus Pair/Connect calls."""
try:
subprocess.run(["timeout", "3", "bluetoothctl", "power", "on"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
timeout=4)
except Exception:
pass
helper = "/usr/bin/bananarchy-bt-le-enable.sh"
try:
if os.geteuid() == 0:
subprocess.run([helper], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=4)
else:
subprocess.run(["doas", "-n", helper], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=4)
except Exception:
pass
def clear_stale_linkkey(mac):
mac = mac.strip().upper()
if not mac:
@@ -1057,6 +1097,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
from jeepney.io.blocking import open_dbus_connection
ensure_daemon_running()
prepare_bt_controller()
mac = mac.strip().upper()
if not mac:
return 1
@@ -1189,8 +1230,9 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
)
def attempt_connect_path(dpath, want_pair):
trust_device_path(nonlocal_conn[0], dpath)
p = get_dev_props(dpath)
set_hog_preferred_bearer(nonlocal_conn[0], dpath, p)
trust_device_path(nonlocal_conn[0], dpath)
if p is None:
return False
if p.get("Connected"):
@@ -1293,6 +1335,8 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
props = get_dev_props(dev_path)
orig_unbonded = (props is None) or (not props.get("Paired") and not props.get("Bonded"))
if not do_pair and orig_unbonded and (props is not None or dev_name):
do_pair = True
if props and not dev_name:
dev_name = str(props.get("Name") or props.get("Alias") or "").strip()
if props is None and dev_name:
@@ -1344,10 +1388,12 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
def stop_daemon():
pids = set()
if os.path.exists(PID_FILE):
try:
with open(PID_FILE, "r", encoding="utf-8") as f:
pid = int(f.read().strip())
pids.add(pid)
os.kill(pid, signal.SIGTERM)
except Exception:
pass
@@ -1355,8 +1401,26 @@ def stop_daemon():
os.unlink(PID_FILE)
except OSError:
pass
subprocess.run(["pkill", "-f", "bananarchy-bt-obex daemon"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# The target rootfs is BusyBox-based and does not ship an external process
# killer, so find stale daemon command lines through /proc instead.
try:
for entry in os.listdir("/proc"):
if not entry.isdigit() or int(entry) == os.getpid():
continue
try:
with open("/proc/" + entry + "/cmdline", "rb") as cf:
cmd = cf.read().replace(b"\x00", b" ").decode("utf-8", "replace")
except OSError:
continue
if "bananarchy-bt-obex" in cmd and " daemon" in cmd:
pids.add(int(entry))
except OSError:
pass
for pid in pids:
try:
os.kill(pid, signal.SIGTERM)
except OSError:
pass
def main():
+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()