@Override
 @SideOnly(Side.CLIENT)
 public void registerIcons(IIconRegister par1IconRegister) {
   for (Chipset chipset : Chipset.VALUES) {
     chipset.icon =
         par1IconRegister.registerIcon("buildcraftsilicon:chipset/" + chipset.getChipsetName());
   }
 }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 @SideOnly(Side.CLIENT)
 public void getSubItems(Item item, CreativeTabs tab, List itemList) {
   for (Chipset chipset : Chipset.VALUES) {
     itemList.add(chipset.getStack());
   }
 }
 public void registerItemStacks() {
   for (Chipset chipset : Chipset.VALUES) {
     GameRegistry.registerCustomItemStack(chipset.getChipsetName(), chipset.getStack());
     OreDictionary.registerOre(
         "chipset"
             + chipset.name().toUpperCase().substring(0, 1)
             + chipset.name().toLowerCase().substring(1),
         chipset.getStack());
   }
 }
예제 #4
0
  public Set<Chipset> getDetectedChipsets(Shell shell, LogOutput log) {
    log.log("Scanning for known android hardware");

    Set<Chipset> detected_chipsets = new TreeSet<Chipset>();
    boolean hasNetlink = hasNl80211(shell);
    boolean foundSupported = false;

    File detectScripts = new File(detectPath);
    if (!detectScripts.isDirectory()) return null;

    for (File script : detectScripts.listFiles()) {
      if (!script.getName().endsWith(".detect")) continue;

      Chipset c = Chipset.FromFile(script);
      if (testChipset(c, hasNetlink)) {
        detected_chipsets.add(c);
        if (!c.experimental) foundSupported = true;
      }
    }

    if (!foundSupported) {
      log.log("Hardware may be unknown, scanning for wifi modules");
      inventSupport(detected_chipsets, hasNetlink);
    }
    return detected_chipsets;
  }
예제 #5
0
  // set chipset configuration
  public void setChipset(Chipset chipset) {
    if (chipset == null) {
      chipset = new Chipset();
      chipset.unknown = true;
    }

    // add support for modes via SDK if available
    if (!chipset.supportedModes.contains(WifiMode.Ap) && WifiApControl.isApSupported())
      chipset.supportedModes.add(WifiMode.Ap);

    if (!chipset.supportedModes.contains(WifiMode.Client))
      chipset.supportedModes.add(WifiMode.Client);
    if (!chipset.supportedModes.contains(WifiMode.Off)) chipset.supportedModes.add(WifiMode.Off);

    // make sure we have root permission for adhoc support
    if (chipset.supportedModes.contains(WifiMode.Adhoc)) {
      if (getAdhocAttemptFile(chipset).exists()) {
        chipset.supportedModes.remove(WifiMode.Adhoc);
        Log.v(TAG, "Adhoc mode has previously failed and cannot be supported.");
      } else if (!app.coretask.hasRootPermission()) {
        chipset.supportedModes.remove(WifiMode.Adhoc);
        Log.v(TAG, "Unable to support adhoc mode without root permission");
      }
    }

    wifichipset = chipset;

    if (chipset.supportedModes.contains(WifiMode.Adhoc)) {
      try {
        FileOutputStream out = new FileOutputStream(edifyPath);
        FileInputStream fstream = new FileInputStream(edifysrcPath);
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        String strLine;
        // Read File Line By Line
        while ((strLine = in.readLine()) != null) {
          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);
          } else out.write((strLine + "\n").getBytes());
        }
        in.close();
        out.close();
      } catch (IOException exc) {
        Log.e(TAG, exc.getMessage(), exc);
      }
    }
  }
예제 #6
0
  private boolean testChipset(Chipset chipset, boolean hasNetlink) {
    if (chipset.detected) return true;
    if (chipset.nl80211 && !hasNetlink) return false;
    for (String filename : chipset.mustExist) {
      if (!fileExists(filename)) return false;
    }
    for (String filename : chipset.mustNotExist) {
      if (fileExists(filename)) return false;
    }
    if (chipset.androidVersion > 0) {
      int sdkVersion = Build.VERSION.SDK_INT;

      if (chipset.androidOperator == "<") {
        if (chipset.androidVersion >= sdkVersion) return false;
      } else if (chipset.androidOperator == "<=") {
        if (chipset.androidVersion > sdkVersion) return false;
      } else if (chipset.androidOperator == ">") {
        if (chipset.androidVersion <= sdkVersion) return false;
      } else if (chipset.androidOperator == ">=") {
        if (chipset.androidVersion < sdkVersion) return false;
      } else if (chipset.androidOperator == "==") {
        if (chipset.androidVersion != sdkVersion) return false;
      } else {
        return false;
      }
    }
    if (!chipset.productList.isEmpty()) {
      boolean found = false;
      for (String product : chipset.productList) {
        if (Build.PRODUCT.contains(product)) {
          found = true;
          break;
        }
      }
      if (!found) return false;
    }
    chipset.detected = true;
    return true;
  }
예제 #7
0
  private void inventSupport(Set<Chipset> detected_chipsets, boolean hasNetlink) {
    // Make a wild guess for a script that MIGHT work
    // Start with list of kernel modules
    // XXX we should search for files containing insmod to see if there are
    // any parameters that might be needed (as is the case on the IDEOS
    // U8150)

    Set<String> insmodCommands = new HashSet<String>();

    List<String> knownModules = getList(this.detectPath + "known-wifi.modules");
    List<String> knownNonModules = getList(this.detectPath + "non-wifi.modules");
    List<File> candidatemodules = findModules(insmodCommands);
    List<File> modules = new ArrayList<File>();
    int guesscount = 0;
    // First, let's just try only known modules.
    // XXX - These are the wrong search methods
    for (File module : candidatemodules) {
      if (module.getName().endsWith(".ko"))
        if (!knownNonModules.contains(module.getName()))
          if (knownModules.contains(module.getName())) modules.add(module);
    }

    if (modules.isEmpty()) {
      // We didn't find any on our strict traversal, so try again
      // allowing any non-black-listed modules
      for (File module : candidatemodules) {
        if (module.getName().endsWith(".ko"))
          if (!knownNonModules.contains(module.getName())) modules.add(module);
      }
    }

    if (modules.isEmpty()) {
      // Blast. Couldn't find any modules.
      // Well, let's just try ifconfig and iwconfig anyway, as they
      // might just work.
    }

    // Now that we have the list of modules, we could have a look to see
    // if there are any sample insmod commands
    // that we can find in any system files for clues on what parameters
    // to pass when loading the module, e.g.,
    // any firmware blobs or nvram.txt or other options.
    // XXX - Rather obviously we have not implemented this yet.

    LogActivity.logErase("guess");

    String profilename = "failed";

    for (File m : modules) {
      String path = m.getPath();
      insmodCommands.add("insmod " + path + " \"\"");
    }

    for (String s : insmodCommands) {
      String module = null;
      String args = null;
      String modname = "noidea";
      int i;

      i = s.indexOf("insmod ");
      if (i == -1) continue;
      i += 7;
      module = getNextShellArg(s.substring(i));
      i += module.length() + 1;
      if (i < s.length()) args = getNextShellArg(s.substring(i));
      else args = "\"\"";
      if (args.charAt(0) != '\"') args = "\"" + args + "\"";

      modname = module;
      if (modname.lastIndexOf(".") > -1) modname = modname.substring(1, modname.lastIndexOf("."));
      if (modname.lastIndexOf("/") > -1) modname = modname.substring(1 + modname.lastIndexOf("/"));

      guesscount++;
      profilename = "guess-" + guesscount + "-" + modname + "-" + args.length();

      // 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
      // cleverness for that.

      try {
        BufferedWriter writer =
            new BufferedWriter(
                new FileWriter(this.detectPath + profilename + ".adhoc.edify", false), 256);

        // Write out edify command to load the module
        writer.write(
            "module_loaded(\""
                + modname
                + "\") || log(insmod(\""
                + module
                + "\","
                + args
                + "),\"Loading "
                + module
                + " module\");\n");

        writer.close();
      } catch (IOException e) {
        Log.e(TAG, e.toString(), e);
      }

      // Finally to turn off wifi let's just unload all the modules we
      // loaded earlier.
      // Crude but fast and effective.
      try {
        BufferedWriter writer =
            new BufferedWriter(
                new FileWriter(this.detectPath + profilename + ".off.edify", false), 256);

        // Write out edify command to load the module
        writer.write("module_loaded(\"" + modname + "\") && rmmod(\"" + modname + "\");\n");
        writer.close();
      } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
      }

      // Now write out a detect script for this device.
      // Mark it experimental because we can't be sure that it will be any
      // good. This means that users will have to actively choose it from
      // the
      // wifi settings menu. We could offer it if no non-experimental
      // chipsets match, but that is best done as a general
      // policy in the way the chipset selection works.
      Chipset ret = new Chipset();
      ret.experimental = true;
      ret.adhocOn = profilename + ".adhoc.edify " + profilename + ".edify";
      ret.adhocOff = profilename + ".adhoc.edify " + profilename + ".off.edify";
      ret.interfaceUp = (hasNetlink ? "iw" : "iwconfig") + ".adhoc.edify";
      if (hasNetlink) {
        ret.nl80211 = true;
        ret.noWirelessExtensions = true;
      }
      if (module.contains("/")) ret.mustExist.add(module);
      try {
        ret.SaveTo(new File(this.detectPath + profilename + ".detect"));
      } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
      }

      if (testChipset(ret, hasNetlink)) detected_chipsets.add(ret);

      LogActivity.logMessage(
          "guess",
          "Created best-guess support scripts "
              + profilename
              + " based on kernel module "
              + modname
              + ".",
          false);
    }
  }
예제 #8
0
 public void setChipsetName(String value) {
   setChipset(Chipset.FromFile(new File(detectPath, value + ".detect")));
 }
 @Override
 public String getUnlocalizedName(ItemStack stack) {
   return "item." + Chipset.fromOrdinal(stack.getItemDamage()).getChipsetName();
 }
 @Override
 public IIcon getIconFromDamage(int damage) {
   return Chipset.fromOrdinal(damage).icon;
 }