B2G/gecko/dom/wifi/WifiWorker.js
// handle events sent to us by the event worker
handle events sent to us by the event worker
handle events sent to us by the event worker
function handleEvent(event) {
    debug("Event coming in: " + event);
    if (event.indexOf("CTRL-EVENT-") !== 0 && event.indexOf("WPS") !== 0) {
      if (event.indexOf("Association request to the driver failed") !== -1) {
        notify("passwordmaybeincorrect");
        if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
          manager.authenticationFailuresCount = 0;
          notify("disconnected", {ssid: manager.connectionInfo.ssid});
        }
        return true;
      }
      if (event.indexOf("WPA:") == 0 &&
          event.indexOf("pre-shared key may be incorrect") != -1) {
        notify("passwordmaybeincorrect");
      }
      var match = /Trying to associate with.*SSID[ =]'(.*)'/.exec(event);
      if (match) {
        debug("Matched: " + match[1] + "\n");
        manager.connectionInfo.ssid = match[1];
      }
      return true;
    }
    var space = event.indexOf(" ");
    var eventData = event.substr(0, space + 1);
    if (eventData.indexOf("CTRL-EVENT-STATE-CHANGE") === 0) {
      var fields = {};
      var tokens = event.substr(space + 1).split(" ");
      for (var n = 0; n < tokens.length; ++n) {
        var kv = tokens[n].split("=");
        if (kv.length === 2)
          fields[kv[0]] = kv[1];
      }
      if (!("state" in fields))
        return true;
      fields.state = supplicantStatesMap[fields.state];
      if (fields.BSSID !== "00:00:00:00:00:00")
        manager.connectionInfo.bssid = fields.BSSID;
      if (notifyStateChange(fields) && fields.state === "COMPLETED") {
        onconnected();
      }
      return true;
    }
    if (eventData.indexOf("CTRL-EVENT-DRIVER-STATE") === 0) {
      var handlerName = driverEventMap[eventData];
      if (handlerName)
        notify(handlerName);
      return true;
    }
    if (eventData.indexOf("CTRL-EVENT-TERMINATING") === 0) {
      if (eventData.indexOf("connection closed") !== -1) {
        notify("supplicantlost", { success: true });
        return false;
      }
      if (eventData.indexOf("recv error") !== -1 && ++recvErrors < 10)
        return true;
      notifyStateChange({ state: "DISCONNECTED", BSSID: null, id: -1 });
      notify("supplicantlost", { success: true });
      return false;
    }
    if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) {
      var token = event.split(" ")[1];
      var bssid = token.split("=")[1];
      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
        manager.authenticationFailuresCount = 0;
        notify("disconnected", {ssid: manager.connectionInfo.ssid});
      }
      manager.connectionInfo.bssid = null;
      manager.connectionInfo.ssid = null;
      manager.connectionInfo.id = -1;
      return true;
    }
    if (eventData.indexOf("CTRL-EVENT-ASSOC-REJECT") === 0) {
      notify("passwordmaybeincorrect");
      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
        manager.authenticationFailuresCount = 0;
        notify("disconnected", {ssid: manager.connectionInfo.ssid});
      }
      return true;
    }
    if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) {
      var bssid = event.split(" ")[4];
      var id = event.substr(event.indexOf("id=")).split(" ")[0];
      manager.connectionInfo.bssid = bssid;
      return true;
    }
    if (eventData.indexOf("CTRL-EVENT-SCAN-RESULTS") === 0) {
      debug("Notifying of scan results available");
      if (reEnableBackgroundScan) {
        reEnableBackgroundScan = false;
        setBackgroundScan("ON", 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;
    }
    return true;
  }
function handleEvent ( event ) { debug ( "Event coming in: " + event ) ; if ( event . indexOf ( "CTRL-EVENT-" ) !== 0 && event . indexOf ( "WPS" ) !== 0 ) { if ( event . indexOf ( "Association request to the driver failed" ) !== - 1 ) { notify ( "passwordmaybeincorrect" ) ; if ( manager . authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE ) { manager . authenticationFailuresCount = 0 ; notify ( "disconnected" , { ssid : manager . connectionInfo . ssid } ) ; } return true ; } if ( event . indexOf ( "WPA:" ) == 0 && event . indexOf ( "pre-shared key may be incorrect" ) != - 1 ) { notify ( "passwordmaybeincorrect" ) ; } var match = / Trying to associate with.*SSID[ =]'(.*)' / . exec ( event ) ; if ( match ) { debug ( "Matched: " + match [ 1 ] + "\n" ) ; manager . connectionInfo . ssid = match [ 1 ] ; } return true ; } var space = event . indexOf ( " " ) ; var eventData = event . substr ( 0 , space + 1 ) ; if ( eventData . indexOf ( "CTRL-EVENT-STATE-CHANGE" ) === 0 ) { var fields = { } ; var tokens = event . substr ( space + 1 ) . split ( " " ) ; for ( var n = 0 ; n < tokens . length ; ++ n ) { var kv = tokens [ n ] . split ( "=" ) ; if ( kv . length === 2 ) fields [ kv [ 0 ] ] = kv [ 1 ] ; } if ( ! ( "state" in fields ) ) return true ; fields . state = supplicantStatesMap [ fields . state ] ; if ( fields . BSSID !== "00:00:00:00:00:00" ) manager . connectionInfo . bssid = fields . BSSID ; if ( notifyStateChange ( fields ) && fields . state === "COMPLETED" ) { onconnected ( ) ; } return true ; } if ( eventData . indexOf ( "CTRL-EVENT-DRIVER-STATE" ) === 0 ) { var handlerName = driverEventMap [ eventData ] ; if ( handlerName ) notify ( handlerName ) ; return true ; } if ( eventData . indexOf ( "CTRL-EVENT-TERMINATING" ) === 0 ) { if ( eventData . indexOf ( "connection closed" ) !== - 1 ) { notify ( "supplicantlost" , { success : true } ) ; return false ; } if ( eventData . indexOf ( "recv error" ) !== - 1 && ++ recvErrors < 10 ) return true ; notifyStateChange ( { state : "DISCONNECTED" , BSSID : null , id : - 1 } ) ; notify ( "supplicantlost" , { success : true } ) ; return false ; } if ( eventData . indexOf ( "CTRL-EVENT-DISCONNECTED" ) === 0 ) { var token = event . split ( " " ) [ 1 ] ; var bssid = token . split ( "=" ) [ 1 ] ; if ( manager . authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE ) { manager . authenticationFailuresCount = 0 ; notify ( "disconnected" , { ssid : manager . connectionInfo . ssid } ) ; } manager . connectionInfo . bssid = null ; manager . connectionInfo . ssid = null ; manager . connectionInfo . id = - 1 ; return true ; } if ( eventData . indexOf ( "CTRL-EVENT-ASSOC-REJECT" ) === 0 ) { notify ( "passwordmaybeincorrect" ) ; if ( manager . authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE ) { manager . authenticationFailuresCount = 0 ; notify ( "disconnected" , { ssid : manager . connectionInfo . ssid } ) ; } return true ; } if ( eventData . indexOf ( "CTRL-EVENT-CONNECTED" ) === 0 ) { var bssid = event . split ( " " ) [ 4 ] ; var id = event . substr ( event . indexOf ( "id=" ) ) . split ( " " ) [ 0 ] ; manager . connectionInfo . bssid = bssid ; return true ; } if ( eventData . indexOf ( "CTRL-EVENT-SCAN-RESULTS" ) === 0 ) { debug ( "Notifying of scan results available" ) ; if ( reEnableBackgroundScan ) { reEnableBackgroundScan = false ; setBackgroundScan ( "ON" , 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 ; } return true ; }
handle events sent to us by the event worker
handle events sent to us by the event worker
// Handle connection fail exception on WEP-128, while password length // is not 5 nor 13 bytes. // This is ugly, but we need to grab the SSID here. BSSID is not guaranteed // to be provided, so don't grab BSSID here. // Parse the event data // The BSSID field is only valid in the ASSOCIATING and ASSOCIATED // states, except when we "reauth", except this seems to depend on the // driver, so simply check to make sure that we don't have a null BSSID. // If the monitor socket is closed, we have already stopped the // supplicant and we can stop waiting for more events and // simply exit here (we don't have to notify about having lost // the connection). // As long we haven't seen too many recv errors yet, we // will keep going for a bit longer // Association reject is triggered mostly on incorrect WEP key. // Format: CTRL-EVENT-CONNECTED - Connection to 00:1e:58:ec:d5:6d completed (reauth) [id=1 id_str=] // Read current BSSID here, it will always being provided. // unknown event