David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 1 | #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 Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 24 | #include <linux/hid.h> |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 25 | |
| 26 | enum uhid_event_type { |
David Herrmann | 50598e7 | 2014-07-29 17:14:22 +0200 | [diff] [blame] | 27 | __UHID_LEGACY_CREATE, |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 28 | UHID_DESTROY, |
David Herrmann | ec4b7de | 2012-06-10 15:16:21 +0200 | [diff] [blame] | 29 | UHID_START, |
| 30 | UHID_STOP, |
David Herrmann | e719147 | 2012-06-10 15:16:22 +0200 | [diff] [blame] | 31 | UHID_OPEN, |
| 32 | UHID_CLOSE, |
David Herrmann | 3b3baa8 | 2012-06-10 15:16:24 +0200 | [diff] [blame] | 33 | UHID_OUTPUT, |
David Herrmann | 50598e7 | 2014-07-29 17:14:22 +0200 | [diff] [blame] | 34 | __UHID_LEGACY_OUTPUT_EV, |
| 35 | __UHID_LEGACY_INPUT, |
| 36 | UHID_GET_REPORT, |
| 37 | UHID_GET_REPORT_REPLY, |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 38 | UHID_CREATE2, |
| 39 | UHID_INPUT2, |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame^] | 40 | UHID_SET_REPORT, |
| 41 | UHID_SET_REPORT_REPLY, |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 44 | struct uhid_create2_req { |
| 45 | __u8 name[128]; |
| 46 | __u8 phys[64]; |
| 47 | __u8 uniq[64]; |
| 48 | __u16 rd_size; |
| 49 | __u16 bus; |
| 50 | __u32 vendor; |
| 51 | __u32 product; |
| 52 | __u32 version; |
| 53 | __u32 country; |
| 54 | __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE]; |
| 55 | } __attribute__((__packed__)); |
| 56 | |
David Herrmann | 5e87a36 | 2012-06-10 15:16:19 +0200 | [diff] [blame] | 57 | #define UHID_DATA_MAX 4096 |
| 58 | |
David Herrmann | 3b3baa8 | 2012-06-10 15:16:24 +0200 | [diff] [blame] | 59 | enum uhid_report_type { |
| 60 | UHID_FEATURE_REPORT, |
| 61 | UHID_OUTPUT_REPORT, |
| 62 | UHID_INPUT_REPORT, |
| 63 | }; |
| 64 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 65 | struct uhid_input2_req { |
| 66 | __u16 size; |
| 67 | __u8 data[UHID_DATA_MAX]; |
| 68 | } __attribute__((__packed__)); |
| 69 | |
David Herrmann | 3b3baa8 | 2012-06-10 15:16:24 +0200 | [diff] [blame] | 70 | struct uhid_output_req { |
| 71 | __u8 data[UHID_DATA_MAX]; |
| 72 | __u16 size; |
| 73 | __u8 rtype; |
| 74 | } __attribute__((__packed__)); |
| 75 | |
David Herrmann | 50598e7 | 2014-07-29 17:14:22 +0200 | [diff] [blame] | 76 | struct uhid_get_report_req { |
| 77 | __u32 id; |
| 78 | __u8 rnum; |
| 79 | __u8 rtype; |
| 80 | } __attribute__((__packed__)); |
| 81 | |
| 82 | struct uhid_get_report_reply_req { |
| 83 | __u32 id; |
| 84 | __u16 err; |
| 85 | __u16 size; |
| 86 | __u8 data[UHID_DATA_MAX]; |
| 87 | } __attribute__((__packed__)); |
| 88 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame^] | 89 | struct uhid_set_report_req { |
| 90 | __u32 id; |
| 91 | __u8 rnum; |
| 92 | __u8 rtype; |
| 93 | __u16 size; |
| 94 | __u8 data[UHID_DATA_MAX]; |
| 95 | } __attribute__((__packed__)); |
| 96 | |
| 97 | struct uhid_set_report_reply_req { |
| 98 | __u32 id; |
| 99 | __u16 err; |
| 100 | } __attribute__((__packed__)); |
| 101 | |
David Herrmann | 50598e7 | 2014-07-29 17:14:22 +0200 | [diff] [blame] | 102 | /* |
| 103 | * Compat Layer |
| 104 | * All these commands and requests are obsolete. You should avoid using them in |
| 105 | * new code. We support them for backwards-compatibility, but you might not get |
| 106 | * access to new feature in case you use them. |
| 107 | */ |
| 108 | |
| 109 | enum uhid_legacy_event_type { |
| 110 | UHID_CREATE = __UHID_LEGACY_CREATE, |
| 111 | UHID_OUTPUT_EV = __UHID_LEGACY_OUTPUT_EV, |
| 112 | UHID_INPUT = __UHID_LEGACY_INPUT, |
| 113 | UHID_FEATURE = UHID_GET_REPORT, |
| 114 | UHID_FEATURE_ANSWER = UHID_GET_REPORT_REPLY, |
| 115 | }; |
| 116 | |
| 117 | /* Obsolete! Use UHID_CREATE2. */ |
| 118 | struct uhid_create_req { |
| 119 | __u8 name[128]; |
| 120 | __u8 phys[64]; |
| 121 | __u8 uniq[64]; |
| 122 | __u8 __user *rd_data; |
| 123 | __u16 rd_size; |
| 124 | |
| 125 | __u16 bus; |
| 126 | __u32 vendor; |
| 127 | __u32 product; |
| 128 | __u32 version; |
| 129 | __u32 country; |
| 130 | } __attribute__((__packed__)); |
| 131 | |
| 132 | /* Obsolete! Use UHID_INPUT2. */ |
| 133 | struct uhid_input_req { |
| 134 | __u8 data[UHID_DATA_MAX]; |
| 135 | __u16 size; |
| 136 | } __attribute__((__packed__)); |
| 137 | |
| 138 | /* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */ |
David Herrmann | f80e136 | 2012-06-10 15:16:23 +0200 | [diff] [blame] | 139 | struct uhid_output_ev_req { |
| 140 | __u16 type; |
| 141 | __u16 code; |
| 142 | __s32 value; |
| 143 | } __attribute__((__packed__)); |
| 144 | |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 145 | /* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */ |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 146 | struct uhid_feature_req { |
| 147 | __u32 id; |
| 148 | __u8 rnum; |
| 149 | __u8 rtype; |
| 150 | } __attribute__((__packed__)); |
| 151 | |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 152 | /* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */ |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 153 | struct uhid_feature_answer_req { |
| 154 | __u32 id; |
| 155 | __u16 err; |
| 156 | __u16 size; |
| 157 | __u8 data[UHID_DATA_MAX]; |
David Herrmann | fee5dfe | 2012-12-17 13:20:43 +0100 | [diff] [blame] | 158 | } __attribute__((__packed__)); |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 159 | |
David Herrmann | 50598e7 | 2014-07-29 17:14:22 +0200 | [diff] [blame] | 160 | /* |
| 161 | * UHID Events |
| 162 | * All UHID events from and to the kernel are encoded as "struct uhid_event". |
| 163 | * The "type" field contains a UHID_* type identifier. All payload depends on |
| 164 | * that type and can be accessed via ev->u.XYZ accordingly. |
| 165 | * If user-space writes short events, they're extended with 0s by the kernel. If |
| 166 | * the kernel writes short events, user-space shall extend them with 0s. |
| 167 | */ |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 168 | |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 169 | struct uhid_event { |
| 170 | __u32 type; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 171 | |
| 172 | union { |
| 173 | struct uhid_create_req create; |
David Herrmann | 5e87a36 | 2012-06-10 15:16:19 +0200 | [diff] [blame] | 174 | struct uhid_input_req input; |
David Herrmann | 3b3baa8 | 2012-06-10 15:16:24 +0200 | [diff] [blame] | 175 | struct uhid_output_req output; |
David Herrmann | f80e136 | 2012-06-10 15:16:23 +0200 | [diff] [blame] | 176 | struct uhid_output_ev_req output_ev; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 177 | struct uhid_feature_req feature; |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 178 | struct uhid_get_report_req get_report; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 179 | struct uhid_feature_answer_req feature_answer; |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 180 | struct uhid_get_report_reply_req get_report_reply; |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 181 | struct uhid_create2_req create2; |
| 182 | struct uhid_input2_req input2; |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame^] | 183 | struct uhid_set_report_req set_report; |
| 184 | struct uhid_set_report_reply_req set_report_reply; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 185 | } u; |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 186 | } __attribute__((__packed__)); |
| 187 | |
| 188 | #endif /* __UHID_H_ */ |