Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1523da22 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix driver start/stop handling

The driver start and stop events will be removed as they are now
redundant (and incorrect)

Move to using supplicant INTERFACE_DISABLED indication for deciding
if driver has started or stopped

When driver start is given, the supplicant will first switch to
INTERFACE_DISABLED state and then out of it to start connecting.
We should use this indication to find out driver has started

When driver stop is given, the supplicant will just switch to
INTERFACE_DISABLED state and this indicates driver has stopped

Bug: 4550125
Change-Id: I242cda97951a733c8707c8d99cdfcc9a33b75c2d
parent e14674d5
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -216,6 +216,28 @@ public enum SupplicantState implements Parcelable {
        }
    }

    static boolean isDriverActive(SupplicantState state) {
        switch(state) {
            case DISCONNECTED:
            case DORMANT:
            case INACTIVE:
            case AUTHENTICATING:
            case ASSOCIATING:
            case ASSOCIATED:
            case SCANNING:
            case FOUR_WAY_HANDSHAKE:
            case GROUP_HANDSHAKE:
            case COMPLETED:
                return true;
            case INTERFACE_DISABLED:
            case UNINITIALIZED:
            case INVALID:
                return false;
            default:
                throw new IllegalArgumentException("Unknown supplicant state");
        }
    }

    /** Implement the Parcelable interface {@hide} */
    public int describeContents() {
        return 0;
+2 −6
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class WifiMonitor {
     * <pre>
     * CTRL-EVENT-DRIVER-STATE state
     * </pre>
     * <code>state</code> is either STARTED or STOPPED
     * <code>state</code> can be HANGED
     */
    private static final String driverStateEvent = "DRIVER-STATE";
    /**
@@ -304,11 +304,7 @@ public class WifiMonitor {
            if (state == null) {
                return;
            }
            if (state.equals("STOPPED")) {
                mWifiStateMachine.notifyDriverStopped();
            } else if (state.equals("STARTED")) {
                mWifiStateMachine.notifyDriverStarted();
            } else if (state.equals("HANGED")) {
            if (state.equals("HANGED")) {
                mWifiStateMachine.notifyDriverHung();
            }
        }
+70 −60
Original line number Diff line number Diff line
@@ -212,22 +212,18 @@ public class WifiStateMachine extends StateMachine {
    static final int SUP_CONNECTION_EVENT                 = BASE + 31;
    /* Connection to supplicant lost */
    static final int SUP_DISCONNECTION_EVENT              = BASE + 32;
    /* Driver start completed */
    static final int DRIVER_START_EVENT                   = BASE + 33;
    /* Driver stop completed */
    static final int DRIVER_STOP_EVENT                    = BASE + 34;
   /* Network connection completed */
    static final int NETWORK_CONNECTION_EVENT             = BASE + 36;
    static final int NETWORK_CONNECTION_EVENT             = BASE + 33;
    /* Network disconnection completed */
    static final int NETWORK_DISCONNECTION_EVENT          = BASE + 37;
    static final int NETWORK_DISCONNECTION_EVENT          = BASE + 34;
    /* Scan results are available */
    static final int SCAN_RESULTS_EVENT                   = BASE + 38;
    static final int SCAN_RESULTS_EVENT                   = BASE + 35;
    /* Supplicate state changed */
    static final int SUPPLICANT_STATE_CHANGE_EVENT        = BASE + 39;
    static final int SUPPLICANT_STATE_CHANGE_EVENT        = BASE + 36;
    /* Password failure and EAP authentication failure */
    static final int AUTHENTICATION_FAILURE_EVENT         = BASE + 40;
    static final int AUTHENTICATION_FAILURE_EVENT         = BASE + 37;
    /* WPS overlap detected */
    static final int WPS_OVERLAP_EVENT                    = BASE + 41;
    static final int WPS_OVERLAP_EVENT                    = BASE + 38;


    /* Supplicant commands */
@@ -1421,6 +1417,35 @@ public class WifiStateMachine extends StateMachine {
        return mNetworkInfo.getDetailedState();
    }


    private SupplicantState handleSupplicantStateChange(Message message) {
        StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
        SupplicantState state = stateChangeResult.state;
        // Supplicant state change
        // [31-13] Reserved for future use
        // [8 - 0] Supplicant state (as defined in SupplicantState.java)
        // 50023 supplicant_state_changed (custom|1|5)
        EventLog.writeEvent(EVENTLOG_SUPPLICANT_STATE_CHANGED, state.ordinal());
        mWifiInfo.setSupplicantState(state);
        // Network id is only valid when we start connecting
        if (SupplicantState.isConnecting(state)) {
            mWifiInfo.setNetworkId(stateChangeResult.networkId);
        } else {
            mWifiInfo.setNetworkId(WifiConfiguration.INVALID_NETWORK_ID);
        }

        if (state == SupplicantState.ASSOCIATING) {
            /* BSSID is valid only in ASSOCIATING state */
            mWifiInfo.setBSSID(stateChangeResult.BSSID);
        }
        setNetworkDetailedState(WifiInfo.getDetailedStateOf(state));

        mSupplicantStateTracker.sendMessage(Message.obtain(message));
        mWpsStateMachine.sendMessage(Message.obtain(message));

        return state;
    }

    /**
     * Resets the Wi-Fi Connections by clearing any state, resetting any sockets
     * using the interface, stopping DHCP & disabling interface
@@ -1674,14 +1699,6 @@ public class WifiStateMachine extends StateMachine {
        sendMessage(SCAN_RESULTS_EVENT);
    }

    void notifyDriverStarted() {
        sendMessage(DRIVER_START_EVENT);
    }

    void notifyDriverStopped() {
        sendMessage(DRIVER_STOP_EVENT);
    }

    void notifyDriverHung() {
        setWifiEnabled(false);
        setWifiEnabled(true);
@@ -1737,8 +1754,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_REASSOCIATE:
                case SUP_CONNECTION_EVENT:
                case SUP_DISCONNECTION_EVENT:
                case DRIVER_START_EVENT:
                case DRIVER_STOP_EVENT:
                case NETWORK_CONNECTION_EVENT:
                case NETWORK_DISCONNECTION_EVENT:
                case SCAN_RESULTS_EVENT:
@@ -2284,13 +2299,19 @@ public class WifiStateMachine extends StateMachine {
        public boolean processMessage(Message message) {
            if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
            switch(message.what) {
                case DRIVER_START_EVENT:
               case SUPPLICANT_STATE_CHANGE_EVENT:
                    SupplicantState state = handleSupplicantStateChange(message);
                    /* If suplicant is exiting out of INTERFACE_DISABLED state into
                     * a state that indicates driver has started, it is ready to
                     * receive driver commands
                     */
                    if (SupplicantState.isDriverActive(state)) {
                        transitionTo(mDriverStartedState);
                    }
                    break;
                    /* Queue driver commands & connection events */
                case CMD_START_DRIVER:
                case CMD_STOP_DRIVER:
                case SUPPLICANT_STATE_CHANGE_EVENT:
                case NETWORK_CONNECTION_EVENT:
                case NETWORK_DISCONNECTION_EVENT:
                case AUTHENTICATION_FAILURE_EVENT:
@@ -2429,8 +2450,11 @@ public class WifiStateMachine extends StateMachine {
        public boolean processMessage(Message message) {
            if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
            switch(message.what) {
                case DRIVER_STOP_EVENT:
                case SUPPLICANT_STATE_CHANGE_EVENT:
                    SupplicantState state = handleSupplicantStateChange(message);
                    if (state == SupplicantState.INTERFACE_DISABLED) {
                        transitionTo(mDriverStoppedState);
                    }
                    break;
                    /* Queue driver commands */
                case CMD_START_DRIVER:
@@ -2468,9 +2492,21 @@ public class WifiStateMachine extends StateMachine {
               case CMD_START_DRIVER:
                   mWakeLock.acquire();
                   WifiNative.startDriverCommand();
                    transitionTo(mDriverStartingState);
                   mWakeLock.release();
                   break;
                case SUPPLICANT_STATE_CHANGE_EVENT:
                    SupplicantState state = handleSupplicantStateChange(message);
                    /* A driver start causes supplicant to first report an INTERFACE_DISABLED
                     * state before transitioning out of it for connection. Stay in
                     * DriverStoppedState until we get an INTERFACE_DISABLED state and transition
                     * to DriverStarting upon getting that
                     * TODO: Fix this when the supplicant can be made to just transition out of
                     * INTERFACE_DISABLED state when driver gets started
                     */
                    if (state == SupplicantState.INTERFACE_DISABLED) {
                        transitionTo(mDriverStartingState);
                    }
                    break;
                default:
                    return NOT_HANDLED;
            }
@@ -2535,28 +2571,7 @@ public class WifiStateMachine extends StateMachine {
                    sendErrorBroadcast(WifiManager.WPS_OVERLAP_ERROR);
                    break;
                case SUPPLICANT_STATE_CHANGE_EVENT:
                    stateChangeResult = (StateChangeResult) message.obj;
                    SupplicantState state = stateChangeResult.state;
                    // Supplicant state change
                    // [31-13] Reserved for future use
                    // [8 - 0] Supplicant state (as defined in SupplicantState.java)
                    // 50023 supplicant_state_changed (custom|1|5)
                    EventLog.writeEvent(EVENTLOG_SUPPLICANT_STATE_CHANGED, state.ordinal());
                    mWifiInfo.setSupplicantState(state);
                    // Network id is only valid when we start connecting
                    if (SupplicantState.isConnecting(state)) {
                        mWifiInfo.setNetworkId(stateChangeResult.networkId);
                    } else {
                        mWifiInfo.setNetworkId(WifiConfiguration.INVALID_NETWORK_ID);
                    }

                    if (state == SupplicantState.ASSOCIATING) {
                        /* BSSID is valid only in ASSOCIATING state */
                        mWifiInfo.setBSSID(stateChangeResult.BSSID);
                    }

                    mSupplicantStateTracker.sendMessage(Message.obtain(message));
                    mWpsStateMachine.sendMessage(Message.obtain(message));
                    handleSupplicantStateChange(message);
                   break;
                    /* Do a redundant disconnect without transition */
                case CMD_DISCONNECT:
@@ -2964,11 +2979,6 @@ public class WifiStateMachine extends StateMachine {
                    /* Ignore network disconnect */
                case NETWORK_DISCONNECTION_EVENT:
                    break;
                case SUPPLICANT_STATE_CHANGE_EVENT:
                    StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
                    setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
                    /* DriverStartedState does the rest of the handling */
                    return NOT_HANDLED;
               case CMD_START_SCAN:
                    /* Disable background scan temporarily during a regular scan */
                    if (mEnableBackgroundScan) {