h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
695 stars 143 forks source link

How to pass correct hid device name #703

Open DrSimgear opened 1 month ago

DrSimgear commented 1 month ago

image Device does not show up with the ble name given instead windows generates a name.

DrSimgear commented 1 month ago

https://www.bluetooth.com/specifications/specs/human-interface-device-profile-1-1-1/
5.3.3 SDP Attribute Summary: Service Name

DrSimgear commented 1 month ago

https://github.com/lemmingDev/ESP32-BLE-Gamepad/issues/35

afpineda commented 1 month ago

Same question here.

5.3.3 SDP Attribute Summary: Service Name

I read somewhere else that Windows takes the controller name from that attribute in the advertisment. How to set that? No idea.

To my opinion, we need better API documentation.

h2zero commented 1 month ago

I read somewhere else that Windows takes the controller name from that attribute in the advertisment. How to set that? No idea.

I'm not sure how windows recognizes the device name and as far as HID support is concerned I don't know much about it, the code for it is community supplied.

There are 2 ways to set the name via BLE: NimBLEDevice::init("your device name") or: NimBLEAdvertising::setName("your device name") or NimBLEAdvertisementData::setName("your device name") if using custom data etc...

To my opinion, we need better API documentation.

While this is true for any repo it's not easy to maintain and I welcome with open arms any contributions. I'm not sure what documentation is missing for this use case, can you elaborate?

Here is the way most of this HID stuff works, USB or Bluetooth, there is a VID and PID value, Windows probably looks at those first, compares to the table of registered devices and derives the name from the registry, ignoring any other data from the BLE device, this is only my guess. If I am correct in my suspicion, and windows ignores the values I have described how to set above, then there is nothing you can do unless you want to spend $$$$ to register your VID/PID to have it recognized by windows.

afpineda commented 1 month ago

I'm not sure how windows recognizes the device name and as far as HID support is concerned I don't know much about it, the code for it is community supplied.

There is no issue with the device name. It is correctly set by NimBLE and correctly recognized by Windows. The point is this: The HID "controller name" is not the same as the "device name". This fact is causing some confusion.

There are 2 ways to set the name via BLE: NimBLEDevice::init("your device name") or: NimBLEAdvertising::setName("your device name") or NimBLEAdvertisementData::setName("your device name") if using custom data etc...

I did some tests. NimBLEAdvertising::setName() does not solve the issue because the issue is not related to the device name, but to the service name (see below), I guess.

Here is the way most of this HID stuff works, USB or Bluetooth, there is a VID and PID value, Windows probably looks at those first, compares to the table of registered devices and derives the name from the registry, ignoring any other data from the BLE device, this is only my guess. If I am correct in my suspicion, and windows ignores the values I have described how to set above, then there is nothing you can do unless you want to spend $$$$ to register your VID/PID to have it recognized by windows.

This question has been answered by a Microsot's employee here: https://learn.microsoft.com/en-us/answers/questions/406840/hidd-getproductstring-with-classic-bluetooth-devic

"The product string returned will be the value of the SDP attribute called "Service Name" in table 5.3 (section 5.3.3) of the spec."

I took a look to that section, which is available here: https://www.bluetooth.com/specifications/specs/human-interface-device-profile-1-1-1/ It states that the SDP attribute "Service Name" is optional. So, I guess it is not implemented in NimBLE by default. I would like to add such attribute myself, but how?

h2zero commented 1 month ago

Thanks, that makes sense. I don't know much about the HID stuff, never had to work with it.

I'd suggest looking at how all the other attributes are added and see if you can add this one and the same manner.

afpineda commented 1 month ago

I took a look to that section, which is available here: https://www.bluetooth.com/specifications/specs/human-interface-device-profile-1-1-1/ It states that the SDP attribute "Service Name" is optional. So, I guess it is not implemented in NimBLE by default. I would like to add such attribute myself, but how?

My mistake. This applies to Bluetooth classic only, not BLE.

However, I found a proper workaround, which is described here.

h2zero commented 1 month ago

Thanks for the update, confirms my suspicions that windows gets the name from the Bluetooth registry using the VID/PID which isn't home gamer friendly obviously.