The Bluetooth device serial number is the GAP address.
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.
Have you check with other platforms like Linux or macOS?
@HaiMianBBao
Please also provide more details of the device, thanks. Is it plain Bluetooth device or BLE device?
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.
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?
Yes, it seem so. If you can suggest a correct way of getting the SN for BLE device that would be very helpful, thanks.