1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "audio_usb_validate_desc.h"
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/usb.h>
13 #include <linux/usb/audio-v2.h>
14 #include <linux/usb/audio-v3.h>
15 #include <linux/usb/audio.h>
16
17 #include "audio_driver_log.h"
18 #include "hdf_base.h"
19 #include "osal_mem.h"
20 #include "securec.h"
21
22 #define HDF_LOG_TAG HDF_AUDIO_USB
23
24 #define UAC_VERSION_ALL 255
25 #define AUDIO_USB_DESC_LEN_1 1
26 #define AUDIO_USB_DESC_LEN_2 2
27 #define AUDIO_USB_DESC_LEN_3 3
28 #define AUDIO_USB_DESC_LEN_4 4
29
30 #define AUDIO_USB_INTERVAL_LEN_1 1
31 #define AUDIO_USB_INTERVAL_LEN_4 4
32
33 #define AUDIO_USB_INDEX_1 1
34 #define AUDIO_USB_INDEX_2 2
35 #define AUDIO_USB_INDEX_3 3
36
37 #define AUDIO_USB_COMBINE_BYTE 1
38 #define AUDIO_USB_COMBINE_WORD 2
39 #define AUDIO_USB_COMBINE_TRIPLE 3
40 #define AUDIO_USB_COMBINE_QUAD 4
41
42 #define USB_SHIFT_SIZE_8 8
43 #define USB_SHIFT_SIZE_16 16
44 #define USB_SHIFT_SIZE_24 24
45
46 struct UsbDescValidator {
47 uint8_t protocol;
48 uint8_t type;
49 bool (*func)(const void *ptr, const struct UsbDescValidator *usbDesc);
50 size_t size;
51 };
52
AudioUsbGetIfaceDesc(struct usb_host_interface * interface)53 struct usb_interface_descriptor *AudioUsbGetIfaceDesc(struct usb_host_interface *interface)
54 {
55 if (interface == NULL) {
56 AUDIO_DRIVER_LOG_ERR("input param is NULL.");
57 return NULL;
58 }
59 return (&(interface)->desc);
60 }
61
AudioEndpointDescriptor(struct usb_host_interface * alts,uint32_t epIndex)62 struct usb_endpoint_descriptor *AudioEndpointDescriptor(struct usb_host_interface *alts, uint32_t epIndex)
63 {
64 if (alts == NULL) {
65 AUDIO_DRIVER_LOG_ERR("input param is NULL.");
66 return NULL;
67 }
68 return (&(alts)->endpoint[epIndex].desc);
69 }
70
AudioUsbGetSpeed(struct usb_device * dev)71 enum usb_device_speed AudioUsbGetSpeed(struct usb_device *dev)
72 {
73 if (dev == NULL) {
74 AUDIO_DRIVER_LOG_ERR("input param is NULL.");
75 return USB_SPEED_UNKNOWN;
76 }
77 return ((dev)->speed);
78 }
79
AudioUsbCombineWord(uint8_t * bytes)80 uint32_t AudioUsbCombineWord(uint8_t *bytes)
81 {
82 // This data is composed of two bytes of data.
83 return (*(bytes)) | ((uint32_t)(bytes)[AUDIO_USB_INDEX_1] << USB_SHIFT_SIZE_8);
84 }
85
AudioUsbCombineTriple(uint8_t * bytes)86 uint32_t AudioUsbCombineTriple(uint8_t *bytes)
87 {
88 // This data is composed of three bytes of data.
89 return AudioUsbCombineWord(bytes) | ((uint32_t)(bytes)[AUDIO_USB_INDEX_2] << USB_SHIFT_SIZE_16);
90 }
91
AudioUsbCombineQuad(uint8_t * bytes)92 uint32_t AudioUsbCombineQuad(uint8_t *bytes)
93 {
94 // This data is composed of four bytes of data.
95 return AudioUsbCombineTriple(bytes) | ((uint32_t)(bytes)[AUDIO_USB_INDEX_3] << USB_SHIFT_SIZE_24);
96 }
97
AudioUsbCombineBytes(uint8_t * bytes,int32_t size)98 uint32_t AudioUsbCombineBytes(uint8_t *bytes, int32_t size)
99 {
100 if (bytes == NULL) {
101 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
102 return 0; // combine bytes is 0
103 }
104 switch (size) {
105 case AUDIO_USB_COMBINE_BYTE:
106 return *bytes;
107 case AUDIO_USB_COMBINE_WORD:
108 return AudioUsbCombineWord(bytes);
109 case AUDIO_USB_COMBINE_TRIPLE:
110 return AudioUsbCombineTriple(bytes);
111 case AUDIO_USB_COMBINE_QUAD:
112 return AudioUsbCombineQuad(bytes);
113 default:
114 return 0; // combine bytes is 0
115 }
116 }
117
AudioUsbFindDesc(void * descStart,int32_t descLen,void * after,uint8_t descType)118 void *AudioUsbFindDesc(void *descStart, int32_t descLen, void *after, uint8_t descType)
119 {
120 uint8_t *start = NULL;
121 uint8_t *end = NULL;
122 uint8_t *next = NULL;
123
124 if (descStart == NULL) {
125 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
126 return NULL;
127 }
128 start = descStart;
129 end = start + descLen;
130 for (; start < end;) {
131 if (start[0] < AUDIO_USB_DESC_LEN_2) {
132 AUDIO_DRIVER_LOG_ERR("start is less than 2.");
133 return NULL;
134 }
135 next = start + start[0];
136 if (next > end) {
137 AUDIO_DRIVER_LOG_ERR("next is greater than end.");
138 return NULL;
139 }
140 if (start[1] == descType && (after == NULL || (void *)start > after)) {
141 return start;
142 }
143 start = next;
144 }
145 return NULL;
146 }
147
AudioUsbFindCsintDesc(void * buf,int32_t bufLen,void * after,uint8_t descSubType)148 void *AudioUsbFindCsintDesc(void *buf, int32_t bufLen, void *after, uint8_t descSubType)
149 {
150 uint8_t *afterDesc = after;
151
152 if (buf == NULL) {
153 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
154 return NULL;
155 }
156
157 while ((afterDesc = AudioUsbFindDesc(buf, bufLen, afterDesc, USB_DT_CS_INTERFACE)) != NULL) {
158 if (afterDesc[0] >= AUDIO_USB_DESC_LEN_3 && afterDesc[AUDIO_USB_DESC_LEN_2] == descSubType) {
159 return afterDesc;
160 }
161 }
162
163 return NULL;
164 }
165
AudioUsbCtlMsg(struct usb_device * dev,struct AudioUsbCtlMsgParam * usbCtlMsgParam,void * data,uint16_t size)166 int32_t AudioUsbCtlMsg(struct usb_device *dev, struct AudioUsbCtlMsgParam *usbCtlMsgParam, void *data, uint16_t size)
167 {
168 int32_t ret, err;
169 int32_t timeout;
170 void *buf = NULL;
171
172 if (dev == NULL || data == NULL) {
173 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
174 return HDF_ERR_INVALID_PARAM;
175 }
176
177 if (usb_pipe_type_check(dev, usbCtlMsgParam->pipe)) {
178 AUDIO_DRIVER_LOG_ERR("usb_pipe_type_check failed.");
179 return HDF_FAILURE;
180 }
181
182 if (size == 0) {
183 AUDIO_DRIVER_LOG_ERR("msg data size is 0.");
184 return HDF_FAILURE;
185 }
186
187 buf = kmemdup(data, size, GFP_KERNEL);
188 if (buf == NULL) {
189 AUDIO_DRIVER_LOG_ERR("kmemdup failed.");
190 return HDF_ERR_MALLOC_FAIL;
191 }
192
193 if ((usbCtlMsgParam->requestType & USB_DIR_IN) != 0) {
194 timeout = USB_CTRL_GET_TIMEOUT;
195 } else {
196 timeout = USB_CTRL_SET_TIMEOUT;
197 }
198
199 ret = usb_control_msg(dev, usbCtlMsgParam->pipe, usbCtlMsgParam->request, usbCtlMsgParam->requestType,
200 usbCtlMsgParam->value, usbCtlMsgParam->index, buf, size, timeout);
201
202 err = memcpy_s(data, size, buf, size);
203 if (err != EOK) {
204 AUDIO_DRIVER_LOG_ERR("memcpy_s buf failed!");
205 kfree(buf);
206 return HDF_ERR_MALLOC_FAIL;
207 }
208 kfree(buf);
209 return ret;
210 }
211
AudioUsbParseDataInterval(struct usb_device * usbDev,struct usb_host_interface * alts)212 uint8_t AudioUsbParseDataInterval(struct usb_device *usbDev, struct usb_host_interface *alts)
213 {
214 struct usb_endpoint_descriptor *epDesc = NULL;
215 enum usb_device_speed usbSpeed;
216
217 if (usbDev == NULL || alts == NULL) {
218 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
219 return HDF_ERR_INVALID_PARAM;
220 }
221 epDesc = AudioEndpointDescriptor(alts, 0);
222 usbSpeed = AudioUsbGetSpeed(usbDev);
223 switch (usbSpeed) {
224 case USB_SPEED_HIGH:
225 case USB_SPEED_WIRELESS:
226 case USB_SPEED_SUPER:
227 case USB_SPEED_SUPER_PLUS:
228 if (epDesc->bInterval >= AUDIO_USB_INTERVAL_LEN_1 && epDesc->bInterval <= AUDIO_USB_INTERVAL_LEN_4) {
229 return epDesc->bInterval - AUDIO_USB_INTERVAL_LEN_1;
230 }
231 break;
232 default:
233 break;
234 }
235 return HDF_SUCCESS;
236 }
237
ValidateDesc(uint8_t * hdr,int32_t protocol,const struct UsbDescValidator * usbDesc)238 static bool ValidateDesc(uint8_t *hdr, int32_t protocol, const struct UsbDescValidator *usbDesc)
239 {
240 if (hdr[AUDIO_USB_INDEX_1] != USB_DT_CS_INTERFACE) {
241 return true;
242 }
243 AUDIO_DRIVER_LOG_DEBUG("hdr is USB_DT_CS_INTERFACE.");
244
245 for (; usbDesc != NULL && usbDesc->type != 0; usbDesc++) {
246 if (usbDesc->type == hdr[AUDIO_USB_INDEX_2] &&
247 (usbDesc->protocol == UAC_VERSION_ALL || usbDesc->protocol == protocol)) {
248 if (usbDesc->func != NULL) {
249 return usbDesc->func(hdr, usbDesc);
250 }
251 return hdr[0] >= usbDesc->size;
252 }
253 }
254
255 return true;
256 }
257
ValidateUac1Header(const void * uacDesc,const struct UsbDescValidator * usbDesc)258 static bool ValidateUac1Header(const void *uacDesc, const struct UsbDescValidator *usbDesc)
259 {
260 const struct uac1_ac_header_descriptor *uacHeaderDesc = uacDesc;
261 uint32_t descSize = sizeof(*uacHeaderDesc) + uacHeaderDesc->bInCollection;
262
263 if (uacHeaderDesc->bLength >= sizeof(*uacHeaderDesc) && uacHeaderDesc->bLength >= descSize) {
264 return true;
265 }
266 return false;
267 }
268
269 /* for mixer unit; covering all UACs */
ValidateMixerUnit(const void * ptr,const struct UsbDescValidator * usbDesc)270 static bool ValidateMixerUnit(const void *ptr, const struct UsbDescValidator *usbDesc)
271 {
272 const struct uac_mixer_unit_descriptor *uacMixerDesc = ptr;
273 size_t length;
274 bool temp;
275 AUDIO_DRIVER_LOG_DEBUG("entry.");
276
277 if (uacMixerDesc->bLength < sizeof(*uacMixerDesc) || !uacMixerDesc->bNrInPins) {
278 return false;
279 }
280 length = sizeof(struct uac_mixer_unit_descriptor) + uacMixerDesc->bNrInPins;
281
282 switch (usbDesc->protocol) {
283 case UAC_VERSION_1:
284 length += AUDIO_USB_DESC_LEN_2 + AUDIO_USB_DESC_LEN_2;
285 break;
286 case UAC_VERSION_2:
287 length += AUDIO_USB_DESC_LEN_4 + AUDIO_USB_DESC_LEN_1;
288 length += AUDIO_USB_DESC_LEN_2;
289 break;
290 case UAC_VERSION_3:
291 length += AUDIO_USB_DESC_LEN_2;
292 break;
293 default:
294 length += AUDIO_USB_DESC_LEN_2 + AUDIO_USB_DESC_LEN_2;
295 break;
296 }
297 temp = uacMixerDesc->bLength >= length;
298 return temp;
299 }
300
UacProcessGetLength(const struct uac_processing_unit_descriptor * uacProcessDesc,const uint8_t * hdr,const struct UsbDescValidator * usbDesc,size_t * length)301 static bool UacProcessGetLength(const struct uac_processing_unit_descriptor *uacProcessDesc, const uint8_t *hdr,
302 const struct UsbDescValidator *usbDesc, size_t *length)
303 {
304 size_t tmpLen;
305 switch (usbDesc->protocol) {
306 case UAC_VERSION_1:
307 default:
308 *length += AUDIO_USB_DESC_LEN_4;
309 if (uacProcessDesc->bLength < *length + 1) {
310 return false;
311 }
312 tmpLen = hdr[*length];
313 *length += tmpLen + AUDIO_USB_DESC_LEN_2;
314 break;
315 case UAC_VERSION_2:
316 *length += AUDIO_USB_DESC_LEN_4 + AUDIO_USB_DESC_LEN_2;
317 if (usbDesc->type == UAC2_PROCESSING_UNIT_V2) {
318 *length += AUDIO_USB_DESC_LEN_2;
319 } else {
320 *length += AUDIO_USB_DESC_LEN_1;
321 }
322 *length += AUDIO_USB_DESC_LEN_1;
323 break;
324 case UAC_VERSION_3:
325 *length += AUDIO_USB_DESC_LEN_4 + AUDIO_USB_DESC_LEN_2;
326 break;
327 }
328
329 return true;
330 }
331
UacV1ProcessGetLen(const struct uac_processing_unit_descriptor * uacProcessDesc,const uint8_t * hdr,size_t * length)332 static bool UacV1ProcessGetLen(
333 const struct uac_processing_unit_descriptor *uacProcessDesc, const uint8_t *hdr, size_t *length)
334 {
335 size_t tmpLen;
336 switch (le16_to_cpu(uacProcessDesc->wProcessType)) {
337 case UAC_PROCESS_UP_DOWNMIX:
338 case UAC_PROCESS_DOLBY_PROLOGIC:
339 if (uacProcessDesc->bLength < *length + AUDIO_USB_DESC_LEN_1) {
340 return false;
341 }
342 tmpLen = hdr[*length];
343 *length += AUDIO_USB_DESC_LEN_1 + tmpLen * AUDIO_USB_DESC_LEN_2;
344 break;
345 default:
346 break;
347 }
348 return true;
349 }
350
UacV2ProcessGetLen(const struct uac_processing_unit_descriptor * uacProcessDesc,const uint8_t * hdr,size_t * length)351 static bool UacV2ProcessGetLen(
352 const struct uac_processing_unit_descriptor *uacProcessDesc, const uint8_t *hdr, size_t *length)
353 {
354 size_t tmpLen;
355 switch (le16_to_cpu(uacProcessDesc->wProcessType)) {
356 case UAC2_PROCESS_UP_DOWNMIX:
357 case UAC2_PROCESS_DOLBY_PROLOCIC:
358 if (uacProcessDesc->bLength < *length + 1) {
359 return false;
360 }
361 tmpLen = hdr[*length];
362 *length += AUDIO_USB_DESC_LEN_1 + tmpLen * AUDIO_USB_DESC_LEN_4;
363 break;
364 default:
365 break;
366 }
367 return true;
368 }
369
UacV3ProcessGetLen(const struct uac_processing_unit_descriptor * uacProcessDesc,const uint8_t * hdr,size_t * length)370 static bool UacV3ProcessGetLen(
371 const struct uac_processing_unit_descriptor *uacProcessDesc, const uint8_t *hdr, size_t *length)
372 {
373 size_t tmpLen;
374 switch (le16_to_cpu(uacProcessDesc->wProcessType)) {
375 case UAC3_PROCESS_UP_DOWNMIX:
376 if (uacProcessDesc->bLength < *length + 1) {
377 return false;
378 }
379 tmpLen = hdr[*length];
380 *length += AUDIO_USB_DESC_LEN_1 + tmpLen * AUDIO_USB_DESC_LEN_2;
381 break;
382 case UAC3_PROCESS_MULTI_FUNCTION:
383 *length += AUDIO_USB_DESC_LEN_2 + AUDIO_USB_DESC_LEN_4;
384 break;
385 default:
386 break;
387 }
388 return true;
389 }
390
ValidateProcessingUnitSub(const struct UsbDescValidator * usbDesc,const struct uac_processing_unit_descriptor * uacProcessDesc,const uint8_t * hdr,size_t * length)391 static bool ValidateProcessingUnitSub(const struct UsbDescValidator *usbDesc,
392 const struct uac_processing_unit_descriptor *uacProcessDesc, const uint8_t *hdr, size_t *length)
393 {
394 switch (usbDesc->protocol) {
395 case UAC_VERSION_1:
396 if (!UacV1ProcessGetLen(uacProcessDesc, hdr, length)) {
397 AUDIO_DRIVER_LOG_ERR("UacV1ProcessGetLen failed.");
398 return false;
399 }
400 break;
401 case UAC_VERSION_2:
402 if (!UacV2ProcessGetLen(uacProcessDesc, hdr, length)) {
403 AUDIO_DRIVER_LOG_ERR("UacV1ProcessGetLen failed.");
404 return false;
405 }
406 break;
407 case UAC_VERSION_3:
408 if (usbDesc->type == UAC3_EXTENSION_UNIT) {
409 *length += AUDIO_USB_DESC_LEN_2; /* wClusterDescrID */
410 break;
411 }
412 if (!UacV3ProcessGetLen(uacProcessDesc, hdr, length)) {
413 AUDIO_DRIVER_LOG_ERR("UacV1ProcessGetLen failed.");
414 return false;
415 }
416 break;
417 default:
418 if (!UacV1ProcessGetLen(uacProcessDesc, hdr, length)) {
419 AUDIO_DRIVER_LOG_ERR("UacV1ProcessGetLen failed.");
420 return false;
421 }
422 break;
423 }
424 return true;
425 }
426
427 /* both for processing and extension units; covering all UACs */
ValidateProcessingUnit(const void * ptr,const struct UsbDescValidator * usbDesc)428 static bool ValidateProcessingUnit(const void *ptr, const struct UsbDescValidator *usbDesc)
429 {
430 size_t length;
431 const struct uac_processing_unit_descriptor *uacProcessDesc = ptr;
432 const uint8_t *hdr = ptr;
433
434 if (uacProcessDesc->bLength < sizeof(*uacProcessDesc)) {
435 return false;
436 }
437 length = sizeof(*uacProcessDesc) + uacProcessDesc->bNrInPins;
438 if (uacProcessDesc->bLength < length) {
439 return false;
440 }
441
442 if (!UacProcessGetLength(uacProcessDesc, hdr, usbDesc, &length)) {
443 AUDIO_DRIVER_LOG_ERR("UacProcessGetLength failed.");
444 return false;
445 }
446
447 if (uacProcessDesc->bLength < length) {
448 return false;
449 }
450 if (usbDesc->type == UAC1_EXTENSION_UNIT || usbDesc->type == UAC2_EXTENSION_UNIT_V2) {
451 return true; /* OK */
452 }
453 if (!ValidateProcessingUnitSub(usbDesc, uacProcessDesc, hdr, &length)) {
454 AUDIO_DRIVER_LOG_ERR("ValidateProcessingUnitSub failed.");
455 return false;
456 }
457
458 if (uacProcessDesc->bLength < length) {
459 return false;
460 }
461
462 return true;
463 }
464
465 /* both for selector and clock selector units; covering all UACs */
ValidateSelectorUnit(const void * ptr,const struct UsbDescValidator * usbDesc)466 static bool ValidateSelectorUnit(const void *ptr, const struct UsbDescValidator *usbDesc)
467 {
468 const struct uac_selector_unit_descriptor *uacSelectorDesc = ptr;
469 size_t length;
470
471 if (uacSelectorDesc->bLength < sizeof(*uacSelectorDesc)) {
472 return false;
473 }
474 length = sizeof(*uacSelectorDesc) + uacSelectorDesc->bNrInPins;
475 switch (usbDesc->protocol) {
476 case UAC_VERSION_1:
477 default:
478 length += AUDIO_USB_DESC_LEN_1;
479 break;
480 case UAC_VERSION_2:
481 length += AUDIO_USB_DESC_LEN_2;
482 break;
483 case UAC_VERSION_3:
484 length += AUDIO_USB_DESC_LEN_4 + AUDIO_USB_DESC_LEN_2;
485 break;
486 }
487 return uacSelectorDesc->bLength >= length;
488 }
489
ValidateUac1FeatureUnit(const void * ptr,const struct UsbDescValidator * usbDesc)490 static bool ValidateUac1FeatureUnit(const void *ptr, const struct UsbDescValidator *usbDesc)
491 {
492 (void)usbDesc;
493 const struct uac_feature_unit_descriptor *featureDesc = ptr;
494
495 if (featureDesc->bLength < sizeof(*featureDesc) || !featureDesc->bControlSize) {
496 return false;
497 }
498
499 return featureDesc->bLength >= sizeof(*featureDesc) + featureDesc->bControlSize + AUDIO_USB_DESC_LEN_1;
500 }
501
ValidateUac2FeatureUnit(const void * ptr,const struct UsbDescValidator * usbDesc)502 static bool ValidateUac2FeatureUnit(const void *ptr, const struct UsbDescValidator *usbDesc)
503 {
504 (void)usbDesc;
505 const struct uac2_feature_unit_descriptor *featureDesc = ptr;
506
507 if (featureDesc->bLength < sizeof(*featureDesc)) {
508 return false;
509 }
510
511 return featureDesc->bLength >= sizeof(*featureDesc) + AUDIO_USB_DESC_LEN_4 + AUDIO_USB_DESC_LEN_1;
512 }
513
514 static const struct UsbDescValidator audioValidators[] = {
515 {.protocol = UAC_VERSION_1, .type = UAC_HEADER, .func = ValidateUac1Header },
516 {.protocol = UAC_VERSION_1, .type = UAC_INPUT_TERMINAL, .size = sizeof(struct uac_input_terminal_descriptor) },
517 {.protocol = UAC_VERSION_1, .type = UAC_OUTPUT_TERMINAL, .size = sizeof(struct uac1_output_terminal_descriptor)},
518 {.protocol = UAC_VERSION_1, .type = UAC_MIXER_UNIT, .func = ValidateMixerUnit },
519 {.protocol = UAC_VERSION_1, .type = UAC_SELECTOR_UNIT, .func = ValidateSelectorUnit },
520 {.protocol = UAC_VERSION_1, .type = UAC_FEATURE_UNIT, .func = ValidateUac1FeatureUnit },
521 {.protocol = UAC_VERSION_1, .type = UAC1_PROCESSING_UNIT, .func = ValidateProcessingUnit },
522 {.protocol = UAC_VERSION_1, .type = UAC1_EXTENSION_UNIT, .func = ValidateProcessingUnit },
523
524 {.protocol = UAC_VERSION_2, .type = UAC_HEADER, .size = sizeof(struct uac2_ac_header_descriptor) },
525 {.protocol = UAC_VERSION_2, .type = UAC_INPUT_TERMINAL, .size = sizeof(struct uac2_input_terminal_descriptor) },
526 {.protocol = UAC_VERSION_2, .type = UAC_OUTPUT_TERMINAL, .size = sizeof(struct uac2_output_terminal_descriptor)},
527 {.protocol = UAC_VERSION_2, .type = UAC_MIXER_UNIT, .func = ValidateMixerUnit },
528 {.protocol = UAC_VERSION_2, .type = UAC_SELECTOR_UNIT, .func = ValidateSelectorUnit },
529 {.protocol = UAC_VERSION_2, .type = UAC_FEATURE_UNIT, .func = ValidateUac2FeatureUnit },
530 {.protocol = UAC_VERSION_2, .type = UAC2_PROCESSING_UNIT_V2, .func = ValidateProcessingUnit },
531 {.protocol = UAC_VERSION_2, .type = UAC2_EXTENSION_UNIT_V2, .func = ValidateProcessingUnit },
532 {.protocol = UAC_VERSION_2, .type = UAC2_CLOCK_SOURCE, .size = sizeof(struct uac_clock_source_descriptor) },
533 {.protocol = UAC_VERSION_2, .type = UAC2_CLOCK_SELECTOR, .func = ValidateSelectorUnit },
534 {.protocol = UAC_VERSION_2, .type = UAC2_CLOCK_MULTIPLIER, .size = sizeof(struct uac_clock_multiplier_descriptor)},
535 };
536
AudioUsbValidateAudioDesc(void * ptr,int32_t protocol)537 bool AudioUsbValidateAudioDesc(void *ptr, int32_t protocol)
538 {
539 if (ptr == NULL) {
540 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
541 return false;
542 }
543
544 bool valid = ValidateDesc(ptr, protocol, audioValidators);
545
546 return valid;
547 }
548