3 * .../hidraw-ioctl </dev/hidrawN -a
4 * .../hidraw-ioctl </dev/hidrawN -[drnp]
5 * where -a means all, and the other letters are:
6 * -d descriptors (in hex)
7 * -D descriptors length (decimal), descriptors (in hex)
8 * -i HIDIOCGRAWINFO: bustype, vendor, product (all in hex)
10 * -p HIDIOCGRAWPATHPHYS
13 * 2 at least one ioctl on the device failed
14 * other some other problem
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
26 #include <linux/types.h>
32 void die_vprintf_hook(const char *fmt, va_list al) { }
33 void die_hook(void) { }
34 const char *progname= "hidraw-ioctl";
36 static void prerror(const char *what) {
37 printf("%s: %s\n", what, strerror(errno));
40 #define ERR(s) do{ prerror(s); e=1; goto next_opt; }while(0)
42 int main(int argc, char **argv) {
43 static const char allopts[]= "Dinp";
47 if (!*argv || !(opts=*++argv) || *opts++!='-' || *++argv)
48 badusage("need exactly one argument, containing options");
49 if (!strcmp(opts,"a")) opts= allopts;
51 while ((opt= *opts++)) {
56 r= ioctl(0, HIDIOCGRDESCSIZE, &descsz);
57 if (r) ERR("HIDIOCGRDESCSIZE");
59 if (opt=='D') printf("%d\n",descsz);
63 struct hidraw_report_descriptor d;
64 unsigned char buf[descsz];
67 r= ioctl(0, HIDIOCGRDESC, &d);
68 if (r) ERR("HIDIOCGRDESC");
70 dumphex(stdout, d.d.value, d.d.size);
76 struct hidraw_devinfo di;
77 r= ioctl(0, HIDIOCGRAWINFO, &di);
78 if (r) ERR("HIDIOCGRAWINFO");
79 printf("%08"PRIx32" %04"PRIx16" %04"PRIx16"\n",
80 di.bustype, di.vendor, di.product);
84 unsigned char buf[PATH_MAX];
85 r= ioctl(0, HIDIOCGRAWNAME(PATH_MAX), buf);
86 if (r<0) ERR("HIDIOCGRAWNAME");
87 printf("%d %.*s\n", r, r,buf);
91 r= ioctl(0, HIDIOCGRAWPHYS(PATH_MAX), buf);
92 if (r<0) ERR("HIDIOCGRAWPHYS");
93 printf("%d %.*s\n", r, r,buf);
97 badusage("unknown option");
101 if (ferror(stdout) || fflush(stdout))
102 diee("write/flush stdout");