一、 PPP移植
各项工作具体说明
向linux内核添加3G模块的驱动(USB转串口驱动)和PPP协议的支持,然后编译内核并下载到开发板。当然如果之前已经移植好内核,那么只需要增加几个选项就可以,然后在编译内核就可以了,这个文档默认内核已经移植过,所以只讲与USB转串口驱动和PPP协议支持的几个选项。
[lingyun@localhost linux-3.0]$ make menuconfig1、USB的驱动要选这几个:
DeviceDrivers---→
USBsupport---→
<*>USB SerialConverter support--→
[*]USBGeneric Serial Driver
<*>USBdriver for GSM and CDMA modems
2、到此3G模块驱动添加完成,下面进行ppp协议支持的添加(下面所示的几个选项必选):
DeviceDrivers--→
Network devicesupport---→
<*> PPP (point-to-point protocol) support
[*] PPP multilink support (EXPERIMENTAL)
<*> PPP support for async serial ports
<*> PPP support for sync tty ports
<*> PPP Deflate compression
<*> PPP BSD-Compress compression
完成了这些步骤以后就可以退出make menuconfig进行make编译内核了。然后再把生成的镜像文件下载到板子上重启开发板即可。然后就会发现在/dev/目录下生成ppp设备节点:~ >: ls -l dev/ppp
crw-rw---- 1 root root 108, 0 Mar 27 17:35 dev/ppp
ppp协议介绍
/***********************转载声明*********************************/
二、 usb_modeswitch移植
下载usbmode库:
[lingyun@localhost fulinux]$ mkdir usbmode
[lingyun@localhost fulinux]$ cd usbmode/
[lingyun@localhost usbmode]$ wget http://pkgs.fedoraproject.org/repo/pkgs/libusb1/libusb-1.0.0.tar.bz2/df2447c23750ef2b4a314200feacc2ee/libusb-1.0.0.tar.bz2
[lingyun@localhost usbmode]$ wget http://jaist.dl.sourceforge.net/project/libusb/libusb-compat-0.1/libusb-compat-0.1.5/libusb-compat-0.1.5.tar.bz2
[lingyun@localhost usbmode]$wget http://pkgs.fedoraproject.org/repo/pkgs/usb_modeswitch/usb-modeswitch-1.2.4.tar.bz2/dbd4ce7966d7b4a5a0604a8280f7164d/usb-modeswitch-1.2.4.tar.bz2
[lingyun@localhost usbmode]$ wget http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-data-20130607.tar.bz2
以上这些下载地址如果有失效的,搜索相应的文件下载,即可下载。
解压:
[lingyun@localhost usbmode]$ tar xjf libusb-1.0.0.tar.bz2
[lingyun@localhost usbmode]$ tar xjf libusb-compat-0.1.5.tar.bz2
[lingyun@localhost usbmode]$ tar xjf usb-modeswitch-1.2.4.tar.bz2
[lingyun@localhost usbmode]$ tar xjf usb-modeswitch-data-20130607.tar.bz2
编译libusb:
[lingyun@localhost usbmode]$ mkdir install
[lingyun@localhost usbmode]$ cd libusb-1.0.0
[lingyun@localhost libusb-1.0.0]$ ./configure --prefix=/home/lingyun/fulinux/usbmode/install/ --build=i686 --host=arm-linux --disable-shared --enable-static (注意有两--的前面有一个空格,如果你的cpu架构师i386的记得改,host参数你改为你的交叉编译器)
[lingyun@localhost libusb-1.0.0]$ make
[lingyun@localhost libusb-1.0.0]$ make install
[lingyun@localhost libusb-1.0.0]$ ls ../install/
include lib
[lingyun@localhost libusb-1.0.0]$
编译usb_modeswitch:
[lingyun@localhost usbmode]$ cd usb-modeswitch-1.2.6
[lingyun@localhost usb-modeswitch-1.2.6]$ ls
[lingyun@localhost usb-modeswitch-1.2.6]$ vim Makefile
CC ?=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc #addr fulinux
CFLAGS += -Wall -l ../install/include-static #add by fulinux
LIBS = -L ../install/lib/ -l usb -l usb-1.0-l pthread #add by fulinux
[lingyun@localhost libusb-1.0.0]$ cd ..
[lingyun@localhost usbmode]$ export PKG_CONFIG_PATH=/home/lingyun/fulinux/usbmode/install/lib/pkgconfig:$PKG_CONFIG_PATH
[lingyun@localhost usbmode]$ cd libusb-compat-0.1.5
[lingyun@localhost libusb-compat-0.1.5]$
[lingyun@localhost libusb-compat-0.1.5]$ ./configure --prefix=/home/lingyun/fulinux/usbmode/install/ --build=i686 --host=arm-linux --disable-shared --enable-static
[lingyun@localhost libusb-compat-0.1.5]$ make
[lingyun@localhost libusb-compat-0.1.5]$ make install
[lingyun@localhost libusb-compat-0.1.5]$ ls ../install/
bin include lib
[lingyun@localhost libusb-compat-0.1.5]$
编译usb_modeswitch:
[lingyun@localhost libusb-compat-0.1.5]$ cd ../usb-modeswitch-1.2.4
[lingyun@localhost usb-modeswitch-1.2.6]$ vim Makefile
CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
CFLAGS += -Wall -I ../install/include -static
LIBS = -L ../install/lib -l usb -l usb-1.0 -l pthread
[lingyun@localhost usb-modeswitch-1.2.4]$ make
[lingyun@localhost usb-modeswitch-1.2.4]$ cp usb_modeswitch ../install/bin/
[lingyun@localhost usb-modeswitch-1.2.4]$ cp usb_modeswitch /tftp/
上面用usb-modeswitch-1.2.6编译时发现有问题,有如下
[lingyun@localhost usb-modeswitch-1.2.6]$ make
cc -o usb_modeswitch usb_modeswitch.c -Wall -I../install/include -static -L /home/lingyun/fulinux/usbmode/install/lib -l usb -l usb-1.0 -l pthread
/usr/bin/ld: skipping incompatible /home/lingyun/fulinux/usbmode/install/lib/libusb.a when searching for -lusb
/usr/bin/ld: cannot find -lusb
collect2: ld returned 1 exit status
make: *** [usb_modeswitch] Error 1
[lingyun@localhost usb-modeswitch-1.2.6]$
“incompatible”库和这个有冲突。建议使用。1.2.6以下的版本。
把usb-modeswitch-data-20130607下的usb_modeswitch.d中的所有文件都拷贝到开发板的etc/usb_modeswitch.d/目录:
[lingyun@localhost usbmode]$ cd usb-modeswitch-data-20130607
[lingyun@localhost usb-modeswitch-data-20130607]$ ls
40-usb_modeswitch.rules ChangeLog COPYING gen-rules.tcl Makefile README usb_modeswitch.d
[lingyun@localhost usb-modeswitch-data-20130607]$ tar cjf usb_modeswitch.d.tar.bz2 usb_modeswitch.d/
[lingyun@localhost usb-modeswitch-data-20130607]$ ls
40-usb_modeswitch.rules ChangeLog COPYING gen-rules.tcl Makefile README usb_modeswitch.d usb_modeswitch.d.tar.bz2
[lingyun@localhost usb-modeswitch-data-20130607]$ cp usb_modeswitch.d.tar.bz2 /tftp/
[lingyun@localhost usb-modeswitch-data-20130607]$
把usb_modeswitch下载到开发板的/usr/sbin目录下,把usb_modeswitch.d下载开发板到/etc/目录下:
/usr/sbin >: tftp -gr usb_modeswitch 192.168.1.3
usb_modeswitch 100% |*******************************| 390k 0:00:00 ETA
/etc >: tftp -gr usb_modeswitch.d.tar.bz2 192.168.1.3
usb_modeswitch.d.tar 100% |*******************************| 8741 0:00:00 ETA
/etc >: tar xjf usb_modeswitch.d.tar.bz2
三、pppd和chat
交叉编译好工作源代码ppp-2.4.4,得到pppd和chat,解压源代码包,进入目录,进行交叉编译:
[lingyun@localhost fulinux]$ mkdir ppp
[lingyun@localhost fulinux]$ cd ppp/
[lingyun@localhost ppp]$ wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.4.tar.gz
[lingyun@localhost ppp]$ tar zxf ppp-2.4.4.tar.gz
[lingyun@localhost ppp]$ cd ppp-2.4.4
[lingyun@localhost ppp-2.4.4]$ ./configure
[lingyun@localhost chat]$ linux
[lingyun@localhost chat]$ vim chat.c
1168 if (timeout_next) {
1169 timeout_next = 0;
1170
1171 s = clean(s,0); /* By fulinux add */
1172
1173 timeout = atoi(s);
1174
1175 free(s); /* By fulinux add */
1176
1177 if (timeout <= 0)
[lingyun@localhost chat]$ vim Makefile
INSTALL= install
CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc #by fulinux add
all: chat
chat: chat.o
$(CC) -static -o chat chat.o #by fulinux add
[lingyun@localhost chat]$ cd ../pppd
[lingyun@localhost pppd]$ vim auth.c
1316 ao->neg_upap = !refuse_pap /*&& (passwd[0] != 0 || get_pap_passwd(NULL))*/; /*by fulinux add*/
[lingyun@localhost pppd]$ vim Makefile
33 CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc #by fulinux add
46#MPPE=y
51#FILTER=y
68#PLUGIN=y
[lingyun@localhost pppd]$ cd ..
[lingyun@localhost ppp-2.4.4]$ make
make[1]: Leaving directory `/usr/local/src/lingyun/fulinux/ppp/ppp-2.4.4/pppdump'
[lingyun@localhost ppp-2.4.4]$ cd chat/
[lingyun@localhost chat]$ ls
chat chat.8 chat.c chat.o Makefile Makefile.linux Makefile.sol2
[lingyun@localhost chat]$ file chat
chat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
[lingyun@localhost chat]$ cd ..
[lingyun@localhost ppp-2.4.4]$ cd pppd
[lingyun@localhost pppd]$ file pppd
pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[lingyun@localhost pppd]$
将交叉编译出来的这两个应用程序chat和pppd拷贝到开发板 /usr/sbin目录下,更改其属性为可执行文件。
[lingyun@localhost chat]$ cp chat /tftp/
[lingyun@localhost pppd]$ cp pppd /tftp/
在开发板中操作:
~ >: cd usr/sbin/
/usr/sbin >: tftp -gr chat 192.168.1.3
chat 100% |*******************************| 147k 0:00:00 ETA
/usr/sbin >: tftp -gr pppd 192.168.1.3
pppd 100% |*******************************| 621k 0:00:00 ETA
/usr/sbin >: chmod a+x chat
/usr/sbin >: chmod a+x pppd
配置拨号的脚文件
拨号上网需要的配置文件有3个:
wcdma,wcdma-chat-connect,wcdma-chat-disconnect(存放位置是开发板的/etc/ppp/peers)。
~ >: mkdir -p /etc/ppp/peers/
wcdma配置文件内容
# /etc/ppp/peers/wcdma
# This is pppd script for China liantong
# Usage: root>pppd call cdma
hide-password
noauth
connect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect'
disconnect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'
debug
/dev/ttyUSB2
115200
defaultroute
noipdefault
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
lock
dump
nodetach
user"card"
password"card"
crtscts
remotename 3gppp
ipparam 3gppp
usepeerdns
wcdma-chat-connect配置文件内容
ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
TIMEOUT 120
"" AT
OK \rATZ
OK \rAT+CGDCONT=1,"IP","3gnet",,0,0
OK-AT-OK ATDT*99#
CONNECT \d\c
wcdma-chat-disconnect配置文件内容
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "INSending break to the modem\n"
""\k"
""+++ATH"
SAY "\nGood bye\n"
还要添加一个域名解析的文件:
nameserver 4.2.2.2
nameserver 8.8.8.8
将上面的四个文件拷贝到/tftp目录下。
并下载到开发板相应的目录中去:
因为
lrwxrwxrwx 1 root root 29 Apr 21 2013 resolv.conf -> /apps/etc/network/resolv.conf
所以:
/apps/etc/network >: tftp -gr resolv.conf 192.168.1.3
~ >: cd etc/ppp/peers/
/etc/ppp/peers >: ls
/etc/ppp/peers >: tftp -gr wcdma 192.168.1.3
/etc/ppp/peers >: tftp -gr wcdma-chat-disconnect 192.168.1.3
/etc/ppp/peers >: tftp -gr wcdma-chat-connect 192.168.1.3
/etc/ppp/peers >: ls
wcdma wcdma-chat-connect wcdma-chat-disconnect
到这里PPP 移植就完成了。
到了这里大部分工作已经完成了,但是我们的开发板依然不能拨号,还需进一步修改和添加配置文件。
当我们的MF626插件中兴WCDMA USB调制解调器,Linux内核识别作为一个cd – rom。
scsi0 :usb-storage 1-1.4:1.0
scsi 0:0:0:0: CD-ROM ZTE USB SCSI CD-ROM 2.31 PQ: 0 ANSI: 2
现在我们需要使用usb_modeswitch切换3 g USB调制解调器来调制解调器(USB转换为seiral),对于usb_modeswitch使用libusb,libusb依赖于USB文件系统。所以我们在使用usb_modeswitch之前必须挂在usbfs,否则它不能检测USB设备。
添加中兴WCDMA现代usb_modeswitchMF626配置文件:
~ >: cd apps/
/apps >: vi zte_mf626.conf
#ZTE devices
DefaultVendor = 0x19d2
DefaultProduct= 0x2000
TargetVendor = 0x19d2
TargetProdduct= "0001,0002,0015,0016,0017,0031,0052,0055,0063,0064,0066,0091,0108,0117,0128,0157,2002,2003"
MessageContent = "5553424312345678000000000000061e000000000000000000000000000000"
MessageContent2 = "5553424312345679000000000000061b000000020000000000000000000000"
MessageContent3 = "55534243123456702000000080000c85010101180101010101000000000000"
NeedResponse=1
~
/apps >: ls
etc zte_mf626.conf
/apps >: usb_modeswitch -c /apps/zte_mf626.conf
Looking for target devices ...
No devices in target mode or class found
Looking for default devices ...
No devices in default mode found. Nothing to do. Bye.
这是因为usbfs文件系统没有挂在起来,所以使用usb_modeswitch之前要挂载它:
/apps >: mount -tusbfs usbfs /proc/bus/usb/
/apps >: mount
rootfs on / type rootfs (rw)
/dev/root on / type jffs2 (rw,relatime)
proc on /proc type proc (rw,relatime)
usbfs on /proc/bus/usb type usbfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime)
ramfs on /tmp type ramfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
ubi7:apps on /apps type ubifs (rw,sync,noatime)
/dev/mtdblock8 on /data type jffs2 (rw,sync,noatime)
/apps >:
~ >: ls proc/bus/usb/
001 devices
这样我usbfs就挂载起来了,但是如果重启开发板后,还得重新挂载,为了每次启动系统都能自动挂载,我们进行如下修改:
~ >: cd etc/
/etc >: vim fstab
# /etc/fstab: static file system information.
#
# <file system> <mount pt> <type> <options> <dump> <pass>
/dev/root / ext2 rw,noauto 0 1
proc /proc proc defaults 0 0
usbfs /proc/bus/usb usbfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
ramfs /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
~
现在的话就可以看到如下信息了:
~ >: usb_modeswitch -c /apps/zte_mf626.conf
Looking for target devices ...
No devices in target mode or class found
Looking for default devices ...
found matching product ID
adding device
Found device in default mode, class or configuration (1)
Accessing device 005 on bus 001 ...
Getting the current device configuration ...
OK, got current device configuration (1)
Using interface number 0
Using endpoints 0x01 (out) and 0x81 (in)
Inquiring device details; driver will be detached ...
Looking for active driver ...
OK, driver found; name unknown, limitation of libusb1
OK, driver "unkown" detached
SCSI inquiry data (for identification)
-------------------------
Vendor String: ZTE
Model String: USB SCSI CD-ROM
Revision String: 2.31
-------------------------
USB description data (for identification)
usb 1-1.1: usbfs: process 688 (usb_modeswitch) did not claim interface 0 before use
-------------------------
Manufacturer: ZTE,Incorporated
Product: ZTE CDMA Technologies MSM
Serial No.: 1234567890ABCDEF
-------------------------
Setting up communication with interface 0
Using endpoint 0x01 for message sending ...
Trying to send message 1 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 1 (CSW) ...
OK, response successfully read (13 bytes).
Trying to send message 2 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 2 (CSW) ...
OK, response successfully read (13 bytes).
Trying to send message 3 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 3 (CSW) ...
OK, response successfully read (0 bytes).
Resetting response endpoint 0x81
Resetting message endpoint 0x01
Device is gone, skipping any further commands
-> Run lsusb to note any changes. Bye.
~ >: usb 1-1.1: USB disconnect, device number 5
usb 1-1.1: new full speed USB device number 6 using s3c2410-ohci
usb 1-1.1: New USB device found, idVendor=19d2, idProduct=0031
usb 1-1.1: New USB device strings: Mfr=2, Product=1, SerialNumber=3
usb 1-1.1: Product: ZTE CDMA Technologies MSM
usb 1-1.1: Manufacturer: ZTE,Incorporated
usb 1-1.1: SerialNumber: 1234567890ABCDEF
option 1-1.1:1.0: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1.1:1.1: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB1
scsi3 : usb-storage 1-1.1:1.2
option 1-1.1:1.3: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB2
scsi 3:0:0:0: Direct-Access ZTE MMC Storage 2.31 PQ: 0 ANSI: 2
sd 3:0:0:0: Attached scsi generic sg0 type 0
sd 3:0:0:0: [sda] Attached SCSI removable disk
发送at命令:
~ >: microcom -s 115200 dev/ttyUSB2 (或者~ >: microcom -s 115200 dev/ttyUSB1)
at
OK
1, 查模块制造商:
at+cgmi
ZTE INCORPORATED
OK
2, 查GPRS模块型号:
at+cgmm
3, 查模块版本:
at+cgmr
BD_TMOP673M3V1.0.1B07
OK
3, 查SIM卡是否在位:
at+cpin?
4,查GPRS模块信号强度,其中”,”前的数字为信号强度,如下面示例中的12为信号强度。
at+csq
若信号强度为99,则无效。我这里信号强度一般在20左右。
5,查SIM卡是否注册上网络,其中”,”后的值为SIM卡的注册状态,如下面示例中的1.
OK如果状态值为0,表示未注册;如果为1表示本地号码注册上;如果为2,表示正在搜索运营商注册,但没注册上;3表示拒绝注册;4,未知状态; 5, 漫游号码注册上。
6,查SIM卡运营商,如下面显示的”CHN-CUGSM”为中国联通的号码:
at+cops?在UC864E模块上,使用AT+COPS?查询,则联通的号码将显示为”cmnet”,但在GTM900B/C, SIM5215上显示的是”CHN-CUGSM”. 中国移动的则为”China Mobile”,在现实的时候也有一些区别,例如在UC864E上中国移动显示为” China Mobile”,当中只有一个空格;而在GTM900B上则显示” China Mobile”,当中有两个空格。但是这上面是China Mobile Communication Corp.
8, AT命令打电话,注意在拨的号码后面有个分号;
atd10086;
OK
我不知道怎么通电话。
9,如果有电话到来时,则是串口上将收到RING字符串,这时我们可以使用ATA命令摘机,如果不想接听,可以使用ATH挂断;
但是我没有接到RING。
10,在进行PPP拨号上网前,我们必须使用下面命令来设置APN:
中国移动:
AT+CGDCONT=1,"IP","cmnet"
OK
中国联通有两个APN: uninet和3gnet, 如果给3G卡的话,可以设置APN为3gnet
AT+CGDCONT=1,"IP","uninet"
OK
AT+CGDCONT?
+CGDCONT:1,"IP","uninet","0.0.0.0",0,0
OK
或设置APN为3gnet:
AT+CGDCONT=1,"IP","3gnet"
OK
AT+CGDCONT?
+CGDCONT:1,"IP","3gnet","0.0.0.0",0,0
OK
短信相关命令:
设置短信格式为Text模式:
AT+CMGF=1
OK
设置短信格式为PDU模式:
AT+CMGF=0
OK
设置短信中心号,一般不需要我们手动设置。
湖北联通的短信中心号设置如下:
AT+CSCA="+8613010360500"
OK
湖北移动的短信中心号为:
AT+CSCA?
+CSCA: "+8613800270500",145
OK
现在就可以进行拨号了:
如果遇到下面问题
/etc/ppp/peers >: pppd call wcdma
pppd: In file /etc/ppp/peers/wcdma: unrecognized option 'user"card"'
在文件wcdma中user和“card"中间有一个空格。
>:pppd call wcdma
pppdoptions in effect:
debug # (from /etc/ppp/peers/wcdma)
nodetach # (from /etc/ppp/peers/wcdma)
dump # (from /etc/ppp/peers/wcdma)
noauth # (from /etc/ppp/peers/wcdma)
usercard # (from/etc/ppp/peers/wcdma)
password?????? # (from/etc/ppp/peers/wcdma)
remotename3gppp # (from/etc/ppp/peers/wcdma)
/dev/ttyUSB2 # (from /etc/ppp/peers/wcdma)
115200 # (from /etc/ppp/peers/wcdma)
lock # (from /etc/ppp/peers/wcdma)
connect/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect # (from /etc/ppp/peers/wcdma)
disconnect/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect # (from /etc/ppp/peers/wcdma)
crtscts # (from /etc/ppp/peers/wcdma)
local # (from /etc/ppp/peers/wcdma)
hide-password # (from /etc/ppp/peers/wcdma)
novj # (from /etc/ppp/peers/wcdma)
novjccomp # (from /etc/ppp/peers/wcdma)
ipcp-accept-local # (from /etc/ppp/peers/wcdma)
ipcp-accept-remote # (from /etc/ppp/peers/wcdma)
ipparam3gppp # (from/etc/ppp/peers/wcdma)
noipdefault # (from /etc/ppp/peers/wcdma)
defaultroute # (from /etc/ppp/peers/wcdma)
usepeerdns # (from /etc/ppp/peers/wcdma)
noccp # (from /etc/ppp/peers/wcdma)
abort on(BUSY)
abort on(NO CARRIER)
abort on(NO DIALTONE)
abort on(ERROR)
abort on(NO ANSWER)
timeoutset 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","cmnet",,0,0^M)
expect(OK)
^M
AT+CGDCONT=1,"IP","cmnet",,0,0^M^M
OK
-- got it
send(ATDT*99#^M)
expect(CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
send (\d)
Serialconnection established.
usingchannel 1
Usinginterface ppp0
Connect:ppp0 <--> /dev/ttyUSB2
sent [LCPConfReq id=0x1 <asyncmap 0x0> <magic 0xfb2b5aaa> <pcomp><accomp>]
rcvd [LCPConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic0x172b914> <pcomp> <accomp>]
sent [LCPConfAck id=0x0 <asyncmap 0x0> <auth chap MD5> <magic0x172b914> <pcomp> <accomp>]
rcvd [LCPConfAck id=0x1 <asyncmap 0x0> <magic 0xfb2b5aaa> <pcomp><accomp>]
rcvd [LCPDiscReq id=0x1 magic=0x172b914]
rcvd[CHAP Challenge id=0x1 <bcbf3cbe363150861c15cffae8617331>, name ="UMTS_CHAP_SRVR"]
sent[CHAP Response id=0x1 <6fcce180826b52be7803fc7a4b601de5>, name = "card"]
rcvd[CHAP Success id=0x1 ""]
CHAPauthentication succeeded
CHAPauthentication succeeded
sent[IPCP ConfReq id=0x1 <addr 0.0.0.0><ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
rcvd[IPCP ConfNak id=0x1 <ms-dns1 10.11.12.13><ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins10.11.12.14>]
sent[IPCP ConfReq id=0x2 <addr 0.0.0.0><ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd[IPCP ConfReq id=0x0]
sent[IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd[IPCP ConfNak id=0x2 <addr 10.218.148.212> <ms-dns1 211.137.58.20><ms-dns3 211.136.20.203>]
sent[IPCP ConfReq id=0x3 <addr 10.218.148.212> <ms-dns1 211.137.58.20><ms-dns3 211.136.20.203>]
rcvd[IPCP ConfReq id=0x1]
sent[IPCP ConfAck id=0x1]
rcvd[IPCP ConfAck id=0x3 <addr 10.218.148.212> <ms-dns1 211.137.58.20><ms-dns3 211.136.20.203>]
Could notdetermine remote IP address: defaulting to 10.64.64.64
local IP address 10.218.148.212
remote IPaddress 10.64.64.64
primary DNS address 211.137.58.20
secondaryDNS address 211.136.20.203
这样虽然拨号成功,但是它是在前台运行的,现在我们不能进行其他的任何操作,以前前台被它占领了,所以我们用pppd call wcdma $这个命令让它在后台运行,这样我们就可以在前台进行其他的操作了。
/etc/ppp/peers >: pppd call wcdma &
pppd options in effect:
debug # (from /etc/ppp/peers/wcdma)
nodetach # (from /etc/ppp/peers/wcdma)
dump # (from /etc/ppp/peers/wcdma)
noauth # (from /etc/ppp/peers/wcdma)
user card # (from /etc/ppp/peers/wcdma)
password ?????? # (from /etc/ppp/peers/wcdma)
remotename 3gppp # (from /etc/ppp/peers/wcdma)
/dev/ttyUSB2 # (from /etc/ppp/peers/wcdma)
115200 # (from /etc/ppp/peers/wcdma)
lock # (from /etc/ppp/peers/wcdma)
connect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect # (from /etc/ppp/peers/wcdma)
disconnect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect # (from /etc/ppp/peers/wcdma)
crtscts # (from /etc/ppp/peers/wcdma)
local # (from /etc/ppp/peers/wcdma)
hide-password # (from /etc/ppp/peers/wcdma)
novj # (from /etc/ppp/peers/wcdma)
novjccomp # (from /etc/ppp/peers/wcdma)
ipcp-accept-local # (from /etc/ppp/peers/wcdma)
ipcp-accept-remote # (from /etc/ppp/peers/wcdma)
ipparam 3gppp # (from /etc/ppp/peers/wcdma)
noipdefault # (from /etc/ppp/peers/wcdma)
defaultroute # (from /etc/ppp/peers/wcdma)
usepeerdns # (from /etc/ppp/peers/wcdma)
noccp # (from /etc/ppp/peers/wcdma)
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","cmnet",,0,0^M)
expect (OK)
^M
AT+CGDCONT=1,"IP","cmnet",,0,0^M^M
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
send (\d)
Serial connection established.
using channel 4
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB2
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xa913b970> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0x159ffde> <pcomp> <accomp>]
sent [LCP ConfAck id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0x159ffde> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xa913b970> <pcomp> <accomp>]
rcvd [LCP DiscReq id=0x1 magic=0x159ffde]
rcvd [CHAP Challenge id=0x1 <3a9d31cd14b44974b0c8cd921ce63204>, name = "UMTS_CHAP_SRVR"]
sent [CHAP Response id=0x1 <1d26db27eacd007feabbdb56426234b6>, name = "card"]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x2 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x3 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x3 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x4 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x5 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x5 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x6 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x6 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x7 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x7 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x8 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x8 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x9 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x9 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xa <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xa <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xb <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xb <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xc <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xc <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xd <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xd <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xe <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xe <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0xf <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0xf <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x10 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x10 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x11 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x11 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x12 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x12 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x13 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x13 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x14 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x14 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x15 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x15 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x16 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x16 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x17 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x17 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x18 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x18 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x19 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x19 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1a <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1a <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1b <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1b <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1c <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1c <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1d <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1d <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1e <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1e <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x1f <addr 0.0.0.0>]
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1f <addr 10.146.208.148>]
sent [IPCP ConfReq id=0x20]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfNak id=0x20 <addr 10.146.208.148>]
sent [IPCP ConfReq id=0x21 <addr 10.146.208.148>]
rcvd [IPCP ConfAck id=0x21 <addr 10.146.208.148>]
Could not determine remote IP address: defaulting to 10.64.64.64
local IP address 10.146.208.148
remote IP address 10.64.64.64
primary DNS address 10.11.12.13
secondary DNS address 10.11.12.14
/etc/ppp/peers >:
三、 现在我们就来测试一下,看看能不能上网
ping 域名服务器4.2.2.2
/etc/ppp/peers >: ping 4.2.2.2 -I ppp0
PING 4.2.2.2 (4.2.2.2): 56 data bytes
64 bytes from 4.2.2.2: seq=0 ttl=50 time=2524.370 ms
64 bytes from 4.2.2.2: seq=1 ttl=50 time=1520.146 ms
64 bytes from 4.2.2.2: seq=2 ttl=50 time=693.452 ms
64 bytes from 4.2.2.2: seq=3 ttl=50 time=629.477 ms
64 bytes from 4.2.2.2: seq=4 ttl=50 time=644.438 ms
64 bytes from 4.2.2.2: seq=5 ttl=50 time=640.548 ms
64 bytes from 4.2.2.2: seq=6 ttl=50 time=632.466 ms
64 bytes from 4.2.2.2: seq=7 ttl=50 time=587.508 ms
64 bytes from 4.2.2.2: seq=8 ttl=50 time=565.546 ms
64 bytes from 4.2.2.2: seq=9 ttl=50 time=557.537 ms
64 bytes from 4.2.2.2: seq=10 ttl=50 time=554.518 ms
--- 4.2.2.2 ping statistics ---
11 packets transmitted, 11 packets received, 0% packet loss
round-trip min/avg/max = 554.518/868.182/2524.370 ms
/etc/ppp/peers >:
可以。
再ping一下百度网:
/etc/ppp/peers >: ping www.baidu.com -I ppp0
PING www.baidu.com (220.181.111.148): 56 data bytes
64 bytes from 220.181.111.148: seq=0 ttl=49 time=934.383 ms
64 bytes from 220.181.111.148: seq=1 ttl=49 time=391.010 ms
64 bytes from 220.181.111.148: seq=2 ttl=49 time=345.984 ms
64 bytes from 220.181.111.148: seq=3 ttl=49 time=301.072 ms
64 bytes from 220.181.111.148: seq=4 ttl=49 time=915.210 ms
64 bytes from 220.181.111.148: seq=5 ttl=49 time=390.039 ms
64 bytes from 220.181.111.148: seq=6 ttl=49 time=585.136 ms
--- www.baidu.com ping statistics ---
8 packets transmitted, 7 packets received, 12% packet loss
round-trip min/avg/max = 301.072/551.833/934.383 ms
/etc/ppp/peers >:
略有丢包。
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# ifconfig eth0 down
# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.89.16.57 P-t-P:172.16.193.36 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1380 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:852 (852.0 B) TX bytes:894 (894.0 B)
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
# ping www.baidu.com
ping: bad address 'www.baidu.com'
但是直接ping IP地址是可以ping通的。
# ping 4.2.2.2
PING 4.2.2.2 (4.2.2.2): 56 data bytes
ping: sendto: Network is unreachable
# ping 4.2.2.2 -I ppp0
PING 4.2.2.2 (4.2.2.2): 56 data bytes
64 bytes from 4.2.2.2: seq=0 ttl=52 time=651.326 ms
64 bytes from 4.2.2.2: seq=1 ttl=52 time=368.773 ms
64 bytes from 4.2.2.2: seq=2 ttl=52 time=365.775 ms
--- 4.2.2.2 ping statistics ---
4 packets transmitted, 3 packets received, 25% packet loss
round-trip min/avg/max = 365.775/461.958/651.326 ms
上面ping时都会加参数 -I ppp0,通过修改路由表可以不用加参数,如同eth0工作时的方式:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
# route add default ppp0
或者# route add default dev ppp0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
# route add default ppp0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
# ping www.baidu.com
PING www.baidu.com (115.239.210.27): 56 data bytes
64 bytes from 115.239.210.27: seq=0 ttl=54 time=72.789 ms
64 bytes from 115.239.210.27: seq=1 ttl=54 time=73.628 ms
64 bytes from 115.239.210.27: seq=2 ttl=54 time=69.630 m
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
172.16.193.36 * 255.255.255.255 UH 0 0 0 ppp0
# ping www.baidu.com
PING www.baidu.com (115.239.210.27): 56 data bytes
64 bytes from 115.239.210.27: seq=0 ttl=54 time=72.789 ms
64 bytes from 115.239.210.27: seq=1 ttl=54 time=73.628 ms
64 bytes from 115.239.210.27: seq=2 ttl=54 time=69.630 ms
最后登录一下水木年华bbs
附(借鉴):
本文介绍在嵌入式Linux中,实现3G联网的基本方法。包括驱动配置,和联网的过程。也对在PC上实现3G的过程进行了介绍。
硬件:3g usb模块(华为ce189的3g网卡)+一张sim卡(电信cdma2000)
软件系统:Linux
主要内容:
一、在pc端确认拨号功能可用
二、在嵌入式端的实现
三、其它
一、在pc端确认拨号功能可用
==================================
在windows下直接插入网卡即可自动安装其驱动,比较简单直观,其实linux下连接也很简单,这里给出linux下的连接方式。
系统:Ubuntu 12.04
1、将sim卡插入3g网卡,再将3g网卡插入pc。
2、对3g网卡进行网络配置
这里有图形和命令行两种方式。后面在嵌入式系统中会采用命令行方式配置3g信息。
2.1、图形方式
通过图形设置比较直观,可大致了解3g配置所需的信息。
编辑链接->移动宽带->添加(新连接名为china telecom 1)
具体配置:
(1)IP配置:自动(即ppp自动)
(2)移动宽带:
编号:#777
用户名:[email protected]
密码:vnet.mobi
(3)ppp设置:
默认。
即chap、pap等鉴权方式都选中。
(4)连接
保存上述配置后,即可通过点击新建的连接"china telecom 1"连上。
(5)确认联网情况
ifconfig可见网络的名字为ppp0
通过firefox即可上网。
2.2命令行脚本方式:
通过pppd拨号上网,可以对连接过程有更深一步的了解,且使用预先配置好的信息,无需用户干预。如下
(1)pppd对cdma2000的拨号脚本
#cat /etc/ppp/peers/cdma2000ce189
#This is pppd script used by huawei ce189.
/dev/ttyUSB0
115200
crtscts
modem
debug
lock
nodetach
usepeerdns
defaultroute
noipdefault
noauth
user "[email protected]"
password "vnet.mobi"
#lcp-echo-failure 5
#lcp-echo-interval 30
#persist
0.0.0.0:0.0.0.0
connect '/usr/sbin/chat -s -v -f /etc/ppp/cdma2000-connect-chat'
这里,注意,noauth选项一定要有,这里"lcp-echo-failure 5"表示5次心跳确认失败后会终止连接、"lcp-echo-interval 30"表示心跳确认时间为30秒,"persist"表示基于前面心跳失败后,不会终止连接而是重新拨号。
(2)pppd拨号脚本调用的chat拨号脚本
#cat /etc/ppp/cdma2000-connect-chat
TIMEOUT 5
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
"" AT
"OK-+++\c-OK" ATH0
TIMEOUT 40
"" AT
OK ATDT#777
CONNECT ""
这里,脚本含义参见"man chat",基本每行是"<期望接收的字符> <发送字符>"。
#by fulinux add
chat-cdma2000-disconnect内容如下:
再植http://blog.csdn.net/qq_695538007/article/details/9632351,但是不确定
转载申明来自: http://mcuos.com/thread-8385-1-1.html
原文作者: 武汉大学生嵌入式学习培训 郭文学 <[email protected] QQ:281143292>
关于武汉凌云嵌入式学习培训 : http://mcuos.com/thread-7178-1-1.html
武汉凌云嵌入式学习培训官方论坛: http://mcuos.com/forum-316-1.html
前段时间花了75RMB买了个二手的3G上网卡玩,以前都是玩直接焊在板子上GPRS模块,包括GPRS的GTM900B/C,WCDMA的UC864E和早期调试的TD-SCDMA的模块。买的3G上网卡和焊在板子上的不一样,他有个Zero CD到串口设备转换的过程。下面是我的3G上网卡ZTE MF626的拨号过程。
开发板: FL2440
3G上网卡: ZTE MF626
Linux内核版本:
~ >: uname -a
Linux WirelessRouter 3.0.0 #5 Mon Jul 16 01:02:13 CST 2012 armv4tl GNU/Linux
usb 1-1.4: new full speed USB device number 6 using s3c2410-ohci
usb 1-1.4: New USB device found, idVendor=19d2, idProduct=2000
usb 1-1.4: New USB device strings: Mfr=2, Product=1, SerialNumber=3
usb 1-1.4: Product: ZTE CDMA Technologies MSM
usb 1-1.4: Manufacturer: ZTE,Incorporated
usb 1-1.4: SerialNumber: 1234567890ABCDEF
scsi2 : usb-storage 1-1.4:1.0
scsi 2:0:0:0: CD-ROM ZTE USB SCSI CD-ROM 2.31 PQ: 0 ANSI: 2
scsi 2:0:0:0: Attached scsi generic sg0 type 5
~ >: ls /dev/ttyUSB*
ls: /dev/ttyUSB*: No such file or directory 看不到串口设备
~ >: usb_modeswitch -c /etc/ppp/zte_mf626.conf
Looking for target devices ...
No devices in target mode or class found
Looking for default devices ...
found matching product ID
adding device
Found device in default mode, class or configuration (1)
Accessing device 006 on bus 001 ...
Getting the current device configuration ...
OK, got current device configuration (1)
Using first interface: 0x00
Using endpoints 0x01 (out) and 0x81 (in)
Inquiring device details; driver will be detached ...
Looking for active driver ...
OK, driver found; name unknown, limitation of libusb1
OK, driver "unkown" detached
SCSI inquiry data (for identification)
-------------------------
Vendor String: ZTE
Model String: USB SCSI CD-ROM
Revision String: 2.31
-------------------------
USB description data (for identification)
usb 1-1.4: usbfs: process 831 (usb_modeswitch) did not claim interface 0 before use
-------------------------
Manufacturer: ZTE,Incorporated
Product: ZTE CDMA Technologies MSM
Serial No.: 1234567890ABCDEF
-------------------------
Setting up communication with interface 0
Using endpoint 0x01 for message sending ...
Trying to send message 1 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 1 (CSW) ...
OK, response successfully read (13 bytes).
Trying to send message 2 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 2 (CSW) ...
OK, response successfully read (13 bytes).
Trying to send message 3 to endpoint 0x01 ...
OK, message successfully sent
Reading the response to message 3 (CSW) ...
OK, response successfully read (0 bytes).
Resetting response endpoint 0x81
Resetting message endpoint 0x01
Device is gone, skipping any further commands
-> Run lsusb to note any changes. Bye.
usb 1-1.4: USB disconnect, device number 6
usb 1-1.4: new full speed USB device number 7 using s3c2410-ohci
usb 1-1.4: New USB device found, idVendor=19d2, idProduct=0031
usb 1-1.4: New USB device strings: Mfr=2, Product=1, SerialNumber=3
usb 1-1.4: Product: ZTE CDMA Technologies MSM
usb 1-1.4: Manufacturer: ZTE,Incorporated
usb 1-1.4: SerialNumber: 1234567890ABCDEF
option 1-1.4:1.0: GSM modem (1-port) converter detected
usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1.4:1.1: GSM modem (1-port) converter detected
usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB1
scsi3 : usb-storage 1-1.4:1.2
option 1-1.4:1.3: GSM modem (1-port) converter detected
usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB2
scsi 3:0:0:0: Direct-Access ZTE MMC Storage 2.31 PQ: 0 ANSI: 2
sd 3:0:0:0: Attached scsi generic sg0 type 0
sd 3:0:0:0: [sda] Attached SCSI removable disk
~ >: ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2
~ >: ifup-ppp
ifup-ppp Usage: ifup-ppp [-d /dev/ttyUSB0] [-a apn] [-u username] [-p password] [-v chap/pap] [-i ipaddr] pppXX
This shell script used to do pppd dial up on GPRS/3G modem, if no options gived, it
will use the default configure file "/apps/etc/network/ifcfg-pppXX". If get options
in this command, it will use the option from the command line, and be careful the -d
option must be given to specify the modem device.
pppXX: Required, specify the dial up generated PPP device, such as ppp10.
-d: Required, if use command line options, specify the modem TTY device.
-a: Option, APN(Access Point Name) for the SIM card provider.
-u: Option, username for the GPRS login if needed.
-p: Option, password for the GPRS login if needed.
-v: Option, authenticate method, pap or chap.
-i: Option, <local_IP_address>:<remote_IP_address> such as 0.0.0.0:0.0.0.0
Example: ifup-ppp -d /dev/ttyUSB0 -a 3gnet -u uid -p pwd ppp10
Copyright (C) 2012 GuoWenxue < [email protected] QQ:281143292>
~ >: ifup-ppp -d /dev/ttyUSB2 -a "apn" -u "uid" -p "pwd" -v chap ppp10
+ pppd /dev/ttyUSB2 115200 name uid password pwd unit 10 require-chap idle 86400 refuse-mschap refuse-mschap-v2 refuse-eap nodefaultroute updetach debug lcp-echo-failure 3 lcp-echo-interval 5 ipcp-accept-local ipcp-accept-remote ipcp-restart 50 modem crtscts noipdefault noauth novj noccp novjccomp lock connect /usr/sbin/chat -v -V -s -E -f /etc/ppp/gprs-chat
abort on (BUSY)
abort on (NO ANSWER)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (\nRING\r\n\r\nRING\r)
timeout set to 20 seconds
send (ATE0^M)
expect (OK)
^M
OKOK
-- got it
send (AT+CGDCONT=1,"IP","apn"^M)
expect (OK)
^M
^M
OKOK
-- got it
send (ATD*99***1#^M)
+ requesting data connection
expect (CONNECT)
^M
^M
CONNECTCONNECT
-- got it
send (^M)
+ connected
Script /usr/sbin/chat -v -V -s -E -f /etc/ppp/gprs-chat finished (pid 920), status = 0x0
Serial connection established.
using channel 2
Using interface ppp10
Connect: ppp10 <--> /dev/ttyUSB2
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x13ccd8e> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0x317e9ad> <pcomp> <accomp>]
sent [LCP ConfAck id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0x317e9ad> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x13ccd8e> <pcomp> <accomp>]
sent [LCP EchoReq id=0x0 magic=0x13ccd8e]
rcvd [LCP DiscReq id=0x1 magic=0x317e9ad]
rcvd [CHAP Challenge id=0x1 <407507e94434a3e8aed3bc32885eed0a>, name = "UMTS_CHAP_SRVR"]
sent [CHAP Response id=0x1 <2901a6bd9c799e61aaca38fa541dcc0d>, name = "uid"]
rcvd [LCP EchoRep id=0x0 magic=0x317e9ad 01 3c cd 8e]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0>]
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1 <addr 10.184.119.29>]
sent [IPCP ConfReq id=0x2 <addr 10.184.119.29>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfAck id=0x2 <addr 10.184.119.29>]
Could not determine remote IP address: defaulting to 10.64.64.74
local IP address 10.184.119.29
remote IP address 10.64.64.74
+ route add default ppp10
~ >:
~ >: ifconfig
eth0 Link encap:Ethernet HWaddr 00:E5:49:83:76:1A
inet addr:192.168.1.168 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:64 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8805 (8.5 KiB) TX bytes:0 (0.0 B)
Interrupt:51 Base address:0x4300
lo Link encap ocal Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
mon.wlan0 Link encap:UNSPEC HWaddr 00-0C-43-30-72-81-01-00-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3657 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:429682 (419.6 KiB) TX bytes:0 (0.0 B)
ppp10 Link encap oint-to-Point Protocol
inet addr:10.184.119.29 P-t-P:10.64.64.74 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:28 (28.0 B) TX bytes:34 (34.0 B)
wlan0 Link encap:Ethernet HWaddr 00:0C:43:30:72:81
inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
~ >:
~ >: ping -c 4 -I ppp10 -s 1024 4.2.2.2
PING 4.2.2.2 (4.2.2.2): 1024 data bytes
1032 bytes from 4.2.2.2: seq=0 ttl=51 time=1195.062 ms
1032 bytes from 4.2.2.2: seq=1 ttl=51 time=1113.194 ms
1032 bytes from 4.2.2.2: seq=2 ttl=51 time=1186.090 ms
1032 bytes from 4.2.2.2: seq=3 ttl=51 time=941.224 ms
--- 4.2.2.2 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 941.224/1108.892/1195.062 ms
~ >:
附3:
http://www.linuxidc.com/Linux/2011-03/33430.htm
一. 环境
1. 开发板内核:linux kernel 2.6.14
2. 3G卡片:HUAWEI E1750
二. 相关工具与库文件下载
1. usb_modeswitch-1.0.6.tar.bz2(http://www.draisberghof.de/usb_modeswitch/)
建议下载较新版本,如果怕麻烦就下载与我一样的版本,下同。
Usb_modeswitch是对USB设备的工作模式进行转换一种万能工具,当然这种宝贝,只有在linux下才能体现其巨大的作用。随着移动通信,无线通信的发展,越来越多的设备被制作成USB接口,像一些无线网卡,3G数据卡等等。这些设备的厂家一般都会提供windows 下驱动,这些设备在第一次插上机子的时候,它们处于CDROM+闪存模式,可以从中提供驱动程序安装驱动,在驱动程序安装完成后,驱动会转换成3G模式,此时就会出现usb modem设备,目前的3G卡片全都是这样,这就是所谓的“ZeroCD”。
而在linux下我们可没有那么好的待遇,厂家一般不会给我们提供linux下面的驱动,而目前的内核还不能自动识别并驱动。所以我们需要用usb_modeswitch这个工具来进行模式转换,设备模式依赖usb-storage和usbserial模式,所以,在开发板上需要有这两种模块的支持,设备并能够正常工作于这两种模式下。
2.usb_modeswitch-current_data.tar.bz2(http://www.draisberghof.de/usb_modeswitch/)
这个包里包括提供给UDEV的驱动设备信息,和很多设备使用usb_mdoeswitch进行转换模式时需要配置的参数。下载它用于参考。
3. libusb-1.0.6.tar.bz2 (http://sourceforge.net/projects/libusb/files/libusb-1.0/)
Libusb才是我们的真正骨干力量,提供给usb_modeswitch一套系统API,所以,自然usb_modeswitch这个包工头要想工作,肯定不能离开libusb这个工人为其服务。
4.libusb-compat-0.1.3.tar.bz2 (http://www.linuxfromscratch.org/blfs/view/svn/general/libusb-compat.html)
libusb分为0.1和1.0两年版本,而1.0版本与0.1有较大的不同,并不向下兼容,必须依赖libusb-compat。
三. 交叉编译usb_modeswitch
1. 交叉编译 libusb
A. 解压并进入libusb-1.0.6目录,建立子目录install用于存放最后生存的库文件与头文件。
[[email protected]]# mkdir install
B. 配置并生成Makefile文件
[[email protected]]#./configure --build=i686-linux --host=arm-linux --prefix=/home/Anson/libusb-1.0.6/install
C. [[email protected]]#make
D. [[email protected]]# make install
2. 设置PKG_CONFIG_PATH环境变量,以使我们后面的编译能够顺利找到libusb库
A.设置环境变量
[[email protected]]# export PKG_CONFIG_PATH=/home/Anson/libusb-1.0.6/install/lib/pkgconfig:$PKG_CONFIG_PATH
B.查看是否设置正确
[[email protected]]#echo $PKG_CONFIG_PATH
3. 交叉编译lib_compat
与上面编译libusb的方法类似:
A.[[email protected]]#.mkdir install
B . [[email protected]]#./configure --build=i686-linux --host=arm-linux --prefix=/home/Anson/libusb-compat-0.1.3/install
C. [[email protected]]#make
D. [[email protected]]#make install
说明:如果此时出现"-Wno-pointer-sign"、"-fvisibility=hidden"这类错误,则是由于编译器版本过低不支持导致的,可以直接在Makefile和libusb/Makefile文件中删除这些编译选项即可。
4. 交叉编译usb_modeswitch
A.修改Makefile文件
修改STRIP和CC选项为:
STRIP = arm-xxx-linux-strip
CC = arm-xxx-linux-gcc
B. 可以将上面的libusb和libusb-compat的库和头文件拷贝到交叉编译器的lib和include目录下,或者直接加上编译选项指令库的路径即可如下:
INCLUDEDIR = /home/anson//libusb-1.0.6/install/include/libusb-1.0
LIBDIR = /home/anson/libusb-1.0.6/install/lib
$(PROG): $(OBJS)
$(CC) $(CCFLAGS) -I $(INCLUDEDIR) -L $(LIBDIR) -o $(PROG) $(OBJS)
这里的usb.h就是libusb-compat目录下的,如果没有usb.h,usb_modeswitch是编译不过去的。
C. make
5. 编辑usb_modeswitch目录下的usb_modeswitch.conf文件,加入以下内容:
DefaultVendor= 0x12d1 DefaultProduct= 0x1446 TargetVendor = 0x12d1 TargetProduct= 0x1001 MessageContent="55534243000000000000000000000011060000000000000000000000000000" MessageEndpoint=0x01 CheckSuccess=5 HuaweiMode=0 (特别注意这个参数,我在开发板上的麻烦就出在这个参数上面) |
6. 将上面生成的libusb动态库拷贝到开发板的库目录下,将上面生成的usb_modeswitch可执行程序和usb_modeswitch.conf配置文件下载到开发板某目录下。
附件4:
Android 3G 拨号脚本
1.WCDMA
debug
nodetach
lock
/dev/ttyUSB0
115200
user "card"
password "card"
crtscts
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
connect '/usr/sbin/chat -s -v -f chat-wcdma-connect'
disconnect '/usr/sbin/chat -s -v -f chat-wcdma-disconnect'
>>>chat-wcdma-connect
TIMEOUT 5
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rAT
OK \rATZ
OK \rAT+CGDCONT=1,"IP","3gnet",,0,0
OK-AT-OK ATDT*99#
CONNECT \d\c
>>>chat-wcdma-disconnect
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
2.TD-CDMA
debug
logfile /var/log/pppd.log
lock
/dev/ttyUSB0
115200
user "card"
password "card"
crtscts
connect '/usr/sbin/chat -v -t3 -f td-connect-chat'
disconnect '/usr/sbin/chat -s -v -f td-disconnect-chat'
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
>>>td-connect-chat
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK-AT-OK ATD#777
CONNECT \d\c
>>>td-disconnect-chat
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
3.CDMA1x
<<<cdma1x
debug
nodetach
lock
/dev/ttyUSB0
115200
user "card"
password "card"
crtscts
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
connect '/usr/sbin/chat -s -v -f cdma1x-connect-chat'
disconnect '/usr/sbin/chat -s -v -f cdma1x-disconnect-chat'
>>> cdma1x-connect-chat
TIMEOUT 5
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK \rAT\^PREFMODE=2
OK-AT-OK ATD#777
CONNECT \d\c
>>>cdma1x-disconnect-chat
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
4.CDMA2000-EVDO
>>>evdo
debug
nodetach
lock
/dev/ttyUSB0
115200
user "card"
password "card"
crtscts
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
connect '/usr/sbin/chat -s -v -f evdo-connect-chat'
disconnect '/usr/sbin/chat -s -v -f evdo-disconnect-chat'
>>>evdo-connect-chat
TIMEOUT 5
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK-AT-OK ATD#777
CONNECT \d\c
>>>evdo-disconnect-chat
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
参考文档:http://blog.csdn.net/ipromiseu/archive/2010/01/07/5154004.aspx