maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC) (https://talk.maemo.org/showthread.php?t=58570)

9000 2011-04-02 06:45

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
I see. I made a few changes to run dnsmasq as daemon.

I've updated the script on first page. Note that I change the network from 192.168.1 to 192.168.3 to avoid conflicting with WiFi. Please try again.

jschan 2011-04-02 16:36

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
heh, sounds like we've done some of the same work. I'm using custom scripts at this point based off the dbus script tethering example and your script. In all, it's 3 files at the moment:
1) an enhanced version of your script that uses daemons and takes params like start/stop and optional external interface to tether to (bnep0 or wlan0 generally, defaulting to bnep0 if one isn't supplied).
2) a dbus script used as a front controller to call the above script with the correct params (if neither the wlan or bnep interfaces are up, it doesn't try to setup tethering)
3) a dbus config script to trigger the front controller script

So far it's working great, though the scripts aren't elegant at all. If I get some time to clean them up and test properly, i'll post them.

Edit: fixed some typos... writing this from the xoom is pretty error prone on this virtual keyboard.

9000 2011-04-03 01:26

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
FYI.

1) It's serving the host IP address rather than interface in the dbus version. I don't set lease time as I'm supposed to know who do I serve.
2) the dbus version is triggered by preset event
3) aye

jschan 2011-04-03 09:22

Re: [HOWTO] N900 Bluetooth-PAN Tethering (tested with a WiFi XOOM!)
 
1 Attachment(s)
I cleaned up my scripts a bit, added some documentation, and threw them into the attached tar file.

The version of the script here includes the following new features:
- Adds in support for multiple concurrent tethering clients (tested using a ThinkPad and a XOOM at the same time via bluetooth PAN)
- Adds in support for disabling tethering for a particular client
- Automatically picks the Internet interface (though it's pretty dumb about it)
- Works with included file to get dbus-scripts to automatically setup tethering on new connections
- Provides additional error checks and messages (though these could definitely use more work)

It's missing the pick-which-connection feature you have in the current version of your script, though I did try to make the entire script pretty verbose for easy modifications.

Outside of that, using the main script is very similar to your current script except that you have to specify whether you want to "start" or "stop" the tethering. The requirements and setup is pretty much what you have already written about in great detail in the first post.

Here's the script for each reference (it's also in the attached tar file):
Code:

#!/bin/sh
#
# /opt/tether/tether.sh
#
# Written by jschan @ http://talk.maemo.org
#
# Code snippets and inspiration from:
#  - http://wiki.maemo.org/DbusScripts
#  - http://talk.maemo.org/showthread.php?t=58570
#  - http://code.google.com/p/n900ipv6/source/browse/share/pan
#
# Enables tethering over USB network and Bluetooth PAN.
#
# usage: ./tether.sh start|stop [internal_interface]
#
# Examples:
#  - "./tether.sh start" - Enables tethering on a single PAN client when an Internet connection is active
#  - "./tether.sh stop" - Disables tethering on a single PAN client (assumes the client is on bnep0)
#  - "./tether.sh start bnep1" - Enables tethering on a 2nd PAN client when an Internet connection is active
#  - "./tether.sh stop bnep1" - Disables tethering on the 2nd PAN client, without interfering with the 1st
#
# Notes:
#  - Tested to work with multiple Bluetooth PAN clients including a WiFi-only XOOM
#  - Tested to work in conjuction with a dbus-scripts to automate tethering setups
#  - Doesn't currently have support for multiple concurrent Internet interfaces
#    such as an IPv4 grps connection and a seperate IPv6 grps connection.
#  - IPv6 isn't supported yet... (Waiting for T-Mobile IPv6 activation)
#

DEFAULT_INTERFACE="bnep0"
PAN_NETWORK_PREFIX="10.20"
USB_NETWORK_PREFIX="10.30"
INTERFACE_OCTET="88"
DHCP_MIN_IP_OCTET="100"
DHCP_MAX_IP_OCTET="127"
DHCP_MAX_LEASE_TIME="1h"
PRIMARY_DNS="8.8.8.8"
SECONDARY_DNS="8.8.4.4"

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
        echo "usage: $0 start|stop [internal_interface]"
        exit 1
fi

if [ -z "$2" ]; then
        INTERFACE="$DEFAULT_INTERFACE"
else
        INTERFACE="$2"
fi

print_message () {
        echo "$(date) $*"
              run-standalone.sh dbus-send \
                --type=method_call \
                --dest=org.freedesktop.Notifications \
                /org/freedesktop/Notifications \
                org.freedesktop.Notifications.SystemNoteInfoprint \
                string:"$*"
}
#set -x

INTERFACE_TYPE="$(echo $INTERFACE | sed 's/\([a-z]*\)[0-9]*/\1/')"
INTERFACE_NUMBER="$(echo $INTERFACE | sed 's/[a-z]*\([0-9]*\)/\1/')"

case $INTERFACE_TYPE in
        bnep )
                NETWORK_PREFIX="$PAN_NETWORK_PREFIX.$INTERFACE_NUMBER"
        ;;
        usb )
                NETWORK_PREFIX="$USB_NETWORK_PREFIX.$INTERFACE_NUMBER"
        ;;
        * )
                # Notify no active Internet connection
                print_message "Unsupported interface type: $INTERFACE_TYPE"
                exit 1
        ;;
esac

INTERFACE_IP="$NETWORK_PREFIX.$INTERFACE_OCTET"
NETMASK="255.255.255.0"
EXTERNAL_INTERFACE="$(ifconfig | awk '/(gprs|wlan)/ {print $1}' | head -1)"

DHCP_MIN_IP="$NETWORK_PREFIX.$DHCP_MIN_IP_OCTET"
DHCP_MAX_IP="$NETWORK_PREFIX.$DHCP_MAX_IP_OCTET"
DHCP_GATEWAY="$INTERFACE_IP"

MESSAGE="Tethering from $INTERFACE to $EXTERNAL_INTERFACE"
ACTIVATION_MSG="$MESSAGE activated"
DEACTIVATION_MSG="$MESSAGE deactivated"
DNSMASQ_PID_NAME="dnsmasq.$INTERFACE"
DNSMASQ_PID_FILE="/var/run/$DNSMASQ_PID_NAME.pid"

if [ "$1" == "start" ]; then
        INTERFACE_EXISTANCE_CHECK="$(ifconfig -a | grep $INTERFACE | awk '{print $1}')"
        if [ -z "$INTERFACE_EXISTANCE_CHECK" ]; then
                # Notify no active Internet connection
                print_message "$INTERFACE does not exist"
                exit 1
        fi

        if [ -z "$EXTERNAL_INTERFACE" ]; then
                # Notify no active Internet connection
                print_message "Tethering request from $INTERFACE recieved"
                exit 1
        fi

        # Setup interface
        ifconfig $INTERFACE down 2> /dev/null
        ifconfig $INTERFACE up
        ifconfig $INTERFACE $INTERFACE_IP netmask $NETMASK

        # Load modules
        modprobe ipt_MASQUERADE

        # flush old iptables rules
        iptables --flush
        iptables --table nat --flush

        # Setup NAT
        iptables --out-interface $EXTERNAL_INTERFACE \
                --table nat \
                --append POSTROUTING \
                --jump MASQUERADE

        # Enable IP forwarding
        #echo 1 > /proc/sys/net/ipv4/ip_forward
        echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
        echo 1 > /proc/sys/net/ipv4/conf/$EXTERNAL_INTERFACE/forwarding

        # Setup DNS and DHCP
        start-stop-daemon \
                --exec /usr/sbin/dnsmasq \
                --pidfile $DNSMASQ_PID_FILE \
                --start -- \
                        --interface=$INTERFACE \
                        --listen-address=$INTERFACE_IP \
                        --except-interface=lo \
                        --bind-interfaces \
                        --pid-file=$DNSMASQ_PID_FILE \
                        --dhcp-range=$DHCP_MIN_IP,$DHCP_MAX_IP,$DHCP_MAX_LEASE_TIME \
                        --dhcp-option=1,$NETMASK \
                        --dhcp-option=3,$DHCP_GATEWAY \
                        --dhcp-option=6,$PRIMARY_DNS,$SECONDARY_DNS

        # Notify user bluetooth tethering is active
        print_message "$ACTIVATION_MSG"

elif [ "$1" == "stop" ]; then

        start-stop-daemon \
                --exec /usr/sbin/dnsmasq \
                --pidfile $DNSMASQ_PID_FILE \
                --stop

        # Bring down the interface
        ifconfig $INTERFACE down 2> /dev/null

        # Disable IP forwarding for tethered interface
        if [ -f "/proc/sys/net/ipv4/conf/$INTERFACE/forwarding" ]; then
                echo 0 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding 2> /dev/null
        fi

        # Notify user bluetooth tethering is inactive
        print_message "$DEACTIVATION_MSG"

        # Disable external interface IP forwarding if appropriate
        DNSMASQ_CHECK="$(ps -eaf | grep 'dnsmasq' | grep -v -e '127\.0\.0\.1' -e 'grep')"
        if [ -z "$DNSMASQ_CHECK" ]; then
                echo "$(date) No more clients tethered--disabling all forwarding"
                echo 0 > /proc/sys/net/ipv4/conf/$EXTERNAL_INTERFACE/forwarding
                echo 0 > /proc/sys/net/ipv4/ip_forward
        fi

else

        echo "unknown argument: $1"
        echo "usage: $0 start|stop [internal_interface]"
        exit 1

fi

If you want to install my scripts, just install dbus-scripts if you haven't already, untar the attached tar file into a new /opt/tether directory, copy the "tether-dbus-config" file into the /etc/dbus-scripts.d directory, and restart dbus-scripts.

Thanks again for all of you help getting me over the humps while I was working on this, 9000. I was thinking about returning this XOOM if I couldn't tether it to the n900, but I'm digging it now... :)

9000 2011-04-03 11:16

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Well done jschan. ^^

jschan 2011-04-08 08:47

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
found some more docs about calls on the dbus: http://wiki.maemo.org/Phone_control#...ved_connection

apparently, if you don't already have a data connection open, you can open one. unfortunately, it looks like it requires user specific data, though i'm sure a gconftool call along with some combination of grep and awk could probably generalize it.

anyhow, i updated my script with it so that it makes the connection without having the prompt for a connection. the important parts are as follows:

Code:

DEFAULT_IAP_ID="***SEE DOCS ABOVE***"
...
EXTERNAL_INTERFACE="**CHECK***"
if [ -z "$EXTERNAL_INTERFACE" ]; then
        print_message "Establishing Default Connection"
        dbus-send --system --type=method_call \
                --dest=com.nokia.icd /com/nokia/icd \
                com.nokia.icd.connect \
                string:$DEFAULT_IAP_ID uint32:0

        EXTERNAL_INTERFACE="**CHECK AGAIN***"
        if [ -z "$EXTERNAL_INTERFACE" ]; then
                # Notify no active Internet connection
                print_message "Unable to establish tether"
                exit 1
        fi
fi
...

cheers

9000 2011-04-08 16:18

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Quote:

Originally Posted by jschan (Post 984091)
found some more docs about calls on the dbus: http://wiki.maemo.org/Phone_control#...ved_connection

apparently, if you don't already have a data connection open, you can open one. unfortunately, it looks like it requires user specific data, though i'm sure a gconftool call along with some combination of grep and awk could probably generalize it.

anyhow, i updated my script with it so that it makes the connection without having the prompt for a connection. the important parts are as follows:

Code:

DEFAULT_IAP_ID="***SEE DOCS ABOVE***"
...
EXTERNAL_INTERFACE="**CHECK***"
if [ -z "$EXTERNAL_INTERFACE" ]; then
        print_message "Establishing Default Connection"
        dbus-send --system --type=method_call \
                --dest=com.nokia.icd /com/nokia/icd \
                com.nokia.icd.connect \
                string:$DEFAULT_IAP_ID uint32:0

        EXTERNAL_INTERFACE="**CHECK AGAIN***"
        if [ -z "$EXTERNAL_INTERFACE" ]; then
                # Notify no active Internet connection
                print_message "Unable to establish tether"
                exit 1
        fi
fi
...

cheers

You can use the following one-liner to get the IAP:

Code:

for i in `gconftool -R /system/osso/connectivity/IAP | grep /system/osso/connectivity/IAP/ | sed -e "s:\(.*\)\:\(.*\):\1:"`; do if [ "`gconftool -g $i/type`" == "GPRS" ]; then IAP=$i; fi; done
I assumed by "default" you mean "GPRS".

anapospastos 2011-04-21 23:58

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
I succesfully paired my sony ericsson k850 to N900. I ve had some problems when I tried it a couple of months ago but now I made it. Changes of first post may helped in this and especially ip settings. Thank you 9000.

ToniA 2011-04-29 09:17

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Thanks guys, this is really cool. I was already quite desperate after having tried out the Joikuspot and normal Bluetooth (DUN profile) pairing between the Xoom and the N900.

I still have one minor issue though. Even on a freshly flashed PR1.3 (I also reflashed the eMMC content) the dbus-scripts do not seem to work at all, i.e. it very much looks like I don't get any events. So right now I'm running the tether.sh script manually.

Any ideas where to look at? I tried to debug (http://wiki.maemo.org/DbusScripts#Th...l_--debug_flag), but couldn't see any Bluetooth-related events.

9000 2011-04-29 09:43

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Have you followed the configuration instructions in the corresponding page? ( http://wiki.maemo.org/DbusScripts )


All times are GMT. The time now is 04:08.

vBulletin® Version 3.8.8