diff options
Diffstat (limited to 'wifi/java/android')
| -rw-r--r-- | wifi/java/android/net/wifi/WifiMonitor.java | 506 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 53 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 20 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 5 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 2 |
5 files changed, 374 insertions, 212 deletions
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java index fe3c709..92b8e46 100644 --- a/wifi/java/android/net/wifi/WifiMonitor.java +++ b/wifi/java/android/net/wifi/WifiMonitor.java @@ -32,7 +32,10 @@ import android.util.Log; import com.android.internal.util.Protocol; import com.android.internal.util.StateMachine; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import java.util.regex.Matcher; @@ -44,6 +47,7 @@ import java.util.regex.Matcher; */ public class WifiMonitor { + private static final boolean DBG = false; private static final String TAG = "WifiMonitor"; /** Events we receive from the supplicant daemon */ @@ -279,9 +283,6 @@ public class WifiMonitor { /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */ private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED"; - private final StateMachine mStateMachine; - private final WifiNative mWifiNative; - /* Supplicant events reported to a state machine */ private static final int BASE = Protocol.BASE_WIFI_MONITOR; @@ -347,164 +348,324 @@ public class WifiMonitor { private static final String WPA_RECV_ERROR_STR = "recv error"; /** - * Tracks consecutive receive errors - */ - private int mRecvErrors = 0; - - /** * Max errors before we close supplicant connection */ private static final int MAX_RECV_ERRORS = 10; + private final String mInterfaceName; + private final WifiNative mWifiNative; + private final StateMachine mWifiStateMachine; + private boolean mMonitoring; + public WifiMonitor(StateMachine wifiStateMachine, WifiNative wifiNative) { - mStateMachine = wifiStateMachine; + if (DBG) Log.d(TAG, "Creating WifiMonitor"); mWifiNative = wifiNative; + mInterfaceName = wifiNative.mInterfaceName; + mWifiStateMachine = wifiStateMachine; + mMonitoring = false; + + WifiMonitorSingleton.getMonitor().registerInterfaceMonitor(mInterfaceName, this); } public void startMonitoring() { - new MonitorThread().start(); + WifiMonitorSingleton.getMonitor().startMonitoring(mInterfaceName); } - class MonitorThread extends Thread { - public MonitorThread() { - super("WifiMonitor"); + public void stopMonitoring() { + WifiMonitorSingleton.getMonitor().stopMonitoring(mInterfaceName); + } + + public void stopSupplicant() { + WifiMonitorSingleton.getMonitor().stopSupplicant(); + } + + public void killSupplicant(boolean p2pSupported) { + WifiMonitorSingleton.getMonitor().killSupplicant(p2pSupported); + } + + private static class WifiMonitorSingleton { + private static Object sSingletonLock = new Object(); + private static WifiMonitorSingleton sWifiMonitorSingleton = null; + private HashMap<String, WifiMonitor> mIfaceMap = new HashMap<String, WifiMonitor>(); + private boolean mConnected = false; + private WifiNative mWifiNative; + + private WifiMonitorSingleton() { } - public void run() { + static WifiMonitorSingleton getMonitor() { + if (DBG) Log.d(TAG, "WifiMonitorSingleton gotten"); + synchronized (sSingletonLock) { + if (sWifiMonitorSingleton == null) { + if (DBG) Log.d(TAG, "WifiMonitorSingleton created"); + sWifiMonitorSingleton = new WifiMonitorSingleton(); + } + } + return sWifiMonitorSingleton; + } - if (connectToSupplicant()) { - // Send a message indicating that it is now possible to send commands - // to the supplicant - mStateMachine.sendMessage(SUP_CONNECTION_EVENT); - } else { - mStateMachine.sendMessage(SUP_DISCONNECTION_EVENT); + public synchronized void startMonitoring(String iface) { + WifiMonitor m = mIfaceMap.get(iface); + if (m == null) { + Log.e(TAG, "startMonitor called with unknown iface=" + iface); return; } + Log.d(TAG, "startMonitoring(" + iface + ") with mConnected = " + mConnected); + + if (mConnected) { + m.mMonitoring = true; + m.mWifiStateMachine.sendMessage(SUP_CONNECTION_EVENT); + } else { + if (DBG) Log.d(TAG, "connecting to supplicant"); + int connectTries = 0; + while (true) { + if (mWifiNative.connectToSupplicant()) { + m.mMonitoring = true; + m.mWifiStateMachine.sendMessage(SUP_CONNECTION_EVENT); + new MonitorThread(mWifiNative, this).start(); + mConnected = true; + break; + } + if (connectTries++ < 5) { + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) { + } + } else { + mIfaceMap.remove(iface); + m.mWifiStateMachine.sendMessage(SUP_DISCONNECTION_EVENT); + break; + } + } + } + } + + public synchronized void stopMonitoring(String iface) { + WifiMonitor m = mIfaceMap.get(iface); + if (DBG) Log.d(TAG, "stopMonitoring(" + iface + ") = " + m.mWifiStateMachine); + m.mMonitoring = false; + m.mWifiStateMachine.sendMessage(SUP_DISCONNECTION_EVENT); + } + + public synchronized void registerInterfaceMonitor(String iface, WifiMonitor m) { + if (DBG) Log.d(TAG, "registerInterface(" + iface + "+" + m.mWifiStateMachine + ")"); + mIfaceMap.put(iface, m); + if (mWifiNative == null) { + mWifiNative = m.mWifiNative; + } + } + + public synchronized void unregisterInterfaceMonitor(String iface) { + // REVIEW: When should we call this? If this isn't called, then WifiMonitor + // objects will remain in the mIfaceMap; and won't ever get deleted + + WifiMonitor m = mIfaceMap.remove(iface); + if (DBG) Log.d(TAG, "unregisterInterface(" + iface + "+" + m.mWifiStateMachine + ")"); + } + + public synchronized void stopSupplicant() { + mWifiNative.stopSupplicant(); + } + + public synchronized void killSupplicant(boolean p2pSupported) { + mWifiNative.killSupplicant(p2pSupported); + mConnected = false; + Iterator<Map.Entry<String, WifiMonitor>> it = mIfaceMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry<String, WifiMonitor> e = it.next(); + WifiMonitor m = e.getValue(); + m.mMonitoring = false; + } + } + + private synchronized WifiMonitor getMonitor(String iface) { + return mIfaceMap.get(iface); + } + } + + private static class MonitorThread extends Thread { + private final WifiNative mWifiNative; + private final WifiMonitorSingleton mWifiMonitorSingleton; + private int mRecvErrors = 0; + private StateMachine mStateMachine = null; + + public MonitorThread(WifiNative wifiNative, WifiMonitorSingleton wifiMonitorSingleton) { + super("WifiMonitor"); + mWifiNative = wifiNative; + mWifiMonitorSingleton = wifiMonitorSingleton; + } + + public void run() { //noinspection InfiniteLoopStatement for (;;) { String eventStr = mWifiNative.waitForEvent(); // Skip logging the common but mostly uninteresting scan-results event - if (false && eventStr.indexOf(SCAN_RESULTS_STR) == -1) { + if (DBG && eventStr.indexOf(SCAN_RESULTS_STR) == -1) { Log.d(TAG, "Event [" + eventStr + "]"); } - if (!eventStr.startsWith(EVENT_PREFIX_STR)) { - if (eventStr.startsWith(WPA_EVENT_PREFIX_STR) && - 0 < eventStr.indexOf(PASSWORD_MAY_BE_INCORRECT_STR)) { - mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT); - } else if (eventStr.startsWith(WPS_SUCCESS_STR)) { - mStateMachine.sendMessage(WPS_SUCCESS_EVENT); - } else if (eventStr.startsWith(WPS_FAIL_STR)) { - handleWpsFailEvent(eventStr); - } else if (eventStr.startsWith(WPS_OVERLAP_STR)) { - mStateMachine.sendMessage(WPS_OVERLAP_EVENT); - } else if (eventStr.startsWith(WPS_TIMEOUT_STR)) { - mStateMachine.sendMessage(WPS_TIMEOUT_EVENT); - } else if (eventStr.startsWith(P2P_EVENT_PREFIX_STR)) { - handleP2pEvents(eventStr); - } else if (eventStr.startsWith(HOST_AP_EVENT_PREFIX_STR)) { - handleHostApEvents(eventStr); + + WifiMonitor m = null; + mStateMachine = null; + + if (eventStr.startsWith("IFNAME=")) { + int space = eventStr.indexOf(' '); + if (space != -1) { + String iface = eventStr.substring(7,space); + m = mWifiMonitorSingleton.getMonitor(iface); + if (m != null) { + if (m.mMonitoring) { + mStateMachine = m.mWifiStateMachine; + eventStr = eventStr.substring(space + 1); + } + else { + if (DBG) Log.d(TAG, "Dropping event because monitor (" + iface + + ") is stopped"); + continue; + } + } + else { + eventStr = eventStr.substring(space + 1); + } } - continue; } - String eventName = eventStr.substring(EVENT_PREFIX_LEN_STR); - int nameEnd = eventName.indexOf(' '); - if (nameEnd != -1) - eventName = eventName.substring(0, nameEnd); - if (eventName.length() == 0) { - if (false) Log.i(TAG, "Received wpa_supplicant event with empty event name"); - continue; - } - /* - * Map event name into event enum - */ - int event; - if (eventName.equals(CONNECTED_STR)) - event = CONNECTED; - else if (eventName.equals(DISCONNECTED_STR)) - event = DISCONNECTED; - else if (eventName.equals(STATE_CHANGE_STR)) - event = STATE_CHANGE; - else if (eventName.equals(SCAN_RESULTS_STR)) - event = SCAN_RESULTS; - else if (eventName.equals(LINK_SPEED_STR)) - event = LINK_SPEED; - else if (eventName.equals(TERMINATING_STR)) - event = TERMINATING; - else if (eventName.equals(DRIVER_STATE_STR)) - event = DRIVER_STATE; - else if (eventName.equals(EAP_FAILURE_STR)) - event = EAP_FAILURE; - else if (eventName.equals(ASSOC_REJECT_STR)) - event = ASSOC_REJECT; - else - event = UNKNOWN; - - String eventData = eventStr; - if (event == DRIVER_STATE || event == LINK_SPEED) - eventData = eventData.split(" ")[1]; - else if (event == STATE_CHANGE || event == EAP_FAILURE) { - int ind = eventStr.indexOf(" "); - if (ind != -1) { - eventData = eventStr.substring(ind + 1); + if (mStateMachine != null) { + if (dispatchEvent(eventStr)) { + break; } } else { - int ind = eventStr.indexOf(" - "); - if (ind != -1) { - eventData = eventStr.substring(ind + 3); - } - } - - if (event == STATE_CHANGE) { - handleSupplicantStateChange(eventData); - } else if (event == DRIVER_STATE) { - handleDriverEvent(eventData); - } else if (event == TERMINATING) { - /** - * Close the supplicant connection if we see - * too many recv errors - */ - if (eventData.startsWith(WPA_RECV_ERROR_STR)) { - if (++mRecvErrors > MAX_RECV_ERRORS) { - if (false) { - Log.d(TAG, "too many recv errors, closing connection"); - } - } else { - continue; + if (DBG) Log.d(TAG, "Sending to all monitors because there's no interface id"); + boolean done = false; + Iterator<Map.Entry<String, WifiMonitor>> it = + mWifiMonitorSingleton.mIfaceMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry<String, WifiMonitor> e = it.next(); + m = e.getValue(); + mStateMachine = m.mWifiStateMachine; + if (dispatchEvent(eventStr)) { + done = true; } } - // notify and exit - mStateMachine.sendMessage(SUP_DISCONNECTION_EVENT); - break; - } else if (event == EAP_FAILURE) { - if (eventData.startsWith(EAP_AUTH_FAILURE_STR)) { - mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT); + if (done) { + // After this thread terminates, we'll no longer + // be connected to the supplicant + if (DBG) Log.d(TAG, "Disconnecting from the supplicant, no more events"); + mWifiMonitorSingleton.mConnected = false; + break; } - } else if (event == ASSOC_REJECT) { - mStateMachine.sendMessage(ASSOCIATION_REJECTION_EVENT); - } else { - handleEvent(event, eventData); } - mRecvErrors = 0; } } - private boolean connectToSupplicant() { - int connectTries = 0; + /* @return true if the event was supplicant disconnection */ + private boolean dispatchEvent(String eventStr) { + + if (!eventStr.startsWith(EVENT_PREFIX_STR)) { + if (eventStr.startsWith(WPA_EVENT_PREFIX_STR) && + 0 < eventStr.indexOf(PASSWORD_MAY_BE_INCORRECT_STR)) { + mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT); + } else if (eventStr.startsWith(WPS_SUCCESS_STR)) { + mStateMachine.sendMessage(WPS_SUCCESS_EVENT); + } else if (eventStr.startsWith(WPS_FAIL_STR)) { + handleWpsFailEvent(eventStr); + } else if (eventStr.startsWith(WPS_OVERLAP_STR)) { + mStateMachine.sendMessage(WPS_OVERLAP_EVENT); + } else if (eventStr.startsWith(WPS_TIMEOUT_STR)) { + mStateMachine.sendMessage(WPS_TIMEOUT_EVENT); + } else if (eventStr.startsWith(P2P_EVENT_PREFIX_STR)) { + handleP2pEvents(eventStr); + } else if (eventStr.startsWith(HOST_AP_EVENT_PREFIX_STR)) { + handleHostApEvents(eventStr); + } + else { + if (DBG) Log.w(TAG, "couldn't identify event type - " + eventStr); + } + return false; + } - while (true) { - if (mWifiNative.connectToSupplicant()) { - return true; + String eventName = eventStr.substring(EVENT_PREFIX_LEN_STR); + int nameEnd = eventName.indexOf(' '); + if (nameEnd != -1) + eventName = eventName.substring(0, nameEnd); + if (eventName.length() == 0) { + if (DBG) Log.i(TAG, "Received wpa_supplicant event with empty event name"); + return false; + } + /* + * Map event name into event enum + */ + int event; + if (eventName.equals(CONNECTED_STR)) + event = CONNECTED; + else if (eventName.equals(DISCONNECTED_STR)) + event = DISCONNECTED; + else if (eventName.equals(STATE_CHANGE_STR)) + event = STATE_CHANGE; + else if (eventName.equals(SCAN_RESULTS_STR)) + event = SCAN_RESULTS; + else if (eventName.equals(LINK_SPEED_STR)) + event = LINK_SPEED; + else if (eventName.equals(TERMINATING_STR)) + event = TERMINATING; + else if (eventName.equals(DRIVER_STATE_STR)) + event = DRIVER_STATE; + else if (eventName.equals(EAP_FAILURE_STR)) + event = EAP_FAILURE; + else if (eventName.equals(ASSOC_REJECT_STR)) + event = ASSOC_REJECT; + else + event = UNKNOWN; + + String eventData = eventStr; + if (event == DRIVER_STATE || event == LINK_SPEED) + eventData = eventData.split(" ")[1]; + else if (event == STATE_CHANGE || event == EAP_FAILURE) { + int ind = eventStr.indexOf(" "); + if (ind != -1) { + eventData = eventStr.substring(ind + 1); } - if (connectTries++ < 5) { - nap(1); - } else { - break; + } else { + int ind = eventStr.indexOf(" - "); + if (ind != -1) { + eventData = eventStr.substring(ind + 3); + } + } + + if (event == STATE_CHANGE) { + handleSupplicantStateChange(eventData); + } else if (event == DRIVER_STATE) { + handleDriverEvent(eventData); + } else if (event == TERMINATING) { + /** + * Close the supplicant connection if we see + * too many recv errors + */ + if (eventData.startsWith(WPA_RECV_ERROR_STR)) { + if (++mRecvErrors > MAX_RECV_ERRORS) { + if (DBG) { + Log.d(TAG, "too many recv errors, closing connection"); + } + } else { + return false; + } + } + + // notify and exit + mStateMachine.sendMessage(SUP_DISCONNECTION_EVENT); + return true; + } else if (event == EAP_FAILURE) { + if (eventData.startsWith(EAP_AUTH_FAILURE_STR)) { + mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT); } + } else if (event == ASSOC_REJECT) { + mStateMachine.sendMessage(ASSOCIATION_REJECTION_EVENT); + } else { + handleEvent(event, eventData); } + mRecvErrors = 0; return false; } @@ -723,71 +884,60 @@ public class WifiMonitor { } notifySupplicantStateChange(networkId, wifiSsid, BSSID, newSupplicantState); } - } - private void handleNetworkStateChange(NetworkInfo.DetailedState newState, String data) { - String BSSID = null; - int networkId = -1; - if (newState == NetworkInfo.DetailedState.CONNECTED) { - Matcher match = mConnectedEventPattern.matcher(data); - if (!match.find()) { - if (false) Log.d(TAG, "Could not find BSSID in CONNECTED event string"); - } else { - BSSID = match.group(1); - try { - networkId = Integer.parseInt(match.group(2)); - } catch (NumberFormatException e) { - networkId = -1; + private void handleNetworkStateChange(NetworkInfo.DetailedState newState, String data) { + String BSSID = null; + int networkId = -1; + if (newState == NetworkInfo.DetailedState.CONNECTED) { + Matcher match = mConnectedEventPattern.matcher(data); + if (!match.find()) { + if (DBG) Log.d(TAG, "Could not find BSSID in CONNECTED event string"); + } else { + BSSID = match.group(1); + try { + networkId = Integer.parseInt(match.group(2)); + } catch (NumberFormatException e) { + networkId = -1; + } } + notifyNetworkStateChange(newState, BSSID, networkId); } } - notifyNetworkStateChange(newState, BSSID, networkId); - } - /** - * Send the state machine a notification that the state of Wifi connectivity - * has changed. - * @param networkId the configured network on which the state change occurred - * @param newState the new network state - * @param BSSID when the new state is {@link DetailedState#CONNECTED - * NetworkInfo.DetailedState.CONNECTED}, - * this is the MAC address of the access point. Otherwise, it - * is {@code null}. - */ - void notifyNetworkStateChange(NetworkInfo.DetailedState newState, String BSSID, int netId) { - if (newState == NetworkInfo.DetailedState.CONNECTED) { - Message m = mStateMachine.obtainMessage(NETWORK_CONNECTION_EVENT, - netId, 0, BSSID); - mStateMachine.sendMessage(m); - } else { - Message m = mStateMachine.obtainMessage(NETWORK_DISCONNECTION_EVENT, - netId, 0, BSSID); - mStateMachine.sendMessage(m); + /** + * Send the state machine a notification that the state of Wifi connectivity + * has changed. + * @param networkId the configured network on which the state change occurred + * @param newState the new network state + * @param BSSID when the new state is {@link DetailedState#CONNECTED + * NetworkInfo.DetailedState.CONNECTED}, + * this is the MAC address of the access point. Otherwise, it + * is {@code null}. + */ + void notifyNetworkStateChange(NetworkInfo.DetailedState newState, String BSSID, int netId) { + if (newState == NetworkInfo.DetailedState.CONNECTED) { + Message m = mStateMachine.obtainMessage(NETWORK_CONNECTION_EVENT, + netId, 0, BSSID); + mStateMachine.sendMessage(m); + } else { + Message m = mStateMachine.obtainMessage(NETWORK_DISCONNECTION_EVENT, + netId, 0, BSSID); + mStateMachine.sendMessage(m); + } } - } - /** - * Send the state machine a notification that the state of the supplicant - * has changed. - * @param networkId the configured network on which the state change occurred - * @param wifiSsid network name - * @param BSSID network address - * @param newState the new {@code SupplicantState} - */ - void notifySupplicantStateChange(int networkId, WifiSsid wifiSsid, String BSSID, - SupplicantState newState) { - mStateMachine.sendMessage(mStateMachine.obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT, - new StateChangeResult(networkId, wifiSsid, BSSID, newState))); - } - - /** - * Sleep for a period of time. - * @param secs the number of seconds to sleep - */ - private static void nap(int secs) { - try { - Thread.sleep(secs * 1000); - } catch (InterruptedException ignore) { + /** + * Send the state machine a notification that the state of the supplicant + * has changed. + * @param networkId the configured network on which the state change occurred + * @param wifiSsid network name + * @param BSSID network address + * @param newState the new {@code SupplicantState} + */ + void notifySupplicantStateChange(int networkId, WifiSsid wifiSsid, String BSSID, + SupplicantState newState) { + mStateMachine.sendMessage(mStateMachine.obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT, + new StateChangeResult(networkId, wifiSsid, BSSID, newState))); } } } diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index b1dd2ce..d30c7cf 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -47,7 +47,9 @@ public class WifiNative { static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; static final int SCAN_WITH_CONNECTION_SETUP = 2; - String mInterface = ""; + public final String mInterfaceName; + public final String mInterfacePrefix; + private boolean mSuspendOptEnabled = false; public native static boolean loadDriver(); @@ -62,52 +64,53 @@ public class WifiNative { or when the supplicant is hung */ public native static boolean killSupplicant(boolean p2pSupported); - private native boolean connectToSupplicant(String iface); + private native boolean connectToSupplicantNative(); - private native void closeSupplicantConnection(String iface); + private native void closeSupplicantConnectionNative(); /** * Wait for the supplicant to send an event, returning the event string. * @return the event string sent by the supplicant. */ - private native String waitForEvent(String iface); + private native String waitForEventNative(); - private native boolean doBooleanCommand(String iface, String command); + private native boolean doBooleanCommandNative(String command); - private native int doIntCommand(String iface, String command); + private native int doIntCommandNative(String command); - private native String doStringCommand(String iface, String command); + private native String doStringCommandNative(String command); - public WifiNative(String iface) { - mInterface = iface; - mTAG = "WifiNative-" + iface; + public WifiNative(String interfaceName) { + mInterfaceName = interfaceName; + mInterfacePrefix = "IFNAME=" + interfaceName + " "; + mTAG = "WifiNative-" + interfaceName; } public boolean connectToSupplicant() { - return connectToSupplicant(mInterface); + return connectToSupplicantNative(); } public void closeSupplicantConnection() { - closeSupplicantConnection(mInterface); + closeSupplicantConnectionNative(); } public String waitForEvent() { - return waitForEvent(mInterface); + return waitForEventNative(); } private boolean doBooleanCommand(String command) { if (DBG) Log.d(mTAG, "doBoolean: " + command); - return doBooleanCommand(mInterface, command); + return doBooleanCommandNative(mInterfacePrefix + command); } private int doIntCommand(String command) { if (DBG) Log.d(mTAG, "doInt: " + command); - return doIntCommand(mInterface, command); + return doIntCommandNative(mInterfacePrefix + command); } private String doStringCommand(String command) { if (DBG) Log.d(mTAG, "doString: " + command); - return doStringCommand(mInterface, command); + return doStringCommandNative(mInterfacePrefix + command); } public boolean ping() { @@ -411,9 +414,9 @@ public class WifiNative { public boolean startWpsPbc(String iface, String bssid) { if (TextUtils.isEmpty(bssid)) { - return doBooleanCommand("IFNAME=" + iface + " WPS_PBC"); + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); } else { - return doBooleanCommand("IFNAME=" + iface + " WPS_PBC " + bssid); + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); } } @@ -424,7 +427,7 @@ public class WifiNative { public boolean startWpsPinKeypad(String iface, String pin) { if (TextUtils.isEmpty(pin)) return false; - return doBooleanCommand("IFNAME=" + iface + " WPS_PIN any " + pin); + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); } @@ -438,9 +441,9 @@ public class WifiNative { public String startWpsPinDisplay(String iface, String bssid) { if (TextUtils.isEmpty(bssid)) { - return doStringCommand("IFNAME=" + iface + " WPS_PIN any"); + return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); } else { - return doStringCommand("IFNAME=" + iface + " WPS_PIN " + bssid); + return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); } } @@ -492,7 +495,7 @@ public class WifiNative { } public boolean setP2pGroupIdle(String iface, int time) { - return doBooleanCommand("IFNAME=" + iface + " SET p2p_group_idle " + time); + return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); } public void setPowerSave(boolean enabled) { @@ -505,9 +508,9 @@ public class WifiNative { public boolean setP2pPowerSave(String iface, boolean enabled) { if (enabled) { - return doBooleanCommand("IFNAME=" + iface + " P2P_SET ps 1"); + return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); } else { - return doBooleanCommand("IFNAME=" + iface + " P2P_SET ps 0"); + return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); } } @@ -645,7 +648,7 @@ public class WifiNative { public boolean p2pGroupRemove(String iface) { if (TextUtils.isEmpty(iface)) return false; - return doBooleanCommand("P2P_GROUP_REMOVE " + iface); + return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); } public boolean p2pReject(String deviceAddress) { diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 4628c91..1fcd609 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -68,6 +68,7 @@ import android.os.SystemProperties; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings; +import android.util.Log; import android.util.LruCache; import android.text.TextUtils; @@ -543,7 +544,6 @@ public class WifiStateMachine extends StateMachine { public WifiStateMachine(Context context, String wlanInterface) { super("WifiStateMachine"); - mContext = context; mInterfaceName = wlanInterface; @@ -888,6 +888,7 @@ public class WifiStateMachine extends StateMachine { * TODO: doc */ public void setOperationalMode(int mode) { + if (DBG) log("setting operational mode to " + String.valueOf(mode)); sendMessage(CMD_SET_OPERATIONAL_MODE, mode, 0); } @@ -1756,8 +1757,7 @@ public class WifiStateMachine extends StateMachine { /* Socket connection can be lost when we do a graceful shutdown * or when the driver is hung. Ensure supplicant is stopped here. */ - mWifiNative.killSupplicant(mP2pSupported); - mWifiNative.closeSupplicantConnection(); + mWifiMonitor.killSupplicant(mP2pSupported); sendSupplicantConnectionChangedBroadcast(false); setWifiState(WIFI_STATE_DISABLED); } @@ -2139,7 +2139,7 @@ public class WifiStateMachine extends StateMachine { * Avoids issues with drivers that do not handle interface down * on a running supplicant properly. */ - mWifiNative.killSupplicant(mP2pSupported); + mWifiMonitor.killSupplicant(mP2pSupported); if(mWifiNative.startSupplicant(mP2pSupported)) { setWifiState(WIFI_STATE_ENABLING); if (DBG) log("Supplicant start successful"); @@ -2222,7 +2222,7 @@ public class WifiStateMachine extends StateMachine { case WifiMonitor.SUP_DISCONNECTION_EVENT: if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) { loge("Failed to setup control channel, restart supplicant"); - mWifiNative.killSupplicant(mP2pSupported); + mWifiMonitor.killSupplicant(mP2pSupported); transitionTo(mInitialState); sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS); } else { @@ -2329,9 +2329,7 @@ public class WifiStateMachine extends StateMachine { } if (DBG) log("stopping supplicant"); - if (!mWifiNative.stopSupplicant()) { - loge("Failed to stop supplicant"); - } + mWifiMonitor.stopSupplicant(); /* Send ourselves a delayed message to indicate failure after a wait time */ sendMessageDelayed(obtainMessage(CMD_STOP_SUPPLICANT_FAILED, @@ -3200,6 +3198,7 @@ public class WifiStateMachine extends StateMachine { class VerifyingLinkState extends State { @Override public void enter() { + log(getName() + " enter"); setNetworkDetailedState(DetailedState.VERIFYING_POOR_LINK); mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.VERIFYING_POOR_LINK); sendNetworkStateChangeBroadcast(mLastBssid); @@ -3209,11 +3208,14 @@ public class WifiStateMachine extends StateMachine { switch (message.what) { case WifiWatchdogStateMachine.POOR_LINK_DETECTED: //stay here + log(getName() + " POOR_LINK_DETECTED: no transition"); break; case WifiWatchdogStateMachine.GOOD_LINK_DETECTED: + log(getName() + " GOOD_LINK_DETECTED: transition to captive portal check"); transitionTo(mCaptivePortalCheckState); break; default: + log(getName() + " what=" + message.what + " NOT_HANDLED"); return NOT_HANDLED; } return HANDLED; @@ -3223,6 +3225,7 @@ public class WifiStateMachine extends StateMachine { class CaptivePortalCheckState extends State { @Override public void enter() { + log(getName() + " enter"); setNetworkDetailedState(DetailedState.CAPTIVE_PORTAL_CHECK); mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CAPTIVE_PORTAL_CHECK); sendNetworkStateChangeBroadcast(mLastBssid); @@ -3231,6 +3234,7 @@ public class WifiStateMachine extends StateMachine { public boolean processMessage(Message message) { switch (message.what) { case CMD_CAPTIVE_CHECK_COMPLETE: + log(getName() + " CMD_CAPTIVE_CHECK_COMPLETE"); try { mNwService.enableIpv6(mInterfaceName); } catch (RemoteException re) { diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index cf75381..461dedb 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -120,6 +120,11 @@ public class WifiStateTracker implements NetworkStateTracker { mWifiManager.captivePortalCheckComplete(); } + @Override + public void captivePortalCheckCompleted(boolean isCaptivePortal) { + // not implemented + } + /** * Turn the wireless radio off for a network. * @param turnOn {@code true} to turn the radio on, {@code false} diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 68a082a..63b94a2 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -858,7 +858,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { } if (mGroups.clear()) sendP2pPersistentGroupsChangedBroadcast(); - mWifiNative.closeSupplicantConnection(); + mWifiMonitor.stopMonitoring(); transitionTo(mP2pDisablingState); break; case WifiP2pManager.SET_DEVICE_NAME: |
