Skip to content

Commit b987282

Browse files
Sync csa branch with main (#886)
2 parents c73fd90 + 07f6f9e commit b987282

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

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);
@@ -662,7 +666,7 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
662666

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

667671
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationReady)
668672
.Clear(WifiInterface::WifiState::kStationConnecting)
@@ -681,15 +685,18 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
681685
// TODO: Currently unimplemented
682686
break;
683687

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

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

767774
wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kStationConnecting).Clear(WifiInterface::WifiState::kStationConnected);
775+
mUseQuickJoin = !(status == SL_STATUS_SI91X_NO_AP_FOUND);
768776
ScheduleConnectionAttempt();
769777

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

804+
mInstance.mUseQuickJoin = !(status == SL_STATUS_SI91X_NO_AP_FOUND);
796805
mInstance.ScheduleConnectionAttempt();
797806
}
798807

@@ -894,7 +903,10 @@ void WifiInterfaceImpl::PostWifiPlatformEvent(WifiPlatformEvent event)
894903

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

900912
#if CHIP_CONFIG_ENABLE_ICD_SERVER
@@ -1067,12 +1079,9 @@ bool WifiInterfaceImpl::IsStationReady()
10671079
return wfx_rsi.dev_state.Has(WifiState::kStationInit);
10681080
}
10691081

1070-
CHIP_ERROR WifiInterfaceImpl::TriggerDisconnection()
1082+
void WifiInterfaceImpl::TriggerDisconnection()
10711083
{
1072-
VerifyOrReturnError(TriggerPlatformWifiDisconnection() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
1073-
wfx_rsi.dev_state.Clear(WifiState::kStationConnected);
1074-
1075-
return CHIP_NO_ERROR;
1084+
PostWifiPlatformEvent(WifiPlatformEvent::kStationDisconnect);
10761085
}
10771086

10781087
void WifiInterfaceImpl::NotifyConnectivity(void)
@@ -1131,25 +1140,22 @@ bool WifiInterfaceImpl::IsWifiProvisioned()
11311140
return wfx_rsi.dev_state.Has(WifiState::kStationProvisioned);
11321141
}
11331142

1134-
void WifiInterfaceImpl::SetWifiCredentials(const WiFiCredentials & credentials)
1143+
CHIP_ERROR WifiInterfaceImpl::SetWifiCredentials(const WiFiCredentials & credentials)
11351144
{
1145+
VerifyOrReturnError(credentials.ssidLen, CHIP_ERROR_INVALID_ARGUMENT);
1146+
VerifyOrReturnError(credentials.ssidLen <= kMaxWiFiSSIDLength, CHIP_ERROR_INVALID_ARGUMENT);
11361147
wfx_rsi.credentials = credentials;
11371148
wfx_rsi.dev_state.Set(WifiState::kStationProvisioned);
1149+
return CHIP_NO_ERROR;
11381150
}
11391151

11401152
CHIP_ERROR WifiInterfaceImpl::ConnectToAccessPoint()
11411153
{
11421154
VerifyOrReturnError(IsWifiProvisioned(), CHIP_ERROR_INCORRECT_STATE);
1143-
VerifyOrReturnError(wfx_rsi.credentials.ssidLen, CHIP_ERROR_INCORRECT_STATE);
1144-
1145-
// TODO: We should move this validation to where we set the credentials. It is too late here.
1146-
VerifyOrReturnError(wfx_rsi.credentials.ssidLen <= kMaxWiFiSSIDLength, CHIP_ERROR_INVALID_ARGUMENT);
11471155

1148-
ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.credentials.ssid);
1149-
1150-
WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin;
1151-
PostWifiPlatformEvent(event);
1156+
ChipLogProgress(DeviceLayer, "%s to access point: %s", mUseQuickJoin ? "quick join" : "connect", wfx_rsi.credentials.ssid);
11521157

1158+
PostWifiPlatformEvent(mUseQuickJoin ? WifiPlatformEvent::kStationStartJoin : WifiPlatformEvent::kStationStartScan);
11531159
return CHIP_NO_ERROR;
11541160
}
11551161

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)