Using pppd to connect using bluetooth 3G/GPRS in Linux is quite a challenge for
ordinary Linux user. In this post, I explain how I got it working on my system.
This is my system configuration:
- OS: Slamd64 12.1. An x86_64 Unofficial Port of Slackware Linux Distribution
with kernel 2.6.25.17 and pppd version 2.4.4
- A Turion64 Laptop with 1GB RAM.
- Broadcom BCM2045A Bluetooth USB adapter.
- Nokia E61 acting as a modem.
As a test case in configuring the system, I will try to connect to the network
for UIM registration purposes.
The relevant configuration files are:
- /etc/ppp/chap-secrets
- /etc/ppp/pap-secrets
- /etc/ppp/options
- /etc/ppp/peers/_your_ppp_extra_config_
- /etc/ppp/_your_chat_script_
- /etc/ppp/ip-up
- /etc/ppp/ip-down
The chap-secrets and pap-secrets contains the username and password to
authenticate yourself to the ppp peer/server. It has to be modified to suit your need.
The options file contains the default options for all connections which will
be made by pppd. You should place your connection specific options in a custom file
in /etc/ppp/peers directory and invoke it with:
pppd call _your_ppp_extra_config_
This will initiate the ppp connection to the peer.
You will need the chat script to talk to your modem. The ip-up and ip-down
scripts are optional. I am using it to update the nameserver configuration after the
IP connection through ppp established.
These are the options configured in my /etc/ppp/options file:
asyncmap 0
crtscts
lock
modem
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4
Opening the pppd man pages should help you to understand those options.
Now, my ppp extra configuration file is /etc/ppp/peers/im2.
I'm using the following command to dial into my 3G/GPRS ISP using this file
(dialing should be done as root):
pppd call im2
The contents of /etc/ppp/peers/im2 as follows:
/dev/rfcomm0 crtscts 115200
connect 'chat -v -f /etc/ppp/chat/im2_chat'
defaultroute name indosatm2 noipdefault usepeerdns idle 0
Actually, this file contains commands and options passed to pppd when I call it
in the shell dump shown above. This is the breakdown:
- /dev/rfcomm0 is the modem I'm using in this ppp session.
- crtscts means use hardware flowcontrol in this ppp session.
- 115200 is the baud rate at which I'm connecting.
- 115200 is the baud rate at which I'm connecting.
- The connect 'chat -v -f /etc/ppp/chat/im2_chat'
means invoke the chat program with the /etc/ppp/chat/im2_chat
as the chat file. The chat file is used to initialize the modem and
waiting for connection string from the ISP.
- defaultroute means add a default route to the system routing tables
when the ppp connection established.
- name indosatm2 directs pppd to find an entry in either /etc/ppp/chap-secrets
or /etc/ppp/pap-secrets which corresponds to indosatm2 as the login/user
name for the connection.
- noipdefault enforce the peer/server to supply the IP address during IPCP negotiation when pppd
tries to establish the connection.
- usepeerdns asks the peer for upto two DNS server addresses.
- idle 0 is an optional parameter which means pppd should disconnect if the ppp link is idle for the
requested amount of time (in seconds).
At this point the file used to dial the ppp server is clear. To check the current status while you are dialling
the ppp server, you can use:
tail -f /var/log/messages
and then checking your network interface when the IP connection has been established with ifconfig.
If ifconfig shows something like:
root@konoha:~ # ifconfig
ppp0 Link encap:Point-to-Point Protocol
inet addr:114.58.67.148 P-t-P:10.6.6.6 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:229 errors:0 dropped:0 overruns:0 frame:0
TX packets:229 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:271660 (265.2 KiB) TX bytes:13892 (13.5 KiB)
Then the ppp connection has been established correctly.
Now, let's move to the chat script.
Read the chat man pages for the details. This is my chat script (/etc/ppp/chat/im2_chat).
ECHO ON
ABORT 'NO CARRIER'
ABORT 'NO DIALTONE'
ABORT 'ERROR'
ABORT 'NO ANSWER'
ABORT 'BUSY'
'' ATZ
OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'
OK 'AT+IFC=2,2;+CVHU=1'
OK 'ATS7=60+DS=3,0;&K3'
OK 'AT+CGDCONT=1,"IP","indosatm2"'
OK 'ATS0=0'
OK 'ATDT*99#'
~
As you can see, Nokia E61 when used as modem requires quite a lot of initialization strings.
Again, read the chat man pages for the details.
The secrets files are shown below. I provided them here because the login is a universal way
to register the UIM of any user of the Indosat IM2 broom user which pose no security risks to me.
This is the /etc/ppp/chap-secrets file:
# Secrets for authentication using CHAP
# client server secret IP addresses
indosatm2 * prabayar
and this is the /etc/ppp/pap-secrets file:
# Secrets for authentication using PAP
# client server secret IP addresses
indosatm2 * prabayar
That's it, the secrets file needed to login to register an Indosat IM2 broom 3G/GPRS package.
Note that indosatm2 is the login and prabayar is the password.
I have added new (previously non-existent in default pppd installation) ip-up and ip-down
scripts to handle the name resolution chores once the IP connection through the ppp interface
established. This is the /etc/ppp/ip-up script:
#!/bin/sh
#
# Update /etc/resolv.conf pppd generated file.
# Backup the old /etc/resolv.conf
#
RESOLV_BACKUP="/etc/old_resolv.conf"
RESOLV="/etc/resolv.conf"
PPP_RESOLV="/etc/ppp/resolv.conf"
cp -v ${RESOLV} ${RESOLV_BACKUP}
cp -vf ${PPP_RESOLV} ${RESOLV}
unset RESOLV_BACKUP
unset RESOLV
unset PPP_RESOLV
The script above is pretty simple bash script. I think I don't need to explain it.
The /etc/ppp/ip-down script as follows:
#!/bin/sh
#
# Restore /etc/resolv.conf
#
RESOLV_BACKUP="/etc/old_resolv.conf"
RESOLV="/etc/resolv.conf"
cp -vf ${RESOLV_BACKUP} ${RESOLV}
rm -vf ${RESOLV_BACKUP}
unset RESOLV_BACKUP
unset RESOLV
Note that the variable values in both ip-up and ip-down scripts have to match each other,
otherwise you are deleting the wrong file(s) or non-existent file. It can be dangerous
because these scripts run under root privilege.
Now, let's try to connect to the ISP (Indosat IM2) to register the UIM.
pppd call im2
This is the log in /var/log/messages during the connection establishment:
root@opunaga: # tail -f /var/log/messages
Dec 11 12:09:59 opunaga pppd[6867]: pppd 2.4.4 started by root, uid 0
Dec 11 12:10:00 opunaga hcid[2000]: link_key_request (sba=4E:89:44:0C:46:14, dba=00:12:D1:85:E8:8F)
Dec 11 12:10:01 opunaga chat[6870]: abort on (NO CARRIER)
Dec 11 12:10:01 opunaga chat[6870]: abort on (NO DIALTONE)
Dec 11 12:10:01 opunaga chat[6870]: abort on (ERROR)
Dec 11 12:10:01 opunaga chat[6870]: abort on (NO ANSWER)
Dec 11 12:10:01 opunaga chat[6870]: abort on (BUSY)
Dec 11 12:10:01 opunaga chat[6870]: send (ATZ^M)
Dec 11 12:10:01 opunaga chat[6870]: expect (OK)
Dec 11 12:10:01 opunaga chat[6870]: ATZ^M^M
Dec 11 12:10:01 opunaga chat[6870]: OK
Dec 11 12:10:01 opunaga chat[6870]: -- got it
Dec 11 12:10:01 opunaga chat[6870]: send (ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0^M)
Dec 11 12:10:01 opunaga chat[6870]: expect (OK)
Dec 11 12:10:01 opunaga chat[6870]: ^M
Dec 11 12:10:01 opunaga chat[6870]: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0^M^M
Dec 11 12:10:01 opunaga chat[6870]: OK
Dec 11 12:10:01 opunaga chat[6870]: -- got it
Dec 11 12:10:01 opunaga chat[6870]: send (AT+IFC=2,2;+CVHU=1^M)
Dec 11 12:10:01 opunaga chat[6870]: expect (OK)
Dec 11 12:10:01 opunaga chat[6870]: ^M
Dec 11 12:10:01 opunaga chat[6870]: AT+IFC=2,2;+CVHU=1^M^M
Dec 11 12:10:01 opunaga chat[6870]: OK
Dec 11 12:10:01 opunaga chat[6870]: -- got it
Dec 11 12:10:01 opunaga chat[6870]: send (ATS7=60+DS=3,0;&K3^M)
Dec 11 12:10:01 opunaga chat[6870]: expect (OK)
Dec 11 12:10:01 opunaga chat[6870]: ^M
Dec 11 12:10:01 opunaga chat[6870]: ATS7=60+DS=3,0;&K3^M^M
Dec 11 12:10:01 opunaga chat[6870]: OK
Dec 11 12:10:01 opunaga chat[6870]: -- got it
Dec 11 12:10:01 opunaga chat[6870]: send (AT+CGDCONT=1,"IP","indosatm2"^M)
Dec 11 12:10:02 opunaga chat[6870]: expect (OK)
Dec 11 12:10:02 opunaga chat[6870]: ^M
Dec 11 12:10:02 opunaga chat[6870]: AT+CGDCONT=1,"IP","indosatm2"^M^M
Dec 11 12:10:02 opunaga chat[6870]: OK
Dec 11 12:10:02 opunaga chat[6870]: -- got it
Dec 11 12:10:02 opunaga chat[6870]: send (ATS0=0^M)
Dec 11 12:10:02 opunaga chat[6870]: expect (OK)
Dec 11 12:10:02 opunaga chat[6870]: ^M
Dec 11 12:10:02 opunaga chat[6870]: ATS0=0^M^M
Dec 11 12:10:02 opunaga chat[6870]: OK
Dec 11 12:10:02 opunaga chat[6870]: -- got it
Dec 11 12:10:02 opunaga chat[6870]: send (ATDT*99#^M)
Dec 11 12:10:02 opunaga chat[6870]: expect (~)
Dec 11 12:10:02 opunaga chat[6870]: ^M
Dec 11 12:10:11 opunaga chat[6870]: ATDT*99#^M^M
Dec 11 12:10:11 opunaga chat[6870]: CONNECT^M
Dec 11 12:10:11 opunaga chat[6870]: ~
Dec 11 12:10:11 opunaga chat[6870]: -- got it
Dec 11 12:10:11 opunaga pppd[6867]: Serial connection established.
Dec 11 12:10:11 opunaga pppd[6867]: Using interface ppp0
Dec 11 12:10:11 opunaga pppd[6867]: Connect: ppp0 <--> /dev/rfcomm0
Dec 11 12:10:12 opunaga pppd[6867]: PAP authentication succeeded
Dec 11 12:10:16 opunaga pppd[6867]: local IP address 192.168.28.189
Dec 11 12:10:16 opunaga pppd[6867]: remote IP address 10.6.6.6
Dec 11 12:10:16 opunaga pppd[6867]: primary DNS address 202.155.47.130
Dec 11 12:10:16 opunaga pppd[6867]: secondary DNS address 202.155.0.10
and let's see our ppp interface:
root@opunaga:darmawan # ifconfig
ppp0 Link encap:Point-to-Point Protocol
inet addr:192.168.28.189 P-t-P:10.6.6.6 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:5902 (5.7 KiB) TX bytes:2061 (2.0 KiB)
Now, we have everything working as expected ;).
That's it for the moment. I hope you can setup your 3G/GPRS connection with pppd as well.
I've come to not using wvdial for sometime because I prefer using pppd directly which I think more convenient.
Post a Comment
3 comments:
kalau aku sejak dulu sampai sekarang pake ppp(d) ini
konfigurasi pakai pppconfig. kalau ada yang perlu disunting manual ya langsung edit berkasnya di /etc/ppp/ dan /etc/chatscripts/
aku pake slackware hingga tahun 2006, setelah itu pake debian/kuliax sampai sekarang
hmmm... pppconfig memang lebih gampang dan udah bawaannya Slackware. Tapi gw milih ga pake tool itu karena pengen tau gimana pppd bekerja (internalnya pppd). Ini penting karena berhubungan langsung dengan pekerjaan gw ;).
In any case, thanks for the comment.
Cool story as for me. I'd like to read a bit more about this topic. The only thing I would like to see here is a few photos of any gizmos.
Alex Kripke
Cell jammer
Post a Comment