驅動實現:主要就是模塊的 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,則應該考慮不停的的讓模塊去搜尋網絡。
