decode-fcp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/firewire-constants.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "list.h"
  6. #include "nosy-dump.h"
  7. #define CSR_FCP_COMMAND 0xfffff0000b00ull
  8. #define CSR_FCP_RESPONSE 0xfffff0000d00ull
  9. static const char * const ctype_names[] = {
  10. [0x0] = "control", [0x8] = "not implemented",
  11. [0x1] = "status", [0x9] = "accepted",
  12. [0x2] = "specific inquiry", [0xa] = "rejected",
  13. [0x3] = "notify", [0xb] = "in transition",
  14. [0x4] = "general inquiry", [0xc] = "stable",
  15. [0x5] = "(reserved 0x05)", [0xd] = "changed",
  16. [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
  17. [0x7] = "(reserved 0x07)", [0xf] = "interim",
  18. };
  19. static const char * const subunit_type_names[] = {
  20. [0x00] = "monitor", [0x10] = "(reserved 0x10)",
  21. [0x01] = "audio", [0x11] = "(reserved 0x11)",
  22. [0x02] = "printer", [0x12] = "(reserved 0x12)",
  23. [0x03] = "disc", [0x13] = "(reserved 0x13)",
  24. [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
  25. [0x05] = "tuner", [0x15] = "(reserved 0x15)",
  26. [0x06] = "ca", [0x16] = "(reserved 0x16)",
  27. [0x07] = "camera", [0x17] = "(reserved 0x17)",
  28. [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
  29. [0x09] = "panel", [0x19] = "(reserved 0x19)",
  30. [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
  31. [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
  32. [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
  33. [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
  34. [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
  35. [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
  36. };
  37. struct avc_enum {
  38. int value;
  39. const char *name;
  40. };
  41. struct avc_field {
  42. const char *name; /* Short name for field. */
  43. int offset; /* Location of field, specified in bits; */
  44. /* negative means from end of packet. */
  45. int width; /* Width of field, 0 means use data_length. */
  46. struct avc_enum *names;
  47. };
  48. struct avc_opcode_info {
  49. const char *name;
  50. struct avc_field fields[8];
  51. };
  52. struct avc_enum power_field_names[] = {
  53. { 0x70, "on" },
  54. { 0x60, "off" },
  55. { }
  56. };
  57. static const struct avc_opcode_info opcode_info[256] = {
  58. /* TA Document 1999026 */
  59. /* AV/C Digital Interface Command Set General Specification 4.0 */
  60. [0xb2] = { "power", {
  61. { "state", 0, 8, power_field_names }
  62. }
  63. },
  64. [0x30] = { "unit info", {
  65. { "foo", 0, 8 },
  66. { "unit_type", 8, 5 },
  67. { "unit", 13, 3 },
  68. { "company id", 16, 24 },
  69. }
  70. },
  71. [0x31] = { "subunit info" },
  72. [0x01] = { "reserve" },
  73. [0xb0] = { "version" },
  74. [0x00] = { "vendor dependent" },
  75. [0x02] = { "plug info" },
  76. [0x12] = { "channel usage" },
  77. [0x24] = { "connect" },
  78. [0x20] = { "connect av" },
  79. [0x22] = { "connections" },
  80. [0x11] = { "digital input" },
  81. [0x10] = { "digital output" },
  82. [0x25] = { "disconnect" },
  83. [0x21] = { "disconnect av" },
  84. [0x19] = { "input plug signal format" },
  85. [0x18] = { "output plug signal format" },
  86. [0x1f] = { "general bus setup" },
  87. /* TA Document 1999025 */
  88. /* AV/C Descriptor Mechanism Specification Version 1.0 */
  89. [0x0c] = { "create descriptor" },
  90. [0x08] = { "open descriptor" },
  91. [0x09] = { "read descriptor" },
  92. [0x0a] = { "write descriptor" },
  93. [0x05] = { "open info block" },
  94. [0x06] = { "read info block" },
  95. [0x07] = { "write info block" },
  96. [0x0b] = { "search descriptor" },
  97. [0x0d] = { "object number select" },
  98. /* TA Document 1999015 */
  99. /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
  100. [0xb3] = { "rate", {
  101. { "subfunction", 0, 8 },
  102. { "result", 8, 8 },
  103. { "plug_type", 16, 8 },
  104. { "plug_id", 16, 8 },
  105. }
  106. },
  107. /* TA Document 1999008 */
  108. /* AV/C Audio Subunit Specification 1.0 */
  109. [0xb8] = { "function block" },
  110. /* TA Document 2001001 */
  111. /* AV/C Panel Subunit Specification 1.1 */
  112. [0x7d] = { "gui update" },
  113. [0x7e] = { "push gui data" },
  114. [0x7f] = { "user action" },
  115. [0x7c] = { "pass through" },
  116. /* */
  117. [0x26] = { "asynchronous connection" },
  118. };
  119. struct avc_frame {
  120. uint32_t operand0:8;
  121. uint32_t opcode:8;
  122. uint32_t subunit_id:3;
  123. uint32_t subunit_type:5;
  124. uint32_t ctype:4;
  125. uint32_t cts:4;
  126. };
  127. static void
  128. decode_avc(struct link_transaction *t)
  129. {
  130. struct avc_frame *frame =
  131. (struct avc_frame *) t->request->packet.write_block.data;
  132. const struct avc_opcode_info *info;
  133. const char *name;
  134. char buffer[32];
  135. int i;
  136. info = &opcode_info[frame->opcode];
  137. if (info->name == NULL) {
  138. snprintf(buffer, sizeof(buffer),
  139. "(unknown opcode 0x%02x)", frame->opcode);
  140. name = buffer;
  141. } else {
  142. name = info->name;
  143. }
  144. printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
  145. ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
  146. frame->subunit_id, name);
  147. for (i = 0; info->fields[i].name != NULL; i++)
  148. printf(", %s", info->fields[i].name);
  149. printf("\n");
  150. }
  151. int
  152. decode_fcp(struct link_transaction *t)
  153. {
  154. struct avc_frame *frame =
  155. (struct avc_frame *) t->request->packet.write_block.data;
  156. unsigned long long offset =
  157. ((unsigned long long) t->request->packet.common.offset_high << 32) |
  158. t->request->packet.common.offset_low;
  159. if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK_REQUEST)
  160. return 0;
  161. if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
  162. switch (frame->cts) {
  163. case 0x00:
  164. decode_avc(t);
  165. break;
  166. case 0x01:
  167. printf("cal fcp frame (cts=0x01)\n");
  168. break;
  169. case 0x02:
  170. printf("ehs fcp frame (cts=0x02)\n");
  171. break;
  172. case 0x03:
  173. printf("havi fcp frame (cts=0x03)\n");
  174. break;
  175. case 0x0e:
  176. printf("vendor specific fcp frame (cts=0x0e)\n");
  177. break;
  178. case 0x0f:
  179. printf("extended cts\n");
  180. break;
  181. default:
  182. printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
  183. break;
  184. }
  185. return 1;
  186. }
  187. return 0;
  188. }