In my c++ library I have next code to pair BT device (that is supposed to be HID) without UI to be displayed to continue the authentication process:
//Authentication callback
static BOOL WINAPI BluetoothAuthCallback(LPVOID param, PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS params)
{
BLUETOOTH_DEVICE_INFO aw = params->deviceInfo;
HANDLE lRadio = NULL;
BLUETOOTH_AUTHENTICATE_RESPONSE bar2Send;
::ZeroMemory(&bar2Send, sizeof(BLUETOOTH_AUTHENTICATE_RESPONSE));
bar2Send.bthAddressRemote = params->deviceInfo.Address;
bar2Send.authMethod = params->authenticationMethod;
DWORD result = BluetoothSendAuthenticationResponseEx(lRadio, &bar2Send);
return true;
}
//Pairing function in MyMsBtStackManager class
bool MyMsBtStackManager::PairDevice(const
BLUETOOTH_DEVICE_INFO btdi)
{
HBLUETOOTH_AUTHENTICATION_REGISTRATION hCallbackHandle = 0;
DWORD result = BluetoothRegisterForAuthenticationEx(&btdi, &hCallbackHandle, &BluetoothAuthCallback, param);
if (result != ERROR_SUCCESS)
{
return false;
}
DWORD res = BluetoothAuthenticateDeviceEx(NULL, lRadio, &btdi, NULL, MITMProtectionNotRequired);
BOOL resultUnReg = BluetoothUnregisterAuthentication(hCallbackHandle);
if (res == ERROR_SUCCESS)
{
return true;
}
return false;
}
The problem is that device is paired. But not seen as HID device.
If BluetoothRegisterForAuthenticationEx is removed then UI is displayed to continue authentication process and everything is fine - device is seen as HID.
Can someone give me any advice how I can make authentication process automatic using code but still get device as HID? Do I need to register to any other notifications from system?
Thanks