Fix Watch detection on BlueZ 5.x (btmon decodes manufacturer data)#2
Open
Mulkitis wants to merge 1 commit into
Open
Fix Watch detection on BlueZ 5.x (btmon decodes manufacturer data)#2Mulkitis wants to merge 1 commit into
Mulkitis wants to merge 1 commit into
Conversation
The Nearby-Info parser matched the raw manufacturer byte string `4c 00 10 05 ...` on a single btmon line. BlueZ 5.x btmon does not print raw manufacturer hex; it decodes Apple data across separate lines (`Company: Apple, Inc. (76)` / `Type: Unknown (16)` / `Data: <payload>`) and never emits that byte string, so detection never fired (0 matches in an 8476-line capture on BlueZ 5.72). Replace the single-line regex with a per-report state machine that tracks Company -> Type(16) -> Data, reads the status flags from payload[1], and fires the detection on the report's trailing RSSI line (btmon prints RSSI last), yielding the correct RSSI. IRK handling, flag semantics, and the session-control path are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug report + fix: detection never fires on BlueZ 5.x (
btmondecodes manufacturer data)Issue
Title: Watch is never detected on BlueZ 5.x —
btmonnever emits the4c 00 10 05bytes the parser matchesEnvironment (tested):
btmonfrombluez5.72)cryptographypresentresolvable private addresses (so this is not an IRK/config problem)
Summary:
With a valid IRK and the Watch present, on-wrist, and unlocked, the daemon sits
at
Waiting for Apple Watch...and never logs[DETECT]. No unlock ever occurs.Root cause:
main()parsesbtmonoutput expecting the raw Apple manufacturer bytes on oneline:
btmonon BlueZ 5.x does not print raw manufacturer hex. It decodes Applemanufacturer-specific data across multiple lines and never emits the
4c 00 …byte string. A real advertising report looks like:
4c 00is rendered asCompany: Apple, Inc. (76).10is rendered asType: Unknown (16)(decimal).05) is consumed bybtmon; only the payload appears inData:.Consequently the regex matches zero times. In a ~30 s / 8476-line
btmoncapture on the tested system,
grep -c '4c 00 10 0[56]'returned0, while theWatch's Nearby Info was present throughout (as
Company: Apple, Inc. (76)/Type: Unknown (16)/Data:).Impact:
On the tested BlueZ 5.72 build the daemon is non-functional out of the box —
detection can never trigger regardless of IRK correctness or Watch proximity.
Any BlueZ that decodes manufacturer data this way is affected. (The claim is
scoped to the tested version; other builds should be confirmed against their own
btmonoutput.)Secondary issue found while fixing:
btmonprintsRSSIas the lastfield of each advertising report, i.e. after the manufacturer data. The
original single-line design would therefore have associated a detection with the
previous report's RSSI. The fix below resolves this by firing the detection on
the report's
RSSIline.Proposed fix
Replace the single-line regex with a small per-report state machine that:
Company: Apple, Inc. (76)→Type … (16)→Data:sequence,payload[1](same byte the original used), andRSSI:line so the correct RSSI is used.Behaviour, flag semantics (
FLAG_AUTO_UNLOCK_ON = 0x80,FLAG_WATCH_LOCKED = 0x20), and downstream calls (is_my_watch,handle_watch_detection,check_presence_timeout) are unchanged.Diff (
unlock_daemon.py,main())Verification
Before:
grep -c '4c 00 10 0[56]'over a livebtmoncapture →0matches; daemon never leaves
Waiting for Apple Watch....After: replaying the same captured
btmonoutput through the patchedparser yields, e.g.:
and the existing
handle_watch_detectionpath proceeds as designed.Flag decoding is unchanged and matches observed states:
Notes for maintainer
Type: Unknown (16)depends onbtmon's decoded label; if afuture BlueZ labels Nearby Info differently, the
Type: … (16)check is theline to revisit. A
Company: Apple, Inc. (76)guard precedes it to avoidmatching a
(16)type from another vendor block.