#
# If the ppp0 pid file is present then the program is running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
kill -INT `cat /var/run/$DEVICE.pid`
#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
if [ ! "$?" = "0" ]; then
rm -f /var/run/$DEVICE.pid
echo "ERROR: Removed stale pid file"
exit 1
fi
#
# Success. Let pppd clean up its own junk.
echo "PPP link to $DEVICE terminated."
exit 0
fi
#
# The ppp process is not running for ppp0
echo "ERROR: PPP link is not active on $DEVICE"
exit 1
做好上面的配置以後,輸入pppd call gprs命令,注意如果你的gprs這個檔案不在/etc/ppp/peers/目錄下,在給出標註路徑給pppd[root@localhost ppp_scripts]# pppd call gprs
timeout set to 15 seconds
abort on (/nBUSY/r)
abort on (/nNO ANSWER/r)
abort on (/nRINGING/r/n/r/nRINGING/r)
timeout set to 40 seconds
send (^MAT^M^M)
expect (OK)
^M^M
OK
-- got itsend (ATS0=0^M^M)
expect (OK)
^M
AT^M
OK
-- got itsend (ATE0V1^M^M)
expect (OK)
^M
^M^M
OK
-- got itsend (AT+CGDCONT=1,"IP","CMNET"^M^M)
expect (OK)
^M
ATS0=0^M^M
OK
-- got itsend (ATDT*99***1#^M^M)
expect (CONNECT)
^M
^M^M
OK^M
ATE0V1^M^M
OK^M
^M
OK^M
^M
OK^M
^M
OK^M
^M
CONNECT
-- got itsend (^M)
Serial connection established.
using channel 20
Using interface ppp0
Connect: ppp0 <--> /dev/ttyS0
Warning - secret file /etc/ppp/pap-secrets has world and/or group access
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x60eeae90> <pcomp> <accomp>]
rcvd [LCP ConfRej id=0x1 <magic 0x60eeae90>]
sent [LCP ConfReq id=0x2 <asyncmap 0x0> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x2 <asyncmap 0x0> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <auth chap MD5> <pcomp> <accomp>]
sent [LCP ConfAck id=0x1 <asyncmap 0x0> <auth chap MD5> <pcomp> <accomp>]
rcvd [CHAP Challenge id=0x1 <9da6cccb51534834ab1f037118ab33455632736e8a763a6e206b1f1666a4cfd7e881cac88916>, name = ""]
Warning - secret file /etc/ppp/chap-secrets has world and/or group access
sent [CHAP Response id=0x1 <da093b418f6931ac976e9481ce6f49c4>, name = "smsong"]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 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 ProtRej id=0x1 80 fd 01 01 00 0c 1a 04 78 00 18 04 78 00]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfNak id=0x1 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfAck id=0x2]
rcvd [IPCP ConfNak id=0x2 <addr 10.144.202.159> <ms-dns1 211.138.200.69> <ms-dns3 211.103.13.101>]
sent [IPCP ConfReq id=0x3 <addr 10.144.202.159> <ms-dns1 211.138.200.69> <ms-dns3 211.103.13.101>]
rcvd [IPCP ConfAck id=0x3 <addr 10.144.202.159> <ms-dns1 211.138.200.69> <ms-dns3 211.103.13.101>]
Could not determine remote IP address: defaulting to 10.64.64.64
local IP address 10.144.202.159
remote IP address 10.64.64.64
primary DNS address 211.138.200.69
secondary DNS address 211.103.13.101
Script /etc/ppp/ip-up started (pid 4578)
Script /etc/ppp/ip-up finished (pid 4578), status = 0x0使用ctrl+c可以中斷連線,這樣一般不太好測試是不是串連上了(遇有開發不上的控制台只有一個的原因),可以去掉/etc/ppp /peers/gprs檔案中的nodetach參數,要用ping,你需要將eth0即網口給禁用掉,這樣ping才會通過ppp0連接埠尋找路由串連外網。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
可以用命令tail -f /var/log/messages看到日誌:Mar 20 20:55:55 localhost pppd[4557]: pppd 2.4.4 started by root, uid 0
Mar 20 20:55:56 localhost chat[4558]: timeout set to 15 seconds
Mar 20 20:55:56 localhost chat[4558]: abort on (/nBUSY/r)
Mar 20 20:55:56 localhost chat[4558]: abort on (/nNO ANSWER/r)
Mar 20 20:55:56 localhost chat[4558]: abort on (/nRINGING/r/n/r/nRINGING/r)
Mar 20 20:55:56 localhost chat[4558]: timeout set to 40 seconds
Mar 20 20:55:56 localhost chat[4558]: send (^MAT^M^M)
Mar 20 20:55:56 localhost chat[4558]: expect (OK)
Mar 20 20:55:56 localhost chat[4558]: ^M^M
Mar 20 20:55:56 localhost chat[4558]: OK
Mar 20 20:55:56 localhost chat[4558]: -- got it
Mar 20 20:55:56 localhost chat[4558]: send (ATS0=0^M^M)
Mar 20 20:55:56 localhost chat[4558]: expect (OK)
Mar 20 20:55:56 localhost chat[4558]: ^M
Mar 20 20:55:56 localhost chat[4558]: AT^M
Mar 20 20:55:56 localhost chat[4558]: OK
Mar 20 20:55:56 localhost chat[4558]: -- got it
Mar 20 20:55:56 localhost chat[4558]: send (ATE0V1^M^M)
Mar 20 20:55:56 localhost chat[4558]: expect (OK)
Mar 20 20:55:56 localhost chat[4558]: ^M
Mar 20 20:55:56 localhost chat[4558]: ^M^M
Mar 20 20:55:56 localhost chat[4558]: OK
Mar 20 20:55:56 localhost chat[4558]: -- got it
Mar 20 20:55:56 localhost chat[4558]: send (AT+CGDCONT=1,"IP","CMNET"^M^M)
Mar 20 20:55:57 localhost chat[4558]: expect (OK)
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: ATS0=0^M^M
Mar 20 20:55:57 localhost chat[4558]: OK
Mar 20 20:55:57 localhost chat[4558]: -- got it
Mar 20 20:55:57 localhost chat[4558]: send (ATDT*99***1#^M^M)
Mar 20 20:55:57 localhost chat[4558]: expect (CONNECT)
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: ^M^M
Mar 20 20:55:57 localhost chat[4558]: OK^M
Mar 20 20:55:57 localhost chat[4558]: ATE0V1^M^M
Mar 20 20:55:57 localhost chat[4558]: OK^M
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: OK^M
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: OK^M
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: OK^M
Mar 20 20:55:57 localhost chat[4558]: ^M
Mar 20 20:55:57 localhost chat[4558]: CONNECT
Mar 20 20:55:57 localhost chat[4558]: -- got it
Mar 20 20:55:57 localhost chat[4558]: send (^M)
Mar 20 20:55:57 localhost pppd[4557]: Serial connection established.
Mar 20 20:55:57 localhost pppd[4557]: Using interface ppp0
Mar 20 20:55:57 localhost pppd[4557]: Connect: ppp0 <--> /dev/ttyS0
Mar 20 20:55:58 localhost pppd[4557]: Warning - secret file /etc/ppp/pap-secrets has world and/or group access
Mar 20 20:56:00 localhost pppd[4557]: Warning - secret file /etc/ppp/chap-secrets has world and/or group access
Mar 20 20:56:00 localhost pppd[4557]: CHAP authentication succeeded
Mar 20 20:56:00 localhost pppd[4557]: CHAP authentication succeeded
Mar 20 20:56:01 localhost kernel: PPP Deflate Compression module registered
Mar 20 20:56:02 localhost pppd[4557]: Could not determine remote IP address: defaulting to 10.64.64.64
Mar 20 20:56:02 localhost pppd[4557]: local IP address 10.144.202.159
Mar 20 20:56:02 localhost pppd[4557]: remote IP address 10.64.64.64
Mar 20 20:56:02 localhost pppd[4557]: primary DNS address 211.138.200.69
Mar 20 20:56:02 localhost pppd[4557]: secondary DNS address 211.103.13.101++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0A:EB:91:3B:C4
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:209 Base address:0x4000lo 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:1240 errors:0 dropped:0 overruns:0 frame:0
TX packets:1240 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2039094 (1.9 MiB) TX bytes:2039094 (1.9 MiB)ppp0 Link encap:Point-to-Point Protocol
inet addr:10.144.202.159 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:62 (62.0 b) TX bytes:98 (98.0 b)[root@localhost ~]# ifconfig eth0 down
禁用乙太網路介面eth0,使得不和ppp0介面使用時候的路由衝突
[root@localhost ~]# ping 211.136.20.203
PING 211.136.20.203 (211.136.20.203) 56(84) bytes of data.
64 bytes from 211.136.20.203: icmp_seq=1 ttl=247 time=3379 ms
64 bytes from 211.136.20.203: icmp_seq=2 ttl=247 time=2388 ms
64 bytes from 211.136.20.203: icmp_seq=3 ttl=247 time=2892 ms
64 bytes from 211.136.20.203: icmp_seq=4 ttl=247 time=1952 ms
64 bytes from 211.136.20.203: icmp_seq=5 ttl=247 time=1692 ms
64 bytes from 211.136.20.203: icmp_seq=6 ttl=247 time=2112 ms
64 bytes from 211.136.20.203: icmp_seq=7 ttl=247 time=1492 ms
64 bytes from 211.136.20.203: icmp_seq=8 ttl=247 time=1472 ms--- 211.136.20.203 ping statistics ---
9 packets transmitted, 8 received, 11% packet loss, time 7999ms
rtt min/avg/max/mdev = 1472.094/2172.525/3379.568/638.150 ms, pipe 4這個時候如果你只能ping純的ip地址,而不能解析網域名稱,這個時候你可能需要將/etc/ppp/resolv.conf(內容被新獲得的 dns取代)內容拷貝到/etc/resolv.conf中或者做一個到/etc/resolv.conf的連結。這樣就可以ping網域名稱和在瀏覽器中開啟網頁啦。[root@localhost ~]# ping www.linuxidc.net
PING www.6688.cc (202.108.22.5) 56(84) bytes of data.
64 bytes from 202.108.22.5: icmp_seq=1 ttl=50 time=3142 ms
64 bytes from 202.108.22.5: icmp_seq=2 ttl=50 time=3348 ms
64 bytes from 202.108.22.5: icmp_seq=3 ttl=50 time=2796 ms
64 bytes from 202.108.22.5: icmp_seq=4 ttl=50 time=3632 ms
64 bytes from 202.108.22.5: icmp_seq=5 ttl=50 time=1936 ms
64 bytes from 202.108.22.5: icmp_seq=7 ttl=50 time=909 ms
64 bytes from 202.108.22.5: icmp_seq=6 ttl=50 time=1951 ms
64 bytes from 202.108.22.5: icmp_seq=8 ttl=50 time=2839 ms
64 bytes from 202.108.22.5: icmp_seq=9 ttl=50 time=1984 ms
64 bytes from 202.108.22.5: icmp_seq=10 ttl=50 time=2404 ms
64 bytes from 202.108.22.5: icmp_seq=11 ttl=50 time=1417 ms--- www.6688.cc ping statistics ---
12 packets transmitted, 11 received, 8% packet loss, time 13806ms
rtt min/avg/max/mdev = 909.082/2396.720/3632.981/803.194 ms, pipe 4
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
另外,如果你希望一開機就可以自動撥接,只要在自己的開機啟動指令碼(我的開發板上是/etc/init.d/rcS,在pc上有好幾個如:/etc /rc.local檔案,做連結到cd /etc/rcN.d,N的選擇看啟動並執行層級)裡面加上如下的語句,注意這個指令碼裡面的可執行程式給出的必須是據對路徑,因為剛開機嘛,整個機子的環境變數還沒有設定好。 還有不要在新加入的命令後面加&使得其變成後台進程,它會周期性執行,會出錯!添加的幾條shell語句如下:
/etc/ppp/rmlock #簡單的一個判斷並刪除無效的串口的lock檔案,保證成功撥號
/usr/bin/pppd call gprs #自動撥號
/usr/bin/sleep 20 #給它20s的撥號時間,看你的模組撥通的情況了。
/bin/qtopia & #這個是原來指令碼裡面有的,把它的順序安排在這個位置,是為了在看到qt介面啟 #動以後,真好gprs撥號已經建立號,也就可以上網了。
/sbin/ifconfig eth0 down #順便開機禁用eth0網口註:rmlock檔案
#/etc/ppp/rmlock file
#!/bin/sh
if [ -f /var/lock/LCK..s3c2410_serial1 ]; then
/bin/rm -f /var/lock/LCK..s3c2410_serial1
fi
如何解決pppd 啟動並執行段錯誤:
當你手動中斷ppp連結次數過多後,可能回出現pppd啟動並執行段錯誤,The suggestion from debian bug report solves this problem. It is pretty straightforward: Simply delete /var/run/pppd.tdb file (in my system, it is /var/run/pppd2.tdb).總結:根據自己的環境和喜好選用其中一種撥號方式,wvdial的方式移植到arm開發板的時候,交叉編譯的時候出錯很多,可以試試,相對比較麻煩,而其它運行需要wvstreams的庫的支援,佔用空間大。第2中方式最常用,但是出錯的可能性比較大,原因使其比較靈活,第3中跟第2中方式類似。在出錯的時候可以到google上搜尋同樣的錯誤現象,參考並修改自己的參數,再分析嘗試,只要堅持到底,才會真有收穫!當時你要沒有什麼時間了也不想學習ppp的內部撥號機制,建議用windows把,那個封裝的很好。穩定可靠!呵呵祝:ppp&Linux撥號的朋友好運!