mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-19 15:33:56 +00:00
Sync with NetBSD.
- Bump shared library version on libusbhid. - Retire libusbhid.h; it is called usbhid.h now. - hid_start_parse() takes a third argument. - hid_locate() takes a fifth argument. - hid_report_size() order of arguments changes. - Other changes, including formatting and whitespace. Bump __FreeBSD_version. This change will break all third party applications that rely on previous FreeBSD specific behavior.
This commit is contained in:
parent
06283c3ba9
commit
cf0e07e504
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=113273
@ -6,7 +6,7 @@ MAINTAINER= n_hibma@FreeBSD.ORG
|
|||||||
LIB= usbhid
|
LIB= usbhid
|
||||||
MAN= usbhid.3
|
MAN= usbhid.3
|
||||||
|
|
||||||
SHLIB_MAJOR= 0
|
SHLIB_MAJOR= 1
|
||||||
|
|
||||||
MLINKS= usbhid.3 libusbhid.3 usbhid.3 hid_get_report_desc.3 \
|
MLINKS= usbhid.3 libusbhid.3 usbhid.3 hid_get_report_desc.3 \
|
||||||
usbhid.3 hid_dispose_report_desc.3 \
|
usbhid.3 hid_dispose_report_desc.3 \
|
||||||
@ -19,7 +19,6 @@ MLINKS= usbhid.3 libusbhid.3 usbhid.3 hid_get_report_desc.3 \
|
|||||||
|
|
||||||
SRCS= descr.c parse.c usage.c data.c
|
SRCS= descr.c parse.c usage.c data.c
|
||||||
|
|
||||||
INCS= libusbhid.h
|
INCS= usbhid.h
|
||||||
|
|
||||||
.include <bsd.lib.mk>
|
.include <bsd.lib.mk>
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "libusbhid.h"
|
#include "usbhid.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
hid_get_data(const void *p, const hid_item_t *h)
|
hid_get_data(const void *p, const hid_item_t *h)
|
||||||
|
@ -37,13 +37,11 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#if defined(__FreeBSD__)
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <dev/usb/usb.h>
|
#include <dev/usb/usb.h>
|
||||||
|
|
||||||
#include "libusbhid.h"
|
#include "usbhid.h"
|
||||||
#include "usbvar.h"
|
#include "usbvar.h"
|
||||||
|
|
||||||
report_desc_t
|
report_desc_t
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
/* $NetBSD: usb.h,v 1.8 2000/08/13 22:22:02 augustss Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
||||||
*
|
|
||||||
* $FreeBSD$
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
typedef struct report_desc *report_desc_t;
|
|
||||||
|
|
||||||
typedef struct hid_data *hid_data_t;
|
|
||||||
|
|
||||||
typedef enum hid_kind {
|
|
||||||
hid_input = 0,
|
|
||||||
hid_output = 1,
|
|
||||||
hid_feature = 2,
|
|
||||||
hid_collection,
|
|
||||||
hid_endcollection
|
|
||||||
} hid_kind_t;
|
|
||||||
|
|
||||||
typedef struct hid_item {
|
|
||||||
/* Global */
|
|
||||||
int _usage_page;
|
|
||||||
int logical_minimum;
|
|
||||||
int logical_maximum;
|
|
||||||
int physical_minimum;
|
|
||||||
int physical_maximum;
|
|
||||||
int unit_exponent;
|
|
||||||
int unit;
|
|
||||||
int report_size;
|
|
||||||
int report_ID;
|
|
||||||
#define NO_REPORT_ID 0
|
|
||||||
int report_count;
|
|
||||||
/* Local */
|
|
||||||
unsigned int usage;
|
|
||||||
int usage_minimum;
|
|
||||||
int usage_maximum;
|
|
||||||
int designator_index;
|
|
||||||
int designator_minimum;
|
|
||||||
int designator_maximum;
|
|
||||||
int string_index;
|
|
||||||
int string_minimum;
|
|
||||||
int string_maximum;
|
|
||||||
int set_delimiter;
|
|
||||||
/* Misc */
|
|
||||||
int collection;
|
|
||||||
int collevel;
|
|
||||||
enum hid_kind kind;
|
|
||||||
unsigned int flags;
|
|
||||||
/* Absolute data position (bits) */
|
|
||||||
unsigned int pos;
|
|
||||||
/* */
|
|
||||||
struct hid_item *next;
|
|
||||||
} hid_item_t;
|
|
||||||
|
|
||||||
#define HID_PAGE(u) (((u) >> 16) & 0xffff)
|
|
||||||
#define HID_USAGE(u) ((u) & 0xffff)
|
|
||||||
|
|
||||||
/* Obtaining a report descriptor, descr.c: */
|
|
||||||
report_desc_t hid_get_report_desc(int file);
|
|
||||||
report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size);
|
|
||||||
void hid_dispose_report_desc(report_desc_t);
|
|
||||||
|
|
||||||
/* Parsing of a HID report descriptor, parse.c: */
|
|
||||||
hid_data_t hid_start_parse(report_desc_t d, int kindset);
|
|
||||||
void hid_end_parse(hid_data_t s);
|
|
||||||
int hid_get_item(hid_data_t s, hid_item_t *h);
|
|
||||||
int hid_report_size(report_desc_t d, unsigned int id, enum hid_kind k);
|
|
||||||
int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h);
|
|
||||||
|
|
||||||
/* Conversion to/from usage names, usage.c: */
|
|
||||||
const char *hid_usage_page(int i);
|
|
||||||
const char *hid_usage_in_page(unsigned int u);
|
|
||||||
void hid_init(const char *file);
|
|
||||||
int hid_parse_usage_in_page(const char *name);
|
|
||||||
int hid_parse_usage_page(const char *name);
|
|
||||||
|
|
||||||
/* Extracting/insertion of data, data.c: */
|
|
||||||
int hid_get_data(const void *p, const hid_item_t *h);
|
|
||||||
void hid_set_data(void *p, const hid_item_t *h, int data);
|
|
@ -1,7 +1,7 @@
|
|||||||
/* $NetBSD: parse.c,v 1.11 2000/09/24 02:19:54 augustss Exp $ */
|
/* $NetBSD: parse.c,v 1.11 2000/09/24 02:19:54 augustss Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
|
* Copyright (c) 1999, 2001 Lennart Augustsson <augustss@netbsd.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <dev/usb/usb.h>
|
#include <dev/usb/usb.h>
|
||||||
#include <dev/usb/usbhid.h>
|
#include <dev/usb/usbhid.h>
|
||||||
|
|
||||||
#include "libusbhid.h"
|
#include "usbhid.h"
|
||||||
#include "usbvar.h"
|
#include "usbvar.h"
|
||||||
|
|
||||||
#define MAXUSAGE 100
|
#define MAXUSAGE 100
|
||||||
@ -49,18 +49,30 @@ struct hid_data {
|
|||||||
unsigned int usages[MAXUSAGE];
|
unsigned int usages[MAXUSAGE];
|
||||||
int nusage;
|
int nusage;
|
||||||
int minset;
|
int minset;
|
||||||
|
int logminsize;
|
||||||
int multi;
|
int multi;
|
||||||
int multimax;
|
int multimax;
|
||||||
int kindset;
|
int kindset;
|
||||||
|
int reportid;
|
||||||
|
|
||||||
/* Absolute data position (bits) for input/output/feature.
|
/*
|
||||||
Assumes that hid_input, hid_output and hid_feature have
|
* The start of collection item has no report ID set, so save
|
||||||
values 0, 1 and 2. */
|
* it until we know the ID.
|
||||||
unsigned int kindpos[3];
|
*/
|
||||||
|
hid_item_t savedcoll;
|
||||||
|
u_char hassavedcoll;
|
||||||
|
/*
|
||||||
|
* Absolute data position (bits) for input/output/feature.
|
||||||
|
* Assumes that hid_input, hid_output and hid_feature have
|
||||||
|
* values 0, 1 and 2.
|
||||||
|
*/
|
||||||
|
unsigned int kindpos[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int min(int x, int y) { return x < y ? x : y; }
|
static int min(int x, int y) { return x < y ? x : y; }
|
||||||
|
|
||||||
|
static int hid_get_item_raw(hid_data_t s, hid_item_t *h);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hid_clear_local(hid_item_t *c)
|
hid_clear_local(hid_item_t *c)
|
||||||
{
|
{
|
||||||
@ -78,7 +90,7 @@ hid_clear_local(hid_item_t *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hid_data_t
|
hid_data_t
|
||||||
hid_start_parse(report_desc_t d, int kindset)
|
hid_start_parse(report_desc_t d, int kindset, int id)
|
||||||
{
|
{
|
||||||
struct hid_data *s;
|
struct hid_data *s;
|
||||||
|
|
||||||
@ -87,6 +99,8 @@ hid_start_parse(report_desc_t d, int kindset)
|
|||||||
s->start = s->p = d->data;
|
s->start = s->p = d->data;
|
||||||
s->end = d->data + d->size;
|
s->end = d->data + d->size;
|
||||||
s->kindset = kindset;
|
s->kindset = kindset;
|
||||||
|
s->reportid = id;
|
||||||
|
s->hassavedcoll = 0;
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +117,31 @@ hid_end_parse(hid_data_t s)
|
|||||||
|
|
||||||
int
|
int
|
||||||
hid_get_item(hid_data_t s, hid_item_t *h)
|
hid_get_item(hid_data_t s, hid_item_t *h)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
r = hid_get_item_raw(s, h);
|
||||||
|
if (r <= 0)
|
||||||
|
break;
|
||||||
|
if (h->report_ID == s->reportid || s->reportid == -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define REPORT_SAVED_COLL \
|
||||||
|
do { \
|
||||||
|
if (s->hassavedcoll) { \
|
||||||
|
*h = s->savedcoll; \
|
||||||
|
h->report_ID = c->report_ID; \
|
||||||
|
s->hassavedcoll = 0; \
|
||||||
|
return (1); \
|
||||||
|
} \
|
||||||
|
} while(/*LINTED*/ 0)
|
||||||
|
|
||||||
|
static int
|
||||||
|
hid_get_item_raw(hid_data_t s, hid_item_t *h)
|
||||||
{
|
{
|
||||||
hid_item_t *c;
|
hid_item_t *c;
|
||||||
unsigned int bTag = 0, bType = 0, bSize;
|
unsigned int bTag = 0, bType = 0, bSize;
|
||||||
@ -110,6 +149,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
int dval;
|
int dval;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
hid_item_t *hi;
|
hid_item_t *hi;
|
||||||
|
hid_item_t nc;
|
||||||
int i;
|
int i;
|
||||||
hid_kind_t retkind;
|
hid_kind_t retkind;
|
||||||
|
|
||||||
@ -117,13 +157,21 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
|
|
||||||
top:
|
top:
|
||||||
if (s->multimax) {
|
if (s->multimax) {
|
||||||
|
REPORT_SAVED_COLL;
|
||||||
|
if (c->logical_minimum >= c->logical_maximum) {
|
||||||
|
if (s->logminsize == 1)
|
||||||
|
c->logical_minimum =(int8_t)c->logical_minimum;
|
||||||
|
else if (s->logminsize == 2)
|
||||||
|
c->logical_minimum =(int16_t)c->logical_minimum;
|
||||||
|
}
|
||||||
if (s->multi < s->multimax) {
|
if (s->multi < s->multimax) {
|
||||||
c->usage = s->usages[min(s->multi, s->nusage-1)];
|
c->usage = s->usages[min(s->multi, s->nusage-1)];
|
||||||
s->multi++;
|
s->multi++;
|
||||||
*h = *c;
|
*h = *c;
|
||||||
|
/*
|
||||||
/* 'multimax' is only non-zero if the current
|
* 'multimax' is only non-zero if the current
|
||||||
item kind is input/output/feature */
|
* item kind is input/output/feature
|
||||||
|
*/
|
||||||
h->pos = s->kindpos[c->kind];
|
h->pos = s->kindpos[c->kind];
|
||||||
s->kindpos[c->kind] += c->report_size;
|
s->kindpos[c->kind] += c->report_size;
|
||||||
h->next = 0;
|
h->next = 0;
|
||||||
@ -208,6 +256,8 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
if (s->nusage < MAXUSAGE-1)
|
if (s->nusage < MAXUSAGE-1)
|
||||||
s->nusage++;
|
s->nusage++;
|
||||||
}
|
}
|
||||||
|
c->usage_minimum = 0;
|
||||||
|
c->usage_maximum = 0;
|
||||||
s->minset = 0;
|
s->minset = 0;
|
||||||
}
|
}
|
||||||
goto top;
|
goto top;
|
||||||
@ -217,7 +267,8 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
*h = *c;
|
*h = *c;
|
||||||
h->next = 0;
|
h->next = 0;
|
||||||
h->pos = s->kindpos[c->kind];
|
h->pos = s->kindpos[c->kind];
|
||||||
s->kindpos[c->kind] += c->report_size * c->report_count;
|
s->kindpos[c->kind] +=
|
||||||
|
c->report_size * c->report_count;
|
||||||
hid_clear_local(c);
|
hid_clear_local(c);
|
||||||
s->minset = 0;
|
s->minset = 0;
|
||||||
return (1);
|
return (1);
|
||||||
@ -229,15 +280,25 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
c->kind = hid_collection;
|
c->kind = hid_collection;
|
||||||
c->collection = dval;
|
c->collection = dval;
|
||||||
c->collevel++;
|
c->collevel++;
|
||||||
*h = *c;
|
nc = *c;
|
||||||
hid_clear_local(c);
|
hid_clear_local(c);
|
||||||
c->report_ID = NO_REPORT_ID;
|
/*c->report_ID = NO_REPORT_ID;*/
|
||||||
s->nusage = 0;
|
s->nusage = 0;
|
||||||
return (1);
|
if (s->hassavedcoll) {
|
||||||
|
*h = s->savedcoll;
|
||||||
|
h->report_ID = nc.report_ID;
|
||||||
|
s->savedcoll = nc;
|
||||||
|
return (1);
|
||||||
|
} else {
|
||||||
|
s->hassavedcoll = 1;
|
||||||
|
s->savedcoll = nc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 11: /* Feature */
|
case 11: /* Feature */
|
||||||
retkind = hid_feature;
|
retkind = hid_feature;
|
||||||
goto ret;
|
goto ret;
|
||||||
case 12: /* End collection */
|
case 12: /* End collection */
|
||||||
|
REPORT_SAVED_COLL;
|
||||||
c->kind = hid_endcollection;
|
c->kind = hid_endcollection;
|
||||||
c->collevel--;
|
c->collevel--;
|
||||||
*h = *c;
|
*h = *c;
|
||||||
@ -247,6 +308,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
default:
|
default:
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 1: /* Global */
|
case 1: /* Global */
|
||||||
switch (bTag) {
|
switch (bTag) {
|
||||||
@ -255,6 +317,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
c->logical_minimum = dval;
|
c->logical_minimum = dval;
|
||||||
|
s->logminsize = bSize;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
c->logical_maximum = dval;
|
c->logical_maximum = dval;
|
||||||
@ -276,6 +339,9 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
c->report_ID = dval;
|
c->report_ID = dval;
|
||||||
|
s->kindpos[hid_input] =
|
||||||
|
s->kindpos[hid_output] =
|
||||||
|
s->kindpos[hid_feature] = 0;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
c->report_count = dval;
|
c->report_count = dval;
|
||||||
@ -297,29 +363,17 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
case 2: /* Local */
|
case 2: /* Local */
|
||||||
switch (bTag) {
|
switch (bTag) {
|
||||||
case 0:
|
case 0:
|
||||||
if (bSize == 1)
|
c->usage = c->_usage_page | dval;
|
||||||
dval = c->_usage_page | (dval&0xff);
|
|
||||||
else if (bSize == 2)
|
|
||||||
dval = c->_usage_page | (dval&0xffff);
|
|
||||||
c->usage = dval;
|
|
||||||
if (s->nusage < MAXUSAGE)
|
if (s->nusage < MAXUSAGE)
|
||||||
s->usages[s->nusage++] = dval;
|
s->usages[s->nusage++] = c->usage;
|
||||||
/* else XXX */
|
/* else XXX */
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
s->minset = 1;
|
s->minset = 1;
|
||||||
if (bSize == 1)
|
c->usage_minimum = c->_usage_page | dval;
|
||||||
dval = c->_usage_page | (dval&0xff);
|
|
||||||
else if (bSize == 2)
|
|
||||||
dval = c->_usage_page | (dval&0xffff);
|
|
||||||
c->usage_minimum = dval;
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (bSize == 1)
|
c->usage_maximum = c->_usage_page | dval;
|
||||||
dval = c->_usage_page | (dval&0xff);
|
|
||||||
else if (bSize == 2)
|
|
||||||
dval = c->_usage_page | (dval&0xffff);
|
|
||||||
c->usage_maximum = dval;
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
c->designator_index = dval;
|
c->designator_index = dval;
|
||||||
@ -353,35 +407,30 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
hid_report_size(report_desc_t r, unsigned int id, enum hid_kind k)
|
hid_report_size(report_desc_t r, enum hid_kind k, int id)
|
||||||
{
|
{
|
||||||
struct hid_data *d;
|
struct hid_data *d;
|
||||||
hid_item_t h;
|
hid_item_t h;
|
||||||
unsigned int size = 0;
|
int size;
|
||||||
|
|
||||||
memset(&h, 0, sizeof h);
|
memset(&h, 0, sizeof h);
|
||||||
d = hid_start_parse(r, 1<<k);
|
size = 0;
|
||||||
while (hid_get_item(d, &h)) {
|
for (d = hid_start_parse(r, 1<<k, id); hid_get_item(d, &h); ) {
|
||||||
if (h.report_ID == id && h.kind == k) {
|
if (h.report_ID == id && h.kind == k) {
|
||||||
unsigned int newsize = h.pos + h.report_size;
|
size = d->kindpos[k];
|
||||||
if (newsize > size)
|
|
||||||
size = newsize;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hid_end_parse(d);
|
hid_end_parse(d);
|
||||||
|
return ((size + 7) / 8);
|
||||||
if (id != NO_REPORT_ID)
|
|
||||||
size += 8; /* add 8 bits for the report ID */
|
|
||||||
|
|
||||||
return ((size + 7) / 8); /* return size in bytes */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
hid_locate(report_desc_t desc, unsigned int u, enum hid_kind k, hid_item_t *h)
|
hid_locate(report_desc_t desc, unsigned int u, enum hid_kind k,
|
||||||
|
hid_item_t *h, int id)
|
||||||
{
|
{
|
||||||
hid_data_t d;
|
hid_data_t d;
|
||||||
|
|
||||||
for (d = hid_start_parse(desc, 1<<k); hid_get_item(d, h); ) {
|
for (d = hid_start_parse(desc, 1<<k, id); hid_get_item(d, h); ) {
|
||||||
if (h->kind == k && !(h->flags & HIO_CONST) && h->usage == u) {
|
if (h->kind == k && !(h->flags & HIO_CONST) && h->usage == u) {
|
||||||
hid_end_parse(d);
|
hid_end_parse(d);
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "libusbhid.h"
|
#include "usbhid.h"
|
||||||
|
|
||||||
#define _PATH_HIDTABLE "/usr/share/misc/usb_hid_usages"
|
#define _PATH_HIDTABLE "/usr/share/misc/usb_hid_usages"
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.\" $NetBSD: usb.3,v 1.13 2000/09/24 02:17:52 augustss Exp $
|
.\" $NetBSD: usb.3,v 1.13 2000/09/24 02:17:52 augustss Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
|
.\" Copyright (c) 1999, 2001 Lennart Augustsson <augustss@NetBSD.org>
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
@ -26,7 +26,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd May 11, 1999
|
.Dd December 29, 2001
|
||||||
.Dt USBHID 3
|
.Dt USBHID 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -48,7 +48,7 @@
|
|||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.Lb libusbhid
|
.Lb libusbhid
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In libusbhid.h
|
.In usbhid.h
|
||||||
.Ft report_desc_t
|
.Ft report_desc_t
|
||||||
.Fn hid_get_report_desc "int file"
|
.Fn hid_get_report_desc "int file"
|
||||||
.Ft report_desc_t
|
.Ft report_desc_t
|
||||||
@ -56,34 +56,34 @@
|
|||||||
.Ft void
|
.Ft void
|
||||||
.Fn hid_dispose_report_desc "report_desc_t d"
|
.Fn hid_dispose_report_desc "report_desc_t d"
|
||||||
.Ft hid_data_t
|
.Ft hid_data_t
|
||||||
.Fn hid_start_parse "report_desc_t d" "int kindset"
|
.Fn hid_start_parse "report_desc_t d" "int kindset" "int id"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn hid_end_parse "hid_data_t s"
|
.Fn hid_end_parse "hid_data_t s"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn hid_get_item "hid_data_t s" "hid_item_t *h"
|
.Fn hid_get_item "hid_data_t s" "hid_item_t *h"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn hid_report_size "report_desc_t d" "unsigned int id" "hid_kind_t k"
|
.Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int id"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn hid_locate "report_desc_t d" "unsigned int usage" "hid_kind_t k" "hid_item_t *h"
|
.Fn hid_locate "report_desc_t d" "u_int usage" "hid_kind_t k" "hid_item_t *h" "int id"
|
||||||
.Ft "const char *"
|
.Ft char *
|
||||||
.Fn hid_usage_page "int i"
|
.Fn hid_usage_page "int i"
|
||||||
.Ft "const char *"
|
.Ft char *
|
||||||
.Fn hid_usage_in_page "unsigned int u"
|
.Fn hid_usage_in_page "u_int u"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn hid_parse_usage_page "const char *name"
|
.Fn hid_parse_usage_page "const char *"
|
||||||
.Ft int
|
.Ft char *
|
||||||
.Fn hid_parse_usage_in_page "const char *name"
|
.Fn hid_parse_usage_in_page "const char *"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn hid_init "const char *file"
|
.Fn hid_init "char *file"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn hid_get_data "const void *data" "const hid_item_t *h"
|
.Fn hid_get_data "void *data" "hid_item_t *h"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn hid_set_data "void *p" "const hid_item_t *h" "int data"
|
.Fn hid_set_data "void *data" "hid_item_t *h" "u_int data"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
library provides routines to extract data from USB Human Interface Devices.
|
library provides routines to extract data from USB Human Interface Devices.
|
||||||
.Ss Introduction
|
.Ss INTRODUCTION
|
||||||
USB HID devices send and receive data layed out in a device dependent way.
|
USB HID devices send and receive data layed out in a device dependent way.
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
@ -94,7 +94,7 @@ which contains the data layout information and then use this information.
|
|||||||
The routines can be divided into four parts: extraction of the descriptor,
|
The routines can be divided into four parts: extraction of the descriptor,
|
||||||
parsing of the descriptor, translating to/from symbolic names, and
|
parsing of the descriptor, translating to/from symbolic names, and
|
||||||
data manipulation.
|
data manipulation.
|
||||||
.Ss Descriptor Functions
|
.Ss DESCRIPTOR FUNCTIONS
|
||||||
A report descriptor can be obtained by calling
|
A report descriptor can be obtained by calling
|
||||||
.Fn hid_get_report_desc
|
.Fn hid_get_report_desc
|
||||||
with a file descriptor obtained by opening a
|
with a file descriptor obtained by opening a
|
||||||
@ -114,18 +114,19 @@ If
|
|||||||
.Fn hid_dispose_report_desc
|
.Fn hid_dispose_report_desc
|
||||||
fails it will return
|
fails it will return
|
||||||
.Dv NULL .
|
.Dv NULL .
|
||||||
.Ss Descriptor Parsing Functions
|
.Ss DESCRIPTOR PARSING FUNCTIONS
|
||||||
To parse the report descriptor the
|
To parse the report descriptor the
|
||||||
.Fn hid_start_parse
|
.Fn hid_start_parse
|
||||||
function should be called with a report descriptor and a set that
|
function should be called with a report descriptor and a set that
|
||||||
describes which items that are interesting.
|
describes which items that are interesting.
|
||||||
The set is obtained
|
The set is obtained by OR-ing together values
|
||||||
by OR-ing together values
|
|
||||||
.Fa "(1 << k)"
|
.Fa "(1 << k)"
|
||||||
where
|
where
|
||||||
.Fa k
|
.Fa k
|
||||||
is an item of type
|
is an item of type
|
||||||
.Vt hid_kind_t .
|
.Vt hid_kind_t .
|
||||||
|
The report id (if present) is given by
|
||||||
|
.Fa id .
|
||||||
The function returns
|
The function returns
|
||||||
.Dv NULL
|
.Dv NULL
|
||||||
if the initialization fails, otherwise an opaque value to be used
|
if the initialization fails, otherwise an opaque value to be used
|
||||||
@ -146,15 +147,16 @@ will be filled with the relevant data for the item.
|
|||||||
The definition of
|
The definition of
|
||||||
.Vt hid_item_t
|
.Vt hid_item_t
|
||||||
can be found in
|
can be found in
|
||||||
.Aq Pa libusbhid.h
|
.Aq Pa usbhid.h
|
||||||
and the meaning of the components in the USB HID documentation.
|
and the meaning of the components in the USB HID documentation.
|
||||||
.Pp
|
.Pp
|
||||||
Data should be read/written to the device in the size of
|
Data should be read/written to the device in the size of
|
||||||
the report.
|
the report.
|
||||||
The size of a report (of a certain kind) can be
|
The size of a report (of a certain kind) can be computed by the
|
||||||
computed by the
|
|
||||||
.Fn hid_report_size
|
.Fn hid_report_size
|
||||||
function.
|
function.
|
||||||
|
If the report is prefixed by an ID byte it is given by
|
||||||
|
.Fa id .
|
||||||
.Pp
|
.Pp
|
||||||
To locate a single item the
|
To locate a single item the
|
||||||
.Fn hid_locate
|
.Fn hid_locate
|
||||||
@ -162,7 +164,7 @@ function can be used.
|
|||||||
It should be given the usage code of
|
It should be given the usage code of
|
||||||
the item and its kind and it will fill the item and return
|
the item and its kind and it will fill the item and return
|
||||||
non-zero if the item was found.
|
non-zero if the item was found.
|
||||||
.Ss Name Translation Functions
|
.Ss Name TRANSLATION FUNCTIONS
|
||||||
The function
|
The function
|
||||||
.Fn hid_usage_page
|
.Fn hid_usage_page
|
||||||
will return the symbolic name of a usage page, and the function
|
will return the symbolic name of a usage page, and the function
|
||||||
@ -188,7 +190,7 @@ with the name of the table.
|
|||||||
Passing
|
Passing
|
||||||
.Dv NULL
|
.Dv NULL
|
||||||
to this function will cause it to use the default table.
|
to this function will cause it to use the default table.
|
||||||
.Ss Data Extraction Functions
|
.Ss Data EXTRACTION FUNCTIONS
|
||||||
Given the data obtained from a HID device and an item in the
|
Given the data obtained from a HID device and an item in the
|
||||||
report descriptor the
|
report descriptor the
|
||||||
.Fn hid_get_data
|
.Fn hid_get_data
|
||||||
@ -209,7 +211,7 @@ This man page is woefully incomplete.
|
|||||||
The
|
The
|
||||||
.Tn USB
|
.Tn USB
|
||||||
specifications can be found at
|
specifications can be found at
|
||||||
.Pa http://www.usb.org/developers/docs.htm .
|
.Pa http://www.usb.org/developers/docs.html .
|
||||||
.Pp
|
.Pp
|
||||||
.Xr uhid 4 ,
|
.Xr uhid 4 ,
|
||||||
.Xr usb 4
|
.Xr usb 4
|
||||||
|
@ -87,11 +87,11 @@ report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size);
|
|||||||
void hid_dispose_report_desc(report_desc_t);
|
void hid_dispose_report_desc(report_desc_t);
|
||||||
|
|
||||||
/* Parsing of a HID report descriptor, parse.c: */
|
/* Parsing of a HID report descriptor, parse.c: */
|
||||||
hid_data_t hid_start_parse(report_desc_t d, int kindset);
|
hid_data_t hid_start_parse(report_desc_t d, int kindset, int id);
|
||||||
void hid_end_parse(hid_data_t s);
|
void hid_end_parse(hid_data_t s);
|
||||||
int hid_get_item(hid_data_t s, hid_item_t *h);
|
int hid_get_item(hid_data_t s, hid_item_t *h);
|
||||||
int hid_report_size(report_desc_t d, unsigned int id, enum hid_kind k);
|
int hid_report_size(report_desc_t d, enum hid_kind k, int id);
|
||||||
int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h);
|
int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h, int id);
|
||||||
|
|
||||||
/* Conversion to/from usage names, usage.c: */
|
/* Conversion to/from usage names, usage.c: */
|
||||||
const char *hid_usage_page(int i);
|
const char *hid_usage_page(int i);
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
* doc/en_US.ISO8859-1/books/porters-handbook/book.sgml
|
* doc/en_US.ISO8859-1/books/porters-handbook/book.sgml
|
||||||
*/
|
*/
|
||||||
#undef __FreeBSD_version
|
#undef __FreeBSD_version
|
||||||
#define __FreeBSD_version 500110 /* Master, propagated to newvers */
|
#define __FreeBSD_version 500111 /* Master, propagated to newvers */
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
@ -47,13 +47,14 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libusbhid.h>
|
#include <usbhid.h>
|
||||||
#include <dev/usb/usb.h>
|
#include <dev/usb/usb.h>
|
||||||
#include <dev/usb/usbhid.h>
|
#include <dev/usb/usbhid.h>
|
||||||
|
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int all = 0;
|
int all = 0;
|
||||||
int noname = 0;
|
int noname = 0;
|
||||||
|
static int reportid;
|
||||||
|
|
||||||
char **names;
|
char **names;
|
||||||
int nnames;
|
int nnames;
|
||||||
@ -125,7 +126,7 @@ dumpitems(report_desc_t r)
|
|||||||
struct hid_item h;
|
struct hid_item h;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
for (d = hid_start_parse(r, ~0); hid_get_item(d, &h); ) {
|
for (d = hid_start_parse(r, ~0, reportid); hid_get_item(d, &h); ) {
|
||||||
switch (h.kind) {
|
switch (h.kind) {
|
||||||
case hid_collection:
|
case hid_collection:
|
||||||
printf("Collection page=%s usage=%s\n",
|
printf("Collection page=%s usage=%s\n",
|
||||||
@ -204,7 +205,7 @@ dumpdata(int f, report_desc_t rd, int loop)
|
|||||||
char namebuf[10000], *namep;
|
char namebuf[10000], *namep;
|
||||||
|
|
||||||
hids = 0;
|
hids = 0;
|
||||||
for (d = hid_start_parse(rd, 1<<hid_input);
|
for (d = hid_start_parse(rd, 1<<hid_input, reportid);
|
||||||
hid_get_item(d, &h); ) {
|
hid_get_item(d, &h); ) {
|
||||||
if (h.kind == hid_collection)
|
if (h.kind == hid_collection)
|
||||||
colls[++sp] = h.usage;
|
colls[++sp] = h.usage;
|
||||||
|
Loading…
Reference in New Issue
Block a user