Skip to content

fix: Preserve ScanResponse on Windows and resolve cross-platform N/A device names#461

Open
Yongle-Fu wants to merge 3 commits intodeviceplug:devfrom
Yongle-Fu:fix/scan-and-name-issues
Open

fix: Preserve ScanResponse on Windows and resolve cross-platform N/A device names#461
Yongle-Fu wants to merge 3 commits intodeviceplug:devfrom
Yongle-Fu:fix/scan-and-name-issues

Conversation

@Yongle-Fu
Copy link
Copy Markdown

This PR resolves 3 critical and long-standing behavior inconsistencies across the Windows and macOS backends, strictly enforcing lifecycle contracts and BLE specifications.

1. Common: Fix accidental eviction of connected peripherals

Problem: AdapterManager.clear_peripherals() was previously unconditionally emptying the internal device map. This meant that whenever scanning was stopped, any active/connected peripherals were instantly silently evicted, killing the connection.
Fix: Introduced .retain() to filter out connections checking is_connected() sync-safe loop. CoreBluetooth/BlueZ semantics are now properly enforced across all platforms.

2. WinRT: Prevent Service-UUID filters from silently dropping ScanResponse

Problem: Windows ScanResponse packets contain vital identity information (like Name) but often omit the UUIDs found in the primary advertisement. Because the WinRT watcher applied the UUID filter strictly to the contents of every single packet, all ScanResponse packets were silently dropped, resulting in "N/A" device names.
Fix: Implemented a lightweight, tightly-scoped BluetoothAddress cache within the WinRT watcher. If a device's initial advertisement passes the UUID filter, its address is cached, granting safe passage for its subsequent UUIDless ScanResponse.

3. Cross-platform: Enforce COMPLETE_LOCAL_NAME priority

macOS (CoreBluetooth):

  • Inverted priority mapping: advertisement_name (Scan Response / Complete Name) is now strongly preferred over the internal peripheral.name() GAP cache (which operates as a truncated short name).
  • Added length-aware safe-guards inside update_name() to prevent subsequent incomplete packets from wiping out a previously parsed long name.

Windows (WinRT):

  • Parsed SHORT_LOCAL_NAME (0x08) and COMPLETE_LOCAL_NAME (0x09) directly from DataSections.
  • Enforced standard BLE precedence where Complete Name overrides Short Name across individual and fragmented packet arrivals.

Yongle added 3 commits April 14, 2026 20:21
Stopping a scan or calling clear_peripherals() currently evicts active
connections from the internal state map. This fixes cross-platform consistency
by ensuring connected devices are always retained (matching the established
behavior pattern of macOS CoreBluetooth and Linux BlueZ).
…anResponses

The Windows WinRT BLE watcher previously dropped all ScanResponse packets
when a UUID filter was applied, because ScanResponses lack the service UUIDs
present in the main advertisement.

This introduces a lightweight Address cache within the watcher closure,
allowing subsequent ScanResponse packets to pass through the filter if
the device previously advertised the requested UUID.
…LOCAL_NAME

Windows (WinRT):
- Parse SHORT_LOCAL_NAME (0x08) and COMPLETE_LOCAL_NAME (0x09) from DataSections
- Prevent short names from overwriting complete names across split packets

macOS (CoreBluetooth):
- Prefer advertisement_name (scan response) over peripheral.name() (GAP cache),
  as GAP names are frequently truncated short names
- Add length protections in update_name() to prevent shorter names from
  overwriting longer complete names in successive updates

Android:
- Restore upstream MTU auto-negotiation compatibility
@qwandor qwandor changed the base branch from master to dev April 14, 2026 12:31
@qwandor qwandor added uwp (windows) Issues related to the UWP/Win10 core bug Something isn't working corebluetooth (macos/ios) Issues related to the MacOS/iOS CoreBluetooth impl labels Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working corebluetooth (macos/ios) Issues related to the MacOS/iOS CoreBluetooth impl uwp (windows) Issues related to the UWP/Win10 core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants