From ad37555d422d0e4b4662a53f1df5fe77c6a7a841 Mon Sep 17 00:00:00 2001 From: mav Date: Sat, 30 Jul 2011 13:22:44 +0000 Subject: MFprojects/hid: - Fix usbhidctl and usbhidaction to handle HID devices with multiple report ids, such as multimedia keyboards. - Add collection type and report id to the `usbhidctl -r` output. They are important for proper device understanding and debugging. - Fix usbhidaction tool to properly handle items having report_count more then 1. Approved by: re (kib) MFC after: 2 weeks --- usr.bin/usbhidctl/usbhid.c | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'usr.bin/usbhidctl') diff --git a/usr.bin/usbhidctl/usbhid.c b/usr.bin/usbhidctl/usbhid.c index 2ac947d..281078d 100644 --- a/usr.bin/usbhidctl/usbhid.c +++ b/usr.bin/usbhidctl/usbhid.c @@ -46,7 +46,6 @@ int verbose = 0; int all = 0; int noname = 0; int hexdump = 0; -static int reportid; char **names; int nnames; @@ -101,11 +100,12 @@ dumpitem(const char *label, struct hid_item *h) { if ((h->flags & HIO_CONST) && !verbose) return; - printf("%s size=%d count=%d page=%s usage=%s%s", label, - h->report_size, h->report_count, + printf("%s rid=%d size=%d count=%d page=%s usage=%s%s%s", label, + h->report_ID, h->report_size, h->report_count, hid_usage_page(HID_PAGE(h->usage)), hid_usage_in_page(h->usage), - h->flags & HIO_CONST ? " Const" : ""); + h->flags & HIO_CONST ? " Const" : "", + h->flags & HIO_VARIABLE ? "" : " Array"); printf(", logical range %d..%d", h->logical_minimum, h->logical_maximum); if (h->physical_minimum != h->physical_maximum) @@ -116,6 +116,24 @@ dumpitem(const char *label, struct hid_item *h) printf("\n"); } +static const char * +hid_collection_type(int32_t type) +{ + static char num[8]; + + switch (type) { + case 0: return ("Physical"); + case 1: return ("Application"); + case 2: return ("Logical"); + case 3: return ("Report"); + case 4: return ("Named_Array"); + case 5: return ("Usage_Switch"); + case 6: return ("Usage_Modifier"); + } + snprintf(num, sizeof(num), "0x%02x", type); + return (num); +} + void dumpitems(report_desc_t r) { @@ -123,10 +141,11 @@ dumpitems(report_desc_t r) struct hid_item h; int size; - for (d = hid_start_parse(r, ~0, reportid); hid_get_item(d, &h); ) { + for (d = hid_start_parse(r, ~0, -1); hid_get_item(d, &h); ) { switch (h.kind) { case hid_collection: - printf("Collection page=%s usage=%s\n", + printf("Collection type=%s page=%s usage=%s\n", + hid_collection_type(h.collection), hid_usage_page(HID_PAGE(h.usage)), hid_usage_in_page(h.usage)); break; @@ -145,13 +164,13 @@ dumpitems(report_desc_t r) } } hid_end_parse(d); - size = hid_report_size(r, hid_input, 0); + size = hid_report_size(r, hid_input, -1); printf("Total input size %d bytes\n", size); - size = hid_report_size(r, hid_output, 0); + size = hid_report_size(r, hid_output, -1); printf("Total output size %d bytes\n", size); - size = hid_report_size(r, hid_feature, 0); + size = hid_report_size(r, hid_feature, -1); printf("Total feature size %d bytes\n", size); } @@ -180,14 +199,17 @@ prdata(u_char *buf, struct hid_item *h) pos = h->pos; for (i = 0; i < h->report_count; i++) { data = hid_get_data(buf, h); + if (i > 0) + printf(" "); if (h->logical_minimum < 0) printf("%d", (int)data); else printf("%u", data); if (hexdump) printf(" [0x%x]", data); - pos += h->report_size; + h->pos += h->report_size; } + h->pos = pos; } void @@ -202,7 +224,7 @@ dumpdata(int f, report_desc_t rd, int loop) char namebuf[10000], *namep; hids = 0; - for (d = hid_start_parse(rd, 1<next) { + if (n->report_ID != 0 && dbuf[0] != n->report_ID) + continue; namep = namebuf; namep += sprintf(namep, "%s:%s.", hid_usage_page(HID_PAGE(n->collection)), @@ -242,7 +266,7 @@ dumpdata(int f, report_desc_t rd, int loop) if (all || gotname(namebuf)) { if (!noname) printf("%s=", namebuf); - prdata(dbuf + (reportid != 0), n); + prdata(dbuf, n); printf("\n"); } } -- cgit v1.1