Linux下撥號採用的是PPP協議,這與windows是一致的.
只是windows下採用撥號程式對協議用圖形化介面加以封裝,因此我們在撥號時不易察覺.
而在Linux下,采利用的是pppd程式,因此較windows而言能理解的更清楚.
Linux下的GUI撥號程式是KPPP,其實也是將pppd加以封裝而已.
在Linux下撥號採用的指令碼為ppp-on,ppp-on-dialer,ppp-off
在預設安裝的RH9下可以在/usr/share/doc/ppp/script下找到這三個指令碼
這三個指令碼原本是用來為普通的數據機作撥號指令碼的,
我們可以利用這三個指令碼做一定的修改,即可實現ppp撥號GPRS上網.
撥號原理為:
初始化模組,主要是設定APN:CMNET
at+cgdcont=1,ip,cmnet
然後利用chat程式撥號*99***1#
待撥號連線成功後,由pppd將建立通訊鏈路即可.
指令碼改動如下:
在ppp-on裡改了電話號碼為*99***1#
將帳號與密碼清除,
改了DIALER_SCRIPT的路徑
把下面的裝置改成/dev/ttyS0,速率改為19200
將crtscts參數去掉,
在ppp-on-dialer裡把帳號密碼去掉
改動後的指令碼如下:
#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command. However, it is simple.
#
# These are the parameters. Change as needed.
TELEPHONE=*99***1# # The telephone number for the connection
ACCOUNT= # The account name for logon (as in 'George Burns')
PASSWORD= # The password for this account (and 'Gracie Allen')
LOCAL_IP=0.0.0.0 # Local IP address if known. Dynamic = 0.0.0.0
REMOTE_IP=0.0.0.0 # Remote IP address if desired. Normally 0.0.0.0
NETMASK=255.255.255.0 # The proper netmask if needed
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE ACCOUNT PASSWORD
#
# This is the location of the script which dials the phone and logs
# in. Please use the absolute file name as the $PATH variable is not
# used on the connect option. (To do so on a 'root' account would be
# a security hole so don't ask.)
#
DIALER_SCRIPT=/home/testBoot/ppp/ppp-on-dialer#存放ppp-on-dialer的路徑
#
# Initiate the connection
#
# I put most of the common options on this command. Please, don't
# forget the 'lock' option or some programs such as mgetty will not
# work. The asyncmap and escape will permit the PPP link to work with
# a telnet or rlogin connection. You are welcome to make any changes
# as desired. Don't use the 'defaultroute' option if you currently
# have a default route to an ethernet gateway.
#
exec /usr/sbin/pppd debug lock nocrtscts modem /dev/ttyS0 19200 /
asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP /
noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT
在改動完成後,執行指令碼ppp-on
./ppp-on
即可撥接
如要自己寫程式來執行此指令碼的話,則利用EXEC函數即可,至於EXEC的具體用法,可參閱C函數的說明書
有一點要提醒的是,在利用EXEC的時候,原進程會湮滅,而只有所執行程式的進行在運行,因此,如果想保留原進程,我採用的方法是利用fork函數,在子進程中執行指令碼,而在父進程中執行自己的程式即可