Skip to content

Commit 219ef37

Browse files
committed
fix(wifi): use 501 stub pattern for P2P POSIX path
P2P operations (scan, connect, disconnect, status) require busctl + jq which are not available on BusyBox/POSIX path. Instead of an opaque error, return a proper 501 "Not Implemented" JSON error matching the established stub pattern (same as MPLS, tunnel, etc). Consolidates the dependency check into _p2p_check_deps() shared by all four P2P task functions. Agent-side P2P support is deferred to the RXNM 2.0 monolithic architecture.
1 parent 86dcf63 commit 219ef37

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

lib/rxnm-wifi.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,19 @@ _task_forget() {
253253
json_success '{"action": "forget", "ssid": "'"$json_safe_ssid"'", "removed_configs": '"$removed_count"'}'
254254
}
255255

256-
_task_p2p_scan() {
257-
# P2P operations require busctl + jq (Bash path). POSIX path delegates to agent.
256+
_p2p_check_deps() {
257+
# P2P operations require busctl + jq (Bash path only).
258+
# POSIX/BusyBox: return 501 — agent P2P support deferred to 2.0.
258259
if [ "$RXNM_HAS_JQ" != "true" ] || ! command -v busctl >/dev/null 2>&1; then
259-
echo "P2P scan requires jq and busctl" >&2; return 1
260+
json_error "P2P requires Bash path (jq + busctl). Not available on POSIX path." "501" \
261+
"Agent P2P support planned for RXNM 2.0"
262+
return 1
260263
fi
264+
return 0
265+
}
266+
267+
_task_p2p_scan() {
268+
_p2p_check_deps || return 1
261269

262270
local objects_json=""
263271
if ! objects_json=$(busctl --timeout=2s call net.connman.iwd / org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short 2>/dev/null); then
@@ -291,6 +299,7 @@ _task_p2p_scan() {
291299
}
292300

293301
_task_p2p_connect() {
302+
_p2p_check_deps || return 1
294303
local peer_name="$1"
295304
local objects_json; objects_json=$(busctl --timeout=2s call net.connman.iwd / org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short 2>/dev/null)
296305
local peer_path
@@ -301,13 +310,15 @@ _task_p2p_connect() {
301310
}
302311

303312
_task_p2p_disconnect() {
313+
_p2p_check_deps || return 1
304314
local objects_json; objects_json=$(busctl --timeout=2s call net.connman.iwd / org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short 2>/dev/null)
305315
local connected_peer; connected_peer=$(echo "$objects_json" | "$JQ_BIN" -r '.data[0] | to_entries[] | select(.value["net.connman.iwd.p2p.Peer"] != null) | select(.value["net.connman.iwd.p2p.Peer"].Connected.data == true) | .key')
306316
if [ -z "$connected_peer" ]; then echo "No P2P connection active"; return 1; fi
307317
if busctl --timeout=10s call net.connman.iwd "$connected_peer" net.connman.iwd.p2p.Peer Disconnect >/dev/null 2>&1; then echo "OK"; return 0; else echo "Disconnect failed"; return 1; fi
308318
}
309319

310320
_task_p2p_status() {
321+
_p2p_check_deps || return 1
311322
local objects_json; objects_json=$(busctl --timeout=2s call net.connman.iwd / org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short 2>/dev/null)
312323
local net_json="[]"
313324
if command -v networkctl >/dev/null; then net_json=$(timeout 2s networkctl list --json=short 2>/dev/null || echo "[]"); fi

0 commit comments

Comments
 (0)