viernes, 31 de diciembre de 2010

Sharing your PC network with an Android device using an USB

I have a Galaxy Tab but I cannot use WiFi at work since it is not allowed by company policy. Still I needed to connect to my desktop to test an application that I was developing. I have Ubuntu linux running in my desktop.

Step 1 Gain root access in the Android device.


I used z4Root. It is not longer in the Android Market. I downloaded version 1.3.0 from http://forum.xda-developers.com/showthread.php?t=833953

Step 2 Install BusyBox in Android.


You will need some unix commands in BusyBox. You can find BusyBox here:

http://www.gadgetsdna.com/busybox-installation-steps-on-jailbroken-android-device/683/

Step 3 Setup a ppp connection thru the USB

I followed instructions in here:
http://forum.xda-developers.com/showthread.php?t=522498

Make sure that you download ppp-mod. Installed in /system/xbin

I am using the following script to create the ppp connection.

#!/bin/sh
# The path to adb
ADB=/usr/apps/android-sdk-linux_x86/tools/adb
PORT=12000
# This is a RW directory in the Android
DIR=/mnt/sdcard
$ADB forward tcp:$PORT tcp:$PORT
sysctl net.ipv4.ip_forward=1
iptables -t nat -I POSTROUTING -s 192.168.0.254 -j MASQUERADE -o eth0
cat >run-ppp <<EOS
echo "port is $PORT"
ip r del default
kill-all pppd-mod
pppd-mod nodetach noauth pty "nc -l -p $PORT" defaultroute
EOS

$ADB push run-ppp $DIR/run-ppp
echo "Set up PPP in the Android device"
$ADB shell "su -c 'sh $DIR/run-ppp'" &
sleep 5
echo "Set up PPP in the host"
# execute pppd connected to 12000/tcp
pppd nodetach noauth nodeflate pty "nc localhost $PORT" ipparam vpn 192.168.0.1:192.168.0.254

1 comentario: