summaryrefslogtreecommitdiff
path: root/src/class/vendor
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-09-01 12:02:25 +0700
committerhathach <[email protected]>2020-09-01 12:02:25 +0700
commitbe708bb8a444a6e8f8676be842fcfd02a583ed0b (patch)
treea72cd5e5491ade67c40b0a5f152d9d697420caaf /src/class/vendor
parentd108ea4326d824da73da0a4f9632c5da6aa2e3ec (diff)
parentf10b8145afb6d7b78fbf31b525951b4137e1d774 (diff)
Merge branch 'master' into update-host
Diffstat (limited to 'src/class/vendor')
-rw-r--r--src/class/vendor/vendor_device.c20
-rw-r--r--src/class/vendor/vendor_device.h8
2 files changed, 17 insertions, 11 deletions
diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c
index 7f2fe9793..3fcea89c4 100644
--- a/src/class/vendor/vendor_device.c
+++ b/src/class/vendor/vendor_device.c
@@ -166,9 +166,12 @@ void vendord_reset(uint8_t rhport)
}
}
-bool vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len)
+uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
{
- TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass);
+ TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass, 0);
+
+ uint16_t const drv_len = sizeof(tusb_desc_interface_t) + itf_desc->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
+ TU_VERIFY(max_len >= drv_len, 0);
// Find available interface
vendord_interface_t* p_vendor = NULL;
@@ -180,18 +183,21 @@ bool vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16
break;
}
}
- TU_VERIFY(p_vendor);
+ TU_VERIFY(p_vendor, 0);
// Open endpoint pair with usbd helper
- TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_vendor->ep_out, &p_vendor->ep_in));
+ TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_vendor->ep_out, &p_vendor->ep_in), 0);
p_vendor->itf_num = itf_desc->bInterfaceNumber;
- (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
// Prepare for incoming data
- TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)));
+ if ( !usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)) )
+ {
+ TU_LOG1_FAILED();
+ TU_BREAKPOINT();
+ }
- return true;
+ return drv_len;
}
bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h
index 30fe94c3a..a4235bfce 100644
--- a/src/class/vendor/vendor_device.h
+++ b/src/class/vendor/vendor_device.h
@@ -118,10 +118,10 @@ static inline uint32_t tud_vendor_write_available (void)
//--------------------------------------------------------------------+
// Internal Class Driver API
//--------------------------------------------------------------------+
-void vendord_init(void);
-void vendord_reset(uint8_t rhport);
-bool vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
-bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
+void vendord_init(void);
+void vendord_reset(uint8_t rhport);
+uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
+bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
#ifdef __cplusplus
}