diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 5de80c2d108549..b8a240f5e01a21 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -64,6 +64,7 @@ #include #ifdef SL_WIFI +#include "WifiInterfaceAbstraction.h" #include "wfx_host_events.h" #include #include diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index c7d4487cfc4f5d..2045c83afad0c2 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -42,7 +42,7 @@ #if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 #include "SiWxPlatformInterface.h" -#include "WifiInterfaceAbstraction.h" +#include "WiseconnectInterfaceAbstraction.h" #endif // SLI_SI91X_MCU_INTERFACE #include diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 3409d8e815e6f0..5045989389af0e 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -115,6 +115,7 @@ config("wifi-interface-config") { source_set("wifi-interface") { sources = [ "${silabs_common_plat_dir}/wifi/WifiInterfaceAbstraction.cpp", + "${silabs_common_plat_dir}/wifi/WiseconnectInterfaceAbstraction.cpp", "SiWxWifiInterface.cpp", # Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed diff --git a/examples/platform/silabs/SiWx917/SiWxWifiInterface.cpp b/examples/platform/silabs/SiWx917/SiWxWifiInterface.cpp index 8696d083706638..962d1720b736cf 100644 --- a/examples/platform/silabs/SiWx917/SiWxWifiInterface.cpp +++ b/examples/platform/silabs/SiWx917/SiWxWifiInterface.cpp @@ -29,6 +29,7 @@ #include "FreeRTOS.h" #include "WifiInterfaceAbstraction.h" +#include "WiseconnectInterfaceAbstraction.h" #include "ble_config.h" #include "dhcp_client.h" #include "event_groups.h" @@ -45,7 +46,6 @@ #include extern "C" { -#include "sl_net.h" #include "sl_si91x_driver.h" #include "sl_si91x_host_interface.h" #include "sl_si91x_types.h" @@ -53,7 +53,6 @@ extern "C" { #include "sl_wifi_callback_framework.h" #include "sl_wifi_constants.h" #include "sl_wifi_types.h" -#include "wfx_host_events.h" #if SL_MBEDTLS_USE_TINYCRYPT #include "sl_si91x_constants.h" #include "sl_si91x_trng.h" @@ -440,6 +439,38 @@ sl_status_t JoinWifiNetwork(void) } // namespace +/** + * @brief Wifi initialization called from app main + * + * @return sl_status_t Returns underlying Wi-Fi initialization error + */ +sl_status_t sl_matter_wifi_platform_init(void) +{ + sl_status_t status = SL_STATUS_OK; + + status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr); + VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status)); + + // Create Sempaphore for scan completion + sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr); + VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); + + // Create Semaphore for scan in-progress protection + sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr); + VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); + + // Create the message queue + sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr); + VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED); + + // Create timer for DHCP polling + // TODO: Use LWIP timer instead of creating a new one here + sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr); + VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED); + + return status; +} + /****************************************************************** * @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap) * @brief @@ -614,7 +645,7 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid if (wfx_rsi.scan_ssid != nullptr && (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, std::min(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) == - CMP_SUCCESS)) + 0)) { continue; } @@ -838,38 +869,6 @@ void ProcessEvent(WifiEvent event) } } -/** - * @brief Wifi initialization called from app main - * - * @return sl_status_t Returns underlying Wi-Fi initialization error - */ -sl_status_t sl_matter_wifi_platform_init(void) -{ - sl_status_t status = SL_STATUS_OK; - - status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr); - VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status)); - - // Create Sempaphore for scan completion - sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr); - VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); - - // Create Semaphore for scan in-progress protection - sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr); - VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); - - // Create the message queue - sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr); - VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED); - - // Create timer for DHCP polling - // TODO: Use LWIP timer instead of creating a new one here - sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr); - VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED); - - return status; -} - /********************************************************************************* * @fn void sl_matter_wifi_task(void *arg) * @brief @@ -922,10 +921,10 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) &HEX_VALUE_FF; - wfx_rsi.ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; - wfx_rsi.ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; - wfx_rsi.ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; + wfx_rsi.ip4_addr[0] = (ip) &0xFF; + wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; + wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; + wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; ChipLogDetail(DeviceLayer, "DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2], wfx_rsi.ip4_addr[3]); /* Notify the Connectivity Manager - via the app */ @@ -933,3 +932,21 @@ void wfx_dhcp_got_ipv4(uint32_t ip) wfx_ip_changed_notify(IP_STATUS_SUCCESS); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + +#if SL_ICD_ENABLED +/********************************************************************* + * @fn 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) + * @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) // TODO : Figure out why the extern C is necessary +{ + return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK); +} +#endif diff --git a/examples/platform/silabs/efr32/rs911x/Rsi91xWifiInterface.cpp b/examples/platform/silabs/efr32/rs911x/Rsi91xWifiInterface.cpp index 5c3a7f7240b21d..5513ee37335319 100644 --- a/examples/platform/silabs/efr32/rs911x/Rsi91xWifiInterface.cpp +++ b/examples/platform/silabs/efr32/rs911x/Rsi91xWifiInterface.cpp @@ -50,6 +50,7 @@ extern "C" { #endif #include "WifiInterfaceAbstraction.h" +#include "WiseconnectInterfaceAbstraction.h" #include "dhcp_client.h" #include "ethernetif.h" #include "lwip/nd6.h" @@ -60,8 +61,20 @@ extern "C" { #include #include +using WifiStateFlags = chip::BitFlags; + #define WFX_QUEUE_SIZE 10 #define WFX_RSI_BUF_SZ (1024 * 10) +#define RSI_RESPONSE_MAX_SIZE (28) +#define RSI_RESPONSE_HOLD_BUFF_SIZE (128) +#define RSI_DRIVER_STATUS (0) +#define OPER_MODE_0 (0) +#define COEX_MODE_0 (0) +#define RESP_BUFF_SIZE (6) +#define AP_CHANNEL_NO_0 (0) +#define SCAN_BITMAP_OPTN_1 (1) + +WfxRsi_t wfx_rsi; static osThreadId_t sDrvThread; constexpr uint32_t kDrvTaskSize = 1792; @@ -750,7 +763,7 @@ void ProcessEvent(WifiEvent event) chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); // check if the scanned ssid is the one we are looking for - if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS) + if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != 0) { continue; // we found the targeted ssid. } @@ -861,10 +874,10 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) &HEX_VALUE_FF; - wfx_rsi.ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; - wfx_rsi.ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; - wfx_rsi.ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; + wfx_rsi.ip4_addr[0] = (ip) &0xFF; + wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; + wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; + wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; ChipLogProgress(DeviceLayer, "DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2], wfx_rsi.ip4_addr[3]); /* Notify the Connectivity Manager - via the app */ @@ -960,4 +973,17 @@ int32_t wfx_rsi_send_data(void * p, uint16_t len) return status; } -WfxRsi_t wfx_rsi; +#if SL_ICD_ENABLED +/********************************************************************* + * @fn sl_status_t wfx_power_save(void) + * @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(void) // TODO : Figure out why the extern C is necessary +{ + return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK); +} +#endif /* SL_ICD_ENABLED */ diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 443d7be4ab4a2c..75f1edcd55fd9d 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -43,7 +43,6 @@ #include "silabs_utils.h" #include "spi_multiplex.h" -#include "wfx_host_events.h" #ifdef SL_BOARD_NAME #include "sl_board_control.h" @@ -74,6 +73,9 @@ #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE +#define MIN_XLEN (0) +#define WFX_SPI_NVIC_PRIORITY (5) + #define CONCAT(A, B) (A##B) #define SPI_CLOCK(N) CONCAT(cmuClock_USART, N) // Macro to drive semaphore block minimun timer in milli seconds @@ -110,16 +112,16 @@ void sl_wfx_host_gpio_init(void) CMU_ClockEnable(cmuClock_GPIO, true); // Set CS pin to high/inactive - GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, PINOUT_SET); + GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, 1); - GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, PINOUT_SET); - GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModePushPull, PINOUT_CLEAR); + GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, 1); + GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModePushPull, 0); CMU_OscillatorEnable(cmuOsc_LFXO, true, true); // Set up interrupt based callback function - trigger on both edges. GPIOINT_Init(); - GPIO_PinModeSet(WFX_INTERRUPT_PIN.port, WFX_INTERRUPT_PIN.pin, gpioModeInputPull, PINOUT_CLEAR); + GPIO_PinModeSet(WFX_INTERRUPT_PIN.port, WFX_INTERRUPT_PIN.pin, gpioModeInputPull, 0); GPIO_ExtIntConfig(WFX_INTERRUPT_PIN.port, WFX_INTERRUPT_PIN.pin, SL_WFX_HOST_PINOUT_SPI_IRQ, true, false, true); GPIOINT_CallbackRegister(SL_WFX_HOST_PINOUT_SPI_IRQ, rsi_gpio_irq_cb); GPIO_IntDisable(1 << SL_WFX_HOST_PINOUT_SPI_IRQ); /* Will be enabled by RSI */ @@ -204,7 +206,7 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) if (SL_STATUS_OK == status) { GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; spi_enabled = false; } } @@ -267,7 +269,7 @@ sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void) #endif // SL_SPICTRL_MUX return SL_STATUS_FAIL; } - GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; + GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; #if SL_MX25CTRL_MUX sl_wfx_host_spiflash_cs_deassert(); #endif // SL_MX25CTRL_MUX @@ -300,7 +302,7 @@ sl_status_t sl_wfx_host_post_lcd_spi_transfer(void) { USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); - GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; + GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; sl_status_t status = sl_board_disable_display(); #if SL_SPICTRL_MUX xSemaphoreGive(spi_sem_sync_hdl); diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c index 3c67d3955229c8..8bd277e6242c4d 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c +++ b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c @@ -35,8 +35,6 @@ #include "event_groups.h" #include "task.h" -#include "wfx_host_events.h" - #if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include "sl_board_configuration.h" diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c index df3438b6ed5409..ba517b417bdff7 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c +++ b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c @@ -35,8 +35,6 @@ #include "event_groups.h" #include "task.h" -#include "wfx_host_events.h" - #include "rsi_board_configuration.h" #include "rsi_driver.h" /*===========================================================*/ @@ -63,17 +61,17 @@ void rsi_hal_config_gpio(uint8_t gpio_number, uint8_t mode, uint8_t value) { case RSI_HAL_SLEEP_CONFIRM_PIN: case RSI_HAL_LP_SLEEP_CONFIRM_PIN: - GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, PINOUT_SET); + GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1); break; case RSI_HAL_WAKEUP_INDICATION_PIN: #ifndef LOGGING_STATS - GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, PINOUT_CLEAR); + GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, 0); #else - GPIO_PinModeSet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, PINOUT_CLEAR); + GPIO_PinModeSet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, 0); #endif break; case RSI_HAL_RESET_PIN: - GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, PINOUT_SET); + GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, 1); break; default: break; @@ -95,17 +93,17 @@ void rsi_hal_set_gpio(uint8_t gpio_number) { case RSI_HAL_SLEEP_CONFIRM_PIN: case RSI_HAL_LP_SLEEP_CONFIRM_PIN: - GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, PINOUT_SET); + GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1); break; case RSI_HAL_WAKEUP_INDICATION_PIN: #ifndef LOGGING_STATS - GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeInput, PINOUT_SET); + GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeInput, 1); #else - GPIO_PinModeSet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin, gpioModeInput, PINOUT_SET); + GPIO_PinModeSet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin, gpioModeInput, 1); #endif break; case RSI_HAL_RESET_PIN: - GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModeWiredOrPullDown, PINOUT_SET); + GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModeWiredOrPullDown, 1); break; default: break; diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c index 0f0c39a680bd68..9c1b1377487a75 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c +++ b/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c @@ -34,8 +34,6 @@ extern void SysTick_Handler(void); extern void xPortSysTickHandler(void); #endif /* SysTick */ #endif /* RSI_WITH_OS */ -#include "wfx_host_events.h" - /* RSI Driver include file */ #include "rsi_driver.h" /* RSI WLAN Config include file */ @@ -51,6 +49,8 @@ extern void xPortSysTickHandler(void); #include "rsi_wlan_config.h" #define WFX_RSI_NUM_TIMERS (2) /* Number of RSI timers to alloc */ +#define CONVERT_SEC_TO_MSEC (1000) +#define CONVERT_USEC_TO_MSEC (1 / 1000) #ifndef _use_the_rsi_defined_functions @@ -135,7 +135,7 @@ int32_t rsi_timer_start(uint8_t timer_node, uint8_t mode, uint8_t type, uint32_t return RSI_ERROR_INSUFFICIENT_BUFFER; } - (void) xTimerStart(tp->handle, TIMER_TICKS_TO_WAIT_0); + (void) xTimerStart(tp->handle, pdMS_TO_TICKS(0)); return RSI_ERROR_NONE; } diff --git a/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c b/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c index d6b67440364832..1d1ab1409c4161 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c +++ b/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c @@ -46,7 +46,6 @@ #include "silabs_utils.h" #include "sl_si91x_ncp_utility.h" -#include "wfx_host_events.h" #if SL_MX25CTRL_MUX sl_status_t sl_wfx_host_spiflash_cs_assert(void); @@ -220,7 +219,7 @@ sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void) #endif // SL_SPICTRL_MUX return SL_STATUS_FAIL; } - GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; + GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; #if SL_MX25CTRL_MUX sl_wfx_host_spiflash_cs_deassert(); #endif // SL_MX25CTRL_MUX diff --git a/examples/platform/silabs/efr32/rs911x/rs9117.gni b/examples/platform/silabs/efr32/rs911x/rs9117.gni index 63f027e59f9087..87e3caeeb74ad5 100644 --- a/examples/platform/silabs/efr32/rs911x/rs9117.gni +++ b/examples/platform/silabs/efr32/rs911x/rs9117.gni @@ -22,6 +22,7 @@ rs911x_src_plat = [ "${examples_plat_dir}/rs911x/hal/sl_si91x_ncp_utility.c", "${examples_plat_dir}/rs911x/hal/efx32_ncp_host.c", "${silabs_common_plat_dir}/wifi/WifiInterfaceAbstraction.cpp", + "${silabs_common_plat_dir}/wifi/WiseconnectInterfaceAbstraction.cpp", ] rs9117_inc_plat = [ diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/examples/platform/silabs/efr32/rs911x/rs911x.gni index 4aedb66dca9f0c..068d5abdb349c7 100644 --- a/examples/platform/silabs/efr32/rs911x/rs911x.gni +++ b/examples/platform/silabs/efr32/rs911x/rs911x.gni @@ -23,6 +23,7 @@ rs911x_src_plat = [ "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c", "${examples_plat_dir}/rs911x/hal/efx_spi.c", "${silabs_common_plat_dir}/wifi/WifiInterfaceAbstraction.cpp", + "${silabs_common_plat_dir}/wifi/WiseconnectInterfaceAbstraction.cpp", ] # diff --git a/examples/platform/silabs/efr32/wf200/Wf200WifiInterface.cpp b/examples/platform/silabs/efr32/wf200/Wf200WifiInterface.cpp index e38f4c43a27e67..0aec9baa4dccae 100644 --- a/examples/platform/silabs/efr32/wf200/Wf200WifiInterface.cpp +++ b/examples/platform/silabs/efr32/wf200/Wf200WifiInterface.cpp @@ -15,35 +15,31 @@ * limitations under the License. */ -/* Includes */ - -#include -#include -#include - +#include "AppConfig.h" +#include "FreeRTOS.h" +#include "dhcp_client.h" #include "em_bus.h" #include "em_cmu.h" #include "em_gpio.h" #include "em_ldma.h" #include "em_usart.h" +#include "ethernetif.h" +#include "event_groups.h" #include "gpiointerrupt.h" - -#include "AppConfig.h" #include "sl_wfx_board.h" +#include "sl_wfx_cmd_api.h" +#include "sl_wfx_constants.h" #include "sl_wfx_host.h" #include "sl_wfx_task.h" -#include "wfx_host_events.h" - -#include "FreeRTOS.h" -#include "event_groups.h" #include "task.h" - -#include "dhcp_client.h" -#include "ethernetif.h" +#include "wfx_host_events.h" #include #include #include #include +#include +#include +#include using namespace ::chip; using namespace ::chip::DeviceLayer; @@ -68,9 +64,30 @@ static wfx_wifi_scan_result_t ap_info; #define PASSIVE_CHANNEL_TIME 0 #define NUM_PROBE_REQUEST 2 -// wfx_fmac_driver context -sl_wfx_context_t wifiContext; -static uint8_t wifi_extra; +/* Wi-Fi bitmask events - for the task */ +#define SL_WFX_CONNECT (1 << 1) +#define SL_WFX_DISCONNECT (1 << 2) +#define SL_WFX_START_AP (1 << 3) +#define SL_WFX_STOP_AP (1 << 4) +#define SL_WFX_SCAN_START (1 << 5) +#define SL_WFX_SCAN_COMPLETE (1 << 6) +#define SL_WFX_RETRY_CONNECT (1 << 7) + +#define WLAN_TASK_STACK_SIZE (1024) +#define ETH_FRAME (0) +#define AP_START_SUCCESS (0) +#define BITS_TO_WAIT (0) +#define BEACON_1 (0) +#define CHANNEL_LIST ((const uint8_t *) 0) +#define CHANNEL_COUNT (0) +#define IE_DATA ((const uint8_t *) 0) +#define IE_DATA_LENGTH (0) +#define BSSID_SCAN ((const uint8_t *) 0) +#define CHANNEL_0 (0) +#define PREVENT_ROAMING (1) +#define DISABLE_PMF_MODE (0) +#define STA_IP_FAIL (0) +#define WLAN_TASK_PRIORITY (1) /***************************************************************************** * macros @@ -90,8 +107,6 @@ uint8_t softap_channel = SOFTAP_CHANNEL_DEFAULT; /* station network interface structures */ struct netif * sta_netif; wfx_wifi_provision_t wifi_provision; -sl_wfx_get_counters_cnf_t * counters; -sl_wfx_get_counters_cnf_t * Tempcounters; #define PUT_COUNTER(name) ChipLogDetail(DeviceLayer, "%-24s %lu", #name, (unsigned long) counters->body.count_##name); bool hasNotifiedIPV6 = false; @@ -131,6 +146,162 @@ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac); extern uint32_t gOverrunCount; +namespace { + +// wfx_fmac_driver context +sl_wfx_context_t wifiContext; +uint8_t wifi_extra; + +typedef struct __attribute__((__packed__)) sl_wfx_get_counters_cnf_body_s +{ + uint32_t status; + uint16_t mib_id; + uint16_t length; + uint32_t rcpi; + uint32_t count_plcp_errors; + uint32_t count_fcs_errors; + uint32_t count_tx_packets; + uint32_t count_rx_packets; + uint32_t count_rx_packet_errors; + uint32_t count_rx_decryption_failures; + uint32_t count_rx_mic_failures; + uint32_t count_rx_no_key_failures; + uint32_t count_tx_multicast_frames; + uint32_t count_tx_frames_success; + uint32_t count_tx_frame_failures; + uint32_t count_tx_frames_retried; + uint32_t count_tx_frames_multi_retried; + uint32_t count_rx_frame_duplicates; + uint32_t count_rts_success; + uint32_t count_rts_failures; + uint32_t count_ack_failures; + uint32_t count_rx_multicast_frames; + uint32_t count_rx_frames_success; + uint32_t count_rx_cmacicv_errors; + uint32_t count_rx_cmac_replays; + uint32_t count_rx_mgmt_ccmp_replays; + uint32_t count_rx_bipmic_errors; + uint32_t count_rx_beacon; + uint32_t count_miss_beacon; + uint32_t reserved[15]; +} sl_wfx_get_counters_cnf_body_t; + +typedef struct __attribute__((__packed__)) sl_wfx_get_counters_cnf_s +{ + /** Common message header. */ + sl_wfx_header_t header; + /** Confirmation message body. */ + sl_wfx_get_counters_cnf_body_t body; +} sl_wfx_get_counters_cnf_t; + +typedef struct __attribute__((__packed__)) sl_wfx_mib_req_body_s +{ + uint16_t mib_id; ///< ID of the MIB to be read. + uint16_t reserved; +} sl_wfx_mib_req_body_t; + +typedef struct __attribute__((__packed__)) sl_wfx_header_mib_s +{ + uint16_t length; ///< Message length in bytes including this uint16_t. + ///< Maximum value is 8188 but maximum Request size is FW dependent and reported in the + ///< ::sl_wfx_startup_ind_body_t::size_inp_ch_buf. + uint8_t id; ///< Contains the message Id indexed by sl_wfx_general_commands_ids_t or sl_wfx_message_ids_t. + uint8_t reserved : 1; + uint8_t interface : 2; + uint8_t seqnum : 3; + uint8_t encrypted : 2; +} sl_wfx_header_mib_t; + +typedef struct __attribute__((__packed__)) sl_wfx_mib_req_s +{ + /** Common message header. */ + sl_wfx_header_mib_t header; + /** Request message body. */ + sl_wfx_mib_req_body_t body; +} sl_wfx_mib_req_t; + +sl_wfx_get_counters_cnf_t * counters; + +/**************************************************************************** + * @brief + * get the wifi state + * @return returns wificonetext state + *****************************************************************************/ +sl_wfx_state_t wfx_get_wifi_state(void) +{ + return wifiContext.state; +} + +sl_status_t get_all_counters(void) +{ + sl_status_t result; + uint8_t command_id = 0x05; + uint16_t mib_id = 0x2035; + sl_wfx_mib_req_t * request = nullptr; + uint32_t request_length = SL_WFX_ROUND_UP_EVEN(sizeof(sl_wfx_header_mib_t) + sizeof(sl_wfx_mib_req_body_t)); + + result = + sl_wfx_allocate_command_buffer((sl_wfx_generic_message_t **) &request, command_id, SL_WFX_CONTROL_BUFFER, request_length); + + VerifyOrReturnError(request != nullptr, SL_STATUS_NULL_POINTER); + + request->body.mib_id = mib_id; + request->header.interface = 0x2; + request->header.encrypted = 0x0; + + result = sl_wfx_send_request(command_id, (sl_wfx_generic_message_t *) request, request_length); + SL_WFX_ERROR_CHECK(result); + + result = sl_wfx_host_wait_for_confirmation(command_id, SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS, (void **) &counters); + SL_WFX_ERROR_CHECK(result); + + ChipLogDetail(DeviceLayer, "%-24s %12s ", "", "Debug Counters Content"); + ChipLogDetail(DeviceLayer, "%-24s %lu", "rcpi", (unsigned long) counters->body.rcpi); + PUT_COUNTER(plcp_errors); + PUT_COUNTER(fcs_errors); + PUT_COUNTER(tx_packets); + PUT_COUNTER(rx_packets); + PUT_COUNTER(rx_packet_errors); + PUT_COUNTER(rx_decryption_failures); + PUT_COUNTER(rx_mic_failures); + PUT_COUNTER(rx_no_key_failures); + PUT_COUNTER(tx_multicast_frames); + PUT_COUNTER(tx_frames_success); + PUT_COUNTER(tx_frame_failures); + PUT_COUNTER(tx_frames_retried); + PUT_COUNTER(tx_frames_multi_retried); + PUT_COUNTER(rx_frame_duplicates); + PUT_COUNTER(rts_success); + PUT_COUNTER(rts_failures); + PUT_COUNTER(ack_failures); + PUT_COUNTER(rx_multicast_frames); + PUT_COUNTER(rx_frames_success); + PUT_COUNTER(rx_cmacicv_errors); + PUT_COUNTER(rx_cmac_replays); + PUT_COUNTER(rx_mgmt_ccmp_replays); + PUT_COUNTER(rx_bipmic_errors); + PUT_COUNTER(rx_beacon); + PUT_COUNTER(miss_beacon); + +error_handler: + + if (result == SL_STATUS_TIMEOUT) + { + if (sl_wfx_context->used_buffers > 0) + { + sl_wfx_context->used_buffers--; + } + } + if (request != nullptr) + { + sl_wfx_free_command_buffer((sl_wfx_generic_message_t *) request, command_id, SL_WFX_CONTROL_BUFFER); + } + + return result; +} + +} // namespace + /*************************************************************************** * @brief * Creates WFX events processing task. @@ -278,7 +449,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res /* don't save if filter only wants specific ssid */ if (scan_ssid != nullptr) { - if (strcmp(scan_ssid, (char *) &scan_result->ssid_def.ssid[0]) != CMP_SUCCESS) + if (strcmp(scan_ssid, (char *) &scan_result->ssid_def.ssid[0]) != 0) return; } if ((ap = (struct scan_result_holder *) (chip::Platform::MemoryAlloc(sizeof(*ap)))) == (struct scan_result_holder *) 0) @@ -779,74 +950,6 @@ int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) return status; } -sl_status_t get_all_counters(void) -{ - sl_status_t result; - uint8_t command_id = 0x05; - uint16_t mib_id = 0x2035; - sl_wfx_mib_req_t * request = nullptr; - uint32_t request_length = SL_WFX_ROUND_UP_EVEN(sizeof(sl_wfx_header_mib_t) + sizeof(sl_wfx_mib_req_body_t)); - - result = - sl_wfx_allocate_command_buffer((sl_wfx_generic_message_t **) &request, command_id, SL_WFX_CONTROL_BUFFER, request_length); - - VerifyOrReturnError(request != nullptr, SL_STATUS_NULL_POINTER); - - request->body.mib_id = mib_id; - request->header.interface = 0x2; - request->header.encrypted = 0x0; - - result = sl_wfx_send_request(command_id, (sl_wfx_generic_message_t *) request, request_length); - SL_WFX_ERROR_CHECK(result); - - result = sl_wfx_host_wait_for_confirmation(command_id, SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS, (void **) &counters); - SL_WFX_ERROR_CHECK(result); - - ChipLogDetail(DeviceLayer, "%-24s %12s ", "", "Debug Counters Content"); - ChipLogDetail(DeviceLayer, "%-24s %lu", "rcpi", (unsigned long) counters->body.rcpi); - PUT_COUNTER(plcp_errors); - PUT_COUNTER(fcs_errors); - PUT_COUNTER(tx_packets); - PUT_COUNTER(rx_packets); - PUT_COUNTER(rx_packet_errors); - PUT_COUNTER(rx_decryption_failures); - PUT_COUNTER(rx_mic_failures); - PUT_COUNTER(rx_no_key_failures); - PUT_COUNTER(tx_multicast_frames); - PUT_COUNTER(tx_frames_success); - PUT_COUNTER(tx_frame_failures); - PUT_COUNTER(tx_frames_retried); - PUT_COUNTER(tx_frames_multi_retried); - PUT_COUNTER(rx_frame_duplicates); - PUT_COUNTER(rts_success); - PUT_COUNTER(rts_failures); - PUT_COUNTER(ack_failures); - PUT_COUNTER(rx_multicast_frames); - PUT_COUNTER(rx_frames_success); - PUT_COUNTER(rx_cmacicv_errors); - PUT_COUNTER(rx_cmac_replays); - PUT_COUNTER(rx_mgmt_ccmp_replays); - PUT_COUNTER(rx_bipmic_errors); - PUT_COUNTER(rx_beacon); - PUT_COUNTER(miss_beacon); - -error_handler: - - if (result == SL_STATUS_TIMEOUT) - { - if (sl_wfx_context->used_buffers > 0) - { - sl_wfx_context->used_buffers--; - } - } - if (request != nullptr) - { - sl_wfx_free_command_buffer((sl_wfx_generic_message_t *) request, command_id, SL_WFX_CONTROL_BUFFER); - } - - return result; -} - /************************************************************************ * @brief * reset the count @@ -877,16 +980,6 @@ sl_status_t wfx_wifi_start(void) return SL_STATUS_OK; } -/**************************************************************************** - * @brief - * get the wifi state - * @return returns wificonetext state - *****************************************************************************/ -sl_wfx_state_t wfx_get_wifi_state(void) -{ - return wifiContext.state; -} - /**************************************************************************** * @brief * getnetif using interface @@ -909,19 +1002,6 @@ struct netif * wfx_GetNetif(sl_wfx_interface_t interface) return SelectedNetif; } -/**************************************************************************** - * @brief - * get the wifi mac address using interface - * @param[in] interface: - * @return returns wificontext.mac_addr_o if successful, - * wificontext.mac_addr_1 otherwise - *****************************************************************************/ -sl_wfx_mac_address_t wfx_get_wifi_mac_addr(sl_wfx_interface_t interface) -{ - // return Mac address used by WFX SL_WFX_STA_INTERFACE or SL_WFX_SOFTAP_INTERFACE, - return (interface == SL_WFX_STA_INTERFACE) ? wifiContext.mac_addr_0 : wifiContext.mac_addr_1; -} - /**************************************************************************** * @brief * set the wifi provision @@ -960,17 +1040,6 @@ void wfx_clear_wifi_provision(void) memset(&wifi_provision, 0, sizeof(wifi_provision)); } -/**************************************************************************** - * @brief - * driver STA provisioned - * @return returns true if successful, - * false otherwise - *****************************************************************************/ -bool wfx_is_sta_provisioned(void) -{ - return (wifi_provision.ssid[0]) ? true : false; -} - /**************************************************************************** * @fn sl_status_t wfx_connect_to_ap(void) * @brief @@ -1147,10 +1216,10 @@ void wfx_dhcp_got_ipv4(uint32_t ip) */ uint8_t ip4_addr[4]; - ip4_addr[0] = (ip) &HEX_VALUE_FF; - ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; - ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; - ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; + ip4_addr[0] = (ip) &0xFF; + ip4_addr[1] = (ip >> 8) & 0xFF; + ip4_addr[2] = (ip >> 16) & 0xFF; + ip4_addr[3] = (ip >> 24) & 0xFF; ChipLogDetail(DeviceLayer, "DHCP IP=%d.%d.%d.%d", ip4_addr[0], ip4_addr[1], ip4_addr[2], ip4_addr[3]); sta_ip = ip; diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 3ef34c928e0363..b5a31cbaafd22c 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -40,7 +40,6 @@ #include "spidrv.h" #include "spi_multiplex.h" -#include "wfx_host_events.h" #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #include "sl_power_manager.h" diff --git a/examples/platform/silabs/efr32/wf200/wf200_init.c b/examples/platform/silabs/efr32/wf200/wf200_init.c index 3631216e767a0c..40f1aaf08af6bb 100644 --- a/examples/platform/silabs/efr32/wf200/wf200_init.c +++ b/examples/platform/silabs/efr32/wf200/wf200_init.c @@ -40,7 +40,6 @@ #include "AppConfig.h" #include "sl_wfx_host.h" #include "sl_wfx_task.h" -#include "wfx_host_events.h" #include "sl_spidrv_instances.h" #include "spidrv.h" @@ -258,7 +257,7 @@ sl_status_t sl_wfx_host_set_wake_up_pin(uint8_t state) CORE_DECLARE_IRQ_STATE; CORE_ENTER_ATOMIC(); - if (state > PINOUT_CLEAR_STATUS) + if (state > 0) { #ifdef SLEEP_ENABLED #ifdef SL_WFX_USE_SDIO @@ -320,8 +319,7 @@ sl_status_t sl_wfx_host_reset_chip(void) *****************************************************************************/ sl_status_t sl_wfx_host_wait_for_wake_up(void) { - xSemaphoreTake(wfx_wakeup_sem, pdMS_TO_TICKS(TICKS_TO_WAIT_0)); - xSemaphoreTake(wfx_wakeup_sem, pdMS_TO_TICKS(TICKS_TO_WAIT_3)); + xSemaphoreTake(wfx_wakeup_sem, pdMS_TO_TICKS(3)); return SL_STATUS_OK; } @@ -388,7 +386,7 @@ sl_status_t sl_wfx_host_wait_for_confirmation(uint8_t confirmation_id, uint32_t for (uint32_t i = 0; i < timeout; i++) { /* Wait for an event posted by the function sl_wfx_host_post_event() */ - if (xQueueReceive(wfx_event_Q, &posted_event_id, TICKS_TO_WAIT_1) == pdTRUE) + if (xQueueReceive(wfx_event_Q, &posted_event_id, 1) == pdTRUE) { /* Once a message is received, check if it is the expected ID */ if (confirmation_id == posted_event_id) @@ -418,7 +416,7 @@ sl_status_t sl_wfx_host_lock(void) sl_status_t status = SL_STATUS_OK; - if (xSemaphoreTake(wfx_mutex, pdMS_TO_TICKS(TICKS_TO_WAIT_500)) != pdTRUE) + if (xSemaphoreTake(wfx_mutex, pdMS_TO_TICKS(500)) != pdTRUE) { SILABS_LOG("*ERR*Wi-Fi driver mutex timo"); status = SL_STATUS_TIMEOUT; diff --git a/examples/platform/silabs/wifi/WifiInterfaceAbstraction.cpp b/examples/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index 7c1a9d233b0d55..cd041d452ffe64 100644 --- a/examples/platform/silabs/wifi/WifiInterfaceAbstraction.cpp +++ b/examples/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -22,7 +22,6 @@ #include "wfx_host_events.h" #include #include -#include #include #include #include @@ -34,7 +33,7 @@ using namespace chip; using namespace chip::DeviceLayer; -using WifiStateFlags = chip::BitFlags; +#define CONVERT_SEC_TO_MS(TimeInS) (TimeInS * 1000) namespace { @@ -44,22 +43,6 @@ constexpr uint8_t kWlanRetryIntervalInSec = 5; uint8_t retryInterval = kWlanMinRetryIntervalsInSec; osTimerId_t sRetryTimer; -// TODO: Remove this when the full abstraction is implemented -#ifdef RS911X_WIFI -// Thread for the WLAN RSI -osThreadId_t sWlanThread; -constexpr uint32_t kWlanTaskSize = 2048; -uint8_t wlanStack[kWlanTaskSize]; -osThread_t sWlanTaskControlBlock; -constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", - .attr_bits = osThreadDetached, - .cb_mem = &sWlanTaskControlBlock, - .cb_size = osThreadCbSize, - .stack_mem = wlanStack, - .stack_size = kWlanTaskSize, - .priority = osPriorityAboveNormal7 }; -#endif // RS911X_WIFI - /* * Notifications to the upper-layer * All done in the context of the RSI/WiFi task (rsi_if.c) @@ -77,354 +60,6 @@ void RetryConnectionTimerHandler(void * arg) } // namespace -// TODO: Remove this when the full abstraction is implemented -#ifdef RS911X_WIFI -/********************************************************************* - * @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) -{ - VerifyOrReturnError(!(wfx_rsi.dev_state.Has(WifiState::kStationStarted)), SL_STATUS_OK); - wfx_rsi.dev_state.Set(WifiState::kStationStarted); - - // Creating a Wi-Fi driver thread - sWlanThread = osThreadNew(sl_matter_wifi_task, NULL, &kWlanTaskAttr); - - VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL); - - ChipLogProgress(DeviceLayer, "sl_matter_wifi_task created successfully"); - 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.Set(WifiState::kStationMode); -} - -/********************************************************************* - * @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) -{ - return wfx_rsi.dev_state.Has(WifiState::kStationMode); -} - -/********************************************************************* - * @fn void 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) -{ - VerifyOrReturn(addr != nullptr); -#ifdef SL_WFX_CONFIG_SOFTAP - *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; -#else - *addr = wfx_rsi.sta_mac; -#endif -} - -/********************************************************************* - * @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) -{ - VerifyOrReturn(cfg != nullptr); - wfx_rsi.sec = *cfg; - wfx_rsi.dev_state.Set(WifiState::kStationProvisioned); -} - -/********************************************************************* - * @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) -{ - VerifyOrReturnError(wifiConfig != nullptr, false); - VerifyOrReturnError(wfx_rsi.dev_state.Has(WifiState::kStationProvisioned), false); - *wifiConfig = wfx_rsi.sec; - return true; -} - -/********************************************************************* - * @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.Clear(WifiState::kStationProvisioned); - ChipLogProgress(DeviceLayer, "Clear WiFi Provision"); -} - -/************************************************************************* - * @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_t wfx_connect_to_ap(void) -{ - VerifyOrReturnError(wfx_rsi.dev_state.Has(WifiState::kStationProvisioned), SL_STATUS_INVALID_CONFIGURATION); - VerifyOrReturnError(wfx_rsi.sec.ssid_length, SL_STATUS_INVALID_CREDENTIALS); - VerifyOrReturnError(wfx_rsi.sec.ssid_length <= WFX_MAX_SSID_LENGTH, SL_STATUS_HAS_OVERFLOWED); - ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.sec.ssid); - - WifiEvent event = WifiEvent::kStationStartJoin; - sl_matter_wifi_post_event(event); - return SL_STATUS_OK; -} - -#if SL_ICD_ENABLED -#if SLI_SI917 -/********************************************************************* - * @fn 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) - * @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(void) - * @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(void) -{ - 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 sl_matter_wifi_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) -{ - return wfx_rsi.dev_state.Has(WifiState::kStationConnected); -} - -/********************************************************************* - * @fn wifi_mode_t wfx_get_wifi_mode(void) - * @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(void) -{ - if (wfx_rsi.dev_state.Has(WifiState::kStationInit)) - return WIFI_MODE_STA; - return WIFI_MODE_NULL; -} - -/********************************************************************* - * @fn sl_status_t sl_matter_wifi_disconnect(void) - * @brief - * called fuction when STA disconnected - * @param[in] None - * @return return SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ***********************************************************************/ -sl_status_t sl_matter_wifi_disconnect(void) -{ - sl_status_t status; - status = sl_wifi_platform_disconnect(); - wfx_rsi.dev_state.Clear(WifiState::kStationConnected); - 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) -{ - VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); - return wfx_rsi.dev_state.Has(WifiState::kStationDhcpDone); -} -#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) -{ - VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); - // TODO: WifiState::kStationConnected does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG - return wfx_rsi.dev_state.Has(WifiState::kStationConnected); -} - -/********************************************************************* - * @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.Has(WifiState::kStationInit); -} - -/********************************************************************* - * @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(void) - * @brief - * get the driver reset count - * @param[in] None - * @return - * reset count - *****************************************************************************/ -int32_t wfx_reset_counts(void) -{ - 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 *)) -{ - // check if already in progress - VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); - wfx_rsi.scan_cb = callback; - - VerifyOrReturnError(ssid != nullptr, false); - wfx_rsi.scan_ssid_length = strnlen(ssid, std::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); - wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); - VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); - chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); - - WifiEvent event = WifiEvent::kScan; - sl_matter_wifi_post_event(event); - - 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 */ - ChipLogError(DeviceLayer, "cannot cancel scan"); -} -#endif /* SL_WFX_CONFIG_SCAN */ -#endif // RS911X_WIFI - /*********************************************************************************** * @fn sl_matter_wifi_task_started(void) * @brief diff --git a/examples/platform/silabs/wifi/WifiInterfaceAbstraction.h b/examples/platform/silabs/wifi/WifiInterfaceAbstraction.h index 99ac5fdf88a4bd..1d4b2163c77abe 100644 --- a/examples/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/examples/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -27,6 +27,22 @@ */ #define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ +#define MAX_JOIN_RETRIES_COUNT (5) + +enum class WifiState : uint16_t +{ + kStationInit = (1 << 0), + kAPReady = (1 << 1), + kStationProvisioned = (1 << 2), + kStationConnecting = (1 << 3), + kStationConnected = (1 << 4), + kStationDhcpDone = (1 << 6), /* Requested to do DHCP after conn */ + kStationMode = (1 << 7), /* Enable Station Mode */ + kAPMode = (1 << 8), /* Enable AP Mode */ + kStationReady = (kStationConnected | kStationDhcpDone), + kStationStarted = (1 << 9), /* RSI task started */ + kScanStarted = (1 << 10), /* Scan Started */ +}; enum class WifiEvent : uint8_t { @@ -41,25 +57,9 @@ enum class WifiEvent : uint8_t kStationDhcpPoll = 8 }; -enum class WifiState : uint16_t -{ - kStationInit = (1 << 0), - kAPReady = (1 << 1), - kStationProvisioned = (1 << 2), - kStationConnecting = (1 << 3), - kStationConnected = (1 << 4), - kStationDhcpDone = (1 << 6), /* Requested to do DHCP after conn */ - kStationMode = (1 << 7), /* Enable Station Mode */ - kAPMode = (1 << 8), /* Enable AP Mode */ - kStationReady = (kStationConnected | kStationDhcpDone), - kStationStarted = (1 << 9), /* RSI task started */ - kScanStarted = (1 << 10), /* Scan Started */ -}; -using WifiStateFlags = chip::BitFlags; - typedef struct wfx_rsi_s { - WifiStateFlags dev_state; + chip::BitFlags dev_state; uint16_t ap_chan; /* The chan our STA is using */ wfx_wifi_provision_t sec; #ifdef SL_WFX_CONFIG_SCAN @@ -90,13 +90,6 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_rsi_reset_count(); int32_t sl_wifi_platform_disconnect(); -// TODO : this needs to be extern otherwise we get a linking error. We need to figure out why in the header clean up -// NCP files are including this while being c files -#ifdef __cplusplus -extern "C" { -#endif -sl_status_t sl_matter_wifi_platform_init(void); - #if CHIP_CONFIG_ENABLE_ICD_SERVER #if SLI_SI917 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); @@ -104,9 +97,6 @@ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ int32_t wfx_rsi_power_save(); #endif /* SLI_SI917 */ #endif /* SL_ICD_ENABLED */ -#ifdef __cplusplus -} -#endif /** * @brief Posts an event to the Wi-Fi task diff --git a/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.cpp b/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.cpp new file mode 100644 index 00000000000000..3c2ec032a8ca3b --- /dev/null +++ b/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.cpp @@ -0,0 +1,350 @@ +/* + * + * Copyright (c) 2024 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, + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WiseconnectInterfaceAbstraction.h" +#include +#include +#include + +namespace { + +// Thread for the WLAN RSI +osThreadId_t sWlanThread; +constexpr uint32_t kWlanTaskSize = 2048; +uint8_t wlanStack[kWlanTaskSize]; +osThread_t sWlanTaskControlBlock; +constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", + .attr_bits = osThreadDetached, + .cb_mem = &sWlanTaskControlBlock, + .cb_size = osThreadCbSize, + .stack_mem = wlanStack, + .stack_size = kWlanTaskSize, + .priority = osPriorityAboveNormal7 }; + +} // namespace + +/********************************************************************* + * @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) +{ + VerifyOrReturnError(!(wfx_rsi.dev_state.Has(WifiState::kStationStarted)), SL_STATUS_OK); + wfx_rsi.dev_state.Set(WifiState::kStationStarted); + + // Creating a Wi-Fi driver thread + sWlanThread = osThreadNew(sl_matter_wifi_task, NULL, &kWlanTaskAttr); + + VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL); + + ChipLogProgress(DeviceLayer, "sl_matter_wifi_task created successfully"); + 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.Set(WifiState::kStationMode); +} + +/********************************************************************* + * @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) +{ + return wfx_rsi.dev_state.Has(WifiState::kStationMode); +} + +/********************************************************************* + * @fn void 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) +{ + VerifyOrReturn(addr != nullptr); +#ifdef SL_WFX_CONFIG_SOFTAP + *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; +#else + *addr = wfx_rsi.sta_mac; +#endif +} + +/********************************************************************* + * @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) +{ + VerifyOrReturn(cfg != nullptr); + wfx_rsi.sec = *cfg; + wfx_rsi.dev_state.Set(WifiState::kStationProvisioned); +} + +/********************************************************************* + * @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) +{ + VerifyOrReturnError(wifiConfig != nullptr, false); + VerifyOrReturnError(wfx_rsi.dev_state.Has(WifiState::kStationProvisioned), false); + *wifiConfig = wfx_rsi.sec; + return true; +} + +/********************************************************************* + * @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.Clear(WifiState::kStationProvisioned); + ChipLogProgress(DeviceLayer, "Clear WiFi Provision"); +} + +/************************************************************************* + * @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_t wfx_connect_to_ap(void) +{ + VerifyOrReturnError(wfx_rsi.dev_state.Has(WifiState::kStationProvisioned), SL_STATUS_INVALID_CONFIGURATION); + VerifyOrReturnError(wfx_rsi.sec.ssid_length, SL_STATUS_INVALID_CREDENTIALS); + VerifyOrReturnError(wfx_rsi.sec.ssid_length <= WFX_MAX_SSID_LENGTH, SL_STATUS_HAS_OVERFLOWED); + ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.sec.ssid); + + WifiEvent event = WifiEvent::kStationStartJoin; + sl_matter_wifi_post_event(event); + return SL_STATUS_OK; +} + +/********************************************************************* + * @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 sl_matter_wifi_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) +{ + return wfx_rsi.dev_state.Has(WifiState::kStationConnected); +} + +/********************************************************************* + * @fn wifi_mode_t wfx_get_wifi_mode(void) + * @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(void) +{ + if (wfx_rsi.dev_state.Has(WifiState::kStationInit)) + return WIFI_MODE_STA; + return WIFI_MODE_NULL; +} + +/********************************************************************* + * @fn sl_status_t sl_matter_wifi_disconnect(void) + * @brief + * called fuction when STA disconnected + * @param[in] None + * @return return SL_STATUS_OK if successful, + * SL_STATUS_FAIL otherwise + ***********************************************************************/ +sl_status_t sl_matter_wifi_disconnect(void) +{ + sl_status_t status; + status = sl_wifi_platform_disconnect(); + wfx_rsi.dev_state.Clear(WifiState::kStationConnected); + 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) +{ + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return wfx_rsi.dev_state.Has(WifiState::kStationDhcpDone); +} +#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) +{ + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + // TODO: WifiState::kStationConnected does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG + return wfx_rsi.dev_state.Has(WifiState::kStationConnected); +} + +/********************************************************************* + * @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.Has(WifiState::kStationInit); +} + +/********************************************************************* + * @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(void) + * @brief + * get the driver reset count + * @param[in] None + * @return + * reset count + *****************************************************************************/ +int32_t wfx_reset_counts(void) +{ + 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 *)) +{ + // check if already in progress + VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); + wfx_rsi.scan_cb = callback; + + VerifyOrReturnError(ssid != nullptr, false); + wfx_rsi.scan_ssid_length = strnlen(ssid, std::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); + VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); + chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); + + WifiEvent event = WifiEvent::kScan; + sl_matter_wifi_post_event(event); + + 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 */ + ChipLogError(DeviceLayer, "cannot cancel scan"); +} +#endif /* SL_WFX_CONFIG_SCAN */ diff --git a/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.h b/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.h new file mode 100644 index 00000000000000..d847e99fb575a5 --- /dev/null +++ b/examples/platform/silabs/wifi/WiseconnectInterfaceAbstraction.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2024 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, + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include "WifiInterfaceAbstraction.h" +#include +#include +#include +#include +#include + +#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ +#define GET_IPV6_SUCCESS (1) + +extern WfxRsi_t wfx_rsi; + +void sl_matter_wifi_task(void * arg); + +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 +void wfx_ip_changed_notify(int got_ip); +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + +int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap); +int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); +int32_t wfx_rsi_reset_count(); +int32_t sl_wifi_platform_disconnect(); + +sl_status_t sl_matter_wifi_platform_init(void); + +/** + * @brief Posts an event to the Wi-Fi task + * + * @param[in] event Event to process. + */ +void sl_matter_wifi_post_event(WifiEvent event); diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 9ebf113c4f8afa..6c639a7a777faf 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -27,13 +27,7 @@ #include "FreeRTOS.h" #include "timers.h" #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus #include "wfx_sl_ble_init.h" -#ifdef __cplusplus -} -#endif // __cplusplus #else #include "gatt_db.h" #include "sl_bgapi.h" diff --git a/src/platform/silabs/efr32/wifi/ethernetif.cpp b/src/platform/silabs/efr32/wifi/ethernetif.cpp index 5993cf90cc631a..d6123d2ead0301 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.cpp +++ b/src/platform/silabs/efr32/wifi/ethernetif.cpp @@ -162,7 +162,7 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) /* We allocate a pbuf chain of pbufs from the Lwip buffer pool * and copy the data to the pbuf chain */ - if ((p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL)) != STRUCT_PBUF) + if ((p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL)) != NULL) { for (q = p, bufferoffset = 0; q != NULL; q = q->next) { @@ -268,7 +268,7 @@ static err_t low_level_output(struct netif * netif, struct pbuf * p) /* send the generated frame over Wifi network */ while ((result != SL_STATUS_OK) && (i++ < 10)) { - result = sl_wfx_send_ethernet_frame(tx_buffer, framelength, SL_WFX_STA_INTERFACE, PRIORITY_0); + result = sl_wfx_send_ethernet_frame(tx_buffer, framelength, SL_WFX_STA_INTERFACE, 0 /* priority */); } sl_wfx_host_free_buffer(tx_buffer, SL_WFX_TX_FRAME_BUFFER); diff --git a/src/platform/silabs/efr32/wifi/ethernetif.h b/src/platform/silabs/efr32/wifi/ethernetif.h index dfea1ea6ad3540..56e564d30b6767 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.h +++ b/src/platform/silabs/efr32/wifi/ethernetif.h @@ -19,9 +19,16 @@ #include "lwip/err.h" #include "lwip/netif.h" + +#ifdef WF200_WIFI +#include "sl_wfx_api.h" +#include "sl_wfx_constants.h" +#endif // WF200_WIFI + #ifdef __cplusplus extern "C" { #endif + /*************************************************************************** * @fn err_t sta_ethernetif_init(struct netif *netif) * @brief @@ -47,6 +54,7 @@ void sl_wfx_host_received_frame_callback(sl_wfx_received_ind_t * rx_buffer); #else void wfx_host_received_sta_frame_cb(uint8_t * buf, int len); #endif /* WF200_WIFI */ + #ifdef __cplusplus } #endif diff --git a/src/platform/silabs/efr32/wifi/lwip_netif.cpp b/src/platform/silabs/efr32/wifi/lwip_netif.cpp index f8d719b387fb09..b6c523c636a2a5 100644 --- a/src/platform/silabs/efr32/wifi/lwip_netif.cpp +++ b/src/platform/silabs/efr32/wifi/lwip_netif.cpp @@ -38,12 +38,17 @@ #include using namespace ::chip; using namespace ::chip::DeviceLayer; + static struct netif sta_netif; #ifdef SL_WFX_CONFIG_SOFTAP static struct netif ap_netif; #endif +#define LINK_UP (1) +#define LINK_DOWN (0) +#define MAC_48_BIT_SET (1) + /**************************************************************************** * @fn static void netif_config(struct netif *sta_if, struct netif *ap_if) * @brief diff --git a/src/platform/silabs/efr32/wifi/wfx_msgs.h b/src/platform/silabs/efr32/wifi/wfx_msgs.h index edf0aec5828fa7..af167a1f2c2f95 100644 --- a/src/platform/silabs/efr32/wifi/wfx_msgs.h +++ b/src/platform/silabs/efr32/wifi/wfx_msgs.h @@ -15,13 +15,17 @@ * limitations under the License. */ +// TODO: Delete this file after moving the wifi abstraction files to the src directory. +// Nothing should be added to this file anymore. +// File is kept due to the current header inclusion structure. + #ifndef _WFX_MSGS_H_ #define _WFX_MSGS_H_ -/* - * Taken from sl_wfx firmware - so I can re-use. - * I need to do a better job than to use this stuff - * in the CPP files of Matter - */ + +#ifdef WF200_WIFI +#include "sl_wfx_api.h" +#include "sl_wfx_constants.h" +#else typedef struct { uint8_t octet[6]; ///< Table to store a MAC address @@ -62,29 +66,7 @@ typedef struct __attribute__((__packed__)) sl_wfx_startup_ind_body_s uint32_t status; ///< Initialization status. A value of zero indicates the boot is completed successfully (see enum sl_wfx_status_t) uint16_t hardware_id; ///<=RO misc_read_reg7 register value -#if 0 /* Not used in RS911x for now - use stuff here for the port */ - uint8_t opn[SL_WFX_OPN_SIZE]; ///<=OTP part_OPN - uint8_t uid[SL_WFX_UID_SIZE]; ///<=OTP UID - uint16_t num_inp_ch_bufs; /// #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#include - +#include "wfx_sl_ble_init.h" #include +#include #include #include #include #include +#include #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #include #endif -#include -#ifdef __cplusplus extern "C" { -#endif -#include "wfx_sl_ble_init.h" #if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include #endif #include -#ifdef __cplusplus } -#endif #define BLE_MIN_CONNECTION_INTERVAL_MS 24 #define BLE_MAX_CONNECTION_INTERVAL_MS 40 diff --git a/src/platform/silabs/rs911x/rsi_ble_config.h b/src/platform/silabs/rs911x/rsi_ble_config.h index f508c3396f4e09..b28c810679081a 100644 --- a/src/platform/silabs/rs911x/rsi_ble_config.h +++ b/src/platform/silabs/rs911x/rsi_ble_config.h @@ -16,6 +16,10 @@ ******************************************************************************/ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + #include "rsi_ble_apis.h" #if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include "rsi_bt_common_apis.h" @@ -24,6 +28,10 @@ #include #endif +#ifdef __cplusplus +} +#endif + #if SL_MATTER_GN_BUILD == 0 #include "sl_matter_wifi_config.h" #endif // SL_MATTER_GN_BUILD diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 971852592c3e2e..89169993810ef7 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -20,9 +20,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include #include #include +#include using namespace chip::DeviceLayer::Internal; diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index 7fd9fc94b9d58e..4eaff9c0677444 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -25,15 +25,17 @@ // BLE include file to refer BLE APIs #include "ble_config.h" #include "cmsis_os2.h" -#include "wfx_host_events.h" +#include +#include + +extern "C" { #include #include #include #include #include #include -#include -#include +} #define ATT_REC_IN_HOST (0) #define WFX_QUEUE_SIZE 10 diff --git a/src/platform/silabs/wifi/wfx_host_events.h b/src/platform/silabs/wifi/wfx_host_events.h index d3d8de6ec78569..38808610ee74fe 100644 --- a/src/platform/silabs/wifi/wfx_host_events.h +++ b/src/platform/silabs/wifi/wfx_host_events.h @@ -26,6 +26,8 @@ #include "lwip/netifapi.h" #include "lwip/tcpip.h" +#include "wfx_msgs.h" + #if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include "rsi_common_apis.h" #include "sl_si91x_types.h" @@ -44,106 +46,27 @@ #define WFX_MAX_PASSKEY_LENGTH (64) #endif // (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) -#define CONVERT_SEC_TO_MS(TimeInS) (TimeInS * 1000) - -/* Wi-Fi bitmask events - for the task */ -#define SL_WFX_CONNECT (1 << 1) -#define SL_WFX_DISCONNECT (1 << 2) -#define SL_WFX_START_AP (1 << 3) -#define SL_WFX_STOP_AP (1 << 4) -#define SL_WFX_SCAN_START (1 << 5) -#define SL_WFX_SCAN_COMPLETE (1 << 6) -#define SL_WFX_RETRY_CONNECT (1 << 7) - -// WLAN MAX retry -#define MAX_JOIN_RETRIES_COUNT (5) - -#define WLAN_TASK_STACK_SIZE (1024) - -// WLAN related Macros -#define ETH_FRAME (0) -#define CMP_SUCCESS (0) #define BSSID_LEN (6) #define MAC_ADDRESS_FIRST_OCTET (6) -#define AP_START_SUCCESS (0) -#define BITS_TO_WAIT (0) #define CONNECTION_STATUS_SUCCESS (1) #define IP_STATUS_FAIL (0) -#define GET_IPV6_SUCCESS (1) #define GET_IPV6_FAIL (0) -#define BEACON_1 (0) -#define CHANNEL_LIST ((const uint8_t *) 0) -#define CHANNEL_COUNT (0) -#define IE_DATA ((const uint8_t *) 0) -#define IE_DATA_LENGTH (0) -#define BSSID_SCAN ((const uint8_t *) 0) -#define CHANNEL_0 (0) -#define PREVENT_ROAMING (1) -#define DISABLE_PMF_MODE (0) -#define STA_IP_FAIL (0) #define IP_STATUS_SUCCESS (1) -#define ACTIVE_CHANNEL_TIME_100 (100) -#define PASSIVE_CHANNEL_TIME_0 (0) -#define PROBE_NUM_REQ_1 (1) -#define PINOUT_CLEAR_STATUS (0) -#define TICKS_TO_WAIT_0 (0) -#define TICKS_TO_WAIT_3 (3) -#define TICKS_TO_WAIT_1 (1) -#define TICKS_TO_WAIT_500 (500) +#define SL_WFX_STARTUP_IND_ID (1) +#define SL_WFX_CONNECT_IND_ID (2) +#define SL_WFX_DISCONNECT_IND_ID (3) +#define SL_WFX_SCAN_COMPLETE_ID (4) // TASK and Interrupt Macros #define SUCCESS_STATUS (1) -#define LINK_UP (1) -#define LINK_DOWN (0) -#define MAC_48_BIT_SET (1) -#define STRUCT_PBUF ((struct pbuf *) 0) -#define PRIORITY_0 (0) -#define HEX_VALUE_FF (0XFF) -// Timer Delay -#define MAX_XLEN (16) -#define MIN_XLEN (0) -#define PINOUT_CLEAR (0) -#define PINOUT_SET (1) -#define WFX_SPI_NVIC_PRIORITY (5) -#define WFX_GPIO_NVIC_PRIORITY (5) -#define CB_VALUE ((DMADRV_Callback_t) 0) - -/* TIMER_TICKS_TO_WAIT Specifies the time, in ticks, that the calling task should - * be held in the Blocked state to wait for the start command to be successfully - * sent to the timer command queue. - */ -#define TIMER_TICKS_TO_WAIT_0 pdMS_TO_TICKS(0) - -#define CONVERT_SEC_TO_MSEC (1000) -#define CONVERT_USEC_TO_MSEC (1 / 1000) - -#define RSI_RESPONSE_MAX_SIZE (28) -#define RSI_RESPONSE_HOLD_BUFF_SIZE (128) -#define RSI_DRIVER_STATUS (0) -#define OPER_MODE_0 (0) -#define COEX_MODE_0 (0) -#define RESP_BUFF_SIZE (6) -#define AP_CHANNEL_NO_0 (0) -#define SCAN_BITMAP_OPTN_1 (1) -#define IP_CONF_RSP_BUFF_LENGTH_4 (4) -#define STATION (0) - -#define SPI_CONFIG_SUCCESS (0) typedef enum { WIFI_EVENT, IP_EVENT, } wfx_event_base_t; -typedef enum -{ - IP_EVENT_STA_GOT_IP, - IP_EVENT_GOT_IP6, - IP_EVENT_STA_LOST_IP, -} ip_event_id_t; - /* Note that these are same as RSI_security */ typedef enum { @@ -195,6 +118,13 @@ typedef struct wfx_wifi_scan_ext uint32_t overrun_count; } wfx_wifi_scan_ext_t; +typedef enum +{ + IP_EVENT_STA_GOT_IP, + IP_EVENT_GOT_IP6, + IP_EVENT_STA_LOST_IP, +} ip_event_id_t; + #ifdef RS911X_WIFI /* * This Sh%t is here to support WFXUtils - and the Matter stuff that uses it @@ -205,121 +135,27 @@ typedef enum SL_WFX_STA_INTERFACE = 0, ///< Interface 0, linked to the station SL_WFX_SOFTAP_INTERFACE = 1, ///< Interface 1, linked to the softap } sl_wfx_interface_t; -#endif /* RS911X_WIFI */ - -#ifdef WF200_WIFI -#include "FreeRTOS.h" -#include "event_groups.h" -#include "semphr.h" -#include "sl_wfx_cmd_api.h" -#include "sl_wfx_constants.h" -#include "task.h" -#include "timers.h" - -#define WLAN_TASK_PRIORITY (1) -typedef struct __attribute__((__packed__)) sl_wfx_get_counters_cnf_body_s -{ - uint32_t status; - uint16_t mib_id; - uint16_t length; - uint32_t rcpi; - uint32_t count_plcp_errors; - uint32_t count_fcs_errors; - uint32_t count_tx_packets; - uint32_t count_rx_packets; - uint32_t count_rx_packet_errors; - uint32_t count_rx_decryption_failures; - uint32_t count_rx_mic_failures; - uint32_t count_rx_no_key_failures; - uint32_t count_tx_multicast_frames; - uint32_t count_tx_frames_success; - uint32_t count_tx_frame_failures; - uint32_t count_tx_frames_retried; - uint32_t count_tx_frames_multi_retried; - uint32_t count_rx_frame_duplicates; - uint32_t count_rts_success; - uint32_t count_rts_failures; - uint32_t count_ack_failures; - uint32_t count_rx_multicast_frames; - uint32_t count_rx_frames_success; - uint32_t count_rx_cmacicv_errors; - uint32_t count_rx_cmac_replays; - uint32_t count_rx_mgmt_ccmp_replays; - uint32_t count_rx_bipmic_errors; - uint32_t count_rx_beacon; - uint32_t count_miss_beacon; - uint32_t reserved[15]; -} sl_wfx_get_counters_cnf_body_t; - -typedef struct __attribute__((__packed__)) sl_wfx_get_counters_cnf_s -{ - /** Common message header. */ - sl_wfx_header_t header; - /** Confirmation message body. */ - sl_wfx_get_counters_cnf_body_t body; -} sl_wfx_get_counters_cnf_t; - -typedef struct __attribute__((__packed__)) sl_wfx_mib_req_body_s -{ - uint16_t mib_id; ///< ID of the MIB to be read. - uint16_t reserved; -} sl_wfx_mib_req_body_t; - -typedef struct __attribute__((__packed__)) sl_wfx_header_mib_s -{ - uint16_t length; ///< Message length in bytes including this uint16_t. - ///< Maximum value is 8188 but maximum Request size is FW dependent and reported in the - ///< ::sl_wfx_startup_ind_body_t::size_inp_ch_buf. - uint8_t id; ///< Contains the message Id indexed by sl_wfx_general_commands_ids_t or sl_wfx_message_ids_t. - uint8_t reserved : 1; - uint8_t interface : 2; - uint8_t seqnum : 3; - uint8_t encrypted : 2; -} sl_wfx_header_mib_t; - -typedef struct __attribute__((__packed__)) sl_wfx_mib_req_s -{ - /** Common message header. */ - sl_wfx_header_mib_t header; - /** Request message body. */ - sl_wfx_mib_req_body_t body; -} sl_wfx_mib_req_t; - -#else /* End WF200 else RS9116,917 NCP and 917 SoC */ - -#include "wfx_msgs.h" -/* Wi-Fi events*/ -#define SL_WFX_STARTUP_IND_ID (1) -#define SL_WFX_CONNECT_IND_ID (2) -#define SL_WFX_DISCONNECT_IND_ID (3) -#define SL_WFX_SCAN_COMPLETE_ID (4) -#endif /* WF200_WIFI */ - -#ifdef __cplusplus -extern "C" { #endif -void sl_wfx_host_gpio_init(void); sl_status_t wfx_wifi_start(void); void wfx_enable_sta_mode(void); - void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr); void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig); bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig); - bool wfx_is_sta_mode_enabled(void); int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap); int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_reset_counts(); - void wfx_clear_wifi_provision(void); sl_status_t wfx_connect_to_ap(void); void wfx_setup_ip6_link_local(sl_wfx_interface_t); bool wfx_is_sta_connected(void); sl_status_t sl_matter_wifi_disconnect(void); + #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 bool wfx_have_ipv4_addr(sl_wfx_interface_t); #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + bool wfx_have_ipv6_addr(sl_wfx_interface_t); wifi_mode_t wfx_get_wifi_mode(void); bool wfx_start_scan(char * ssid, void (*scan_cb)(wfx_wifi_scan_result_t *)); /* true returned if successfully started */ @@ -338,7 +174,6 @@ void wfx_lwip_set_sta_link_down(void); void sl_matter_lwip_start(void); struct netif * wfx_get_netif(sl_wfx_interface_t interface); -bool wfx_hw_ready(void); #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 void wfx_dhcp_got_ipv4(uint32_t); void wfx_ip_changed_notify(int got_ip); @@ -355,6 +190,8 @@ int32_t wfx_rsi_send_data(void * p, uint16_t len); #endif //!(EXP_BOARD) #endif // RS911X_WIFI +bool wfx_hw_ready(void); + #ifdef RS911X_WIFI // for RS9116, 917 NCP and 917 SoC /* RSI Power Save */ #if SL_ICD_ENABLED @@ -366,21 +203,23 @@ sl_status_t wfx_power_save(); #endif /* SL_ICD_ENABLED */ #endif /* RS911X_WIFI */ -#ifdef WF200_WIFI -bool wfx_is_sta_provisioned(void); -sl_wfx_state_t wfx_get_wifi_state(void); -void wfx_bus_start(void); -sl_status_t get_all_counters(void); -void sl_wfx_host_gpio_init(void); -sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload); -#endif /* WF200_WIFI */ +#ifdef __cplusplus +extern "C" { +#endif #if (SLI_SI91X_MCU_INTERFACE) #if SL_ICD_ENABLED +// TODO : This should be moved outside of the Wifi interface functions void sl_button_on_change(uint8_t btn, uint8_t btnAction); #endif /* SL_ICD_ENABLED */ #endif /* SLI_SI91X_MCU_INTERFACE */ +#ifdef WF200_WIFI +void sl_wfx_host_gpio_init(void); +void wfx_bus_start(void); +sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload); +#endif /* WF200_WIFI */ + #ifdef __cplusplus } #endif