xref: /linux/include/uapi/linux/uhid.h (revision e2be04c7)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 #ifndef __UHID_H_
3 #define __UHID_H_
4 
5 /*
6  * User-space I/O driver support for HID subsystem
7  * Copyright (c) 2012 David Herrmann
8  */
9 
10 /*
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the Free
13  * Software Foundation; either version 2 of the License, or (at your option)
14  * any later version.
15  */
16 
17 /*
18  * Public header for user-space communication. We try to keep every structure
19  * aligned but to be safe we also use __attribute__((__packed__)). Therefore,
20  * the communication should be ABI compatible even between architectures.
21  */
22 
23 #include <linux/input.h>
24 #include <linux/types.h>
25 #include <linux/hid.h>
26 
27 enum uhid_event_type {
28 	__UHID_LEGACY_CREATE,
29 	UHID_DESTROY,
30 	UHID_START,
31 	UHID_STOP,
32 	UHID_OPEN,
33 	UHID_CLOSE,
34 	UHID_OUTPUT,
35 	__UHID_LEGACY_OUTPUT_EV,
36 	__UHID_LEGACY_INPUT,
37 	UHID_GET_REPORT,
38 	UHID_GET_REPORT_REPLY,
39 	UHID_CREATE2,
40 	UHID_INPUT2,
41 	UHID_SET_REPORT,
42 	UHID_SET_REPORT_REPLY,
43 };
44 
45 struct uhid_create2_req {
46 	__u8 name[128];
47 	__u8 phys[64];
48 	__u8 uniq[64];
49 	__u16 rd_size;
50 	__u16 bus;
51 	__u32 vendor;
52 	__u32 product;
53 	__u32 version;
54 	__u32 country;
55 	__u8 rd_data[HID_MAX_DESCRIPTOR_SIZE];
56 } __attribute__((__packed__));
57 
58 enum uhid_dev_flag {
59 	UHID_DEV_NUMBERED_FEATURE_REPORTS			= (1ULL << 0),
60 	UHID_DEV_NUMBERED_OUTPUT_REPORTS			= (1ULL << 1),
61 	UHID_DEV_NUMBERED_INPUT_REPORTS				= (1ULL << 2),
62 };
63 
64 struct uhid_start_req {
65 	__u64 dev_flags;
66 };
67 
68 #define UHID_DATA_MAX 4096
69 
70 enum uhid_report_type {
71 	UHID_FEATURE_REPORT,
72 	UHID_OUTPUT_REPORT,
73 	UHID_INPUT_REPORT,
74 };
75 
76 struct uhid_input2_req {
77 	__u16 size;
78 	__u8 data[UHID_DATA_MAX];
79 } __attribute__((__packed__));
80 
81 struct uhid_output_req {
82 	__u8 data[UHID_DATA_MAX];
83 	__u16 size;
84 	__u8 rtype;
85 } __attribute__((__packed__));
86 
87 struct uhid_get_report_req {
88 	__u32 id;
89 	__u8 rnum;
90 	__u8 rtype;
91 } __attribute__((__packed__));
92 
93 struct uhid_get_report_reply_req {
94 	__u32 id;
95 	__u16 err;
96 	__u16 size;
97 	__u8 data[UHID_DATA_MAX];
98 } __attribute__((__packed__));
99 
100 struct uhid_set_report_req {
101 	__u32 id;
102 	__u8 rnum;
103 	__u8 rtype;
104 	__u16 size;
105 	__u8 data[UHID_DATA_MAX];
106 } __attribute__((__packed__));
107 
108 struct uhid_set_report_reply_req {
109 	__u32 id;
110 	__u16 err;
111 } __attribute__((__packed__));
112 
113 /*
114  * Compat Layer
115  * All these commands and requests are obsolete. You should avoid using them in
116  * new code. We support them for backwards-compatibility, but you might not get
117  * access to new feature in case you use them.
118  */
119 
120 enum uhid_legacy_event_type {
121 	UHID_CREATE			= __UHID_LEGACY_CREATE,
122 	UHID_OUTPUT_EV			= __UHID_LEGACY_OUTPUT_EV,
123 	UHID_INPUT			= __UHID_LEGACY_INPUT,
124 	UHID_FEATURE			= UHID_GET_REPORT,
125 	UHID_FEATURE_ANSWER		= UHID_GET_REPORT_REPLY,
126 };
127 
128 /* Obsolete! Use UHID_CREATE2. */
129 struct uhid_create_req {
130 	__u8 name[128];
131 	__u8 phys[64];
132 	__u8 uniq[64];
133 	__u8 __user *rd_data;
134 	__u16 rd_size;
135 
136 	__u16 bus;
137 	__u32 vendor;
138 	__u32 product;
139 	__u32 version;
140 	__u32 country;
141 } __attribute__((__packed__));
142 
143 /* Obsolete! Use UHID_INPUT2. */
144 struct uhid_input_req {
145 	__u8 data[UHID_DATA_MAX];
146 	__u16 size;
147 } __attribute__((__packed__));
148 
149 /* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */
150 struct uhid_output_ev_req {
151 	__u16 type;
152 	__u16 code;
153 	__s32 value;
154 } __attribute__((__packed__));
155 
156 /* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */
157 struct uhid_feature_req {
158 	__u32 id;
159 	__u8 rnum;
160 	__u8 rtype;
161 } __attribute__((__packed__));
162 
163 /* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */
164 struct uhid_feature_answer_req {
165 	__u32 id;
166 	__u16 err;
167 	__u16 size;
168 	__u8 data[UHID_DATA_MAX];
169 } __attribute__((__packed__));
170 
171 /*
172  * UHID Events
173  * All UHID events from and to the kernel are encoded as "struct uhid_event".
174  * The "type" field contains a UHID_* type identifier. All payload depends on
175  * that type and can be accessed via ev->u.XYZ accordingly.
176  * If user-space writes short events, they're extended with 0s by the kernel. If
177  * the kernel writes short events, user-space shall extend them with 0s.
178  */
179 
180 struct uhid_event {
181 	__u32 type;
182 
183 	union {
184 		struct uhid_create_req create;
185 		struct uhid_input_req input;
186 		struct uhid_output_req output;
187 		struct uhid_output_ev_req output_ev;
188 		struct uhid_feature_req feature;
189 		struct uhid_get_report_req get_report;
190 		struct uhid_feature_answer_req feature_answer;
191 		struct uhid_get_report_reply_req get_report_reply;
192 		struct uhid_create2_req create2;
193 		struct uhid_input2_req input2;
194 		struct uhid_set_report_req set_report;
195 		struct uhid_set_report_reply_req set_report_reply;
196 		struct uhid_start_req start;
197 	} u;
198 } __attribute__((__packed__));
199 
200 #endif /* __UHID_H_ */
201