Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %s", NullTerminated(ssid, ssidLen).c_str());
// Resetting the retry connection state machine for a new access point connection
WifiInterface::GetInstance().ResetConnectionRetryInterval();
// Configure the WFX WiFi interface.
WifiInterface::GetInstance().SetWifiCredentials(wifiConfig);
ReturnErrorOnFailure(WifiInterface::GetInstance().SetWifiCredentials(wifiConfig));
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled));
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/SiWx/ble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ constexpr osThreadAttr_t kBleTaskAttr = { .name = "rsi_ble",
.cb_size = osThreadCbSize,
.stack_mem = bleStack,
.stack_size = kBleTaskSize,
.priority = osPriorityHigh };
.priority = osPriorityHigh2 };

void rsi_ble_add_matter_service(void)
{
Expand Down
60 changes: 41 additions & 19 deletions src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi",
.cb_size = osThreadCbSize,
.stack_mem = wlanStack,
.stack_size = kWlanTaskSize,
.priority = osPriorityAboveNormal7 };
.priority = osPriorityHigh };

#if CHIP_CONFIG_ENABLE_ICD_SERVER
constexpr uint32_t kTimeToFullBeaconReception = 5000; // 5 seconds
Expand Down Expand Up @@ -645,7 +645,7 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)

case WifiPlatformEvent::kStationDisconnect: {
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDisconnect");
// TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something
TEMPORARY_RETURN_IGNORED TriggerPlatformWifiDisconnection();

wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationReady)
.Clear(WifiInterface::WifiState::kStationConnecting)
Expand All @@ -664,15 +664,18 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
// TODO: Currently unimplemented
break;

case WifiPlatformEvent::kStationStartJoin:
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartJoin");

// To avoid IOP issues, it is recommended to enable high-performance mode before joining the network.
// TODO: Remove this once the IOP issue related to power save mode switching is fixed in the Wi-Fi SDK.
case WifiPlatformEvent::kStationStartScan:
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartScan");
// To avoid IOP issues, enable high-performance mode before scan/join. TODO: Remove once IOP fix is in Wi-Fi SDK.
#if CHIP_CONFIG_ENABLE_ICD_SERVER
TEMPORARY_RETURN_IGNORED chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
InitiateScan();
PostWifiPlatformEvent(WifiPlatformEvent::kStationStartJoin);
break;

case WifiPlatformEvent::kStationStartJoin:
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartJoin");
JoinWifiNetwork();
break;

Expand Down Expand Up @@ -748,7 +751,14 @@ sl_status_t WifiInterfaceImpl::JoinWifiNetwork(void)
ChipLogError(DeviceLayer, "sl_net_up failed: 0x%lx", static_cast<uint32_t>(status));

wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationConnecting).Clear(WifiInterface::WifiState::kStationConnected);
ScheduleConnectionAttempt();
if (status == SL_STATUS_SI91X_NO_AP_FOUND)
{
ScheduleConnectionAttempt(false); // Scan and join
}
else
{
ScheduleConnectionAttempt(true); // Quick join
}

return status;
}
Expand Down Expand Up @@ -776,7 +786,14 @@ sl_status_t WifiInterfaceImpl::JoinCallback(sl_wifi_event_t event, char * result
ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", status);
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationConnected);

mInstance.ScheduleConnectionAttempt();
if (status == SL_STATUS_SI91X_NO_AP_FOUND)
{
mInstance.ScheduleConnectionAttempt(false); // Scan and join
}
else
{
mInstance.ScheduleConnectionAttempt(true); // Quick join
}
}

return status;
Expand Down Expand Up @@ -1048,9 +1065,7 @@ bool WifiInterfaceImpl::IsStationReady()

CHIP_ERROR WifiInterfaceImpl::TriggerDisconnection()
{
VerifyOrReturnError(TriggerPlatformWifiDisconnection() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
wfx_rsi.dev_state.Clear(WifiState::kStationConnected);

PostWifiPlatformEvent(WifiPlatformEvent::kStationDisconnect);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -1110,25 +1125,32 @@ bool WifiInterfaceImpl::IsWifiProvisioned()
return wfx_rsi.dev_state.Has(WifiState::kStationProvisioned);
}

void WifiInterfaceImpl::SetWifiCredentials(const WifiCredentials & credentials)
CHIP_ERROR WifiInterfaceImpl::SetWifiCredentials(const WifiCredentials & credentials)
{
VerifyOrReturnError(credentials.ssidLength, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(credentials.ssidLength <= WFX_MAX_SSID_LENGTH, CHIP_ERROR_INVALID_ARGUMENT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WFX_MAX_SSID_LENGTH has been replaced with DeviceLayer::Internal::kMaxWiFiSSIDLength

wfx_rsi.credentials = credentials;
wfx_rsi.dev_state.Set(WifiState::kStationProvisioned);
return CHIP_NO_ERROR;
}

CHIP_ERROR WifiInterfaceImpl::ConnectToAccessPoint()
{
VerifyOrReturnError(IsWifiProvisioned(), CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(wfx_rsi.credentials.ssidLength, CHIP_ERROR_INCORRECT_STATE);

// TODO: We should move this validation to where we set the credentials. It is too late here.
VerifyOrReturnError(wfx_rsi.credentials.ssidLength <= WFX_MAX_SSID_LENGTH, CHIP_ERROR_INVALID_ARGUMENT);

ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.credentials.ssid);

WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin;
PostWifiPlatformEvent(event);
PostWifiPlatformEvent(WifiPlatformEvent::kStationStartScan);
return CHIP_NO_ERROR;
}

CHIP_ERROR WifiInterfaceImpl::QuickJoinToAccessPoint()
{
VerifyOrReturnError(IsWifiProvisioned(), CHIP_ERROR_INCORRECT_STATE);

ChipLogProgress(DeviceLayer, "quick join to access point: %s", wfx_rsi.credentials.ssid);

PostWifiPlatformEvent(WifiPlatformEvent::kStationStartJoin);
return CHIP_NO_ERROR;
}

Expand Down
12 changes: 7 additions & 5 deletions src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ class WifiInterfaceImpl final : public WifiInterface
kStationDisconnect = 1,
kAPStart = 2,
kAPStop = 3,
kStationStartJoin = 5,
kConnectionComplete = 6, /* This combines the DHCP and Notify */
kStationDhcpDone = 7,
kStationDhcpPoll = 8,
kStationStartScan = 5,
kStationStartJoin = 6,
kConnectionComplete = 7, /* This combines the DHCP and Notify */
kStationDhcpDone = 8,
kStationDhcpPoll = 9,
};

static WifiInterfaceImpl & GetInstance() { return mInstance; }
Expand All @@ -58,9 +59,10 @@ class WifiInterfaceImpl final : public WifiInterface
bool IsStationReady() override;
CHIP_ERROR TriggerDisconnection() override;
void ClearWifiCredentials() override;
void SetWifiCredentials(const WifiCredentials & credentials) override;
CHIP_ERROR SetWifiCredentials(const WifiCredentials & credentials) override;
CHIP_ERROR GetWifiCredentials(WifiCredentials & credentials) override;
CHIP_ERROR ConnectToAccessPoint(void) override;
CHIP_ERROR QuickJoinToAccessPoint(void) override;
bool HasAnIPv4Address() override;
bool HasAnIPv6Address() override;
void CancelScanNetworks() override;
Expand Down
23 changes: 12 additions & 11 deletions src/platform/silabs/wifi/WifiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ constexpr uint8_t kWlanMaxRetryIntervalsInSec = 60;
uint8_t retryInterval = kWlanMinRetryIntervalsInSec;

/**
* @brief Retry timer callback that triggers a reconnection attempt
*
* TODO: The structure of the retry needs to be redone
*
* @param arg
* @brief Retry timer callback that triggers a reconnection attempt.
* @param arg Pointer to bool (quickJoin) written by ScheduleConnectionAttempt when the timer was started.
*/
void RetryConnectionTimerHandler(void * arg)
{
if (chip::DeviceLayer::Silabs::WifiInterface::GetInstance().ConnectToAccessPoint() != CHIP_NO_ERROR)
bool quickJoin = *static_cast<bool *>(arg);
chip::DeviceLayer::Silabs::WifiInterface & wifi = chip::DeviceLayer::Silabs::WifiInterface::GetInstance();
CHIP_ERROR err = quickJoin ? wifi.QuickJoinToAccessPoint() : wifi.ConnectToAccessPoint();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ConnectToAccessPoint() failed.");
ChipLogError(DeviceLayer, "Connection attempt failed.");
}
}

Expand Down Expand Up @@ -126,8 +126,8 @@ void WifiInterface::NotifyWifiTaskInitialized(void)
sl_wfx_startup_ind_t evt = { 0 };

// TODO: We should move this to the init function and not the notification function
// Creating a timer which will be used to retry connection with AP
mRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, NULL, NULL);
// Creating a timer which will be used to retry connection with AP (arg points to mRetryTimerQuickJoin, set in ScheduleConnectionAttempt).
mRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, &mRetryTimerQuickJoin, NULL);
VerifyOrReturn(mRetryTimer != NULL);

evt.header.id = to_underlying(WifiEvent::kStartUp);
Expand All @@ -148,8 +148,10 @@ void WifiInterface::NotifyWifiTaskInitialized(void)
}

// TODO: The retry stategy needs to be re-worked
void WifiInterface::ScheduleConnectionAttempt()
void WifiInterface::ScheduleConnectionAttempt(bool quickJoin)
{
mRetryTimerQuickJoin = quickJoin;

if (retryInterval > kWlanMaxRetryIntervalsInSec)
{
retryInterval = kWlanMaxRetryIntervalsInSec;
Expand All @@ -158,7 +160,6 @@ void WifiInterface::ScheduleConnectionAttempt()
if (osTimerStart(mRetryTimer, pdMS_TO_TICKS(retryInterval * 1000)) != osOK)
{
ChipLogProgress(DeviceLayer, "Failed to start retry timer");
// Sending the join command if retry timer failed to start
if (ConnectToAccessPoint() != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ConnectToAccessPoint() failed.");
Expand Down
18 changes: 16 additions & 2 deletions src/platform/silabs/wifi/WifiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
* The function will overwrite any existing Wi-Fi credentials.
*
* @param[in] credentials
* @return CHIP_ERROR CHIP_NO_ERROR on success, CHIP_ERROR_INVALID_ARGUMENT if ssidLength is 0 or exceeds WFX_MAX_SSID_LENGTH
*/
virtual void SetWifiCredentials(const WifiCredentials & credentials) = 0;
virtual CHIP_ERROR SetWifiCredentials(const WifiCredentials & credentials) = 0;

/**
* @brief Returns the configured Wi-Fi credentials
Expand All @@ -323,6 +324,16 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
*/
virtual CHIP_ERROR ConnectToAccessPoint(void) = 0;

/**
* @brief Triggers join to the provisioned access point without scanning.
* Use when scan info (e.g. channel, BSSID) is already known to avoid a prior scan.
*
* @return CHIP_ERROR CHIP_NO_ERROR, the join was successfully triggered
* CHIP_ERROR_INCORRECT_STATE, not provisioned or no credentials
* CHIP_ERROR_INVALID_ARGUMENT, credentials invalid
*/
virtual CHIP_ERROR QuickJoinToAccessPoint(void) = 0;

/**
* @brief Cancels the on-going network scan operation.
* If one isn't in-progress, function doesn't do anything
Expand Down Expand Up @@ -403,8 +414,10 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
* @note The retry interval increases exponentially with each attempt, starting from a minimum value and doubling each time,
* up to a maximum value. For example, if the initial retry interval is 1 second, the subsequent intervals will be 2
* seconds, 4 seconds, 8 seconds, and so on, until the maximum retry interval is reached.
*
* @param quickJoin If true, the next retry will use quick join; if false, scan then join (ConnectToAccessPoint).
*/
void ScheduleConnectionAttempt();
void ScheduleConnectionAttempt(bool quickJoin = false);

bool mHasNotifiedIPv6 = false;
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
Expand All @@ -413,6 +426,7 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface

private:
osTimerId_t mRetryTimer;
bool mRetryTimerQuickJoin = false;
};

} // namespace Silabs
Expand Down
Loading