Skip to content

Commit

Permalink
[Silabs] Continue WifiInterface headers clean up (#37107)
Browse files Browse the repository at this point in the history
* Clean up Wifi Interface headers

* Rename SiWx function

* fix comment

* fix build

* Address review comments
  • Loading branch information
mkardous-silabs authored Jan 20, 2025
1 parent ad3f882 commit f19f44a
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 744 deletions.
2 changes: 1 addition & 1 deletion examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ CHIP_ERROR BaseApplication::Init()
* Wait for the WiFi to be initialized
*/
ChipLogProgress(AppServer, "APP: Wait WiFi Init");
while (!wfx_hw_ready())
while (!IsStationReady())
{
osDelay(pdMS_TO_TICKS(10));
}
Expand Down
16 changes: 10 additions & 6 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@

#ifdef SL_WIFI
#include <platform/silabs/wifi/WifiInterface.h>
#endif /* SL_WIFI */

// TODO: We shouldn't need any platform specific includes in this file
#ifdef WF200_WIFI
#include <platform/silabs/wifi/wf200/ncp/sl_wfx_task.h>
#endif // WF200_WIFI
#endif // SL_WIFI

#if PW_RPC_ENABLED
#include "Rpc.h"
Expand All @@ -40,6 +45,7 @@
#include "MemMonitoring.h"
#endif

// TODO: We shouldn't need any platform specific includes in this file
#if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1
#include <platform/silabs/SiWx917/SiWxPlatformInterface.h>
#include <platform/silabs/wifi/wiseconnect-interface/WiseconnectWifiInterface.h>
Expand Down Expand Up @@ -308,17 +314,15 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
#ifdef SL_WIFI
CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
{
// TODO: Platform specific init should not be required here
#ifdef WF200_WIFI
// Start wfx bus communication task.
wfx_bus_start();
#ifdef SL_WFX_USE_SECURE_LINK
// start securelink key renegotiation task
wfx_securelink_task_start();
#endif // SL_WFX_USE_SECURE_LINK
#endif // WF200_WIFI

// TODO: Platform specific init should not be required here
#if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1
VerifyOrReturnError(sl_matter_wifi_platform_init() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(InitSiWxWifi() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
#endif // SLI_SI91X_MCU_INTERFACE

return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/gn_silabs_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ else

NCP_DIR_SUFFIX="/"$2
USE_WIFI=true
optArgs+="chip_device_platform =\"efr32\" chip_crypto_keystore=\"psa\""
optArgs+="chip_device_platform =\"efr32\" chip_crypto_keystore=\"psa\" "
shift
shift
;;
Expand Down
15 changes: 8 additions & 7 deletions src/platform/silabs/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,27 @@ void ConfigurationManagerImpl::ClearThreadStack()

void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
CHIP_ERROR err;
CHIP_ERROR error = CHIP_NO_ERROR;

ChipLogProgress(DeviceLayer, "Performing factory reset");

err = SilabsConfig::FactoryResetConfig();
if (err != CHIP_NO_ERROR)
error = SilabsConfig::FactoryResetConfig();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", chip::ErrorStr(err));
ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", chip::ErrorStr(error));
}

GetDefaultInstance().ClearThreadStack();

PersistedStorage::KeyValueStoreMgrImpl().ErasePartition();

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
sl_status_t status = sl_matter_wifi_disconnect();
if (status != SL_STATUS_OK)
error = TriggerDisconnection();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "sl_matter_wifi_disconnect() failed: %lx", status);
ChipLogError(DeviceLayer, "TriggerDisconnection() failed: %s", chip::ErrorStr(error));
}

ChipLogProgress(DeviceLayer, "Clearing WiFi provision");
wfx_clear_wifi_provision();
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
Expand Down
14 changes: 4 additions & 10 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod
{
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
{
wifi_mode_t curWiFiMode = wfx_get_wifi_mode();
if ((curWiFiMode == WIFI_MODE_STA) || (curWiFiMode == WIFI_MODE_APSTA))
if (IsStationModeEnabled())
{
mWiFiStationMode = kWiFiStationMode_Enabled;
}
Expand All @@ -138,6 +137,7 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod
mWiFiStationMode = kWiFiStationMode_Disabled;
}
}

return mWiFiStationMode;
}

Expand Down Expand Up @@ -259,14 +259,9 @@ void ConnectivityManagerImpl::DriveStationState()
(mWiFiStationMode != kWiFiStationMode_Enabled && !IsWiFiStationProvisioned()))
{
ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface");
sl_status_t status = sl_matter_wifi_disconnect();
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %lx", status);

// TODO: Clean the function up to remove the usage of goto
goto exit;
}
CHIP_ERROR error = TriggerDisconnection();
SuccessOrExitAction(error, ChipLogError(DeviceLayer, "TriggerDisconnection() failed: %s", ErrorStr(error)));

ChangeWiFiStationState(kWiFiStationState_Disconnecting);
}
Expand Down Expand Up @@ -344,7 +339,6 @@ void ConnectivityManagerImpl::DriveStationState()

void ConnectivityManagerImpl::OnStationConnected()
{
wfx_setup_ip6_link_local(SL_WFX_STA_INTERFACE);
NetworkCommissioning::SlWiFiDriver::GetInstance().OnConnectWiFiNetwork();

UpdateInternetConnectivityState();
Expand Down
94 changes: 45 additions & 49 deletions src/platform/silabs/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,30 @@ void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetr

CHIP_ERROR DiagnosticDataProviderImpl::GetRebootCount(uint16_t & rebootCount)
{
uint32_t count = 0;
CHIP_ERROR err = ConfigurationMgr().GetRebootCount(count);
uint32_t count = 0;
CHIP_ERROR error = ConfigurationMgr().GetRebootCount(count);

if (err == CHIP_NO_ERROR)
if (error == CHIP_NO_ERROR)
{
VerifyOrReturnError(count <= UINT16_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE);
rebootCount = static_cast<uint16_t>(count);
}

return err;
return error;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason)
{
uint32_t reason = 0;
CHIP_ERROR err = ConfigurationMgr().GetBootReason(reason);
uint32_t reason = 0;
CHIP_ERROR error = ConfigurationMgr().GetBootReason(reason);

if (err == CHIP_NO_ERROR)
if (error == CHIP_NO_ERROR)
{
VerifyOrReturnError(reason <= UINT8_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE);
bootReason = static_cast<BootReasonType>(reason);
}

return err;
return error;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetUpTime(uint64_t & upTime)
Expand Down Expand Up @@ -252,8 +252,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
ifp->name = CharSpan::fromCharString(ifp->Name);
ifp->isOperational = true;
Inet::InterfaceType interfaceType;
CHIP_ERROR err = interfaceIterator.GetInterfaceType(interfaceType);
if (err == CHIP_NO_ERROR || err == CHIP_ERROR_NOT_IMPLEMENTED)
CHIP_ERROR error = interfaceIterator.GetInterfaceType(interfaceType);
if (error == CHIP_NO_ERROR || error == CHIP_ERROR_NOT_IMPLEMENTED)
{
switch (interfaceType)
{
Expand Down Expand Up @@ -336,26 +336,27 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net
CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(MutableByteSpan & BssId)
{
constexpr size_t bssIdSize = 6;
wfx_wifi_scan_result_t ap = { 0 };

VerifyOrReturnError(BssId.size() >= bssIdSize, CHIP_ERROR_BUFFER_TOO_SMALL);

wfx_wifi_scan_result_t ap;
int32_t err = wfx_get_ap_info(&ap);
if (err == 0)
if (GetAccessPointInfo(ap) == CHIP_NO_ERROR)
{
memcpy(BssId.data(), ap.bssid, bssIdSize);
BssId.reduce_size(bssIdSize);
return CHIP_NO_ERROR;
}

return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType)
{
using app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum;

wfx_wifi_scan_result_t ap;
int32_t err = wfx_get_ap_info(&ap);
if (err == 0)
wfx_wifi_scan_result_t ap = { 0 };
CHIP_ERROR error = GetAccessPointInfo(ap);
if (error == CHIP_NO_ERROR)
{
// TODO: Is this actually right? Do the wfx_wifi_scan_result_t values
// match the Matter spec ones?
Expand All @@ -373,9 +374,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(app::Clusters::WiFiNetwork

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber)
{
wfx_wifi_scan_result_t ap;
int32_t err = wfx_get_ap_info(&ap);
if (err == 0)
wfx_wifi_scan_result_t ap = { 0 };
CHIP_ERROR error = GetAccessPointInfo(ap);
if (error == CHIP_NO_ERROR)
{
channelNumber = ap.chan;
return CHIP_NO_ERROR;
Expand All @@ -385,9 +386,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNu

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi)
{
wfx_wifi_scan_result_t ap;
int32_t err = wfx_get_ap_info(&ap);
if (err == 0)
wfx_wifi_scan_result_t ap = { 0 };
CHIP_ERROR error = GetAccessPointInfo(ap);
if (error == CHIP_NO_ERROR)
{
rssi = ap.rssi;
return CHIP_NO_ERROR;
Expand All @@ -397,9 +398,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi)

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
beaconLostCount = extra_info.beacon_lost_count;
return CHIP_NO_ERROR;
Expand All @@ -414,9 +415,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentM

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
packetMulticastRxCount = extra_info.mcast_rx_count;
return CHIP_NO_ERROR;
Expand All @@ -426,9 +427,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t &

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
packetMulticastTxCount = extra_info.mcast_tx_count;
return CHIP_NO_ERROR;
Expand All @@ -438,9 +439,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastTxCount(uint32_t &

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
packetUnicastRxCount = extra_info.ucast_rx_count;
return CHIP_NO_ERROR;
Expand All @@ -450,9 +451,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastRxCount(uint32_t & pa

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
packetUnicastTxCount = extra_info.ucast_tx_count;
return CHIP_NO_ERROR;
Expand All @@ -462,9 +463,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & pa

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
overrunCount = extra_info.overrun_count;
return CHIP_NO_ERROR;
Expand All @@ -474,9 +475,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCou

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconRxCount(uint32_t & beaconRxCount)
{
wfx_wifi_scan_ext_t extra_info;
int32_t err = wfx_get_ap_ext(&extra_info);
if (err == 0)
wfx_wifi_scan_ext_t extra_info = { 0 };
CHIP_ERROR error = GetAccessPointExtendedInfo(extra_info);
if (error == CHIP_NO_ERROR)
{
beaconRxCount = extra_info.beacon_rx_count;
return CHIP_NO_ERROR;
Expand All @@ -486,12 +487,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconRxCount(uint32_t & beaconRxC

CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts()
{
int32_t err = wfx_reset_counts();
if (err == 0)
{
return CHIP_NO_ERROR;
}
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
return ResetCounters();
}
#endif // SL_WIFI

Expand Down
7 changes: 1 addition & 6 deletions src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,10 @@ Status SlWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCh

CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen)
{
int32_t status = SL_STATUS_OK;
if (ConnectivityMgr().IsWiFiStationProvisioned())
{
ChipLogProgress(DeviceLayer, "Disconecting for current wifi");
status = sl_matter_wifi_disconnect();
if (status != SL_STATUS_OK)
{
return CHIP_ERROR_INTERNAL;
}
ReturnErrorOnFailure(TriggerDisconnection());
}
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));

Expand Down
10 changes: 10 additions & 0 deletions src/platform/silabs/SiWx917/SiWxPlatformInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ void gpio_uulp_pin_interrupt_callback(uint32_t pin_intr)
}
}

/**
* @brief Processing function when a button is triggered
*
* TODO: Move this to SPAM
*
* @param btn which button was pressed
* @param btnAction the action that triggered the buttone vent
*/
void sl_button_on_change(uint8_t btn, uint8_t btnAction);

#endif // SLI_SI91X_MCU_INTERFACE
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#ifdef __cplusplus
Expand Down
Loading

0 comments on commit f19f44a

Please sign in to comment.