Linux的GPRS modem上网连接设置
为了让我们的彩信应用在Linux小机上运行起来,实现彩信的收发,就需要在Linux上实现GPRS modem的拨号上网,通过PPP拨号建立和WAP服务器的连接。查了些资料后,没遇到多少麻烦就实现了PPP拨号上网,在此
记录
混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载
以作备忘。
我们是使用一个可以接受AT命令的GPRS手机作GPRS的modem,其通过USB线和Linux小机通讯(串口线也是一样的),将其和小机连接后将出现一个ttyUSB0的设备,用如下命令对这个设备做一个链接:
ln -s /dev/ttyUSB0 /dev/gprsmodem
这些做好后,编写一个名为gprs的pppd拨号配置文件,保存到目录/etc/ppp/peers下,其内容如下所示:
user wap
password wap
defaultroute "/dev/gprsmodem"
connect "/usr/sbin/chat -v -f /etc/ppp/gprsmodem.chat"
debug
kdebug 4
ipcp-no-addresses
noipdefault
noauth
novj
noccp
然后编写一个名为gprsmodem.chat的chat会话文件,保存到目录/etc/ppp下,内容如下所示:
'ABORT' 'BUSY'
'ABORT' 'ERROR'
'ABORT' 'NO ANSWER'
'ABORT' 'NO CARRIER'
'ABORT' 'NO DIALTONE'
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
'' 'ATZ'
'TIMEOUT' '10'
'OK' 'AT+CGDCONT=1,"IP","CMWAP"'
# 'OK' 'AT+CGQREQ=1,0,0,0,0,0' // 这两行根据使用的模组来确定
# 'OK' 'AT+CGQMIN=1,0,0,0,0,0' // 是否需要和具体的数值
'OK' 'ATD*99***1#'
'CONNECT' ''
之后,用如下命令即可进行PPP拨号上网了。
pppd call gprs
此命令完成后,使用如下命令是否拨号成功和查看分配的IP地址。
ifconfig
若拨号不成功,使用如下命令查看log信息查找原因,一般都可以找到。
vim /var/log/messages
另外,若内核没有PPP拨号相关的模块,则按如下方式配置PPP相关的内核选项,重新编译内核和模块,才能进行PPP拨号。
CONFIG_PPP=m
# CONFIG_PPP_MULTILINK is not set
CONFIG_PPP_FILTER=y
CONFIG_PPP_ASYNC=m
CONFIG_PPP_SYNC_TTY=m
CONFIG_PPP_DEFLATE=m
CONFIG_PPP_BSDCOMP=m
# CONFIG_PPPOE is not set
Linux系统ppp-on脚本进行GPRS拨号上网
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函数的
说明书
房屋状态说明书下载罗氏说明书下载焊机说明书下载罗氏说明书下载GGD说明书下载
有一点要提醒的是,在利用EXEC的时候,原进程会湮灭,而只有所执行程序的进行在运行,因此,如果想保留原进程,我采用的方法是利用fork函数,在子进程中执行脚本,而在父进程中执行自己的程序即可
redhat下搞定红外线/GPRS/WAP代理上网
作者:chinaboy
笔记本:IBM THINKPAD 570E
手机: 三菱M320
一、硬件设定。
开机,按F1进BIOS,enable serial port,enable infrared。
二、安装irda-utils0.9.14
下载地址:http://sourceforge.net/project/showf...?group_id=5616
解压--- -./configure ------ make all -----make install
三、编辑红外脚本myirda
vi myirda
内容如下:
#!/bin/sh
#Start up the IrDA process and load necessary modules
#
case "$1" in
start)
#Start IRDA
echo -n "Starting up the IR modules"
modprobe irda
modprobe ircomm
modprobe ircomm-tty
irattach /dev/ttyS1 -s
echo "Done."
echo ""
;;
stop)
#KILL IRDA
echo -n "Stopping IRDA and removing used modules"
#Kill the irattach process and remove the modules
killall -9 irattach
rmmod ircomm-tty ircomm irda
echo "Done."
echo ""
;;
*)
echo "Usage:irdastart.sh{start|stop}"
echo ""
exit 1
esac
exit 0
保存
chmod 755 myirda
chmod 755 /dev/ircomm0
开启:
./myirda start
关闭:
./myirda stop
四、测试:
打开手机红外线,对准接收窗口,./myirda start,运行irdadump命令,应该有数据显示,否则红外设置不成功。
五、建立拨号连接:
我用gnome,
系统工具----互联网配制向导-----调制解调器连接
建立MODEM如下图:
INCLUDEPICTURE "http://linux.chinaitlab.com/UploadFiles_7565/200601/20060104102528481.jpg" \* MERGEFORMATINET
图1
配制连接如下图:
图2
图3
拨号:
ifup ppp0
在opera中设置代理服务器: http 10.0.0.172:80
可以上网浏览了^_^