Bug 998892 - Append "interface=XXX" to the WPS PBC/PIN supplicant command only for JB. r=vchang

This commit is contained in:
Henry Chang 2014-05-06 15:04:16 +08:00
parent b6e64d4eac
commit 1e6c8f331c
3 changed files with 44 additions and 13 deletions

View File

@ -16,7 +16,7 @@ const SUPP_PROP = "init.svc.wpa_supplicant";
const WPA_SUPPLICANT = "wpa_supplicant";
const DEBUG = false;
this.WifiCommand = function(aControlMessage, aInterface) {
this.WifiCommand = function(aControlMessage, aInterface, aSdkVersion) {
function debug(msg) {
if (DEBUG) {
dump('-------------- WifiCommand: ' + msg);
@ -142,17 +142,36 @@ this.WifiCommand = function(aControlMessage, aInterface) {
doStringCommand("LOG_LEVEL", callback);
};
command.wpsPbc = function (iface, callback) {
doBooleanCommand("WPS_PBC" + (iface ? (" interface=" + iface) : ""),
"OK", callback);
command.wpsPbc = function (callback, iface) {
let cmd = 'WPS_PBC';
// If the network interface is specified and we are based on JB,
// append the argument 'interface=[iface]' to the supplicant command.
//
// Note: The argument "interface" is only required for wifi p2p on JB.
// For other cases, the argument is useless and even leads error.
// Check the evil work here:
// http://androidxref.com/4.2.2_r1/xref/external/wpa_supplicant_8/wpa_supplicant/ctrl_iface_unix.c#172
//
if (iface && isJellybean()) {
cmd += (' inferface=' + iface);
}
doBooleanCommand(cmd, "OK", callback);
};
command.wpsPin = function (detail, callback) {
doStringCommand("WPS_PIN " +
(detail.bssid === undefined ? "any" : detail.bssid) +
(detail.pin === undefined ? "" : (" " + detail.pin)) +
(detail.iface ? (" interface=" + detail.iface) : ""),
callback);
let cmd = 'WPS_PIN ';
// See the comment above in wpsPbc().
if (detail.iface && isJellybean()) {
cmd += ('inferface=' + iface + ' ');
}
cmd += (detail.bssid === undefined ? "any" : detail.bssid);
cmd += (detail.pin === undefined ? "" : (" " + detail.pin));
doStringCommand(cmd, callback);
};
command.wpsCancel = function (callback) {
@ -520,5 +539,17 @@ this.WifiCommand = function(aControlMessage, aInterface) {
callback(ok);
}
function isJellybean() {
// According to http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
// ----------------------------------------------------
// | Platform Version | API Level | VERSION_CODE |
// ----------------------------------------------------
// | Android 4.1, 4.1.1 | 16 | JELLY_BEAN_MR2 |
// | Android 4.2, 4.2.2 | 17 | JELLY_BEAN_MR1 |
// | Android 4.3 | 18 | JELLY_BEAN |
// ----------------------------------------------------
return aSdkVersion === 16 || aSdkVersion === 17 || aSdkVersion === 18;
}
return command;
};

View File

@ -1271,7 +1271,7 @@ function P2pStateMachine(aP2pCommand, aNetUtil) {
_sm.pause();
if (WPS_METHOD_PBC === _savedConfig.wpsMethod) {
aP2pCommand.wpsPbc(_groupInfo.ifname, onWpsCommandSent);
aP2pCommand.wpsPbc(onWpsCommandSent, _groupInfo.ifname);
} else {
let detail = { pin: _savedConfig.pin, iface: _groupInfo.ifname };
aP2pCommand.wpsPin(detail, onWpsCommandSent);

View File

@ -161,12 +161,12 @@ var WifiManager = (function() {
// Regular Wifi stuff.
var netUtil = WifiNetUtil(controlMessage);
var wifiCommand = WifiCommand(controlMessage, manager.ifname);
var wifiCommand = WifiCommand(controlMessage, manager.ifname, sdkVersion);
// Wifi P2P stuff
var p2pManager;
if (p2pSupported) {
let p2pCommand = WifiCommand(controlMessage, WifiP2pManager.INTERFACE_NAME);
let p2pCommand = WifiCommand(controlMessage, WifiP2pManager.INTERFACE_NAME, sdkVersion);
p2pManager = WifiP2pManager(p2pCommand, netUtil);
}
@ -3019,7 +3019,7 @@ WifiWorker.prototype = {
let self = this;
let detail = msg.data;
if (detail.method === "pbc") {
WifiManager.wpsPbc(WifiManager.ifname, function(ok) {
WifiManager.wpsPbc(function(ok) {
if (ok)
self._sendMessage(message, true, true, msg);
else