blob: 9cd1550db24adeccbf12dfdf3c325da3a3fc3752 [file] [log] [blame]
Stefan Richter9f6d3c42010-07-22 11:58:05 +02001#include <stdlib.h>
2#include <stdio.h>
3#include "list.h"
4#include "nosy-dump.h"
5
6#define CSR_FCP_COMMAND 0xfffff0000b00ull
7#define CSR_FCP_RESPONSE 0xfffff0000d00ull
8
Stefan Richter92c16f72010-07-22 11:58:05 +02009static 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",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020018};
19
Stefan Richter92c16f72010-07-22 11:58:05 +020020static const char * const subunit_type_names[] = {
21 [0x00] = "monitor", [0x10] = "(reserved 0x10)",
22 [0x01] = "audio", [0x11] = "(reserved 0x11)",
23 [0x02] = "printer", [0x12] = "(reserved 0x12)",
24 [0x03] = "disc", [0x13] = "(reserved 0x13)",
25 [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
26 [0x05] = "tuner", [0x15] = "(reserved 0x15)",
27 [0x06] = "ca", [0x16] = "(reserved 0x16)",
28 [0x07] = "camera", [0x17] = "(reserved 0x17)",
29 [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
30 [0x09] = "panel", [0x19] = "(reserved 0x19)",
31 [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
32 [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
33 [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
34 [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
35 [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
36 [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020037};
38
39struct avc_enum {
Stefan Richter92c16f72010-07-22 11:58:05 +020040 int value;
41 const char *name;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020042};
43
44struct avc_field {
Stefan Richter92c16f72010-07-22 11:58:05 +020045 const char *name; /* Short name for field. */
46 int offset; /* Location of field, specified in bits; */
47 /* negative means from end of packet. */
48 int width; /* Width of field, 0 means use data_length. */
49 struct avc_enum *names;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020050};
51
52struct avc_opcode_info {
Stefan Richter92c16f72010-07-22 11:58:05 +020053 const char *name;
54 struct avc_field fields[8];
Stefan Richter9f6d3c42010-07-22 11:58:05 +020055};
56
57struct avc_enum power_field_names[] = {
Stefan Richter92c16f72010-07-22 11:58:05 +020058 { 0x70, "on" },
59 { 0x60, "off" },
60 { }
Stefan Richter9f6d3c42010-07-22 11:58:05 +020061};
62
63static const struct avc_opcode_info opcode_info[256] = {
64
Stefan Richter92c16f72010-07-22 11:58:05 +020065 /* TA Document 1999026 */
66 /* AV/C Digital Interface Command Set General Specification 4.0 */
67 [0xb2] = { "power", {
68 { "state", 0, 8, power_field_names }
69 }
70 },
71 [0x30] = { "unit info", {
72 { "foo", 0, 8 },
73 { "unit_type", 8, 5 },
74 { "unit", 13, 3 },
75 { "company id", 16, 24 },
76 }
77 },
78 [0x31] = { "subunit info" },
79 [0x01] = { "reserve" },
80 [0xb0] = { "version" },
81 [0x00] = { "vendor dependent" },
82 [0x02] = { "plug info" },
83 [0x12] = { "channel usage" },
84 [0x24] = { "connect" },
85 [0x20] = { "connect av" },
86 [0x22] = { "connections" },
87 [0x11] = { "digital input" },
88 [0x10] = { "digital output" },
89 [0x25] = { "disconnect" },
90 [0x21] = { "disconnect av" },
91 [0x19] = { "input plug signal format" },
92 [0x18] = { "output plug signal format" },
93 [0x1f] = { "general bus setup" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +020094
Stefan Richter92c16f72010-07-22 11:58:05 +020095 /* TA Document 1999025 */
96 /* AV/C Descriptor Mechanism Specification Version 1.0 */
97 [0x0c] = { "create descriptor" },
98 [0x08] = { "open descriptor" },
99 [0x09] = { "read descriptor" },
100 [0x0a] = { "write descriptor" },
101 [0x05] = { "open info block" },
102 [0x06] = { "read info block" },
103 [0x07] = { "write info block" },
104 [0x0b] = { "search descriptor" },
105 [0x0d] = { "object number select" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200106
Stefan Richter92c16f72010-07-22 11:58:05 +0200107 /* TA Document 1999015 */
108 /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
109 [0xb3] = { "rate", {
110 { "subfunction", 0, 8 },
111 { "result", 8, 8 },
112 { "plug_type", 16, 8 },
113 { "plug_id", 16, 8 },
114 }
115 },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200116
Stefan Richter92c16f72010-07-22 11:58:05 +0200117 /* TA Document 1999008 */
118 /* AV/C Audio Subunit Specification 1.0 */
119 [0xb8] = { "function block" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200120
Stefan Richter92c16f72010-07-22 11:58:05 +0200121 /* TA Document 2001001 */
122 /* AV/C Panel Subunit Specification 1.1 */
123 [0x7d] = { "gui update" },
124 [0x7e] = { "push gui data" },
125 [0x7f] = { "user action" },
126 [0x7c] = { "pass through" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200127
Stefan Richter92c16f72010-07-22 11:58:05 +0200128 /* */
129 [0x26] = { "asynchronous connection" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200130};
131
132struct avc_frame {
Stefan Richter92c16f72010-07-22 11:58:05 +0200133 uint32_t operand0:8;
134 uint32_t opcode:8;
135 uint32_t subunit_id:3;
136 uint32_t subunit_type:5;
137 uint32_t ctype:4;
138 uint32_t cts:4;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200139};
140
141static void
142decode_avc(struct link_transaction *t)
143{
Stefan Richter92c16f72010-07-22 11:58:05 +0200144 struct avc_frame *frame =
145 (struct avc_frame *) t->request->packet.write_block.data;
146 const struct avc_opcode_info *info;
147 const char *name;
148 char buffer[32];
149 int i;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200150
Stefan Richter92c16f72010-07-22 11:58:05 +0200151 info = &opcode_info[frame->opcode];
152 if (info->name == NULL) {
153 snprintf(buffer, sizeof(buffer),
154 "(unknown opcode 0x%02x)", frame->opcode);
155 name = buffer;
156 } else {
157 name = info->name;
158 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200159
Stefan Richter92c16f72010-07-22 11:58:05 +0200160 printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
161 ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
162 frame->subunit_id, name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200163
Stefan Richter92c16f72010-07-22 11:58:05 +0200164 for (i = 0; info->fields[i].name != NULL; i++)
165 printf(", %s", info->fields[i].name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200166
Stefan Richter92c16f72010-07-22 11:58:05 +0200167 printf("\n");
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200168}
169
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200170int
171decode_fcp(struct link_transaction *t)
172{
Stefan Richter92c16f72010-07-22 11:58:05 +0200173 struct avc_frame *frame =
174 (struct avc_frame *) t->request->packet.write_block.data;
175 unsigned long long offset =
176 ((unsigned long long) t->request->packet.common.offset_high << 32) |
177 t->request->packet.common.offset_low;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200178
Stefan Richter92c16f72010-07-22 11:58:05 +0200179 if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK)
180 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200181
Stefan Richter92c16f72010-07-22 11:58:05 +0200182 if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
183 switch (frame->cts) {
184 case 0x00:
185 decode_avc(t);
186 break;
187 case 0x01:
188 printf("cal fcp frame (cts=0x01)\n");
189 break;
190 case 0x02:
191 printf("ehs fcp frame (cts=0x02)\n");
192 break;
193 case 0x03:
194 printf("havi fcp frame (cts=0x03)\n");
195 break;
196 case 0x0e:
197 printf("vendor specific fcp frame (cts=0x0e)\n");
198 break;
199 case 0x0f:
200 printf("extended cts\n");
201 break;
202 default:
203 printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
204 break;
205 }
206 return 1;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200207 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200208
Stefan Richter92c16f72010-07-22 11:58:05 +0200209 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200210}
211