From 7609b6749682afbfa3fbcf4c066dae510ddb2d39 Mon Sep 17 00:00:00 2001 From: "Alan C. Assis" Date: Sun, 14 Jun 2020 19:59:38 -0300 Subject: [PATCH] Fix issues reported on PR #1233 --- drivers/usbhost/Kconfig | 3 ++- drivers/usbhost/usbhost_cdcmbim.c | 39 +++++++++++++++++-------------- include/nuttx/net/net.h | 2 +- include/nuttx/usb/cdc.h | 8 ++++--- net/Kconfig | 5 ++++ net/netdev/netdev_register.c | 13 +++++++---- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/drivers/usbhost/Kconfig b/drivers/usbhost/Kconfig index d9678d105b..f57904bf4b 100644 --- a/drivers/usbhost/Kconfig +++ b/drivers/usbhost/Kconfig @@ -265,8 +265,9 @@ endif # USBHOST_CDCACM config USBHOST_CDCMBIM bool "CDC/MBIM support" default n - depends on USBHOST_HAVE_ASYNCH && !USBHOST_BULK_DISABLE && !USBHOST_INT_DISABLE + depends on USBHOST_HAVE_ASYNCH && !USBHOST_BULK_DISABLE && !USBHOST_INT_DISABLE && EXPERIMENTAL select USBHOST_ASYNCH + select NET_MBIM ---help--- Select this option to build in host support for CDC/MBIM network devices. diff --git a/drivers/usbhost/usbhost_cdcmbim.c b/drivers/usbhost/usbhost_cdcmbim.c index eb1f0da3a7..b0b251cd58 100644 --- a/drivers/usbhost/usbhost_cdcmbim.c +++ b/drivers/usbhost/usbhost_cdcmbim.c @@ -56,6 +56,7 @@ ****************************************************************************/ /* put in cdc.h */ + #define USB_CDC_SEND_ENCAPSULATED_COMMAND 0x00 #define USB_CDC_GET_ENCAPSULATED_RESPONSE 0x01 #define USB_CDC_GET_NTB_PARAMETERS 0x80 @@ -564,10 +565,10 @@ static ssize_t cdcwdm_write(FAR struct file *filep, FAR const char *buffer, static int cdcwdm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) { - FAR struct inode *inode; + FAR struct inode *inode; FAR struct usbhost_cdcmbim_s *priv; - int ret = OK; - int i; + int ret = OK; + int i; DEBUGASSERT(filep && filep->f_inode && fds); inode = filep->f_inode; @@ -803,9 +804,11 @@ static void usbhost_bulkin_work(FAR void *arg) { struct usbhost_cdcmbim_s *priv; struct usbhost_hubport_s *hport; + struct usb_cdc_ncm_nth16_s *nth; uint16_t ndpoffset; uint16_t dgram_len; uint16_t dgram_off; + uint16_t block_len; priv = (struct usbhost_cdcmbim_s *)arg; DEBUGASSERT(priv); @@ -828,8 +831,7 @@ static void usbhost_bulkin_work(FAR void *arg) /* Parse the NTB header */ - struct usb_cdc_ncm_nth16_s *nth = - (struct usb_cdc_ncm_nth16_s *)priv->rxnetbuf; + nth = (struct usb_cdc_ncm_nth16_s *)priv->rxnetbuf; if (usbhost_getle32(nth->signature) != USB_CDC_NCM_NTH16_SIGNATURE) { @@ -837,7 +839,7 @@ static void usbhost_bulkin_work(FAR void *arg) goto out; } - uint16_t block_len = usbhost_getle16(nth->block_length); + block_len = usbhost_getle16(nth->block_length); if (block_len > priv->bulkinbytes) { @@ -856,6 +858,7 @@ static void usbhost_bulkin_work(FAR void *arg) do { + struct usb_cdc_ncm_dpe16_s *dpe; struct usb_cdc_ncm_ndp16_s *ndp = (struct usb_cdc_ncm_ndp16_s *)(priv->rxnetbuf + ndpoffset); @@ -863,8 +866,6 @@ static void usbhost_bulkin_work(FAR void *arg) /* Parse each DPE */ - struct usb_cdc_ncm_dpe16_s *dpe; - for (dpe = ndp->dpe16; usbhost_getle16(dpe->index); dpe++) { dgram_off = usbhost_getle16(dpe->index); @@ -904,7 +905,17 @@ out: static void usbhost_rxdata_work(FAR void *arg) { + /* Would be nice if CTRLIN would return how many bytes it read... */ + + struct mbim_header_s + { + uint8_t type[4]; + uint8_t len[4]; + }; + FAR struct usbhost_cdcmbim_s *priv; + struct mbim_header_s *hdr; + uint32_t len; int ret; priv = (FAR struct usbhost_cdcmbim_s *)arg; @@ -931,16 +942,8 @@ static void usbhost_rxdata_work(FAR void *arg) goto errout; } - /* Would be nice if CTRLIN would return how many bytes it read... */ - - struct mbim_header_s - { - uint8_t type[4]; - uint8_t len[4]; - }; - - struct mbim_header_s *hdr = (struct mbim_header_s *)priv->comm_rxbuf; - uint32_t len = usbhost_getle32(hdr->len); + hdr = (struct mbim_header_s *)priv->comm_rxbuf; + len = usbhost_getle32(hdr->len); if (len > priv->maxctrlsize) { diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 3bb4808795..c2cbb930e1 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -156,7 +156,7 @@ enum net_lltype_e NET_LL_IEEE80211, /* IEEE 802.11 */ NET_LL_IEEE802154, /* IEEE 802.15.4 MAC */ NET_LL_PKTRADIO, /* Non-standard packet radio */ - NET_LL_MBIM + NET_LL_MBIM /* CDC-MBIM USB host driver */ }; /* This defines a bitmap big enough for one bit for each socket option */ diff --git a/include/nuttx/usb/cdc.h b/include/nuttx/usb/cdc.h index 7c3b7fb2a5..429fc056d3 100644 --- a/include/nuttx/usb/cdc.h +++ b/include/nuttx/usb/cdc.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/***************************************************************************** * include/nuttx/usb/cdc.h * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -16,7 +16,7 @@ * License for the specific language governing permissions and limitations * under the License. * - ****************************************************************************/ + *****************************************************************************/ #ifndef __INCLUDE_NUTTX_USB_CDC_H #define __INCLUDE_NUTTX_USB_CDC_H @@ -930,7 +930,9 @@ struct cdc_linecoding_s struct cdc_linestatus_s { uint8_t size[2]; /* wLength, Size of this structure, in bytes */ - uint8_t ringer[4]; /* dwRingerBitmap, Ringer Conf bitmap for this line */ + uint8_t ringer[4]; /* dwRingerBitmap, Ringer Configuration bitmap for this + * line + */ uint8_t line[4]; /* dwLineState, Defines current state of the line */ uint32_t call[1]; /* dwCallStateN, Current state of call N on the line */ }; diff --git a/net/Kconfig b/net/Kconfig index fed3d01259..0240f1cba6 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -150,6 +150,11 @@ config NET_LOOPBACK_PKTSIZE CONFIG_NET_LOOPBACK_PKTSIZE is zero, meaning that this maximum packet size will be used by loopback driver. +menuconfig NET_MBIM + bool "MBIM modem support" + depends on USBHOST_CDCMBIM + default n + menuconfig NET_SLIP bool "SLIP support" select ARCH_HAVE_NETDEV_STATISTICS diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 1ca7e546d4..4b08efaefa 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -314,11 +314,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) devfmt = NETDEV_TUN_FORMAT; break; #endif - case NET_LL_MBIM: - llhdrlen = 0; - pktsize = 1200; - devfmt = NETDEV_WWAN_FORMAT; - break; + +#ifdef CONFIG_NET_MBIM + case NET_LL_MBIM: + llhdrlen = 0; + pktsize = 1200; + devfmt = NETDEV_WWAN_FORMAT; + break; +#endif default: nerr("ERROR: Unrecognized link type: %d\n", lltype);