-/* $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 $ */
/*
fprintf(stderr,
" %s -f device [-t table] -w name=value ...\n",
__progname);
+ fprintf(stderr, " %s -f device -R\n", __progname);
exit(1);
}
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;
case 'r':
rflag = 1;
break;
+ case 'R':
+ Rflag = 1;
+ break;
case 't':
table = optarg;
break;
}
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
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 */
/* 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 */
-.\" $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.
.\" 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
.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).
.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