Permalink
Browse files

Add preliminary support for using iw in Chipset and active Mode detec…

…tion
  • Loading branch information...
lakeman committed Jun 27, 2013
1 parent 7a6104f commit 405e915397a7b5feef37c87961646273d299526d
@@ -1,4 +1,4 @@
exists /lib/modules/dhd.ko
exists /system/etc/wifi/bcm4330_sta.bin
exists /system/etc/wifi/nvram_net.txt
-capability Adhoc sgs2.adhoc.edify sgs2.off.edify
+capability Adhoc sgs2.adhoc.edify sgs2.off.edify iwconfig.adhoc.edify
@@ -1,4 +1,4 @@
exists /lib/modules/dhd.ko
exists /system/vendor/firmware/bcm4330_sta.bin
exists /system/etc/nvram_net.txt
-capability Adhoc sgs2cm.adhoc.edify sgs2.off.edify
+capability Adhoc sgs2cm.adhoc.edify sgs2.off.edify iwconfig.adhoc.edify
@@ -0,0 +1,5 @@
+experimental
+nowirelessextensions
+nl80211
+capability Adhoc iw.adhoc.edify
+
@@ -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,12 @@
+log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
+ + " mode ad-hoc"), "Setting ad-hoc mode");
+log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
+ + " essid \"" + getcfg("wifi.essid")+"\""), "Setting essid");
+log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
+ + " channel " + getcfg("wifi.channel")), "Setting channel");
+run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
+ + " commit");
+log(run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " " +
+ getcfg("ip.gateway") + " netmask " + getcfg("ip.netmask")) &&
+ run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " up"), "Activating WiFi interface");
+
@@ -6,3 +6,5 @@ tiwlan_drv.ko
ar6000.ko
ar4000.ko
ar9000.ko
+wifi.ko
+
@@ -1,4 +1,4 @@
exists /system/lib/modules/tiwlan_drv.ko
exists /system/etc/wifi/Fw1273_CHIP.bin
-/system/bin/tiwlan_loader
+exists /system/bin/tiwlan_loader
capability Adhoc legend.adhoc.edify legend.off.edify
@@ -1,14 +1,3 @@
module_loaded("dhd") && rmmod("dhd");
log(insmod("/lib/modules/dhd.ko","dhd_pkt_filter_enable=0 firmware_path=/system/etc/wifi/bcm4330_sta.bin nvram_path=/system/etc/wifi/nvram_net.txt"),"Loading /lib/modules/dhd.ko module");
sleep("3");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " mode ad-hoc"), "Setting ad-hoc mode");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " essid \"" + getcfg("wifi.essid")+"\""), "Setting essid");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " channel " + getcfg("wifi.channel")), "Setting channel");
-run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " commit");
-log(run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " " +
- getcfg("ip.gateway") + " netmask " + getcfg("ip.netmask")) &&
- run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " up"), "Activating WiFi interface");
@@ -1,14 +1,3 @@
module_loaded("dhd") && rmmod("dhd");
log(insmod("/lib/modules/dhd.ko","dhd_pkt_filter_enable=0 firmware_path=/system/vendor/firmware/bcm4330_sta.bin nvram_path=/system/etc/nvram_net.txt"),"Loading /lib/modules/dhd.ko module");
sleep("3");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " mode ad-hoc"), "Setting ad-hoc mode");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " essid \"" + getcfg("wifi.essid")+"\""), "Setting essid");
-log(run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " channel " + getcfg("wifi.channel")), "Setting channel");
-run_program("/data/data/org.servalproject/bin/iwconfig " + getcfg("wifi.interface")
- + " commit");
-log(run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " " +
- getcfg("ip.gateway") + " netmask " + getcfg("ip.netmask")) &&
- run_program("/data/data/org.servalproject/bin/ifconfig " + getcfg("wifi.interface") + " up"), "Activating WiFi interface");
@@ -29,11 +29,13 @@
public String chipset;
public Set<WifiMode> supportedModes;
String adhocOn;
+ String interfaceUp;
String adhocOff;
boolean detected = false;
boolean experimental = false;
public boolean unknown = false;
boolean noWirelessExtensions = false;
+ boolean nl80211 = false;
Chipset() {
supportedModes = EnumSet.noneOf(WifiMode.class);
@@ -56,6 +56,8 @@
import org.apache.http.protocol.HttpContext;
import org.servalproject.LogActivity;
import org.servalproject.ServalBatPhoneApplication;
+import org.servalproject.shell.CommandLog;
+import org.servalproject.shell.Shell;
import android.os.Build;
import android.util.Log;
@@ -67,6 +69,7 @@
private static final String strCapability = "capability";
private static final String strExperimental = "experimental";
private static final String strNoWirelessExtensions = "nowirelessextensions";
+ private static final String strNl80211 = "nl80211";
private static final String strAh_on_tag = "#Insert_Adhoc_on";
private static final String strAh_off_tag = "#Insert_Adhoc_off";
private static final String strProduct = "productmatches";
@@ -100,7 +103,6 @@ private ChipsetDetection() {
}
private static ChipsetDetection detection;
- private int experimentalCount = 0;
public static ChipsetDetection getDetection() {
if (detection == null)
@@ -438,10 +440,14 @@ private boolean testForChipset(Chipset chipset) {
chipset.adhocOn = arChipset[2];
if (arChipset.length >= 4)
chipset.adhocOff = arChipset[3];
+ if (arChipset.length >= 5)
+ chipset.interfaceUp = arChipset[3];
} else if (arChipset[0].equals(strExperimental)) {
chipset.experimental = true;
} else if (arChipset[0].equals(strNoWirelessExtensions)) {
chipset.noWirelessExtensions = true;
+ } else if (arChipset[0].equals(strNl80211)) {
+ chipset.nl80211 = true;
} else {
boolean lineMatch = false;
@@ -530,6 +536,25 @@ private void appendFile(FileOutputStream out, String path)
input.close();
}
+ private static int nl80211 = 0;
+
+ public boolean hasNl80211() {
+ if (nl80211 == 0) {
+ try {
+ CommandLog c = new CommandLog(app.coretask.DATA_FILE_PATH
+ + "/bin/iw list");
+ Shell.runCommand(c);
+ if (c.exitCode() == 0)
+ nl80211 = 1;
+ else
+ nl80211 = -1;
+ } catch (Exception e) {
+ Log.e("ChipsetDetection", e.getMessage(), e);
+ }
+ }
+ return nl80211 == 1;
+ }
+
public void inventSupport() {
// Make a wild guess for a script that MIGHT work
// Start with list of kernel modules
@@ -546,7 +571,7 @@ public void inventSupport() {
List<File> candidatemodules = findModules(insmodCommands);
List<File> modules = new ArrayList<File>();
int guesscount = 0;
-
+ boolean nl80211Support = hasNl80211();
// First, let's just try only known modules.
// XXX - These are the wrong search methods
for (File module : candidatemodules) {
@@ -631,9 +656,13 @@ public void inventSupport() {
try {
writer = new BufferedWriter(new FileWriter(detectFile, false),
256);
- writer.write("capability Adhoc " + profilename
- + ".adhoc.edify " + profilename + ".off.edify\n");
- writer.write("experimental\n");
+ writer.write(strCapability + " Adhoc " + profilename
+ + ".adhoc.edify " + profilename + ".off.edify " +
+ (nl80211Support ? "iw" : "iwconfig") + ".adhoc.edify\n");
+ writer.write(strExperimental + "\n");
+ if (nl80211Support)
+ writer.write(strNl80211 + "\n" +
+ strNoWirelessExtensions + "\n");
if (module.contains("/")) {
// XXX We have a problem if we don't know the full path to
// the module
@@ -646,9 +675,7 @@ public void inventSupport() {
Log.e("BatPhone", e.toString(), e);
}
- // The actual edify script consists of the insmod commands followed
- // by templated content
- // that does all the ifconfig/iwconfig stuff.
+ // The actual edify script consists of the insmod commands
// Thus this code does not work with unusual chipsets like the
// tiwlan drivers that use
// funny configuration commands. Oh well. One day we might add some
@@ -663,14 +690,6 @@ public void inventSupport() {
+ "\") || log(insmod(\"" + module + "\"," + args
+ "),\"Loading " + module + " module\");\n");
- // Write templated adhoc.edify script
- String line;
- BufferedReader template = new BufferedReader(new FileReader(
- this.detectPath + "adhoc.edify.template"));
- while ((line = template.readLine()) != null) {
- writer.write(line + "\n");
- }
-
writer.close();
} catch (IOException e) {
Log.e("BatPhone", e.toString(), e);
@@ -829,6 +848,8 @@ public void setChipset(Chipset chipset) {
if (strLine.startsWith(strAh_on_tag)) {
if (chipset.adhocOn != null)
appendFile(out, detectPath + chipset.adhocOn);
+ if (chipset.interfaceUp != null)
+ appendFile(out, detectPath + chipset.interfaceUp);
} else if (strLine.startsWith(strAh_off_tag)) {
if (chipset.adhocOff != null)
appendFile(out, detectPath + chipset.adhocOff);
@@ -855,7 +876,6 @@ public boolean isModeSupported(WifiMode mode) {
public Set<Chipset> getDetectedChipsets() {
if (detected_chipsets == null) {
detected_chipsets = new TreeSet<Chipset>();
- experimentalCount = 0;
File detectScripts = new File(detectPath);
if (!detectScripts.isDirectory())
@@ -866,7 +886,6 @@ public boolean isModeSupported(WifiMode mode) {
continue;
Chipset c = new Chipset(script);
if (testForChipset(c)) {
- this.experimentalCount++;
detected_chipsets.add(c);
}
}
@@ -232,6 +232,54 @@ private void updateAdhocConf() {
props.put("ip.gateway", addr.getHostAddress());
props.put("wifi.interface", coretask.getProp("wifi.interface"));
props.put("wifi.txpower", this.getTxPower());
+ int channel = this.getChannel();
+ props.put("wifi.channel", Integer.toString(channel));
+ int frequency = 2437;
+ switch (channel) {
+ case 1:
+ frequency = 2412;
+ break;
+ case 2:
+ frequency = 2417;
+ break;
+ case 3:
+ frequency = 2422;
+ break;
+ case 4:
+ frequency = 2427;
+ break;
+ case 5:
+ frequency = 2432;
+ break;
+ case 6:
+ frequency = 2437;
+ break;
+ case 7:
+ frequency = 2442;
+ break;
+ case 8:
+ frequency = 2447;
+ break;
+ case 9:
+ frequency = 2452;
+ break;
+ case 10:
+ frequency = 2457;
+ break;
+ case 11:
+ frequency = 2462;
+ break;
+ case 12:
+ frequency = 2467;
+ break;
+ case 13:
+ frequency = 2472;
+ break;
+ case 14:
+ frequency = 2484;
+ break;
+ }
+ props.put("wifi.frequency", Integer.toString(frequency));
props.store(new FileOutputStream(adhoc), null);
} catch (IOException e) {
Oops, something went wrong.

0 comments on commit 405e915

Please sign in to comment.