xref: /linux/include/uapi/linux/hiddev.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  *  Copyright (c) 1999-2000 Vojtech Pavlik
4607ca46eSDavid Howells  *
5607ca46eSDavid Howells  *  Sponsored by SuSE
6607ca46eSDavid Howells  */
7607ca46eSDavid Howells /*
8607ca46eSDavid Howells  * This program is free software; you can redistribute it and/or modify
9607ca46eSDavid Howells  * it under the terms of the GNU General Public License as published by
10607ca46eSDavid Howells  * the Free Software Foundation; either version 2 of the License, or
11607ca46eSDavid Howells  * (at your option) any later version.
12607ca46eSDavid Howells  *
13607ca46eSDavid Howells  * This program is distributed in the hope that it will be useful,
14607ca46eSDavid Howells  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15607ca46eSDavid Howells  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16607ca46eSDavid Howells  * GNU General Public License for more details.
17607ca46eSDavid Howells  *
18607ca46eSDavid Howells  * You should have received a copy of the GNU General Public License
19607ca46eSDavid Howells  * along with this program; if not, write to the Free Software
20607ca46eSDavid Howells  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21607ca46eSDavid Howells  *
22607ca46eSDavid Howells  * Should you need to contact me, the author, you can do so either by
23607ca46eSDavid Howells  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
24607ca46eSDavid Howells  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
25607ca46eSDavid Howells  */
26607ca46eSDavid Howells #ifndef _UAPI_HIDDEV_H
27607ca46eSDavid Howells #define _UAPI_HIDDEV_H
28607ca46eSDavid Howells 
29607ca46eSDavid Howells 
30607ca46eSDavid Howells 
31607ca46eSDavid Howells #include <linux/types.h>
32607ca46eSDavid Howells 
33607ca46eSDavid Howells /*
34607ca46eSDavid Howells  * The event structure itself
35607ca46eSDavid Howells  */
36607ca46eSDavid Howells 
37607ca46eSDavid Howells struct hiddev_event {
38607ca46eSDavid Howells 	unsigned hid;
39607ca46eSDavid Howells 	signed int value;
40607ca46eSDavid Howells };
41607ca46eSDavid Howells 
42607ca46eSDavid Howells struct hiddev_devinfo {
43607ca46eSDavid Howells 	__u32 bustype;
44607ca46eSDavid Howells 	__u32 busnum;
45607ca46eSDavid Howells 	__u32 devnum;
46607ca46eSDavid Howells 	__u32 ifnum;
47607ca46eSDavid Howells 	__s16 vendor;
48607ca46eSDavid Howells 	__s16 product;
49607ca46eSDavid Howells 	__s16 version;
50607ca46eSDavid Howells 	__u32 num_applications;
51607ca46eSDavid Howells };
52607ca46eSDavid Howells 
53607ca46eSDavid Howells struct hiddev_collection_info {
54607ca46eSDavid Howells 	__u32 index;
55607ca46eSDavid Howells 	__u32 type;
56607ca46eSDavid Howells 	__u32 usage;
57607ca46eSDavid Howells 	__u32 level;
58607ca46eSDavid Howells };
59607ca46eSDavid Howells 
60607ca46eSDavid Howells #define HID_STRING_SIZE 256
61607ca46eSDavid Howells struct hiddev_string_descriptor {
62607ca46eSDavid Howells 	__s32 index;
63607ca46eSDavid Howells 	char value[HID_STRING_SIZE];
64607ca46eSDavid Howells };
65607ca46eSDavid Howells 
66607ca46eSDavid Howells struct hiddev_report_info {
67607ca46eSDavid Howells 	__u32 report_type;
68607ca46eSDavid Howells 	__u32 report_id;
69607ca46eSDavid Howells 	__u32 num_fields;
70607ca46eSDavid Howells };
71607ca46eSDavid Howells 
72607ca46eSDavid Howells /* To do a GUSAGE/SUSAGE, fill in at least usage_code,  report_type and
73607ca46eSDavid Howells  * report_id.  Set report_id to REPORT_ID_UNKNOWN if the rest of the fields
74607ca46eSDavid Howells  * are unknown.  Otherwise use a usage_ref struct filled in from a previous
75607ca46eSDavid Howells  * successful GUSAGE call to save time.  To actually send a value to the
76607ca46eSDavid Howells  * device, perform a SUSAGE first, followed by a SREPORT.  An INITREPORT or a
77607ca46eSDavid Howells  * GREPORT isn't necessary for a GUSAGE to return valid data.
78607ca46eSDavid Howells  */
79607ca46eSDavid Howells #define HID_REPORT_ID_UNKNOWN 0xffffffff
80607ca46eSDavid Howells #define HID_REPORT_ID_FIRST   0x00000100
81607ca46eSDavid Howells #define HID_REPORT_ID_NEXT    0x00000200
82607ca46eSDavid Howells #define HID_REPORT_ID_MASK    0x000000ff
83607ca46eSDavid Howells #define HID_REPORT_ID_MAX     0x000000ff
84607ca46eSDavid Howells 
85607ca46eSDavid Howells #define HID_REPORT_TYPE_INPUT	1
86607ca46eSDavid Howells #define HID_REPORT_TYPE_OUTPUT	2
87607ca46eSDavid Howells #define HID_REPORT_TYPE_FEATURE	3
88607ca46eSDavid Howells #define HID_REPORT_TYPE_MIN     1
89607ca46eSDavid Howells #define HID_REPORT_TYPE_MAX     3
90607ca46eSDavid Howells 
91607ca46eSDavid Howells struct hiddev_field_info {
92607ca46eSDavid Howells 	__u32 report_type;
93607ca46eSDavid Howells 	__u32 report_id;
94607ca46eSDavid Howells 	__u32 field_index;
95607ca46eSDavid Howells 	__u32 maxusage;
96607ca46eSDavid Howells 	__u32 flags;
97607ca46eSDavid Howells 	__u32 physical;		/* physical usage for this field */
98607ca46eSDavid Howells 	__u32 logical;		/* logical usage for this field */
99607ca46eSDavid Howells 	__u32 application;		/* application usage for this field */
100607ca46eSDavid Howells 	__s32 logical_minimum;
101607ca46eSDavid Howells 	__s32 logical_maximum;
102607ca46eSDavid Howells 	__s32 physical_minimum;
103607ca46eSDavid Howells 	__s32 physical_maximum;
104607ca46eSDavid Howells 	__u32 unit_exponent;
105607ca46eSDavid Howells 	__u32 unit;
106607ca46eSDavid Howells };
107607ca46eSDavid Howells 
108607ca46eSDavid Howells /* Fill in report_type, report_id and field_index to get the information on a
109607ca46eSDavid Howells  * field.
110607ca46eSDavid Howells  */
111607ca46eSDavid Howells #define HID_FIELD_CONSTANT		0x001
112607ca46eSDavid Howells #define HID_FIELD_VARIABLE		0x002
113607ca46eSDavid Howells #define HID_FIELD_RELATIVE		0x004
114607ca46eSDavid Howells #define HID_FIELD_WRAP			0x008
115607ca46eSDavid Howells #define HID_FIELD_NONLINEAR		0x010
116607ca46eSDavid Howells #define HID_FIELD_NO_PREFERRED		0x020
117607ca46eSDavid Howells #define HID_FIELD_NULL_STATE		0x040
118607ca46eSDavid Howells #define HID_FIELD_VOLATILE		0x080
119607ca46eSDavid Howells #define HID_FIELD_BUFFERED_BYTE		0x100
120607ca46eSDavid Howells 
121607ca46eSDavid Howells struct hiddev_usage_ref {
122607ca46eSDavid Howells 	__u32 report_type;
123607ca46eSDavid Howells 	__u32 report_id;
124607ca46eSDavid Howells 	__u32 field_index;
125607ca46eSDavid Howells 	__u32 usage_index;
126607ca46eSDavid Howells 	__u32 usage_code;
127607ca46eSDavid Howells 	__s32 value;
128607ca46eSDavid Howells };
129607ca46eSDavid Howells 
130607ca46eSDavid Howells /* hiddev_usage_ref_multi is used for sending multiple bytes to a control.
131607ca46eSDavid Howells  * It really manifests itself as setting the value of consecutive usages */
132607ca46eSDavid Howells #define HID_MAX_MULTI_USAGES 1024
133607ca46eSDavid Howells struct hiddev_usage_ref_multi {
134607ca46eSDavid Howells 	struct hiddev_usage_ref uref;
135607ca46eSDavid Howells 	__u32 num_values;
136607ca46eSDavid Howells 	__s32 values[HID_MAX_MULTI_USAGES];
137607ca46eSDavid Howells };
138607ca46eSDavid Howells 
139607ca46eSDavid Howells /* FIELD_INDEX_NONE is returned in read() data from the kernel when flags
140607ca46eSDavid Howells  * is set to (HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT) and a new report has
141607ca46eSDavid Howells  * been sent by the device
142607ca46eSDavid Howells  */
143607ca46eSDavid Howells #define HID_FIELD_INDEX_NONE 0xffffffff
144607ca46eSDavid Howells 
145607ca46eSDavid Howells /*
146607ca46eSDavid Howells  * Protocol version.
147607ca46eSDavid Howells  */
148607ca46eSDavid Howells 
149607ca46eSDavid Howells #define HID_VERSION		0x010004
150607ca46eSDavid Howells 
151607ca46eSDavid Howells /*
152607ca46eSDavid Howells  * IOCTLs (0x00 - 0x7f)
153607ca46eSDavid Howells  */
154607ca46eSDavid Howells 
155607ca46eSDavid Howells #define HIDIOCGVERSION		_IOR('H', 0x01, int)
156607ca46eSDavid Howells #define HIDIOCAPPLICATION	_IO('H', 0x02)
157607ca46eSDavid Howells #define HIDIOCGDEVINFO		_IOR('H', 0x03, struct hiddev_devinfo)
158607ca46eSDavid Howells #define HIDIOCGSTRING		_IOR('H', 0x04, struct hiddev_string_descriptor)
159607ca46eSDavid Howells #define HIDIOCINITREPORT	_IO('H', 0x05)
160607ca46eSDavid Howells #define HIDIOCGNAME(len)	_IOC(_IOC_READ, 'H', 0x06, len)
161607ca46eSDavid Howells #define HIDIOCGREPORT		_IOW('H', 0x07, struct hiddev_report_info)
162607ca46eSDavid Howells #define HIDIOCSREPORT		_IOW('H', 0x08, struct hiddev_report_info)
163607ca46eSDavid Howells #define HIDIOCGREPORTINFO	_IOWR('H', 0x09, struct hiddev_report_info)
164607ca46eSDavid Howells #define HIDIOCGFIELDINFO	_IOWR('H', 0x0A, struct hiddev_field_info)
165607ca46eSDavid Howells #define HIDIOCGUSAGE		_IOWR('H', 0x0B, struct hiddev_usage_ref)
166607ca46eSDavid Howells #define HIDIOCSUSAGE		_IOW('H', 0x0C, struct hiddev_usage_ref)
167607ca46eSDavid Howells #define HIDIOCGUCODE		_IOWR('H', 0x0D, struct hiddev_usage_ref)
168607ca46eSDavid Howells #define HIDIOCGFLAG		_IOR('H', 0x0E, int)
169607ca46eSDavid Howells #define HIDIOCSFLAG		_IOW('H', 0x0F, int)
170607ca46eSDavid Howells #define HIDIOCGCOLLECTIONINDEX	_IOW('H', 0x10, struct hiddev_usage_ref)
171607ca46eSDavid Howells #define HIDIOCGCOLLECTIONINFO	_IOWR('H', 0x11, struct hiddev_collection_info)
172607ca46eSDavid Howells #define HIDIOCGPHYS(len)	_IOC(_IOC_READ, 'H', 0x12, len)
173607ca46eSDavid Howells 
174607ca46eSDavid Howells /* For writing/reading to multiple/consecutive usages */
175607ca46eSDavid Howells #define HIDIOCGUSAGES		_IOWR('H', 0x13, struct hiddev_usage_ref_multi)
176607ca46eSDavid Howells #define HIDIOCSUSAGES		_IOW('H', 0x14, struct hiddev_usage_ref_multi)
177607ca46eSDavid Howells 
178607ca46eSDavid Howells /*
179607ca46eSDavid Howells  * Flags to be used in HIDIOCSFLAG
180607ca46eSDavid Howells  */
181607ca46eSDavid Howells #define HIDDEV_FLAG_UREF	0x1
182607ca46eSDavid Howells #define HIDDEV_FLAG_REPORT	0x2
183607ca46eSDavid Howells #define HIDDEV_FLAGS		0x3
184607ca46eSDavid Howells 
185607ca46eSDavid Howells /* To traverse the input report descriptor info for a HID device, perform the
186607ca46eSDavid Howells  * following:
187607ca46eSDavid Howells  *
188607ca46eSDavid Howells  * rinfo.report_type = HID_REPORT_TYPE_INPUT;
189607ca46eSDavid Howells  * rinfo.report_id = HID_REPORT_ID_FIRST;
190607ca46eSDavid Howells  * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
191607ca46eSDavid Howells  *
192607ca46eSDavid Howells  * while (ret >= 0) {
193607ca46eSDavid Howells  * 	for (i = 0; i < rinfo.num_fields; i++) {
194607ca46eSDavid Howells  * 		finfo.report_type = rinfo.report_type;
195607ca46eSDavid Howells  * 		finfo.report_id = rinfo.report_id;
196607ca46eSDavid Howells  * 		finfo.field_index = i;
197607ca46eSDavid Howells  * 		ioctl(fd, HIDIOCGFIELDINFO, &finfo);
198607ca46eSDavid Howells  * 		for (j = 0; j < finfo.maxusage; j++) {
199607ca46eSDavid Howells  * 			uref.report_type = rinfo.report_type;
200607ca46eSDavid Howells  * 			uref.report_id = rinfo.report_id;
201607ca46eSDavid Howells  * 			uref.field_index = i;
202607ca46eSDavid Howells  * 			uref.usage_index = j;
203607ca46eSDavid Howells  * 			ioctl(fd, HIDIOCGUCODE, &uref);
204607ca46eSDavid Howells  * 			ioctl(fd, HIDIOCGUSAGE, &uref);
205607ca46eSDavid Howells  * 		}
206607ca46eSDavid Howells  * 	}
207607ca46eSDavid Howells  * 	rinfo.report_id |= HID_REPORT_ID_NEXT;
208607ca46eSDavid Howells  * 	ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
209607ca46eSDavid Howells  * }
210607ca46eSDavid Howells  */
211607ca46eSDavid Howells 
212607ca46eSDavid Howells 
213607ca46eSDavid Howells #endif /* _UAPI_HIDDEV_H */
214