O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



HACK
#17
Bluetooth to GPRS in Linux
Use your Bluetooth phone as a modem when Wi-Fi isn't available
The Code
[Discuss (0) | Link to this hack]

The Code

Snippet 1

#!/usr/bin/perl
while ( ) {
    print "PIN:$1\n" if /^$ARGV[1]\s+(\w+)/o;
}
__DATA_  _
# Your Bluetooth PINs can go here, in BD address / PIN pairs, 
# one to a line, separated by whitespace.
#
# ## etc.

00:11:22:33:44:55       11111

Snippet 2

options {
        autoinit yes;
        security auto;
        pairing multi;
        pin_helper /etc/bluetooth/pindb;
}

Snippet 3

# for n in `seq 0 63`; do mknod -m660 /dev/rfcomm$n c 216 $n; done
# chown root:uucp /dev/rfcomm* 

Snippet 4

rfcomm0 {
        # Automatically bind the device at startup
        bind yes;
        device 00:11:22:33:44:55;
        channel 1;
        comment "My Phone";
}

Snippet 5

/dev/rfcomm0

connect '/usr/sbin/chat -v -f /etc/ppp/peers/gprs.chat'
noauth
defaultroute
usepeerdns
lcp-echo-interval 65535
debug

Snippet 6

TIMEOUT         15
ECHO            ON
HANGUP          ON
''              AT
OK              ATZ
OK              ATD*99#

Snippet 7

[Dialer gprs]
Modem       = /dev/rfcomm0
Phone       = *99#
Username    = foo
Password    = bar

Snippet 8

# comment out CHATSCRIPT and uncomment WVDIALSECT if you're using wvdial
DEVICE=ppp0
MODEMPORT=/dev/rfcomm0
CHATSCRIPT=/etc/ppp/peers/gprs.chat
# WVDIALSECT=gprs

Snippet 9

welcome 'cp -b /etc/ppp/resolv.conf /etc/resolv.conf'
disconnect 'mv /etc/resolv.conf~ /etc/resolv.conf'

Snippet 10

# Enable IP forwarding and rp_filter (to kill IP spoof attempts).
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter

# Load relevant kernel modules, if necessary.
for i in ip_tables ipt_MASQUERADE iptable_nat
    ip_conntrack ip_conntrack_ftp ip_conntrack_irc \
    ip_nat_irc ip_nat_ftp; do 
    modprobe $i 2>/dev/null;
done

# Masquerade anything that's not from a PPP interface
# (e.g. ethernet, Wi-Fi, etc.)
iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.