hidp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2003-2011 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #define _GNU_SOURCE
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "parser.h"
  20. static char *type2str(uint8_t head)
  21. {
  22. switch (head & 0xf0) {
  23. case 0x00:
  24. return "Handshake";
  25. case 0x10:
  26. return "Control";
  27. case 0x40:
  28. return "Get report";
  29. case 0x50:
  30. return "Set report";
  31. case 0x60:
  32. return "Get protocol";
  33. case 0x70:
  34. return "Set protocol";
  35. case 0x80:
  36. return "Get idle";
  37. case 0x90:
  38. return "Set idle";
  39. case 0xa0:
  40. return "Data";
  41. case 0xb0:
  42. return "Data continuation";
  43. default:
  44. return "Reserved";
  45. }
  46. }
  47. static char *result2str(uint8_t head)
  48. {
  49. switch (head & 0x0f) {
  50. case 0x00:
  51. return "Successful";
  52. case 0x01:
  53. return "Not ready";
  54. case 0x02:
  55. return "Invalid report ID";
  56. case 0x03:
  57. return "Unsupported request";
  58. case 0x04:
  59. return "Invalid parameter";
  60. case 0x0e:
  61. return "Unknown";
  62. case 0x0f:
  63. return "Fatal";
  64. default:
  65. return "Reserved";
  66. }
  67. }
  68. static char *operation2str(uint8_t head)
  69. {
  70. switch (head & 0x0f) {
  71. case 0x00:
  72. return "No operation";
  73. case 0x01:
  74. return "Hard reset";
  75. case 0x02:
  76. return "Soft reset";
  77. case 0x03:
  78. return "Suspend";
  79. case 0x04:
  80. return "Exit suspend";
  81. case 0x05:
  82. return "Virtual cable unplug";
  83. default:
  84. return "Reserved";
  85. }
  86. }
  87. static char *report2str(uint8_t head)
  88. {
  89. switch (head & 0x03) {
  90. case 0x00:
  91. return "Other report";
  92. case 0x01:
  93. return "Input report";
  94. case 0x02:
  95. return "Output report";
  96. case 0x03:
  97. return "Feature report";
  98. default:
  99. return "Reserved";
  100. }
  101. }
  102. static char *protocol2str(uint8_t head)
  103. {
  104. switch (head & 0x01) {
  105. case 0x00:
  106. return "Boot protocol";
  107. case 0x01:
  108. return "Report protocol";
  109. default:
  110. return "Reserved";
  111. }
  112. }
  113. void hidp_dump(int level, struct frame *frm)
  114. {
  115. uint8_t hdr;
  116. char *param;
  117. hdr = p_get_u8(frm);
  118. switch (hdr & 0xf0) {
  119. case 0x00:
  120. param = result2str(hdr);
  121. break;
  122. case 0x10:
  123. param = operation2str(hdr);
  124. break;
  125. case 0x60:
  126. case 0x70:
  127. param = protocol2str(hdr);
  128. break;
  129. case 0x40:
  130. case 0x50:
  131. case 0xa0:
  132. case 0xb0:
  133. param = report2str(hdr);
  134. break;
  135. default:
  136. param = "";
  137. break;
  138. }
  139. p_indent(level, frm);
  140. printf("HIDP: %s: %s\n", type2str(hdr), param);
  141. raw_dump(level, frm);
  142. }