chiark / gitweb /
hostside: hidrawconv: cope with difference between 2.6.26 and 2.6.33, guessing the...
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 19 Feb 2011 19:21:03 +0000 (19:21 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 19 Feb 2011 19:48:11 +0000 (19:48 +0000)
hostside/hidrawconv-joytechneos.c
hostside/hidrawconv.c
hostside/hidrawconv.h

index 64b6a2bd36573989a7808bc7c16066fbbf3c2d0c..adeb086191038b0b26dbf33cf7b3edded17cd8b3 100644 (file)
@@ -29,11 +29,21 @@ static void pr(const uint8_t *msg, int msglen, const uint8_t *last) {
   reportlocs(msg, last, msglen, vallocs);
 }
 
+ProcessReport *const nested_processors[MAXREPORTS]= {
+ [0x4a] = pr
+};
+
 const char *progname= "hidrawconv-joytechneos";
 
 const char *const descriptor=
   "05010904a101854a0901a1000501093009311580257f350045ff660000750895028102c0050209ba150026ff00750895018102050209bb150026ff007508950181020501093915012508360000463b016514750895018102950c7501050945013500150025011901290c810295040605ff09018102c005140924a101854d150026ff000931750895079182c005010906a101854b050719e029e71500250175019508810295017508810195057501050819012905910295017503910195057508150025680507190029688100c0";
 
+static LastReports inner_lasts;
+
+static void pr_outer(const uint8_t *msg, int msglen, const uint8_t *last) {
+  dispatch(&inner_lasts,"inner message: ",nested_processors, msg+1,msglen-1);
+}
+
 ProcessReport *const report_processors[MAXREPORTS]= {
- [0x4a] = pr
+ [0x00] = pr_outer
 };
index 6151b0ade984162544fadf9c1200625d1a379be5..3321ccf701aa517a1a475b27db361d56fd971e62 100644 (file)
@@ -5,6 +5,7 @@
  * where -a means all, and the other letters are:
  *   -d   print expected descriptor (as for hidraw-ioctl -d)
  *   -e   pretend to be evdev-manip
+ *   -E   pretend to be evdev-manip, print to stderr about the device at start
  * exit status:
  *   0      all ok
  *   other  some other problem
@@ -48,6 +49,11 @@ void reportlocs(const uint8_t msg[], const uint8_t last[],
 void dispatch(LastReports *lasts, const char *message_prefix,
              ProcessReport *const report_processors[MAXREPORTS],
              const uint8_t *msg, int l) {
+  if (!l) {
+    fprintf(stderr,"%s:%s report too short\n", progname, message_prefix);
+    return;
+  }
+
   ProcessReport *pr= report_processors[msg[0]];
   Last *last= &lasts->lasts[msg[0]];
   if (!pr) {
@@ -66,13 +72,37 @@ void dispatch(LastReports *lasts, const char *message_prefix,
   memcpy(last->msg, msg, l);
 }  
 
-static void events(void) {
-  uint8_t msg[MAXREPORTLEN];
+static void events(int verbose) {
+  uint8_t msg[MAXREPORTLEN+1];
+  char phys[PATH_MAX], name[PATH_MAX];
+  int rphys, errnophys=0, rname, errnoname=0;
+  int reportnumbug;
+
+  rphys= ioctl(0, HIDIOCGRAWPHYS(PATH_MAX), phys);  errnophys=errno;
+  rname= ioctl(0, HIDIOCGRAWNAME(PATH_MAX), name);  errnoname=errno;
+  if (rphys>=0 && rname>=0) {
+    reportnumbug= 0;
+    if (verbose)
+      fprintf(stderr,"%s: %.*s %.*s\n",progname,rphys,phys,rname,name);
+  } else if (rphys<0 && errnophys==EINVAL &&
+            rname<0 && errnoname==EINVAL) {
+    fprintf(stderr,"%s: warning, HIDIOCGRAWPHYS/NAME gave EINVAL,"
+           " assuming kernel eats report number, assuming reports are 00\n",
+           progname);
+    reportnumbug= 1;
+  } else {
+    die("HIDIOCGRAWPHYS %s / HIDIOCGRAWNAME %s",
+       rphys<0 ? strerror(errnophys) : "ok",
+       rname<0 ? strerror(errnoname) : "ok");
+  }
+
+  if (reportnumbug) msg[0]=0;
 
   for (;;) {
-    int l= read(0, msg, sizeof(msg));
+    int l= read(0, msg+reportnumbug, sizeof(msg)-reportnumbug);
     if (!l) break;
     if (l<0) { perror("hidrawconv: read"); exit(-1); }
+    l += reportnumbug;
     dispatch(&lasts,"",report_processors, msg,l);
     if (ferror(stdout) || fflush(stdout))
       diee("failed flushing event to stdout");
@@ -83,15 +113,19 @@ int main(int argc, char **argv) {
   const char *how;
 
   if (!*argv || !(how=*++argv) || *how++!='-' || !*how || how[1] || *++argv)
-    badusage("need exactly one argument, -d or -e");
+    badusage("need exactly one argument, -d, -e or -E");
 
   switch (how[0]) {
   case 'd':
     puts(descriptor);
     break;
 
+  case 'E':
+    events(1);
+    break;
+
   case 'e':
-    events();
+    events(0);
     break;
 
   default:
index 2fdfdb2d43056c2d881f8550e73258d1146d5fa4..6ffd35eccd60fa2817f7f2051002783abbc9f83d 100644 (file)
@@ -4,6 +4,13 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <linux/types.h>
+
+#include "hidraw.h"
+
 #include "common.h"
 
 #define MAXREPORTLEN 256