summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <[email protected]>2026-03-22 20:06:52 +0000
committercopilot-swe-agent[bot] <[email protected]>2026-03-22 20:06:52 +0000
commitf494d3517fe21ecd7259cd8a90d2c6709edd0e90 (patch)
tree20e9116550b63b8776a90690397fa654a0c3171e
parentc843e5e2a76302eabc2228c42ffecd2a242443cb (diff)
net: save actual ep_size from descriptor in netd_open instead of hardcoding 64/512
Co-authored-by: HiFiPhile <[email protected]> Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/4c20b579-db28-4643-b062-81881adcf6c1
-rw-r--r--src/class/net/ecm_rndis_device.c7
-rw-r--r--src/class/net/ncm_device.c4
2 files changed, 8 insertions, 3 deletions
diff --git a/src/class/net/ecm_rndis_device.c b/src/class/net/ecm_rndis_device.c
index 773c495ed..d4c2ebf9a 100644
--- a/src/class/net/ecm_rndis_device.c
+++ b/src/class/net/ecm_rndis_device.c
@@ -51,6 +51,7 @@ typedef struct {
uint8_t ep_notif;
uint8_t ep_in;
uint8_t ep_out;
+ uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
bool ecm_mode;
@@ -176,6 +177,9 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
// Pair of endpoints
TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
+ // Save the actual bulk endpoint size (IN and OUT assumed equal)
+ _netd_itf.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
+
if (_netd_itf.ecm_mode) {
// ECM by default is in-active, save the endpoint attribute
// to open later when received setInterface
@@ -356,8 +360,7 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
/* data transmission finished */
if (ep_addr == _netd_itf.ep_in) {
/* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
- uint16_t const ep_size = (tud_speed_get() == TUSB_SPEED_HIGH) ? 512 : 64;
- if (xferred_bytes && (0 == (xferred_bytes % ep_size))) {
+ if (xferred_bytes && (0 == (xferred_bytes % _netd_itf.ep_size))) {
do_in_xfer(NULL, 0); /* a ZLP is needed */
} else {
/* we're finally finished */
diff --git a/src/class/net/ncm_device.c b/src/class/net/ncm_device.c
index cf32514ba..fe33d0247 100644
--- a/src/class/net/ncm_device.c
+++ b/src/class/net/ncm_device.c
@@ -83,6 +83,7 @@ typedef struct {
uint8_t itf_num; // interface number
uint8_t itf_data_alt; // ==0 -> no endpoints, i.e. no network traffic, ==1 -> normal operation with two endpoints (spec, chapter 5.3)
uint8_t rhport; // storage of \a rhport because some callbacks are done without it
+ uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
// recv handling
recv_ntb_t *recv_free_ntb[RECV_NTB_N]; // free list of recv NTBs
@@ -340,7 +341,7 @@ static xmit_ntb_t *xmit_get_next_ready_ntb(void) {
static bool xmit_insert_required_zlp(uint8_t rhport, uint32_t xferred_bytes) {
TU_LOG_DRV("xmit_insert_required_zlp(%d,%ld)\n", rhport, xferred_bytes);
- uint16_t const ep_size = (tud_speed_get() == TUSB_SPEED_HIGH) ? 512 : 64;
+ uint16_t const ep_size = ncm_interface.ep_size;
if (xferred_bytes == 0 || xferred_bytes % ep_size != 0) {
return false;
}
@@ -906,6 +907,7 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16
// a TUSB_DESC_ENDPOINT (actually two) must follow, open these endpoints
TU_ASSERT(tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT, 0);
TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &ncm_interface.ep_out, &ncm_interface.ep_in));
+ ncm_interface.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
drv_len += 2 * sizeof(tusb_desc_endpoint_t);
return drv_len;