Skip to content
Permalink
Browse files
Make serval work on Android-IBSS
See:
  https://groups.google.com/forum/#!topic/serval-project-developers/JGN00i00nFk
  http://www.thinktube.com/android-tech/46-android-wifi-ibss

iw binary comes from:
  http://www.onlyxool.net/porting-iw-tools-to-android/

Target SDK has changed from 8 to 10 (minSdkVersion is still 8). It allows to
know if an interface is up or down. The test is done only if the device
supports it (>= 9).

A variable "wifi.frequency" has been added in adhoc.conf (iw expects frequency
instead of channel).

Tested on Galaxy Nexus.
  • Loading branch information
rom1v committed Mar 25, 2013
1 parent 4300cf1 commit b1e00d190dfa7720fcb8e481bf4c55816c5fa4e6
BIN +158 KB data/bin/iw
Binary file not shown.
@@ -1,6 +1,7 @@
wifi.interface=eth0
wifi.essid=Serval
wifi.channel=6
wifi.frequency=2437
wifi.txpower=disabled
wifi.driver=wext
ip.gateway=10.0.0.0
@@ -0,0 +1,45 @@
# Works only with patched ROM
# see http://www.thinktube.com/android-tech/46-android-wifi-ibss

# activate WiFi interface
log(
run_program(
"/data/data/org.servalproject/bin/ifconfig " +
getcfg("wifi.interface") + " up"
), "Activating WiFi interface"
);

# configure IP/netmask
log(
run_program(
"/data/data/org.servalproject/bin/ifconfig " +
getcfg("wifi.interface") + " " + getcfg("ip.gateway") +
" netmask " + getcfg("ip.netmask")
), "Configuring " + getcfg("wifi.interface")
);

# set wifi mode ad-hoc (IBSS)
log(
run_program(
"/data/data/org.servalproject/bin/iw dev " +
getcfg("wifi.interface") + " set type ibss"
), "Setting ad-hoc mode"
);

# leave any existing IBSS before configuring a new one
log(
run_program(
"/data/data/org.servalproject/bin/iw dev " +
getcfg("wifi.interface") + " ibss leave"
), "Leaving previous associated IBSS"
);

# join a new IBSS
log(
run_program(
"/data/data/org.servalproject/bin/iw dev " +
getcfg("wifi.interface") + " ibss join " +
getcfg("wifi.essid") + " " + getcfg("wifi.frequency")
), "Joining IBSS"
);

@@ -0,0 +1,4 @@
exists /system/bin/ndc
exists /system/etc/wifi/bcmdhd.cal
capability Adhoc galaxynexus.adhoc.edify galaxynexus.off.edify
nowirelessextensions
Empty file.
@@ -10,5 +10,5 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-8
target=android-10
apk-configurations=
@@ -22,11 +22,15 @@
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.servalproject.ServalBatPhoneApplication;
import org.servalproject.shell.CommandCapture;
import org.servalproject.shell.Shell;

import android.annotation.TargetApi;
import android.os.Build;
import android.util.Log;

public enum WifiMode {
@@ -72,6 +76,7 @@ public static WifiMode getWiFiMode(String interfaceName) {
return getWiFiMode(null, interfaceName);
}

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static WifiMode getWiFiMode(Shell rootShell, String interfaceName) {
NetworkInterface networkInterface = null;
lastIwconfigOutput = null;
@@ -83,13 +88,48 @@ public static WifiMode getWiFiMode(Shell rootShell, String interfaceName) {
// interface doesn't exist? must be off.
if (networkInterface == null)
return WifiMode.Off;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD
&& !networkInterface.isUp()) {
/* With non-wext drivers, network type is kept even when network interface is down */
return WifiMode.Off;
}
} catch (Exception e) {
Log.e("BatPhone/WifiMode", e.toString(), e);
}

if (ChipsetDetection.getDetection().getWifiChipset()
.lacksWirelessExtensions()) {

/* maybe it works with "iw", let's try */
CoreTask coretask = ServalBatPhoneApplication.context.coretask;
CommandCapture c = new CommandCapture(coretask.DATA_FILE_PATH + "/bin/iw dev "
+ interfaceName + " info");
try {
if (rootShell == null) {
rootShell = Shell.startShell();
}
rootShell.run(c);
if (c.exitCode() == 0) {
Pattern iwTypePattern = Pattern.compile("type\\s(\\w+)");
Matcher m = iwTypePattern.matcher(c.toString());
if (m.find()) {
String type = m.group(1).toLowerCase();
if ("managed".equals(type)) {
return WifiMode.Client;
}
if ("ibss".equals(type)) {
return WifiMode.Adhoc;
}
return WifiMode.Unknown;
}
}
/* fall through, try something else */
} catch (Exception e) {
Log.e("WifiMode", "Cannot execute iw", e);
/* fall through, try something else */
}

// We cannot use iwstatus, so see if our interface/IP is available.
// IP address is probably the safest option.

0 comments on commit b1e00d1

Please sign in to comment.