summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-08-31 13:00:49 +0800
committersakumisu <[email protected]>2026-08-31 14:16:57 +0800
commit740f349f89ecd9e659b7d242af925e84020fa955 (patch)
treefcf1124185ae9278fd8263df9e3efa06d40a6ba6
parentff1c3ce3877ba24a986c3ba110f907a8786ea9c1 (diff)
update(class): update host net class rx length check
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--class/cdc/usbh_cdc_ecm.c13
-rw-r--r--class/cdc/usbh_cdc_ncm.c33
-rw-r--r--class/vendor/net/usbh_asix.c33
-rw-r--r--class/vendor/net/usbh_rtl8152.c33
-rw-r--r--class/wireless/usbh_rndis.c37
5 files changed, 51 insertions, 98 deletions
diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c
index 6fef9b20..aa15b2dd 100644
--- a/class/cdc/usbh_cdc_ecm.c
+++ b/class/cdc/usbh_cdc_ecm.c
@@ -271,21 +271,18 @@ find_class:
}
g_cdc_ecm_rx_length = g_cdc_ecm_class.bulkin_urb.actual_length;
+ if (g_cdc_ecm_rx_length == 0) {
+ continue;
+ }
- /* A transfer is complete because last packet is a short packet.
- * Short packet is not zero, match g_cdc_ecm_rx_length % USB_GET_MAXPACKETSIZE(g_cdc_ecm_class.bulkin->wMaxPacketSize).
- * Short packet is zero, check if g_cdc_ecm_class.bulkin_urb.actual_length < transfer_size, for example transfer is complete with size is 512 < 1514.
- * This case is always true
- */
- if (g_cdc_ecm_rx_length % USB_GET_MAXPACKETSIZE(g_cdc_ecm_class.bulkin->wMaxPacketSize) ||
- (g_cdc_ecm_class.bulkin_urb.actual_length < CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE)) {
+ if (g_cdc_ecm_rx_length < CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE) {
USB_LOG_DBG("rxlen:%d\r\n", g_cdc_ecm_rx_length);
usbh_cdc_ecm_eth_input(g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_length);
g_cdc_ecm_rx_length = 0;
} else {
- /* There's no way to run here. */
+ USB_LOG_ERR("cdc ecm rx packet overflow\r\n");
}
}
// clang-format off
diff --git a/class/cdc/usbh_cdc_ncm.c b/class/cdc/usbh_cdc_ncm.c
index 33cb7691..53334e8c 100644
--- a/class/cdc/usbh_cdc_ncm.c
+++ b/class/cdc/usbh_cdc_ncm.c
@@ -23,6 +23,10 @@
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_SEGSZE 1514U
+#if CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE > (16 * 1024)
+#error "CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE must be less than 16K"
+#endif
+
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_rx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_tx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
@@ -260,11 +264,6 @@ void usbh_cdc_ncm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
{
uint32_t g_cdc_ncm_rx_length;
int ret;
-#if CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE <= (16 * 1024)
- uint32_t transfer_size = CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE;
-#else
- uint32_t transfer_size = (16 * 1024);
-#endif
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create cdc ncm rx thread\r\n");
@@ -286,20 +285,18 @@ find_class:
g_cdc_ncm_rx_length = 0;
while (1) {
- usbh_bulk_urb_fill(&g_cdc_ncm_class.bulkin_urb, g_cdc_ncm_class.hport, g_cdc_ncm_class.bulkin, &g_cdc_ncm_rx_buffer[g_cdc_ncm_rx_length], transfer_size, USB_OSAL_WAITING_FOREVER, NULL, NULL);
+ usbh_bulk_urb_fill(&g_cdc_ncm_class.bulkin_urb, g_cdc_ncm_class.hport, g_cdc_ncm_class.bulkin, g_cdc_ncm_rx_buffer, CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE, USB_OSAL_WAITING_FOREVER, NULL, NULL);
ret = usbh_submit_urb(&g_cdc_ncm_class.bulkin_urb);
if (ret < 0) {
goto find_class;
}
- g_cdc_ncm_rx_length += g_cdc_ncm_class.bulkin_urb.actual_length;
+ g_cdc_ncm_rx_length = g_cdc_ncm_class.bulkin_urb.actual_length;
+ if(g_cdc_ncm_rx_length == 0) {
+ continue;
+ }
- /* A transfer is complete because last packet is a short packet.
- * Short packet is not zero, match g_cdc_ncm_rx_length % USB_GET_MAXPACKETSIZE(g_cdc_ncm_class.bulkin->wMaxPacketSize).
- * Short packet is zero, check if g_cdc_ncm_class.bulkin_urb.actual_length < transfer_size, for example transfer is complete with size is 1024 < 2048.
- */
- if ((g_cdc_ncm_rx_length % USB_GET_MAXPACKETSIZE(g_cdc_ncm_class.bulkin->wMaxPacketSize)) ||
- (g_cdc_ncm_class.bulkin_urb.actual_length < transfer_size)) {
+ if (g_cdc_ncm_rx_length < CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE) {
USB_LOG_DBG("rxlen:%d\r\n", g_cdc_ncm_rx_length);
struct cdc_ncm_nth16 *nth16 = (struct cdc_ncm_nth16 *)&g_cdc_ncm_rx_buffer[0];
@@ -333,15 +330,7 @@ find_class:
g_cdc_ncm_rx_length = 0;
} else {
-#if CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE <= (16 * 1024)
- if (g_cdc_ncm_rx_length == CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE) {
-#else
- if ((g_cdc_ncm_rx_length + (16 * 1024)) > CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE) {
-#endif
- USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE\r\n");
- while (1) {
- }
- }
+ USB_LOG_ERR("cdc ncm rx packet overflow\r\n");
}
}
// clang-format off
diff --git a/class/vendor/net/usbh_asix.c b/class/vendor/net/usbh_asix.c
index 3e286851..e8d6a782 100644
--- a/class/vendor/net/usbh_asix.c
+++ b/class/vendor/net/usbh_asix.c
@@ -15,6 +15,10 @@
static struct usbh_asix g_asix_class;
+#if CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE > (16 * 1024)
+#error "CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE must be less than 16K"
+#endif
+
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
@@ -679,11 +683,6 @@ void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
uint16_t len;
uint16_t len_crc;
uint32_t data_offset;
-#if CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE <= (16 * 1024)
- uint32_t transfer_size = CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE;
-#else
- uint32_t transfer_size = (16 * 1024);
-#endif
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create asix rx thread\r\n");
@@ -706,20 +705,18 @@ find_class:
g_asix_rx_length = 0;
while (1) {
- usbh_bulk_urb_fill(&g_asix_class.bulkin_urb, g_asix_class.hport, g_asix_class.bulkin, &g_asix_rx_buffer[g_asix_rx_length], transfer_size, USB_OSAL_WAITING_FOREVER, NULL, NULL);
+ usbh_bulk_urb_fill(&g_asix_class.bulkin_urb, g_asix_class.hport, g_asix_class.bulkin, g_asix_rx_buffer, CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE, USB_OSAL_WAITING_FOREVER, NULL, NULL);
ret = usbh_submit_urb(&g_asix_class.bulkin_urb);
if (ret < 0) {
goto find_class;
}
- g_asix_rx_length += g_asix_class.bulkin_urb.actual_length;
+ g_asix_rx_length = g_asix_class.bulkin_urb.actual_length;
+ if (g_asix_rx_length == 0) {
+ continue;
+ }
- /* A transfer is complete because last packet is a short packet.
- * Short packet is not zero, match g_asix_rx_length % USB_GET_MAXPACKETSIZE(g_asix_class.bulkin->wMaxPacketSize).
- * Short packet is zero, check if g_asix_class.bulkin_urb.actual_length < transfer_size, for example transfer is complete with size is 1024 < 2048.
- */
- if (g_asix_rx_length % USB_GET_MAXPACKETSIZE(g_asix_class.bulkin->wMaxPacketSize) ||
- (g_asix_class.bulkin_urb.actual_length < transfer_size)) {
+ if (g_asix_rx_length < CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE) {
USB_LOG_DBG("rxlen:%d\r\n", g_asix_rx_length);
data_offset = 0;
@@ -743,15 +740,7 @@ find_class:
}
}
} else {
-#if CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE <= (16 * 1024)
- if (g_asix_rx_length == CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE) {
-#else
- if ((g_asix_rx_length + (16 * 1024)) > CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE) {
-#endif
- USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE\r\n");
- while (1) {
- }
- }
+ USB_LOG_ERR("asix packet overflow\r\n");
}
}
// clang-format off
diff --git a/class/vendor/net/usbh_rtl8152.c b/class/vendor/net/usbh_rtl8152.c
index 1cbf9b4f..571653f1 100644
--- a/class/vendor/net/usbh_rtl8152.c
+++ b/class/vendor/net/usbh_rtl8152.c
@@ -12,6 +12,10 @@
#define DEV_FORMAT "/dev/rtl8152"
+#if CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE > (16 * 1024)
+#error "CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE must be less than 16K"
+#endif
+
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_inttx_buffer[USB_ALIGN_UP(2, CONFIG_USB_ALIGN_SIZE)];
@@ -2138,11 +2142,6 @@ void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
int ret;
uint16_t len;
uint16_t data_offset;
-#if CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE <= (16 * 1024)
- uint32_t transfer_size = CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE;
-#else
- uint32_t transfer_size = (16 * 1024);
-#endif
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create rtl8152 rx thread\r\n");
@@ -2174,20 +2173,18 @@ find_class:
g_rtl8152_rx_length = 0;
while (1) {
- usbh_bulk_urb_fill(&g_rtl8152_class.bulkin_urb, g_rtl8152_class.hport, g_rtl8152_class.bulkin, &g_rtl8152_rx_buffer[g_rtl8152_rx_length], transfer_size, USB_OSAL_WAITING_FOREVER, NULL, NULL);
+ usbh_bulk_urb_fill(&g_rtl8152_class.bulkin_urb, g_rtl8152_class.hport, g_rtl8152_class.bulkin, g_rtl8152_rx_buffer, CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE, USB_OSAL_WAITING_FOREVER, NULL, NULL);
ret = usbh_submit_urb(&g_rtl8152_class.bulkin_urb);
if (ret < 0) {
goto find_class;
}
- g_rtl8152_rx_length += g_rtl8152_class.bulkin_urb.actual_length;
+ g_rtl8152_rx_length = g_rtl8152_class.bulkin_urb.actual_length;
+ if (g_rtl8152_rx_length == 0) {
+ continue;
+ }
- /* A transfer is complete because last packet is a short packet.
- * Short packet is not zero, match g_rtl8152_rx_length % USB_GET_MAXPACKETSIZE(g_rtl8152_class.bulkin->wMaxPacketSize).
- * Short packet is zero, check if g_rtl8152_class.bulkin_urb.actual_length < transfer_size, for example transfer is complete with size is 1024 < 2048.
- */
- if (g_rtl8152_rx_length % USB_GET_MAXPACKETSIZE(g_rtl8152_class.bulkin->wMaxPacketSize) ||
- (g_rtl8152_class.bulkin_urb.actual_length < transfer_size)) {
+ if (g_rtl8152_rx_length < CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
data_offset = 0;
USB_LOG_DBG("rxlen:%d\r\n", g_rtl8152_rx_length);
@@ -2210,15 +2207,7 @@ find_class:
}
}
} else {
-#if CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE <= (16 * 1024)
- if (g_rtl8152_rx_length == CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
-#else
- if ((g_rtl8152_rx_length + (16 * 1024)) > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
-#endif
- USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE\r\n");
- while (1) {
- }
- }
+ USB_LOG_ERR("rtl8152 packet overflow\r\n");
}
}
// clang-format off
diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c
index 2ce075d6..acee7043 100644
--- a/class/wireless/usbh_rndis.c
+++ b/class/wireless/usbh_rndis.c
@@ -13,6 +13,10 @@
#define DEV_FORMAT "/dev/rndis"
+#if CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE > (16 * 1024)
+#error "CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE must be less than 16K"
+#endif
+
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[512];
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
@@ -448,11 +452,6 @@ void usbh_rndis_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
uint32_t pmg_offset;
rndis_data_packet_t *pmsg;
rndis_data_packet_t temp;
-#if CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE <= (16 * 1024)
- uint32_t transfer_size = CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE;
-#else
- uint32_t transfer_size = (16 * 1024);
-#endif
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
@@ -476,22 +475,21 @@ find_class:
g_rndis_rx_length = 0;
while (1) {
- usbh_bulk_urb_fill(&g_rndis_class.bulkin_urb, g_rndis_class.hport, g_rndis_class.bulkin, &g_rndis_rx_buffer[g_rndis_rx_length], transfer_size, USB_OSAL_WAITING_FOREVER, NULL, NULL);
+ usbh_bulk_urb_fill(&g_rndis_class.bulkin_urb, g_rndis_class.hport, g_rndis_class.bulkin, g_rndis_rx_buffer, CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE, USB_OSAL_WAITING_FOREVER, NULL, NULL);
ret = usbh_submit_urb(&g_rndis_class.bulkin_urb);
if (ret < 0) {
break;
}
- g_rndis_rx_length += g_rndis_class.bulkin_urb.actual_length;
+ g_rndis_rx_length = g_rndis_class.bulkin_urb.actual_length;
+ if (g_rndis_rx_length == 0) {
+ USB_LOG_WRN("rndis rx length is 0 but no zero required in spec\r\n");
+ continue;
+ }
- /* A transfer is complete because last packet is a short packet.
- * Short packet is not zero, match g_rndis_rx_length % USB_GET_MAXPACKETSIZE(g_rndis_class.bulkin->wMaxPacketSize).
- * Short packet cannot be zero.
- */
if (g_rndis_rx_length % USB_GET_MAXPACKETSIZE(g_rndis_class.bulkin->wMaxPacketSize)) {
pmg_offset = 0;
-
- uint32_t total_len = g_rndis_rx_length;
+ USB_LOG_DBG("rxlen:%d\r\n", g_rndis_rx_length);
while (g_rndis_rx_length > 0) {
USB_LOG_DBG("rxlen:%u\r\n", (unsigned int)g_rndis_rx_length);
@@ -516,21 +514,12 @@ find_class:
g_rndis_rx_length = 0;
}
} else {
- USB_LOG_ERR("offset:%u,remain:%u,total:%u\r\n", (unsigned int)pmg_offset, (unsigned int)g_rndis_rx_length, (unsigned int)total_len);
+ USB_LOG_ERR("Error rndis packet message, offset:%u, remain:%u\r\n", (unsigned int)pmg_offset, (unsigned int)g_rndis_rx_length);
g_rndis_rx_length = 0;
- USB_LOG_ERR("Error rndis packet message\r\n");
}
}
} else {
-#if CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE <= (16 * 1024)
- if (g_rndis_rx_length == CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE) {
-#else
- if ((g_rndis_rx_length + (16 * 1024)) > CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE) {
-#endif
- USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE\r\n");
- while (1) {
- }
- }
+ USB_LOG_ERR("rndis packet overflow\r\n");
}
}