From 1504712066ae650e1292cdc2f9d618f9216c3426 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 19 Feb 2011 19:21:03 +0000 Subject: [PATCH] hostside: hidrawconv: cope with difference between 2.6.26 and 2.6.33, guessing the kernel behaviour by whether the kernel supports HIDIOCGRAWPHYS and HIDIOCGRAWNAME --- hostside/hidrawconv-joytechneos.c | 12 ++++++++- hostside/hidrawconv.c | 44 +++++++++++++++++++++++++++---- hostside/hidrawconv.h | 7 +++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/hostside/hidrawconv-joytechneos.c b/hostside/hidrawconv-joytechneos.c index 64b6a2b..adeb086 100644 --- a/hostside/hidrawconv-joytechneos.c +++ b/hostside/hidrawconv-joytechneos.c @@ -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 }; diff --git a/hostside/hidrawconv.c b/hostside/hidrawconv.c index 6151b0a..3321ccf 100644 --- a/hostside/hidrawconv.c +++ b/hostside/hidrawconv.c @@ -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: diff --git a/hostside/hidrawconv.h b/hostside/hidrawconv.h index 2fdfdb2..6ffd35e 100644 --- a/hostside/hidrawconv.h +++ b/hostside/hidrawconv.h @@ -4,6 +4,13 @@ #include #include +#include +#include + +#include + +#include "hidraw.h" + #include "common.h" #define MAXREPORTLEN 256 -- 2.30.2