Skip to content

Page classic Bluetooth printers through each adapter - #391

Merged
DL6ER merged 3 commits into
masterfrom
fix/classic-adapter
Dec 5, 2026
Merged

DL6ER merged 3 commits into
masterfrom
fix/classic-adapter

Conversation

@DL6ER

@DL6ER DL6ER commented Dec 5, 2026

Copy link
Copy Markdown
Owner

With two Bluetooth adapters, e.g., one shared over USB/IP from another room, the kernel paged printers on classic Bluetooth through whichever adapter it lists first. A Nelko P21 next to the computer was then never reached.

A connection now pages through each adapter with classic Bluetooth until one reaches the printer, starting with the one that last did. A pairing holds for one adapter only, so a refused pairing goes on to the next one too.

I tried it with the P21 and two adapters, one of them over USB/IP.

Before After
P21 cannot be reached P21 ready

DL6ER added 3 commits December 5, 2026 14:24
`transports.rfcomm()` never bound its socket, so the kernel paged printers on classic Bluetooth through its first adapter, the one added last. With a second adapter far away (e.g., one shared over USB/IP), a Nelko P21 next to the computer was never reached: every status query told `EHOSTDOWN`.

Each connection now pages through each adapter that is on with classic Bluetooth until one reaches the printer:

1. The adapter that last reached it comes first, then the one that heard it, then the kernel's order. `bluetooth.classic_adapters()` reads them from the management channel, one with Bluetooth LE only is left out.
2. A refused pairing goes on to the next adapter, a pairing holds for one adapter only. A gone adapter (`EHOSTUNREACH`, `ENETDOWN`, `ENODEV`, `EADDRNOTAVAIL`) is forgotten and the next one paged; where only gone adapters answered, the printer is told as `EHOSTUNREACH`, "The printer cannot be reached".
3. Only giving way stops it early. A printer switched off costs one page per adapter, about 10 s with two.
4. The paging of a connection that timed out is canceled, so that it does not go on while the next adapter pages.

The adapters on with Bluetooth LE and classic Bluetooth are read once for both and kept 60 s, 10 s where one did not tell what it is in time. That they cannot be read is logged once while it stays so.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
1. A connection no adapter reached reads the adapters again, so that the next one pages through an adapter switched on since, one that told what it is too late, and no longer through one switched off as it paged. Where an adapter reached the printer, i.e., it is not paired or refused the connection, the adapters read are kept.
2. What paging told is ranked in one place: not paired, an answer of the printer (`ECONNREFUSED`, `ECONNRESET`), switched off, anything else, e.g., a timeout, `EALREADY` or `ECONNABORTED`, then gone adapters.
3. The paging of a connection that timed out is canceled within the turn of Bluetooth, as on the way that gives way, so that the next connection does not page through the same adapter meanwhile.
4. The adapters read are kept in one place, `_keep()`, under a lock shared with `forget_adapters()`. A read is stamped with the time it began and kept only over an older one; `forget_adapters()` keeps an expired read of its own time, so that a read that began before it is not kept. That they cannot be read is logged once the lock is released.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 15:17

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@DL6ER
DL6ER merged commit 1a26443 into master Dec 5, 2026
7 checks passed
@DL6ER
DL6ER deleted the fix/classic-adapter branch December 5, 2026 16:07
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