1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #17200 from bergzand/pr/usbus_cdc_ecm/check_max_frame_len

cdc_ecm: Truncate frames at max ethernet size
This commit is contained in:
Francisco 2021-11-16 07:54:01 +01:00 committed by GitHub
commit 5f119e3b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -307,15 +307,16 @@ static void _handle_rx_flush_ev(event_t *ev)
_handle_rx_flush(cdcecm);
}
static void _store_frame_chunk(usbus_cdcecm_device_t *cdcecm)
static void _store_frame_chunk(usbus_cdcecm_device_t *cdcecm, size_t len)
{
uint8_t *buf = cdcecm->ep_out->ep->buf;
size_t len = 0;
usbdev_ep_get(cdcecm->ep_out->ep, USBOPT_EP_AVAILABLE, &len,
sizeof(size_t));
memcpy(cdcecm->in_buf + cdcecm->len, buf, len);
cdcecm->len += len;
/* Truncate if it exceeds the expected MTU size. */
/* TODO: Should be converted to an endpoint halt after #17090 is merged */
if (cdcecm->len + len < ETHERNET_FRAME_LEN) {
memcpy(cdcecm->in_buf + cdcecm->len, buf, len);
cdcecm->len += len;
}
if (len < USBUS_CDCECM_EP_DATA_SIZE) {
netdev_trigger_event_isr(&cdcecm->netdev);
}
@ -334,7 +335,7 @@ static void _transfer_handler(usbus_t *usbus, usbus_handler_t *handler,
}
size_t len = 0;
usbdev_ep_get(ep, USBOPT_EP_AVAILABLE, &len, sizeof(size_t));
_store_frame_chunk(cdcecm);
_store_frame_chunk(cdcecm, len);
if (len == USBUS_CDCECM_EP_DATA_SIZE) {
usbdev_ep_ready(ep, 0);
}