Saturday, February 14, 2009

Debian 下使用Nokia手机作为modem上网

我使用的是N73, 其他的Nokia手机方法应该是类似的.

第一步, 将数据线连接至PC, 然后在手机上选择PC套件, 这时通过在PC上通过dmesg应该可以看到kernel已经检测到数据线的插入, 并已经自动load usbseria module.

第二步, 此时检查一下 /dev/ttyACM0 (我这里是ACM0, 但也许是USB0或者其它)是否已经建立, 这个在dmesg中应该也可以看到.

第三步, 可以通过minicom连接至ttyACM0, 输入一个简单的AT cmd, 比如就输入AT, 看看是否返回OK. 没什么问题的话, 可以退出minicom. 这步只是验证一下手机是否连好, 可以忽略.

第四步, 准备建立ppp相关的配置文件了, 首先在 /etc/ppp/peer 下面建立一个 nokia-provider 文件, 内容如下:

/dev/ttyACM0
debug
connect '/usr/sbin/chat -v -f /etc/ppp/peers/connect-chat'
disconnect '/usr/sbin/chat -v -f /etc/ppp/peers/disconnect-chat'
460800
crtscts # hardware flow control for cable
local
lcp-echo-failure 0
lcp-echo-interval 0
:0.0.0.0
noipdefault # pppd must not propose any IP address to the peer!
ipcp-accept-local # Accept peers idea of our local address
defaultroute # Add the ppp interface as default route to the IP routing table
usepeerdns # User DNS returned by server
noauth # The phone is not required to authenticate
noipv6
novj
nobsdcomp
novjccomp
nopcomp
noaccomp
persist # Persistent connection
maxfail 99999 # Retry and retry and retry if failed...

然后再建立一个文件 connect-chat, 内容如下:
TIMEOUT 10
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
'' \rAT
TIMEOUT 12
OK ATE1
OK 'AT+cgdcont=1,"IP","CMWAP","",0,0'
OK ATD*99***1#
CONNECT

注意我这里填的是CMWAP, 如果你的运营商给你开通了CMNET, 你也可以填写CMNET, 使用CMWAP上网的话, 还必须给浏览器添加网关, 这个后面会说.

然后再添加 disconnect-chat 文件:
#!/bin/sh
# send break exec /usr/sbin/chat -V -s -S \
ABORT "BUSY" \
ABORT "ERROR" \
ABORT "NO DIALTONE" \
SAY "\nSending break to the modem\n" \
"" "\K" \
"" "\K" \
"" "\K" \
"" "\d\d+++\d\dATH" \
SAY "\nPDP context detached\n"

第五步, 输入 pon nokia-provider, 这样就启动pppd了. 不用多久 通过ifconfig应该就可以看到ppp0, 注意那个"P-t-P:10.6.6.6", 此时要添加一个默认网关: route add default gw 10.6.6.6.
OK 现在你的debian就可以通过nokia手机上网了, 注意看手机屏幕, 你的GPRS连接应该已经连上了.

第六步, 之前提到过的, 如果使用APN是CMWAP, 那么, 在通过浏览器访问网站时, 还必须设置代理服务器为10.0.0.172, 这是中国移动提供的网关, 开启的端口很少, 我只用了80, 其他未测试过.

参考:
http://users.utu.fi/tmwire/nokia_n73_linux.html

No comments: