Restore handling of the third argument (id) of hid_start_parse(), same as
it is done in NetBSD/OpenBSD, and as it was here before r205728. I personally think this API or its implementation is incorrect, as it is not correct to filter collections based on report ID, as they are orthogonal in general case, but I see no harm from supporting this feature. PR: usb/171810 Submitted by: Vitaly Magerya <vmagerya@gmail.com> MFC after: 1 month
This commit is contained in:
parent
2a4e4c6772
commit
ec9b9fbd50
@ -68,7 +68,7 @@ hid_get_report_id(int fd)
|
|||||||
if ((rep = hid_get_report_desc(fd)) == NULL)
|
if ((rep = hid_get_report_desc(fd)) == NULL)
|
||||||
goto use_ioctl;
|
goto use_ioctl;
|
||||||
kindset = 1 << hid_input | 1 << hid_output | 1 << hid_feature;
|
kindset = 1 << hid_input | 1 << hid_output | 1 << hid_feature;
|
||||||
for (d = hid_start_parse(rep, kindset, 0); hid_get_item(d, &h); ) {
|
for (d = hid_start_parse(rep, kindset, -1); hid_get_item(d, &h); ) {
|
||||||
/* Return the first report ID we met. */
|
/* Return the first report ID we met. */
|
||||||
if (h.report_ID != 0) {
|
if (h.report_ID != 0) {
|
||||||
temp = h.report_ID;
|
temp = h.report_ID;
|
||||||
|
@ -70,6 +70,7 @@ struct hid_data {
|
|||||||
uint8_t iusage; /* current "usages_min/max" index */
|
uint8_t iusage; /* current "usages_min/max" index */
|
||||||
uint8_t ousage; /* current "usages_min/max" offset */
|
uint8_t ousage; /* current "usages_min/max" offset */
|
||||||
uint8_t susage; /* usage set flags */
|
uint8_t susage; /* usage set flags */
|
||||||
|
int32_t reportid; /* requested report ID */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
@ -149,7 +150,7 @@ hid_switch_rid(struct hid_data *s, struct hid_item *c, int32_t next_rID)
|
|||||||
* hid_start_parse
|
* hid_start_parse
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
hid_data_t
|
hid_data_t
|
||||||
hid_start_parse(report_desc_t d, int kindset, int id __unused)
|
hid_start_parse(report_desc_t d, int kindset, int id)
|
||||||
{
|
{
|
||||||
struct hid_data *s;
|
struct hid_data *s;
|
||||||
|
|
||||||
@ -158,6 +159,7 @@ hid_start_parse(report_desc_t d, int kindset, int id __unused)
|
|||||||
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;
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +209,8 @@ hid_get_byte(struct hid_data *s, const uint16_t wSize)
|
|||||||
/*------------------------------------------------------------------------*
|
/*------------------------------------------------------------------------*
|
||||||
* hid_get_item
|
* hid_get_item
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
int
|
static int
|
||||||
hid_get_item(hid_data_t s, hid_item_t *h)
|
hid_get_item_raw(hid_data_t s, hid_item_t *h)
|
||||||
{
|
{
|
||||||
hid_item_t *c;
|
hid_item_t *c;
|
||||||
unsigned int bTag, bType, bSize;
|
unsigned int bTag, bType, bSize;
|
||||||
@ -508,6 +510,19 @@ hid_get_item(hid_data_t s, hid_item_t *h)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
hid_get_item(hid_data_t s, hid_item_t *h)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
r = hid_get_item_raw(s, h);
|
||||||
|
if (r <= 0 || s->reportid == -1 || h->report_ID == s->reportid)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
hid_report_size(report_desc_t r, enum hid_kind k, int id)
|
hid_report_size(report_desc_t r, enum hid_kind k, int id)
|
||||||
{
|
{
|
||||||
@ -523,7 +538,7 @@ hid_report_size(report_desc_t r, enum hid_kind k, int id)
|
|||||||
|
|
||||||
memset(&h, 0, sizeof h);
|
memset(&h, 0, sizeof h);
|
||||||
for (d = hid_start_parse(r, 1 << k, id); hid_get_item(d, &h); ) {
|
for (d = hid_start_parse(r, 1 << k, id); hid_get_item(d, &h); ) {
|
||||||
if ((h.report_ID == id || id < 0) && h.kind == k) {
|
if (h.kind == k) {
|
||||||
/* compute minimum */
|
/* compute minimum */
|
||||||
if (lpos > h.pos)
|
if (lpos > h.pos)
|
||||||
lpos = h.pos;
|
lpos = h.pos;
|
||||||
|
@ -144,16 +144,15 @@ fails it will return
|
|||||||
.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, a set that
|
||||||
describes which items that are interesting.
|
describes which items that are interesting, and the desired report
|
||||||
|
ID (or -1 to obtain items of all report IDs).
|
||||||
The set is obtained by OR-ing together values
|
The set is obtained 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user