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