2006-05-11 01:53:14 +04:00
|
|
|
/* $NetBSD: usbhid.c,v 1.30 2006/05/10 21:53:48 mrg Exp $ */
|
1998-07-13 15:14:03 +04:00
|
|
|
|
|
|
|
/*
|
2001-10-23 02:03:49 +04:00
|
|
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
1998-07-13 15:14:03 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:17:06 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-09-24 06:27:12 +04:00
|
|
|
* by David Sainty <David.Sainty@dtsp.co.nz>
|
1998-07-13 15:14:03 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2003-06-23 17:05:47 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#ifndef lint
|
2006-05-11 01:53:14 +04:00
|
|
|
__RCSID("$NetBSD: usbhid.c,v 1.30 2006/05/10 21:53:48 mrg Exp $");
|
2003-06-23 17:05:47 +04:00
|
|
|
#endif
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbhid.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
1998-07-13 15:14:03 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-07-03 06:51:12 +04:00
|
|
|
#include <string.h>
|
1998-07-13 15:14:03 +04:00
|
|
|
#include <unistd.h>
|
2001-12-28 20:49:31 +03:00
|
|
|
#include <usbhid.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero if not in a verbose mode. Greater levels of verbosity
|
|
|
|
* are indicated by values larger than one.
|
|
|
|
*/
|
|
|
|
unsigned int verbose;
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
/* Parser tokens */
|
|
|
|
#define DELIM_USAGE '.'
|
|
|
|
#define DELIM_PAGE ':'
|
|
|
|
#define DELIM_SET '='
|
1998-07-14 00:56:28 +04:00
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
static int reportid;
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
struct Susbvar {
|
|
|
|
/* Variable name, not NUL terminated */
|
|
|
|
char const *variable;
|
|
|
|
size_t varlen;
|
1998-07-14 00:56:28 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
char const *value; /* Value to set variable to */
|
|
|
|
|
|
|
|
#define MATCH_ALL (1 << 0)
|
|
|
|
#define MATCH_COLLECTIONS (1 << 1)
|
|
|
|
#define MATCH_NODATA (1 << 2)
|
|
|
|
#define MATCH_CONSTANTS (1 << 3)
|
|
|
|
#define MATCH_WASMATCHED (1 << 4)
|
|
|
|
#define MATCH_SHOWPAGENAME (1 << 5)
|
|
|
|
#define MATCH_SHOWNUMERIC (1 << 6)
|
|
|
|
#define MATCH_WRITABLE (1 << 7)
|
2001-10-23 02:03:49 +04:00
|
|
|
#define MATCH_SHOWVALUES (1 << 8)
|
2000-09-24 06:27:12 +04:00
|
|
|
unsigned int mflags;
|
|
|
|
|
|
|
|
/* Workspace for hidmatch() */
|
|
|
|
ssize_t matchindex;
|
|
|
|
|
|
|
|
int (*opfunc)(struct hid_item *item, struct Susbvar *var,
|
|
|
|
u_int32_t const *collist, size_t collen, u_char *buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sreport {
|
|
|
|
struct usb_ctl_report *buffer;
|
|
|
|
|
|
|
|
enum {srs_uninit, srs_clean, srs_dirty} status;
|
|
|
|
int report_id;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int uhid_report;
|
|
|
|
hid_kind_t hid_kind;
|
|
|
|
char const *name;
|
|
|
|
} const reptoparam[] = {
|
|
|
|
#define REPORT_INPUT 0
|
|
|
|
{ UHID_INPUT_REPORT, hid_input, "input" },
|
|
|
|
#define REPORT_OUTPUT 1
|
|
|
|
{ UHID_OUTPUT_REPORT, hid_output, "output" },
|
|
|
|
#define REPORT_FEATURE 2
|
|
|
|
{ UHID_FEATURE_REPORT, hid_feature, "feature" }
|
|
|
|
#define REPORT_MAXVAL 2
|
|
|
|
};
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
/*
|
|
|
|
* Extract 16-bit unsigned usage ID from a numeric string. Returns -1
|
|
|
|
* if string failed to parse correctly.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
strtousage(const char *nptr, size_t nlen)
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
long result;
|
|
|
|
char numstr[16];
|
|
|
|
|
|
|
|
if (nlen >= sizeof(numstr) || !isdigit((unsigned char)*nptr))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We use strtol() here, but unfortunately strtol() requires a
|
|
|
|
* NUL terminated string - which we don't have - at least not
|
|
|
|
* officially.
|
|
|
|
*/
|
|
|
|
memcpy(numstr, nptr, nlen);
|
|
|
|
numstr[nlen] = '\0';
|
|
|
|
|
|
|
|
result = strtol(numstr, &endptr, 0);
|
|
|
|
|
|
|
|
if (result < 0 || result > 0xffff || endptr != &numstr[nlen])
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct usagedata {
|
|
|
|
char const *page_name;
|
|
|
|
char const *usage_name;
|
|
|
|
size_t page_len;
|
|
|
|
size_t usage_len;
|
|
|
|
int isfinal;
|
|
|
|
u_int32_t usage_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test a rule against the current usage data. Returns -1 on no
|
|
|
|
* match, 0 on partial match and 1 on complete match.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
hidtestrule(struct Susbvar *var, struct usagedata *cache)
|
|
|
|
{
|
|
|
|
char const *varname;
|
|
|
|
ssize_t matchindex, pagesplit;
|
|
|
|
size_t strind, varlen;
|
|
|
|
int numusage;
|
|
|
|
u_int32_t usage_id;
|
|
|
|
|
|
|
|
matchindex = var->matchindex;
|
|
|
|
varname = var->variable;
|
|
|
|
varlen = var->varlen;
|
|
|
|
|
|
|
|
usage_id = cache->usage_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the current variable name, locating the end of the
|
|
|
|
* current 'usage', and possibly where the usage page name
|
|
|
|
* ends.
|
|
|
|
*/
|
|
|
|
pagesplit = -1;
|
|
|
|
for (strind = matchindex; strind < varlen; strind++) {
|
|
|
|
if (varname[strind] == DELIM_USAGE)
|
|
|
|
break;
|
|
|
|
if (varname[strind] == DELIM_PAGE)
|
|
|
|
pagesplit = strind;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cache->isfinal && strind != varlen)
|
|
|
|
/*
|
|
|
|
* Variable name is too long (hit delimiter instead of
|
|
|
|
* end-of-variable).
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pagesplit >= 0) {
|
|
|
|
/*
|
|
|
|
* Page name was specified, determine whether it was
|
|
|
|
* symbolic or numeric.
|
|
|
|
*/
|
|
|
|
char const *strstart;
|
|
|
|
int numpage;
|
|
|
|
|
|
|
|
strstart = &varname[matchindex];
|
|
|
|
|
|
|
|
numpage = strtousage(strstart, pagesplit - matchindex);
|
|
|
|
|
|
|
|
if (numpage >= 0) {
|
|
|
|
/* Valid numeric */
|
|
|
|
|
|
|
|
if (numpage != HID_PAGE(usage_id))
|
|
|
|
/* Numeric didn't match page ID */
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
/* Not a valid numeric */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load and cache the page name if and only if
|
|
|
|
* it hasn't already been loaded (it's a
|
|
|
|
* fairly expensive operation).
|
|
|
|
*/
|
|
|
|
if (cache->page_name == NULL) {
|
|
|
|
cache->page_name = hid_usage_page(HID_PAGE(usage_id));
|
|
|
|
cache->page_len = strlen(cache->page_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare specified page name to actual page
|
|
|
|
* name.
|
|
|
|
*/
|
|
|
|
if (cache->page_len !=
|
|
|
|
(size_t)(pagesplit - matchindex) ||
|
|
|
|
memcmp(cache->page_name,
|
|
|
|
&varname[matchindex],
|
|
|
|
cache->page_len) != 0)
|
|
|
|
/* Mismatch, page name wrong */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Page matches, discard page name */
|
|
|
|
matchindex = pagesplit + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
numusage = strtousage(&varname[matchindex], strind - matchindex);
|
|
|
|
|
|
|
|
if (numusage >= 0) {
|
|
|
|
/* Valid numeric */
|
|
|
|
|
|
|
|
if (numusage != HID_USAGE(usage_id))
|
|
|
|
/* Numeric didn't match usage ID */
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
/* Not a valid numeric */
|
|
|
|
|
|
|
|
/* Load and cache the usage name */
|
|
|
|
if (cache->usage_name == NULL) {
|
|
|
|
cache->usage_name = hid_usage_in_page(usage_id);
|
|
|
|
cache->usage_len = strlen(cache->usage_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare specified usage name to actual usage name
|
|
|
|
*/
|
|
|
|
if (cache->usage_len != (size_t)(strind - matchindex) ||
|
|
|
|
memcmp(cache->usage_name, &varname[matchindex],
|
|
|
|
cache->usage_len) != 0)
|
|
|
|
/* Mismatch, usage name wrong */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cache->isfinal)
|
|
|
|
/* Match */
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Partial match: Move index past this usage string +
|
|
|
|
* delimiter
|
|
|
|
*/
|
|
|
|
var->matchindex = strind + 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hidmatch() determines whether the item specified in 'item', and
|
2004-10-30 09:16:13 +04:00
|
|
|
* nested within a hierarchy of collections specified in 'collist'
|
2001-10-23 02:03:49 +04:00
|
|
|
* matches any of the rules in the list 'varlist'. Returns the
|
|
|
|
* matching rule on success, or NULL on no match.
|
|
|
|
*/
|
2000-09-24 06:27:12 +04:00
|
|
|
static struct Susbvar*
|
|
|
|
hidmatch(u_int32_t const *collist, size_t collen, struct hid_item *item,
|
|
|
|
struct Susbvar *varlist, size_t vlsize)
|
1998-07-14 00:56:28 +04:00
|
|
|
{
|
2001-10-23 02:03:49 +04:00
|
|
|
size_t colind, vlactive, vlind;
|
2000-09-24 06:27:12 +04:00
|
|
|
int iscollection;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep track of how many variables are still "active". When
|
|
|
|
* the active count reaches zero, don't bother to continue
|
|
|
|
* looking for matches.
|
|
|
|
*/
|
|
|
|
vlactive = vlsize;
|
|
|
|
|
|
|
|
iscollection = item->kind == hid_collection ||
|
|
|
|
item->kind == hid_endcollection;
|
|
|
|
|
|
|
|
for (vlind = 0; vlind < vlsize; vlind++) {
|
|
|
|
struct Susbvar *var;
|
|
|
|
|
|
|
|
var = &varlist[vlind];
|
|
|
|
|
|
|
|
var->matchindex = 0;
|
|
|
|
|
|
|
|
if (!(var->mflags & MATCH_COLLECTIONS) && iscollection) {
|
|
|
|
/* Don't match collections for this variable */
|
|
|
|
var->matchindex = -1;
|
|
|
|
vlactive--;
|
|
|
|
} else if (!iscollection && !(var->mflags & MATCH_CONSTANTS) &&
|
|
|
|
(item->flags & HIO_CONST)) {
|
|
|
|
/*
|
|
|
|
* Don't match constants for this variable,
|
|
|
|
* but ignore the constant bit on collections.
|
|
|
|
*/
|
|
|
|
var->matchindex = -1;
|
|
|
|
vlactive--;
|
|
|
|
} else if ((var->mflags & MATCH_WRITABLE) &&
|
|
|
|
((item->kind != hid_output &&
|
|
|
|
item->kind != hid_feature) ||
|
|
|
|
(item->flags & HIO_CONST))) {
|
|
|
|
/*
|
|
|
|
* If we are only matching writable items, if
|
|
|
|
* this is not an output or feature kind, or
|
|
|
|
* it is a constant, reject it.
|
|
|
|
*/
|
|
|
|
var->matchindex = -1;
|
|
|
|
vlactive--;
|
|
|
|
} else if (var->mflags & MATCH_ALL) {
|
|
|
|
/* Match immediately */
|
|
|
|
return &varlist[vlind];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
/*
|
|
|
|
* Loop through each usage in the collection list, including
|
|
|
|
* the 'item' itself on the final iteration. For each usage,
|
|
|
|
* test which variables named in the rule list are still
|
|
|
|
* applicable - if any.
|
|
|
|
*/
|
2000-09-24 06:27:12 +04:00
|
|
|
for (colind = 0; vlactive > 0 && colind <= collen; colind++) {
|
2001-10-23 02:03:49 +04:00
|
|
|
struct usagedata cache;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
cache.page_len = 0; /* XXX gcc */
|
|
|
|
cache.usage_len = 0; /* XXX gcc */
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
cache.isfinal = (colind == collen);
|
|
|
|
if (cache.isfinal)
|
|
|
|
cache.usage_id = item->usage;
|
2000-09-24 06:27:12 +04:00
|
|
|
else
|
2001-10-23 02:03:49 +04:00
|
|
|
cache.usage_id = collist[colind];
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
cache.usage_name = NULL;
|
|
|
|
cache.page_name = NULL;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
/*
|
|
|
|
* Loop through each rule, testing whether the rule is
|
|
|
|
* still applicable or not. For each rule,
|
|
|
|
* 'matchindex' retains the current match state as an
|
|
|
|
* index into the variable name string, or -1 if this
|
|
|
|
* rule has been proven not to match.
|
|
|
|
*/
|
2000-09-24 06:27:12 +04:00
|
|
|
for (vlind = 0; vlind < vlsize; vlind++) {
|
|
|
|
struct Susbvar *var;
|
2001-10-23 02:03:49 +04:00
|
|
|
int matchres;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
var = &varlist[vlind];
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
if (var->matchindex < 0)
|
2000-09-24 06:27:12 +04:00
|
|
|
/* Mismatch at a previous level */
|
|
|
|
continue;
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
matchres = hidtestrule(var, &cache);
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
if (matchres < 0) {
|
|
|
|
/* Bad match */
|
2000-09-24 06:27:12 +04:00
|
|
|
var->matchindex = -1;
|
|
|
|
vlactive--;
|
|
|
|
continue;
|
2001-10-23 02:03:49 +04:00
|
|
|
} else if (matchres > 0) {
|
|
|
|
/* Complete match */
|
2000-09-24 06:27:12 +04:00
|
|
|
return var;
|
2001-10-23 02:03:49 +04:00
|
|
|
}
|
2000-09-24 06:27:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
allocreport(struct Sreport *report, report_desc_t rd, int repindex)
|
|
|
|
{
|
|
|
|
int reptsize;
|
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
reptsize = hid_report_size(rd, reptoparam[repindex].hid_kind, reportid);
|
2000-09-24 06:27:12 +04:00
|
|
|
if (reptsize < 0)
|
|
|
|
errx(1, "Negative report size");
|
|
|
|
report->size = reptsize;
|
|
|
|
|
|
|
|
if (report->size > 0) {
|
|
|
|
/*
|
|
|
|
* Allocate a buffer with enough space for the
|
|
|
|
* report in the variable-sized data field.
|
|
|
|
*/
|
|
|
|
report->buffer = malloc(sizeof(*report->buffer) -
|
2002-02-20 23:30:12 +03:00
|
|
|
sizeof(report->buffer->ucr_data) +
|
2000-09-24 06:27:12 +04:00
|
|
|
report->size);
|
|
|
|
if (report->buffer == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
} else
|
|
|
|
report->buffer = NULL;
|
|
|
|
|
|
|
|
report->status = srs_clean;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freereport(struct Sreport *report)
|
|
|
|
{
|
|
|
|
if (report->buffer != NULL)
|
|
|
|
free(report->buffer);
|
|
|
|
report->status = srs_uninit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
getreport(struct Sreport *report, int hidfd, report_desc_t rd, int repindex)
|
|
|
|
{
|
|
|
|
if (report->status == srs_uninit) {
|
|
|
|
allocreport(report, rd, repindex);
|
|
|
|
if (report->size == 0)
|
|
|
|
return;
|
|
|
|
|
2002-02-20 23:30:12 +03:00
|
|
|
report->buffer->ucr_report = reptoparam[repindex].uhid_report;
|
2000-09-24 06:27:12 +04:00
|
|
|
if (ioctl(hidfd, USB_GET_REPORT, report->buffer) < 0)
|
2004-10-31 10:36:19 +03:00
|
|
|
err(1, "USB_GET_REPORT(%s) [probably not supported by "
|
|
|
|
"device]",
|
|
|
|
reptoparam[repindex].name);
|
2000-09-24 06:27:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setreport(struct Sreport *report, int hidfd, int repindex)
|
|
|
|
{
|
|
|
|
if (report->status == srs_dirty) {
|
2002-02-20 23:30:12 +03:00
|
|
|
report->buffer->ucr_report = reptoparam[repindex].uhid_report;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
if (ioctl(hidfd, USB_SET_REPORT, report->buffer) < 0)
|
|
|
|
err(1, "USB_SET_REPORT(%s)",
|
|
|
|
reptoparam[repindex].name);
|
|
|
|
|
|
|
|
report->status = srs_clean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
static int
|
|
|
|
varop_value(struct hid_item *item, struct Susbvar *var,
|
|
|
|
u_int32_t const *collist, size_t collen, u_char *buf)
|
|
|
|
{
|
|
|
|
printf("%d\n", hid_get_data(buf, item));
|
1998-07-14 00:56:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
/* ARGSUSED1 */
|
|
|
|
static int
|
|
|
|
varop_display(struct hid_item *item, struct Susbvar *var,
|
|
|
|
u_int32_t const *collist, size_t collen, u_char *buf)
|
1998-07-13 15:14:03 +04:00
|
|
|
{
|
2000-09-24 06:27:12 +04:00
|
|
|
size_t colitem;
|
2001-12-30 00:23:24 +03:00
|
|
|
int val, i;
|
|
|
|
|
|
|
|
for (i = 0; i < item->report_count; i++) {
|
|
|
|
for (colitem = 0; colitem < collen; colitem++) {
|
|
|
|
if (var->mflags & MATCH_SHOWPAGENAME)
|
|
|
|
printf("%s:",
|
|
|
|
hid_usage_page(HID_PAGE(collist[colitem])));
|
|
|
|
printf("%s.", hid_usage_in_page(collist[colitem]));
|
|
|
|
}
|
2000-09-24 06:27:12 +04:00
|
|
|
if (var->mflags & MATCH_SHOWPAGENAME)
|
2001-12-30 00:23:24 +03:00
|
|
|
printf("%s:", hid_usage_page(HID_PAGE(item->usage)));
|
|
|
|
val = hid_get_data(buf, item);
|
|
|
|
item->pos += item->report_size;
|
|
|
|
if (item->usage_minimum != 0 || item->usage_maximum != 0) {
|
|
|
|
val += item->usage_minimum;
|
|
|
|
printf("%s=1", hid_usage_in_page(val));
|
|
|
|
} else {
|
|
|
|
printf("%s=%d%s", hid_usage_in_page(item->usage),
|
|
|
|
val, item->flags & HIO_CONST ? " (const)" : "");
|
|
|
|
}
|
|
|
|
if (item->report_count > 1)
|
|
|
|
printf(" [%d]", i);
|
|
|
|
printf("\n");
|
2000-09-24 06:27:12 +04:00
|
|
|
}
|
|
|
|
return 0;
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
/* ARGSUSED1 */
|
|
|
|
static int
|
|
|
|
varop_modify(struct hid_item *item, struct Susbvar *var,
|
|
|
|
u_int32_t const *collist, size_t collen, u_char *buf)
|
1998-07-13 15:14:03 +04:00
|
|
|
{
|
2000-09-24 06:27:12 +04:00
|
|
|
u_int dataval;
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
dataval = (u_int)strtol(var->value, NULL, 10);
|
|
|
|
|
|
|
|
hid_set_data(buf, item, dataval);
|
|
|
|
|
2001-10-23 02:03:49 +04:00
|
|
|
if (var->mflags & MATCH_SHOWVALUES)
|
|
|
|
/* Display set value */
|
2000-09-24 06:27:12 +04:00
|
|
|
varop_display(item, var, collist, collen, buf);
|
|
|
|
|
|
|
|
return 1;
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
static void
|
|
|
|
reportitem(char const *label, struct hid_item const *item, unsigned int mflags)
|
1999-04-21 21:41:08 +04:00
|
|
|
{
|
2001-12-28 20:49:31 +03:00
|
|
|
int isconst = item->flags & HIO_CONST,
|
|
|
|
isvar = item->flags & HIO_VARIABLE;
|
|
|
|
printf("%s size=%d count=%d%s%s page=%s", label,
|
2000-09-24 06:27:12 +04:00
|
|
|
item->report_size, item->report_count,
|
2001-12-28 20:49:31 +03:00
|
|
|
isconst ? " Const" : "",
|
|
|
|
!isvar && !isconst ? " Array" : "",
|
|
|
|
hid_usage_page(HID_PAGE(item->usage)));
|
|
|
|
if (item->usage_minimum != 0 || item->usage_maximum != 0) {
|
|
|
|
printf(" usage=%s..%s", hid_usage_in_page(item->usage_minimum),
|
|
|
|
hid_usage_in_page(item->usage_maximum));
|
|
|
|
if (mflags & MATCH_SHOWNUMERIC)
|
|
|
|
printf(" (%u:0x%x..%u:0x%x)",
|
|
|
|
HID_PAGE(item->usage_minimum),
|
|
|
|
HID_USAGE(item->usage_minimum),
|
|
|
|
HID_PAGE(item->usage_maximum),
|
|
|
|
HID_USAGE(item->usage_maximum));
|
|
|
|
} else {
|
|
|
|
printf(" usage=%s", hid_usage_in_page(item->usage));
|
|
|
|
if (mflags & MATCH_SHOWNUMERIC)
|
|
|
|
printf(" (%u:0x%x)",
|
|
|
|
HID_PAGE(item->usage), HID_USAGE(item->usage));
|
|
|
|
}
|
1999-04-21 21:41:08 +04:00
|
|
|
printf(", logical range %d..%d",
|
2000-09-24 06:27:12 +04:00
|
|
|
item->logical_minimum, item->logical_maximum);
|
|
|
|
if (item->physical_minimum != item->physical_maximum)
|
1999-04-21 21:41:08 +04:00
|
|
|
printf(", physical range %d..%d",
|
2000-09-24 06:27:12 +04:00
|
|
|
item->physical_minimum, item->physical_maximum);
|
|
|
|
if (item->unit)
|
|
|
|
printf(", unit=0x%02x exp=%d", item->unit,
|
|
|
|
item->unit_exponent);
|
1999-04-21 21:41:08 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
/* ARGSUSED1 */
|
|
|
|
static int
|
|
|
|
varop_report(struct hid_item *item, struct Susbvar *var,
|
|
|
|
u_int32_t const *collist, size_t collen, u_char *buf)
|
1998-07-13 15:14:03 +04:00
|
|
|
{
|
2000-09-24 06:27:12 +04:00
|
|
|
switch (item->kind) {
|
|
|
|
case hid_collection:
|
2001-10-23 02:03:49 +04:00
|
|
|
printf("Collection page=%s usage=%s",
|
2000-09-24 06:27:12 +04:00
|
|
|
hid_usage_page(HID_PAGE(item->usage)),
|
|
|
|
hid_usage_in_page(item->usage));
|
2001-10-23 02:03:49 +04:00
|
|
|
if (var->mflags & MATCH_SHOWNUMERIC)
|
|
|
|
printf(" (%u:0x%x)\n",
|
|
|
|
HID_PAGE(item->usage), HID_USAGE(item->usage));
|
|
|
|
else
|
|
|
|
printf("\n");
|
2000-09-24 06:27:12 +04:00
|
|
|
break;
|
|
|
|
case hid_endcollection:
|
|
|
|
printf("End collection\n");
|
|
|
|
break;
|
|
|
|
case hid_input:
|
|
|
|
reportitem("Input ", item, var->mflags);
|
|
|
|
break;
|
|
|
|
case hid_output:
|
|
|
|
reportitem("Output ", item, var->mflags);
|
|
|
|
break;
|
|
|
|
case hid_feature:
|
|
|
|
reportitem("Feature", item, var->mflags);
|
|
|
|
break;
|
|
|
|
}
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devloop(int hidfd, report_desc_t rd, struct Susbvar *varlist, size_t vlsize)
|
|
|
|
{
|
2001-10-23 02:03:49 +04:00
|
|
|
u_char *dbuf;
|
2000-09-24 06:27:12 +04:00
|
|
|
struct hid_data *hdata;
|
2001-10-23 02:03:49 +04:00
|
|
|
size_t collind, dlen;
|
2000-09-24 06:27:12 +04:00
|
|
|
struct hid_item hitem;
|
2005-02-10 01:14:13 +03:00
|
|
|
u_int32_t colls[256];
|
2000-09-24 06:27:12 +04:00
|
|
|
struct Sreport inreport;
|
|
|
|
|
|
|
|
allocreport(&inreport, rd, REPORT_INPUT);
|
|
|
|
|
|
|
|
if (inreport.size <= 0)
|
|
|
|
errx(1, "Input report descriptor invalid length");
|
|
|
|
|
|
|
|
dlen = inreport.size;
|
2002-02-20 23:30:12 +03:00
|
|
|
dbuf = inreport.buffer->ucr_data;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ssize_t readlen;
|
|
|
|
|
|
|
|
readlen = read(hidfd, dbuf, dlen);
|
2001-12-22 15:34:41 +03:00
|
|
|
if (readlen < 0)
|
|
|
|
err(1, "Device read error");
|
|
|
|
if (dlen != (size_t)readlen)
|
|
|
|
errx(1, "Unexpected response length: %lu != %lu",
|
|
|
|
(unsigned long)readlen, (unsigned long)dlen);
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
collind = 0;
|
2001-12-28 20:49:31 +03:00
|
|
|
hdata = hid_start_parse(rd, 1 << hid_input, reportid);
|
2000-09-24 06:27:12 +04:00
|
|
|
if (hdata == NULL)
|
|
|
|
errx(1, "Failed to start parser");
|
|
|
|
|
|
|
|
while (hid_get_item(hdata, &hitem)) {
|
|
|
|
struct Susbvar *matchvar;
|
|
|
|
|
|
|
|
switch (hitem.kind) {
|
|
|
|
case hid_collection:
|
|
|
|
if (collind >= (sizeof(colls) / sizeof(*colls)))
|
|
|
|
errx(1, "Excessive nested collections");
|
|
|
|
colls[collind++] = hitem.usage;
|
|
|
|
break;
|
|
|
|
case hid_endcollection:
|
|
|
|
if (collind == 0)
|
|
|
|
errx(1, "Excessive collection ends");
|
|
|
|
collind--;
|
|
|
|
break;
|
|
|
|
case hid_input:
|
|
|
|
break;
|
|
|
|
case hid_output:
|
|
|
|
case hid_feature:
|
|
|
|
errx(1, "Unexpected non-input item returned");
|
|
|
|
}
|
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
if (reportid != -1 && hitem.report_ID != reportid)
|
|
|
|
continue;
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
matchvar = hidmatch(colls, collind, &hitem,
|
|
|
|
varlist, vlsize);
|
|
|
|
|
|
|
|
if (matchvar != NULL)
|
|
|
|
matchvar->opfunc(&hitem, matchvar,
|
|
|
|
colls, collind,
|
2002-02-20 23:30:12 +03:00
|
|
|
inreport.buffer->ucr_data);
|
2000-09-24 06:27:12 +04:00
|
|
|
}
|
|
|
|
hid_end_parse(hdata);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devshow(int hidfd, report_desc_t rd, struct Susbvar *varlist, size_t vlsize,
|
|
|
|
int kindset)
|
|
|
|
{
|
|
|
|
struct hid_data *hdata;
|
2001-10-23 02:03:49 +04:00
|
|
|
size_t collind, repind, vlind;
|
2000-09-24 06:27:12 +04:00
|
|
|
struct hid_item hitem;
|
2005-02-10 01:14:13 +03:00
|
|
|
u_int32_t colls[256];
|
2000-09-24 06:27:12 +04:00
|
|
|
struct Sreport reports[REPORT_MAXVAL + 1];
|
|
|
|
|
|
|
|
|
|
|
|
for (repind = 0; repind < (sizeof(reports) / sizeof(*reports));
|
|
|
|
repind++) {
|
|
|
|
reports[repind].status = srs_uninit;
|
|
|
|
reports[repind].buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
collind = 0;
|
2001-12-28 20:49:31 +03:00
|
|
|
hdata = hid_start_parse(rd, kindset, reportid);
|
2000-09-24 06:27:12 +04:00
|
|
|
if (hdata == NULL)
|
|
|
|
errx(1, "Failed to start parser");
|
|
|
|
|
|
|
|
while (hid_get_item(hdata, &hitem)) {
|
|
|
|
struct Susbvar *matchvar;
|
|
|
|
int repindex;
|
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
if (verbose > 3)
|
|
|
|
printf("item: kind=%d repid=%d usage=0x%x\n",
|
|
|
|
hitem.kind, hitem.report_ID, hitem.usage);
|
2000-09-24 06:27:12 +04:00
|
|
|
repindex = -1;
|
|
|
|
switch (hitem.kind) {
|
1998-07-13 15:14:03 +04:00
|
|
|
case hid_collection:
|
2000-09-24 06:27:12 +04:00
|
|
|
if (collind >= (sizeof(colls) / sizeof(*colls)))
|
|
|
|
errx(1, "Excessive nested collections");
|
|
|
|
colls[collind++] = hitem.usage;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case hid_endcollection:
|
2000-09-24 06:27:12 +04:00
|
|
|
if (collind == 0)
|
|
|
|
errx(1, "Excessive collection ends");
|
|
|
|
collind--;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case hid_input:
|
2000-09-24 06:27:12 +04:00
|
|
|
repindex = REPORT_INPUT;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case hid_output:
|
2000-09-24 06:27:12 +04:00
|
|
|
repindex = REPORT_OUTPUT;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case hid_feature:
|
2000-09-24 06:27:12 +04:00
|
|
|
repindex = REPORT_FEATURE;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
}
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
if (reportid != -1 && hitem.report_ID != reportid)
|
|
|
|
continue;
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
matchvar = hidmatch(colls, collind, &hitem, varlist, vlsize);
|
|
|
|
|
|
|
|
if (matchvar != NULL) {
|
|
|
|
u_char *bufdata;
|
|
|
|
struct Sreport *repptr;
|
|
|
|
|
|
|
|
matchvar->mflags |= MATCH_WASMATCHED;
|
|
|
|
|
|
|
|
if (repindex >= 0)
|
|
|
|
repptr = &reports[repindex];
|
|
|
|
else
|
|
|
|
repptr = NULL;
|
|
|
|
|
|
|
|
if (repptr != NULL &&
|
|
|
|
!(matchvar->mflags & MATCH_NODATA))
|
|
|
|
getreport(repptr, hidfd, rd, repindex);
|
|
|
|
|
|
|
|
bufdata = (repptr == NULL || repptr->buffer == NULL) ?
|
2002-02-20 23:30:12 +03:00
|
|
|
NULL : repptr->buffer->ucr_data;
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
if (matchvar->opfunc(&hitem, matchvar, colls, collind,
|
2006-05-01 09:04:02 +04:00
|
|
|
bufdata) && repptr)
|
2000-09-24 06:27:12 +04:00
|
|
|
repptr->status = srs_dirty;
|
|
|
|
}
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
2000-09-24 06:27:12 +04:00
|
|
|
hid_end_parse(hdata);
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
for (repind = 0; repind < (sizeof(reports) / sizeof(*reports));
|
|
|
|
repind++) {
|
|
|
|
setreport(&reports[repind], hidfd, repind);
|
|
|
|
freereport(&reports[repind]);
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
/* Warn about any items that we couldn't find a match for */
|
|
|
|
for (vlind = 0; vlind < vlsize; vlind++) {
|
|
|
|
struct Susbvar *var;
|
|
|
|
|
|
|
|
var = &varlist[vlind];
|
|
|
|
|
|
|
|
if (var->variable != NULL &&
|
|
|
|
!(var->mflags & MATCH_WASMATCHED))
|
|
|
|
warnx("Failed to match: %.*s", (int)var->varlen,
|
|
|
|
var->variable);
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
static void
|
|
|
|
usage(void)
|
1998-07-13 15:14:03 +04:00
|
|
|
{
|
2001-02-20 02:03:42 +03:00
|
|
|
const char *progname = getprogname();
|
2000-09-24 06:27:12 +04:00
|
|
|
|
2004-01-06 02:23:32 +03:00
|
|
|
fprintf(stderr, "usage: %s -f device [-t tablefile] [-l] [-v] -a\n",
|
2001-03-28 07:17:41 +04:00
|
|
|
progname);
|
|
|
|
fprintf(stderr, " %s -f device [-t tablefile] [-v] -r\n",
|
|
|
|
progname);
|
|
|
|
fprintf(stderr,
|
|
|
|
" %s -f device [-t tablefile] [-l] [-n] [-v] name ...\n",
|
|
|
|
progname);
|
|
|
|
fprintf(stderr,
|
|
|
|
" %s -f device [-t tablefile] -w name=value ...\n",
|
|
|
|
progname);
|
2000-09-24 06:27:12 +04:00
|
|
|
exit(1);
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2000-09-24 06:27:12 +04:00
|
|
|
char const *dev;
|
|
|
|
char const *table;
|
2001-10-23 02:03:49 +04:00
|
|
|
size_t varnum;
|
|
|
|
int aflag, lflag, nflag, rflag, wflag;
|
|
|
|
int ch, hidfd;
|
|
|
|
report_desc_t repdesc;
|
|
|
|
char devnamebuf[PATH_MAX];
|
2000-09-24 06:27:12 +04:00
|
|
|
struct Susbvar variables[128];
|
|
|
|
|
|
|
|
wflag = aflag = nflag = verbose = rflag = lflag = 0;
|
|
|
|
dev = NULL;
|
|
|
|
table = NULL;
|
|
|
|
while ((ch = getopt(argc, argv, "?af:lnrt:vw")) != -1) {
|
|
|
|
switch (ch) {
|
1998-07-14 00:56:28 +04:00
|
|
|
case 'a':
|
2000-09-24 06:27:12 +04:00
|
|
|
aflag = 1;
|
1998-07-14 00:56:28 +04:00
|
|
|
break;
|
1998-07-13 15:14:03 +04:00
|
|
|
case 'f':
|
|
|
|
dev = optarg;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2000-09-24 06:27:12 +04:00
|
|
|
lflag = 1;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case 'n':
|
2000-09-24 06:27:12 +04:00
|
|
|
nflag = 1;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case 'r':
|
2000-09-24 06:27:12 +04:00
|
|
|
rflag = 1;
|
1998-07-13 15:14:03 +04:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
table = optarg;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
2000-09-24 06:27:12 +04:00
|
|
|
case 'w':
|
|
|
|
wflag = 1;
|
|
|
|
break;
|
1998-07-13 15:14:03 +04:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
2000-09-24 06:27:12 +04:00
|
|
|
/* NOTREACHED */
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2000-09-24 06:27:12 +04:00
|
|
|
if (dev == NULL || (lflag && (wflag || rflag))) {
|
|
|
|
/*
|
|
|
|
* No device specified, or attempting to loop and set
|
|
|
|
* or dump report at the same time
|
|
|
|
*/
|
1998-07-13 15:14:03 +04:00
|
|
|
usage();
|
2000-09-24 06:27:12 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
for (varnum = 0; varnum < (size_t)argc; varnum++) {
|
|
|
|
char const *name, *valuesep;
|
|
|
|
struct Susbvar *svar;
|
1998-12-03 23:46:10 +03:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
svar = &variables[varnum];
|
|
|
|
name = argv[varnum];
|
|
|
|
valuesep = strchr(name, DELIM_SET);
|
|
|
|
|
|
|
|
svar->variable = name;
|
|
|
|
svar->mflags = 0;
|
|
|
|
|
|
|
|
if (valuesep == NULL) {
|
|
|
|
/* Read variable */
|
|
|
|
if (wflag)
|
|
|
|
errx(1, "Must not specify -w to read variables");
|
|
|
|
svar->value = NULL;
|
|
|
|
svar->varlen = strlen(name);
|
|
|
|
|
|
|
|
if (nflag) {
|
|
|
|
/* Display value of variable only */
|
|
|
|
svar->opfunc = varop_value;
|
|
|
|
} else {
|
|
|
|
/* Display name and value of variable */
|
|
|
|
svar->opfunc = varop_display;
|
|
|
|
|
|
|
|
if (verbose >= 1)
|
|
|
|
/* Show page names in verbose modes */
|
|
|
|
svar->mflags |= MATCH_SHOWPAGENAME;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Write variable */
|
|
|
|
if (!wflag)
|
|
|
|
errx(2, "Must specify -w to set variables");
|
|
|
|
svar->mflags |= MATCH_WRITABLE;
|
2001-10-23 02:03:49 +04:00
|
|
|
if (verbose >= 1)
|
|
|
|
/*
|
|
|
|
* Allow displaying of set value in
|
|
|
|
* verbose mode. This isn't
|
|
|
|
* particularly useful though, so
|
|
|
|
* don't bother documenting it.
|
|
|
|
*/
|
|
|
|
svar->mflags |= MATCH_SHOWVALUES;
|
2000-09-24 06:27:12 +04:00
|
|
|
svar->varlen = valuesep - name;
|
|
|
|
svar->value = valuesep + 1;
|
|
|
|
svar->opfunc = varop_modify;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aflag || rflag) {
|
|
|
|
struct Susbvar *svar;
|
|
|
|
|
|
|
|
svar = &variables[varnum++];
|
|
|
|
|
|
|
|
svar->variable = NULL;
|
|
|
|
svar->mflags = MATCH_ALL;
|
|
|
|
|
|
|
|
if (rflag) {
|
|
|
|
/*
|
|
|
|
* Dump report descriptor. Do dump collection
|
|
|
|
* items also, and hint that it won't be
|
|
|
|
* necessary to get the item status.
|
|
|
|
*/
|
|
|
|
svar->opfunc = varop_report;
|
|
|
|
svar->mflags |= MATCH_COLLECTIONS | MATCH_NODATA;
|
|
|
|
|
|
|
|
switch (verbose) {
|
|
|
|
default:
|
|
|
|
/* Level 2: Show item numerics and constants */
|
|
|
|
svar->mflags |= MATCH_SHOWNUMERIC;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 1:
|
|
|
|
/* Level 1: Just show constants */
|
|
|
|
svar->mflags |= MATCH_CONSTANTS;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Display name and value of variable */
|
|
|
|
svar->opfunc = varop_display;
|
|
|
|
|
|
|
|
switch (verbose) {
|
|
|
|
default:
|
|
|
|
/* Level 2: Show constants and page names */
|
|
|
|
svar->mflags |= MATCH_CONSTANTS;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 1:
|
|
|
|
/* Level 1: Just show page names */
|
|
|
|
svar->mflags |= MATCH_SHOWPAGENAME;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (varnum == 0) {
|
|
|
|
/* Nothing to do... Display usage information. */
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
1998-07-23 17:48:59 +04:00
|
|
|
}
|
|
|
|
|
1999-05-12 04:38:20 +04:00
|
|
|
hid_init(table);
|
1998-07-13 15:14:03 +04:00
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
if (dev[0] != '/') {
|
|
|
|
snprintf(devnamebuf, sizeof(devnamebuf), "/dev/%s%s",
|
2004-11-06 00:56:01 +03:00
|
|
|
isdigit((unsigned char)dev[0]) ? "uhid" : "", dev);
|
2000-09-24 06:27:12 +04:00
|
|
|
dev = devnamebuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
hidfd = open(dev, O_RDWR);
|
|
|
|
if (hidfd < 0)
|
1998-07-13 15:14:03 +04:00
|
|
|
err(1, "%s", dev);
|
|
|
|
|
2001-12-28 20:49:31 +03:00
|
|
|
if (ioctl(hidfd, USB_GET_REPORT_ID, &reportid) < 0)
|
|
|
|
reportid = -1;
|
|
|
|
if (verbose > 1)
|
|
|
|
printf("report ID=%d\n", reportid);
|
2000-09-24 06:27:12 +04:00
|
|
|
repdesc = hid_get_report_desc(hidfd);
|
|
|
|
if (repdesc == 0)
|
1998-07-13 15:14:03 +04:00
|
|
|
errx(1, "USB_GET_REPORT_DESC");
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
if (lflag) {
|
|
|
|
devloop(hidfd, repdesc, variables, varnum);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rflag)
|
|
|
|
/* Report mode header */
|
1999-05-12 01:02:24 +04:00
|
|
|
printf("Report descriptor:\n");
|
2000-09-24 06:27:12 +04:00
|
|
|
|
|
|
|
devshow(hidfd, repdesc, variables, varnum,
|
|
|
|
1 << hid_input |
|
|
|
|
1 << hid_output |
|
|
|
|
1 << hid_feature);
|
|
|
|
|
|
|
|
if (rflag) {
|
|
|
|
/* Report mode trailer */
|
|
|
|
size_t repindex;
|
|
|
|
for (repindex = 0;
|
|
|
|
repindex < (sizeof(reptoparam) / sizeof(*reptoparam));
|
|
|
|
repindex++) {
|
2001-12-28 20:49:31 +03:00
|
|
|
int size;
|
2000-09-24 06:27:12 +04:00
|
|
|
size = hid_report_size(repdesc,
|
|
|
|
reptoparam[repindex].hid_kind,
|
2001-12-28 20:49:31 +03:00
|
|
|
reportid);
|
|
|
|
printf("Total %7s size %d bytes\n",
|
|
|
|
reptoparam[repindex].name, size);
|
2000-09-24 06:27:12 +04:00
|
|
|
}
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|
|
|
|
|
2000-09-24 06:27:12 +04:00
|
|
|
hid_dispose_report_desc(repdesc);
|
1998-07-13 15:14:03 +04:00
|
|
|
exit(0);
|
2000-09-24 06:27:12 +04:00
|
|
|
/* NOTREACHED */
|
1998-07-13 15:14:03 +04:00
|
|
|
}
|