hiddev.h 6.2 KB

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