diff options
author | Roshan Pius <rpius@google.com> | 2018-03-26 16:32:36 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-07-11 14:40:59 -0700 |
commit | 7f889a2957413dcfa23cd6405e4d0efe1296501a (patch) | |
tree | c60be58a3f1a868857cc039e290909f0f0fc040a /service | |
parent | 74a92448fcfd47f7a4a2a8855a71ca05fc1fa4af (diff) |
WifiNative: Don't start wpa_supplicant in scan mode
Changes:
a) Create a new helper method for starting a client interface in scan
only mode.
b) Create an internal iface type to keep track of scan only STA ifaces.
c) The new |STA_FOR_SCAN| iface type will not use wpa_supplicant.
Bug: 71635713
Test: Unit tests
Test: Manual tests (External Scan requests in scan only mode works).
Test: Ran WifiManager & WifiSoftap ACTS Tests
Change-Id: I2552a991746c23b548dc4cf6f2985e09d8ecbbed
Diffstat (limited to 'service')
3 files changed, 120 insertions, 25 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java index dac117e68..19f8671f4 100644 --- a/service/java/com/android/server/wifi/ClientModeManager.java +++ b/service/java/com/android/server/wifi/ClientModeManager.java @@ -223,8 +223,9 @@ public class ClientModeManager implements ActiveModeManager { updateWifiState(WifiManager.WIFI_STATE_ENABLING, WifiManager.WIFI_STATE_DISABLED); - mClientInterfaceName = mWifiNative.setupInterfaceForClientMode( - false /* not low priority */, mWifiNativeInterfaceCallback); + mClientInterfaceName = + mWifiNative.setupInterfaceForClientInConnectivityMode( + mWifiNativeInterfaceCallback); if (TextUtils.isEmpty(mClientInterfaceName)) { Log.e(TAG, "Failed to create ClientInterface. Sit in Idle"); updateWifiState(WifiManager.WIFI_STATE_UNKNOWN, diff --git a/service/java/com/android/server/wifi/ScanOnlyModeManager.java b/service/java/com/android/server/wifi/ScanOnlyModeManager.java index 991657929..2dbeff70a 100644 --- a/service/java/com/android/server/wifi/ScanOnlyModeManager.java +++ b/service/java/com/android/server/wifi/ScanOnlyModeManager.java @@ -194,7 +194,7 @@ public class ScanOnlyModeManager implements ActiveModeManager { public boolean processMessage(Message message) { switch (message.what) { case CMD_START: - mClientInterfaceName = mWifiNative.setupInterfaceForClientMode(true, + mClientInterfaceName = mWifiNative.setupInterfaceForClientInScanMode( mWifiNativeInterfaceCallback); if (TextUtils.isEmpty(mClientInterfaceName)) { Log.e(TAG, "Failed to create ClientInterface. Sit in Idle"); diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index bc599c141..aa4dc6a85 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -114,15 +114,16 @@ public class WifiNative { private static class Iface { /** Type of ifaces possible */ public static final int IFACE_TYPE_AP = 0; - public static final int IFACE_TYPE_STA = 1; + public static final int IFACE_TYPE_STA_FOR_CONNECTIVITY = 1; + public static final int IFACE_TYPE_STA_FOR_SCAN = 2; - @IntDef({IFACE_TYPE_AP, IFACE_TYPE_STA}) + @IntDef({IFACE_TYPE_AP, IFACE_TYPE_STA_FOR_CONNECTIVITY, IFACE_TYPE_STA_FOR_SCAN}) @Retention(RetentionPolicy.SOURCE) public @interface IfaceType{} /** Identifier allocated for the interface */ public final int id; - /** Type of the iface: STA or AP */ + /** Type of the iface: STA (for Connectivity or Scan) or AP */ public final @IfaceType int type; /** Name of the interface */ public String name; @@ -141,13 +142,28 @@ public class WifiNative { @Override public String toString() { StringBuffer sb = new StringBuffer(); + String typeString; + switch(type) { + case IFACE_TYPE_STA_FOR_CONNECTIVITY: + typeString = "STA_CONNECTIVITY"; + break; + case IFACE_TYPE_STA_FOR_SCAN: + typeString = "STA_SCAN"; + break; + case IFACE_TYPE_AP: + typeString = "AP"; + break; + default: + typeString = "<UNKNOWN>"; + break; + } sb.append("Iface:") .append("{") .append("Name=").append(name) .append(",") .append("Id=").append(id) .append(",") - .append("Type=").append(type == IFACE_TYPE_STA ? "STA" : "AP") + .append("Type=").append(typeString) .append("}"); return sb.toString(); } @@ -220,9 +236,14 @@ public class WifiNative { return null; } - /** Checks if there are any STA iface active. */ - private boolean hasAnyStaIface() { - return hasAnyIfaceOfType(Iface.IFACE_TYPE_STA); + /** Checks if there are any STA (for connectivity) iface active. */ + private boolean hasAnyStaIfaceForConnectivity() { + return hasAnyIfaceOfType(Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY); + } + + /** Checks if there are any STA (for scan) iface active. */ + private boolean hasAnyStaIfaceForScan() { + return hasAnyIfaceOfType(Iface.IFACE_TYPE_STA_FOR_SCAN); } /** Checks if there are any AP iface active. */ @@ -230,14 +251,19 @@ public class WifiNative { return hasAnyIfaceOfType(Iface.IFACE_TYPE_AP); } + /** Finds the name of any STA iface active. */ private String findAnyStaIfaceName() { - Iface iface = findAnyIfaceOfType(Iface.IFACE_TYPE_STA); + Iface iface = findAnyIfaceOfType(Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY); + if (iface == null) { + iface = findAnyIfaceOfType(Iface.IFACE_TYPE_STA_FOR_SCAN); + } if (iface == null) { return null; } return iface.name; } + /** Finds the name of any AP iface active. */ private String findAnyApIfaceName() { Iface iface = findAnyIfaceOfType(Iface.IFACE_TYPE_AP); if (iface == null) { @@ -334,7 +360,7 @@ public class WifiNative { /** Helper method invoked to start supplicant if there were no STA ifaces */ private boolean startSupplicant() { synchronized (mLock) { - if (!mIfaceMgr.hasAnyStaIface()) { + if (!mIfaceMgr.hasAnyStaIfaceForConnectivity()) { if (!mWificondControl.enableSupplicant()) { Log.e(TAG, "Failed to enable supplicant"); return false; @@ -356,7 +382,7 @@ public class WifiNative { /** Helper method invoked to stop supplicant if there are no more STA ifaces */ private void stopSupplicantIfNecessary() { synchronized (mLock) { - if (!mIfaceMgr.hasAnyStaIface()) { + if (!mIfaceMgr.hasAnyStaIfaceForConnectivity()) { if (!mSupplicantStaIfaceHal.deregisterDeathHandler()) { Log.e(TAG, "Failed to deregister supplicant death handler"); } @@ -389,8 +415,11 @@ public class WifiNative { return true; } - /** Helper method invoked to teardown client iface and perform necessary cleanup */ - private void onClientInterfaceDestroyed(@NonNull Iface iface) { + /** + * Helper method invoked to teardown client iface (for connectivity) and perform + * necessary cleanup + */ + private void onClientInterfaceForConnectivityDestroyed(@NonNull Iface iface) { synchronized (mLock) { mWifiMonitor.stopMonitoring(iface.name); if (!unregisterNetworkObserver(iface.networkObserver)) { @@ -407,6 +436,19 @@ public class WifiNative { } } + /** Helper method invoked to teardown client iface (for scan) and perform necessary cleanup */ + private void onClientInterfaceForScanDestroyed(@NonNull Iface iface) { + synchronized (mLock) { + if (!unregisterNetworkObserver(iface.networkObserver)) { + Log.e(TAG, "Failed to unregister network observer on " + iface); + } + if (!mWificondControl.tearDownClientInterface(iface.name)) { + Log.e(TAG, "Failed to teardown iface in wificond on " + iface); + } + stopHalAndWificondIfNecessary(); + } + } + /** Helper method invoked to teardown softAp iface and perform necessary cleanup */ private void onSoftApInterfaceDestroyed(@NonNull Iface iface) { synchronized (mLock) { @@ -433,8 +475,10 @@ public class WifiNative { /** Helper method invoked to teardown iface and perform necessary cleanup */ private void onInterfaceDestroyed(@NonNull Iface iface) { synchronized (mLock) { - if (iface.type == Iface.IFACE_TYPE_STA) { - onClientInterfaceDestroyed(iface); + if (iface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY) { + onClientInterfaceForConnectivityDestroyed(iface); + } else if (iface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { + onClientInterfaceForScanDestroyed(iface); } else if (iface.type == Iface.IFACE_TYPE_AP) { onSoftApInterfaceDestroyed(iface); } @@ -559,7 +603,8 @@ public class WifiNative { iface.externalListener.onUp(iface.name); } else { iface.externalListener.onDown(iface.name); - if (iface.type == Iface.IFACE_TYPE_STA) { + if (iface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY + || iface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { mWifiMetrics.incrementNumClientInterfaceDown(); } else if (iface.type == Iface.IFACE_TYPE_AP) { mWifiMetrics.incrementNumSoftApInterfaceDown(); @@ -834,17 +879,15 @@ public class WifiNative { } /** - * Setup an interface for Client mode operations. + * Setup an interface for client mode (for connectivity) operations. * * This method configures an interface in STA mode in all the native daemons * (wificond, wpa_supplicant & vendor HAL). * - * @param lowPrioritySta The requested STA has a low request priority (lower probability of - * getting created, higher probability of getting destroyed). * @param interfaceCallback Associated callback for notifying status changes for the iface. * @return Returns the name of the allocated interface, will be null on failure. */ - public String setupInterfaceForClientMode(boolean lowPrioritySta, + public String setupInterfaceForClientInConnectivityMode( @NonNull InterfaceCallback interfaceCallback) { synchronized (mLock) { if (!startHal()) { @@ -857,13 +900,13 @@ public class WifiNative { mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToSupplicant(); return null; } - Iface iface = mIfaceMgr.allocateIface(Iface.IFACE_TYPE_STA); + Iface iface = mIfaceMgr.allocateIface(Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY); if (iface == null) { Log.e(TAG, "Failed to allocate new STA iface"); return null; } iface.externalListener = interfaceCallback; - iface.name = createStaIface(iface, lowPrioritySta); + iface.name = createStaIface(iface, /* lowPrioritySta */ false); if (TextUtils.isEmpty(iface.name)) { Log.e(TAG, "Failed to create STA iface in vendor HAL"); mIfaceMgr.removeIface(iface.id); @@ -899,6 +942,56 @@ public class WifiNative { } /** + * Setup an interface for client mode (for scan) operations. + * + * This method configures an interface in STA mode in the native daemons + * (wificond, vendor HAL). + * + * @param interfaceCallback Associated callback for notifying status changes for the iface. + * @return Returns the name of the allocated interface, will be null on failure. + */ + public String setupInterfaceForClientInScanMode( + @NonNull InterfaceCallback interfaceCallback) { + synchronized (mLock) { + if (!startHal()) { + Log.e(TAG, "Failed to start Hal"); + mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToHal(); + return null; + } + Iface iface = mIfaceMgr.allocateIface(Iface.IFACE_TYPE_STA_FOR_SCAN); + if (iface == null) { + Log.e(TAG, "Failed to allocate new STA iface"); + return null; + } + iface.externalListener = interfaceCallback; + iface.name = createStaIface(iface, /* lowPrioritySta */ true); + if (TextUtils.isEmpty(iface.name)) { + Log.e(TAG, "Failed to create iface in vendor HAL"); + mIfaceMgr.removeIface(iface.id); + mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToHal(); + return null; + } + if (mWificondControl.setupInterfaceForClientMode(iface.name) == null) { + Log.e(TAG, "Failed to setup iface in wificond=" + iface.name); + teardownInterface(iface.name); + mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToWificond(); + return null; + } + iface.networkObserver = new NetworkObserverInternal(iface.id); + if (!registerNetworkObserver(iface.networkObserver)) { + Log.e(TAG, "Failed to register network observer for iface=" + iface.name); + teardownInterface(iface.name); + return null; + } + // Just to avoid any race conditions with interface state change callbacks, + // update the interface state before we exit. + onInterfaceStateChanged(iface, isInterfaceUp(iface.name)); + Log.i(TAG, "Successfully setup " + iface); + return iface.name; + } + } + + /** * Setup an interface for Soft AP mode operations. * * This method configures an interface in AP mode in all the native daemons @@ -991,7 +1084,8 @@ public class WifiNative { } // Trigger the iface removal from HAL. The rest of the cleanup will be triggered // from the interface destroyed callback. - if (iface.type == Iface.IFACE_TYPE_STA) { + if (iface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY + || iface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { if (!removeStaIface(iface)) { Log.e(TAG, "Failed to remove iface in vendor HAL=" + ifaceName); return; |