decode-fcp.c 5.5 KB

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