xref: /freebsd/sys/dev/usb/usbhid.h (revision 61e21613)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
6  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef _USB_HID_H_
31 #define	_USB_HID_H_
32 
33 #include <dev/hid/hid.h>
34 
35 #ifndef USB_GLOBAL_INCLUDE_FILE
36 #include <dev/usb/usb_endian.h>
37 #endif
38 
39 #define	UR_GET_HID_DESCRIPTOR	0x06
40 #define	UDESC_HID		0x21
41 #define	UDESC_REPORT		0x22
42 #define	UDESC_PHYSICAL		0x23
43 #define	UR_SET_HID_DESCRIPTOR	0x07
44 #define	UR_GET_REPORT		0x01
45 #define	UR_SET_REPORT		0x09
46 #define	UR_GET_IDLE		0x02
47 #define	UR_SET_IDLE		0x0a
48 #define	UR_GET_PROTOCOL		0x03
49 #define	UR_SET_PROTOCOL		0x0b
50 
51 struct usb_hid_descriptor {
52 	uByte	bLength;
53 	uByte	bDescriptorType;
54 	uWord	bcdHID;
55 	uByte	bCountryCode;
56 	uByte	bNumDescriptors;
57 	struct {
58 		uByte	bDescriptorType;
59 		uWord	wDescriptorLength;
60 	}	descrs[1];
61 } __packed;
62 
63 #define	USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3))
64 
65 #define	UHID_INPUT_REPORT	HID_INPUT_REPORT
66 #define	UHID_OUTPUT_REPORT	HID_OUTPUT_REPORT
67 #define	UHID_FEATURE_REPORT	HID_FEATURE_REPORT
68 
69 #if defined(_KERNEL) || defined(_STANDALONE)
70 struct usb_config_descriptor;
71 
72 #ifdef COMPAT_USBHID12
73 /* FreeBSD <= 12 compat shims */
74 #define	hid_report_size(buf, len, kind, id)	\
75 	hid_report_size_max(buf, len, kind, id)
76 static __inline uint32_t
77 hid_get_data_unsigned(const uint8_t *buf, hid_size_t len,
78     struct hid_location *loc)
79 {
80 	return (hid_get_udata(buf, len, loc));
81 }
82 static __inline void
83 hid_put_data_unsigned(uint8_t *buf, hid_size_t len, struct hid_location *loc,
84     unsigned value)
85 {
86 	return (hid_put_udata(buf, len, loc, value));
87 }
88 #endif
89 
90 struct usb_hid_descriptor *hid_get_descriptor_from_usb(
91 	    struct usb_config_descriptor *cd,
92 	    struct usb_interface_descriptor *id);
93 usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
94 	    void **descp, uint16_t *sizep, struct malloc_type *mem,
95 	    uint8_t iface_index);
96 #endif	/* _KERNEL || _STANDALONE */
97 #endif	/* _USB_HID_H_ */
98