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