Skip to content

Commit 26a867c

Browse files
[Silabs] Clean up WifiInterface public APIs (project-chip#37035)
* Refactor wifi task start API * Clean up function signatures * Fix incorrect macro * Add wifi suffix to output directory * fix function signature * Improve output build directory * restyle * remove hardcode string * clean up string * Restyled by whitespace --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b5313a7 commit 26a867c

8 files changed

+147
-161
lines changed

scripts/examples/gn_silabs_example.sh

+14-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ DOTFILE=".gn"
4949
SILABS_THREAD_TARGET=\""../silabs:ot-efr32-cert"\"
5050
USAGE="./scripts/examples/gn_silabs_example.sh <AppRootFolder> <outputFolder> <silabs_board_name> [<Build options>]"
5151

52+
PROTOCOL_DIR_SUFFIX="thread"
53+
NCP_DIR_SUFFIX=""
54+
5255
if [ "$#" == "0" ]; then
5356
echo "Build script for EFR32 Matter apps
5457
Format:
@@ -188,6 +191,7 @@ else
188191
echo "--wifi requires rs9116 or SiWx917 or wf200"
189192
exit 1
190193
fi
194+
191195
if [ "$2" = "rs9116" ]; then
192196
optArgs+="use_rs9116=true "
193197
elif [ "$2" = "SiWx917" ]; then
@@ -198,6 +202,8 @@ else
198202
echo "Wifi usage: --wifi rs9116|SiWx917|wf200"
199203
exit 1
200204
fi
205+
206+
NCP_DIR_SUFFIX="/"$2
201207
USE_WIFI=true
202208
optArgs+="chip_device_platform =\"efr32\" chip_crypto_keystore=\"psa\""
203209
shift
@@ -321,20 +327,21 @@ else
321327
source "$CHIP_ROOT/scripts/activate.sh"
322328
fi
323329

330+
if [ "$USE_WIFI" == true ]; then
331+
DOTFILE="$ROOT/build_for_wifi_gnfile.gn"
332+
PROTOCOL_DIR_SUFFIX="wifi"
333+
else
334+
DOTFILE="$ROOT/openthread.gn"
335+
fi
336+
324337
PYTHON_PATH="$(which python3)"
325-
BUILD_DIR=$OUTDIR/$SILABS_BOARD
338+
BUILD_DIR=$OUTDIR/$PROTOCOL_DIR_SUFFIX/$SILABS_BOARD$NCP_DIR_SUFFIX
326339
echo BUILD_DIR="$BUILD_DIR"
327340

328341
if [ "$DIR_CLEAN" == true ]; then
329342
rm -rf "$BUILD_DIR"
330343
fi
331344

332-
if [ "$USE_WIFI" == true ]; then
333-
DOTFILE="$ROOT/build_for_wifi_gnfile.gn"
334-
else
335-
DOTFILE="$ROOT/openthread.gn"
336-
fi
337-
338345
if [ "$USE_DOCKER" == true ] && [ "$USE_WIFI" == false ]; then
339346
echo "Switching OpenThread ROOT"
340347
optArgs+="openthread_root=\"$GSDK_ROOT/util/third_party/openthread\" "

src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp

+22-20
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
6565
// TODO Initialize the Chip Addressing and Routing Module.
6666

6767
// Ensure that station mode is enabled.
68-
wfx_enable_sta_mode();
68+
ConfigureStationMode();
6969

7070
err = DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL);
7171

@@ -153,7 +153,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void)
153153

154154
bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void)
155155
{
156-
return wfx_is_sta_mode_enabled();
156+
return IsStationModeEnabled();
157157
}
158158

159159
CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val)
@@ -218,26 +218,23 @@ CHIP_ERROR ConnectivityManagerImpl::_SetPollingInterval(System::Clock::Milliseco
218218

219219
void ConnectivityManagerImpl::DriveStationState()
220220
{
221-
sl_status_t serr;
222-
bool stationConnected;
221+
bool stationConnected = false;
223222

224223
// Refresh the current station mode.
225224
GetWiFiStationMode();
226225

227226
// If the station interface is NOT under application control...
228227
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
229228
{
230-
// Ensure that the WFX is started.
231-
if ((serr = wfx_wifi_start()) != SL_STATUS_OK)
232-
{
233-
ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %lx", serr);
234-
return;
235-
}
236-
// Ensure that station mode is enabled in the WFX WiFi layer.
237-
wfx_enable_sta_mode();
229+
// Ensure that the Wifi task is started.
230+
CHIP_ERROR error = StartWifiTask();
231+
VerifyOrReturn(error == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "StartWifiTask() failed: %s", ErrorStr(error)));
232+
233+
// Ensure that station mode is enabled in the WiFi layer.
234+
ConfigureStationMode();
238235
}
239236

240-
stationConnected = wfx_is_sta_connected();
237+
stationConnected = IsStationConnected();
241238

242239
// If the station interface is currently connected ...
243240
if (stationConnected)
@@ -262,12 +259,14 @@ void ConnectivityManagerImpl::DriveStationState()
262259
(mWiFiStationMode != kWiFiStationMode_Enabled && !IsWiFiStationProvisioned()))
263260
{
264261
ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface");
265-
serr = sl_matter_wifi_disconnect();
266-
if (serr != SL_STATUS_OK)
262+
sl_status_t status = sl_matter_wifi_disconnect();
263+
if (status != SL_STATUS_OK)
267264
{
268-
ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %lx", serr);
265+
ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %lx", status);
266+
267+
// TODO: Clean the function up to remove the usage of goto
268+
goto exit;
269269
}
270-
SuccessOrExit(serr);
271270

272271
ChangeWiFiStationState(kWiFiStationState_Disconnecting);
273272
}
@@ -310,11 +309,14 @@ void ConnectivityManagerImpl::DriveStationState()
310309
if (mWiFiStationState != kWiFiStationState_Connecting)
311310
{
312311
ChipLogProgress(DeviceLayer, "Attempting to connect WiFi");
313-
if ((serr = wfx_connect_to_ap()) != SL_STATUS_OK)
312+
313+
sl_status_t status = wfx_connect_to_ap();
314+
if (status != SL_STATUS_OK)
314315
{
315-
ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed: %" PRId32, serr);
316+
ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed: %" PRId32, status);
317+
// TODO: Clean the function up to remove the usage of goto
318+
goto exit;
316319
}
317-
SuccessOrExit(serr);
318320

319321
ChangeWiFiStationState(kWiFiStationState_Connecting);
320322
}

src/platform/silabs/NetworkCommissioningWiFiDriver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void SlWiFiDriver::UpdateNetworkingStatus()
186186
}
187187

188188
ByteSpan networkId = ByteSpan((const unsigned char *) mStagingNetwork.ssid, mStagingNetwork.ssidLen);
189-
if (!wfx_is_sta_connected())
189+
if (!IsStationConnected())
190190
{
191191
// TODO: https://github.com/project-chip/connectedhomeip/issues/26861
192192
mpStatusChangeCallback->OnNetworkingStatusChange(Status::kUnknownError, MakeOptional(networkId),
@@ -336,7 +336,7 @@ CHIP_ERROR GetConnectedNetwork(Network & network)
336336
network.connected = false;
337337
// we are able to fetch the wifi provision data and STA should be connected
338338
VerifyOrReturnError(wfx_get_wifi_provision(&wifiConfig), CHIP_ERROR_UNINITIALIZED);
339-
VerifyOrReturnError(wfx_is_sta_connected(), CHIP_ERROR_NOT_CONNECTED);
339+
VerifyOrReturnError(IsStationConnected(), CHIP_ERROR_NOT_CONNECTED);
340340
network.connected = true;
341341
uint8_t length = strnlen(wifiConfig.ssid, DeviceLayer::Internal::kMaxWiFiSSIDLength);
342342
VerifyOrReturnError(length < sizeof(network.networkID), CHIP_ERROR_BUFFER_TOO_SMALL);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ void ProcessEvent(WifiPlatformEvent event)
822822
/*********************************************************************************
823823
* @fn void sl_matter_wifi_task(void *arg)
824824
* @brief
825-
* The main WLAN task - started by wfx_wifi_start() that interfaces with RSI.
825+
* The main WLAN task - started by StartWifiTask() that interfaces with RSI.
826826
* The rest of RSI stuff come in call-backs.
827827
* The initialization has been already done.
828828
* @param[in] arg:

src/platform/silabs/wifi/WifiInterface.h

+31-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ enum class WifiState : uint16_t
8484
kStationMode = (1 << 7), /* Enable Station Mode */
8585
kAPMode = (1 << 8), /* Enable AP Mode */
8686
kStationReady = (kStationConnected | kStationDhcpDone),
87-
kStationStarted = (1 << 9), /* RSI task started */
87+
kStationStarted = (1 << 9),
8888
kScanStarted = (1 << 10), /* Scan Started */
8989
};
9090

@@ -249,20 +249,46 @@ CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, chip::MutableByteSpan & a
249249
*/
250250
CHIP_ERROR StartNetworkScan(chip::ByteSpan ssid, ScanCallback callback);
251251

252+
/**
253+
* @brief Creates and starts the WiFi task that processes Wifi events and operations
254+
*
255+
* @return CHIP_ERROR CHIP_NO_ERROR if the task was successfully started and initialized
256+
* CHIP_ERROR_NO_MEMORY if the task failed to be created
257+
* CHIP_ERROR_INTERNAL if software or hardware initialization failed
258+
*/
259+
CHIP_ERROR StartWifiTask();
260+
261+
/**
262+
* @brief Configures the Wi-Fi devices as a Wi-Fi station
263+
*/
264+
void ConfigureStationMode();
265+
266+
/**
267+
* @brief Returns the state of the Wi-Fi connection
268+
*
269+
* @return true, if the Wi-Fi device is connected to an AP
270+
* false, otherwise
271+
*/
272+
bool IsStationConnected();
273+
274+
/**
275+
* @brief Returns the state of the Wi-Fi Station configuration of the Wi-Fi device
276+
*
277+
* @return true, if the Wi-Fi Station mode is enabled
278+
* false, otherwise
279+
*/
280+
bool IsStationModeEnabled(void);
281+
252282
/* Function to update */
253283

254-
sl_status_t wfx_wifi_start(void);
255-
void wfx_enable_sta_mode(void);
256284
void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig);
257285
bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig);
258-
bool wfx_is_sta_mode_enabled(void);
259286
int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap);
260287
int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info);
261288
int32_t wfx_reset_counts();
262289
void wfx_clear_wifi_provision(void);
263290
sl_status_t wfx_connect_to_ap(void);
264291
void wfx_setup_ip6_link_local(sl_wfx_interface_t);
265-
bool wfx_is_sta_connected(void);
266292
sl_status_t sl_matter_wifi_disconnect(void);
267293

268294
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ void ProcessEvent(WifiPlatformEvent event)
761761
/*********************************************************************************
762762
* @fn void sl_matter_wifi_task(void *arg)
763763
* @brief
764-
* The main WLAN task - started by wfx_wifi_start () that interfaces with RSI.
764+
* The main WLAN task - started by StartWifiTask () that interfaces with RSI.
765765
* The rest of RSI stuff come in call-backs.
766766
* The initialization has been already done.
767767
* @param[in] arg:

0 commit comments

Comments
 (0)