Skip to content

Commit 418b692

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
usbdev/cdcmbim: add response notify
when the host is needed to read the data, RESPONSE_AVAILABLE must first be sent. Signed-off-by: zhanghongyu <[email protected]>
1 parent 5b24917 commit 418b692

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

drivers/usbdev/cdcncm.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@
150150

151151
enum ncm_notify_state_e
152152
{
153-
NCM_NOTIFY_NONE, /* Don't notify */
154-
NCM_NOTIFY_CONNECT, /* Issue CONNECT next */
155-
NCM_NOTIFY_SPEED, /* Issue SPEED_CHANGE next */
153+
NCM_NOTIFY_NONE, /* Don't notify */
154+
NCM_NOTIFY_CONNECT, /* Issue CONNECT next */
155+
NCM_NOTIFY_SPEED, /* Issue SPEED_CHANGE next */
156+
NCM_NOTIFY_RESPONSE_AVAILABLE, /* Issue RESPONSE_AVAILABLE next */
156157
};
157158

158159
struct ndp_parser_opts_s
@@ -392,6 +393,8 @@ static int cdcncm_ioctl(FAR struct netdev_lowerhalf_s *dev, int cmd,
392393
unsigned long arg);
393394
#endif
394395

396+
static void cdcncm_notify_worker(FAR void *arg);
397+
395398
/* USB Device Class Driver **************************************************/
396399

397400
/* USB Device Class methods */
@@ -724,6 +727,9 @@ static ssize_t cdcmbim_write(FAR struct file *filep, FAR const char *buffer,
724727
}
725728

726729
uinfo("wrote %zd bytes\n", buflen);
730+
DEBUGASSERT(self->ncmdriver.notify == NCM_NOTIFY_RESPONSE_AVAILABLE);
731+
work_queue(ETHWORK, &self->ncmdriver.notifywork, cdcncm_notify_worker,
732+
self, 0);
727733

728734
errout:
729735
nxmutex_unlock(&self->lock);
@@ -1521,12 +1527,12 @@ static void cdcncm_resetconfig(FAR struct cdcncm_driver_s *self)
15211527
EP_DISABLE(self->epint);
15221528
EP_DISABLE(self->epbulkin);
15231529
EP_DISABLE(self->epbulkout);
1530+
self->notify = NCM_NOTIFY_SPEED;
15241531
}
15251532

15261533
self->parseropts = &g_ndp16_opts;
15271534
self->ndpsign = self->isncm ? self->parseropts->ndpsign :
15281535
CDC_MBIM_NDP16_NOCRC_SIGN;
1529-
self->notify = NCM_NOTIFY_NONE;
15301536
}
15311537

15321538
/****************************************************************************
@@ -1627,11 +1633,11 @@ static int cdcncm_setconfig(FAR struct cdcncm_driver_s *self, uint8_t config)
16271633
}
16281634

16291635
/****************************************************************************
1630-
* Name: ncm_notify
1636+
* Name: cdcncm_notify
16311637
*
16321638
****************************************************************************/
16331639

1634-
static int ncm_notify(FAR struct cdcncm_driver_s *self)
1640+
static int cdcncm_notify(FAR struct cdcncm_driver_s *self)
16351641
{
16361642
FAR struct usb_ctrlreq_s *req =
16371643
(FAR struct usb_ctrlreq_s *)self->notifyreq->buf;
@@ -1677,7 +1683,20 @@ static int ncm_notify(FAR struct cdcncm_driver_s *self)
16771683
self->notify = NCM_NOTIFY_CONNECT;
16781684
break;
16791685
}
1680-
}
1686+
1687+
case NCM_NOTIFY_RESPONSE_AVAILABLE:
1688+
{
1689+
req->req = MBIM_RESPONSE_AVAILABLE;
1690+
req->value[0] = LSBYTE(0);
1691+
req->value[1] = MSBYTE(0);
1692+
req->len[0] = LSBYTE(0);
1693+
req->len[1] = MSBYTE(0);
1694+
ret = sizeof(*req);
1695+
1696+
self->notify = NCM_NOTIFY_NONE;
1697+
break;
1698+
}
1699+
}
16811700

16821701
req->type = 0xa1;
16831702
req->index[0] = LSBYTE(self->devinfo.ifnobase);
@@ -1687,18 +1706,18 @@ static int ncm_notify(FAR struct cdcncm_driver_s *self)
16871706
}
16881707

16891708
/****************************************************************************
1690-
* Name: ncm_do_notify
1709+
* Name: cdcncm_notify_worker
16911710
*
16921711
****************************************************************************/
16931712

1694-
static void ncm_do_notify(FAR void *arg)
1713+
static void cdcncm_notify_worker(FAR void *arg)
16951714
{
16961715
FAR struct cdcncm_driver_s *self = arg;
16971716
int ret;
16981717

16991718
while (self->notify != NCM_NOTIFY_NONE)
17001719
{
1701-
ret = ncm_notify(self);
1720+
ret = cdcncm_notify(self);
17021721
if (ret > 0)
17031722
{
17041723
FAR struct usbdev_req_s *notifyreq = self->notifyreq;
@@ -1709,6 +1728,12 @@ static void ncm_do_notify(FAR void *arg)
17091728
EP_SUBMIT(self->epint, notifyreq);
17101729
}
17111730
}
1731+
1732+
/* After the NIC information is synchronized, subsequent notifications
1733+
* are all related to the mbim control
1734+
*/
1735+
1736+
self->notify = NCM_NOTIFY_RESPONSE_AVAILABLE;
17121737
}
17131738

17141739
/****************************************************************************
@@ -1727,7 +1752,7 @@ static int cdcncm_setinterface(FAR struct cdcncm_driver_s *self,
17271752
}
17281753

17291754
netdev_lower_carrier_on(&self->dev);
1730-
work_queue(ETHWORK, &self->notifywork, ncm_do_notify, self,
1755+
work_queue(ETHWORK, &self->notifywork, cdcncm_notify_worker, self,
17311756
MSEC2TICK(100));
17321757
}
17331758
else

include/nuttx/usb/cdc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341
/* Table 15: Notifications, Networking Control Model */
342342

343343
#define NCM_NETWORK_CONNECTION ECM_NETWORK_CONNECTION
344+
#define NCM_RESPONSE_AVAILABLE ECM_RESPONSE_AVAILABLE
344345
#define NCM_SPEED_CHANGE ECM_SPEED_CHANGE
345346

346347
/* Table 16: Requests, Mobile Broadband Interface Model */
@@ -351,6 +352,7 @@
351352
/* Table 17: Notifications, Networking Control Model */
352353

353354
#define MBIM_NETWORK_CONNECTION NCM_NETWORK_CONNECTION
355+
#define MBIM_RESPONSE_AVAILABLE NCM_RESPONSE_AVAILABLE
354356
#define MBIM_SPEED_CHANGE NCM_SPEED_CHANGE
355357

356358
/* Descriptors ***************************************************************/

0 commit comments

Comments
 (0)