mirror of
https://github.com/opnsense/src.git
synced 2026-02-20 00:11:07 -05:00
hid: Chase for HID function name changes in existing USB HID drivers
Also hide shim code added in a previous commit under COMPAT_USBHID12. Note: it is enough to add -DCOMPAT_USBHID12 to CFLAGS to compile old code with new HID subsystem, but it is not enough to link it at runtime. HID dependency has to be added explicitly with MODULE_DEPEND macro. Reviewed by: manu, hselasky (as part of D27887)
This commit is contained in:
parent
1975878673
commit
eead9017d2
10 changed files with 49 additions and 69 deletions
|
|
@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/malloc.h>
|
||||
#include <sys/priv.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include "usbdevs.h"
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
|
|
@ -6145,7 +6147,7 @@ uaudio_hid_probe(struct uaudio_softc *sc,
|
|||
}
|
||||
|
||||
/* check if there is an ID byte */
|
||||
hid_report_size(d_ptr, d_len, hid_input, &id);
|
||||
hid_report_size_max(d_ptr, d_len, hid_input, &id);
|
||||
|
||||
if (id != 0)
|
||||
sc->sc_hid.flags |= UAUDIO_HID_HAS_ID;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/selinfo.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
|
@ -2204,7 +2206,7 @@ atp_attach(device_t dev)
|
|||
return (ENXIO);
|
||||
|
||||
/* Get HID report descriptor length */
|
||||
sc->sc_expected_sensor_data_len = hid_report_size(descriptor_ptr,
|
||||
sc->sc_expected_sensor_data_len = hid_report_size_max(descriptor_ptr,
|
||||
descriptor_len, hid_input, NULL);
|
||||
free(descriptor_ptr, M_TEMP);
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include "usbdevs.h"
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
|
|
@ -828,13 +830,13 @@ uhid_attach(device_t dev)
|
|||
DPRINTF("set idle failed, error=%s (ignored)\n",
|
||||
usbd_errstr(error));
|
||||
}
|
||||
sc->sc_isize = hid_report_size
|
||||
sc->sc_isize = hid_report_size_max
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
|
||||
|
||||
sc->sc_osize = hid_report_size
|
||||
sc->sc_osize = hid_report_size_max
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
|
||||
|
||||
sc->sc_fsize = hid_report_size
|
||||
sc->sc_fsize = hid_report_size_max
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
|
||||
|
||||
if (sc->sc_isize > UHID_BSIZE) {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/priv.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
|
@ -717,7 +719,7 @@ ukbd_intr_callback(struct usb_xfer *xfer, usb_error_t error)
|
|||
tmp_loc.count = UKBD_NKEYCODE;
|
||||
while (tmp_loc.count--) {
|
||||
uint32_t key =
|
||||
hid_get_data_unsigned(sc->sc_buffer, len, &tmp_loc);
|
||||
hid_get_udata(sc->sc_buffer, len, &tmp_loc);
|
||||
/* advance to next location */
|
||||
tmp_loc.pos += tmp_loc.size;
|
||||
if (modifiers & MOD_FN)
|
||||
|
|
@ -816,7 +818,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
|
|||
|
||||
if (sc->sc_flags & UKBD_FLAG_NUMLOCK) {
|
||||
if (sc->sc_leds & NLKED) {
|
||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
&sc->sc_loc_numlock, 1);
|
||||
}
|
||||
id = sc->sc_id_numlock;
|
||||
|
|
@ -825,7 +827,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
|
|||
|
||||
if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) {
|
||||
if (sc->sc_leds & SLKED) {
|
||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
&sc->sc_loc_scrolllock, 1);
|
||||
}
|
||||
id = sc->sc_id_scrolllock;
|
||||
|
|
@ -834,7 +836,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
|
|||
|
||||
if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) {
|
||||
if (sc->sc_leds & CLKED) {
|
||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
|
||||
&sc->sc_loc_capslock, 1);
|
||||
}
|
||||
id = sc->sc_id_capslock;
|
||||
|
|
@ -983,7 +985,7 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
|
|||
memset(sc->sc_loc_key_valid, 0, sizeof(sc->sc_loc_key_valid));
|
||||
|
||||
/* check if there is an ID byte */
|
||||
sc->sc_kbd_size = hid_report_size(ptr, len,
|
||||
sc->sc_kbd_size = hid_report_size_max(ptr, len,
|
||||
hid_input, &sc->sc_kbd_id);
|
||||
|
||||
/* investigate if this is an Apple Keyboard */
|
||||
|
|
@ -1033,7 +1035,7 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
|
|||
}
|
||||
|
||||
/* figure out leds on keyboard */
|
||||
sc->sc_led_size = hid_report_size(ptr, len,
|
||||
sc->sc_led_size = hid_report_size_max(ptr, len,
|
||||
hid_output, NULL);
|
||||
|
||||
if (hid_locate(ptr, len,
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/fcntl.h>
|
||||
#include <sys/sbuf.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
|
@ -614,7 +616,7 @@ ums_attach(device_t dev)
|
|||
goto detach;
|
||||
}
|
||||
|
||||
isize = hid_report_size(d_ptr, d_len, hid_input, &sc->sc_iid);
|
||||
isize = hid_report_size_max(d_ptr, d_len, hid_input, &sc->sc_iid);
|
||||
|
||||
/*
|
||||
* The Microsoft Wireless Notebook Optical Mouse seems to be in worse
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include "usbdevs.h"
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
|
|
@ -352,7 +354,7 @@ wmt_attach(device_t dev)
|
|||
sc->cont_max_rlen, uaa->info.bIfaceIndex,
|
||||
UHID_FEATURE_REPORT, sc->cont_max_rid);
|
||||
if (err == USB_ERR_NORMAL_COMPLETION) {
|
||||
cont_count_max = hid_get_data_unsigned(sc->buf + 1,
|
||||
cont_count_max = hid_get_udata(sc->buf + 1,
|
||||
sc->cont_max_rlen - 1, &sc->cont_max_loc);
|
||||
/*
|
||||
* Feature report is a primary source of
|
||||
|
|
@ -377,7 +379,7 @@ wmt_attach(device_t dev)
|
|||
}
|
||||
if (sc->btn_type_rlen > 1) {
|
||||
if (err == 0)
|
||||
sc->is_clickpad = hid_get_data_unsigned(sc->buf + 1,
|
||||
sc->is_clickpad = hid_get_udata(sc->buf + 1,
|
||||
sc->btn_type_rlen - 1, &sc->btn_type_loc) == 0;
|
||||
else
|
||||
DPRINTF("usbd_req_get_report error=%d\n", err);
|
||||
|
|
@ -522,7 +524,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
|
|||
* report with contactid=0 but contactids are zero-based, find
|
||||
* contactcount first.
|
||||
*/
|
||||
cont_count = hid_get_data_unsigned(buf, len, &sc->cont_count_loc);
|
||||
cont_count = hid_get_udata(buf, len, &sc->cont_count_loc);
|
||||
/*
|
||||
* "In Hybrid mode, the number of contacts that can be reported in one
|
||||
* report is less than the maximum number of contacts that the device
|
||||
|
|
@ -559,7 +561,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
|
|||
bzero(slot_data, sizeof(sc->slot_data));
|
||||
WMT_FOREACH_USAGE(sc->caps, usage) {
|
||||
if (sc->locs[cont][usage].size > 0)
|
||||
slot_data[usage] = hid_get_data_unsigned(
|
||||
slot_data[usage] = hid_get_udata(
|
||||
buf, len, &sc->locs[cont][usage]);
|
||||
}
|
||||
|
||||
|
|
@ -611,8 +613,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
|
|||
sc->nconts_todo -= cont_count;
|
||||
if (sc->do_timestamps && sc->nconts_todo == 0) {
|
||||
/* HUD_SCAN_TIME is measured in 100us, convert to us. */
|
||||
scan_time =
|
||||
hid_get_data_unsigned(buf, len, &sc->scan_time_loc);
|
||||
scan_time = hid_get_udata(buf, len, &sc->scan_time_loc);
|
||||
if (sc->prev_touch) {
|
||||
delta = scan_time - sc->scan_time;
|
||||
if (delta < 0)
|
||||
|
|
@ -747,46 +748,6 @@ wmt_ev_open(struct evdev_dev *evdev)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* port of userland hid_report_size() from usbhid(3) to kernel */
|
||||
static int
|
||||
wmt_hid_report_size(const void *buf, uint16_t len, enum hid_kind k, uint8_t id)
|
||||
{
|
||||
struct hid_data *d;
|
||||
struct hid_item h;
|
||||
uint32_t temp;
|
||||
uint32_t hpos;
|
||||
uint32_t lpos;
|
||||
int report_id = 0;
|
||||
|
||||
hpos = 0;
|
||||
lpos = 0xFFFFFFFF;
|
||||
|
||||
for (d = hid_start_parse(buf, len, 1 << k); hid_get_item(d, &h);) {
|
||||
if (h.kind == k && h.report_ID == id) {
|
||||
/* compute minimum */
|
||||
if (lpos > h.loc.pos)
|
||||
lpos = h.loc.pos;
|
||||
/* compute end position */
|
||||
temp = h.loc.pos + (h.loc.size * h.loc.count);
|
||||
/* compute maximum */
|
||||
if (hpos < temp)
|
||||
hpos = temp;
|
||||
if (h.report_ID != 0)
|
||||
report_id = 1;
|
||||
}
|
||||
}
|
||||
hid_end_parse(d);
|
||||
|
||||
/* safety check - can happen in case of currupt descriptors */
|
||||
if (lpos > hpos)
|
||||
temp = 0;
|
||||
else
|
||||
temp = hpos - lpos;
|
||||
|
||||
/* return length in bytes rounded up */
|
||||
return ((temp + 7) / 8 + report_id);
|
||||
}
|
||||
|
||||
static enum wmt_type
|
||||
wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
|
||||
{
|
||||
|
|
@ -1000,16 +961,16 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
|
|||
sc->ai[WMT_ORIENTATION].max = 1;
|
||||
}
|
||||
|
||||
sc->isize = hid_report_size(d_ptr, d_len, hid_input, NULL);
|
||||
sc->report_len = wmt_hid_report_size(d_ptr, d_len, hid_input,
|
||||
sc->isize = hid_report_size_max(d_ptr, d_len, hid_input, NULL);
|
||||
sc->report_len = hid_report_size(d_ptr, d_len, hid_input,
|
||||
report_id);
|
||||
sc->cont_max_rlen = wmt_hid_report_size(d_ptr, d_len, hid_feature,
|
||||
sc->cont_max_rlen = hid_report_size(d_ptr, d_len, hid_feature,
|
||||
sc->cont_max_rid);
|
||||
if (sc->btn_type_rid > 0)
|
||||
sc->btn_type_rlen = wmt_hid_report_size(d_ptr, d_len,
|
||||
sc->btn_type_rlen = hid_report_size(d_ptr, d_len,
|
||||
hid_feature, sc->btn_type_rid);
|
||||
if (sc->thqa_cert_rid > 0)
|
||||
sc->thqa_cert_rlen = wmt_hid_report_size(d_ptr, d_len,
|
||||
sc->thqa_cert_rlen = hid_report_size(d_ptr, d_len,
|
||||
hid_feature, sc->thqa_cert_rid);
|
||||
|
||||
sc->report_id = report_id;
|
||||
|
|
@ -1039,7 +1000,7 @@ wmt_set_input_mode(struct wmt_softc *sc, enum wmt_input_mode mode)
|
|||
bzero(sc->buf + 1, sc->input_mode_rlen - 1);
|
||||
|
||||
sc->buf[0] = sc->input_mode_rid;
|
||||
hid_put_data_unsigned(sc->buf + 1, sc->input_mode_rlen - 1,
|
||||
hid_put_udata(sc->buf + 1, sc->input_mode_rlen - 1,
|
||||
&sc->input_mode_loc, mode);
|
||||
err = usbd_req_set_report(uaa->device, NULL, sc->buf,
|
||||
sc->input_mode_rlen, uaa->info.bIfaceIndex,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/poll.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
|
@ -733,7 +735,8 @@ wsp_attach(device_t dev)
|
|||
|
||||
if (err == USB_ERR_NORMAL_COMPLETION) {
|
||||
/* Get HID report descriptor length */
|
||||
sc->tp_datalen = hid_report_size(d_ptr, d_len, hid_input, NULL);
|
||||
sc->tp_datalen = hid_report_size_max(d_ptr, d_len, hid_input,
|
||||
NULL);
|
||||
free(d_ptr, M_TEMP);
|
||||
|
||||
if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/priv.h>
|
||||
#include <sys/conf.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbhid.h>
|
||||
|
|
@ -227,7 +229,7 @@ ugold_attach(device_t dev)
|
|||
if (error)
|
||||
goto detach;
|
||||
|
||||
(void)hid_report_size(d_ptr, d_len, hid_input, &sc->sc_report_id);
|
||||
(void)hid_report_size_max(d_ptr, d_len, hid_input, &sc->sc_report_id);
|
||||
|
||||
free(d_ptr, M_TEMP);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ __FBSDID("$FreeBSD$");
|
|||
#include <sys/malloc.h>
|
||||
#include <sys/priv.h>
|
||||
|
||||
#include <dev/hid/hid.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
|
|
@ -249,9 +251,9 @@ ucycom_attach(device_t dev)
|
|||
}
|
||||
/* get report sizes */
|
||||
|
||||
sc->sc_flen = hid_report_size(urd_ptr, urd_len, hid_feature, &sc->sc_fid);
|
||||
sc->sc_ilen = hid_report_size(urd_ptr, urd_len, hid_input, &sc->sc_iid);
|
||||
sc->sc_olen = hid_report_size(urd_ptr, urd_len, hid_output, &sc->sc_oid);
|
||||
sc->sc_flen = hid_report_size_max(urd_ptr, urd_len, hid_feature, &sc->sc_fid);
|
||||
sc->sc_ilen = hid_report_size_max(urd_ptr, urd_len, hid_input, &sc->sc_iid);
|
||||
sc->sc_olen = hid_report_size_max(urd_ptr, urd_len, hid_output, &sc->sc_oid);
|
||||
|
||||
if ((sc->sc_ilen > UCYCOM_MAX_IOLEN) || (sc->sc_ilen < 1) ||
|
||||
(sc->sc_olen > UCYCOM_MAX_IOLEN) || (sc->sc_olen < 2) ||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ struct usb_hid_descriptor {
|
|||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
struct usb_config_descriptor;
|
||||
|
||||
#ifdef COMPAT_USBHID12
|
||||
/* FreeBSD <= 12 compat shims */
|
||||
#define hid_report_size(buf, len, kind, id) \
|
||||
hid_report_size_max(buf, len, kind, id)
|
||||
|
|
@ -85,6 +86,7 @@ hid_put_data_unsigned(uint8_t *buf, hid_size_t len, struct hid_location *loc,
|
|||
{
|
||||
return (hid_put_udata(buf, len, loc, value));
|
||||
}
|
||||
#endif
|
||||
|
||||
struct usb_hid_descriptor *hid_get_descriptor_from_usb(
|
||||
struct usb_config_descriptor *cd,
|
||||
|
|
|
|||
Loading…
Reference in a new issue