diff --git a/examples/platform/silabs/wifi/rs911x/rs9117.gni b/examples/platform/silabs/wifi/rs911x/rs9117.gni index 962895194bd034..31e0028461e91d 100644 --- a/examples/platform/silabs/wifi/rs911x/rs9117.gni +++ b/examples/platform/silabs/wifi/rs911x/rs9117.gni @@ -3,12 +3,12 @@ import("//build_overrides/efr32_sdk.gni") import("${efr32_sdk_build_root}/efr32_sdk.gni") rs911x_src_plat = [ + "${examples_plat_dir}/wifi/wfx_rsi_host.cpp", "${examples_plat_dir}/wifi/sl_wifi_if.cpp", - "${examples_plat_dir}/wifi/rs911x/wfx_rsi_host.cpp", "${examples_plat_dir}/wifi/rs911x/hal/rsi_hal_mcu_interrupt.c", "${examples_plat_dir}/wifi/rs911x/hal/sl_si91x_ncp_utility.c", "${examples_plat_dir}/wifi/rs911x/hal/efx32_ncp_host.c", - "${silabs_plat_efr32_wifi_dir}/wfx_notify.cpp", + "${silabs_plat_dir}/wifi/wfx_notify.cpp", ] rs9117_inc_plat = [ diff --git a/examples/platform/silabs/wifi/rs911x/rs911x.gni b/examples/platform/silabs/wifi/rs911x/rs911x.gni index 7bb76813eeda83..cd4ea3045bc59f 100644 --- a/examples/platform/silabs/wifi/rs911x/rs911x.gni +++ b/examples/platform/silabs/wifi/rs911x/rs911x.gni @@ -3,13 +3,13 @@ import("//build_overrides/efr32_sdk.gni") import("${efr32_sdk_build_root}/efr32_sdk.gni") rs911x_src_plat = [ + "${examples_plat_dir}/wifi/wfx_rsi_host.cpp", "${examples_plat_dir}/wifi/rs911x/rsi_if.c", - "${examples_plat_dir}/wifi/rs911x/wfx_rsi_host.cpp", "${examples_plat_dir}/wifi/rs911x/hal/rsi_hal_mcu_interrupt.c", "${examples_plat_dir}/wifi/rs911x/hal/rsi_hal_mcu_ioports.c", "${examples_plat_dir}/wifi/rs911x/hal/rsi_hal_mcu_timer.c", "${examples_plat_dir}/wifi/rs911x/hal/efx_spi.c", - "${silabs_plat_efr32_wifi_dir}/wfx_notify.cpp", + "${silabs_plat_dir}/wifi/wfx_notify.cpp", ] # diff --git a/examples/platform/silabs/wifi/rs911x/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/rs911x/wfx_rsi_host.cpp deleted file mode 100644 index 8764c0a9dda8bb..00000000000000 --- a/examples/platform/silabs/wifi/rs911x/wfx_rsi_host.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "em_bus.h" -#include "em_cmu.h" -#include "em_gpio.h" -#include "em_ldma.h" -#include "em_usart.h" -#include "sl_status.h" - -#include "silabs_utils.h" - -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" - -/* wfxRsi Task will use as its stack */ -StackType_t wfxRsiTaskStack[WFX_RSI_TASK_SZ] = { 0 }; - -/* Structure that will hold the TCB of the wfxRsi Task being created. */ -StaticTask_t wfxRsiTaskBuffer; - -/********************************************************************* - * @fn sl_status_t wfx_wifi_start(void) - * @brief - * Called from ConnectivityManagerImpl.cpp - to enable the device - * Create the RSI task and let it deal with life. - * @param[in] None - * @return Returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ***********************************************************************/ -sl_status_t wfx_wifi_start(void) -{ - if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED) - { - return SL_STATUS_OK; - } - wfx_rsi.dev_state |= WFX_RSI_ST_STARTED; - /* - * Create the Wifi driver task - */ - wfx_rsi.wlan_task = xTaskCreateStatic(wfx_rsi_task, "wfx_rsi", WFX_RSI_TASK_SZ, NULL, WLAN_DRIVER_TASK_PRIORITY, - wfxRsiTaskStack, &wfxRsiTaskBuffer); - - if (NULL == wfx_rsi.wlan_task) - { - return SL_STATUS_FAIL; - } - return SL_STATUS_OK; -} - -/********************************************************************* - * @fn void wfx_enable_sta_mode(void) - * @brief - * driver enable the STA mode - * @param[in] None - * @return None - ***********************************************************************/ -void wfx_enable_sta_mode(void) -{ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_MODE; -} - -/********************************************************************* - * @fn bool wfx_is_sta_mode_enabled(void) - * @brief - * driver enabled the STA mode - * @param[in] None - * @return mode - ***********************************************************************/ -bool wfx_is_sta_mode_enabled(void) -{ - bool mode; - mode = !!(wfx_rsi.dev_state & WFX_RSI_ST_STA_MODE); - return mode; -} - -/********************************************************************* - * @fn wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) - * @brief - * get the wifi mac address - * @param[in] Interface: - * @param[in] addr : address - * @return - * None - ***********************************************************************/ -void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) -{ - sl_wfx_mac_address_t * mac; - -#ifdef SL_WFX_CONFIG_SOFTAP - mac = (interface == SL_WFX_SOFTAP_INTERFACE) ? &wfx_rsi.softap_mac : &wfx_rsi.sta_mac; -#else - mac = &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]); -} - -/********************************************************************* - * @fn void wfx_set_wifi_provision(wfx_wifi_provision_t *cfg) - * @brief - * Driver set the wifi provision - * @param[in] cfg: wifi configuration - * @return - * None - ***********************************************************************/ -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; -} - -/********************************************************************* - * @fn bool wfx_get_wifi_provision(wfx_wifi_provision_t *wifiConfig) - * @brief - * Driver get the wifi provision - * @param[in] wifiConfig: wifi configuration - * @return return false if successful, - * true otherwise - ***********************************************************************/ -bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) -{ - if (wifiConfig != NULL) - { - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) - { - *wifiConfig = wfx_rsi.sec; - return true; - } - } - return false; -} - -/********************************************************************* - * @fn void wfx_clear_wifi_provision(void) - * @brief - * Driver is clear the wifi provision - * @param[in] None - * @return None - ***********************************************************************/ -void wfx_clear_wifi_provision(void) -{ - memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec)); - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED; -} - -/************************************************************************* - * @fn sl_status_t wfx_connect_to_ap(void) - * @brief - * Start a JOIN command to the AP - Done by the wfx_rsi task - * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_INVALID_CONFIGURATION otherwise - ****************************************************************************/ -sl_status_t wfx_connect_to_ap(void) -{ - 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]); - xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN); - } - else - { - SILABS_LOG("%s: error: access point not provisioned", __func__); - return SL_STATUS_INVALID_CONFIGURATION; - } - return SL_STATUS_OK; -} - -#if SL_ICD_ENABLED -#if SLI_SI917 -/********************************************************************* - * @fn sl_status_t wfx_power_save() - * @brief - * Implements the power save in sleepy application - * @param[in] sl_si91x_ble_state : State to set for the BLE - sl_si91x_wifi_state : State to set for the WiFi - * @return SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ***********************************************************************/ -sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) -{ - return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK); -} -#else // For RS9116 -/********************************************************************* - * @fn sl_status_t wfx_power_save() - * @brief - * Implements the power save in sleepy application - * @param[in] None - * @return SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ***********************************************************************/ -sl_status_t wfx_power_save() -{ - return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK); -} -#endif /* SLI_SI917 */ -#endif /* SL_ICD_ENABLED */ - -/********************************************************************* - * @fn void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) - * @brief - * Implement the ipv6 setup - * @param[in] whichif: - * @return None - ***********************************************************************/ -void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) -{ - /* - * TODO: Implement IPV6 setup, currently in wfx_rsi_task() - * This is hooked with MATTER code. - */ -} - -/********************************************************************* - * @fn bool wfx_is_sta_connected(void) - * @brief - * called fuction when driver is connected to STA - * @param[in] None - * @return returns ture if successful, - * false otherwise - ***********************************************************************/ -bool wfx_is_sta_connected(void) -{ - bool status; - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false; - return status; -} - -/********************************************************************* - * @fn wifi_mode_t wfx_get_wifi_mode() - * @brief - * get the wifi mode - * @param[in] None - * @return return WIFI_MODE_NULL if successful, - * WIFI_MODE_STA otherwise - ***********************************************************************/ -wifi_mode_t wfx_get_wifi_mode() -{ - if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) - return WIFI_MODE_STA; - return WIFI_MODE_NULL; -} - -/********************************************************************* - * @fn sl_status_t wfx_sta_discon(void) - * @brief - * called fuction when STA disconnected - * @param[in] None - * @return return SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ***********************************************************************/ -sl_status_t wfx_sta_discon(void) -{ - int32_t status; - status = wfx_rsi_disconnect(); - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED; - return status; -} -#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 -/********************************************************************* - * @fn bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) - * @brief - * called fuction when driver have ipv4 address - * @param[in] which_if: - * @return returns ture if successful, - * false otherwise - ***********************************************************************/ -bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) -{ - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) ? true : false; - } - else - { - status = false; /* TODO */ - } - return status; -} -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - -/********************************************************************* - * @fn bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) - * @brief - * called fuction when driver have ipv6 address - * @param[in] which_if: - * @return returns ture if successful, - * false otherwise - ***********************************************************************/ -bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) -{ - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false; - } - else - { - status = false; /* TODO */ - } - return status; -} - -/********************************************************************* - * @fn bool wfx_hw_ready(void) - * @brief - * called fuction when driver ready - * @param[in] None - * @return returns ture if successful, - * false otherwise - ***********************************************************************/ -bool wfx_hw_ready(void) -{ - return (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) ? true : false; -} - -/********************************************************************* - * @fn int32_t wfx_get_ap_info(wfx_wifi_scan_result_t *ap) - * @brief - * get the access point information - * @param[in] ap: access point - * @return - * access point information - ***********************************************************************/ -int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) -{ - return wfx_rsi_get_ap_info(ap); -} - -/********************************************************************* - * @fn int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t *extra_info) - * @brief - * get the access point extra information - * @param[in] extra_info:access point extra information - * @return - * access point extra information - ***********************************************************************/ -int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) -{ - return wfx_rsi_get_ap_ext(extra_info); -} - -/*************************************************************************** - * @fn int32_t wfx_reset_counts(){ - * @brief - * get the driver reset count - * @param[in] None - * @return - * reset count - *****************************************************************************/ -int32_t wfx_reset_counts() -{ - return wfx_rsi_reset_count(); -} - -#ifdef SL_WFX_CONFIG_SCAN -/******************************************************************************* - * @fn bool wfx_start_scan(char *ssid, void (*callback)(wfx_wifi_scan_result_t *)) - * @brief - * called fuction when driver start scaning - * @param[in] ssid: - * @return returns ture if successful, - * false otherwise - *******************************************************************************/ -bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) -{ - int sz; - - if (wfx_rsi.scan_cb) - return false; /* Already in progress */ - if (ssid) - { - sz = strlen(ssid); - if ((wfx_rsi.scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0) - { - return false; - } - strcpy(wfx_rsi.scan_ssid, ssid); - } - wfx_rsi.scan_cb = callback; - xEventGroupSetBits(wfx_rsi.events, WFX_EVT_SCAN); - - return true; -} - -/*************************************************************************** - * @fn void wfx_cancel_scan(void) - * @brief - * called function when driver cancel scaning - * @param[in] None - * @return - * None - *****************************************************************************/ -void wfx_cancel_scan(void) -{ - /* Not possible */ -} -#endif /* SL_WFX_CONFIG_SCAN */ diff --git a/examples/platform/silabs/wifi/siwx917/BUILD.gn b/examples/platform/silabs/wifi/siwx917/BUILD.gn index bcc6435463f956..09d218ec29f02f 100644 --- a/examples/platform/silabs/wifi/siwx917/BUILD.gn +++ b/examples/platform/silabs/wifi/siwx917/BUILD.gn @@ -208,6 +208,7 @@ source_set("siwx917-common") { sources = [ "${examples_plat_dir}/wifi/sl_wifi_if.cpp", + "${examples_plat_dir}/wifi/wfx_rsi_host.cpp", "${silabs_common_plat_dir}/BaseApplication.cpp", "${silabs_common_plat_dir}/LEDWidget.cpp", "${silabs_common_plat_dir}/MatterConfig.cpp", @@ -215,11 +216,10 @@ source_set("siwx917-common") { "${silabs_common_plat_dir}/heap_4_silabs.c", "${silabs_common_plat_dir}/silabs_utils.cpp", "${silabs_common_plat_dir}/syscalls_stubs.cpp", + "${silabs_plat_dir}/wifi/wfx_notify.cpp", "${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp", "${silabs_plat_si91x_wifi_dir}/ethernetif.cpp", "${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp", - "${silabs_plat_si91x_wifi_dir}/wfx_notify.cpp", - "wfx_rsi_host.cpp", ] if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) { diff --git a/examples/platform/silabs/wifi/sl_wifi_if.cpp b/examples/platform/silabs/wifi/sl_wifi_if.cpp index 1f1f7ac587c880..559b2754ebcdc2 100644 --- a/examples/platform/silabs/wifi/sl_wifi_if.cpp +++ b/examples/platform/silabs/wifi/sl_wifi_if.cpp @@ -70,8 +70,6 @@ extern "C" { #define TRNGKEY_SIZE 4 } // extern "C" -WfxRsi_t wfx_rsi; - /* Declare a variable to hold the data associated with the created event group. */ StaticEventGroup_t rsiDriverEventGroup; @@ -157,6 +155,7 @@ static void StartDHCPTimer(uint32_t timeout) *********************************************************************/ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); sl_status_t status = SL_STATUS_OK; int32_t rssi = 0; ap->security = wfx_rsi.sec.security; @@ -230,6 +229,7 @@ int32_t wfx_rsi_disconnect() sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t result_length, void * arg) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); WfxEvent_t WfxEvent; wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING); @@ -280,6 +280,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t *********************************************************************/ void sl_wfx_host_si91x_sleep_wakeup() { + if (wfx_rsi.dev_state & WFX_RSI_ST_SLEEP_READY) { // TODO: should be removed once we are getting the press interrupt for button 0 with sleep @@ -317,6 +318,7 @@ void sl_wfx_host_si91x_sleep_wakeup() *********************************************************************/ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); int32_t status; status = rsi_bt_power_save_profile(sl_si91x_ble_state, 0); @@ -411,6 +413,7 @@ static void sl_print_firmware_version(sl_wifi_firmware_version_t * firmware_vers *****************************************************************************************/ static sl_status_t wfx_rsi_init(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); sl_status_t status; #ifndef SLI_SI91X_MCU_INTERFACE @@ -488,6 +491,7 @@ void wfx_show_err(char * msg) sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_result, uint32_t result_length, void * arg) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) { callback_status = *(sl_status_t *) scan_result; @@ -541,6 +545,7 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * } sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); SL_WIFI_ARGS_CHECK_NULL_POINTER(scan_result); int x; wfx_wifi_scan_result_t ap; @@ -594,6 +599,7 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ *******************************************************************************************/ static void wfx_rsi_save_ap_info() // translation { + WfxRsi & wfx_rsi = WfxRsi::Instance(); 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 = default_wifi_scan_configuration; @@ -622,6 +628,7 @@ static void wfx_rsi_save_ap_info() // translation **********************************************************************************************/ static sl_status_t wfx_rsi_do_join(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); sl_status_t status = SL_STATUS_OK; sl_wifi_security_t connect_security_mode; WfxEvent_t event; @@ -735,6 +742,7 @@ static sl_status_t wfx_rsi_do_join(void) /// Helper function for HandleDHCPPolling. void NotifyConnectivity() { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (!hasNotifiedWifiConnectivity) { wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); @@ -797,6 +805,7 @@ void WfxPostEvent(WfxEvent_t * event) /// and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. void ResetDHCPNotificationFlags() { + WfxRsi & wfx_rsi = WfxRsi::Instance(); WfxEvent_t outEvent; #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) @@ -811,6 +820,7 @@ void ResetDHCPNotificationFlags() void ProcessEvent(WfxEvent_t inEvent) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); // Process event switch (inEvent.eventType) { @@ -961,6 +971,7 @@ void wfx_rsi_task(void * arg) **********************************************************************************************/ void wfx_dhcp_got_ipv4(uint32_t ip) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); /* * Acquire the new IP address */ @@ -1020,3 +1031,12 @@ int32_t wfx_rsi_send_data(void * p, uint16_t len) } #endif + +namespace { +WfxRsi sInstance; +} + +WfxRsi & WfxRsi::Instance() +{ + return sInstance; +} diff --git a/examples/platform/silabs/wifi/wfx_rsi.h b/examples/platform/silabs/wifi/wfx_rsi.h index 445671f4566b49..e3a24e71b7fa35 100644 --- a/examples/platform/silabs/wifi/wfx_rsi.h +++ b/examples/platform/silabs/wifi/wfx_rsi.h @@ -74,7 +74,7 @@ typedef struct WfxEvent_s /// @param event The event that will be allocated to the event queue void WfxPostEvent(WfxEvent_t * event); -typedef struct wfx_rsi_s +struct WfxRsi { // TODO: Change tp WfxEventType_e once the event queue is implemented EventGroupHandle_t events; @@ -99,9 +99,10 @@ typedef struct wfx_rsi_s sl_wfx_mac_address_t ap_bssid; /* To which our STA is connected */ uint16_t join_retries; uint8_t ip4_addr[4]; /* Not sure if this is enough */ -} WfxRsi_t; -extern WfxRsi_t wfx_rsi; + static WfxRsi & Instance(); +}; + #ifdef __cplusplus extern "C" { diff --git a/examples/platform/silabs/wifi/siwx917/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp similarity index 95% rename from examples/platform/silabs/wifi/siwx917/wfx_rsi_host.cpp rename to examples/platform/silabs/wifi/wfx_rsi_host.cpp index 83c3a95ec0caf7..616a2b9ea5fabb 100644 --- a/examples/platform/silabs/wifi/siwx917/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -45,6 +45,7 @@ StaticTask_t wfxRsiTaskBuffer; ***********************************************************************/ sl_status_t wfx_wifi_start(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED) { SILABS_LOG("%s: already started.", __func__); @@ -75,6 +76,7 @@ sl_status_t wfx_wifi_start(void) ***********************************************************************/ void wfx_enable_sta_mode(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); wfx_rsi.dev_state |= WFX_RSI_ST_STA_MODE; } @@ -87,6 +89,7 @@ void wfx_enable_sta_mode(void) ***********************************************************************/ bool wfx_is_sta_mode_enabled(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); bool mode; mode = !!(wfx_rsi.dev_state & WFX_RSI_ST_STA_MODE); return mode; @@ -103,6 +106,7 @@ bool wfx_is_sta_mode_enabled(void) ***********************************************************************/ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (addr) { #ifdef SL_WFX_CONFIG_SOFTAP @@ -125,6 +129,7 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) { if (cfg) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); wfx_rsi.sec = *cfg; wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; } @@ -142,6 +147,7 @@ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { if (wifiConfig != NULL) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) { *wifiConfig = wfx_rsi.sec; @@ -160,6 +166,7 @@ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) ***********************************************************************/ void wfx_clear_wifi_provision(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec)); wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED; SILABS_LOG("%s: completed.", __func__); @@ -175,6 +182,7 @@ void wfx_clear_wifi_provision(void) ****************************************************************************/ sl_status_t wfx_connect_to_ap(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); WfxEvent_t event; if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) { @@ -191,6 +199,7 @@ sl_status_t wfx_connect_to_ap(void) } #if SL_ICD_ENABLED +#if SLI_SI917 /********************************************************************* * @fn sl_status_t wfx_power_save() * @brief @@ -208,6 +217,7 @@ sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ } return SL_STATUS_OK; } +#endif /* SLI_SI917 */ #endif /* SL_ICD_ENABLED */ /********************************************************************* @@ -236,6 +246,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) ***********************************************************************/ bool wfx_is_sta_connected(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; SILABS_LOG("%s: %s", __func__, (status ? "Connected" : "Disconnected")); return status; @@ -251,6 +262,7 @@ bool wfx_is_sta_connected(void) ***********************************************************************/ wifi_mode_t wfx_get_wifi_mode() { + WfxRsi & wfx_rsi = WfxRsi::Instance(); if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) return WIFI_MODE_STA; return WIFI_MODE_NULL; @@ -266,6 +278,7 @@ wifi_mode_t wfx_get_wifi_mode() ***********************************************************************/ sl_status_t wfx_sta_discon(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); SILABS_LOG("%s: started.", __func__); int32_t status; status = wfx_rsi_disconnect(); @@ -284,6 +297,7 @@ sl_status_t wfx_sta_discon(void) ***********************************************************************/ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); bool status = false; if (which_if == SL_WFX_STA_INTERFACE) { @@ -308,6 +322,7 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) ***********************************************************************/ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); bool status = false; if (which_if == SL_WFX_STA_INTERFACE) { @@ -331,6 +346,7 @@ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) ***********************************************************************/ bool wfx_hw_ready(void) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); return (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) ? true : false; } @@ -384,6 +400,7 @@ int32_t wfx_reset_counts() *******************************************************************************/ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); int sz; WfxEvent_t event; if (wfx_rsi.scan_cb) diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index c0efdd6eab6a97..724944066d90db 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -61,7 +61,7 @@ static_library("SiWx917") { "../../SingletonConfigurationManager.cpp", "../rs911x/BLEManagerImpl.cpp", "../rs911x/rsi_ble_config.h", - "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.cpp", "../rs911x/wfx_sl_ble_init.h", "PlatformManagerImpl.cpp", ] diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 25b8e9f4690555..fc2b4b62d96872 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -71,7 +71,7 @@ static_library("efr32") { sources += [ "../rs911x/BLEManagerImpl.cpp", "../rs911x/rsi_ble_config.h", - "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.cpp", "../rs911x/wfx_sl_ble_init.h", ] } else { diff --git a/src/platform/silabs/efr32/wifi/wfx_notify.cpp b/src/platform/silabs/efr32/wifi/wfx_notify.cpp index f888a1a4c5c0ab..3da3c894b85854 100644 --- a/src/platform/silabs/efr32/wifi/wfx_notify.cpp +++ b/src/platform/silabs/efr32/wifi/wfx_notify.cpp @@ -88,6 +88,7 @@ void wfx_started_notify() *************************************************************************************/ void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); sl_wfx_connect_ind_t evt; SILABS_LOG("%s: started.", __func__); diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 7c6f5a58ffe717..8a953027845b51 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -32,24 +32,20 @@ #include "rail.h" #endif #include -#ifdef __cplusplus +#include "wfx_sl_ble_init.h" extern "C" { -#endif #include "FreeRTOS.h" #include "event_groups.h" #include "task.h" #include "timers.h" #include "wfx_host_events.h" #include "wfx_rsi.h" -#include "wfx_sl_ble_init.h" #if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include #endif #include #include -#ifdef __cplusplus } -#endif #include #include @@ -264,6 +260,7 @@ BLEManagerImpl BLEManagerImpl::sInstance; CHIP_ERROR BLEManagerImpl::_Init() { + WfxRsi & wfx_rsi = WfxRsi::Instance(); CHIP_ERROR err; sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.c b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp similarity index 91% rename from src/platform/silabs/rs911x/wfx_sl_ble_init.c rename to src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 7e7c165043a71a..392acb51b52502 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.c +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -21,9 +21,11 @@ * limitations under the License. */ #include "wfx_sl_ble_init.h" -#include "ble_config.h" #include "cmsis_os2.h" #include "silabs_utils.h" +extern "C" { +#include "ble_config.h" +} // Global Variables rsi_ble_t att_list; sl_wfx_msg_t event_msg; @@ -374,10 +376,12 @@ uint32_t rsi_ble_add_matter_service(void) static const uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } }; + .val = { .val128 = { + RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1, + RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2, + RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3, + RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4, + } } }; rsi_ble_resp_add_serv_t new_serv_resp = { 0 }; rsi_ble_add_service(custom_service, &new_serv_resp); @@ -396,10 +400,12 @@ uint32_t rsi_ble_add_matter_service(void) static const uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } }; + .val= { .val128 = { + RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1, + RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2, + RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3, + RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4, + } } }; // Adding custom characteristic declaration to the custom service rsi_ble_add_char_serv_att( diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index e3d11e0057a98f..0da67eee9c5c37 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -30,12 +30,15 @@ // BLE include file to refer BLE APIs #include "FreeRTOS.h" -#include "ble_config.h" #include "event_groups.h" #include "task.h" #include "timers.h" #include "wfx_host_events.h" #include "wfx_rsi.h" +#include +#include +extern "C" { +#include "ble_config.h" #include #include #include @@ -49,8 +52,7 @@ #include #include #include -#include -#include +} typedef struct sl_wfx_msg_s { diff --git a/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp b/src/platform/silabs/wifi/wfx_notify.cpp similarity index 99% rename from src/platform/silabs/SiWx917/wifi/wfx_notify.cpp rename to src/platform/silabs/wifi/wfx_notify.cpp index ac5e8c304f5dcf..da4e3b653a41f2 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp +++ b/src/platform/silabs/wifi/wfx_notify.cpp @@ -92,6 +92,7 @@ void wfx_started_notify() *************************************************************************************/ void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap) { + WfxRsi & wfx_rsi = WfxRsi::Instance(); sl_wfx_connect_ind_t evt; SILABS_LOG("%s: started.", __func__);