Skip to content

Commit

Permalink
[Bouffalolab] Fix some implemenations to get Wi-Fi Diagnostic informa…
Browse files Browse the repository at this point in the history
…tion (#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
  • Loading branch information
wy-hh authored and pull[bot] committed Nov 15, 2023
1 parent 61a2f69 commit 3479113
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 43 deletions.
80 changes: 42 additions & 38 deletions src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @file
* Provides an implementation of the DiagnosticDataProvider object
* for k32w0 platform.
* for Bouffalolab BL602 platform.
*/

#include <platform/internal/CHIPDeviceLayerInternal.h>
Expand All @@ -36,32 +36,14 @@ extern "C" {
#include <bl_efuse.h>
#include <bl_sys.h>
#include <wifi_mgmr_ext.h>
#include <wifi_mgmr_portable.h>
}

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 @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 43 additions & 2 deletions src/platform/bouffalolab/BL602/wifi_mgmr_portable.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include <stdint.h>
#include <string.h>

#include <bl60x_wifi_driver/wifi_mgmr.h>
#include <bl60x_wifi_driver/wifi_mgmr_api.h>
#include <bl60x_wifi_driver/wifi_mgmr_profile.h>
#include <supplicant_api.h>

#include <stdint.h>
#include <string.h>
#include <wpa_supplicant/src/utils/common.h>

#include <wpa_supplicant/src/common/defs.h>
#include <wpa_supplicant/src/common/wpa_common.h>
#include <wpa_supplicant/src/rsn_supp/wpa_i.h>

extern struct wpa_sm gWpaSm;

int wifi_mgmr_get_bssid(uint8_t * bssid)
{
Expand Down Expand Up @@ -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;
}
8 changes: 5 additions & 3 deletions src/platform/bouffalolab/BL602/wifi_mgmr_portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions third_party/bouffalolab/bl602/bl_iot_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down

0 comments on commit 3479113

Please sign in to comment.