Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1940786
  • 博文数量: 1000
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 7921
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-20 09:23
个人简介

storage R&D guy.

文章分类

全部博文(1000)

文章存档

2019年(5)

2017年(47)

2016年(38)

2015年(539)

2014年(193)

2013年(178)

分类: 服务器与存储

2015-03-27 17:58:48

Ubuntu 3G上网卡拨号过程分析

彭刚  2013.08.16


1安装驱动

本文的实验环境为 

Ubuntu 10.04 Desktop, HUAWEI EC1270 CDMA2000 wireless data terminal.


华为3G上网卡插入PC USB接口,会自动挂载为一个光盘设备,运行其中Linux安装程序即可


使用lsusb命令查看上网卡设备信息:
Bus 005 Device 003: ID 12d1:140c Huawei Technologies Co., Ltd.

华为3G上网卡通常自带了一个很方便的图形界面的拨号工具。但为了分析Linux拨号上网的具体过程细节,我们采用wvdial工具来自行实现拨号上网


wvdial是linux下的一种拨号工具。利用wvdial和pppd可以实现linux下的轻松上网。在整个过程中,wvdial的作用是拨号并等待提示,并根据提示输入相应的用户名和密码等认证信息;pppd的作用是与拨入放协商传输数据的方法并维持该链接。使用wvdial时,需要使用/etc/wvdial.conf配置文件,这个配置文件可以自动生成,但是需要进行一点修改。wvdial载入配置文件后,会对modem进行初始化并拨号,等待拨入方的响应,然后启动pppd。

1>配置wvdail,创建/etc/wvdial.conf文件

$ sudo wvdialconf /etc/wvdial.conf
Editing `/etc/wvdial.conf'.

Scanning your serial ports for a modem.

Modem Port Scan<*1>: S0   S1   S2   S3   
WvModem<*1>: Cannot get information for serial port.
ttyUSB_utps_diag<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyUSB_utps_diag<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 9600 baud
ttyUSB_utps_diag<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
WvModem<*1>: Cannot get information for serial port.
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 -- OK
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyUSB_utps_modem<*1>: Modem Identifier: ATI -- Manufacturer: +GMI: HUAWEI TECHNOLOGIES CO., LTD
ttyUSB_utps_modem<*1>: Speed 9600: AT -- OK
ttyUSB_utps_modem<*1>: Max speed is 9600; that should be safe.
ttyUSB_utps_modem<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
WvModem<*1>: Cannot get information for serial port.
ttyUSB_utps_ndis<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyUSB_utps_ndis<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 9600 baud
ttyUSB_utps_ndis<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
WvModem<*1>: Cannot get information for serial port.
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 -- OK
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyUSB_utps_pcui<*1>: Modem Identifier: ATI -- Manufacturer: +GMI: HUAWEI TECHNOLOGIES CO., LTD
ttyUSB_utps_pcui<*1>: Speed 9600: AT -- OK
ttyUSB_utps_pcui<*1>: Max speed is 9600; that should be safe.
ttyUSB_utps_pcui<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK

Found a modem on /dev/ttyUSB_utps_modem.
Modem configuration written to /etc/wvdial.conf.
ttyUSB_utps_modem: Speed 9600; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
ttyUSB_utps_pcui: Speed 9600; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"

 

2>检查/etc/wvdial.conf文件

$ cat /etc/wvdial.conf 

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
Baud = 9600
New PPPD = yes
Modem = /dev/ttyUSB_utps_modem
ISDN = 0
; Phone =
; Password =
; Username =

3>补充/etc/wvdial.conf文件

上一步生成的/etc/wvdial.conf文件缺少参数 phone number, login name, password如果缺少这些参数运行wvdial时会出现如下错误:

--> Modem initialized.

--> Configuration does not specify a valid phone number.

--> Configuration does not specify a valid login name.

--> Configuration does not specify a valid password.


这些参数可以通过华为自带的图形化拨号软件的参数配置文件查询到。其中Phone参数是指接入点。我曾经见到的接入点名称有中国电信CDMA2000 #777,中国联通WCDMA *99#,中国移动(GPRS)cnwap和cnnet


上一步生成的/etc/wvdial.conf文件也缺少其它一些参数缺少参数Auto DNS使 pppd 并不自动配置DNS,导致无法上网。缺少参数Auto Reconnect 会导致意外断线后不会自动重连。


补充配置参数

$ cat /usr/local/Mobile_Partner/config/data/SysProfile.prof $ sudo vi /etc/wvdial.conf Phone = #777 Password = vnet.mobi Username = ctnet@mycdma.cn

Auto Reconnect = on Abort on Busy = off Auto DNS = on


4>拨号入网

$ sudo wvdial
--> WvDial: Internet dialer version 1.60      //Step 1, loading configuration files
--> Cannot get information for serial port.
--> Initializing modem.                       //Step 2, Send AT commands to modem
--> Sending: ATZ
ATZ
OK
^RSSILVL:60
^CRSSI: 26
^MODE: 8
^RSSILVL:60
^HRSSILVL:60
^CRSSI: 26
^HDRRSSI: 31
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.         //Step 3, read response from modem, handle NO_DIAT_ONE, BUSY, CONNECT
ATDT#777
CONNECT
--> Carrier detected.  Waiting for prompt.
~[7f]}#@!}!}!} }/}"}&} } } } }#}%B#}%})h~
--> PPP negotiation detected.
--> Starting pppd at Fri Aug 16 16:47:54 2013    // Step 4, run pppd
--> Pid of pppd: 17618
--> Using interface ppp0  //Step5, pppd output: bond a ifname to the output of ifconfig command
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> local  IP address 171.219.220.5
--> pppd: (?d[08]@?d[08]
--> remote IP address 172.22.212.185
--> pppd: (?d[08]@?d[08]
--> primary   DNS address 218.6.200.139
--> pppd: (?d[08]@?d[08]
--> secondary DNS address 61.139.2.69
--> pppd: (?d[08]@?d[08]

// 此时已经接入了internet。wvdial进程阻塞在这里,如果发生意外断线,则会自动重连(默认,除非自动重连选项被关闭),并产生后继输出。
// 如果要停止网络,使用ctrl+C命令,可以中断连接。

^CCaught signal 2:  Attempting to exit gracefully...
--> Terminating on signal 15
--> pppd: (?d[08]@?d[08]
--> Connect time 7.7 minutes.
--> pppd: (?d[08]@?d[08]
--> pppd: (?d[08]@?d[08]
--> Disconnecting at Fri Aug 16 16:55:39 2013
^C


5>网络测试

$ sudo ifconfig eth0 down  //将接入的有线网卡ethx关闭,使用3G模块接入的PPP0节点

$ ifconfig 

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:116 errors:0 dropped:0 overruns:0 frame:0

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

          collisions:0 txqueuelen:0

          RX bytes:9624 (9.6 KB)  TX bytes:9624 (9.6 KB)

 

ppp0      Link encap:Point-to-Point Protocol 

          inet addr:172.17.79.184  P-t-P:10.64.64.64  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1

          RX packets:7 errors:0 dropped:0 overruns:0 frame:0

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

          collisions:0 txqueuelen:3

          RX bytes:118 (118.0 B)  TX bytes:157 (157.0 B)

$ cat /etc/resolv.conf
nameserver 218.6.200.139
nameserver 61.139.2.69

使用ping命令来测试网络。如果能PING通互联网站点,则说明3G上网已经成功

6> 参考文献
[1] 
Ubuntu10.04下使用华为E1750 3G模块,
阅读(1897) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~