|
29 | 29 |
|
30 | 30 | #include "FreeRTOS.h"
|
31 | 31 | #include "WifiInterfaceAbstraction.h"
|
| 32 | +#include "WiseconnectInterfaceAbstraction.h" |
32 | 33 | #include "ble_config.h"
|
33 | 34 | #include "dhcp_client.h"
|
34 | 35 | #include "event_groups.h"
|
|
45 | 46 | #include <lib/support/logging/CHIPLogging.h>
|
46 | 47 |
|
47 | 48 | extern "C" {
|
48 |
| -#include "sl_net.h" |
49 | 49 | #include "sl_si91x_driver.h"
|
50 | 50 | #include "sl_si91x_host_interface.h"
|
51 | 51 | #include "sl_si91x_types.h"
|
52 | 52 | #include "sl_wifi.h"
|
53 | 53 | #include "sl_wifi_callback_framework.h"
|
54 | 54 | #include "sl_wifi_constants.h"
|
55 | 55 | #include "sl_wifi_types.h"
|
56 |
| -#include "wfx_host_events.h" |
57 | 56 | #if SL_MBEDTLS_USE_TINYCRYPT
|
58 | 57 | #include "sl_si91x_constants.h"
|
59 | 58 | #include "sl_si91x_trng.h"
|
@@ -440,6 +439,38 @@ sl_status_t JoinWifiNetwork(void)
|
440 | 439 |
|
441 | 440 | } // namespace
|
442 | 441 |
|
| 442 | +/** |
| 443 | + * @brief Wifi initialization called from app main |
| 444 | + * |
| 445 | + * @return sl_status_t Returns underlying Wi-Fi initialization error |
| 446 | + */ |
| 447 | +sl_status_t sl_matter_wifi_platform_init(void) |
| 448 | +{ |
| 449 | + sl_status_t status = SL_STATUS_OK; |
| 450 | + |
| 451 | + status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr); |
| 452 | + VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status)); |
| 453 | + |
| 454 | + // Create Sempaphore for scan completion |
| 455 | + sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr); |
| 456 | + VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); |
| 457 | + |
| 458 | + // Create Semaphore for scan in-progress protection |
| 459 | + sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr); |
| 460 | + VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); |
| 461 | + |
| 462 | + // Create the message queue |
| 463 | + sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr); |
| 464 | + VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED); |
| 465 | + |
| 466 | + // Create timer for DHCP polling |
| 467 | + // TODO: Use LWIP timer instead of creating a new one here |
| 468 | + sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr); |
| 469 | + VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED); |
| 470 | + |
| 471 | + return status; |
| 472 | +} |
| 473 | + |
443 | 474 | /******************************************************************
|
444 | 475 | * @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap)
|
445 | 476 | * @brief
|
@@ -614,7 +645,7 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
|
614 | 645 | // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
|
615 | 646 | if (wfx_rsi.scan_ssid != nullptr &&
|
616 | 647 | (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, std::min(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) ==
|
617 |
| - CMP_SUCCESS)) |
| 648 | + 0)) |
618 | 649 | {
|
619 | 650 | continue;
|
620 | 651 | }
|
@@ -838,38 +869,6 @@ void ProcessEvent(WifiEvent event)
|
838 | 869 | }
|
839 | 870 | }
|
840 | 871 |
|
841 |
| -/** |
842 |
| - * @brief Wifi initialization called from app main |
843 |
| - * |
844 |
| - * @return sl_status_t Returns underlying Wi-Fi initialization error |
845 |
| - */ |
846 |
| -sl_status_t sl_matter_wifi_platform_init(void) |
847 |
| -{ |
848 |
| - sl_status_t status = SL_STATUS_OK; |
849 |
| - |
850 |
| - status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr); |
851 |
| - VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status)); |
852 |
| - |
853 |
| - // Create Sempaphore for scan completion |
854 |
| - sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr); |
855 |
| - VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); |
856 |
| - |
857 |
| - // Create Semaphore for scan in-progress protection |
858 |
| - sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr); |
859 |
| - VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); |
860 |
| - |
861 |
| - // Create the message queue |
862 |
| - sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr); |
863 |
| - VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED); |
864 |
| - |
865 |
| - // Create timer for DHCP polling |
866 |
| - // TODO: Use LWIP timer instead of creating a new one here |
867 |
| - sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr); |
868 |
| - VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED); |
869 |
| - |
870 |
| - return status; |
871 |
| -} |
872 |
| - |
873 | 872 | /*********************************************************************************
|
874 | 873 | * @fn void sl_matter_wifi_task(void *arg)
|
875 | 874 | * @brief
|
@@ -922,14 +921,32 @@ void wfx_dhcp_got_ipv4(uint32_t ip)
|
922 | 921 | /*
|
923 | 922 | * Acquire the new IP address
|
924 | 923 | */
|
925 |
| - wfx_rsi.ip4_addr[0] = (ip) &HEX_VALUE_FF; |
926 |
| - wfx_rsi.ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; |
927 |
| - wfx_rsi.ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; |
928 |
| - wfx_rsi.ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; |
| 924 | + wfx_rsi.ip4_addr[0] = (ip) &0xFF; |
| 925 | + wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; |
| 926 | + wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; |
| 927 | + wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; |
929 | 928 | ChipLogDetail(DeviceLayer, "DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2],
|
930 | 929 | wfx_rsi.ip4_addr[3]);
|
931 | 930 | /* Notify the Connectivity Manager - via the app */
|
932 | 931 | wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone).Set(WifiState::kStationReady);
|
933 | 932 | wfx_ip_changed_notify(IP_STATUS_SUCCESS);
|
934 | 933 | }
|
935 | 934 | #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
|
| 935 | + |
| 936 | +#if SL_ICD_ENABLED |
| 937 | +/********************************************************************* |
| 938 | + * @fn sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t |
| 939 | + sl_si91x_wifi_state) |
| 940 | + * @brief |
| 941 | + * Implements the power save in sleepy application |
| 942 | + * @param[in] sl_si91x_ble_state : State to set for the BLE |
| 943 | + sl_si91x_wifi_state : State to set for the WiFi |
| 944 | + * @return SL_STATUS_OK if successful, |
| 945 | + * SL_STATUS_FAIL otherwise |
| 946 | + ***********************************************************************/ |
| 947 | +sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, |
| 948 | + sl_si91x_performance_profile_t sl_si91x_wifi_state) // TODO : Figure out why the extern C is necessary |
| 949 | +{ |
| 950 | + return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK); |
| 951 | +} |
| 952 | +#endif |
0 commit comments