chiark / gitweb /
hostside: wip test programs etc. for Joytech Neo S gamepad
[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 static void dump(const void *pu, int l) {
19   const uint8_t *p= pu;
20   while (l>0) {
21     printf("%02x",*p++);
22     l--;
23   }
24   putchar(' ');
25 }
26
27 int main(int argc, char **argv) {
28   int r, descsz;
29
30   r= ioctl(0, HIDIOCGRDESCSIZE, &descsz);
31   if (r) {
32     perror("HIDIOCGRDESCSIZE");
33   } else {
34     printf("%d\n",descsz);
35     struct {
36       struct hidraw_report_descriptor d;
37       unsigned char buf[descsz];
38     } d;
39     d.d.size = descsz;
40     r= ioctl(0, HIDIOCGRDESC, &d);
41     if (r) perror("HIDIOCGRDESC");
42     else { dump(d.d.value, d.d.size); putchar('\n'); }
43   }
44
45   struct hidraw_devinfo di;
46   r= ioctl(0, HIDIOCGRAWINFO, &di);
47   if (r) perror("HIDIOCGRAWINFO");
48   else {
49     printf("%08"PRIx32" %04"PRIx16" %04"PRIx16"\n",
50            di.bustype, di.vendor, di.product);
51   }
52
53   unsigned char buf[PATH_MAX];
54
55   r= ioctl(0, HIDIOCGRAWNAME(PATH_MAX), buf);
56   if (r<0) perror("HIDIOCGRAWNAME");
57   else printf("%d %.*s\n", r, r,buf);
58
59   r= ioctl(0, HIDIOCGRAWPHYS(PATH_MAX), buf);
60   if (r<0) perror("HIDIOCGRAWPHYS");
61   else printf("%d %.*s\n", r, r,buf);
62
63   return 0;
64 }