xref: /openbmc/linux/include/uapi/linux/hiddev.h (revision e2be04c7)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 /*
3  *  Copyright (c) 1999-2000 Vojtech Pavlik
4  *
5  *  Sponsored by SuSE
6  */
7 /*
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * Should you need to contact me, the author, you can do so either by
23  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
24  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
25  */
26 #ifndef _UAPI_HIDDEV_H
27 #define _UAPI_HIDDEV_H
28 
29 
30 
31 #include <linux/types.h>
32 
33 /*
34  * The event structure itself
35  */
36 
37 struct hiddev_event {
38 	unsigned hid;
39 	signed int value;
40 };
41 
42 struct hiddev_devinfo {
43 	__u32 bustype;
44 	__u32 busnum;
45 	__u32 devnum;
46 	__u32 ifnum;
47 	__s16 vendor;
48 	__s16 product;
49 	__s16 version;
50 	__u32 num_applications;
51 };
52 
53 struct hiddev_collection_info {
54 	__u32 index;
55 	__u32 type;
56 	__u32 usage;
57 	__u32 level;
58 };
59 
60 #define HID_STRING_SIZE 256
61 struct hiddev_string_descriptor {
62 	__s32 index;
63 	char value[HID_STRING_SIZE];
64 };
65 
66 struct hiddev_report_info {
67 	__u32 report_type;
68 	__u32 report_id;
69 	__u32 num_fields;
70 };
71 
72 /* To do a GUSAGE/SUSAGE, fill in at least usage_code,  report_type and
73  * report_id.  Set report_id to REPORT_ID_UNKNOWN if the rest of the fields
74  * are unknown.  Otherwise use a usage_ref struct filled in from a previous
75  * successful GUSAGE call to save time.  To actually send a value to the
76  * device, perform a SUSAGE first, followed by a SREPORT.  An INITREPORT or a
77  * GREPORT isn't necessary for a GUSAGE to return valid data.
78  */
79 #define HID_REPORT_ID_UNKNOWN 0xffffffff
80 #define HID_REPORT_ID_FIRST   0x00000100
81 #define HID_REPORT_ID_NEXT    0x00000200
82 #define HID_REPORT_ID_MASK    0x000000ff
83 #define HID_REPORT_ID_MAX     0x000000ff
84 
85 #define HID_REPORT_TYPE_INPUT	1
86 #define HID_REPORT_TYPE_OUTPUT	2
87 #define HID_REPORT_TYPE_FEATURE	3
88 #define HID_REPORT_TYPE_MIN     1
89 #define HID_REPORT_TYPE_MAX     3
90 
91 struct hiddev_field_info {
92 	__u32 report_type;
93 	__u32 report_id;
94 	__u32 field_index;
95 	__u32 maxusage;
96 	__u32 flags;
97 	__u32 physical;		/* physical usage for this field */
98 	__u32 logical;		/* logical usage for this field */
99 	__u32 application;		/* application usage for this field */
100 	__s32 logical_minimum;
101 	__s32 logical_maximum;
102 	__s32 physical_minimum;
103 	__s32 physical_maximum;
104 	__u32 unit_exponent;
105 	__u32 unit;
106 };
107 
108 /* Fill in report_type, report_id and field_index to get the information on a
109  * field.
110  */
111 #define HID_FIELD_CONSTANT		0x001
112 #define HID_FIELD_VARIABLE		0x002
113 #define HID_FIELD_RELATIVE		0x004
114 #define HID_FIELD_WRAP			0x008
115 #define HID_FIELD_NONLINEAR		0x010
116 #define HID_FIELD_NO_PREFERRED		0x020
117 #define HID_FIELD_NULL_STATE		0x040
118 #define HID_FIELD_VOLATILE		0x080
119 #define HID_FIELD_BUFFERED_BYTE		0x100
120 
121 struct hiddev_usage_ref {
122 	__u32 report_type;
123 	__u32 report_id;
124 	__u32 field_index;
125 	__u32 usage_index;
126 	__u32 usage_code;
127 	__s32 value;
128 };
129 
130 /* hiddev_usage_ref_multi is used for sending multiple bytes to a control.
131  * It really manifests itself as setting the value of consecutive usages */
132 #define HID_MAX_MULTI_USAGES 1024
133 struct hiddev_usage_ref_multi {
134 	struct hiddev_usage_ref uref;
135 	__u32 num_values;
136 	__s32 values[HID_MAX_MULTI_USAGES];
137 };
138 
139 /* FIELD_INDEX_NONE is returned in read() data from the kernel when flags
140  * is set to (HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT) and a new report has
141  * been sent by the device
142  */
143 #define HID_FIELD_INDEX_NONE 0xffffffff
144 
145 /*
146  * Protocol version.
147  */
148 
149 #define HID_VERSION		0x010004
150 
151 /*
152  * IOCTLs (0x00 - 0x7f)
153  */
154 
155 #define HIDIOCGVERSION		_IOR('H', 0x01, int)
156 #define HIDIOCAPPLICATION	_IO('H', 0x02)
157 #define HIDIOCGDEVINFO		_IOR('H', 0x03, struct hiddev_devinfo)
158 #define HIDIOCGSTRING		_IOR('H', 0x04, struct hiddev_string_descriptor)
159 #define HIDIOCINITREPORT	_IO('H', 0x05)
160 #define HIDIOCGNAME(len)	_IOC(_IOC_READ, 'H', 0x06, len)
161 #define HIDIOCGREPORT		_IOW('H', 0x07, struct hiddev_report_info)
162 #define HIDIOCSREPORT		_IOW('H', 0x08, struct hiddev_report_info)
163 #define HIDIOCGREPORTINFO	_IOWR('H', 0x09, struct hiddev_report_info)
164 #define HIDIOCGFIELDINFO	_IOWR('H', 0x0A, struct hiddev_field_info)
165 #define HIDIOCGUSAGE		_IOWR('H', 0x0B, struct hiddev_usage_ref)
166 #define HIDIOCSUSAGE		_IOW('H', 0x0C, struct hiddev_usage_ref)
167 #define HIDIOCGUCODE		_IOWR('H', 0x0D, struct hiddev_usage_ref)
168 #define HIDIOCGFLAG		_IOR('H', 0x0E, int)
169 #define HIDIOCSFLAG		_IOW('H', 0x0F, int)
170 #define HIDIOCGCOLLECTIONINDEX	_IOW('H', 0x10, struct hiddev_usage_ref)
171 #define HIDIOCGCOLLECTIONINFO	_IOWR('H', 0x11, struct hiddev_collection_info)
172 #define HIDIOCGPHYS(len)	_IOC(_IOC_READ, 'H', 0x12, len)
173 
174 /* For writing/reading to multiple/consecutive usages */
175 #define HIDIOCGUSAGES		_IOWR('H', 0x13, struct hiddev_usage_ref_multi)
176 #define HIDIOCSUSAGES		_IOW('H', 0x14, struct hiddev_usage_ref_multi)
177 
178 /*
179  * Flags to be used in HIDIOCSFLAG
180  */
181 #define HIDDEV_FLAG_UREF	0x1
182 #define HIDDEV_FLAG_REPORT	0x2
183 #define HIDDEV_FLAGS		0x3
184 
185 /* To traverse the input report descriptor info for a HID device, perform the
186  * following:
187  *
188  * rinfo.report_type = HID_REPORT_TYPE_INPUT;
189  * rinfo.report_id = HID_REPORT_ID_FIRST;
190  * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
191  *
192  * while (ret >= 0) {
193  * 	for (i = 0; i < rinfo.num_fields; i++) {
194  * 		finfo.report_type = rinfo.report_type;
195  * 		finfo.report_id = rinfo.report_id;
196  * 		finfo.field_index = i;
197  * 		ioctl(fd, HIDIOCGFIELDINFO, &finfo);
198  * 		for (j = 0; j < finfo.maxusage; j++) {
199  * 			uref.report_type = rinfo.report_type;
200  * 			uref.report_id = rinfo.report_id;
201  * 			uref.field_index = i;
202  * 			uref.usage_index = j;
203  * 			ioctl(fd, HIDIOCGUCODE, &uref);
204  * 			ioctl(fd, HIDIOCGUSAGE, &uref);
205  * 		}
206  * 	}
207  * 	rinfo.report_id |= HID_REPORT_ID_NEXT;
208  * 	ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
209  * }
210  */
211 
212 
213 #endif /* _UAPI_HIDDEV_H */
214