blob: e41223b6a4c8538ec90ba664f4026445cdc76b3f [file] [log] [blame]
Stefan Richter83ef7c72010-07-22 11:58:05 +02001#include <linux/firewire-constants.h>
Stefan Richter9f6d3c42010-07-22 11:58:05 +02002#include <stdio.h>
Stefan Richter83ef7c72010-07-22 11:58:05 +02003#include <stdlib.h>
4
Stefan Richter9f6d3c42010-07-22 11:58:05 +02005#include "list.h"
6#include "nosy-dump.h"
7
8#define CSR_FCP_COMMAND 0xfffff0000b00ull
9#define CSR_FCP_RESPONSE 0xfffff0000d00ull
10
Stefan Richter92c16f72010-07-22 11:58:05 +020011static const char * const ctype_names[] = {
12 [0x0] = "control", [0x8] = "not implemented",
13 [0x1] = "status", [0x9] = "accepted",
14 [0x2] = "specific inquiry", [0xa] = "rejected",
15 [0x3] = "notify", [0xb] = "in transition",
16 [0x4] = "general inquiry", [0xc] = "stable",
17 [0x5] = "(reserved 0x05)", [0xd] = "changed",
18 [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
19 [0x7] = "(reserved 0x07)", [0xf] = "interim",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020020};
21
Stefan Richter92c16f72010-07-22 11:58:05 +020022static const char * const subunit_type_names[] = {
23 [0x00] = "monitor", [0x10] = "(reserved 0x10)",
24 [0x01] = "audio", [0x11] = "(reserved 0x11)",
25 [0x02] = "printer", [0x12] = "(reserved 0x12)",
26 [0x03] = "disc", [0x13] = "(reserved 0x13)",
27 [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
28 [0x05] = "tuner", [0x15] = "(reserved 0x15)",
29 [0x06] = "ca", [0x16] = "(reserved 0x16)",
30 [0x07] = "camera", [0x17] = "(reserved 0x17)",
31 [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
32 [0x09] = "panel", [0x19] = "(reserved 0x19)",
33 [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
34 [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
35 [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
36 [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
37 [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
38 [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020039};
40
41struct avc_enum {
Stefan Richter92c16f72010-07-22 11:58:05 +020042 int value;
43 const char *name;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020044};
45
46struct avc_field {
Stefan Richter92c16f72010-07-22 11:58:05 +020047 const char *name; /* Short name for field. */
48 int offset; /* Location of field, specified in bits; */
49 /* negative means from end of packet. */
50 int width; /* Width of field, 0 means use data_length. */
51 struct avc_enum *names;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020052};
53
54struct avc_opcode_info {
Stefan Richter92c16f72010-07-22 11:58:05 +020055 const char *name;
56 struct avc_field fields[8];
Stefan Richter9f6d3c42010-07-22 11:58:05 +020057};
58
59struct avc_enum power_field_names[] = {
Stefan Richter92c16f72010-07-22 11:58:05 +020060 { 0x70, "on" },
61 { 0x60, "off" },
62 { }
Stefan Richter9f6d3c42010-07-22 11:58:05 +020063};
64
65static const struct avc_opcode_info opcode_info[256] = {
66
Stefan Richter92c16f72010-07-22 11:58:05 +020067 /* TA Document 1999026 */
68 /* AV/C Digital Interface Command Set General Specification 4.0 */
69 [0xb2] = { "power", {
70 { "state", 0, 8, power_field_names }
71 }
72 },
73 [0x30] = { "unit info", {
74 { "foo", 0, 8 },
75 { "unit_type", 8, 5 },
76 { "unit", 13, 3 },
77 { "company id", 16, 24 },
78 }
79 },
80 [0x31] = { "subunit info" },
81 [0x01] = { "reserve" },
82 [0xb0] = { "version" },
83 [0x00] = { "vendor dependent" },
84 [0x02] = { "plug info" },
85 [0x12] = { "channel usage" },
86 [0x24] = { "connect" },
87 [0x20] = { "connect av" },
88 [0x22] = { "connections" },
89 [0x11] = { "digital input" },
90 [0x10] = { "digital output" },
91 [0x25] = { "disconnect" },
92 [0x21] = { "disconnect av" },
93 [0x19] = { "input plug signal format" },
94 [0x18] = { "output plug signal format" },
95 [0x1f] = { "general bus setup" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +020096
Stefan Richter92c16f72010-07-22 11:58:05 +020097 /* TA Document 1999025 */
98 /* AV/C Descriptor Mechanism Specification Version 1.0 */
99 [0x0c] = { "create descriptor" },
100 [0x08] = { "open descriptor" },
101 [0x09] = { "read descriptor" },
102 [0x0a] = { "write descriptor" },
103 [0x05] = { "open info block" },
104 [0x06] = { "read info block" },
105 [0x07] = { "write info block" },
106 [0x0b] = { "search descriptor" },
107 [0x0d] = { "object number select" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200108
Stefan Richter92c16f72010-07-22 11:58:05 +0200109 /* TA Document 1999015 */
110 /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
111 [0xb3] = { "rate", {
112 { "subfunction", 0, 8 },
113 { "result", 8, 8 },
114 { "plug_type", 16, 8 },
115 { "plug_id", 16, 8 },
116 }
117 },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200118
Stefan Richter92c16f72010-07-22 11:58:05 +0200119 /* TA Document 1999008 */
120 /* AV/C Audio Subunit Specification 1.0 */
121 [0xb8] = { "function block" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200122
Stefan Richter92c16f72010-07-22 11:58:05 +0200123 /* TA Document 2001001 */
124 /* AV/C Panel Subunit Specification 1.1 */
125 [0x7d] = { "gui update" },
126 [0x7e] = { "push gui data" },
127 [0x7f] = { "user action" },
128 [0x7c] = { "pass through" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200129
Stefan Richter92c16f72010-07-22 11:58:05 +0200130 /* */
131 [0x26] = { "asynchronous connection" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200132};
133
134struct avc_frame {
Stefan Richter92c16f72010-07-22 11:58:05 +0200135 uint32_t operand0:8;
136 uint32_t opcode:8;
137 uint32_t subunit_id:3;
138 uint32_t subunit_type:5;
139 uint32_t ctype:4;
140 uint32_t cts:4;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200141};
142
143static void
144decode_avc(struct link_transaction *t)
145{
Stefan Richter92c16f72010-07-22 11:58:05 +0200146 struct avc_frame *frame =
147 (struct avc_frame *) t->request->packet.write_block.data;
148 const struct avc_opcode_info *info;
149 const char *name;
150 char buffer[32];
151 int i;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200152
Stefan Richter92c16f72010-07-22 11:58:05 +0200153 info = &opcode_info[frame->opcode];
154 if (info->name == NULL) {
155 snprintf(buffer, sizeof(buffer),
156 "(unknown opcode 0x%02x)", frame->opcode);
157 name = buffer;
158 } else {
159 name = info->name;
160 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200161
Stefan Richter92c16f72010-07-22 11:58:05 +0200162 printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
163 ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
164 frame->subunit_id, name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200165
Stefan Richter92c16f72010-07-22 11:58:05 +0200166 for (i = 0; info->fields[i].name != NULL; i++)
167 printf(", %s", info->fields[i].name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200168
Stefan Richter92c16f72010-07-22 11:58:05 +0200169 printf("\n");
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200170}
171
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200172int
173decode_fcp(struct link_transaction *t)
174{
Stefan Richter92c16f72010-07-22 11:58:05 +0200175 struct avc_frame *frame =
176 (struct avc_frame *) t->request->packet.write_block.data;
177 unsigned long long offset =
178 ((unsigned long long) t->request->packet.common.offset_high << 32) |
179 t->request->packet.common.offset_low;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200180
Stefan Richter83ef7c72010-07-22 11:58:05 +0200181 if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK_REQUEST)
Stefan Richter92c16f72010-07-22 11:58:05 +0200182 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200183
Stefan Richter92c16f72010-07-22 11:58:05 +0200184 if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
185 switch (frame->cts) {
186 case 0x00:
187 decode_avc(t);
188 break;
189 case 0x01:
190 printf("cal fcp frame (cts=0x01)\n");
191 break;
192 case 0x02:
193 printf("ehs fcp frame (cts=0x02)\n");
194 break;
195 case 0x03:
196 printf("havi fcp frame (cts=0x03)\n");
197 break;
198 case 0x0e:
199 printf("vendor specific fcp frame (cts=0x0e)\n");
200 break;
201 case 0x0f:
202 printf("extended cts\n");
203 break;
204 default:
205 printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
206 break;
207 }
208 return 1;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200209 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200210
Stefan Richter92c16f72010-07-22 11:58:05 +0200211 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200212}
213