Fix Bluetooth 5.x/6.x headsets, Android OBEX prompts, and refresh a1120 images
- Scope WirePlumber 50-bluetooth.conf roles to [ a2dp_sink hsp_hs hfp_hf ], lock HFP to 8 kHz CVSD for QDSP6 INTERNAL_BT_SCO, enable dummy AVRCP player, and set LDAC ABR quality. - Select BR/EDR bearer and ConnectProfile fallback for Classic Audio headsets while preserving LE bearer for HOGP devices, forward AVRCP media keys to music.so, bound discoverability to 60 s, fix SCO keepalive teardown/readiness and ATA call state sync, and suppress nokia-sparkler speaker haptic audio during BT SCO. - Advertise Smartphone Class of Device (0x5a020c / btmgmt class 2 3), handle OBEX over both L2CAP SOCK_SEQPACKET and RFCOMM SOCK_STREAM via ObexPacketReader, and add NeoUI incoming file Accept/Reject dialog and configurable target folder picker in networks.so. - Add scripts/test-bluetooth-headset.py and scripts/test-bluetooth-obex.py, and rebuild/pin verified a1120 (cocojamboo) images and release archives for nokia-argon, nokia-beatles, nokia-coconut, and nokia-sparkler.
This commit is contained in:
1 parent
0030dc3910
commit
36a5f8cb8a
29 files changed
+2011
-190
No files matched your search
@@ -557,15 +557,15 @@ fi
|
||||
|
||||
echo "[check] Known-good flashable image set..."
|
||||
for pair in \
|
||||
"6b5c17059bf0341fdeb84c85dca08e64eb6b634e71add27fb9b7a93d17fb7ed8 images/bananarchy-nokia-argon.img" \
|
||||
"c6dad8d28ab3ab478869a0adb78dac1af4e19c111ab60a066687656c103e5723 images/bananarchy-nokia-beatles.img" \
|
||||
"4fd4b19d525677b2e2880346b391d9a13447d62f8ad61ee0088421a100ec08dc images/boot-bananarchy-nokia-beatles.img" \
|
||||
"92b23d34180c157861c492e7c2ea848ea4580857f3c1674020ae6b9f6fbdd39f images/bananarchy-nokia-argon.img" \
|
||||
"5c284c314a378d09fda37e56ebe745ab557d45c77499206440e8c362c709e7a7 images/bananarchy-nokia-beatles.img" \
|
||||
"80485ccf2af4f1d6107965ecde43d888c66ec19006e6feabc7fb63b6a7852391 images/boot-bananarchy-nokia-beatles.img" \
|
||||
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img" \
|
||||
"77addc7d48e40cdd017dc247969131e9ab7bc87ad590faf879d36c03b66df65c images/bananarchy-nokia-coconut.img" \
|
||||
"a5869b63de5cbfca3f6d87583aba162023670945f69a57276b597e1a7b85c5b2 images/boot-bananarchy-nokia-coconut.img" \
|
||||
"4e1d4799d42f56423f9cba8e175adf3b1f6c7fcd89965a7bc0b84a4f03ebc6e5 images/bananarchy-nokia-coconut.img" \
|
||||
"1e22879fc0533f419dc98c88a1700d75101fda85669837d1457bb15b9ab4ed9c images/boot-bananarchy-nokia-coconut.img" \
|
||||
"e876424b38b0782f589756b4107337b24f27f7c37d624cc7d3907a5331df050a images/boot-lk2nd-nokia-coconut-display.img" \
|
||||
"a41a6ed4c2a04d521cf44d5229680f292972a4fc06ff3ad177cc3a13659295d1 images/bananarchy-nokia-sparkler.img" \
|
||||
"e950788360e1044d5ef128d1a170b868620aa5c356354aa6ac7178218e4d8e38 images/boot-bananarchy-nokia-sparkler.img" \
|
||||
"6b40db4674821bdde80d6f7619acc5a6414df684201d3e4e2e7cc3ac6c25dcfd images/bananarchy-nokia-sparkler.img" \
|
||||
"8f41328f0197f5debba92eaffa9df46c530721719309024a4d9cd7bf79a722c7 images/boot-bananarchy-nokia-sparkler.img" \
|
||||
"bc41c2ddd1079246a7e91a40222fcafb82b0b52965c8ee8081872767d006748f images/boot-lk2nd-nokia-sparkler-display.img"; do
|
||||
set -- $pair
|
||||
want=$1
|
||||
@@ -2034,6 +2034,24 @@ if ! "$BT_HID_TEST" >/dev/null 2>&1; then
|
||||
fail "host Bluetooth HID connection test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Bluetooth 5.x/6.x headset A2DP/HFP, AVRCP, SCO, and power policy..."
|
||||
BT_HEADSET_TEST="$BASE_DIR/scripts/test-bluetooth-headset.py"
|
||||
if [ ! -x "$BT_HEADSET_TEST" ]; then
|
||||
fail "missing host unit test scripts/test-bluetooth-headset.py"
|
||||
fi
|
||||
if ! "$BT_HEADSET_TEST" >/dev/null 2>&1; then
|
||||
fail "host Bluetooth headset verification failed"
|
||||
fi
|
||||
|
||||
echo "[check] Bluetooth OBEX phone CoD, L2CAP SEQPACKET, and confirmation dialog..."
|
||||
BT_OBEX_TEST="$BASE_DIR/scripts/test-bluetooth-obex.py"
|
||||
if [ ! -x "$BT_OBEX_TEST" ]; then
|
||||
fail "missing host unit test scripts/test-bluetooth-obex.py"
|
||||
fi
|
||||
if ! "$BT_OBEX_TEST" >/dev/null 2>&1; then
|
||||
fail "host Bluetooth OBEX verification 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"
|
||||
|
||||
Executable
+242
@@ -0,0 +1,242 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host regression tests for Bluetooth 5.x/6.x headset support (A2DP + HSP/HFP).
|
||||
|
||||
Covers:
|
||||
- WirePlumber 50-bluetooth.conf consistency across all overlay/user templates
|
||||
(cvsd-only HFP without mSBC/lc3-a127/lc3_swb/bap/hfp_ag, dummy-avrcp-player,
|
||||
LDAC auto ABR and AAC CBR defaults).
|
||||
- Dual-mode BR/EDR vs BLE bearer selection in bananarchy-bt-obex without
|
||||
regressing LE HOGP keyboards/mice/gamepads, plus AVRCP media key dispatch.
|
||||
- SCO keepalive race handling, zero pkill dependency, hardware volume routing,
|
||||
headset ATA call pickup synchronization, and n-sparkler SCO haptic guard.
|
||||
- Off-by-default discoverability with bounded 60s timeout across toggle,
|
||||
daemon, and xnetworks UI.
|
||||
- All four target DTBs (argon, beatles, coconut, sparkler) exposing WCNSS-BT
|
||||
and QDSP6 INTERNAL_BT_SCO DAIs.
|
||||
"""
|
||||
import ast
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
WP_CONFS = (
|
||||
BASE / "overlay/rootfs/etc/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
|
||||
BASE / "overlay/rootfs/usr/share/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
|
||||
BASE / "overlay/rootfs/home/user/.config/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
|
||||
BASE / "overlay/rootfs/etc/skel/.config/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
|
||||
)
|
||||
|
||||
BT_OBEX = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-obex"
|
||||
BT_TOGGLE = BASE / "overlay/rootfs/usr/bin/sxmo_bluetoothtoggle.sh"
|
||||
AUDIO_SH = BASE / "overlay/rootfs/usr/bin/sxmo_audio.sh"
|
||||
MODEMAUDIO_SH = BASE / "overlay/rootfs/usr/bin/sxmo_modemaudio.sh"
|
||||
CALLSCREEN_CPP = BASE / "src/dwm-plugins/callscreen_plugin.cpp"
|
||||
NETWORKS_CPP = BASE / "src/dwm-plugins/networks_plugin.cpp"
|
||||
MUSIC_CPP = BASE / "src/dwm-plugins/music_plugin.cpp"
|
||||
VIBRATE_C = BASE / "src/dwm-plugins/sxmo_vibrate.c"
|
||||
|
||||
TARGET_DTBS = (
|
||||
BASE / "prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-argon.dtb",
|
||||
BASE / "prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb",
|
||||
BASE / "prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-coconut.dtb",
|
||||
BASE / "prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8909-nokia-sparkler.dtb",
|
||||
)
|
||||
|
||||
|
||||
def require(cond, msg):
|
||||
if not cond:
|
||||
raise SystemExit("FAIL: " + msg)
|
||||
|
||||
|
||||
def read(path):
|
||||
return path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def load_obex_pure_helpers():
|
||||
src = read(BT_OBEX)
|
||||
tree = ast.parse(src, filename=str(BT_OBEX))
|
||||
wanted_assigns = {"CLASSIC_AUDIO_UUID_PREFIXES"}
|
||||
wanted_defs = {
|
||||
"is_hog_device_props",
|
||||
"is_classic_audio_props",
|
||||
"avrcp_fifo_command_for_key",
|
||||
}
|
||||
selected = []
|
||||
for node in tree.body:
|
||||
if isinstance(node, ast.Assign):
|
||||
names = [t.id for t in node.targets if isinstance(t, ast.Name)]
|
||||
if any(n in wanted_assigns for n in names):
|
||||
selected.append(ast.get_source_segment(src, node))
|
||||
elif isinstance(node, ast.FunctionDef) and node.name in wanted_defs:
|
||||
selected.append(ast.get_source_segment(src, node))
|
||||
require(len(selected) == len(wanted_assigns) + len(wanted_defs),
|
||||
"missing pure audio/AVRCP helpers in bananarchy-bt-obex")
|
||||
ns = {}
|
||||
exec("\n\n".join(selected), ns)
|
||||
return ns
|
||||
|
||||
|
||||
def test_wireplumber_config():
|
||||
texts = [read(p) for p in WP_CONFS]
|
||||
for idx, t in enumerate(texts[1:], 1):
|
||||
require(t == texts[0],
|
||||
f"50-bluetooth.conf copy {WP_CONFS[idx]} drifted from etc/wireplumber copy")
|
||||
cfg = texts[0]
|
||||
for forbidden in ("bap_sink", "bap_source", "a2dp_source", "hsp_ag", "hfp_ag",
|
||||
"opus_05_dup ", "opus_05_51", "opus_05_71", "opus_05_pro",
|
||||
" lc3 "):
|
||||
require(forbidden not in cfg,
|
||||
f"50-bluetooth.conf still contains incompatible token {forbidden!r}")
|
||||
for required in (
|
||||
"bluez5.roles = [ a2dp_sink hsp_hs hfp_hf ]",
|
||||
"opus_05_duplex",
|
||||
"bluez5.enable-msbc = false",
|
||||
"bluez5.enable-lc3-a127 = false",
|
||||
"bluez5.enable-hw-volume = true",
|
||||
"bluez5.dummy-avrcp-player = true",
|
||||
'bluez5.a2dp.ldac.quality = "auto"',
|
||||
"bluez5.a2dp.aac.bitratemode = 0",
|
||||
'bluez5.hfphsp-backend = "native"',
|
||||
):
|
||||
require(required in cfg, f"50-bluetooth.conf missing {required!r}")
|
||||
print("[ok] WirePlumber 50-bluetooth.conf profiles, codecs, AVRCP, and CVSD lock")
|
||||
|
||||
|
||||
def test_obex_bearer_and_avrcp():
|
||||
ns = load_obex_pure_helpers()
|
||||
is_hog = ns["is_hog_device_props"]
|
||||
is_audio = ns["is_classic_audio_props"]
|
||||
map_avrcp = ns["avrcp_fifo_command_for_key"]
|
||||
|
||||
hog_kbd = {"UUIDs": ["00001812-0000-1000-8000-00805f9b34fb"]}
|
||||
bt5_dual_buds = {
|
||||
"AddressType": "public",
|
||||
"UUIDs": [
|
||||
"0000110b-0000-1000-8000-00805f9b34fb",
|
||||
"0000111e-0000-1000-8000-00805f9b34fb",
|
||||
"0000184e-0000-1000-8000-00805f9b34fb",
|
||||
],
|
||||
"Icon": "audio-headset",
|
||||
"Class": 0x240404,
|
||||
}
|
||||
ble_beacon = {"AddressType": "random", "UUIDs": ["00001800-0000-1000-8000-00805f9b34fb"]}
|
||||
cod_only_speaker = {"Class": 0x200414}
|
||||
|
||||
require(is_hog(hog_kbd) and not is_audio(hog_kbd),
|
||||
"HOGP keyboard misclassified as Classic Audio")
|
||||
require(is_audio(bt5_dual_buds) and not is_hog(bt5_dual_buds),
|
||||
"Dual-mode BT 5.x/6.x headset not recognized for BR/EDR bearer selection")
|
||||
require(is_audio({"Icon": "audio-headphones"}),
|
||||
"audio-headphones Icon not recognized as Classic Audio")
|
||||
require(is_audio(cod_only_speaker),
|
||||
"Audio CoD speaker not recognized as Classic Audio")
|
||||
require(not is_audio(ble_beacon),
|
||||
"Generic BLE beacon falsely matched Classic Audio")
|
||||
|
||||
require(map_avrcp(164) == "PLAYPAUSE", "KEY_PLAYPAUSE mapping wrong")
|
||||
require(map_avrcp(200) == "PLAY", "KEY_PLAYCD mapping wrong")
|
||||
require(map_avrcp(201) == "PAUSE", "KEY_PAUSECD mapping wrong")
|
||||
require(map_avrcp(166) == "STOP", "KEY_STOPCD mapping wrong")
|
||||
require(map_avrcp(163) == "NEXT", "KEY_NEXTSONG mapping wrong")
|
||||
require(map_avrcp(165) == "PREV", "KEY_PREVIOUSSONG mapping wrong")
|
||||
require(map_avrcp(30) is None, "unrelated key mapped as AVRCP")
|
||||
|
||||
obex_src = read(BT_OBEX)
|
||||
for tok in (
|
||||
"set_hog_preferred_bearer(",
|
||||
"set_audio_preferred_bearer(",
|
||||
'("s", "bredr")',
|
||||
"ConnectProfile",
|
||||
"has_media_transport(",
|
||||
"is_tentative_ble_non_hog(",
|
||||
"avrcp_devs",
|
||||
"dispatch_avrcp_key(",
|
||||
):
|
||||
require(tok in obex_src, f"bananarchy-bt-obex missing {tok}")
|
||||
print("[ok] Dual-bearer BR/EDR headset selection, HOGP preservation, and AVRCP bridge")
|
||||
|
||||
|
||||
def test_discoverability_and_power():
|
||||
obex_src = read(BT_OBEX)
|
||||
toggle_src = read(BT_TOGGLE)
|
||||
net_src = read(NETWORKS_CPP)
|
||||
|
||||
require('discoverable-timeout 0' not in toggle_src,
|
||||
"sxmo_bluetoothtoggle.sh still sets infinite discoverable-timeout 0")
|
||||
require('discoverable-timeout 60' in toggle_src and 'bt_disc="0"' in toggle_src,
|
||||
"sxmo_bluetoothtoggle.sh must default bt_disc=0 and timeout=60")
|
||||
require('"discoverable-timeout", "0"' not in obex_src and
|
||||
'("org.bluez.Adapter1", "PairableTimeout", ("u", 0))' not in obex_src,
|
||||
"bananarchy-bt-obex still forces infinite discoverable/pairable timeout 0")
|
||||
require('"discoverable-timeout", "60"' in obex_src and 'bt_disc = "0"' in obex_src,
|
||||
"bananarchy-bt-obex must default bt_disc='0' and timeout=60")
|
||||
require("discoverable-timeout 0" not in net_src and
|
||||
"discoverable-timeout 60" in net_src,
|
||||
"networks_plugin.cpp must use 60s discoverable timeout")
|
||||
print("[ok] Bounded 60s discoverability and hidden-by-default battery safeguard")
|
||||
|
||||
|
||||
def test_sco_audio_call_and_haptics():
|
||||
audio_src = read(AUDIO_SH)
|
||||
maudio_src = read(MODEMAUDIO_SH)
|
||||
cs_src = read(CALLSCREEN_CPP)
|
||||
net_src = read(NETWORKS_CPP)
|
||||
music_src = read(MUSIC_CPP)
|
||||
vib_src = read(VIBRATE_C)
|
||||
|
||||
require("pkill" not in audio_src,
|
||||
"sxmo_audio.sh must not invoke missing pkill binary")
|
||||
require("launch_bt_sco_pacat" in audio_src and
|
||||
"/tmp/sxmo_bt_sco_wait.pid" in audio_src and
|
||||
"apply_bt_sink_volume" in audio_src,
|
||||
"sxmo_audio.sh missing bounded SCO keepalive retry or $bt_sink volume control")
|
||||
require("elif [ ! -r /tmp/sxmo_in_call ]; then\n stop_bt_sco_keepalive" not in audio_src,
|
||||
"sxmo_audio.sh leaks SCO pacat keepalive when switching off BT mid-call")
|
||||
require("bluez_output\\." in maudio_src and "switch_bt_card_hfp" in maudio_src,
|
||||
"sxmo_modemaudio.sh missing synchronous BT SCO sink readiness wait")
|
||||
require('.pickedupcall' in cs_src and
|
||||
'writeIntFile("/tmp/sxmo_in_call", 1)' in cs_src,
|
||||
"callscreen_plugin.cpp missing headset ATA .pickedupcall / sxmo_in_call sync")
|
||||
require("refreshTargetBtFromList" in net_src and "infoCount >= 24" in net_src,
|
||||
"networks_plugin.cpp missing stale targetBt refresh or info cap bump")
|
||||
for tok in ("XF86XK_AudioPlay", "XF86XK_AudioNext", "XF86XK_AudioPrev",
|
||||
'cmd == "PLAYPAUSE"', 'cmd == "NEXT"', 'cmd == "PREV"'):
|
||||
require(tok in music_src, f"music_plugin.cpp missing AVRCP handler {tok}")
|
||||
require("/tmp/sxmo_bt_sco_mm_active" in vib_src,
|
||||
"sxmo_vibrate.c missing /tmp/sxmo_bt_sco_mm_active haptic suppression")
|
||||
print("[ok] SCO keepalive, ATA call sync, AVRCP music control, and Sparkler SCO haptic guard")
|
||||
|
||||
|
||||
def test_target_dtbs():
|
||||
dtc = shutil.which("dtc")
|
||||
if not dtc:
|
||||
print("[skip] dtc not installed; skipping DTB inspection")
|
||||
return
|
||||
for dtb in TARGET_DTBS:
|
||||
require(dtb.is_file(), f"missing shipped DTB: {dtb}")
|
||||
dts = subprocess.check_output(
|
||||
[dtc, "-q", "-I", "dtb", "-O", "dts", str(dtb)],
|
||||
text=True,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
for node in ('compatible = "qcom,wcnss-bt"', "dai@136", "dai@137",
|
||||
'link-name = "Internal BT-SCO RX"',
|
||||
'link-name = "Internal BT-SCO TX"'):
|
||||
require(node in dts, f"{dtb.name} missing BT/QDSP6 node {node!r}")
|
||||
print("[ok] All 4 target DTBs include WCNSS-BT and INTERNAL_BT_SCO DAIs")
|
||||
|
||||
|
||||
def main():
|
||||
test_wireplumber_config()
|
||||
test_obex_bearer_and_avrcp()
|
||||
test_discoverability_and_power()
|
||||
test_sco_audio_call_and_haptics()
|
||||
test_target_dtbs()
|
||||
print("bluetooth headset verification: all checks passed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+276
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host tests for Bluetooth OBEX OPP recognition, L2CAP SEQPACKET & confirmation UI.
|
||||
|
||||
Covers:
|
||||
- Smartphone Class of Device (0x5a020c in main.conf, btmgmt class 2 3 in
|
||||
LE/toggle helpers) and absence of a2dp_source role in 50-bluetooth.conf so
|
||||
Android phones recognize Bananarchy as a phone capable of OPP transfers.
|
||||
- ObexPacketReader over both AF_UNIX SOCK_SEQPACKET (simulating L2CAP GOEP 2.0)
|
||||
and SOCK_STREAM (RFCOMM GOEP 1.1) without packet truncation.
|
||||
- End-to-end handle_obex_rx_session() over SOCK_SEQPACKET verifying user ACCEPT
|
||||
into a custom target directory and user REJECT returning 0xC3 without writing.
|
||||
- Reliable RegisterProfile before RFCOMM channel 9 fallback and NeoUI dialog
|
||||
wiring in networks_plugin.cpp.
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import types
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
MAIN_CONF = BASE / "overlay/rootfs/etc/bluetooth/main.conf"
|
||||
LE_HELPER = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-le-enable.sh"
|
||||
BT_TOGGLE = BASE / "overlay/rootfs/usr/bin/sxmo_bluetoothtoggle.sh"
|
||||
BT_OBEX = BASE / "overlay/rootfs/usr/bin/bananarchy-bt-obex"
|
||||
NETWORKS_CPP = BASE / "src/dwm-plugins/networks_plugin.cpp"
|
||||
WP_CONF = BASE / "overlay/rootfs/etc/wireplumber/wireplumber.conf.d/50-bluetooth.conf"
|
||||
|
||||
|
||||
def require(cond, msg):
|
||||
if not cond:
|
||||
raise SystemExit("FAIL: " + msg)
|
||||
|
||||
|
||||
def read(path):
|
||||
return path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def load_obex_module():
|
||||
src = read(BT_OBEX)
|
||||
mod = types.ModuleType("bananarchy_bt_obex")
|
||||
mod.__file__ = str(BT_OBEX)
|
||||
exec(compile(src, str(BT_OBEX), "exec"), mod.__dict__)
|
||||
return mod
|
||||
|
||||
|
||||
def test_class_and_roles():
|
||||
main_conf = read(MAIN_CONF)
|
||||
require("ControllerMode = dual" in main_conf, "main.conf must keep ControllerMode = dual")
|
||||
require("Class = 0x5a020c" in main_conf, "main.conf missing Smartphone Class = 0x5a020c")
|
||||
require("btmgmt -i hci0 class 2 3" in read(LE_HELPER),
|
||||
"bananarchy-bt-le-enable.sh missing btmgmt class 2 3")
|
||||
require("btmgmt -i hci0 class 2 3" in read(BT_TOGGLE),
|
||||
"sxmo_bluetoothtoggle.sh missing btmgmt class 2 3")
|
||||
wp = read(WP_CONF)
|
||||
require("a2dp_source" not in wp and "bluez5.roles = [ a2dp_sink hsp_hs hfp_hf ]" in wp,
|
||||
"50-bluetooth.conf must omit a2dp_source so phones do not treat us as an audio sink")
|
||||
print("[ok] Smartphone Class-of-Device and Phone/OPP SDP profile role gate")
|
||||
|
||||
|
||||
def build_obex_put_headers(filename, total_len):
|
||||
name_utf16 = filename.encode("utf-16-be") + b"\x00\x00"
|
||||
name_hdr = struct.pack(">BH", 0x01, 3 + len(name_utf16)) + name_utf16
|
||||
len_hdr = struct.pack(">BI", 0xC3, total_len)
|
||||
return name_hdr + len_hdr
|
||||
|
||||
|
||||
def build_obex_body(chunk, is_final):
|
||||
hi = 0x49 if is_final else 0x48
|
||||
return struct.pack(">BH", hi, 3 + len(chunk)) + chunk
|
||||
|
||||
|
||||
def recv_raw_pkt(sock):
|
||||
dat = sock.recv(4096)
|
||||
require(len(dat) >= 3, "short OBEX response packet")
|
||||
return dat[0], dat[3:]
|
||||
|
||||
|
||||
def test_seqpacket_and_stream_reader(mod):
|
||||
# 1. SOCK_SEQPACKET (Android L2CAP GOEP 2.0): full PDU arrived in one recv()
|
||||
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
try:
|
||||
payload = build_obex_put_headers("android_photo_test.jpg", 12345) + build_obex_body(b"ABCD1234", False)
|
||||
pkt = struct.pack(">BH", 0x02, 3 + len(payload)) + payload
|
||||
a.sendall(pkt)
|
||||
reader = mod.ObexPacketReader(b)
|
||||
op, got = mod.recv_obex_packet(reader)
|
||||
require(op == 0x02 and got == payload,
|
||||
f"SOCK_SEQPACKET packet truncated or corrupted (got {len(got or b'')} vs {len(payload)})")
|
||||
finally:
|
||||
a.close()
|
||||
b.close()
|
||||
|
||||
# 2. SOCK_STREAM (RFCOMM): split headers across fragments
|
||||
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
try:
|
||||
payload = build_obex_put_headers("rfcomm_test.txt", 5) + build_obex_body(b"hello", True)
|
||||
pkt = struct.pack(">BH", 0x82, 3 + len(payload)) + payload
|
||||
a.sendall(pkt[:2])
|
||||
a.sendall(pkt[2:9])
|
||||
a.sendall(pkt[9:])
|
||||
reader = mod.ObexPacketReader(b)
|
||||
op, got = mod.recv_obex_packet(reader)
|
||||
require(op == 0x82 and got == payload, "SOCK_STREAM reassembly failed")
|
||||
finally:
|
||||
a.close()
|
||||
b.close()
|
||||
print("[ok] ObexPacketReader framing over SOCK_SEQPACKET and SOCK_STREAM")
|
||||
|
||||
|
||||
def test_accept_and_reject_sessions(mod):
|
||||
old_no_ui = os.environ.get("BANANARCHY_OBEX_NO_UI")
|
||||
os.environ["BANANARCHY_OBEX_NO_UI"] = "1"
|
||||
orig_vals = (
|
||||
mod.OBEX_CFG_FILE,
|
||||
mod.OBEX_IPC_DIR,
|
||||
mod.OBEX_PROMPT_FILE,
|
||||
mod.OBEX_DECISION_FILE,
|
||||
mod.RX_STATUS_FILE,
|
||||
mod.TX_STATUS_FILE,
|
||||
)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-obex-test-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
ipc_dir = root / "ipc"
|
||||
default_dir = root / "downloads"
|
||||
custom_dir = root / "sdcard_custom"
|
||||
default_dir.mkdir()
|
||||
custom_dir.mkdir()
|
||||
cfg_file = root / "bt_obex_dir"
|
||||
cfg_file.write_text(str(default_dir) + "\n", encoding="utf-8")
|
||||
|
||||
mod.OBEX_CFG_FILE = str(cfg_file)
|
||||
mod.OBEX_IPC_DIR = str(ipc_dir)
|
||||
mod.OBEX_PROMPT_FILE = str(ipc_dir / "prompt.tsv")
|
||||
mod.OBEX_DECISION_FILE = str(ipc_dir / "decision.tsv")
|
||||
mod.RX_STATUS_FILE = str(root / "rx.status")
|
||||
mod.TX_STATUS_FILE = str(root / "tx.status")
|
||||
|
||||
# --- Case A: Accept and save to custom folder over SOCK_SEQPACKET ---
|
||||
cli, srv = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
t = threading.Thread(
|
||||
target=mod.handle_obex_rx_session,
|
||||
args=(srv, "Pixel Test", "AA:BB:CC:DD:EE:11"),
|
||||
daemon=True,
|
||||
)
|
||||
t.start()
|
||||
try:
|
||||
cli.sendall(struct.pack(">BHBBH", 0x80, 7, 0x10, 0x00, 0x8000))
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0xA0, f"expected CONNECT OK (0xA0), got {hex(op)}")
|
||||
|
||||
hdrs = build_obex_put_headers("greeting.txt", 12) + build_obex_body(b"hello ", False)
|
||||
cli.sendall(struct.pack(">BH", 0x02, 3 + len(hdrs)) + hdrs)
|
||||
|
||||
prompt_path = pathlib.Path(mod.OBEX_PROMPT_FILE)
|
||||
deadline = time.monotonic() + 3.0
|
||||
while not prompt_path.exists() and time.monotonic() < deadline:
|
||||
time.sleep(0.02)
|
||||
require(prompt_path.exists(), "OBEX prompt file was never created")
|
||||
fields = prompt_path.read_text(encoding="utf-8").strip().split("\t")
|
||||
require(len(fields) == 6 and fields[1] == "Pixel Test" and fields[3] == "greeting.txt",
|
||||
f"unexpected prompt TSV: {fields}")
|
||||
req_id = fields[0]
|
||||
pathlib.Path(mod.OBEX_DECISION_FILE).write_text(
|
||||
f"{req_id}\tACCEPT\t{custom_dir}\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0x90, f"expected Continue (0x90) after ACCEPT, got {hex(op)}")
|
||||
|
||||
tail = build_obex_body(b"world!", True)
|
||||
cli.sendall(struct.pack(">BH", 0x82, 3 + len(tail)) + tail)
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0xA0, f"expected OK (0xA0) after PUT-Final, got {hex(op)}")
|
||||
|
||||
cli.sendall(struct.pack(">BH", 0x81, 3))
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0xA0, "expected DISCONNECT OK (0xA0)")
|
||||
finally:
|
||||
cli.close()
|
||||
t.join(timeout=3.0)
|
||||
|
||||
saved_file = custom_dir / "greeting.txt"
|
||||
require(saved_file.is_file() and saved_file.read_bytes() == b"hello world!",
|
||||
"accepted file missing or corrupted in custom target folder")
|
||||
require(not pathlib.Path(mod.OBEX_PROMPT_FILE).exists(),
|
||||
"stale OBEX prompt file was not removed")
|
||||
|
||||
# --- Case B: Reject inline PUT-Final over SOCK_SEQPACKET ---
|
||||
cli, srv = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
t = threading.Thread(
|
||||
target=mod.handle_obex_rx_session,
|
||||
args=(srv, "Unknown Phone", "AA:BB:CC:DD:EE:22"),
|
||||
daemon=True,
|
||||
)
|
||||
t.start()
|
||||
try:
|
||||
cli.sendall(struct.pack(">BHBBH", 0x80, 7, 0x10, 0x00, 0x8000))
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0xA0, "expected CONNECT OK")
|
||||
|
||||
one_shot = build_obex_put_headers("rejected.bin", 4) + build_obex_body(b"NOPE", True)
|
||||
cli.sendall(struct.pack(">BH", 0x82, 3 + len(one_shot)) + one_shot)
|
||||
|
||||
prompt_path = pathlib.Path(mod.OBEX_PROMPT_FILE)
|
||||
deadline = time.monotonic() + 3.0
|
||||
while not prompt_path.exists() and time.monotonic() < deadline:
|
||||
time.sleep(0.02)
|
||||
require(prompt_path.exists(), "OBEX prompt file not created for reject case")
|
||||
req_id = prompt_path.read_text(encoding="utf-8").strip().split("\t")[0]
|
||||
pathlib.Path(mod.OBEX_DECISION_FILE).write_text(
|
||||
f"{req_id}\tREJECT\t{custom_dir}\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
op, _ = recv_raw_pkt(cli)
|
||||
require(op == 0xC3, f"expected Forbidden (0xC3) on REJECT, got {hex(op)}")
|
||||
finally:
|
||||
cli.close()
|
||||
t.join(timeout=3.0)
|
||||
|
||||
require(not (custom_dir / "rejected.bin").exists() and not (default_dir / "rejected.bin").exists(),
|
||||
"rejected file must never be written to disk")
|
||||
finally:
|
||||
(
|
||||
mod.OBEX_CFG_FILE,
|
||||
mod.OBEX_IPC_DIR,
|
||||
mod.OBEX_PROMPT_FILE,
|
||||
mod.OBEX_DECISION_FILE,
|
||||
mod.RX_STATUS_FILE,
|
||||
mod.TX_STATUS_FILE,
|
||||
) = orig_vals
|
||||
if old_no_ui is None:
|
||||
os.environ.pop("BANANARCHY_OBEX_NO_UI", None)
|
||||
else:
|
||||
os.environ["BANANARCHY_OBEX_NO_UI"] = old_no_ui
|
||||
print("[ok] Incoming OBEX Accept/Reject & custom target directory loopback sessions")
|
||||
|
||||
|
||||
def test_networks_ui_wiring():
|
||||
src = read(NETWORKS_CPP)
|
||||
for tok in (
|
||||
"ObexActions",
|
||||
"ObexDirPicker",
|
||||
"ObexIncomingPrompt",
|
||||
"OBEX_PROMPT",
|
||||
"bt_obex_dir",
|
||||
"writeObexDecision",
|
||||
"readObexPromptFile",
|
||||
"openObexDirPicker",
|
||||
"tryPresentObexPrompt",
|
||||
):
|
||||
require(tok in src, f"networks_plugin.cpp missing OBEX UI element {tok}")
|
||||
obex_src = read(BT_OBEX)
|
||||
require("if running and not opp_registered:\n rfcomm_listener = bind_rfcomm_fallback()" in obex_src,
|
||||
"bananarchy-bt-obex must register BlueZ OPP profile before fallback channel 9 bind")
|
||||
print("[ok] networks_plugin.cpp OBEX confirmation & directory picker UI wiring")
|
||||
|
||||
|
||||
def main():
|
||||
mod = load_obex_module()
|
||||
test_class_and_roles()
|
||||
test_seqpacket_and_stream_reader(mod)
|
||||
test_accept_and_reject_sessions(mod)
|
||||
test_networks_ui_wiring()
|
||||
print("bluetooth obex verification: all checks passed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user