From 54967379adfaafa8787d9e3152e77d363b2e9e42 Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Wed, 19 Jul 2023 01:28:14 +0800 Subject: [PATCH] ESP32: Map wifi_auth_mode_t to NetworkCommissioning Security (#27929) --- .../ESP32/NetworkCommissioningDriver.cpp | 34 +++++++++++++++++++ .../ESP32/NetworkCommissioningDriver.h | 7 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index a99f20a57a0885..2c597da14d2ad3 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -38,6 +38,40 @@ constexpr char kWiFiCredentialsKeyName[] = "wifi-pass"; static uint8_t WiFiSSIDStr[DeviceLayer::Internal::kMaxWiFiSSIDLength]; } // namespace +BitFlags ConvertSecurityType(wifi_auth_mode_t authMode) +{ + BitFlags securityType; + switch (authMode) + { + case WIFI_AUTH_OPEN: + securityType.Set(WiFiSecurity::kUnencrypted); + break; + case WIFI_AUTH_WEP: + securityType.Set(WiFiSecurity::kWep); + break; + case WIFI_AUTH_WPA_PSK: + securityType.Set(WiFiSecurity::kWpaPersonal); + break; + case WIFI_AUTH_WPA2_PSK: + securityType.Set(WiFiSecurity::kWpa2Personal); + break; + case WIFI_AUTH_WPA_WPA2_PSK: + securityType.Set(WiFiSecurity::kWpa2Personal); + securityType.Set(WiFiSecurity::kWpaPersonal); + break; + case WIFI_AUTH_WPA3_PSK: + securityType.Set(WiFiSecurity::kWpa3Personal); + break; + case WIFI_AUTH_WPA2_WPA3_PSK: + securityType.Set(WiFiSecurity::kWpa3Personal); + securityType.Set(WiFiSecurity::kWpa2Personal); + break; + default: + break; + } + return securityType; +} + CHIP_ERROR GetConfiguredNetwork(Network & network) { wifi_ap_record_t ap_info; diff --git a/src/platform/ESP32/NetworkCommissioningDriver.h b/src/platform/ESP32/NetworkCommissioningDriver.h index ed5fac3414a3b4..7a261654d4f71e 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.h +++ b/src/platform/ESP32/NetworkCommissioningDriver.h @@ -19,6 +19,9 @@ #include #include +using chip::BitFlags; +using chip::app::Clusters::NetworkCommissioning::WiFiSecurityBitmap; + namespace chip { namespace DeviceLayer { namespace NetworkCommissioning { @@ -28,6 +31,8 @@ constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10; constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 30; } // namespace +BitFlags ConvertSecurityType(wifi_auth_mode_t authMode); + class ESPScanResponseIterator : public Iterator { public: @@ -40,7 +45,7 @@ class ESPScanResponseIterator : public Iterator return false; } - item.security.SetRaw(mpScanResults[mIternum].authmode); + item.security = ConvertSecurityType(mpScanResults[mIternum].authmode); static_assert(chip::DeviceLayer::Internal::kMaxWiFiSSIDLength <= UINT8_MAX, "SSID length might not fit in item.ssidLen"); item.ssidLen = static_cast( strnlen(reinterpret_cast(mpScanResults[mIternum].ssid), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength));