Bug 790231 - Add a way of telling if a scan result supports WPS. r=mrbkap
authorMasashi Honma <masashi.honma@gmail.com>
Fri, 05 Oct 2012 16:13:54 -0400
changeset 109454 8321d22a0957f45ada5c57009671c4d485cc0613
parent 109453 1ddc6403c0603eb86e608805561ac5f3bc587023
child 109455 569c37d763ce147d58d783c9e1c973c4f858cc22
push id23630
push useremorley@mozilla.com
push dateSat, 06 Oct 2012 19:35:27 +0000
treeherdermozilla-central@9f677c2bb33d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs790231
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790231 - Add a way of telling if a scan result supports WPS. r=mrbkap
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1232,16 +1232,26 @@ function getKeyManagement(flags) {
     types.push("WPA-PSK");
   if (/\[WPA2?-EAP/.test(flags))
     types.push("WPA-EAP");
   if (/\[WEP/.test(flags))
     types.push("WEP");
   return types;
 }
 
+function getCapabilities(flags) {
+  var types = [];
+  if (!flags)
+    return types;
+
+  if (/\[WPS/.test(flags))
+    types.push("WPS");
+  return types;
+}
+
 // These constants shamelessly ripped from WifiManager.java
 // strength is the value returned by scan_results. It is nominally in dB. We
 // transform it into a percentage for clients looking to simply show a
 // relative indication of the strength of a network.
 const MIN_RSSI = -100;
 const MAX_RSSI = -55;
 
 function calculateSignal(strength) {
@@ -1254,44 +1264,48 @@ function calculateSignal(strength) {
 
   if (strength <= MIN_RSSI)
     return 0;
   if (strength >= MAX_RSSI)
     return 100;
   return Math.floor(((strength - MIN_RSSI) / (MAX_RSSI - MIN_RSSI)) * 100);
 }
 
-function Network(ssid, capabilities, password) {
+function Network(ssid, security, password, capabilities) {
   this.ssid = ssid;
-  this.capabilities = capabilities;
+  this.security = security;
 
   if (typeof password !== "undefined")
     this.password = password;
+  if (typeof capabilities !== "undefined")
+    this.capabilities = capabilities;
   // TODO connected here as well?
 
   this.__exposedProps__ = Network.api;
 }
 
 Network.api = {
   ssid: "r",
+  security: "r",
   capabilities: "r",
   known: "r",
 
   password: "rw",
   keyManagement: "rw",
   psk: "rw",
   identity: "rw",
   wep: "rw",
   hidden: "rw"
 };
 
 // Note: We never use ScanResult.prototype, so the fact that it's unrelated to
 // Network.prototype is OK.
 function ScanResult(ssid, bssid, flags, signal) {
-  Network.call(this, ssid, getKeyManagement(flags));
+  Network.call(this, ssid, getKeyManagement(flags), undefined,
+               getCapabilities(flags));
   this.bssid = bssid;
   this.signalStrength = signal;
   this.relSignalStrength = calculateSignal(Number(signal));
 
   this.__exposedProps__ = ScanResult.api;
 }
 
 // XXX This should probably live in the DOM-facing side, but it's hard to do
@@ -1418,29 +1432,27 @@ function WifiWorker() {
 
   // A list of requests to turn wifi on or off.
   this._stateRequests = [];
 
   // Given a connection status network, takes a network from
   // self.configuredNetworks and prepares it for the DOM.
   netToDOM = function(net) {
     var ssid = dequote(net.ssid);
-    var capabilities = (net.key_mgmt === "NONE" && net.wep_key0)
-                       ? ["WEP"]
-                       : (net.key_mgmt && net.key_mgmt !== "NONE")
-                       ? [net.key_mgmt]
-                       : [];
+    var security = (net.key_mgmt === "NONE" && net.wep_key0) ? ["WEP"]
+                   : (net.key_mgmt && net.key_mgmt !== "NONE") ? [net.key_mgmt]
+                   : [];
     var password;
     if (("psk" in net && net.psk) ||
         ("password" in net && net.password) ||
         ("wep_key0" in net && net.wep_key0)) {
       password = "*";
     }
 
-    var pub = new Network(ssid, capabilities, password);
+    var pub = new Network(ssid, security, password);
     if (net.identity)
       pub.identity = dequote(net.identity);
     if (net.netId)
       pub.known = true;
     if (net.scan_ssid === 1)
       pub.hidden = true;
     return pub;
   };
@@ -1451,16 +1463,17 @@ function WifiWorker() {
     // thing).
     // NB: Modifies net in place: safe since we don't share objects between
     // the dom and the chrome code.
 
     // Things that are useful for the UI but not to us.
     delete net.bssid;
     delete net.signalStrength;
     delete net.relSignalStrength;
+    delete net.security;
     delete net.capabilities;
 
     if (!configured)
       configured = {};
 
     net.ssid = quote(net.ssid);
 
     let wep = false;