LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   simultaneous mobile (cell) phone internet over bluetooth connections (http://www.linuxquestions.org/questions/linux-networking-3/simultaneous-mobile-cell-phone-internet-over-bluetooth-connections-679527/)

Vectis 10-28-2008 08:52 AM

simultaneous mobile (cell) phone internet over bluetooth connections
 
Hi,

I have for a few years now, been able to connect my phone to the internet using a bluetooth connection to my pc, but I can only connect one phone at a time, is it possible to have more than one connected together at the same time?. I have a Nokia 6680 (two actually) and this is setup using a program called 'gnubox'. My pc is running a version of 'Slax' OS and I use the following script on my pc to get this all working:

#!/bin/sh

PHONE_MAC=##:##:##:##:##:## # Phones MAC address
EXT_IF=eth0 # My externl interface (to the net)
INT_NET=192.168.1.0/24 # My internal subnet (eg. 192.168.1.0/24)
MY_IP=192.168.1.2 # This PCs internal IP address (eg. 192.168.1.1)
PHONE_IP=192.168.1.3 # The IP I give to my phone (eg. 192.168.1.10)
DNS_SERVER=62.69.62.6 # My ISPs DNS server

ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe

/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
dund --nodetach --listen --channel 3 --msdun 30 noauth $MY_IP:$PHONE_IP crtscts 115200 ms-dns $DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH

$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE

I guess I need to edit this somehow, to allow for additional connections, but i'm not sure how.

BTW, even though I have my phone mac in this script, I can connect either of my phones providing I enter the bluetooth pin.

pinniped 10-29-2008 03:07 AM

So at the moment you edit that script and connect to one phone or the other?

Your script will have to evolve to become considerably more complex; in particular you will have to create functions to call.

The first step is to create a script which can detect which phones are in range and automatically connect. The script must also be able to check if a phone is already connected (why connect twice). As you connect and so on, you need to identify what interfaces or device files are being created; you will need to pass that information onto the functions which you call so that you can create the correct iptables rules and so on. Also, it would be nice to control things to a degree so that each phone is always accessible by the same name or something (maybe always ppp8 and ppp9?). Have fun reading the manuals and poking around. :)

Vectis 10-29-2008 05:18 PM

I've changed the script somewhat, so as to include my second phone, and I have managed to get both phones connected at the same time, however I have only managed this once. Usually when connecting the second phone, the ip address given to it is the same as the first phone and so I cant access the internet on the second phone. Any ideas?

#!/bin/sh

PHONE_MAC=##:##:##:##:##:## # Phones MAC address
PHONE_MAC2=##:##:##:##:##:## #
EXT_IF=eth0 # My externl interface (to the net)
INT_NET=192.168.1.0/24 # My internal subnet (eg. 192.168.1.0/24)
MY_IP=192.168.1.102 # This PCs internal IP address (eg. 192.168.1.1)
PHONE_IP=192.168.1.3 # The IP I give to my phone (eg. 192.168.1.10)
PHONE2_IP=192.168.1.4
DNS_SERVER=62.69.62.6 # My ISPs DNS server

ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe

/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
rfcomm bind /dev/rfcomm5 $PHONE2_MAC 10
rfcomm bind /dev/rfcomm6 $PHONE2_MAC 3

dund --nodetach --listen --channel 3 --msdun 30 noauth $MY_IP:$PHONE_IP crtscts 115200 ms-dns $DNS_SERVER lock &
dund --nodetach --listen --channel 7 --msdun 30 noauth $MY_IP:$PHONE2_IP crtscts 115200 ms-dns $DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH

$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $EXT_IF -o ppp1 -s $ANY -d $INT_NET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A FORWARD -i ppp1 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE

pinniped 10-29-2008 09:39 PM

Could some of the problem be that you have:

PHONE_MAC2

and later you use the undefined:

PHONE2_MAC

Vectis 10-30-2008 03:31 AM

Sorry, thats a typo. my script does actually read:

PHONE2_MAC

rfcomm gives me this output:

rfcomm0: ##:##:##:##:##:F1 -> ##:##:##:##:##:19 channel 3 connected [reuse-dlc release-on-hup tty-attached]
rfcomm1: ##:##:##:##:##:19 channel 10 clean
rfcomm2: ##:##:##:##:##:19 channel 3 clean
rfcomm3: ##:##:##:##:##:F1 -> ##:##:##:##:##:67 channel 3 connected [reuse-dlc release-on-hup tty-attached]
rfcomm5: ##:##:##:##:##:67 channel 10 clean
rfcomm6: ##:##:##:##:##:67 channel 3 clean

I guess this is the problem, its trying to connect on the same channel and give phone2 the same ip.

When I had them both connected the output was:

rfcomm0: ##:##:##:##:##:F1 -> ##:##:##:##:##:19 channel 7 connected [reuse-dlc release-on-hup tty-attached]
rfcomm1: ##:##:##:##:##:19 channel 10 clean
rfcomm2: ##:##:##:##:##:19 channel 3 clean
rfcomm3: ##:##:##:##:##:F1 -> ##:##:##:##:##:67 channel 3 connected [reuse-dlc release-on-hup tty-attached]
rfcomm5: ##:##:##:##:##:67 channel 10 clean
rfcomm6: ##:##:##:##:##:67 channel 3 clean

I think I will update the Bluez stack (mine is a bit old), and try again.

pinniped 10-30-2008 05:14 AM

Are you running the script multiple times or just once? If there is some way to get information from the phones before you finalize the connection, it should be possible to make your script more robust and explicitly connect each phone to a fixed channel and so on.

Vectis 10-30-2008 08:15 AM

The script is called once from /etc/rc.d/rc.local at boot.

I don't think I have any means of getting info from the phones :(

pinniped 10-30-2008 09:16 AM

I can't see why rfcomm isn't binding just the device you specify. Have a look at the Gentoo guide - maybe you'll find something useful:

http://www.gentoo.org/doc/en/bluetooth-guide.xml

The official documentation of the tools is just plain awful. I wonder if I should dare read through the protocol specs and the source ...

pinniped 10-31-2008 08:08 AM

One thing I don't see in your scripts is the 'connect' - where are you doing the RFCOMM connect between the devices? For example:

rfcomm connect 0 BT_ADDR_OF_PHONE_1 1
(connect rfcomm0 to the device with the given bluetooth hardware address using channel 1)

Sorry - it's late - bind/connect - what's the difference. It's just that 'bind' doesn't means quite the same thing in socket programming.

Vectis 11-02-2008 06:33 AM

Thanks for your continued help.

Do you mean this:

#
# RFCOMM configuration file.
#

rfcomm0 {
# Automatically bind the device at startup
bind yes;

# Bluetooth address of the device
device ##:##:##:##:##:67;

# RFCOMM channel for the connection
channel 1;

# Description of the connection
comment "Example Bluetooth device";
}

rfcomm3 {
# Automatically bind the device at startup
bind yes;

# Bluetooth address of the device
device ##:##:##:##:##:19;

# RFCOMM channel for the connection
channel 1;

# Description of the connection
comment "Phone_2";
}


All times are GMT -5. The time now is 02:03 PM.