Skip to content

Commit

Permalink
ESP32: Map wifi_auth_mode_t to NetworkCommissioning Security (#27929)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored and pull[bot] committed Feb 22, 2024
1 parent 5e309f1 commit 5496737
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ constexpr char kWiFiCredentialsKeyName[] = "wifi-pass";
static uint8_t WiFiSSIDStr[DeviceLayer::Internal::kMaxWiFiSSIDLength];
} // namespace

BitFlags<WiFiSecurityBitmap> ConvertSecurityType(wifi_auth_mode_t authMode)
{
BitFlags<WiFiSecurityBitmap> 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;
Expand Down
7 changes: 6 additions & 1 deletion src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <esp_wifi.h>
#include <platform/NetworkCommissioning.h>

using chip::BitFlags;
using chip::app::Clusters::NetworkCommissioning::WiFiSecurityBitmap;

namespace chip {
namespace DeviceLayer {
namespace NetworkCommissioning {
Expand All @@ -28,6 +31,8 @@ constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10;
constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 30;
} // namespace

BitFlags<WiFiSecurityBitmap> ConvertSecurityType(wifi_auth_mode_t authMode);

class ESPScanResponseIterator : public Iterator<WiFiScanResponse>
{
public:
Expand All @@ -40,7 +45,7 @@ class ESPScanResponseIterator : public Iterator<WiFiScanResponse>
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<uint8_t>(
strnlen(reinterpret_cast<const char *>(mpScanResults[mIternum].ssid), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength));
Expand Down

0 comments on commit 5496737

Please sign in to comment.