Skip to content

fix: clear a soft rfkill block before claiming hciN - #10

Closed
DTTerastar wants to merge 1 commit into
mainfrom
fix/rfkill-unblock-hci0
Closed

DTTerastar wants to merge 1 commit into
mainfrom
fix/rfkill-unblock-hci0

Conversation

@DTTerastar

Copy link
Copy Markdown
Contributor

Why

With the heartbeat guard fix in place (v1.2.1), the guard no longer fails on a stale leftover; it now reports the real bench state. That state is:

[flood] hci0 claimed, rotating at 40.0/s
[flood] HCI_Reset unanswered after 15s (attempt 1/3)
... attempt 3/3
HciError: HCI_Reset never completed in 3 attempts: no completion event within 15.0s (nothing arrived at all).
rfkill: /sys/class/bluetooth/hci0/rfkill0/state=blocked

A soft rfkill block survives on the host between runs. It leaves the controller silent while still allowing the HCI user-channel bind, so the failure looks like a dead dongle and costs 45s (3 × 15s) before it is named.

What changed

The flood clears a soft block on hciN right after it claims the adapter and before the first command, instead of spending 45s discovering it. It is privileged, so it can write the sysfs state. It only ever unblocks, and only its own adapter; it never writes 1 back.

The switch lives under hciN/rfkillM and M is not N, so the adapter is matched on the hciN directory rather than a guessed rfkill number. _silent_hint reuses the same reader.

Verification

Selftest (also the CI step) pins:

  • a blocked adapter's switch is cleared
  • an already-unblocked adapter is left alone
  • a different adapter's block is left alone
  • a missing switch is not an error (no rfkill node, or /sys not mounted)

Open question

An in-container unblock only helps if the container can write /sys/class/bluetooth/hciN/rfkillM/state. The flood step is privileged and network_mode: host, so it should be able to, but that has to be confirmed on the bench; the log now says either "unblocked it" or the errno if it could not. If the host blocks sysfs writes from the container, the alternative is a rfkill unblock bluetooth on the runner outside the pipeline.

🤖 Generated with Claude Code

With the heartbeat bug fixed, the guard now reports the real bench state instead
of a stale leftover: the flood binds hci0, then every command goes unanswered and
HCI_Reset gives up after 45s, with rfkill state=blocked. A soft block survives on
the host between runs and leaves the controller silent while still allowing the
bind, so it looks like a dead dongle. The flood is privileged, so it clears the
block itself, right after claiming the adapter and before the first command,
rather than spending 45s discovering it. Only hciN is touched, and only to
unblock.

The switch lives under hciN/rfkillM and M is not N, so the adapter is matched on
the hciN directory rather than a guessed rfkill number. Selftest covers a blocked
adapter (cleared), an unblocked one and a different adapter's block (left alone),
and a missing switch (not an error).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 05:52
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca26892d-f46a-4501-83d0-aede8f8d9972

📥 Commits

Reviewing files that changed from the base of the PR and between 3ce02b2 and 2a4f312.


📒 Files selected for processing (1)
  • ble_flood.py

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DTTerastar

Copy link
Copy Markdown
Contributor Author

Reducing the open question: the image has no USER directive (runs as root), the flood step is privileged: true, and sysfs is not namespaced, so writing /sys/class/bluetooth/hciN/rfkillM/state should be permitted. Only the bench run can confirm it, but the failure mode is explicit: the log prints either unblocked it (<path>) or the exact errno if the write is refused, so a single HIL run distinguishes the two.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rfkill state values are reversed, causing unblocked adapters to be blocked instead.

1 open finding
What changed in this PR

Adds automatic rfkill unblocking before starting BLE flooding.

Changes:

  • Adds reusable rfkill state discovery.
  • Attempts to unblock the selected adapter.
  • Adds self-test coverage for rfkill handling.
File Description
ble_flood.py Adds rfkill detection, unblocking, and tests.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ble_flood.py
Comment on lines +406 to +407
with open(path) as fh:
out.append((path, fh.read().strip() == "1"))
@DTTerastar

Copy link
Copy Markdown
Contributor Author

Closing: this is wrong. The kernel rfkill ABI (Documentation/ABI/stable/sysfs-class-rfkill) is 0=SOFT_BLOCKED, 1=UNBLOCKED, 2=HARD_BLOCKED, so validating 'state == 1 means blocked' is inverted. Worse, unblock_rfkill would have written 0 to a state==1 adapter, i.e. soft-blocked a healthy one. And the CI log proves rfkill is not the cause at all: it printed state=blocked, which only happens when the file read '1', which per the ABI is unblocked. The label was lying, so the silent controller has another cause. Fixing the inverted label instead, and re-diagnosing.

@DTTerastar DTTerastar closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants