hiddev.h 6.1 KB

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