Skip to content

Commit

Permalink
wraper security type access
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-hh committed Mar 26, 2023
1 parent eeb0493 commit 57fbcf4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
41 changes: 21 additions & 20 deletions src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ extern uint8_t _heap_size;
namespace chip {
namespace DeviceLayer {

uint8_t MapAuthModeToSecurityType(int authmode)
{
switch (authmode)
{
case WIFI_EVENT_BEACON_IND_AUTH_OPEN:
return 1;
case WIFI_EVENT_BEACON_IND_AUTH_WEP:
return 2;
case WIFI_EVENT_BEACON_IND_AUTH_WPA_PSK:
return 3;
case WIFI_EVENT_BEACON_IND_AUTH_WPA2_PSK:
return 4;
case WIFI_EVENT_BEACON_IND_AUTH_WPA3_SAE:
return 5;
default:
return 0;
}
}

DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
{
static DiagnosticDataProviderImpl sInstance;
Expand Down Expand Up @@ -251,7 +232,27 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNe
{
if (ConnectivityMgrImpl()._IsWiFiStationConnected())
{
securityType = static_cast<app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum>(wifi_mgmr_get_security_type());
if (wifi_mgmr_security_type_is_open())
{
securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kNone;
}
else if (wifi_mgmr_security_type_is_wpa())
{
securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa;
}
else if (wifi_mgmr_security_type_is_wpa2())
{
securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa2;
}
else if (wifi_mgmr_security_type_is_wpa3())
{
securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa3;
}
else
{
securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWep;
}

return CHIP_NO_ERROR;
}

Expand Down
56 changes: 26 additions & 30 deletions src/platform/bouffalolab/BL602/wifi_mgmr_portable.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,34 @@ int wifi_mgmr_profile_ssid_get(uint8_t * ssid)
return profile_msg.ssid_len;
}

uint32_t wifi_mgmr_get_security_type(void)
bool wifi_mgmr_security_type_is_open(void)
{
/** return values defined from app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum */
if (strlen(wifiMgmr.wifi_mgmr_stat_info.passphr))
return strlen(wifiMgmr.wifi_mgmr_stat_info.passphr) == 0;
}

bool wifi_mgmr_security_type_is_wpa(void)
{
return WPA_PROTO_WPA == gWpaSm.proto;
}

bool wifi_mgmr_security_type_is_wpa2(void)
{
if (WPA_PROTO_RSN == gWpaSm.proto)
{
if (gWpaSm.pmk_len)
{
if (WPA_PROTO_WPA == gWpaSm.proto)
{
return 3;
}
else if (WPA_PROTO_RSN == gWpaSm.proto)
{
if (gWpaSm.key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_PSK_SHA256))
{
return 4;
}
else
{
return 5;
}
}
else
{
return 2;
}
}
else
{
return 2;
}
return (gWpaSm.key_mgmt & (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_IEEE8021X_SHA256 |
WPA_KEY_MGMT_FT_IEEE8021X)) != 0;
}

return false;
}

bool wifi_mgmr_security_type_is_wpa3(void)
{
if (WPA_PROTO_RSN == gWpaSm.proto)
{
return (gWpaSm.key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE)) != 0;
}

return 1;
return false;
}
6 changes: 5 additions & 1 deletion src/platform/bouffalolab/BL602/wifi_mgmr_portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ void wifi_mgmr_conn_result_get(uint16_t * status_code, uint16_t * reason_code);
int wifi_mgmr_profile_ssid_get(uint8_t * ssid);
int wifi_mgmr_get_scan_ap_num(void);
void wifi_mgmr_get_scan_result(wifi_mgmr_ap_item_t * result, int * num, uint8_t scan_type, char * ssid);
uint32_t wifi_mgmr_get_security_type(void);

bool wifi_mgmr_security_type_is_open(void);
bool wifi_mgmr_security_type_is_wpa(void);
bool wifi_mgmr_security_type_is_wpa2(void);
bool wifi_mgmr_security_type_is_wpa3(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 57fbcf4

Please sign in to comment.