Skip to content

Commit

Permalink
[Silabs] Adds fix for LastNetworkID & LastConnectErrorValue have null…
Browse files Browse the repository at this point in the history
… value after device reset (#26237)

* Adds support for NetworkStatusChangeCallback

* Remove err

* Moves logic to ConnectWiFiNetwork

* Adds null check print

* Adds UpdateNetworkingStatus API

* Adds SSID length check

* Refactors UpdateNetworkingStatus invocation in the ChangeWiFiStationState function

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 23, 2023
1 parent d871db4 commit 4207801
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)
SILABS_LOG("APP: Wait WiFi Init");
while (!wfx_hw_ready())
{
vTaskDelay(10);
vTaskDelay(pdMS_TO_TICKS(10));
}
SILABS_LOG("APP: Done WiFi Init");
/* We will init server when we get IP */
Expand Down
3 changes: 2 additions & 1 deletion src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void ConnectivityManagerImpl::OnStationConnected()

void ConnectivityManagerImpl::OnStationDisconnected()
{
// TODO Invoke WARM to perform actions that occur when the WiFi station interface goes down.
// TODO: Invoke WARM to perform actions that occur when the WiFi station interface goes down.

// Alert other components of the new state.
ChipDeviceEvent event;
Expand All @@ -420,6 +420,7 @@ void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState)
ChipLogProgress(DeviceLayer, "WiFi station state change: %s -> %s", WiFiStationStateToStr(mWiFiStationState),
WiFiStationStateToStr(newState));
mWiFiStationState = newState;
NetworkCommissioning::SlWiFiDriver::GetInstance().UpdateNetworkingStatus();
}
}

Expand Down
40 changes: 34 additions & 6 deletions src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ SlScanResponseIterator<NetworkCommissioning::WiFiScanResponse> mScanResponseIter
CHIP_ERROR SlWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
{
CHIP_ERROR err;
size_t ssidLen = 0;
size_t credentialsLen = 0;
mpScanCallback = nullptr;
mpConnectCallback = nullptr;
size_t ssidLen = 0;
size_t credentialsLen = 0;
mpScanCallback = nullptr;
mpConnectCallback = nullptr;
mpStatusChangeCallback = networkStatusChangeCallback;

#ifdef SL_ONNETWORK_PAIRING
memcpy(&mSavedNetwork.ssid[0], SL_WIFI_SSID, sizeof(SL_WIFI_SSID));
Expand Down Expand Up @@ -135,11 +136,12 @@ 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");
int32_t status = wfx_sta_discon();
if (status != 0)
status = wfx_sta_discon();
if (status != SL_STATUS_OK)
{
return CHIP_ERROR_INTERNAL;
}
Expand All @@ -159,6 +161,32 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
return CHIP_NO_ERROR;
}

// TODO: Re-write implementation with proper driver based callback
void SlWiFiDriver::UpdateNetworkingStatus()
{
if (mpStatusChangeCallback == nullptr)
{
ChipLogError(NetworkProvisioning, "networkStatusChangeCallback is nil");
return;
}

if (mStagingNetwork.ssidLen == 0)
{
ChipLogError(NetworkProvisioning, "ssidLen is 0");
return;
}

ByteSpan networkId = ByteSpan((const unsigned char *) mStagingNetwork.ssid, mStagingNetwork.ssidLen);
if (!wfx_is_sta_connected())
{
mpStatusChangeCallback->OnNetworkingStatusChange(Status::kUnknownError, MakeOptional(networkId),
MakeOptional((int32_t) SL_STATUS_FAIL));
return;
}
mpStatusChangeCallback->OnNetworkingStatusChange(Status::kSuccess, MakeOptional(networkId),
MakeOptional((int32_t) SL_STATUS_OK));
}

void SlWiFiDriver::OnConnectWiFiNetwork()
{
if (mpConnectCallback)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/NetworkCommissioningWiFiDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class SlWiFiDriver final : public WiFiDriver
chip::BitFlags<WiFiSecurity> ConvertSecuritytype(wfx_sec_t security);

void OnConnectWiFiNetwork();
void UpdateNetworkingStatus();
static SlWiFiDriver & GetInstance()
{
static SlWiFiDriver instance;
Expand All @@ -138,6 +139,7 @@ class SlWiFiDriver final : public WiFiDriver
WiFiNetwork mStagingNetwork = {};
ScanCallback * mpScanCallback;
ConnectCallback * mpConnectCallback;
NetworkStatusChangeCallback * mpStatusChangeCallback = nullptr;
};

} // namespace NetworkCommissioning
Expand Down

0 comments on commit 4207801

Please sign in to comment.