xref: /freebsd/sys/dev/hid/hidraw.h (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
28  */
29 
30 #ifndef _HID_HIDRAW_H
31 #define _HID_HIDRAW_H
32 
33 #include <sys/ioccom.h>
34 
35 #define	HIDRAW_BUFFER_SIZE	64	/* number of input reports buffered */
36 #define	HID_MAX_DESCRIPTOR_SIZE	4096	/* artificial limit taken from Linux */
37 
38 /*
39  * Align IOCTL structures to hide differences when running 32-bit
40  * programs under 64-bit kernels:
41  */
42 #ifdef COMPAT_32BIT
43 #define	HIDRAW_IOCTL_STRUCT_ALIGN(n) __aligned(n)
44 #else
45 #define	HIDRAW_IOCTL_STRUCT_ALIGN(n)
46 #endif
47 
48 /* Compatible with usb_gen_descriptor structure */
49 struct hidraw_gen_descriptor {
50 #ifdef COMPAT_32BIT
51 	uint64_t hgd_data;
52 #else
53 	void   *hgd_data;
54 #endif
55 	uint16_t hgd_lang_id;
56 	uint16_t hgd_maxlen;
57 	uint16_t hgd_actlen;
58 	uint16_t hgd_offset;
59 	uint8_t hgd_config_index;
60 	uint8_t hgd_string_index;
61 	uint8_t hgd_iface_index;
62 	uint8_t hgd_altif_index;
63 	uint8_t hgd_endpt_index;
64 	uint8_t hgd_report_type;
65 	uint8_t reserved[8];
66 } HIDRAW_IOCTL_STRUCT_ALIGN(8);
67 
68 struct hidraw_report_descriptor {
69 	uint32_t	size;
70 	uint8_t		value[HID_MAX_DESCRIPTOR_SIZE];
71 } HIDRAW_IOCTL_STRUCT_ALIGN(4);
72 
73 struct hidraw_devinfo {
74 	uint32_t	bustype;
75 	int16_t		vendor;
76 	int16_t		product;
77 } HIDRAW_IOCTL_STRUCT_ALIGN(4);
78 
79 /* FreeBSD uhid(4)-compatible ioctl interface */
80 #define	HIDRAW_GET_REPORT_DESC	_IOWR('U', 21, struct hidraw_gen_descriptor)
81 #define	HIDRAW_SET_IMMED	_IOW ('U', 22, int)
82 #define	HIDRAW_GET_REPORT	_IOWR('U', 23, struct hidraw_gen_descriptor)
83 #define	HIDRAW_SET_REPORT	_IOW ('U', 24, struct hidraw_gen_descriptor)
84 #define	HIDRAW_GET_REPORT_ID	_IOR ('U', 25, int)
85 #define	HIDRAW_SET_REPORT_DESC	_IOW ('U', 26, struct hidraw_gen_descriptor)
86 
87 /* Linux hidraw-compatible ioctl interface */
88 #define	HIDIOCGRDESCSIZE	_IOR('U', 30, int)
89 #define	HIDIOCGRDESC		_IO ('U', 31)
90 #define	HIDIOCGRAWINFO		_IOR('U', 32, struct hidraw_devinfo)
91 #define	HIDIOCGRAWNAME(len)	_IOC(IOC_OUT,   'U', 33, len)
92 #define	HIDIOCGRAWPHYS(len)	_IOC(IOC_OUT,   'U', 34, len)
93 #define	HIDIOCSFEATURE(len)	_IOC(IOC_IN,    'U', 35, len)
94 #define	HIDIOCGFEATURE(len)	_IOC(IOC_INOUT, 'U', 36, len)
95 #define	HIDIOCGRAWUNIQ(len)	_IOC(IOC_OUT,   'U', 37, len)
96 
97 #endif	/* _HID_HIDRAW_H */
98