Skip to content

Commit ac285a4

Browse files
committed
fix(class): fix rndis & ecm tx with lwip
- add usb_device_is_configured to check tx/rx - check g_xxx_tx_data_length in usbd_xxx_start_write because when next frame comes, usb will be busy but when memcpy done, usb will be not busy Signed-off-by: sakumisu <[email protected]>
1 parent cf22bcf commit ac285a4

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

class/cdc/usbd_cdc_ecm.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void cdc_ecm_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
173173
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
174174
{
175175
if (!usb_device_is_configured(0)) {
176-
return -USB_ERR_NODEV;
176+
return -USB_ERR_NOTCONN;
177177
}
178178

179179
if (g_cdc_ecm_tx_data_length > 0) {
@@ -189,7 +189,7 @@ int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
189189
int usbd_cdc_ecm_start_read(uint8_t *buf, uint32_t len)
190190
{
191191
if (!usb_device_is_configured(0)) {
192-
return -USB_ERR_NODEV;
192+
return -USB_ERR_NOTCONN;
193193
}
194194

195195
g_cdc_ecm_rx_data_length = 0;
@@ -201,6 +201,10 @@ struct pbuf *usbd_cdc_ecm_eth_rx(void)
201201
{
202202
struct pbuf *p;
203203

204+
if (!usb_device_is_configured(0)) {
205+
return NULL;
206+
}
207+
204208
if (g_cdc_ecm_rx_data_length == 0) {
205209
return NULL;
206210
}
@@ -222,8 +226,8 @@ int usbd_cdc_ecm_eth_tx(struct pbuf *p)
222226
struct pbuf *q;
223227
uint8_t *buffer;
224228

225-
if (g_cdc_ecm_tx_data_length > 0) {
226-
return -USB_ERR_BUSY;
229+
if (!usb_device_is_configured(0)) {
230+
return -USB_ERR_NOTCONN;
227231
}
228232

229233
if (p->tot_len > sizeof(g_cdc_ecm_tx_buffer)) {
@@ -261,8 +265,12 @@ struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const
261265
return intf;
262266
}
263267

264-
void usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2])
268+
int usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2])
265269
{
270+
if (!usb_device_is_configured(0)) {
271+
return -USB_ERR_NOTCONN;
272+
}
273+
266274
if (connect) {
267275
g_current_net_status = 2;
268276
memcpy(g_connect_speed_table, speed, 8);
@@ -271,6 +279,8 @@ void usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2])
271279
g_current_net_status = 1;
272280
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_DISCONNECTED, NULL);
273281
}
282+
283+
return 0;
274284
}
275285

276286
__WEAK void usbd_cdc_ecm_data_recv_done(uint32_t len)

class/cdc/usbd_cdc_ecm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern "C" {
1515
/* Init cdc ecm interface driver */
1616
struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const uint8_t int_ep, const uint8_t out_ep, const uint8_t in_ep);
1717

18-
void usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2]);
18+
int usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2]);
1919

2020
void usbd_cdc_ecm_data_recv_done(uint32_t len);
2121
void usbd_cdc_ecm_data_send_done(uint32_t len);

class/wireless/usbd_rndis.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void rndis_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
515515
int usbd_rndis_start_write(uint8_t *buf, uint32_t len)
516516
{
517517
if (!usb_device_is_configured(0)) {
518-
return -USB_ERR_NODEV;
518+
return -USB_ERR_NOTCONN;
519519
}
520520

521521
if (g_rndis_tx_data_length > 0) {
@@ -531,7 +531,7 @@ int usbd_rndis_start_write(uint8_t *buf, uint32_t len)
531531
int usbd_rndis_start_read(uint8_t *buf, uint32_t len)
532532
{
533533
if (!usb_device_is_configured(0)) {
534-
return -USB_ERR_NODEV;
534+
return -USB_ERR_NOTCONN;
535535
}
536536

537537
g_rndis_rx_data_buffer = buf;
@@ -547,6 +547,10 @@ struct pbuf *usbd_rndis_eth_rx(void)
547547
{
548548
struct pbuf *p;
549549

550+
if (!usb_device_is_configured(0)) {
551+
return NULL;
552+
}
553+
550554
if (g_rndis_rx_data_length == 0) {
551555
return NULL;
552556
}
@@ -569,14 +573,10 @@ int usbd_rndis_eth_tx(struct pbuf *p)
569573
uint8_t *buffer;
570574
rndis_data_packet_t *hdr;
571575

572-
if (g_usbd_rndis.link_status == NDIS_MEDIA_STATE_DISCONNECTED) {
576+
if (!usb_device_is_configured(0)) {
573577
return -USB_ERR_NOTCONN;
574578
}
575579

576-
if (g_rndis_tx_data_length > 0) {
577-
return -USB_ERR_BUSY;
578-
}
579-
580580
if (p->tot_len > sizeof(g_rndis_tx_buffer)) {
581581
p->tot_len = sizeof(g_rndis_tx_buffer);
582582
}
@@ -630,7 +630,7 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
630630
int usbd_rndis_set_connect(bool connect)
631631
{
632632
if (!usb_device_is_configured(0)) {
633-
return -USB_ERR_NODEV;
633+
return -USB_ERR_NOTCONN;
634634
}
635635

636636
if(g_usbd_rndis.set_rsp_get)

0 commit comments

Comments
 (0)