2009年9月11日 星期五

How to use GPRS connect to internet (GPRS)

Linux GPRS Howto 的說明比一些 GPRS Module 的application Notes 還清楚

PDP : packet data protocol. 資料封包 (對應的,語音連線送的是聲音封包)。
APN : Access Point Name。

用minicom 來下 command。要注意 屬於 dialout groupe。

下 AT 回應 OK 代表RS232 線連線 OK. (其實有看到 AT 就代表 正常,因為 AT 也 modem echo back )

下 AT+CPIN? 檢查 pin number 是不是有輸入,回 READY 代表正常。
如果不是,用 AT+CPIN=1234 輸入 pin number (1234)

下 AT+CGATT? 檢查是不是已經attach 到 GPRS network 了,回應 1 是OK。
如果是 0,用 AT+CGATT=1 叫 modem attach。

設定PDP 傳送的 profile,modem 可以設很多 pdp profile,方便user 轉換。
AT+CGDCONT=1,"IP","INTERNET"

* 1 : profile 1
* "IP" : PDP type (ip packet, 好像一定要大寫)
* "INTERNET" : APN (每一家電信公司不一樣)

撥號,GPRS Servie 的 number 固定是:
*99***1#
後面的 " 1" 是 PDP profile 號碼。

ATDT*99***1#
播完號,出現 CONNECT,然後就會看到一堆亂碼。

..到這裡,代表 linux 到 gprs modem 端已經OK了。
接下來設定 linux 的撥接動作。

GPRS Modem 是以 ppp 的方式傳送資料,所以要config ppp。

好像大多數網站都說 wvdial,所以也用wvdial,wvdial 是 ppp 的 front-end,用一個 config 檔而已。

修改 /etc/wvdial.conf:


[Dialer Defaults]
Modem = /dev/ttyS0
Baud = 115200
Init = AT+CGDCONT=1,"IP","INTERNET"
Phone = *99***1#
Username = any
Password = any
Dial Command = ATDT
New PPPD = yes

雖然不檢查username, password,但是還是要填值,否則 wvdial 會 complain。
然後..$ sudo wvdial 就會出現..
$ sudo wvdial
--> WvDial: Internet dialer version 1.60
--> Initializing modem.
--> Sending: AT+CGDCONT=1,"IP","INTERNET"
AT+CGDCONT=1,"IP","INTERNET"
OK
--> Modem initialized.
--> Sending: ATDT*99***1#
--> Waiting for carrier.
ATDT*99***1#
CONNECT
~[7f]}#@!}!}$} }<}!}$}&@}#}$@#}%}&}, Carrier detected. Waiting for prompt.
~[7f]}#@!}!}%} }<}!}$}&@}#}$@#}%}&}, PPP negotiation detected.
--> Starting pppd at Tue Apr 28 11:52:35 2009
--> Pid of pppd: 30572
--> Using interface ppp0
--> local IP address 118.231.153.119
--> remote IP address 192.168.254.254
--> primary DNS address 168.95.1.1
--> secondary DNS address 168.95.192.1

回到gnome-ppp主窗口,隨意填寫用戶名和密碼,然後點擊connect... 等待connect成功...可以在"Detail"中查看
連接情況,,或者使用cat /var/log/messages查看...
應該會出現..

pppd 2.4.4 started by root, uid 0
Using interface ppp0
Connect: ppp0 <--> /dev/ttyACM0
PAP authentication succeeded
local IP address 10.71.102.206
remote IP address 10.6.6.6
primary DNS address 211.136.112.50
secondary DNS address 211.136.20.203
的類似信息...

此時運行sudo ifconfig...應該能夠看到ppp0連接.

5.設置適當的route,使得出去的數據包都通過ppp0設備連接...
可以先使用 sudo ifconfig eth0 down將eth0關閉,然後運行
sudo route add default gw xx.xx.xx.xx(ppp0地址)添加默認路由...

6.運行ping www.google.com或者使用firefox測試能夠上網....

沒有留言:

 Ubuntu has a mechanism, that is, the installed network card (NIC) will be renamed to another name when the system is booted. Although there...