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)

Denis 2011-06-29 03:35

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
I've also got an asus transformer, I've managed to get it to tether to the n900 using your PAN script...
only issue I had was that when tethered it still behaved like there was no internet connection...
then I found that iptables had been uninstalled when I uninstalled v47 of the power kernel in order to install v46...

now, all is well :)
thanks for the script!

9000 2011-06-29 07:52

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

Originally Posted by Denis (Post 1041191)
I've also got an asus transformer, I've managed to get it to tether to the n900 using your PAN script...
only issue I had was that when tethered it still behaved like there was no internet connection...
then I found that iptables had been uninstalled when I uninstalled v47 of the power kernel in order to install v46...

now, all is well :)
thanks for the script!

Thanks for your feedback. I'm trying to revise the script so as to deal with those devices with short timeout. Anyway, it's good to hear that the script works for you. :rolleyes:

gtab_n900 2011-07-04 09:41

Re: [HOWTO] N900 Bluetooth-PAN Tethering (tested with a WiFi XOOM!)
 
Just like to say a big thanks to jschan and 9000 for all they've written on this topic.

I used jschan's tether scripts with dbus and finally got an unrooted Samsung Tab 10.1 running Android 3.1 tethered via Bluetooth PAN to the N900. The only change I made was to uncomment this line:

Code:

#echo 1 > /proc/sys/net/ipv4/ip_forward
changed to:
Code:

echo 1 > /proc/sys/net/ipv4/ip_forward
Which was commented in the original script. I couldn't get an IP addres without it. The clue was when I tried tethering via kUbuntu and got endless DHCPDISCOVER log messages until timeout which made me search for IP settings in the tether script.

After following jschan's instructions:
1. Turn on BT on the N900
2. Pair gtab with n900
3. N900 BT status icon should turn blue
4. In Wireless & networks > Bluetooth Settings on the gtab your device should be listed as 'Paired' with the Spanner Icon and a darker Bluetooth Tethering icon to the left.
5. Tap the Spanner
6. Under 'Profiles' tap 'Tethering - use for Internet Access'
7. In the status are of the gtab a bright blue Tethering icon will appear, per the screenshot from Youth.

Note with the dbus scripts installed I didn't have to manually run the tethering script to start the process. Battery usage seems ok as well.

Also, I don't have PC Connectivity Manager or Bluez Switch installed.

big thanks again.

9000 2011-07-04 09:49

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

I'm researching on the reason why some device can't get the DHCP, may be update the script very soon.

gtab_n900 2011-07-04 13:10

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Hi, the Tab only got an IP address via the N900 when that ip_forward line was uncommented. Prior to that, pairing and 'connection' was completed but without an IP being provide.

I used jschan's tethering script here:
http://talk.maemo.org/showpost.php?p...&postcount=124

You can see here:
# 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

That it was commented out.

I tried your initial script right back on page 1 of this thread but it didn't work, although that does have the ip_forward line uncommented.

Hope that helps.

9000 2011-07-04 14:16

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
It uses Google's DNS. It should use your ISP DNS instead.

But as long as it works for you it is fine. ;)

DarkPand0r 2011-07-05 08:49

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

I'm having a bit of an odd time... It worked fine yesterday to my Transformer (Not Optimus Prime :P).

I've tried to connect today, but the script says "Bnep0 does not exist"
Not sure whats gone wrong :S

I've tried reinstalling Libicd2 to no avail....

9000 2011-07-05 11:22

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
Have you paired them up?

rdnetto 2011-07-06 09:11

Re: [HOWTO] N900 Bluetooth-PAN Tethering (N900 supplies Internet Access for PC)
 
I haven't been able to get mine to pair properly. Tried with my Asus Transformer and an iPad. The icon (on the n900) only stays blue for a moment with the Transformer. It goes blue permanently with the iPad. Neither of them show any profiles as being available, despite being paired. (Also, the Transformer shows it as being paired regardless of whether or not the bluetooth is actually on, so I think it only pairs when you select a profile).

'lsmod | grep bne' shows nothing, and ifconfig doesn't show bnep0 at any stage. The lines referring to it in your script just produce 'no such device'.

Quote:

Originally Posted by 9000 (Post 787864)
Although setting sudoers is better, but it seems to confuse a lot of people. I've made change to the procedure section 4.3.3 to run the script directly with root privilege:

Code:

echo "/home/user/bluetooth-pan.sh" | sudo gainroot

It's easier to just add this to the beginning of the script:
Code:

if [ $(whoami) != "root" ]; then
  echo "$0" | sudo gainroot
  exit
fi


jschan 2011-07-09 05:33

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

Originally Posted by gtab_n900 (Post 1044424)
Hi, the Tab only got an IP address via the N900 when that ip_forward line was uncommented. Prior to that, pairing and 'connection' was completed but without an IP being provide.

I used jschan's tethering script here:
http://talk.maemo.org/showpost.php?p...&postcount=124

You can see here:
# 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

That it was commented out...

Thanks for letting me know gtab. I went and made the script update and attached it below. It's pretty much what I posted before except with the added ability to auto connect to GPRS when it's not connected to either GPRS nor WLAN. See the notes in the script for how to configure it if you choose to use it (look for the IAP ID setting).

One tip about the auto connect functionality: if the Internet connection is already up, I never seem to have any problems with my Xoom getting a good connection. However, when the N900 has to establish the connection, it takes longer to get through the script and start up DMASQ, thereby causing the same timing issue some of the other guys have experienced, I believe. Simply breaking the bt connection from the tablet and then re-establishing it always fixes the issue since the Internet connection doesn't have to re-establish itself at that point. I'm guessing all Honeycomb tablets (such as your Galaxy) would behave the same way.

Cheers,

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)
#

# You will want to customize the IAP ID value below
#  - DEFAULT_IAP_ID: This a code uniquely identifying the default GPRS connection to use if you aren't currently connected.
#    It can be obtained with the following command: gconftool -R /system/osso/connectivity/IAP
#    Find lines which matches /system/osso/connectivity/IAP/<IAP_ID> for the GRPS connection you use for Internet connectivity.
#    See http://wiki.maemo.org/Phone_control#Connect_to_specific_saved_connection for more information.
DEFAULT_IAP_ID="efc9b252-9bf3-4aa7-a023-348c2d46f101"
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:"$*"
}

connect_default_access_point () {
        print_message "Establishing Default Connection"
        dbus-send \
                --system \
                --type=method_call \
                --print-reply \
                --dest=com.nokia.icd \
                /com/nokia/icd \
                com.nokia.icd.connect \
                string:$DEFAULT_IAP_ID uint32:0
        #sleep 2
}
#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"

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
                connect_default_access_point
                EXTERNAL_INTERFACE="$(ifconfig | awk '/(gprs|wlan)/ {print $1}' | head -1)"

                if [ -z "$EXTERNAL_INTERFACE" ]; then
                        # Notify no active Internet connection
                        print_message "Unable to establish tether for $INTERFACE"
                        exit 1
                fi
        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 \
                --verbose \
                --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 "Tethering from $INTERFACE to $EXTERNAL_INTERFACE activated"

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

        start-stop-daemon \
                --exec /usr/sbin/dnsmasq \
                --pidfile $DNSMASQ_PID_FILE \
                --verbose \
                --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 "Tethering from $INTERFACE to $EXTERNAL_INTERFACE deactivated"

        # 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



All times are GMT. The time now is 09:43.

vBulletin® Version 3.8.8