S3C2440开发板上调试3G USB接口上网卡

链接至我的163博客

首先,我们来了解一下3G上网卡的组成: USB+USB转串口芯片+3G无线拨号模块(调制解调器,就是我们常说的modem)从这样的组成我们基本可以了解3G无线模块对外提供的接口是串口,外部通过向此串口发送AT指令控制其上网、发短信、打电话等操作。而我们要与其通讯则必须要驱动中间的USB转串口芯片。

        由此可见要顺利使用3G USB接口卡上网除了要有一张移动、联通或者电信的SIM卡外,还需要具备如下模块:USB转串口驱动,用于与3G无线拨号模块通信;PPP协议用于无线模块与ISP之间的通信连接;由于现在的3G USB模块都集成了存储卡、WIFI等功能因此在linux下需要使用usb_modeswitch在各个功能间进行切换,比如切换到我们需要的modem功能才能上网。

        明确PPP和PPPOE的概念:PPP是点对点协议(Point to Point Protocol)的缩写。它是TCP/IP网络协议包的一个成员。PPP是TCP/IP的扩展,它增加了两个额外的功能组:它可以通过串行接口传输TCP/IP包; 它可以安全登录当使用作为公共电话系统的部分的串行接口时,必须要注意确保所有通信的真实性。这个终端PPP集合了用户名字和密码安全。因此,一个路由器或者服务器通过 PPP接收到一个请求时,如果这个请求的来源是不安全的,这就需要授权。这个授权是PPP的一部分。因为它的通过串行接口路由TCP/IP包的能力和它的授权能力,ISP(Internet服务提供商)通常使用PPP来允许拨号用户连接到Internet。PPPoE的意思是通过以太网的点对点协议。PPP通常通过串行通信,例如拨号modem连接。很多DSL Internet服务提供商现在使用通过以太网的PPP协议,因为它的额外的登录和安全性的特性。PPPoE将这些功能带给不使用串行连接来连接他们的用户的ISP。串行的ISP已经在modem通讯中使用PPP。另一方面,DSL提供商使用Ethernet而不是串行通讯。因为这样,就需要PPPoE的额外的功能,允许他们通过使用用户登录来确保通讯的安全和测量每个用户的数据流量。PPPoE(Point to Point Protocol over Ethernet,基于以太网的点对点协议)的工作流程包含发现(Discovery)和会话(Session)两个阶段,发现阶段是无状态的,目的是获得PPPoE终端(在局端的ADSL设备上)的以太网MAC地址,并建立一个惟一的PPPoE SESSION-ID。发现阶段结束后,就进入标准的PPP会话阶段。

 

一、 向linux内核添加3G模块的驱动(USB转串口的驱动)和ppp协议的支持,交叉编译并下载内核到开发板。

由于linux-2.6.30.4内核支持“USB driver for GSM and CDMA modems”,所以不需要修改代码,只修改内核配置即可。

在终端输入:make menuconfig 出现内核配置界面后选择:

Device Drivers---→

USB support---→

<*>USB SerialConverter support--→

[*]USB Serial Console device support

[*]USB Generic Serial Driver

          <*>USB driver for GSM and CDMA modems

到此3G模块驱动添加完成,上面“USB Serial Console device support”这个要选择,在usb_modeswitch切换到modem模式加载usb转串口驱动的时候不会生成 ttyUSB0等设备。下面进行ppp协议支持的添加(下面所示的几个选项必选)。

Device Drivers--→

Network device support---→

<*> 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

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 选择ppp协议支持(之前所提的必选,这里全部选上)编译进内核。

完成这些步骤之后,可以进行内核的交叉编译,退出make menuconfig,输入make zImage ARCH=arm CROSS_COMPILE=arm-linux-,编译生成的内核映像文件位于当前内核源代码文件的/arch/arm/boot目录下,将生成的内核映像文件下载到板子上。

内核启动后,会在/dev目录下生成ppp设备节点。如:

ls /dev/ppp -l

crw-rw----  1 root   root  108, 0 Jan  1 00:00 /dev/ppp

 

二、交叉编译好工作源代码ppp-2.4.4,得到pppd和chat

        解压源代码包,进入目录,进行交叉编译,这里所用的板子的交叉编译器是:

     #cd /home/ppp-2.4.4

       #./configure

       #make CC= arm-linux-gcc

拨号所用到的程序就是ppp-2.4.4/pppd下的pppd和ppp-2.4.4/chat下的chat可执行程序,将交叉编译出来的这两个应用程序拷贝到开发板 /usr/sbin目录下,更改其属性为可执行文件。

[root@localhost opt]$ mkdir ppp

[root@localhost opt]$ cd ppp/

[root@localhost ppp]$ wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.4.tar.gz

[root@localhost ppp]$ tar zxf ppp-2.4.4.tar.gz 

[root@localhost ppp]$ cd ppp-2.4.4

[root@localhost ppp-2.4.4]$ ./configure

[root@localhost chat]$ vim Makefile

INSTALL= install

CC=arm-linux-gcc  

all:    chat

chat:   chat.o

    $(CC) -static -o chat chat.o

面修改Makefile文件主要是设置编译器,如果环境变量中没有设置编译器路径,则CC处需要用编译器的绝对路径;并将chat以静态库的方式连接,如果没有用-static则是动态库链接

[root@localhost chat]$ cd ../pppd 

[root@localhost pppd]$ vim Makefile

 CC=arm-linux-gcc

TARGETS = pppd

面修改pppd的Makefile文件主要是设置编译器

[root@localhost pppd]$ cd ..

[root@localhost ppp-2.4.4]$ make

[root@localhost ppp-2.4.4]# file chat/chat

chat/chat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped

[root@localhost ppp-2.4.4]# file pppd/pppd

pppd/pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped

可以看到生成可执行文件chat和pppd,其中chat是静态链接,pppd是动态链接

将交叉编译出来的这两个应用程序chat和pppd拷贝到开发板 /usr/sbin目录下,更改其属性为可执行文件。

[root@localhost chat]$ cp chat /tftp/

[root@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

        

        在系统/var/目录下创建2个文件夹:(注意,这一步很关键,不然在进行拨号时会报Can't create lock file /var/lock/LCK..ttyUSB0: No such file or directory的错误)

mkdir /var/lock -p

mkdir /var/run -p

如果usb_modeswitch切换成功,查看/var/lock和/var/run目录会看到如下内容:

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 

         pppd是一个后台服务进程(daemon),是一个用户空间的进程,所以把策略性的内容从内核的PPP协议处理模块移到pppd中是很自然的事了。pppd实现了所有鉴权、压缩/解压和加密/解密等扩展功能的控制协议。pppd只是一个普通的用户进程,它如何扩展PPP协议呢?这就是pppd与内核中的PPP协议处理模块之间约定了,它们之间采用了最传统的内核空间与用户空间之间通信方式:设备文件。设备文件名是/dev/ppp。通过read系统调用,pppd可以读取PPP协议处理模块的数据包,当然,PPP协议处理模块只会把应该由pppd处理的数据包发给pppd。通过write系统调用,pppd可以把要发送的数据包传递给PPP协议处理模块。通过ioctrl系统调用,pppd可以设置PPP协议的参数,可以建立/关闭连接。

        chat是pppd所带一个辅助工具。chat用来与GSM模组建立会话。它的实现比较简单,它向串口发送AT命令,建立与GSM模组的会话,以便让PPP协议可以在串口上传输数据包。

 

三、usb_modeswitch和lsusb移植

usb_modeswitch和lsusb依赖于libusb,所以要先安装libusb

从网站http://www.draisberghof.de/usb_modeswitch/#download下载安装包如下:

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 解压:

[root@localhost opt]$ mkdir usbmode

[root@localhost opt]$ cd usbmode/

[root@localhost usbmode]$ tar xjf libusb-1.0.20.tar.bz2 

[root@localhost usbmode]$ tar xjf libusb-compat-0.1.5.tar.bz2 

[root@localhost usbmode]$ tar xjf usb-modeswitch-2.3.0.tar.bz2 

[root@localhost usbmode]$ tar xjf usb-modeswitch-data-20160112.tar.bz2 

 

编译libusb:

[root@localhost usbmode]$ mkdir install

[root@localhost usbmode]$ cd libusb-1.0.20

[root@localhost libusb-1.0.20]$ ./configure  --prefix=/opt/usbmode/install/   --build=i686  --host=arm-linux   --disable-shared   --enable-static    (注意有两--的前面有一个空格,如果你的cpu架构是i386的记得改,host参数你改为你的交叉编译器,--build= 谁在这里编译? 意思说你目前的编译动作在哪里跑的 ?--host= 目前编译出来的程序在哪里跑 ? )

在configure这步可能会出现如下错误:configure: error: "udev support requested but libudev not installed"

解决方法:(对于udev作用目前不了解,需要进一步研究!!!!!!!)

方法1、如果是Ubuntu可用: apt-get install libudev-dev安装,若不想安装或安装失败可用方法2 

方法2、在./configure 最后加入 --disable-udev

[root@localhost libusb-1.0.20]$ make

[root@localhost libusb-1.0.20]$ make install

[root@localhost libusb-1.0.20]$ ls ../install/

include  lib

[root@localhost libusb-1.0.20]$ 

libusb编译成功后,可以在/opt/usbmode/install/目录下生成 include和lib文件夹

 

编译usb_modeswitch:

libusb分为0.1和1.0两版本,而1.0版本与0.1有较大的不同,并不向下兼容,必须依赖libusb-compat

[root@localhost usbmode]$ export PKG_CONFIG_PATH=/opt/usbmode/install/lib/pkgconfig:$PKG_CONFIG_PATH

[root@localhost usbmode]$ cd libusb-compat-0.1.5

[root@localhost libusb-compat-0.1.5]$ 

[root@localhost libusb-compat-0.1.5]$ ./configure --prefix=/opt/usbmode/install/  --build=i686 --host=arm-linux --disable-shared --enable-static

[root@localhost libusb-compat-0.1.5]$ make 

[root@localhost libusb-compat-0.1.5]$ make install

[root@localhost libusb-compat-0.1.5]$ ls ../install/

bin  include  lib

[root@localhost libusb-compat-0.1.5]$ 

 

[root@localhost libusb-compat-0.1.5]$ cd ../usb-modeswitch-2.3.0

[root@localhost usb-modeswitch-2.3.0]$ vim Makefile 

CC          = arm-linux-gcc

CFLAGS      += -Wall -I ../install/include -I ../install/include/libusb-1.0 -static

LIBS        = -L ../install/lib -l usb -l usb-1.0 -l pthread  -lrt

说明:我在链接的时候出现undefined reference to `clock_gettime' 链接错误问题解决,因此添加了-lrt

[root@localhost usb-modeswitch-2.3.0]$ make

[root@localhost usb-modeswitch-2.3.0]$ cp usb_modeswitch ../install/bin/

[root@localhost usb-modeswitch-2.3.0]$ cp usb_modeswitch /tftp/

成功,在目录下会生成 usb_modeswitch 可执行文件

 

把usb-modeswitch-data-20160112下的usb_modeswitch.d中的所有文件都拷贝到开发板的etc/usb_modeswitch.d/目录:

[root@localhost usbmode]$ cd usb-modeswitch-data-201601112

[root@localhost usb-modeswitch-data-201601112]$ ls

40-usb_modeswitch.rules  ChangeLog  COPYING  gen-rules.tcl  Makefile  README  usb_modeswitch.d

[root@localhost usb-modeswitch-data-201601112]$ tar cjf usb_modeswitch.d.tar.bz2 usb_modeswitch.d/

[root@localhost usb-modeswitch-data-201601112]$ ls

40-usb_modeswitch.rules  ChangeLog  COPYING  gen-rules.tcl  Makefile  README  usb_modeswitch.d  usb_modeswitch.d.tar.bz2

[root@localhost usb-modeswitch-data-201601112]$ cp usb_modeswitch.d.tar.bz2 /tftp/

[root@localhost usb-modeswitch-data-201601112]$ 

 

把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

 

busybox工具里面没有lsusb命令,lsusb命令可以移植到ARM中,lsusb也依赖前面编译出来的libusb库,我下载了两个lsusb工具包分别为usbutils-0.80.tar.gz和usbutils-002.tar.gz,其中usbutils-002.tar.gz版本没有编译成功,下面的编译以usbutils-0.80.tar.gz为例。

[root@localhost usbmode]$ tar xjf usbutils-0.80.tar.gz

[root@localhost usbmode]$cd usbutils-0.80

[root@localhost usbutils-0.80]# ./configure CC=arm-linux-gcc --host=arm-linux LIBUSB_CFLAGS="-Wall -I ../install/include -I ../install/include/libusb-1.0 -static" LIBUSB_LIBS="-L ../install/lib -l usb -l usb-1.0 -l pthread  -lrt" CPPFLAGS=-I"/opt/usbmode/install/include/"  CFLAGS="-O2"

[root@localhost usbutils-0.80]# make

[root@localhost usbutils-0.80]# ls -la lsusb

-rwxr-xr-x 1 root root 324662 2016-04-20 17:08 lsusb

[root@localhost usbutils-0.80]# 

可以看到生成lsusb命令,将其拷贝到开发板的/sbin/目录下。需要将此目录下的usb.ids文件拷贝到文件系统的/usr/local/share/目录下,如果没有此目录可以自行创建,否则会有错误提示:

[root@CQZNSB /]# lsusb

lsusb: cannot open "/usr/local/share/usb.ids", No such file or directory

Bus 001 Device 001: ID 1d6b:0001  

四、usb_modeswitch及usb_modeswitch.d中配置文件的使用 

        我的3G无线数据上网卡型号为STD808,插入开发板USB接口,输出信息如下:

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 可以看到默认的idVendor=0x21f5,idProduct=0x3010,这时候设备被识别为CD-ROM,设备号为sr0,可以mount /dev/sr0 /tmp,可以查看到里面的驱动程序。

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 在usb_modeswitch.d中可以看到有文件21f5:3010,cat这个文件可以看到内容如下:

# StrongRising STD808

TargetVendor=0x21f5

TargetProduct=0x1101

StandardEject=1

        这里需要特别注意的是TargetProduct=0x1101就是我们进行usb_modeswitch切换后3g上网卡modem的功能号,从前面的输出我们可以知道STD808上网卡是集成了CD-ROM功能和modem功能的设备,他们的vendor都是0x21f5,而他们的功能是通过productID来区分的,Productid为0x3010的时候是CD-ROM功能,为0x1101的时候是3g的modem功能,STD808默认的是CD-ROM功能,要使用它的modem功能就需要使用usb_modeswitch进行切换。

        另外一个需要注意的问题就是切换为usb modem功能后使用的驱动就是前面第一步编译到内核中的usb转串口驱动,而通用的串口驱动(即内核选项中的USB Generic Serial Driver)存在数据丢失、不标准的流控、在波特率控制上的缺陷等原因,因此需要使用USB driver for GSM and CDMA modems来进一步完善通用的串口驱动,可以从内核配置时候的层次结构看出:

Device Drivers---→

USB support---→

<*>USB SerialConverter support--→

[*]USB Generic Serial Driver

          <*>USB driver for GSM and CDMA modems

这个用于USB driver for GSM and CDMA modems的文件在内核drivers/usb/serial/option.c中,因此需要修改option.c文件将我们进行usb_modeswitch切换后的3g modem功能的VendorId和ProductId添加进去,这里在我在文件中添加内容如下,如果文件中原本就存在就不需要添加:

#define StrongriTSM_VENDOR_ID 0x21f5

#define StrongriTSM_PRODUCT_STD808 0x1101

 

static struct usb_device_id option_ids[] = {

{ USB_DEVICE(StrongriTSM_VENDOR_ID, StrongriTSM_PRODUCT_STD808) }, //在option_ids结构中新添加的

如果不对option.c添加切换后modem的VendorId和ProductId,会看不到串口驱动模块加载成功后生成的设备驱动号ttyUSB0 ttyUSB1 ttyUSB2等;或者vendorid和productid添加不对,比如productid添加为0x3010,那么modeswitch切换就会成功,也不会看到ttyUSB*等设备号。

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 直接使用配置文件进行切换,发现错误提示没有默认的vendor/product ID,因此需要修改配置文件如下:

# StrongRising STD808

DefaultVendor=0x21f5

DefaultProduct=0x3010

TargetVendor=0x21f5

TargetProduct=0x1101

#TargetProduct=0x3010

StandardEject=1

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 再次切换发现错误提示:No devices in target mode or class found,这是因为usbfs文件系统没有挂在起来,所以使用usb_modeswitch之前要挂载它:mount -tusbfs usbfs /proc/bus/usb/ ,我在执行这个mount的时候总是得到错误提示mounting usbfs on /proc/bus/usb/ failed: Device or resource busy说设备忙,最后查询了很久是因为我在/etc/init.d/rcS启动中已经执行了mount -tusbfs none /proc/bus/usb/,所以不能mount上,修改后就可以了。

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 

这样我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

~

也可以在/etc/init.d/rcS中执行mount -tusbfs usbfs /proc/bus/usb/。

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 

五、测试

在没有插入sim卡的时候,直接通过串口向3g modem发送at指令,可以读取模块的一些基本信息,首先设置PC串口工具打开输入回显功能:

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 AT+CGSN 获得GSM模块的IMEI(国际移动设备标识)序列号,这个设备号跟模块上标示出来的一样。

如果在发送microcom的时候发生错误:microcom: can't create /var/lock/LCK..ttyUSB0: File exists,可以如下处理:

S3C2440开发板上调试3G USB接口上网卡 - 北极星 - xiebingsuccess的博客

 

一个完整的拨号过程:

[root@EmbedSky peers]# pppd call tdscdma&

[1] + Killed                     pppd call tdscdma

[root@EmbedSky peers]# Removed stale lock on ttyUSB0 (pid 1168)

abort on (NO CARRIER)

abort on (ERROR)

abort on (NO DIALTONE)

abort on (BUSY)

abort on (NO ANSWER)

send (AT^M)

expect (OK)

^M

OK

 -- got it

 

send (ATZ^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATE0V1^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATS0=0^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (AT+CGDCONT=1,\"IP\",\"cmnet\"^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (AT+CFUN=1^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATDT*99***1#^M)

expect (CONNECT)

^M

^M

^DUSIMU: 1^M

^M

^DPROFI: 0^M

^M

+CREG: 2^M

^M

+CIEV: 2,0^M

^M

^DACTI: 2^M

^M

^MODE:0,0^M

^M

CONNECT

 -- got it

 

Serial connection established.

using channel 1

Using interface ppp0

Connect: ppp0 <--> /dev/ttyUSB0

sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x755225ce> <pcomp> <accomp>]

rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x755225ce> <pcomp> <accomp>]

rcvd [LCP ConfReq id=0x0 <mru 1500> <asyncmap 0xffffffff> <auth pap> <magic 0x11223344> <pcomp> <accomp>]

No auth is possible

sent [LCP ConfRej id=0x0 <auth pap>]

rcvd [LCP ConfReq id=0x1 <mru 1500> <asyncmap 0xffffffff> <magic 0x11223344> <pcomp> <accomp>]

sent [LCP ConfAck id=0x1 <mru 1500> <asyncmap 0xffffffff> <magic 0x11223344> <pcomp> <accomp>]

sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

rcvd [IPCP ConfReq id=0x2 <addr 192.168.0.1>]

sent [IPCP ConfAck id=0x2 <addr 192.168.0.1>]

rcvd [IPCP ConfRej id=0x1 <ms-dns3 0.0.0.0>]

sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0>]

rcvd [IPCP ConfNak id=0x2 <addr 10.1.4.192> <ms-dns1 211.136.192.6>]

sent [IPCP ConfReq id=0x3 <addr 10.1.4.192> <ms-dns1 211.136.192.6>]

rcvd [IPCP ConfAck id=0x3 <addr 10.1.4.192> <ms-dns1 211.136.192.6>]

not replacing existing default route via 192.168.0.251

local  IP address 10.1.4.192

remote IP address 192.168.0.1

primary   DNS address 211.136.192.6

 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.1     *               255.255.255.255 UH    0      0        0 ppp0

192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

 

default         192.168.0.251   0.0.0.0         UG    0      0        0 eth0

 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# ifconfig

eth0      Link encap:Ethernet  HWaddr 10:23:45:67:89:AB  

          inet addr:192.168.0.66  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST 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)

          Interrupt:51 Base address:0x6000 

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:2 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:200 (200.0 B)  TX bytes:200 (200.0 B)

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:10.1.4.192  P-t-P:192.168.0.1  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:5 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:3 

          RX bytes:52 (52.0 B)  TX bytes:86 (86.0 B)

[root@EmbedSky peers]# 

[root@EmbedSky peers]# ping 211.136.192.6

PING 211.136.192.6 (211.136.192.6): 56 data bytes

^C

--- 211.136.192.6 ping statistics ---

11 packets transmitted, 0 packets received, 100% packet loss

[root@EmbedSky peers]# ping 211.136.192.6 -I ppp0

PING 211.136.192.6 (211.136.192.6): 56 data bytes

64 bytes from 211.136.192.6: seq=0 ttl=57 time=2849.674 ms

64 bytes from 211.136.192.6: seq=1 ttl=57 time=1885.510 ms

64 bytes from 211.136.192.6: seq=2 ttl=57 time=920.626 ms

64 bytes from 211.136.192.6: seq=3 ttl=57 time=215.787 ms

64 bytes from 211.136.192.6: seq=4 ttl=57 time=210.700 ms

^C

--- 211.136.192.6 ping statistics ---

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 210.700/1216.459/2849.674 ms

[root@EmbedSky peers]# 

可以看到能ping同域名地址,但在ping www.baidu.com的时候发现不能解析域名,但已经将ppp拨号的域名服务器添加到/etc/resolv.conf文件中,后来将路由表中的到eth0的默认路由删掉后,将ppp0作为默认路由,可以进行域名解析了,但不能ping同www.baidu.com,估计是sim卡的问题,因为我将3g模块插到电脑上用同样的sim卡拨号成功后,也不能ping www.baidu.com,而且也不能浏览网页。

[root@EmbedSky peers]# ping www.baidu.com -I ppp0

^C

[root@EmbedSky peers]# cat /etc/resolv.conf 

nameserver 211.136.192.6

 

[root@EmbedSky peers]# ping www.baidu.com -I ppp0

ping: bad address 'www.baidu.com'

[root@EmbedSky peers]# ping 211.136.192.6 -I ppp0

PING 211.136.192.6 (211.136.192.6): 56 data bytes

64 bytes from 211.136.192.6: seq=8 ttl=57 time=10040.763 ms

64 bytes from 211.136.192.6: seq=9 ttl=57 time=9075.408 ms

64 bytes from 211.136.192.6: seq=10 ttl=57 time=8110.566 ms

64 bytes from 211.136.192.6: seq=11 ttl=57 time=7145.518 ms

64 bytes from 211.136.192.6: seq=12 ttl=57 time=6200.445 ms

64 bytes from 211.136.192.6: seq=13 ttl=57 time=5255.524 ms

64 bytes from 211.136.192.6: seq=14 ttl=57 time=4290.430 ms

64 bytes from 211.136.192.6: seq=15 ttl=57 time=3345.449 ms

64 bytes from 211.136.192.6: seq=16 ttl=57 time=2400.487 ms

64 bytes from 211.136.192.6: seq=17 ttl=57 time=1435.525 ms

64 bytes from 211.136.192.6: seq=18 ttl=57 time=490.556 ms

64 bytes from 211.136.192.6: seq=19 ttl=57 time=205.411 ms

64 bytes from 211.136.192.6: seq=20 ttl=57 time=220.701 ms

64 bytes from 211.136.192.6: seq=21 ttl=57 time=215.453 ms

^C

--- 211.136.192.6 ping statistics ---

22 packets transmitted, 14 packets received, 36% packet loss

round-trip min/avg/max = 205.411/4173.731/10040.763 ms

[root@EmbedSky peers]# ping www.baidu.com -I ppp0

^C

[root@EmbedSky peers]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.1     *               255.255.255.255 UH    0      0        0 ppp0

192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

default         192.168.0.251   0.0.0.0         UG    0      0        0 eth0

[root@EmbedSky peers]# 

[root@EmbedSky peers]# route add default gw 192.168.0.1

[root@EmbedSky peers]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.1     *               255.255.255.255 UH    0      0        0 ppp0

192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

default         192.168.0.1     0.0.0.0         UG    0      0        0 ppp0

default         192.168.0.251   0.0.0.0         UG    0      0        0 eth0

[root@EmbedSky peers]# ping www.baidu.com -I ppp0

^C

[root@EmbedSky peers]# route del default gw 192.168.0.251

[root@EmbedSky peers]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.1     *               255.255.255.255 UH    0      0        0 ppp0

192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

default         192.168.0.1     0.0.0.0         UG    0      0        0 ppp0

[root@EmbedSky peers]# ping www.baidu.com -I ppp0

PING www.baidu.com (111.13.100.92): 56 data bytes

^C

--- www.baidu.com ping statistics ---

88 packets transmitted, 0 packets received, 100% packet loss

[root@EmbedSky peers]# 

[root@EmbedSky peers]# rcvd [LCP TermReq id=0xa3]

LCP terminated by peer

Connect time 56.1 minutes.

Sent 9848 bytes, received 1955 bytes.

sent [LCP TermAck id=0xa3]

Connection terminated.

abort on (OK)

abort on (BUSY)

abort on (DELAYED)

abort on (NO ANSWER)

abort on (NO CARRIER)

abort on (NO DIALTONE)

abort on (VOICE)

abort on (ERROR)

abort on (RINGING)

timeout set to 12 seconds

send (\K^M)

send (\K^M)

send (\K^M)

send (+++ATH^M)

send (+++ATH^M)

send (+++ATH^M)

send (ATZ^M)

 

Goodbay

Serial link disconnected.

Modem hangup

在网上看到很多童鞋在问,3g模块ppp拨号成功后,不能ping通外网的问题,就如同上面我遇到的问题,后来我换了一张我自己的手机卡来测试,我先是在pc电脑上用3g模块进行拨号,拨号成功,也能ping通外网;然后我在用到我的嵌入式板子上进行拨号,这次OK了,能ping通外网,所以3g模块ppp拨号成功后,不能ping通外网的问题多半是卡的问题,可能是欠费了,下面是用我自己的手机卡测试的结果:

[root@EmbedSky peers]# pppd call tdscdma&

[root@EmbedSky peers]# 

[root@EmbedSky peers]# abort on (NO CARRIER)

abort on (ERROR)

abort on (NO DIALTONE)

abort on (BUSY)

abort on (NO ANSWER)

send (AT^M)

expect (OK)

^M

OK

 -- got it

 

send (ATZ^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATE0V1^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATS0=0^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (AT+CGDCONT=1,\"IP\",\"cmnet\"^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (AT+CFUN=1^M)

expect (OK)

^M

^M

OK

 -- got it

 

send (ATDT*99***1#^M)

expect (CONNECT)

^M

^M

^DUSIMU: 1^M

^M

^DPROFI: 0^M

^M

+CREG: 2^M

^M

+CIEV: 2,0^M

^M

^DACTI: 2^M

^M

^MODE:0,0^M

^M

CONNECT

 -- got it

 

Serial connection established.

using channel 6

Using interface ppp0

Connect: ppp0 <--> /dev/ttyUSB0

sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xd7acabac> <pcomp> <accomp>]

rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xd7acabac> <pcomp> <accomp>]

rcvd [LCP ConfReq id=0x0 <mru 1500> <asyncmap 0xffffffff> <auth pap> <magic 0x11223344> <pcomp> <accomp>]

No auth is possible

sent [LCP ConfRej id=0x0 <auth pap>]

rcvd [LCP ConfReq id=0x1 <mru 1500> <asyncmap 0xffffffff> <magic 0x11223344> <pcomp> <accomp>]

sent [LCP ConfAck id=0x1 <mru 1500> <asyncmap 0xffffffff> <magic 0x11223344> <pcomp> <accomp>]

sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

rcvd [IPCP ConfReq id=0x2 <addr 192.168.0.1>]

sent [IPCP ConfAck id=0x2 <addr 192.168.0.1>]

rcvd [IPCP ConfRej id=0x1 <ms-dns3 0.0.0.0>]

sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0>]

rcvd [IPCP ConfNak id=0x2 <addr 10.6.210.149> <ms-dns1 183.230.126.225>]

sent [IPCP ConfReq id=0x3 <addr 10.6.210.149> <ms-dns1 183.230.126.225>]

rcvd [IPCP ConfAck id=0x3 <addr 10.6.210.149> <ms-dns1 183.230.126.225>]

local  IP address 10.6.210.149

remote IP address 192.168.0.1

primary   DNS address 183.230.126.225

 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# vi /etc/resolv.conf 

nameserver 183.230.126.225

[root@EmbedSky peers]# ls

chat-tdscdma-connect     chat-testmodem_1         gprs-disconnect-chat

chat-tdscdma-disconnect  gprs                     tdscdma

chat-testmodem           gprs-connect-chat        tdscdma_test

[root@EmbedSky peers]# 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:45 errors:0 dropped:0 overruns:0 frame:0

          TX packets:45 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:4278 (4.1 KiB)  TX bytes:4278 (4.1 KiB)

 

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:10.6.210.149  P-t-P:192.168.0.1  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:5 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:3 

          RX bytes:52 (52.0 B)  TX bytes:86 (86.0 B)

 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# 

[root@EmbedSky peers]# ping www.baidu.com

PING www.baidu.com (111.13.100.91): 56 data bytes

64 bytes from 111.13.100.91: seq=0 ttl=50 time=376.636 ms

64 bytes from 111.13.100.91: seq=1 ttl=50 time=230.397 ms

64 bytes from 111.13.100.91: seq=2 ttl=50 time=225.513 ms

64 bytes from 111.13.100.91: seq=3 ttl=50 time=240.410 ms

^C

--- www.baidu.com ping statistics ---

4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max = 225.513/268.239/376.636 ms

[root@EmbedSky peers]# ping www.163.com  

PING www.163.com (218.201.42.179): 56 data bytes

64 bytes from 218.201.42.179: seq=0 ttl=51 time=176.627 ms

64 bytes from 218.201.42.179: seq=1 ttl=51 time=170.500 ms

64 bytes from 218.201.42.179: seq=2 ttl=51 time=185.480 ms

^C

--- www.163.com ping statistics ---

3 packets transmitted, 3 packets received, 0% packet loss

round-trip min/avg/max = 170.500/177.535/185.480 ms

[root@EmbedSky peers]# usb 1-1: USB disconnect, address 5

Modem hangup

Connect time 3.4 minutes.

Sent 820 bytes, received 1255 bytes.

Connection terminated.

option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0

option 1-1:1.0: device disconnected

option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1

option 1-1:1.1: device disconnected

option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2

option 1-1:1.2: device disconnected

option1 ttyUSB3: GSM modem (1-port) converter now disconnected from ttyUSB3

option 1-1:1.3: device disconnected

option1 ttyUSB4: GSM modem (1-port) converter now disconnected from ttyUSB4

option 1-1:1.4: device disconnected

option1 ttyUSB5: GSM modem (1-port) converter now disconnected from ttyUSB5

option 1-1:1.5: device disconnected

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值