sys/usb/usbus/cdc_ecm_netdev: fix _recv() return values
Previously, the function would always return the max_len parameter. This poses two issues: 1. the API requires to return the actual packet size 2. the API requires that if the packet is larger than max_len, the packet is flushed and -ENOBUFS is returned 3. this basically bypasses the packet flushing, consequtive _recv() would return the last packet again This commit fixes those issues.
This commit is contained in:
parent
a301e81b47
commit
70d480c301
@ -128,19 +128,23 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
|||||||
|
|
||||||
static int _recv(netdev_t *netdev, void *buf, size_t max_len, void *info)
|
static int _recv(netdev_t *netdev, void *buf, size_t max_len, void *info)
|
||||||
{
|
{
|
||||||
|
(void)info;
|
||||||
usbus_cdcecm_device_t *cdcecm = _netdev_to_cdcecm(netdev);
|
usbus_cdcecm_device_t *cdcecm = _netdev_to_cdcecm(netdev);
|
||||||
|
|
||||||
(void)info;
|
size_t pktlen = cdcecm->len;
|
||||||
|
|
||||||
if (max_len == 0 && buf == NULL) {
|
if (max_len == 0 && buf == NULL) {
|
||||||
return cdcecm->len;
|
return pktlen;
|
||||||
}
|
}
|
||||||
if (max_len && buf == NULL) {
|
if (max_len && buf == NULL) {
|
||||||
_signal_rx_flush(cdcecm);
|
_signal_rx_flush(cdcecm);
|
||||||
return cdcecm->len;
|
return pktlen;
|
||||||
|
}
|
||||||
|
if (pktlen <= max_len) {
|
||||||
|
memcpy(buf, cdcecm->in_buf, pktlen);
|
||||||
}
|
}
|
||||||
memcpy(buf, cdcecm->in_buf, max_len);
|
|
||||||
_signal_rx_flush(cdcecm);
|
_signal_rx_flush(cdcecm);
|
||||||
return max_len;
|
return (pktlen <= max_len) ? (int)pktlen : -ENOBUFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _init(netdev_t *netdev)
|
static int _init(netdev_t *netdev)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user