I am having trouble with Bluetooth Pairing on Windows 11
using Simple Secure Pairing SSP
mode Numeric Comparison
.
I have created a BLE peripheral
with Bluetooth v4.2
hardware, capable of handling (most) of SSP including Numeric Comparison.
Then using the Windows SDK
, to requesting custom Pairing with the peripheral:
result = await deviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmPinMatch, devicePairingProtectionLevel).AsTask(cancellationToken);
(Other DevicePairingProtectionLevel were attempted as well)
The application subscribes to the custom pairing callback:
deviceInformation.Pairing.Custom.PairingRequested += OnPairingRequested;
And is called back as expected indicating the negotiated mode is indeed ConfirmPinMatch
and has a matching Pin
argument.
Each device then accept the pairing request, but the original PairAsync method never returns on Windows 11 using Bluetooth v5.3
hardware. (thus Ive added the AsTask
extension to allow cancellation).
Yet, this code works on Windows 10
using Bluetooth v4.1 hardware, when pairing to the very same BLE peripheral. And I have also confirmed the correct operation of this BLE peripheral when using an Android
device to Pair with it. Android which handles all Pairing in the OS itself.
So this evidence suggests the problem is in Windows 11.
Its worth noting that both Windows 10 and 11 machines support a different version of bluetooth so its not a comparison without difference, but SSP was introduced in Bluetooth v2.1
so i wouldn't expect the SDK now to hang indefinitely due to the unequal versions used.
I have no idea how to debug this, or even report a bug. It's not like the Windows OS or SDK is open source and i can step through what the API is doing... or is it? Ive limited experience with windows programming so Im not sure where to take this issue.
(Fwiw Ive tried targeting different versions including the latest windows10.0.26100.0
)
Please advise.
So it appears that not having set the Authentication requirements flags correctly was the root cause of my issue.
I haven't diagnosed if it is a requirement of Windows or Bluetooth, but when the machine running win 11 and BT5.3 the call to bond failed to return with a peripheral that set neither the Secure Connections and/or MITM protection flag. This on the surface seem to me like a bug in Windows if the call never returns, and I should've fallen back to whatever worked with win10 4.1.
Regardless if your here searching why this call isn't returning for you, you can check these settings on your peripheral.