| 68 | void |
| 69 | DumpDescriptorData(const usb_generic_descriptor* descriptor) |
| 70 | { |
| 71 | printf(" Type ............. 0x%02x\n", |
| 72 | descriptor->descriptor_type); |
| 73 | |
| 74 | printf(" Data ............. "); |
| 75 | //len includes len and descriptor_type field |
| 76 | for (int32 i = 0; i < descriptor->length - 2; i++) |
| 77 | printf("%02x ", descriptor->data[i]); |
| 78 | printf("\n"); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void |
| 83 | DumpAudioCSInterfaceDescriptorHeader( |
| 84 | const usb_audiocontrol_header_descriptor* descriptor) |
| 85 | { |
| 86 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 87 | descriptor->descriptor_type); |
| 88 | |
| 89 | printf(" Subtype ........... %u (HEADER)\n", |
| 90 | descriptor->descriptor_subtype); |
| 91 | printf(" bcdADC Release date 0x%04x\n", |
| 92 | descriptor->bcd_release_no); |
| 93 | printf(" Total Length ...... %u\n", |
| 94 | descriptor->r1.total_length); |
| 95 | printf(" In Collection ..... %u\n", |
| 96 | descriptor->r1.in_collection); |
| 97 | |
| 98 | for (uint8 i = 0; i < descriptor->r1.in_collection; i++) |
| 99 | printf(" Interface nr.%u ... %u\n", |
| 100 | i + 1, descriptor->r1.interface_numbers[i]); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | void |
| 105 | DumpChannelConfig(uint32 wChannelConfig) |
| 106 | { |
| 107 | const char* kChannelConfigStrings[] = { |
| 108 | "Left Front (L)", |
| 109 | "Right Front (R)", |
| 110 | "Ceter Front (C)", |
| 111 | "Low Frequency Enchancement (LFE)", |
| 112 | "Left Surround (Ls)", |
| 113 | "Right Surround (Rs)", |
| 114 | "Left of Center (Lc)", |
| 115 | "Right of Center (Rc)", |
| 116 | "Surround (S)", |
| 117 | "Side Left (Sl)", |
| 118 | "Side Right (Sr)", |
| 119 | "Top (T)" |
| 120 | }; |
| 121 | const char* indent = " "; |
| 122 | |
| 123 | int mask = 1; |
| 124 | for (uint8 i = 0; i < 13; i++) { |
| 125 | if (wChannelConfig & mask) |
| 126 | printf("%s%s\n", indent, kChannelConfigStrings[i]); |
| 127 | mask <<= 1; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | const char* |
| 133 | InputTerminalTypeName(uint16 terminalType) |
| 134 | { |
| 135 | switch (terminalType) { |
| 136 | case 0x0200: |
| 137 | return "Undefined"; |
| 138 | case 0x0201: |
| 139 | return "Microphone"; |
| 140 | case 0x0202: |
| 141 | return "Desktop microphone"; |
| 142 | case 0x0203: |
| 143 | return "Personal microphone"; |
| 144 | case 0x0204: |
| 145 | return "Omni-directional microphone"; |
| 146 | case 0x0205: |
| 147 | return "Microphone array"; |
| 148 | case 0x0206: |
| 149 | return "Processing microphone array"; |
| 150 | default: |
| 151 | return "Unknown"; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | |
| 156 | const char* |
| 157 | OutputTerminalTypeName(uint16 terminalType) |
| 158 | { |
| 159 | switch (terminalType) { |
| 160 | case 0x0300: |
| 161 | return "Undefined"; |
| 162 | case 0x0301: |
| 163 | return "Speaker"; |
| 164 | case 0x0302: |
| 165 | return "Headphones"; |
| 166 | case 0x0303: |
| 167 | return "Head Mounted Display Audio"; |
| 168 | case 0x0304: |
| 169 | return "Desktop speaker"; |
| 170 | case 0x0305: |
| 171 | return "Room speaker"; |
| 172 | case 0x0306: |
| 173 | return "Communication speaker"; |
| 174 | case 0x0307: |
| 175 | return "Low frequency effects speaker"; |
| 176 | default: |
| 177 | return "Unknown"; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | |
| 182 | void |
| 183 | DumpAudioCSInterfaceDescriptorInputTerminal( |
| 184 | const usb_audio_input_terminal_descriptor* descriptor) |
| 185 | { |
| 186 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 187 | descriptor->descriptor_type); |
| 188 | printf(" Subtype ........... %u (INPUT_TERMINAL)\n", |
| 189 | descriptor->descriptor_subtype); |
| 190 | printf(" Terminal ID ....... %u\n", |
| 191 | descriptor->terminal_id); |
| 192 | printf(" Terminal Type ..... %u (%s)\n", |
| 193 | descriptor->terminal_type, |
| 194 | InputTerminalTypeName(descriptor->terminal_type)); |
| 195 | printf(" Associated Terminal %u\n", |
| 196 | descriptor->assoc_terminal); |
| 197 | printf(" Nr Channels ....... %u\n", |
| 198 | descriptor->r1.num_channels); |
| 199 | printf(" Channel Config .... %u\n", |
| 200 | descriptor->r1.channel_config); |
| 201 | DumpChannelConfig(descriptor->r1.channel_config); |
| 202 | |
| 203 | printf(" Channel Names ..... %u\n", |
| 204 | descriptor->r1.channel_names); |
| 205 | printf(" Terminal .......... %u\n", |
| 206 | descriptor->r1.terminal); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | void |
| 211 | DumpAudioCSInterfaceDescriptorOutputTerminal( |
| 212 | const usb_audio_output_terminal_descriptor* descriptor) |
| 213 | { |
| 214 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 215 | descriptor->descriptor_type); |
| 216 | printf(" Subtype ........... %u (OUTPUT_TERMINAL)\n", |
| 217 | descriptor->descriptor_subtype); |
| 218 | printf(" Terminal ID ....... %u\n", |
| 219 | descriptor->terminal_id); |
| 220 | printf(" Terminal Type ..... %u (%s)\n", |
| 221 | descriptor->terminal_type, |
| 222 | InputTerminalTypeName(descriptor->terminal_type)); |
| 223 | printf(" Associated Terminal %u\n", |
| 224 | descriptor->assoc_terminal); |
| 225 | printf(" Source ID ......... %u\n", |
| 226 | descriptor->source_id); |
| 227 | printf(" Terminal .......... %u\n", |
| 228 | descriptor->r1.terminal); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | void |
| 233 | DumpAudioCSInterfaceDescriptorMixerUnit( |
| 234 | const usb_audio_mixer_unit_descriptor* descriptor) |
| 235 | { |
| 236 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 237 | descriptor->descriptor_type); |
| 238 | printf(" Subtype ........... %u (MIXER_UNIT)\n", |
| 239 | descriptor->descriptor_subtype); |
| 240 | printf(" Unit ID ........... %u\n", |
| 241 | descriptor->unit_id); |
| 242 | |
| 243 | printf(" Input Pins ........ %u\n", |
| 244 | descriptor->num_input_pins); |
| 245 | for (uint8 i = 0; i < descriptor->num_input_pins; i++) |
| 246 | printf(" Source ID %u ...... %u\n", |
| 247 | i + 1, descriptor->input_pins[i]); |
| 248 | |
| 249 | usb_audio_output_channels_descriptor_r1* channels = |
| 250 | (usb_audio_output_channels_descriptor_r1*) |
| 251 | descriptor + descriptor->num_input_pins + 5; |
| 252 | printf(" Channels .......... %u\n", |
| 253 | channels->num_output_pins); |
| 254 | printf(" Channel Config .... %u\n", |
| 255 | channels->channel_config); |
| 256 | DumpChannelConfig(channels->channel_config); |
| 257 | printf(" Channel Names ..... %u\n", |
| 258 | channels->channel_names); |
| 259 | |
| 260 | usb_generic_descriptor* generic = (usb_generic_descriptor*)descriptor; |
| 261 | uint8 idx = 7 + descriptor->num_input_pins; |
| 262 | for (uint i = 1; idx < descriptor->length - 3; idx++, i++) |
| 263 | printf(" Bitmap Control .... %u: %u\n", i, |
| 264 | (uint8)generic->data[idx]); |
| 265 | |
| 266 | printf(" Mixer ............. %u\n", |
| 267 | generic->data[generic->length - 3]); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | void |
| 272 | DumpAudioCSInterfaceDescriptorSelectorUnit( |
| 273 | const usb_audio_selector_unit_descriptor* descriptor) |
| 274 | { |
| 275 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 276 | descriptor->descriptor_type); |
| 277 | printf(" Subtype ........... %u (SELECTOR_UNIT)\n", |
| 278 | descriptor->descriptor_subtype); |
| 279 | printf(" Unit ID ........... %u\n", |
| 280 | descriptor->unit_id); |
| 281 | |
| 282 | printf(" Input Pins ........ %u\n", |
| 283 | descriptor->num_input_pins); |
| 284 | for (uint8 i = 0; i < descriptor->num_input_pins; i++) |
| 285 | printf(" Source ID %u .. %u\n", |
| 286 | i + 1, descriptor->input_pins[i]); |
| 287 | |
| 288 | usb_generic_descriptor* generic = (usb_generic_descriptor*)descriptor; |
| 289 | printf(" Selector .......... %u\n", |
| 290 | (uint8)generic->data[descriptor->num_input_pins+2]); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | void |
| 295 | DumpBMAControl(uint16 bma) |
| 296 | { |
| 297 | const char* BMAControlStrings[] = { |
| 298 | "Mute", |
| 299 | "Volume", |
| 300 | "Bass", |
| 301 | "Mid", |
| 302 | "Treble", |
| 303 | "Graphic Equalizer", |
| 304 | "Automatic Gain", |
| 305 | "Delay", |
| 306 | "Bass Boost", |
| 307 | "Loudness" |
| 308 | }; |
| 309 | const char* indent = " "; |
| 310 | |
| 311 | int mask = 1; |
| 312 | for (uint8 i = 0; i < 11; i++) { |
| 313 | if(bma & mask) |
| 314 | printf("%s%s\n", indent, BMAControlStrings[i]); |
| 315 | mask <<= 1; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | |
| 320 | void |
| 321 | DumpAudioCSInterfaceDescriptorFeatureUnit( |
| 322 | const usb_audio_feature_unit_descriptor* descriptor) |
| 323 | { |
| 324 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 325 | descriptor->descriptor_type); |
| 326 | printf(" Subtype ........... %u (FEATURE_UNIT)\n", |
| 327 | descriptor->descriptor_subtype); |
| 328 | printf(" Unit ID ........... %u\n", |
| 329 | descriptor->unit_id); |
| 330 | printf(" Source ID ......... %u\n", |
| 331 | descriptor->source_id); |
| 332 | |
| 333 | printf(" Control Size ...... %u\n", |
| 334 | descriptor->r1.control_size); |
| 335 | uint8 channels = (descriptor->length - 6) / descriptor->r1.control_size; |
| 336 | if (descriptor->r1.control_size == 1) { |
| 337 | for (uint8 i = 0; i < channels; i++) { |
| 338 | printf(" BMA Control %u .... %u\n", |
| 339 | i + 1, (uint8)descriptor->r1.bma_controls[i]); |
| 340 | DumpBMAControl((uint8)descriptor->r1.bma_controls[i]); |
| 341 | } |
| 342 | } else if (descriptor->r1.control_size == 2) { |
| 343 | for (uint8 i = 0; i < channels; i++) { |
| 344 | printf(" BMA Control %u .... %u\n", |
| 345 | i + 1, (uint16)descriptor->r1.bma_controls[i * 2]); |
| 346 | DumpBMAControl((uint16)descriptor->r1.bma_controls[i * 2]); |
| 347 | } |
| 348 | } else { |
| 349 | for (uint8 i = 0; i < channels; i++) { |
| 350 | printf(" BMA Control Raw ... "); |
| 351 | for(uint8 j = 0; j < descriptor->r1.control_size; j++) { |
| 352 | printf("%02x ", descriptor->r1.bma_controls[i+j]); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | usb_generic_descriptor* generic = (usb_generic_descriptor*)descriptor; |
| 358 | printf(" Feature ........... %u\n", |
| 359 | (uint8)generic->data[descriptor->length - 3]); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | void |
| 364 | DumpAudioCSInterfaceDescriptorAssociated( |
| 365 | const usb_generic_descriptor* descriptor) |
| 366 | { |
| 367 | printf(" Type .............. %u (CS_INTERFACE)\n", |
| 368 | descriptor->descriptor_type); |
| 369 | printf(" Subtype ........... %u (ASSOC_INTERFACE)\n", |
| 370 | (uint8)descriptor->data[0]); |
| 371 | printf(" Interface ......... %u\n", |
| 372 | (uint8)descriptor->data[1]); |
| 373 | |
| 374 | printf(" Data .............. "); |
| 375 | for (uint8 i = 0; i < descriptor->length - 2; i++) |
| 376 | printf("%02x ", descriptor->data[i]); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | void |
| 381 | DumpAudioCSInterfaceDescriptor(const usb_generic_descriptor* descriptor) |
| 382 | { |
| 383 | uint16 descriptorSubtype = descriptor->data[0]; |
| 384 | switch (descriptorSubtype) { |
| 385 | case USB_AUDIO_AC_HEADER: |
| 386 | DumpAudioCSInterfaceDescriptorHeader( |
| 387 | (usb_audiocontrol_header_descriptor*)descriptor); |
| 388 | break; |
| 389 | case USB_AUDIO_AC_INPUT_TERMINAL: |
| 390 | DumpAudioCSInterfaceDescriptorInputTerminal( |
| 391 | (usb_audio_input_terminal_descriptor*)descriptor); |
| 392 | break; |
| 393 | case USB_AUDIO_AC_OUTPUT_TERMINAL: |
| 394 | DumpAudioCSInterfaceDescriptorOutputTerminal( |
| 395 | (usb_audio_output_terminal_descriptor*)descriptor); |
| 396 | break; |
| 397 | case USB_AUDIO_AC_MIXER_UNIT: |
| 398 | DumpAudioCSInterfaceDescriptorMixerUnit( |
| 399 | (usb_audio_mixer_unit_descriptor*)descriptor); |
| 400 | break; |
| 401 | case USB_AUDIO_AC_SELECTOR_UNIT: |
| 402 | DumpAudioCSInterfaceDescriptorSelectorUnit( |
| 403 | (usb_audio_selector_unit_descriptor*)descriptor); |
| 404 | break; |
| 405 | case USB_AUDIO_AC_FEATURE_UNIT: |
| 406 | DumpAudioCSInterfaceDescriptorFeatureUnit( |
| 407 | (usb_audio_feature_unit_descriptor*)descriptor); |
| 408 | break; |
| 409 | case USB_AUDIO_AC_EXTENSION_UNIT: |
| 410 | DumpAudioCSInterfaceDescriptorAssociated(descriptor); |
| 411 | break; |
| 412 | default: |
| 413 | DumpDescriptorData(descriptor); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | |
| 418 | void |
| 419 | DumpAudioDescriptor(const usb_generic_descriptor* descriptor) |
| 420 | { |
| 421 | switch (descriptor->descriptor_type) { |
| 422 | case USB_AUDIO_CS_INTERFACE: |
| 423 | DumpAudioCSInterfaceDescriptor(descriptor); |
| 424 | break; |
| 425 | default: |
| 426 | DumpDescriptorData(descriptor); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | |
| 431 | void |
| 432 | DumpDescriptor(const usb_generic_descriptor* descriptor, int classNum) |
| 433 | { |
| 434 | switch (classNum) { |
| 435 | case 1: |
| 436 | DumpAudioDescriptor(descriptor); |
| 437 | break; |
| 438 | default: |
| 439 | DumpDescriptorData(descriptor); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | |