[高通SDM450][Android9.0]设备默认支持连接WPA3-SAE加密协议的WIFI

开发平台基本信息

芯片: SDM450
版本: Android 9.0
kernel: msm-4.9

问题描述

前段时间,有个医院的客户反馈我们的设备无法连接上他们医院路由器的WIFI,并且设备显示wifi已保存,但就是连接不上。而且,连接手机的热点却是能正常连接并且能够上网的。

问题分析

  1. 首先,基本可以排除硬件问题,因为能够连接手机热点并且能够上网;
  2. 其次,因为显示已保存,所以猜想会不会是WIFI的状态是保存了,但是,实际上WIFI的密码等参数没有写到本地文件,但是,客户忘记WIFI密码、恢复出厂设置,也都无法连接。
  3. 硬件跟软件操作流程都没问题,那就只能对比WIFI的差异性了,让客户把机器的WIFI信息保存的文件导出来,对比一下路由WIFI跟热点有什么区别。

注:WIFI信息保存的路径:/data/misc/wifi/WifiConfigStore.xml

在这里插入图片描述

从上图,可以看出来热点的加密方式是WPA_PSK;而路由器WIFI的加密方式是SAE;所以,猜想是不是我们的设备不支持SAE加密方式WIFI。果然,移植相关补丁之后,客户反馈能够正常连接他们的WIFI了,下面给出具体的补丁。

解决方法

路径:frameworks/base/

diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 5bbfcee..c9655a5 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -673,6 +673,8 @@
     <!-- Wifi driver supports IEEE80211AC for softap -->
     <bool translatable="false" name="config_wifi_softap_ieee80211ac_supported">false</bool>
 
+    <bool translatable="false" name="config_wifi_wpa3_supported">false</bool>
+
     <!-- Flag indicating whether we should enable the automatic brightness.
          Software implementation will be used if config_hardware_auto_brightness_available is not set -->
     <bool name="config_automatic_brightness_available">false</bool>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 4a40131..6aa7750 100755
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -319,6 +319,7 @@
   <java-symbol type="bool" name="config_wifi_batched_scan_supported" />
   <java-symbol type="bool" name="config_wifi_softap_acs_supported" />
   <java-symbol type="bool" name="config_wifi_softap_ieee80211ac_supported" />
+  <java-symbol type="bool" name="config_wifi_wpa3_supported" />
   <java-symbol type="bool" name="config_enableMultiUserUI"/>
   <java-symbol type="bool" name="config_enableNewAutoSelectNetworkUI"/>
   <java-symbol type="bool" name="config_disableUsbPermissionDialogs"/>
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index 2e85014..2126719 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -140,6 +140,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
      */
     private final Map<String, TimestampedScoredNetwork> mScoredNetworkCache = new HashMap<>();
 
+    private boolean apSupportsSaeAndPsk;
     static final String KEY_NETWORKINFO = "key_networkinfo";
     static final String KEY_WIFIINFO = "key_wifiinfo";
     static final String KEY_SSID = "key_ssid";
@@ -313,6 +314,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
         ssid = firstResult.SSID;
         bssid = firstResult.BSSID;
         security = getSecurity(firstResult);
+        apSupportsSaeAndPsk = checkForSaeAndPsk(firstResult);
+        if (apSupportsSaeAndPsk) {
+            boolean wpa3Support = mContext.getResources().getBoolean(
+                    com.android.internal.R.bool.config_wifi_wpa3_supported);
+            Log.e(TAG, "wpa3Support: " + wpa3Support);
+            if (!wpa3Support)
+                security = SECURITY_PSK;
+        }
+
         if (security == SECURITY_PSK) {
             pskType = getPskType(firstResult);
         }
@@ -624,7 +634,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
             return ssid.equals(removeDoubleQuotes(config.SSID)) && config.FQDN.equals(mConfig.FQDN);
         } else {
             return ssid.equals(removeDoubleQuotes(config.SSID))
-                    && security == getSecurity(config)
+                && (security == getSecurity(config)
+                        || (apSupportsSaeAndPsk && (getSecurity(config) == SECURITY_PSK)))
                     && (mConfig == null || mConfig.shared == config.shared);
         }
     }
@@ -1387,6 +1398,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
         return SECURITY_NONE;
     }
 
+    private static boolean checkForSaeAndPsk(ScanResult result) {
+        if (result.capabilities.contains("SAE")
+                && result.capabilities.contains("PSK"))
+            return true;
+        else
+            return false;
+    }
+
+
     static int getSecurity(WifiConfiguration config) {
         if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
             return SECURITY_PSK;
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index 0270796..21d3e7c 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -150,7 +150,14 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
     private WifiNetworkScoreCache mScoreCache;
     private boolean mNetworkScoringUiEnabled;
     private long mMaxSpeedLabelScoreCacheAge;
+    private boolean mWpa3Support;
 
+    private static final String WIFI_SECURITY_PSK = "PSK";
+    private static final String WIFI_SECURITY_EAP = "EAP";
+    private static final String WIFI_SECURITY_SAE = "SAE";
+    private static final String WIFI_SECURITY_OWE = "OWE";
+    private static final String WIFI_SECURITY_DPP = "DPP";
+    private static final String WIFI_SECURITY_SUITE_B_192 = "SUITE_B_192";
 
 
     @VisibleForTesting
@@ -217,6 +224,8 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
                 .build();
 
         mNetworkScoreManager = networkScoreManager;
+        mWpa3Support = mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_wifi_wpa3_supported);
 
         // TODO(sghuman): Remove this and create less hacky solution for testing
         final HandlerThread workThread = new HandlerThread(TAG
@@ -500,17 +509,63 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
     }
 
     /**
+     * Filters unsupported networks from scan results. New WPA3 networks
+     * may not be compatible with the device HW/SW.
+     * @param scanResults List of scan results
+     * @return List of filtered scan results based on local device capabilities+     */
+    private List<ScanResult> filterScanResultsByCapabilities(List<ScanResult> scanResults) {
+        if (scanResults == null) {
+            return null;
+        }
+
+        List<ScanResult> filteredScanResultList = new ArrayList<>();
+
+        // Iterate through the list of scan results and filter out APs which are not
+        // compatible with our device.
+        for (ScanResult scanResult : scanResults) {
+            if (scanResult.capabilities.contains(WIFI_SECURITY_PSK)) {
+                // All devices (today) support RSN-PSK or WPA-PSK
+                // Add this here because some APs may support both PSK and SAE and the check
+                // below will filter it out.
+                filteredScanResultList.add(scanResult);
+                continue;
+            }
+
+            if (!mWpa3Support
+                    && (scanResult.capabilities.contains(WIFI_SECURITY_SUITE_B_192)
+                        || scanResult.capabilities.contains(WIFI_SECURITY_SAE)
+                        || scanResult.capabilities.contains(WIFI_SECURITY_OWE)
+                        || scanResult.capabilities.contains(WIFI_SECURITY_DPP))) {
+                if (isVerboseLoggingEnabled()) {
+                    Log.v(TAG, "filterScanResultsByCapabilities: Filtering SSID "
+                            + scanResult.SSID + " with capabilities: " + scanResult.capabilities);
+                }
+            } else {
+                // Safe to add
+                filteredScanResultList.add(scanResult);
+            }
+        }
+
+        return filteredScanResultList;
+    }
+
+    /**
      * Retrieves latest scan results and wifi configs, then calls
      * {@link #updateAccessPoints(List, List)}.
      */
     private void fetchScansAndConfigsAndUpdateAccessPoints() {
-        final List<ScanResult> newScanResults = mWifiManager.getScanResults();
+        List<ScanResult> newScanResults = mWifiManager.getScanResults();
+
+        // Filter all unsupported networks from the scan result list
+        final List<ScanResult> filteredScanResults =
+            filterScanResultsByCapabilities(newScanResults);
+
         if (isVerboseLoggingEnabled()) {
-            Log.i(TAG, "Fetched scan results: " + newScanResults);
+            Log.i(TAG, "Fetched scan results: " + filteredScanResults);
         }
 
         List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
-        updateAccessPoints(newScanResults, configs);
+        updateAccessPoints(filteredScanResults, configs);
     }
 
     /** Update the internal list of access points. */

路径:frameworks/opt/net/wifi/

diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index a3bd169..a33e0eb 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -1616,7 +1616,16 @@ public class WifiMetrics {
                     supporting80211mcAps++;
                 }
 
-                ScanResultMatchInfo matchInfo = ScanResultMatchInfo.fromScanResult(scanResult);
+                ScanResultMatchInfo matchInfo = null;
+                try{
+                    matchInfo = ScanResultMatchInfo.fromScanResult(scanResult);
+                } catch (IllegalArgumentException e) {
+                    Log.e(TAG,
+                            "Invalid BSSID provided in the scan result1111: " + scanResult.BSSID);
+                }
+                if(matchInfo == null){
+                    continue;
+                }
                 Pair<PasspointProvider, PasspointMatch> providerMatch = null;
                 PasspointProvider passpointProvider = null;
                 if (networkDetail.isInterworking()) {
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 883ba93..99830df 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -61,6 +61,7 @@ public class WifiNetworkSelector {
     private final int mStayOnNetworkMinimumTxRate;
     private final int mStayOnNetworkMinimumRxRate;
     private final boolean mEnableAutoJoinWhenAssociated;
+    private final boolean mWpa3Support;
 
     /**
      * WiFi Network Selector supports various types of networks. Each type can
@@ -350,6 +351,8 @@ public class WifiNetworkSelector {
                 continue;
             }
 
+            if (!mWpa3Support && ScanResultUtil.isScanResultForOweNetwork(scanResult))
+                continue;
             // Skip saved networks
             if (mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail) != null) {
                 continue;
@@ -612,5 +615,7 @@ public class WifiNetworkSelector {
                 R.integer.config_wifi_framework_min_tx_rate_for_staying_on_network);
         mStayOnNetworkMinimumRxRate = context.getResources().getInteger(
                 R.integer.config_wifi_framework_min_rx_rate_for_staying_on_network);
+        mWpa3Support = context.getResources().getBoolean(
+                R.bool.config_wifi_wpa3_supported);
     }
 }
diff --git a/service/java/com/android/server/wifi/util/ScanResultUtil.java b/service/java/com/android/server/wifi/util/ScanResultUtil.java
index 271b543..24d0e44 100644
--- a/service/java/com/android/server/wifi/util/ScanResultUtil.java
+++ b/service/java/com/android/server/wifi/util/ScanResultUtil.java
@@ -63,6 +63,14 @@ public class ScanResultUtil {
     }
 
     /**
+     * Helper method to check if the provided |scanResult| corresponds to a EAP network or not.
+     * This checks if the provided capabilities string contains EAP encryption type or not.
+     */
+    public static boolean isScanResultForEapSuiteBNetwork(ScanResult scanResult) {
+        return scanResult.capabilities.contains("SUITE_B_192");
+    }
+
+    /**
      * Helper method to check if the provided |scanResult| corresponds to a WEP network or not.
      * This checks if the provided capabilities string contains WEP encryption type or not.
      */
@@ -118,7 +126,8 @@ public class ScanResultUtil {
      */
     public static boolean isScanResultForOpenNetwork(ScanResult scanResult) {
         return !(isScanResultForWepNetwork(scanResult) || isScanResultForPskNetwork(scanResult)
-                || isScanResultForEapNetwork(scanResult));
+                || isScanResultForEapNetwork(scanResult) || isScanResultForSaeNetwork(scanResult)
+                || isScanResultForDppNetwork(scanResult) || isScanResultForEapSuiteBNetwork(scanResult));
     }
 
     /**
路径:packages/apps/Settings/

diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index 96d9b8b..1862cfe 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -83,10 +83,19 @@
                         style="@style/wifi_item_label"
                         android:text="@string/wifi_security" />
 
+                <Spinner android:id="@+id/security_no_wpa3"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    style="@style/wifi_item_spinner"
+                    android:visibility="gone"
+                    android:prompt="@string/wifi_security"
+                    android:entries="@array/wifi_security_no_wpa3" />
+
                 <Spinner android:id="@+id/security"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         style="@style/wifi_item_spinner"
+                        android:visibility="gone"
                         android:prompt="@string/wifi_security"
                         android:entries="@array/wifi_security" />
             </LinearLayout>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index b55de87..99e0bee 100755
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -230,6 +230,20 @@
     </string-array>
 
     <!-- Match this with the constants in AccessPoint. --> <skip />
+    <!-- Wi-Fi security types for New User Dialog. WPA3 is not configurable. -->
+    <string-array name="wifi_security_no_wpa3">
+        <!-- The Wi-Fi network does not have any security. -->
+        <item>@string/wifi_security_none</item>
+        <!-- Do not translate. -->
+        <item>@string/wifi_security_wep</item>
+        <!-- Do not translate. -->
+        <item>@string/wifi_security_psk_generic</item>
+        <!-- Do not translate. -->
+        <item>@string/wifi_security_eap</item>
+    </string-array>
+
+
+    <!-- Match this with the constants in AccessPoint. --> <skip />
     <!-- Wi-Fi security types for New User Dialog. EAP is not configurable. -->
     <string-array name="wifi_security_no_eap">
         <!-- The Wi-Fi network does not have any security. -->
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 1c74ca9..5f25504 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -187,6 +187,7 @@ public class WifiConfigController implements TextWatcher,
     private TelephonyManager mTelephonyManager;
     private SubscriptionManager mSubscriptionManager = null;
     private int selectedSimCardNumber;
+    private boolean mWPA3Support;
 
     public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
             int mode) {
@@ -245,13 +246,20 @@ public class WifiConfigController implements TextWatcher,
                         : View.VISIBLE);
         mShareThisWifiCheckBox = (CheckBox) mView.findViewById(R.id.share_this_wifi);
         mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+        mWPA3Support = mContext.getResources().getBoolean(com.android.internal.R.bool.config_wifi_wpa3_supported);
 
         if (mAccessPoint == null) { // new network
             mConfigUi.setTitle(R.string.wifi_add_network);
 
             mSsidView = (TextView) mView.findViewById(R.id.ssid);
             mSsidView.addTextChangedListener(this);
-            mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
+
+            if (mWPA3Support) {
+                mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
+            } else {
+                mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security_no_wpa3));
+            }
+            mSecuritySpinner.setVisibility(View.VISIBLE);
             mSecuritySpinner.setOnItemSelectedListener(this);
             mView.findViewById(R.id.type).setVisibility(View.VISIBLE);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值