Create Device Handle for Bluetooth LE Service for Specific Device RRS feed

  • Question

  • Hi,

    I am trying to create a handle (using CreateFile) for a Bluetooth LE service so I can read a characteristic of said service.  I am creating the handle using the service device path as opposed to the device path of the actual device itself becuase windows requires that when reading or writing to the Bluetooth LE device that the application opens a handle to the service instance itself.  For the sake of this example let's say that service is the Device Information Service, which has a short 16-bit Uuid of 0x180A.  To see all the devices with this service I use the following code:

    GUID guid; CLSIDFromString((LPCOLESTR)L"{0000180A-0000-1000-8000-00805F9B34FB}", &guid); // create a HDEVINFO with all present services HDEVINFO hDeviceInfo; hDeviceInfo = SetupDiGetClassDevs( &guid, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (hDeviceInfo == INVALID_HANDLE_VALUE) { // return null if no devices present return NULL; } // enumerate through all devices in the set SP_DEVICE_INTERFACE_DATA deviceInterfaceData; deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); for (DWORD i = 0; SetupDiEnumDeviceInterfaces(hDeviceInfo, NULL, &guid, i, &deviceInterfaceData); i++) { DWORD bufferSize; BOOL success; // first just get the buffer size // note that this will return 0 SetupDiGetDeviceInterfaceDetail( hDeviceInfo, &deviceInterfaceData, NULL, NULL, &bufferSize, NULL);

    // allocate memory for the device interface detail data object PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LPTR, bufferSize); deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

    // now get the device interface detail data success = SetupDiGetDeviceInterfaceDetail( hDeviceInfo, &deviceInterfaceData, deviceInterfaceDetailData, bufferSize, NULL, NULL); if (success) { _tprintf(L"%s\n", deviceInterfaceDetailData->DevicePath);

    // the device path can now be used to create a handle to the service instance

    } LocalFree(deviceInterfaceDetailData); } // Cleanup SetupDiDestroyDeviceInfoList(hDeviceInfo);

    As you can see, I extended the short 16 bit Uuid to 128 bits using the standard SIG extension.  Then I create an HDEVINFO that has all the present services matching the UUid.  As we know every Bluetooth LE device implements the Device Information Service.  Therefore, my HDEVINFO set will contain the Device Information Service for every Bluetooth LE device paired to my PC.  Is it possible to force my HDEVINFO set to contain the Device Information Service for a specific Bluetooth LE device.  If not, is there a way to tell which device the service belongs too while enumerating the HDEVINFO set?



    Wednesday, March 26, 2014 6:59 PM