This commit is contained in:
Ryan VanderMeulen 2012-08-16 20:51:32 -04:00
Родитель 52afa94578 45acb52a4f
Коммит ad0c7a9dde
3 изменённых файлов: 116 добавлений и 4 удалений

Просмотреть файл

@ -78,10 +78,12 @@ DOMWifiManager.prototype = {
"WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
"WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
"WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
"WifiManager:wps:Return:OK", "WifiManager:wps:Return:NO",
"WifiManager:wifiDown", "WifiManager:wifiUp",
"WifiManager:onconnecting", "WifiManager:onassociate",
"WifiManager:onconnect", "WifiManager:ondisconnect",
"WifiManager:connectionInfoUpdate"];
"WifiManager:onwpstimeout", "WifiManager:onwpsfail",
"WifiManager:onwpsoverlap", "WifiManager:connectionInfoUpdate"];
this.initHelper(aWindow, messages);
this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
@ -163,6 +165,16 @@ DOMWifiManager.prototype = {
Services.DOMRequest.fireError(request, msg.data);
break;
case "WifiManager:wps:Return:OK":
request = this.takeRequest(msg.rid);
Services.DOMRequest.fireSuccess(request, true);
break;
case "WifiManager:wps:Return:NO":
request = this.takeRequest(msg.rid);
Services.DOMRequest.fireError(request, msg.data);
break;
case "WifiManager:wifiDown":
this._enabled = false;
this._currentNetwork = null;
@ -202,6 +214,27 @@ DOMWifiManager.prototype = {
this._fireStatusChangeEvent();
break;
case "WifiManager:onwpstimeout":
this._currentNetwork = null;
this._connectionStatus = "wps-timedout";
this._lastConnectionInfo = null;
this._fireStatusChangeEvent();
break;
case "WifiManager:onwpsfail":
this._currentNetwork = null;
this._connectionStatus = "wps-failed";
this._lastConnectionInfo = null;
this._fireStatusChangeEvent();
break;
case "WifiManager:onwpsoverlap":
this._currentNetwork = null;
this._connectionStatus = "wps-overlapped";
this._lastConnectionInfo = null;
this._fireStatusChangeEvent();
break;
case "WifiManager:connectionInfoUpdate":
this._lastConnectionInfo = msg;
this._fireConnectionInfoUpdate(msg);
@ -274,6 +307,14 @@ DOMWifiManager.prototype = {
return request;
},
wps: function nsIDOMWifiManager_wps(detail) {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
var request = this.createRequest();
this._sendMessageForRequest("WifiManager:wps", detail, request);
return request;
},
get enabled() {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);

Просмотреть файл

@ -274,6 +274,14 @@ var WifiManager = (function() {
doSetScanModeCommand(setActive, callback);
}
function wpsPbcCommand(callback) {
doBooleanCommand("WPS_PBC", "OK", callback);
}
function wpsCancelCommand(callback) {
doBooleanCommand("WPS_CANCEL", "OK", callback);
}
function startDriverCommand(callback) {
doBooleanCommand("DRIVER START", "OK");
}
@ -747,7 +755,7 @@ var WifiManager = (function() {
// handle events sent to us by the event worker
function handleEvent(event) {
debug("Event coming in: " + event);
if (event.indexOf("CTRL-EVENT-") !== 0) {
if (event.indexOf("CTRL-EVENT-") !== 0 && event.indexOf("WPS") !== 0) {
if (event.indexOf("WPA:") == 0 &&
event.indexOf("pre-shared key may be incorrect") != -1) {
notify("passwordmaybeincorrect");
@ -835,6 +843,18 @@ var WifiManager = (function() {
notify("scanresultsavailable");
return true;
}
if (eventData.indexOf("WPS-TIMEOUT") === 0) {
notifyStateChange({ state: "WPS_TIMEOUT", BSSID: null, id: -1 });
return true;
}
if (eventData.indexOf("WPS-FAIL") === 0) {
notifyStateChange({ state: "WPS_FAIL", BSSID: null, id: -1 });
return true;
}
if (eventData.indexOf("WPS-OVERLAP-DETECTED") === 0) {
notifyStateChange({ state: "WPS_OVERLAP_DETECTED", BSSID: null, id: -1 });
return true;
}
// unknown event
return true;
}
@ -1155,6 +1175,8 @@ var WifiManager = (function() {
setScanModeCommand(mode === "active", callback);
}
manager.scan = scanCommand;
manager.wpsPbc = wpsPbcCommand;
manager.wpsCancel = wpsCancelCommand;
manager.getRssiApprox = getRssiApproxCommand;
manager.getLinkSpeed = getLinkSpeedCommand;
manager.getDhcpInfo = function() { return dhcpInfo; }
@ -1301,7 +1323,7 @@ function WifiWorker() {
this._mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
const messages = ["WifiManager:setEnabled", "WifiManager:getNetworks",
"WifiManager:associate", "WifiManager:forget",
"WifiManager:getState"];
"WifiManager:wps", "WifiManager:getState"];
messages.forEach((function(msgName) {
this._mm.addMessageListener(msgName, this);
@ -1528,6 +1550,15 @@ function WifiWorker() {
null);
break;
case "WPS_TIMEOUT":
self._fireEvent("onwpstimeout", {});
break;
case "WPS_FAIL":
self._fireEvent("onwpsfail", {});
break;
case "WPS_OVERLAP_DETECTED":
self._fireEvent("onwpsoverlap", {});
break;
}
};
@ -1861,6 +1892,9 @@ WifiWorker.prototype = {
case "WifiManager:forget":
this.forget(msg.data, msg.rid, msg.mid);
break;
case "WifiManager:wps":
this.wps(msg.data, msg.rid, msg.mid);
break;
case "WifiManager:getState": {
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
return { network: net,
@ -2048,6 +2082,29 @@ WifiWorker.prototype = {
});
},
wps: function(detail, rid, mid) {
const message = "WifiManager:wps:Return";
let self = this;
if (detail.method === "pbc") {
WifiManager.wpsPbc(function(ok) {
if (ok)
self._sendMessage(message, true, true, rid, mid);
else
self._sendMessage(message, false, "WPS PBC failed", rid, mid);
});
} else if (detail.method === "cancel") {
WifiManager.wpsCancel(function(ok) {
if (ok)
self._sendMessage(message, true, true, rid, mid);
else
self._sendMessage(message, false, "WPS Cancel failed", rid, mid);
});
} else {
self._sendMessage(message, false, "Unknown wps method=" + detail.method +
" was received", rid, mid);
}
},
// This is a bit ugly, but works. In particular, this depends on the fact
// that RadioManager never actually tries to get the worker from us.
get worker() { throw "Not implemented"; },

Просмотреть файл

@ -17,7 +17,7 @@ interface nsIWifi : nsISupports
void shutdown();
};
[scriptable, uuid(eda793cd-0bb3-475e-9223-0e778856ebd1)]
[scriptable, uuid(b1f2e67f-75a8-4781-bf7f-eb21662ae9f3)]
interface nsIDOMWifiManager : nsISupports
{
/**
@ -63,6 +63,20 @@ interface nsIDOMWifiManager : nsISupports
*/
nsIDOMDOMRequest forget(in jsval network);
/**
* Wi-Fi Protected Setup functionality.
* @param detail WPS detail which has 'method' and 'pin' field.
* The possible method field values are:
* - pbc: The Push Button Configuration.
* - pin: The PIN configuration.
* - cancel: Request to cancel WPS in progress.
* If method field is 'pin', 'pin' field can exist and has
* a PIN number.
* onsuccess: We have successfully started/canceled wps.
* onerror: We have failed to start/cancel wps.
*/
nsIDOMDOMRequest wps(in jsval detail);
/**
* TODO Remove in favor of a settings API.
* Returns whether or not wifi is currently enabled.