4G模块EC20在linux系统下的拨号上网
驱动实现:主要就是模块的 USB VID和PID,这个我是把模块插到开发板上,参考移远的手册
Quectel_WCDMA<E_Linux_USB_Driver_User_Guide_V1.7.pdf
1、在如下文件添加 File: [KERNEL]/drivers/usb/serial/option.c
static const struct usb_device_id option_ids[] = { #if 1 //Added by Quectel { USB_DEVICE(0x05C6, 0x9090) }, /* Quectel UC15 */ { USB_DEVICE(0x05C6, 0x9003) }, /* Quectel UC20 */ { USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC25/EC20 R2.0 */ { USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21 */ { USB_DEVICE(0x05C6, 0x9215) }, /* Quectel EC20 */ { USB_DEVICE(0x2C7C, 0x0191) }, /* Quectel EG91 */ { USB_DEVICE(0x2C7C, 0x0195) }, /* Quectel EG95 */ { USB_DEVICE(0x2C7C, 0x0306) }, /* Quectel EG06/EP06/EM06 */ { USB_DEVICE(0x2C7C, 0x0296) }, /* Quectel BG96 */ #endif
2、在[KERNEL]/drivers/usb/serial/qcserial.c 删除下面的代码
{USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */
3、在[KERNEL]/drivers/net/usb/qmi_wwan.c 删除下面的代码
{QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */
4、在File: [KERNEL]/drivers/usb/serial/usb_wwan.c 添加
static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint, int dir, void *ctx, char *buf, int len,void (*callback) (struct urb *)) { …… usb_fill_bulk_urb(urb, serial->dev, usb_sndbulkpipe(serial->dev, endpoint) | dir, buf, len, callback, ctx); #if 1 //Added by Quectel for Zero Packet if (dir == USB_DIR_OUT) { struct usb_device_descriptor *desc = &serial->dev->descriptor; if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9090)) urb->transfer_flags |= URB_ZERO_PACKET; if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9003)) urb->transfer_flags |= URB_ZERO_PACKET; if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9215)) urb->transfer_flags |= URB_ZERO_PACKET; if (desc->idVendor == cpu_to_le16(0x2C7C)) urb->transfer_flags |= URB_ZERO_PACKET; } #endif return urb; }
5、在File: [KERNEL]/drivers/usb/serial/option.c 添加
static struct usb_serial_driver option_1port_device = { …… #ifdef CONFIG_PM .suspend = usb_wwan_suspend, .resume = usb_wwan_resume, #if 1 //Added by Quectel .reset_resume = usb_wwan_resume, #endif #endif };
6、make menuconfig 配置:
USB相关:
[*] Device Drivers → [*] USB Support → [*] USB Serial Converter support → [*] USB driver for GSM and CDMA modems PPP相关:(和PPP相关的,我都选上了) [*] Device Drivers → [*] Network device support → [*] PPP (point-to-point protocol) support
7、保存退出,执行make
在arch/arm/boot目录下得到zImage文件,烧写到开发板
8.调试 插上模块,在/dev/目录下可以看到映射出来的虚拟串口,证明驱动已经起作用了
[ 24.065585] usb 1-1: new high-speed USB device number 2 using musb-hdrc [ 24.215673] usb 1-1: New USB device found, idVendor=2c7c, idProduct=0125 [ 24.227160] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 24.246001] usb 1-1: Product: Android [ 24.254111] usb 1-1: Manufacturer: Android [ 24.394500] usbcore: registered new interface driver usbserial [ 24.452664] usbcore: registered new interface driver usbserial_generic [ 24.474928] usbserial: USB Serial support registered for generic [ 24.589908] usbcore: registered new interface driver option [ 24.606913] usbserial: USB Serial support registered for GSM modem (1-port) [ 24.623323] option 1-1:1.0: GSM modem (1-port) converter detected [ 24.638503] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0 [ 24.654726] option 1-1:1.1: GSM modem (1-port) converter detected [ 24.671628] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1 [ 24.687754] option 1-1:1.2: GSM modem (1-port) converter detected [ 24.704506] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2 [ 24.720777] option 1-1:1.3: GSM modem (1-port) converter detected [ 24.739149] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB3
8、用at指令测试 ,用改串口工具比较好用
busybox microcom -t 5000 -s 9600 /dev/ttyUSB2
9、输入AT,返回OK,如下图
10、拨号上网脚本(unicom)
nodetach lock /dev/ttyUSB1 115200 user "card" password "card" crtscts usepeerdns noauth noipdefault novj novjccomp noccp defaultroute ipcp-accept-local ipcp-accept-remote connect \'chat -s -v -f /etc/ppp/peers/chat-unicom\' disconnect \'chat -s -v -f /etc/ppp/peers/chat-unicom-disconnect\'
11、拨号上网脚本chat(chat-unicom)
ABORT \'NO CARRIER\' ABORT \'NO DIALTONE\' ABORT \'ERROR\' ABORT \'NO ANSWER\' ABORT \'BUSY\' \'\' AT OK AT+CGDCONT=1,\"IP\",\"3gnet\" OK ATDT*99***1# CONNECT
12、断开连接(chat-unicom-disconnect)
ABORT OK ABORT BUSY ABORT DELAYED ABORT "NO ANSWER" ABORT "NO CARRIER" ABORT "NO DIALTONE" ABORT VOICE ABORT ERROR ABORT RINGING TIMEOUT 12 "" \K "" \K "" \K "" +++ATH "" +++ATH "" +++ATH "" ATZ SAY "\nGoodbay\n"
13、执行pppd call unicom & 后台运行拨号
pppd call unicom &
14、拨号成功,log
root@PICOAM3359:/etc/ppp/peers# [ 87.176124] PPP generic driver version 2.4.2 pppd options in effect: debug # (from /etc/ppp/peers/unicom) nodetach # (from /etc/ppp/peers/unicom) dump # (from /etc/ppp/peers/unicom) noauth # (from /etc/ppp/peers/unicom) refuse-chap # (from /etc/ppp/peers/unicom) refuse-mschap # (from /etc/ppp/peers/unicom) refuse-mschap-v2 # (from /etc/ppp/peers/unicom) user password # (from /etc/ppp/peers/unicom) remotename 3gppp # (from /etc/ppp/peers/unicom) /dev/ttyUSB3 # (from /etc/ppp/peers/unicom) 115200 # (from /etc/ppp/peers/unicom) lock # (from /etc/ppp/peers/unicom) connect chat -s -v -f /etc/ppp/peers/chat-unicom # (from /etc/ppp/peers/unicom) disconnect chat -s -v -f /etc/ppp/peers/chat-unicom-disconnect # (from /etc/ppp/peers/unicom) crtscts # (from /etc/ppp/peers/unicom) local # (from /etc/ppp/peers/unicom) hide-password # (from /etc/ppp/peers/unicom) novj # (from /etc/ppp/peers/unicom) novjccomp # (from /etc/ppp/peers/unicom) ipcp-accept-local # (from /etc/ppp/peers/unicom) ipcp-accept-remote # (from /etc/ppp/peers/unicom) ipparam 3gppp # (from /etc/ppp/peers/unicom) noipdefault # (from /etc/ppp/peers/unicom) defaultroute # (from /etc/ppp/peers/unicom) usepeerdns # (from /etc/ppp/peers/unicom) noccp # (from /etc/ppp/peers/unicom) abort on (BUSY) abort on (NO CARRIER) abort on (NO DIALTONE) abort on (ERROR) abort on (NO ANSWER) timeout set to 120 seconds send (AT^M) expect (OK) AT^M^M OK -- got it send (^MATZ^M) expect (OK) ^M ATZ^M^M OK -- got it send (^MAT+CGDCONT=1,"IP","ctnet",,0,0^M) expect (OK) ^M AT+CGDCONT=1,"IP","ctnet",,0,0^M^M OK -- got it send (ATDT#777^M) expect (CONNECT) ^M ATDT#777^M^M CONNECT -- got it send (\d) Script chat -s -v -f /etc/ppp/peers/chat-unicom finished (pid 747), status = 0x0 Serial connection established. using channel 1 Using interface ppp0 Connect: ppp0 <--> /dev/ttyUSB3 Warning - secret file /etc/ppp/pap-secrets has world and/or group access sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xd62c6e62> <pcomp> <accomp>] rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth pap> <magic 0x5d94eb2b> <pcomp> <accomp>] No auth is possible sent [LCP ConfRej id=0x0 <auth pap>] rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xd62c6e62> <pcomp> <accomp>] rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x5d94eb2b> <pcomp> <accomp>] sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x5d94eb2b> <pcomp> <accomp>] sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>] rcvd [LCP DiscReq id=0x2 magic=0x5d94eb2b] rcvd [IPCP ConfReq id=0x0] sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>] rcvd [IPCP ConfNak id=0x1 <addr 10.153.128.59> <ms-dns1 219.141.136.10> <ms-dns2 219.141.140.10>] sent [IPCP ConfReq id=0x2 <addr 10.153.128.59> <ms-dns1 219.141.136.10> <ms-dns2 219.141.140.10>] rcvd [IPCP ConfReq id=0x1] sent [IPCP ConfAck id=0x1] rcvd [IPCP ConfAck id=0x2 <addr 10.153.128.59> <ms-dns1 219.141.136.10> <ms-dns2 219.141.140.10>] Could not determine remote IP address: defaulting to 10.64.64.64 Failed to create /etc/ppp/resolv.conf: Read-only file system local IP address 10.153.128.59 remote IP address 10.64.64.64 primary DNS address 219.141.136.10 secondary DNS address 219.141.140.10 Script /etc/ppp/ip-up started (pid 755) Script /etc/ppp/ip-up finished (pid 755), status = 0x0
15、拨号成功会出现一个ppp0的网卡
16、ping外网
注意:如果你换成其他营运商,需要改apn和拨号,不然连不上网
APN设置
移动: at+cgdcont=1,"ip","cmnet"
联通: at+cgdcont=1,"ip","3gnet"
电信: at+cgdcont=1,"ip","ctnet"
拨号:
移动: *99***1#或*98*1#
联通: *99#
电信: #777
二、模块信息参数获取
AT/r //检测串口通信状态
ATE设置回显功能
ATE0:回显关闭
ATE1:回显开启
AT+CGMI 返回模块厂家信息
AT+CGMM 返回模块型号信息
AT+CGMR 返回固件版本信息
AT+CGSN 查看产品IMEI序列号
AT+CSCS 选择TE特性设置
AT+CIMI IMSI认证请求,返回SIM卡的IMSI
AT+CCLK 设置或查看当前日期和时间
AT+ccid/r // 查询SIM卡的 ICCID (检测是否装有SIM 卡)
AT+cgmr/r //检测软件版本,5.0 以上的才有GPRS?功能支持
AT+CREG? 查询网络注册情况
其中第二个参数为1或5则说明已经注册成功。
如果不是,卡没有插好,或者模块有问题,大多可能是卡有问题,换张卡。
AT+csq/r //检测信号质量,确定是否可以登陆上网络;若返回10--31,0之间的信号数字则继续,
如果信号是99,99,则应该考虑不停的的让模块去搜寻网络。