码迷,mamicode.com
首页 > 其他好文 > 详细

ubantu下手动配置脚本实现3G模块上网

时间:2014-11-07 20:36:04      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:style   io   color   ar   os   使用   sp   for   strong   

WCDMA


本节使用的是 huawei em770w 模块,使用中国联通 WCDMA。

pppd 脚本


pppd 脚本默认放在/etc/ppp/peers/ 目录下,比如我们使用 wcdma 这个名字为这个脚本的

文件名
使用命令
    #pppd call wcdma
这样就启动了 pppd 程序


pppd 程序的作用就是建立协议,生成网络接口 ppp0(如果第一个).下面是一个 pppd call 脚本
的例子:

#/etc/ppp/peers/wcdma
#This is pppd script, used Huawei EM770W(Union)
/dev/ttyUSB0
115200
crtscts
modem
debug
nodetach
usepeerdns
defaultroute
user "3gnet"
0.0.0.0:0.0.0.0
connect ‘/usr/sbin/chat -s -v -f /etc/ppp/wcdma-connect-chat‘

有关 pppd 更多的意义请直接使用 linux 帮助 man pppd

下面是一些重要参数的解释
参数 意义
/dev/ttyUSB0 接口
115200         接口波特率
crtscts           接口带硬件流控
modem          这个参数使得 pppd 进程将等待模块发回的 CD (Carrier Detect)信号,与
local               真好相反
debug             输出调试信息
nodetach        不后台运行,默认是后台运行的
usepeerdns    使用 dns
defaultroute    本地和远端的 ip 都设为 0 使得接入的 isp 分配本地的 ip 地址
user “3gnet”    用户名
connect ‘...’     调用连接 chat 脚本

chat 脚本

  chat 脚本是真正 AT 指令的发送和接收脚本,下面是一个 chat 脚本

#/etc/ppp/wcdma-connect-chat
TIMEOUT 5
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
#"AT
#‘OK-+++\c-OK‘ ATH0
TIMEOUT 5
ECHO OFF
‘‘ AT
OK AT+CGDCONT=1,"IP","3gnet",,0,0
OK ATDT*99#
CONNECT ‘‘

#pppd call wcdma

  如果想在终端看到信息就在pppd 脚本中选择nodetach,否则pppd将在后台运行,终端不显示任何信息,这样可通过查看/var/log/ppp-connect-errors 记录,了解程序运行的过程。$ tail  -100 /var/log/ppp-connect-errors

如果没有错误将出现

timeout set to 5 seconds
abort on (DELAYED)
abort on (BUSY)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 5 seconds
send (^MAT^M)
expect (OK)
A^M^M
OK
-- got it
send (AT+CGDCONT=1,"IP","3gnet",,0,0^M)
expect (OK)
^M
AT+CGDCONT=1,"IP","3gnet",,0,0^M^M
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
send (^M)
Serial connection established.
using channel 9
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xf5d87df8> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x20 <asyncmap 0x0> <auth chap MD5> <magic 0x172fd2b> <pcomp>
<accomp>]
No auth is possible
sent [LCP ConfRej id=0x20 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xf5d87df8> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x21 <asyncmap 0x0> <magic 0x172fd2b> <pcomp> <accomp>]
sent [LCP ConfAck id=0x21 <asyncmap 0x0> <magic 0x172fd2b> <pcomp> <accomp>]
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3
0.0.0.0>]
rcvd [LCP DiscReq id=0x22 magic=0x172fd2b]
rcvd [LCP ProtRej id=0x23 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for ‘Compression Control Protocol‘ (0x80fd) received
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 <compress VJ 0f 01> <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 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 10.11.12.13>
<ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x10]
sent [IPCP ConfNak id=0x10 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x3 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x11]
sent [IPCP ConfAck id=0x11]
rcvd [IPCP ConfNak id=0x4 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
sent [IPCP ConfReq id=0x5 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
rcvd [IPCP ConfAck id=0x5 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.8.254
local IP address 172.20.255.208
remote IP address 10.64.64.64
primary DNS address 202.99.160.68
secondary DNS address 202.99.166.4

$ifconfig 可以看到多出来ppp0

如果出现

Serial connection established.
using channel 3
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB2
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
LCP: timeout sending Config-Requests
Connection terminated.

或者

send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
NO CARRIER
-- failed
Failed (NO CARRIER)

可以试试换换ttyUSB端口号,默认是虚拟出的第一个端口,ttyUSB0

ubantu下手动配置脚本实现3G模块上网

标签:style   io   color   ar   os   使用   sp   for   strong   

原文地址:http://www.cnblogs.com/ltfbk/p/4081987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!