6 #include <linux/hidraw.h>
8 typedef unsigned char byte;
9 typedef unsigned int uns;
11 static void parse(byte *desc, uns size)
13 byte *end = desc + size;
19 printf("FATAL: Unsupported long item found.\n");
22 if ((flags & 0x0c) == 0x0c) {
23 printf("FATAL: Unsupported item type 3.\n");
26 const uns sizes[4] = { 0, 1, 2, 4 };
27 uns size = sizes[flags & 3];
28 if (desc + size > end) {
29 printf("FATAL: Truncated item.\n");
33 for (uns i=0; i<size; i++)
34 val |= *desc++ << (8*i);
36 printf("%*s%c%x[%d:%08x] ", indent, "", "MGL?"[(flags >> 2) & 3], flags >> 4, size, val);
39 case 0x80: printf("Input\n");
41 case 0x90: printf("Output\n");
43 case 0xa0: printf("Collection (type %d) {\n", val);
46 case 0xb0: printf("Feature\n");
48 case 0xc0: printf("} EndCollection\n");
52 printf("WARNING: Unbalanced collections!\n");
56 case 0x04: printf("UsagePage %04x\n", val);
58 case 0x14: printf("LogicalMin %d\n", val);
60 case 0x24: printf("LogicalMax %d\n", val);
62 case 0x34: printf("PhysicalMin %d\n", val);
64 case 0x44: printf("PhysicalMax %d\n", val);
66 case 0x54: printf("UnitExponent\n");
68 case 0x64: printf("Unit\n");
70 case 0x74: printf("ReportSize %d\n", val);
72 case 0x84: printf("ReportID %d\n", val);
74 case 0x94: printf("ReportCount %d\n", val);
76 case 0xa4: printf("PUSH\n");
78 case 0xb4: printf("POP\n");
82 case 0x08: printf("Usage %04x\n", val);
84 case 0x18: printf("UsageMin %04x\n", val);
86 case 0x28: printf("UsageMax %04x\n", val);
88 case 0x38: printf("DesignatorIndex %d\n", val);
90 case 0x48: printf("DesignatorMin %d\n", val);
92 case 0x58: printf("DesignatorMax %d\n", val);
94 case 0x78: printf("StringIndex %d\n", val);
96 case 0x88: printf("StringMin %d\n", val);
98 case 0x98: printf("StringMax %d\n", val);
100 case 0xa8: printf("Delimiter %s\n", (val==0 ? "open" : val==1 ? "close" : "???"));
104 default: printf("?\n");
109 printf("WARNING: Unbalanced collections!\n");
114 int fd = open("/dev/hidraw1", O_RDONLY);
116 fprintf(stderr, "Cannot open hidraw: %m\n");
121 if (ioctl(fd, HIDIOCGRDESCSIZE, &size) < 0) {
122 fprintf(stderr, "Cannot get desc size: %m\n");
125 printf("Detected descriptor size %d\n", size);
127 struct hidraw_report_descriptor desc;
129 if (ioctl(fd, HIDIOCGRDESC, &desc) < 0) {
130 fprintf(stderr, "Cannot get desc contents: %m\n");
133 printf("Read %d bytes\n", desc.size);
135 struct hidraw_devinfo din;
136 if (ioctl(fd, HIDIOCGRAWINFO, &din) < 0) {
137 fprintf(stderr, "Cannot get raw info: %m\n");
140 printf("bustype: %d, id=%04x:%04x\n", din.bustype, (unsigned short) din.vendor, (unsigned short) din.product);
142 parse(desc.value, size);