xref: /freebsd/sys/dev/hid/hidraw.h (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
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 /* Compatible with usb_gen_descriptor structure */
39 struct hidraw_gen_descriptor {
40 	void   *hgd_data;
41 	uint16_t hgd_lang_id;
42 	uint16_t hgd_maxlen;
43 	uint16_t hgd_actlen;
44 	uint16_t hgd_offset;
45 	uint8_t hgd_config_index;
46 	uint8_t hgd_string_index;
47 	uint8_t hgd_iface_index;
48 	uint8_t hgd_altif_index;
49 	uint8_t hgd_endpt_index;
50 	uint8_t hgd_report_type;
51 	uint8_t reserved[8];
52 };
53 
54 struct hidraw_report_descriptor {
55 	uint32_t	size;
56 	uint8_t		value[HID_MAX_DESCRIPTOR_SIZE];
57 };
58 
59 struct hidraw_devinfo {
60 	uint32_t	bustype;
61 	int16_t		vendor;
62 	int16_t		product;
63 };
64 
65 /* FreeBSD uhid(4)-compatible ioctl interface */
66 #define	HIDRAW_GET_REPORT_DESC	_IOWR('U', 21, struct hidraw_gen_descriptor)
67 #define	HIDRAW_SET_IMMED	_IOW ('U', 22, int)
68 #define	HIDRAW_GET_REPORT	_IOWR('U', 23, struct hidraw_gen_descriptor)
69 #define	HIDRAW_SET_REPORT	_IOW ('U', 24, struct hidraw_gen_descriptor)
70 #define	HIDRAW_GET_REPORT_ID	_IOR ('U', 25, int)
71 #define	HIDRAW_SET_REPORT_DESC	_IOW ('U', 26, struct hidraw_gen_descriptor)
72 
73 /* Linux hidraw-compatible ioctl interface */
74 #define	HIDIOCGRDESCSIZE	_IOR('U', 30, int)
75 #define	HIDIOCGRDESC		_IO ('U', 31)
76 #define	HIDIOCGRAWINFO		_IOR('U', 32, struct hidraw_devinfo)
77 #define	HIDIOCGRAWNAME(len)	_IOC(IOC_OUT,   'U', 33, len)
78 #define	HIDIOCGRAWPHYS(len)	_IOC(IOC_OUT,   'U', 34, len)
79 #define	HIDIOCSFEATURE(len)	_IOC(IOC_IN,    'U', 35, len)
80 #define	HIDIOCGFEATURE(len)	_IOC(IOC_INOUT, 'U', 36, len)
81 #define	HIDIOCGRAWUNIQ(len)	_IOC(IOC_OUT,   'U', 37, len)
82 
83 #endif	/* _HID_HIDRAW_H */
84