blob: 116536eeae62ac0a0b0b6f8da1c5ae7179cd4f1a [file] [log] [blame]
David Herrmannace3d862012-06-10 15:16:14 +02001#ifndef __UHID_H_
2#define __UHID_H_
3
4/*
5 * User-space I/O driver support for HID subsystem
6 * Copyright (c) 2012 David Herrmann
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16/*
17 * Public header for user-space communication. We try to keep every structure
18 * aligned but to be safe we also use __attribute__((__packed__)). Therefore,
19 * the communication should be ABI compatible even between architectures.
20 */
21
22#include <linux/input.h>
23#include <linux/types.h>
Petri Gynther45226432014-03-24 13:50:01 -070024#include <linux/hid.h>
David Herrmannace3d862012-06-10 15:16:14 +020025
26enum uhid_event_type {
David Herrmann50598e72014-07-29 17:14:22 +020027 __UHID_LEGACY_CREATE,
David Herrmannd365c6c2012-06-10 15:16:18 +020028 UHID_DESTROY,
David Herrmannec4b7de2012-06-10 15:16:21 +020029 UHID_START,
30 UHID_STOP,
David Herrmanne7191472012-06-10 15:16:22 +020031 UHID_OPEN,
32 UHID_CLOSE,
David Herrmann3b3baa82012-06-10 15:16:24 +020033 UHID_OUTPUT,
David Herrmann50598e72014-07-29 17:14:22 +020034 __UHID_LEGACY_OUTPUT_EV,
35 __UHID_LEGACY_INPUT,
36 UHID_GET_REPORT,
37 UHID_GET_REPORT_REPLY,
Petri Gynther45226432014-03-24 13:50:01 -070038 UHID_CREATE2,
39 UHID_INPUT2,
David Herrmannace3d862012-06-10 15:16:14 +020040};
41
Petri Gynther45226432014-03-24 13:50:01 -070042struct uhid_create2_req {
43 __u8 name[128];
44 __u8 phys[64];
45 __u8 uniq[64];
46 __u16 rd_size;
47 __u16 bus;
48 __u32 vendor;
49 __u32 product;
50 __u32 version;
51 __u32 country;
52 __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE];
53} __attribute__((__packed__));
54
David Herrmann5e87a362012-06-10 15:16:19 +020055#define UHID_DATA_MAX 4096
56
David Herrmann3b3baa82012-06-10 15:16:24 +020057enum uhid_report_type {
58 UHID_FEATURE_REPORT,
59 UHID_OUTPUT_REPORT,
60 UHID_INPUT_REPORT,
61};
62
Petri Gynther45226432014-03-24 13:50:01 -070063struct uhid_input2_req {
64 __u16 size;
65 __u8 data[UHID_DATA_MAX];
66} __attribute__((__packed__));
67
David Herrmann3b3baa82012-06-10 15:16:24 +020068struct uhid_output_req {
69 __u8 data[UHID_DATA_MAX];
70 __u16 size;
71 __u8 rtype;
72} __attribute__((__packed__));
73
David Herrmann50598e72014-07-29 17:14:22 +020074struct uhid_get_report_req {
75 __u32 id;
76 __u8 rnum;
77 __u8 rtype;
78} __attribute__((__packed__));
79
80struct uhid_get_report_reply_req {
81 __u32 id;
82 __u16 err;
83 __u16 size;
84 __u8 data[UHID_DATA_MAX];
85} __attribute__((__packed__));
86
87/*
88 * Compat Layer
89 * All these commands and requests are obsolete. You should avoid using them in
90 * new code. We support them for backwards-compatibility, but you might not get
91 * access to new feature in case you use them.
92 */
93
94enum uhid_legacy_event_type {
95 UHID_CREATE = __UHID_LEGACY_CREATE,
96 UHID_OUTPUT_EV = __UHID_LEGACY_OUTPUT_EV,
97 UHID_INPUT = __UHID_LEGACY_INPUT,
98 UHID_FEATURE = UHID_GET_REPORT,
99 UHID_FEATURE_ANSWER = UHID_GET_REPORT_REPLY,
100};
101
102/* Obsolete! Use UHID_CREATE2. */
103struct uhid_create_req {
104 __u8 name[128];
105 __u8 phys[64];
106 __u8 uniq[64];
107 __u8 __user *rd_data;
108 __u16 rd_size;
109
110 __u16 bus;
111 __u32 vendor;
112 __u32 product;
113 __u32 version;
114 __u32 country;
115} __attribute__((__packed__));
116
117/* Obsolete! Use UHID_INPUT2. */
118struct uhid_input_req {
119 __u8 data[UHID_DATA_MAX];
120 __u16 size;
121} __attribute__((__packed__));
122
123/* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */
David Herrmannf80e1362012-06-10 15:16:23 +0200124struct uhid_output_ev_req {
125 __u16 type;
126 __u16 code;
127 __s32 value;
128} __attribute__((__packed__));
129
David Herrmannfa71f322014-07-29 17:14:21 +0200130/* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */
David Herrmannfcfcf0d2012-06-10 15:16:25 +0200131struct uhid_feature_req {
132 __u32 id;
133 __u8 rnum;
134 __u8 rtype;
135} __attribute__((__packed__));
136
David Herrmannfa71f322014-07-29 17:14:21 +0200137/* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */
David Herrmannfcfcf0d2012-06-10 15:16:25 +0200138struct uhid_feature_answer_req {
139 __u32 id;
140 __u16 err;
141 __u16 size;
142 __u8 data[UHID_DATA_MAX];
David Herrmannfee5dfe2012-12-17 13:20:43 +0100143} __attribute__((__packed__));
David Herrmannfcfcf0d2012-06-10 15:16:25 +0200144
David Herrmann50598e72014-07-29 17:14:22 +0200145/*
146 * UHID Events
147 * All UHID events from and to the kernel are encoded as "struct uhid_event".
148 * The "type" field contains a UHID_* type identifier. All payload depends on
149 * that type and can be accessed via ev->u.XYZ accordingly.
150 * If user-space writes short events, they're extended with 0s by the kernel. If
151 * the kernel writes short events, user-space shall extend them with 0s.
152 */
David Herrmannfa71f322014-07-29 17:14:21 +0200153
David Herrmannace3d862012-06-10 15:16:14 +0200154struct uhid_event {
155 __u32 type;
David Herrmannd365c6c2012-06-10 15:16:18 +0200156
157 union {
158 struct uhid_create_req create;
David Herrmann5e87a362012-06-10 15:16:19 +0200159 struct uhid_input_req input;
David Herrmann3b3baa82012-06-10 15:16:24 +0200160 struct uhid_output_req output;
David Herrmannf80e1362012-06-10 15:16:23 +0200161 struct uhid_output_ev_req output_ev;
David Herrmannfcfcf0d2012-06-10 15:16:25 +0200162 struct uhid_feature_req feature;
David Herrmannfa71f322014-07-29 17:14:21 +0200163 struct uhid_get_report_req get_report;
David Herrmannfcfcf0d2012-06-10 15:16:25 +0200164 struct uhid_feature_answer_req feature_answer;
David Herrmannfa71f322014-07-29 17:14:21 +0200165 struct uhid_get_report_reply_req get_report_reply;
Petri Gynther45226432014-03-24 13:50:01 -0700166 struct uhid_create2_req create2;
167 struct uhid_input2_req input2;
David Herrmannd365c6c2012-06-10 15:16:18 +0200168 } u;
David Herrmannace3d862012-06-10 15:16:14 +0200169} __attribute__((__packed__));
170
171#endif /* __UHID_H_ */