hidapi icon indicating copy to clipboard operation
hidapi copied to clipboard

The Bluetooth device serial number is the GAP address.

Open HaiMianBBao opened this issue 5 months ago • 5 comments

I used hidapi on Windows to enumerate Bluetooth HID devices and found that the serial number of the Bluetooth HID device is the Bluetooth GAP address, not the actual serial number.

HaiMianBBao avatar Jul 07 '25 12:07 HaiMianBBao

Have you check with other platforms like Linux or macOS?

mcuee avatar Jul 07 '25 12:07 mcuee

@HaiMianBBao

Please also provide more details of the device, thanks. Is it plain Bluetooth device or BLE device?

mcuee avatar Jul 09 '25 02:07 mcuee

I am very sorry, but I am unable to conduct tests on macOS and Linux systems. My device is a BLE HID device, and I can see the serial number using the nRF Connect app on my iPhone. However, the serial number enumerated by HIDAPI is the Bluetooth GAP address.

HaiMianBBao avatar Jul 09 '25 05:07 HaiMianBBao

static void hid_internal_get_ble_info(struct hid_device_info* dev, DEVINST dev_node)
{
	if (wcslen(dev->manufacturer_string) == 0) {
		/* Manufacturer Name String (UUID: 0x2A29) */
		wchar_t* manufacturer_string = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_Manufacturer, DEVPROP_TYPE_STRING);
		if (manufacturer_string) {
			free(dev->manufacturer_string);
			dev->manufacturer_string = manufacturer_string;
		}
	}

	if (wcslen(dev->serial_number) == 0) {
		/* Serial Number String (UUID: 0x2A25) */
		wchar_t* serial_number = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_DeviceAddress, DEVPROP_TYPE_STRING);
		if (serial_number) {
			free(dev->serial_number);
			dev->serial_number = serial_number;
		}
	}

	if (wcslen(dev->product_string) == 0) {
		/* Model Number String (UUID: 0x2A24) */
		wchar_t* product_string = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_ModelNumber, DEVPROP_TYPE_STRING);
		if (!product_string) {
			DEVINST parent_dev_node = 0;
			/* Fallback: Get devnode grandparent to reach out Bluetooth LE device node */
			if (CM_Get_Parent(&parent_dev_node, dev_node, 0) == CR_SUCCESS) {
				/* Device Name (UUID: 0x2A00) */
				product_string = (wchar_t *)hid_internal_get_devnode_property(parent_dev_node, &DEVPKEY_NAME, DEVPROP_TYPE_STRING);
			}
		}

		if (product_string) {
			free(dev->product_string);
			dev->product_string = product_string;
		}
	}
}

wchar_t* serial_number = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_DeviceAddress, DEVPROP_TYPE_STRING);

Is it related to this piece of code?

HaiMianBBao avatar Jul 09 '25 05:07 HaiMianBBao

Yes, it seem so. If you can suggest a correct way of getting the SN for BLE device that would be very helpful, thanks.

Youw avatar Jul 09 '25 08:07 Youw