Fix HCI event filter for events >= 32 (LE Meta Event) #51
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.
Summary
Fix the
setEvent()method inCInterop.HCIFilterSocketOptionto correctly handle HCI events with codes >= 32.Problem
The current implementation always sets bits in
eventMask.0, even for events >= 32. The HCI filter structure uses two 32-bit event mask words:eventMask.0for events 0-31eventMask.1for events 32-63For LE Meta Event (code 0x3E = 62):
bit = 62 & 63 = 62HCISetBit(62, &eventMask.0)attempts to set bit 62 in a 32-bit integerThis results in the LE Meta events being filtered out by the kernel, making all BLE scanning non-functional.
Symptoms
lowEnergyScan()returns a validAsyncLowEnergyScanStreambtmonshows LE Advertising Reports ARE being received by the kernelVerification
Tested on Linux 6.8.0-90-generic (Ubuntu 24.04) with Realtek USB Bluetooth adapter. After the fix, scanning correctly discovers BLE devices:
Possibly Related
This may be related to #40 - while that issue reports a different error, the underlying cause (improper HCI filter configuration) is similar.