Tethering via WiFi - Troubleshooting

Search This thread

divinehawk

Member
Nov 10, 2008
12
1
FYI,

I've been able to successfully use iptables to configure ip masquerading (NAT). With it, I am tethered over WiFi without using tetherbot (which still works as a backup). Hopefully someone else can package this to be more useful.
Update: See posts #13 and #15 on how to use Ad-hoc mode.

  • Root required
  • Existing wifi network required (and configured)

1> Disable WiFi through the UI. Then turn on Wifi manually using the following commands as root. Normally the phone data interface and WiFi can't be turned on at the same time. (Can this be done through the android gui somehow?)

insmod /system/lib/modules/wlan.ko

wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /system/etc/wifi/tiwlan.ini

cd /data/local/tmp
wpa_supplicant -f -Dtiwlan0 -itiwlan0 -c/data/misc/wifi/wpa_supplicant.conf &

sleep 5
ifconfig tiwlan0 192.168.2.30 netmask 255.255.255.0
ifconfig tiwlan0 up

Note that I had to use a static ip since dhcp will typically add in a gateway.

2> Enable and configure ip forwarding

iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I FORWARD -s 192.168.2.0/24 -j ACCEPT
iptables -P FORWARD DROP

iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward

3> On your computers, set your default gateway to your phone's WiFi IP address (192.168.2.30 - in my case). Also set your DNS to a real DNS server.

Attached is the iptables binary, compiled with the android sdk.
 

Attachments

  • iptables.zip
    54.8 KB · Views: 2,672
Last edited:
  • Like
Reactions: S0AndS0

hondamx525

Senior Member
Oct 22, 2008
301
0
just curious as to why you would want the "tethering" this way. isnt it most likely that any wifi your phone can connect to your computer most probably can too? just curious?
 

neoobs

Retired Moderator
Mar 25, 2008
1,239
11
just curious as to why you would want the "tethering" this way. isnt it most likely that any wifi your phone can connect to your computer most probably can too? just curious?

This is just progress on tethering. The proxy method is a horrible way of tethering. iptables is the correct way if done correctly. His developments while useless to most are still good because it is progressive. And he can get hotspots now LOL
 

divinehawk

Member
Nov 10, 2008
12
1
just curious as to why you would want the "tethering" this way. isnt it most likely that any wifi your phone can connect to your computer most probably can too? just curious?

The above configuration uses your existing wifi settings (I haven't tried ad-hoc mode).

USB networking would be better, or even bluetooth. But I'm not sure this is possible.
 

scootley

Senior Member
Nov 10, 2008
60
18
divinehawk, do you really need an access point? have you tried this using an ad-hoc network? (I am not sure if the G1's WiFi supports ad-hoc networks)
 

divinehawk

Member
Nov 10, 2008
12
1
divinehawk, do you really need an access point? have you tried this using an ad-hoc network? (I am not sure if the G1's WiFi supports ad-hoc networks)

Doesn't look like the gui will let you do ad-hoc. Maybe if a modified wpa_supplicant.conf. I'll report back if I have success.

Ideal mode would be for the phone to *act* as an access point. But that usually requires driver support.
 

alansj

Member
Nov 6, 2008
44
47
USB networking would be better, or even bluetooth. But I'm not sure this is possible.

Code:
# adb --help
[...]
adb forward <local> <remote> - forward socket connections
                                 forward specs are one of: 
                                   tcp:<port>
[...]

...but I guess everybody already knew that. I suppose that doing it via iptables under this approach, you are still limited to specific ports.
 
Last edited:

neoobs

Retired Moderator
Mar 25, 2008
1,239
11
Code:
# adb --help
[...]
adb forward <local> <remote> - forward socket connections
                                 forward specs are one of: 
                                   tcp:<port>
[...]

that only works if you want to make a proxy... I think he is trying to make it a true internet sharing app similar to that of the wing and other WM devices
 

neoobs

Retired Moderator
Mar 25, 2008
1,239
11
How about something similar to PdaNet?

http://www.theiphoneblog.com/2008/10/16/how-to-tether-with-pdanet/

It's interesting that it works by having you set up an ad-hoc wireless network from your computer and then connecting to that from the iPhone. Maybe that's essentially what scootley was suggesting above.

PdaNet .deb here:
http://apt.modmyi.com/2debs/pdanet1.40.deb

That would be awesome... I hope someone can do that soon. I am dying to be able to connect it to my computer.
 

rale00

Member
Nov 8, 2008
19
0
I just managed to get an ad-hoc connection going between my phone and laptop, and NAT running on it. The steps are pretty much the same as in the first post of this thread, but in addition I made some changes to /system/etc/wifi/tiwlan.ini (make sure to keep a backup of the original).

First, make sure wifi is disabled on the phone gui.

Next, Set up the ad-hoc network on the laptop. I called mine "newtest". Change the properties for the connection to assign a static ip. I used 192.168.2.2. Set gateway to 192.168.2.1, and set dns to a public server - i used 4.2.2.1.

In tiwlan.ini, look for "WiFiAdhoc = 0". Change it to the following (set ssid to whatever you use):

WiFiAdhoc = 1
dot11DesiredSSID = newtest
dot11DesiredBSSType = 0

After updating tiwlan.ini, enable wifi manually:

insmod /system/lib/modules/wlan.ko
wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /system/etc/wifi/tiwlan.ini
ifconfig tiwlan0 192.168.2.1 netmask 255.255.255.0
ifconfig tiwlan0 up

At this point, the phone should connect to the ad-hoc network.

Now, from the OP's post, the iptables rules:

iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I FORWARD -s 192.168.2.0/24 -j ACCEPT
iptables -P FORWARD DROP

iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward

If all went well, you now have internet access.
 

divinehawk

Member
Nov 10, 2008
12
1
Thanks rale00,
I just managed to get an ad-hoc connection going between my phone and laptop, and NAT running on it. The steps are pretty much the same as in the first post of this thread, but in addition I made some changes to /system/etc/wifi/tiwlan.ini (make sure to keep a backup of the original).

You can also copy tiwlan.ini to somewhere else, such as /data/local, make changes, then just specify the new file when you run wlan_loader.

wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /data/local/wifi/tiwlan.ini

Also note that without running wpa_supplicant, you are going unencrypted. Using a custom wpa_supplicant.conf might work (unverified at the moment, can you try?):

My adhoc_wpa.conf
ctrl_interface=tiwlan0
update_config=1

# IBSS/ad-hoc network with WPA-None/TKIP.
network={
ssid="newtest"
mode=1
frequency=2412
proto=WPA
key_mgmt=WPA-NONE
pairwise=NONE
group=TKIP
psk="TEST545#@network"
}

Run with:
wpa_supplicant -f -Dtiwlan0 -itiwlan0 -c/data/local/adhoc_wpa.conf &
 

rale00

Member
Nov 8, 2008
19
0
I tried the config you suggested for wpa_supplicant, along with a few others, but I can't seem to get a secure connection working. It tries to connect, but times out authenticating.

Maybe someone else will have some better luck with it?
 

alansj

Member
Nov 6, 2008
44
47
It seems like one logical next step would be a dhcp server.

saurik's Debian demonstration is pretty cool but I don't have the skill to get all the dependencies sorted out and cross-compile. Nevertheless, it seems possible:

http://armel-debs.applieddata.net/debian/dists/lenny/main/binary-armel/Packages.gz says:

Code:
Package: dhcp3-server
Priority: optional
Section: net
Installed-Size: 724
Maintainer: Andrew Pollock <apollock@debian.org>
Architecture: armel
Source: dhcp3
Version: 3.1.1-5
[B]Depends: debianutils (>= 2.8.2), dhcp3-common (= 3.1.1-5), lsb-base, libc6 (>= 2.7-1), debconf (>= 0.5) | debconf-2.0[/B]
Suggests: dhcp3-server-ldap
Conflicts: dhcp
Filename: pool/main/d/dhcp3/dhcp3-server_3.1.1-5_armel.deb
Size: 338070

Somebody who can set up the proper build environment and sort out the dependencies could theoretically statically build dhcp3-server.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    FYI,

    I've been able to successfully use iptables to configure ip masquerading (NAT). With it, I am tethered over WiFi without using tetherbot (which still works as a backup). Hopefully someone else can package this to be more useful.
    Update: See posts #13 and #15 on how to use Ad-hoc mode.

    • Root required
    • Existing wifi network required (and configured)

    1> Disable WiFi through the UI. Then turn on Wifi manually using the following commands as root. Normally the phone data interface and WiFi can't be turned on at the same time. (Can this be done through the android gui somehow?)

    insmod /system/lib/modules/wlan.ko

    wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /system/etc/wifi/tiwlan.ini

    cd /data/local/tmp
    wpa_supplicant -f -Dtiwlan0 -itiwlan0 -c/data/misc/wifi/wpa_supplicant.conf &

    sleep 5
    ifconfig tiwlan0 192.168.2.30 netmask 255.255.255.0
    ifconfig tiwlan0 up

    Note that I had to use a static ip since dhcp will typically add in a gateway.

    2> Enable and configure ip forwarding

    iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -I FORWARD -s 192.168.2.0/24 -j ACCEPT
    iptables -P FORWARD DROP

    iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE

    echo 1 > /proc/sys/net/ipv4/ip_forward

    3> On your computers, set your default gateway to your phone's WiFi IP address (192.168.2.30 - in my case). Also set your DNS to a real DNS server.

    Attached is the iptables binary, compiled with the android sdk.
    1
    You could I guess...

    Honestly it may be easier to just use adb to run the shell scripts that enable/disable the configuration.

    Hm, I've got it starting up from Terminal Emulator (Term.apk). I still have to type things on the command-line but at least I can start it up from my phone. First, I created this shell script to make it easier (which I named "tether" and stuck in /data/bin/):

    Code:
    #!/system/bin/sh
    
    case "$1" in
    'start')
    insmod /system/lib/modules/wlan.ko
    wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /data/local/tiwlan.ini
    ifconfig tiwlan0 192.168.2.1 netmask 255.255.255.0
    ifconfig tiwlan0 up 
    /data/local/bin/iptables -F
    /data/local/bin/iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    /data/local/bin/iptables -I FORWARD -s 192.168.2.0/24 -j ACCEPT
    /data/local/bin/iptables -P FORWARD DROP
    /data/local/bin/iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward 
    /data/local/bin/dnsmasq -x /data/local/dnsmasq.pid
    ;;
    'stop')
    rmmod wlan
    kill -9 `cat /data/local/dnsmasq.pid`
    /data/local/bin/iptables -F
    echo 0 > /proc/sys/net/ipv4/ip_forward
    ;;
    *)
    echo "Usage: $0 [start|stop]"
    ;;
    esac

    Then, I started up Terminal Emulator and called my 'suroot' binary (sh with setuid root). I tried calling 'tether start' directly but it was giving me permission denied errors. Then, I did this, which worked:

    Code:
    /data/local/bin/tether start | suroot

    Don't ask my why that works when calling it directly while in a shell via suroot does not work. In order to make it easier for myself, I put the above command into a 1-line shell script called "tetherup" which I placed in my /system/bin/ directory (because it's in my path). The net result is that via Terminal Emulator I can do the following to start up my tether:

    Code:
    # suroot
    # tetherup
    1
    I am on Windows Xp and that guide is what I was trying, but it does works with 2 PCs;
    the adhoc connection is working but the G1 does not show or connect it.
    I am on Haykuro 6.0r1
    It is strange that the applicazione WIFIScanner can catch my PCADSL adhoc but the G1 wifi Settings page does not show it even if I Add it with the Wi-Fi network options.
    The two images shows the WifiScanner application and the Wifi Setting page.
    Any Help?

    Hi. I have the same situation but I am using the app "Wifi Analyzer". Could anybody tell me if following the instructions in #13 we can connect the phone to the computer with the Ad-Hoc mode to use my broadband in my Gphone.

    Thanks.