[Silabs] Si917: C files converted to C++. (#32547)
* [Silabs] Si917: C files converted to C++.
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn
index 9214e97..73e70c1 100644
--- a/examples/platform/silabs/SiWx917/BUILD.gn
+++ b/examples/platform/silabs/SiWx917/BUILD.gn
@@ -219,8 +219,8 @@
"${silabs_plat_si91x_wifi_dir}/ethernetif.cpp",
"${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp",
"${silabs_plat_si91x_wifi_dir}/wfx_notify.cpp",
- "SiWx917/sl_wifi_if.c",
- "SiWx917/wfx_rsi_host.c",
+ "SiWx917/sl_wifi_if.cpp",
+ "SiWx917/wfx_rsi_host.cpp",
]
if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) {
diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
similarity index 97%
rename from examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
rename to examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
index 48b8f54..c443bec 100644
--- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
+++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
@@ -25,15 +25,11 @@
#include "FreeRTOS.h"
#include "event_groups.h"
#include "sl_board_configuration.h"
-#include "sl_net.h"
-#include "sl_si91x_host_interface.h"
#include "sl_si91x_types.h"
-#include "sl_wifi_callback_framework.h"
#include "sl_wifi_constants.h"
#include "sl_wifi_types.h"
#include "sl_wlan_config.h"
#include "task.h"
-#include "wfx_host_events.h"
#if (EXP_BOARD)
#include "rsi_bt_common_apis.h"
@@ -53,7 +49,6 @@
#endif // SL_ICD_ENABLED && SLI_SI91X_MCU_INTERFACE
#include "dhcp_client.h"
-#include "sl_wifi.h"
#include "wfx_host_events.h"
#include "wfx_rsi.h"
#define ADV_SCAN_THRESHOLD -40
@@ -65,11 +60,17 @@
// TODO: Confirm that this value works for size and timing
#define WFX_QUEUE_SIZE 10
-
+extern "C" {
+#include "sl_net.h"
+#include "sl_si91x_host_interface.h"
+#include "sl_wifi.h"
+#include "sl_wifi_callback_framework.h"
+#include "wfx_host_events.h"
#if SLI_SI91X_MCU_INTERFACE
#include "sl_si91x_trng.h"
#define TRNGKEY_SIZE 4
#endif // SLI_SI91X_MCU_INTERFACE
+} // extern "C" {
WfxRsi_t wfx_rsi;
@@ -553,7 +554,7 @@
SILABS_LOG("SCAN SSID: %s , ap scan: %s", wfx_rsi.scan_ssid, ap.ssid);
if (strcmp(wfx_rsi.scan_ssid, ap.ssid) == CMP_SUCCESS)
{
- ap.security = scan_result->scan_info[x].security_mode;
+ ap.security = static_cast<wfx_sec_t>(scan_result->scan_info[x].security_mode);
ap.rssi = (-1) * scan_result->scan_info[x].rssi_val;
memcpy(&ap.bssid[0], &scan_result->scan_info[x].bssid[0], BSSID_MAX_STR_LEN);
(*wfx_rsi.scan_cb)(&ap);
@@ -562,7 +563,7 @@
}
else
{
- ap.security = scan_result->scan_info[x].security_mode;
+ ap.security = static_cast<wfx_sec_t>(scan_result->scan_info[x].security_mode);
ap.rssi = (-1) * scan_result->scan_info[x].rssi_val;
memcpy(&ap.bssid[0], &scan_result->scan_info[x].bssid[0], BSSID_MAX_STR_LEN);
(*wfx_rsi.scan_cb)(&ap);
@@ -597,8 +598,7 @@
{
sl_status_t status = SL_STATUS_OK;
#ifndef EXP_BOARD // TODO: this changes will be reverted back after the SDK team fix the scan API
- sl_wifi_scan_configuration_t wifi_scan_configuration = { 0 };
- wifi_scan_configuration = default_wifi_scan_configuration;
+ sl_wifi_scan_configuration_t wifi_scan_configuration = default_wifi_scan_configuration;
#endif
sl_wifi_ssid_t ssid_arg;
ssid_arg.length = strlen(wfx_rsi.sec.ssid);
@@ -682,10 +682,11 @@
/* Call rsi connect call with given ssid and password
* And check there is a success
*/
- sl_wifi_credential_t cred = { 0 };
- cred.type = SL_WIFI_PSK_CREDENTIAL;
+ sl_wifi_credential_t cred;
+ memset(&cred, 0, sizeof(sl_wifi_credential_t));
+ cred.type = SL_WIFI_PSK_CREDENTIAL;
memcpy(cred.psk.value, &wfx_rsi.sec.passkey[0], strlen(wfx_rsi.sec.passkey));
- sl_wifi_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID;
+ sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID;
status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], strlen(wfx_rsi.sec.passkey));
if (SL_STATUS_OK != status)
{
@@ -851,7 +852,8 @@
if (!(wfx_rsi.dev_state & WFX_RSI_ST_SCANSTARTED))
{
SILABS_LOG("%s: start SSID scan", __func__);
- sl_wifi_scan_configuration_t wifi_scan_configuration = { 0 };
+ sl_wifi_scan_configuration_t wifi_scan_configuration;
+ memset(&wifi_scan_configuration, 0, sizeof(sl_wifi_scan_configuration_t));
// TODO: Add scan logic
sl_wifi_advanced_scan_configuration_t advanced_scan_configuration = { 0 };
diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp
similarity index 92%
rename from examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c
rename to examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp
index 1711076..83c3a95 100644
--- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c
+++ b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp
@@ -103,16 +103,14 @@
***********************************************************************/
void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr)
{
- sl_wfx_mac_address_t * mac;
-
+ if (addr)
+ {
#ifdef SL_WFX_CONFIG_SOFTAP
- mac = (interface == SL_WFX_SOFTAP_INTERFACE) ? &wfx_rsi.softap_mac : &wfx_rsi.sta_mac;
+ *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac;
#else
- mac = &wfx_rsi.sta_mac;
+ *addr = wfx_rsi.sta_mac;
#endif
- *addr = *mac;
- SILABS_LOG("%s: %02x:%02x:%02x:%02x:%02x:%02x", __func__, mac->octet[0], mac->octet[1], mac->octet[2], mac->octet[3],
- mac->octet[4], mac->octet[5]);
+ }
}
/*********************************************************************
@@ -125,10 +123,11 @@
***********************************************************************/
void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg)
{
- SILABS_LOG("%s: SSID: %s", __func__, &wfx_rsi.sec.ssid[0]);
-
- wfx_rsi.sec = *cfg;
- wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED;
+ if (cfg)
+ {
+ wfx_rsi.sec = *cfg;
+ wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED;
+ }
}
/*********************************************************************
@@ -179,13 +178,13 @@
WfxEvent_t event;
if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED)
{
- SILABS_LOG("%s: connecting to access point -> SSID: %s", __func__, &wfx_rsi.sec.ssid[0]);
+ SILABS_LOG("Connecting to access point -> SSID: %s", &wfx_rsi.sec.ssid[0]);
event.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&event);
}
else
{
- SILABS_LOG("%s: error: access point not provisioned", __func__);
+ SILABS_LOG("Error: access point not provisioned.");
return SL_STATUS_INVALID_CONFIGURATION;
}
return SL_STATUS_OK;
@@ -237,9 +236,8 @@
***********************************************************************/
bool wfx_is_sta_connected(void)
{
- bool status;
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false;
- SILABS_LOG("%s: status: %s", __func__, (status ? "connected" : "not connected"));
+ bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0;
+ SILABS_LOG("%s: %s", __func__, (status ? "Connected" : "Disconnected"));
return status;
}
@@ -289,7 +287,7 @@
bool status = false;
if (which_if == SL_WFX_STA_INTERFACE)
{
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) ? true : false;
+ status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0;
}
else
{
@@ -313,13 +311,13 @@
bool status = false;
if (which_if == SL_WFX_STA_INTERFACE)
{
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false;
+ status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0;
}
else
{
status = false; /* TODO */
}
- SILABS_LOG("%s: status: %d", __func__, status);
+ SILABS_LOG("%s: %d", __func__, status);
return status;
}
diff --git a/examples/platform/silabs/efr32/rs911x/rs9117.gni b/examples/platform/silabs/efr32/rs911x/rs9117.gni
index 5a561c9..c068e7a 100644
--- a/examples/platform/silabs/efr32/rs911x/rs9117.gni
+++ b/examples/platform/silabs/efr32/rs911x/rs9117.gni
@@ -3,8 +3,8 @@
import("${efr32_sdk_build_root}/efr32_sdk.gni")
rs911x_src_plat = [
- "${examples_plat_dir}/rs911x/sl_wifi_if.c",
- "${examples_plat_dir}/rs911x/wfx_rsi_host.c",
+ "${examples_plat_dir}/rs911x/sl_wifi_if.cpp",
+ "${examples_plat_dir}/rs911x/wfx_rsi_host.cpp",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c",
"${examples_plat_dir}/rs911x/hal/sl_si91x_ncp_utility.c",
"${examples_plat_dir}/rs911x/hal/efx32_ncp_host.c",
diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/examples/platform/silabs/efr32/rs911x/rs911x.gni
index 6b52ff1..ebf7c54 100644
--- a/examples/platform/silabs/efr32/rs911x/rs911x.gni
+++ b/examples/platform/silabs/efr32/rs911x/rs911x.gni
@@ -4,7 +4,7 @@
rs911x_src_plat = [
"${examples_plat_dir}/rs911x/rsi_if.c",
- "${examples_plat_dir}/rs911x/wfx_rsi_host.c",
+ "${examples_plat_dir}/rs911x/wfx_rsi_host.cpp",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_ioports.c",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c",
diff --git a/examples/platform/silabs/efr32/rs911x/sl_wifi_if.c b/examples/platform/silabs/efr32/rs911x/sl_wifi_if.c
deleted file mode 120000
index eae406d..0000000
--- a/examples/platform/silabs/efr32/rs911x/sl_wifi_if.c
+++ /dev/null
@@ -1 +0,0 @@
-../../SiWx917/SiWx917/sl_wifi_if.c
\ No newline at end of file
diff --git a/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp b/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp
new file mode 120000
index 0000000..2f233cc
--- /dev/null
+++ b/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp
@@ -0,0 +1 @@
+../../SiWx917/SiWx917/sl_wifi_if.cpp
\ No newline at end of file
diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.cpp
similarity index 100%
rename from examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c
rename to examples/platform/silabs/efr32/rs911x/wfx_rsi_host.cpp