From 27511297c81d37c41d0f041116f321125c90e465 Mon Sep 17 00:00:00 2001 From: Narayan Mohanram Date: Thu, 20 Jan 2022 13:34:39 -0800 Subject: [PATCH] Silabs wifi - chip support for EFR32 - Using WF200 and RS911x (#13193) * EFR32+SiLabs WiFi port - using lock app * Changed Wiseconnect SDK to relative symbolic link * Moved WiFi stuff to efr32_sdk/repo/matter/wifi * added Lighting app to silabs_wifi * Silabs_wifi Lighting-app removed some junk files * Update for building with scripts/examples/gn_efr32_example.sh * Rebased to master - Fixes to AppTask.cpp+BUILD.gn * Merged Thread and WiFi apps (Lighting and Windows) into examples/xxx-app/efr32 * Updated lock-app/efr32 to include WiFi build * Fixes to ifdef's in lock-app for efr32 * Removed examples/xx-app/silabs_wifi. Merged into examples/xx-app/efr32 * updated build-script for efr32 to use wifi * WiFi fixes to initialize RS911X for EFR32 * Update for WiFi port to sync with SiLabs work * WiFi - Added saving SSID/PSK/Security * Cleaned up comments in BUILD.gn * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Restyled by shellharden * Restyled by shfmt * Restyled by clang-format * include file reference was changed to * Added WF200 files and changed Defines to match master * Fixed issue with build script that does not handle ARG3/4 Co-authored-by: Restyled.io --- .github/workflows/examples-efr32.yaml | 2 +- config/efr32/toolchain/BUILD.gn | 6 + examples/lighting-app/efr32/BUILD.gn | 110 +++- .../efr32/build_for_wifi_args.gni | 22 + .../efr32/build_for_wifi_gnfile.gn | 28 + .../lighting-app/efr32/include/AppConfig.h | 2 +- .../efr32/include/FreeRTOSConfig.h | 4 + examples/lighting-app/efr32/src/AppTask.cpp | 60 ++- examples/lighting-app/efr32/src/main.cpp | 23 +- examples/lighting-app/efr32/with_pw_rpc.gni | 1 - examples/lock-app/efr32/BUILD.gn | 108 +++- .../lock-app/efr32/build_for_wifi_args.gni | 22 + .../lock-app/efr32/build_for_wifi_gnfile.gn | 28 + examples/lock-app/efr32/include/AppConfig.h | 2 +- examples/lock-app/efr32/src/AppTask.cpp | 57 +- examples/lock-app/efr32/src/main.cpp | 13 +- examples/platform/efr32/uart.cpp | 8 +- .../window-app/common/include/WindowApp.h | 9 +- examples/window-app/common/src/WindowApp.cpp | 16 +- examples/window-app/efr32/BUILD.gn | 115 ++++- .../window-app/efr32/build_for_wifi_args.gni | 22 + .../window-app/efr32/build_for_wifi_gnfile.gn | 28 + .../window-app/efr32/src/WindowAppImpl.cpp | 38 +- examples/window-app/efr32/src/main.cpp | 17 +- scripts/examples/gn_efr32_example.sh | 85 ++- src/lwip/efr32/lwipopts-rs911x.h | 203 ++++++++ src/lwip/efr32/lwipopts-thread.h | 182 +++++++ src/lwip/efr32/lwipopts-wf200.h | 203 ++++++++ src/lwip/efr32/lwipopts.h | 185 +------ src/platform/EFR32/BUILD.gn | 8 +- src/platform/EFR32/CHIPDevicePlatformConfig.h | 11 +- src/platform/EFR32/CHIPDevicePlatformEvent.h | 41 +- .../EFR32/ConfigurationManagerImpl.cpp | 20 + src/platform/EFR32/ConfigurationManagerImpl.h | 2 + src/platform/EFR32/ConnectivityManagerImpl.h | 95 ++++ .../EFR32/ConnectivityManagerImpl_WIFI.cpp | 485 ++++++++++++++++++ .../DeviceNetworkProvisioningDelegateImpl.cpp | 19 + .../DeviceNetworkProvisioningDelegateImpl.h | 4 + .../EFR32/DiagnosticDataProviderImpl.cpp | 8 +- src/platform/EFR32/EFR32Config.h | 7 +- src/platform/EFR32/InetPlatformConfig.h | 15 +- src/platform/EFR32/PlatformManagerImpl.cpp | 68 +++ src/platform/EFR32/PlatformManagerImpl.h | 6 + src/platform/EFR32/ServiceProvisioning.cpp | 56 ++ src/platform/EFR32/ServiceProvisioning.h | 25 + src/platform/EFR32/wifi_args.gni | 46 ++ third_party/efr32_sdk/efr32_sdk.gni | 23 + third_party/wiseconnect-wifi-bt-sdk | 1 + 48 files changed, 2230 insertions(+), 309 deletions(-) create mode 100644 examples/lighting-app/efr32/build_for_wifi_args.gni create mode 100644 examples/lighting-app/efr32/build_for_wifi_gnfile.gn create mode 100644 examples/lock-app/efr32/build_for_wifi_args.gni create mode 100644 examples/lock-app/efr32/build_for_wifi_gnfile.gn create mode 100644 examples/window-app/efr32/build_for_wifi_args.gni create mode 100644 examples/window-app/efr32/build_for_wifi_gnfile.gn create mode 100644 src/lwip/efr32/lwipopts-rs911x.h create mode 100644 src/lwip/efr32/lwipopts-thread.h create mode 100644 src/lwip/efr32/lwipopts-wf200.h create mode 100644 src/platform/EFR32/ConnectivityManagerImpl_WIFI.cpp create mode 100644 src/platform/EFR32/ServiceProvisioning.cpp create mode 100644 src/platform/EFR32/ServiceProvisioning.h create mode 100644 src/platform/EFR32/wifi_args.gni create mode 120000 third_party/wiseconnect-wifi-bt-sdk diff --git a/.github/workflows/examples-efr32.yaml b/.github/workflows/examples-efr32.yaml index cebd9102383422..88818ec8693c55 100644 --- a/.github/workflows/examples-efr32.yaml +++ b/.github/workflows/examples-efr32.yaml @@ -82,7 +82,7 @@ jobs: timeout-minutes: 10 run: | scripts/examples/gn_efr32_example.sh examples/lighting-app/efr32/ out/lighting_app_debug_rpc BRD4161A \ - -args='import("//with_pw_rpc.gni")' + 'import("//with_pw_rpc.gni")' .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py efr32 BRD4161A+rpc lighting-app \ out/lighting_app_debug_rpc/BRD4161A/chip-efr32-lighting-example.out /tmp/bloat_reports/ - name: Build example EFR32 Window Covering for BRD4161A diff --git a/config/efr32/toolchain/BUILD.gn b/config/efr32/toolchain/BUILD.gn index 76747ede876a5c..8f448eb44838b9 100644 --- a/config/efr32/toolchain/BUILD.gn +++ b/config/efr32/toolchain/BUILD.gn @@ -37,3 +37,9 @@ arm_toolchain("efr32_window_app") { import("${chip_root}/examples/window-app/efr32/args.gni") } } +arm_toolchain("rs911x_lock_app") { + toolchain_args = { + current_os = "freertos" + import("${chip_root}/examples/lock-app/rs911x/args.gni") + } +} diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index a248836a3f7efa..b9bbca9a8dc80f 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -44,6 +44,13 @@ declare_args() { # Monitor & log memory usage at runtime. enable_heap_monitoring = false + + # Wifi related stuff - they are overriden by gn -args="use_wf200=true" + use_wf200 = false + use_rs911x = false + use_rs911x_sockets = false + sl_wfx_config_softap = false + sl_wfx_config_scan = false } show_qr_code = true @@ -52,6 +59,26 @@ show_qr_code = true if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") { show_qr_code = false } +if (use_rs911x || use_wf200) { + wifi_sdk_dir = "${chip_root}/third_party/efr32_sdk/repo/matter/wifi" + if (use_rs911x) { + wiseconnect_sdk_root = "${chip_root}/third_party/wiseconnect-wifi-bt-sdk" + import("${wifi_sdk_dir}/rs911x/rs911x.gni") + } else { + import("${wifi_sdk_dir}/wf200/wf200.gni") + } +} +efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] +if (use_rs911x || use_wf200) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_DHCP=1", + "LWIP_IPV6_ND=1", + "LWIP_IGMP=1", + ] +} efr32_sdk("sdk") { sources = [ @@ -63,6 +90,7 @@ efr32_sdk("sdk") { "${chip_root}/src/platform/EFR32", "${efr32_project_dir}/include", "${examples_plat_dir}", + "${chip_root}/src/lib", ] defines = [ @@ -77,10 +105,36 @@ efr32_sdk("sdk") { "PW_RPC_ENABLED", ] } + if (use_rs911x) { + defines += rs911x_defs + include_dirs += rs911x_plat_incs + } else if (use_wf200) { + defines += wf200_defs + include_dirs += wf200_plat_incs + } else { + defines += [ "SL_HEAP_SIZE=20480" ] + } + if (use_rs911x_sockets) { + include_dirs += [ "${examples_plat_dir}/wifi/rsi-sockets" ] + defines += rs911x_sock_defs + } else { + # Using LWIP instead of the native TCP/IP stack + # Thread also uses LWIP + # + defines += efr32_lwip_defs + } + if (sl_wfx_config_softap) { + defines += "SL_WFX_CONFIG_SOFTAP" + } + if (sl_wfx_config_scan) { + defines += "SL_WFX_CONFIG_SCAN" + } } efr32_executable("lighting_app") { output_name = "chip-efr32-lighting-example.out" + include_dirs = [ "include" ] + defines = [] sources = [ "${examples_plat_dir}/LEDWidget.cpp", @@ -99,26 +153,50 @@ efr32_executable("lighting_app") { "${chip_root}/examples/lighting-app/lighting-common", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", - "${examples_plat_dir}:efr-matter-shell", ] - - if (chip_openthread_ftd) { - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", - "${chip_root}/third_party/openthread/repo:libopenthread-ftd", - ] - } else { + if (!use_rs911x && !use_wf200) { deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", - "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", + "${examples_plat_dir}:efr-matter-shell", ] + if (chip_openthread_ftd) { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", + "${chip_root}/third_party/openthread/repo:libopenthread-ftd", + ] + } else { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", + "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + ] + } + } + if (use_rs911x) { + sources += rs911x_src_plat + + # All the stuff from wiseconnect + sources += rs911x_src_sapi + + # Apparently - the rsi library needs this (though we may not use use it) + sources += rs911x_src_sock + include_dirs += rs911x_inc_plat + + if (use_rs911x_sockets) { + # + # Using native sockets inside RS911x + # + include_dirs += rs911x_sock_inc + } else { + # + # We use LWIP - not built-in sockets + # + sources += rs911x_src_lwip + } + } else if (use_wf200) { + sources += wf200_plat_src + include_dirs += wf200_plat_incs } - - include_dirs = [ "include" ] - - defines = [] if (show_qr_code) { sources += [ "${examples_plat_dir}/display/lcd.c" ] diff --git a/examples/lighting-app/efr32/build_for_wifi_args.gni b/examples/lighting-app/efr32/build_for_wifi_args.gni new file mode 100644 index 00000000000000..04529fddd2076a --- /dev/null +++ b/examples/lighting-app/efr32/build_for_wifi_args.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2020 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/pigweed.gni") + +efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +chip_enable_openthread = false +import("${chip_root}/src/platform/EFR32/wifi_args.gni") + +pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" +pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/lighting-app/efr32/build_for_wifi_gnfile.gn b/examples/lighting-app/efr32/build_for_wifi_gnfile.gn new file mode 100644 index 00000000000000..9752ee73e7c91d --- /dev/null +++ b/examples/lighting-app/efr32/build_for_wifi_gnfile.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "freertos" + use_thread = false + import("//build_for_wifi_args.gni") +} diff --git a/examples/lighting-app/efr32/include/AppConfig.h b/examples/lighting-app/efr32/include/AppConfig.h index efe17b3b39288f..91501d889a6234 100644 --- a/examples/lighting-app/efr32/include/AppConfig.h +++ b/examples/lighting-app/efr32/include/AppConfig.h @@ -21,7 +21,7 @@ // ---- Lighting Example App Config ---- -#define APP_TASK_NAME "APP" +#define APP_TASK_NAME "Lit" // Time it takes in ms for the simulated actuator to move from one // state to another. diff --git a/examples/lighting-app/efr32/include/FreeRTOSConfig.h b/examples/lighting-app/efr32/include/FreeRTOSConfig.h index 3d241f9a24ce0e..17bc3975fe19af 100644 --- a/examples/lighting-app/efr32/include/FreeRTOSConfig.h +++ b/examples/lighting-app/efr32/include/FreeRTOSConfig.h @@ -237,7 +237,11 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #define configENABLE_BACKWARD_COMPATIBILITY (1) #define configSUPPORT_STATIC_ALLOCATION (1) #define configSUPPORT_DYNAMIC_ALLOCATION (1) +#ifdef SL_WIFI +#define configTOTAL_HEAP_SIZE ((size_t)(28 * 1024)) +#else #define configTOTAL_HEAP_SIZE ((size_t)(20 * 1024)) +#endif /* Optional functions - most linkers will remove unused functions anyway. */ #define INCLUDE_vTaskPrioritySet (1) diff --git a/examples/lighting-app/efr32/src/AppTask.cpp b/examples/lighting-app/efr32/src/AppTask.cpp index 778acda0bd3fc9..acdf7f8c78ea4d 100644 --- a/examples/lighting-app/efr32/src/AppTask.cpp +++ b/examples/lighting-app/efr32/src/AppTask.cpp @@ -51,6 +51,9 @@ #include #include #endif +#ifdef SL_WIFI +#include "wfx_host_events.h" +#endif /* SL_WIFI */ #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 @@ -73,9 +76,17 @@ QueueHandle_t sAppEventQueue; LEDWidget sStatusLED; LEDWidget sLightLED; +#ifdef SL_WIFI +bool sIsWiFiProvisioned = false; +bool sIsWiFiEnabled = false; +bool sIsWiFiAttached = false; +#endif /* SL_WIFI */ + +#if CHIP_ENABLE_OPENTHREAD bool sIsThreadProvisioned = false; bool sIsThreadEnabled = false; -bool sHaveBLEConnections = false; +#endif /* CHIP_ENABLE_OPENTHREAD */ +bool sHaveBLEConnections = false; EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; @@ -88,6 +99,7 @@ StaticTask_t appTaskStruct; /********************************************************** * Identify Callbacks *********************************************************/ + namespace { void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) { @@ -208,6 +220,18 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; +#ifdef SL_WIFI + /* + * Wait for the WiFi to be initialized + */ + EFR32_LOG("APP: Wait WiFi Init"); + while (!wfx_hw_ready()) + { + vTaskDelay(10); + } + EFR32_LOG("APP: Done WiFi Init"); + /* We will init server when we get IP */ +#endif // Init ZCL Data Model chip::Server::GetInstance().Init(); @@ -294,9 +318,16 @@ void AppTask::AppTaskMain(void * pvParameter) // when the CHIP task is busy (e.g. with a long crypto operation). if (PlatformMgr().TryLockChipStack()) { +#ifdef SL_WIFI + sIsWiFiProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); + sIsWiFiEnabled = ConnectivityMgr().IsWiFiStationEnabled(); + sIsWiFiAttached = ConnectivityMgr().IsWiFiStationConnected(); +#endif /* SL_WIFI */ +#if CHIP_ENABLE_OPENTHREAD sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); - sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); +#endif /* CHIP_ENABLE_OPENTHREAD */ + sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } @@ -333,18 +364,16 @@ void AppTask::AppTaskMain(void * pvParameter) sStatusLED.Blink(300, 700); } } - else if (sIsThreadProvisioned && sIsThreadEnabled) +#if CHIP_ENABLE_OPENTHREAD + if (sIsThreadProvisioned && sIsThreadEnabled) +#else + if (sIsWiFiProvisioned && sIsWiFiEnabled && !sIsWiFiAttached) +#endif { sStatusLED.Blink(950, 50); } - else if (sHaveBLEConnections) - { - sStatusLED.Blink(100, 100); - } - else - { - sStatusLED.Blink(50, 950); - } + else if (sHaveBLEConnections) { sStatusLED.Blink(100, 100); } + else { sStatusLED.Blink(50, 950); } } sStatusLED.Animate(); @@ -484,16 +513,17 @@ void AppTask::FunctionHandler(AppEvent * aEvent) sAppTask.CancelTimer(); sAppTask.mFunction = kFunction_NoneSelected; +#ifdef SL_WIFI + if (!ConnectivityMgr().IsWiFiStationProvisioned()) +#else if (!ConnectivityMgr().IsThreadProvisioned()) +#endif /* !SL_WIFI */ { // Enable BLE advertisements ConnectivityMgr().SetBLEAdvertisingEnabled(true); ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); } - else - { - EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); - } + else { EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); } } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { diff --git a/examples/lighting-app/efr32/src/main.cpp b/examples/lighting-app/efr32/src/main.cpp index 943f0993a7af35..297601ac6f8670 100644 --- a/examples/lighting-app/efr32/src/main.cpp +++ b/examples/lighting-app/efr32/src/main.cpp @@ -48,8 +48,8 @@ #include "lcd.h" #endif -#if CHIP_ENABLE_OPENTHREAD #include +#if CHIP_ENABLE_OPENTHREAD #include #include #include @@ -62,6 +62,10 @@ #include #endif // CHIP_ENABLE_OPENTHREAD +#if defined(RS911X_WIFI) || defined(WF200_WIFI) +#include "wfx_host_events.h" +#endif /* RS911X_WIFI */ + #if PW_RPC_ENABLED #include "Rpc.h" #endif @@ -70,6 +74,7 @@ #include "matter_shell.h" #endif +#define BLE_DEV_NAME "SiLabs-Light" using namespace ::chip; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; @@ -135,7 +140,7 @@ int main(void) EFR32_LOG("PlatformMgr().InitChipStack() failed"); appError(ret); } - chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("EFR32_LIGHT"); + chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(BLE_DEV_NAME); #if CHIP_ENABLE_OPENTHREAD EFR32_LOG("Initializing OpenThread stack"); ret = ThreadStackMgr().InitThreadStack(); @@ -160,6 +165,13 @@ int main(void) EFR32_LOG("PlatformMgr().StartEventLoopTask() failed"); appError(ret); } +#ifdef WF200_WIFI + // 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 */ #if CHIP_ENABLE_OPENTHREAD EFR32_LOG("Starting OpenThread task"); @@ -172,6 +184,13 @@ int main(void) appError(ret); } #endif // CHIP_ENABLE_OPENTHREAD +#ifdef RS911X_WIFI + /* + * Start up any RSI interface stuff + * (Not required) - Note that wfx_wifi_start will deal with + * starting up a rsi task - which will initialize the SPI interface. + */ +#endif EFR32_LOG("Starting App Task"); ret = GetAppTask().StartAppTask(); diff --git a/examples/lighting-app/efr32/with_pw_rpc.gni b/examples/lighting-app/efr32/with_pw_rpc.gni index d0a8f2c0485f06..3922567d5b071a 100644 --- a/examples/lighting-app/efr32/with_pw_rpc.gni +++ b/examples/lighting-app/efr32/with_pw_rpc.gni @@ -23,6 +23,5 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true -chip_openthread_ftd = true cpp_standard = "gnu++17" diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 534ce5343e2dde..7dcc8802659fdc 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -43,6 +43,13 @@ declare_args() { # Monitor & log memory usage at runtime. enable_heap_monitoring = false + + # Wifi related stuff - they are overriden by gn -args="use_wf200=true" + use_wf200 = false + use_rs911x = false + use_rs911x_sockets = false + sl_wfx_config_softap = false + sl_wfx_config_scan = false } show_qr_code = true @@ -51,6 +58,26 @@ show_qr_code = true if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") { show_qr_code = false } +if (use_rs911x || use_wf200) { + wifi_sdk_dir = "${chip_root}/third_party/efr32_sdk/repo/matter/wifi" + if (use_rs911x) { + wiseconnect_sdk_root = "${chip_root}/third_party/wiseconnect-wifi-bt-sdk" + import("${wifi_sdk_dir}/rs911x/rs911x.gni") + } else { + import("${wifi_sdk_dir}/wf200/wf200.gni") + } +} +efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] +if (use_rs911x || use_wf200) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_DHCP=1", + "LWIP_IPV6_ND=1", + "LWIP_IGMP=1", + ] +} efr32_sdk("sdk") { sources = [ @@ -62,6 +89,7 @@ efr32_sdk("sdk") { "${chip_root}/src/platform/EFR32", "${efr32_project_dir}/include", "${examples_plat_dir}", + "${chip_root}/src/lib", ] defines = [ @@ -75,10 +103,37 @@ efr32_sdk("sdk") { "PW_RPC_ENABLED", ] } + if (use_rs911x) { + defines += rs911x_defs + include_dirs += rs911x_plat_incs + } else if (use_wf200) { + defines += wf200_defs + include_dirs += wf200_plat_incs + } else { + defines += [ "SL_HEAP_SIZE=20480" ] + } + if (use_rs911x_sockets) { + include_dirs += [ "${examples_plat_dir}/wifi/rsi-sockets" ] + defines += rs911x_sock_defs + } else { + # Using LWIP instead of the native TCP/IP stack + # Thread also uses LWIP + # + defines += efr32_lwip_defs + } + if (sl_wfx_config_softap) { + defines += "SL_WFX_CONFIG_SOFTAP" + } + if (sl_wfx_config_scan) { + defines += "SL_WFX_CONFIG_SCAN" + } } efr32_executable("lock_app") { output_name = "chip-efr32-lock-example.out" + include_dirs = [ "include" ] + + defines = [] sources = [ "${examples_plat_dir}/LEDWidget.cpp", @@ -101,22 +156,49 @@ efr32_executable("lock_app") { "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", "${examples_plat_dir}:efr-matter-shell", ] - - if (chip_openthread_ftd) { - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", - "${chip_root}/third_party/openthread/repo:libopenthread-ftd", - ] - } else { + if (!use_rs911x && !use_wf200) { deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", - "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", + "${examples_plat_dir}:efr-matter-shell", ] + if (chip_openthread_ftd) { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", + "${chip_root}/third_party/openthread/repo:libopenthread-ftd", + ] + } else { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", + "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + ] + } + } + if (use_rs911x) { + sources += rs911x_src_plat + + # All the stuff from wiseconnect + sources += rs911x_src_sapi + + # Apparently - the rsi library needs this (though we may not use use it) + sources += rs911x_src_sock + include_dirs += rs911x_inc_plat + + if (use_rs911x_sockets) { + # + # Using native sockets inside RS911x + # + include_dirs += rs911x_sock_inc + } else { + # + # We use LWIP - not built-in sockets + # + sources += rs911x_src_lwip + } + } else if (use_wf200) { + sources += wf200_plat_src + include_dirs += wf200_plat_incs } - - include_dirs = [ "include" ] - - defines = [] if (show_qr_code) { sources += [ "${examples_plat_dir}/display/lcd.c" ] diff --git a/examples/lock-app/efr32/build_for_wifi_args.gni b/examples/lock-app/efr32/build_for_wifi_args.gni new file mode 100644 index 00000000000000..04529fddd2076a --- /dev/null +++ b/examples/lock-app/efr32/build_for_wifi_args.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2020 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/pigweed.gni") + +efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +chip_enable_openthread = false +import("${chip_root}/src/platform/EFR32/wifi_args.gni") + +pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" +pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/lock-app/efr32/build_for_wifi_gnfile.gn b/examples/lock-app/efr32/build_for_wifi_gnfile.gn new file mode 100644 index 00000000000000..9752ee73e7c91d --- /dev/null +++ b/examples/lock-app/efr32/build_for_wifi_gnfile.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "freertos" + use_thread = false + import("//build_for_wifi_args.gni") +} diff --git a/examples/lock-app/efr32/include/AppConfig.h b/examples/lock-app/efr32/include/AppConfig.h index 77223889639fb1..84b588c4997970 100644 --- a/examples/lock-app/efr32/include/AppConfig.h +++ b/examples/lock-app/efr32/include/AppConfig.h @@ -21,7 +21,7 @@ // ---- Lock Example App Config ---- -#define APP_TASK_NAME "APP" +#define APP_TASK_NAME "Lck" // Time it takes in ms for the simulated actuator to move from one // state to another. diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index 0a67f008a94317..a02b834ca0e9eb 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -47,6 +47,9 @@ #include #include #endif +#ifdef SL_WIFI +#include "wfx_host_events.h" +#endif #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 @@ -68,9 +71,17 @@ QueueHandle_t sAppEventQueue; LEDWidget sStatusLED; LEDWidget sLockLED; +#ifdef SL_WIFI +bool sIsWiFiProvisioned = false; +bool sIsWiFiEnabled = false; +bool sIsWiFiAttached = false; +#endif + +#if CHIP_ENABLE_OPENTHREAD bool sIsThreadProvisioned = false; bool sIsThreadEnabled = false; -bool sHaveBLEConnections = false; +#endif +bool sHaveBLEConnections = false; StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; StaticTask_t appTaskStruct; @@ -98,6 +109,18 @@ CHIP_ERROR AppTask::StartAppTask() CHIP_ERROR AppTask::Init() { +#ifdef SL_WIFI + /* + * Wait for the WiFi to be initialized + */ + EFR32_LOG("APP: Wait WiFi Init"); + while (!wfx_hw_ready()) + { + vTaskDelay(10); + } + EFR32_LOG("APP: Done WiFi Init"); + /* We will init server when we get IP */ +#endif // Init ZCL Data Model chip::Server::GetInstance().Init(); @@ -185,9 +208,16 @@ void AppTask::AppTaskMain(void * pvParameter) // when the CHIP task is busy (e.g. with a long crypto operation). if (PlatformMgr().TryLockChipStack()) { +#ifdef SL_WIFI + sIsWiFiProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); + sIsWiFiEnabled = ConnectivityMgr().IsWiFiStationEnabled(); + sIsWiFiAttached = ConnectivityMgr().IsWiFiStationConnected(); +#endif +#if CHIP_ENABLE_OPENTHREAD sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); - sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); +#endif + sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } @@ -205,18 +235,16 @@ void AppTask::AppTaskMain(void * pvParameter) // Otherwise, blink the LED ON for a very short time. if (sAppTask.mFunction != kFunction_FactoryReset) { +#if CHIP_ENABLE_OPENTHREAD if (sIsThreadProvisioned && sIsThreadEnabled) +#else + if (sIsWiFiProvisioned && sIsWiFiEnabled && !sIsWiFiAttached) +#endif { sStatusLED.Blink(950, 50); } - else if (sHaveBLEConnections) - { - sStatusLED.Blink(100, 100); - } - else - { - sStatusLED.Blink(50, 950); - } + else if (sHaveBLEConnections) { sStatusLED.Blink(100, 100); } + else { sStatusLED.Blink(50, 950); } } sStatusLED.Animate(); @@ -356,16 +384,17 @@ void AppTask::FunctionHandler(AppEvent * aEvent) sAppTask.CancelTimer(); sAppTask.mFunction = kFunction_NoneSelected; +#ifdef SL_WIFI + if (!ConnectivityMgr().IsWiFiStationProvisioned()) +#else if (!ConnectivityMgr().IsThreadProvisioned()) +#endif { // Enable BLE advertisements ConnectivityMgr().SetBLEAdvertisingEnabled(true); ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); } - else - { - EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); - } + else { EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); } } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { diff --git a/examples/lock-app/efr32/src/main.cpp b/examples/lock-app/efr32/src/main.cpp index c92b9e71c8b7d5..7e25365142199d 100644 --- a/examples/lock-app/efr32/src/main.cpp +++ b/examples/lock-app/efr32/src/main.cpp @@ -56,8 +56,8 @@ #include "matter_shell.h" #endif -#if CHIP_ENABLE_OPENTHREAD #include +#if CHIP_ENABLE_OPENTHREAD #include #include #include @@ -70,6 +70,10 @@ #include #endif // CHIP_ENABLE_OPENTHREAD +#if defined(RS911X_WIFI) || defined(WF200_WIFI) +#include "wfx_host_events.h" +#endif /* RS911X_WIFI */ + using namespace ::chip; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; @@ -169,6 +173,13 @@ int main(void) appError(ret); } #endif // CHIP_ENABLE_OPENTHREAD +#ifdef WF200_WIFI + // 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 */ EFR32_LOG("Starting App Task"); ret = GetAppTask().StartAppTask(); diff --git a/examples/platform/efr32/uart.cpp b/examples/platform/efr32/uart.cpp index 9d3cbc2b1d966d..8d384a9ac657b4 100644 --- a/examples/platform/efr32/uart.cpp +++ b/examples/platform/efr32/uart.cpp @@ -200,7 +200,9 @@ void USART_IRQHandler(void) #ifdef ENABLE_CHIP_SHELL chip::NotifyShellProcessFromISR(); #endif -#ifndef PW_RPC_ENABLED +#if defined(SL_WIFI) + /* TODO */ +#elif !defined(PW_RPC_ENABLED) otSysEventSignalPending(); #endif } @@ -224,7 +226,9 @@ static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, ui #ifdef ENABLE_CHIP_SHELL chip::NotifyShellProcessFromISR(); #endif -#ifndef PW_RPC_ENABLED +#if defined(SL_WIFI) + /* TODO */ +#elif !defined(PW_RPC_ENABLED) otSysEventSignalPending(); #endif } diff --git a/examples/window-app/common/include/WindowApp.h b/examples/window-app/common/include/WindowApp.h index e8184e21103b40..f5dc1f582ba35a 100644 --- a/examples/window-app/common/include/WindowApp.h +++ b/examples/window-app/common/include/WindowApp.h @@ -135,10 +135,15 @@ class WindowApp protected: struct StateFlags { +#if CHIP_ENABLE_OPENTHREAD bool isThreadProvisioned = false; bool isThreadEnabled = false; - bool haveBLEConnections = false; - bool isWinking = false; +#else + bool isWiFiProvisioned = false; + bool isWiFiEnabled = false; +#endif + bool haveBLEConnections = false; + bool isWinking = false; }; Cover & GetCover(); diff --git a/examples/window-app/common/src/WindowApp.cpp b/examples/window-app/common/src/WindowApp.cpp index 813ad816a156ad..d69e128257e9f2 100644 --- a/examples/window-app/common/src/WindowApp.cpp +++ b/examples/window-app/common/src/WindowApp.cpp @@ -138,8 +138,11 @@ CHIP_ERROR WindowApp::Run() { StateFlags oldState; +#if CHIP_ENABLE_OPENTHREAD oldState.isThreadProvisioned = !ConnectivityMgr().IsThreadProvisioned(); - +#else + oldState.isWiFiProvisioned = !ConnectivityMgr().IsWiFiStationProvisioned(); +#endif while (true) { ProcessEvents(); @@ -151,13 +154,22 @@ CHIP_ERROR WindowApp::Run() // when the CHIP task is busy (e.g. with a long crypto operation). if (PlatformMgr().TryLockChipStack()) { +#if CHIP_ENABLE_OPENTHREAD mState.isThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); mState.isThreadEnabled = ConnectivityMgr().IsThreadEnabled(); - mState.haveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); +#else + mState.isWiFiProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); + mState.isWiFiEnabled = ConnectivityMgr().IsWiFiStationEnabled(); +#endif + mState.haveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } +#if CHIP_ENABLE_OPENTHREAD if (mState.isThreadProvisioned != oldState.isThreadProvisioned) +#else + if (mState.isWiFiProvisioned != oldState.isWiFiProvisioned) +#endif { // Provisioned state changed DispatchEvent(EventId::ProvisionedStateChanged); diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 40bf9abe5f4545..2f3c814e4a83cb 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -37,6 +37,13 @@ declare_args() { # Monitor & log memory usage at runtime. enable_heap_monitoring = false + + # Wifi related stuff - they are overriden by gn -args="use_wf200=true" + use_wf200 = false + use_rs911x = false + use_rs911x_sockets = false + sl_wfx_config_softap = false + sl_wfx_config_scan = false } show_qr_code = true @@ -45,6 +52,26 @@ show_qr_code = true if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") { show_qr_code = false } +if (use_rs911x || use_wf200) { + wifi_sdk_dir = "${chip_root}/third_party/efr32_sdk/repo/matter/wifi" + if (use_rs911x) { + wiseconnect_sdk_root = "${chip_root}/third_party/wiseconnect-wifi-bt-sdk" + import("${wifi_sdk_dir}/rs911x/rs911x.gni") + } else { + import("${wifi_sdk_dir}/wf200/wf200.gni") + } +} +efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] +if (use_rs911x || use_wf200) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_DHCP=1", + "LWIP_IPV6_ND=1", + "LWIP_IGMP=1", + ] +} efr32_sdk("sdk") { sources = [ @@ -56,17 +83,47 @@ efr32_sdk("sdk") { "${chip_root}/src/platform/EFR32", "${efr32_project_dir}/include", "${examples_plat_dir}", + "${chip_root}/src/lib", ] defines = [ "BOARD_ID=${efr32_board}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", ] + if (use_rs911x) { + defines += rs911x_defs + include_dirs += rs911x_plat_incs + } else if (use_wf200) { + defines += wf200_defs + include_dirs += wf200_plat_incs + } else { + defines += [ "SL_HEAP_SIZE=20480" ] + } + if (use_rs911x_sockets) { + include_dirs += [ "${examples_plat_dir}/wifi/rsi-sockets" ] + defines += rs911x_sock_defs + } else { + # Using LWIP instead of the native TCP/IP stack + # Thread also uses LWIP + # + defines += efr32_lwip_defs + } + if (sl_wfx_config_softap) { + defines += "SL_WFX_CONFIG_SOFTAP" + } + if (sl_wfx_config_scan) { + defines += "SL_WFX_CONFIG_SCAN" + } } efr32_executable("window_app") { output_name = "chip-efr32-window-example.out" output_dir = root_out_dir + include_dirs = [ + "include", + "${project_dir}/common/include", + ] + defines = [] sources = [ "${examples_plat_dir}/LEDWidget.cpp", @@ -79,36 +136,58 @@ efr32_executable("window_app") { "src/main.cpp", ] + if (use_rs911x) { + sources += rs911x_src_plat + + # All the stuff from wiseconnect + sources += rs911x_src_sapi + + # Apparently - the rsi library needs this (though we may not use use it) + sources += rs911x_src_sock + include_dirs += rs911x_inc_plat + + if (use_rs911x_sockets) { + # + # Using native sockets inside RS911x + # + include_dirs += rs911x_sock_inc + } else { + # + # We use LWIP - not built-in sockets + # + sources += rs911x_src_lwip + } + } else if (use_wf200) { + sources += wf200_plat_src + include_dirs += wf200_plat_incs + } deps = [ ":sdk", "${chip_root}/examples/common/QRCode", "${chip_root}/examples/window-app/common:window-common", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", - "${examples_plat_dir}:efr-matter-shell", ] - if (chip_openthread_ftd) { - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", - "${chip_root}/third_party/openthread/repo:libopenthread-ftd", - ] - } else { + if (!use_rs911x && !use_wf200) { deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", - "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", + "${examples_plat_dir}:efr-matter-shell", ] + if (chip_openthread_ftd) { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", + "${chip_root}/third_party/openthread/repo:libopenthread-ftd", + ] + } else { + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", + "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + ] + } } - include_dirs = [ - "include", - "${project_dir}/common/include", - ] - - defines = [] - if (show_qr_code) { sources += [ "${examples_plat_dir}/display/lcd.c", diff --git a/examples/window-app/efr32/build_for_wifi_args.gni b/examples/window-app/efr32/build_for_wifi_args.gni new file mode 100644 index 00000000000000..04529fddd2076a --- /dev/null +++ b/examples/window-app/efr32/build_for_wifi_args.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2020 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/pigweed.gni") + +efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +chip_enable_openthread = false +import("${chip_root}/src/platform/EFR32/wifi_args.gni") + +pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" +pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/window-app/efr32/build_for_wifi_gnfile.gn b/examples/window-app/efr32/build_for_wifi_gnfile.gn new file mode 100644 index 00000000000000..9752ee73e7c91d --- /dev/null +++ b/examples/window-app/efr32/build_for_wifi_gnfile.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "freertos" + use_thread = false + import("//build_for_wifi_args.gni") +} diff --git a/examples/window-app/efr32/src/WindowAppImpl.cpp b/examples/window-app/efr32/src/WindowAppImpl.cpp index 6a294c941b5261..7bff2706e5b5cb 100644 --- a/examples/window-app/efr32/src/WindowAppImpl.cpp +++ b/examples/window-app/efr32/src/WindowAppImpl.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef SL_WIFI +#include "wfx_host_events.h" +#endif + #define APP_TASK_STACK_SIZE (4096) #define APP_TASK_PRIORITY 2 #define APP_EVENT_QUEUE_SIZE 10 @@ -143,6 +147,18 @@ void WindowAppImpl::OnIconTimeout(WindowApp::Timer & timer) CHIP_ERROR WindowAppImpl::Init() { +#ifdef SL_WIFI + /* + * Wait for the WiFi to be initialized + */ + EFR32_LOG("APP: Wait WiFi Init"); + while (!wfx_hw_ready()) + { + vTaskDelay(10); + } + EFR32_LOG("APP: Done WiFi Init"); + /* We will init server when we get IP */ +#endif WindowApp::Init(); // Initialize App Task @@ -308,18 +324,18 @@ void WindowAppImpl::UpdateLEDs() { mStatusLED.Blink(200, 200); } - else if (mState.isThreadProvisioned && mState.isThreadEnabled) - { - mStatusLED.Blink(950, 50); - } - else if (mState.haveBLEConnections) - { - mStatusLED.Blink(100, 100); - } else +#if CHIP_ENABLE_OPENTHREAD + if (mState.isThreadProvisioned && mState.isThreadEnabled) +#else + if (mState.isWiFiProvisioned && mState.isWiFiEnabled) +#endif + { - mStatusLED.Blink(50, 950); + mStatusLED.Blink(950, 50); } + else if (mState.haveBLEConnections) { mStatusLED.Blink(100, 100); } + else { mStatusLED.Blink(50, 950); } // Action LED @@ -346,7 +362,11 @@ void WindowAppImpl::UpdateLCD() { // Update LCD #ifdef DISPLAY_ENABLED +#if CHIP_ENABLE_OPENTHREAD if (mState.isThreadProvisioned) +#else + if (mState.isWiFiProvisioned) +#endif { Cover & cover = GetCover(); EmberAfWcType type = TypeGet(cover.mEndpoint); diff --git a/examples/window-app/efr32/src/main.cpp b/examples/window-app/efr32/src/main.cpp index b9d4e3070a4d01..2a8704b949dc9d 100644 --- a/examples/window-app/efr32/src/main.cpp +++ b/examples/window-app/efr32/src/main.cpp @@ -28,8 +28,8 @@ #include #include -#if CHIP_ENABLE_OPENTHREAD #include +#if CHIP_ENABLE_OPENTHREAD #include #include #include @@ -42,6 +42,10 @@ #include #endif // CHIP_ENABLE_OPENTHREAD +#if defined(RS911X_WIFI) || defined(WF200_WIFI) +#include "wfx_host_events.h" +#endif /* RS911X_WIFI */ + #if PW_RPC_ENABLED #include #endif @@ -50,6 +54,7 @@ #include "matter_shell.h" #endif +#define BLE_DEV_NAME "EFR32_WINDOW" using namespace ::chip::DeviceLayer; // ================================================================================ @@ -107,7 +112,7 @@ int main(void) EFR32_LOG("PlatformMgr().InitChipStack() failed"); appError(err); } - chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("EFR32_WINDOW"); + chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(BLE_DEV_NAME); EFR32_LOG("Starting Platform Manager Event Loop"); err = PlatformMgr().StartEventLoopTask(); @@ -144,6 +149,14 @@ int main(void) } #endif // CHIP_ENABLE_OPENTHREAD +#ifdef WF200_WIFI + // 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 ENABLE_CHIP_SHELL chip::startShellTask(); #endif diff --git a/scripts/examples/gn_efr32_example.sh b/scripts/examples/gn_efr32_example.sh index 1054dbaa184d49..ed0cc22502bfff 100755 --- a/scripts/examples/gn_efr32_example.sh +++ b/scripts/examples/gn_efr32_example.sh @@ -16,27 +16,86 @@ # limitations under the License. # -set -e - # Build script for GN EFT32 examples GitHub workflow. +set -e source "$(dirname "$0")/../../scripts/activate.sh" set -x env +USE_WF200=0 +USE_RS911X=0 +USE_WIFI=0 + +ROOT=$1 +arg2=$2 +shift +shift +while [ $# -gt 0 ]; do + case $1 in + --wifi) + if [ -z "$2" ]; then + echo "--efr requires BRDxxxx" + exit 1 + fi + if [ X"$2" = "Xrs911x" ]; then + WIFI_ARGS="use_rs911x=true" + elif [ "$2" = wf200 ]; then + WIFI_ARGS="use_wf200=true" + else + echo "Wifi usage: --wifi rs911x|wf200" + exit 1 + fi + shift + shift -if [ -z "$3" ]; then - gn gen --check --fail-on-unused-args --root="$1" --args="" "$2"/"$EFR32_BOARD"/ - ninja -v -C "$2"/"$EFR32_BOARD"/ - #print stats - arm-none-eabi-size -A "$2"/"$EFR32_BOARD"/*.out + ;; + --efr) + if [ -z "$2" ]; then + echo "--efr requires BRDxxxx" + exit 1 + fi + EFR32_BOARD=$2 + shift + shift + ;; + + --gnargs) + echo "-gnargs - Not yet implemented" + exit 1 + GNARGS=$2 + shift + shift + ;; + + *) + EFR32_BOARD=$1 + shift + if [ X"$1" != "X" ]; then + GNARGS=$1 + shift + fi + ;; + esac +done + +if [ X"$EFR32_BOARD" = "X" ]; then + echo "EFR32_BOARD not defined" + exit 1 +fi +BUILD_DIR=$arg2/$EFR32_BOARD +echo BUILD_DIR="$BUILD_DIR" +if [ "X$WIFI_ARGS" != "X" ]; then + gn gen --check --fail-on-unused-args --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="efr32_board=\"$EFR32_BOARD\" $WIFI_ARGS" "$BUILD_DIR" else - if [ -z "$4" ]; then - gn gen --check --fail-on-unused-args --root="$1" --args="efr32_board=\"$3\"" "$2/$3" + # thread build + # + if [ -z "$GNARGS" ]; then + gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR" else - gn gen --check --fail-on-unused-args --root="$1" --args="efr32_board=\"$3\"" "$2/$3" "$4" + gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $GNARGS" "$BUILD_DIR" fi - ninja -v -C "$2/$3" - #print stats - arm-none-eabi-size -A "$2"/"$3"/*.out fi +ninja -v -C "$BUILD_DIR"/ +#print stats +arm-none-eabi-size -A "$BUILD_DIR"/*.out diff --git a/src/lwip/efr32/lwipopts-rs911x.h b/src/lwip/efr32/lwipopts-rs911x.h new file mode 100644 index 00000000000000..9be70a784da48c --- /dev/null +++ b/src/lwip/efr32/lwipopts-rs911x.h @@ -0,0 +1,203 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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. + */ + +/** + * @file + * Compile-time configuration for LwIP on EFR32 platforms using the + * Silicon Labs EFR32 SDK. + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#if CHIP_HAVE_CONFIG_H +#include +#endif + +#include + +#define NO_SYS 0 +#define MEM_ALIGNMENT (4) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) +#define LWIP_TIMEVAL_PRIVATE (0) +#if 1 +#define MEM_LIBC_MALLOC (1) +#define mem_clib_free vPortFree +#define mem_clib_malloc pvPortMalloc +#else +#define MEM_LIBC_MALLOC (0) +#endif + +#define LWIP_COMPAT_MUTEX (0) +#define SYS_LIGHTWEIGHT_PROT (1) +#define LWIP_AUTOIP (0) +#define LWIP_DHCP_AUTOIP_COOP (0) +#define LWIP_SOCKET_SET_ERRNO 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#define MEMP_NUM_REASSDATA 0 +#define LWIP_SO_RCVTIMEO 0 +#define SO_REUSE (1) +#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) +#define LWIP_STATS (0) +#define LWIP_TCPIP_CORE_LOCKING 1 +#define TCP_QUEUE_OOSEQ 0 +#define ARP_QUEUEING (0) +#define TCPIP_THREAD_NAME "LWIP" + +#define LWIP_SOCKET 0 + +#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 + +#define LWIP_RAW 1 +#define MEMP_NUM_RAW_PCB (4) + +#define MEMP_NUM_UDP_PCB (7) + +#define LWIP_HAVE_LOOPIF (0) + +// TODO: not sure why this is disabled +#define LWIP_NETIF_LOOPBACK (0) + +#define MEMP_NUM_NETCONN (0) + +#ifndef LWIP_IPV4 +#define LWIP_IPV4 1 +#endif +#ifndef LWIP_IPV6 +#define LWIP_IPV6 1 +#endif +#ifndef LWIP_ARP +#define LWIP_ARP (1) +#endif +#define LWIP_DNS (0) +#ifndef LWIP_ICMP +#define LWIP_ICMP (1) +#endif +#ifndef LWIP_IGMP +#define LWIP_IGMP (1) +#endif +#ifndef LWIP_DHCP +#define LWIP_DHCP (1) +#endif +#define LWIP_IPV6_REASS (0) +#define LWIP_IPV6_DHCP6 0 +#define LWIP_IPV6_AUTOCONFIG (1) +#define LWIP_IPV6_ROUTER_SUPPORT 1 +#define LWIP_ND6_LISTEN_RA 1 + +#define LWIP_ND6_NUM_NEIGHBORS (2) +#define LWIP_ND6_NUM_DESTINATIONS (3) +#define LWIP_ND6_NUM_PREFIXES (2) +#define LWIP_ND6_NUM_ROUTERS (2) +#define LWIP_ND6_MAX_MULTICAST_SOLICIT (2) +#define LWIP_ND6_MAX_UNICAST_SOLICIT (2) +#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (3) +#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) +#define LWIP_ND6_ALLOW_RA_UPDATES 1 + +#if defined(EFR32MG21) +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (5) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#else +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (8) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#endif + +#define TCP_MSS (1152) +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_LISTEN_BACKLOG (1) + +#define ETH_PAD_SIZE (0) +#define SUB_ETHERNET_HEADER_SPACE (0) +#define PBUF_LINK_HLEN (14) + +#if defined(EFR32MG21) +#define TCPIP_THREAD_STACKSIZE (1536) +#else +#define TCPIP_THREAD_STACKSIZE (2048) +#endif + +#define TCPIP_THREAD_PRIO (2) + +#define NETIF_MAX_HWADDR_LEN 8U + +#define LWIP_IPV6_NUM_ADDRESSES 5 + +#ifndef LWIP_IPV6_ND +#define LWIP_IPV6_ND 1 +#endif +#define LWIP_ND6_QUEUEING 1 +#define LWIP_NUM_ND6_QUEUE 3 + +#define LWIP_MULTICAST_PING 0 + +#define TCPIP_MBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 + +#ifdef LWIP_DEBUG + +#define MEMP_OVERFLOW_CHECK (0) +#define MEMP_SANITY_CHECK (0) +#define MEM_DEBUG (LWIP_DBG_OFF) +#define MEMP_DEBUG (LWIP_DBG_OFF) +#define PBUF_DEBUG (LWIP_DBG_OFF) +#define API_LIB_DEBUG (LWIP_DBG_OFF) +#define API_MSG_DEBUG (LWIP_DBG_OFF) +#define TCPIP_DEBUG (LWIP_DBG_OFF) +#define NETIF_DEBUG (LWIP_DBG_OFF) +#define SOCKETS_DEBUG (LWIP_DBG_OFF) +#define DEMO_DEBUG (LWIP_DBG_OFF) +#define DHCP_DEBUG (LWIP_DBG_OFF) +#define AUTOIP_DEBUG (LWIP_DBG_OFF) +#define ETHARP_DEBUG (LWIP_DBG_OFF) +#define IP_DEBUG (LWIP_DBG_OFF) +#define IP_REASS_DEBUG (LWIP_DBG_OFF) +#define IP6_DEBUG (LWIP_DBG_OFF) +#define RAW_DEBUG (LWIP_DBG_OFF) +#define ICMP_DEBUG (LWIP_DBG_OFF) +#define UDP_DEBUG (LWIP_DBG_OFF) +#define TCP_DEBUG (LWIP_DBG_OFF) +#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_RTO_DEBUG (LWIP_DBG_OFF) +#define TCP_CWND_DEBUG (LWIP_DBG_OFF) +#define TCP_WND_DEBUG (LWIP_DBG_OFF) +#define TCP_FR_DEBUG (LWIP_DBG_OFF) +#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) +#define TCP_RST_DEBUG (LWIP_DBG_OFF) +#define PPP_DEBUG (LWIP_DBG_OFF) +#endif + +#define LWIP_DBG_TYPES_ON \ + (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/efr32/lwipopts-thread.h b/src/lwip/efr32/lwipopts-thread.h new file mode 100644 index 00000000000000..f667e5bb3a8f27 --- /dev/null +++ b/src/lwip/efr32/lwipopts-thread.h @@ -0,0 +1,182 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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. + */ + +/** + * @file + * Compile-time configuration for LwIP on EFR32 platforms using the + * Silicon Labs EFR32 SDK. + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#if CHIP_HAVE_CONFIG_H +#include +#endif + +#include + +#define NO_SYS 0 +#define MEM_ALIGNMENT (4) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) +#define LWIP_TIMEVAL_PRIVATE (0) +#define MEM_LIBC_MALLOC (0) +#define LWIP_COMPAT_MUTEX (0) +#define SYS_LIGHTWEIGHT_PROT (1) +#define LWIP_AUTOIP (0) +#define LWIP_DHCP_AUTOIP_COOP (0) +#define LWIP_SOCKET_SET_ERRNO 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#define MEMP_NUM_REASSDATA 0 +#define LWIP_SO_RCVTIMEO 0 +#define SO_REUSE (1) +#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) +#define LWIP_STATS (0) +#define LWIP_TCPIP_CORE_LOCKING 1 +#define TCP_QUEUE_OOSEQ 0 +#define ARP_QUEUEING (0) +#define TCPIP_THREAD_NAME "LWIP" + +#define LWIP_SOCKET 0 + +#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 + +#define LWIP_RAW 1 +#define MEMP_NUM_RAW_PCB (4) + +#define MEMP_NUM_UDP_PCB (5) + +#define LWIP_HAVE_LOOPIF (0) + +// TODO: not sure why this is disabled +#define LWIP_NETIF_LOOPBACK (0) + +#define MEMP_NUM_NETCONN (0) + +#define LWIP_IPV4 0 + +#define LWIP_IPV6 1 +#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 +#define LWIP_ARP (0) +#define LWIP_DNS (0) +#define LWIP_ICMP (0) +#define LWIP_IGMP (0) +#define LWIP_DHCP (0) +#define LWIP_IPV6_REASS (0) +#define LWIP_IPV6_DHCP6 0 +#define LWIP_IPV6_AUTOCONFIG (0) +#define LWIP_IPV6_ROUTER_SUPPORT 0 +#define LWIP_ND6_LISTEN_RA 0 + +#define LWIP_ND6_NUM_NEIGHBORS (0) +#define LWIP_ND6_NUM_DESTINATIONS (0) +#define LWIP_ND6_NUM_PREFIXES (0) +#define LWIP_ND6_NUM_ROUTERS (0) +#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) +#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) +#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0) +#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) + +#if defined(EFR32MG21) +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (5) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#else +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (8) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#endif + +#define TCP_MSS (1152) +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_LISTEN_BACKLOG (1) + +#define ETH_PAD_SIZE (0) +#define SUB_ETHERNET_HEADER_SPACE (0) +#define PBUF_LINK_HLEN (0) + +#if defined(EFR32MG21) +#define TCPIP_THREAD_STACKSIZE (1536) +#else +#define TCPIP_THREAD_STACKSIZE (2048) +#endif + +#define TCPIP_THREAD_PRIO (2) + +#define NETIF_MAX_HWADDR_LEN 8U + +#define LWIP_IPV6_NUM_ADDRESSES 5 + +#define LWIP_IPV6_ND 0 +#define LWIP_ND6_QUEUEING 0 + +#define LWIP_MULTICAST_PING 0 + +#define TCPIP_MBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 + +#ifdef LWIP_DEBUG + +#define MEMP_OVERFLOW_CHECK (0) +#define MEMP_SANITY_CHECK (0) +#define MEM_DEBUG (LWIP_DBG_OFF) +#define MEMP_DEBUG (LWIP_DBG_OFF) +#define PBUF_DEBUG (LWIP_DBG_OFF) +#define API_LIB_DEBUG (LWIP_DBG_OFF) +#define API_MSG_DEBUG (LWIP_DBG_OFF) +#define TCPIP_DEBUG (LWIP_DBG_OFF) +#define NETIF_DEBUG (LWIP_DBG_OFF) +#define SOCKETS_DEBUG (LWIP_DBG_OFF) +#define DEMO_DEBUG (LWIP_DBG_OFF) +#define DHCP_DEBUG (LWIP_DBG_OFF) +#define AUTOIP_DEBUG (LWIP_DBG_OFF) +#define ETHARP_DEBUG (LWIP_DBG_OFF) +#define IP_DEBUG (LWIP_DBG_OFF) +#define IP_REASS_DEBUG (LWIP_DBG_OFF) +#define IP6_DEBUG (LWIP_DBG_OFF) +#define RAW_DEBUG (LWIP_DBG_OFF) +#define ICMP_DEBUG (LWIP_DBG_OFF) +#define UDP_DEBUG (LWIP_DBG_OFF) +#define TCP_DEBUG (LWIP_DBG_OFF) +#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_RTO_DEBUG (LWIP_DBG_OFF) +#define TCP_CWND_DEBUG (LWIP_DBG_OFF) +#define TCP_WND_DEBUG (LWIP_DBG_OFF) +#define TCP_FR_DEBUG (LWIP_DBG_OFF) +#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) +#define TCP_RST_DEBUG (LWIP_DBG_OFF) +#define PPP_DEBUG (LWIP_DBG_OFF) +#endif + +#define LWIP_DBG_TYPES_ON \ + (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/efr32/lwipopts-wf200.h b/src/lwip/efr32/lwipopts-wf200.h new file mode 100644 index 00000000000000..31dbf793c3b8c9 --- /dev/null +++ b/src/lwip/efr32/lwipopts-wf200.h @@ -0,0 +1,203 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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. + */ + +/** + * @file + * Compile-time configuration for LwIP on EFR32 platforms using the + * Silicon Labs EFR32 SDK. + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#if CHIP_HAVE_CONFIG_H +#include +#endif + +#include + +#define NO_SYS 0 +#define MEM_ALIGNMENT (4) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) +#define LWIP_TIMEVAL_PRIVATE (0) +#if 1 +#define MEM_LIBC_MALLOC (1) +#define mem_clib_free vPortFree +#define mem_clib_malloc pvPortMalloc +#else +#define MEM_LIBC_MALLOC (0) +#endif + +#define LWIP_COMPAT_MUTEX (0) +#define SYS_LIGHTWEIGHT_PROT (1) +#define LWIP_AUTOIP (0) +#define LWIP_DHCP_AUTOIP_COOP (0) +#define LWIP_SOCKET_SET_ERRNO 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#define MEMP_NUM_REASSDATA 0 +#define LWIP_SO_RCVTIMEO 0 +#define SO_REUSE (1) +#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) +#define LWIP_STATS (0) +#define LWIP_TCPIP_CORE_LOCKING 1 +#define TCP_QUEUE_OOSEQ 0 +#define ARP_QUEUEING (0) +#define TCPIP_THREAD_NAME "LWIP" + +#define LWIP_SOCKET 0 + +#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 + +#define LWIP_RAW 1 +#define MEMP_NUM_RAW_PCB (4) + +#define MEMP_NUM_UDP_PCB (5) + +#define LWIP_HAVE_LOOPIF (0) + +// TODO: not sure why this is disabled +#define LWIP_NETIF_LOOPBACK (0) + +#define MEMP_NUM_NETCONN (0) + +#ifndef LWIP_IPV4 +#define LWIP_IPV4 0 +#endif +#ifndef LWIP_IPV6 +#define LWIP_IPV6 1 +#endif +#ifndef LWIP_ARP +#define LWIP_ARP (0) +#endif +#define LWIP_DNS (0) +#ifndef LWIP_ICMP +#define LWIP_ICMP (1) +#endif +#ifndef LWIP_IGMP +#define LWIP_IGMP (0) +#endif +#ifndef LWIP_DHCP +#define LWIP_DHCP (0) +#endif +#define LWIP_IPV6_REASS (0) +#define LWIP_IPV6_DHCP6 0 +#define LWIP_IPV6_AUTOCONFIG (1) +#define LWIP_IPV6_ROUTER_SUPPORT 1 +#define LWIP_ND6_LISTEN_RA 1 + +#define LWIP_ND6_NUM_NEIGHBORS (2) +#define LWIP_ND6_NUM_DESTINATIONS (3) +#define LWIP_ND6_NUM_PREFIXES (2) +#define LWIP_ND6_NUM_ROUTERS (2) +#define LWIP_ND6_MAX_MULTICAST_SOLICIT (2) +#define LWIP_ND6_MAX_UNICAST_SOLICIT (2) +#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (3) +#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) +#define LWIP_ND6_ALLOW_RA_UPDATES 1 + +#if defined(EFR32MG21) +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (5) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#else +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (8) +#define PBUF_POOL_BUFSIZE (1280) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#endif + +#define TCP_MSS (1152) +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_LISTEN_BACKLOG (1) + +#define ETH_PAD_SIZE (0) +#define SUB_ETHERNET_HEADER_SPACE (0) +#define PBUF_LINK_HLEN (14) + +#if defined(EFR32MG21) +#define TCPIP_THREAD_STACKSIZE (1536) +#else +#define TCPIP_THREAD_STACKSIZE (2048) +#endif + +#define TCPIP_THREAD_PRIO (2) + +#define NETIF_MAX_HWADDR_LEN 8U + +#define LWIP_IPV6_NUM_ADDRESSES 5 + +#ifndef LWIP_IPV6_ND +#define LWIP_IPV6_ND 0 +#endif +#define LWIP_ND6_QUEUEING 1 +#define LWIP_NUM_ND6_QUEUE 3 + +#define LWIP_MULTICAST_PING 0 + +#define TCPIP_MBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 + +#ifdef LWIP_DEBUG + +#define MEMP_OVERFLOW_CHECK (0) +#define MEMP_SANITY_CHECK (0) +#define MEM_DEBUG (LWIP_DBG_OFF) +#define MEMP_DEBUG (LWIP_DBG_OFF) +#define PBUF_DEBUG (LWIP_DBG_OFF) +#define API_LIB_DEBUG (LWIP_DBG_OFF) +#define API_MSG_DEBUG (LWIP_DBG_OFF) +#define TCPIP_DEBUG (LWIP_DBG_OFF) +#define NETIF_DEBUG (LWIP_DBG_OFF) +#define SOCKETS_DEBUG (LWIP_DBG_OFF) +#define DEMO_DEBUG (LWIP_DBG_OFF) +#define DHCP_DEBUG (LWIP_DBG_OFF) +#define AUTOIP_DEBUG (LWIP_DBG_OFF) +#define ETHARP_DEBUG (LWIP_DBG_OFF) +#define IP_DEBUG (LWIP_DBG_OFF) +#define IP_REASS_DEBUG (LWIP_DBG_OFF) +#define IP6_DEBUG (LWIP_DBG_OFF) +#define RAW_DEBUG (LWIP_DBG_OFF) +#define ICMP_DEBUG (LWIP_DBG_OFF) +#define UDP_DEBUG (LWIP_DBG_OFF) +#define TCP_DEBUG (LWIP_DBG_OFF) +#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_RTO_DEBUG (LWIP_DBG_OFF) +#define TCP_CWND_DEBUG (LWIP_DBG_OFF) +#define TCP_WND_DEBUG (LWIP_DBG_OFF) +#define TCP_FR_DEBUG (LWIP_DBG_OFF) +#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) +#define TCP_RST_DEBUG (LWIP_DBG_OFF) +#define PPP_DEBUG (LWIP_DBG_OFF) +#endif + +#define LWIP_DBG_TYPES_ON \ + (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/efr32/lwipopts.h b/src/lwip/efr32/lwipopts.h index f667e5bb3a8f27..499e11d4700c19 100644 --- a/src/lwip/efr32/lwipopts.h +++ b/src/lwip/efr32/lwipopts.h @@ -1,182 +1,7 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Nest Labs, Inc. - * - * 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. - */ - -/** - * @file - * Compile-time configuration for LwIP on EFR32 platforms using the - * Silicon Labs EFR32 SDK. - * - */ - -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ - -#if CHIP_HAVE_CONFIG_H -#include -#endif - -#include - -#define NO_SYS 0 -#define MEM_ALIGNMENT (4) -#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) -#define LWIP_TIMEVAL_PRIVATE (0) -#define MEM_LIBC_MALLOC (0) -#define LWIP_COMPAT_MUTEX (0) -#define SYS_LIGHTWEIGHT_PROT (1) -#define LWIP_AUTOIP (0) -#define LWIP_DHCP_AUTOIP_COOP (0) -#define LWIP_SOCKET_SET_ERRNO 0 -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 -#define MEMP_NUM_REASSDATA 0 -#define LWIP_SO_RCVTIMEO 0 -#define SO_REUSE (1) -#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) -#define LWIP_STATS (0) -#define LWIP_TCPIP_CORE_LOCKING 1 -#define TCP_QUEUE_OOSEQ 0 -#define ARP_QUEUEING (0) -#define TCPIP_THREAD_NAME "LWIP" - -#define LWIP_SOCKET 0 - -#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 - -#define LWIP_RAW 1 -#define MEMP_NUM_RAW_PCB (4) - -#define MEMP_NUM_UDP_PCB (5) - -#define LWIP_HAVE_LOOPIF (0) - -// TODO: not sure why this is disabled -#define LWIP_NETIF_LOOPBACK (0) - -#define MEMP_NUM_NETCONN (0) - -#define LWIP_IPV4 0 - -#define LWIP_IPV6 1 -#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 -#define LWIP_ARP (0) -#define LWIP_DNS (0) -#define LWIP_ICMP (0) -#define LWIP_IGMP (0) -#define LWIP_DHCP (0) -#define LWIP_IPV6_REASS (0) -#define LWIP_IPV6_DHCP6 0 -#define LWIP_IPV6_AUTOCONFIG (0) -#define LWIP_IPV6_ROUTER_SUPPORT 0 -#define LWIP_ND6_LISTEN_RA 0 - -#define LWIP_ND6_NUM_NEIGHBORS (0) -#define LWIP_ND6_NUM_DESTINATIONS (0) -#define LWIP_ND6_NUM_PREFIXES (0) -#define LWIP_ND6_NUM_ROUTERS (0) -#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) -#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) -#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0) -#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) - -#if defined(EFR32MG21) -#define MEMP_SEPARATE_POOLS (1) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) -#define MEMP_USE_CUSTOM_POOLS (0) -#define PBUF_POOL_SIZE (5) -#define PBUF_POOL_BUFSIZE (1280) -#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) -#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#else -#define MEMP_SEPARATE_POOLS (1) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) -#define MEMP_USE_CUSTOM_POOLS (0) -#define PBUF_POOL_SIZE (8) -#define PBUF_POOL_BUFSIZE (1280) -#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) -#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#endif - -#define TCP_MSS (1152) -#define TCP_SND_BUF (2 * TCP_MSS) -#define TCP_LISTEN_BACKLOG (1) - -#define ETH_PAD_SIZE (0) -#define SUB_ETHERNET_HEADER_SPACE (0) -#define PBUF_LINK_HLEN (0) - -#if defined(EFR32MG21) -#define TCPIP_THREAD_STACKSIZE (1536) +#if defined(WF200_WIFI) +#include "lwipopts-wf200.h" +#elif defined(RS911X_WIFI) +#include "lwipopts-rs911x.h" #else -#define TCPIP_THREAD_STACKSIZE (2048) -#endif - -#define TCPIP_THREAD_PRIO (2) - -#define NETIF_MAX_HWADDR_LEN 8U - -#define LWIP_IPV6_NUM_ADDRESSES 5 - -#define LWIP_IPV6_ND 0 -#define LWIP_ND6_QUEUEING 0 - -#define LWIP_MULTICAST_PING 0 - -#define TCPIP_MBOX_SIZE 6 -#define DEFAULT_RAW_RECVMBOX_SIZE 6 -#define DEFAULT_UDP_RECVMBOX_SIZE 6 -#define DEFAULT_TCP_RECVMBOX_SIZE 6 - -#ifdef LWIP_DEBUG - -#define MEMP_OVERFLOW_CHECK (0) -#define MEMP_SANITY_CHECK (0) -#define MEM_DEBUG (LWIP_DBG_OFF) -#define MEMP_DEBUG (LWIP_DBG_OFF) -#define PBUF_DEBUG (LWIP_DBG_OFF) -#define API_LIB_DEBUG (LWIP_DBG_OFF) -#define API_MSG_DEBUG (LWIP_DBG_OFF) -#define TCPIP_DEBUG (LWIP_DBG_OFF) -#define NETIF_DEBUG (LWIP_DBG_OFF) -#define SOCKETS_DEBUG (LWIP_DBG_OFF) -#define DEMO_DEBUG (LWIP_DBG_OFF) -#define DHCP_DEBUG (LWIP_DBG_OFF) -#define AUTOIP_DEBUG (LWIP_DBG_OFF) -#define ETHARP_DEBUG (LWIP_DBG_OFF) -#define IP_DEBUG (LWIP_DBG_OFF) -#define IP_REASS_DEBUG (LWIP_DBG_OFF) -#define IP6_DEBUG (LWIP_DBG_OFF) -#define RAW_DEBUG (LWIP_DBG_OFF) -#define ICMP_DEBUG (LWIP_DBG_OFF) -#define UDP_DEBUG (LWIP_DBG_OFF) -#define TCP_DEBUG (LWIP_DBG_OFF) -#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_RTO_DEBUG (LWIP_DBG_OFF) -#define TCP_CWND_DEBUG (LWIP_DBG_OFF) -#define TCP_WND_DEBUG (LWIP_DBG_OFF) -#define TCP_FR_DEBUG (LWIP_DBG_OFF) -#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) -#define TCP_RST_DEBUG (LWIP_DBG_OFF) -#define PPP_DEBUG (LWIP_DBG_OFF) +#include "lwipopts-thread.h" #endif - -#define LWIP_DBG_TYPES_ON \ - (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ - -#endif /* __LWIPOPTS_H__ */ diff --git a/src/platform/EFR32/BUILD.gn b/src/platform/EFR32/BUILD.gn index 5efbf9e4c733e7..00469606e03597 100644 --- a/src/platform/EFR32/BUILD.gn +++ b/src/platform/EFR32/BUILD.gn @@ -36,7 +36,6 @@ static_library("EFR32") { "CHIPPlatformConfig.h", "ConfigurationManagerImpl.cpp", "ConfigurationManagerImpl.h", - "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", @@ -87,6 +86,7 @@ static_library("EFR32") { sources += [ "../OpenThread/OpenThreadUtils.cpp", + "ConnectivityManagerImpl.cpp", "ThreadStackManagerImpl.cpp", "ThreadStackManagerImpl.h", ] @@ -95,5 +95,11 @@ static_library("EFR32") { sources += [ "../OpenThread/DnssdImpl.cpp" ] deps += [ "${chip_root}/src/lib/dnssd:platform_header" ] } + } else { + sources += [ + "ConnectivityManagerImpl_WIFI.cpp", + "ServiceProvisioning.cpp", + "ServiceProvisioning.h", + ] } } diff --git a/src/platform/EFR32/CHIPDevicePlatformConfig.h b/src/platform/EFR32/CHIPDevicePlatformConfig.h index 36ea40f8ebe700..74521d1da33f60 100644 --- a/src/platform/EFR32/CHIPDevicePlatformConfig.h +++ b/src/platform/EFR32/CHIPDevicePlatformConfig.h @@ -29,17 +29,18 @@ #define CHIP_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN 0xB00000 #define CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN 0xC00000 +#if defined(SL_WIFI) +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 +#elif CHIP_ENABLE_OPENTHREAD + #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 - -#if CHIP_ENABLE_OPENTHREAD #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 -#define CHIP_DEVICE_CONFIG_ENABLE_DNSSD 1 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 -#endif - #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_COMMISSIONABLE_DISCOVERY 1 +#define CHIP_DEVICE_CONFIG_ENABLE_DNSSD 1 +#endif /* CHIP_ENABLE_OPENTHREAD */ #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1 diff --git a/src/platform/EFR32/CHIPDevicePlatformEvent.h b/src/platform/EFR32/CHIPDevicePlatformEvent.h index d2ae1b7c65ff35..1252e16064dd89 100644 --- a/src/platform/EFR32/CHIPDevicePlatformEvent.h +++ b/src/platform/EFR32/CHIPDevicePlatformEvent.h @@ -25,6 +25,9 @@ #pragma once #include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#include "wfx_host_events.h" +#endif namespace chip { namespace DeviceLayer { @@ -44,7 +47,7 @@ enum PublicPlatformSpecificEventTypes */ enum InternalPlatformSpecificEventTypes { - /* None currently defined */ + kWFXSystemEvent = kRange_InternalPlatformSpecific, }; } // namespace DeviceEventType @@ -57,9 +60,39 @@ struct ChipDevicePlatformEvent final { union { - /* None currently defined */ +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + struct + { + wfx_event_base_t eventBase; + union + { + sl_wfx_generic_message_t genericMsgEvent; + sl_wfx_startup_ind_t startupEvent; + sl_wfx_connect_ind_t connectEvent; + sl_wfx_disconnect_ind_t disconnectEvent; + + /* + * NOT CURRENTLY USED + *Some structs might be bigger in size than the one we use + * so we reduce the union size by commenting them out. + * Keep for possible future implementation. + */ + + // sl_wfx_generic_ind_t genericEvent; + // sl_wfx_exception_ind_t exceptionEvent; + // sl_wfx_error_ind_t errorEvent; + // sl_wfx_received_ind_t receivedEvent; + // sl_wfx_scan_result_ind_t scanResultEvent; + // sl_wfx_scan_complete_ind_t scanCompleteEvent; + // sl_wfx_start_ap_ind_t startApEvent; + // sl_wfx_stop_ap_ind_t stopApEvent; + // sl_wfx_ap_client_connected_ind_t apClientConnectedEvent; + // sl_wfx_ap_client_rejected_ind_t apClientRejectedEvent; + // sl_wfx_ap_client_disconnected_ind_t apClientDisconnectedEvent; + } data; + } WFXSystemEvent; +#endif }; }; - -} // namespace DeviceLayer +}; // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index f550516e28b5a3..fccf7f6fd0f4de 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -32,6 +32,10 @@ #include "em_rmu.h" +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#include "wfx_host_events.h" +#endif + namespace chip { namespace DeviceLayer { @@ -291,10 +295,26 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) PersistedStorage::KeyValueStoreMgrImpl().ErasePartition(); #endif // CHIP_KVS_AVAILABLE +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + ChipLogProgress(DeviceLayer, "Clearing WiFi provision"); + wfx_clear_wifi_provision(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + // Restart the system. ChipLogProgress(DeviceLayer, "System restarting"); NVIC_SystemReset(); } +#ifdef SL_WIFI +CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) +{ + sl_wfx_mac_address_t macaddr; + wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr); + memcpy(buf, &macaddr.octet[0], sizeof(macaddr.octet)); + + return CHIP_NO_ERROR; +} +#endif + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/ConfigurationManagerImpl.h b/src/platform/EFR32/ConfigurationManagerImpl.h index a638abc425f5f0..7a157ccc3b7fac 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/platform/EFR32/ConfigurationManagerImpl.h @@ -77,10 +77,12 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp static void DoFactoryReset(intptr_t arg); }; +#ifndef SL_WIFI inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } +#endif /* SL_WIFI */ } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/ConnectivityManagerImpl.h b/src/platform/EFR32/ConnectivityManagerImpl.h index 02e1c11c8c7cb9..7e817ad4da743c 100644 --- a/src/platform/EFR32/ConnectivityManagerImpl.h +++ b/src/platform/EFR32/ConnectivityManagerImpl.h @@ -30,7 +30,11 @@ #else #include #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#include +#else #include +#endif namespace Inet { class IPAddress; @@ -39,6 +43,8 @@ class IPAddress; namespace chip { namespace DeviceLayer { +class PlatformManagerImpl; + /** * Concrete implementation of the ConnectivityManager singleton object for Silicon Labs EFR32 platforms. */ @@ -54,7 +60,11 @@ class ConnectivityManagerImpl final : public ConnectivityManager, #else public Internal::GenericConnectivityManagerImpl_NoThread, #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + public Internal::GenericConnectivityManagerImpl_WiFi +#else public Internal::GenericConnectivityManagerImpl_NoWiFi +#endif { // Allow the ConnectivityManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -63,18 +73,103 @@ class ConnectivityManagerImpl final : public ConnectivityManager, private: // ===== Members that implement the ConnectivityManager abstract interface. + bool _HaveIPv4InternetConnectivity(void); + bool _HaveIPv6InternetConnectivity(void); +#if 0 // CHIP_DEVICE_CONFIG_ENABLE_THREAD + bool _HaveServiceConnectivity(void); +#endif CHIP_ERROR _Init(void); void _OnPlatformEvent(const ChipDeviceEvent * event); +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + using Flags = GenericConnectivityManagerImpl_WiFi::ConnectivityFlags; + WiFiStationMode _GetWiFiStationMode(void); + CHIP_ERROR _SetWiFiStationMode(WiFiStationMode val); + bool _IsWiFiStationEnabled(void); + bool _IsWiFiStationApplicationControlled(void); + bool _IsWiFiStationConnected(void); + System::Clock::Timeout _GetWiFiStationReconnectInterval(void); + CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); + bool _IsWiFiStationProvisioned(void); + void _ClearWiFiStationProvision(void); + CHIP_ERROR _GetAndLogWifiStatsCounters(void); + bool _CanStartWiFiScan(); + void _OnWiFiScanDone(); + void _OnWiFiStationProvisionChange(); +#endif // ===== Members for internal use by the following friends. friend ConnectivityManager & ConnectivityMgr(void); friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); static ConnectivityManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + System::Clock::Timestamp mLastStationConnectFailTime; + WiFiStationMode mWiFiStationMode; + WiFiStationState mWiFiStationState; + System::Clock::Timeout mWiFiStationReconnectInterval; + BitFlags mFlags; + + void DriveStationState(void); + void OnStationConnected(void); + void OnStationDisconnected(void); + void ChangeWiFiStationState(WiFiStationState newState); + static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState); + + void UpdateInternetConnectivityState(void); +#endif }; +inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + return mFlags.Has(Flags::kHaveIPv4InternetConnectivity); +#else + return false; +#endif +} + +inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + return mFlags.Has(Flags::kHaveIPv6InternetConnectivity); +#else + return false; +#endif +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +inline bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled(void) +{ + return mWiFiStationMode == kWiFiStationMode_ApplicationControlled; +} + +inline bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) +{ + return mWiFiStationState == kWiFiStationState_Connected; +} + +inline System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiStationReconnectInterval(void) +{ + return mWiFiStationReconnectInterval; +} + +inline bool ConnectivityManagerImpl::_CanStartWiFiScan() +{ + return mWiFiStationState != kWiFiStationState_Connecting; +} +#endif +#if 0 // CHIP_DEVICE_CONFIG_ENABLE_THREAD +inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) +{ + return _HaveServiceConnectivityViaThread(); +} +#endif + /** + * * Returns the public interface of the ConnectivityManager singleton object. * * Chip applications should use this to access features of the ConnectivityManager object diff --git a/src/platform/EFR32/ConnectivityManagerImpl_WIFI.cpp b/src/platform/EFR32/ConnectivityManagerImpl_WIFI.cpp new file mode 100644 index 00000000000000..bbae58753acf5b --- /dev/null +++ b/src/platform/EFR32/ConnectivityManagerImpl_WIFI.cpp @@ -0,0 +1,485 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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 behaves like a config.h, comes first */ +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#endif + +#include "wfx_host_events.h" + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::System; +using namespace ::chip::TLV; +using namespace ::chip::DeviceLayer::Internal; + +namespace chip { +namespace DeviceLayer { + +ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; + +CHIP_ERROR ConnectivityManagerImpl::_Init() +{ + CHIP_ERROR err; + // Queue work items to bootstrap the AP and station state machines once the Chip event loop is running. + mWiFiStationMode = kWiFiStationMode_Disabled; + mWiFiStationState = kWiFiStationState_NotConnected; + mLastStationConnectFailTime = System::Clock::kZero; + mWiFiStationReconnectInterval = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL); + mFlags.ClearAll(); + + // TODO Initialize the Chip Addressing and Routing Module. + + // Ensure that station mode is enabled. + wfx_enable_sta_mode(); + + err = DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); + + SuccessOrExit(err); + +exit: + return err; +} + +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) +{ + // Forward the event to the generic base classes as needed. + // Handle Wfx wifi events... + if (event->Type == DeviceEventType::kWFXSystemEvent) + { + if (event->Platform.WFXSystemEvent.eventBase == WIFI_EVENT) + { + switch (event->Platform.WFXSystemEvent.data.genericMsgEvent.header.id) + { + case SL_WFX_STARTUP_IND_ID: + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_START"); + DriveStationState(); + break; + case SL_WFX_CONNECT_IND_ID: + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_CONNECTED"); + if (mWiFiStationState == kWiFiStationState_Connecting) + { + if (event->Platform.WFXSystemEvent.data.connectEvent.body.status == 0) + { + ChangeWiFiStationState(kWiFiStationState_Connecting_Succeeded); + } + else + { + ChangeWiFiStationState(kWiFiStationState_Connecting_Failed); + } + } + DriveStationState(); + break; + case SL_WFX_DISCONNECT_IND_ID: + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_DISCONNECTED"); + if (mWiFiStationState == kWiFiStationState_Connecting) + { + ChangeWiFiStationState(kWiFiStationState_Connecting_Failed); + } + DriveStationState(); + break; + default: + break; + } + } + else if (event->Platform.WFXSystemEvent.eventBase == IP_EVENT) + { + switch (event->Platform.WFXSystemEvent.data.genericMsgEvent.header.id) + { + case IP_EVENT_STA_GOT_IP: + ChipLogProgress(DeviceLayer, "IP_EVENT_STA_GOT_IP"); + UpdateInternetConnectivityState(); + break; + case IP_EVENT_STA_LOST_IP: + ChipLogProgress(DeviceLayer, "IP_EVENT_STA_LOST_IP"); + UpdateInternetConnectivityState(); + break; + case IP_EVENT_GOT_IP6: + ChipLogProgress(DeviceLayer, "IP_EVENT_GOT_IP6"); + UpdateInternetConnectivityState(); + break; + default: + break; + } + } + } +} +ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void) +{ + if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) + { + wifi_mode_t curWiFiMode = wfx_get_wifi_mode(); + if ((curWiFiMode == WIFI_MODE_STA) || (curWiFiMode == WIFI_MODE_APSTA)) + { + mWiFiStationMode = kWiFiStationMode_Enabled; + } + else + { + mWiFiStationMode = kWiFiStationMode_Disabled; + } + } + return mWiFiStationMode; +} + +bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) +{ + char ssid[65]; + size_t len = 0; + + /* See if we have SSID in our Keys */ + if ((Internal::EFR32Config::ReadConfigValueStr(Internal::EFR32Config::kConfigKey_WiFiSSID, ssid, sizeof(ssid) - 1, len) == + CHIP_NO_ERROR) && + (ssid[0] != 0)) + { + return true; + } + + return false; +} + +bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) +{ + return wfx_is_sta_mode_enabled(); +} +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val) +{ + DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); + + if (mWiFiStationMode != val) + { + ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode), + WiFiStationModeToStr(val)); + } + + mWiFiStationMode = val; + + return CHIP_NO_ERROR; +} +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationReconnectInterval(System::Clock::Timeout val) +{ + mWiFiStationReconnectInterval = val; + return CHIP_NO_ERROR; +} +void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) +{ + if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) + { + wfx_clear_wifi_provision(); + + DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); + } +} + +CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWifiStatsCounters(void) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void ConnectivityManagerImpl::_OnWiFiScanDone() +{ + // CHIP_ERROR_NOT_IMPLEMENTED +} + +void ConnectivityManagerImpl::_OnWiFiStationProvisionChange() +{ + // Schedule a call to the DriveStationState method to adjust the station state as needed. + ChipLogProgress(DeviceLayer, "_ON WIFI PROVISION CHANGE"); + DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); +} + +// == == == == == == == == == == ConnectivityManager Private Methods == == == == == == == == == == + +void ConnectivityManagerImpl::DriveStationState() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + sl_status_t serr; + bool stationConnected; + + // Refresh the current station mode. + GetWiFiStationMode(); + + // If the station interface is NOT under application control... + if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) + { + // Ensure that the WFX is started. + if ((serr = wfx_wifi_start()) != SL_STATUS_OK) + { + ChipLogError(DeviceLayer, "WFX_wifi_start: FAIL: %s", chip::ErrorStr(err)); + return; + } + // Ensure that station mode is enabled in the WFX WiFi layer. + wfx_enable_sta_mode(); + } + + stationConnected = wfx_is_sta_connected(); + + // If the station interface is currently connected ... + if (stationConnected) + { + // Advance the station state to Connected if it was previously NotConnected or + // a previously initiated connect attempt succeeded. + if (mWiFiStationState == kWiFiStationState_NotConnected || mWiFiStationState == kWiFiStationState_Connecting_Succeeded) + { + ChangeWiFiStationState(kWiFiStationState_Connected); + ChipLogProgress(DeviceLayer, "WiFi station interface connected"); + mLastStationConnectFailTime = System::Clock::kZero; + OnStationConnected(); + } + + // If the WiFi station interface is no longer enabled, or no longer provisioned, + // disconnect the station from the AP, unless the WiFi station mode is currently + // under application control. + if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled && + (mWiFiStationMode != kWiFiStationMode_Enabled || !IsWiFiStationProvisioned())) + { + ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface"); + serr = wfx_sta_discon(); + if (serr != SL_STATUS_OK) + { + ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %s", chip::ErrorStr(err)); + } + SuccessOrExit(serr); + + ChangeWiFiStationState(kWiFiStationState_Disconnecting); + } + } + // Otherwise the station interface is NOT connected to an AP, so... + else + { + System::Clock::Timestamp now = System::SystemClock().GetMonotonicTimestamp(); + + // Advance the station state to NotConnected if it was previously Connected or Disconnecting, + // or if a previous initiated connect attempt failed. + if (mWiFiStationState == kWiFiStationState_Connected || mWiFiStationState == kWiFiStationState_Disconnecting || + mWiFiStationState == kWiFiStationState_Connecting_Failed) + { + WiFiStationState prevState = mWiFiStationState; + ChangeWiFiStationState(kWiFiStationState_NotConnected); + if (prevState != kWiFiStationState_Connecting_Failed) + { + ChipLogProgress(DeviceLayer, "WiFi station interface disconnected"); + mLastStationConnectFailTime = System::Clock::kZero; + OnStationDisconnected(); + } + else + { + mLastStationConnectFailTime = now; + } + } + + // If the WiFi station interface is now enabled and provisioned (and by implication, + // not presently under application control), AND the system is not in the process of + // scanning, then... + if (mWiFiStationMode == kWiFiStationMode_Enabled && IsWiFiStationProvisioned()) + { + // Initiate a connection to the AP if we haven't done so before, or if enough + // time has passed since the last attempt. + if (mLastStationConnectFailTime == System::Clock::kZero || + now >= mLastStationConnectFailTime + mWiFiStationReconnectInterval) + { + if (mWiFiStationState != kWiFiStationState_Connecting) + { + wfx_wifi_provision_t wcfg; + size_t sz; + + (void) Internal::EFR32Config::ReadConfigValueStr(Internal::EFR32Config::kConfigKey_WiFiSSID, wcfg.ssid, + sizeof(wcfg.ssid), sz); + (void) Internal::EFR32Config::ReadConfigValueStr(Internal::EFR32Config::kConfigKey_WiFiPSK, wcfg.passkey, + sizeof(wcfg.passkey), sz); + (void) Internal::EFR32Config::ReadConfigValueBin(Internal::EFR32Config::kConfigKey_WiFiSEC, &wcfg.security, + sizeof(wcfg.security), sz); + wfx_set_wifi_provision(&wcfg); + + ChipLogProgress(DeviceLayer, "Attempting to connect WiFi (%s)", wcfg.ssid); + if ((serr = wfx_connect_to_ap()) != SL_STATUS_OK) + { + ChipLogError(DeviceLayer, "wfx_connect_to_ap failed"); + } + SuccessOrExit(serr); + + ChangeWiFiStationState(kWiFiStationState_Connecting); + } + } + + // Otherwise arrange another connection attempt at a suitable point in the future. + else + { + System::Clock::Timestamp timeToNextConnect = (mLastStationConnectFailTime + mWiFiStationReconnectInterval) - now; + + ChipLogProgress(DeviceLayer, "Next WiFi station reconnect in %" PRIu32 " ms", + System::Clock::Milliseconds32(timeToNextConnect).count()); + + ReturnOnFailure(DeviceLayer::SystemLayer().StartTimer(timeToNextConnect, DriveStationState, NULL)); + } + } + } + +exit: + + ChipLogProgress(DeviceLayer, "Done driving station state, nothing else to do..."); + // Kick-off any pending network scan that might have been deferred due to the activity + // of the WiFi station. +} + +void ConnectivityManagerImpl::OnStationConnected() +{ + ChipDeviceEvent event; + + wfx_setup_ip6_link_local(SL_WFX_STA_INTERFACE); + + // Alert other components of the new state. + event.Type = DeviceEventType::kWiFiConnectivityChange; + event.WiFiConnectivityChange.Result = kConnectivity_Established; + (void) PlatformMgr().PostEvent(&event); + + UpdateInternetConnectivityState(); +} + +void ConnectivityManagerImpl::OnStationDisconnected() +{ + // TODO Invoke WARM to perform actions that occur when the WiFi station interface goes down. + + // Alert other components of the new state. + ChipDeviceEvent event; + event.Type = DeviceEventType::kWiFiConnectivityChange; + event.WiFiConnectivityChange.Result = kConnectivity_Lost; + (void) PlatformMgr().PostEvent(&event); + + UpdateInternetConnectivityState(); +} +void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, void * aAppState) +{ + sInstance.DriveStationState(); +} + +void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState) +{ + if (mWiFiStationState != newState) + { + ChipLogProgress(DeviceLayer, "WiFi station state change: %s -> %s", WiFiStationStateToStr(mWiFiStationState), + WiFiStationStateToStr(newState)); + mWiFiStationState = newState; + } +} + +void ConnectivityManagerImpl::UpdateInternetConnectivityState(void) +{ + bool haveIPv4Conn = false; + bool haveIPv6Conn = false; + bool hadIPv4Conn = mFlags.Has(ConnectivityFlags::kHaveIPv4InternetConnectivity); + bool hadIPv6Conn = mFlags.Has(ConnectivityFlags::kHaveIPv6InternetConnectivity); + IPAddress addr; + + // If the WiFi station is currently in the connected state... + if (mWiFiStationState == kWiFiStationState_Connected) + { +#if 1 //! defined (SL_WF200) || (SL_WF200 == 0) + + haveIPv4Conn = wfx_have_ipv4_addr(SL_WFX_STA_INTERFACE); + /* TODO - haveIPv6Conn */ +#else /* Old code that needed LWIP and its internals */ + // Get the LwIP netif for the WiFi station interface. + struct netif * netif = Internal::WFXUtils::GetStationNetif(); + + // If the WiFi station interface is up... + if (netif != NULL && netif_is_up(netif) && netif_is_link_up(netif)) + { + // // Check if a DNS server is currently configured. If so... + // TODO + // ip_addr_t dnsServerAddr = *dns_getserver(0); + // if (!ip_addr_isany_val(dnsServerAddr)) + if (1) + { + // If the station interface has been assigned an IPv4 address, and has + // an IPv4 gateway, then presume that the device has IPv4 Internet + // connectivity. + if (!ip4_addr_isany_val(*netif_ip4_addr(netif)) && !ip4_addr_isany_val(*netif_ip4_gw(netif))) + { + haveIPv4Conn = true; + char addrStr[INET_ADDRSTRLEN]; + // TODO: change the code to using IPv6 address + sprintf(addrStr, "%d.%d.%d.%d", (int) (netif->ip_addr.u_addr.ip4.addr & 0xff), + (int) ((netif->ip_addr.u_addr.ip4.addr >> 8) & 0xff), + (int) ((netif->ip_addr.u_addr.ip4.addr >> 16) & 0xff), + (int) ((netif->ip_addr.u_addr.ip4.addr >> 24) & 0xff)); + IPAddress::FromString(addrStr, addr); + } + + // TODO + // Search among the IPv6 addresses assigned to the interface for a Global Unicast + // address (2000::/3) that is in the valid state. If such an address is found... + // for (uint8_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) + // { + // if (ip6_addr_isglobal(netif_ip6_addr(netif, i)) && ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) + // { + // // Determine if there is a default IPv6 router that is currently reachable + // // via the station interface. If so, presume for now that the device has + // // IPv6 connectivity. + // struct netif * found_if = nd6_find_route(IP6_ADDR_ANY6); + // if (found_if && netif->num == found_if->num) + // { + // haveIPv6Conn = true; + // } + // } + // } + } + } +#endif /* OLD-Code */ + } + + // If the internet connectivity state has changed... + if (haveIPv4Conn != hadIPv4Conn || haveIPv6Conn != hadIPv6Conn) + { + // Update the current state. + mFlags.Set(ConnectivityFlags::kHaveIPv4InternetConnectivity, haveIPv4Conn) + .Set(ConnectivityFlags::kHaveIPv6InternetConnectivity, haveIPv6Conn); + + // Alert other components of the state change. + ChipDeviceEvent event; + event.Type = DeviceEventType::kInternetConnectivityChange; + event.InternetConnectivityChange.IPv4 = GetConnectivityChange(hadIPv4Conn, haveIPv4Conn); + event.InternetConnectivityChange.IPv6 = GetConnectivityChange(hadIPv6Conn, haveIPv6Conn); + addr.ToString(event.InternetConnectivityChange.address, sizeof(event.InternetConnectivityChange.address)); + (void) PlatformMgr().PostEvent(&event); + + if (haveIPv4Conn != hadIPv4Conn) + { + ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv4", (haveIPv4Conn) ? "ESTABLISHED" : "LOST"); + } + + if (haveIPv6Conn != hadIPv6Conn) + { + ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv6", (haveIPv6Conn) ? "ESTABLISHED" : "LOST"); + } + } +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp index 0f87641906c80b..f01887563d3cdd 100644 --- a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp +++ b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp @@ -16,6 +16,9 @@ */ #include "DeviceNetworkProvisioningDelegateImpl.h" +#include "ServiceProvisioning.h" +#include +#include #if CHIP_ENABLE_OPENTHREAD #include @@ -40,5 +43,21 @@ DeviceNetworkProvisioningDelegateImpl::_ProvisionThreadNetwork(ByteSpan threadDa #endif // CHIP_ENABLE_OPENTHREAD } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionWiFiNetwork(const char * ssid, const char * key) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + ChipLogProgress(NetworkProvisioning, "EFR Wifi provision: SSID: %s", ssid); + err = SetWiFiStationProvisioning(ssid, key); + if (err != CHIP_NO_ERROR) + { + ChipLogError(NetworkProvisioning, "ERR:WiFi:Provision network: %s", chip::ErrorStr(err)); + } + + return err; +} +#endif + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.h index e799358e4b7536..6eb53530c0c8d1 100644 --- a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.h +++ b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.h @@ -35,7 +35,11 @@ class DeviceNetworkProvisioningDelegateImpl final friend class GenericDeviceNetworkProvisioningDelegateImpl; private: +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd); +#else CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd) { return CHIP_ERROR_NOT_IMPLEMENTED; } +#endif CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData); }; diff --git a/src/platform/EFR32/DiagnosticDataProviderImpl.cpp b/src/platform/EFR32/DiagnosticDataProviderImpl.cpp index e04a34057f8f4b..7c838ecb8633e7 100644 --- a/src/platform/EFR32/DiagnosticDataProviderImpl.cpp +++ b/src/platform/EFR32/DiagnosticDataProviderImpl.cpp @@ -25,8 +25,9 @@ #include #include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include - +#endif #include #include "AppConfig.h" @@ -180,13 +181,16 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** { NetworkInterface * ifp = new NetworkInterface(); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance()); ifp->name = Span(threadNetworkName, strlen(threadNetworkName)); ifp->fabricConnected = true; ifp->offPremiseServicesReachableIPv4 = false; ifp->offPremiseServicesReachableIPv6 = false; ifp->type = InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; - +#else + /* TODO */ +#endif uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; ConfigurationMgr().GetPrimary802154MACAddress(macBuffer); ifp->hardwareAddress = ByteSpan(macBuffer, ConfigurationManager::kPrimaryMACAddressLength); diff --git a/src/platform/EFR32/EFR32Config.h b/src/platform/EFR32/EFR32Config.h index 295c6f8e08af1d..ea66ef9cf92df5 100644 --- a/src/platform/EFR32/EFR32Config.h +++ b/src/platform/EFR32/EFR32Config.h @@ -95,8 +95,11 @@ class EFR32Config static constexpr Key kConfigKey_CountryCode = EFR32ConfigKey(kChipConfig_KeyBase, 0x0A); static constexpr Key kConfigKey_Breadcrumb = EFR32ConfigKey(kChipConfig_KeyBase, 0x0B); static constexpr Key kConfigKey_ActiveLocale = EFR32ConfigKey(kChipConfig_KeyBase, 0x0C); - static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); - static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. + static constexpr Key kConfigKey_WiFiSSID = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); + static constexpr Key kConfigKey_WiFiPSK = EFR32ConfigKey(kChipConfig_KeyBase, 0x0E); + static constexpr Key kConfigKey_WiFiSEC = EFR32ConfigKey(kChipConfig_KeyBase, 0x0F); + static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x10); + static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kChipConfig_KeyBase, 0x1F); // Allows 16 Group Keys to be created. // CHIP Counter Keys static constexpr Key kConfigKey_BootCount = EFR32ConfigKey(kChipCounter_KeyBase, 0x00); diff --git a/src/platform/EFR32/InetPlatformConfig.h b/src/platform/EFR32/InetPlatformConfig.h index 87527cf1789e3e..3e8bb9a2f6d229 100644 --- a/src/platform/EFR32/InetPlatformConfig.h +++ b/src/platform/EFR32/InetPlatformConfig.h @@ -25,10 +25,21 @@ #pragma once +#include + // ==================== Platform Adaptations ==================== +#define INET_CONFIG_ERROR_TYPE int32_t +#define INET_CONFIG_NO_ERROR 0 +#define INET_CONFIG_ERROR_MIN 1000000 +#define INET_CONFIG_ERROR_MAX 1000999 + #ifndef INET_CONFIG_ENABLE_IPV4 -#error Inet IPv4 configuration should be configured at build generation time +#ifdef SL_WIFI +#define INET_CONFIG_ENABLE_IPV4 1 +#else /* For Thread only devices */ +#define INET_CONFIG_ENABLE_IPV4 0 +#endif #endif // ========== Platform-specific Configuration Overrides ========= @@ -38,5 +49,5 @@ #endif // INET_CONFIG_NUM_TCP_ENDPOINTS #ifndef INET_CONFIG_NUM_UDP_ENDPOINTS -#define INET_CONFIG_NUM_UDP_ENDPOINTS 4 +#define INET_CONFIG_NUM_UDP_ENDPOINTS 6 #endif // INET_CONFIG_NUM_UDP_ENDPOINTS diff --git a/src/platform/EFR32/PlatformManagerImpl.cpp b/src/platform/EFR32/PlatformManagerImpl.cpp index 790bf23da7ecca..14947f894681a4 100644 --- a/src/platform/EFR32/PlatformManagerImpl.cpp +++ b/src/platform/EFR32/PlatformManagerImpl.cpp @@ -84,6 +84,74 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() return Internal::GenericPlatformManagerImpl_FreeRTOS::_Shutdown(); } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +void PlatformManagerImpl::HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData) +{ + ChipDeviceEvent event; + memset(&event, 0, sizeof(event)); + event.Type = DeviceEventType::kWFXSystemEvent; + event.Platform.WFXSystemEvent.eventBase = eventBase; + + if (eventBase == WIFI_EVENT) + { + switch (eventData->header.id) + { + case SL_WFX_STARTUP_IND_ID: + memcpy(&event.Platform.WFXSystemEvent.data.startupEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.startupEvent)); + break; + case SL_WFX_CONNECT_IND_ID: + memcpy(&event.Platform.WFXSystemEvent.data.connectEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.connectEvent)); + break; + case SL_WFX_DISCONNECT_IND_ID: + memcpy(&event.Platform.WFXSystemEvent.data.disconnectEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.disconnectEvent)); + break; + // case SL_WFX_RECEIVED_IND_ID: + // memcpy(&event.Platform.WFXSystemEvent.data.receivedEvent, eventData, + // sizeof(event.Platform.WFXSystemEvent.data.receivedEvent)); + // break; + // case SL_WFX_GENERIC_IND_ID: + // memcpy(&event.Platform.WFXSystemEvent.data.genericEvent, eventData, + // sizeof(event.Platform.WFXSystemEvent.data.genericEvent)); + // break; + // case SL_WFX_EXCEPTION_IND_ID: + // memcpy(&event.Platform.WFXSystemEvent.data.exceptionEvent, eventData, + // sizeof(event.Platform.WFXSystemEvent.data.exceptionEvent)); + // break; + // case SL_WFX_ERROR_IND_ID: + // memcpy(&event.Platform.WFXSystemEvent.data.errorEvent, eventData, + // sizeof(event.Platform.WFXSystemEvent.data.errorEvent)); + // break; + default: + break; + } + } + else if (eventBase == IP_EVENT) + { + switch (eventData->header.id) + { + case IP_EVENT_STA_GOT_IP: + memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); + break; + case IP_EVENT_GOT_IP6: + memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); + break; + case IP_EVENT_STA_LOST_IP: + memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); + break; + default: + break; + } + } + + (void) sInstance.PostEvent(&event); +} +#endif } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/PlatformManagerImpl.h b/src/platform/EFR32/PlatformManagerImpl.h index 63a3df6fc03eb8..975fd6ab3463e0 100644 --- a/src/platform/EFR32/PlatformManagerImpl.h +++ b/src/platform/EFR32/PlatformManagerImpl.h @@ -25,6 +25,9 @@ #pragma once #include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#include "wfx_host_events.h" +#endif namespace chip { namespace DeviceLayer { @@ -46,6 +49,9 @@ 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/EFR32/ServiceProvisioning.cpp b/src/platform/EFR32/ServiceProvisioning.cpp new file mode 100644 index 00000000000000..494c03b7ec2a61 --- /dev/null +++ b/src/platform/EFR32/ServiceProvisioning.cpp @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2020 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 "wfx_host_events.h" +#include + +#include "ServiceProvisioning.h" + +using namespace ::chip::DeviceLayer; + +CHIP_ERROR SetWiFiStationProvisioning(const char * ssid, const char * key) +{ + ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled); + + CHIP_ERROR err = CHIP_NO_ERROR; + wfx_wifi_provision_t wifiConfig; + + // Set the wifi configuration + memset(&wifiConfig, 0, sizeof(wifiConfig)); + memcpy(wifiConfig.ssid, ssid, std::min(strlen(ssid) + 1, sizeof(wifiConfig.ssid))); + memcpy(wifiConfig.passkey, key, std::min(strlen(key) + 1, sizeof(wifiConfig.passkey))); + wifiConfig.security = WFX_SEC_WPA2; /* Need something better ? Scan? */ + + // Configure the WFX WiFi interface. + wfx_set_wifi_provision(&wifiConfig); + /* Save into internal Keys */ + (void) Internal::EFR32Config::WriteConfigValueStr(Internal::EFR32Config::kConfigKey_WiFiSSID, (char *) ssid); + (void) Internal::EFR32Config::WriteConfigValueStr(Internal::EFR32Config::kConfigKey_WiFiPSK, key); + (void) Internal::EFR32Config::WriteConfigValueBin(Internal::EFR32Config::kConfigKey_WiFiSEC, &wifiConfig.security, + sizeof(wifiConfig.security)); + + ChipLogProgress(DeviceLayer, "SP WiFi STA provision set (SSID: %s)", wifiConfig.ssid); + + ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled); + ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled); + + return err; +} diff --git a/src/platform/EFR32/ServiceProvisioning.h b/src/platform/EFR32/ServiceProvisioning.h new file mode 100644 index 00000000000000..109ec4ae33ea6c --- /dev/null +++ b/src/platform/EFR32/ServiceProvisioning.h @@ -0,0 +1,25 @@ +/* + * + * Copyright (c) 2020 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 _SERVICE_PROVISIONING_H +#define _SERVICE_PROVISIONING_H + +#include + +CHIP_ERROR SetWiFiStationProvisioning(const char * ssid, const char * key); + +#endif // _SERVICE_PROVISIONING_H diff --git a/src/platform/EFR32/wifi_args.gni b/src/platform/EFR32/wifi_args.gni new file mode 100644 index 00000000000000..fc6660bc825d73 --- /dev/null +++ b/src/platform/EFR32/wifi_args.gni @@ -0,0 +1,46 @@ +# Copyright (c) 2021 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("//build_overrides/pigweed.gni") + +import("${chip_root}/examples/platform/efr32/args.gni") + +# ARM architecture flags will be set based on efr32_family. +arm_platform_config = "${efr32_sdk_build_root}/efr32_arm.gni" + +mbedtls_target = "${efr32_sdk_build_root}:efr32_sdk" + +#lwip_platform = "external" +lwip_platform = "efr32" +lwip_ipv6 = true +lwip_ipv4 = true +lwip_api = true +lwip_ethernet = true + +chip_device_platform = "efr32" +chip_enable_openthread = false +chip_inet_config_enable_ipv4 = true +chip_inet_config_enable_dns_resolver = false + +chip_build_tests = false +chip_config_memory_management = "platform" +chip_mdns = "minimal" +chip_enable_pw_rpc = false + +pw_build_LINK_DEPS = [ + "$dir_pw_assert:impl", + "$dir_pw_log:impl", +] diff --git a/third_party/efr32_sdk/efr32_sdk.gni b/third_party/efr32_sdk/efr32_sdk.gni index 82191ec80ca1e1..0bd7a6faf8bd9d 100644 --- a/third_party/efr32_sdk/efr32_sdk.gni +++ b/third_party/efr32_sdk/efr32_sdk.gni @@ -38,6 +38,12 @@ template("efr32_sdk") { } assert(efr32_sdk_root != "", "efr32_sdk_root must be specified") + use_wf200 = false + if (defined(invoker.use_wf200)) { + if (invoker.use_wf200) { + use_wf200 = true + } + } sdk_target_name = target_name @@ -224,6 +230,15 @@ template("efr32_sdk") { "CHIP_KVS_SECTOR_COUNT=4", ] } + if (use_wf200) { + _include_dirs += [ + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver", + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/bus", + "${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", + ] + } cflags = [] foreach(include_dir, _include_dirs) { @@ -443,6 +458,14 @@ template("efr32_sdk") { ] } } + if (use_wf200) { + sources += [ + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/bus/sl_wfx_bus.c", + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/bus/sl_wfx_bus_spi.c", + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/secure_link/sl_wfx_secure_link.c", + "${efr32_sdk_root}/platform/radio/wifi/wfx_fmac_driver/sl_wfx.c", + ] + } if (efr32_family == "efr32mg12") { sources += [ diff --git a/third_party/wiseconnect-wifi-bt-sdk b/third_party/wiseconnect-wifi-bt-sdk new file mode 120000 index 00000000000000..11fcb1f88f5c89 --- /dev/null +++ b/third_party/wiseconnect-wifi-bt-sdk @@ -0,0 +1 @@ +../../../wiseconnect-wifi-bt-sdk \ No newline at end of file