Note sure if best to continue here, or create a new thread...
But having some fun trying to get a better understanding of the Bluetooth, HID and SDP code and over time assuming I don't lose interest, may experiment more with some overhauling
of our Bluetooth code.
Sorry in advance for the following rambling, but thought I would mention some of this in case anyone would like to follow along.
The current code more or less has grown from mimicking a few different Bluetooth devices like some keyboards, Mice and Joysticks. So far all HID like devices. Not sure if at some point
maybe extend to some other Bluetooth protocols or not. Just doing this for my own fun.
At some point we should probably do a Bluetooth version 2 code bse, which cleans up lots of things, like adding simple calls to turn on pairing mode, and do better protocol negotiations, and handle a lot more of the underlying Bluetooth subsystems like
This current round of experiments started off when we were playing with a few different Bluetooth keyboards, like right now the Rii (
https://smile.amazon.com/gp/product/B00JO80LVW)
Which I purchased over 4.5 years ago. It works as a keyboard with our current code, at least the main keyboard part works. But this device also has a touchpad on it, plus multi-media keys as well
And those don't work.
I have noticed that the normal keyboard stuff, is sent on Report 1, as our keyboard BT code expects. But it is also sending out some other different reports as well,
like when I touch the touchpad I get a report that starts with an 8, also there is a report that starts with a 3...
So started to wonder if these devices have a "HID Report Descriptor"...
First experiments were on Linux, where the keyboard works, also as mouse... And found a way to get the HID Descriptor to print out. So yes it does.
So I figured it out that the data for that was coming from the Bluetoth Service Descovery Protocol (SDP) area, which our current code does not setup a connection to. Experimented a year or two ago
with some of this but did not have that working. Note this is in Bluetooth_core_v5 pdf files in Vol3 Part B.
I now have it making an SDP connection (note I am doing this at a different time than the Linux code but it appears to work).
I then cobbled up code to send out a: ServiceSearchAttribute transaction request, and started to get a response but turned on that the response was split over two messages, so like we did
for the RX_Pipe, I had to update the RX2_Pipe code to detect this and combine two packets into one, and then I could start parsing it. Also put the code to handle the device splitting
up the response into multiple response packets. (Section 4.7). I now have them being all combined into one big buffer...
The current code is doing simple decoding the data. I won't put the whole thing here, but starts off like:
Code:
process_sdp_service_search_attribute_response: cb dat:32 cont:0
SDP Data returned: 944 bytes
20200000 - 36 03 AD 36 00 8E 09 00 00 0A 00 00 00 00 09 00 : 6..6.... ........
20200010 - 01 35 03 19 10 00 09 00 04 35 0D 35 06 19 01 00 : .5...... .5.5....
20200020 - 09 00 01 35 03 19 00 01 09 00 05 35 03 19 10 02 : ...5.... ...5....
20200030 - 09 00 06 35 09 09 65 6E 09 00 6A 09 01 00 09 00 : ...5..en ..j.....
20200040 - 09 35 08 35 06 19 01 00 09 01 00 09 01 00 25 2F : .5.5.... ......%/
20200050 - 42 72 6F 61 64 63 6F 6D 20 42 6C 75 65 74 6F 6F : Broadcom Bluetoo
20200060 - 74 68 20 57 69 72 65 6C 65 73 73 20 4B 65 79 62 : th Wirel ess Keyb
20200070 - 6F 61 72 64 20 53 44 50 20 53 65 72 76 65 72 09 : oard SDP Server.
20200080 - 01 01 25 08 4B 65 79 62 6F 61 72 64 09 02 00 35 : ..%.Keyb oard...5
20200090 - 03 09 01 00 36 02 75 09 00 00 0A 00 01 00 00 09 : ....6.u. ........
202000A0 - 00 01 35 03 19 11 24 09 00 04 35 0D 35 06 19 01 : ..5...$. ..5.5...
202000B0 - 00 09 00 11 35 03 19 00 11 09 00 05 35 03 19 10 : ....5... ....5...
202000C0 - 02 09 00 06 35 09 09 65 6E 09 00 6A 09 01 00 09 : ....5..e n..j....
202000D0 - 00 09 35 08 35 06 19 11 24 09 01 00 09 00 0D 35 : ..5.5... $......5
202000E0 - 0F 35 0D 35 06 19 01 00 09 00 13 35 03 19 00 11 : .5.5.... ...5....
202000F0 - 09 01 00 25 3D 42 72 6F 61 64 63 6F 6D 20 42 6C : ...%=Bro adcom Bl
20200100 - 75 65 74 6F 6F 74 68 20 57 69 72 65 6C 65 73 73 : uetooth Wireless
20200110 - 20 20 4B 65 79 62 6F 61 72 64 20 20 20 20 20 20 : Keyboa rd
20200120 - 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 :
20200130 - 20 20 09 01 01 25 08 4B 65 79 62 6F 61 72 64 09 : ...%.K eyboard.
20200140 - 01 02 25 10 42 72 6F 61 64 63 6F 6D 20 43 6F 72 : ..%.Broa dcom Cor
20200150 - 70 2E 20 20 09 02 00 09 01 00 09 02 01 09 01 11 : p. .... ........
20200160 - 09 02 02 08 40 09 02 03 08 21 09 02 04 28 01 09 : ....@... .!...(..
20200170 - 02 05 28 01 09 02 06 36 01 54 36 01 51 08 22 26 : ..(....6 .T6.Q."&
20200180 - 01 4C 05 01 09 06 A1 01 85 01 75 01 95 08 05 07 : .L...... ..u.....
20200190 - 19 E0 29 E7 15 00 25 01 81 02 95 01 75 08 81 03 : ..)...%. ....u...
202001A0 - 95 05 75 01 05 08 19 01 29 05 91 02 95 01 75 03 : ..u..... ).....u.
202001B0 - 91 03 95 06 75 08 15 00 26 FF 00 05 07 19 00 29 : ....u... &......)
202001C0 - FF 81 00 C0 05 0C 09 01 A1 01 85 02 15 00 25 01 : ........ ......%.
202001D0 - 75 01 95 12 0A 23 02 0A 83 01 0A 0A 03 0A 0B 03 : u....#.. ........
202001E0 - 0A 05 03 0A 8A 01 0A 21 02 09 B6 09 CD 09 B5 09 : .......! ........
202001F0 - E2 09 EA 09 E9 09 B7 09 40 0A 83 01 0A 02 03 0A : ........ @.......
20200200 - 07 03 81 02 95 01 75 06 81 03 C0 05 0C 09 01 A1 : ......u. ........
20200210 - 01 85 03 05 01 09 06 A1 02 05 06 09 20 15 00 26 : ........ .... ..&
20200220 - FF 00 75 08 95 01 81 02 C0 C0 05 01 09 80 A1 01 : ..u..... ........
20200230 - 85 04 15 00 25 01 75 01 95 01 09 82 81 02 95 01 : ....%.u. ........
20200240 - 75 07 81 03 C0 05 0C 09 01 A1 01 85 05 05 01 09 : u....... ........
20200250 - 06 A1 02 06 00 FF 25 01 75 01 95 02 0A 03 FE 0A : ......%. u.......
20200260 - 04 FE 81 02 95 06 81 03 C0 C0 05 01 09 02 A1 01 : ........ ........
20200270 - 85 08 09 01 A1 00 05 09 19 01 29 05 15 00 25 01 : ........ ..)...%.
20200280 - 95 05 75 01 81 02 95 01 75 03 81 01 05 01 09 30 : ..u..... u......0
20200290 - 09 31 16 01 80 26 FF 7F 75 10 95 02 81 06 09 38 : .1...&.. u......8
202002A0 - 15 81 25 7F 75 08 95 01 81 06 05 0C 0A 38 02 95 : ..%.u... .....8..
202002B0 - 01 81 06 C0 C0 05 0C 09 01 A1 01 85 FF 05 06 95 : ........ ........
202002C0 - 01 75 02 19 24 29 26 81 02 75 06 81 01 C0 09 02 : .u..$)&. .u......
202002D0 - 07 35 08 35 06 09 04 09 09 01 00 09 02 08 28 00 : .5.5.... ......(.
202002E0 - 09 02 09 28 01 09 02 0A 28 01 09 02 0B 09 01 00 : ...(.... (.......
202002F0 - 09 02 0C 09 0C 80 09 02 0D 28 00 09 02 0E 28 01 : ........ .(....(.
20200300 - 09 02 0F 09 03 18 09 02 10 09 00 00 36 00 A1 09 : ........ ....6...
20200310 - 00 00 0A 00 01 00 01 09 00 01 35 03 19 12 00 09 : ........ ..5.....
20200320 - 00 04 35 0D 35 06 19 01 00 09 00 01 35 03 19 00 : ..5.5... ....5...
20200330 - 01 09 00 06 35 09 09 65 6E 09 00 6A 09 01 00 09 : ....5..e n..j....
20200340 - 00 09 35 08 35 06 19 12 00 09 01 00 09 01 00 25 : ..5.5... .......%
20200350 - 2F 42 72 6F 61 64 63 6F 6D 20 42 6C 75 65 74 6F : /Broadco m Blueto
20200360 - 6F 74 68 20 57 69 72 65 6C 65 73 73 20 4B 65 79 : oth Wire less Key
20200370 - 62 6F 61 72 64 20 50 6E 50 20 53 65 72 76 65 72 : board Pn P Server
20200380 - 09 01 01 25 08 4B 65 79 62 6F 61 72 64 09 02 00 : ...%.Key board...
20200390 - 09 01 03 09 02 01 09 05 AC 09 02 02 09 85 02 09 : ........ ........
202003A0 - 02 03 09 01 1B 09 02 04 28 01 09 02 05 09 00 02 : ........ (.......
{s: 941
{s: 142
UINT: 0(0)
UINT: 0(0)
UINT: 1(1)
{s: 3
UUID: 4096(1000) }
UINT: 4(4)
{s: 13
{s: 6
UUID: 256(100)
UINT: 1(1) }
{s: 3
UUID: 1(1) } }
UINT: 5(5)
{s: 3
UUID: 4098(1002) }
UINT: 6(6)
{s: 9
UINT: 25966(656E)
UINT: 106(6A)
UINT: 256(100) }
UINT: 9(9)
{s: 8
{s: 6
UUID: 256(100)
UINT: 256(100) } }
UINT: 256(100)
St:
20200050 - 42 72 6F 61 64 63 6F 6D 20 42 6C 75 65 74 6F 6F : Broadcom Bluetoo
20200060 - 74 68 20 57 69 72 65 6C 65 73 73 20 4B 65 79 62 : th Wirel ess Keyb
20200070 - 6F 61 72 64 20 53 44 50 20 53 65 72 76 65 72 : oard SDP Server
UINT: 257(101)
St:
20200084 - 4B 65 79 62 6F 61 72 64 : Keyboard
UINT: 512(200)
{s: 3
UINT: 256(100) } }
{s: 629
All of this part of code is in test program. There is some stuff added to USBHost for this...
Then I added code to ask for specific attribute, in this case 0x206 which is the HID Report Descriptor..
More information in the Bluetooth PDF Document: HUMAN INTERFACE DEVICE PROFILE 1.1
So the sort of structure output for this one specific attribute
Code:
process_sdp_service_search_attribute_response: cb dat:16 cont:0
SDP Data returned: 358 bytes
20200000 - 36 01 63 36 00 00 36 01 5A 09 02 06 36 01 54 36 : 6.c6..6. Z...6.T6
20200010 - 01 51 08 22 26 01 4C 05 01 09 06 A1 01 85 01 75 : .Q."&.L. .......u
20200020 - 01 95 08 05 07 19 E0 29 E7 15 00 25 01 81 02 95 : .......) ...%....
20200030 - 01 75 08 81 03 95 05 75 01 05 08 19 01 29 05 91 : .u.....u .....)..
20200040 - 02 95 01 75 03 91 03 95 06 75 08 15 00 26 FF 00 : ...u.... .u...&..
20200050 - 05 07 19 00 29 FF 81 00 C0 05 0C 09 01 A1 01 85 : ....)... ........
20200060 - 02 15 00 25 01 75 01 95 12 0A 23 02 0A 83 01 0A : ...%.u.. ..#.....
20200070 - 0A 03 0A 0B 03 0A 05 03 0A 8A 01 0A 21 02 09 B6 : ........ ....!...
20200080 - 09 CD 09 B5 09 E2 09 EA 09 E9 09 B7 09 40 0A 83 : ........ .....@..
20200090 - 01 0A 02 03 0A 07 03 81 02 95 01 75 06 81 03 C0 : ........ ...u....
202000A0 - 05 0C 09 01 A1 01 85 03 05 01 09 06 A1 02 05 06 : ........ ........
202000B0 - 09 20 15 00 26 FF 00 75 08 95 01 81 02 C0 C0 05 : . ..&..u ........
202000C0 - 01 09 80 A1 01 85 04 15 00 25 01 75 01 95 01 09 : ........ .%.u....
202000D0 - 82 81 02 95 01 75 07 81 03 C0 05 0C 09 01 A1 01 : .....u.. ........
202000E0 - 85 05 05 01 09 06 A1 02 06 00 FF 25 01 75 01 95 : ........ ...%.u..
202000F0 - 02 0A 03 FE 0A 04 FE 81 02 95 06 81 03 C0 C0 05 : ........ ........
20200100 - 01 09 02 A1 01 85 08 09 01 A1 00 05 09 19 01 29 : ........ .......)
20200110 - 05 15 00 25 01 95 05 75 01 81 02 95 01 75 03 81 : ...%...u .....u..
20200120 - 01 05 01 09 30 09 31 16 01 80 26 FF 7F 75 10 95 : ....0.1. ..&..u..
20200130 - 02 81 06 09 38 15 81 25 7F 75 08 95 01 81 06 05 : ....8..% .u......
20200140 - 0C 0A 38 02 95 01 81 06 C0 C0 05 0C 09 01 A1 01 : ..8..... ........
20200150 - 85 FF 05 06 95 01 75 02 19 24 29 26 81 02 75 06 : ......u. .$)&..u.
20200160 - 81 01 C0 36 00 00 : ...6..
{s: 355
{s: 0 }
{s: 346
UINT: 518(206)
{s: 340
{s: 337
UINT: 34(22)
St:
20200017 - 05 01 09 06 A1 01 85 01 75 01 95 08 05 07 19 E0 : ........ u.......
20200027 - 29 E7 15 00 25 01 81 02 95 01 75 08 81 03 95 05 : )...%... ..u.....
20200037 - 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 03 : u.....). ....u...
20200047 - 95 06 75 08 15 00 26 FF 00 05 07 19 00 29 FF 81 : ..u...&. .....)..
20200057 - 00 C0 05 0C 09 01 A1 01 85 02 15 00 25 01 75 01 : ........ ....%.u.
20200067 - 95 12 0A 23 02 0A 83 01 0A 0A 03 0A 0B 03 0A 05 : ...#.... ........
20200077 - 03 0A 8A 01 0A 21 02 09 B6 09 CD 09 B5 09 E2 09 : .....!.. ........
20200087 - EA 09 E9 09 B7 09 40 0A 83 01 0A 02 03 0A 07 03 : ......@. ........
20200097 - 81 02 95 01 75 06 81 03 C0 05 0C 09 01 A1 01 85 : ....u... ........
202000A7 - 03 05 01 09 06 A1 02 05 06 09 20 15 00 26 FF 00 : ........ .. ..&..
202000B7 - 75 08 95 01 81 02 C0 C0 05 01 09 80 A1 01 85 04 : u....... ........
202000C7 - 15 00 25 01 75 01 95 01 09 82 81 02 95 01 75 07 : ..%.u... ......u.
202000D7 - 81 03 C0 05 0C 09 01 A1 01 85 05 05 01 09 06 A1 : ........ ........
202000E7 - 02 06 00 FF 25 01 75 01 95 02 0A 03 FE 0A 04 FE : ....%.u. ........
202000F7 - 81 02 95 06 81 03 C0 C0 05 01 09 02 A1 01 85 08 : ........ ........
20200107 - 09 01 A1 00 05 09 19 01 29 05 15 00 25 01 95 05 : ........ )...%...
20200117 - 75 01 81 02 95 01 75 03 81 01 05 01 09 30 09 31 : u.....u. .....0.1
20200127 - 16 01 80 26 FF 7F 75 10 95 02 81 06 09 38 15 81 : ...&..u. .....8..
20200137 - 25 7F 75 08 95 01 81 06 05 0C 0A 38 02 95 01 81 : %.u..... ...8....
20200147 - 06 C0 C0 05 0C 09 01 A1 01 85 FF 05 06 95 01 75 : ........ .......u
20200157 - 02 19 24 29 26 81 02 75 06 81 01 C0 : ..$)&..u ....
} } }
{s: 0 } }
I then passed the buffer extracted from this decoder to the HID Report dump code, that is a copy from our example Blueooth Hid sketch and now see
Code:
HID Report Descriptor (0x20200017) size: 332
05 01 // Usage Page(1) - Generic Desktop
09 06 // Usage(6) -(Keyboard)
A1 01 // Collection(1) top Usage(10000)
85 01 // Report ID(1)
75 01 // Report Size(1)
95 08 // Report Count(8)
05 07 // Usage Page(7) - Keycode
19 E0 // Usage Minimum(e0) - (Left Control)
29 E7 // Usage Maximum(e7) - (Right GUI)
15 00 // Logical Minimum(0)
25 01 // Logical maximum(1)
81 02 // Input(2) // (Data, Variable, Absolute)
95 01 // Report Count(1)
75 08 // Report Size(8)
81 03 // Input(3) // (Constant, Variable, Absolute)
95 05 // Report Count(5)
75 01 // Report Size(1)
05 08 // Usage Page(8) - LEDs
19 01 // Usage Minimum(1) -
29 05 // Usage Maximum(5) -
91 02 // Output(2) // (Data, Variable, Absolute)
95 01 // Report Count(1)
75 03 // Report Size(3)
91 03 // Output(3) // (Constant, Variable, Absolute)
95 06 // Report Count(6)
75 08 // Report Size(8)
15 00 // Logical Minimum(0)
26 FF 00 // Logical maximum(ff)
05 07 // Usage Page(7) - Keycode
19 00 // Usage Minimum(0) - (Keycode 0)
29 FF // Usage Maximum(ff) - (Keycode 255)
81 00 // Input(0) // (Data, Array, Absolute)
C0 // End Collection
05 0C // Usage Page(c) - Consumer
09 01 // Usage(1) -(Consumer Controls)
A1 01 // Collection(1) top Usage(c0000)
85 02 // Report ID(2)
15 00 // Logical Minimum(0)
25 01 // Logical maximum(1)
75 01 // Report Size(1)
95 12 // Report Count(12)
0A 23 02 // Usage(223) -(AC Home)
0A 83 01 // Usage(183) -(AL Consumer Control Configuration)
0A 0A 03 // Usage(30a) -(?)
0A 0B 03 // Usage(30b) -(?)
0A 05 03 // Usage(305) -(?)
0A 8A 01 // Usage(18a) -(AL Email Reader)
0A 21 02 // Usage(221) -(AC Search)
09 B6 // Usage(b6) -(Scan Previous Track)
09 CD // Usage(cd) -(Pause/Continue)
09 B5 // Usage(b5) -(Scan Next Track)
09 E2 // Usage(e2) -(Mute)
09 EA // Usage(ea) -(Volume Down)
09 E9 // Usage(e9) -(Volume Up)
09 B7 // Usage(b7) -(Stop)
09 40 // Usage(40) -(Menu)
0A 83 01 // Usage(183) -(AL Consumer Control Configuration)
0A 02 03 // Usage(302) -(?)
0A 07 03 // Usage(307) -(?)
81 02 // Input(2) // (Data, Variable, Absolute)
95 01 // Report Count(1)
75 06 // Report Size(6)
81 03 // Input(3) // (Constant, Variable, Absolute)
C0 // End Collection
05 0C // Usage Page(c) - Consumer
09 01 // Usage(1) -(Consumer Controls)
A1 01 // Collection(1) top Usage(c0000)
85 03 // Report ID(3)
05 01 // Usage Page(1) - Generic Desktop
09 06 // Usage(6) -(Keyboard)
A1 02 // Collection(2)
05 06 // Usage Page(6) - Other ?
09 20 // Usage(20) -
15 00 // Logical Minimum(0)
26 FF 00 // Logical maximum(ff)
75 08 // Report Size(8)
95 01 // Report Count(1)
81 02 // Input(2) // (Data, Variable, Absolute)
C0 // End Collection
C0 // End Collection
05 01 // Usage Page(1) - Generic Desktop
09 80 // Usage(80) -(?)
A1 01 // Collection(1) top Usage(10080)
85 04 // Report ID(4)
15 00 // Logical Minimum(0)
25 01 // Logical maximum(1)
75 01 // Report Size(1)
95 01 // Report Count(1)
09 82 // Usage(82) -(System Sleep)
81 02 // Input(2) // (Data, Variable, Absolute)
95 01 // Report Count(1)
75 07 // Report Size(7)
81 03 // Input(3) // (Constant, Variable, Absolute)
C0 // End Collection
05 0C // Usage Page(c) - Consumer
09 01 // Usage(1) -(Consumer Controls)
A1 01 // Collection(1) top Usage(c0000)
85 05 // Report ID(5)
05 01 // Usage Page(1) - Generic Desktop
09 06 // Usage(6) -(Keyboard)
A1 02 // Collection(2)
06 00 FF // Usage Page(ff00) - Vendor Defined
25 01 // Logical maximum(1)
75 01 // Report Size(1)
95 02 // Report Count(2)
0A 03 FE // Usage(fe03) -
0A 04 FE // Usage(fe04) -
81 02 // Input(2) // (Data, Variable, Absolute)
95 06 // Report Count(6)
81 03 // Input(3) // (Constant, Variable, Absolute)
C0 // End Collection
C0 // End Collection
05 01 // Usage Page(1) - Generic Desktop
09 02 // Usage(2) -(Mouse)
A1 01 // Collection(1) top Usage(10000)
85 08 // Report ID(8)
09 01 // Usage(1) -(?)
A1 00 // Collection(0)
05 09 // Usage Page(9) - Button
19 01 // Usage Minimum(1) - (BUTTON 1)
29 05 // Usage Maximum(5) - (BUTTON 5)
15 00 // Logical Minimum(0)
25 01 // Logical maximum(1)
95 05 // Report Count(5)
75 01 // Report Size(1)
81 02 // Input(2) // (Data, Variable, Absolute)
95 01 // Report Count(1)
75 03 // Report Size(3)
81 01 // Input(1) // (Constant, Array, Absolute)
05 01 // Usage Page(1) - Generic Desktop
09 30 // Usage(30) -(X)
09 31 // Usage(31) -(Y)
16 01 80 // Logical Minimum(8001)
26 FF 7F // Logical maximum(7fff)
75 10 // Report Size(10)
95 02 // Report Count(2)
81 06 // Input(6) // (Data, Variable, Relative)
09 38 // Usage(38) -(Wheel)
15 81 // Logical Minimum(81)
25 7F // Logical maximum(7f)
75 08 // Report Size(8)
95 01 // Report Count(1)
81 06 // Input(6) // (Data, Variable, Relative)
05 0C // Usage Page(c) - Consumer
0A 38 02 // Usage(238) -(AC Pan)
95 01 // Report Count(1)
81 06 // Input(6) // (Data, Variable, Relative)
C0 // End Collection
C0 // End Collection
05 0C // Usage Page(c) - Consumer
09 01 // Usage(1) -(Consumer Controls)
A1 01 // Collection(1) top Usage(c0000)
85 FF // Report ID(ff)
05 06 // Usage Page(6) - Other ?
95 01 // Report Count(1)
75 02 // Report Size(2)
19 24 // Usage Minimum(24) -
29 26 // Usage Maximum(26) -
81 02 // Input(2) // (Data, Variable, Absolute)
75 06 // Report Size(6)
81 01 // Input(1) // (Constant, Array, Absolute)
C0 // End Collection
Maybe next up is to migrate some of the sketch back into bluetooth.cpp, to more easily be able to query an attribute and parse it. And
And then the logical question is, should I then add more of the logical HID support (hidd.cpp) into Bluetooth), where the different BTHID clients can claim these different reports
and then add the hid parse code in to call off for each individual usage item?
Probably. But not sure how far I will take it.
If anyone is interested in this:
The WIP (experiments) is up on my USBHOST code in the branch BT_SDP_experiments.
Current test code included here.
Again I have idea how far I will take this!
(Random Rambling Complete)