bluekitchen / btstack

Dual-mode Bluetooth stack, with small memory footprint.
http://bluekitchen-gmbh.com
Other
1.74k stars 614 forks source link

HID_SUBEVENT_DESCRIPTOR_AVAILABLE fires only for the first connection #633

Closed Slion closed 1 month ago

Slion commented 1 month ago

Describe the bug

I'm trying to get HID host to work with multiple connections but HID_SUBEVENT_DESCRIPTOR_AVAILABLE never fires past the first connection. Logs attached.

To Reproduce

Try connect 2 HID device to your host.

Expected behavior

HID_SUBEVENT_DESCRIPTOR_AVAILABLE should fire for second device connection too.

HCI Packet Logs HCI-Desc-Not-Available.zip

Environment:

mringwal commented 1 month ago

Please check the number of L2CAP Channels (MAX_NR_L2CAP_CHANNELS) unless malloc is used and/or increase by one. It looks like the SDP Query fails as there are no L2CAP Channels available.

Slion commented 1 month ago

Following your answer on the mailing I did gave it a try with MAX_NR_L2CAP_CHANNELS 16 from 4 and MAX_NR_L2CAP_SERVICES 16 from 3 but it did not do any better.

Actually, it's now working I do get that second report descriptor. With the following config:

#define MAX_NR_HCI_CONNECTIONS 8
#define MAX_NR_HID_HOST_CONNECTIONS 8
#define MAX_NR_L2CAP_CHANNELS  16
#define MAX_NR_L2CAP_SERVICES  4

So you are saying MAX_NR_L2CAP_CHANNELS should be 2× MAX_NR_HID_HOST_CONNECTIONS right? What about MAX_NR_L2CAP_SERVICES ?

Would be cool if HID_SUBEVENT_DESCRIPTOR_AVAILABLE would fire but with a status error code in case the SDP request fails.

Slion commented 1 month ago

I had possibly two issues going on here, one I guess with the limited L2CAP channels that did not give any error back. The other one has to do with the buffer you pass to hid_host_init. It needs to be large enough to contain all the HID report descriptors for all the devices you are connecting. When space runs out in that buffer HID_SUBEVENT_DESCRIPTOR_AVAILABLE is fired with with status ERROR_CODE_MEMORY_CAPACITY_EXCEEDED as returned by hid_subevent_descriptor_available_get_status. Would be nice if this was documented in hid_host_init.

Slion commented 1 month ago

A quote from @mringwal from the mailing list:

MAX_NR_HID_HOST_CONNECTIONS does not match MAX_NR_HCI_CONNECTIONS, but it would make sense if HID is your main application. You also need 2 L2CAP Connections for each HID Device.

I find HCI connections are rather expensive each takes almost 4KB. Lucky the L2CAP channels are cheap, I get 16 for around 1KB.