准备一个3G modem
首先,你需要找一个2G或3G的USB modem。这个在淘宝上花200左右就能买到。我手边用的是Huawei E1750 WCDMA的modem。
一般modem会自带Windows的拨号上网程序,用oFono就可以在Linux下拨号上网了。
GPRS上网
1. 启动ofono
sudo src/ofonod –nd ‘*’
2. 把猫插入USB口,ofono会自动检测到modem
ofonod[2667]: src/modem.c:ofono_modem_create() name: (null), type: huawei
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property Path
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property Registered
ofonod[2667]: plugins/udev.c:add_modem() /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/ttyUSB0/tty/ttyUSB0 (huawei)
ofonod[2667]: plugins/udev.c:add_huawei() modem 0x9f82b40
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property ModemRegistered
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property PcuiRegistered
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property Modem
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property ModemRegistered
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property Path
ofonod[2667]: plugins/udev.c:add_modem() /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.1/ttyUSB1/tty/ttyUSB1 (huawei)
ofonod[2667]: plugins/udev.c:add_huawei() modem 0x9f82b40
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property ModemRegistered
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property PcuiRegistered
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property Path
ofonod[2667]: plugins/udev.c:add_modem() /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.2/ttyUSB2/tty/ttyUSB2 (huawei)
ofonod[2667]: plugins/udev.c:add_huawei() modem 0x9f82b40
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property ModemRegistered
ofonod[2667]: src/modem.c:get_modem_property() modem 0x9f82b40 property PcuiRegistered
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property Pcui
ofonod[2667]: src/modem.c:set_modem_property() modem 0x9f82b40 property PcuiRegistered
ofonod[2667]: plugins/huawei.c:huawei_probe() 0x9f82b40
3. ofono/test/list-modems
xxx@xxx:~/ofono/test$ ./list-modems
[ /huawei0 ]
Interfaces =
Powered = 0
Features =
Online = 0
4. ./enable-modem /huawei0; ./online-modem /huawei0。从oFono的console你能看到很多log,ofono会初始化modem的各个部分。接下来,让我们看看GPRS部分吧。
5. 你需要先建一个GPRS context, 并设置APN网关。因为我用的是联通的SIM卡,APN是uninet,如果是移动的话,APN用cmnet或者cmwap。
xxx@xxx:~/ofono/test$ ./create-context uninet
Setting APN of /huawei0/context1 to uninet
6. ./list-contexts
xxx@xxx:~/ofono/test$ ./list-contexts
[ /huawei0 ]
[ /huawei0/context1 ]
Username =
Protocol = ip
Name = Internet
Settings = { }
Active = 0
AccessPointName = uninet
Password =
Type = internet
7. ./activate-context. 这是oFono console会有这样的output:
ofonod[2830]: Modem:> AT+CGDCONT=1,"IP","uninet"/r
ofonod[2830]: Modem:< /r/nOK/r/n
ofonod[2830]: Modem:> AT+CGDATA="PPP",1/r
ofonod[2830]: Modem:< /r/nCONNECT/r/n
Entering new phase: 1
Entering new phase: 2
Entering new phase: 3
Received IPCP NAK
Setting suggested dns1
Setting suggested dns2
Setting suggested nbns1
Setting suggested nbns2
Received IPCP NAK
Setting suggested ip addr
Setting suggested dns1
Setting suggested dns2
Entering new phase: 4
8. ./list-contexts会显示已经建立了ppp0 interface。配置好路由后就可以上网了。
xxx@xxx:~/ofono/test$ ./list-contexts
[ /huawei0 ]
[ /huawei0/context1 ]
Username =
Protocol = ip
Name = Internet
Settings = { Interface=ppp0 Netmask=255.255.255.255 Method=static DomainNameServers=221.12.1.227,221.12.33.227, Address=172.18.172.196 }
Active = 1
AccessPointName = uninet
Password =
Type = internet
9. 编辑/etc/resolv.conf, 加入DNS服务器地址
nameserver 221.12.1.227
nameserver 221.12.33.227
10. 配置网络
xxx@xxx:/home/xxx/ofono# sudo ifconfig ppp0 172.18.172.196 netmask 255.255.255.255
xxx@xxx:/home/xxx/ofono# sudo ifconfig ppp0 up
xxx@xxx:/home/xxx/ofono# sudo ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:872 errors:0 dropped:0 overruns:0 frame:0
TX packets:872 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:59538 (59.5 KB) TX bytes:59538 (59.5 KB)
ppp0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:172.18.172.196 P-t-P:172.18.172.196 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:177 (177.0 B) TX bytes:2380 (2.3 KB)
xxx@xxx:/home/xxx/ofono# ping www.google.com
PING www-g-com-chn.l.google.com (66.249.89.104) 56(84) bytes of data.
64 bytes from nrt04s01-in-f104.1e100.net (66.249.89.104): icmp_seq=1 ttl=51 time=207 ms
64 bytes from nrt04s01-in-f104.1e100.net (66.249.89.104): icmp_seq=2 ttl=51 time=186 ms
^C
--- www-g-com-chn.l.google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 186.073/196.811/207.549/10.738 ms
恭喜,你可以通过3G卡上网了!;-)