Bug 788081 - B2G tethering: correctly handle 1xx responses from netd. r=philikon

This commit is contained in:
Vincent Chang 2012-09-05 17:30:48 +08:00
parent 00a718898e
commit 443bde7b49
2 changed files with 61 additions and 12 deletions

View File

@ -46,9 +46,17 @@ const TETHERING_TYPE_USB = "USB";
const USB_FUNCTION_RNDIS = "rndis,adb";
const USB_FUNCTION_ADB = "adb";
// 2xx - Requested action has been successfully completed.
const NETD_COMMAND_OKAY = 200;
const NETD_COMMAND_ERROR = 300;
// 1xx - Requested action is proceeding
const NETD_COMMAND_PROCEEDING = 100;
// 2xx - Requested action has been successfully completed
const NETD_COMMAND_OKAY = 200;
// 4xx - The command is accepted but the requested action didn't
// take place.
const NETD_COMMAND_FAIL = 400;
// 5xx - The command syntax or parameters error
const NETD_COMMAND_ERROR = 500;
// 6xx - Unsolicited broadcasts
const NETD_COMMAND_UNSOLICITED = 600;
const WIFI_FIRMWARE_AP = "AP";
const WIFI_FIRMWARE_STATION = "STA";
@ -81,6 +89,20 @@ const MANUAL_PROXY_CONFIGURATION = 1;
const DEBUG = false;
function netdResponseType(code) {
return Math.floor(code/100)*100;
}
function isError(code) {
let type = netdResponseType(code);
return (type != NETD_COMMAND_PROCEEDING && type != NETD_COMMAND_OKAY);
}
function isComplete(code) {
let type = netdResponseType(code);
return (type != NETD_COMMAND_PROCEEDING);
}
/**
* This component watches for network interfaces changing state and then
* adjusts routes etc. accordingly.
@ -761,7 +783,7 @@ NetworkManager.prototype = {
}
// Disable tethering settings when fail to enable it.
if (code < NETD_COMMAND_OKAY && code >= NETD_COMMAND_ERROR) {
if (isError(code)) {
this.tetheringSettings[SETTINGS_WIFI_ENABLED] = false;
settingsLock.set("tethering.wifi.enabled", false, null);
}
@ -776,7 +798,7 @@ NetworkManager.prototype = {
debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
// Disable tethering settings when fail to enable it.
if (code < NETD_COMMAND_OKAY && code >= NETD_COMMAND_ERROR) {
if (isError(code)) {
this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
settingsLock.set("tethering.usb.enabled", false, null);
}

View File

@ -26,12 +26,34 @@ const USB_FUNCTION_RETRY_TIMES = 20;
// Check "sys.usb.state" every 100ms.
const USB_FUNCTION_RETRY_INTERVAL = 100;
// 1xx - Requested action is proceeding
const NETD_COMMAND_PROCEEDING = 100;
// 2xx - Requested action has been successfully completed
const NETD_COMMAND_OKAY = 200;
const NETD_COMMAND_ERROR = 300;
const NETD_COMMAND_OKAY = 200;
// 4xx - The command is accepted but the requested action didn't
// take place.
const NETD_COMMAND_FAIL = 400;
// 5xx - The command syntax or parameters error
const NETD_COMMAND_ERROR = 500;
// 6xx - Unsolicited broadcasts
const NETD_COMMAND_UNSOLICITED = 600;
importScripts("systemlibs.js");
function netdResponseType(code) {
return Math.floor(code/100)*100;
}
function isError(code) {
let type = netdResponseType(code);
return (type != NETD_COMMAND_PROCEEDING && type != NETD_COMMAND_OKAY);
}
function isComplete(code) {
let type = netdResponseType(code);
return (type != NETD_COMMAND_PROCEEDING);
}
let gWifiFailChain = [stopSoftAP,
setIpForwardingEnabled,
stopTethering];
@ -224,17 +246,22 @@ function onNetdMessage(data) {
}
// Set pending to false before we handle next command.
gPending = false;
debug("Receiving '" + gCurrentCommand + "' command response from netd.");
debug(" ==> Code: " + code + " Reason: " + reason);
// 1xx response code regards as command is proceeding, we need to wait for
// final response code such as 2xx, 4xx and 5xx before sending next command.
if (isComplete(code)) {
gPending = false;
}
if (gCurrentCallback) {
let error;
(code >= NETD_COMMAND_OKAY && code < NETD_COMMAND_ERROR) ? (error = false) : (error = true);
gCurrentCallback(error, {code: code, reason: reason});
gCurrentCallback(isError(code), {code: code, reason: reason});
}
// Handling pending commands if any.
nextNetdCommand();
if (isComplete(code)) {
nextNetdCommand();
}
}
/**