4G模块 EC20 R2.0 USB Serial/GobiNet/QMI WWAN 驱动移植过程
一、开发环境
硬件平台 :Jetson-TX2
4G模块 :移远EC20 R2.0
系统版本 :Ubuntu 18.04.4 LTS (GNU/Linux 4.9.140-tegra aarch64)
kernel :4.9.140-tegra
编译环境 :aarch64-linux-gnu
二、确定 EC20 R2.0 的基本信息
- 插上4G模块,获得 VID 和 PID
[ 11.877412] usb 1-2.4: new high-speed USB device number 4 using tegra-xusb
[ 11.909529] usb 1-2.4: New USB device found, idVendor=2c7c, idProduct=0125
[ 11.909535] usb 1-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 11.909538] usb 1-2.4: Product: Android
[ 11.909541] usb 1-2.4: Manufacturer: Android
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 2c7c:0125
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 003: ID 03f0:1f4a Hewlett-Packard
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
第二行可以看出:Vid = 2c7c, Pid = 0125
- 查看手册确定,可以支持的驱动类型
《Quectel_WCDMA<E_Linux_USB_Driver_User_Guide_V1.6.pdf》
- usb-devices,查看EC20 usb接口信息
T: Bus=01 Lev=02 Prnt=02 Port=03 Cnt=01 Dev#= 4 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1
P: Vendor=2c7c ProdID=0125 Rev=03.18
S: Manufacturer=Android
S: Product=Android
C: #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
I: If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
I: If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
I: If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
I: If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
可以看到EC20出现了5个usb接口,接口0-3需要适配 usb serial 驱动,通过 ttyUSB2 节点使用PPP拨号上网;接口4 需要适配 GobiNet or QMI WWAN 驱动,使用quectel-CM 应用上网。
三、USB Serial 驱动移植
usb串口驱动有两种适配方式,修改([KERNEL]/drivers/usb/serial/)option.c或 qcserial.c 文件。
option.c:USB Driver for GSM modems
qcserial.c:Qualcomm Serial USB driver
option 驱动
- TX2 板子使用的 kernel 已经支持 option.c 文件产生的 USB Serial Driver;
- 对于不支持的 kernel ,按照如下方式修改。
修改 [KERNEL]/drivers/usb/serial/option.c 支持EC20 R2.0
(1)添加 VID 和 PID
static const struct usb_device_id option_ids[] = {
USB_DEVICE(0x2C7C, 0x0125), /* Quectel EC25/EC20 R2.0 */
(2)下面2个文件,需要删除 usb_device_id 数组中 VID 和 PID 的元素, 内核没有编译该文件或不加载 qcserial.ko / qmi_wwan.ko 的话,可以不用修改。
[KERNEL]/drivers/usb/serial/qcserial.c
[KERNEL]/drivers/net/usb/qmi_wwan.c
qmi_wwan.c 驱动和 option.c 驱动使用不同的usb接口,应该是不冲突的,但是参考手册说因为冲突需要删除。
(3)Add the Zero Packet Mechanism
(4)Add Reset Resume (掉电恢复)
备注:
(3) (4) 两项 TX2 kernel 源码中没有修改,应该对于4G上网功能影响不大,算是辅助功能,这里没有深入分析。
- 测试
(1)加载 option.ko并插上4G模块,dmesg信息如下
[ 11.959321] usbcore: registered new interface driver option
[ 11.959363] usbserial: USB Serial support registered for GSM modem (1-port)
[ 11.959476] option 1-2.4:1.0: GSM modem (1-port) converter detected
[ 11.961727] usb 1-2.4: GSM modem (1-port) converter now attached to ttyUSB0
[ 11.961823] option 1-2.4:1.1: GSM modem (1-port) converter detected
[ 11.962035] usb 1-2.4: GSM modem (1-port) converter now attached to ttyUSB1
[ 11.962152] option 1-2.4:1.2: GSM modem (1-port) converter detected
[ 11.964814] usb 1-2.4: GSM modem (1-port) converter now attached to ttyUSB2
[ 11.964905] option 1-2.4:1.3: GSM modem (1-port) converter detected
[ 11.965171] usb 1-2.4: GSM modem (1-port) converter now attached to ttyUSB3
(2)AT命令测试
$ sudo busybox microcom -t 10000 -s 115200 /dev/ttyUSB3
OK
AT+QNWINFO
+QNWINFO: "FDD LTE","46000","LTE BAND 3",1300
OK
$ sudo busybox microcom -t 10000 -s 115200 /dev/ttyUSB2
AT+QNWINFO
+QNWINFO: "FDD LTE","46000","LTE BAND 3",1300
OK
使用ttyUSB3和ttyUSB2接口测试AT都正常
(3)使用PPP拨号,上网正常
TX2开发板使用的 Ubuntu 18.04 系统,其中网络管理中有 PPP 拨号功能,可以直接拨号;如没有,需在 kernel 中添加 PPP 支持并编译 ppp 源码。
PPP拨号后,ifconfig 命令可以看到,生成了ppp0网卡。
$ ifconfig
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.192.118.96 netmask 255.255.255.255 destination 0.0.0.0
ppp txqueuelen 3 (Point-to-Point Protocol)
RX packets 11 bytes 126 (126.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 435 (435.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
使用 ps aux 命令,可以看到拨号的pppd进程,使用的是 ttyUSB2 接口拨号上网。
$ ps aux
root 11488 0.2 0.0 160096 6564 ? Sl 17:17 0:00 /usr/sbin/pppd nodetach lock nodefaultroute ipv6 , user guest ttyUSB2 noipdefault noauth usepeerdns lcp-echo-failure 0 lcp-echo-interval 0 idle 0 ipparam /org/freedesktop/NetworkManager/PPP/2 plugin /usr/lib/pppd/2.4.7/nm-pppd-plugin.so
$ ping www.qq.com -I ppp0
PING https.qq.com (125.39.52.26) from 10.192.118.96 ppp0: 56(84) bytes of data.
64 bytes from no-data (125.39.52.26): icmp_seq=1 ttl=49 time=313 ms
64 bytes from no-data (125.39.52.26): icmp_seq=2 ttl=49 time=95.3 ms
64 bytes from no-data (125.39.52.26): icmp_seq=3 ttl=49 time=52.6 ms
64 bytes from no-data (125.39.52.26): icmp_seq=4 ttl=49 time=63.8 ms
64 bytes from no-data (125.39.52.26): icmp_seq=5 ttl=49 time=69.0 ms
64 bytes from no-data (125.39.52.26): icmp_seq=6 ttl=49 time=85.8 ms
^C
--- https.qq.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 52.647/113.319/313.091/90.433 ms
qcserial 驱动
- 驱动适配
修改 [KERNEL]/drivers/usb/serial/qcserial.c 支持EC20 R2.0
(1) 直接加载 qcserial.ko,若出现问题,请添加如下补丁
[ 11.723033] usbcore: registered new interface driver qcserial
[ 11.723083] usbserial: USB Serial support registered for Qualcomm USB modem
[ 11.723132] usb 1-2.4: unknown number of interfaces: 5
qcserial.c 补丁文件
It seems like this device has same vendor and product IDs as G2K
devices, but it has different number of interfaces(4 vs 5) and also
different interface layout which makes it currently unusable:
usbcore: registered new interface driver qcserial
usbserial: USB Serial support registered for Qualcomm USB modem
usb 2-1.2: unknown number of interfaces: 5
lsusb output:
Bus 002 Device 003: ID 05c6:9215 Qualcomm, Inc. Acer Gobi 2000 Wireless
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x05c6 Qualcomm, Inc.
idProduct 0x9215 Acer Gobi 2000 Wireless Modem
bcdDevice 2.32
iManufacturer 1 Quectel
iProduct 2 Quectel LTE Module
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 209
bNumInterfaces 5
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 500mA
Signed-off-by: Petr Štetiar <ynezz@xxxxxxx>
---
drivers/usb/serial/qcserial.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index ebcec8c..d462132 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -22,6 +22,8 @@
#define DRIVER_AUTHOR "Qualcomm Inc"
#define DRIVER_DESC "Qualcomm USB Serial driver"
+#define QUECTEL_EC20_IDPRODUCT 0x9215
+
/* standard device layouts supported by this driver */
enum qcserial_layouts {
QCSERIAL_G2K = 0, /* Gobi 2000 */
@@ -167,6 +169,38 @@ static const struct usb_device_id id_table[] = {
};
MODULE_DEVICE_TABLE(usb, id_table);
+static int handle_quectel_ec20(struct device *dev, int ifnum)
+{
+ int altsetting = 0;
+
+ /*
+ * Quectel EC20 Mini PCIe LTE module layout:
+ * 0: DM/DIAG (use libqcdm from ModemManager for communication)
+ * 1: NMEA
+ * 2: AT-capable modem port
+ * 3: Modem interface
+ * 4: NDIS
+ */
+ switch (ifnum) {
+ case 0:
+ dev_dbg(dev, "Quectel EC20 DM/DIAG interface found\n");
+ break;
+ case 1:
+ dev_dbg(dev, "Quectel EC20 NMEA GPS interface found\n");
+ break;
+ case 2:
+ case 3:
+ dev_dbg(dev, "Quectel EC20 Modem port found\n");
+ break;
+ case 4:
+ /* Don't claim the QMI/net interface */
+ altsetting = -1;
+ break;
+ }
+
+ return altsetting;
+}
+
static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
{
struct usb_host_interface *intf = serial->interface->cur_altsetting;
@@ -235,6 +269,11 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
altsetting = -1;
break;
case QCSERIAL_G2K:
+ if (nintf == 5 && id->idProduct == QUECTEL_EC20_IDPRODUCT) {
+ altsetting = handle_quectel_ec20(dev, ifnum);
+ goto done;
+ }
+
/*
* Gobi 2K+ USB layout:
* 0: QMI/net
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
(2) 添加 VID 和 PID
static const struct usb_device_id id_table[] = {
{USB_DEVICE(0x2C7C, 0x0125)}, /* Quectel EC25/EC20 R2.0 */
(3) EC20 R2.0 特殊处理
在 qcserial.c 补丁中针对 Gobi 2000 中 EC20进行了特殊处理。
补丁中使用的EC20 PID 是 0x9215, 临时将其修改为EC20 R2.0 PID 0x0125进行测试;正式版本请对 0x0125 PID 适配,请自行修改。
#define QUECTEL_EC20_IDPRODUCT 0x9215
修改为:
#define QUECTEL_EC20_IDPRODUCT 0x0125
(4)下面1个文件,需要删除 usb_device_id 数组中 VID 和 PID 的元素, 若内核没有编译该文件或不加载 option.ko 的话,可以不用修改。
File: [KERNEL]/drivers/usb/serial/option.c
static const struct usb_device_id option_ids[] = {
USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC25), /* 0x2C7C, 0x0125 */
- 上网测试
(1)加载 qcserial.ko并插上4G模块,dmesg信息如下
[ 11.987527] usbcore: registered new interface driver qcserial
[ 11.987573] usbserial: USB Serial support registered for Qualcomm USB modem
[ 11.993842] qcserial 1-2.4:1.0: Qualcomm USB modem converter detected
[ 11.994090] usb 1-2.4: Qualcomm USB modem converter now attached to ttyUSB0
[ 12.002639] qcserial 1-2.4:1.1: Qualcomm USB modem converter detected
[ 12.002902] usb 1-2.4: Qualcomm USB modem converter now attached to ttyUSB1
[ 12.011237] qcserial 1-2.4:1.2: Qualcomm USB modem converter detected
[ 12.011480] usb 1-2.4: Qualcomm USB modem converter now attached to ttyUSB2
[ 12.012202] qcserial 1-2.4:1.3: Qualcomm USB modem converter detected
[ 12.012441] usb 1-2.4: Qualcomm USB modem converter now attached to ttyUSB3
(2)AT命令测试
$ sudo busybox microcom -t 10000 -s 115200 /dev/ttyUSB3
OK
AT+QNWINFO
+QNWINFO: "FDD LTE","46000","LTE BAND 3",1300
OK
(3)使用PPP拨号,上网正常
TX2开发板使用的 Ubuntu 18.04 系统,其中网络管理中有 PPP 拨号功能,可以直接拨号;如没有,需在 kernel 中添加 PPP 支持并编译 ppp 源码。
$ ifconfig
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.46.1.65 netmask 255.255.255.255 destination 0.0.0.0
ppp txqueuelen 3 (Point-to-Point Protocol)
RX packets 27 bytes 1705 (1.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 2658 (2.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
$ ping www.qq.com -I ppp0
PING https.qq.com (125.39.52.26) from 10.46.1.65 ppp0: 56(84) bytes of data.
64 bytes from no-data (125.39.52.26): icmp_seq=1 ttl=49 time=166 ms
64 bytes from no-data (125.39.52.26): icmp_seq=2 ttl=49 time=102 ms
64 bytes from no-data (125.39.52.26): icmp_seq=3 ttl=49 time=75.0 ms
64 bytes from no-data (125.39.52.26): icmp_seq=4 ttl=49 time=79.0 ms
64 bytes from no-data (125.39.52.26): icmp_seq=5 ttl=49 time=104 ms
64 bytes from no-data (125.39.52.26): icmp_seq=6 ttl=49 time=78.0 ms
^C
--- https.qq.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5001ms
rtt min/avg/max/mdev = 75.021/100.917/166.559/31.615 ms
四、GobiNet 驱动移植
- 驱动适配
(1)将 GobiNet 源码拷贝到 [KERNEL]/drivers/net/usb 目录
(2)修改该目录下的 makefile 文件,添加如下代码
obj-$(CONFIG_USB_GOBI_NET) += GobiNet.o
GobiNet-y := GobiUSBNet.o QMIDevice.o QMI.o
(3)修改该目录下的Kconfig文件,添加如下代码
config USB_GOBI_NET
tristate "Gobi USB Net driver for Quectel moudule"
help
Support Quectel moudule
(4)编译 kernel 或 GobiNet.ko
找到 USB_GOBI_NET 配置, 将他编入内核(y)或编成模块(m)
$ make ARCH=arm64 menuconfig
│Symbol: USB_GOBI_NET [=y] │
│ Type : tristate │
│ Prompt: Gobi USB Net driver for Quectel moudule │
│ Location: │
│ -> Device Drivers │
│ -> Network device support (NETDEVICES [=y]) │
│ (1) -> USB Network Adapters (USB_NET_DRIVERS [=y]) │
│ Defined at drivers/net/usb/Kconfig:610 │
│ Depends on: NETDEVICES [=y] && USB_NET_DRIVERS [=y] │
- 上网测试
(1)加载 GobiNet.ko 并插上4G模块,dmesg信息如下
[ 5166.598656] usb 1-2.4: new high-speed USB device number 4 using tegra-xusb
[ 5166.631145] usb 1-2.4: New USB device found, idVendor=2c7c, idProduct=0125
[ 5166.631198] usb 1-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 5166.631513] usb 1-2.4: Product: Android
[ 5166.631530] usb 1-2.4: Manufacturer: Android
[ 5166.643823] GobiNet 1-2.4:1.4 eth1: register 'GobiNet' at usb-3530000.xhci-2.4, GobiNet Ethernet Device, 12:65:51:00:62:cd
[ 5166.648392] creating qcqmi1
[ 5166.728113] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
[ 5166.729237] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
使用 ifconfig 命令可看到出现了 eth1 网卡,但是没有设置ip地址。
$ ifconfig
eth1: flags=4227<UP,BROADCAST,NOARP,MULTICAST> mtu 1500
ether 12:65:51:00:62:cd txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(2)使用 quectel-CM 应用上网
$ sudo ./quectel-CM -s ctnet&
[09-21_13:45:36:250] Quectel_Linux_ConnectManager_SR01A01V23
[09-21_13:45:36:251] ./quectel-CM profile[1] = ctnet///0, pincode = (null)
[09-21_13:45:36:252] Find qmichannel = /dev/qcqmi1
[09-21_13:45:36:252] Find usbnet_adapter = eth1
[09-21_13:45:36:306] Get clientWDS = 7
[09-21_13:45:36:338] Get clientDMS = 8
[09-21_13:45:36:370] Get clientNAS = 9
[09-21_13:45:36:402] Get clientUIM = 10
[09-21_13:45:36:435] Get clientWDA = 11
[09-21_13:45:36:467] requestBaseBandVersion EC20CEHCLGR06A03M1G
[09-21_13:45:36:530] requestGetSIMStatus SIMStatus: SIM_READY --- 检测到SIM卡
[09-21_13:45:36:531] requestSetProfile[1] ctnet///0
[09-21_13:45:36:595] requestGetProfile[1] ctnet///0
[09-21_13:45:36:627] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[09-21_13:45:36:659] requestQueryDataCall ConnectionStatus: DISCONNECTED
[09-21_13:45:36:724] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[09-21_13:45:36:756] requestSetupDataCall WdsConnectionIPv4Handle: 0x08d21410
[09-21_13:45:36:851] requestQueryDataCall ConnectionStatus: CONNECTED
[09-21_13:45:36:902] Fail to access /usr/share/udhcpc/default.script, errno: 2 (No such file or directory) // 使用的是 /etc/udhcpc/default.script 目录下的脚本
udhcpc: started, v1.27.2
[09-21_13:45:36:927] Setting IP address 0.0.0.0 on eth1
udhcpc: sending discover
udhcpc: sending select for 10.39.110.92
udhcpc: lease of 10.39.110.92 obtained, lease time 7200 // 获取到了ip地址
[09-21_13:45:37:110] Setting IP address 10.39.110.92 on eth1
+: Unknown host
[09-21_13:45:37:117] Deleting routers // 调用default.script脚本设置ip、路由和DNS
SIOCDELRT: No such process
[09-21_13:45:37:124] Adding router 10.39.110.93
[09-21_13:45:37:127] Recreating /etc/resolv.conf
[09-21_13:45:37:132] Adding DNS server 211.137.130.2
[09-21_13:45:37:132] Adding DNS server 211.137.130.18
[09-21_13:45:40:723] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
如出现问题请参考:
linux 4G模块(EC20 R2.0)调试记录
(3)测试联网
ping www.qq.com -I eth1
PING https.qq.com (112.53.26.232) from 10.39.110.92 eth1: 56(84) bytes of data.
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=1 ttl=53 time=82.2 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=2 ttl=53 time=59.4 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=3 ttl=53 time=68.9 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=4 ttl=53 time=77.1 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=5 ttl=53 time=84.3 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=6 ttl=53 time=67.3 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=7 ttl=53 time=81.3 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=8 ttl=53 time=76.5 ms
^C
--- https.qq.com ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7012ms
rtt min/avg/max/mdev = 59.469/74.675/84.377/8.086 ms
注意:
看到网上的帖子和手册,需要同时适配 USB Serial Driver 和 GobiNet Driver。屏蔽 USB Serial Driver 驱动,只保留 GobiNet Driver 也上网正常。但是我们需要获取4G网卡的网络状态等,可以通过 USB Serial 使用 AT 命令获取网络状态。能否使用 GobiNet 获取网络状态,我也不清楚。如果可以的话,只使用GobiNet Driver就可以了。
五、QMI WWAN 驱动移植
- TX2 板子使用的 kernel 已经支持 qmi_wwan.c 文件产生的 QMI WWAN Driver;
- 对于不支持的 kernel ,按照如下方式修改。
修改 [KERNEL]/drivers//drivers/net/usb/qmi_wwan.c 支持EC20 R2.0
(1)添加 VID 和 PID
static const struct usb_device_id products[] = {
#if 1 //Added by Quectel
#ifndef QMI_FIXED_INTF
/* map QMI/wwan function by a fixed interface number */
#define QMI_FIXED_INTF(vend, prod, num) \
.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
USB_DEVICE_ID_MATCH_INT_INFO, \
.idVendor = vend, \
.idProduct = prod, \
.bInterfaceClass = 0xff, \
.bInterfaceSubClass = 0xff, \
.bInterfaceProtocol = 0xff, \
.driver_info = (unsigned long)&qmi_wwan_force_int##num,
#endif
{ QMI_FIXED_INTF(0x2C7C, 0x0125, 4) }, /* Quectel EC25/EC20 R2.0 */
#endif
(2)Add Support for Raw IP Mode for EC21/EC25/EC20 R2.0
需要添加的代码过长,请参考文档。
(3)将该文件编入内核或编译成模块
Enable CONFIG_USB_NET_QMI_WWAN
[*] Device Drivers →
-*- Network device support →
USB Network Adapters →
{*} Multi-purpose USB Networking Framework
<*> QMI WWAN driver for Qualcomm MSM based 3G and LTE modems
注意:
qmi_wwan.ko 依赖 cdc-wdm.ko,需要将 cdc-wdm.c 编入内核或编译成模块
- 上网测试
(1)加载 qmi_wwan.ko 并插上4G模块,dmesg信息如下
[ 11.877289] usb 1-2.4: new high-speed USB device number 4 using tegra-xusb
[ 11.909334] usb 1-2.4: New USB device found, idVendor=2c7c, idProduct=0125
[ 11.909339] usb 1-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 11.909342] usb 1-2.4: Product: Android
[ 11.909344] usb 1-2.4: Manufacturer: Android
[ 227.572656] qmi_wwan 1-2.4:1.4: cdc-wdm0: USB WDM device
[ 227.574819] qmi_wwan 1-2.4:1.4 wwan0: register 'qmi_wwan' at usb-3530000.xhci-2.4, WWAN/QMI device, fa:fb:f9:d2:f3:ed
[ 227.574917] usbcore: registered new interface driver qmi_wwan
(2)查看文件节点
/sys/class/net$ ls
dummy0 eth0 l4tbr0 lo rndis0 usb0 wlan0 wwan0
$ls /dev/cdc-wdm0
/dev/cdc-wdm0
wwan0 是网卡文件,现在使用ifconfig,看不到这个网卡。
cdc-wdm0 是驱动的设备节点。
(3)使用 quectel-CM 应用上网
sudo ./quectel-CM -s ctnet&
[09-22_14:31:14:170] Quectel_Linux_ConnectManager_SR01A01V23
[09-22_14:31:14:170] ./quectel-CM profile[1] = ctnet///0, pincode = (null)
[09-22_14:31:14:172] Find qmichannel = /dev/cdc-wdm0
[09-22_14:31:14:172] Find usbnet_adapter = wwan0
[09-22_14:31:14:194] /proc/7368/fd/7 -> /dev/cdc-wdm0
[09-22_14:31:14:194] /proc/7368/exe -> /usr/lib/libqmi/qmi-proxy
[09-22_14:31:16:207] cdc_wdm_fd = 7
[09-22_14:31:16:292] Get clientWDS = 18
[09-22_14:31:16:324] Get clientDMS = 2
[09-22_14:31:16:356] Get clientNAS = 3
[09-22_14:31:16:388] Get clientUIM = 1
[09-22_14:31:16:420] Get clientWDA = 1
[09-22_14:31:16:452] requestBaseBandVersion EC20CEHCLGR06A03M1G
[09-22_14:31:16:516] requestGetSIMStatus SIMStatus: SIM_READY
[09-22_14:31:16:517] requestSetProfile[1] ctnet///0
[09-22_14:31:16:580] requestGetProfile[1] ctnet///0
[09-22_14:31:16:612] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[09-22_14:31:16:644] requestQueryDataCall ConnectionStatus: DISCONNECTED
[09-22_14:31:16:708] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[09-22_14:31:16:740] requestSetupDataCall WdsConnectionIPv4Handle: 0xe17c8590
[09-22_14:31:16:804] requestQueryDataCall ConnectionStatus: CONNECTED
[09-22_14:31:16:850] Fail to access /usr/share/udhcpc/default.script, errno: 2 (No such file or directory)
udhcpc: started, v1.27.2
[09-22_14:31:16:869] Setting IP address 0.0.0.0 on wwan0
udhcpc: sending discover
udhcpc: sending select for 10.112.217.14
udhcpc: lease of 10.112.217.14 obtained, lease time 7200
[09-22_14:31:16:989] Setting IP address 10.112.217.14 on wwan0
[09-22_14:31:17:002] Deleting routers
SIOCDELRT: No such process
[09-22_14:31:17:006] Adding router 10.112.217.13
[09-22_14:31:17:010] Recreating /etc/resolv.conf
[09-22_14:31:17:017] Adding DNS server 211.137.130.18
[09-22_14:31:17:017] Adding DNS server 211.137.130.2
(3)测试联网
此时使用 ifconfig 命令,就可以看见 wwan0 网卡,并设置好了IP
wwan0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.112.217.14 netmask 255.255.255.252 destination 10.112.217.14
inet6 fe80::65af:a0e9:a8ae:4a3d prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 76 bytes 8826 (8.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 88 bytes 6624 (6.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
$ ping www.qq.com -I wwan0
PING https.qq.com (112.53.26.232) from 10.228.222.241 wwan0: 56(84) bytes of data.
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=1 ttl=53 time=72.4 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=2 ttl=53 time=90.7 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=3 ttl=53 time=72.1 ms
64 bytes from 112.53.26.232 (112.53.26.232): icmp_seq=4 ttl=53 time=125 ms
^C
--- https.qq.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 72.179/90.169/125.290/21.639 ms