I'm developing a Bluetooth(not BLE) application on Windows. I need the Windows PC to be the server, and advertise service through SDP protocol, but somehow I can hardly find a suitable API, except this one: BluetoothSetLocalServiceInfo. Documents are here: https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothsetlocalserviceinfo. However, I currently still cannot successfully use it to publish a service that other devices could detect using the following code, although it returned ERROR_SUCCESS.
void BluetoothManager::RegisterServiceBtAPI(){
BLUETOOTH_LOCAL_SERVICE_INFO_STRUCT serviceInfo;
serviceInfo.Enabled = TRUE;
BLUETOOTH_ADDRESS btAddress;
QUtils::CharArray2BTH_ADDR(btServerAddress.toString().toStdString().c_str(), &btAddress.ullLong);
serviceInfo.btAddr = btAddress;
QString("ServiceName").toWCharArray(serviceInfo.szName);
QString("DeviceName").toWCharArray(serviceInfo.szDeviceString);
QUtils::EnableSpecificPrivilege(SE_LOAD_DRIVER_NAME);
//{00001101-0000-1000-8000-00805F9B34FB};
const GUID serviceGUID = { 0x00001101, 0x0000, 0x0000, { 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } };
int result = BluetoothSetLocalServiceInfo(
NULL, &serviceGUID, 0, &serviceInfo
);
if(result!=ERROR_SUCCESS){
emit ShowDebug(QString("BluetoothSetLocalServiceInfo failed with error: %1").arg(result));
}else{
emit ShowDebug(QString("BluetoothSetLocalServiceInfo succeeded."));
}
}
I'm wondering if it's correct to use this method to advertise bluetooth service on Windows PC and if so, whether or not I used it correctly. If not, what is the suitable API to publish a service on Windows?
I think the correct API should be WSASetService. Documents could be found here: https://learn.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wsasetservice. Alternatively, IOCTL_BTH_SDP_SUBMIT_RECORD IOCTL could be used, although I don't known how yet. Documents are here: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/bthioctl/ni-bthioctl-ioctl_bth_sdp_submit_record.