Bug 806611 - Make wpa_supplicant noisy when debug is enabled for wifi. r=vchang
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 30 Oct 2012 17:35:34 -0700
changeset 112335 c999fc311c2859a4f35475a7745317bead62a2e7
parent 112334 6706f42b153b6b6e7015dd55fa2f440476f9a402
child 112336 c87fcf6ed0a77d0f532b41217b584a806879c5b9
push id23812
push useremorley@mozilla.com
push dateTue, 06 Nov 2012 14:01:34 +0000
treeherdermozilla-central@f4aeed115e54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang
bugs806611
milestone19.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 806611 - Make wpa_supplicant noisy when debug is enabled for wifi. r=vchang
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -278,16 +278,58 @@ var WifiManager = (function() {
           });
         });
       });
       return;
     }
     doBooleanCommand("SCAN", "OK", callback);
   }
 
+  var debugEnabled = false;
+  function setLogLevel(level, callback) {
+    doBooleanCommand("LOG_LEVEL " + level, "OK", callback);
+  }
+
+  function syncDebug() {
+    if (debugEnabled !== DEBUG) {
+      let wanted = DEBUG;
+      setLogLevel(wanted ? "DEBUG" : "INFO", function(ok) {
+        if (ok)
+          debugEnabled = wanted;
+      });
+    }
+  }
+
+  function getLogLevel(callback) {
+    doStringCommand("LOG_LEVEL", callback);
+  }
+
+  function getDebugEnabled(callback) {
+    getLogLevel(function(level) {
+      if (level === null) {
+        debug("Unable to get wpa_supplicant's log level");
+        callback(false);
+        return;
+      }
+
+      var lines = level.split("\n");
+      for (let i = 0; i < lines.length; ++i) {
+        let match = /Current level: (.*)/.exec(lines[i]);
+        if (match) {
+          debugEnabled = match[1].toLowerCase() === "debug";
+          callback(true);
+          return;
+        }
+      }
+
+      // If we're here, we didn't get the current level.
+      callback(false);
+    });
+  }
+
   function setScanModeCommand(setActive, callback) {
     scanModeActive = setActive;
     doSetScanModeCommand(setActive, callback);
   }
 
   function wpsPbcCommand(callback) {
     doBooleanCommand("WPS_PBC", "OK", callback);
   }
@@ -914,16 +956,19 @@ var WifiManager = (function() {
 
     setProperty("ctl.stop", "wpa_supplicant", tick);
   }
 
   function didConnectSupplicant(callback) {
     waitForEvent();
 
     // Load up the supplicant state.
+    getDebugEnabled(function(ok) {
+      syncDebug();
+    });
     statusCommand(function(status) {
       parseStatus(status);
       notify("supplicantconnection");
       callback();
     });
   }
 
   function prepareForStartup(callback) {
@@ -1242,16 +1287,17 @@ var WifiManager = (function() {
       case "SCANNING":
       case "UNINITIALIZED":
       case "INVALID":
       case "CONNECTED":
       default:
         return false;
     }
   }
+  manager.syncDebug = syncDebug;
   manager.stateOrdinal = function(state) {
     return supplicantStatesMap.indexOf(state);
   }
   manager.supplicantLoopDetection = function(prevState, state) {
     var isPrevStateInHandShake = manager.isHandShakeState(prevState);
     var isStateInHandShake = manager.isHandShakeState(state);
 
     if (isPrevStateInHandShake) {
@@ -2623,10 +2669,11 @@ let debug;
 function updateDebug() {
   if (DEBUG) {
     debug = function (s) {
       dump("-*- WifiWorker component: " + s + "\n");
     };
   } else {
     debug = function (s) {};
   }
+  WifiManager.syncDebug();
 }
 updateDebug();