From 23575889a170db47133850d3dc9809f96ab98722 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Mon, 27 Mar 2023 20:08:08 +0800 Subject: [PATCH] [Bouffalolab] Fix some implemenations to get Wi-Fi Diagnostic information (#25621) * Correct some return DiagnosticDataProviderImpl * Fix restyle * Get wifi diagnostic data when wifi is connected * Fix restyle * Fix compile error after restyled * correct comments * wraper security type access * Fix restyle --- .../BL602/DiagnosticDataProviderImpl.cpp | 80 ++++++++++--------- .../bouffalolab/BL602/wifi_mgmr_portable.c | 45 ++++++++++- .../bouffalolab/BL602/wifi_mgmr_portable.h | 8 +- third_party/bouffalolab/bl602/bl_iot_sdk.gni | 4 + 4 files changed, 94 insertions(+), 43 deletions(-) diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index 7c1d8fe9c28ff6..2b61b4bae3a990 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 @@ -36,6 +36,7 @@ extern "C" { #include #include #include +#include } extern uint8_t _heap_size; @@ -43,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; @@ -248,37 +230,60 @@ 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; + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { + 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; + } - // authmode = mgmr_get_security_type(); - // securityType = MapAuthModeToSecurityType(authmode); - return CHIP_NO_ERROR; + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_READ_FAILED; } 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(); + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { + channelNumber = wifiMgmr.channel; + return CHIP_NO_ERROR; + } - return CHIP_NO_ERROR; + return CHIP_ERROR_READ_FAILED; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) { - // rssi = mgmr_get_rssi(); + if (ConnectivityMgrImpl()._IsWiFiStationConnected()) + { + rssi = wifiMgmr.wlan_sta.sta.rssi; + return CHIP_NO_ERROR; + } - return CHIP_NO_ERROR; + return CHIP_ERROR_READ_FAILED; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) @@ -353,13 +358,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..04ee57fe66c4b7 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -1,9 +1,18 @@ +#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 +112,35 @@ int wifi_mgmr_profile_ssid_get(uint8_t * ssid) return profile_msg.ssid_len; } + +bool wifi_mgmr_security_type_is_open(void) +{ + 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) + { + 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 false; +} diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h index 243cec7ecdd87a..cf25c7ef730c14 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h @@ -6,15 +6,17 @@ 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); +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 } #endif 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" ]