diff --git a/build_overrides/efr32_sdk.gni b/build_overrides/efr32_sdk.gni index 4a7344b4c7..fd5e7ce094 100644 --- a/build_overrides/efr32_sdk.gni +++ b/build_overrides/efr32_sdk.gni @@ -14,5 +14,5 @@ declare_args() { # Root directory for efr32 SDK build files. - efr32_sdk_build_root = "//third_party/silabs" + silabs_sdk_build_root = "//third_party/silabs" } diff --git a/examples/air-quality-sensor-app/silabs/BUILD.gn b/examples/air-quality-sensor-app/silabs/BUILD.gn index ed3077a3f1..958918e0d5 100644 --- a/examples/air-quality-sensor-app/silabs/BUILD.gn +++ b/examples/air-quality-sensor-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/air-quality-sensor-app/silabs/README.md b/examples/air-quality-sensor-app/silabs/README.md index d0e89d363d..1280f237fe 100644 --- a/examples/air-quality-sensor-app/silabs/README.md +++ b/examples/air-quality-sensor-app/silabs/README.md @@ -257,6 +257,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/air-quality-sensor-app/silabs/build_for_wifi_args.gni b/examples/air-quality-sensor-app/silabs/build_for_wifi_args.gni index 718600a811..8b5ccad9eb 100644 --- a/examples/air-quality-sensor-app/silabs/build_for_wifi_args.gni +++ b/examples/air-quality-sensor-app/silabs/build_for_wifi_args.gni @@ -15,7 +15,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_wifi = true chip_enable_ota_requestor = true app_data_model = diff --git a/examples/build_overrides/efr32_sdk.gni b/examples/build_overrides/efr32_sdk.gni index d5a35449d9..ece2fd94e9 100644 --- a/examples/build_overrides/efr32_sdk.gni +++ b/examples/build_overrides/efr32_sdk.gni @@ -14,5 +14,5 @@ declare_args() { # Root directory for erf32 SDK. - efr32_sdk_build_root = "//third_party/connectedhomeip/third_party/silabs" + silabs_sdk_build_root = "//third_party/connectedhomeip/third_party/silabs" } diff --git a/examples/chef/silabs/BUILD.gn b/examples/chef/silabs/BUILD.gn index f719245758..34dba76cc3 100644 --- a/examples/chef/silabs/BUILD.gn +++ b/examples/chef/silabs/BUILD.gn @@ -18,8 +18,8 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") diff --git a/examples/chef/silabs/build_for_wifi_args.gni b/examples/chef/silabs/build_for_wifi_args.gni index 9394037ba0..97180fa504 100644 --- a/examples/chef/silabs/build_for_wifi_args.gni +++ b/examples/chef/silabs/build_for_wifi_args.gni @@ -15,6 +15,6 @@ import("//build_overrides/chip.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true diff --git a/examples/energy-management-app/silabs/BUILD.gn b/examples/energy-management-app/silabs/BUILD.gn index 624cfff625..d4a4887cee 100644 --- a/examples/energy-management-app/silabs/BUILD.gn +++ b/examples/energy-management-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/energy-management-app/silabs/README.md b/examples/energy-management-app/silabs/README.md index 96237911df..6d0608a494 100644 --- a/examples/energy-management-app/silabs/README.md +++ b/examples/energy-management-app/silabs/README.md @@ -257,6 +257,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/energy-management-app/silabs/build_for_wifi_args.gni b/examples/energy-management-app/silabs/build_for_wifi_args.gni index 1b1c0ecd6a..feeffecd6f 100644 --- a/examples/energy-management-app/silabs/build_for_wifi_args.gni +++ b/examples/energy-management-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") sl_enable_test_event_trigger = true chip_enable_ota_requestor = false diff --git a/examples/light-switch-app/silabs/BUILD.gn b/examples/light-switch-app/silabs/BUILD.gn index 2602842edf..cbe8a512f8 100644 --- a/examples/light-switch-app/silabs/BUILD.gn +++ b/examples/light-switch-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/light-switch-app/silabs/README.md b/examples/light-switch-app/silabs/README.md index fe39610cbf..4d5e41bbc9 100644 --- a/examples/light-switch-app/silabs/README.md +++ b/examples/light-switch-app/silabs/README.md @@ -263,6 +263,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/light-switch-app/silabs/build_for_wifi_args.gni b/examples/light-switch-app/silabs/build_for_wifi_args.gni index ac70e16a8b..ed368c0248 100644 --- a/examples/light-switch-app/silabs/build_for_wifi_args.gni +++ b/examples/light-switch-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/light-switch-app/light-switch-common" diff --git a/examples/lighting-app/silabs/BUILD.gn b/examples/lighting-app/silabs/BUILD.gn index 55d7d41009..00aa6d9028 100644 --- a/examples/lighting-app/silabs/BUILD.gn +++ b/examples/lighting-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/lighting-app/silabs/README.md b/examples/lighting-app/silabs/README.md index 606208a387..85c5c36ae7 100644 --- a/examples/lighting-app/silabs/README.md +++ b/examples/lighting-app/silabs/README.md @@ -245,6 +245,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/lighting-app/silabs/build_for_wifi_args.gni b/examples/lighting-app/silabs/build_for_wifi_args.gni index 7e33551c30..f8cc0089c8 100644 --- a/examples/lighting-app/silabs/build_for_wifi_args.gni +++ b/examples/lighting-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") # Not needed for the Lighting-app chip_enable_read_client = false diff --git a/examples/lit-icd-app/silabs/BUILD.gn b/examples/lit-icd-app/silabs/BUILD.gn index eb7fa7a09a..8dfa759c2b 100644 --- a/examples/lit-icd-app/silabs/BUILD.gn +++ b/examples/lit-icd-app/silabs/BUILD.gn @@ -19,7 +19,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -39,7 +39,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/lit-icd-app/silabs/README.md b/examples/lit-icd-app/silabs/README.md index a38944bad5..2c690565f8 100644 --- a/examples/lit-icd-app/silabs/README.md +++ b/examples/lit-icd-app/silabs/README.md @@ -250,6 +250,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/lit-icd-app/silabs/build_for_wifi_args.gni b/examples/lit-icd-app/silabs/build_for_wifi_args.gni index c8048dc71e..57843c9b54 100644 --- a/examples/lit-icd-app/silabs/build_for_wifi_args.gni +++ b/examples/lit-icd-app/silabs/build_for_wifi_args.gni @@ -18,7 +18,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/lit-icd-app/lit-icd-common" diff --git a/examples/lock-app/silabs/BUILD.gn b/examples/lock-app/silabs/BUILD.gn index a20a4ad66f..81640548c3 100644 --- a/examples/lock-app/silabs/BUILD.gn +++ b/examples/lock-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/lock-app/silabs/README.md b/examples/lock-app/silabs/README.md index 4a16af08c0..452f4fd044 100644 --- a/examples/lock-app/silabs/README.md +++ b/examples/lock-app/silabs/README.md @@ -277,6 +277,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/lock-app/silabs/build_for_wifi_args.gni b/examples/lock-app/silabs/build_for_wifi_args.gni index cbc84b30bb..bb6da0b535 100644 --- a/examples/lock-app/silabs/build_for_wifi_args.gni +++ b/examples/lock-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/lock-app/silabs/data_model:silabs-lock" diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index b577382705..57e082e551 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -64,9 +64,9 @@ #include #ifdef SL_WIFI -#include "wfx_host_events.h" #include #include +#include #endif // SL_WIFI #ifdef DIC_ENABLE diff --git a/examples/platform/silabs/FreeRTOSConfig.h b/examples/platform/silabs/FreeRTOSConfig.h index 1c2db9621f..24a1408a47 100644 --- a/examples/platform/silabs/FreeRTOSConfig.h +++ b/examples/platform/silabs/FreeRTOSConfig.h @@ -103,8 +103,6 @@ extern "C" { #endif -#include - #include #include diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 82a4c8df74..6c6429d23b 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -25,7 +25,7 @@ #include #ifdef SL_WIFI -#include "wfx_host_events.h" +#include #endif /* SL_WIFI */ #if PW_RPC_ENABLED @@ -40,9 +40,10 @@ #include "MemMonitoring.h" #endif -#ifdef SLI_SI91X_MCU_INTERFACE -#include "wfx_rsi.h" -#endif /* SLI_SI91X_MCU_INTERFACE */ +#if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 +#include +#include +#endif // SLI_SI91X_MCU_INTERFACE #include // If building with the EFR32-provided crypto backend, we can use the @@ -128,7 +129,7 @@ void UnlockOpenThreadTask(void) CHIP_ERROR SilabsMatterConfig::InitOpenThread(void) { - SILABS_LOG("Initializing OpenThread stack"); + ChipLogProgress(DeviceLayer, "Initializing OpenThread stack"); ReturnErrorOnFailure(ThreadStackMgr().InitThreadStack()); #if CHIP_DEVICE_CONFIG_THREAD_FTD @@ -145,7 +146,7 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void) #endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // CHIP_DEVICE_CONFIG_THREAD_FTD - SILABS_LOG("Starting OpenThread task"); + ChipLogProgress(DeviceLayer, "Starting OpenThread task"); return ThreadStackMgrImpl().StartThreadTask(); } #endif // CHIP_ENABLE_OPENTHREAD @@ -178,7 +179,7 @@ void ApplicationStart(void * unused) SetDeviceAttestationCredentialsProvider(&Provision::Manager::GetInstance().GetStorage()); chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - SILABS_LOG("Starting App Task"); + ChipLogProgress(DeviceLayer, "Starting App Task"); err = AppTask::GetAppTask().StartAppTask(); if (err != CHIP_NO_ERROR) appError(err); @@ -198,13 +199,13 @@ void SilabsMatterConfig::AppInit() GetPlatform().Init(); sMainTaskHandle = osThreadNew(ApplicationStart, nullptr, &kMainTaskAttr); - SILABS_LOG("Starting scheduler"); + ChipLogProgress(DeviceLayer, "Starting scheduler"); VerifyOrDie(sMainTaskHandle); // We can't proceed if the Main Task creation failed. GetPlatform().StartScheduler(); // Should never get here. chip::Platform::MemoryShutdown(); - SILABS_LOG("Start Scheduler Failed"); + ChipLogProgress(DeviceLayer, "Start Scheduler Failed"); appError(CHIP_ERROR_INTERNAL); } @@ -217,9 +218,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) // initialization. mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); #endif - SILABS_LOG("=================================================="); - SILABS_LOG("%s starting", appName); - SILABS_LOG("=================================================="); + ChipLogProgress(DeviceLayer, "=================================================="); + ChipLogProgress(DeviceLayer, "%s starting", appName); + ChipLogProgress(DeviceLayer, "=================================================="); #if PW_RPC_ENABLED chip::rpc::Init(); @@ -232,7 +233,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) //============================================== // Init Matter Stack //============================================== - SILABS_LOG("Init CHIP Stack"); + ChipLogProgress(DeviceLayer, "Init CHIP Stack"); #ifdef SL_WIFI // Init Chip memory management before the stack @@ -322,16 +323,13 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void) // Start wfx bus communication task. wfx_bus_start(); #ifdef SL_WFX_USE_SECURE_LINK - wfx_securelink_task_start(); // start securelink key renegotiation task -#endif // SL_WFX_USE_SECURE_LINK -#endif /* WF200_WIFI */ - -#ifdef SLI_SI91X_MCU_INTERFACE - sl_status_t status; - if ((status = wfx_wifi_rsi_init()) != SL_STATUS_OK) - { - ReturnErrorOnFailure((CHIP_ERROR) status); - } + // start securelink key renegotiation task + wfx_securelink_task_start(); +#endif // SL_WFX_USE_SECURE_LINK +#endif // WF200_WIFI + +#if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 + VerifyOrReturnError(sl_matter_wifi_platform_init() == SL_STATUS_OK, CHIP_ERROR_INTERNAL); #endif // SLI_SI91X_MCU_INTERFACE return CHIP_NO_ERROR; @@ -344,6 +342,7 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void) extern "C" void vApplicationIdleHook(void) { #if (SLI_SI91X_MCU_INTERFACE && CHIP_CONFIG_ENABLE_ICD_SERVER) - sl_si91x_invoke_btn_press_event(); + SiWxPlatformInterface::sl_si91x_btn_event_handler(); + SiWxPlatformInterface::sl_si91x_uart_power_requirement_handler(); #endif } diff --git a/examples/platform/silabs/MatterConfig.h b/examples/platform/silabs/MatterConfig.h index b6abcc1726..0f951c36f8 100644 --- a/examples/platform/silabs/MatterConfig.h +++ b/examples/platform/silabs/MatterConfig.h @@ -16,6 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once #include #include diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 6756cc28c7..2d6d3574ea 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -15,11 +15,12 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") +import("${chip_root}/examples/platform/silabs/args.gni") import("${chip_root}/src/lib/lib.gni") import("${chip_root}/src/platform/device.gni") -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") import("${chip_root}/third_party/silabs/silabs_board.gni") -import("${efr32_sdk_build_root}/SiWx917_sdk.gni") +import("${silabs_sdk_build_root}/SiWx917_sdk.gni") declare_args() { enable_heap_monitoring = false @@ -27,19 +28,6 @@ declare_args() { # OTA timeout in seconds ota_periodic_query_timeout_sec = 86400 - # Wifi related stuff - they are overridden by gn -args="use_wf200=true" - sl_wfx_config_softap = false - sl_wfx_config_scan = true - - # Argument to force enable WPA3 security on rs91x - rs91x_wpa3_transition = true - - #default WiFi SSID - chip_default_wifi_ssid = "" - - #default Wifi Password - chip_default_wifi_psk = "" - # The EnableKey in hex string format used by TestEventTrigger command in # GeneralDiagnostics cluster. The length of the string should be 16 bytes. sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF" @@ -50,10 +38,7 @@ assert(chip_enable_wifi) silabs_plat_dir = "${chip_root}/src/platform/silabs" silabs_plat_si91x_wifi_dir = "${chip_root}/src/platform/silabs/SiWx917/wifi" -import("${silabs_common_plat_dir}/args.gni") config("chip_examples_project_config") { - include_dirs = [ "project_include" ] - # Link options that provide a replacement for dynamic memory operations in standard # library with the sl_memory_manager in platform code. ldflags = [ @@ -131,54 +116,22 @@ config("siwx917-common-config") { ldflags = [ "-Wl,--no-warn-rwx-segment" ] } -config("silabs-wifi-config") { - defines = [] - include_dirs = [] - - if (chip_default_wifi_ssid != "") { - defines += [ - "SL_ONNETWORK_PAIRING=1", - "SL_WIFI_SSID=\"${chip_default_wifi_ssid}\"", - ] - } - if (chip_default_wifi_psk != "") { - assert(chip_default_wifi_ssid != "", - "ssid can't be null if psk is provided") - defines += [ "SL_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] - } - - if (sl_wfx_config_softap) { - defines += [ "SL_WFX_CONFIG_SOFTAP" ] - } - - if (sl_wfx_config_scan) { - defines += [ "SL_WFX_CONFIG_SCAN" ] - } - - if (chip_enable_wifi_ipv4) { - defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4" ] - } - - if (rs91x_wpa3_transition) { - defines += [ "WIFI_ENABLE_SECURITY_WPA3_TRANSITION=1" ] - } -} - source_set("siwx917-common") { deps = [ "${silabs_common_plat_dir}/provision:storage" ] defines = [] public_deps = [] + public_configs = [ ":siwx917-common-config", - "${efr32_sdk_build_root}:silabs_config", + "${silabs_sdk_build_root}:silabs_config", ":chip_examples_project_config", ] include_dirs = [ - ".", - "SiWx917/", "${silabs_plat_dir}/wifi", + "${silabs_common_plat_dir}/wifi", "${silabs_plat_si91x_wifi_dir}", + "${silabs_common_plat_dir}", ] #TO-DO Cleanup to be done for all the wifi files into common folder @@ -189,12 +142,6 @@ source_set("siwx917-common") { "${silabs_common_plat_dir}/SoftwareFaultReports.cpp", "${silabs_common_plat_dir}/silabs_utils.cpp", "${silabs_common_plat_dir}/syscalls_stubs.cpp", - "${silabs_common_plat_dir}/wifi/wfx_notify.cpp", - "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp", - "${silabs_plat_dir}/wifi/dhcp_client.cpp", - "${silabs_plat_si91x_wifi_dir}/ethernetif.cpp", - "${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp", - "SiWx917/sl_wifi_if.cpp", ] if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) { @@ -219,10 +166,6 @@ source_set("siwx917-common") { sources += [ "${silabs_common_plat_dir}/MemMonitoring.cpp" ] } - if (chip_enable_wifi) { - public_configs += [ ":silabs-wifi-config" ] - } - if (chip_build_libshell) { deps += [ ":matter-shell" ] diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp deleted file mode 100644 index 47c9aa51cd..0000000000 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ /dev/null @@ -1,955 +0,0 @@ -/* - * - * Copyright (c) 2023 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. - */ - -/* - * This file implements the interface to the wifi sdk - */ - -#include -#include -#include - -#if (SL_MATTER_GN_BUILD == 0) -#include "sl_matter_wifi_config.h" -#endif // SL_MATTER_GN_BUILD - -#include "FreeRTOS.h" -#include "ble_config.h" -#include "dhcp_client.h" -#include "event_groups.h" -#include "sl_board_configuration.h" -#include "sl_status.h" -#include "task.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" - -#include -#include -#include -#include -#include -#include - -extern "C" { -#include "sl_net.h" -#include "sl_si91x_driver.h" -#include "sl_si91x_host_interface.h" -#include "sl_si91x_types.h" -#include "sl_wifi.h" -#include "sl_wifi_callback_framework.h" -#include "sl_wifi_constants.h" -#include "sl_wifi_types.h" -#include "sl_wlan_config.h" -#include "wfx_host_events.h" -#if SL_MBEDTLS_USE_TINYCRYPT -#include "sl_si91x_constants.h" -#include "sl_si91x_trng.h" -#endif // SL_MBEDTLS_USE_TINYCRYPT -} - -#if (EXP_BOARD) -#include "rsi_bt_common_apis.h" -#endif - -#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE -#include "rsi_rom_power_save.h" -#include "sl_si91x_button_pin_config.h" -#include "sl_si91x_power_manager.h" - -// [SLC-TEMP] Adding power manager include until we update wiseconnect version and upstream the changes -#include "sl_si91x_power_manager.h" - -namespace { -// TODO: should be removed once we are getting the press interrupt for button 0 with sleep -#define BUTTON_PRESSED 1 -bool btn0_pressed = false; - -#ifdef ENABLE_CHIP_SHELL -bool ps_requirement_added = false; -#endif // ENABLE_CHIP_SHELL -} // namespace -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE - -#define ADV_SCAN_THRESHOLD -40 -#define ADV_RSSI_TOLERANCE_THRESHOLD 5 -#define ADV_ACTIVE_SCAN_DURATION 15 -#define ADV_PASSIVE_SCAN_DURATION 20 -#define ADV_MULTIPROBE 1 -#define ADV_SCAN_PERIODICITY 10 - -// TODO: Confirm that this value works for size and timing -#define WFX_QUEUE_SIZE 10 - -// TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else. -#define WIFI_SCAN_TIMEOUT_TICK 10000 - -#if !defined(MIN) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif - -WfxRsi_t wfx_rsi; - -bool hasNotifiedIPV6 = false; -#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) -bool hasNotifiedIPV4 = false; -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ -bool hasNotifiedWifiConnectivity = false; - -volatile bool scan_results_complete = false; -volatile bool bg_scan_results_complete = false; -extern osSemaphoreId_t sl_rs_ble_init_sem; -static wfx_wifi_scan_ext_t temp_reset; -volatile sl_status_t callback_status = SL_STATUS_OK; -// Scan semaphore -static osSemaphoreId_t sScanSemaphore; -// DHCP Poll timer -static osTimerId_t sDHCPTimer; -static osMessageQueueId_t sWifiEventQueue = NULL; - -static void DHCPTimerEventHandler(void * arg) -{ - WfxEvent_t event; - event.eventType = WFX_EVT_DHCP_POLL; - WfxPostEvent(&event); -} - -static void CancelDHCPTimer(void) -{ - osStatus_t status; - - // Check if timer started - if (!osTimerIsRunning(sDHCPTimer)) - { - ChipLogDetail(DeviceLayer, "CancelDHCPTimer: timer not running"); - return; - } - - status = osTimerStop(sDHCPTimer); - if (status != osOK) - { - ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer: %d", status); - } -} - -static void StartDHCPTimer(uint32_t timeout) -{ - osStatus_t status; - - // Cancel timer if already started - CancelDHCPTimer(); - - status = osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)); - if (status != osOK) - { - ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer: %d", status); - } -} - -/****************************************************************** - * @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap) - * @brief - * Getting the AP details - * @param[in] ap: access point - * @return - * status - *********************************************************************/ -int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) -{ - sl_status_t status = SL_STATUS_OK; - int32_t rssi = 0; - ap->ssid_length = wfx_rsi.sec.ssid_length; - ap->security = wfx_rsi.sec.security; - ap->chan = wfx_rsi.ap_chan; - chip::Platform::CopyString(ap->ssid, ap->ssid_length, wfx_rsi.sec.ssid); - memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_LEN); - sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); - ap->rssi = rssi; - return status; -} - -/****************************************************************** - * @fn int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t *extra_info) - * @brief - * Getting the AP extra details - * @param[in] extra info: access point extra information - * @return - * status - *********************************************************************/ -int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) -{ - sl_status_t status = SL_STATUS_OK; - sl_wifi_statistics_t test = { 0 }; - status = sl_wifi_get_statistics(SL_WIFI_CLIENT_INTERFACE, &test); - VERIFY_STATUS_AND_RETURN(status); - extra_info->beacon_lost_count = test.beacon_lost_count - temp_reset.beacon_lost_count; - extra_info->beacon_rx_count = test.beacon_rx_count - temp_reset.beacon_rx_count; - extra_info->mcast_rx_count = test.mcast_rx_count - temp_reset.mcast_rx_count; - extra_info->mcast_tx_count = test.mcast_tx_count - temp_reset.mcast_tx_count; - extra_info->ucast_rx_count = test.ucast_rx_count - temp_reset.ucast_rx_count; - extra_info->ucast_tx_count = test.ucast_tx_count - temp_reset.ucast_tx_count; - extra_info->overrun_count = test.overrun_count - temp_reset.overrun_count; - return status; -} - -/****************************************************************** - * @fn int32_t wfx_rsi_reset_count(void) - * @brief - * Getting the driver reset count - * @param[in] None - * @return - * status - *********************************************************************/ -int32_t wfx_rsi_reset_count(void) -{ - sl_wifi_statistics_t test = { 0 }; - sl_status_t status = SL_STATUS_OK; - status = sl_wifi_get_statistics(SL_WIFI_CLIENT_INTERFACE, &test); - VERIFY_STATUS_AND_RETURN(status); - temp_reset.beacon_lost_count = test.beacon_lost_count; - temp_reset.beacon_rx_count = test.beacon_rx_count; - temp_reset.mcast_rx_count = test.mcast_rx_count; - temp_reset.mcast_tx_count = test.mcast_tx_count; - temp_reset.ucast_rx_count = test.ucast_rx_count; - temp_reset.ucast_tx_count = test.ucast_tx_count; - temp_reset.overrun_count = test.overrun_count; - return status; -} - -/****************************************************************** - * @fn wfx_rsi_disconnect(void) - * @brief - * Getting the driver disconnect status - * @param[in] None - * @return - * status - *********************************************************************/ -int32_t wfx_rsi_disconnect(void) -{ - return sl_wifi_disconnect(SL_WIFI_CLIENT_INTERFACE); -} - -sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t result_length, void * arg) -{ - WfxEvent_t WfxEvent; - - wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING); - if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) - { - callback_status = *(sl_status_t *) result; - ChipLogError(DeviceLayer, "join_callback_handler: failed: 0x%lx", static_cast(callback_status)); - wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED); - wfx_retry_connection(++wfx_rsi.join_retries); - return SL_STATUS_FAIL; - } - /* - * Join was complete - Do the DHCP - */ - ChipLogDetail(DeviceLayer, "join_callback_handler: success"); - memset(&temp_reset, 0, sizeof(temp_reset)); - wfx_rsi.join_retries = 0; - callback_status = SL_STATUS_OK; - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); - return SL_STATUS_OK; -} - -#if CHIP_CONFIG_ENABLE_ICD_SERVER -#if SLI_SI91X_MCU_INTERFACE -// Required to invoke button press event during sleep as falling edge is not detected -void sl_si91x_invoke_btn_press_event(void) -{ - // TODO: should be removed once we are getting the press interrupt for button 0 with sleep - if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed) - { - sl_button_on_change(SL_BUTTON_BTN0_NUMBER, BUTTON_PRESSED); - btn0_pressed = true; - } - if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN)) - { - btn0_pressed = false; - } - -#ifdef ENABLE_CHIP_SHELL - // Checking the UULP PIN 1 status to reinit the UART and not allow the device to go to sleep - if (RSI_NPSSGPIO_GetPin(RTE_UULP_GPIO_1_PIN)) - { - if (!ps_requirement_added) - { - sl_si91x_power_manager_add_ps_requirement(SL_SI91X_POWER_MANAGER_PS4); - ps_requirement_added = true; - } - } - else - { - if (ps_requirement_added) - { - sl_si91x_power_manager_remove_ps_requirement(SL_SI91X_POWER_MANAGER_PS4); - ps_requirement_added = false; - } - } -#endif // ENABLE_CHIP_SHELL -} -#endif // SLI_SI91X_MCU_INTERFACE - -/****************************************************************** - * @fn wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) - * @brief - * Setting the RS911x in DTIM sleep based mode - * - * @param[in] sl_si91x_ble_state : State to set for the BLE - * @param[in] sl_si91x_wifi_state : State to set for the WiFi - * @return - * None - *********************************************************************/ -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) -{ - int32_t status; - - status = rsi_bt_power_save_profile(sl_si91x_ble_state, 0); - if (status != RSI_SUCCESS) - { - ChipLogError(DeviceLayer, "rsi_bt_power_save_profile failed: 0x%lx", static_cast(status)); - return status; - } - sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state }; - status = sl_wifi_set_performance_profile(&wifi_profile); - if (status != RSI_SUCCESS) - { - ChipLogError(DeviceLayer, "sl_wifi_set_performance_profile failed: 0x%lx", static_cast(status)); - return status; - } - - return status; -} -#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ - -/************************************************************************************* - * @fn static int32_t wfx_wifi_rsi_init(void) - * @brief - * Wifi initialization called from app main - * @param[in] None - * @return - * None - *****************************************************************************************/ -int32_t wfx_wifi_rsi_init(void) -{ - ChipLogDetail(DeviceLayer, "wfx_wifi_rsi_init: started"); - sl_status_t status; - status = sl_wifi_init(&config, NULL, sl_wifi_default_event_handler); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - // Create Sempaphore for scan - sScanSemaphore = osSemaphoreNew(1, 0, NULL); - VerifyOrReturnError(sScanSemaphore != NULL, SL_STATUS_ALLOCATION_FAILED); - - // Create the message queue - sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); - VerifyOrReturnError(sWifiEventQueue != NULL, SL_STATUS_ALLOCATION_FAILED); - - // Create timer for DHCP polling - // TODO: Use LWIP timer instead of creating a new one here - sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, NULL, NULL); - VerifyOrReturnError(sDHCPTimer != NULL, SL_STATUS_ALLOCATION_FAILED); - - return status; -} - -/************************************************************************************* - * @fn static void sl_print_firmware_version(sl_wifi_firmware_version_t*) - * @brief - * To print the firmware version - * @param[in] sl_wifi_firmware_version_t* - * @return - * None - *****************************************************************************************/ -static void sl_print_firmware_version(sl_wifi_firmware_version_t * firmware_version) -{ - ChipLogDetail(DeviceLayer, "Firmware version is: %x%x.%d.%d.%d.%d.%d.%d", firmware_version->chip_id, firmware_version->rom_id, - firmware_version->major, firmware_version->minor, firmware_version->security_version, firmware_version->patch_num, - firmware_version->customer_id, firmware_version->build_num); -} - -/************************************************************************************* - * @fn static int32_t wfx_rsi_init(void) - * @brief - * driver initialization - * @param[in] None - * @return - * None - *****************************************************************************************/ -static sl_status_t wfx_rsi_init(void) -{ - sl_status_t status; - -#ifndef SLI_SI91X_MCU_INTERFACE - status = wfx_wifi_rsi_init(); - if (status != SL_STATUS_OK) - { - ChipLogError(DeviceLayer, "wfx_rsi_init failed: 0x%lx", static_cast(status)); - return status; - } -#else // For SoC -#if CHIP_CONFIG_ENABLE_ICD_SERVER - uint8_t xtal_enable = 1; - status = sl_si91x_m4_ta_secure_handshake(SL_SI91X_ENABLE_XTAL, 1, &xtal_enable, 0, NULL); - if (status != SL_STATUS_OK) - { - ChipLogError(DeviceLayer, "sl_si91x_m4_ta_secure_handshake failed: 0x%lx", static_cast(status)); - return status; - } -#ifdef ENABLE_CHIP_SHELL - // While using the matter shell with the ICD server, the GPIO 1 is used to check the UULP PIN 1 status - // since UART doesn't act as a wakeup source in the UULP mode - /*Configuring the NPS GPIO 1*/ - RSI_NPSSGPIO_SetPinMux(RTE_UULP_GPIO_1_PIN, 0); - /*Configure the NPSS GPIO direction to input */ - RSI_NPSSGPIO_SetDir(RTE_UULP_GPIO_1_PIN, 1); - /*Enable the REN*/ - RSI_NPSSGPIO_InputBufferEn(RTE_UULP_GPIO_1_PIN, 1); -#endif // ENABLE_CHIP_SHELL -#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ -#endif /* SLI_SI91X_MCU_INTERFACE */ - - sl_wifi_firmware_version_t version = { 0 }; - status = sl_wifi_get_firmware_version(&version); - if (status != SL_STATUS_OK) - { - ChipLogError(DeviceLayer, "sl_wifi_get_firmware_version failed: 0x%lx", static_cast(status)); - return status; - } - sl_print_firmware_version(&version); - - status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]); - if (status != SL_STATUS_OK) - { - ChipLogDetail(DeviceLayer, "sl_wifi_get_mac_address failed: 0x%lx", static_cast(status)); - return status; - } - -#ifdef SL_MBEDTLS_USE_TINYCRYPT - const uint32_t trngKey[TRNG_KEY_SIZE] = { 0x16157E2B, 0xA6D2AE28, 0x8815F7AB, 0x3C4FCF09 }; - - // To check the Entropy of TRNG and verify TRNG functioning. - status = sl_si91x_trng_entropy(); - if (status != SL_STATUS_OK) - { - ChipLogError(DeviceLayer, "sl_si91x_trng_entropy failed: 0x%lx", static_cast(status)); - return status; - } - - // Initiate and program the key required for TRNG hardware engine - status = sl_si91x_trng_program_key((uint32_t *) trngKey, TRNG_KEY_SIZE); - if (status != SL_STATUS_OK) - { - ChipLogError(DeviceLayer, "sl_si91x_trng_program_key failed: 0x%lx", static_cast(status)); - return status; - } -#endif // SL_MBEDTLS_USE_TINYCRYPT - - wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY; - osSemaphoreRelease(sl_rs_ble_init_sem); - return status; -} - -/************************************************************************************* - * @fn void wfx_show_err(char *msg) - * @brief - * driver shows error message - * @param[in] msg - * @return - * None - *****************************************************************************************/ -void wfx_show_err(char * msg) -{ - ChipLogError(DeviceLayer, "wfx_show_err: message: %s", 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) -{ - if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) - { - callback_status = *(sl_status_t *) scan_result; - ChipLogError(DeviceLayer, "scan_callback_handler: failed: 0x%lx", static_cast(callback_status)); - scan_results_complete = true; -#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION - wfx_rsi.sec.security = WFX_SEC_WPA3; -#else - wfx_rsi.sec.security = WFX_SEC_WPA2; -#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ - - osSemaphoreRelease(sScanSemaphore); - return SL_STATUS_FAIL; - } - wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; - wfx_rsi.ap_chan = scan_result->scan_info[0].rf_channel; - memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, BSSID_LEN); - switch (scan_result->scan_info[0].security_mode) - { - case SL_WIFI_OPEN: - wfx_rsi.sec.security = WFX_SEC_NONE; - break; - case SL_WIFI_WPA: - case SL_WIFI_WPA_ENTERPRISE: - wfx_rsi.sec.security = WFX_SEC_WPA; - break; - case SL_WIFI_WPA_WPA2_MIXED: - case SL_WIFI_WPA2: - case SL_WIFI_WPA2_ENTERPRISE: - wfx_rsi.sec.security = WFX_SEC_WPA2; - break; - case SL_WIFI_WEP: - wfx_rsi.sec.security = WFX_SEC_WEP; - break; - case SL_WIFI_WPA3_TRANSITION: -#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION - case SL_WIFI_WPA3: - wfx_rsi.sec.security = WFX_SEC_WPA3; -#else - wfx_rsi.sec.security = WFX_SEC_WPA2; -#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ - break; - default: - wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; - break; - } - wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED; - scan_results_complete = true; - - osSemaphoreRelease(sScanSemaphore); - return SL_STATUS_OK; -} - -sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) -{ - SL_WIFI_ARGS_CHECK_NULL_POINTER(scan_result); - VerifyOrReturnError(wfx_rsi.scan_cb != NULL, SL_STATUS_INVALID_HANDLE); - - wfx_wifi_scan_result_t cur_scan_result; - for (int idx = 0; idx < (int) scan_result->scan_count; idx++) - { - memset(&cur_scan_result, 0, sizeof(cur_scan_result)); - - cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, - chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); - // cur_scan_result.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the cur_scan_result.ssid_length calculated above - chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination - - // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid - if (wfx_rsi.scan_ssid != NULL && - (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) != - CMP_SUCCESS)) - { - continue; - } - cur_scan_result.security = static_cast(scan_result->scan_info[idx].security_mode); - cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val; - memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN); - wfx_rsi.scan_cb(&cur_scan_result); - - // if user has not provided the ssid, then call the callback for each scan result - if (wfx_rsi.scan_ssid == NULL) - { - continue; - } - break; - } - - // cleanup and return - wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED; - wfx_rsi.scan_cb((wfx_wifi_scan_result_t *) 0); - wfx_rsi.scan_cb = nullptr; - if (wfx_rsi.scan_ssid) - { - chip::Platform::MemoryFree(wfx_rsi.scan_ssid); - wfx_rsi.scan_ssid = NULL; - } - return SL_STATUS_OK; -} - -sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * result, uint32_t result_length, void * arg) -{ - callback_status = show_scan_results(result); - bg_scan_results_complete = true; - osSemaphoreRelease(sScanSemaphore); - return SL_STATUS_OK; -} -/*************************************************************************************** - * @fn static void wfx_rsi_save_ap_info(void) - * @brief - * Saving the details of the AP - * @param[in] None - * @return - * None - *******************************************************************************************/ -static void wfx_rsi_save_ap_info(void) // translation -{ - sl_status_t status = SL_STATUS_OK; -#ifndef EXP_BOARD - // TODO: this changes will be reverted back after the Silabs WiFi SDK team fix the scan API - sl_wifi_scan_configuration_t wifi_scan_configuration = default_wifi_scan_configuration; -#endif - sl_wifi_ssid_t ssid_arg; - memset(&ssid_arg, 0, sizeof(ssid_arg)); - ssid_arg.length = chip::min(wfx_rsi.sec.ssid_length, sizeof(ssid_arg.value) - 1); - chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length + 1, wfx_rsi.sec.ssid); // +1 for null termination - sl_wifi_set_scan_callback(scan_callback_handler, NULL); - scan_results_complete = false; -#ifndef EXP_BOARD - // TODO: this changes will be reverted back after the Silabs WiFi SDK team fix the scan API - status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, &ssid_arg, &wifi_scan_configuration); -#endif - if (SL_STATUS_IN_PROGRESS == status) - { - osSemaphoreAcquire(sScanSemaphore, WIFI_SCAN_TIMEOUT_TICK); - } -} - -/******************************************************************************************** - * @fn static void wfx_rsi_do_join(void) - * @brief - * Start an async Join command - * @return - * None - **********************************************************************************************/ -static sl_status_t wfx_rsi_do_join(void) -{ - ReturnErrorCodeIf((wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)), SL_STATUS_IN_PROGRESS); - sl_status_t status = SL_STATUS_OK; - sl_wifi_client_configuration_t ap; - memset(&ap, 0, sizeof(ap)); - - switch (wfx_rsi.sec.security) - { - case WFX_SEC_WEP: - ap.security = SL_WIFI_WEP; - break; - case WFX_SEC_WPA: - ap.security = SL_WIFI_WPA_WPA2_MIXED; - break; - case WFX_SEC_WPA2: -#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION - ap.security = SL_WIFI_WPA3_TRANSITION; - break; - case WFX_SEC_WPA3: - ap.security = SL_WIFI_WPA3_TRANSITION; -#else - ap.security = SL_WIFI_WPA_WPA2_MIXED; -#endif // WIFI_ENABLE_SECURITY_WPA3_TRANSITION - break; - case WFX_SEC_NONE: - ap.security = SL_WIFI_OPEN; - break; - default: - ChipLogError(DeviceLayer, "wfx_rsi_do_join: unknown security type."); - return status; - } - /* - * Join the network - */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; - status = sl_wifi_set_join_callback(join_callback_handler, NULL); - VerifyOrReturnError(status == SL_STATUS_OK, status); - -#if CHIP_CONFIG_ENABLE_ICD_SERVER - // Setting the listen interval to 0 which will set it to DTIM interval - sl_wifi_listen_interval_t sleep_interval = { .listen_interval = 0 }; - status = sl_wifi_set_listen_interval(SL_WIFI_CLIENT_INTERFACE, sleep_interval); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 }; - status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config); - VerifyOrReturnError(status == SL_STATUS_OK, status); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER - sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID; - status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], wfx_rsi.sec.passkey_length); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - uint32_t timeout_ms = 0; - ap.ssid.length = wfx_rsi.sec.ssid_length; - ap.encryption = SL_WIFI_NO_ENCRYPTION; - ap.credential_id = id; - memcpy((char *) &ap.ssid.value[0], wfx_rsi.sec.ssid, wfx_rsi.sec.ssid_length); - ChipLogDetail(DeviceLayer, "wfx_rsi_do_join: SSID: %s, SECURITY: %d(%d)", ap.ssid.value, ap.security, wfx_rsi.sec.security); - - status = sl_wifi_connect(SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms); - // sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress - // after the initial scan is done, the scan does not check for SSID - ReturnErrorCodeIf((status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS), status); - - // failure only happens when the firmware returns an error - ChipLogError(DeviceLayer, "wfx_rsi_do_join: sl_wifi_connect failed: 0x%lx", static_cast(status)); - VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status); - - wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); - ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: retry attempt %d", wfx_rsi.join_retries); - wfx_retry_connection(++wfx_rsi.join_retries); - - WfxEvent_t event; - event.eventType = WFX_EVT_STA_START_JOIN; - WfxPostEvent(&event); - - return status; -} - -/// NotifyConnectivity -/// @brief Notify the application about the connectivity status if it has not been notified yet. -/// Helper function for HandleDHCPPolling. -void NotifyConnectivity(void) -{ - VerifyOrReturn(!hasNotifiedWifiConnectivity); - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); - hasNotifiedWifiConnectivity = true; -} - -void HandleDHCPPolling(void) -{ - struct netif * sta_netif; - WfxEvent_t event; - - sta_netif = wfx_get_netif(SL_WFX_STA_INTERFACE); - if (sta_netif == NULL) - { - // TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state - ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"); - return; - } -#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - uint8_t dhcp_state = dhcpclient_poll(sta_netif); - if (dhcp_state == DHCP_ADDRESS_ASSIGNED && !hasNotifiedIPV4) - { - wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr); - hasNotifiedIPV4 = true; - event.eventType = WFX_EVT_STA_DHCP_DONE; - WfxPostEvent(&event); - NotifyConnectivity(); - } - else if (dhcp_state == DHCP_OFF) - { - wfx_ip_changed_notify(IP_STATUS_FAIL); - hasNotifiedIPV4 = false; - } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - /* Checks if the assigned IPv6 address is preferred by evaluating - * the first block of IPv6 address ( block 0) - */ - if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6) - { - char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 }; - VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != NULL); - ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr); - wfx_ipv6_notify(GET_IPV6_SUCCESS); - hasNotifiedIPV6 = true; - event.eventType = WFX_EVT_STA_DHCP_DONE; - WfxPostEvent(&event); - NotifyConnectivity(); - } -} - -void WfxPostEvent(WfxEvent_t * event) -{ - sl_status_t status = osMessageQueuePut(sWifiEventQueue, event, 0, 0); - - if (status != osOK) - { - ChipLogError(DeviceLayer, "WfxPostEvent: failed to post event: 0x%lx", static_cast(status)); - // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. - } -} - -/// ResetDHCPNotificationFlags -/// @brief Reset the flags that are used to notify the application about DHCP connectivity -/// and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. -void ResetDHCPNotificationFlags(void) -{ - WfxEvent_t outEvent; - -#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - hasNotifiedIPV4 = false; -#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4 - hasNotifiedIPV6 = false; - hasNotifiedWifiConnectivity = false; - - outEvent.eventType = WFX_EVT_STA_DO_DHCP; - WfxPostEvent(&outEvent); -} - -void ProcessEvent(WfxEvent_t inEvent) -{ - // Process event - switch (inEvent.eventType) - { - case WFX_EVT_STA_CONN: - ChipLogDetail(DeviceLayer, "WFX_EVT_STA_CONN"); - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED; - ResetDHCPNotificationFlags(); - wfx_lwip_set_sta_link_up(); - /* We need to get AP Mac - TODO */ - // Uncomment once the hook into MATTER is moved to IP connectivty instead - // of AP connectivity. - // wfx_connected_notify(0, &wfx_rsi.ap_mac); // This - // is independant of IP connectivity. - break; - case WFX_EVT_STA_DISCONN: - ChipLogDetail(DeviceLayer, "WFX_EVT_STA_DISCONN"); - // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something - wfx_rsi.dev_state &= - ~(WFX_RSI_ST_STA_READY | WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE); - /* TODO: Implement disconnect notify */ - ResetDHCPNotificationFlags(); - wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) -> - // wfx_ip_changed_notify(0) for IPV4 -#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - wfx_ip_changed_notify(IP_STATUS_FAIL); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - wfx_ipv6_notify(GET_IPV6_FAIL); - break; - case WFX_EVT_AP_START: - // TODO: Currently unimplemented - break; - case WFX_EVT_AP_STOP: - // TODO: Currently unimplemented - break; - case WFX_EVT_SCAN: -#ifdef SL_WFX_CONFIG_SCAN - if (!(wfx_rsi.dev_state & WFX_RSI_ST_SCANSTARTED)) - { - ChipLogDetail(DeviceLayer, "WFX_EVT_SCAN"); - sl_wifi_scan_configuration_t wifi_scan_configuration; - memset(&wifi_scan_configuration, 0, sizeof(wifi_scan_configuration)); - - // TODO: Add scan logic - sl_wifi_advanced_scan_configuration_t advanced_scan_configuration = { 0 }; - int32_t status; - advanced_scan_configuration.active_channel_time = ADV_ACTIVE_SCAN_DURATION; - advanced_scan_configuration.passive_channel_time = ADV_PASSIVE_SCAN_DURATION; - advanced_scan_configuration.trigger_level = ADV_SCAN_THRESHOLD; - advanced_scan_configuration.trigger_level_change = ADV_RSSI_TOLERANCE_THRESHOLD; - advanced_scan_configuration.enable_multi_probe = ADV_MULTIPROBE; - status = sl_wifi_set_advanced_scan_configuration(&advanced_scan_configuration); - if (SL_STATUS_OK != status) - { - // TODO: Seems like Chipdie should be called here, the device should be initialized here - ChipLogError(DeviceLayer, "sl_wifi_set_advanced_scan_configuration failed: 0x%lx", static_cast(status)); - return; - } - - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) - { - /* Terminate with end of scan which is no ap sent back */ - wifi_scan_configuration.type = SL_WIFI_SCAN_TYPE_ADV_SCAN; - wifi_scan_configuration.periodic_scan_interval = ADV_SCAN_PERIODICITY; - } - else - { - wifi_scan_configuration = default_wifi_scan_configuration; - } - sl_wifi_set_scan_callback(bg_scan_callback_handler, NULL); - scan_results_complete = false; - wfx_rsi.dev_state |= WFX_RSI_ST_SCANSTARTED; - status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, NULL, &wifi_scan_configuration); - if (SL_STATUS_IN_PROGRESS == status) - { - osSemaphoreAcquire(sScanSemaphore, WIFI_SCAN_TIMEOUT_TICK); - } - } - break; -#endif /* SL_WFX_CONFIG_SCAN */ - case WFX_EVT_STA_START_JOIN: - // saving the AP related info - wfx_rsi_save_ap_info(); - // Joining to the network - wfx_rsi_do_join(); - break; - case WFX_EVT_STA_DO_DHCP: - StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL); - break; - case WFX_EVT_STA_DHCP_DONE: - CancelDHCPTimer(); - break; - case WFX_EVT_DHCP_POLL: - HandleDHCPPolling(); - default: - break; - } -} - -/********************************************************************************* - * @fn void wfx_rsi_task(void *arg) - * @brief - * The main WLAN task - started by wfx_wifi_start() that interfaces with RSI. - * The rest of RSI stuff come in call-backs. - * The initialization has been already done. - * @param[in] arg: - * @return - * None - **********************************************************************************/ -/* ARGSUSED */ -void wfx_rsi_task(void * arg) -{ - (void) arg; - sl_status_t status = wfx_rsi_init(); - - WfxEvent_t wfxEvent; - if (status != RSI_SUCCESS) - { - ChipLogError(DeviceLayer, "wfx_rsi_task: wfx_rsi_init failed: 0x%lx", static_cast(status)); - return; - } - wfx_lwip_start(); - wfx_started_notify(); - - ChipLogDetail(DeviceLayer, "wfx_rsi_task: starting event loop"); - for (;;) - { - status = osMessageQueueGet(sWifiEventQueue, &wfxEvent, NULL, osWaitForever); - if (status == osOK) - { - ProcessEvent(wfxEvent); - } - else - { - ChipLogError(DeviceLayer, "wfx_rsi_task: get event failed: 0x%lx", static_cast(status)); - } - } -} - -#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 -/******************************************************************************************** - * @fn void wfx_dhcp_got_ipv4(uint32_t ip) - * @brief - * Acquire the new ip address - * @param[in] ip: internet protocol - * @return - * None - **********************************************************************************************/ -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; - 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 */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_DHCP_DONE; - wfx_ip_changed_notify(IP_STATUS_SUCCESS); - wfx_rsi.dev_state |= WFX_RSI_ST_STA_READY; -} -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h b/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h deleted file mode 100644 index cd605b0f0a..0000000000 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h +++ /dev/null @@ -1,102 +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. - */ - -#ifndef RSI_CONFIG_H -#define RSI_CONFIG_H - -#include "ble_config.h" -#if SLI_SI91X_MCU_INTERFACE -#include "rsi_wisemcu_hardware_setup.h" -#endif // SLI_SI91X_MCU_INTERFACE -#include "sl_wifi_device.h" - -//! Enable feature -#define RSI_ENABLE 1 -//! Disable feature -#define RSI_DISABLE 0 - -static const sl_wifi_device_configuration_t config = { - .boot_option = LOAD_NWP_FW, - .mac_address = NULL, - .band = SL_SI91X_WIFI_BAND_2_4GHZ, - .region_code = US, - .boot_config = { .oper_mode = SL_SI91X_CLIENT_MODE, - .coex_mode = SL_SI91X_WLAN_BLE_MODE, - .feature_bit_map = -#ifdef SLI_SI91X_MCU_INTERFACE - (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE), -#else - (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_AGGREGATION), -#endif - .tcp_ip_feature_bit_map = (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_DNS_CLIENT | - SL_SI91X_TCP_IP_FEAT_SSL | SL_SI91X_TCP_IP_FEAT_BYPASS -#ifdef ipv6_FEATURE_REQUIRED - | SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6 -#endif - | SL_SI91X_TCP_IP_FEAT_ICMP | SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID), - .custom_feature_bit_map = (SL_SI91X_CUSTOM_FEAT_EXTENTION_VALID | RSI_CUSTOM_FEATURE_BIT_MAP), - .ext_custom_feature_bit_map = (RSI_EXT_CUSTOM_FEATURE_BIT_MAP | (SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE) -#if (defined A2DP_POWER_SAVE_ENABLE) - | SL_SI91X_EXT_FEAT_XTAL_CLK_ENABLE(2) -#endif - ), - .bt_feature_bit_map = (RSI_BT_FEATURE_BITMAP -#if (RSI_BT_GATT_ON_CLASSIC) - | SL_SI91X_BT_ATT_OVER_CLASSIC_ACL /* to support att over classic acl link */ -#endif - ), -#ifdef RSI_PROCESS_MAX_RX_DATA - .ext_tcp_ip_feature_bit_map = - (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID | SL_SI91X_EXT_TCP_MAX_RECV_LENGTH), -#else - .ext_tcp_ip_feature_bit_map = (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID), -#endif - //! ENABLE_BLE_PROTOCOL in bt_feature_bit_map - .ble_feature_bit_map = - ((SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) | - SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) | - SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) | - SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC)) | - SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENTION_VALID | SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) | - SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) | SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE -#if RSI_BLE_GATT_ASYNC_ENABLE - | SL_SI91X_BLE_GATT_ASYNC_ENABLE -#endif - ), - - .ble_ext_feature_bit_map = ((SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) | - SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES)) -#if RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST - | SL_SI91X_BLE_INDICATE_CONFIRMATION_FROM_HOST // indication response from app -#endif -#if RSI_BLE_MTU_EXCHANGE_FROM_HOST - | SL_SI91X_BLE_MTU_EXCHANGE_FROM_HOST // MTU Exchange request initiation from app -#endif -#if RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST - | (SL_SI91X_BLE_SET_SCAN_RESP_DATA_FROM_HOST) // Set SCAN Resp Data from app -#endif -#if RSI_BLE_DISABLE_CODED_PHY_FROM_HOST - | (SL_SI91X_BLE_DISABLE_CODED_PHY_FROM_HOST) // Disable Coded PHY from app -#endif -#if BLE_SIMPLE_GATT - | SL_SI91X_BLE_GATT_INIT -#endif - ), - .config_feature_bit_map = (SL_SI91X_FEAT_SLEEP_GPIO_SEL_BITMAP | RSI_CONFIG_FEATURE_BITMAP) } -}; - -#endif diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index d909cb1f88..fb41a5b309 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -27,9 +27,8 @@ #include "sl_memlcd.h" #include #if SL_WIFI && !SLI_SI91X_MCU_INTERFACE -#include "spi_multiplex.h" +#include #endif // SL_WIFI && !SLI_SI91X_MCU_INTERFACE -#include #include // Main Logo and App image diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 2d417c22c1..e0e7b45070 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -18,8 +18,8 @@ import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/app/icd/icd.gni") import("${chip_root}/src/lib/lib.gni") import("${chip_root}/src/platform/device.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_board.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/silabs_board.gni") declare_args() { enable_heap_monitoring = false @@ -27,19 +27,6 @@ declare_args() { # OTA timeout in seconds ota_periodic_query_timeout_sec = 86400 - # Wifi related stuff - they are overridden by gn -args="use_wf200=true" - sl_wfx_config_softap = false - sl_wfx_config_scan = true - - # Argument to force enable WPA3 security on rs91x - rs91x_wpa3_transition = true - - #default WiFi SSID - chip_default_wifi_ssid = "" - - #default Wifi Password - chip_default_wifi_psk = "" - # The EnableKey in hex string format used by TestEventTrigger command in # GeneralDiagnostics cluster. The length of the string should be 16 bytes. sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF" @@ -53,20 +40,6 @@ assert(!(use_rs9116 && chip_enable_openthread)) assert(!(use_SiWx917 && chip_enable_openthread)) assert(!(use_wf200 && chip_enable_openthread)) -if (chip_enable_wifi) { - assert(use_rs9116 || use_wf200 || use_SiWx917) - import("${chip_root}/src/platform/silabs/wifi_args.gni") - - if (use_rs9116) { - import("rs911x/rs911x.gni") - } else if (use_SiWx917) { - import("rs911x/rs9117.gni") - } - if (use_wf200) { - import("wf200/wf200.gni") - } -} - config("chip_examples_project_config") { include_dirs = [ "project_include" ] @@ -111,10 +84,10 @@ source_set("openthread_core_config_efr32_chip_examples") { if (chip_enable_openthread) { sources = [ "project_include/OpenThreadConfig.h" ] - public_deps = [ "${efr32_sdk_build_root}:efr32_sdk" ] + public_deps = [ "${silabs_sdk_build_root}:silabs_sdk" ] if (use_silabs_thread_lib) { - public_deps += [ "${efr32_sdk_build_root}:openthread_core_config_efr32" ] + public_deps += [ "${silabs_sdk_build_root}:openthread_core_config_efr32" ] } else { public_deps += [ "${chip_root}/third_party/openthread/platforms/efr32:openthread_core_config_efr32" ] } @@ -167,47 +140,13 @@ config("efr32-common-config") { ldflags = [ "-Wl,--no-warn-rwx-segment" ] } -config("silabs-wifi-config") { - defines = [] - include_dirs = [] - - if (chip_default_wifi_ssid != "") { - defines += [ - "SL_ONNETWORK_PAIRING=1", - "SL_WIFI_SSID=\"${chip_default_wifi_ssid}\"", - ] - } - if (chip_default_wifi_psk != "") { - assert(chip_default_wifi_ssid != "", - "ssid can't be null if psk is provided") - defines += [ "SL_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] - } - - if (sl_wfx_config_softap) { - defines += [ "SL_WFX_CONFIG_SOFTAP" ] - } - - if (sl_wfx_config_scan) { - defines += [ "SL_WFX_CONFIG_SCAN" ] - } - - if (chip_enable_wifi_ipv4) { - defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4" ] - } - - if (rs91x_wpa3_transition) { - # TODO: Change this macro once WF200 support is provided - defines += [ "WIFI_ENABLE_SECURITY_WPA3_TRANSITION=1" ] - } -} - source_set("efr32-common") { deps = [ "${silabs_common_plat_dir}/provision:storage" ] defines = [] public_deps = [] public_configs = [ ":efr32-common-config", - "${efr32_sdk_build_root}:silabs_config", + "${silabs_sdk_build_root}:silabs_config", ":chip_examples_project_config", ] @@ -265,32 +204,6 @@ source_set("efr32-common") { ] } - if (chip_enable_wifi) { - if (use_rs9116) { - sources += rs911x_src_plat - - # All the stuff from wiseconnect - sources += rs911x_src_sapi - include_dirs += rs911x_inc_plat - - #add compilation flags for rs991x build. This will be addressed directly in wiseconnect sdk in the next version release of that sdk - cflags = rs911x_cflags - } else if (use_SiWx917) { - sources += rs911x_src_plat - - # All the stuff from wiseconnect - sources += rs9117_src_sapi - include_dirs += rs9117_inc_plat - - #add compilation flags for rs991x build. This will be addressed directly in wiseconnect sdk in the next version release of that sdk - } else if (use_wf200) { - sources += wf200_plat_src - include_dirs += wf200_plat_incs - } - - public_configs += [ ":silabs-wifi-config" ] - } - if (chip_build_libshell) { deps += [ ":matter-shell" ] diff --git a/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp b/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp deleted file mode 120000 index 2f233ccc6c..0000000000 --- a/examples/platform/silabs/efr32/rs911x/sl_wifi_if.cpp +++ /dev/null @@ -1 +0,0 @@ -../../SiWx917/SiWx917/sl_wifi_if.cpp \ No newline at end of file diff --git a/examples/platform/silabs/efr32/rs911x/sl_wlan_config.h b/examples/platform/silabs/efr32/rs911x/sl_wlan_config.h deleted file mode 100644 index 2ce2060cd7..0000000000 --- a/examples/platform/silabs/efr32/rs911x/sl_wlan_config.h +++ /dev/null @@ -1,109 +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. - */ - -#ifndef RSI_CONFIG_H -#define RSI_CONFIG_H - -#include "ble_config.h" -#include "sl_wifi_device.h" - -//! Enable feature -#define RSI_ENABLE 1 -//! Disable feature -#define RSI_DISABLE 0 - -static const sl_wifi_device_configuration_t config = { - .boot_option = LOAD_NWP_FW, - .mac_address = NULL, - .band = SL_SI91X_WIFI_BAND_2_4GHZ, - .region_code = US, - .boot_config = { .oper_mode = SL_SI91X_CLIENT_MODE, - .coex_mode = SL_SI91X_WLAN_BLE_MODE, - .feature_bit_map = -#ifdef SLI_SI91X_MCU_INTERFACE - (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE), -#else - (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_AGGREGATION), -#endif - .tcp_ip_feature_bit_map = (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_DNS_CLIENT | - SL_SI91X_TCP_IP_FEAT_SSL | SL_SI91X_TCP_IP_FEAT_BYPASS -#ifdef ipv6_FEATURE_REQUIRED - | SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6 -#endif - | SL_SI91X_TCP_IP_FEAT_ICMP | SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID), - .custom_feature_bit_map = (SL_SI91X_CUSTOM_FEAT_EXTENTION_VALID | RSI_CUSTOM_FEATURE_BIT_MAP), - .ext_custom_feature_bit_map = ( -#ifdef SLI_SI917 - (RSI_EXT_CUSTOM_FEATURE_BIT_MAP) -#else // defaults -#ifdef SLI_SI91X_MCU_INTERFACE - (SL_SI91X_EXT_FEAT_256K_MODE | RSI_EXT_CUSTOM_FEATURE_BIT_MAP) -#else - (SL_SI91X_EXT_FEAT_384K_MODE | RSI_EXT_CUSTOM_FEATURE_BIT_MAP) -#endif -#endif - | (SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE) -#if (defined A2DP_POWER_SAVE_ENABLE) - | SL_SI91X_EXT_FEAT_XTAL_CLK_ENABLE(2) -#endif - ), - .bt_feature_bit_map = (RSI_BT_FEATURE_BITMAP -#if (RSI_BT_GATT_ON_CLASSIC) - | SL_SI91X_BT_ATT_OVER_CLASSIC_ACL /* to support att over classic acl link */ -#endif - ), -#ifdef RSI_PROCESS_MAX_RX_DATA - .ext_tcp_ip_feature_bit_map = - (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID | SL_SI91X_EXT_TCP_MAX_RECV_LENGTH), -#else - .ext_tcp_ip_feature_bit_map = (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID), -#endif - //! ENABLE_BLE_PROTOCOL in bt_feature_bit_map - .ble_feature_bit_map = - ((SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) | - SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) | - SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) | - SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC)) | - SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENTION_VALID | SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) | - SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) | SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE -#if RSI_BLE_GATT_ASYNC_ENABLE - | SL_SI91X_BLE_GATT_ASYNC_ENABLE -#endif - ), - - .ble_ext_feature_bit_map = ((SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) | - SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES)) -#if RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST - | SL_SI91X_BLE_INDICATE_CONFIRMATION_FROM_HOST // indication response from app -#endif -#if RSI_BLE_MTU_EXCHANGE_FROM_HOST - | SL_SI91X_BLE_MTU_EXCHANGE_FROM_HOST // MTU Exchange request initiation from app -#endif -#if RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST - | (SL_SI91X_BLE_SET_SCAN_RESP_DATA_FROM_HOST) // Set SCAN Resp Data from app -#endif -#if RSI_BLE_DISABLE_CODED_PHY_FROM_HOST - | (SL_SI91X_BLE_DISABLE_CODED_PHY_FROM_HOST) // Disable Coded PHY from app -#endif -#if BLE_SIMPLE_GATT - | SL_SI91X_BLE_GATT_INIT -#endif - ), - .config_feature_bit_map = (SL_SI91X_FEAT_SLEEP_GPIO_SEL_BITMAP | RSI_CONFIG_FEATURE_BITMAP) } -}; - -#endif diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_configuration.h b/examples/platform/silabs/efr32/wf200/sl_wfx_configuration.h deleted file mode 100644 index deb468d1a6..0000000000 --- a/examples/platform/silabs/efr32/wf200/sl_wfx_configuration.h +++ /dev/null @@ -1,30 +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. - */ - -#pragma once - -// SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS> Timeout period in milliseconds<250-10000> -// Default: 5000 -// Timeout period in milliseconds for requests. -#define SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS (5000) - -// WFx Secure Link configuration - -// SL_WFX_SLK_CURVE25519> Use crypto curves -// Default: 1 -// If this option is enabled ECDH crypto is used, KDF otherwise. -#define SL_WFX_SLK_CURVE25519 (1) diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_crypto.c b/examples/platform/silabs/efr32/wf200/sl_wfx_crypto.c deleted file mode 100644 index ddad3ec5b9..0000000000 --- a/examples/platform/silabs/efr32/wf200/sl_wfx_crypto.c +++ /dev/null @@ -1,409 +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. - */ - -#ifdef SL_WFX_USE_SECURE_LINK - -/* Includes */ - -#include "sl_wfx.h" -#include - -#include "mbedtls/ccm.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/ecdh.h" -#include "mbedtls/entropy.h" -#include "mbedtls/md.h" -#include "mbedtls/sha256.h" - -#include "FreeRTOS.h" -#include "queue.h" -#include "semphr.h" -#include "task.h" - -// Secure link MAC key location for WGM160P (in DI page in flash) -#ifdef EFM32GG11B820F2048GM64 // WGM160PX22KGA2 -#define SL_WFX_FCCC_BASE_ADDR ((void *) 0x0fe08000ul) -#define SL_WFX_FCCC_DI_OFFSET 0x1B0ul -#define SL_WFX_FCCC_DI_ADDR ((void *) (SL_WFX_FCCC_BASE_ADDR + SL_WFX_FCCC_DI_OFFSET)) -#define SL_WFX_SECURE_LINK_MAC_KEY_LOCATION ((void *) (SL_WFX_FCCC_BASE_ADDR + 0x3D0)) -#endif -/****************************************************** - * Macros - ******************************************************/ -#define MAC_KEY_FAIL_BYTE 0XFF -#define KEY_DIGEST_SIZE 92 -#define MEMCMP_FAIL 0 -#define MPI_SET 1 -#define SUCCESS_STATUS_WIFI_SECURE_LINK_EXCHANGE 0 -#define SHA224_0 0 -#define HMAC_SIZE 92 -#define MEMSET_LEN 1 -#define LABLE_LEN 24 -#define ADDRESS_LENGTH 0 -#define CCM_STATUS_SUCCESS 0 -/****************************************************** - * Constants - ******************************************************/ - -/* Semaphore to signal wfx driver available */ -extern TaskHandle_t wfx_securelink_task; -extern SemaphoreHandle_t wfx_securelink_rx_mutex; - -/****************************************************** - * Enumerations - ******************************************************/ - -/****************************************************** - * Type Definitions - ******************************************************/ - -/****************************************************** - * Structures - ******************************************************/ - -/****************************************************** - * Function Declarations - ******************************************************/ - -static inline void reverse_bytes(uint8_t * src, uint8_t length); - -/****************************************************** - * Variable Definitions - ******************************************************/ - -#if SL_WFX_SLK_CURVE25519 -static mbedtls_ecdh_context mbedtls_host_context; -static mbedtls_ctr_drbg_context host_drbg_context; -#endif -static mbedtls_entropy_context entropy; -uint8_t temp_key_location[SL_WFX_HOST_PUB_KEY_MAC_SIZE]; -#ifdef EFM32GG11B820F2048GM64 // WGM160PX22KGA2 -static const uint8_t * const secure_link_mac_key = (uint8_t *) SL_WFX_SECURE_LINK_MAC_KEY_LOCATION; -#else -static const uint8_t secure_link_mac_key[SL_WFX_SECURE_LINK_MAC_KEY_LENGTH] = { 0x2B, 0x49, 0xFD, 0x66, 0xCB, 0x74, 0x6D, 0x6B, - 0x4F, 0xDC, 0xC3, 0x79, 0x4E, 0xC5, 0x9A, 0x86, - 0xE5, 0x48, 0x2A, 0x41, 0x22, 0x87, 0x8B, 0x12, - 0x1A, 0x7C, 0x3E, 0xEF, 0xB7, 0x04, 0x9E, 0xB3 }; -#endif -/****************************************************** - * Function Definitions - ******************************************************/ -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_get_secure_link_mac_key(uint8_t *sl_mac_key) - * @brief - * Get secure link mac key - * @param[in] sl_mac_key: - * @return returns SL_STATUS_OK - *****************************************************************************/ -sl_status_t sl_wfx_host_get_secure_link_mac_key(uint8_t * sl_mac_key) -{ - sl_status_t result = SL_STATUS_WIFI_SECURE_LINK_MAC_KEY_ERROR; - - memcpy(sl_mac_key, secure_link_mac_key, SL_WFX_SECURE_LINK_MAC_KEY_LENGTH); - - for (uint8_t index = 0; index < SL_WFX_SECURE_LINK_MAC_KEY_LENGTH; ++index) - { - // Assuming 0xFF... when not written - if (sl_mac_key[index] != MAC_KEY_FAIL_BYTE) - { - result = SL_STATUS_OK; - break; - } - } - - return result; -} - -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_compute_pub_key(sl_wfx_securelink_exchange_pub_keys_req_body_t *request, - const uint8_t *sl_mac_key) - * @brief - * compute host public key - * @param[in] request : - * @param[in] sl_mac_key : - * @return returns SL_STATUS_OK - *****************************************************************************/ -sl_status_t sl_wfx_host_compute_pub_key(sl_wfx_securelink_exchange_pub_keys_req_body_t * request, const uint8_t * sl_mac_key) -{ - sl_status_t status = SL_STATUS_OK; - -#if SL_WFX_SLK_CURVE25519 - const char identifier[] = "ecdh"; - - mbedtls_ecdh_init(&mbedtls_host_context); - mbedtls_ctr_drbg_init(&host_drbg_context); - mbedtls_entropy_init(&entropy); - status = mbedtls_ctr_drbg_seed(&host_drbg_context, mbedtls_entropy_func, &entropy, (const unsigned char *) identifier, - sizeof(identifier)); - status += mbedtls_ecp_group_load(&mbedtls_host_context.grp, MBEDTLS_ECP_DP_CURVE25519); - status += mbedtls_ecdh_gen_public(&mbedtls_host_context.grp, &mbedtls_host_context.d, &mbedtls_host_context.Q, - mbedtls_ctr_drbg_random, &host_drbg_context); - status += mbedtls_mpi_write_binary(&mbedtls_host_context.Q.X, request->host_pub_key, SL_WFX_HOST_PUB_KEY_SIZE); -#else - mbedtls_entropy_init(&entropy); - status = mbedtls_entropy_func(&entropy, request->host_pub_key, SL_WFX_HOST_PUB_KEY_SIZE); -#endif - reverse_bytes(request->host_pub_key, SL_WFX_HOST_PUB_KEY_SIZE); - SL_WFX_ERROR_CHECK(status); - - // Generate SHA512 digest of public key - status = mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA512), sl_mac_key, SL_WFX_HOST_PUB_KEY_SIZE, - request->host_pub_key, SL_WFX_HOST_PUB_KEY_SIZE, request->host_pub_key_mac); - SL_WFX_ERROR_CHECK(status); - -error_handler: - if (status != SL_STATUS_OK) - { - return SL_STATUS_WIFI_SECURE_LINK_EXCHANGE_FAILED; - } - return status; -} - -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_verify_pub_key(sl_wfx_securelink_exchange_pub_keys_ind_t *response_packet, - const uint8_t *sl_mac_key, - uint8_t *sl_host_pub_key) - * @brief - * verify host public key - * @param[in] response_packet: - * @param[in] sl_mac_key: - * @param[in] sl_host_pub_key: - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ -sl_status_t sl_wfx_host_verify_pub_key(sl_wfx_securelink_exchange_pub_keys_ind_t * response_packet, const uint8_t * sl_mac_key, - uint8_t * sl_host_pub_key) -{ - sl_status_t status = SL_STATUS_OK; - uint8_t shared_key_digest[KEY_DIGEST_SIZE]; - - if (xSemaphoreTake(wfx_securelink_rx_mutex, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_WIFI_SECURE_LINK_EXCHANGE_FAILED; - } - - // Compute the Hash and verify the public key/hashing - status = mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA512), sl_mac_key, SL_WFX_NCP_PUB_KEY_SIZE, - response_packet->body.ncp_pub_key, SL_WFX_NCP_PUB_KEY_SIZE, temp_key_location); - SL_WFX_ERROR_CHECK(status); - - // Calculate session key if public key/SHA512 digest matches - if (memcmp(temp_key_location, response_packet->body.ncp_pub_key_mac, SL_WFX_HOST_PUB_KEY_MAC_SIZE) != MEMCMP_FAIL) - { - status = SL_STATUS_WIFI_SECURE_LINK_EXCHANGE_FAILED; - goto error_handler; - } - -#if SL_WFX_SLK_CURVE25519 - SL_WFX_UNUSED_PARAMETER(sl_host_pub_key); - - mbedtls_mpi_lset(&mbedtls_host_context.Qp.Z, MPI_SET); - - // Read Ineo public key - reverse_bytes(response_packet->body.ncp_pub_key, SL_WFX_NCP_PUB_KEY_SIZE); - mbedtls_mpi_read_binary(&mbedtls_host_context.Qp.X, response_packet->body.ncp_pub_key, SL_WFX_NCP_PUB_KEY_SIZE); - - // Calculate shared secret - if (mbedtls_ecdh_compute_shared(&mbedtls_host_context.grp, &mbedtls_host_context.z, &mbedtls_host_context.Qp, - &mbedtls_host_context.d, mbedtls_ctr_drbg_random, - &host_drbg_context) != SUCCESS_STATUS_WIFI_SECURE_LINK_EXCHANGE) - { - status = SL_STATUS_WIFI_SECURE_LINK_EXCHANGE_FAILED; - goto error_handler; - } - - // Generate session key - mbedtls_mpi_write_binary(&mbedtls_host_context.z, temp_key_location, SL_WFX_HOST_PUB_KEY_SIZE); - reverse_bytes(temp_key_location, SL_WFX_HOST_PUB_KEY_SIZE); - mbedtls_sha256(temp_key_location, SL_WFX_HOST_PUB_KEY_SIZE, shared_key_digest, SHA224_0); -#else - uint8_t hmac_input[HMAC_SIZE] = { 0 }; - char label[LABLE_LEN] = "SecureLink!KeyDerivation"; - - memset((uint16_t *) &hmac_input[0], (uint16_t) sl_wfx_htole16(1), MEMSET_LEN); - memcpy((uint8_t *) &hmac_input[2], (uint8_t *) label, LABLE_LEN); - memcpy((uint8_t *) &hmac_input[26], sl_host_pub_key, SL_WFX_NCP_PUB_KEY_SIZE); - memcpy((uint8_t *) &hmac_input[58], (uint8_t *) response_packet->body.ncp_pub_key, SL_WFX_NCP_PUB_KEY_SIZE); - memset((uint16_t *) &hmac_input[90], (uint16_t) sl_wfx_htole16(128), 1); - - // Generate SHA256 digest of hmac_input - status = mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), sl_mac_key, SL_WFX_HOST_PUB_KEY_SIZE, - (uint8_t *) hmac_input, HMAC_SIZE, shared_key_digest); -#endif - - memcpy(sl_wfx_context->secure_link_session_key, shared_key_digest, - SL_WFX_SECURE_LINK_SESSION_KEY_LENGTH); // Use the lower 16 bytes of the sha256 - sl_wfx_context->secure_link_nonce.hp_packet_count = 0; - sl_wfx_context->secure_link_nonce.rx_packet_count = 0; - sl_wfx_context->secure_link_nonce.tx_packet_count = 0; - -error_handler: - if (xSemaphoreGive(wfx_securelink_rx_mutex) != pdTRUE) - { - printf("ERROR: sl_wfx_securelink_rx_mutex. unable to post.\n"); - } - return status; -} - -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_free_crypto_context(void) - * @brief - * Free host crypto context - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ -sl_status_t sl_wfx_host_free_crypto_context(void) -{ -#if SL_WFX_SLK_CURVE25519 - mbedtls_ecdh_free(&mbedtls_host_context); - mbedtls_ctr_drbg_free(&host_drbg_context); -#endif - mbedtls_entropy_free(&entropy); - - return SL_STATUS_OK; -} - -/******************************************************************************** - * @fn sl_status_t sl_wfx_host_decode_secure_link_data(uint8_t *buffer, uint32_t length, uint8_t *session_key) - * @brief - * Decode receive data - * Length excludes size of CCM tag and secure link header - * @param[in] buffer: - * @param[in] length: - * @param[in] session_key: - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - ********************************************************************************/ -sl_status_t sl_wfx_host_decode_secure_link_data(uint8_t * buffer, uint32_t length, uint8_t * session_key) -{ - mbedtls_ccm_context ccm_context; - sl_status_t status = SL_STATUS_SECURITY_DECRYPT_ERROR; - int crypto_status; - sl_wfx_nonce_t nonce = { 0, 0, 0 }; - - if (xSemaphoreTake(wfx_securelink_rx_mutex, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_FAIL; - } - - // Nonce for decryption should have TX and HP counters 0, only use RX counter - nonce.rx_packet_count = sl_wfx_context->secure_link_nonce.rx_packet_count; - - // Init context - mbedtls_ccm_init(&ccm_context); - - // Set the crypto key - crypto_status = mbedtls_ccm_setkey(&ccm_context, MBEDTLS_CIPHER_ID_AES, session_key, SL_WFX_SECURE_LINK_SESSION_KEY_BIT_COUNT); - SL_WFX_ERROR_CHECK(crypto_status); - - // Decrypt the data - if (!mbedtls_ccm_auth_decrypt(&ccm_context, length, (uint8_t *) &nonce, SL_WFX_SECURE_LINK_NONCE_SIZE_BYTES, NULL, - ADDRESS_LENGTH, (uint8_t *) buffer, (uint8_t *) buffer, (uint8_t *) buffer + length, - SL_WFX_SECURE_LINK_CCM_TAG_SIZE)) - { - status = SL_STATUS_OK; - } - -error_handler: - mbedtls_ccm_free(&ccm_context); - if (xSemaphoreGive(wfx_securelink_rx_mutex) != pdTRUE) - { - printf("ERROR: sl_wfx_securelink_rx_mutex. unable to post.\n"); - } - return status; -} - -/********************************************************************* - * @fn sl_status_t sl_wfx_host_encode_secure_link_data(sl_wfx_generic_message_t *buffer, - uint32_t data_length, - uint8_t *session_key, - uint8_t *nonce) - * @brief - * Encode transmit data - * Length excludes size of CCM tag and secure link header - * @param[in] buffer: - * @param[in] data_length: - * @param[in] session_key: - * @param[in] nonce: - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise -*************************************************************************/ -sl_status_t sl_wfx_host_encode_secure_link_data(sl_wfx_generic_message_t * buffer, uint32_t data_length, uint8_t * session_key, - uint8_t * nonce) -{ - mbedtls_ccm_context ccm_context; - sl_status_t status = SL_STATUS_FAIL; - - mbedtls_ccm_init(&ccm_context); - if (mbedtls_ccm_setkey(&ccm_context, MBEDTLS_CIPHER_ID_AES, session_key, SL_WFX_SECURE_LINK_SESSION_KEY_BIT_COUNT) == - CCM_STATUS_SUCCESS) - { - mbedtls_ccm_encrypt_and_tag(&ccm_context, data_length, nonce, SL_WFX_SECURE_LINK_NONCE_SIZE_BYTES, NULL, ADDRESS_LENGTH, - (uint8_t *) &buffer->header.id, (uint8_t *) &buffer->header.id, - (uint8_t *) &buffer->header.id + data_length, SL_WFX_SECURE_LINK_CCM_TAG_SIZE); - status = SL_STATUS_OK; - } - - mbedtls_ccm_free(&ccm_context); - - return status; -} - -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_schedule_secure_link_renegotiation(void) - * @brief - * Called when the driver needs to schedule secure link renegotiation - * @param[in] None - * @returns Returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ -sl_status_t sl_wfx_host_schedule_secure_link_renegotiation(void) -{ - // call sl_wfx_secure_link_renegotiate_session_key() as soon as it makes sense for the host to do so - xTaskNotifyGive(wfx_securelink_task); - return SL_STATUS_OK; -} - -/**************************************************************************** - * @fn static inline void reverse_bytes(uint8_t *src, uint8_t length) - * @brief - * reverse the bytes - * @param[in] src: source - * @param[in] length: - * @returns None - *****************************************************************************/ -static inline void reverse_bytes(uint8_t * src, uint8_t length) -{ - uint8_t * lo = src; - uint8_t * hi = src + length - 1; - uint8_t swap; - - while (lo < hi) - { - swap = *lo; - *lo++ = *hi; - *hi-- = swap; - } -} - -/******************************************************************************************************** - ******************************************************************************************************** - * DEPENDENCIES & AVAIL CHECK(S) - ******************************************************************************************************** - *******************************************************************************************************/ - -#endif // SL_WFX_USE_SECURE_LINK diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_securelink_task.c b/examples/platform/silabs/efr32/wf200/sl_wfx_securelink_task.c deleted file mode 100644 index 28ffdda2c3..0000000000 --- a/examples/platform/silabs/efr32/wf200/sl_wfx_securelink_task.c +++ /dev/null @@ -1,85 +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. - */ - -#ifdef SL_WFX_USE_SECURE_LINK -#include "secure_link/sl_wfx_secure_link.h" - -#include "FreeRTOS.h" -#include "queue.h" -#include "semphr.h" -#include "task.h" -#include -#include -#include - -// Securelink Task Configurations -#define WFX_SECURELINK_TASK_PRIO 1u -#define WFX_SECURELINK_TASK_STK_SIZE 512u - -TaskHandle_t secureLinkTaskHandle; -SemaphoreHandle_t s_xSLSemaphore; -StackType_t secureLinkStack[WFX_SECURELINK_TASK_STK_SIZE]; -StaticTask_t secureLinkTaskStruct; - -StaticSemaphore_t xSlMutexBuffer; - -/********************************************************************* - * @fn static void prvSecureLinkTask(void *p_arg) - * @brief - * The task that implements the Secure Link renegotiation with WFX. - * @param[in] p_arg: - * @return None - *************************************************************************/ -static void prvSecureLinkTask(void * p_arg) -{ - sl_status_t result; - (void) p_arg; - - /* Create a mutex used for making Secure Link renegotiations atomic */ - s_xSLSemaphore = xSemaphoreCreateMutexStatic(&xSlMutexBuffer); - - for (;;) - { - /* Wait for a key renegotiation request */ - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - - result = sl_wfx_secure_link_renegotiate_session_key(); - if (result != SL_STATUS_OK) - { - printf("session key negotiation error %lu\n", result); - } - } -} - -/**************************************************************************** - * @fn void wfx_securelink_task_start(void) - * @brief - * Creates WFX securelink key renegotiation task. - * @param[in] None - * @return None - ******************************************************************************/ -void wfx_securelink_task_start(void) -{ - secureLinkTaskHandle = xTaskCreateStatic(prvSecureLinkTask, "secureLinkTask", WFX_SECURELINK_TASK_STK_SIZE, NULL, - WFX_SECURELINK_TASK_PRIO, secureLinkStack, &secureLinkTaskStruct); - if (secureLinkTaskHandle == NULL) - { - printf("Failed to create WFX secureLinkTask"); - } -} - -#endif diff --git a/examples/platform/silabs/efr32/wf200/wf200.gni b/examples/platform/silabs/efr32/wf200/wf200.gni deleted file mode 100644 index 307b681537..0000000000 --- a/examples/platform/silabs/efr32/wf200/wf200.gni +++ /dev/null @@ -1,12 +0,0 @@ -import("//build_overrides/chip.gni") -import("//build_overrides/efr32_sdk.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") - -wf200_plat_incs = [ "${examples_plat_dir}/wf200" ] -wf200_plat_src = [ - "${silabs_common_plat_dir}/wifi/wfx_notify.cpp", - "${examples_plat_dir}/wf200/sl_wfx_task.c", - "${examples_plat_dir}/wf200/wf200_init.c", - "${examples_plat_dir}/wf200/efr_spi.c", - "${examples_plat_dir}/wf200/host_if.cpp", -] diff --git a/examples/platform/silabs/provision/BUILD.gn b/examples/platform/silabs/provision/BUILD.gn index f9e056f5ff..517dd33c12 100644 --- a/examples/platform/silabs/provision/BUILD.gn +++ b/examples/platform/silabs/provision/BUILD.gn @@ -14,12 +14,12 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_board.gni") +import("${silabs_sdk_build_root}/silabs_board.gni") if (wifi_soc) { - import("${efr32_sdk_build_root}/SiWx917_sdk.gni") + import("${silabs_sdk_build_root}/SiWx917_sdk.gni") } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") } source_set("storage") { diff --git a/examples/platform/silabs/wfx_rsi.h b/examples/platform/silabs/wfx_rsi.h deleted file mode 100644 index 0e62cb7802..0000000000 --- a/examples/platform/silabs/wfx_rsi.h +++ /dev/null @@ -1,124 +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. - */ -#pragma once - -#include -#include -#include -#include -#include - -#ifndef RSI_BLE_ENABLE -#define RSI_BLE_ENABLE (1) -#endif - -/* - * Interface to RSI Sapis - */ - -#define WFX_RSI_WLAN_TASK_SZ (1024 + 512 + 256) /* Stack for the WLAN task */ // TODO: For rs9116 -#define WFX_RSI_BUF_SZ (1024 * 10) -#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ -#define WFX_RSI_NUM_TIMERS (2) /* Number of RSI timers to alloc */ - -typedef enum -{ - WFX_EVT_STA_CONN, - WFX_EVT_STA_DISCONN, - WFX_EVT_AP_START, - WFX_EVT_AP_STOP, - WFX_EVT_SCAN, /* This is used as scan result and start */ - WFX_EVT_STA_START_JOIN, - WFX_EVT_STA_DO_DHCP, - WFX_EVT_STA_DHCP_DONE, - WFX_EVT_DHCP_POLL -} WfxEventType_e; - -typedef enum -{ - WFX_RSI_ST_DEV_READY = (1 << 0), - WFX_RSI_ST_AP_READY = (1 << 1), - WFX_RSI_ST_STA_PROVISIONED = (1 << 2), - WFX_RSI_ST_STA_CONNECTING = (1 << 3), - WFX_RSI_ST_STA_CONNECTED = (1 << 4), - WFX_RSI_ST_STA_DHCP_DONE = (1 << 6), /* Requested to do DHCP after conn */ - WFX_RSI_ST_STA_MODE = (1 << 7), /* Enable Station Mode */ - WFX_RSI_ST_AP_MODE = (1 << 8), /* Enable AP Mode */ - WFX_RSI_ST_STA_READY = (WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE), - WFX_RSI_ST_STARTED = (1 << 9), /* RSI task started */ - WFX_RSI_ST_SCANSTARTED = (1 << 10), /* Scan Started */ -} WfxStateType_e; - -typedef struct WfxEvent_s -{ - WfxEventType_e eventType; - void * eventData; // event data TODO: confirm needed -} WfxEvent_t; - -typedef struct wfx_rsi_s -{ - uint16_t dev_state; - uint16_t ap_chan; /* The chan our STA is using */ - wfx_wifi_provision_t sec; -#ifdef SL_WFX_CONFIG_SCAN - void (*scan_cb)(wfx_wifi_scan_result_t *); - char * scan_ssid; /* Which one are we scanning for */ - size_t scan_ssid_length; -#endif -#ifdef SL_WFX_CONFIG_SOFTAP - sl_wfx_mac_address_t softap_mac; -#endif - sl_wfx_mac_address_t sta_mac; - sl_wfx_mac_address_t ap_mac; /* To which our STA is connected */ - 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; - -#ifdef __cplusplus -extern "C" { -#endif -void wfx_rsidev_init(void); -void wfx_rsi_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 wfx_rsi_disconnect(); -int32_t wfx_wifi_rsi_init(void); -#if CHIP_CONFIG_ENABLE_ICD_SERVER -#if SLI_SI91X_MCU_INTERFACE -void sl_si91x_invoke_btn_press_event(); -#endif // SLI_SI91X_MCU_INTERFACE -#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); -#else -int32_t wfx_rsi_power_save(); -#endif /* SLI_SI917 */ -#endif /* SL_ICD_ENABLED */ - -/// WfxPostEvent -/// @brief Allows to allocate an event to the WFX task event queue from outside of sl_wifi_if.c -/// @param event The event that will be allocated to the event queue -void WfxPostEvent(WfxEvent_t * event); -#ifdef __cplusplus -} -#endif diff --git a/examples/pump-app/silabs/BUILD.gn b/examples/pump-app/silabs/BUILD.gn index 8321ba6c80..e8acd1501c 100644 --- a/examples/pump-app/silabs/BUILD.gn +++ b/examples/pump-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/pump-app/silabs/README.md b/examples/pump-app/silabs/README.md index 7bde704c4a..285b5d7d18 100644 --- a/examples/pump-app/silabs/README.md +++ b/examples/pump-app/silabs/README.md @@ -242,6 +242,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/pump-app/silabs/build_for_wifi_args.gni b/examples/pump-app/silabs/build_for_wifi_args.gni index c954446921..9e6aeced58 100644 --- a/examples/pump-app/silabs/build_for_wifi_args.gni +++ b/examples/pump-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/pump-app/silabs/data_model:silabs-pump" diff --git a/examples/refrigerator-app/silabs/build_for_wifi_args.gni b/examples/refrigerator-app/silabs/build_for_wifi_args.gni index e82cf8be12..a12daf827a 100644 --- a/examples/refrigerator-app/silabs/build_for_wifi_args.gni +++ b/examples/refrigerator-app/silabs/build_for_wifi_args.gni @@ -15,7 +15,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_wifi = true chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/refrigerator-app/silabs/data_model:silabs-refrigerator" diff --git a/examples/smoke-co-alarm-app/silabs/BUILD.gn b/examples/smoke-co-alarm-app/silabs/BUILD.gn index c6fe0967a9..ad2db01459 100644 --- a/examples/smoke-co-alarm-app/silabs/BUILD.gn +++ b/examples/smoke-co-alarm-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/smoke-co-alarm-app/silabs/README.md b/examples/smoke-co-alarm-app/silabs/README.md index e16621df11..d59510e7e6 100644 --- a/examples/smoke-co-alarm-app/silabs/README.md +++ b/examples/smoke-co-alarm-app/silabs/README.md @@ -260,6 +260,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/smoke-co-alarm-app/silabs/build_for_wifi_args.gni b/examples/smoke-co-alarm-app/silabs/build_for_wifi_args.gni index e5097f8a1d..bdebe11b97 100644 --- a/examples/smoke-co-alarm-app/silabs/build_for_wifi_args.gni +++ b/examples/smoke-co-alarm-app/silabs/build_for_wifi_args.gni @@ -16,7 +16,7 @@ import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = diff --git a/examples/thermostat/silabs/BUILD.gn b/examples/thermostat/silabs/BUILD.gn index f51ee14825..623d87c2f7 100644 --- a/examples/thermostat/silabs/BUILD.gn +++ b/examples/thermostat/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -38,7 +38,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/thermostat/silabs/README.md b/examples/thermostat/silabs/README.md index 25ba47891b..4d95fe2bf3 100644 --- a/examples/thermostat/silabs/README.md +++ b/examples/thermostat/silabs/README.md @@ -251,6 +251,7 @@ combination with JLinkRTTClient as follows: - _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode for 30 seconds. The device will then switch to a slower interval advertisement. After 15 minutes, the advertisement stops. + Additionally, it will cycle through the QR code, application status screen and device status screen, respectively. - _Pressed and hold for 6 s_ : Initiates the factory reset of the device. Releasing the button within the 6-second window cancels the factory reset diff --git a/examples/thermostat/silabs/build_for_wifi_args.gni b/examples/thermostat/silabs/build_for_wifi_args.gni index db1e280b0b..76a77c24cd 100644 --- a/examples/thermostat/silabs/build_for_wifi_args.gni +++ b/examples/thermostat/silabs/build_for_wifi_args.gni @@ -15,7 +15,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/config/standalone/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_wifi = true chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/thermostat/thermostat-common" diff --git a/examples/window-app/silabs/BUILD.gn b/examples/window-app/silabs/BUILD.gn index c45dbda632..f55d63012f 100644 --- a/examples/window-app/silabs/BUILD.gn +++ b/examples/window-app/silabs/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") +import("${silabs_sdk_build_root}/silabs_executable.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -39,7 +39,7 @@ if (wifi_soc) { import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" } diff --git a/examples/window-app/silabs/build_for_wifi_args.gni b/examples/window-app/silabs/build_for_wifi_args.gni index d6a8a54afb..6f445aeb79 100644 --- a/examples/window-app/silabs/build_for_wifi_args.gni +++ b/examples/window-app/silabs/build_for_wifi_args.gni @@ -15,7 +15,7 @@ import("//build_overrides/chip.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_openthread = false -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") chip_enable_ota_requestor = true app_data_model = "${chip_root}/examples/window-app/common:window-common" diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index 8ae78b3d2e..62e96802c3 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -35,9 +35,9 @@ #include #ifdef SL_WIFI -#include "wfx_host_events.h" #include #include +#include #endif #ifdef DISPLAY_ENABLED diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 145bc2dd1d..ae11375c95 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -220,7 +220,7 @@ if (current_os == "zephyr" || current_os == "mbed") { sources += [ "${chip_root}/third_party/lwip/repo/lwip/src/apps/mdns/mdns.c" ] } else if (lwip_platform == "silabs") { - public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ] + public_deps += [ "${silabs_sdk_build_root}:silabs_sdk" ] sources += [ "${lwip_platform}/lwipopts-rs911x.h", diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 9919e8a091..9a5410d246 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/CHIPDevicePlatformEvent.h b/src/platform/silabs/CHIPDevicePlatformEvent.h index 8ab1e21b45..090ada6403 100644 --- a/src/platform/silabs/CHIPDevicePlatformEvent.h +++ b/src/platform/silabs/CHIPDevicePlatformEvent.h @@ -26,7 +26,7 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION -#include "wfx_host_events.h" +#include #endif namespace chip { diff --git a/src/platform/silabs/ConfigurationManagerImpl.cpp b/src/platform/silabs/ConfigurationManagerImpl.cpp index 122799952a..668b150ccc 100644 --- a/src/platform/silabs/ConfigurationManagerImpl.cpp +++ b/src/platform/silabs/ConfigurationManagerImpl.cpp @@ -30,7 +30,7 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION -#include "wfx_host_events.h" +#include #endif namespace chip { @@ -289,10 +289,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) PersistedStorage::KeyValueStoreMgrImpl().ErasePartition(); #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION - sl_status_t status = wfx_sta_discon(); + sl_status_t status = sl_matter_wifi_disconnect(); if (status != SL_STATUS_OK) { - ChipLogError(DeviceLayer, "wfx_sta_discon() failed: %lx", status); + ChipLogError(DeviceLayer, "sl_matter_wifi_disconnect() failed: %lx", status); } ChipLogProgress(DeviceLayer, "Clearing WiFi provision"); wfx_clear_wifi_provision(); diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index 6e5470f7d0..0d9d63317e 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -40,7 +40,7 @@ #endif #include "CHIPDevicePlatformConfig.h" -#include "wfx_host_events.h" +#include using namespace ::chip; using namespace ::chip::Inet; @@ -277,7 +277,7 @@ void ConnectivityManagerImpl::DriveStationState() (mWiFiStationMode != kWiFiStationMode_Enabled && !IsWiFiStationProvisioned())) { ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface"); - serr = wfx_sta_discon(); + serr = sl_matter_wifi_disconnect(); if (serr != SL_STATUS_OK) { ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %lx", serr); diff --git a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp index 7f6240c32c..ba80a94be6 100644 --- a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp @@ -140,7 +140,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, if (ConnectivityMgr().IsWiFiStationProvisioned()) { ChipLogProgress(DeviceLayer, "Disconecting for current wifi"); - status = wfx_sta_discon(); + status = sl_matter_wifi_disconnect(); if (status != SL_STATUS_OK) { return CHIP_ERROR_INTERNAL; diff --git a/src/platform/silabs/NetworkCommissioningWiFiDriver.h b/src/platform/silabs/NetworkCommissioningWiFiDriver.h index f152edb343..12986b9987 100644 --- a/src/platform/silabs/NetworkCommissioningWiFiDriver.h +++ b/src/platform/silabs/NetworkCommissioningWiFiDriver.h @@ -18,7 +18,7 @@ #pragma once #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION #include -#include +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/silabs/PlatformManagerImpl.cpp b/src/platform/silabs/PlatformManagerImpl.cpp index 14dd4f78f2..9ffb217103 100644 --- a/src/platform/silabs/PlatformManagerImpl.cpp +++ b/src/platform/silabs/PlatformManagerImpl.cpp @@ -84,10 +84,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) err = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(); SuccessOrExit(err); -#if CHIP_SYSTEM_CONFIG_USE_LWIP +#if CHIP_SYSTEM_CONFIG_USE_LWIP && !defined(SLI_SI91X_MCU_INTERFACE) // Initialize LwIP. tcpip_init(NULL, NULL); -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && !defined(SLI_SI91X_MCU_INTERFACE) ReturnErrorOnFailure(System::Clock::InitClock_RealTime()); @@ -134,9 +134,17 @@ void PlatformManagerImpl::_Shutdown() Internal::GenericPlatformManagerImpl_FreeRTOS::_Shutdown(); } +} // namespace DeviceLayer +} // namespace chip + #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION -void PlatformManagerImpl::HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData) +// This function needs to be global so it can be used from the platform implementation without depending on the platfrom itself. +// This is a workaround to avoid a circular dependency. +void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData) { + using namespace chip; + using namespace chip::DeviceLayer; + ChipDeviceEvent event; memset(&event, 0, sizeof(event)); event.Type = DeviceEventType::kWFXSystemEvent; @@ -199,9 +207,7 @@ void PlatformManagerImpl::HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wf } } - (void) sInstance.PostEvent(&event); + // TODO: We should add error processing here + (void) PlatformMgr().PostEvent(&event); } #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/silabs/PlatformManagerImpl.h b/src/platform/silabs/PlatformManagerImpl.h index 25813afb48..dd5344d909 100644 --- a/src/platform/silabs/PlatformManagerImpl.h +++ b/src/platform/silabs/PlatformManagerImpl.h @@ -26,10 +26,14 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION -#include "wfx_host_events.h" +#include #endif #include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); +#endif + namespace chip { namespace DeviceLayer { @@ -62,9 +66,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener public: // ===== Platform-specific members that may be accessed directly by the application. -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION - void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); -#endif System::Clock::Timestamp GetStartTime() { return mStartTime; } diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 188f1f3396..826d8accd9 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -18,7 +18,7 @@ import("${chip_root}/src/platform/device.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/crypto/crypto.gni") -import("${chip_root}/src/platform/silabs/wifi_args.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") import("${chip_root}/third_party/silabs/SiWx917_sdk.gni") import("${chip_root}/third_party/silabs/silabs_board.gni") @@ -30,10 +30,14 @@ if (chip_crypto == "platform") { import("//build_overrides/mbedtls.gni") } -config("siwx917-platform-wifi-config") { - include_dirs = [ "wifi" ] - defines = [] +source_set("logging") { + sources = [ "${chip_root}/src/platform/silabs/Logging.cpp" ] + deps = [ + "${chip_root}/src/platform:platform_base", + "${chip_root}/src/platform/logging:headers", + ] } + static_library("SiWx917") { sources = [ "${silabs_platform_dir}/BLEManagerImpl.h", @@ -45,6 +49,7 @@ static_library("SiWx917") { "${silabs_platform_dir}/ConfigurationManagerImpl.cpp", "${silabs_platform_dir}/ConfigurationManagerImpl.h", "${silabs_platform_dir}/ConnectivityManagerImpl.h", + "${silabs_platform_dir}/ConnectivityManagerImpl_WIFI.cpp", "${silabs_platform_dir}/DiagnosticDataProviderImpl.cpp", "${silabs_platform_dir}/DiagnosticDataProviderImpl.h", "${silabs_platform_dir}/InetPlatformConfig.h", @@ -52,6 +57,8 @@ static_library("SiWx917") { "${silabs_platform_dir}/KeyValueStoreManagerImpl.h", "${silabs_platform_dir}/MigrationManager.cpp", "${silabs_platform_dir}/MigrationManager.h", + "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.cpp", + "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.h", "${silabs_platform_dir}/PlatformManagerImpl.cpp", "${silabs_platform_dir}/PlatformManagerImpl.h", "${silabs_platform_dir}/SilabsConfig.cpp", @@ -66,6 +73,7 @@ static_library("SiWx917") { "../rs911x/rsi_ble_config.h", "../rs911x/wfx_sl_ble_init.cpp", "../rs911x/wfx_sl_ble_init.h", + "SiWxPlatformInterface.h", ] if (chip_enable_ota_requestor) { @@ -94,24 +102,7 @@ static_library("SiWx917") { public_deps += [ "${chip_root}/src/crypto", "${mbedtls_root}:mbedtls", + "${silabs_platform_dir}/wifi:wifi-platform", ] } - - sources += [ - "${silabs_platform_dir}/ConnectivityManagerImpl_WIFI.cpp", - "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.cpp", - "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.h", - "${silabs_platform_dir}/wifi/wfx_host_events.h", - "wifi/wfx_msgs.h", - "wifi/wifi_config.h", - ] - public_configs = [ ":siwx917-platform-wifi-config" ] -} - -source_set("logging") { - sources = [ "${chip_root}/src/platform/silabs/Logging.cpp" ] - deps = [ - "${chip_root}/src/platform:platform_base", - "${chip_root}/src/platform/logging:headers", - ] } diff --git a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp index c954600873..074097bac7 100644 --- a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp @@ -20,8 +20,8 @@ #include #include -#include "wfx_host_events.h" #include +#include #ifdef __cplusplus extern "C" { #endif diff --git a/src/platform/silabs/SiWx917/SiWxPlatformInterface.h b/src/platform/silabs/SiWx917/SiWxPlatformInterface.h new file mode 100644 index 0000000000..8589db3b3f --- /dev/null +++ b/src/platform/silabs/SiWx917/SiWxPlatformInterface.h @@ -0,0 +1,111 @@ +/* + * + * 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, + * 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. + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#if SLI_SI91X_MCU_INTERFACE +#include "sl_si91x_button.h" +#include "sl_si91x_button_pin_config.h" +#include "sl_si91x_driver_gpio.h" + +/** + * @brief invoked when button press event is received when in sleep + * @param[in] pin_intr GPIO pin interrupt number. + * @return none. + * @note this is a callback from the Wiseconnect SDK + */ +void gpio_uulp_pin_interrupt_callback(uint32_t pin_intr) +{ + // UULP_GPIO_2 is used to detect the button 0 press + VerifyOrReturn(pin_intr == RTE_UULP_GPIO_2_PIN, ChipLogError(DeviceLayer, "invalid pin interrupt: %ld", pin_intr)); + sl_status_t status = SL_STATUS_OK; + uint8_t pin_intr_status = sl_si91x_gpio_get_uulp_npss_pin(pin_intr); + if (pin_intr_status == LOW) + { + // BTN_0 is pressed + // NOTE: the GPIO is masked since the interrupt is invoked before scheduler is started, thus this is required to hand over + // control to scheduler, the PIN is unmasked in the power manager flow before going to sleep + status = sl_si91x_gpio_driver_mask_uulp_npss_interrupt(BIT(pin_intr)); + VerifyOrReturn(status == SL_STATUS_OK, ChipLogError(DeviceLayer, "failed to mask interrupt: %ld", status)); + } +} + +#endif // SLI_SI91X_MCU_INTERFACE +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER +#ifdef __cplusplus +} +#endif + +namespace chip { +namespace DeviceLayer { +namespace Silabs { +namespace SiWxPlatformInterface { + +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#if SLI_SI91X_MCU_INTERFACE +/** + * @brief Required to invoke button press event during sleep as falling edge is not detected + * @param[in] none. + * @note flow is GPIO wakeup due to BTN0 press -> check button state in idle task required as the GPIO interrupt is not + * detected during sleep for BUTTON RELEASED + */ +inline void sl_si91x_btn_event_handler() +{ + sl_button_on_change(SL_BUTTON_BTN0_NUMBER, + (sl_si91x_gpio_get_uulp_npss_pin(SL_BUTTON_BTN0_PIN) == LOW) ? BUTTON_PRESSED : BUTTON_RELEASED); +} + +/** + * @brief Required to enable MATTER shell UART with ICD feature flag + * @param[in] none. + * @note this requires hardware jumping of the GPIO PINs to work with the baseboard. + */ +void sl_si91x_uart_power_requirement_handler() +{ +#ifdef ENABLE_CHIP_SHELL + // Checking the UULP PIN 1 status to reinit the UART and not allow the device to go to sleep + if (sl_si91x_gpio_get_uulp_npss_pin(RTE_UULP_GPIO_1_PIN)) + { + if (!ps_requirement_added) + { + sl_si91x_power_manager_add_ps_requirement(SL_SI91X_POWER_MANAGER_PS4); + ps_requirement_added = true; + } + } + else + { + if (ps_requirement_added) + { + sl_si91x_power_manager_remove_ps_requirement(SL_SI91X_POWER_MANAGER_PS4); + ps_requirement_added = false; + } + } +#endif // ENABLE_CHIP_SHELL +} + +#endif // SLI_SI91X_MCU_INTERFACE +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER +} // namespace SiWxPlatformInterface +} // namespace Silabs +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp b/src/platform/silabs/SiWx917/wifi/ethernetif.cpp deleted file mode 100644 index 2860b895ce..0000000000 --- a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp +++ /dev/null @@ -1,269 +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. - */ - -/* Includes */ - -#include -#include -#include - -#include "wfx_host_events.h" -#include "wifi_config.h" -#ifdef __cplusplus -extern "C" { -#endif -#include "cmsis_os2.h" -#include "sl_board_configuration.h" -#include "sl_net.h" -#include "sl_si91x_driver.h" -#include "sl_si91x_host_interface.h" -#include "sl_si91x_types.h" -#include "sl_wifi.h" -#include "sl_wifi_callback_framework.h" -#include "sl_wifi_constants.h" -#include "sl_wifi_types.h" -#ifdef __cplusplus -} -#endif -/* LwIP includes. */ -#include "ethernetif.h" -#include "lwip/ethip6.h" -#include "lwip/timeouts.h" -#include "netif/etharp.h" -#include - -StaticSemaphore_t xEthernetIfSemaBuffer; - -/***************************************************************************** - * Defines - ******************************************************************************/ -#define STATION_NETIF0 's' -#define STATION_NETIF1 't' - -#define LWIP_FRAME_ALIGNMENT 60 - -uint32_t gOverrunCount = 0; - -/***************************************************************************** - * Variables - ******************************************************************************/ - -/***************************************************************************** - * @fn static void low_level_init(struct netif *netif) - * @brief - * Initializes the hardware parameters. Called from ethernetif_init(). - * - * @param[in] netif: the already initialized lwip network interface structure - * - * @return - * None - ******************************************************************************/ -static void low_level_init(struct netif * netif) -{ - /* set netif MAC hardware address length */ - netif->hwaddr_len = ETH_HWADDR_LEN; - - /* Set netif MAC hardware address */ - sl_wfx_mac_address_t mac_addr; - - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac_addr); - - netif->hwaddr[0] = mac_addr.octet[0]; - netif->hwaddr[1] = mac_addr.octet[1]; - netif->hwaddr[2] = mac_addr.octet[2]; - netif->hwaddr[3] = mac_addr.octet[3]; - netif->hwaddr[4] = mac_addr.octet[4]; - netif->hwaddr[5] = mac_addr.octet[5]; - - /* Set netif maximum transfer unit */ - netif->mtu = 1500; - - /* Accept broadcast address and ARP traffic */ - netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP; - -#if LWIP_IPV6_MLD - netif->flags |= NETIF_FLAG_MLD6; -#endif /* LWIP_IPV6_MLD */ -} - -/******************************************************************************** - * @fn static void low_level_input(struct netif *netif, uint8_t *b, uint16_t len) - * @brief - * Make PBUF out of a linear buffer - that can be fed into lwip - * @param[in] netif: the already initialized lwip network interface structure - * @param[in] len: length - * @return - * None - ************************************************************************************/ -static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) -{ - struct pbuf *p, *q; - uint32_t bufferoffset; - - if (len <= 0) - { - return; - } - if (len < LWIP_FRAME_ALIGNMENT) - { /* 60 : LWIP frame alignment */ - len = LWIP_FRAME_ALIGNMENT; - } - - /* Drop packets originated from the same interface and is not destined for the said interface */ - const uint8_t * src_mac = b + netif->hwaddr_len; - const uint8_t * dst_mac = b; - - if (!(ip6_addr_ispreferred(netif_ip6_addr_state(netif, 0))) && (memcmp(netif->hwaddr, src_mac, netif->hwaddr_len) == 0) && - (memcmp(netif->hwaddr, dst_mac, netif->hwaddr_len) != 0)) - { -#ifdef WIFI_DEBUG_ENABLED - ChipLogDetail(DeviceLayer, "DROP: [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - - b[12], b[13]); -#endif - return; - } - - /* 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) - { - for (q = p, bufferoffset = 0; q != NULL; q = q->next) - { - memcpy((uint8_t *) q->payload, (uint8_t *) b + bufferoffset, q->len); - bufferoffset += q->len; - } -#ifdef WIFI_DEBUG_ENABLED - ChipLogDetail(DeviceLayer, "ACCEPT(%d): [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - bufferoffset, - - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - - b[12], b[13]); -#endif - - if (netif->input(p, netif) != ERR_OK) - { - gOverrunCount++; - pbuf_free(p); - } - } - else - { - gOverrunCount++; - } -} - -static SemaphoreHandle_t ethout_sem; -/***************************************************************************** - * @fn static err_t low_level_output(struct netif *netif, struct pbuf *p) - * @brief - * This function is called from LWIP task when LWIP stack - * has some data to be forwarded over WiFi Network - * - * @param[in] netif: lwip network interface - * - * @param[in] p: the packet to send - * - * @return - * ERR_OK if successful - ******************************************************************************/ -static err_t low_level_output(struct netif * netif, struct pbuf * p) -{ - UNUSED_PARAMETER(netif); - sl_status_t status; - status = sl_wifi_send_raw_data_frame(SL_WIFI_CLIENT_INTERFACE, (uint8_t *) p->payload, p->len); - if (status != SL_STATUS_OK) - { - return ERR_IF; - } - return ERR_OK; -} - -/***************************************************************************** - * @fn void sl_si91x_host_process_data_frame(uint8_t *buf, int len) - * @brief - * host received frame cb - * - * @param[in] buf: buffer - * - * @param[in] len: length - * - * @return - * None - ******************************************************************************/ -sl_status_t sl_si91x_host_process_data_frame(sl_wifi_interface_t interface, sl_wifi_buffer_t * buffer) -{ - struct pbuf * pbuf_packet; - void * packet; - struct netif * ifp; - sl_si91x_packet_t * rsi_pkt; - packet = sl_si91x_host_get_buffer_data(buffer, 0, NULL); - rsi_pkt = (sl_si91x_packet_t *) packet; - - /* get the network interface for STATION interface, - * and forward the received frame buffer to LWIP - */ - if ((ifp = wfx_get_netif(SL_WFX_STA_INTERFACE)) != (struct netif *) 0) - { - low_level_input(ifp, rsi_pkt->data, rsi_pkt->length); - } - return SL_STATUS_OK; -} - -/***************************************************************************** - * @fn err_t sta_ethernetif_init(struct netif *netif) - * @brief - * sta ethernet if initialization - * - * @param[in] netif: the lwip network interface structure - * - * @return - * ERR_OK if successful - ******************************************************************************/ -err_t sta_ethernetif_init(struct netif * netif) -{ - LWIP_ASSERT("netif != NULL", (netif != NULL)); - - /* Set the netif name to identify the interface */ - netif->name[0] = STATION_NETIF0; - netif->name[1] = STATION_NETIF1; - -#if LWIP_IPV4 && LWIP_ARP - netif->output = etharp_output; -#endif /* #if LWIP_IPV4 && LWIP_ARP */ -#if LWIP_IPV6 && LWIP_ETHERNET - netif->output_ip6 = ethip6_output; -#endif /* LWIP_IPV6 && LWIP_ETHERNET */ - netif->linkoutput = low_level_output; - - /* initialize the hardware */ - low_level_init(netif); - - /* Need single output only */ - ethout_sem = xSemaphoreCreateBinaryStatic(&xEthernetIfSemaBuffer); - xSemaphoreGive(ethout_sem); - - return ERR_OK; -} diff --git a/src/platform/silabs/SiWx917/wifi/ethernetif.h b/src/platform/silabs/SiWx917/wifi/ethernetif.h deleted file mode 100644 index bac51b9258..0000000000 --- a/src/platform/silabs/SiWx917/wifi/ethernetif.h +++ /dev/null @@ -1,49 +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. - */ - -#pragma once - -#include "lwip/err.h" -#include "lwip/netif.h" -#ifdef __cplusplus -extern "C" { -#endif -/*************************************************************************** - * @fn err_t sta_ethernetif_init(struct netif *netif) - * @brief - * Sets up the station network interface. - * - * @param netif the lwip network interface structure - * @returns ERR_OK if successful - ******************************************************************************/ -err_t sta_ethernetif_init(struct netif * netif); - -/*************************************************************************** - * @fn err_t ap_ethernetif_init(struct netif *netif - * @brief - * Sets up the AP network interface. - * - * @param netif the lwip network interface structure - * @returns ERR_OK if successful - ******************************************************************************/ -err_t ap_ethernetif_init(struct netif * netif); - -void wfx_host_received_sta_frame_cb(uint8_t * buf, int len); - -#ifdef __cplusplus -} -#endif diff --git a/src/platform/silabs/SiWx917/wifi/wifi_config.h b/src/platform/silabs/SiWx917/wifi/wifi_config.h deleted file mode 100644 index f2f3b7ffeb..0000000000 --- a/src/platform/silabs/SiWx917/wifi/wifi_config.h +++ /dev/null @@ -1,71 +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. - */ - -#ifndef DEMO_CONFIG_H -#define DEMO_CONFIG_H - -#define USE_DHCP_CLIENT_DEFAULT (1) ///< If defined, DHCP is enabled, otherwise static address below is used - -/************************** Station Static Default ****************************/ -#define STA_IP_ADDR0_DEFAULT ((uint8_t) 192) ///< Static IP: IP address value 0 -#define STA_IP_ADDR1_DEFAULT ((uint8_t) 168) ///< Static IP: IP address value 1 -#define STA_IP_ADDR2_DEFAULT ((uint8_t) 0) ///< Static IP: IP address value 2 -#define STA_IP_ADDR3_DEFAULT ((uint8_t) 1) ///< Static IP: IP address value 3 - -/*NETMASK*/ -#define STA_NETMASK_ADDR0_DEFAULT ((uint8_t) 255) ///< Static IP: Netmask value 0 -#define STA_NETMASK_ADDR1_DEFAULT ((uint8_t) 255) ///< Static IP: Netmask value 1 -#define STA_NETMASK_ADDR2_DEFAULT ((uint8_t) 255) ///< Static IP: Netmask value 2 -#define STA_NETMASK_ADDR3_DEFAULT ((uint8_t) 0) ///< Static IP: Netmask value 3 - -/*Gateway Address*/ -#define STA_GW_ADDR0_DEFAULT ((uint8_t) 0) ///< Static IP: Gateway value 0 -#define STA_GW_ADDR1_DEFAULT ((uint8_t) 0) ///< Static IP: Gateway value 1 -#define STA_GW_ADDR2_DEFAULT ((uint8_t) 0) ///< Static IP: Gateway value 2 -#define STA_GW_ADDR3_DEFAULT ((uint8_t) 0) ///< Static IP: Gateway value 3 - -/************************** Access Point Static Default ****************************/ -// #define AP_IP_ADDR0_DEFAULT (uint8_t) 10 ///< Static IP: IP address value 0 -// #define AP_IP_ADDR1_DEFAULT (uint8_t) 10 ///< Static IP: IP address value 1 -// #define AP_IP_ADDR2_DEFAULT (uint8_t) 0 ///< Static IP: IP address value 2 -// #define AP_IP_ADDR3_DEFAULT (uint8_t) 1 ///< Static IP: IP address value 3 - -/*NETMASK*/ -// #define AP_NETMASK_ADDR0_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 0 -// #define AP_NETMASK_ADDR1_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 1 -// #define AP_NETMASK_ADDR2_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 2 -// #define AP_NETMASK_ADDR3_DEFAULT (uint8_t) 0 ///< Static IP: Netmask value 3 - -/*Gateway Address*/ -// #define AP_GW_ADDR0_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 0 -// #define AP_GW_ADDR1_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 1 -// #define AP_GW_ADDR2_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 2 -// #define AP_GW_ADDR3_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 3 - -#define WLAN_SSID_DEFAULT "AP_name" ///< wifi ssid for client mode -#define WLAN_PASSKEY_DEFAULT "passkey" ///< wifi password for client mode -#define WLAN_SECURITY_DEFAULT WFM_SECURITY_MODE_WPA2_PSK ///< wifi security mode for client mode: -///< WFM_SECURITY_MODE_OPEN/WFM_SECURITY_MODE_WEP/WFM_SECURITY_MODE_WPA2_WPA1_PSK - -#define SOFTAP_SSID_DEFAULT "silabs_softap" ///< wifi ssid for soft ap mode -#define SOFTAP_PASSKEY_DEFAULT "changeme" ///< wifi password for soft ap mode -#define SOFTAP_SECURITY_DEFAULT WFM_SECURITY_MODE_WPA2_PSK ///< wifi security for soft ap mode: -///< WFM_SECURITY_MODE_OPEN/WFM_SECURITY_MODE_WEP/WFM_SECURITY_MODE_WPA2_WPA1_PSK - -#define SOFTAP_CHANNEL_DEFAULT (6) ///< wifi channel for soft ap - -#endif // DEMO_CONFIG_H diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 4bc881f5f5..f39628d484 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -20,8 +20,6 @@ import("${chip_root}/src/platform/device.gni") import("${chip_root}/third_party/silabs/efr32_sdk.gni") import("${chip_root}/third_party/silabs/silabs_board.gni") -silabs_platform_dir = "${chip_root}/src/platform/silabs" - assert(chip_device_platform == "efr32") if (chip_enable_openthread) { @@ -32,9 +30,12 @@ if (chip_crypto == "platform") { import("//build_overrides/mbedtls.gni") } -config("efr32-platform-wifi-config") { - include_dirs = [ "wifi" ] - defines = [] +source_set("logging") { + sources = [ "${chip_root}/src/platform/silabs/Logging.cpp" ] + deps = [ + "${chip_root}/src/platform:platform_base", + "${chip_root}/src/platform/logging:headers", + ] } static_library("efr32") { @@ -159,28 +160,8 @@ static_library("efr32") { "${silabs_platform_dir}/ConnectivityManagerImpl_WIFI.cpp", "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.cpp", "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.h", - "${silabs_platform_dir}/wifi/wfx_host_events.h", - "wifi/wfx_msgs.h", - "wifi/wifi_config.h", ] - if (use_wf200 || use_rs9116 || use_SiWx917) { - sources += [ - "${silabs_platform_dir}/wifi/dhcp_client.cpp", - "wifi/ethernetif.cpp", - "wifi/ethernetif.h", - "wifi/lwip_netif.cpp", - ] - } - - public_configs += [ ":efr32-platform-wifi-config" ] + public_deps += [ "${silabs_platform_dir}/wifi:wifi-platform" ] } } - -source_set("logging") { - sources = [ "${chip_root}/src/platform/silabs/Logging.cpp" ] - deps = [ - "${chip_root}/src/platform:platform_base", - "${chip_root}/src/platform/logging:headers", - ] -} diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 11921d86f3..a0efd10100 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -19,17 +19,17 @@ #include #include #include +#include + +#if SL_WIFI +#include +#endif // SL_WIFI extern "C" { #include "btl_interface.h" #include "sl_core.h" -#if SL_WIFI -#include "spi_multiplex.h" -#endif // SL_WIFI } -#include - #ifdef _SILICON_LABS_32B_SERIES_2 // Series 2 bootloader_ api calls must be called from a critical section context for thread safeness #define WRAP_BL_DFU_CALL(code) \ diff --git a/src/platform/silabs/efr32/args.gni b/src/platform/silabs/efr32/args.gni index 394e4bb1bd..501661866a 100644 --- a/src/platform/silabs/efr32/args.gni +++ b/src/platform/silabs/efr32/args.gni @@ -20,9 +20,9 @@ import("${chip_root}/examples/platform/silabs/args.gni") import("${chip_root}/src/crypto/crypto.gni") # ARM architecture flags will be set based on silabs_family. -arm_platform_config = "${efr32_sdk_build_root}/silabs_arm.gni" +arm_platform_config = "${silabs_sdk_build_root}/silabs_arm.gni" -mbedtls_target = "${efr32_sdk_build_root}:efr32_sdk" +mbedtls_target = "${silabs_sdk_build_root}:silabs_sdk" openthread_external_mbedtls = mbedtls_target diff --git a/src/platform/silabs/efr32/wifi/lwip_netif.cpp b/src/platform/silabs/efr32/wifi/lwip_netif.cpp deleted file mode 100644 index 3a0d104a90..0000000000 --- a/src/platform/silabs/efr32/wifi/lwip_netif.cpp +++ /dev/null @@ -1,156 +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 "wfx_host_events.h" -#include "wifi_config.h" - -#include "dhcp_client.h" -#include "ethernetif.h" - -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" - -#include -#include -using namespace ::chip; -using namespace ::chip::DeviceLayer; -static struct netif sta_netif; - -#ifdef SL_WFX_CONFIG_SOFTAP -static struct netif ap_netif; -#endif - -/**************************************************************************** - * @fn static void netif_config(struct netif *sta_if, struct netif *ap_if) - * @brief - * netif configuration - * @param[in] sta_if: - * @param[in] ap_if: - * @return None - *****************************************************************************/ -static void netif_config(struct netif * sta_if, struct netif * ap_if) -{ - if (sta_if != NULL) - { -#if LWIP_IPV4 - ip_addr_t sta_ipaddr; - ip_addr_t sta_netmask; - ip_addr_t sta_gw; - - /* Initialize the Station information */ - ip_addr_set_zero_ip4(&sta_ipaddr); - ip_addr_set_zero_ip4(&sta_netmask); - ip_addr_set_zero_ip4(&sta_gw); -#endif /* LWIP_IPV4 */ - - /* Add station interfaces */ - netif_add(sta_if, -#if LWIP_IPV4 - (const ip4_addr_t *) &sta_ipaddr, (const ip4_addr_t *) &sta_netmask, (const ip4_addr_t *) &sta_gw, -#endif /* LWIP_IPV4 */ - NULL, &sta_ethernetif_init, &tcpip_input); - - /* Registers the default network interface */ - netif_set_default(sta_if); - } -} - -/**************************************************************************** - * @fn void wfx_lwip_set_sta_link_up(void) - * @brief - * Set station link status to up. - * @param[in] None - * @return None - *****************************************************************************/ -void wfx_lwip_set_sta_link_up(void) -{ - netifapi_netif_set_up(&sta_netif); - netifapi_netif_set_link_up(&sta_netif); -#if LWIP_IPV4 && LWIP_DHCP - dhcpclient_set_link_state(LINK_UP); -#endif /* LWIP_IPV4 && LWIP_DHCP */ - /* - * Enable IPV6 - */ - -#if LWIP_IPV6_AUTOCONFIG - sta_netif.ip6_autoconfig_enabled = 1; -#endif /* LWIP_IPV6_AUTOCONFIG */ - netif_create_ip6_linklocal_address(&sta_netif, MAC_48_BIT_SET); -} - -/*************************************************************************** - * @fn void wfx_lwip_set_sta_link_down(void) - * @brief - * Set station link status to down. - * @param[in] None - * @return None - *****************************************************************************/ -void wfx_lwip_set_sta_link_down(void) -{ -#if LWIP_IPV4 && LWIP_DHCP - dhcpclient_set_link_state(LINK_DOWN); -#endif /* LWIP_IPV4 && LWIP_DHCP */ - netifapi_netif_set_link_down(&sta_netif); - netifapi_netif_set_down(&sta_netif); -} - -/*************************************************************************** - * @fn void wfx_lwip_start(void) - * @brief - * Initialize the LwIP stack - * @param[in] None - * @return None - *****************************************************************************/ -void wfx_lwip_start(void) -{ - /* Initialize the LwIP stack */ - netif_config(&sta_netif, NULL); -} - -/*************************************************************************** - * @fn struct netif *wfx_get_netif(sl_wfx_interface_t interface) - * @brief - * get the netif - * @param[in] interface: - * @return None - *****************************************************************************/ -struct netif * wfx_get_netif(sl_wfx_interface_t interface) -{ - if (interface == SL_WFX_STA_INTERFACE) - { - return &sta_netif; - } -#ifdef SL_WFX_CONFIG_SOFTAP - else if (interface == SL_WFX_SOFTAP_INTERFACE) - { - return &ap_netif; - } -#endif - return (struct netif *) 0; -} diff --git a/src/platform/silabs/efr32/wifi/wfx_msgs.h b/src/platform/silabs/efr32/wifi/wfx_msgs.h deleted file mode 100644 index edf0aec582..0000000000 --- a/src/platform/silabs/efr32/wifi/wfx_msgs.h +++ /dev/null @@ -1,182 +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. - */ - -#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 - */ -typedef struct -{ - uint8_t octet[6]; ///< Table to store a MAC address -} sl_wfx_mac_address_t; -/** - * @brief General Message header structure - * - */ -typedef struct __attribute__((__packed__)) sl_wfx_header_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 info; ///< TODO comment missing -} sl_wfx_header_t; - -/** - * @brief Generic message structure for all requests, confirmations and indications - * - */ -typedef struct __attribute__((__packed__)) sl_wfx_generic_message_s -{ - sl_wfx_header_t header; ///< 4 bytes header - uint8_t body[]; ///< variable size payload of the message -} sl_wfx_generic_message_t; -#define SL_WFX_OPN_SIZE 14 -#define SL_WFX_UID_SIZE 8 -#define SL_WFX_DISABLED_CHANNEL_LIST_SIZE 2 -#define SL_WFX_FIRMWARE_LABEL_SIZE 128 -/** - * @brief Startup Indication message. - * This is the first message sent to the host to confirm boot success. - * It gives detailed information on the HW and FW versions and capabilities - */ -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; ///WFM_STATUS_SUCCESS: the connection request was completed successfully. - *
any other value: the connection request failed. - *
See sl_wfx_fmac_status_t for enumeration values. - */ - uint32_t status; - /** - * @brief MAC address of the connected access point. - */ - uint8_t mac[6]; - /** - * @brief Channel of the connected access point. - * @details 1 - 13: Channel number. - */ - uint16_t channel; - /** - * @brief Beacon Interval of the connected access point. - */ - uint8_t beacon_interval; - /** - * @brief DTIM period of the connected access point. - * @details 1 - 255: DTIM period. - */ - uint8_t dtim_period; - /** - * @brief Maximum PHY data rate supported by the connection. - * @details See sl_wfx_rate_index_t for enumeration values. - */ - uint16_t max_phy_rate; -} sl_wfx_connect_ind_body_t; - -/** - * @brief Indication message used to signal the completion of a connection operation. - * @details The device will send this indication to signal the connection request initiated - * with sl_wfx_connect_req_t has been completed. The indication is also sent when - * the device autonomously roams to another access point. - * @ingroup WFM_GROUP_MODE_IDLE - */ -typedef struct __attribute__((__packed__)) sl_wfx_connect_ind_s -{ - /** Common message header. */ - sl_wfx_header_t header; - /** Indication message body. */ - sl_wfx_connect_ind_body_t body; -} sl_wfx_connect_ind_t; -/** - * @brief Indication message body for sl_wfx_disconnect_ind_t. - */ -typedef struct __attribute__((__packed__)) sl_wfx_disconnect_ind_body_s -{ - /** - * @brief MAC address of the access point. - */ - uint8_t mac[6]; - /** - * @brief Reason for disconnection. - * @details WFM_DISCONNECTED_REASON_UNSPECIFIED: The device disconnected because of an internal error. - *
WFM_DISCONNECTED_REASON_AP_LOST: The device lost the AP beacons for too long. - *
WFM_DISCONNECTED_REASON_REJECTED: The device was disconnected by the AP. - *
WFM_DISCONNECTED_REASON_LEAVING_BSS: Disconnection was requested through the device API. - *
WFM_DISCONNECTED_REASON_WPA_COUNTERMEASURES: WPA countermeasures triggered a disconnection - *
See sl_wfx_disconnected_reason_t for enumeration values. - */ - uint16_t reason; -} sl_wfx_disconnect_ind_body_t; - -/** - * @brief Indication message used to signal the completion of a disconnection operation. - * @details The device will send this indication to signal the disconnection request initiated - * with sl_wfx_disconnect_req_t has been completed. The indication is also sent when - * the device has lost the connection to an access point and has been unable to regain it. - * @ingroup WFM_GROUP_MODE_STA - */ -typedef struct __attribute__((__packed__)) sl_wfx_disconnect_ind_s -{ - /** Common message header. */ - sl_wfx_header_t header; - /** Indication message body. */ - sl_wfx_disconnect_ind_body_t body; -} sl_wfx_disconnect_ind_t; - -#endif /* _WFX_MSGS_H_ */ diff --git a/src/platform/silabs/efr32/wifi/wifi_config.h b/src/platform/silabs/efr32/wifi/wifi_config.h deleted file mode 100644 index 8e00201b7f..0000000000 --- a/src/platform/silabs/efr32/wifi/wifi_config.h +++ /dev/null @@ -1,53 +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. - */ - -#ifndef WIFI_CONFIG_H -#define WIFI_CONFIG_H - -#define USE_DHCP_CLIENT_DEFAULT 1 ///< If defined, DHCP is enabled, otherwise static address below is used - -/************************** Station Static Default ****************************/ -#define STA_IP_ADDR0_DEFAULT (uint8_t) 192 ///< Static IP: IP address value 0 -#define STA_IP_ADDR1_DEFAULT (uint8_t) 168 ///< Static IP: IP address value 1 -#define STA_IP_ADDR2_DEFAULT (uint8_t) 0 ///< Static IP: IP address value 2 -#define STA_IP_ADDR3_DEFAULT (uint8_t) 1 ///< Static IP: IP address value 3 - -/*NETMASK*/ -#define STA_NETMASK_ADDR0_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 0 -#define STA_NETMASK_ADDR1_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 1 -#define STA_NETMASK_ADDR2_DEFAULT (uint8_t) 255 ///< Static IP: Netmask value 2 -#define STA_NETMASK_ADDR3_DEFAULT (uint8_t) 0 ///< Static IP: Netmask value 3 - -/*Gateway Address*/ -#define STA_GW_ADDR0_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 0 -#define STA_GW_ADDR1_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 1 -#define STA_GW_ADDR2_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 2 -#define STA_GW_ADDR3_DEFAULT (uint8_t) 0 ///< Static IP: Gateway value 3 - -#define WLAN_SSID_DEFAULT "AP_name" ///< wifi ssid for client mode -#define WLAN_PASSKEY_DEFAULT "passkey" ///< wifi password for client mode -#define WLAN_SECURITY_DEFAULT WFM_SECURITY_MODE_WPA2_PSK ///< wifi security mode for client mode: -///< WFM_SECURITY_MODE_OPEN/WFM_SECURITY_MODE_WEP/WFM_SECURITY_MODE_WPA2_WPA1_PSK - -#define SOFTAP_SSID_DEFAULT "silabs_softap" ///< wifi ssid for soft ap mode -#define SOFTAP_PASSKEY_DEFAULT "changeme" ///< wifi password for soft ap mode -#define SOFTAP_SECURITY_DEFAULT WFM_SECURITY_MODE_WPA2_PSK ///< wifi security for soft ap mode: -///< WFM_SECURITY_MODE_OPEN/WFM_SECURITY_MODE_WEP/WFM_SECURITY_MODE_WPA2_WPA1_PSK - -#define SOFTAP_CHANNEL_DEFAULT 6 ///< wifi channel for soft ap - -#endif // WIFI_CONFIG_H diff --git a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp index 2e0ab6b811..361dfa93a4 100644 --- a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp +++ b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp @@ -218,8 +218,7 @@ void SilabsPlatform::StartScheduler() } #ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT -extern "C" { -void sl_button_on_change(const sl_button_t * handle) +extern "C" void sl_button_on_change(const sl_button_t * handle) { if (Silabs::GetPlatform().mButtonCallback == nullptr) { @@ -235,7 +234,6 @@ void sl_button_on_change(const sl_button_t * handle) } } } -} uint8_t SilabsPlatform::GetButtonState(uint8_t button) { diff --git a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp index 7e5be6c1bf..1b03de76f3 100644 --- a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp +++ b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp @@ -152,8 +152,7 @@ void SilabsPlatform::StartScheduler() vTaskStartScheduler(); } -extern "C" { -void sl_button_on_change(uint8_t btn, uint8_t btnAction) +extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction) { #if SL_ICD_ENABLED // This is to make sure we get a one-press and one-release event for the button @@ -161,21 +160,21 @@ void sl_button_on_change(uint8_t btn, uint8_t btnAction) // Currently the btn0 is pull-up resistor due to which is sends a release event on every wakeup if (btn == SL_BUTTON_BTN0_NUMBER) { - if (btnAction == BUTTON_PRESSED) + // if the btn was not pressed and only a release event came, ignore it + // if the btn was already pressed and another press event came, ignore it + // essentially, if both of them are in the same state then ignore it. + VerifyOrReturn(btnAction != btn0_pressed); + + if ((btnAction == BUTTON_PRESSED) && (btn0_pressed == false)) { btn0_pressed = true; } - else if ((btnAction == BUTTON_RELEASED) && (btn0_pressed == false)) - { - // if the btn was not pressed and only a release event came, ignore it - return; - } else if ((btnAction == BUTTON_RELEASED) && (btn0_pressed == true)) { btn0_pressed = false; } } -#endif /* SL_ICD_ENABLED */ +#endif // SL_ICD_ENABLED if (Silabs::GetPlatform().mButtonCallback == nullptr) { return; @@ -187,7 +186,6 @@ void sl_button_on_change(uint8_t btn, uint8_t btnAction) } Silabs::GetPlatform().mButtonCallback(btn, btnAction); } -} uint8_t SilabsPlatform::GetButtonState(uint8_t button) { diff --git a/src/platform/silabs/provision/BUILD.gn b/src/platform/silabs/provision/BUILD.gn index ea5d4b072a..7ae41c0515 100644 --- a/src/platform/silabs/provision/BUILD.gn +++ b/src/platform/silabs/provision/BUILD.gn @@ -14,7 +14,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_board.gni") +import("${silabs_sdk_build_root}/silabs_board.gni") config("provision-config") { include_dirs = [ "." ] diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 176f396f44..75f118b38a 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -26,30 +26,25 @@ #include #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 f508c3396f..b28c810679 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 971852592c..8916999381 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 54351674ef..4eaff9c067 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -22,22 +22,20 @@ */ #pragma once -/** - * Include files - * */ // BLE include file to refer BLE APIs #include "ble_config.h" #include "cmsis_os2.h" -#include "wfx_host_events.h" -#include "wfx_rsi.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/BUILD.gn b/src/platform/silabs/wifi/BUILD.gn new file mode 100644 index 0000000000..882a66deb4 --- /dev/null +++ b/src/platform/silabs/wifi/BUILD.gn @@ -0,0 +1,150 @@ +# 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, +# 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. + +import("//build_overrides/chip.gni") +import("//build_overrides/lwip.gni") +import("${chip_root}/src/platform/device.gni") +import("${chip_root}/third_party/silabs/efr32_sdk.gni") +import("${chip_root}/third_party/silabs/silabs_board.gni") + +declare_args() { + # Wifi related stuff - they are overridden by gn -args="use_wf200=true" + sl_wfx_config_softap = false + sl_wfx_config_scan = true + + # Argument to force enable WPA3 security on rs91x + rs91x_wpa3_transition = true + + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" +} + +if (chip_enable_wifi && !wifi_soc) { + assert(use_rs9116 || use_wf200 || use_SiWx917) + import("${chip_root}/src/platform/silabs/wifi/args.gni") + + if (use_rs9116) { + import("${silabs_platform_dir}/wifi/rs911x/rs911x.gni") + } else if (use_SiWx917) { + import("${silabs_platform_dir}/wifi/rs911x/rs9117.gni") + } + if (use_wf200) { + import("${silabs_platform_dir}/wifi/wf200/wf200.gni") + } +} + +config("wifi-platform-config") { + defines = [] + include_dirs = [] + + if (use_rs9116) { + # All the stuff from wiseconnect + include_dirs += rs911x_inc_plat + } else if (use_SiWx917) { + # All the stuff from wiseconnect + include_dirs += rs9117_inc_plat + } + + if (chip_default_wifi_ssid != "") { + defines += [ + "SL_ONNETWORK_PAIRING=1", + "SL_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "SL_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } + + if (sl_wfx_config_softap) { + defines += [ "SL_WFX_CONFIG_SOFTAP" ] + } + + if (sl_wfx_config_scan) { + defines += [ "SL_WFX_CONFIG_SCAN" ] + } + + if (chip_enable_wifi_ipv4) { + defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4" ] + } + + if (rs91x_wpa3_transition) { + # TODO: Change this macro once WF200 support is provided + defines += [ "WIFI_ENABLE_SECURITY_WPA3_TRANSITION=1" ] + } + + # TODO: This defines needs to be here for the spi_multiplex.h configuration header. + # We need to find a better way to handle this. + if (!disable_lcd) { + defines += [ "DISPLAY_ENABLED" ] + } +} + +source_set("wifi-platform") { + sources = [ + "${silabs_platform_dir}/wifi/WifiInterfaceAbstraction.cpp", + "${silabs_platform_dir}/wifi/WifiInterfaceAbstraction.h", + "${silabs_platform_dir}/wifi/wfx_msgs.h", + ] + + public_configs = [ ":wifi-platform-config" ] + + public_deps = [ + "${chip_root}/src/app/icd/server:icd-server-config", + "${chip_root}/src/inet", + "${chip_root}/src/lib/support", + ] + + if (use_rs9116) { + sources += rs911x_src_plat + + # All the stuff from wiseconnect + sources += rs911x_src_sapi + } else if (use_SiWx917) { + sources += rs911x_src_plat + + # All the stuff from wiseconnect + sources += rs9117_src_sapi + + #add compilation flags for rs991x build. This will be addressed directly in wiseconnect sdk in the next version release of that sdk + } else if (use_wf200) { + sources += wf200_plat_src + } + + if (wifi_soc) { + sources += [ + "${silabs_platform_dir}/wifi/SiWx/WifiInterface.cpp", + "${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp", + "${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h", + + # Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed + "${sdk_support_root}/components/service/network_manager/src/sl_net_for_lwip.c", + ] + + public_deps += [ "${lwip_root}:lwip" ] + } + + if (use_wf200 || use_rs9116) { + sources += [ + "${silabs_platform_dir}/wifi/lwip-support/dhcp_client.cpp", + "${silabs_platform_dir}/wifi/lwip-support/ethernetif.cpp", + "${silabs_platform_dir}/wifi/lwip-support/ethernetif.h", + "${silabs_platform_dir}/wifi/lwip-support/lwip_netif.cpp", + ] + } +} diff --git a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp new file mode 100644 index 0000000000..aa25647395 --- /dev/null +++ b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp @@ -0,0 +1,902 @@ +/* + * + * Copyright (c) 2023 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. + */ + +/* + * This file implements the interface to the wifi sdk + */ + +#include +#include +#include + +#if (SL_MATTER_GN_BUILD == 0) +#include "sl_matter_wifi_config.h" +#endif // SL_MATTER_GN_BUILD + +#include "FreeRTOS.h" +#include "ble_config.h" +#include "event_groups.h" +#include "sl_status.h" +#include "sl_wifi_device.h" +#include "task.h" +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include "sl_si91x_driver.h" +#include "sl_si91x_host_interface.h" +#include "sl_si91x_types.h" +#include "sl_wifi.h" +#include "sl_wifi_callback_framework.h" +#include "sl_wifi_constants.h" +#include "sl_wifi_types.h" +#if SL_MBEDTLS_USE_TINYCRYPT +#include "sl_si91x_constants.h" +#include "sl_si91x_trng.h" +#endif // SL_MBEDTLS_USE_TINYCRYPT + +#include +#include +#include +#include +} + +#if SLI_SI91X_MCU_INTERFACE +#include "rsi_wisemcu_hardware_setup.h" +#endif // SLI_SI91X_MCU_INTERFACE + +#if (EXP_BOARD) +#include "rsi_bt_common_apis.h" +#include +#endif + +#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE +#include "rsi_rom_power_save.h" +#include "sl_gpio_board.h" +#include "sl_si91x_driver_gpio.h" +#include "sl_si91x_power_manager.h" +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE + +WfxRsi_t wfx_rsi; +extern osSemaphoreId_t sl_rs_ble_init_sem; + +// [SLC-TEMP] Adding power manager include until we update wiseconnect version and upstream the changes +#include "sl_si91x_power_manager.h" + +namespace { + +#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE +// TODO: should be removed once we are getting the press interrupt for button 0 with sleep +bool btn0_pressed = false; +#ifdef ENABLE_CHIP_SHELL +bool ps_requirement_added = false; +#endif // ENABLE_CHIP_SHELL +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE + +bool hasNotifiedWifiConnectivity = false; +bool hasNotifiedIPV6 = false; +#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) +bool hasNotifiedIPV4 = false; +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + +wfx_wifi_scan_ext_t temp_reset; + +osSemaphoreId_t sScanCompleteSemaphore; +osSemaphoreId_t sScanInProgressSemaphore; +osTimerId_t sDHCPTimer; +osMessageQueueId_t sWifiEventQueue = nullptr; + +sl_net_wifi_lwip_context_t wifi_client_context; +sl_wifi_security_t security = SL_WIFI_SECURITY_UNKNOWN; + +const sl_wifi_device_configuration_t config = { + .boot_option = LOAD_NWP_FW, + .mac_address = NULL, + .band = SL_SI91X_WIFI_BAND_2_4GHZ, + .region_code = US, + .boot_config = { .oper_mode = SL_SI91X_CLIENT_MODE, + .coex_mode = SL_SI91X_WLAN_BLE_MODE, + .feature_bit_map = +#ifdef SLI_SI91X_MCU_INTERFACE + (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE), +#else + (SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_AGGREGATION), +#endif + .tcp_ip_feature_bit_map = (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_DNS_CLIENT | + SL_SI91X_TCP_IP_FEAT_SSL | SL_SI91X_TCP_IP_FEAT_BYPASS +#ifdef ipv6_FEATURE_REQUIRED + | SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6 +#endif + | SL_SI91X_TCP_IP_FEAT_ICMP | SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID), + .custom_feature_bit_map = (SL_SI91X_CUSTOM_FEAT_EXTENTION_VALID | RSI_CUSTOM_FEATURE_BIT_MAP), + .ext_custom_feature_bit_map = (RSI_EXT_CUSTOM_FEATURE_BIT_MAP | (SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE) +#if (defined A2DP_POWER_SAVE_ENABLE) + | SL_SI91X_EXT_FEAT_XTAL_CLK_ENABLE(2) +#endif + ), + .bt_feature_bit_map = (RSI_BT_FEATURE_BITMAP +#if (RSI_BT_GATT_ON_CLASSIC) + | SL_SI91X_BT_ATT_OVER_CLASSIC_ACL /* to support att over classic acl link */ +#endif + ), +#ifdef RSI_PROCESS_MAX_RX_DATA + .ext_tcp_ip_feature_bit_map = + (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID | SL_SI91X_EXT_TCP_MAX_RECV_LENGTH), +#else + .ext_tcp_ip_feature_bit_map = (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID), +#endif + //! ENABLE_BLE_PROTOCOL in bt_feature_bit_map + .ble_feature_bit_map = + ((SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) | + SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) | + SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) | + SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC)) | + SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENTION_VALID | SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) | + SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) | SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE +#if RSI_BLE_GATT_ASYNC_ENABLE + | SL_SI91X_BLE_GATT_ASYNC_ENABLE +#endif + ), + + .ble_ext_feature_bit_map = ((SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) | + SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES)) +#if RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST + | SL_SI91X_BLE_INDICATE_CONFIRMATION_FROM_HOST // indication response from app +#endif +#if RSI_BLE_MTU_EXCHANGE_FROM_HOST + | SL_SI91X_BLE_MTU_EXCHANGE_FROM_HOST // MTU Exchange request initiation from app +#endif +#if RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST + | (SL_SI91X_BLE_SET_SCAN_RESP_DATA_FROM_HOST) // Set SCAN Resp Data from app +#endif +#if RSI_BLE_DISABLE_CODED_PHY_FROM_HOST + | (SL_SI91X_BLE_DISABLE_CODED_PHY_FROM_HOST) // Disable Coded PHY from app +#endif +#if BLE_SIMPLE_GATT + | SL_SI91X_BLE_GATT_INIT +#endif + ), + .config_feature_bit_map = (SL_SI91X_FEAT_SLEEP_GPIO_SEL_BITMAP | RSI_CONFIG_FEATURE_BITMAP) } +}; + +constexpr int8_t kAdvScanThreshold = -40; +constexpr uint8_t kAdvRssiToleranceThreshold = 5; +constexpr uint8_t kAdvActiveScanDuration = 15; +constexpr uint8_t kAdvPassiveScanDuration = 20; +constexpr uint8_t kAdvMultiProbe = 1; +constexpr uint8_t kAdvScanPeriodicity = 10; + +// TODO: Confirm that this value works for size and timing +constexpr uint8_t kWfxQueueSize = 10; + +// TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else. +constexpr uint16_t kWifiScanTimeoutTicks = 10000; + +void DHCPTimerEventHandler(void * arg) +{ + WifiEvent event = WifiEvent::kStationDhcpPoll; + sl_matter_wifi_post_event(event); +} + +void CancelDHCPTimer(void) +{ + VerifyOrReturn(osTimerIsRunning(sDHCPTimer), ChipLogDetail(DeviceLayer, "CancelDHCPTimer: timer not running")); + VerifyOrReturn(osTimerStop(sDHCPTimer) == osOK, ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer")); +} + +void StartDHCPTimer(uint32_t timeout) +{ + // Cancel timer if already started + CancelDHCPTimer(); + + VerifyOrReturn(osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)) == osOK, + ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer")); +} + +sl_status_t sl_wifi_siwx917_init(void) +{ + sl_status_t status = SL_STATUS_OK; + +#ifdef SLI_SI91X_MCU_INTERFACE + // SoC Configurations + uint8_t xtal_enable = 1; + status = sl_si91x_m4_ta_secure_handshake(SL_SI91X_ENABLE_XTAL, 1, &xtal_enable, 0, nullptr); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_si91x_m4_ta_secure_handshake failed: 0x%lx", static_cast(status))); + +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#ifdef ENABLE_CHIP_SHELL + // While using the matter shell with a Low Power Build, GPIO 1 is used to check the UULP PIN 1 status + // since UART doesn't act as a wakeup source in the UULP mode. + + // Configuring the NPS GPIO 1 + RSI_NPSSGPIO_SetPinMux(RTE_UULP_GPIO_1_PIN, 0); + + // Configure the NPSS GPIO direction to input + RSI_NPSSGPIO_SetDir(RTE_UULP_GPIO_1_PIN, 1); + + // Enable the REN + RSI_NPSSGPIO_InputBufferEn(RTE_UULP_GPIO_1_PIN, 1); +#endif // ENABLE_CHIP_SHELL +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + +#else + // NCP Configurations + status = sl_matter_wifi_platform_init(); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_matter_wifi_platform_init failed: 0x%lx", static_cast(status))); +#endif // SLI_SI91X_MCU_INTERFACE + + sl_wifi_firmware_version_t version = { 0 }; + status = sl_wifi_get_firmware_version(&version); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_wifi_get_firmware_version failed: 0x%lx", static_cast(status))); + + ChipLogDetail(DeviceLayer, "Firmware version is: %x%x.%d.%d.%d.%d.%d.%d", version.chip_id, version.rom_id, version.major, + version.minor, version.security_version, version.patch_num, version.customer_id, version.build_num); + + status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_wifi_get_mac_address failed: 0x%lx", static_cast(status))); + +#ifdef SL_MBEDTLS_USE_TINYCRYPT + constexpr uint32_t trngKey[TRNG_KEY_SIZE] = { 0x16157E2B, 0xA6D2AE28, 0x8815F7AB, 0x3C4FCF09 }; + + // To check the Entropy of TRNG and verify TRNG functioning. + status = sl_si91x_trng_entropy(); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_si91x_trng_entropy failed: 0x%lx", static_cast(status))); + + // Initiate and program the key required for TRNG hardware engine + status = sl_si91x_trng_program_key((uint32_t *) trngKey, TRNG_KEY_SIZE); + VerifyOrReturnError(status == SL_STATUS_OK, status, + ChipLogError(DeviceLayer, "sl_si91x_trng_program_key failed: 0x%lx", static_cast(status))); +#endif // SL_MBEDTLS_USE_TINYCRYPT + + wfx_rsi.dev_state.Set(WifiState::kStationInit); + osSemaphoreRelease(sl_rs_ble_init_sem); + return status; +} + +// TODO: this changes will be reverted back after the Silabs WiFi SDK team fix the scan API +#ifndef EXP_BOARD +sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_result, uint32_t result_length, void * arg) +{ + sl_status_t status = SL_STATUS_OK; + if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) + { + ChipLogError(DeviceLayer, "Scan Netwrok Failed: 0x%lx", *reinterpret_cast(status)); +#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION + security = SL_WIFI_WPA3; +#else + security = SL_WIFI_WPA_WPA2_MIXED; +#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ + + status = SL_STATUS_FAIL; + } + else + { + security = static_cast(scan_result->scan_info[0].security_mode); + wfx_rsi.ap_chan = scan_result->scan_info[0].rf_channel; + memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, BSSID_LEN); + } + + osSemaphoreRelease(sScanCompleteSemaphore); + return status; +} +#endif + +sl_status_t InitiateScan() +{ + sl_status_t status = SL_STATUS_OK; + +// TODO: this changes will be reverted back after the Silabs WiFi SDK team fix the scan API +#ifndef EXP_BOARD + sl_wifi_ssid_t ssid = { 0 }; + + // TODO: this changes will be reverted back after the Silabs WiFi SDK team fix the scan API + sl_wifi_scan_configuration_t wifi_scan_configuration = default_wifi_scan_configuration; + + ssid.length = wfx_rsi.sec.ssid_length; + + // TODO: workaround because the string management with the null termination is flawed + chip::Platform::CopyString((char *) &ssid.value[0], ssid.length + 1, wfx_rsi.sec.ssid); + sl_wifi_set_scan_callback(ScanCallback, NULL); + + osSemaphoreAcquire(sScanInProgressSemaphore, osWaitForever); + + // This is an odd success code? + status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, &ssid, &wifi_scan_configuration); + if (status == SL_STATUS_IN_PROGRESS) + { + osSemaphoreAcquire(sScanCompleteSemaphore, kWifiScanTimeoutTicks); + status = SL_STATUS_OK; + } + + osSemaphoreRelease(sScanInProgressSemaphore); +#endif + + return status; +} + +sl_status_t SetWifiConfigurations() +{ + sl_status_t status = SL_STATUS_OK; + +#if CHIP_CONFIG_ENABLE_ICD_SERVER + // Setting the listen interval to 0 which will set it to DTIM interval + sl_wifi_listen_interval_t sleep_interval = { .listen_interval = 0 }; + status = sl_wifi_set_listen_interval(SL_WIFI_CLIENT_INTERFACE, sleep_interval); + VerifyOrReturnError(status == SL_STATUS_OK, status); + + sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 }; + status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config); + VerifyOrReturnError(status == SL_STATUS_OK, status); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + + status = sl_net_set_credential(SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], + wfx_rsi.sec.passkey_length); + VerifyOrReturnError(status == SL_STATUS_OK, status); + + sl_net_wifi_client_profile_t profile = { + .config = { + .ssid = { + //static cast because the types dont match + .length = static_cast(wfx_rsi.sec.ssid_length), + }, + .channel = { + .channel = SL_WIFI_AUTO_CHANNEL, + .band = SL_WIFI_AUTO_BAND, + .bandwidth = SL_WIFI_AUTO_BANDWIDTH + }, + .bssid = {{0}}, + .bss_type = SL_WIFI_BSS_TYPE_INFRASTRUCTURE, + .security = security, + .encryption = SL_WIFI_NO_ENCRYPTION, + .client_options = SL_WIFI_JOIN_WITH_SCAN, + .credential_id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID, + }, + .ip = { + .mode = SL_IP_MANAGEMENT_DHCP, + .type = SL_IPV6, + .host_name = NULL, + .ip = {{{0}}}, + } + }; + // TODO: memcpy for now since the types dont match + memcpy((char *) &profile.config.ssid.value, wfx_rsi.sec.ssid, wfx_rsi.sec.ssid_length); + + status = sl_net_set_profile((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID, &profile); + VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_set_profile Failed")); + + return status; +} + +sl_status_t JoinWifiNetwork(void) +{ + VerifyOrReturnError(!wfx_rsi.dev_state.HasAny(WifiState::kStationConnecting, WifiState::kStationConnected), + SL_STATUS_IN_PROGRESS); + sl_status_t status = SL_STATUS_OK; + + // Start Join Network + wfx_rsi.dev_state.Set(WifiState::kStationConnecting); + + status = SetWifiConfigurations(); + VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "Failure to set the Wifi Configurations!")); + + status = sl_net_up((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID); + + if (status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS) + { + WifiEvent event = WifiEvent::kStationConnect; + sl_matter_wifi_post_event(event); + return status; + } + + // failure only happens when the firmware returns an error + ChipLogError(DeviceLayer, "sl_wifi_connect failed: 0x%lx", static_cast(status)); + VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status); + + wfx_rsi.dev_state.Clear(WifiState::kStationConnecting).Clear(WifiState::kStationConnected); + + ChipLogProgress(DeviceLayer, "Connection retry attempt %d", wfx_rsi.join_retries); + wfx_retry_connection(++wfx_rsi.join_retries); + + WifiEvent event = WifiEvent::kStationStartJoin; + sl_matter_wifi_post_event(event); + + return status; +} + +} // 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 + * Getting the AP details + * @param[in] ap: access point + * @return + * status + *********************************************************************/ +int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) +{ + sl_status_t status = SL_STATUS_OK; + int32_t rssi = 0; + ap->ssid_length = wfx_rsi.sec.ssid_length; + ap->security = wfx_rsi.sec.security; + ap->chan = wfx_rsi.ap_chan; + chip::Platform::CopyString(ap->ssid, ap->ssid_length, wfx_rsi.sec.ssid); + memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_LEN); + sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); + ap->rssi = rssi; + return status; +} + +/****************************************************************** + * @fn int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t *extra_info) + * @brief + * Getting the AP extra details + * @param[in] extra info: access point extra information + * @return + * status + *********************************************************************/ +int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) +{ + sl_status_t status = SL_STATUS_OK; + sl_wifi_statistics_t test = { 0 }; + status = sl_wifi_get_statistics(SL_WIFI_CLIENT_INTERFACE, &test); + VERIFY_STATUS_AND_RETURN(status); + extra_info->beacon_lost_count = test.beacon_lost_count - temp_reset.beacon_lost_count; + extra_info->beacon_rx_count = test.beacon_rx_count - temp_reset.beacon_rx_count; + extra_info->mcast_rx_count = test.mcast_rx_count - temp_reset.mcast_rx_count; + extra_info->mcast_tx_count = test.mcast_tx_count - temp_reset.mcast_tx_count; + extra_info->ucast_rx_count = test.ucast_rx_count - temp_reset.ucast_rx_count; + extra_info->ucast_tx_count = test.ucast_tx_count - temp_reset.ucast_tx_count; + extra_info->overrun_count = test.overrun_count - temp_reset.overrun_count; + return status; +} + +/****************************************************************** + * @fn int32_t wfx_rsi_reset_count(void) + * @brief + * Getting the driver reset count + * @param[in] None + * @return + * status + *********************************************************************/ +int32_t wfx_rsi_reset_count(void) +{ + sl_wifi_statistics_t test = { 0 }; + sl_status_t status = SL_STATUS_OK; + status = sl_wifi_get_statistics(SL_WIFI_CLIENT_INTERFACE, &test); + VERIFY_STATUS_AND_RETURN(status); + temp_reset.beacon_lost_count = test.beacon_lost_count; + temp_reset.beacon_rx_count = test.beacon_rx_count; + temp_reset.mcast_rx_count = test.mcast_rx_count; + temp_reset.mcast_tx_count = test.mcast_tx_count; + temp_reset.ucast_rx_count = test.ucast_rx_count; + temp_reset.ucast_tx_count = test.ucast_tx_count; + temp_reset.overrun_count = test.overrun_count; + return status; +} + +/****************************************************************** + * @fn sl_wifi_platform_disconnect(void) + * @brief + * Getting the driver disconnect status + * @param[in] None + * @return + * status + *********************************************************************/ +int32_t sl_wifi_platform_disconnect(void) +{ + return sl_net_down((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE); +} + +/****************************************************************** + * @fn wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) + * @brief + * Setting the RS911x in DTIM sleep based mode + * + * @param[in] sl_si91x_ble_state : State to set for the BLE + * @param[in] sl_si91x_wifi_state : State to set for the WiFi + * @return + * None + *********************************************************************/ +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) +{ + int32_t status; + + status = rsi_bt_power_save_profile(sl_si91x_ble_state, 0); + if (status != RSI_SUCCESS) + { + ChipLogError(DeviceLayer, "rsi_bt_power_save_profile failed: 0x%lx", static_cast(status)); + return status; + } + sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state }; + status = sl_wifi_set_performance_profile(&wifi_profile); + if (status != RSI_SUCCESS) + { + ChipLogError(DeviceLayer, "sl_wifi_set_performance_profile failed: 0x%lx", static_cast(status)); + return status; + } + + return status; +} + +sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) +{ + SL_WIFI_ARGS_CHECK_NULL_POINTER(scan_result); + VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, SL_STATUS_INVALID_HANDLE); + + wfx_wifi_scan_result_t cur_scan_result; + for (int idx = 0; idx < (int) scan_result->scan_count; idx++) + { + memset(&cur_scan_result, 0, sizeof(cur_scan_result)); + + cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, + chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + // cur_scan_result.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the cur_scan_result.ssid_length calculated above + chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, + (char *) scan_result->scan_info[idx].ssid); // +1 for null termination + + // 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))) == + 0)) + { + continue; + } + cur_scan_result.security = static_cast(scan_result->scan_info[idx].security_mode); + cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val; + memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN); + wfx_rsi.scan_cb(&cur_scan_result); + + // if user has not provided the ssid, then call the callback for each scan result + if (wfx_rsi.scan_ssid == nullptr) + { + continue; + } + break; + } + + // cleanup and return + wfx_rsi.dev_state.Clear(WifiState::kScanStarted); + wfx_rsi.scan_cb((wfx_wifi_scan_result_t *) 0); + wfx_rsi.scan_cb = nullptr; + if (wfx_rsi.scan_ssid) + { + chip::Platform::MemoryFree(wfx_rsi.scan_ssid); + wfx_rsi.scan_ssid = nullptr; + } + return SL_STATUS_OK; +} + +sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * result, uint32_t result_length, void * arg) +{ + show_scan_results(result); // To do Check error + osSemaphoreRelease(sScanCompleteSemaphore); + return SL_STATUS_OK; +} + +/// NotifyConnectivity +/// @brief Notify the application about the connectivity status if it has not been notified yet. +/// Helper function for HandleDHCPPolling. +void NotifyConnectivity(void) +{ + VerifyOrReturn(!hasNotifiedWifiConnectivity); + wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); + hasNotifiedWifiConnectivity = true; +} + +void HandleDHCPPolling(void) +{ + WifiEvent event; + + // TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state + struct netif * sta_netif = &wifi_client_context.netif; + VerifyOrReturn(sta_netif != nullptr, ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif")); + +#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) + uint8_t dhcp_state = dhcpclient_poll(sta_netif); + if (dhcp_state == DHCP_ADDRESS_ASSIGNED && !hasNotifiedIPV4) + { + wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr); + hasNotifiedIPV4 = true; + event = WifiEvent::kStationDhcpDone; + sl_matter_wifi_post_event(event); + NotifyConnectivity(); + } + else if (dhcp_state == DHCP_OFF) + { + wfx_ip_changed_notify(IP_STATUS_FAIL); + hasNotifiedIPV4 = false; + } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + /* Checks if the assigned IPv6 address is preferred by evaluating + * the first block of IPv6 address ( block 0) + */ + if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6) + { + char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 }; + VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr); + ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr); + wfx_ipv6_notify(GET_IPV6_SUCCESS); + hasNotifiedIPV6 = true; + event = WifiEvent::kStationDhcpDone; + sl_matter_wifi_post_event(event); + NotifyConnectivity(); + } +} +void sl_matter_wifi_post_event(WifiEvent event) +{ + sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0); + + if (status != osOK) + { + ChipLogError(DeviceLayer, "sl_matter_wifi_post_event: failed to post event with status: %ld", status); + // TODO: Handle error, requeue event depending on queue size or notify relevant task, + // Chipdie, etc. + } +} +/// ResetDHCPNotificationFlags +/// @brief Reset the flags that are used to notify the application about DHCP connectivity +/// and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. +void ResetDHCPNotificationFlags(void) +{ + +#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) + hasNotifiedIPV4 = false; +#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4 + hasNotifiedIPV6 = false; + hasNotifiedWifiConnectivity = false; + + WifiEvent event = WifiEvent::kStationDoDhcp; + sl_matter_wifi_post_event(event); +} + +void ProcessEvent(WifiEvent event) +{ + // Process event + switch (event) + { + case WifiEvent::kStationConnect: + ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect"); + wfx_rsi.dev_state.Set(WifiState::kStationConnected); + ResetDHCPNotificationFlags(); + break; + + case WifiEvent::kStationDisconnect: { + ChipLogDetail(DeviceLayer, "WifiEvent::kStationDisconnect"); + // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something + + wfx_rsi.dev_state.Clear(WifiState::kStationReady) + .Clear(WifiState::kStationConnecting) + .Clear(WifiState::kStationConnected) + .Clear(WifiState::kStationDhcpDone); + + /* TODO: Implement disconnect notify */ + ResetDHCPNotificationFlags(); +#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) + wfx_ip_changed_notify(0); // for IPV4 + wfx_ip_changed_notify(IP_STATUS_FAIL); +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + wfx_ipv6_notify(GET_IPV6_FAIL); + } + break; + + case WifiEvent::kAPStart: + // TODO: Currently unimplemented + break; + + case WifiEvent::kScan: + ChipLogDetail(DeviceLayer, "WifiEvent::kScan"); + +#ifdef SL_WFX_CONFIG_SCAN + if (!(wfx_rsi.dev_state.Has(WifiState::kScanStarted))) + { + ChipLogDetail(DeviceLayer, "WifiEvent::kScan"); + sl_wifi_scan_configuration_t wifi_scan_configuration; + memset(&wifi_scan_configuration, 0, sizeof(wifi_scan_configuration)); + + // TODO: Add scan logic + sl_wifi_advanced_scan_configuration_t advanced_scan_configuration = { 0 }; + int32_t status; + advanced_scan_configuration.active_channel_time = kAdvActiveScanDuration; + advanced_scan_configuration.passive_channel_time = kAdvPassiveScanDuration; + advanced_scan_configuration.trigger_level = kAdvScanThreshold; + advanced_scan_configuration.trigger_level_change = kAdvRssiToleranceThreshold; + advanced_scan_configuration.enable_multi_probe = kAdvMultiProbe; + status = sl_wifi_set_advanced_scan_configuration(&advanced_scan_configuration); + if (SL_STATUS_OK != status) + { + // TODO: Seems like Chipdie should be called here, the device should be initialized here + ChipLogError(DeviceLayer, "sl_wifi_set_advanced_scan_configuration failed: 0x%lx", static_cast(status)); + return; + } + + if (wfx_rsi.dev_state.Has(WifiState::kStationConnected)) + { + /* Terminate with end of scan which is no ap sent back */ + wifi_scan_configuration.type = SL_WIFI_SCAN_TYPE_ADV_SCAN; + wifi_scan_configuration.periodic_scan_interval = kAdvScanPeriodicity; + } + else + { + wifi_scan_configuration = default_wifi_scan_configuration; + } + sl_wifi_set_scan_callback(bg_scan_callback_handler, nullptr); + wfx_rsi.dev_state.Set(WifiState::kScanStarted); + + osSemaphoreAcquire(sScanInProgressSemaphore, osWaitForever); + status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, nullptr, &wifi_scan_configuration); + if (SL_STATUS_IN_PROGRESS == status) + { + osSemaphoreAcquire(sScanCompleteSemaphore, kWifiScanTimeoutTicks); + } + + osSemaphoreRelease(sScanInProgressSemaphore); + } +#endif /* SL_WFX_CONFIG_SCAN */ + break; + + case WifiEvent::kStationStartJoin: + ChipLogDetail(DeviceLayer, "WifiEvent::kStationStartJoin"); + + InitiateScan(); + JoinWifiNetwork(); + break; + + case WifiEvent::kStationDoDhcp: + ChipLogDetail(DeviceLayer, "WifiEvent::kStationDoDhcp"); + StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL); + break; + + case WifiEvent::kStationDhcpDone: + ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpDone"); + CancelDHCPTimer(); + break; + + case WifiEvent::kStationDhcpPoll: + ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpPoll"); + HandleDHCPPolling(); + break; + + default: + break; + } +} + +/********************************************************************************* + * @fn void sl_matter_wifi_task(void *arg) + * @brief + * The main WLAN task - started by wfx_wifi_start() that interfaces with RSI. + * The rest of RSI stuff come in call-backs. + * The initialization has been already done. + * @param[in] arg: + * @return + * None + **********************************************************************************/ +/* ARGSUSED */ +void sl_matter_wifi_task(void * arg) +{ + (void) arg; + WifiEvent event; + sl_status_t status = SL_STATUS_OK; + + status = sl_wifi_siwx917_init(); + VerifyOrReturn( + status == SL_STATUS_OK, + ChipLogError(DeviceLayer, "sl_matter_wifi_task: sl_wifi_siwx917_init failed: 0x%lx", static_cast(status))); + + sl_matter_wifi_task_started(); + + ChipLogDetail(DeviceLayer, "sl_matter_wifi_task: starting event loop"); + for (;;) + { + if (osMessageQueueGet(sWifiEventQueue, &event, nullptr, osWaitForever) == osOK) + { + ProcessEvent(event); + } + else + { + ChipLogError(DeviceLayer, "sl_matter_wifi_task: get event failed: 0x%lx", static_cast(status)); + } + } +} + +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 +/******************************************************************************************** + * @fn void wfx_dhcp_got_ipv4(uint32_t ip) + * @brief + * Acquire the new ip address + * @param[in] ip: internet protocol + * @return + * None + **********************************************************************************************/ +void wfx_dhcp_got_ipv4(uint32_t ip) +{ + /* + * Acquire the new IP address + */ + 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 */ + wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone).Set(WifiState::kStationReady); + 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/wifi/wfx_notify.cpp b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp similarity index 85% rename from examples/platform/silabs/wifi/wfx_notify.cpp rename to src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index f9d1d4f61e..99d699d8f0 100644 --- a/examples/platform/silabs/wifi/wfx_notify.cpp +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -15,41 +15,41 @@ * limitations under the License. */ -#include "AppConfig.h" -#include "BaseApplication.h" +// SL MATTER WI-FI INTERFACE + +#include "silabs_utils.h" #include +#include +#include +#include +#include +#include #include #include #include -#include "FreeRTOS.h" -#include "event_groups.h" -#include "silabs_utils.h" -#include "task.h" -#include "wfx_host_events.h" +using namespace chip; +using namespace chip::DeviceLayer; -#ifdef RS911X_WIFI -#include "wfx_rsi.h" -#endif +#define CONVERT_SEC_TO_MS(TimeInS) (TimeInS * 1000) -#include - -using namespace ::chip; -using namespace ::chip::DeviceLayer; +// TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation. +// As such we can't depend on the platform here as well +extern void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); namespace { + constexpr uint8_t kWlanMinRetryIntervalsInSec = 1; constexpr uint8_t kWlanMaxRetryIntervalsInSec = 60; constexpr uint8_t kWlanRetryIntervalInSec = 5; uint8_t retryInterval = kWlanMinRetryIntervalsInSec; osTimerId_t sRetryTimer; -} // namespace + /* * Notifications to the upper-layer * All done in the context of the RSI/WiFi task (rsi_if.c) */ - -static void RetryConnectionTimerHandler(void * arg) +void RetryConnectionTimerHandler(void * arg) { #if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE wfx_rsi_power_save(RSI_ACTIVE, HIGH_PERFORMANCE); @@ -59,14 +59,17 @@ static void RetryConnectionTimerHandler(void * arg) ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed."); } } + +} // namespace + /*********************************************************************************** - * @fn wfx_started_notify(void) + * @fn sl_matter_wifi_task_started(void) * @brief * Wifi device started notification * @param[in]: None * @return None *************************************************************************************/ -void wfx_started_notify(void) +void sl_matter_wifi_task_started(void) { sl_wfx_startup_ind_t evt; sl_wfx_mac_address_t mac; @@ -82,7 +85,7 @@ void wfx_started_notify(void) wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac); memcpy(&evt.body.mac_addr[0], &mac.octet[0], MAC_ADDRESS_FIRST_OCTET); - PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); } /*********************************************************************************** @@ -109,7 +112,7 @@ void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap) #endif memcpy(&evt.body.mac[0], &ap->octet[0], MAC_ADDRESS_FIRST_OCTET); - PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); } /************************************************************************************** @@ -118,7 +121,7 @@ void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap) * notification of disconnection * @param[in] status: * @return None - ********************************************************************************************/ + *************************************************************************************/ void wfx_disconnected_notify(int32_t status) { sl_wfx_disconnect_ind_t evt; @@ -127,7 +130,7 @@ void wfx_disconnected_notify(int32_t status) evt.header.id = SL_WFX_DISCONNECT_IND_ID; evt.header.length = sizeof evt; evt.body.reason = status; - PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); } /************************************************************************************** @@ -136,7 +139,7 @@ void wfx_disconnected_notify(int32_t status) * notification of ipv6 * @param[in] got_ip: * @return None - ********************************************************************************************/ + *************************************************************************************/ void wfx_ipv6_notify(int got_ip) { sl_wfx_generic_message_t eventData; @@ -144,7 +147,7 @@ void wfx_ipv6_notify(int got_ip) memset(&eventData, 0, sizeof(eventData)); eventData.header.id = got_ip ? IP_EVENT_GOT_IP6 : IP_EVENT_STA_LOST_IP; eventData.header.length = sizeof(eventData.header); - PlatformMgrImpl().HandleWFXSystemEvent(IP_EVENT, &eventData); + HandleWFXSystemEvent(IP_EVENT, &eventData); } /************************************************************************************** @@ -153,7 +156,7 @@ void wfx_ipv6_notify(int got_ip) * notification of ip change * @param[in] got_ip: * @return None - ********************************************************************************************/ + *************************************************************************************/ void wfx_ip_changed_notify(int got_ip) { sl_wfx_generic_message_t eventData; @@ -161,7 +164,7 @@ void wfx_ip_changed_notify(int got_ip) memset(&eventData, 0, sizeof(eventData)); eventData.header.id = got_ip ? IP_EVENT_STA_GOT_IP : IP_EVENT_STA_LOST_IP; eventData.header.length = sizeof(eventData.header); - PlatformMgrImpl().HandleWFXSystemEvent(IP_EVENT, &eventData); + HandleWFXSystemEvent(IP_EVENT, &eventData); } /************************************************************************************** @@ -172,11 +175,11 @@ void wfx_ip_changed_notify(int got_ip) * with AP continously after a certain time interval. * @param[in] retryAttempt * @return None - ********************************************************************************************/ + *************************************************************************************/ void wfx_retry_connection(uint16_t retryAttempt) { // During commissioning, we retry to join the network MAX_JOIN_RETRIES_COUNT - if (BaseApplication::sAppDelegate.isCommissioningInProgress()) + if (/*BaseApplication::sAppDelegate.isCommissioningInProgress()*/ true) { if (retryAttempt < MAX_JOIN_RETRIES_COUNT) { diff --git a/src/platform/silabs/wifi/wfx_host_events.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h similarity index 55% rename from src/platform/silabs/wifi/wfx_host_events.h rename to src/platform/silabs/wifi/WifiInterfaceAbstraction.h index 3bd973467b..f6364d040e 100644 --- a/src/platform/silabs/wifi/wfx_host_events.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -14,9 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once +#include +#include +#include +#include +#include + #include "sl_status.h" #include @@ -32,6 +37,12 @@ #include "sl_wifi_constants.h" #include "sl_wifi_device.h" +/* + * Interface to RSI Sapis + */ + +#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ + // MAX SSID LENGTH excluding NULL character #define WFX_MAX_SSID_LENGTH (32) // MAX PASSKEY LENGTH including NULL character @@ -44,106 +55,56 @@ #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) + +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 +{ + kStationConnect = 0, + kStationDisconnect = 1, + kAPStart = 2, + kAPStop = 3, + kScan = 4, /* This is used as scan result and start */ + kStationStartJoin = 5, + kStationDoDhcp = 6, + kStationDhcpDone = 7, + kStationDhcpPoll = 8 +}; + 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 +156,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 +173,50 @@ 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; +#endif -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 +typedef struct wfx_rsi_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" { + chip::BitFlags dev_state; + uint16_t ap_chan; /* The chan our STA is using */ + wfx_wifi_provision_t sec; +#ifdef SL_WFX_CONFIG_SCAN + void (*scan_cb)(wfx_wifi_scan_result_t *); + char * scan_ssid; /* Which one are we scanning for */ + size_t scan_ssid_length; +#endif +#ifdef SL_WFX_CONFIG_SOFTAP + sl_wfx_mac_address_t softap_mac; #endif + sl_wfx_mac_address_t sta_mac; + sl_wfx_mac_address_t ap_mac; /* To which our STA is connected */ + 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; + +// TODO: We shouldn't need to have access to a global variable in the interface here +extern WfxRsi_t wfx_rsi; -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 wfx_sta_discon(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 */ @@ -328,17 +225,16 @@ void wfx_cancel_scan(void); /* * Call backs into the Matter Platform code */ -void wfx_started_notify(void); +void sl_matter_wifi_task_started(void); void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap); void wfx_disconnected_notify(int32_t status); + /* Implemented for LWIP */ -void wfx_host_received_sta_frame_cb(uint8_t * buf, int len); void wfx_lwip_set_sta_link_up(void); void wfx_lwip_set_sta_link_down(void); -void wfx_lwip_start(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 +251,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 +264,49 @@ 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 */ +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(); + +#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); +#else +int32_t wfx_rsi_power_save(); +#endif /* SLI_SI917 */ +#endif /* SL_ICD_ENABLED */ + +/** + * @brief Posts an event to the Wi-Fi task + * + * @param[in] event Event to process. + */ +void sl_matter_wifi_post_event(WifiEvent event); + +#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 diff --git a/src/platform/silabs/wifi_args.gni b/src/platform/silabs/wifi/args.gni similarity index 91% rename from src/platform/silabs/wifi_args.gni rename to src/platform/silabs/wifi/args.gni index 5d523bd3a6..7b4da179da 100644 --- a/src/platform/silabs/wifi_args.gni +++ b/src/platform/silabs/wifi/args.gni @@ -21,9 +21,9 @@ import("${chip_root}/examples/platform/silabs/args.gni") import("${chip_root}/src/crypto/crypto.gni") # ARM architecture flags will be set based on silabs_family. -arm_platform_config = "${efr32_sdk_build_root}/silabs_arm.gni" +arm_platform_config = "${silabs_sdk_build_root}/silabs_arm.gni" -mbedtls_target = "${efr32_sdk_build_root}:efr32_sdk" +mbedtls_target = "${silabs_sdk_build_root}:silabs_sdk" # default to platform crypto implementation but allow commandline override if (chip_crypto == "") { @@ -35,7 +35,7 @@ if (chip_crypto == "") { chip_use_transitional_commissionable_data_provider = false # Use GSDK lwip instead of CHIP -lwip_root = "${efr32_sdk_build_root}/silabs_lwip" +lwip_root = "${silabs_sdk_build_root}/silabs_lwip" #lwip_platform = "external" lwip_platform = "silabs" diff --git a/src/platform/silabs/wifi/dhcp_client.cpp b/src/platform/silabs/wifi/lwip-support/dhcp_client.cpp similarity index 97% rename from src/platform/silabs/wifi/dhcp_client.cpp rename to src/platform/silabs/wifi/lwip-support/dhcp_client.cpp index c8b47a9f2b..a16064eb1d 100644 --- a/src/platform/silabs/wifi/dhcp_client.cpp +++ b/src/platform/silabs/wifi/lwip-support/dhcp_client.cpp @@ -23,11 +23,7 @@ #include "dhcp_client.h" #include "lwip/dhcp.h" -#include "wfx_host_events.h" -#include "wifi_config.h" - -#include "FreeRTOS.h" -#include "event_groups.h" +#include #include diff --git a/src/platform/silabs/wifi/dhcp_client.h b/src/platform/silabs/wifi/lwip-support/dhcp_client.h similarity index 100% rename from src/platform/silabs/wifi/dhcp_client.h rename to src/platform/silabs/wifi/lwip-support/dhcp_client.h diff --git a/src/platform/silabs/efr32/wifi/ethernetif.cpp b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp similarity index 98% rename from src/platform/silabs/efr32/wifi/ethernetif.cpp rename to src/platform/silabs/wifi/lwip-support/ethernetif.cpp index d0f0ec6daf..7e880f62e9 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.cpp +++ b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp @@ -21,12 +21,6 @@ #include #include -#include "em_bus.h" -#include "em_cmu.h" -#include "em_gpio.h" -#include "em_ldma.h" -#include "em_usart.h" - #ifndef WF200_WIFI #include "FreeRTOS.h" #include "event_groups.h" @@ -50,8 +44,7 @@ extern "C" { #endif // (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #endif // WF200_WIFI -#include "wfx_host_events.h" -#include "wifi_config.h" +#include #ifdef WF200_WIFI #include "sl_wfx.h" #endif @@ -163,7 +156,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) { @@ -269,7 +262,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/wifi/lwip-support/ethernetif.h similarity index 94% rename from src/platform/silabs/efr32/wifi/ethernetif.h rename to src/platform/silabs/wifi/lwip-support/ethernetif.h index dfea1ea6ad..56e564d30b 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.h +++ b/src/platform/silabs/wifi/lwip-support/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/SiWx917/wifi/lwip_netif.cpp b/src/platform/silabs/wifi/lwip-support/lwip_netif.cpp similarity index 94% rename from src/platform/silabs/SiWx917/wifi/lwip_netif.cpp rename to src/platform/silabs/wifi/lwip-support/lwip_netif.cpp index d4bcbe4739..3b8dea41cc 100644 --- a/src/platform/silabs/SiWx917/wifi/lwip_netif.cpp +++ b/src/platform/silabs/wifi/lwip-support/lwip_netif.cpp @@ -19,25 +19,26 @@ #include #include -#include "wfx_host_events.h" -#include "wifi_config.h" +#include #include "dhcp_client.h" #include "ethernetif.h" -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" +#include -#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 @@ -114,13 +115,13 @@ void wfx_lwip_set_sta_link_down(void) } /*************************************************************************** - * @fn void wfx_lwip_start(void) + * @fn void sl_matter_lwip_start(void) * @brief * Initialize the LwIP stack * @param[in] None * @return None *****************************************************************************/ -void wfx_lwip_start(void) +void sl_matter_lwip_start(void) { /* Initialize the LwIP stack */ netif_config(&sta_netif, NULL); diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp similarity index 81% rename from examples/platform/silabs/efr32/rs911x/rsi_if.cpp rename to src/platform/silabs/wifi/rs911x/WifiInterface.cpp index 4510978329..bf04b0610c 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp @@ -15,24 +15,20 @@ * 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 "lwip/nd6.h" +#include "silabs_utils.h" #include "sl_status.h" #include -// TODO Fix include order issue #33120 -#include "wfx_host_events.h" +#include +#include +#include +#include +#include +#include +#include +#include -#ifdef __cplusplus extern "C" { -#endif #include "rsi_bootup_config.h" #include "rsi_common_apis.h" #include "rsi_data_types.h" @@ -45,21 +41,22 @@ extern "C" { #include "rsi_wlan_apis.h" #include "rsi_wlan_config.h" #include "rsi_wlan_non_rom.h" -#ifdef __cplusplus } -#endif -#include "dhcp_client.h" -#include "lwip/nd6.h" -#include "silabs_utils.h" -#include "wfx_rsi.h" - -#include -#include -#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; @@ -107,9 +104,8 @@ static void rsi_wireless_driver_task_wrapper(void * argument) static void DHCPTimerEventHandler(void * arg) { - WfxEvent_t event; - event.eventType = WFX_EVT_DHCP_POLL; - WfxPostEvent(&event); + WifiEvent event = WifiEvent::kStationDhcpPoll; + sl_matter_wifi_post_event(event); } static void CancelDHCPTimer(void) @@ -226,14 +222,14 @@ int32_t wfx_rsi_reset_count(void) } /****************************************************************** - * @fn wfx_rsi_disconnect(void) + * @fn sl_wifi_platform_disconnect(void) * @brief * Getting the driver disconnect status * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_disconnect(void) +int32_t sl_wifi_platform_disconnect(void) { return rsi_wlan_disconnect(); } @@ -283,8 +279,7 @@ int32_t wfx_rsi_power_save(void) *********************************************************************/ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t len) { - WfxEvent_t WfxEvent; - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; + wfx_rsi.dev_state.Clear(WifiState::kStationConnecting); if (status != RSI_SUCCESS) { /* @@ -300,8 +295,8 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t */ ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: success"); memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); + WifiEvent event = WifiEvent::kStationConnect; + sl_matter_wifi_post_event(event); wfx_rsi.join_retries = 0; } @@ -318,11 +313,12 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len) { ChipLogError(DeviceLayer, "wfx_rsi_join_fail_cb: status: %d", status); - WfxEvent_t WfxEvent; wfx_rsi.join_retries += 1; - wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); - WfxEvent.eventType = WFX_EVT_STA_START_JOIN; - WfxPostEvent(&WfxEvent); + + wfx_rsi.dev_state.Clear(WifiState::kStationConnecting).Clear(WifiState::kStationConnected); + + WifiEvent event = WifiEvent::kStationStartJoin; + sl_matter_wifi_post_event(event); } /************************************************************************************* * @fn wfx_rsi_wlan_pkt_cb(uint16_t status, uint8_t *buf, uint32_t len) @@ -344,31 +340,30 @@ static void wfx_rsi_wlan_pkt_cb(uint16_t status, uint8_t * buf, uint32_t len) } /************************************************************************************* - * @fn static int32_t wfx_rsi_init(void) + * @fn static int32_t sl_matter_wifi_init(void) * @brief * driver initialization * @param[in] None * @return * None *****************************************************************************************/ -static int32_t wfx_rsi_init(void) +static int32_t sl_matter_wifi_init(void) { int32_t status; uint8_t buf[RSI_RESPONSE_HOLD_BUFF_SIZE]; extern void rsi_hal_board_init(void); - ChipLogProgress(DeviceLayer, "wfx_rsi_init: starting(HEAP_SZ = %d)", SL_HEAP_SIZE); //! Driver initialization status = rsi_driver_init(wfx_rsi_drv_buf, WFX_RSI_BUF_SZ); if ((status < RSI_DRIVER_STATUS) || (status > WFX_RSI_BUF_SZ)) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_driver_init failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_driver_init failed: %ld", status); return status; } /* ! Redpine module intialisation */ if ((status = rsi_device_init(LOAD_NWP_FW)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_device_init failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_device_init failed: %ld", status); return status; } /* @@ -377,7 +372,7 @@ static int32_t wfx_rsi_init(void) sDrvThread = osThreadNew(rsi_wireless_driver_task_wrapper, NULL, &kDrvTaskAttr); if (NULL == sDrvThread) { - ChipLogError(DeviceLayer, "wfx_rsi_init: failed to create task"); + ChipLogError(DeviceLayer, "failed to create task"); return RSI_ERROR_INVALID_PARAM; } @@ -388,7 +383,7 @@ static int32_t wfx_rsi_init(void) if ((status = rsi_wireless_init(OPER_MODE_0, COEX_MODE_0)) != RSI_SUCCESS) { #endif - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wireless_init failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_wireless_init failed: %ld", status); return status; } @@ -397,7 +392,7 @@ static int32_t wfx_rsi_init(void) */ if (rsi_wlan_get(RSI_FW_VERSION, buf, sizeof(buf)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_FW_VERSION) failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_wlan_get(RSI_FW_VERSION) failed: %ld", status); return status; } @@ -415,16 +410,15 @@ static int32_t wfx_rsi_init(void) (void) rsi_wlan_radio_init(); /* Required so we can get MAC address */ if ((status = rsi_wlan_get(RSI_MAC_ADDRESS, &wfx_rsi.sta_mac.octet[0], RESP_BUFF_SIZE)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_MAC_ADDRESS) failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_wlan_get(RSI_MAC_ADDRESS) failed: %ld", status); return status; } - ChipLogDetail(DeviceLayer, "wfx_rsi_init: MAC: %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.octet[0], - wfx_rsi.sta_mac.octet[1], wfx_rsi.sta_mac.octet[2], wfx_rsi.sta_mac.octet[3], wfx_rsi.sta_mac.octet[4], - wfx_rsi.sta_mac.octet[5]); + ChipLogDetail(DeviceLayer, "MAC: %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.octet[0], wfx_rsi.sta_mac.octet[1], + wfx_rsi.sta_mac.octet[2], wfx_rsi.sta_mac.octet[3], wfx_rsi.sta_mac.octet[4], wfx_rsi.sta_mac.octet[5]); // Create the message queue - sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); + sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WifiEvent), NULL); if (sWifiEventQueue == NULL) { return SL_STATUS_ALLOCATION_FAILED; @@ -443,12 +437,12 @@ static int32_t wfx_rsi_init(void) */ if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_wlan_register_callbacks failed: %ld", status); return status; } if ((status = rsi_wlan_register_callbacks(RSI_WLAN_DATA_RECEIVE_NOTIFY_CB, wfx_rsi_wlan_pkt_cb)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); + ChipLogError(DeviceLayer, "rsi_wlan_register_callbacks failed: %ld", status); return status; } @@ -456,8 +450,7 @@ static int32_t wfx_rsi_init(void) rsi_semaphore_post(&sl_rs_ble_init_sem); #endif - wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY; - ChipLogProgress(DeviceLayer, "wfx_rsi_init: success"); + wfx_rsi.dev_state.Set(WifiState::kStationInit); return RSI_SUCCESS; } @@ -530,22 +523,18 @@ static void wfx_rsi_save_ap_info(void) // translation } /******************************************************************************************** - * @fn static void wfx_rsi_do_join(void) + * @fn static void sl_wifi_platform_join_network(void) * @brief * Start an async Join command * @return * None **********************************************************************************************/ -static void wfx_rsi_do_join(void) +static void sl_wifi_platform_join_network(void) { - int32_t status; + sl_status_t status = SL_STATUS_OK; rsi_security_mode_t connect_security_mode; - if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)) - { - ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: already in progress"); - return; - } + VerifyOrReturn(!wfx_rsi.dev_state.HasAny(WifiState::kStationConnecting, WifiState::kStationConnected)); switch (wfx_rsi.sec.security) { @@ -566,11 +555,12 @@ static void wfx_rsi_do_join(void) connect_security_mode = RSI_OPEN; break; default: - ChipLogError(DeviceLayer, "wfx_rsi_do_join: error: unknown security type."); + ChipLogError(DeviceLayer, "sl_wifi_platform_join_network: error: unknown security type."); return; } - ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security); + ChipLogProgress(DeviceLayer, "sl_wifi_platform_join_network: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], + wfx_rsi.sec.security); /* * Join the network @@ -578,11 +568,11 @@ static void wfx_rsi_do_join(void) /* TODO - make the WFX_SECURITY_xxx - same as RSI_xxx * Right now it's done by hand - we need something better */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; + wfx_rsi.dev_state.Set(WifiState::kStationConnecting); if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_register_callbacks failed: %ld", status); + ChipLogError(DeviceLayer, "sl_wifi_platform_join_network: rsi_wlan_register_callbacks failed: %ld", status); } /* Try to connect Wifi with given Credentials @@ -591,8 +581,9 @@ static void wfx_rsi_do_join(void) if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0], wfx_rsi_join_cb)) != RSI_SUCCESS) { - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; - ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_connect_async failed: %ld on try %d", status, wfx_rsi.join_retries); + wfx_rsi.dev_state.Clear(WifiState::kStationConnecting); + ChipLogProgress(DeviceLayer, "sl_wifi_platform_join_network: rsi_wlan_connect_async failed: %ld on try %d", status, + wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); } } @@ -613,7 +604,6 @@ void NotifyConnectivity(void) void HandleDHCPPolling(void) { struct netif * sta_netif; - WfxEvent_t event; sta_netif = wfx_get_netif(SL_WFX_STA_INTERFACE); if (sta_netif == NULL) @@ -644,19 +634,19 @@ void HandleDHCPPolling(void) { wfx_ipv6_notify(GET_IPV6_SUCCESS); hasNotifiedIPV6 = true; - event.eventType = WFX_EVT_STA_DHCP_DONE; - WfxPostEvent(&event); + WifiEvent event = WifiEvent::kStationDhcpDone; + sl_matter_wifi_post_event(event); NotifyConnectivity(); } } /** ResetDHCPNotificationFlags * @brief Reset the flags that are used to notify the application about DHCP connectivity - * and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. + * and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. */ void ResetDHCPNotificationFlags(void) { - WfxEvent_t outEvent; + WifiEvent outEvent; #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) hasNotifiedIPV4 = false; @@ -664,20 +654,17 @@ void ResetDHCPNotificationFlags(void) hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; - outEvent.eventType = WFX_EVT_STA_DO_DHCP; - WfxPostEvent(&outEvent); + outEvent = WifiEvent::kStationDoDhcp; + sl_matter_wifi_post_event(outEvent); } -/** - * @brief Post the WfxEvent to tue WiFiEventQueue to be process by the wfx_rsi_task - */ -void WfxPostEvent(WfxEvent_t * event) +void sl_matter_wifi_post_event(WifiEvent event) { - sl_status_t status = osMessageQueuePut(sWifiEventQueue, event, 0, 0); + sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0); if (status != osOK) { - ChipLogError(DeviceLayer, "WfxPostEvent: failed to post event with status: %ld", status); + ChipLogError(DeviceLayer, "sl_matter_wifi_post_event: failed to post event with status: %ld", status); // TODO: Handle error, requeue event depending on queue size or notify relevant task, // Chipdie, etc. } @@ -689,16 +676,16 @@ void WfxPostEvent(WfxEvent_t * event) * This function is responsible for processing different types of Wi-Fi events and taking appropriate actions based on the event * type. * - * @param inEvent The input Wi-Fi event to be processed. + * @param event The input Wi-Fi event to be processed. */ -void ProcessEvent(WfxEvent_t inEvent) +void ProcessEvent(WifiEvent event) { // Process event - switch (inEvent.eventType) + switch (event) { - case WFX_EVT_STA_CONN: { - ChipLogDetail(DeviceLayer, "_onWFXEvent: WFX_EVT_STA_CONN"); - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED; + case WifiEvent::kStationConnect: { + ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect"); + wfx_rsi.dev_state.Set(WifiState::kStationConnected); ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_up(); /* We need to get AP Mac - TODO */ @@ -708,11 +695,12 @@ void ProcessEvent(WfxEvent_t inEvent) // is independant of IP connectivity. } break; - case WFX_EVT_STA_DISCONN: { - ChipLogDetail(DeviceLayer, "_onWFXEvent: WFX_EVT_STA_DISCONN"); + case WifiEvent::kStationDisconnect: { + ChipLogDetail(DeviceLayer, "WifiEvent::kStationDisconnect"); // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something - wfx_rsi.dev_state &= - ~(WFX_RSI_ST_STA_READY | WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE); + WifiStateFlags flagsToClear = WifiStateFlags(WifiState::kStationReady, WifiState::kStationConnecting, + WifiState::kStationConnected, WifiState::kStationDhcpDone); + wfx_rsi.dev_state.Clear(flagsToClear); /* TODO: Implement disconnect notify */ ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) -> @@ -723,13 +711,10 @@ void ProcessEvent(WfxEvent_t inEvent) wfx_ipv6_notify(GET_IPV6_FAIL); } break; - case WFX_EVT_AP_START: + case WifiEvent::kAPStart: // TODO: Currently unimplemented break; - case WFX_EVT_AP_STOP: - // TODO: Currently unimplemented - break; - case WFX_EVT_SCAN: { + case WifiEvent::kScan: { #ifdef SL_WFX_CONFIG_SCAN rsi_rsp_scan_t scan_rsp = { 0 }; memset(&scan_rsp, 0, sizeof(scan_rsp)); @@ -761,7 +746,7 @@ void ProcessEvent(WfxEvent_t inEvent) chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast(scan->ssid)); // +1 for null termination // 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. } @@ -795,22 +780,22 @@ void ProcessEvent(WfxEvent_t inEvent) #endif /* SL_WFX_CONFIG_SCAN */ } break; - case WFX_EVT_STA_START_JOIN: { + case WifiEvent::kStationStartJoin: { // saving the AP related info wfx_rsi_save_ap_info(); // Joining to the network - wfx_rsi_do_join(); + sl_wifi_platform_join_network(); } break; - case WFX_EVT_STA_DO_DHCP: { + case WifiEvent::kStationDoDhcp: { StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL); } break; - case WFX_EVT_STA_DHCP_DONE: { + case WifiEvent::kStationDhcpDone: { CancelDHCPTimer(); } break; - case WFX_EVT_DHCP_POLL: { + case WifiEvent::kStationDhcpPoll: { HandleDHCPPolling(); } break; @@ -820,7 +805,7 @@ void ProcessEvent(WfxEvent_t inEvent) } /********************************************************************************* - * @fn void wfx_rsi_task(void *arg) + * @fn void sl_matter_wifi_task(void *arg) * @brief * The main WLAN task - started by wfx_wifi_start () that interfaces with RSI. * The rest of RSI stuff come in call-backs. @@ -830,30 +815,30 @@ void ProcessEvent(WfxEvent_t inEvent) * None **********************************************************************************/ /* ARGSUSED */ -void wfx_rsi_task(void * arg) +void sl_matter_wifi_task(void * arg) { (void) arg; - uint32_t rsi_status = wfx_rsi_init(); + uint32_t rsi_status = sl_matter_wifi_init(); if (rsi_status != RSI_SUCCESS) { - ChipLogError(DeviceLayer, "wfx_rsi_task: wfx_rsi_init failed: %ld", rsi_status); + ChipLogError(DeviceLayer, "sl_matter_wifi_task: sl_matter_wifi_init failed: %ld", rsi_status); return; } - WfxEvent_t wfxEvent; - wfx_lwip_start(); - wfx_started_notify(); + WifiEvent event; + sl_matter_lwip_start(); + sl_matter_wifi_task_started(); - ChipLogProgress(DeviceLayer, "wfx_rsi_task: starting event loop"); + ChipLogProgress(DeviceLayer, "sl_matter_wifi_task: starting event loop"); for (;;) { - osStatus_t status = osMessageQueueGet(sWifiEventQueue, &wfxEvent, NULL, osWaitForever); + osStatus_t status = osMessageQueueGet(sWifiEventQueue, &event, NULL, osWaitForever); if (status == osOK) { - ProcessEvent(wfxEvent); + ProcessEvent(event); } else { - ChipLogProgress(DeviceLayer, "wfx_rsi_task: get event failed: %x", status); + ChipLogProgress(DeviceLayer, "sl_matter_wifi_task: get event failed: %x", status); } } } @@ -872,16 +857,15 @@ 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 */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_DHCP_DONE; + wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone, WifiState::kStationReady); wfx_ip_changed_notify(IP_STATUS_SUCCESS); - wfx_rsi.dev_state |= WFX_RSI_ST_STA_READY; } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -972,4 +956,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/efx32_ncp_host.c b/src/platform/silabs/wifi/rs911x/platform/efx32_ncp_host.c similarity index 96% rename from examples/platform/silabs/efr32/rs911x/hal/efx32_ncp_host.c rename to src/platform/silabs/wifi/rs911x/platform/efx32_ncp_host.c index 6703e2b287..ff67284d2a 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx32_ncp_host.c +++ b/src/platform/silabs/wifi/rs911x/platform/efx32_ncp_host.c @@ -26,9 +26,11 @@ #include "sl_constants.h" #include "sl_rsi_utility.h" #include "sl_si91x_host_interface.h" +#include "sl_si91x_ncp_utility.h" #include "sl_si91x_status.h" #include "sl_status.h" #include "sl_wifi_constants.h" +#include #include #include @@ -40,9 +42,6 @@ #include "sl_board_control.h" #endif // SL_BOARD_NAME -#include "sl_si91x_ncp_utility.h" -#include "spi_multiplex.h" - static bool dma_callback(unsigned int channel, unsigned int sequenceNo, void * userParam); uint32_t rx_ldma_channel; diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/src/platform/silabs/wifi/rs911x/platform/efx_spi.c similarity index 95% rename from examples/platform/silabs/efr32/rs911x/hal/efx_spi.c rename to src/platform/silabs/wifi/rs911x/platform/efx_spi.c index 1f10640e04..a339f711a4 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/src/platform/silabs/wifi/rs911x/platform/efx_spi.c @@ -18,33 +18,23 @@ /** * Includes */ -#include -#include -#include #include "FreeRTOS.h" -#include "event_groups.h" -#include "semphr.h" -#include "task.h" - -#include "dmadrv.h" -#include "em_chip.h" #include "em_cmu.h" -#include "em_core.h" -#include "em_device.h" -#include "em_gpio.h" -#include "em_ldma.h" +#include "em_eusart.h" #include "gpiointerrupt.h" +#include "rsi_board_configuration.h" +#include "rsi_driver.h" +#include "semphr.h" +#include "silabs_utils.h" #include "sl_device_init_clocks.h" #include "sl_device_init_hfxo.h" +#include "sl_spidrv_eusart_exp_config.h" #include "sl_spidrv_instances.h" #include "sl_status.h" #include "spidrv.h" - -#include "silabs_utils.h" -#include "spi_multiplex.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" +#include "task.h" +#include #ifdef SL_BOARD_NAME #include "sl_board_control.h" @@ -54,9 +44,6 @@ #include "sl_power_manager.h" #endif -#include "rsi_board_configuration.h" -#include "rsi_driver.h" - #if SL_BTLCTRL_MUX #include "btl_interface.h" #endif // SL_BTLCTRL_MUX @@ -68,13 +55,12 @@ #include "sl_mx25_flash_shutdown_usart_config.h" #endif // SL_MX25CTRL_MUX -#include "em_eusart.h" -#include "sl_spidrv_eusart_exp_config.h" -#include "spi_multiplex.h" - #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 @@ -111,16 +97,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 */ @@ -205,7 +191,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; } } @@ -268,7 +254,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 @@ -301,7 +287,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_board_configuration.h b/src/platform/silabs/wifi/rs911x/platform/rsi_board_configuration.h similarity index 100% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_board_configuration.h rename to src/platform/silabs/wifi/rs911x/platform/rsi_board_configuration.h diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal.h b/src/platform/silabs/wifi/rs911x/platform/rsi_hal.h similarity index 100% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_hal.h rename to src/platform/silabs/wifi/rs911x/platform/rsi_hal.h diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c b/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_interrupt.c similarity index 98% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c rename to src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_interrupt.c index 1cb5ddf920..8bd277e624 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_interrupt.c +++ b/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_interrupt.c @@ -35,9 +35,6 @@ #include "event_groups.h" #include "task.h" -#include "wfx_host_events.h" -#include "wfx_rsi.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/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_ioports.c similarity index 92% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c rename to src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_ioports.c index 6ea20caf48..ba517b417b 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c +++ b/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_ioports.c @@ -35,9 +35,6 @@ #include "event_groups.h" #include "task.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" - #include "rsi_board_configuration.h" #include "rsi_driver.h" /*===========================================================*/ @@ -64,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; @@ -96,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_rtc.c b/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_rtc.c similarity index 100% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_rtc.c rename to src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_rtc.c diff --git a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c b/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_timer.c similarity index 97% rename from examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c rename to src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_timer.c index 7a80072817..9c1b137748 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_timer.c +++ b/src/platform/silabs/wifi/rs911x/platform/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 */ @@ -49,7 +47,10 @@ extern void xPortSysTickHandler(void); #include "rsi_wlan.h" #include "rsi_wlan_apis.h" #include "rsi_wlan_config.h" -#include "wfx_rsi.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 @@ -134,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_board_configuration.h b/src/platform/silabs/wifi/rs911x/platform/sl_board_configuration.h similarity index 100% rename from examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h rename to src/platform/silabs/wifi/rs911x/platform/sl_board_configuration.h diff --git a/examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration_SiWx917.h b/src/platform/silabs/wifi/rs911x/platform/sl_board_configuration_SiWx917.h similarity index 100% rename from examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration_SiWx917.h rename to src/platform/silabs/wifi/rs911x/platform/sl_board_configuration_SiWx917.h diff --git a/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c b/src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.c similarity index 95% rename from examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c rename to src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.c index b16bbdc475..1d1ab1409c 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.c +++ b/src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.c @@ -46,8 +46,6 @@ #include "silabs_utils.h" #include "sl_si91x_ncp_utility.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" #if SL_MX25CTRL_MUX sl_status_t sl_wfx_host_spiflash_cs_assert(void); @@ -221,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/hal/sl_si91x_ncp_utility.h b/src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.h similarity index 84% rename from examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.h rename to src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.h index 0bd8dae764..b434e35f82 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/sl_si91x_ncp_utility.h +++ b/src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.h @@ -29,7 +29,9 @@ #include "semphr.h" #include "silabs_utils.h" #include "sl_status.h" -#include "spi_multiplex.h" + +// TODO: This is a WF200 specific include. It is not clear why we need this in the 917 NCP files. +#include #if defined(CHIP_9117) #include "em_usart.h" @@ -46,4 +48,4 @@ sl_status_t spi_board_init(void); extern uint32_t rx_ldma_channel; extern uint32_t tx_ldma_channel; -#endif // SL_SI91X_NCP_UTILITY_H \ No newline at end of file +#endif // SL_SI91X_NCP_UTILITY_H diff --git a/examples/platform/silabs/efr32/rs911x/rs9117.gni b/src/platform/silabs/wifi/rs911x/rs9117.gni similarity index 51% rename from examples/platform/silabs/efr32/rs911x/rs9117.gni rename to src/platform/silabs/wifi/rs911x/rs9117.gni index cff3e3da1f..cbeaf98698 100644 --- a/examples/platform/silabs/efr32/rs911x/rs9117.gni +++ b/src/platform/silabs/wifi/rs911x/rs9117.gni @@ -1,23 +1,38 @@ +# 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, +# 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. + import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") rs911x_src_plat = [ - "${examples_plat_dir}/rs911x/sl_wifi_if.cpp", - "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c", - "${examples_plat_dir}/rs911x/hal/sl_si91x_ncp_utility.c", - "${examples_plat_dir}/rs911x/hal/efx32_ncp_host.c", - "${silabs_common_plat_dir}/wifi/wfx_notify.cpp", - "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp", -] + "${chip_root}/src/platform/silabs/wifi/SiWx/WifiInterface.cpp", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_interrupt.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/sl_si91x_ncp_utility.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/sl_board_configuration.h", + "${chip_root}/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp", + "${chip_root}/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h", + + # TODO: We shouldn't need a file form the WF200 for the SiWx917 NCP builds + "${chip_root}/src/platform/silabs/wifi/wf200/platform/spi_multiplex.h", -rs9117_inc_plat = [ - "${examples_plat_dir}/rs911x", - "${examples_plat_dir}/rs911x/hal", - "${wifi_sdk_root}/components/si91x/ble/inc", + # TODO : We should be using the file from the Wiseconnect SDK and not our copy of it. + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/efx32_ncp_host.c", ] -rs911x_cflags = [ "-Wno-empty-body" ] +rs9117_inc_plat = [ "${wifi_sdk_root}/components/si91x/ble/inc" ] + rs9117_src_sapi = [ # sl_si91x_wireless component "${wifi_sdk_root}/components/device/silabs/si91x/wireless/src/sl_si91x_driver.c", @@ -30,6 +45,9 @@ rs9117_src_sapi = [ "${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/spi/sl_si91x_spi.c", "${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/sl_si91x_ncp_driver.c", + # Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed + "${sdk_support_root}/components/service/network_manager/src/sl_net_for_lwip.c", + # wifi component "${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_callback_framework.c", "${wifi_sdk_root}/components/protocol/wifi/si91x/sl_wifi.c", diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/src/platform/silabs/wifi/rs911x/rs911x.gni similarity index 63% rename from examples/platform/silabs/efr32/rs911x/rs911x.gni rename to src/platform/silabs/wifi/rs911x/rs911x.gni index b25fbefc8e..3daba8b049 100644 --- a/examples/platform/silabs/efr32/rs911x/rs911x.gni +++ b/src/platform/silabs/wifi/rs911x/rs911x.gni @@ -1,15 +1,30 @@ +# 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, +# 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. + import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") rs911x_src_plat = [ - "${examples_plat_dir}/rs911x/rsi_if.cpp", - "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c", - "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_ioports.c", - "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c", - "${examples_plat_dir}/rs911x/hal/efx_spi.c", - "${silabs_common_plat_dir}/wifi/wfx_notify.cpp", - "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp", + "${chip_root}/src/platform/silabs/wifi/rs911x/WifiInterface.cpp", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_interrupt.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_ioports.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_hal_mcu_timer.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/efx_spi.c", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_board_configuration.h", + "${chip_root}/src/platform/silabs/wifi/rs911x/platform/rsi_hal.h", + "${chip_root}/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp", ] # @@ -53,10 +68,4 @@ rs911x_src_sapi = [ "${wiseconnect_sdk_root}/sapi/network/socket/rsi_socket_rom.c", ] -rs911x_cflags = [ "-Wno-empty-body" ] - -rs911x_inc_plat = [ - "${examples_plat_dir}/rs911x", - "${examples_plat_dir}/rs911x/hal", - "${wiseconnect_sdk_root}/sapi/include", -] +rs911x_inc_plat = [ "${wiseconnect_sdk_root}/sapi/include" ] diff --git a/examples/platform/silabs/efr32/rs911x/rsi_wlan_config.h b/src/platform/silabs/wifi/rs911x/rsi_wlan_config.h similarity index 100% rename from examples/platform/silabs/efr32/rs911x/rsi_wlan_config.h rename to src/platform/silabs/wifi/rs911x/rsi_wlan_config.h diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp similarity index 91% rename from examples/platform/silabs/efr32/wf200/host_if.cpp rename to src/platform/silabs/wifi/wf200/WifiInterface.cpp index f1686b0aa8..6d2ce15b82 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -15,41 +15,37 @@ * limitations under the License. */ -/* Includes */ - -#include -#include -#include - +#include "FreeRTOS.h" #include "em_bus.h" #include "em_cmu.h" #include "em_gpio.h" #include "em_ldma.h" #include "em_usart.h" -#include "gpiointerrupt.h" - -#include "wifi_config.h" - -#include "AppConfig.h" -#include "sl_wfx_board.h" -#include "sl_wfx_host.h" -#include "sl_wfx_task.h" -#include "wfx_host_events.h" - -#include "FreeRTOS.h" #include "event_groups.h" +#include "gpiointerrupt.h" +#include "sl_wfx_cmd_api.h" +#include "sl_wfx_constants.h" #include "task.h" - -#include "dhcp_client.h" -#include "ethernetif.h" #include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace ::chip; using namespace ::chip::DeviceLayer; +// TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation. +// As such we can't depend on the platform here as well +extern void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); + /* wfxRsi Task will use as its stack */ StackType_t wfxEventTaskStack[1024] = { 0 }; @@ -70,9 +66,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 @@ -92,8 +109,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; @@ -133,6 +148,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. @@ -164,7 +335,7 @@ sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload) /******** INDICATION ********/ case SL_WFX_STARTUP_IND_ID: { ChipLogProgress(DeviceLayer, "startup completed."); - PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, event_payload); + HandleWFXSystemEvent(WIFI_EVENT, event_payload); break; } case SL_WFX_CONNECT_IND_ID: { @@ -280,7 +451,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) @@ -715,8 +886,8 @@ static void wfx_wifi_hw_start(void) { /* Initialize the LwIP stack */ ChipLogDetail(DeviceLayer, "WF200:Start LWIP"); - wfx_lwip_start(); - wfx_started_notify(); + sl_matter_lwip_start(); + sl_matter_wifi_task_started(); wifiContext.state = SL_WFX_STARTED; /* Really this is a bit mask */ ChipLogDetail(DeviceLayer, "WF200:ready.."); } @@ -782,74 +953,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 @@ -880,16 +983,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 @@ -912,19 +1005,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 @@ -963,17 +1043,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 @@ -1072,7 +1141,7 @@ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) * @returns Returns SL_STATUS_OK if successful, * SL_STATUS_FAIL otherwise *****************************************************************************/ -sl_status_t wfx_sta_discon(void) +sl_status_t sl_matter_wifi_disconnect(void) { ChipLogProgress(DeviceLayer, "STA-Disconnecting"); int32_t status = sl_wfx_send_disconnect_command(); @@ -1150,10 +1219,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/src/platform/silabs/wifi/wf200/platform/efr_spi.c similarity index 99% rename from examples/platform/silabs/efr32/wf200/efr_spi.c rename to src/platform/silabs/wifi/wf200/platform/efr_spi.c index 3ef34c928e..6f80fc83d9 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/src/platform/silabs/wifi/wf200/platform/efr_spi.c @@ -14,14 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include - -#include "AppConfig.h" #include "FreeRTOS.h" -#include "semphr.h" - #include "dmadrv.h" #include "em_bus.h" #include "em_cmu.h" @@ -29,6 +22,7 @@ #include "em_ldma.h" #include "em_usart.h" #include "gpiointerrupt.h" +#include "semphr.h" #include "sl_spidrv_exp_config.h" #include "sl_spidrv_instances.h" #include "sl_wfx.h" @@ -38,9 +32,10 @@ #include "sl_wfx_host_api.h" #include "sl_wfx_task.h" #include "spidrv.h" - -#include "spi_multiplex.h" -#include "wfx_host_events.h" +#include +#include +#include +#include #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #include "sl_power_manager.h" @@ -442,6 +437,8 @@ sl_status_t sl_wfx_host_post_lcd_spi_transfer(void) #endif // SL_SPICTRL_MUX return SL_STATUS_OK; } +#else +#error still not working #endif // SL_LCDCTRL_MUX #if SL_UARTCTRL_MUX diff --git a/examples/platform/silabs/efr32/sl_custom_board.h b/src/platform/silabs/wifi/wf200/platform/sl_custom_board.h similarity index 100% rename from examples/platform/silabs/efr32/sl_custom_board.h rename to src/platform/silabs/wifi/wf200/platform/sl_custom_board.h diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_board.h b/src/platform/silabs/wifi/wf200/platform/sl_wfx_board.h similarity index 100% rename from examples/platform/silabs/efr32/wf200/sl_wfx_board.h rename to src/platform/silabs/wifi/wf200/platform/sl_wfx_board.h diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_host.h b/src/platform/silabs/wifi/wf200/platform/sl_wfx_host.h similarity index 100% rename from examples/platform/silabs/efr32/wf200/sl_wfx_host.h rename to src/platform/silabs/wifi/wf200/platform/sl_wfx_host.h diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_task.c b/src/platform/silabs/wifi/wf200/platform/sl_wfx_task.c similarity index 100% rename from examples/platform/silabs/efr32/wf200/sl_wfx_task.c rename to src/platform/silabs/wifi/wf200/platform/sl_wfx_task.c diff --git a/examples/platform/silabs/efr32/wf200/sl_wfx_task.h b/src/platform/silabs/wifi/wf200/platform/sl_wfx_task.h similarity index 100% rename from examples/platform/silabs/efr32/wf200/sl_wfx_task.h rename to src/platform/silabs/wifi/wf200/platform/sl_wfx_task.h diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/src/platform/silabs/wifi/wf200/platform/spi_multiplex.h similarity index 100% rename from examples/platform/silabs/efr32/spi_multiplex.h rename to src/platform/silabs/wifi/wf200/platform/spi_multiplex.h diff --git a/examples/platform/silabs/efr32/wf200/wf200_init.c b/src/platform/silabs/wifi/wf200/platform/wf200_init.c similarity index 97% rename from examples/platform/silabs/efr32/wf200/wf200_init.c rename to src/platform/silabs/wifi/wf200/platform/wf200_init.c index 3631216e76..40f1aaf08a 100644 --- a/examples/platform/silabs/efr32/wf200/wf200_init.c +++ b/src/platform/silabs/wifi/wf200/platform/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/src/platform/silabs/wifi/wf200/wf200.gni b/src/platform/silabs/wifi/wf200/wf200.gni new file mode 100644 index 0000000000..437f9def5d --- /dev/null +++ b/src/platform/silabs/wifi/wf200/wf200.gni @@ -0,0 +1,30 @@ +# 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, +# 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. + +import("//build_overrides/chip.gni") +import("//build_overrides/efr32_sdk.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") + +wf200_plat_src = [ + "${chip_root}/src/platform/silabs/wifi/wf200/WifiInterface.cpp", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_wfx_task.c", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/wf200_init.c", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/efr_spi.c", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_wfx_board.h", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_wfx_host.h", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_wfx_task.h", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_custom_board.h", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/spi_multiplex.h", + "${chip_root}/src/platform/silabs/wifi/wf200/platform/sl_wfx_board.h", +] diff --git a/src/platform/silabs/SiWx917/wifi/wfx_msgs.h b/src/platform/silabs/wifi/wfx_msgs.h similarity index 95% rename from src/platform/silabs/SiWx917/wifi/wfx_msgs.h rename to src/platform/silabs/wifi/wfx_msgs.h index b87a7c0707..af167a1f2c 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_msgs.h +++ b/src/platform/silabs/wifi/wfx_msgs.h @@ -15,15 +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_ -#include -/* - * 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 @@ -158,5 +160,6 @@ typedef struct __attribute__((__packed__)) sl_wfx_disconnect_ind_s /** Indication message body. */ sl_wfx_disconnect_ind_body_t body; } sl_wfx_disconnect_ind_t; +#endif #endif /* _WFX_MSGS_H_ */ diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp similarity index 72% rename from examples/platform/silabs/wifi/wfx_rsi_host.cpp rename to src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp index df64e915d4..2266989b90 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2022 Project CHIP Authors + * 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. @@ -10,35 +10,21 @@ * * 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 - -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" - -#include #include -#include #include +#include -#include "wfx_host_events.h" -#include "wfx_rsi.h" - -#include +namespace { // Thread for the WLAN RSI -static osThreadId_t sWlanThread; +osThreadId_t sWlanThread; constexpr uint32_t kWlanTaskSize = 2048; -static uint8_t wlanStack[kWlanTaskSize]; -static osThread_t sWlanTaskControlBlock; +uint8_t wlanStack[kWlanTaskSize]; +osThread_t sWlanTaskControlBlock; constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", .attr_bits = osThreadDetached, .cb_mem = &sWlanTaskControlBlock, @@ -47,6 +33,8 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", .stack_size = kWlanTaskSize, .priority = osPriorityAboveNormal7 }; +} // namespace + /********************************************************************* * @fn sl_status_t wfx_wifi_start(void) * @brief @@ -58,15 +46,15 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", ***********************************************************************/ sl_status_t wfx_wifi_start(void) { - VerifyOrReturnError(!(wfx_rsi.dev_state & WFX_RSI_ST_STARTED), SL_STATUS_OK); - wfx_rsi.dev_state |= WFX_RSI_ST_STARTED; + 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(wfx_rsi_task, NULL, &kWlanTaskAttr); + sWlanThread = osThreadNew(sl_matter_wifi_task, NULL, &kWlanTaskAttr); VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL); - ChipLogProgress(DeviceLayer, "wfx_rsi_task created successfully"); + ChipLogProgress(DeviceLayer, "sl_matter_wifi_task created successfully"); return SL_STATUS_OK; } @@ -79,7 +67,7 @@ sl_status_t wfx_wifi_start(void) ***********************************************************************/ void wfx_enable_sta_mode(void) { - wfx_rsi.dev_state |= WFX_RSI_ST_STA_MODE; + wfx_rsi.dev_state.Set(WifiState::kStationMode); } /********************************************************************* @@ -91,9 +79,7 @@ void wfx_enable_sta_mode(void) ***********************************************************************/ bool wfx_is_sta_mode_enabled(void) { - bool mode; - mode = !!(wfx_rsi.dev_state & WFX_RSI_ST_STA_MODE); - return mode; + return wfx_rsi.dev_state.Has(WifiState::kStationMode); } /********************************************************************* @@ -127,7 +113,7 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) { VerifyOrReturn(cfg != nullptr); wfx_rsi.sec = *cfg; - wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; + wfx_rsi.dev_state.Set(WifiState::kStationProvisioned); } /********************************************************************* @@ -141,7 +127,7 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { VerifyOrReturnError(wifiConfig != nullptr, false); - VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, false); + VerifyOrReturnError(wfx_rsi.dev_state.Has(WifiState::kStationProvisioned), false); *wifiConfig = wfx_rsi.sec; return true; } @@ -156,7 +142,7 @@ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) void wfx_clear_wifi_provision(void) { memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec)); - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED; + wfx_rsi.dev_state.Clear(WifiState::kStationProvisioned); ChipLogProgress(DeviceLayer, "Clear WiFi Provision"); } @@ -169,47 +155,15 @@ void wfx_clear_wifi_provision(void) ****************************************************************************/ sl_status_t wfx_connect_to_ap(void) { - VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, SL_STATUS_INVALID_CONFIGURATION); + 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); - WfxEvent_t event; - event.eventType = WFX_EVT_STA_START_JOIN; - WfxPostEvent(&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); + WifiEvent event = WifiEvent::kStationStartJoin; + sl_matter_wifi_post_event(event); + return SL_STATUS_OK; } -#endif /* SLI_SI917 */ -#endif /* SL_ICD_ENABLED */ /********************************************************************* * @fn void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) @@ -221,7 +175,7 @@ sl_status_t wfx_power_save(void) void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) { /* - * TODO: Implement IPV6 setup, currently in wfx_rsi_task() + * TODO: Implement IPV6 setup, currently in sl_matter_wifi_task() * This is hooked with MATTER code. */ } @@ -236,8 +190,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) ***********************************************************************/ bool wfx_is_sta_connected(void) { - bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; - return status; + return wfx_rsi.dev_state.Has(WifiState::kStationConnected); } /********************************************************************* @@ -250,24 +203,24 @@ bool wfx_is_sta_connected(void) ***********************************************************************/ wifi_mode_t wfx_get_wifi_mode(void) { - if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) + if (wfx_rsi.dev_state.Has(WifiState::kStationInit)) return WIFI_MODE_STA; return WIFI_MODE_NULL; } /********************************************************************* - * @fn sl_status_t wfx_sta_discon(void) + * @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 wfx_sta_discon(void) +sl_status_t sl_matter_wifi_disconnect(void) { sl_status_t status; - status = wfx_rsi_disconnect(); - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED; + status = sl_wifi_platform_disconnect(); + wfx_rsi.dev_state.Clear(WifiState::kStationConnected); return status; } #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 @@ -282,7 +235,7 @@ sl_status_t wfx_sta_discon(void) bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); - return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0); + return wfx_rsi.dev_state.Has(WifiState::kStationDhcpDone); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -297,8 +250,8 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); - // TODO: WFX_RSI_ST_STA_CONNECTED does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG - return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0); + // TODO: WifiState::kStationConnected does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG + return wfx_rsi.dev_state.Has(WifiState::kStationConnected); } /********************************************************************* @@ -311,7 +264,7 @@ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) ***********************************************************************/ bool wfx_hw_ready(void) { - return (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) ? true : false; + return wfx_rsi.dev_state.Has(WifiState::kStationInit); } /********************************************************************* @@ -365,18 +318,17 @@ int32_t wfx_reset_counts(void) 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); + VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); wfx_rsi.scan_cb = callback; - // if SSID is provided to scan only that SSID - if(ssid) { - wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); - wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length + 1)); - VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); - chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length + 1, ssid); - } - WfxEvent_t event; - event.eventType = WFX_EVT_SCAN; - WfxPostEvent(&event); + + 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; } diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h new file mode 100644 index 0000000000..9073a02ef6 --- /dev/null +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h @@ -0,0 +1,47 @@ +/* + * + * 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 +#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/system/BUILD.gn b/src/system/BUILD.gn index 40ae99ae99..a8d15cf83f 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -177,7 +177,7 @@ source_set("system_config_header") { public_deps += [ "${lwip_root}:lwip" ] } else { if (chip_device_platform == "efr32") { - public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ] + public_deps += [ "${silabs_sdk_build_root}:silabs_sdk" ] } if (chip_device_platform == "qpg") { public_deps += [ "${qpg_sdk_build_root}:qpg_sdk" ] diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index 6e22d8bb49..e2f625e4b9 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -18,7 +18,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index f7f52398a5..bb09b8426c 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -40,7 +40,7 @@ pw_unit_test_BACKEND = "$dir_pw_unit_test:light" # Override the executable type and the test main's target. pw_unit_test_EXECUTABLE_TARGET_TYPE = "silabs_executable" pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE = - "${efr32_sdk_build_root}/silabs_executable.gni" + "${silabs_sdk_build_root}/silabs_executable.gni" pw_unit_test_MAIN = "//:efr32_test_main" # Additional variables needed by silabs_executable that must be passed in to pw_test. diff --git a/third_party/openthread/platforms/efr32/BUILD.gn b/third_party/openthread/platforms/efr32/BUILD.gn index e270db2ae8..88f8f44c10 100644 --- a/third_party/openthread/platforms/efr32/BUILD.gn +++ b/third_party/openthread/platforms/efr32/BUILD.gn @@ -18,8 +18,8 @@ import("//build_overrides/openthread.gni") import("//build_overrides/openthread.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") -import("${efr32_sdk_build_root}/silabs_board.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/silabs_board.gni") config("openthread_efr32_config") { defines = [ @@ -48,7 +48,7 @@ source_set("openthread_core_config_efr32") { "${sl_ot_efr32_root}/openthread-core-efr32-config.h", ] - public_deps = [ "${efr32_sdk_build_root}:efr32_sdk" ] + public_deps = [ "${silabs_sdk_build_root}:silabs_sdk" ] public_configs = [ ":openthread_efr32_config" ] } diff --git a/third_party/silabs/BUILD.gn b/third_party/silabs/BUILD.gn index 16e0ba68c4..16d823dd4e 100644 --- a/third_party/silabs/BUILD.gn +++ b/third_party/silabs/BUILD.gn @@ -18,12 +18,12 @@ import("//build_overrides/jlink.gni") import("//build_overrides/openthread.gni") import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") -import("${efr32_sdk_build_root}/silabs_board.gni") +import("${silabs_sdk_build_root}/silabs_board.gni") if (wifi_soc == true) { # CCP board - import("${efr32_sdk_build_root}/SiWx917_sdk.gni") + import("${silabs_sdk_build_root}/SiWx917_sdk.gni") } else { - import("${efr32_sdk_build_root}/efr32_sdk.gni") + import("${silabs_sdk_build_root}/efr32_sdk.gni") } declare_args() { @@ -49,7 +49,7 @@ config("silabs_config") { } assert(silabs_sdk_target != "", "silabs_sdk_target must be specified") -group("efr32_sdk") { +group("silabs_sdk") { public_deps = [ silabs_sdk_target ] public_configs = [ ":silabs_config" ] } @@ -117,7 +117,7 @@ if (wifi_soc != true) { # CCP board public_deps = [ ":libopenthread-platform", - "${efr32_sdk_build_root}:efr32_sdk", + "${silabs_sdk_build_root}:silabs_sdk", ] public_configs = [ ":openthread_efr32_config" ] @@ -190,7 +190,7 @@ if (wifi_soc != true) { # CCP board "${segger_rtt_root}:segger_rtt", ] - deps = [ "${efr32_sdk_build_root}:efr32_sdk" ] + deps = [ "${silabs_sdk_build_root}:silabs_sdk" ] # selected thread device type FTD or MTD XTD = "ftd" diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 3accbed0bc..0bc8c7c693 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -16,12 +16,11 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") import("//build_overrides/jlink.gni") import("//build_overrides/mbedtls.gni") - import("${chip_root}/src/app/icd/icd.gni") import("${chip_root}/src/crypto/crypto.gni") import("${chip_root}/src/lib/lib.gni") -import("${chip_root}/src/platform/silabs/wifi_args.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${chip_root}/src/platform/silabs/wifi/args.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") import("silabs_board.gni") examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" @@ -322,9 +321,12 @@ template("siwx917_sdk") { "SL_ACTIVE_MODE_DURATION_MS=${sl_active_mode_duration_ms}", "SL_IDLE_MODE_DURATION_S=${sl_idle_mode_duration_s}", "SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC=${sl_icd_supported_clients_per_fabric}", - "SL_SI91X_NPSS_GPIO_BTN_HANDLER=1", "SL_SI91X_POWER_MANAGER_UC_AVAILABLE=1", "SL_SI91X_TICKLESS_MODE=1", + + # Enable Wakeup source for ICD + "SL_ENABLE_GPIO_WAKEUP_SOURCE=1", + "ENABLE_NPSS_GPIO_2=1", ] } @@ -682,7 +684,6 @@ template("siwx917_sdk") { "${wifi_sdk_root}/components/device/silabs/si91x/wireless/src/sl_si91x_callback_framework.c", "${wifi_sdk_root}/components/device/silabs/si91x/wireless/src/sl_si91x_driver.c", "${wifi_sdk_root}/components/device/silabs/si91x/wireless/threading/sli_si91x_multithreaded.c", - "${wifi_sdk_root}/components/service/network_manager/si91x/sl_net_si91x.c", # modified hal "${efr32_sdk_root}/platform/emdrv/nvm3/src/nvm3_default_common_linker.c", @@ -829,7 +830,7 @@ template("siwx917_sdk") { "${_mbedtls_root}/library/ssl_srv.c", "${_mbedtls_root}/library/ssl_tls.c", "${_mbedtls_root}/library/x509.c", - "${efr32_sdk_build_root}/mqtt/stack/mqtt.c", + "${silabs_sdk_build_root}/mqtt/stack/mqtt.c", ] } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 146077372f..9ca85baa47 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -96,6 +96,7 @@ declare_args() { examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32" silabs_plat_efr32_wifi_dir = "${chip_root}/src/platform/silabs/efr32/wifi" silabs_common_plat_dir = "${chip_root}/examples/platform/silabs" +silabs_platform_dir = "${chip_root}/src/platform/silabs" is_series_2 = silabs_family == "mgm24" || silabs_family == "efr32mg24" || silabs_family == "efr32mg26" @@ -333,6 +334,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/firmware", "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/pds/brd8022a", "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/secure_link", + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/config", ] } @@ -365,12 +367,23 @@ template("efr32_sdk") { "${wifi_sdk_root}/components/protocol/wifi/si91x", ] } + + if (use_rs9116) { + # TODO: we should create a seperate directory for headers that are necessary for the underlying sdks + _include_dirs += [ + "${chip_root}/src/platform/silabs/wifi/rs911x/platform", + "${chip_root}/src/platform/silabs/wifi/rs911x", + ] + } + if (use_rs9116 || use_SiWx917) { _include_dirs += [ "${chip_root}/src/platform/silabs/rs911x" ] } + if (use_wf200 || use_rs9116 || use_SiWx917) { _include_dirs += [ "${chip_root}/src/platform/silabs/wifi" ] } + if (silabs_family != "mgm24") { _include_dirs += [ "${efr32_sdk_root}/platform/radio/rail_lib/hal", @@ -583,7 +596,7 @@ template("efr32_sdk") { } if (use_wf200 || use_rs9116 || use_SiWx917) { - import("${chip_root}/src/platform/silabs/wifi_args.gni") + import("${chip_root}/src/platform/silabs/wifi/args.gni") defines += [ "LWIP_NETIF_API=1" ] if (chip_enable_wifi_ipv4) { diff --git a/third_party/silabs/lwip.gni b/third_party/silabs/lwip.gni index 9a35e7c45f..db19c08839 100644 --- a/third_party/silabs/lwip.gni +++ b/third_party/silabs/lwip.gni @@ -13,7 +13,7 @@ # limitations under the License. import("//build_overrides/efr32_sdk.gni") import("//build_overrides/lwip.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${silabs_sdk_build_root}/efr32_sdk.gni") # Defines a lwIP build target. # diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index fddcd73de5..eab695e438 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit fddcd73de5d30e41036993dc575f78835fba6e7c +Subproject commit eab695e438ada903a18956eb916696678227cb0d diff --git a/third_party/silabs/silabs_lwip/BUILD.gn b/third_party/silabs/silabs_lwip/BUILD.gn index e148763a9c..4d0bcb24c5 100644 --- a/third_party/silabs/silabs_lwip/BUILD.gn +++ b/third_party/silabs/silabs_lwip/BUILD.gn @@ -41,7 +41,7 @@ lwip_target("silabs_lwip") { public_deps = [ "${chip_root}/src/lwip:lwip_buildconfig", - "${efr32_sdk_build_root}:efr32_sdk", + "${silabs_sdk_build_root}:silabs_sdk", ] public_configs = [