48#include <sys/stdint.h>
49#include <sys/stddef.h>
54#include <sys/kernel.h>
56#include <sys/module.h>
59#include <sys/condvar.h>
60#include <sys/sysctl.h>
62#include <sys/unistd.h>
63#include <sys/callout.h>
64#include <sys/malloc.h>
69#include <dev/hid/hid.h>
79#define USB_DEBUG_VAR uhid_debug
86static int uhid_debug = 0;
88static SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
91 &uhid_debug, 0,
"Debug level");
94#define UHID_BSIZE 1024
95#define UHID_FRAME_NUM 50
125#define UHID_FLAG_IMMED 0x01
126#define UHID_FLAG_STATIC_DESC 0x04
163 .basename[0] =
"uhid",
214 if ((actlen >= (
int)sc->
sc_isize) ||
215 ((actlen > 0) && (sc->
sc_iid != 0))) {
223 DPRINTF(
"ignored transfer, %d bytes\n", actlen);
247 uint8_t type, uint8_t
id, uint16_t
size)
252 req->wIndex[0] = iface_no;
259 uint8_t type, uint8_t
id, uint16_t
size)
264 req->wIndex[0] = iface_no;
305 if (actlen !=
size) {
373 .flags = {.pipe_bof = 1,.no_pipe_ok = 1, },
382 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
451 uint8_t
id,
void *kern_data,
void *user_data,
455 uint8_t free_data = 0;
457 if (kern_data == NULL) {
458 kern_data = malloc(
len, M_USBDEV, M_WAITOK);
469 err = copyout(kern_data, user_data,
len);
476 free(kern_data, M_USBDEV);
483 uint8_t
id,
void *kern_data,
void *user_data,
487 uint8_t free_data = 0;
489 if (kern_data == NULL) {
490 kern_data = malloc(
len, M_USBDEV, M_WAITOK);
492 err = copyin(user_data, kern_data,
len);
505 free(kern_data, M_USBDEV);
519 if (fflags & FREAD) {
530 if (fflags & FWRITE) {
542 if (fflags & (FREAD | FWRITE)) {
553#ifdef COMPAT_FREEBSD32
555 struct usb_gen_descriptor32 *ugd32 = NULL;
562#ifdef COMPAT_FREEBSD32
564 case USB_GET_REPORT_DESC32:
565 case USB_GET_REPORT32:
566 case USB_SET_REPORT32:
569 usb_gen_descriptor_from32(ugd, ugd32);
589 if (!(fflags & FREAD)) {
612 if (!(fflags & FREAD)) {
639 if (!(fflags & FWRITE)) {
673#ifdef COMPAT_FREEBSD32
675 update_usb_gen_descriptor32(ugd32, ugd);
746 if (hid_locate(buf,
len,
747 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACT_MAX),
748 hid_feature, 0, NULL, NULL, NULL) &&
750 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACTID),
751 hid_input, 0, NULL, NULL, NULL)) {
759 return (BUS_PROBE_GENERIC);
767 int unit = device_get_unit(
dev);
770 DPRINTFN(10,
"sc=%p\n", sc);
774 mtx_init(&sc->
sc_mtx,
"uhid lock", NULL, MTX_DEF | MTX_RECURSE);
797 }
else if (uaa->
info.
idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
798 static uint8_t reportbuf[] = {2, 2, 2};
806 reportbuf,
sizeof(reportbuf),
810 DPRINTF(
"set report failed, error=%s (ignored)\n",
820 static const uint8_t reportbuf[3] = {1, 3, 0};
826 __DECONST(
void *, reportbuf),
sizeof(reportbuf),
829 DPRINTF(
"set output report failed, error=%s (ignored)\n",
843 device_printf(
dev,
"no report descriptor\n");
851 DPRINTF(
"set idle failed, error=%s (ignored)\n",
864 DPRINTF(
"input size is too large, "
865 "%d bytes (truncating)\n",
870 DPRINTF(
"output size is too large, "
871 "%d bytes (truncating)\n",
876 DPRINTF(
"feature size is too large, "
877 "%d bytes (truncating)\n",
885 UID_ROOT, GID_OPERATOR, 0644);
915#ifndef HIDRAW_MAKE_UHID_ALIAS
928#ifdef HIDRAW_MAKE_UHID_ALIAS
937#ifdef HIDRAW_MAKE_UHID_ALIAS
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
struct usb_device * sc_udev
struct usb_xfer * sc_xfer[UHID_N_TRANSFER]
struct usb_fifo_sc sc_fifo
enum usb_hc_mode usb_mode
struct usbd_lookup_info info
struct usb_device * device
uint8_t bInterfaceSubClass
uint8_t bInterfaceProtocol
static usb_fifo_close_t uhid_close
static usb_fifo_cmd_t uhid_start_read
static device_probe_t uhid_probe
static device_detach_t uhid_detach
MODULE_DEPEND(uhid, usb, 1, 1, 1)
static int uhid_set_report(struct uhid_softc *sc, uint8_t type, uint8_t id, void *kern_data, void *user_data, uint16_t len)
static devclass_t uhid_devclass
static void uhid_fill_set_report(struct usb_device_request *req, uint8_t iface_no, uint8_t type, uint8_t id, uint16_t size)
#define UHID_FLAG_STATIC_DESC
static usb_callback_t uhid_read_callback
static usb_fifo_open_t uhid_open
static usb_callback_t uhid_intr_write_callback
static void uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no, uint8_t type, uint8_t id, uint16_t size)
static int uhid_get_report(struct uhid_softc *sc, uint8_t type, uint8_t id, void *kern_data, void *user_data, uint16_t len)
static usb_fifo_ioctl_t uhid_ioctl_post
USB_PNP_HOST_INFO(uhid_devs)
static struct usb_fifo_methods uhid_fifo_methods
static usb_callback_t uhid_write_callback
static device_method_t uhid_methods[]
static usb_callback_t uhid_intr_read_callback
static usb_fifo_cmd_t uhid_stop_write
static usb_fifo_cmd_t uhid_stop_read
static const struct usb_config uhid_config[UHID_N_TRANSFER]
static const uint8_t uhid_graphire_report_descr[]
static const uint8_t uhid_graphire3_4x5_report_descr[]
DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, NULL, 0)
static const STRUCT_USB_HOST_ID uhid_devs[]
static device_attach_t uhid_attach
static driver_t uhid_driver
static const uint8_t uhid_xb360gp_report_descr[]
static usb_fifo_ioctl_t uhid_ioctl
static usb_fifo_cmd_t uhid_start_write
#define UISUBCLASS_XBOX360_CONTROLLER
#define UT_READ_CLASS_INTERFACE
#define UIPROTO_XBOX360_GAMEPAD
#define UT_WRITE_CLASS_INTERFACE
#define UIPROTO_BOOT_KEYBOARD
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len)
#define USETW2(w, b1, b0)
const char * usbd_errstr(usb_error_t err)
int ugen_fill_deviceinfo(struct usb_fifo *f, struct usb_device_info *di)
usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx, void **descp, uint16_t *sizep, struct malloc_type *mem, uint8_t iface_index)
#define USB_GET_REPORT_ID
#define USB_GET_DEVICEINFO
#define USB_GET_REPORT_DESC
int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa)
uint8_t usb_test_quirk(const struct usb_attach_arg *uaa, uint16_t quirk)
#define UHID_XB360GP_REPORT_DESCR
#define UHID_GRAPHIRE3_4X5_REPORT_DESCR
#define UHID_GRAPHIRE_REPORT_DESCR
usb_error_t usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, void *data, uint16_t len, uint8_t iface_index, uint8_t type, uint8_t id)
usb_error_t usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, void *data, uint16_t len, uint8_t iface_index, uint8_t type, uint8_t id)
usb_error_t usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx, uint8_t iface_index, uint8_t duration, uint8_t id)
void usbd_transfer_submit(struct usb_xfer *xfer)
void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
struct usb_page_cache * usbd_xfer_get_frame(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
void usbd_transfer_start(struct usb_xfer *xfer)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_set_stall(struct usb_xfer *xfer)
void usbd_transfer_stop(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
void device_set_usb_desc(device_t dev)
int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, uint16_t nbuf)
int() usb_fifo_ioctl_t(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags)
#define USB_IFACE_SUBCLASS(isc)
void * usb_fifo_softc(struct usb_fifo *fifo)
void() usb_fifo_close_t(struct usb_fifo *fifo, int fflags)
void usb_fifo_detach(struct usb_fifo_sc *f_sc)
void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, uint8_t what)
void usb_fifo_get_data_error(struct usb_fifo *fifo)
int usb_fifo_attach(struct usb_device *udev, void *priv_sc, struct mtx *priv_mtx, struct usb_fifo_methods *pm, struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit, uint8_t iface_index, uid_t uid, gid_t gid, int mode)
void() usb_fifo_cmd_t(struct usb_fifo *fifo)
void usb_fifo_free_buffer(struct usb_fifo *f)
void usb_fifo_put_data_error(struct usb_fifo *fifo)
#define USB_IFACE_CLASS(ic)
uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, uint8_t what)
#define USB_ST_TRANSFERRED
#define USB_IFACE_PROTOCOL(ip)
void() usb_callback_t(struct usb_xfer *, usb_error_t)
int() usb_fifo_open_t(struct usb_fifo *fifo, int fflags)
#define STRUCT_USB_HOST_ID
#define USB_GET_STATE(xfer)
uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo)
#define UHID_FEATURE_REPORT
#define UHID_OUTPUT_REPORT
#define UHID_INPUT_REPORT