View Single Post
Posts: 166 | Thanked: 74 times | Joined on May 2010
#190
Originally Posted by gtab_n900 View Post
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
Attached Files
File Type: tar tether.tar (20.0 KB, 469 views)
 

The Following 2 Users Say Thank You to jschan For This Useful Post: