packaging: Build PIE executables to allow address space randomization
[platform/upstream/usbutils.git] / desc-defs.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * USB descriptor definitions
4  *
5  * Copyright (C) 2017-2018 Michael Drake <michael.drake@codethink.co.uk>
6  */
7
8 #include "config.h"
9
10 #include <stdbool.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13
14 #include "desc-defs.h"
15
16 /** Macro for computing number of elements in array. */
17 #define ARRAY_LEN(a) ((sizeof(a)) / (sizeof(a[0])))
18
19 /**
20  * Undefined descriptor
21  *
22  * Ensures remaining data is dumped as garbage at end of descriptor.
23  */
24 const struct desc desc_undefined[] = {
25         { .field = NULL }
26 };
27
28 /** USB Audio Device Class 1 Channel Names.  (Note: Order matters.) */
29 static const char * const uac1_channel_names[] = {
30         "Left Front (L)", "Right Front (R)", "Center Front (C)",
31         "Low Frequency Enhancement (LFE)", "Left Surround (LS)",
32         "Right Surround (RS)", "Left of Center (LC)", "Right of Center (RC)",
33         "Surround (S)", "Side Left (SL)", "Side Right (SR)", "Top (T)"
34 };
35
36 /** USB Audio Device Class 2 Channel Names.  (Note: Order matters.) */
37 static const char * const uac2_channel_names[] = {
38         "Front Left (FL)", "Front Right (FR)", "Front Center (FC)",
39         "Low Frequency Effects (LFE)", "Back Left (BL)", "Back Right (BR)",
40         "Front Left of Center (FLC)", "Front Right of Center (FRC)",
41         "Back Center (BC)", "Side Left (SL)", "Side Right (SR)",
42         "Top Center (TC)", "Top Front Left (TFL)", "Top Front Center (TFC)",
43         "Top Front Right (TFR)", "Top Back Left (TBL)", "Top Back Center (TBC)",
44         "Top Back Right (TBR)", "Top Front Left of Center (TFLC)",
45         "Top Front Right of Center (TFRC)", "Left Low Frequency Effects (LLFE)",
46         "Right Low Frequency Effects (RLFE)", "Top Side Left (TSL)",
47         "Top Side Right (TSR)", "Bottom Center (BC)",
48         "Back Left of Center (BLC)", "Back Right of Center (BRC)"
49 };
50
51 /** Audio Control Interface Header bmControls; Human readable bit meanings. */
52 static const char * const uac2_interface_header_bmcontrols[] = {
53         [0] = "Latency control",
54         [1] = NULL
55 };
56
57 /** UAC1: 4.3.2 Class-Specific AC Interface Descriptor; Table 4-2. */
58 static const struct desc desc_audio_1_ac_header[] = {
59         { .field = "bcdADC",        .size = 2, .type = DESC_BCD },
60         { .field = "wTotalLength",  .size = 2, .type = DESC_CONSTANT },
61         { .field = "bInCollection", .size = 1, .type = DESC_CONSTANT },
62         { .field = "baInterfaceNr", .size = 1, .type = DESC_NUMBER,
63                         .array = { .array = true } },
64         { .field = NULL }
65 };
66
67 /** UAC2: 4.7.2 Class-Specific AC Interface Descriptor; Table 4-5. */
68 static const struct desc desc_audio_2_ac_header[] = {
69         { .field = "bcdADC",       .size = 2, .type = DESC_BCD },
70         { .field = "bCategory",    .size = 1, .type = DESC_CONSTANT },
71         { .field = "wTotalLength", .size = 2, .type = DESC_NUMBER },
72         { .field = "bmControls",   .size = 1, .type = DESC_BMCONTROL_2,
73                         .bmcontrol = uac2_interface_header_bmcontrols },
74         { .field = NULL }
75 };
76
77 /** UAC3: 4.5.2 Class-Specific AC Interface Descriptor; Table 4-15. */
78 static const struct desc desc_audio_3_ac_header[] = {
79         { .field = "bCategory",    .size = 1, .type = DESC_CONSTANT },
80         { .field = "wTotalLength", .size = 2, .type = DESC_NUMBER },
81         { .field = "bmControls",   .size = 4, .type = DESC_BMCONTROL_2,
82                         .bmcontrol = uac2_interface_header_bmcontrols },
83         { .field = NULL }
84 };
85
86 /** AudioControl Header descriptor definitions for the three Audio Device Class protocols */
87 const struct desc * const desc_audio_ac_header[3] = {
88         desc_audio_1_ac_header,
89         desc_audio_2_ac_header,
90         desc_audio_3_ac_header,
91 };
92
93 /** UAC2: 4.7.2.10 Effect Unit Descriptor; Table 4-15. */
94 static const struct desc desc_audio_2_ac_effect_unit[] = {
95         { .field = "bUnitID",     .size = 1, .type = DESC_NUMBER },
96         { .field = "wEffectType", .size = 2, .type = DESC_CONSTANT },
97         { .field = "bSourceID",   .size = 1, .type = DESC_CONSTANT },
98         { .field = "bmaControls", .size = 4, .type = DESC_BITMAP,
99                         .array = { .array = true } },
100         { .field = "iEffects",    .size = 1, .type = DESC_STR_DESC_INDEX },
101         { .field = NULL }
102 };
103
104 /** UAC3: 4.5.2.9 Effect Unit Descriptor; Table 4-33. */
105 static const struct desc desc_audio_3_ac_effect_unit[] = {
106         { .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
107         { .field = "wEffectType",      .size = 2, .type = DESC_CONSTANT },
108         { .field = "bSourceID",        .size = 1, .type = DESC_CONSTANT },
109         { .field = "bmaControls",      .size = 4, .type = DESC_BITMAP,
110                         .array = { .array = true } },
111         { .field = "wEffectsDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
112         { .field = NULL }
113 };
114
115 /** Effect Unit descriptor definitions for the three Audio Device Class protocols */
116 const struct desc * const desc_audio_ac_effect_unit[3] = {
117         NULL, /* UAC1 not supported */
118         desc_audio_2_ac_effect_unit,
119         desc_audio_3_ac_effect_unit,
120 };
121
122 /** UAC2 Input Terminal bmControls; Human readable bit meanings. */
123 static const char * const uac2_input_term_bmcontrols[] = {
124         [0] = "Copy Protect",
125         [1] = "Connector",
126         [2] = "Overload",
127         [3] = "Cluster",
128         [4] = "Underflow",
129         [5] = "Overflow",
130         [6] = NULL
131 };
132
133 /** UAC3 Input Terminal bmControls; Human readable bit meanings. */
134 static const char * const uac3_input_term_bmcontrols[] = {
135         [0] = "Insertion",
136         [1] = "Overload",
137         [2] = "Underflow",
138         [3] = "Overflow",
139         [4] = "Underflow",
140         [5] = NULL
141 };
142
143 /** UAC1: 4.3.2.1 Input Terminal Descriptor; Table 4-3. */
144 static const struct desc desc_audio_1_ac_input_terminal[] = {
145         { .field = "bTerminalID",    .size = 1, .type = DESC_NUMBER },
146         { .field = "wTerminalType",  .size = 2, .type = DESC_TERMINAL_STR },
147         { .field = "bAssocTerminal", .size = 1, .type = DESC_CONSTANT },
148         { .field = "bNrChannels",    .size = 1, .type = DESC_NUMBER },
149         { .field = "wChannelConfig", .size = 2, .type = DESC_BITMAP_STRINGS,
150                         .bitmap_strings = { .strings = uac1_channel_names, .count = 12 } },
151         { .field = "iChannelNames",  .size = 1, .type = DESC_STR_DESC_INDEX },
152         { .field = "iTerminal",      .size = 1, .type = DESC_STR_DESC_INDEX },
153         { .field = NULL }
154 };
155
156 /** UAC2: 4.7.2.4 Input Terminal Descriptor; Table 4-9. */
157 static const struct desc desc_audio_2_ac_input_terminal[] = {
158         { .field = "bTerminalID",     .size = 1, .type = DESC_NUMBER },
159         { .field = "wTerminalType",   .size = 2, .type = DESC_TERMINAL_STR },
160         { .field = "bAssocTerminal",  .size = 1, .type = DESC_CONSTANT },
161         { .field = "bCSourceID",      .size = 1, .type = DESC_CONSTANT },
162         { .field = "bNrChannels",     .size = 1, .type = DESC_NUMBER },
163         { .field = "bmChannelConfig", .size = 4, .type = DESC_BITMAP_STRINGS,
164                         .bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
165         { .field = "iChannelNames",   .size = 1, .type = DESC_STR_DESC_INDEX },
166         { .field = "bmControls",      .size = 2, .type = DESC_BMCONTROL_2,
167                         .bmcontrol = uac2_input_term_bmcontrols },
168         { .field = "iTerminal",       .size = 1, .type = DESC_STR_DESC_INDEX },
169         { .field = NULL }
170 };
171
172 /** UAC3: 4.5.2.1 Input Terminal Descriptor; Table 4-16. */
173 static const struct desc desc_audio_3_ac_input_terminal[] = {
174         { .field = "bTerminalID",        .size = 1, .type = DESC_NUMBER },
175         { .field = "wTerminalType",      .size = 2, .type = DESC_TERMINAL_STR },
176         { .field = "bAssocTerminal",     .size = 1, .type = DESC_NUMBER },
177         { .field = "bCSourceID",         .size = 1, .type = DESC_NUMBER },
178         { .field = "bmControls",         .size = 4, .type = DESC_BMCONTROL_2,
179                         .bmcontrol = uac3_input_term_bmcontrols },
180         { .field = "wClusterDescrID",    .size = 2, .type = DESC_NUMBER },
181         { .field = "wExTerminalDescrID", .size = 2, .type = DESC_NUMBER },
182         { .field = "wConnectorsDescrID", .size = 2, .type = DESC_NUMBER },
183         { .field = "wTerminalDescrStr",  .size = 2, .type = DESC_CS_STR_DESC_ID },
184         { .field = NULL }
185 };
186
187 /** Input Terminal descriptor definitions for the three Audio Device Class protocols */
188 const struct desc * const desc_audio_ac_input_terminal[3] = {
189         desc_audio_1_ac_input_terminal,
190         desc_audio_2_ac_input_terminal,
191         desc_audio_3_ac_input_terminal,
192 };
193
194 /** UAC2 Output Terminal bmControls; Human readable bit meanings. */
195 static const char * const uac2_output_term_bmcontrols[] = {
196         [0] = "Copy Protect",
197         [1] = "Connector",
198         [2] = "Overload",
199         [3] = "Underflow",
200         [4] = "Overflow",
201         [5] = NULL
202 };
203
204 /** UAC3 Output Terminal bmControls; Human readable bit meanings. */
205 static const char * const uac3_output_term_bmcontrols[] = {
206         [0] = "Insertion",
207         [1] = "Overload",
208         [2] = "Underflow",
209         [3] = "Overflow",
210         [4] = NULL
211 };
212
213 /** UAC1: 4.3.2.2 Output Terminal Descriptor; Table 4-4. */
214 static const struct desc desc_audio_1_ac_output_terminal[] = {
215         { .field = "bTerminalID",    .size = 1, .type = DESC_NUMBER },
216         { .field = "wTerminalType",  .size = 2, .type = DESC_TERMINAL_STR },
217         { .field = "bAssocTerminal", .size = 1, .type = DESC_NUMBER },
218         { .field = "bSourceID",      .size = 1, .type = DESC_NUMBER },
219         { .field = "iTerminal",      .size = 1, .type = DESC_STR_DESC_INDEX },
220         { .field = NULL }
221 };
222
223 /** UAC2: 4.7.2.5 Output Terminal Descriptor; Table 4-10. */
224 static const struct desc desc_audio_2_ac_output_terminal[] = {
225         { .field = "bTerminalID",    .size = 1, .type = DESC_NUMBER },
226         { .field = "wTerminalType",  .size = 2, .type = DESC_TERMINAL_STR },
227         { .field = "bAssocTerminal", .size = 1, .type = DESC_NUMBER },
228         { .field = "bSourceID",      .size = 1, .type = DESC_NUMBER },
229         { .field = "bCSourceID",     .size = 1, .type = DESC_NUMBER },
230         { .field = "bmControls",     .size = 2, .type = DESC_BMCONTROL_2,
231                         .bmcontrol = uac2_output_term_bmcontrols },
232         { .field = "iTerminal",      .size = 1, .type = DESC_STR_DESC_INDEX },
233         { .field = NULL }
234 };
235
236 /** UAC3: 4.5.2.2 Output Terminal Descriptor; Table 4-17. */
237 static const struct desc desc_audio_3_ac_output_terminal[] = {
238         { .field = "bTerminalID",        .size = 1, .type = DESC_NUMBER },
239         { .field = "wTerminalType",      .size = 2, .type = DESC_TERMINAL_STR },
240         { .field = "bAssocTerminal",     .size = 1, .type = DESC_NUMBER },
241         { .field = "bSourceID",          .size = 1, .type = DESC_NUMBER },
242         { .field = "bCSourceID",         .size = 1, .type = DESC_NUMBER },
243         { .field = "bmControls",         .size = 4, .type = DESC_BMCONTROL_2,
244                         .bmcontrol = uac3_output_term_bmcontrols },
245         { .field = "wExTerminalDescrID", .size = 2, .type = DESC_NUMBER },
246         { .field = "wConnectorsDescrID", .size = 2, .type = DESC_NUMBER },
247         { .field = "wTerminalDescrStr",  .size = 2, .type = DESC_CS_STR_DESC_ID },
248         { .field = NULL }
249 };
250
251 /** Output Terminal descriptor definitions for the three Audio Device Class protocols */
252 const struct desc * const desc_audio_ac_output_terminal[3] = {
253         desc_audio_1_ac_output_terminal,
254         desc_audio_2_ac_output_terminal,
255         desc_audio_3_ac_output_terminal,
256 };
257
258 /** UAC3: 4.5.2.3.1 Extended Terminal Header Descriptor; Table 4-18. */
259 static const struct desc desc_audio_3_ac_extended_terminal_header[] = {
260         { .field = "wDescriptorID", .size = 2, .type = DESC_NUMBER },
261         { .field = "bNrChannels",   .size = 1, .type = DESC_NUMBER },
262         { .field = NULL }
263 };
264
265 /** Extended Terminal descriptor definitions for the three Audio Device Class protocols */
266 const struct desc * const desc_audio_ac_extended_terminal[3] = {
267         NULL, /* UAC1 not supported */
268         NULL, /* UAC2 not supported */
269         desc_audio_3_ac_extended_terminal_header,
270 };
271
272 /** UAC3: 4.5.2.15 Power Domain Descriptor; Table 4-46. */
273 static const struct desc desc_audio_3_ac_power_domain[] = {
274         { .field = "bPowerDomainID",    .size = 1, .type = DESC_NUMBER },
275         { .field = "waRecoveryTime(1)", .size = 2, .type = DESC_NUMBER },
276         { .field = "waRecoveryTime(2)", .size = 2, .type = DESC_NUMBER },
277         { .field = "bNrEntities",       .size = 1, .type = DESC_NUMBER },
278         { .field = "baEntityID",        .size = 1, .type = DESC_NUMBER,
279                         .array = { .array = true, .length_field1 = "bNrEntities" } },
280         { .field = "wPDomainDescrStr",  .size = 2, .type = DESC_CS_STR_DESC_ID },
281         { .field = NULL }
282 };
283
284 /** Power Domain descriptor definitions for the three Audio Device Class protocols */
285 const struct desc * const desc_audio_ac_power_domain[3] = {
286         NULL, /* UAC1 not supported */
287         NULL, /* UAC2 not supported */
288         desc_audio_3_ac_power_domain,
289 };
290
291 /** UAC2 Mixer Unit bmControls; Human readable bit meanings. */
292 static const char * const uac2_mixer_unit_bmcontrols[] = {
293         [0] = "Cluster",
294         [1] = "Underflow",
295         [2] = "Overflow",
296         [3] = NULL
297 };
298
299 /** UAC3 Mixer Unit bmControls; Human readable bit meanings. */
300 static const char * const uac3_mixer_unit_bmcontrols[] = {
301         [0] = "Underflow",
302         [1] = "Overflow",
303         [2] = NULL
304 };
305
306 /** UAC1: 4.3.2.3 Mixer Unit Descriptor; Table 4-5. */
307 static const struct desc desc_audio_1_ac_mixer_unit[] = {
308         { .field = "bUnitID",        .size = 1, .type = DESC_NUMBER },
309         { .field = "bNrInPins",      .size = 1, .type = DESC_NUMBER },
310         { .field = "baSourceID",     .size = 1, .type = DESC_NUMBER,
311                         .array = { .array = true, .length_field1 = "bNrInPins" } },
312         { .field = "bNrChannels",    .size = 1, .type = DESC_NUMBER },
313         { .field = "wChannelConfig", .size = 2, .type = DESC_BITMAP_STRINGS,
314                         .bitmap_strings = { .strings = uac1_channel_names, .count = 12 } },
315         { .field = "iChannelNames",  .size = 1, .type = DESC_STR_DESC_INDEX },
316         { .field = "bmControls",     .size = 1, .type = DESC_BITMAP,
317                         .array = { .array = true, .bits = true,
318                                         .length_field1 = "bNrInPins",
319                                         .length_field2 = "bNrChannels" } },
320         { .field = "iMixer",         .size = 1, .type = DESC_STR_DESC_INDEX },
321         { .field = NULL }
322 };
323
324 /** UAC2: 4.7.2.6 Mixer Unit Descriptor; Table 4-11. */
325 static const struct desc desc_audio_2_ac_mixer_unit[] = {
326         { .field = "bUnitID",        .size = 1, .type = DESC_NUMBER },
327         { .field = "bNrInPins",      .size = 1, .type = DESC_NUMBER },
328         { .field = "baSourceID",     .size = 1, .type = DESC_NUMBER,
329                         .array = { .array = true, .length_field1 = "bNrInPins" } },
330         { .field = "bNrChannels",    .size = 1, .type = DESC_NUMBER },
331         { .field = "bmChannelConfig",.size = 4, .type = DESC_BITMAP_STRINGS,
332                         .bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
333         { .field = "iChannelNames",  .size = 1, .type = DESC_STR_DESC_INDEX },
334         { .field = "bmMixerControls",.size = 1, .type = DESC_BITMAP,
335                         .array = { .array = true, .bits = true,
336                                         .length_field1 = "bNrInPins",
337                                         .length_field2 = "bNrChannels" } },
338         { .field = "bmControls",     .size = 1, .type = DESC_BMCONTROL_2,
339                         .bmcontrol = uac2_mixer_unit_bmcontrols },
340         { .field = "iMixer",         .size = 1, .type = DESC_STR_DESC_INDEX },
341         { .field = NULL }
342 };
343
344 /** UAC3: 4.5.2.5 Mixer Unit Descriptor; Table 4-29. */
345 static const struct desc desc_audio_3_ac_mixer_unit[] = {
346         { .field = "bUnitID",        .size = 1, .type = DESC_NUMBER },
347         { .field = "bNrInPins",      .size = 1, .type = DESC_NUMBER },
348         { .field = "baSourceID",     .size = 1, .type = DESC_NUMBER,
349                         .array = { .array = true, .length_field1 = "bNrInPins" } },
350         { .field = "wClusterDescrID",.size = 2, .type = DESC_NUMBER },
351         { .field = "bmMixerControls",.size = 1, .type = DESC_BITMAP,
352                         .array = { .array = true } },
353         { .field = "bmControls",     .size = 4, .type = DESC_BMCONTROL_2,
354                         .bmcontrol = uac3_mixer_unit_bmcontrols },
355         { .field = "wMixerDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
356         { .field = NULL }
357 };
358
359 /** Mixer Unit descriptor definitions for the three Audio Device Class protocols */
360 const struct desc * const desc_audio_ac_mixer_unit[3] = {
361         desc_audio_1_ac_mixer_unit,
362         desc_audio_2_ac_mixer_unit,
363         desc_audio_3_ac_mixer_unit,
364 };
365
366 /** Selector Unit bmControls; Human readable bit meanings. */
367 static const char * const uac2_selector_unit_bmcontrols[] = {
368         [0] = "Selector",
369         [1] = NULL
370 };
371
372 /** UAC1: 4.3.2.4 Selector Unit Descriptor; Table 4-6. */
373 static const struct desc desc_audio_1_ac_selector_unit[] = {
374         { .field = "bUnitID",    .size = 1, .type = DESC_NUMBER },
375         { .field = "bNrInPins",  .size = 1, .type = DESC_NUMBER },
376         { .field = "baSourceID", .size = 1, .type = DESC_NUMBER,
377                         .array = { .array = true, .length_field1 = "bNrInPins" } },
378         { .field = "iSelector",  .size = 1, .type = DESC_STR_DESC_INDEX },
379         { .field = NULL }
380 };
381
382 /** UAC2: 4.7.2.7 Selector Unit Descriptor; Table 4-12. */
383 static const struct desc desc_audio_2_ac_selector_unit[] = {
384         { .field = "bUnitID",    .size = 1, .type = DESC_NUMBER },
385         { .field = "bNrInPins",  .size = 1, .type = DESC_NUMBER },
386         { .field = "baSourceID", .size = 1, .type = DESC_NUMBER,
387                         .array = { .array = true, .length_field1 = "bNrInPins" } },
388         { .field = "bmControls", .size = 1, .type = DESC_BMCONTROL_2,
389                         .bmcontrol = uac2_selector_unit_bmcontrols },
390         { .field = "iSelector",  .size = 1, .type = DESC_STR_DESC_INDEX },
391         { .field = NULL }
392 };
393
394 /** UAC3: 4.5.2.6 Selector Unit Descriptor; Table 4-30. */
395 static const struct desc desc_audio_3_ac_selector_unit[] = {
396         { .field = "bUnitID",           .size = 1, .type = DESC_NUMBER },
397         { .field = "bNrInPins",         .size = 1, .type = DESC_NUMBER },
398         { .field = "baSourceID",        .size = 1, .type = DESC_NUMBER,
399                         .array = { .array = true, .length_field1 = "bNrInPins" } },
400         { .field = "bmControls",        .size = 4, .type = DESC_BMCONTROL_2,
401                         .bmcontrol = uac2_selector_unit_bmcontrols },
402         { .field = "wSelectorDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
403         { .field = NULL }
404 };
405
406 /** Selector Unit descriptor definitions for the three Audio Device Class protocols */
407 const struct desc * const desc_audio_ac_selector_unit[3] = {
408         desc_audio_1_ac_selector_unit,
409         desc_audio_2_ac_selector_unit,
410         desc_audio_3_ac_selector_unit,
411 };
412
413 /** UAC1: Table A-7: Processing Unit Process Types */
414 static const char * const uac1_proc_unit_types[] = {
415         [0] = "Undefined",
416         [1] = "Up/Down-mix",
417         [2] = "Dolby Prologic",
418         [3] = "3D Stereo Extender",
419         [4] = "Reverberation",
420         [5] = "Chorus",
421         [6] = "Dyn Range Comp",
422         [7] = NULL
423 };
424
425 /** UAC1: Up/Down-mix and Dolby Prologic proc unit descriptor extensions Table 4-9, Table 4-10. */
426 static const struct desc desc_audio_1_ac_proc_unit_extended[] = {
427         { .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
428         { .field = "waModes",          .size = 2, .type = DESC_BITMAP,
429                         .array = { .array = true, .length_field1 = "bNrModes" } },
430         { .field = NULL }
431 };
432
433 /** UAC1: Table A-7: Processing Unit Process Types */
434 static const struct desc_ext desc_audio_1_ac_proc_unit_specific[] = {
435         { .type = 1, .desc = desc_audio_1_ac_proc_unit_extended },
436         { .type = 2, .desc = desc_audio_1_ac_proc_unit_extended },
437         { .desc = NULL }
438 };
439
440 /** UAC1: 4.3.2.6 Processing Unit Descriptor; Table 4-8. */
441 static const struct desc desc_audio_1_ac_processing_unit[] = {
442         { .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
443         { .field = "wProcessType",     .size = 2, .type = DESC_NUMBER_STRINGS,
444                         .number_strings = uac1_proc_unit_types },
445         { .field = "bNrInPins",        .size = 1, .type = DESC_NUMBER },
446         { .field = "baSourceID",       .size = 1, .type = DESC_NUMBER,
447                         .array = { .array = true, .length_field1 = "bNrInPins" } },
448         { .field = "bNrChannels",      .size = 1, .type = DESC_NUMBER },
449         { .field = "wChannelConfig",   .size = 2, .type = DESC_BITMAP_STRINGS,
450                         .bitmap_strings = { .strings = uac1_channel_names, .count = 12 } },
451         { .field = "iChannelNames",    .size = 1, .type = DESC_STR_DESC_INDEX },
452         { .field = "bControlSize",     .size = 1, .type = DESC_NUMBER },
453         { .field = "bmControls",       .size = 1, .type = DESC_BITMAP,
454                         .array = { .array = true, .length_field1 = "bControlSize" } },
455         { .field = "iProcessing",      .size = 1, .type = DESC_STR_DESC_INDEX },
456         { .field = "Process-specific", .size = 1, .type = DESC_EXTENSION,
457                 .extension = { .type_field = "wProcessType", .d = desc_audio_1_ac_proc_unit_specific } },
458         { .field = NULL }
459 };
460
461 /** UAC2: 4.7.2.11.1 Up/Down-mix Processing Unit Descriptor; Table 4-21. */
462 static const struct desc desc_audio_2_ac_proc_unit_up_down_mix[] = {
463         { .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
464         { .field = "daModes",          .size = 4, .type = DESC_BITMAP,
465                         .array = { .array = true, .length_field1 = "bNrModes" } },
466         { .field = NULL }
467 };
468
469 /** UAC2: 4.7.2.11.2 Dolby prologic Processing Unit Descriptor; Table 4-22. */
470 static const struct desc desc_audio_2_ac_proc_unit_dolby_prologic[] = {
471         { .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
472         { .field = "daModes",          .size = 4, .type = DESC_BITMAP,
473                         .array = { .array = true, .length_field1 = "bNrModes" } },
474         { .field = NULL }
475 };
476
477 /** UAC2: Table A-12: Processing Unit Process Types */
478 static const struct desc_ext desc_audio_2_ac_proc_unit_specific[] = {
479         { .type = 1, .desc = desc_audio_2_ac_proc_unit_up_down_mix },
480         { .type = 2, .desc = desc_audio_2_ac_proc_unit_dolby_prologic },
481         { .desc = NULL }
482 };
483
484 /** UAC2: Table A-12: Processing Unit Process Types */
485 static const char * const uac2_proc_unit_types[] = {
486         [0] = "Undefined",
487         [1] = "Up/Down-mix",
488         [2] = "Dolby Prologic",
489         [3] = "Stereo Extender",
490         [4] = NULL
491 };
492
493 /** UAC2: 4.7.2.11 Processing Unit Descriptor; Table 4-20. */
494 static const struct desc desc_audio_2_ac_processing_unit[] = {
495         { .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
496         { .field = "wProcessType",     .size = 2, .type = DESC_NUMBER_STRINGS,
497                         .number_strings = uac2_proc_unit_types },
498         { .field = "bNrInPins",        .size = 1, .type = DESC_NUMBER },
499         { .field = "baSourceID",       .size = 1, .type = DESC_NUMBER,
500                         .array = { .array = true, .length_field1 = "bNrInPins" } },
501         { .field = "bNrChannels",      .size = 1, .type = DESC_NUMBER },
502         { .field = "bmChannelConfig",  .size = 4, .type = DESC_BITMAP_STRINGS,
503                         .bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
504         { .field = "iChannelNames",    .size = 1, .type = DESC_STR_DESC_INDEX },
505         { .field = "bmControls",       .size = 2, .type = DESC_BITMAP },
506         { .field = "iProcessing",      .size = 1, .type = DESC_STR_DESC_INDEX },
507         { .field = "Process-specific", .size = 1, .type = DESC_EXTENSION,
508                 .extension = { .type_field = "wProcessType", .d = desc_audio_2_ac_proc_unit_specific } },
509         { .field = NULL }
510 };
511
512 /** Processor unit Up/Down-mix bmControls; Human readable bit meanings. */
513 static const char * const uac3_proc_unit_up_down_mix_bmcontrols[] = {
514         [0] = "Mode Select",
515         [1] = "Underflow",
516         [2] = "Overflow",
517         [3] = NULL
518 };
519
520 /** UAC3: 4.5.2.10.1 Up/Down-mix Processing Unit Descriptor; Table 4-39. */
521 static const struct desc desc_audio_3_ac_proc_unit_up_down_mix[] = {
522         { .field = "bmControls",       .size = 4, .type = DESC_BMCONTROL_2,
523                         .bmcontrol = uac3_proc_unit_up_down_mix_bmcontrols },
524         { .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
525         { .field = "waClusterDescrID", .size = 2, .type = DESC_NUMBER,
526                         .array = { .array = true, .length_field1 = "bNrModes" } },
527         { .field = NULL }
528 };
529
530 /** Processor unit stereo extender bmControls; Human readable bit meanings. */
531 static const char * const uac3_proc_unit_stereo_extender_bmcontrols[] = {
532         [0] = "Width",
533         [1] = "Underflow",
534         [2] = "Overflow",
535         [3] = NULL
536 };
537
538 /** UAC3: 4.5.2.10.2 Stereo Extender Processing Unit Descriptor; Table 4-40. */
539 static const struct desc desc_audio_3_ac_proc_unit_stereo_extender[] = {
540         { .field = "bmControls", .size = 4, .type = DESC_BMCONTROL_2,
541                         .bmcontrol = uac3_proc_unit_stereo_extender_bmcontrols },
542         { .field = NULL }
543 };
544
545 /** UAC3: 4.5.2.10.3 Multi Func Proc Unit Descriptor; Algorithms; Table 4-41. */
546 static const char *uac3_proc_unit_multi_func_algorithms[] = {
547         [0] = "Algorithm Undefined.",
548         [1] = "Beam Forming.",
549         [2] = "Acoustic Echo Cancellation.",
550         [3] = "Active Noise Cancellation.",
551         [4] = "Blind Source Separation.",
552         [5] = "Noise Suppression/Reduction.",
553         [6] = NULL
554 };
555
556 /** Processor unit Multi Func bmControls; Human readable bit meanings. */
557 static const char * const uac3_proc_unit_multi_func_bmcontrols[] = {
558         [0] = "Underflow",
559         [1] = "Overflow",
560         [2] = NULL
561 };
562
563 /** UAC3: 4.5.2.10.3 Multi Function Processing Unit Descriptor; Table 4-41. */
564 static const struct desc desc_audio_3_ac_proc_unit_multi_function[] = {
565         { .field = "bmControls",       .size = 4, .type = DESC_BMCONTROL_2,
566                         .bmcontrol = uac3_proc_unit_multi_func_bmcontrols },
567         { .field = "wClusterDescrID",  .size = 2, .type = DESC_NUMBER, },
568         { .field = "bmAlgorithms", .size = 4, .type = DESC_BITMAP_STRINGS,
569                         .bitmap_strings = {
570                                 .strings = uac3_proc_unit_multi_func_algorithms,
571                                 .count = 6
572                         } },
573         { .field = NULL }
574 };
575
576 /** UAC3: Table A-20: Processing Unit Process Types */
577 static const char * const uac3_proc_unit_types[] = {
578         [0] = "Undefined",
579         [1] = "Up/Down-mix",
580         [2] = "Stereo Extender",
581         [3] = "Multi-Function",
582         [4] = NULL
583 };
584
585 /** UAC3: Table A-20: Processing Unit Process Types */
586 static const struct desc_ext desc_audio_3_ac_proc_unit_specific[] = {
587         { .type = 1, .desc = desc_audio_3_ac_proc_unit_up_down_mix },
588         { .type = 2, .desc = desc_audio_3_ac_proc_unit_stereo_extender },
589         { .type = 3, .desc = desc_audio_3_ac_proc_unit_multi_function },
590         { .desc = NULL }
591 };
592
593 /** UAC3: 4.5.2.10 Processing Unit Descriptor; Table 4-38. */
594 static const struct desc desc_audio_3_ac_processing_unit[] = {
595         { .field = "bUnitID",             .size = 1, .type = DESC_NUMBER },
596         { .field = "wProcessType",        .size = 2, .type = DESC_NUMBER_STRINGS,
597                         .number_strings = uac3_proc_unit_types },
598         { .field = "bNrInPins",           .size = 1, .type = DESC_NUMBER },
599         { .field = "baSourceID",          .size = 1, .type = DESC_NUMBER,
600                         .array = { .array = true, .length_field1 = "bNrInPins" } },
601         { .field = "wProcessingDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
602         { .field = "Process-specific",    .size = 1, .type = DESC_EXTENSION,
603                 .extension = { .type_field = "wProcessType", .d = desc_audio_3_ac_proc_unit_specific } },
604         { .field = NULL }
605 };
606
607 /** Processing Unit descriptor definitions for the three Audio Device Class protocols */
608 const struct desc * const desc_audio_ac_processing_unit[3] = {
609         desc_audio_1_ac_processing_unit,
610         desc_audio_2_ac_processing_unit,
611         desc_audio_3_ac_processing_unit,
612 };
613
614 /** Audio Control Feature Unit bmControls; Human readable bit meanings. */
615 static const char * const uac_feature_unit_bmcontrols[] = {
616         [ 0] = "Mute",
617         [ 1] = "Volume",
618         [ 2] = "Bass",
619         [ 3] = "Mid",
620         [ 4] = "Treble",
621         [ 5] = "Graphic Equalizer",
622         [ 6] = "Automatic Gain",
623         [ 7] = "Delay",
624         [ 8] = "Bass Boost",
625         [ 9] = "Loudness",
626         [10] = "Input gain",
627         [11] = "Input gain pad",
628         [12] = "Phase inverter",
629         [13] = NULL
630 };
631
632 /** UAC1: 4.3.2.5 Feature Unit Descriptor; Table 4-7. */
633 static const struct desc desc_audio_1_ac_feature_unit[] = {
634         { .field = "bUnitID",      .size = 1,                    .type = DESC_NUMBER },
635         { .field = "bSourceID",    .size = 1,                    .type = DESC_CONSTANT },
636         { .field = "bControlSize", .size = 1,                    .type = DESC_NUMBER },
637         { .field = "bmaControls",  .size_field = "bControlSize", .type = DESC_BMCONTROL_1,
638                         .bmcontrol = uac_feature_unit_bmcontrols, .array = { .array = true } },
639         { .field = "iFeature",     .size = 1,                    .type = DESC_STR_DESC_INDEX },
640         { .field = NULL }
641 };
642
643 /** UAC2: 4.7.2.8 Feature Unit Descriptor; Table 4-13. */
644 static const struct desc desc_audio_2_ac_feature_unit[] = {
645         { .field = "bUnitID",     .size = 1, .type = DESC_NUMBER },
646         { .field = "bSourceID",   .size = 1, .type = DESC_CONSTANT },
647         { .field = "bmaControls", .size = 4, .type = DESC_BMCONTROL_2,
648                         .bmcontrol = uac_feature_unit_bmcontrols, .array = { .array = true } },
649         { .field = "iFeature",    .size = 1, .type = DESC_STR_DESC_INDEX },
650         { .field = NULL }
651 };
652
653 /** UAC3: 4.5.2.7 Feature Unit Descriptor; Table 4-31. */
654 static const struct desc desc_audio_3_ac_feature_unit[] = {
655         { .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
656         { .field = "bSourceID",        .size = 1, .type = DESC_NUMBER },
657         { .field = "bmaControls",      .size = 4, .type = DESC_BMCONTROL_2,
658                         .bmcontrol = uac_feature_unit_bmcontrols, .array = { .array = true } },
659         { .field = "wFeatureDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
660         { .field = NULL }
661 };
662
663 /** Feature Unit descriptor definitions for the three Audio Device Class protocols */
664 const struct desc * const desc_audio_ac_feature_unit[3] = {
665         desc_audio_1_ac_feature_unit,
666         desc_audio_2_ac_feature_unit,
667         desc_audio_3_ac_feature_unit,
668 };
669
670 /** UAC2 Extension Unit bmControls; Human readable bit meanings. */
671 static const char * const uac2_extension_unit_bmcontrols[] = {
672         [0] = "Enable",
673         [1] = "Cluster",
674         [2] = "Underflow",
675         [3] = "Overflow",
676         [4] = NULL
677 };
678
679 /** UAC3 Extension Unit bmControls; Human readable bit meanings. */
680 static const char * const uac3_extension_unit_bmcontrols[] = {
681         [0] = "Underflow",
682         [1] = "Overflow",
683         [2] = NULL
684 };
685
686 /** UAC1: 4.3.2.7 Extension Unit Descriptor; Table 4-15. */
687 static const struct desc desc_audio_1_ac_extension_unit[] = {
688         { .field = "bUnitID",        .size = 1, .type = DESC_NUMBER },
689         { .field = "wExtensionCode", .size = 2, .type = DESC_CONSTANT },
690         { .field = "bNrInPins",      .size = 1, .type = DESC_NUMBER },
691         { .field = "baSourceID",     .size = 1, .type = DESC_NUMBER,
692                         .array = { .array = true, .length_field1 = "bNrInPins" } },
693         { .field = "bNrChannels",    .size = 1, .type = DESC_NUMBER },
694         { .field = "wChannelConfig", .size = 2, .type = DESC_BITMAP_STRINGS,
695                         .bitmap_strings = { .strings = uac1_channel_names, .count = 12 } },
696         { .field = "iChannelNames",  .size = 1, .type = DESC_STR_DESC_INDEX },
697         { .field = "bControlSize",   .size = 1, .type = DESC_NUMBER },
698         { .field = "bmControls",     .size = 1, .type = DESC_BITMAP,
699                         .array = { .array = true, .length_field1 = "bControlSize" } },
700         { .field = "iExtension",     .size = 1, .type = DESC_STR_DESC_INDEX },
701         { .field = NULL }
702 };
703
704 /** UAC2: 4.7.2.12 Extension Unit Descriptor; Table 4-24. */
705 static const struct desc desc_audio_2_ac_extension_unit[] = {
706         { .field = "bUnitID",         .size = 1, .type = DESC_NUMBER },
707         { .field = "wExtensionCode",  .size = 2, .type = DESC_CONSTANT },
708         { .field = "bNrInPins",       .size = 1, .type = DESC_NUMBER },
709         { .field = "baSourceID",      .size = 1, .type = DESC_NUMBER,
710                         .array = { .array = true, .length_field1 = "bNrInPins" } },
711         { .field = "bNrChannels",     .size = 1, .type = DESC_NUMBER },
712         { .field = "bmChannelConfig", .size = 4, .type = DESC_BITMAP_STRINGS,
713                         .bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
714         { .field = "iChannelNames",   .size = 1, .type = DESC_STR_DESC_INDEX },
715         { .field = "bmControls",      .size = 1, .type = DESC_BMCONTROL_2,
716                         .bmcontrol = uac2_extension_unit_bmcontrols },
717         { .field = "iExtension",      .size = 1, .type = DESC_STR_DESC_INDEX },
718         { .field = NULL }
719 };
720
721 /** UAC3: 4.5.2.11 Extension Unit Descriptor; Table 4-42. */
722 static const struct desc desc_audio_3_ac_extension_unit[] = {
723         { .field = "bUnitID",            .size = 1, .type = DESC_NUMBER },
724         { .field = "wExtensionCode",     .size = 2, .type = DESC_CONSTANT },
725         { .field = "bNrInPins",          .size = 1, .type = DESC_NUMBER },
726         { .field = "baSourceID",         .size = 1, .type = DESC_NUMBER,
727                         .array = { .array = true, .length_field1 = "bNrInPins" } },
728         { .field = "wExtensionDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
729         { .field = "bmControls",         .size = 4, .type = DESC_BMCONTROL_2,
730                         .bmcontrol = uac3_extension_unit_bmcontrols },
731         { .field = "wClusterDescrID",    .size = 2, .type = DESC_NUMBER },
732         { .field = NULL }
733 };
734
735 /** Extension Unit descriptor definitions for the three Audio Device Class protocols */
736 const struct desc * const desc_audio_ac_extension_unit[3] = {
737         desc_audio_1_ac_extension_unit,
738         desc_audio_2_ac_extension_unit,
739         desc_audio_3_ac_extension_unit,
740 };
741
742 /** UAC2 Clock Source bmControls; Human readable bit meanings. */
743 static const char * const uac2_clock_source_bmcontrols[] = {
744         [0] = "Clock Frequency",
745         [1] = "Clock Validity",
746         [2] = NULL
747 };
748
749 static const char * const uac2_clk_src_bmattr[] = {
750         [0] = "External",
751         [1] = "Internal fixed",
752         [2] = "Internal variable",
753         [3] = "Internal programmable"
754 };
755
756 static const char * const uac3_clk_src_bmattr[] = {
757         [0] = "External",
758         [1] = "Internal",
759         [2] = "(asynchronous)",
760         [3] = "(synchronized to SOF)"
761 };
762
763 /** Special rendering function for UAC2 clock source bmAttributes */
764 static void desc_snowflake_dump_uac2_clk_src_bmattr(
765                 unsigned long long value,
766                 unsigned int indent)
767 {
768         printf(" %s clock %s\n",
769                         uac2_clk_src_bmattr[value & 0x3],
770                         (value & 0x4) ? uac3_clk_src_bmattr[3] : "");
771 }
772
773 /** Special rendering function for UAC3 clock source bmAttributes */
774 static void desc_snowflake_dump_uac3_clk_src_bmattr(
775                 unsigned long long value,
776                 unsigned int indent)
777 {
778         printf(" %s clock %s\n",
779                         uac3_clk_src_bmattr[(value & 0x1)],
780                         uac3_clk_src_bmattr[0x2 | ((value & 0x2) >> 1)]);
781 }
782
783 /** UAC2: 4.7.2.1 Clock Source Descriptor; Table 4-6. */
784 static const struct desc desc_audio_2_ac_clock_source[] = {
785         { .field = "bClockID",       .size = 1, .type = DESC_CONSTANT },
786         { .field = "bmAttributes",   .size = 1, .type = DESC_SNOWFLAKE,
787                         .snowflake = desc_snowflake_dump_uac2_clk_src_bmattr },
788         { .field = "bmControls",     .size = 1, .type = DESC_BMCONTROL_2,
789                         .bmcontrol = uac2_clock_source_bmcontrols },
790         { .field = "bAssocTerminal", .size = 1, .type = DESC_CONSTANT },
791         { .field = "iClockSource",   .size = 1, .type = DESC_STR_DESC_INDEX },
792         { .field = NULL }
793 };
794
795 /** UAC3: 4.5.2.12 Clock Source Descriptor; Table 4-43. */
796 static const struct desc desc_audio_3_ac_clock_source[] = {
797         { .field = "bClockID",           .size = 1, .type = DESC_NUMBER },
798         { .field = "bmAttributes",       .size = 1, .type = DESC_SNOWFLAKE,
799                         .snowflake = desc_snowflake_dump_uac3_clk_src_bmattr },
800         { .field = "bmControls",         .size = 4, .type = DESC_BMCONTROL_2,
801                         .bmcontrol = uac2_clock_source_bmcontrols },
802         { .field = "bReferenceTerminal", .size = 1, .type = DESC_NUMBER },
803         { .field = "wClockSourceStr",    .size = 2, .type = DESC_CS_STR_DESC_ID },
804         { .field = NULL }
805 };
806
807 /** Clock Source descriptor definitions for the three Audio Device Class protocols */
808 const struct desc * const desc_audio_ac_clock_source[3] = {
809         NULL, /* UAC1 not supported */
810         desc_audio_2_ac_clock_source,
811         desc_audio_3_ac_clock_source,
812 };
813
814 /** UAC2 Clock Selector bmControls; Human readable bit meanings. */
815 static const char * const uac2_clock_selector_bmcontrols[] = {
816         [0] = "Clock Selector",
817         [1] = NULL
818 };
819
820 /** UAC2: 4.7.2.2 Clock Selector Descriptor; Table 4-7. */
821 static const struct desc desc_audio_2_ac_clock_selector[] = {
822         { .field = "bClockID",       .size = 1, .type = DESC_NUMBER },
823         { .field = "bNrInPins",      .size = 1, .type = DESC_NUMBER },
824         { .field = "baCSourceID",    .size = 1, .type = DESC_NUMBER,
825                         .array = { .array = true, .length_field1 = "bNrInPins" } },
826         { .field = "bmControls",     .size = 1, .type = DESC_BMCONTROL_2,
827                         .bmcontrol = uac2_clock_selector_bmcontrols },
828         { .field = "iClockSelector", .size = 1, .type = DESC_STR_DESC_INDEX },
829         { .field = NULL }
830 };
831
832 /** UAC3: 4.5.2.13 Clock Selector Descriptor; Table 4-44. */
833 static const struct desc desc_audio_3_ac_clock_selector[] = {
834         { .field = "bClockID",           .size = 1, .type = DESC_NUMBER },
835         { .field = "bNrInPins",          .size = 1, .type = DESC_NUMBER },
836         { .field = "baCSourceID",        .size = 1, .type = DESC_NUMBER,
837                         .array = { .array = true, .length_field1 = "bNrInPins" } },
838         { .field = "bmControls",         .size = 4, .type = DESC_BMCONTROL_2,
839                         .bmcontrol = uac2_clock_selector_bmcontrols },
840         { .field = "wCSelectorDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
841         { .field = NULL }
842 };
843
844 /** Clock Selector descriptor definitions for the three Audio Device Class protocols */
845 const struct desc * const desc_audio_ac_clock_selector[3] = {
846         NULL, /* UAC1 not supported */
847         desc_audio_2_ac_clock_selector,
848         desc_audio_3_ac_clock_selector,
849 };
850
851 /** UAC2 Clock Multiplier bmControls; Human readable bit meanings. */
852 static const char * const uac2_clock_multiplier_bmcontrols[] = {
853         [0] = "Clock Numerator",
854         [1] = "Clock Denominator",
855         [2] = NULL
856 };
857
858 /** UAC2: 4.7.2.3 Clock Multiplier Descriptor; Table 4-8. */
859 static const struct desc desc_audio_2_ac_clock_multiplier[] = {
860         { .field = "bClockID",         .size = 1, .type = DESC_CONSTANT },
861         { .field = "bCSourceID",       .size = 1, .type = DESC_NUMBER },
862         { .field = "bmControls",       .size = 1, .type = DESC_BMCONTROL_2,
863                         .bmcontrol = uac2_clock_multiplier_bmcontrols },
864         { .field = "iClockMultiplier", .size = 1, .type = DESC_STR_DESC_INDEX },
865         { .field = NULL }
866 };
867
868 /** UAC3: 4.5.2.14 Clock Multiplier Descriptor; Table 4-45. */
869 static const struct desc desc_audio_3_ac_clock_multiplier[] = {
870         { .field = "bClockID",             .size = 1, .type = DESC_NUMBER },
871         { .field = "bCSourceID",           .size = 1, .type = DESC_NUMBER },
872         { .field = "bmControls",           .size = 4, .type = DESC_BMCONTROL_2,
873                         .bmcontrol = uac2_clock_multiplier_bmcontrols },
874         { .field = "wCMultiplierDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
875         { .field = NULL }
876 };
877
878 /** Clock Multiplier descriptor definitions for the three Audio Device Class protocols */
879 const struct desc * const desc_audio_ac_clock_multiplier[3] = {
880         NULL, /* UAC1 not supported */
881         desc_audio_2_ac_clock_multiplier,
882         desc_audio_3_ac_clock_multiplier,
883 };
884
885 /** UAC2: 4.7.2.9 Sampling Rate Converter Descriptor; Table 4-14. */
886 static const struct desc desc_audio_2_ac_sample_rate_converter[] = {
887         { .field = "bUnitID",       .size = 1, .type = DESC_CONSTANT },
888         { .field = "bSourceID",     .size = 1, .type = DESC_CONSTANT },
889         { .field = "bCSourceInID",  .size = 1, .type = DESC_CONSTANT },
890         { .field = "bCSourceOutID", .size = 1, .type = DESC_CONSTANT },
891         { .field = "iSRC",          .size = 1, .type = DESC_STR_DESC_INDEX },
892         { .field = NULL }
893 };
894
895 /** UAC3: 4.5.2.8 Sampling Rate Converter Descriptor; Table 4-32. */
896 static const struct desc desc_audio_3_ac_sample_rate_converter[] = {
897         { .field = "bUnitID",       .size = 1, .type = DESC_NUMBER },
898         { .field = "bSourceID",     .size = 1, .type = DESC_NUMBER },
899         { .field = "bCSourceInID",  .size = 1, .type = DESC_NUMBER },
900         { .field = "bCSourceOutID", .size = 1, .type = DESC_NUMBER },
901         { .field = "wSRCDescrStr",  .size = 2, .type = DESC_CS_STR_DESC_ID },
902         { .field = NULL }
903 };
904
905 /** Sample Rate Converter descriptor definitions for the three Audio Device Class protocols */
906 const struct desc * const desc_audio_ac_sample_rate_converter[3] = {
907         NULL, /* UAC1 not supported */
908         desc_audio_2_ac_sample_rate_converter,
909         desc_audio_3_ac_sample_rate_converter,
910 };
911
912 /** UAC2 AudioStreaming Interface bmControls; Human readable bit meanings. */
913 static const char * const uac2_as_interface_bmcontrols[] = {
914         [0] = "Active Alternate Setting",
915         [1] = "Valid Alternate Setting",
916         [2] = NULL
917 };
918
919 /** UAC3 AudioStreaming Interface bmControls; Human readable bit meanings. */
920 static const char * const uac3_as_interface_bmcontrols[] = {
921         [0] = "Active Alternate Setting",
922         [1] = "Valid Alternate Setting",
923         [2] = "Audio Data Format Control",
924         [3] = NULL
925 };
926
927 /* wFormatTag hex prefix for format type */
928 #define UAC_FORMAT_TYPE_I   0x0
929 #define UAC_FORMAT_TYPE_II  0x1
930 #define UAC_FORMAT_TYPE_III 0x2
931
932 /** Format type I codes; Human-readable values. */
933 static const char * const audio_data_format_type_i[] = {
934         [0] = "TYPE_I_UNDEFINED",
935         [1] = "PCM",
936         [2] = "PCM8",
937         [3] = "IEEE_FLOAT",
938         [4] = "ALAW",
939         [5] = "MULAW"
940 };
941
942 /** Format type II codes; Human-readable values. */
943 static const char * const audio_data_format_type_ii[] = {
944         [0] = "TYPE_II_UNDEFINED",
945         [1] = "MPEG",
946         [2] = "AC-3"
947 };
948
949 /** Format type III codes; Human-readable values. */
950 static const char * const audio_data_format_type_iii[] = {
951         [0] = "TYPE_III_UNDEFINED",
952         [1] = "IEC1937_AC-3",
953         [2] = "IEC1937_MPEG-1_Layer1",
954         [3] = "IEC1937_MPEG-Layer2/3/NOEXT",
955         [4] = "IEC1937_MPEG-2_EXT",
956         [5] = "IEC1937_MPEG-2_Layer1_LS",
957         [6] = "IEC1937_MPEG-2_Layer2/3_LS"
958 };
959
960 /** Special rendering function for UAC1 AS interface wFormatTag */
961 static void desc_snowflake_dump_uac1_as_interface_wformattag(
962                 unsigned long long value,
963                 unsigned int indent)
964 {
965         const char *format_string = "undefined";
966
967         /* Format codes are 0xTNNN, where T=Type prefix, NNN = format code. */
968
969         if (value <= ((UAC_FORMAT_TYPE_I << 12) +
970                       ARRAY_LEN(audio_data_format_type_i))) {
971                 format_string = audio_data_format_type_i[value];
972
973         } else if ((value >=  (UAC_FORMAT_TYPE_II << 12)) &&
974                    (value <= ((UAC_FORMAT_TYPE_II << 12) +
975                               ARRAY_LEN(audio_data_format_type_ii)))) {
976                 format_string = audio_data_format_type_ii[value & 0xfff];
977
978         } else if ((value >=  (UAC_FORMAT_TYPE_III << 12)) &&
979                    (value <= ((UAC_FORMAT_TYPE_III << 12) +
980                               ARRAY_LEN(audio_data_format_type_iii)))) {
981                 format_string = audio_data_format_type_iii[value & 0xfff];
982         }
983
984         printf(" %s\n", format_string);
985 }
986
987 /** Special rendering function for UAC2 AS interface bmFormats */
988 static void desc_snowflake_dump_uac2_as_interface_bmformats(
989                 unsigned long long value,
990                 unsigned int indent)
991 {
992         unsigned int i;
993
994         printf("\n");
995         for (i = 0; i < 5; i++) {
996                 if ((value >> i) & 0x1) {
997                         printf("%*s%s\n", indent * 2, "",
998                                         audio_data_format_type_i[i + 1]);
999                 }
1000         }
1001
1002 }
1003
1004 /** UAC1: 4.5.2 Class-Specific AS Interface Descriptor; Table 4-19. */
1005 static const struct desc desc_audio_1_as_interface[] = {
1006         { .field = "bTerminalLink", .size = 1, .type = DESC_CONSTANT },
1007         { .field = "bDelay",        .size = 1, .type = DESC_NUMBER_POSTFIX,
1008                         .number_postfix = " frames" },
1009         { .field = "wFormatTag",    .size = 2, .type = DESC_SNOWFLAKE,
1010                         .snowflake = desc_snowflake_dump_uac1_as_interface_wformattag },
1011         { .field = NULL }
1012 };
1013
1014 /** UAC2: 4.9.2 Class-Specific AS Interface Descriptor; Table 4-27. */
1015 static const struct desc desc_audio_2_as_interface[] = {
1016         { .field = "bTerminalLink",   .size = 1, .type = DESC_NUMBER },
1017         { .field = "bmControls",      .size = 1, .type = DESC_BMCONTROL_2,
1018                         .bmcontrol = uac2_as_interface_bmcontrols },
1019         { .field = "bFormatType",     .size = 1, .type = DESC_CONSTANT },
1020         { .field = "bmFormats",       .size = 4, .type = DESC_SNOWFLAKE,
1021                         .snowflake = desc_snowflake_dump_uac2_as_interface_bmformats },
1022         { .field = "bNrChannels",     .size = 1, .type = DESC_NUMBER },
1023         { .field = "bmChannelConfig", .size = 4, .type = DESC_BITMAP_STRINGS,
1024                         .bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
1025         { .field = "iChannelNames",   .size = 1, .type = DESC_STR_DESC_INDEX },
1026         { .field = NULL }
1027 };
1028
1029 /** UAC3: 4.7.2 Class-Specific AS Interface Descriptor; Table 4-49. */
1030 static const struct desc desc_audio_3_as_interface[] = {
1031         { .field = "bTerminalLink",   .size = 1, .type = DESC_NUMBER },
1032         { .field = "bmControls",      .size = 4, .type = DESC_BMCONTROL_2,
1033                         .bmcontrol = uac3_as_interface_bmcontrols },
1034         { .field = "wClusterDescrID", .size = 2, .type = DESC_NUMBER },
1035         { .field = "bmFormats",       .size = 8, .type = DESC_BITMAP },
1036         { .field = "bSubslotSize",    .size = 1, .type = DESC_NUMBER },
1037         { .field = "bBitResolution",  .size = 1, .type = DESC_NUMBER },
1038         { .field = "bmAuxProtocols",  .size = 2, .type = DESC_BITMAP },
1039         { .field = "bControlSize",    .size = 1, .type = DESC_NUMBER },
1040         { .field = NULL }
1041 };
1042
1043 /** AudioStreaming Interface descriptor definitions for the three Audio Device Class protocols */
1044 const struct desc * const desc_audio_as_interface[3] = {
1045         desc_audio_1_as_interface,
1046         desc_audio_2_as_interface,
1047         desc_audio_3_as_interface,
1048 };
1049
1050 /** UAC1: Data Endpoint bmAttributes; Human readable bit meanings. */
1051 static const char * const uac1_as_endpoint_bmattributes[] = {
1052         [0] = "Sampling Frequency",
1053         [1] = "Pitch",
1054         [2] = "Audio Data Format Control",
1055         [7] = "MaxPacketsOnly"
1056 };
1057
1058 /** UAC2: Data Endpoint bmAttributes; Human readable bit meanings. */
1059 static const char * const uac2_as_endpoint_bmattributes[] = {
1060         [7] = "MaxPacketsOnly",
1061 };
1062
1063 /** UAC2 AudioStreaming Interface bmControls; Human readable bit meanings. */
1064 static const char * const uac2_as_isochronous_audio_data_endpoint_bmcontrols[] = {
1065         [0] = "Pitch",
1066         [1] = "Data Overrun",
1067         [2] = "Data Underrun",
1068         [3] = NULL
1069 };
1070
1071 /** Audio Data Endpoint bLockDelayUnits; Human readable value meanings. */
1072 static const char * const uac_as_isochronous_audio_data_endpoint_blockdelayunits[] = {
1073         [0] = "Undefined",
1074         [1] = "Milliseconds",
1075         [2] = "Decoded PCM samples",
1076         [3] = NULL
1077 };
1078
1079 /** UAC1: 4.6.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor; Table 4-21. */
1080 static const struct desc desc_audio_1_as_isochronous_audio_data_endpoint[] = {
1081         { .field = "bmAttributes",    .size = 1, .type = DESC_BITMAP_STRINGS,
1082                         .bitmap_strings = { .strings = uac1_as_endpoint_bmattributes, .count = 8 } },
1083         { .field = "bLockDelayUnits", .size = 1, .type = DESC_NUMBER_STRINGS,
1084                         .number_strings = uac_as_isochronous_audio_data_endpoint_blockdelayunits },
1085         { .field = "wLockDelay",      .size = 2, .type = DESC_NUMBER },
1086         { .field = NULL }
1087 };
1088
1089 /** UAC2: 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor; Table 4-34. */
1090 static const struct desc desc_audio_2_as_isochronous_audio_data_endpoint[] = {
1091         { .field = "bmAttributes",    .size = 1, .type = DESC_BITMAP_STRINGS,
1092                         .bitmap_strings = { .strings = uac2_as_endpoint_bmattributes, .count = 8 } },
1093         { .field = "bmControls",      .size = 1, .type = DESC_BMCONTROL_2,
1094                         .bmcontrol = uac2_as_isochronous_audio_data_endpoint_bmcontrols },
1095         { .field = "bLockDelayUnits", .size = 1, .type = DESC_NUMBER_STRINGS,
1096                         .number_strings = uac_as_isochronous_audio_data_endpoint_blockdelayunits },
1097         { .field = "wLockDelay",      .size = 2, .type = DESC_NUMBER },
1098         { .field = NULL }
1099 };
1100
1101 /** UAC3: 4.8.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor; Table 4-52. */
1102 static const struct desc desc_audio_3_as_isochronous_audio_data_endpoint[] = {
1103         { .field = "bmControls",      .size = 4, .type = DESC_BMCONTROL_2,
1104                         .bmcontrol = uac2_as_isochronous_audio_data_endpoint_bmcontrols },
1105         { .field = "bLockDelayUnits", .size = 1, .type = DESC_NUMBER_STRINGS,
1106                         .number_strings = uac_as_isochronous_audio_data_endpoint_blockdelayunits },
1107         { .field = "wLockDelay",      .size = 2, .type = DESC_NUMBER },
1108         { .field = NULL }
1109 };
1110
1111 /** Isochronous Audio Data Endpoint descriptor definitions for the three Audio Device Class protocols */
1112 const struct desc * const desc_audio_as_isochronous_audio_data_endpoint[3] = {
1113         desc_audio_1_as_isochronous_audio_data_endpoint,
1114         desc_audio_2_as_isochronous_audio_data_endpoint,
1115         desc_audio_3_as_isochronous_audio_data_endpoint,
1116 };
1117
1118 /** USB3: 9.6.2.7 Configuration Summary Descriptor; Table 9-21. */
1119 const struct desc desc_usb3_dc_configuration_summary[] = {
1120         { .field = "bLength",             .size = 1, .type = DESC_NUMBER },
1121         { .field = "bDescriptorType",     .size = 1, .type = DESC_CONSTANT },
1122         { .field = "bDevCapabilityType",  .size = 1, .type = DESC_NUMBER },
1123         { .field = "bcdVersion",          .size = 2, .type = DESC_BCD },
1124         { .field = "bClass",              .size = 1, .type = DESC_NUMBER },
1125         { .field = "bSubClass",           .size = 1, .type = DESC_NUMBER },
1126         { .field = "bProtocol",           .size = 1, .type = DESC_NUMBER },
1127         { .field = "bConfigurationCount", .size = 1, .type = DESC_NUMBER },
1128         { .field = "bConfigurationIndex", .size = 1, .type = DESC_NUMBER,
1129                         .array = { .array = true, .length_field1 = "bConfigurationCount" } },
1130         { .field = NULL }
1131 };