Understanding BlueZ for HID bluetooth

SuperPCFan

New Member
Joined
May 2, 2021
Messages
5
Reaction score
0
Credits
71
I want to use a RPi4 with Raspbian GNU/Linux 10 (buster) as bluetooth HID device.

The bluetooth pairing works fine as long as I not load my Java app. At the startup my Java app uses the BlueCove lib to start a "btspp" server with the HID service (1124). I got no exception from Java and no error from the sddb at setup. With "sdptool" a can see the HID service running at the sddb.

But when I try to pair my RPi4 with a client PC after startup of my app the connection is refused right after the beginning. I added the system log (btlog.txt) of the pairing process which shows the errors but I do not understand the error ids and I cannot find a error id description.

I assume there is a mistake in the HID service attributes settings my app defines but after reviewing specs and examples I cannot find a obvious problem. I added my Java bluetooth class with the attribute constants and the HID descriptors.

Has someone a hint?
 

Attachments

  • btlog.txt
    3.4 KB · Views: 300
  • BtHidHandler.zip
    3.4 KB · Views: 365
  • mediaJoystickRepDesc.txt
    1.2 KB · Views: 315
  • mediaKeyboardRepDesc.txt
    867 bytes · Views: 324
  • mediaMouseRepDesc.txt
    138 bytes · Views: 292


I found a possible problem, but have no solution upto now. It looks like to be an encoding issue.

As the spec defines the Hid descriptor item should be a "string attribute type with unsigned int8 elements". Therefore I wrote this codesnippet to convert my descriptor (checked and tested for correctness) from a Byte list to the needed string format:

JavaScript:
StringBuilder btHIDDescriptor_Data = new StringBuilder();
ArrayList<Byte> report = HidWorkbench.parseDatFormat(new BufferedReader(new FileReader(reportDatFile)));
report.forEach(bElement -> {
    btHIDDescriptor_Data.append((char)bElement.byteValue());
});
btHIDDescriptor.addElement(new DataElement(DataElement.STRING, btHIDDescriptor_Data.toString()));

The HID report descriptor from my file "mediaMouseRepDesc" for example looks like:
05010902A10185010901A1000930093109381581257F75089503810605091901290815002501750195088102C0C0

The strange issue I found and don't understand is the readback from the sddb. If I read the service back from the sddb in xml format I get:
05010902efbea101efbe85010901efbea10009300931093815efbe81257f7508efbe9503efbe8106050919012908150025017501efbe9508efbe8102efbf80efbf80

In addition to the expected values there are bytes in the string I cannot determine. I don't get a pattern or meaning behind it. My Java application says the string ist exact as long as the byte list is. That let me assume that it's an encoding issue, but what encoding is expected here?
 
I tested the string conversion with different encoding constraints (UTF-8, US_ASCII, ISO-8859-1 and so on). All encoding types leads to the same fault in different variations.
If the byte value is negativ, all encodings add different bytes with different values in front of it.
It seems not to be possible to generate a string with Java that contains really only single-byte-characters.

But this would imply a strange design fault in the BlueCove lib.
The constructor new DataElement(DataElement.STRING, reportString) only accepts strings. Other types like byte[] or char[] throw a illegal argument exception. I must use strings but any Java string in every type is misinterpreted.

So I don't know how the report descriptor configuration with this lib should work.

This leads to my initial question. Due to the issue I do not understand the error log I do not know if this descriptor issue is really the problem.
 
Last edited:

Members online


Top