Bug 806611 - Make wpa_supplicant noisy when debug is enabled for wifi. r=vchang a=bbajaj
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 30 Oct 2012 17:35:34 -0700
changeset 116697 8e94d84fd6e39e03dc5ae0ee99a20ac8a8720da6
parent 116696 deb39a21892f3eb6a1cecf41ded9cd5577fb1433
child 116698 4a62e0864b5d9443cd97dd8226793ef8183e8688
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang, bbajaj
bugs806611
milestone18.0a2
Bug 806611 - Make wpa_supplicant noisy when debug is enabled for wifi. r=vchang a=bbajaj
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();