| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _HIDDEV_H | 
 | 2 | #define _HIDDEV_H | 
 | 3 |  | 
 | 4 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 |  *  Copyright (c) 1999-2000 Vojtech Pavlik | 
 | 6 |  * | 
 | 7 |  *  Sponsored by SuSE | 
 | 8 |  */ | 
 | 9 |  | 
 | 10 | /* | 
 | 11 |  * This program is free software; you can redistribute it and/or modify | 
 | 12 |  * it under the terms of the GNU General Public License as published by | 
 | 13 |  * the Free Software Foundation; either version 2 of the License, or  | 
 | 14 |  * (at your option) any later version. | 
 | 15 |  *  | 
 | 16 |  * This program is distributed in the hope that it will be useful, | 
 | 17 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 18 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 19 |  * GNU General Public License for more details. | 
 | 20 |  *  | 
 | 21 |  * You should have received a copy of the GNU General Public License | 
 | 22 |  * along with this program; if not, write to the Free Software | 
 | 23 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
 | 24 |  *  | 
 | 25 |  * Should you need to contact me, the author, you can do so either by | 
 | 26 |  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail: | 
 | 27 |  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic | 
 | 28 |  */ | 
 | 29 |  | 
| Jaswinder Singh Rajput | c244ae5 | 2009-01-30 21:17:06 +0530 | [diff] [blame] | 30 | #include <linux/types.h> | 
 | 31 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 	__u32 bustype; | 
 | 43 | 	__u32 busnum; | 
 | 44 | 	__u32 devnum; | 
 | 45 | 	__u32 ifnum; | 
 | 46 | 	__s16 vendor; | 
 | 47 | 	__s16 product; | 
 | 48 | 	__s16 version; | 
 | 49 | 	__u32 num_applications; | 
 | 50 | }; | 
 | 51 |  | 
 | 52 | struct hiddev_collection_info { | 
 | 53 | 	__u32 index; | 
 | 54 | 	__u32 type; | 
 | 55 | 	__u32 usage; | 
 | 56 | 	__u32 level; | 
 | 57 | }; | 
 | 58 |  | 
 | 59 | #define HID_STRING_SIZE 256 | 
 | 60 | struct hiddev_string_descriptor { | 
 | 61 | 	__s32 index; | 
 | 62 | 	char value[HID_STRING_SIZE]; | 
 | 63 | }; | 
 | 64 |  | 
 | 65 | struct hiddev_report_info { | 
 | 66 | 	__u32 report_type; | 
 | 67 | 	__u32 report_id; | 
 | 68 | 	__u32 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 | 	__u32 report_type; | 
 | 92 | 	__u32 report_id; | 
 | 93 | 	__u32 field_index; | 
 | 94 | 	__u32 maxusage; | 
 | 95 | 	__u32 flags; | 
 | 96 | 	__u32 physical;		/* physical usage for this field */ | 
 | 97 | 	__u32 logical;		/* logical usage for this field */ | 
 | 98 | 	__u32 application;		/* application usage for this field */ | 
 | 99 | 	__s32 logical_minimum; | 
 | 100 | 	__s32 logical_maximum; | 
 | 101 | 	__s32 physical_minimum; | 
 | 102 | 	__s32 physical_maximum; | 
 | 103 | 	__u32 unit_exponent; | 
 | 104 | 	__u32 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 | 	__u32 report_type; | 
 | 122 | 	__u32 report_id; | 
 | 123 | 	__u32 field_index; | 
 | 124 | 	__u32 usage_index; | 
 | 125 | 	__u32 usage_code; | 
 | 126 | 	__s32 value; | 
 | 127 | }; | 
 | 128 |  | 
 | 129 | /* hiddev_usage_ref_multi is used for sending multiple bytes to a control. | 
 | 130 |  * It really manifests itself as setting the value of consecutive usages */ | 
 | 131 | #define HID_MAX_MULTI_USAGES 1024 | 
 | 132 | struct hiddev_usage_ref_multi { | 
 | 133 | 	struct hiddev_usage_ref uref; | 
 | 134 | 	__u32 num_values; | 
 | 135 | 	__s32 values[HID_MAX_MULTI_USAGES]; | 
 | 136 | }; | 
 | 137 |  | 
 | 138 | /* FIELD_INDEX_NONE is returned in read() data from the kernel when flags | 
 | 139 |  * is set to (HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT) and a new report has | 
 | 140 |  * been sent by the device  | 
 | 141 |  */ | 
 | 142 | #define HID_FIELD_INDEX_NONE 0xffffffff | 
 | 143 |  | 
 | 144 | /* | 
 | 145 |  * Protocol version. | 
 | 146 |  */ | 
 | 147 |  | 
 | 148 | #define HID_VERSION		0x010004 | 
 | 149 |  | 
 | 150 | /* | 
 | 151 |  * IOCTLs (0x00 - 0x7f) | 
 | 152 |  */ | 
 | 153 |  | 
 | 154 | #define HIDIOCGVERSION		_IOR('H', 0x01, int) | 
 | 155 | #define HIDIOCAPPLICATION	_IO('H', 0x02) | 
 | 156 | #define HIDIOCGDEVINFO		_IOR('H', 0x03, struct hiddev_devinfo) | 
 | 157 | #define HIDIOCGSTRING		_IOR('H', 0x04, struct hiddev_string_descriptor) | 
 | 158 | #define HIDIOCINITREPORT	_IO('H', 0x05) | 
 | 159 | #define HIDIOCGNAME(len)	_IOC(_IOC_READ, 'H', 0x06, len) | 
 | 160 | #define HIDIOCGREPORT		_IOW('H', 0x07, struct hiddev_report_info) | 
 | 161 | #define HIDIOCSREPORT		_IOW('H', 0x08, struct hiddev_report_info) | 
 | 162 | #define HIDIOCGREPORTINFO	_IOWR('H', 0x09, struct hiddev_report_info) | 
 | 163 | #define HIDIOCGFIELDINFO	_IOWR('H', 0x0A, struct hiddev_field_info) | 
 | 164 | #define HIDIOCGUSAGE		_IOWR('H', 0x0B, struct hiddev_usage_ref) | 
 | 165 | #define HIDIOCSUSAGE		_IOW('H', 0x0C, struct hiddev_usage_ref) | 
 | 166 | #define HIDIOCGUCODE		_IOWR('H', 0x0D, struct hiddev_usage_ref) | 
 | 167 | #define HIDIOCGFLAG		_IOR('H', 0x0E, int) | 
 | 168 | #define HIDIOCSFLAG		_IOW('H', 0x0F, int) | 
 | 169 | #define HIDIOCGCOLLECTIONINDEX	_IOW('H', 0x10, struct hiddev_usage_ref) | 
 | 170 | #define HIDIOCGCOLLECTIONINFO	_IOWR('H', 0x11, struct hiddev_collection_info) | 
 | 171 | #define HIDIOCGPHYS(len)	_IOC(_IOC_READ, 'H', 0x12, len) | 
 | 172 |  | 
 | 173 | /* For writing/reading to multiple/consecutive usages */ | 
 | 174 | #define HIDIOCGUSAGES		_IOWR('H', 0x13, struct hiddev_usage_ref_multi) | 
 | 175 | #define HIDIOCSUSAGES		_IOW('H', 0x14, struct hiddev_usage_ref_multi) | 
 | 176 |  | 
 | 177 | /*  | 
 | 178 |  * Flags to be used in HIDIOCSFLAG | 
 | 179 |  */ | 
 | 180 | #define HIDDEV_FLAG_UREF	0x1 | 
 | 181 | #define HIDDEV_FLAG_REPORT	0x2 | 
 | 182 | #define HIDDEV_FLAGS		0x3 | 
 | 183 |  | 
 | 184 | /* To traverse the input report descriptor info for a HID device, perform the  | 
 | 185 |  * following: | 
 | 186 |  * | 
| Antonio Ospite | 34a5cee | 2008-10-02 22:14:54 +0200 | [diff] [blame] | 187 |  * rinfo.report_type = HID_REPORT_TYPE_INPUT; | 
 | 188 |  * rinfo.report_id = HID_REPORT_ID_FIRST; | 
 | 189 |  * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  * | 
| Antonio Ospite | 34a5cee | 2008-10-02 22:14:54 +0200 | [diff] [blame] | 191 |  * while (ret >= 0) { | 
 | 192 |  * 	for (i = 0; i < rinfo.num_fields; i++) { | 
 | 193 |  * 		finfo.report_type = rinfo.report_type; | 
 | 194 |  * 		finfo.report_id = rinfo.report_id; | 
 | 195 |  * 		finfo.field_index = i; | 
 | 196 |  * 		ioctl(fd, HIDIOCGFIELDINFO, &finfo); | 
 | 197 |  * 		for (j = 0; j < finfo.maxusage; j++) { | 
| Antonio Ospite | dded364 | 2008-10-02 22:15:02 +0200 | [diff] [blame] | 198 |  * 			uref.report_type = rinfo.report_type; | 
 | 199 |  * 			uref.report_id = rinfo.report_id; | 
| Antonio Ospite | 34a5cee | 2008-10-02 22:14:54 +0200 | [diff] [blame] | 200 |  * 			uref.field_index = i; | 
 | 201 |  * 			uref.usage_index = j; | 
 | 202 |  * 			ioctl(fd, HIDIOCGUCODE, &uref); | 
 | 203 |  * 			ioctl(fd, HIDIOCGUSAGE, &uref); | 
 | 204 |  * 		} | 
 | 205 |  * 	} | 
 | 206 |  * 	rinfo.report_id |= HID_REPORT_ID_NEXT; | 
 | 207 |  * 	ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); | 
 | 208 |  * } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 |  */ | 
 | 210 |  | 
 | 211 |  | 
 | 212 | #ifdef __KERNEL__ | 
 | 213 |  | 
 | 214 | /* | 
 | 215 |  * In-kernel definitions. | 
 | 216 |  */ | 
 | 217 |  | 
 | 218 | struct hid_device; | 
 | 219 | struct hid_usage; | 
 | 220 | struct hid_field; | 
 | 221 | struct hid_report; | 
 | 222 |  | 
 | 223 | #ifdef CONFIG_USB_HIDDEV | 
| Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 224 | int hiddev_connect(struct hid_device *hid, unsigned int force); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | void hiddev_disconnect(struct hid_device *); | 
 | 226 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 227 | 		      struct hid_usage *usage, __s32 value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | void hiddev_report_event(struct hid_device *hid, struct hid_report *report); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #else | 
| Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 230 | static inline int hiddev_connect(struct hid_device *hid, | 
 | 231 | 		unsigned int force) | 
 | 232 | { return -1; } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static inline void hiddev_disconnect(struct hid_device *hid) { } | 
 | 234 | static inline void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 235 | 		      struct hid_usage *usage, __s32 value) { } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | static inline void hiddev_report_event(struct hid_device *hid, struct hid_report *report) { } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | #endif | 
 | 238 |  | 
 | 239 | #endif | 
 | 240 | #endif |