嵌入式 PPPD工具实现3G拨号实践以及工具PPPD和CHAT详解摘录

PPPD:

1、我的平台:SIMCOM 5360E 中国联通3G

首先是WCDMA脚本:

root@njqy:/etc/ppp/peers# cat kj_wcdma
#/etc/ppp/peers/wcdma
#This is pppd script, used SIMCOM 5360(Union)
/dev/ttyUSB3
115200
crtscts
modem
debug
nodetach
usepeerdns
defaultroute
user "3gnet"
connect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-connect-chat'
root@njqy:/etc/ppp/peers#

wcdma-connect-chat脚本:

root@njqy:/etc/ppp/peers# cat wcdma-connect-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

''      AT
OK     AT+CFUN=1 #实现基本的全功能模式
OK     AT+CNAOP=2 #设置为WCDMA
OK     AT+CNMP=14 #设置WCDMA模式
OK     AT+CGDCONT=1,"IP","3gnet",,0,0 #VPN服务器
OK     ATDT*99# #联通3G特殊号码
CONNECT    ''
root@njqy:/etc/ppp/peers#

2、PPPD在man中详解:

NAME

pppd - 点对点协议守护进程 

总览 SYNOPSIS

pppd [ tty_name ] [ speed ] [ options

描述

点对点协议 (PPP) 提供一种在点对点串列线路上传输资料流 (datagrams)的方法。PPP是由三个部份所组成的:一个在串列线路上封装(encapsulating)资料流的方法,一个可延伸的连结控制协定(LinkControlProtocol:LCP),以及一些用来建立并配置不同网路层协定的网路控制协定(NetworkControlProtocols:NCP)

封装的机制(scheme)是由核心中的驱动程式码来提供。pppd提供基本的LCP,验证(authentication)的支援,以及一个用来建立并配置网际网路协定(InternatProtocol(IP))(叫做IP控制协定,IPCP)的NCP。 

常用选项 FREQUENTLY USED OPTIONS

<tty_name>

在该名称的设备上进行通讯。如果需要的话可以前置一个 "/dev/"字串。如果没有给设备名称,pppd将会使用控制台的终端机(controllingteriminal),并且产生(fork)出来时将不会把自己放到背景去。
<speed>

将波特率设为speed。在像是4.4BSD以及NetBSA的系统上,可以指定任何速率。其他系统(e.g.SunOs)只允许有限的几种速率。
asyncmap <map>

把非同步(async)字元设为对照到。这个对照表描述哪些控制字元不能在串列线路上成功地接收。pppd将会要求彼端以两个位元组的逸出序列(escapesequence)来传送这些字元。其参数是32位元的十六进位数字而每个位元代表一个得避开(escape)的字元。位元0(00000001) 代表字元0x00;位元31(80000000)代表字元0x1f或是^_。如果给了多个asyncmap选项,这些数值会以逻辑的或(OR)合在一起。如果没有给asyncmap选项,将没有非同步字元对照表会被加以协商来导引接收。这样彼端将会避开所有的控制字元。
auth
要求彼端在允许传送或接收网路封包之前先验证它自己。 This option is the default if the system has a default route. If neither this option nor the noauth option is specified, pppd will only allow the peer to use IP addresses to which the system does not already have a route.
call name
Read options from the file /etc/ppp/peers/name. This file may contain privileged options, such as noauth, even if pppd is not being run by root. The name string may not begin with / or include .. as a pathname component. The format of the options file is described below.
connect script

使用以所指定的可执行指令或是shell指令来设定串列线路。这个指令稿一般会使用"chat"程式来拨数据机并开始远端ppp区段作业(session)。 A value for this option from a privileged source cannot be overridden by a non-privileged user.
crtscts
使用硬体流量控制(i.e.RTS/CTS)来控制串列埠上的资料流。 If neither the crtscts, thenocrtscts, the cdtrcts nor the nocdtrcts option is given, the hardware flow control setting for the serial port is left unchanged. Some serial ports (such as Macintosh serial ports) lack a true RTS output. Such serial ports use this mode to implement unidirectional flow control. The serial port will suspend transmission when requested by the modem (via CTS) but will be unable to request the modem stop sending to the computer. This mode retains the ability to use DTR as a modem control line.
defaultroute

当IPCP协商完全成功时,增加一个预设递送路径到系统的递送表,将彼端当作闸道器使用。这个项目在ppp连线中断後会移除。
disconnect script

在pppd已经终结该连线之後执行以所指定的可执行指令或是shell指令。这个指令稿可以用来,例如,如果硬体的数据机控制信号无法使用时,发出指令给数据机使其挂断电话。 The disconnect script is not run if the modem has already hung up. A value for this option from a privileged source cannot be overridden by a non-privileged user.
escape xx,yy,...

指定在传输上确实应该要避开的字元(不管对方是否有用它的非同步控制字元对照表要求避开它们)。这些要被避开的字元是以用逗号隔开的一串十六进位数字指定的。要注意到几乎任何字元都可以用escape选项指定避开,不像asyncmap选项只允许指定控制字元。不能避开的字元是那些有十六进位值0x20-0x3f或是0x5e者。
file name

从档案里读取选项(其格式叙述在後) The file must be readable by the user who has invoked pppd.
init script
Run the executable or shell command specified by script to initialize the serial line. This script would typically use the chat(8) program to configure the modem to enable auto answer. A value for this option from a privileged source cannot be overridden by a non-privileged user.
lock
指定pppd应该在此串列设备上使用UUCP式的锁定以确定对该设备为互斥(exclusive)存取。
mru n
把MRU[MaximumReceiveUnit最大接收单元]的值设为 n来进行协商。pppd将会要求彼端传送不比位元组更长的封包。最小的MRU值是128。预设的MRU值则是 1500。对於慢速线路上的建议值是296(其中40个位元组给TCP/IP表头+256个位元组的资料)。
(Note that for IPv6 MRU must be at least 1280)
mtu n

将MTU[MaximumTransmitUnit最大传输单元]的值设为n。除非彼端经由MRU协商要求一个更小的值,pppd 将会要求核心网路程式码透过PPP网路界面所传送的资料封包不超过n个位元组。
(Note that for IPv6 MTU must be at least 1280)
passive

在LCP中开启"passive"选项。加上这个选项,pppd将会试图初使一个连线;如果没有从彼端接收到回应,那麽 pppd将只会被动地等待从彼端所传来的一个有效LCP封包(代替结束离开,就像它在没有这个选项时所作的)。

选项 OPTIONS

<local_IP_address>:<remote_IP_address>

设定本地以及/或是远端界面的IP位址。两者之中的任何一个都可以省略。该IP位址可以利用主机名称或者是十进位数值加小数点符号指定(e.g.150.234.56.78)。预设的本地位址是系统的(第一个)IP位址(除非有加上 noipdefault选项)。远端位址如果没有在任何选项中指定的话将从彼端取得。因此,在简单的案例中,这个选项不是必须的。如果有一个本地以及/或是远端的IP位址以这个选项加以指定的话,pppd将不会接受在IPCP协商中从彼端所传来不同的值,除非加上ipcp-accept-local 以及/或是ipcp-accept-remote选项,个别地。
ipv6 <local_interface_identifier>,<remote_interface_identifier>
Set the local and/or remote 64-bit interface identifier. Either one may be omitted. The identifier must be specified in standard ascii notation of IPv6 addresses (e.g. ::dead:beef). If the ipv6cp-use-ipaddr option is given, the local identifier is the local IPv4 address (see above). On systems which supports a unique persistent id, such as EUI-48 derived from the Ethernet MAC address, ipv6cp-use-persistent option can be used to replace the ipv6 <local>,<remote> option. Otherwise the identifier is randomized.
active-filter filter-expression
Specifies a packet filter to be applied to data packets to determine which packets are to be regarded as link activity, and therefore reset the idle timer, or cause the link to be brought up in demand-dialling mode. This option is useful in conjunction with the idle option if there are packets being sent or received regularly over the link (for example, routing information packets) which would otherwise prevent the link from ever appearing to be idle. The filter-expression syntax is as described for tcpdump(1), except that qualifiers which are inappropriate for a PPP link, such asether and arp, are not permitted. Generally the filter expression should be enclosed in single-quotes to prevent whitespace in the expression from being interpreted by the shell. This option is currently only available under NetBSD, and then only if both the kernel and pppd were compiled with PPP_FILTER defined.
allow-ip address(es)
Allow peers to use the given IP address or subnet without authenticating themselves. The parameter is parsed as for each element of the list of allowed IP addresses in the secrets files (see the AUTHENTICATION section below).
bsdcomp nr,nt
Request that the peer compress packets that it sends, using the BSD-Compress scheme, with a maximum code size of nr bits, and agree to compress packets sent to the peer with a maximum code size of nt bits. If nt is not specified, it defaults to the value given for nr. Values in the range 9 to 15 may be used for nr and nt; larger values give better compression but consume more kernel memory for compression dictionaries. Alternatively, a value of 0 for nr or nt disables compression in the corresponding direction. Use nobsdcomp or bsdcomp 0 to disable BSD-Compress compression entirely.
cdtrcts
Use a non-standard hardware flow control (i.e. DTR/CTS) to control the flow of data on the serial port. If neither the crtscts, the nocrtscts, the cdtrcts nor thenocdtrcts option is given, the hardware flow control setting for the serial port is left unchanged. Some serial ports (such as Macintosh serial ports) lack a true RTS output. Such serial ports use this mode to implement true bi-directional flow control. The sacrifice is that this flow control mode does not permit using DTR as a modem control line.
chap-interval n

如果有给这个选项,pppd将会每n 秒重新盘查彼端。
chap-max-challenge n

将CHAP盘查(challenge)传输的最大数目设为n(预设为10)。
chap-restart n

将CHAP重新开始的间隔(重新传输的时间限制)设为n 秒钟(预设为3)。
connect-delay n
Wait for up n milliseconds after the connect script finishes for a valid PPP packet from the peer. At the end of this time, or when a valid PPP packet is received from the peer, pppd will commence negotiation by sending its first LCP packet. The default value is 1000 (1 second). This wait period only applies if the connect or ptyoption is used.
debug
递增侦错层级(与-d相同)。如果加上这个选项,pppd 将以可供阅读的格式记录所有传送或接收的控制封包内容。这些封包透过syslog以facilitydaemon还有level debug加以记录。该资讯可以适当设定/etc/syslog.conf 来导向到一个档案去。(参阅syslog.conf(5))。(如果 pppd以开启扩充侦错(extradebugging)编译的话,它将会使用facilitylocal2取代daemon来记录讯息)。
default-asyncmap
Disable asyncmap negotiation, forcing all control characters to be escaped for both the transmit and the receive direction.
default-mru
Disable MRU [Maximum Receive Unit] negotiation. With this option, pppd will use the default MRU value of 1500 bytes for both the transmit and receive direction.
deflate nr,nt
Request that the peer compress packets that it sends, using the Deflate scheme, with a maximum window size of 2**nr bytes, and agree to compress packets sent to the peer with a maximum window size of 2**nt bytes. If nt is not specified, it defaults to the value given for nr. Values in the range 9 to 15 may be used for nr and nt; larger values give better compression but consume more kernel memory for compression dictionaries. Alternatively, a value of 0 for nr or nt disables compression in the corresponding direction. Use nodeflate or deflate 0 to disable Deflate compression entirely. (Note: pppd requests Deflate compression in preference to BSD-Compress if the peer can do either.)
demand
Initiate the link only on demand, i.e. when data traffic is present. With this option, the remote IP address must be specified by the user on the command line or in an options file. Pppd will initially configure the interface and enable it for IP traffic without connecting to the peer. When traffic is available, pppd will connect to the peer and perform negotiation, authentication, etc. When this is completed, pppd will commence passing data packets (i.e., IP packets) across the link.

The demand option implies the persist option. If this behaviour is not desired, use the nopersist option after the demand option. The idle and holdoff options are also useful in conjuction with the demand option.

domain d

新增领域名称到本地主机名称以支援验证。例如,如果gethostname()回应porsche这个名称,但是完整合格的领域名称是porsche.Quotron.COM的话,你可以使用 domain选项来将领域名称设为Quotron.COM。
Pppd would then use the name porsche.Quotron.COM for looking up secrets in the secrets file, and as the default name to send to the peer when authenticating itself to the peer. This option is privileged.
dryrun
With the dryrun option, pppd will print out all the option values which have been set and then exit, after parsing the command line and options files and checking the option values, but before initiating the link. The option values are logged at level info, and also printed to standard output unless the device on standard output is the device that pppd would be using to communicate with the peer.
dump
With the dump option, pppd will print out all the option values which have been set. This option is like the dryrun option except that pppd proceeds as normal rather than exiting.
endpoint <epdisc>
Sets the endpoint discriminator sent by the local machine to the peer during multilink negotiation to <epdisc>. The default is to use the MAC address of the first ethernet interface on the system, if any, otherwise the IPv4 address corresponding to the hostname, if any, provided it is not in the multicast or locally-assigned IP address ranges, or the localhost address. The endpoint discriminator can be the string null or of the form type:value, where type is a decimal number or one of the strings local, IP, MAC, magic, or phone. The value is an IP address in dotted-decimal notation for the IP type, or a string of bytes in hexadecimal, separated by periods or colons for the other types. For the MAC type, the value may also be the name of an ethernet or similar network interface. This option is currently only available under Linux.
hide-password
When logging the contents of PAP packets, this option causes pppd to exclude the password string from the log. This is the default.
holdoff n
Specifies how many seconds to wait before re-initiating the link after it terminates. This option only has any effect if the persist or demand option is used. The holdoff period is not applied if the link was terminated because it was idle.
idle n
Specifies that pppd should disconnect if the link is idle for n seconds. The link is idle when no data packets (i.e. IP packets) are being sent or received. Note: it is not advisable to use this option with the persist option without the demand option. If the active-filter option is given, data packets which are rejected by the specified activity filter also count as the link being idle.
ipcp-accept-local
加上这个选项的话,pppd将会接受彼端对於本地IP位址的意见,即使本地的IP位址已经在某个选项中指定。
ipcp-accept-remote
加上这个选项的话,pppd将会接受彼端对於它的IP位址的意见,即使远端的IP位址已经在某个选项中指定。
ipcp-max-configure n

将IPCP配置要求(configure-request)传输的最大数目设为n(预设为10)。
ipcp-max-failure n
将开始传送配置拒绝(configure-Rejects)之前的IPCP配置未接收(configure-NAKs)的最大数目以取代n(预设为10)。
ipcp-max-terminate n

将IPCP终结要求(terminate-request)传输的最大数目设为 n(预设为3)。
ipcp-restart n

将IPCP重新开始的间隔(重新传输的时间限制)设为n 秒钟(预设为3)。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值