|
From: Ludovic R. <lud...@gm...> - 2010-09-27 07:51:06
|
Hello,
I need to get the Report Count from my HID device to know the size I
need to use in hid_write(). The hidapi does not provide anything like
that. I could hardcode the size but I don't like that.
lsusb -v gives me the information I need. It also looks like libhid
can do that with the ReportCount field of the HIDParser struct.
My problem is that both lsusb (from usbutils) and libhid are GPL and
not LGPL. So I can't (legally) use them for my project.
Do you know a LGPL or BSD licensed HID parser?
Thanks
lsusb output;
Bus 001 Device 008: ID 08e6:8203 Gemplus
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x08e6 Gemplus
idProduct 0x8203
bcdDevice 2.00
iManufacturer 1 GEMALTO
iProduct 2 MMX V2.0
iSerial 3 E00000000000001
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 64
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 200mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk (Zip)
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.02
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 110
Report Descriptor: (length is 110)
Item(Global): Usage Page, data= [ 0x43 0xff ] 65347
(null)
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x3e 0x00 ] 62
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x02 ] 2
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x3e 0x00 ] 62
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x03 ] 3
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x05 ] 5
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Global): Usage Page, data= [ 0x47 0xff ] 65351
(null)
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x04 ] 4
Item(Global): Report Count, data= [ 0x3e 0x00 ] 62
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x05 ] 5
Item(Global): Report Count, data= [ 0x3e 0x00 ] 62
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x06 ] 6
Item(Global): Report Count, data= [ 0x05 ] 5
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position
Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x04 EP 4 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)
--
Dr. Ludovic Rousseau
|
|
From: Nikolai K. <sp...@gm...> - 2010-09-27 08:23:04
|
On 09/27/2010 11:50 AM, Ludovic Rousseau wrote: > I need to get the Report Count from my HID device to know the size I > need to use in hid_write(). The hidapi does not provide anything like > that. I could hardcode the size but I don't like that. > > lsusb -v gives me the information I need. It also looks like libhid > can do that with the ReportCount field of the HIDParser struct. > My problem is that both lsusb (from usbutils) and libhid are GPL and > not LGPL. So I can't (legally) use them for my project. > > Do you know a LGPL or BSD licensed HID parser? When I was starting my own HID parser I did a research and didn't find anything except libhid, now there is hidapi and that's all I know about. However, I could maybe help you write your own for your specific purposes - it's not that hard. What information do you need, exactly? Sincerely, Nick |
|
From: Ludovic R. <lud...@gm...> - 2010-09-27 11:49:00
|
2010/9/27 Nikolai Kondrashov <sp...@gm...>: > On 09/27/2010 11:50 AM, Ludovic Rousseau wrote: >> >> I need to get the Report Count from my HID device to know the size I >> need to use in hid_write(). The hidapi does not provide anything like >> that. I could hardcode the size but I don't like that. >> >> lsusb -v gives me the information I need. It also looks like libhid >> can do that with the ReportCount field of the HIDParser struct. >> My problem is that both lsusb (from usbutils) and libhid are GPL and >> not LGPL. So I can't (legally) use them for my project. >> >> Do you know a LGPL or BSD licensed HID parser? > > When I was starting my own HID parser I did a research and didn't find > anything except libhid, now there is hidapi and that's all I know about. > > However, I could maybe help you write your own for your specific purposes > - it's not that hard. What information do you need, exactly? I need: - Report Count field of each report (6 reports) - Usage Page field of each collection (2 collections) The source code should BSD or LGPL or something similar. Thanks -- Dr. Ludovic Rousseau |
|
From: Nikolai K. <sp...@gm...> - 2010-09-27 12:19:46
|
> I need:
> - Report Count field of each report (6 reports)
> - Usage Page field of each collection (2 collections)
>
> The source code should BSD or LGPL or something similar.
I don't have a source code, but I could give you a rough algorithm which
combined with the HID specification will help you write your own parser.
Something like this:
uint32_t usage_page = 0;
uint32_t report_id = 0;
uint8_t *p;
for (p = rdesc_buf; p - rdesc_buf < rdesc_size;)
{
/* See 6.2.2.2 Short Items */
uint8_t pfx = *p++;
uint8_t size = pfx & 0x3;
uint8_t bytes = size_to_bytes(size);
uint8_t type = (pfx >> 2) & 0x3;
uint8_t tag = pfx >> 4;
/* If it's a main item */
if (type == 0)
{
/* If it's a collection item */
if (tag == 0xA)
start_collection(usage_page);
/* Else if it's an end collection item */
else if (tag == 0xC)
end_collection();
}
/* Else, if it's a global item */
else if (type == 1)
{
/* If it's a usage page item */
if (tag == 0x0)
usage_page = le_to_cpu(bytes, p);
/* Else if it's a report ID item */
else if (tag == 0x8)
report_id = le_to_cpu(bytes, p);
/* Else if it's a report count item */
else if (tag == 0x9)
add_report_field(report_id, le_to_cpu(bytes, p));
}
p += bytes;
}
Good luck :)
Sincerely,
Nick
|
|
From: Alan O. <al...@si...> - 2010-09-27 12:04:13
|
On 09/27/2010 03:50 AM, Ludovic Rousseau wrote: > Hello, > > I need to get the Report Count from my HID device to know the size I > need to use in hid_write(). The hidapi does not provide anything like > that. I could hardcode the size but I don't like that. > One argument that is often made is that if you're driving a HID device directly, then you already know the format of the data, including the size of each report. It's not strictly necessary to query the device. Even if you did, what do you do if the device says that its report sizes are different than you expect? Even in the Linux kernel, fixed sizes are used for outputting data to USB devices (sizeof(), hard-coded, etc). I don't think it's a bad thing. I'm sure many on this mailing list will agree (or will explain why I am wrong). > lsusb -v gives me the information I need. It also looks like libhid > can do that with the ReportCount field of the HIDParser struct. > My problem is that both lsusb (from usbutils) and libhid are GPL and > not LGPL. So I can't (legally) use them for my project. > > Do you know a LGPL or BSD licensed HID parser? > I do not. I was able to do some parsing of a report descriptor myself without too much problem. The code is in HIDAPI in linux/hid.c in a function called uses_numbered_reports(). My basic parser looks for Report ID (0x85). I'm just checking for the presence of it. You could probably modify that to look for Report Size and Report Count fields ahead of the Input field. Alan. |