uhid.h 4.5 KB

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