嵌入式 PPPD拨号脚本详解摘录

来源:互联网 发布:mac老系统在哪下载 编辑:程序博客网 时间:2024/05/20 02:55

ppp拨号脚本配置

摘要
本文主要介绍了嵌入式Linux系统下使用pppd 2.4.4来进行PPP拨号需要使用的脚本是如何配置的,配置项的含义,同时也说明了如何来配置参数,实现ppp拨号上网。

一.问题提出
嵌入式Linux操作系统下,如果要进行PPP连接,就需要配置拨号要使用的连接脚本。这些脚本参数就决定了PPPD的行为,会对PPP连接产生很大的影响。所以需要对这些脚本的参数以及具体含义有所了解。

二.解决思路
和PPP连接关系密切的有两个脚本是chat和options两个脚本。其中,chat脚本是用来进行AT呼叫和控制的脚本,而options脚本就影响PPP连接的。

1.CHAT脚本
一个简单的chat脚本有下面的结构:
"" AT
OK ATDT dialnumber
CONNECT ""
一个chat脚本都是由字符串对来组成的。前面的字符串都是期望获取的串,紧跟的是发送的字符串。这个脚本每一项的具体含义是这样的:
1)   MODEM期望空字符串。这句话的意思直接理解就是MODEM不管收到什么字符串,先发出字符串AT;
2)   期望收到“OK”字符串,然后发送字符串“ATDT dialnumber”
3)   如果收到“CONNECT”,就不再发送,认为数据链路已建立连接。
这样的chat脚本是最简单的,如果需要进行超时控制,就可以加入如下字段:
TIMEOUT 10
如果要增加对特殊情况的处理,就加入下面字段:
ABORT BUSY 
ABORT NO ANSWER
ABORT RINGING
这三行语句的意思是:如果收到字符串“BUSY”、“NO ANSWER”、“RINGING”就退出执行。
所以在考虑到各种特殊情况下,配置一个PPP连接的CHAT脚本就可以像下面这样:
TIMEOUT 30
ABORT BUSY  
ABORT NO ANSWER
ABORT RINGING
"" AT
OK ATDT dialnumber
CONNECT ""

2.OPTIONS脚本
OPTIONS脚本的内容,为PPP连接指定了连接使用的设备、使用的控制字符传输速率、指定了硬件加速、溢出控制等。
例如下面的options脚本:
ttyS0 ----
指定连接使用的设备,例如:ttyS0、ttyS1等
57600 ---- 设置连接使用的控制字符传输速率,可以设置为57600、115200等
debug ---- 如果需要加入调试信息,就加入参数debug
logfile /var/ ppplog ----
将连接过程中的信息输入到某个文件中
mtu 1500
-detach
noipdefault ---- 不使用默认IP就可以加入参数noipdefault
defaultroute
usepeerdns ---- 使用服务器端协商的DNS就可以设置参数usepeerdns
lcp-echo-failure 4 ---- 当连续4次没有收到发出的LCP回声请求时,就认为服务器端已不再响应,就退出执行。这里的失败次数可以灵活来决定。
-ccp ----
不使用压缩控制协议
-vj ----
关掉式IP头压缩
-chap ---- 不使用chap鉴权
-mschap-v2 ---- 不使用mschap鉴权
user
hide-password
connect "/usr/bin/chat -v -t6 -f /var/ chat" ---- 制定了要使用的chat脚本的位置。加上参数-v 告诉 chat命令将其所有的输出/入拷贝到系统记录里(通常是 /var/log/messages)。-t 6 指定了执行chat该命令的时间为6s。chat脚本的位置可以位于/etc/目录下,也可以位于/var下,这个可以更加需要灵活设置。
persist --- 永久链接(自动重拨)
crtscts ---告诉ppp使用modem的硬件流量控制
modem ---使ppp使用DCD信号来判断连接是否正常,有无掉线现象
deflate ---使pppd使用defalte压缩方式
idle --- 设置了一个时间限制,当在300秒的时间内没有数据传送,就断开连接
lock --- 则创建一个锁定文件,其他程序在发现存在这个文件后,就能得知相应的串口已经被使用。
demond ---参数告诉pppd停留在后台,监视网络数据,一旦有要求就立即进行连网,超时后就断开连接,但pppd仍然停留在后台等待下次数据传送

其他的参数具体含义可以参照参考PPPD2.4.4 中options.c中注释:


intdebug = 0;
int kdebugflag = 0;
intdefault_device = 1;
char devnam[MAXPATHLEN];
boolnodetach = 0;
bool updetach = 0;
intmaxconnect = 0;
char user[MAXNAMELEN];
charpasswd[MAXSECRETLEN];
bool persist = 0;
char our_name[MAXNAMELEN];
bool demand = 0;
char*ipparam = NULL;
int idle_time_limit = 0;
intholdoff = 30;
bool holdoff_specified;
intlog_to_fd = 1;
bool log_default = 1;
intmaxfail = 10;
char linkname[MAXPATHLEN];
booltune_kernel;
int connect_delay = 1000;
intreq_unit = -1;
bool multilink = 0;
char*bundle_name = NULL;
bool dump_options;
booldryrun;
char *domain;
int child_wait = 5;

3. 鉴权脚本
一般情况下,PPP连接是需要进行身份认证的。签权方式有两种,一种是PAP鉴权,另一种是CHAP鉴权。鉴权需要的用户名和密码是存放在PAP-secrets和chap-secrets脚本中,以如下方式存放:
Username * password
需要进行鉴权时,通过在options脚本中指定鉴权方式为PAP或CHAP,PPP模块就会从PAP-secrets和chap-secrets脚本中读出用户名和密码,附加到PPP的鉴权包中,发送到服务器端进行身份认证。


4. PPP拨号过程与脚本之间的关系
脚本设置成功以后,怎么和pppd2.4.4一起工作呢?这个需要从pppd程序的主函数入手。
这个过程是这样的:
Pppd程序启动以后,就会按照pathname.h中所指定的文家位置去寻找options脚本文件。这个可以按照需要指定文件的位置,确保pppd能够准确找到该文件。
Pppd找到options文件后,按顺序读入参数行。在这里,就可以获取系统要使用的是哪个设备来进行联网、设备的速率是多少。
Pppd 将配置的参数解析为程序当中的全局变量标识符,进行pppd连接控制。


三.实践情况
下面是FT282 上的PPP连接使用的OPTIONS、 CHAT和PAP-SECRETS脚本。
OPTIONS:
connect "/usr/bin/chat -v -t6 -f /var/ppp/td-scdma_chat"
ttyUSB0
115200
debug
logfile /var/log/ppplog
mtu 1500
-detach
noauth
noipdefault
defaultroute
usepeerdns
crtscts
lock
lcp-echo-failure 4
-ccp
-vj
-chap
-mschap-v2
user
hide-password
CHAT:
"" AT
OK ATDT*98*1#
CONNECT ""
PAP-SECRETS:
wap *wap
经过在FT282上进行测试,发现能够顺利进行PPP连接。

 

常见问题:

1、3G/GSM connection returning "Connect script failed"

Q. I am running into an error when enabling the 3G dongle. I run this command -----> pppd nodetach call e160. And the output is:

Script /usr/sbin/chat -vf /etc/ppp/peers/e160_chat finished (pid 1843), status = 0x3
Connect script failed



A. "Connect script failed" is a generic error and can mean several things:

1. SIM card not detected, not attached to an active cell plan, or attached to a cell plan without 3G data service activated.

2. Weak cell signal - try moving the plug to another location, such as closer to a window. With a weaker signal you may need to run the "pppd nodetach..." command several times before it can lock onto a signal. If your 3G/GSM adapter has an external antenna port, consider attaching a GSM antenna to boost the signal.

3. Adapter not ready. Try waiting 1 minute after connecting the adapter before attempting to connect. Check dmesg to confirm the adapter is detected as a GSM device (Look for "usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0")

4. The GSM modem device on the adapter may be showing up as something besides /dev/ttyUSB0. Try changing to /dev/ttyUSB1 or /dev/ttyUSB2 in the config file /etc/ppp/peers/e160 (Look for the line "# Serial device to which the modem is connected").

0 0