Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32: Map wifi_auth_mode_t to NetworkCommissioning Security #27929

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
}
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