Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 1 | #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 Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 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", |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 18 | }; |
| 19 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 20 | static 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct avc_enum { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 40 | int value; |
| 41 | const char *name; |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | struct avc_field { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 45 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct avc_opcode_info { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 53 | const char *name; |
| 54 | struct avc_field fields[8]; |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct avc_enum power_field_names[] = { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 58 | { 0x70, "on" }, |
| 59 | { 0x60, "off" }, |
| 60 | { } |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static const struct avc_opcode_info opcode_info[256] = { |
| 64 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 65 | /* 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 94 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 95 | /* 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 106 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 107 | /* 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 116 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 117 | /* TA Document 1999008 */ |
| 118 | /* AV/C Audio Subunit Specification 1.0 */ |
| 119 | [0xb8] = { "function block" }, |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 120 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 121 | /* 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 127 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 128 | /* */ |
| 129 | [0x26] = { "asynchronous connection" }, |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | struct avc_frame { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 133 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static void |
| 142 | decode_avc(struct link_transaction *t) |
| 143 | { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 144 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 150 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 151 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 159 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 160 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 163 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 164 | for (i = 0; info->fields[i].name != NULL; i++) |
| 165 | printf(", %s", info->fields[i].name); |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 166 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 167 | printf("\n"); |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 170 | int |
| 171 | decode_fcp(struct link_transaction *t) |
| 172 | { |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 173 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 178 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 179 | if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK) |
| 180 | return 0; |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 181 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 182 | 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 Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 207 | } |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 208 | |
Stefan Richter | 92c16f7 | 2010-07-22 11:58:05 +0200 | [diff] [blame^] | 209 | return 0; |
Stefan Richter | 9f6d3c4 | 2010-07-22 11:58:05 +0200 | [diff] [blame] | 210 | } |
| 211 | |