10 #include <sys/types.h>
12 #include <linux/types.h>
13 #include <linux/hiddev.h>
18 static void dump(const void *pu, int l) {
28 static void report_scan(const char *which, int type) {
29 struct hiddev_report_info rinfo;
33 rinfo.report_type = type;
34 rinfo.report_id = HID_REPORT_ID_FIRST;
37 r = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
38 if (r && errno==EINVAL) break;
39 if (r) diee("HIDIOCGREPORTINFO");
41 printf("%s type=%08"PRIx32" id=%08"PRIx32" num_fields=%08"PRIx32"\n",
42 which, rinfo.report_type, rinfo.report_id, rinfo.num_fields);
43 for (i=0; i < rinfo.num_fields; i++) {
44 struct hiddev_field_info finfo;
45 finfo.report_type= rinfo.report_type;
46 finfo.report_id= rinfo.report_id;
48 r= ioctl(fd, HIDIOCGFIELDINFO, &finfo);
49 if (r) diee("HIDIOCGFIELDINFO");
50 printf("%s type=%08"PRIx32" id=%08"PRIx32" fi=%08"PRIx32
51 " maxusage=%08"PRIx32" flags=%08"PRIx32
52 " phys=%08"PRIx32"/log=%08"PRIx32"/app=%08"PRIx32
53 " log=%08"PRIx32"..%08"PRIx32
54 " phys=%08"PRIx32"..%08"PRIx32
56 which, finfo.report_type, finfo.report_id, finfo.field_index,
57 finfo.maxusage, finfo.flags,
58 finfo.physical, finfo.logical, finfo.application,
59 finfo.logical_minimum, finfo.logical_maximum,
60 finfo.physical_minimum, finfo.physical_maximum
62 for (j=0; j < finfo.maxusage; j++) {
63 struct hiddev_usage_ref uref;
64 uref.report_type= finfo.report_type;
65 uref.report_id= finfo.report_id;
68 r= ioctl(fd, HIDIOCGUCODE, &uref);
69 //dump(&uref,sizeof(uref));
70 r= ioctl(fd, HIDIOCGUSAGE, &uref);
71 //dump(&uref,sizeof(uref));
72 printf("%s type=%08"PRIx32" id=%08"PRIx32" fi=%08"PRIx32
73 " ui=%08"PRIx32" uc=%08"PRIx32" val=%08"PRIx32"\n",
74 which, uref.report_type, uref.report_id, uref.field_index,
75 uref.usage_index, uref.usage_code, uref.value);
78 rinfo.report_id |= HID_REPORT_ID_NEXT;
82 void die_vprintf_hook(const char *fmt, va_list al) { }
83 void die_hook(void) { }
84 const char *progname= "hiddev-ioctl";
86 int main(int argc, char **argv) {
88 if (!argv[0] || !argv[1]) badusage("too few args");
89 const char *act= *++argv;
90 if (!strcmp(act, "scan")) {
91 report_scan("input", HID_REPORT_TYPE_INPUT);
92 report_scan("output", HID_REPORT_TYPE_OUTPUT);
93 } else if (!strcmp(act, "send")) {
94 /* type id field val */
95 if (!argv[1] || !argv[2] || !argv[3] || !argv[4]
96 || !argv[5] || !argv[6] || argv[7])
97 badusage("wrong # args");
98 struct hiddev_usage_ref uref;
99 struct hiddev_report_info rinfo;
100 uref.report_type= strtoul(argv[1],0,0);
101 uref.report_id= strtoul(argv[2],0,0);
102 uref.field_index= strtoul(argv[3],0,0);
103 uref.usage_index= strtoul(argv[4],0,0);
104 uref.usage_code= strtoul(argv[5],0,0);
105 uref.value= strtol(argv[6],0,0);
106 rinfo.report_type= uref.report_type;
107 rinfo.report_id= uref.report_id;
109 // r= ioctl(0, HIDIOCGREPORT, &rinfo); if (r) diee("HIDIOCGREPORT");
110 // r= ioctl(0, HIDIOCGUSAGE, &uref); if (r) diee("HIDIOCGUSAGE");
111 //dump(&uref,sizeof(uref));
112 // printf("%08"PRIx32"...",uref.value);
113 r= ioctl(0, HIDIOCSUSAGE, &uref); if (r) diee("HIDIOCSUSAGE");
114 r= ioctl(0, HIDIOCSREPORT, &rinfo); if (r) diee("HIDIOCSREPORT");
116 badusage("unknown action");