chiark / gitweb /
hostside: utils: new dumphex function, moved from hidraw-ioctl.c
[trains.git] / hostside / hidraw-ioctl.c
1 /**/
2
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <inttypes.h>
9 #include <sys/ioctl.h>
10 #include <sys/types.h>
11
12 #include <linux/types.h>
13
14 #include "hidraw.h"
15
16 #include "common.h"
17
18 int main(int argc, char **argv) {
19   int r, descsz;
20
21   r= ioctl(0, HIDIOCGRDESCSIZE, &descsz);
22   if (r) {
23     perror("HIDIOCGRDESCSIZE");
24   } else {
25     printf("%d\n",descsz);
26     struct {
27       struct hidraw_report_descriptor d;
28       unsigned char buf[descsz];
29     } d;
30     d.d.size = descsz;
31     r= ioctl(0, HIDIOCGRDESC, &d);
32     if (r) perror("HIDIOCGRDESC");
33     else { dump(d.d.value, d.d.size); putchar('\n'); }
34   }
35
36   struct hidraw_devinfo di;
37   r= ioctl(0, HIDIOCGRAWINFO, &di);
38   if (r) perror("HIDIOCGRAWINFO");
39   else {
40     printf("%08"PRIx32" %04"PRIx16" %04"PRIx16"\n",
41            di.bustype, di.vendor, di.product);
42   }
43
44   unsigned char buf[PATH_MAX];
45
46   r= ioctl(0, HIDIOCGRAWNAME(PATH_MAX), buf);
47   if (r<0) perror("HIDIOCGRAWNAME");
48   else printf("%d %.*s\n", r, r,buf);
49
50   r= ioctl(0, HIDIOCGRAWPHYS(PATH_MAX), buf);
51   if (r<0) perror("HIDIOCGRAWPHYS");
52   else printf("%d %.*s\n", r, r,buf);
53
54   return 0;
55 }