From a19db970dc524946801aaad25c8fcaebe2694833 Mon Sep 17 00:00:00 2001 From: wyhong Date: Fri, 10 Mar 2023 21:54:13 +0800 Subject: [PATCH 1/8] Correct some return DiagnosticDataProviderImpl --- .../BL602/DiagnosticDataProviderImpl.cpp | 25 +++-------- .../bouffalolab/BL602/wifi_mgmr_portable.c | 43 ++++++++++++++++++- .../bouffalolab/BL602/wifi_mgmr_portable.h | 4 +- third_party/bouffalolab/bl602/bl_iot_sdk.gni | 4 ++ 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 7c1d8fe9c28ff6..a629835f76cf99 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -29,6 +29,7 @@ #include + extern "C" { #include #include @@ -36,6 +37,7 @@ extern "C" { #include #include #include +#include } extern uint8_t _heap_size; @@ -248,36 +250,24 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType) { - using app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum; - securityType = SecurityTypeEnum::kUnspecified; - // int authmode; - - // authmode = mgmr_get_security_type(); - // securityType = MapAuthModeToSecurityType(authmode); + securityType = (app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum)wifi_mgmr_get_security_type(); return CHIP_NO_ERROR; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum & wifiVersion) { - // TODO: Keeping existing behavior, but this looks broken. - // https://github.com/project-chip/connectedhomeip/issues/25546 - wifiVersion = app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum::kA; - return CHIP_NO_ERROR; + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) { - channelNumber = 0; - - // channelNumber = mgmr_get_current_channel_num(); - + channelNumber = wifiMgmr.channel; return CHIP_NO_ERROR; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) { - // rssi = mgmr_get_rssi(); - + rssi = wifiMgmr.wlan_sta.sta.rssi; return CHIP_NO_ERROR; } @@ -353,13 +343,12 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & pa CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCount) { - overrunCount = 0; return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts() { - return CHIP_NO_ERROR; + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconRxCount(uint32_t & beaconRxCount) diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index c41c3bcc8562cb..125bdd06828e40 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -1,9 +1,17 @@ +#include +#include + #include #include #include +#include -#include -#include +#include +#include +#include +#include + +extern struct wpa_sm gWpaSm; int wifi_mgmr_get_bssid(uint8_t * bssid) { @@ -103,3 +111,34 @@ int wifi_mgmr_profile_ssid_get(uint8_t * ssid) return profile_msg.ssid_len; } + +uint32_t wifi_mgmr_get_security_type(void) +{ + /** return values defined from app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum */ + if (strlen(wifiMgmr.wifi_mgmr_stat_info.passphr)) { + 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 if (WPA_PROTO_WAPI == gWpaSm.proto) { + return 6; + } + else { + return 2; + } + } + else { + return 2; + } + } + + return 1; +} \ No newline at end of file diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h index 243cec7ecdd87a..10c406d325f32b 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h @@ -6,14 +6,12 @@ extern "C" { #endif void wifi_mgmr_sta_ssid_get(char * ssid); -int mgmr_get_security_type(void); int wifi_mgmr_get_bssid(uint8_t * bssid); -int mgmr_get_current_channel_num(void); -int mgmr_get_rssi(void); 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); #ifdef __cplusplus } diff --git a/third_party/bouffalolab/bl602/bl_iot_sdk.gni b/third_party/bouffalolab/bl602/bl_iot_sdk.gni index 2376a32a7441e7..85cf926562b4fa 100644 --- a/third_party/bouffalolab/bl602/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl602/bl_iot_sdk.gni @@ -677,6 +677,10 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/wifi_hosal/include", "${bl_iot_sdk_root}/components/network/wifi_manager", "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/include", + "${bl_iot_sdk_root}/components/security", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/include", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/port/include", ] cflags_c = [ "-Wno-sign-compare" ] From e5b7169e11e3cd2c9c17403ad13f8ff3c01df343 Mon Sep 17 00:00:00 2001 From: wyhong Date: Fri, 10 Mar 2023 22:00:56 +0800 Subject: [PATCH 2/8] Fix restyle --- .../BL602/DiagnosticDataProviderImpl.cpp | 3 +- .../bouffalolab/BL602/wifi_mgmr_portable.c | 35 ++++++++++++------- .../bouffalolab/BL602/wifi_mgmr_portable.h | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index a629835f76cf99..932c9017b8dec3 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -29,7 +29,6 @@ #include - extern "C" { #include #include @@ -250,7 +249,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType) { - securityType = (app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum)wifi_mgmr_get_security_type(); + securityType = (app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum) wifi_mgmr_get_security_type(); return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 125bdd06828e40..7df86eb0b6e57e 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -6,10 +6,10 @@ #include #include -#include -#include #include +#include #include +#include extern struct wpa_sm gWpaSm; @@ -112,33 +112,42 @@ int wifi_mgmr_profile_ssid_get(uint8_t * ssid) return profile_msg.ssid_len; } -uint32_t wifi_mgmr_get_security_type(void) +uint32_t wifi_mgmr_get_security_type(void) { /** return values defined from app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum */ - if (strlen(wifiMgmr.wifi_mgmr_stat_info.passphr)) { - if (gWpaSm.pmk_len) { - if (WPA_PROTO_WPA == gWpaSm.proto) { + if (strlen(wifiMgmr.wifi_mgmr_stat_info.passphr)) + { + 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)) { + else if (WPA_PROTO_RSN == gWpaSm.proto) + { + if (gWpaSm.key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_PSK_SHA256)) + { return 4; } - else { + else + { return 5; } } - else if (WPA_PROTO_WAPI == gWpaSm.proto) { + else if (WPA_PROTO_WAPI == gWpaSm.proto) + { return 6; } - else { + else + { return 2; } } - else { + else + { return 2; } } return 1; -} \ No newline at end of file +} diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h index 10c406d325f32b..a75f11edfd8ee2 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h @@ -11,7 +11,7 @@ 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); +uint32_t wifi_mgmr_get_security_type(void); #ifdef __cplusplus } From 0814cd6a59255191d28efe34a54f0f67d47b30c4 Mon Sep 17 00:00:00 2001 From: wyhong Date: Sat, 11 Mar 2023 14:22:47 +0800 Subject: [PATCH 3/8] Get wifi diagnostic data when wifi is connected --- .../BL602/DiagnosticDataProviderImpl.cpp | 26 ++++++++++++++----- .../bouffalolab/BL602/wifi_mgmr_portable.c | 6 +---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 932c9017b8dec3..48349e5081d190 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -18,7 +18,7 @@ /** * @file * Provides an implementation of the DiagnosticDataProvider object - * for k32w0 platform. + * for Bouffalolab BL602 platform. */ #include @@ -249,8 +249,12 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType) { - securityType = (app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum) wifi_mgmr_get_security_type(); - return CHIP_NO_ERROR; + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + securityType = static_cast(wifi_mgmr_get_security_type()); + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_READ_FAILED; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum & wifiVersion) @@ -260,14 +264,22 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(app::Clusters::WiFiNetwork CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) { - channelNumber = wifiMgmr.channel; - return CHIP_NO_ERROR; + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + channelNumber = wifiMgmr.channel; + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_READ_FAILED; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) { - rssi = wifiMgmr.wlan_sta.sta.rssi; - return CHIP_NO_ERROR; + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + rssi = wifiMgmr.wlan_sta.sta.rssi; + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_READ_FAILED; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 7df86eb0b6e57e..a0ba7eb2673387 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -6,10 +6,10 @@ #include #include +#include #include #include #include -#include extern struct wpa_sm gWpaSm; @@ -134,10 +134,6 @@ uint32_t wifi_mgmr_get_security_type(void) return 5; } } - else if (WPA_PROTO_WAPI == gWpaSm.proto) - { - return 6; - } else { return 2; From 6804cdec9d8ef3a912ba25bff51f2e368c4d1290 Mon Sep 17 00:00:00 2001 From: wyhong Date: Sat, 11 Mar 2023 14:26:42 +0800 Subject: [PATCH 4/8] Fix restyle --- .../bouffalolab/BL602/DiagnosticDataProviderImpl.cpp | 11 +++++++---- src/platform/bouffalolab/BL602/wifi_mgmr_portable.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 48349e5081d190..5aa9bb115ac294 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -249,11 +249,12 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType) { - if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { securityType = static_cast(wifi_mgmr_get_security_type()); return CHIP_NO_ERROR; } - + return CHIP_ERROR_READ_FAILED; } @@ -264,7 +265,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(app::Clusters::WiFiNetwork CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) { - if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { channelNumber = wifiMgmr.channel; return CHIP_NO_ERROR; } @@ -274,7 +276,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNu CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) { - if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { rssi = wifiMgmr.wlan_sta.sta.rssi; return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index a0ba7eb2673387..dfa9d1be3f9395 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -6,10 +6,10 @@ #include #include -#include #include #include #include +#include extern struct wpa_sm gWpaSm; From b7f3ed8f1e42be642f19d310125bdca6ea70a791 Mon Sep 17 00:00:00 2001 From: wyhong Date: Sat, 11 Mar 2023 15:00:07 +0800 Subject: [PATCH 5/8] Fix compile error after restyled --- src/platform/bouffalolab/BL602/wifi_mgmr_portable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index dfa9d1be3f9395..15ed87b3603ce6 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -6,10 +6,11 @@ #include #include +#include + #include #include #include -#include extern struct wpa_sm gWpaSm; From c8e5e6a1ec5b2e3b0f041e399af03aae735af2ad Mon Sep 17 00:00:00 2001 From: wyhong Date: Tue, 21 Mar 2023 09:45:20 +0800 Subject: [PATCH 6/8] correct comments --- src/platform/bouffalolab/BL602/wifi_mgmr_portable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 15ed87b3603ce6..0a6f1574edf8db 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -115,7 +115,7 @@ int wifi_mgmr_profile_ssid_get(uint8_t * ssid) uint32_t wifi_mgmr_get_security_type(void) { - /** return values defined from app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum */ + /** return values defined from app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum */ if (strlen(wifiMgmr.wifi_mgmr_stat_info.passphr)) { if (gWpaSm.pmk_len) From 798ae879d8706eabc024d68c7ba1e23158ade4c2 Mon Sep 17 00:00:00 2001 From: wyhong Date: Sun, 26 Mar 2023 23:25:29 +0800 Subject: [PATCH 7/8] wraper security type access --- .../BL602/DiagnosticDataProviderImpl.cpp | 41 +++++++------- .../bouffalolab/BL602/wifi_mgmr_portable.c | 56 +++++++++---------- .../bouffalolab/BL602/wifi_mgmr_portable.h | 6 +- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 5aa9bb115ac294..33df4eb605a733 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -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; @@ -251,7 +232,27 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNe { if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { - securityType = static_cast(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; } diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 0a6f1574edf8db..4291c399ebe40e 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -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; } diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h index a75f11edfd8ee2..cf25c7ef730c14 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h @@ -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 } From c536290d5014a5878f8f00a878b8ed8ec01b276d Mon Sep 17 00:00:00 2001 From: wyhong Date: Sun, 26 Mar 2023 23:37:22 +0800 Subject: [PATCH 8/8] Fix restyle --- .../bouffalolab/BL602/DiagnosticDataProviderImpl.cpp | 10 +++++----- src/platform/bouffalolab/BL602/wifi_mgmr_portable.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 33df4eb605a733..2b61b4bae3a990 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -232,23 +232,23 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNe { if (ConnectivityMgrImpl()._IsWiFiStationConnected()) { - if (wifi_mgmr_security_type_is_open()) + if (wifi_mgmr_security_type_is_open()) { securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kNone; } - else if (wifi_mgmr_security_type_is_wpa()) + else if (wifi_mgmr_security_type_is_wpa()) { securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa; } - else if (wifi_mgmr_security_type_is_wpa2()) + else if (wifi_mgmr_security_type_is_wpa2()) { securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa2; } - else if (wifi_mgmr_security_type_is_wpa3()) + else if (wifi_mgmr_security_type_is_wpa3()) { securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWpa3; } - else + else { securityType = app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum::kWep; } diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 4291c399ebe40e..04ee57fe66c4b7 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -125,11 +125,11 @@ bool wifi_mgmr_security_type_is_wpa(void) bool wifi_mgmr_security_type_is_wpa2(void) { - if (WPA_PROTO_RSN == gWpaSm.proto) + if (WPA_PROTO_RSN == gWpaSm.proto) { - 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 (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; @@ -137,7 +137,7 @@ bool wifi_mgmr_security_type_is_wpa2(void) bool wifi_mgmr_security_type_is_wpa3(void) { - if (WPA_PROTO_RSN == gWpaSm.proto) + if (WPA_PROTO_RSN == gWpaSm.proto) { return (gWpaSm.key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE)) != 0; }