PPP
PPP 用于建立点对点链路。最初是用于慢速设备的,比如早期通过串行线上网。通过一套协议,维护硬件链路上的数据连接,并具备安全和认证特性,可建立计费模式。
我们在PPP拨号脚本中也常常可以看到波特率、用户名、密码、认证方式等参数。现在的猫或者家用路由拨号上网,多用PPPoE,也用到了PPP,因为PPPoE就是PPP over Ethernet。使用以太网链路,将PPP包封装到以太网帧中,从而可以继续利用PPP的认证和安全特性。
对于3、4、5G模块而言,多是通过USB总线连接,但是在内核中,将其识别为串口设备,设备名一般为ttyUSB*,这里的*指代数字,从0增长,一个模块可以转换出多个口,有的用于执行AT指令,有的用于拨号,既然是串口,那么使用PPP似乎就顺利成章了。
既然模块物理连接就是USB接口,那么可否直接利用USB转网口的方式呢?而且,PPP方式的封装和控制,普通认为效率不高,所以也有采用这种方式的必要。幸运的是,有多种直接基于USB口的方式可用,不幸的是,选择太多,缺乏统一标准。
NDIS
Network Driver Interface Specification,网络驱动接口规范。是一个类似接口标准的东西,屏蔽不同的硬件差异,在上层表现为统一的网络设备,从而简化应用层的使用。
RNDIS
指的是一种技术,如果是基于USB硬件,就是TCP/IP over USB,这样的话,对USB就是实现如何更好的将TCP/IP包封装到USB总线要求的格式中个,跟PPPOE有点类似。
CDC
是指USB规范下的通信设备类。基于USB接口的设备种类很多,比如声卡、键盘鼠标、打印机、存储设备等。CDC就跟这些类别属于一个层级,自然可知USB网卡、USB WIFI就应该是这类设备了。这里引申一下,不通设备有其特点,USB作为一种通用串行接口,作此分类,应该是为了更好的适应设备特性,做一些差异处理,从而更高效的利用自身的总线。
CDC(Communication Device Class)类是USB2.0标准下的一个子类,定义了通信相关设备的抽象集合。它与USB2.0标准以及其下的子类的相互关系如下图所示:
如上图,USB2.0标准下定义了很多子类,有音频类,CDC类,HID,打印,大容量存储类,HUB,智能卡等等。CDC就跟这些类别属于一个层级,自然可知USB网卡、USB WIFI就应该是这类设备了。更深入了解可以看这个链接: link.
USB CDC类的通信部分主要包含三部分:枚举过程、虚拟串口操作和数据通信。其中虚拟串口操作部分并不一定强制需要,因为若跳过这些虚拟串口的操作,实际上USB依然是可以通信的。这也就是为什么上图中,在操作虚拟串口之前会有两条数据通信的数据。
ECM/NCM
这两个是Linux下的NDIS标准。ECM是Ethernet Networking Control Model的简称,NCM是Network Control Model的简称,后者是包含前者的。
可以看出,ECM、NCM在USB上是要满足CDC要求的,如果出现CDC-ECM,按这种思路,就比较好理解了。进一步的,作为标准,如果内核支持这种方式,显然就不需要额外的驱动了。
根据这些信息,我们可以设想下主要流程:使用者可以利用CDC驱动,以标准的方式生成网络设备,建立网络连接,发送网络数据。所有通过USB总线跟模块交互的数据都被相关协议和标准做了约束,通过USB硬件到达模块。模块按协议和标准可以拿出其中的控制和数据信息,完成跟基站的交互。至于模块内部怎么实现,那是模块自己的事情了。
在操作系统看来,CDC-ECM设备就是一个虚拟以太网卡,包含标准网卡需要的MAC地址和IP地址。具体英文描述如下:
CDC-ECM(Ethernet Networking Control Model) offers device manufacturers to interface as a standard NIC (Network Interface Card) device. This interface is usually adopted by high speed LAN networking devices allowing high speed Ethernet data transfer over USB.
The ECM (Ethernet Networking Control Model) protocol is used for exchanging Ethernet-framed data between the device and host. A CDC ECM compliant device exposes itself as a virtual NIC to the host operating system. The NIC is assigned with a MAC and an IP address.
A general use case of a CDC ECM device is a point-to-point Ethernet adapter to a LAN/WLAN.
The NCM (Network Control Model) protocol is used for exchanging High Speed Ethernet-framed data between the device and host. A CDC NCM compliant device exposes itself as a virtual NIC to the host operating system. The NIC is assigned with a MAC and an IP address.
A general use case of a CDC NCM device is a Wireless Network Adapter which supports 3.5G/4G networks such as: HSPA+ and LTE.
/lib/modules/$(uname -r)/kernel/drivers/usb/class目录下看到cdc-acm.ko文件。
QMI-WWAN
是高通在Linux下提供的类似ECM的框架,由于高通的行业地位和其产品的时长占有率,该框架使用相当广泛。
GOBINET
内核早期没有添加上述QMI-WWAN驱动,高通使用该驱动完成拨号,后来内核中支持QMI-WWAN,就不再需要单独提供驱动了。
RMNET
介绍
类似CDC-ECM的一种变种,用于高通设备的高效数据传输协议。具体请参考:Rmnet Driver — The Linux Kernel documentation
rmnet driver is used for supporting the Multiplexing and aggregation Protocol (MAP). This protocol is used by all recent chipsets using Qualcomm Technologies, Inc. modems.
rmnet是支持多路复用和聚合的协议,一般被高通芯片所使用的一种协议。
This driver can be used to register onto any physical network device in IP mode. Physical transports include USB, HSIC, PCIe and IP accelerator.
该驱动可用被注册到任何物理网络设备,包括USB,HSIC,PCIE和IP加速器。
Multiplexing allows for creation of logical netdevices (rmnet devices) to handle multiple private data networks (PDN) like a default internet, tethering, multimedia messaging service (MMS) or IP media subsystem (IMS). Hardware sends packets with MAP headers to rmnet. Based on the multiplexer id, rmnet routes to the appropriate PDN after removing the MAP header.
多路复用允许创建逻辑网络设备(rmnet设备)来处理多个私有数据网络(PDN),如默认的互联网、系结、多媒体消息传递服务(MMS)或IP媒体子系统(IMS)。硬件发送具有MAP报头的数据包到rmnet。基于多路复用器id,rmnet在删除MAP报头后路由到适当的PDN。
Aggregation is required to achieve high data rates. This involves hardware sending aggregated bunch of MAP frames. rmnet driver will de-aggregate these MAP frames and send them to appropriate PDN’s.
聚合才能实现较高的数据速率。这涉及到硬件发送聚合的映射帧。rmnet驱动程序解析这些MAP聚合帧,并将它们发送到适当的PDN。
包格式
MAP packet v1 (data / control)
MAP header fields are in big endian format.
Packet format:
Bit 0 1 2-7 8-15 16-31
Function Command / Data Reserved Pad Multiplexer ID Payload length
Bit 32-x
Function Raw bytes
Command (1)/ Data (0) bit value is to indicate if the packet is a MAP command or data packet. Command packet is used for transport level flow control. Data packets are standard IP packets.
Reserved bits must be zero when sent and ignored when received.
Padding is the number of bytes to be appended to the payload to ensure 4 byte alignment.
Multiplexer ID is to indicate the PDN on which data has to be sent.
Payload length includes the padding length but does not include MAP header length.
Map packet v4 (data / control)
MAP header fields are in big endian format.
Packet format:
Bit 0 1 2-7 8-15 16-31
Function Command / Data Reserved Pad Multiplexer ID Payload length
Bit 32-(x-33) (x-32)-x
Function Raw bytes Checksum offload header
Command (1)/ Data (0) bit value is to indicate if the packet is a MAP command or data packet. Command packet is used for transport level flow control. Data packets are standard IP packets.
Reserved bits must be zero when sent and ignored when received.
Padding is the number of bytes to be appended to the payload to ensure 4 byte alignment.
Multiplexer ID is to indicate the PDN on which data has to be sent.
Payload length includes the padding length but does not include MAP header length.
Checksum offload header, has the information about the checksum processing done by the hardware.Checksum offload header fields are in big endian format.
Packet format:
Bit 0-14 15 16-31
Function Reserved Valid Checksum start offset
Bit 31-47 48-64
Function Checksum length Checksum value
Reserved bits must be zero when sent and ignored when received.
Valid bit indicates whether the partial checksum is calculated and is valid. Set to 1, if its is valid. Set to 0 otherwise.
Padding is the number of bytes to be appended to the payload to ensure 4 byte alignment.
Checksum start offset, Indicates the offset in bytes from the beginning of the IP header, from which modem computed checksum.
Checksum length is the Length in bytes starting from CKSUM_START_OFFSET, over which checksum is computed.
Checksum value, indicates the checksum computed.
MAP packet v5 (data / control)
MAP header fields are in big endian format.
Packet format:
Bit 0 1 2-7 8-15 16-31
Function Command / Data Next header Pad Multiplexer ID Payload length
Bit 32-x
Function Raw bytes
Command (1)/ Data (0) bit value is to indicate if the packet is a MAP command or data packet. Command packet is used for transport level flow control. Data packets are standard IP packets.
Next header is used to indicate the presence of another header, currently is limited to checksum header.
Padding is the number of bytes to be appended to the payload to ensure 4 byte alignment.
Multiplexer ID is to indicate the PDN on which data has to be sent.
Payload length includes the padding length but does not include MAP header length.
Checksum offload header v5
hecksum offload header fields are in big endian format.
Bit 0 - 6 7 8-15 16-31 Function Header Type Next Header Checksum Valid Reserved
Header Type is to indicate the type of header, this usually is set to CHECKSUM
Header types = ========================================== 0 Reserved 1 Reserved 2 checksum header
Checksum Valid is to indicate whether the header checksum is valid. Value of 1 implies that checksum is calculated on this packet and is valid, value of 0 indicates that the calculated packet checksum is invalid.
Reserved bits must be zero when sent and ignored when received
MAP packet v1/v5 (command specific)
Bit 0 1 2-7 8 - 15 16 - 31
Function Command Reserved Pad Multiplexer ID Payload length
Bit 32 - 39 40 - 45 46 - 47 48 - 63
Function Command name Reserved Command Type Reserved
Bit 64 - 95
Function Transaction ID
Bit 96 - 127
Function Command data
Command 1 indicates disabling flow while 2 is enabling flow
Command types
Aggregation
Aggregation is multiple MAP packets (can be data or command) delivered to rmnet in a single linear skb. rmnet will process the individual packets and either ACK the MAP command or deliver the IP packet to the network stack as needed.
聚合是在单个线性skb中传递到rmnet的多个MAP数据包(可以是数据或命令)。rmnet将处理单个数据包,并通过访问MAP命令或根据需要将IP数据包传递到网络堆栈。
MAP header|IP Packet|Optional padding|MAP header|IP Packet|Optional padding....
MAP header|IP Packet|Optional padding|MAP header|Command Packet|Optional pad...
用户面配置
rmnet用户空间配置是通过使用iproute2来做的。The driver uses rtnl_link_ops for communication.
MBIM
可以理解为专为移动网络准备的NDIS。
总结
- 其实总结起来就两种,一种是PPP类,一种是NDIS族类,NDIS族类的方式是标准化+高效化,对上,尽量标准化为网络设备,对下,则尽可能适应物理通道,高效利用。
- PPP类获取IP地址是通过ppp协议内部来完成的,而NDIS族类的拨号是通过DHCP来获取的。
- 其实模组拨号的动作都是通过向模组发送AT指令来触发的,我们所谓不同的拨号方式只是对以太网口的设置不同而已。