xref: /freebsd/sys/dev/hid/hidraw.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _HID_HIDRAW_H
29 #define _HID_HIDRAW_H
30 
31 #include <sys/ioccom.h>
32 
33 #define	HIDRAW_BUFFER_SIZE	64	/* number of input reports buffered */
34 #define	HID_MAX_DESCRIPTOR_SIZE	4096	/* artificial limit taken from Linux */
35 
36 /* Compatible with usb_gen_descriptor structure */
37 struct hidraw_gen_descriptor {
38 	void   *hgd_data;
39 	uint16_t hgd_lang_id;
40 	uint16_t hgd_maxlen;
41 	uint16_t hgd_actlen;
42 	uint16_t hgd_offset;
43 	uint8_t hgd_config_index;
44 	uint8_t hgd_string_index;
45 	uint8_t hgd_iface_index;
46 	uint8_t hgd_altif_index;
47 	uint8_t hgd_endpt_index;
48 	uint8_t hgd_report_type;
49 	uint8_t reserved[8];
50 };
51 
52 /* Compatible with usb_device_info structure */
53 struct hidraw_device_info {
54 	uint16_t	hdi_product;
55 	uint16_t	hdi_vendor;
56 	uint16_t	hdi_version;
57 	uint8_t		occupied[18];	/* by usb_device_info */
58 	uint16_t	hdi_bustype;
59 	uint8_t		reserved[14];	/* leave space for the future */
60 	char		hdi_name[128];
61 	char		hdi_phys[128];
62 	char		hdi_uniq[64];
63 	char		hdi_release[8];	/* decrypted USB bcdDevice */
64 };
65 
66 struct hidraw_report_descriptor {
67 	uint32_t	size;
68 	uint8_t		value[HID_MAX_DESCRIPTOR_SIZE];
69 };
70 
71 struct hidraw_devinfo {
72 	uint32_t	bustype;
73 	int16_t		vendor;
74 	int16_t		product;
75 };
76 
77 /* FreeBSD uhid(4)-compatible ioctl interface */
78 #define	HIDRAW_GET_REPORT_DESC	_IOWR('U', 21, struct hidraw_gen_descriptor)
79 #define	HIDRAW_SET_IMMED	_IOW ('U', 22, int)
80 #define	HIDRAW_GET_REPORT	_IOWR('U', 23, struct hidraw_gen_descriptor)
81 #define	HIDRAW_SET_REPORT	_IOW ('U', 24, struct hidraw_gen_descriptor)
82 #define	HIDRAW_GET_REPORT_ID	_IOR ('U', 25, int)
83 #define	HIDRAW_SET_REPORT_DESC	_IOW ('U', 26, struct hidraw_gen_descriptor)
84 #define	HIDRAW_GET_DEVICEINFO	_IOR ('U', 112, struct hidraw_device_info)
85 
86 /* Linux hidraw-compatible ioctl interface */
87 #define	HIDIOCGRDESCSIZE	_IOR('U', 30, int)
88 #define	HIDIOCGRDESC		_IO ('U', 31)
89 #define	HIDIOCGRAWINFO		_IOR('U', 32, struct hidraw_devinfo)
90 #define	HIDIOCGRAWNAME(len)	_IOC(IOC_OUT,   'U', 33, len)
91 #define	HIDIOCGRAWPHYS(len)	_IOC(IOC_OUT,   'U', 34, len)
92 #define	HIDIOCSFEATURE(len)	_IOC(IOC_IN,    'U', 35, len)
93 #define	HIDIOCGFEATURE(len)	_IOC(IOC_INOUT, 'U', 36, len)
94 #define	HIDIOCGRAWUNIQ(len)	_IOC(IOC_OUT,   'U', 37, len)
95 
96 #endif	/* _HID_HIDRAW_H */
97