From 45745579bc23312f4b19f699671b2595a3d0447c Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Mon, 21 Oct 2019 20:03:34 +0200 Subject: [PATCH] cdcecm: early exit on inactive usb interface This adds an early exit when the usb interface with the data endpoints is not activated. This prevents the cdc_ecm_netdev code from attempting to send the PDU when the USB device is not yet initialized or activated by a host. --- sys/usb/usbus/cdc/ecm/cdc_ecm_netdev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/usb/usbus/cdc/ecm/cdc_ecm_netdev.c b/sys/usb/usbus/cdc/ecm/cdc_ecm_netdev.c index 65c575869f..ca5b5e73d3 100644 --- a/sys/usb/usbus/cdc/ecm/cdc_ecm_netdev.c +++ b/sys/usb/usbus/cdc/ecm/cdc_ecm_netdev.c @@ -59,6 +59,11 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) uint8_t *buf = cdcecm->ep_in->ep->buf; const iolist_t *iolist_start = iolist; size_t len = iolist_size(iolist); + /* interface with alternative function ID 1 is the interface containing the + * data endpoints, no sense trying to transmit data if it is not active */ + if (cdcecm->active_iface != 1) { + return -ENOTCONN; + } DEBUG("CDC_ECM_netdev: sending %u bytes\n", len); /* load packet data into FIFO */ size_t iol_offset = 0;