summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-12-13 07:26:50 +0700
committerGitHub <[email protected]>2025-12-13 07:26:50 +0700
commit09f71727d53d4e70803d7460c3e5cdfb7f2bcb06 (patch)
tree63c5044798267aa414a1073f3f7c3976cae65797
parent02da4e81c77fd7e77ff0b92c616519358c6db4ee (diff)
parentbb1495966d189dc2fb001bc9f3b7908a02a971bb (diff)
Merge pull request #3383 from hathach/audio_open
audio: fix audiod_open with midi interfaces
-rw-r--r--src/class/audio/audio_device.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index 33a03d471..55eba81dd 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -800,20 +800,44 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint
(void) max_len;
TU_VERIFY(TUSB_CLASS_AUDIO == itf_desc->bInterfaceClass &&
- AUDIO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass);
+ AUDIO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass, 0);
// Verify version is correct - this check can be omitted
TU_VERIFY(itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V1 ||
- itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V2);
+ itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V2, 0);
+
+ // Verify 2nd interface descriptor is Audio Streaming to avoid mess with MIDI class
+ // Audio Control interface is followed by Audio Streaming interface(s)
+ // MIDI class also starts with Audio Control but is followed by MIDI Streaming
+ {
+ uint8_t const *p_desc = (uint8_t const *) itf_desc;
+ uint8_t const *p_desc_end = p_desc + max_len;
+
+ // Advance to next interface descriptor
+ p_desc = tu_desc_next(p_desc);
+ while (tu_desc_in_bounds(p_desc, p_desc_end) && tu_desc_type(p_desc) != TUSB_DESC_INTERFACE) {
+ p_desc = tu_desc_next(p_desc);
+ }
+
+ // Verify next interface is Audio Streaming (subclass 2), not MIDI Streaming (subclass 3)
+ if (p_desc_end - p_desc >= (int)sizeof(tusb_desc_interface_t)) {
+ tusb_desc_interface_t const *next_itf = (tusb_desc_interface_t const *) p_desc;
+ TU_VERIFY(next_itf->bInterfaceClass == TUSB_CLASS_AUDIO &&
+ next_itf->bInterfaceSubClass == AUDIO_SUBCLASS_STREAMING, 0);
+ } else {
+ // No further interface found or not enough bytes for interface descriptor
+ return 0;
+ }
+ }
// Verify interrupt control EP is enabled if demanded by descriptor
- TU_ASSERT(itf_desc->bNumEndpoints <= 1);// 0 or 1 EPs are allowed
+ TU_ASSERT(itf_desc->bNumEndpoints <= 1, 0);// 0 or 1 EPs are allowed
if (itf_desc->bNumEndpoints == 1) {
- TU_ASSERT(CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP);
+ TU_ASSERT(CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP, 0);
}
// Alternate setting MUST be zero - this check can be omitted
- TU_VERIFY(itf_desc->bAlternateSetting == 0);
+ TU_VERIFY(itf_desc->bAlternateSetting == 0, 0);
// Find available audio driver interface
uint8_t i;