audio: extend FU channel-number guard to remaining six audio examples (audio_test, audio_test_freertos, audio_test_multi_rate
diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c index c9c6dd4..84f24a7 100644 --- a/examples/device/audio_4_channel_mic/src/main.c +++ b/examples/device/audio_4_channel_mic/src/main.c
@@ -224,6 +224,10 @@ // If request is for our feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Request uses format layout 1 @@ -322,6 +326,10 @@ // Feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
diff --git a/examples/device/audio_4_channel_mic_freertos/src/main.c b/examples/device/audio_4_channel_mic_freertos/src/main.c index eac66a4..e20d746 100644 --- a/examples/device/audio_4_channel_mic_freertos/src/main.c +++ b/examples/device/audio_4_channel_mic_freertos/src/main.c
@@ -296,6 +296,10 @@ // If request is for our feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Request uses format layout 1 @@ -391,6 +395,10 @@ // Feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c index 876a41d..f8964df 100644 --- a/examples/device/audio_test/src/main.c +++ b/examples/device/audio_test/src/main.c
@@ -210,6 +210,10 @@ // If request is for our feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Request uses format layout 1 @@ -308,6 +312,10 @@ // Feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
diff --git a/examples/device/audio_test_freertos/src/main.c b/examples/device/audio_test_freertos/src/main.c index cf2fb74..96879dd 100644 --- a/examples/device/audio_test_freertos/src/main.c +++ b/examples/device/audio_test_freertos/src/main.c
@@ -282,6 +282,10 @@ // If request is for our feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Request uses format layout 1 @@ -377,6 +381,10 @@ // Feature unit if (entityID == 2) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
diff --git a/examples/device/audio_test_multi_rate/src/main.c b/examples/device/audio_test_multi_rate/src/main.c index a86beb4..770c491 100644 --- a/examples/device/audio_test_multi_rate/src/main.c +++ b/examples/device/audio_test_multi_rate/src/main.c
@@ -234,6 +234,10 @@ // If request is for our feature unit (ID defined in usbd.h) if (entityID == 0x02) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO10_FU_CTRL_MUTE: switch (p_request->bRequest) { @@ -282,6 +286,10 @@ // If request is for our feature unit (ID defined in usbd.h) if (entityID == 0x02) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO10_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away @@ -355,6 +363,10 @@ // If request is for our feature unit if (entityID == UAC2_ENTITY_FEATURE_UNIT) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Request uses format layout 1 @@ -435,6 +447,10 @@ // Feature unit if (entityID == UAC2_ENTITY_FEATURE_UNIT) { + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1 entries - reject out-of-range (STALL) + if (channelNum > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX) return false; + switch (ctrlSel) { case AUDIO20_FU_CTRL_MUTE: // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
diff --git a/examples/device/cdc_uac2/src/uac2_app.c b/examples/device/cdc_uac2/src/uac2_app.c index a504c3b..effa5e0 100644 --- a/examples/device/cdc_uac2/src/uac2_app.c +++ b/examples/device/cdc_uac2/src/uac2_app.c
@@ -157,6 +157,9 @@ { uint8_t const ctrl_sel = TU_U16_HIGH(p_request->wValue); uint8_t const channel_num = TU_U16_LOW(p_request->wValue); + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1 entries - reject out-of-range (STALL) + if (channel_num > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX) return false; if (ctrl_sel == AUDIO20_FU_CTRL_MUTE && p_request->bRequest == AUDIO20_CS_REQ_CUR) { @@ -196,6 +199,9 @@ uint8_t const ctrl_sel = TU_U16_HIGH(p_request->wValue); uint8_t const channel_num = TU_U16_LOW(p_request->wValue); + // Channel number is host-controlled (0..255) but mute[]/volume[] hold only + // CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1 entries - reject out-of-range (STALL) + if (channel_num > CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX) return false; TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);