summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-12-14 17:35:01 +0700
committerhathach <[email protected]>2022-12-16 17:08:37 +0700
commitf0c51eae44e4cd8f38fdba6469e49b1d98100d7c (patch)
tree8014b64f06303a2dad0997e9b62b7c949ce10768
parent4f0369508450883504e377b40aaec8860c8cb256 (diff)
cdc check for bNumEndpoints before checking for endpoint descriptor
-rw-r--r--src/class/cdc/cdc_host.c64
-rw-r--r--src/host/usbh.c3
2 files changed, 36 insertions, 31 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index aa3a7e1e5..83fa1bf5e 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -152,13 +152,43 @@ bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_xf
}
//--------------------------------------------------------------------+
-// USBH-CLASS DRIVER API
+// CLASS-USBH API
//--------------------------------------------------------------------+
+
void cdch_init(void)
{
tu_memclr(cdch_data, sizeof(cdch_data));
}
+void cdch_close(uint8_t dev_addr)
+{
+ TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
+
+ cdch_data_t * p_cdc = get_itf(dev_addr);
+
+ // Invoke application callback
+ if (tuh_cdc_umount_cb)
+ {
+ if (p_cdc->ep_out || p_cdc->ep_in || p_cdc->ep_notif)
+ {
+ tuh_cdc_umount_cb(dev_addr);
+ }
+ }
+
+ tu_memclr(p_cdc, sizeof(cdch_data_t));
+}
+
+bool cdch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
+{
+ (void) ep_addr;
+ tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes );
+ return true;
+}
+
+//--------------------------------------------------------------------+
+// Enumeration
+//--------------------------------------------------------------------+
+
bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
(void) rhport;
@@ -175,7 +205,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
p_cdc->itf_num = itf_desc->bInterfaceNumber;
p_cdc->itf_protocol = itf_desc->bInterfaceProtocol;
- //------------- Communication Interface -------------//
+ //------------- Control Interface -------------//
uint16_t drv_len = tu_desc_len(itf_desc);
uint8_t const * p_desc = tu_desc_next(itf_desc);
@@ -192,9 +222,10 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
p_desc = tu_desc_next(p_desc);
}
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
+ // Open notification endpoint of control interface if any
+ if (itf_desc->bNumEndpoints == 1)
{
- // notification endpoint
+ TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc));
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
TU_ASSERT( tuh_edpt_open(dev_addr, desc_ep) );
@@ -244,29 +275,4 @@ bool cdch_set_config(uint8_t dev_addr, uint8_t itf_num)
return true;
}
-bool cdch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
-{
- (void) ep_addr;
- tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes );
- return true;
-}
-
-void cdch_close(uint8_t dev_addr)
-{
- TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
-
- cdch_data_t * p_cdc = get_itf(dev_addr);
-
- // Invoke application callback
- if (tuh_cdc_umount_cb)
- {
- if (p_cdc->ep_out || p_cdc->ep_in || p_cdc->ep_notif)
- {
- tuh_cdc_umount_cb(dev_addr);
- }
- }
-
- tu_memclr(p_cdc, sizeof(cdch_data_t));
-}
-
#endif
diff --git a/src/host/usbh.c b/src/host/usbh.c
index ca42a523c..b0cd62bac 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -1524,8 +1524,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
TU_ASSERT(drv_len >= sizeof(tusb_desc_interface_t));
// Find driver for this interface
- uint8_t drv_id;
- for (drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
+ for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
{
usbh_class_driver_t const * driver = &usbh_class_drivers[drv_id];