0001
0002 #include <linux/firewire-constants.h>
0003 #include <stdio.h>
0004 #include <stdlib.h>
0005
0006 #include "list.h"
0007 #include "nosy-dump.h"
0008
0009 #define CSR_FCP_COMMAND 0xfffff0000b00ull
0010 #define CSR_FCP_RESPONSE 0xfffff0000d00ull
0011
0012 static const char * const ctype_names[] = {
0013 [0x0] = "control", [0x8] = "not implemented",
0014 [0x1] = "status", [0x9] = "accepted",
0015 [0x2] = "specific inquiry", [0xa] = "rejected",
0016 [0x3] = "notify", [0xb] = "in transition",
0017 [0x4] = "general inquiry", [0xc] = "stable",
0018 [0x5] = "(reserved 0x05)", [0xd] = "changed",
0019 [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
0020 [0x7] = "(reserved 0x07)", [0xf] = "interim",
0021 };
0022
0023 static const char * const subunit_type_names[] = {
0024 [0x00] = "monitor", [0x10] = "(reserved 0x10)",
0025 [0x01] = "audio", [0x11] = "(reserved 0x11)",
0026 [0x02] = "printer", [0x12] = "(reserved 0x12)",
0027 [0x03] = "disc", [0x13] = "(reserved 0x13)",
0028 [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
0029 [0x05] = "tuner", [0x15] = "(reserved 0x15)",
0030 [0x06] = "ca", [0x16] = "(reserved 0x16)",
0031 [0x07] = "camera", [0x17] = "(reserved 0x17)",
0032 [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
0033 [0x09] = "panel", [0x19] = "(reserved 0x19)",
0034 [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
0035 [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
0036 [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
0037 [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
0038 [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
0039 [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
0040 };
0041
0042 struct avc_enum {
0043 int value;
0044 const char *name;
0045 };
0046
0047 struct avc_field {
0048 const char *name;
0049 int offset;
0050
0051 int width;
0052 struct avc_enum *names;
0053 };
0054
0055 struct avc_opcode_info {
0056 const char *name;
0057 struct avc_field fields[8];
0058 };
0059
0060 struct avc_enum power_field_names[] = {
0061 { 0x70, "on" },
0062 { 0x60, "off" },
0063 { }
0064 };
0065
0066 static const struct avc_opcode_info opcode_info[256] = {
0067
0068
0069
0070 [0xb2] = { "power", {
0071 { "state", 0, 8, power_field_names }
0072 }
0073 },
0074 [0x30] = { "unit info", {
0075 { "foo", 0, 8 },
0076 { "unit_type", 8, 5 },
0077 { "unit", 13, 3 },
0078 { "company id", 16, 24 },
0079 }
0080 },
0081 [0x31] = { "subunit info" },
0082 [0x01] = { "reserve" },
0083 [0xb0] = { "version" },
0084 [0x00] = { "vendor dependent" },
0085 [0x02] = { "plug info" },
0086 [0x12] = { "channel usage" },
0087 [0x24] = { "connect" },
0088 [0x20] = { "connect av" },
0089 [0x22] = { "connections" },
0090 [0x11] = { "digital input" },
0091 [0x10] = { "digital output" },
0092 [0x25] = { "disconnect" },
0093 [0x21] = { "disconnect av" },
0094 [0x19] = { "input plug signal format" },
0095 [0x18] = { "output plug signal format" },
0096 [0x1f] = { "general bus setup" },
0097
0098
0099
0100 [0x0c] = { "create descriptor" },
0101 [0x08] = { "open descriptor" },
0102 [0x09] = { "read descriptor" },
0103 [0x0a] = { "write descriptor" },
0104 [0x05] = { "open info block" },
0105 [0x06] = { "read info block" },
0106 [0x07] = { "write info block" },
0107 [0x0b] = { "search descriptor" },
0108 [0x0d] = { "object number select" },
0109
0110
0111
0112 [0xb3] = { "rate", {
0113 { "subfunction", 0, 8 },
0114 { "result", 8, 8 },
0115 { "plug_type", 16, 8 },
0116 { "plug_id", 16, 8 },
0117 }
0118 },
0119
0120
0121
0122 [0xb8] = { "function block" },
0123
0124
0125
0126 [0x7d] = { "gui update" },
0127 [0x7e] = { "push gui data" },
0128 [0x7f] = { "user action" },
0129 [0x7c] = { "pass through" },
0130
0131
0132 [0x26] = { "asynchronous connection" },
0133 };
0134
0135 struct avc_frame {
0136 uint32_t operand0:8;
0137 uint32_t opcode:8;
0138 uint32_t subunit_id:3;
0139 uint32_t subunit_type:5;
0140 uint32_t ctype:4;
0141 uint32_t cts:4;
0142 };
0143
0144 static void
0145 decode_avc(struct link_transaction *t)
0146 {
0147 struct avc_frame *frame =
0148 (struct avc_frame *) t->request->packet.write_block.data;
0149 const struct avc_opcode_info *info;
0150 const char *name;
0151 char buffer[32];
0152 int i;
0153
0154 info = &opcode_info[frame->opcode];
0155 if (info->name == NULL) {
0156 snprintf(buffer, sizeof(buffer),
0157 "(unknown opcode 0x%02x)", frame->opcode);
0158 name = buffer;
0159 } else {
0160 name = info->name;
0161 }
0162
0163 printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
0164 ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
0165 frame->subunit_id, name);
0166
0167 for (i = 0; info->fields[i].name != NULL; i++)
0168 printf(", %s", info->fields[i].name);
0169
0170 printf("\n");
0171 }
0172
0173 int
0174 decode_fcp(struct link_transaction *t)
0175 {
0176 struct avc_frame *frame =
0177 (struct avc_frame *) t->request->packet.write_block.data;
0178 unsigned long long offset =
0179 ((unsigned long long) t->request->packet.common.offset_high << 32) |
0180 t->request->packet.common.offset_low;
0181
0182 if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK_REQUEST)
0183 return 0;
0184
0185 if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
0186 switch (frame->cts) {
0187 case 0x00:
0188 decode_avc(t);
0189 break;
0190 case 0x01:
0191 printf("cal fcp frame (cts=0x01)\n");
0192 break;
0193 case 0x02:
0194 printf("ehs fcp frame (cts=0x02)\n");
0195 break;
0196 case 0x03:
0197 printf("havi fcp frame (cts=0x03)\n");
0198 break;
0199 case 0x0e:
0200 printf("vendor specific fcp frame (cts=0x0e)\n");
0201 break;
0202 case 0x0f:
0203 printf("extended cts\n");
0204 break;
0205 default:
0206 printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
0207 break;
0208 }
0209 return 1;
0210 }
0211
0212 return 0;
0213 }
0214