Repository navigation
Windows: skip OS-reserved services during discovery (#400) - #401
Merged
Merged
Conversation
Windows reserves a few GATT services for its own stack and answers GetCharacteristicsAsync with AccessDenied for them whether or not the device is paired. HID over GATT (0x1812) is the common one. Since #284 turned the discovery loop's `continue` into `break`, that answer aborted the whole connection attempt, so a device exposing HID could not connect at all. classify_discovery_status() in windows/src/gatt_discovery_policy.h maps the status to include, skip or fail, and both discovery loops use it. AccessDenied is skipped, so the reserved service stays out of the service map while the rest of the database connects normally. Unreachable and ProtocolError still fail discovery, which keeps #284's intent of reporting a discovery a dropped link cut short. Two boundaries keep the skip from hiding a real problem. AccessDenied is not exclusive to reserved services, so if every service of a device was denied the connection still succeeds but a warning names the count. In the Service Changed refresh, a denied service the map already exposes is not dropped: reads and subscriptions are live against it, so the previous map is kept and the error is logged, as before the loop skipped reserved services. Cover it with the fixture's existing SET_HID_SERVICE command (0x17): the new Windows HIL test registers the HID service, reconnects so connect-time discovery meets the denied service, checks the reserved service is absent while the fixture's own service stays readable, then adds the auxiliary service and requires it to appear, which proves the refresh walked past the denied service. A Windows unit test pins the status classification for pull-request CI, where the HIL suite does not run.
fotiDim
force-pushed
the
fix/400-windows-os-reserved-service
branch
from
November 25, 2026 11:42
1763400 to
0402205
Compare
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.
Fixes #400.
Problem
Windows reserves a few GATT services for its own stack and answers
GetCharacteristicsAsyncwithAccessDeniedfor them, whether or not the device is paired. HID over GATT (0x1812) is the common one, and it is on Microsoft's list of services the GATT API prevents apps from accessing.Since #284 turned the discovery loop's
continueintobreak+ a stored error, that answer aborted the whole connection, so a device exposing HID could not connect at all:Failed to get characteristics for service 00001812-0000-1000-8000-00805f9b34fb: AccessDenied. Up to 2.1.0 the service was skipped and the device connected.Fix
classify_discovery_status()in the newwindows/src/gatt_discovery_policy.hdecides what discovery does with eachGetCharacteristicsAsyncstatus:Successincludes the service,AccessDeniedskips it, and every other status fails discovery. Both loops use it:ConnectAsync: a denied service is logged at info level and skipped; the rest of the database connects normally. If every service was denied the connection still succeeds, but a warning names the count, because an empty service map is otherwise indistinguishable from a device with no services.RefreshGattServicesAsync: a denied service is skipped, so a Service Changed refresh with a reserved service in the database installs the new map instead of retaining the old one. The exception is a denied service the connection had already reported: dropping it would silently break its live reads and subscriptions, so the previous map is kept and the error is logged.UnreachableandProtocolErrorstill fail discovery, so #284's intent — reporting a discovery that a dropped link cut short — is kept. The reserved service stays out of the service map, sodiscoverServices()does not report it. (Chromium reports a denied service with an empty characteristic list instead; this leaves it out so a service with no reachable characteristics is not returned.)Tests
hil/integration_test/baseline_hil_test.dart, Windows-only): uses the fixture's existingSET_HID_SERVICEcommand (0x17, already inuniversal_ble_hil_firmware, no firmware change needed). It registers the HID service, reconnects so connect-time discovery meetsAccessDenied(this is the exact failure from the report), asserts the connection is up, the reserved service is absent and the fixture's own service is still readable, then adds the auxiliary service and requires it to appear — which proves the refresh walked past the denied service instead of keeping the old map. Cleanup removes both dynamic services while connected, because the fixture's reset clears the request flags without unregistering them.windows/test/gatt_discovery_policy_test.cpp): pins the status classification in pull-request CI, where the HIL suite does not run — including that an unknown status fails discovery instead of being skipped. The loops themselves are covered only by the HIL suite.hil/README.mdandhil/COVERAGE.mdcounts are updated (86 tests, 26 baseline).Verification
flutter analyze/dart formatinhil/: clean.ctestand the HIL test have not been run locally (macOS host); CI covers the build, the unit test, and the example app.cd hil && flutter test integration_test/baseline_hil_test.dart -d windows --plain-name "OS-reserved". On a build without the native fix it fails atperipheral.reconnect()with the reportedAccessDeniederror.Docs
CHANGELOG.md: new## Unreleasedentry.README.mdDiscoverServices: documents that Windows-denied services are left out of discovery, and that a service already reported is kept if a later refresh is denied access to it.