1.硬件平台使用的是QCA4019,软件使用QSDK:IPQ40xx/AP-DK04.1-C1,Linux version 3.14.43,OpenWrt Chaos Calmer 15.05.1 r35193。
2.4G模块使用的是华为ME909s-821(miniPCI即USB接口),vendorID:productID=12d1:15c1。
3.首先了解4G拨号有多种方式:1)ndis拨号,2)gobinet拨号,3)ppp拨号等,具体方式方法见其他网络描述。
4.代码移植编译:
根据openWRT官方描述的https://oldwiki.archive.openwrt.org/doc/howtobuild/wireless-router-with-a-3g-dongle;添加编译选项。
注意可能需要在、driver/usb/serial/option.c中增加自己的VID:PID,大致如下:(可以参考源码)
struct usb_device_id option_ids[] = {
{ USB_DEVICE(LONGCHEER_VENDOR_ID, PRODUCT_U9300C_ID),
5.openWRT对驱动加载调试:
1)将编译好的image打包成web升级包:(并完成软件升级)
cp -rf bin/ipq806x/openwrt* ../src/IPQ4019.ILQ.1.2/common/build/ipq
cd ../src/IPQ4019.ILQ.1.2/common/build
python update_common_info_standard.py
2)查看配置编译好的模块选项是否成功运行:lsmod(如下驱动模块)
usb_common 1488 2 dwc3
usb_serial_simple 3336 0
usb_storage 36368 0
usb_wwan 6382 3 qcserial
usbcore 141401 52 qcserial
usbnet 20549 15 cdc_mbim
usbserial 23676 20 qcserial
3)lsusb,picocom等工具软件是否已经存在,可以查看;
4)插入4G模块,或已经内嵌的,查看相关节点接口是否生成。
# lsusb
Bus 003 Device 002: ID 12d1:15c1 (成功找到相关模块)
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0003
Bus 003 Device 001: ID 1d6b:0002
Bus 004 Device 001: ID 1d6b:0003
#ls /dev/ (成功生成ttyUSB*设备节点)
ttyUSB0
ttyUSB1
ttyUSB2
ttyUSB3
ttyUSB4
#ifconfig -a 查看成功生成usb0接口
usb0 Link encap:Ethernet HWaddr 02:1E:10:1F:00:00
UP BROADCAST ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:298 (298.0 B)
5)查看dmesg 内核打印信息,可以看到usb相关的识别信息。
[ 18.829236] usbcore: registered new interface driver cdc_acm
[ 18.833971] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[ 18.843310] usbcore: registered new interface driver cdc_eem
[ 18.853178] cdc_ether 3-1:2.0 usb0: register 'cdc_ether' at usb-xhci-hcd.1.auto-1, CDC Ethernet Device, 02:1e:10:1f:00:00
usb0对应的MAC地址,和ifconfig看到的网络接口一致。
[ 19.593610] usbcore: registered new interface driver ipw
[ 19.598004] usbserial: USB Serial support registered for IPWireless converter
[ 19.608745] usbcore: registered new interface driver option
[ 19.613459] usbserial: USB Serial support registered for GSM modem (1-port)
[ 19.620763] option 3-1:2.2: GSM modem (1-port) converter detected
[ 19.626769] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB0
[ 19.633371] option 3-1:2.3: GSM modem (1-port) converter detected
[ 19.639727] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB1
[ 19.646227] option 3-1:2.4: GSM modem (1-port) converter detected
[ 19.652635] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB2
[ 19.659038] option 3-1:2.5: GSM modem (1-port) converter detected
[ 19.665325] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB3
[ 19.671878] option 3-1:2.6: GSM modem (1-port) converter detected
[ 19.678217] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB4
[ 19.686138] usbcore: registered new interface driver qcserial
[ 19.691042] usbserial: USB Serial support registered for Qualcomm USB modem
这里与ttyUSB*相关的设备节点。
到这里,基本的驱动移植已经完成,由于openWRT已经集成了华为4G模块的驱动,这里仅配置即可。如对应一个全新的4G模块,可能需要自己移植驱动,具体就是模块化加载Linux驱动的方式;openWRT下已经有框架可用参考,更加方便(后续总结)。
6.4G模块调试
1)插入一个正常的4G卡(移动、电信);
2)使用picocom与4G模块通信调试:
#picocom /dev/ttyUSB2 (这里的ttyUSB*,不一定就是2,可以自己根据自己的平台情况进行调试)
2)picocom /dev/ttyUSB2,其实就是相当于PC的串口连接到主板进行调试,具体用AT命令集来查看基本的4G模块状态信息。(以下红色的为输入,黑色为输出信息)
ATI
Manufacturer: Huawei Technologies Co., Ltd. (华为的模块)
Model: ME909s-821 (华为的模块型号)
Revision: 11.617.04.00.00 (模块的版本号)
IMEI: 867223028549145 (模块的IMEI值)
+GCAP: +CGSM,+DS,+ES (传输能力域)
OK (证明模块能正常访问)
AT^ICCID (读取SIM卡信息)
AT+CSQ (查看信号质量)
+CSQ: 26,99
OK
AT+COPS=? (查询 ME 网络注册的当前状态)
+COPS: (3,"CHN-UNICOM","UNICOM","46001",2),(3,"CHN-UNICOM","UNICOM","46001",0),(3,"CHINA MOBILE","CMCC","46000",0),,(0,1,3),(0,1,2)
OK
//插入移动卡的信息
+COPS: (2,"CHINA MOBILE","CMCC","46000",0),,(0,1,3),(0,1,2)
OK
AT+CREG? (查询当前网络注册状况)
+CREG: 0,2
OK
AT+CREG=? (查询参数
+CREG: (0-2)
OK
7.配置PPP拨号
1)在/etc/config/network中增加以下接口配置:
config interface 'ppp0'
option proto '3g'
option apn 'ctnet'
option dialnumber '*99#'
option device '/dev/ttyUSB0'
option service 'umts'
option username '[email protected]'
option password 'zpqxwlan3g'
2)在/etc/chatscripts/3g.chat中以下配置支持
ABORT BUSY
ABORT 'NO CARRIER'
ABORT ERROR
REPORT CONNECT
TIMEOUT 10
"" "AT&F"
OK "ATE1"
OK 'AT+CGDCONT=1,"IP","$USE_APN"'
SAY "Calling UMTS/GPRS"
TIMEOUT 30
OK "ATD$DIALNUMBER"
CONNECT ' '
3)在/etc/chatscripts/evdo.chat中以下配置支持电信3G拨号
ABORT BUSY
ABORT 'NO CARRIER'
ABORT ERROR
ABORT 'NO DIAL TONE'
ABORT 'NO ANSWER'
ABORT DELAYED
REPORT CONNECT
TIMEOUT 10
'' AT
OK ATZ
SAY 'Calling CDMA/EVDO'
TIMEOUT 30
OK ATDT#777
CONNECT ''
4)3g.sh,ppp.sh在/lib/netifd/proto下的脚本文件中
注:这里对于华为的4G模块(ME909s-821)在电信模式下拨号修改支持
if echo "$cardinfo" | grep -qi ME909s; then
export MODE="AT^SYSCFGEX=\"00\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,,"
else
export MODE="AT^SYSCFG=${CODE},3FFFFFFF,2,4"
fi
5)可以使用logread -f来读取ppp过程的错误信息。
6)如果拨号成功,将在ifconfig下创建一个3g-ppp0的网络接口,并获取到一个拨号成功的IP地址,可以直接ping通百度。
8.WiFi关联上网配置:
在openWRT下,直接在LAN中配置桥接,将ppp0,eth0,eth1,wifi均加入到一个桥上即可完成上网功能配置。
需要在ppp0接口下的防火墙页面配置中配置成WAN接口。