xref: /freebsd/sys/dev/usb/usbhid.h (revision 62d42655bca1e496160718c1443e67e626e24365)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
4718cf2ccSPedro F. Giffuni  *
502ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
602ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
702ac6454SAndrew Thompson  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
802ac6454SAndrew Thompson  *
902ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1002ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1102ac6454SAndrew Thompson  * are met:
1202ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1402ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1502ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1602ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1702ac6454SAndrew Thompson  *
1802ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1902ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2002ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2102ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2202ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2302ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2402ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2502ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2602ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2702ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2802ac6454SAndrew Thompson  * SUCH DAMAGE.
2902ac6454SAndrew Thompson  */
3002ac6454SAndrew Thompson 
3175973647SAndrew Thompson #ifndef _USB_HID_H_
3275973647SAndrew Thompson #define	_USB_HID_H_
3302ac6454SAndrew Thompson 
3467de2db2SVladimir Kondratyev #include <dev/hid/hid.h>
3567de2db2SVladimir Kondratyev 
36d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE
3702ac6454SAndrew Thompson #include <dev/usb/usb_endian.h>
38d2b99310SHans Petter Selasky #endif
3902ac6454SAndrew Thompson 
4002ac6454SAndrew Thompson #define	UR_GET_HID_DESCRIPTOR	0x06
4102ac6454SAndrew Thompson #define	UDESC_HID		0x21
4202ac6454SAndrew Thompson #define	UDESC_REPORT		0x22
4302ac6454SAndrew Thompson #define	UDESC_PHYSICAL		0x23
4402ac6454SAndrew Thompson #define	UR_SET_HID_DESCRIPTOR	0x07
4502ac6454SAndrew Thompson #define	UR_GET_REPORT		0x01
4602ac6454SAndrew Thompson #define	UR_SET_REPORT		0x09
4702ac6454SAndrew Thompson #define	UR_GET_IDLE		0x02
4802ac6454SAndrew Thompson #define	UR_SET_IDLE		0x0a
4902ac6454SAndrew Thompson #define	UR_GET_PROTOCOL		0x03
5002ac6454SAndrew Thompson #define	UR_SET_PROTOCOL		0x0b
5102ac6454SAndrew Thompson 
52760bc48eSAndrew Thompson struct usb_hid_descriptor {
5302ac6454SAndrew Thompson 	uByte	bLength;
5402ac6454SAndrew Thompson 	uByte	bDescriptorType;
5502ac6454SAndrew Thompson 	uWord	bcdHID;
5602ac6454SAndrew Thompson 	uByte	bCountryCode;
5702ac6454SAndrew Thompson 	uByte	bNumDescriptors;
5802ac6454SAndrew Thompson 	struct {
5902ac6454SAndrew Thompson 		uByte	bDescriptorType;
6002ac6454SAndrew Thompson 		uWord	wDescriptorLength;
6102ac6454SAndrew Thompson 	}	descrs[1];
6202ac6454SAndrew Thompson } __packed;
6302ac6454SAndrew Thompson 
6402ac6454SAndrew Thompson #define	USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3))
6502ac6454SAndrew Thompson 
6619758786SVladimir Kondratyev #define	UHID_INPUT_REPORT	HID_INPUT_REPORT
6719758786SVladimir Kondratyev #define	UHID_OUTPUT_REPORT	HID_OUTPUT_REPORT
6819758786SVladimir Kondratyev #define	UHID_FEATURE_REPORT	HID_FEATURE_REPORT
6919758786SVladimir Kondratyev 
70a2dd1caaSHans Petter Selasky #if defined(_KERNEL) || defined(_STANDALONE)
71ed6d949aSAndrew Thompson struct usb_config_descriptor;
72ed6d949aSAndrew Thompson 
73eead9017SVladimir Kondratyev #ifdef COMPAT_USBHID12
7419758786SVladimir Kondratyev /* FreeBSD <= 12 compat shims */
7519758786SVladimir Kondratyev #define	hid_report_size(buf, len, kind, id)	\
7619758786SVladimir Kondratyev 	hid_report_size_max(buf, len, kind, id)
7719758786SVladimir Kondratyev static __inline uint32_t
7819758786SVladimir Kondratyev hid_get_data_unsigned(const uint8_t *buf, hid_size_t len,
7919758786SVladimir Kondratyev     struct hid_location *loc)
8019758786SVladimir Kondratyev {
8119758786SVladimir Kondratyev 	return (hid_get_udata(buf, len, loc));
8219758786SVladimir Kondratyev }
8319758786SVladimir Kondratyev static __inline void
8419758786SVladimir Kondratyev hid_put_data_unsigned(uint8_t *buf, hid_size_t len, struct hid_location *loc,
85*62d42655SHans Petter Selasky     unsigned value)
8619758786SVladimir Kondratyev {
8719758786SVladimir Kondratyev 	return (hid_put_udata(buf, len, loc, value));
8819758786SVladimir Kondratyev }
89eead9017SVladimir Kondratyev #endif
9019758786SVladimir Kondratyev 
91ed6d949aSAndrew Thompson struct usb_hid_descriptor *hid_get_descriptor_from_usb(
92ed6d949aSAndrew Thompson 	    struct usb_config_descriptor *cd,
93ed6d949aSAndrew Thompson 	    struct usb_interface_descriptor *id);
94ed6d949aSAndrew Thompson usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
95ed6d949aSAndrew Thompson 	    void **descp, uint16_t *sizep, struct malloc_type *mem,
96ed6d949aSAndrew Thompson 	    uint8_t iface_index);
97a2dd1caaSHans Petter Selasky #endif	/* _KERNEL || _STANDALONE */
9875973647SAndrew Thompson #endif	/* _USB_HID_H_ */
99