Skip to content

Commit 07f6f9e

Browse files
[Silabs] Splitting the scan, connect and disconnect for the Wi-Fi (project-chip#43632)
* Splitting the scan, connect and disconnect * Addressing review comments * Update src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> * Update src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> * Updating the function to void from CHIP_ERROR --------- Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
1 parent 0023dea commit 07f6f9e

6 files changed

Lines changed: 45 additions & 45 deletions

File tree

src/platform/silabs/ConfigurationManagerImpl.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
315315
PersistedStorage::KeyValueStoreMgrImpl().ErasePartition();
316316

317317
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
318-
error = WifiInterface::GetInstance().TriggerDisconnection();
319-
if (error != CHIP_NO_ERROR)
320-
{
321-
ChipLogError(DeviceLayer, "TriggerDisconnection() failed: %" CHIP_ERROR_FORMAT, error.Format());
322-
}
318+
WifiInterface::GetInstance().TriggerDisconnection();
323319

324320
ChipLogProgress(DeviceLayer, "Clearing WiFi provision");
325321
WifiInterface::GetInstance().ClearWifiCredentials();

src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,7 @@ void ConnectivityManagerImpl::DriveStationState()
257257
{
258258
ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface");
259259

260-
CHIP_ERROR error = WifiInterface::GetInstance().TriggerDisconnection();
261-
SuccessOrExitAction(error,
262-
ChipLogError(DeviceLayer, "TriggerDisconnection() failed: %" CHIP_ERROR_FORMAT, error.Format()));
263-
260+
WifiInterface::GetInstance().TriggerDisconnection();
264261
ChangeWiFiStationState(kWiFiStationState_Disconnecting);
265262
}
266263
#endif

src/platform/silabs/NetworkCommissioningWiFiDriver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
143143
if (ConnectivityMgr().IsWiFiStationProvisioned())
144144
{
145145
ChipLogProgress(DeviceLayer, "Disconnecting for current wifi");
146-
ReturnErrorOnFailure(WifiInterface::GetInstance().TriggerDisconnection());
146+
WifiInterface::GetInstance().TriggerDisconnection();
147147
}
148148
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));
149149

@@ -163,8 +163,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
163163
ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %s", NullTerminated(ssid, ssidLen).c_str());
164164
// Resetting the retry connection state machine for a new access point connection
165165
WifiInterface::GetInstance().ResetConnectionRetryInterval();
166-
// Configure the WFX WiFi interface.
167-
WifiInterface::GetInstance().SetWifiCredentials(wifiConfig);
166+
ReturnErrorOnFailure(WifiInterface::GetInstance().SetWifiCredentials(wifiConfig));
168167
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));
169168
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled));
170169
return CHIP_NO_ERROR;

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ sl_status_t SetWifiConfigurations()
503503
.encryption = SL_WIFI_DEFAULT_ENCRYPTION,
504504
.client_options = SL_WIFI_JOIN_WITH_SCAN,
505505
.credential_id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID,
506+
.channel_bitmap = {
507+
.channel_bitmap_2_4 = SL_WIFI_DEFAULT_CHANNEL_BITMAP
508+
},
506509
},
507510
.ip = {
508511
.mode = SL_IP_MANAGEMENT_DHCP,
@@ -520,7 +523,8 @@ sl_status_t SetWifiConfigurations()
520523
{
521524
// AP channel is known - This indicates that the network scan was done for a specific SSID.
522525
// Providing the channel and BSSID in the profile avoids scanning all channels again.
523-
profile.config.channel.channel = wfx_rsi.ap_chan;
526+
profile.config.channel.channel = wfx_rsi.ap_chan;
527+
profile.config.channel_bitmap.channel_bitmap_2_4 = (1UL << (wfx_rsi.ap_chan - 1));
524528

525529
chip::MutableByteSpan bssidSpan(profile.config.bssid.octet, kWiFiBSSIDLength);
526530
chip::ByteSpan inBssid(wfx_rsi.ap_bssid.data(), kWiFiBSSIDLength);
@@ -661,7 +665,7 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
661665

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

666670
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationReady)
667671
.Clear(WifiInterface::WifiState::kStationConnecting)
@@ -680,15 +684,18 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
680684
// TODO: Currently unimplemented
681685
break;
682686

683-
case WifiPlatformEvent::kStationStartJoin:
684-
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartJoin");
685-
686-
// To avoid IOP issues, it is recommended to enable high-performance mode before joining the network.
687-
// TODO: Remove this once the IOP issue related to power save mode switching is fixed in the Wi-Fi SDK.
687+
case WifiPlatformEvent::kStationStartScan:
688+
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartScan");
689+
// To avoid IOP issues, enable high-performance mode before scan/join. TODO: Remove once IOP fix is in Wi-Fi SDK.
688690
#if CHIP_CONFIG_ENABLE_ICD_SERVER
689691
TEMPORARY_RETURN_IGNORED chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
690692
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
691693
InitiateScan();
694+
PostWifiPlatformEvent(WifiPlatformEvent::kStationStartJoin);
695+
break;
696+
697+
case WifiPlatformEvent::kStationStartJoin:
698+
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartJoin");
692699
JoinWifiNetwork();
693700
break;
694701

@@ -764,6 +771,7 @@ sl_status_t WifiInterfaceImpl::JoinWifiNetwork(void)
764771
ChipLogError(DeviceLayer, "sl_net_up failed: 0x%lx", static_cast<uint32_t>(status));
765772

766773
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationConnecting).Clear(WifiInterface::WifiState::kStationConnected);
774+
mUseQuickJoin = !(status == SL_STATUS_SI91X_NO_AP_FOUND);
767775
ScheduleConnectionAttempt();
768776

769777
return status;
@@ -792,6 +800,7 @@ sl_status_t WifiInterfaceImpl::JoinCallback(sl_wifi_event_t event, char * result
792800
ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", status);
793801
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationConnected);
794802

803+
mInstance.mUseQuickJoin = !(status == SL_STATUS_SI91X_NO_AP_FOUND);
795804
mInstance.ScheduleConnectionAttempt();
796805
}
797806

@@ -893,7 +902,10 @@ void WifiInterfaceImpl::PostWifiPlatformEvent(WifiPlatformEvent event)
893902

894903
sl_status_t WifiInterfaceImpl::TriggerPlatformWifiDisconnection()
895904
{
896-
return sl_net_down(SL_NET_WIFI_CLIENT_INTERFACE);
905+
sl_status_t status = sl_net_down(SL_NET_WIFI_CLIENT_INTERFACE);
906+
VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_down failed: 0x%lx", status));
907+
908+
return SL_STATUS_OK;
897909
}
898910

899911
#if CHIP_CONFIG_ENABLE_ICD_SERVER
@@ -1062,12 +1074,9 @@ bool WifiInterfaceImpl::IsStationReady()
10621074
return wfx_rsi.dev_state.Has(WifiState::kStationInit);
10631075
}
10641076

1065-
CHIP_ERROR WifiInterfaceImpl::TriggerDisconnection()
1077+
void WifiInterfaceImpl::TriggerDisconnection()
10661078
{
1067-
VerifyOrReturnError(TriggerPlatformWifiDisconnection() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
1068-
wfx_rsi.dev_state.Clear(WifiState::kStationConnected);
1069-
1070-
return CHIP_NO_ERROR;
1079+
PostWifiPlatformEvent(WifiPlatformEvent::kStationDisconnect);
10711080
}
10721081

10731082
void WifiInterfaceImpl::NotifyConnectivity(void)
@@ -1126,25 +1135,22 @@ bool WifiInterfaceImpl::IsWifiProvisioned()
11261135
return wfx_rsi.dev_state.Has(WifiState::kStationProvisioned);
11271136
}
11281137

1129-
void WifiInterfaceImpl::SetWifiCredentials(const WiFiCredentials & credentials)
1138+
CHIP_ERROR WifiInterfaceImpl::SetWifiCredentials(const WiFiCredentials & credentials)
11301139
{
1140+
VerifyOrReturnError(credentials.ssidLen, CHIP_ERROR_INVALID_ARGUMENT);
1141+
VerifyOrReturnError(credentials.ssidLen <= kMaxWiFiSSIDLength, CHIP_ERROR_INVALID_ARGUMENT);
11311142
wfx_rsi.credentials = credentials;
11321143
wfx_rsi.dev_state.Set(WifiState::kStationProvisioned);
1144+
return CHIP_NO_ERROR;
11331145
}
11341146

11351147
CHIP_ERROR WifiInterfaceImpl::ConnectToAccessPoint()
11361148
{
11371149
VerifyOrReturnError(IsWifiProvisioned(), CHIP_ERROR_INCORRECT_STATE);
1138-
VerifyOrReturnError(wfx_rsi.credentials.ssidLen, CHIP_ERROR_INCORRECT_STATE);
1139-
1140-
// TODO: We should move this validation to where we set the credentials. It is too late here.
1141-
VerifyOrReturnError(wfx_rsi.credentials.ssidLen <= kMaxWiFiSSIDLength, CHIP_ERROR_INVALID_ARGUMENT);
11421150

1143-
ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.credentials.ssid);
1144-
1145-
WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin;
1146-
PostWifiPlatformEvent(event);
1151+
ChipLogProgress(DeviceLayer, "%s to access point: %s", mUseQuickJoin ? "quick join" : "connect", wfx_rsi.credentials.ssid);
11471152

1153+
PostWifiPlatformEvent(mUseQuickJoin ? WifiPlatformEvent::kStationStartJoin : WifiPlatformEvent::kStationStartScan);
11481154
return CHIP_NO_ERROR;
11491155
}
11501156

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ class WifiInterfaceImpl final : public WifiInterface
3434
kStationDisconnect = 1,
3535
kAPStart = 2,
3636
kAPStop = 3,
37-
kStationStartJoin = 5,
38-
kConnectionComplete = 6, /* This combines the DHCP and Notify */
39-
kStationDhcpDone = 7,
40-
kStationDhcpPoll = 8,
37+
kStationStartScan = 5,
38+
kStationStartJoin = 6,
39+
kConnectionComplete = 7, /* This combines the DHCP and Notify */
40+
kStationDhcpDone = 8,
41+
kStationDhcpPoll = 9,
4142
};
4243

4344
static WifiInterfaceImpl & GetInstance() { return mInstance; }
@@ -56,9 +57,9 @@ class WifiInterfaceImpl final : public WifiInterface
5657
bool IsStationConnected() override;
5758
bool IsStationModeEnabled() override;
5859
bool IsStationReady() override;
59-
CHIP_ERROR TriggerDisconnection() override;
60+
void TriggerDisconnection() override;
6061
void ClearWifiCredentials() override;
61-
void SetWifiCredentials(const WiFiCredentials & credentials) override;
62+
CHIP_ERROR SetWifiCredentials(const WiFiCredentials & credentials) override;
6263
CHIP_ERROR GetWifiCredentials(WiFiCredentials & credentials) override;
6364
CHIP_ERROR ConnectToAccessPoint(void) override;
6465
bool HasAnIPv4Address() override;
@@ -153,6 +154,7 @@ class WifiInterfaceImpl final : public WifiInterface
153154
void NotifySuccessfulConnection();
154155

155156
bool mHasNotifiedWifiConnectivity = false;
157+
bool mUseQuickJoin = false;
156158

157159
static WifiInterfaceImpl mInstance;
158160
};

src/platform/silabs/wifi/WifiInterface.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,9 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
238238
*
239239
* @note The disconnection is not immediate. It can take a certain amount of time for the device to be in a disconnected state
240240
* once the function is called. When the function returns, the device might not have yet disconnected from the Wi-Fi network.
241-
*
242-
* @return CHIP_ERROR CHIP_NO_ERROR, disconnection request was succesfully triggered
243-
* otherwise, CHIP_ERROR_INTERNAL
241+
* The implementation may only enqueue a disconnect (e.g. post an event); there is no synchronous success/failure to report.
244242
*/
245-
virtual CHIP_ERROR TriggerDisconnection() = 0;
243+
virtual void TriggerDisconnection() = 0;
246244

247245
/**
248246
* @brief Gets the connected access point information.
@@ -288,8 +286,9 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
288286
* The function will overwrite any existing Wi-Fi credentials.
289287
*
290288
* @param[in] credentials
289+
* @return CHIP_ERROR CHIP_NO_ERROR on success, CHIP_ERROR_INVALID_ARGUMENT if ssidLength is 0 or exceeds max SSID length
291290
*/
292-
virtual void SetWifiCredentials(const WiFiCredentials & credentials) = 0;
291+
virtual CHIP_ERROR SetWifiCredentials(const WiFiCredentials & credentials) = 0;
293292

294293
/**
295294
* @brief Returns the configured Wi-Fi credentials
@@ -307,6 +306,7 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
307306
* connection attempt was successful or not.
308307
*
309308
* The returned error code only indicates if the connection attempt was triggered or not.
309+
* On retry after failure, the implementation may use quick join (no scan) when channel/BSSID are known.
310310
*
311311
* @return CHIP_ERROR CHIP_NO_ERROR, the connection attempt was succesfully triggered
312312
* CHIP_ERROR_INCORRECT_STATE, the Wi-Fi station does not have any Wi-Fi credentials

0 commit comments

Comments
 (0)