From 4e83d08179a0e4352970a2940b991d844ec73888 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Tue, 30 Oct 2012 17:35:34 -0700 Subject: [PATCH] Bug 806611 - Make wpa_supplicant noisy when debug is enabled for wifi. r=vchang --HG-- extra : rebase_source : 4b6065dbf20d1399474e92a8807f85b0c35fdecf --- dom/wifi/WifiWorker.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index 5cda67c34f0e..e303ca004f2f 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -283,6 +283,48 @@ var WifiManager = (function() { 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); @@ -919,6 +961,9 @@ var WifiManager = (function() { waitForEvent(); // Load up the supplicant state. + getDebugEnabled(function(ok) { + syncDebug(); + }); statusCommand(function(status) { parseStatus(status); notify("supplicantconnection"); @@ -1247,6 +1292,7 @@ var WifiManager = (function() { return false; } } + manager.syncDebug = syncDebug; manager.stateOrdinal = function(state) { return supplicantStatesMap.indexOf(state); } @@ -2628,5 +2674,6 @@ function updateDebug() { } else { debug = function (s) {}; } + WifiManager.syncDebug(); } updateDebug();