uhid.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #ifndef __UHID_H_
  2. #define __UHID_H_
  3. /*
  4. * User-space I/O driver support for HID subsystem
  5. * Copyright (c) 2012 David Herrmann
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. */
  13. /*
  14. * Public header for user-space communication. We try to keep every structure
  15. * aligned but to be safe we also use __attribute__((__packed__)). Therefore,
  16. * the communication should be ABI compatible even between architectures.
  17. */
  18. #include <linux/input.h>
  19. #include <linux/types.h>
  20. #include <linux/hid.h>
  21. enum uhid_event_type {
  22. __UHID_LEGACY_CREATE,
  23. UHID_DESTROY,
  24. UHID_START,
  25. UHID_STOP,
  26. UHID_OPEN,
  27. UHID_CLOSE,
  28. UHID_OUTPUT,
  29. __UHID_LEGACY_OUTPUT_EV,
  30. __UHID_LEGACY_INPUT,
  31. UHID_GET_REPORT,
  32. UHID_GET_REPORT_REPLY,
  33. UHID_CREATE2,
  34. UHID_INPUT2,
  35. UHID_SET_REPORT,
  36. UHID_SET_REPORT_REPLY,
  37. };
  38. struct uhid_create2_req {
  39. __u8 name[128];
  40. __u8 phys[64];
  41. __u8 uniq[64];
  42. __u16 rd_size;
  43. __u16 bus;
  44. __u32 vendor;
  45. __u32 product;
  46. __u32 version;
  47. __u32 country;
  48. __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE];
  49. } __attribute__((__packed__));
  50. enum uhid_dev_flag {
  51. UHID_DEV_NUMBERED_FEATURE_REPORTS = (1ULL << 0),
  52. UHID_DEV_NUMBERED_OUTPUT_REPORTS = (1ULL << 1),
  53. UHID_DEV_NUMBERED_INPUT_REPORTS = (1ULL << 2),
  54. };
  55. struct uhid_start_req {
  56. __u64 dev_flags;
  57. };
  58. #define UHID_DATA_MAX 4096
  59. enum uhid_report_type {
  60. UHID_FEATURE_REPORT,
  61. UHID_OUTPUT_REPORT,
  62. UHID_INPUT_REPORT,
  63. };
  64. struct uhid_input2_req {
  65. __u16 size;
  66. __u8 data[UHID_DATA_MAX];
  67. } __attribute__((__packed__));
  68. struct uhid_output_req {
  69. __u8 data[UHID_DATA_MAX];
  70. __u16 size;
  71. __u8 rtype;
  72. } __attribute__((__packed__));
  73. struct uhid_get_report_req {
  74. __u32 id;
  75. __u8 rnum;
  76. __u8 rtype;
  77. } __attribute__((__packed__));
  78. struct uhid_get_report_reply_req {
  79. __u32 id;
  80. __u16 err;
  81. __u16 size;
  82. __u8 data[UHID_DATA_MAX];
  83. } __attribute__((__packed__));
  84. struct uhid_set_report_req {
  85. __u32 id;
  86. __u8 rnum;
  87. __u8 rtype;
  88. __u16 size;
  89. __u8 data[UHID_DATA_MAX];
  90. } __attribute__((__packed__));
  91. struct uhid_set_report_reply_req {
  92. __u32 id;
  93. __u16 err;
  94. } __attribute__((__packed__));
  95. /*
  96. * Compat Layer
  97. * All these commands and requests are obsolete. You should avoid using them in
  98. * new code. We support them for backwards-compatibility, but you might not get
  99. * access to new feature in case you use them.
  100. */
  101. enum uhid_legacy_event_type {
  102. UHID_CREATE = __UHID_LEGACY_CREATE,
  103. UHID_OUTPUT_EV = __UHID_LEGACY_OUTPUT_EV,
  104. UHID_INPUT = __UHID_LEGACY_INPUT,
  105. UHID_FEATURE = UHID_GET_REPORT,
  106. UHID_FEATURE_ANSWER = UHID_GET_REPORT_REPLY,
  107. };
  108. /* Obsolete! Use UHID_CREATE2. */
  109. struct uhid_create_req {
  110. __u8 name[128];
  111. __u8 phys[64];
  112. __u8 uniq[64];
  113. __u8 *rd_data;
  114. __u16 rd_size;
  115. __u16 bus;
  116. __u32 vendor;
  117. __u32 product;
  118. __u32 version;
  119. __u32 country;
  120. } __attribute__((__packed__));
  121. /* Obsolete! Use UHID_INPUT2. */
  122. struct uhid_input_req {
  123. __u8 data[UHID_DATA_MAX];
  124. __u16 size;
  125. } __attribute__((__packed__));
  126. /* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */
  127. struct uhid_output_ev_req {
  128. __u16 type;
  129. __u16 code;
  130. __s32 value;
  131. } __attribute__((__packed__));
  132. /* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */
  133. struct uhid_feature_req {
  134. __u32 id;
  135. __u8 rnum;
  136. __u8 rtype;
  137. } __attribute__((__packed__));
  138. /* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */
  139. struct uhid_feature_answer_req {
  140. __u32 id;
  141. __u16 err;
  142. __u16 size;
  143. __u8 data[UHID_DATA_MAX];
  144. } __attribute__((__packed__));
  145. /*
  146. * UHID Events
  147. * All UHID events from and to the kernel are encoded as "struct uhid_event".
  148. * The "type" field contains a UHID_* type identifier. All payload depends on
  149. * that type and can be accessed via ev->u.XYZ accordingly.
  150. * If user-space writes short events, they're extended with 0s by the kernel. If
  151. * the kernel writes short events, user-space shall extend them with 0s.
  152. */
  153. struct uhid_event {
  154. __u32 type;
  155. union {
  156. struct uhid_create_req create;
  157. struct uhid_input_req input;
  158. struct uhid_output_req output;
  159. struct uhid_output_ev_req output_ev;
  160. struct uhid_feature_req feature;
  161. struct uhid_get_report_req get_report;
  162. struct uhid_feature_answer_req feature_answer;
  163. struct uhid_get_report_reply_req get_report_reply;
  164. struct uhid_create2_req create2;
  165. struct uhid_input2_req input2;
  166. struct uhid_set_report_req set_report;
  167. struct uhid_set_report_reply_req set_report_reply;
  168. struct uhid_start_req start;
  169. } u;
  170. } __attribute__((__packed__));
  171. #endif /* __UHID_H_ */