aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/hid
diff options
context:
space:
mode:
authorVladimir Kondratyev <wulf@FreeBSD.org>2020-10-04 22:21:08 +0000
committerVladimir Kondratyev <wulf@FreeBSD.org>2021-01-07 23:18:42 +0000
commit67de2db2623a10dc4edec1642b2f8685d5587d7f (patch)
tree8112775288ab4903e175c2ecd4bb9a00fa57b968 /sys/dev/hid
parent1ffa5c63f449866e030b2130dfa5c633d9062074 (diff)
Diffstat (limited to 'sys/dev/hid')
-rw-r--r--sys/dev/hid/hid.c87
-rw-r--r--sys/dev/hid/hid.h43
-rw-r--r--sys/dev/hid/hidrdesc.h72
3 files changed, 73 insertions, 129 deletions
diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
index 22e5fb5446c3..61b7587a6c62 100644
--- a/sys/dev/hid/hid.c
+++ b/sys/dev/hid/hid.c
@@ -780,91 +780,6 @@ hid_is_collection(const void *desc, usb_size_t size, int32_t usage)
}
/*------------------------------------------------------------------------*
- * hid_get_descriptor_from_usb
- *
- * This function will search for a HID descriptor between two USB
- * interface descriptors.
- *
- * Return values:
- * NULL: No more HID descriptors.
- * Else: Pointer to HID descriptor.
- *------------------------------------------------------------------------*/
-struct usb_hid_descriptor *
-hid_get_descriptor_from_usb(struct usb_config_descriptor *cd,
- struct usb_interface_descriptor *id)
-{
- struct usb_descriptor *desc = (void *)id;
-
- if (desc == NULL) {
- return (NULL);
- }
- while ((desc = usb_desc_foreach(cd, desc))) {
- if ((desc->bDescriptorType == UDESC_HID) &&
- (desc->bLength >= USB_HID_DESCRIPTOR_SIZE(0))) {
- return (void *)desc;
- }
- if (desc->bDescriptorType == UDESC_INTERFACE) {
- break;
- }
- }
- return (NULL);
-}
-
-/*------------------------------------------------------------------------*
- * usbd_req_get_hid_desc
- *
- * This function will read out an USB report descriptor from the USB
- * device.
- *
- * Return values:
- * NULL: Failure.
- * Else: Success. The pointer should eventually be passed to free().
- *------------------------------------------------------------------------*/
-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)
-{
- struct usb_interface *iface = usbd_get_iface(udev, iface_index);
- struct usb_hid_descriptor *hid;
- usb_error_t err;
-
- if ((iface == NULL) || (iface->idesc == NULL)) {
- return (USB_ERR_INVAL);
- }
- hid = hid_get_descriptor_from_usb
- (usbd_get_config_descriptor(udev), iface->idesc);
-
- if (hid == NULL) {
- return (USB_ERR_IOERROR);
- }
- *sizep = UGETW(hid->descrs[0].wDescriptorLength);
- if (*sizep == 0) {
- return (USB_ERR_IOERROR);
- }
- if (mtx)
- mtx_unlock(mtx);
-
- *descp = malloc(*sizep, mem, M_ZERO | M_WAITOK);
-
- if (mtx)
- mtx_lock(mtx);
-
- if (*descp == NULL) {
- return (USB_ERR_NOMEM);
- }
- err = usbd_req_get_report_descriptor
- (udev, mtx, *descp, *sizep, iface_index);
-
- if (err) {
- free(*descp, mem);
- *descp = NULL;
- return (err);
- }
- return (USB_ERR_NORMAL_COMPLETION);
-}
-
-/*------------------------------------------------------------------------*
* calculate HID item resolution. unit/mm for distances, unit/rad for angles
*------------------------------------------------------------------------*/
int32_t
@@ -1013,3 +928,5 @@ hid_is_keyboard(const void *d_ptr, uint16_t d_len)
return (1);
return (0);
}
+
+MODULE_VERSION(hid, 1);
diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
index 926c404dca55..b1829318bda1 100644
--- a/sys/dev/hid/hid.h
+++ b/sys/dev/hid/hid.h
@@ -28,38 +28,8 @@
* SUCH DAMAGE.
*/
-#ifndef _USB_HID_H_
-#define _USB_HID_H_
-
-#ifndef USB_GLOBAL_INCLUDE_FILE
-#include <dev/usb/usb_endian.h>
-#endif
-
-#define UR_GET_HID_DESCRIPTOR 0x06
-#define UDESC_HID 0x21
-#define UDESC_REPORT 0x22
-#define UDESC_PHYSICAL 0x23
-#define UR_SET_HID_DESCRIPTOR 0x07
-#define UR_GET_REPORT 0x01
-#define UR_SET_REPORT 0x09
-#define UR_GET_IDLE 0x02
-#define UR_SET_IDLE 0x0a
-#define UR_GET_PROTOCOL 0x03
-#define UR_SET_PROTOCOL 0x0b
-
-struct usb_hid_descriptor {
- uByte bLength;
- uByte bDescriptorType;
- uWord bcdHID;
- uByte bCountryCode;
- uByte bNumDescriptors;
- struct {
- uByte bDescriptorType;
- uWord wDescriptorLength;
- } descrs[1];
-} __packed;
-
-#define USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3))
+#ifndef _HID_HID_H_
+#define _HID_HID_H_
/* Usage pages */
#define HUP_UNDEFINED 0x0000
@@ -206,7 +176,6 @@ struct usb_hid_descriptor {
#define HUM_DEGREE 0x14
#if defined(_KERNEL) || defined(_STANDALONE)
-struct usb_config_descriptor;
#define HID_ITEM_MAXUSAGE 4
@@ -271,14 +240,8 @@ uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len,
void hid_put_data_unsigned(uint8_t *buf, usb_size_t len,
struct hid_location *loc, unsigned int value);
int hid_is_collection(const void *desc, usb_size_t size, int32_t usage);
-struct usb_hid_descriptor *hid_get_descriptor_from_usb(
- struct usb_config_descriptor *cd,
- struct usb_interface_descriptor *id);
-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);
int32_t hid_item_resolution(struct hid_item *hi);
int hid_is_mouse(const void *d_ptr, uint16_t d_len);
int hid_is_keyboard(const void *d_ptr, uint16_t d_len);
#endif /* _KERNEL || _STANDALONE */
-#endif /* _USB_HID_H_ */
+#endif /* _HID_HID_H_ */
diff --git a/sys/dev/hid/hidrdesc.h b/sys/dev/hid/hidrdesc.h
index 889381e82c15..f6cbb755cd24 100644
--- a/sys/dev/hid/hidrdesc.h
+++ b/sys/dev/hid/hidrdesc.h
@@ -33,7 +33,7 @@
* This file contains replacements for broken HID report descriptors.
*/
-#define UHID_GRAPHIRE_REPORT_DESCR(...) \
+#define HID_GRAPHIRE_REPORT_DESCR(...) \
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
0x09, 0x01, /* USAGE (Digitizer) */\
0xa1, 0x01, /* COLLECTION (Application) */\
@@ -97,7 +97,7 @@
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */\
0xc0, /* END_COLLECTION */\
-#define UHID_GRAPHIRE3_4X5_REPORT_DESCR(...) \
+#define HID_GRAPHIRE3_4X5_REPORT_DESCR(...) \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
0x09, 0x02, /* USAGE (Mouse) */\
0xa1, 0x01, /* COLLECTION (Application) */\
@@ -184,7 +184,7 @@
* The descriptor has no output report format, thus preventing you from
* controlling the LEDs and the built-in rumblers.
*/
-#define UHID_XB360GP_REPORT_DESCR(...) \
+#define HID_XB360GP_REPORT_DESCR(...) \
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
0x09, 0x05, /* USAGE (Gamepad) */\
0xa1, 0x01, /* COLLECTION (Application) */\
@@ -277,7 +277,7 @@
0xc0 /* END COLLECTION */\
/* Fixed report descriptor for Super Nintendo gamepads */
-#define UHID_SNES_REPORT_DESCR(...) \
+#define HID_SNES_REPORT_DESCR(...) \
0x05, 0x01, /* Usage Page (Desktop), */\
0x09, 0x04, /* Usage (Joystik), */\
0xA1, 0x01, /* Collection (Application), */\
@@ -304,3 +304,67 @@
0x81, 0x01, /* Input (Constant), */\
0xC0, /* End Collection, */\
0xC0 /* End Collection */
+
+/* HID mouse boot protocol descriptor */
+#define HID_MOUSE_BOOTPROTO_DESCR(...) \
+ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */\
+ 0x09, 0x02, /* Usage (Mouse) */\
+ 0xA1, 0x01, /* Collection (Application) */\
+ 0x09, 0x01, /* Usage (Pointer) */\
+ 0xA1, 0x00, /* Collection (Physical) */\
+ 0x95, 0x03, /* Report Count (3) */\
+ 0x75, 0x01, /* Report Size (1) */\
+ 0x05, 0x09, /* Usage Page (Button) */\
+ 0x19, 0x01, /* Usage Minimum (0x01) */\
+ 0x29, 0x03, /* Usage Maximum (0x03) */\
+ 0x15, 0x00, /* Logical Minimum (0) */\
+ 0x25, 0x01, /* Logical Maximum (1) */\
+ 0x81, 0x02, /* Input (Data,Var,Abs) */\
+ 0x95, 0x01, /* Report Count (1) */\
+ 0x75, 0x05, /* Report Size (5) */\
+ 0x81, 0x03, /* Input (Const) */\
+ 0x75, 0x08, /* Report Size (8) */\
+ 0x95, 0x02, /* Report Count (2) */\
+ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */\
+ 0x09, 0x30, /* Usage (X) */\
+ 0x09, 0x31, /* Usage (Y) */\
+ 0x15, 0x81, /* Logical Minimum (-127) */\
+ 0x25, 0x7F, /* Logical Maximum (127) */\
+ 0x81, 0x06, /* Input (Data,Var,Rel) */\
+ 0xC0, /* End Collection */\
+ 0xC0, /* End Collection */
+
+/* HID keyboard boot protocol descriptor */
+#define HID_KBD_BOOTPROTO_DESCR(...) \
+ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */\
+ 0x09, 0x06, /* Usage (Keyboard) */\
+ 0xA1, 0x01, /* Collection (Application) */\
+ 0x05, 0x07, /* Usage Page (Kbrd/Keypad) */\
+ 0x19, 0xE0, /* Usage Minimum (0xE0) */\
+ 0x29, 0xE7, /* Usage Maximum (0xE7) */\
+ 0x15, 0x00, /* Logical Minimum (0) */\
+ 0x25, 0x01, /* Logical Maximum (1) */\
+ 0x75, 0x01, /* Report Size (1) */\
+ 0x95, 0x08, /* Report Count (8) */\
+ 0x81, 0x02, /* Input (Data,Var,Abs) */\
+ 0x95, 0x01, /* Report Count (1) */\
+ 0x75, 0x08, /* Report Size (8) */\
+ 0x81, 0x01, /* Input (Const,Array,Abs) */\
+ 0x95, 0x03, /* Report Count (3) */\
+ 0x75, 0x01, /* Report Size (1) */\
+ 0x05, 0x08, /* Usage Page (LEDs) */\
+ 0x19, 0x01, /* Usage Minimum (Num Lock) */\
+ 0x29, 0x03, /* Usage Maximum (Scroll Lock) */\
+ 0x91, 0x02, /* Output (Data,Var,Abs) */\
+ 0x95, 0x05, /* Report Count (5) */\
+ 0x75, 0x01, /* Report Size (1) */\
+ 0x91, 0x01, /* Output (Const,Array,Abs) */\
+ 0x95, 0x06, /* Report Count (6) */\
+ 0x75, 0x08, /* Report Size (8) */\
+ 0x15, 0x00, /* Logical Minimum (0) */\
+ 0x26, 0xFF, 0x00, /* Logical Maximum (255) */\
+ 0x05, 0x07, /* Usage Page (Kbrd/Keypad) */\
+ 0x19, 0x00, /* Usage Minimum (0x00) */\
+ 0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */\
+ 0x81, 0x00, /* Input (Data,Array,Abs) */\
+ 0xC0, /* End Collection */