From: jcs Date: Mon, 31 May 2021 18:30:11 +0000 (+0000) Subject: add an -R flag to dump the raw report descriptor bytes for parsing X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a2d6543fe33e1fba36d32852450ab6ecca0a1322;p=openbsd add an -R flag to dump the raw report descriptor bytes for parsing with other tools man page help from jmc ok anton --- diff --git a/usr.bin/usbhidctl/usbhid.c b/usr.bin/usbhidctl/usbhid.c index 921f211a280..25cc61bdf93 100644 --- a/usr.bin/usbhidctl/usbhid.c +++ b/usr.bin/usbhidctl/usbhid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbhid.c,v 1.16 2021/02/04 06:57:19 anton Exp $ */ +/* $OpenBSD: usbhid.c,v 1.17 2021/05/31 18:30:11 jcs Exp $ */ /* $NetBSD: usbhid.c,v 1.22 2002/02/20 20:30:42 christos Exp $ */ /* @@ -755,6 +755,7 @@ usage(void) fprintf(stderr, " %s -f device [-t table] -w name=value ...\n", __progname); + fprintf(stderr, " %s -f device -R\n", __progname); exit(1); } @@ -764,16 +765,18 @@ main(int argc, char **argv) char const *dev; char const *table; size_t varnum; - int aflag, lflag, nflag, rflag, wflag; - int ch, hidfd; + uint32_t repsize; + int aflag, lflag, nflag, rflag, Rflag, wflag; + int ch, hidfd, x; + uint8_t *repdata; report_desc_t repdesc; char devnamebuf[PATH_MAX]; struct Susbvar variables[128]; - wflag = aflag = nflag = verbose = rflag = lflag = 0; + wflag = aflag = nflag = verbose = rflag = Rflag = lflag = 0; dev = NULL; table = NULL; - while ((ch = getopt(argc, argv, "?af:lnrt:vw")) != -1) { + while ((ch = getopt(argc, argv, "?af:lnRrt:vw")) != -1) { switch (ch) { case 'a': aflag = 1; @@ -790,6 +793,9 @@ main(int argc, char **argv) case 'r': rflag = 1; break; + case 'R': + Rflag = 1; + break; case 't': table = optarg; break; @@ -807,7 +813,8 @@ main(int argc, char **argv) } argc -= optind; argv += optind; - if (dev == NULL || (lflag && (wflag || rflag))) { + if (dev == NULL || (lflag && (wflag || rflag || Rflag)) || + (rflag && Rflag)) { /* * No device specified, or attempting to loop and set * or dump report at the same time @@ -942,6 +949,14 @@ main(int argc, char **argv) if (repdesc == 0) errx(1, "USB_GET_REPORT_DESC"); + if (Rflag) { + hid_get_report_desc_data(repdesc, &repdata, &repsize); + + for (x = 0; x < repsize; x++) + printf("%s0x%02x", x > 0 ? " " : "", repdata[x]); + printf("\n"); + } + if (lflag) { devloop(hidfd, repdesc, variables, varnum); /* NOTREACHED */ @@ -951,10 +966,11 @@ main(int argc, char **argv) /* Report mode header */ printf("Report descriptor:\n"); - devshow(hidfd, repdesc, variables, varnum, - 1 << hid_input | - 1 << hid_output | - 1 << hid_feature); + if (!Rflag) + devshow(hidfd, repdesc, variables, varnum, + 1 << hid_input | + 1 << hid_output | + 1 << hid_feature); if (rflag) { /* Report mode trailer */ diff --git a/usr.bin/usbhidctl/usbhidctl.1 b/usr.bin/usbhidctl/usbhidctl.1 index 5b8e59f7bd7..5f0f2d5d01f 100644 --- a/usr.bin/usbhidctl/usbhidctl.1 +++ b/usr.bin/usbhidctl/usbhidctl.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: usbhidctl.1,v 1.14 2013/07/16 00:07:52 schwarze Exp $ +.\" $OpenBSD: usbhidctl.1,v 1.15 2021/05/31 18:30:11 jcs Exp $ .\" $NetBSD: usbhidctl.1,v 1.14 2001/12/28 17:49:32 augustss Exp $ .\" .\" Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: July 16 2013 $ +.Dd $Mdocdate: May 31 2021 $ .Dt USBHIDCTL 1 .Os .Sh NAME @@ -53,6 +53,9 @@ .Fl f Ar device .Op Fl t Ar table .Fl w Ar name Ns = Ns Ar value ... +.Nm +.Fl f Ar device +.Fl R .Sh DESCRIPTION .Nm can be used to output or modify the state of a USB HID (Human Interface Device). @@ -88,6 +91,8 @@ Only 'input' items are displayed in this mode. .It Fl n Suppress printing of the item name when querying specific items. Only output the current value. +.It Fl R +Dump the raw USB HID report descriptor data as hexadecimal bytes. .It Fl r Dump the USB HID report descriptor. .It Fl t Ar table