From 857b2f8fddb9b30f353b0543939df1bd12f9f641 Mon Sep 17 00:00:00 2001 From: lesl Date: Thu, 9 Jul 2020 01:08:16 +0800 Subject: wifi: bypass randomized Mac set failure when hal not support There are two use cases on SAP setMacaddress. 1. Mac randomization a. HAl not support - get pass b. Hal support - report error - generic error (Behavior changed in this commit) 2. Customized bssid - it should get failure since it is unsupported. a. Hal support - generic error b. Hal not support - unsupported configuration error indication. Bug: 160550985 Bug: 160550184 Test: atest FrameworksWifiTest Test: R-GSI + Q-vendor : Hotspot works normally. Merged-In: I530f41cd072ad0061e65fea9daf47c6b28113a77 Change-Id: I530f41cd072ad0061e65fea9daf47c6b28113a77 --- .../com/android/server/wifi/SoftApManager.java | 14 ++++++++++---- .../java/com/android/server/wifi/WifiNative.java | 9 +++++++++ .../com/android/server/wifi/WifiVendorHal.java | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index ffbb388cc..9ef52e796 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -348,10 +348,16 @@ public class SoftApManager implements ActiveModeManager { return SUCCESS; } - // We're configuring a random/custom MAC address. In this case, driver support is mandatory. - if (!mWifiNative.setMacAddress(mApInterfaceName, mac)) { - Log.e(TAG, "failed to set explicitly requested MAC address"); - return ERROR_GENERIC; + + if (mWifiNative.isSetMacAddressSupported(mApInterfaceName)) { + if (!mWifiNative.setMacAddress(mApInterfaceName, mac)) { + Log.e(TAG, "failed to set explicitly requested MAC address"); + return ERROR_GENERIC; + } + } else if (!mIsRandomizeBssid) { + // If hardware does not support MAC address setter, + // only report the error for non randomization. + return ERROR_UNSUPPORTED_CONFIGURATION; } return SUCCESS; } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 39d0fcc84..cf362d6a8 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1787,6 +1787,15 @@ public class WifiNative { return mWifiVendorHal.setMacAddress(interfaceName, mac); } + /** + * Returns true if Hal version supports setMacAddress, otherwise false. + * + * @param interfaceName Name of the interface + */ + public boolean isSetMacAddressSupported(@NonNull String interfaceName) { + return mWifiVendorHal.isSetMacAddressSupported(interfaceName); + } + /** * Get the factory MAC address of the given interface * @param interfaceName Name of the interface. diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index ed6ac7fdd..fd90c35df 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -1331,6 +1331,28 @@ public class WifiVendorHal { return boolResult(false); } + /** + * Returns true if Hal version supports setMacAddress, otherwise false. + * + * @param ifaceName Name of the interface + */ + public boolean isSetMacAddressSupported(@NonNull String ifaceName) { + synchronized (sLock) { + android.hardware.wifi.V1_2.IWifiStaIface sta12 = + getWifiStaIfaceForV1_2Mockable(ifaceName); + if (sta12 != null) { + return true; + } + + android.hardware.wifi.V1_4.IWifiApIface ap14 = + getWifiApIfaceForV1_4Mockable(ifaceName); + if (ap14 != null) { + return true; + } + } + return false; + } + /** * Get factory MAC address of the given interface * -- cgit v1.2.3