From c7469ce986b495ccd3777e542df31bd90f4134f2 Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Tue, 9 Aug 2022 09:53:08 +0200 Subject: [PATCH] dfu: Allow DFU coexistence with other interfaces dfu_moded_open() only works correct when its called on DFU interface descriptor. It means that DFU is the only one interface in configuration or driver is called after all others interface drivers were tried and gave up. If other interface is supported and but driver for DFU is called first (this is the case for BTH and RNDIS). Code after while loop (that was not entered) has an TU_ASSERT that will make set_configuration to fail. Now TU_VERIFY is called first to make sure open code is called for DFU only and not other interface descriptors like in other drivers. --- src/class/dfu/dfu_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c index 8d859d2ee..aa5891ca9 100644 --- a/src/class/dfu/dfu_device.c +++ b/src/class/dfu/dfu_device.c @@ -167,6 +167,8 @@ uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint8_t alt_count = 0; uint16_t drv_len = 0; + TU_VERIFY(itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS && itf_desc->bInterfaceProtocol == DFU_PROTOCOL_DFU, 0); + while(itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS && itf_desc->bInterfaceProtocol == DFU_PROTOCOL_DFU) { TU_ASSERT(max_len > drv_len, 0);