1
0
Fork 0
forked from nuttx/nuttx-update

usb_cdcmbim: add mbim device driver

./build.sh sim:usbdev -j12
sudo gdb nuttx/nuttx -ex "source nuttx/tools/gdb/__init__.py"

below command to create mbim NIC on host
nsh> conn 3

NuttX's MBIM device implementation adds an additional MBIM network
card to the NuttX system, which can debug the data communication with
the host, but this network card is unnecessary and needs to be removed
when the business actually uses this driver, And the cdcncm_receive
method needs to be re-implemented.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2024-04-16 20:04:55 +08:00 committed by Xiang Xiao
parent 271f76590f
commit 5b24917bb9
7 changed files with 848 additions and 152 deletions

View file

@ -57,6 +57,7 @@ CONFIG_NETUTILS_TELNETD=y
CONFIG_NET_BINDTODEVICE=y
CONFIG_NET_BROADCAST=y
CONFIG_NET_CDCECM=y
CONFIG_NET_CDCMBIM=y
CONFIG_NET_CDCNCM=y
CONFIG_NET_ETH_PKTSIZE=1518
CONFIG_NET_ICMP_SOCKET=y
@ -71,6 +72,7 @@ CONFIG_NET_IPFORWARD_NSTRUCT=100
CONFIG_NET_IPv6=y
CONFIG_NET_MAX_RECV_BUFSIZE=65535
CONFIG_NET_MAX_SEND_BUFSIZE=65535
CONFIG_NET_MBIM=y
CONFIG_NET_NAT=y
CONFIG_NET_RECV_BUFSIZE=16384
CONFIG_NET_SEND_BUFSIZE=16384

View file

@ -258,6 +258,53 @@ static void *board_composite2_connect(int port)
return composite_initialize(composite_getdevdescs(), dev, dev_idx);
}
/****************************************************************************
* Name: board_composite3_connect
*
* Description:
* Connect the USB composite device on the specified USB device port for
* configuration 3.
*
* Input Parameters:
* port - The USB device port.
*
* Returned Value:
* A non-NULL handle value is returned on success. NULL is returned on
* any failure.
*
****************************************************************************/
static void *board_composite3_connect(int port)
{
struct composite_devdesc_s dev[1];
int dev_idx = 0;
#ifdef CONFIG_NET_CDCMBIM
/* Configure the CDC/NCM device */
cdcmbim_get_composite_devdesc(&dev[dev_idx]);
/* Interfaces */
dev[dev_idx].devinfo.ifnobase = 0;
dev[dev_idx].minor = 0;
/* Strings */
dev[dev_idx].devinfo.strbase = COMPOSITE_NSTRIDS - 1;
/* Endpoints */
dev[dev_idx].devinfo.epno[CDCNCM_EP_INTIN_IDX] = 5;
dev[dev_idx].devinfo.epno[CDCNCM_EP_BULKIN_IDX] = 6;
dev[dev_idx].devinfo.epno[CDCNCM_EP_BULKOUT_IDX] = 7;
dev_idx += 1;
#endif
return composite_initialize(composite_getdevdescs(), dev, dev_idx);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -303,10 +350,14 @@ void *board_composite_connect(int port, int configid)
{
return board_composite1_connect(port);
}
else
else if (configid == 2)
{
return board_composite2_connect(port);
}
else
{
return board_composite3_connect(port);
}
}
#endif /* CONFIG_BOARDCTL_USBDEVCTRL && CONFIG_USBDEV_COMPOSITE */

View file

@ -1248,6 +1248,16 @@ menuconfig NET_CDCNCM
if NET_CDCNCM
config NET_CDCMBIM
bool "CDC-MBIM Ethernet-over-USB"
default n
---help---
This option may require CONFIG_NETDEV_LATEINIT=y, otherwise the
power-up initialization may call the non-existent xxx_netinitialize().
This option is not automatically selected because it may be that
you have an additional network device that requires the early
xxx_netinitialize() call.
menuconfig CDCNCM_COMPOSITE
bool "CDC/NCM composite support"
default n
@ -1385,9 +1395,17 @@ config CDCNCM_VENDORSTR
default "NuttX"
config CDCNCM_PRODUCTSTR
string "Product string"
string "CDCNCM Product string"
default "CDC/NCM Ethernet"
if NET_CDCMBIM
config CDCMBIM_PRODUCTSTR
string "CDCMBIM Product string"
default "CDC/MBIM Ethernet"
endif # NET_CDCMBIM
endif # !CDCNCM_COMPOSITE
config CDCNCM_QUOTA_TX

File diff suppressed because it is too large Load diff

View file

@ -343,6 +343,16 @@
#define NCM_NETWORK_CONNECTION ECM_NETWORK_CONNECTION
#define NCM_SPEED_CHANGE ECM_SPEED_CHANGE
/* Table 16: Requests, Mobile Broadband Interface Model */
#define MBIM_SEND_COMMAND ECM_SEND_COMMAND
#define MBIM_GET_RESPONSE ECM_GET_RESPONSE
/* Table 17: Notifications, Networking Control Model */
#define MBIM_NETWORK_CONNECTION NCM_NETWORK_CONNECTION
#define MBIM_SPEED_CHANGE NCM_SPEED_CHANGE
/* Descriptors ***************************************************************/
/* Table 25: bDescriptor SubType in Functional Descriptors */
@ -913,6 +923,25 @@ struct cdc_ncm_funcdesc_s
#define SIZEOF_NCM_FUNCDESC 6
struct cdc_mbim_funcdesc_s
{
uint8_t size; /* bLength, Size of this descriptor */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_NCM as defined in
* Table 25.
*/
uint8_t version[2]; /* bcdNcmVersion, the NCM version 0x0100 */
uint8_t maxctrlmsg[2];
uint8_t numfilter;
uint8_t maxfiltersize;
uint8_t maxsegmentsize[2];
uint8_t netcaps; /* bmNetworkCapabilities, The NCM net types the device
* supports.
*/
};
#define SIZEOF_MBIM_FUNCDESC 12
/* Table 43: ATM Networking Functional Descriptor */
struct cdc_atm_funcdesc_s

View file

@ -57,16 +57,16 @@ extern "C"
****************************************************************************/
/****************************************************************************
* Name: cdcncm_initialize
* Name: cdcncm_initialize / cdcmbim_initialize
*
* Description:
* Register CDC/NCM USB device interface. Register the corresponding
* Register CDC_NCM/MBIM USB device interface. Register the corresponding
* network driver to NuttX and bring up the network.
*
* Input Parameters:
* minor - Device minor number.
* handle - An optional opaque reference to the CDC/NCM class object that
* may subsequently be used with cdcncm_uninitialize().
* handle - An optional opaque reference to the CDC_NCM/MBIM class object
* that may subsequently be used with cdcncm_uninitialize().
*
* Returned Value:
* Zero (OK) means that the driver was successfully registered. On any
@ -76,10 +76,13 @@ extern "C"
#ifndef CONFIG_CDCNCM_COMPOSITE
int cdcncm_initialize(int minor, FAR void **handle);
# ifdef CONFIG_NET_CDCMBIM
int cdcmbim_initialize(int minor, FAR void **handle);
# endif
#endif
/****************************************************************************
* Name: cdcncm_get_composite_devdesc
* Name: cdcncm_get_composite_devdesc / cdcmbim_get_composite_devdesc
*
* Description:
* Helper function to fill in some constants into the composite
@ -95,6 +98,9 @@ int cdcncm_initialize(int minor, FAR void **handle);
#ifdef CONFIG_CDCNCM_COMPOSITE
void cdcncm_get_composite_devdesc(FAR struct composite_devdesc_s *dev);
# ifdef CONFIG_NET_CDCMBIM
void cdcmbim_get_composite_devdesc(FAR struct composite_devdesc_s *dev);
# endif
#endif
#undef EXTERN

View file

@ -228,7 +228,6 @@ config NET_LOOPBACK_PKTSIZE
menuconfig NET_MBIM
bool "MBIM modem support"
depends on USBHOST_CDCMBIM
default n
menuconfig NET_SLIP