Chinaunix首页 | 论坛 | 博客
  • 博客访问: 640426
  • 博文数量: 404
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1237
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-03 10:45
文章分类

全部博文(404)

文章存档

2017年(1)

2016年(27)

2015年(39)

2014年(55)

2013年(66)

2012年(216)

分类: LINUX

2015-04-13 15:24:43

   这几天做了一下gprs拨号上网,模块是西门子的mc39i。我的系统是fedora core 6。其实很简单,我又有高手指导,:-)。
 
  首先从/usr/share/doc/ppp-2.4.4/scripts中cp ppp-on,ppp-off,ppp-on-dialer三个脚本到/home/a/ppp。然后做如下修改:
在ppp-on里
1.改电话号码为*99***1#
2.将账号与密码清除
3.修改DIALER_SCRIPT的路径为/home/a/ppp/ppp-on-dialer
4.把下设备改成/dev/ttyS0,速率改为115200
5.将crtscts参数去掉,
在ppp-on-dialer里把帐号密码那块去掉。
 
下面是对脚本的一些说明。当然都是网上搜来的了。:-)
 
/home/a/ppp/ppp-on
#!/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/a/ppp/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 modem /dev/ttyS0 115200 \
 asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \
 noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT


exec /usr/sbin/pppd debug lock modem /dev/ttyS0 115200 \
 asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \
 noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT这个命令的作用是:(可以使用man pppd查看帮助)
运行/usr/sbin/pppd程序,给它传入命令行参数的意义是:
/dev/ttyS0: 拨号所用的MODEM所连接的串口(ttyS0是串口1,ttyS1是串口2...)
115200 : MODEM的通信速率(57600 BPS)
modem  : 用MODEM进行拨号。
nocrtscts : 无流控
lock  : 锁定这个设备
debug  :输出调试信息
defaultroute : 此拨号连接作为默认路由
connect /home/a/ppp/ppp-on-dialer:使用/home/a/ppp/ppp-on-dialer进行拨号

 

/home/a/ppp/ppp-on-dialer
#!/bin/sh
#
# This is part 2 of the ppp-on script. It will perform the connection
# protocol for the desired connection.
#
exec chat -v      \
 TIMEOUT  3    \
 ABORT  '\nBUSY\r'   \
 ABORT  '\nNO ANSWER\r'   \
 ABORT  '\nRINGING\r\n\r\nRINGING\r' \
 ''  \rAT    \
 'OK-+++\c-OK' ATH0    \
 TIMEOUT  30    \
 OK  AT+IPR=115200   \
 OK  AT+CGDCONT=1,"IP","CMNET"   \
 OK  AT+CGACT=1,1   \
 OK  ATDT*99***1#   \
 CONNECT  ''    \
# ogin:--ogin: $ACCOUNT   \
# assword: $PASSWORD
chat命令的帮助请参考man -a chat查看。
ABORT BUSY
ABORT ERROR
ABORT NO CARRIER
ABORT NO DIALTONE
ABORT RING
<--------如果遇到MODEM回应"BUSY","ERROR","NO CARRIER","NO DIALTONE"则立即报错并退出拨号。
"" AT

<--------外送"AT"命令。

OK  AT+IPR=115200

<--------设置波特率。
"OK" "AT+CGDCONT=1,“ip”,“cmnet”

<---当判到“OK"回应时,外送AT+CGDCONT=1,"ip","cmnet" 命令。设置GPRS接人网关。其中CMNET为移动梦网的接人网关
OK  AT+CGACT=1,1
<--------激活GPRS功能,如果返回OK,则GPRS连接成功;如果返回ERROR则意味着GPRS失败。这时候应该检查一下SIM卡的GPRS业务是否已经开通,GPRS模块天线是否安装正确等问题。
"OK" "ATDT*99***1#"
<---当判到“OK"回应时,外送拨号ATDT*99***1# 命令。
"CONNECT"
<---当判到“CONNECT"回应时,拨号结束,程序退出。
 
/home/a/ppp/ppp-off

#!/bin/sh
##############################################
# Determine the device to be terminated.
#
if [ "$1" = "" ]; then
 DEVICE=ppp0
else
 DEVICE=$1
fi
###############################################
# 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
阅读(588) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~