From deebeeffccb051994e383101f906eb6eed133ffb Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 01/21] [Telink] Enable IPv4 --- config/telink/chip-module/CMakeLists.txt | 2 +- config/telink/chip-module/Kconfig | 9 +++++++++ config/telink/chip-module/Kconfig.defaults | 2 +- src/platform/telink/args.gni | 4 ---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 0f2e4edce0f8d1..ee0f0ad6a878c1 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -95,7 +95,7 @@ matter_add_gn_arg_bool ("chip_logging" CONFIG_LOG) matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT) -matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) +matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4) matter_add_gn_arg_bool ("chip_enable_nfc" CONFIG_CHIP_NFC_COMMISSIONING) matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 4444cc8e9e44ed..861c57f260db23 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -178,6 +178,15 @@ config CHIP_LOG_SIZE_OPTIMIZATION full configuration enabled by this option in the platform/telink/CHIPPlatformConfig.h file. +config CHIP_IPV4 + bool "IPv4 support for Matter" + default n + depends on NET_IPV4 + help + If disabled, it allows to build Telink SDK application + with IPv4 support independently of the Matter stack still + running over IPv6. + config CHIP_BUTTON_MANAGER_IRQ_MODE bool "Use GPIO in an IRQ mode instead of polling the GPIO" default PM || BOARD_TLSR9118BDK40D diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index e6554774187a18..4abd9d84af112f 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -300,10 +300,10 @@ config CHIP_WIFI select WIFI_W91 select WIFI select NET_STATISTICS - select NET_L2_ETHERNET select NET_IPV6_ND # enable Neighbor Discovery to handle Router Advertisements select NET_IPV6_NBR_CACHE select NET_STATISTICS_USER_API + select NET_IPV4 # TODO: remove when IPv6 will be ready if CHIP_WIFI diff --git a/src/platform/telink/args.gni b/src/platform/telink/args.gni index 8a0a79b3a59761..23d446dd82bc64 100644 --- a/src/platform/telink/args.gni +++ b/src/platform/telink/args.gni @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -chip_device_platform = "telink" - -chip_inet_config_enable_ipv4 = false - declare_args() { # Enable factory data support chip_enable_factory_data = false From 15856308d0227a13d9b275be6a2e88f6bed49e62 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 02/21] [Telink] Logs for WiFi debug --- config/telink/chip-module/Kconfig.defaults | 4 ++-- src/platform/telink/CHIPPlatformConfig.h | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 4abd9d84af112f..1b3adce5c92b82 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -34,11 +34,11 @@ choice LOG_MODE endchoice choice MATTER_LOG_LEVEL_CHOICE - default MATTER_LOG_LEVEL_INF + default MATTER_LOG_LEVEL_DBG endchoice config CHIP_APP_LOG_LEVEL - default 3 # info + default 4 # debug config LOG_DEFAULT_LEVEL default 1 # error diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index 1bb4ab7b07203d..edd68b95380a84 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -102,11 +102,7 @@ #define CHIP_CONFIG_MAX_FABRICS 5 #endif -#ifndef CONFIG_CHIP_LOG_SIZE_OPTIMIZATION -#define CONFIG_CHIP_LOG_SIZE_OPTIMIZATION 0 -#endif - -#if CONFIG_CHIP_LOG_SIZE_OPTIMIZATION +#ifdef CONFIG_CHIP_LOG_SIZE_OPTIMIZATION // Disable some of the too detailed log modules to save flash #define CHIP_CONFIG_LOG_MODULE_ExchangeManager_DETAIL 0 #define CHIP_CONFIG_LOG_MODULE_Crypto_DETAIL 0 @@ -129,7 +125,6 @@ #define CHIP_CONFIG_LOG_MODULE_AppServer_DETAIL 0 #define CHIP_CONFIG_LOG_MODULE_Support_DETAIL 0 #define CHIP_CONFIG_LOG_MODULE_Support_PROGRESS 0 -#define CHIP_CONFIG_LOG_MODULE_DeviceLayer_DETAIL 0 #endif #ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC From 1f8a2f25588651d94160c8ba8d44801182f3fbb3 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 03/21] [Telink] Get NetIf interface instead of static --- .../wifi/ConnectivityManagerImplWiFi.cpp | 1 - src/platform/telink/wifi/WiFiManager.cpp | 60 ++++++++----------- src/platform/telink/wifi/WiFiManager.h | 1 + 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/platform/telink/wifi/ConnectivityManagerImplWiFi.cpp b/src/platform/telink/wifi/ConnectivityManagerImplWiFi.cpp index 3fefcf709e1b9b..5bef79bb22fdc5 100644 --- a/src/platform/telink/wifi/ConnectivityManagerImplWiFi.cpp +++ b/src/platform/telink/wifi/ConnectivityManagerImplWiFi.cpp @@ -29,7 +29,6 @@ using namespace ::chip; using namespace ::chip::Inet; using namespace ::chip::System; -using namespace ::chip::TLV; namespace chip { namespace DeviceLayer { diff --git a/src/platform/telink/wifi/WiFiManager.cpp b/src/platform/telink/wifi/WiFiManager.cpp index 88195fdbee2ab8..9f7bac7f0c59b0 100644 --- a/src/platform/telink/wifi/WiFiManager.cpp +++ b/src/platform/telink/wifi/WiFiManager.cpp @@ -23,8 +23,6 @@ #include "WiFiManager.h" #include -#include -#include #include #include #include @@ -135,7 +133,7 @@ const Map void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface) { - if (0 == strcmp(iface->if_dev->dev->name, "wlan0")) + if (iface == Instance().mNetIf) { Platform::UniquePtr eventData(new uint8_t[cb->info_length]); VerifyOrReturn(eventData); @@ -146,6 +144,9 @@ void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mg CHIP_ERROR WiFiManager::Init() { + mNetIf = InetUtils::GetWiFiInterface(); + VerifyOrReturnError(mNetIf != nullptr, INET_ERROR_UNKNOWN_INTERFACE); + net_mgmt_init_event_callback(&mWiFiMgmtClbk, WifiMgmtEventHandler, kWifiManagementEvents); net_mgmt_add_event_callback(&mWiFiMgmtClbk); @@ -156,9 +157,6 @@ CHIP_ERROR WiFiManager::Init() CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCallback, ScanDoneCallback doneCallback, bool internalScan) { - net_if * iface = InetUtils::GetInterface(); - VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); - mInternalScan = internalScan; mScanResultCallback = resultCallback; mScanDoneCallback = doneCallback; @@ -166,7 +164,7 @@ CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCal mWiFiState = WIFI_STATE_SCANNING; mSsidFound = false; - if (0 != net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) + if (0 != net_mgmt(NET_REQUEST_WIFI_SCAN, mNetIf, NULL, 0)) { ChipLogError(DeviceLayer, "Scan request failed"); return CHIP_ERROR_INTERNAL; @@ -207,11 +205,8 @@ CHIP_ERROR WiFiManager::Connect(const ByteSpan & ssid, const ByteSpan & credenti CHIP_ERROR WiFiManager::Disconnect() { - net_if * iface = InetUtils::GetInterface(); - VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); - mApplicationDisconnectRequested = true; - int status = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, NULL, 0); + int status = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, mNetIf, NULL, 0); if (status) { @@ -236,11 +231,9 @@ CHIP_ERROR WiFiManager::Disconnect() CHIP_ERROR WiFiManager::GetWiFiInfo(WiFiInfo & info) const { - net_if * iface = InetUtils::GetInterface(); - VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); - struct wifi_iface_status status = { 0 }; + wifi_iface_status status = { 0 }; - if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status, sizeof(struct wifi_iface_status))) + if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, mNetIf, &status, sizeof(wifi_iface_status))) { ChipLogError(DeviceLayer, "Status request failed"); return CHIP_ERROR_INTERNAL; @@ -265,7 +258,7 @@ CHIP_ERROR WiFiManager::GetWiFiInfo(WiFiInfo & info) const CHIP_ERROR WiFiManager::GetNetworkStatistics(NetworkStatistics & stats) const { net_stats_wifi data{}; - net_mgmt(NET_REQUEST_STATS_GET_WIFI, InetUtils::GetInterface(), &data, sizeof(data)); + net_mgmt(NET_REQUEST_STATS_GET_WIFI, mNetIf, &data, sizeof(data)); stats.mPacketMulticastRxCount = data.multicast.rx; stats.mPacketMulticastTxCount = data.multicast.tx; @@ -356,13 +349,13 @@ void WiFiManager::ScanDoneHandler(Platform::UniquePtr data) ChipLogProgress(DeviceLayer, "Starting connection recover: re-scanning... (next attempt in %d ms)", currentTimeout.count()); DeviceLayer::SystemLayer().StartTimer(currentTimeout, Recover, nullptr); + return; } Instance().mWiFiState = WIFI_STATE_ASSOCIATING; - net_if * iface = InetUtils::GetInterface(); - VerifyOrReturn(nullptr != iface, CHIP_ERROR_INTERNAL); - if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &(Instance().mWiFiParams.mParams), sizeof(wifi_connect_req_params))) + if (net_mgmt(NET_REQUEST_WIFI_CONNECT, Instance().mNetIf, &(Instance().mWiFiParams.mParams), + sizeof(wifi_connect_req_params))) { ChipLogError(DeviceLayer, "Connection request failed"); if (Instance().mHandling.mOnConnectionFailed) @@ -387,20 +380,16 @@ void WiFiManager::ScanDoneHandler(Platform::UniquePtr data) void WiFiManager::SendRouterSolicitation(System::Layer * layer, void * param) { - net_if * iface = InetUtils::GetInterface(); - if (iface && iface->if_dev->link_addr.type == NET_LINK_ETHERNET) + net_if_start_rs(Instance().mNetIf); + Instance().mRouterSolicitationCounter++; + if (Instance().mRouterSolicitationCounter < kRouterSolicitationMaxCount) { - net_if_start_rs(iface); - Instance().mRouterSolicitationCounter++; - if (Instance().mRouterSolicitationCounter < kRouterSolicitationMaxCount) - { - DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kRouterSolicitationIntervalMs), - SendRouterSolicitation, nullptr); - } - else - { - Instance().mRouterSolicitationCounter = 0; - } + DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kRouterSolicitationIntervalMs), SendRouterSolicitation, + nullptr); + } + else + { + Instance().mRouterSolicitationCounter = 0; } } @@ -529,11 +518,10 @@ System::Clock::Milliseconds32 WiFiManager::CalculateNextRecoveryTime() CHIP_ERROR WiFiManager::SetLowPowerMode(bool onoff) { - net_if * iface = InetUtils::GetInterface(); - VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(nullptr != mNetIf, CHIP_ERROR_INTERNAL); wifi_ps_config currentConfig{}; - if (net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, iface, ¤tConfig, sizeof(currentConfig))) + if (net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, mNetIf, ¤tConfig, sizeof(currentConfig))) { ChipLogError(DeviceLayer, "Get current low power mode config request failed"); return CHIP_ERROR_INTERNAL; @@ -543,7 +531,7 @@ CHIP_ERROR WiFiManager::SetLowPowerMode(bool onoff) (currentConfig.ps_params.enabled == WIFI_PS_DISABLED && onoff == true)) { wifi_ps_params params{ .enabled = onoff ? WIFI_PS_ENABLED : WIFI_PS_DISABLED }; - if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) + if (net_mgmt(NET_REQUEST_WIFI_PS, mNetIf, ¶ms, sizeof(params))) { ChipLogError(DeviceLayer, "Set low power mode request failed"); return CHIP_ERROR_INTERNAL; diff --git a/src/platform/telink/wifi/WiFiManager.h b/src/platform/telink/wifi/WiFiManager.h index f48d8f9b372469..8191e4bef16f99 100644 --- a/src/platform/telink/wifi/WiFiManager.h +++ b/src/platform/telink/wifi/WiFiManager.h @@ -215,6 +215,7 @@ class WiFiManager void ResetRecoveryTime(); System::Clock::Milliseconds32 CalculateNextRecoveryTime(); + net_if * mNetIf{ nullptr }; ConnectionParams mWiFiParams{}; ConnectionHandling mHandling; wifi_iface_state mWiFiState; From 7d938754504393152d8ba55c00c636531b7c4ffe Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 04/21] [Telink] Add GetSupportedWiFiBandsMask --- src/platform/telink/wifi/TelinkWiFiDriver.cpp | 6 ++++++ src/platform/telink/wifi/TelinkWiFiDriver.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.cpp b/src/platform/telink/wifi/TelinkWiFiDriver.cpp index d6b47053839e35..db74dc7fa8f637 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.cpp +++ b/src/platform/telink/wifi/TelinkWiFiDriver.cpp @@ -276,6 +276,12 @@ void TelinkWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * ca } } +uint32_t TelinkWiFiDriver::GetSupportedWiFiBandsMask() const +{ + uint32_t bands = static_cast(1UL << chip::to_underlying(WiFiBandEnum::k2g4)); + return bands; +} + } // namespace NetworkCommissioning } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.h b/src/platform/telink/wifi/TelinkWiFiDriver.h index b9f9b6374c42e3..7c932492e12d6d 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.h +++ b/src/platform/telink/wifi/TelinkWiFiDriver.h @@ -86,6 +86,7 @@ class TelinkWiFiDriver final : public WiFiDriver Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; + uint32_t GetSupportedWiFiBandsMask() const override; static TelinkWiFiDriver & Instance() { From 605a0bcae0e031754d2f9d2273e6b02cbe413c86 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 05/21] [Telink] Use ssid for OnNetworkingStatusChange --- src/platform/telink/wifi/TelinkWiFiDriver.cpp | 17 ++++++++++++++++- src/platform/telink/wifi/WiFiManager.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.cpp b/src/platform/telink/wifi/TelinkWiFiDriver.cpp index db74dc7fa8f637..6e8a049a098b6d 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.cpp +++ b/src/platform/telink/wifi/TelinkWiFiDriver.cpp @@ -122,7 +122,22 @@ void TelinkWiFiDriver::OnNetworkStatusChanged(Status status) if (mpNetworkStatusChangeCallback) { - mpNetworkStatusChangeCallback->OnNetworkingStatusChange(status, NullOptional, NullOptional); + const uint8_t * ssid{}; + size_t ssidLen{}; + WiFiManager::WiFiInfo wifiInfo; + + if (CHIP_NO_ERROR == WiFiManager::Instance().GetWiFiInfo(wifiInfo)) + { + ssid = wifiInfo.mSsid; + ssidLen = wifiInfo.mSsidLen; + } + else + { + ssid = WiFiManager::Instance().GetWantedNetwork().ssid; + ssidLen = WiFiManager::Instance().GetWantedNetwork().ssidLen; + } + mpNetworkStatusChangeCallback->OnNetworkingStatusChange(status, MakeOptional(ByteSpan(wifiInfo.mSsid, wifiInfo.mSsidLen)), + NullOptional); } if (mpConnectCallback) diff --git a/src/platform/telink/wifi/WiFiManager.h b/src/platform/telink/wifi/WiFiManager.h index 8191e4bef16f99..97a2a4fc0738cb 100644 --- a/src/platform/telink/wifi/WiFiManager.h +++ b/src/platform/telink/wifi/WiFiManager.h @@ -177,6 +177,7 @@ class WiFiManager CHIP_ERROR ClearStationProvisioningData(); CHIP_ERROR Disconnect(); CHIP_ERROR GetWiFiInfo(WiFiInfo & info) const; + const WiFiNetwork & GetWantedNetwork() const { return mWantedNetwork; } CHIP_ERROR GetNetworkStatistics(NetworkStatistics & stats) const; void AbortConnectionRecovery(); CHIP_ERROR SetLowPowerMode(bool onoff); From 6657043681b755f981ae11235de3f62bb314762f Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 06/21] [Telink] Add join default WiFi network for debug --- config/telink/chip-module/Kconfig.defaults | 19 ++++++- .../telink/common/include/AppTaskCommon.h | 7 ++- .../telink/common/src/AppTaskCommon.cpp | 56 ++++++++++++++++++- src/platform/telink/wifi/TelinkWiFiDriver.cpp | 14 +++++ src/platform/telink/wifi/TelinkWiFiDriver.h | 2 + 5 files changed, 93 insertions(+), 5 deletions(-) diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 1b3adce5c92b82..c19b9121657ffe 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -303,10 +303,27 @@ config CHIP_WIFI select NET_IPV6_ND # enable Neighbor Discovery to handle Router Advertisements select NET_IPV6_NBR_CACHE select NET_STATISTICS_USER_API - select NET_IPV4 # TODO: remove when IPv6 will be ready + select NET_IPV4 # TODO: remove when IPv6 will be ready if CHIP_WIFI +config DEFAULT_WIFI_SSID + string "Default WiFi SSID" + depends on CHIP_WIFI + default "" + help + The SSID of network to connect to if no WiFi station configuration exists in NV storage + at the time the device boots. + This option is for testing only and should be disabled in production releases + +config DEFAULT_WIFI_PASSWORD + string "Default WiFi Password" + depends on CHIP_WIFI + default "" + help + The password for the default WiFi network. + This option is for testing only and should be disabled in production releases. + config CHIP_WIFI_CONNECTION_RECOVERY_MINIMUM_INTERVAL int "Define the minimum connection recovery time interval in milliseconds" depends on CHIP_WIFI diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index b1e5ad356692bb..7a4ead865a6133 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -102,10 +102,15 @@ class AppTaskCommon static void StartBleAdvButtonEventHandler(void); static void StartBleAdvHandler(AppEvent * aEvent); -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD static void StartThreadButtonEventHandler(void); static void StartThreadHandler(AppEvent * aEvent); +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI + static void StartWiFiButtonEventHandler(void); + static void StartWiFiHandler(AppEvent * aEvent); #endif +#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ static void ExampleActionButtonEventHandler(void); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 96bb3ca87463dc..05c898ac73fa4c 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -26,6 +26,10 @@ #include "ThreadUtil.h" +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#endif + #include #include #include @@ -213,9 +217,13 @@ CHIP_ERROR AppTaskCommon::StartApp(void) AppEvent event = {}; -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD StartThreadButtonEventHandler(); +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI + StartWiFiButtonEventHandler(); #endif +#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ #ifdef CONFIG_BOOTLOADER_MCUBOOT if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && @@ -360,10 +368,16 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) FactoryResetButtonEventHandler(); break; #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD case kButtonId_StartThread: StartThreadButtonEventHandler(); break; +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI + case kButtonId_StartWiFi: + StartWiFiButtonEventHandler(); + break; #endif +#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ case kButtonId_StartBleAdv: StartBleAdvButtonEventHandler(); break; @@ -433,9 +447,13 @@ void AppTaskCommon::LinkButtons(ButtonManager & buttonManager) buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD buttonManager.addCallback(StartThreadButtonEventHandler, 3, true); +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI + buttonManager.addCallback(StartWiFiButtonEventHandler, 3, true); #endif +#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ } void AppTaskCommon::UpdateStatusLED() @@ -578,7 +596,8 @@ void AppTaskCommon::FactoryResetTimerEventHandler(AppEvent * aEvent) LOG_INF("Factory Reset Trigger Counter is cleared"); } -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD void AppTaskCommon::StartThreadButtonEventHandler(void) { AppEvent event; @@ -609,7 +628,38 @@ void AppTaskCommon::StartThreadHandler(AppEvent * aEvent) LOG_INF("Device already commissioned"); } } + +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI +void AppTaskCommon::StartWiFiButtonEventHandler(void) +{ + AppEvent event; + + event.Type = AppEvent::kEventType_Button; + event.ButtonEvent.Action = kButtonPushEvent; + event.Handler = StartWiFiHandler; + GetAppTask().PostEvent(&event); +} + +void AppTaskCommon::StartWiFiHandler(AppEvent * aEvent) +{ + LOG_INF("StartWiFiHandler"); + + if (!strlen(CONFIG_DEFAULT_WIFI_SSID) || !strlen(CONFIG_DEFAULT_WIFI_PASSWORD)) + { + LOG_ERR("default WiFi SSID/Password are not set"); + } + + if (!chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned()) + { + NetworkCommissioning::TelinkWiFiDriver().StartDefaultWiFiNetwork(); + } + else + { + LOG_INF("Device already commissioned"); + } +} #endif +#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ void AppTaskCommon::ExampleActionButtonEventHandler(void) { diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.cpp b/src/platform/telink/wifi/TelinkWiFiDriver.cpp index 6e8a049a098b6d..913aa61358bb3b 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.cpp +++ b/src/platform/telink/wifi/TelinkWiFiDriver.cpp @@ -297,6 +297,20 @@ uint32_t TelinkWiFiDriver::GetSupportedWiFiBandsMask() const return bands; } +void TelinkWiFiDriver::StartDefaultWiFiNetwork(void) +{ + chip::ByteSpan ssidSpan = ByteSpan(Uint8::from_const_char(CONFIG_DEFAULT_WIFI_SSID), strlen(CONFIG_DEFAULT_WIFI_SSID)); + chip::ByteSpan passwordSpan = ByteSpan(Uint8::from_const_char(CONFIG_DEFAULT_WIFI_PASSWORD), strlen(CONFIG_DEFAULT_WIFI_PASSWORD)); + + char debugBuffer[1] = {0}; + MutableCharSpan debugText(debugBuffer, 0); + uint8_t outNetworkIndex = 0; + + AddOrUpdateNetwork(ssidSpan, passwordSpan, debugText, outNetworkIndex); + CommitConfiguration(); + RevertConfiguration(); +} + } // namespace NetworkCommissioning } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.h b/src/platform/telink/wifi/TelinkWiFiDriver.h index 7c932492e12d6d..a3b8c5c032221c 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.h +++ b/src/platform/telink/wifi/TelinkWiFiDriver.h @@ -98,6 +98,8 @@ class TelinkWiFiDriver final : public WiFiDriver void OnScanWiFiNetworkResult(const WiFiScanResponse & result); void OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status); + void StartDefaultWiFiNetwork(void); + private: void LoadFromStorage(); From 10357553643429cd78fd25efeb20802cfff513a7 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 22:35:59 +0300 Subject: [PATCH 07/21] [Telink] Use key matrix --- config/telink/chip-module/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 861c57f260db23..46dc36b8973d77 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -189,7 +189,7 @@ config CHIP_IPV4 config CHIP_BUTTON_MANAGER_IRQ_MODE bool "Use GPIO in an IRQ mode instead of polling the GPIO" - default PM || BOARD_TLSR9118BDK40D + default PM help Use GPIO in an IRQ mode to avoid button polling loop and extend the battery lifetime by waking up by GPIO event. GPIO events are working only with GPIO IRQ. This option changes button matrix configuration. From d108e4fcdcd1adae2d423421d8f3407a5a644aa9 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 29 May 2024 21:02:58 +0300 Subject: [PATCH 08/21] [Telink] Enable temporarry IPv4 & DHCPV4 Issue with IPv6 UDP bind & CHIP_IPV4 config --- .github/workflows/chef.yaml | 6 +++--- .github/workflows/examples-telink.yaml | 4 ++-- config/telink/chip-module/Kconfig.defaults | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 77c1a21be6b388..5eb05a6c007da3 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -108,9 +108,9 @@ jobs: uses: ./.github/actions/checkout-submodules-and-bootstrap with: platform: telink - # - name: Update Zephyr to specific revision (for developers purpose) - # shell: bash - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 0e8032dfef7e02498f34ba0b5d5d2df71a62adb1" + - name: Update Zephyr to specific revision (for developers purpose) + shell: bash + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 9874a7fcd01168662208c52297b859ed88a8d9fd" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 6c836294381a0f..246513105e2aac 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -56,8 +56,8 @@ jobs: with: gh-context: ${{ toJson(github) }} - # - name: Update Zephyr to specific revision (for developers purpose) - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 0e8032dfef7e02498f34ba0b5d5d2df71a62adb1" + - name: Update Zephyr to specific revision (for developers purpose) + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 9874a7fcd01168662208c52297b859ed88a8d9fd" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index c19b9121657ffe..df80fb6b01d413 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -303,7 +303,9 @@ config CHIP_WIFI select NET_IPV6_ND # enable Neighbor Discovery to handle Router Advertisements select NET_IPV6_NBR_CACHE select NET_STATISTICS_USER_API - select NET_IPV4 # TODO: remove when IPv6 will be ready + select NET_IPV4 # TODO: remove IPv4 when IPv6 will be ready (see CHIP_IPV4) + select NET_CONFIG_NEED_IPV4 + select NET_DHCPV4 if CHIP_WIFI From 0dcdb406c3f43b8e0c2c6b447784d4a8057ede91 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Fri, 31 May 2024 13:53:20 +0300 Subject: [PATCH 09/21] [Telink] Fixes to enable and test BLE --- config/telink/chip-module/Kconfig.defaults | 6 +-- .../telink/common/include/AppTaskCommon.h | 1 + .../telink/common/src/AppTaskCommon.cpp | 13 +++--- .../platform/telink/common/src/mainCommon.cpp | 3 +- src/platform/telink/BLEManagerImpl.cpp | 40 ++++++++++++++----- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index df80fb6b01d413..d52e243d4fd80c 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -303,9 +303,9 @@ config CHIP_WIFI select NET_IPV6_ND # enable Neighbor Discovery to handle Router Advertisements select NET_IPV6_NBR_CACHE select NET_STATISTICS_USER_API - select NET_IPV4 # TODO: remove IPv4 when IPv6 will be ready (see CHIP_IPV4) - select NET_CONFIG_NEED_IPV4 - select NET_DHCPV4 +# select NET_IPV4 # TODO: remove IPv4 when IPv6 will be ready (see CHIP_IPV4) +# select NET_CONFIG_NEED_IPV4 +# select NET_DHCPV4 if CHIP_WIFI diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 7a4ead865a6133..81cbe06508393a 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -76,6 +76,7 @@ class AppTaskCommon { kButtonId_ExampleAction = 1, kButtonId_FactoryReset, + kButtonId_StartWiFi, kButtonId_StartThread, kButtonId_StartBleAdv } ButtonId; diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 05c898ac73fa4c..7f3509814820aa 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -24,9 +24,9 @@ #include "LEDManager.h" #include "PWMManager.h" +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include "ThreadUtil.h" - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI #include #endif @@ -78,7 +78,7 @@ uint8_t sFactoryResetCntr = 0; bool sIsCommissioningFailed = false; bool sIsNetworkProvisioned = false; bool sIsNetworkEnabled = false; -bool sIsThreadAttached = false; +bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; #if APP_SET_DEVICE_INFO_PROVIDER @@ -460,7 +460,7 @@ void AppTaskCommon::UpdateStatusLED() { if (sIsNetworkProvisioned && sIsNetworkEnabled) { - if (sIsThreadAttached) + if (sIsNetworkAttached) { LedManager::getInstance().setLed(LedManager::EAppLed_Status, 950, 50); } @@ -524,8 +524,8 @@ void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { LOG_INF("StartBleAdvHandler"); - // Don't allow on starting Matter service BLE advertising after Thread provisioning. - if (ConnectivityMgr().IsThreadProvisioned()) + // Don't allow on starting Matter service BLE advertising after device provisioning. + if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) { LOG_INF("Device already commissioned"); return; @@ -728,6 +728,7 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* case DeviceEventType::kWiFiConnectivityChange: sIsNetworkProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); sIsNetworkEnabled = ConnectivityMgr().IsWiFiStationEnabled(); + sIsNetworkAttached = ConnectivityMgr().IsWiFiStationConnected(); #if CONFIG_CHIP_OTA_REQUESTOR if (event->WiFiConnectivityChange.Result == kConnectivity_Established) { diff --git a/examples/platform/telink/common/src/mainCommon.cpp b/examples/platform/telink/common/src/mainCommon.cpp index 7018adaa1b8c7c..583d61c0082c57 100644 --- a/examples/platform/telink/common/src/mainCommon.cpp +++ b/examples/platform/telink/common/src/mainCommon.cpp @@ -167,7 +167,8 @@ int main(void) #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI sWiFiCommissioningInstance.Init(); #else - return CHIP_ERROR_INTERNAL; + err = CHIP_ERROR_INTERNAL; + goto exit; #endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */ err = GetAppTask().StartApp(); diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index c33de4264e1edd..f67238a49c122b 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,9 +45,16 @@ #include #include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#endif + +// TODO: need common mac_init solution for B9X & W91 +#ifndef CONFIG_BOARD_TLSR9118BDK40D extern "C" { #include } +#endif #if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) #include @@ -117,7 +124,10 @@ CHIP_ERROR InitBLEMACAddress() int error = 0; bt_addr_le_t addr; +// TODO: need common mac_init solution for B9X & W91 +#ifndef CONFIG_BOARD_TLSR9118BDK40D b9x_bt_blc_mac_init(addr.a.val); +#endif if (BT_ADDR_IS_STATIC(&addr.a)) // in case of Random static address, create a new id { @@ -284,16 +294,19 @@ inline CHIP_ERROR BLEManagerImpl::PrepareAdvertisingRequest(void) CHIP_ERROR BLEManagerImpl::StartAdvertising(void) { - if (ConnectivityMgr().IsThreadProvisioned()) + if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) { - ChipLogProgress(DeviceLayer, "Thread provisioned, can't StartAdvertising"); + ChipLogProgress(DeviceLayer, "Device provisioned, can't StartAdvertising"); return CHIP_ERROR_INCORRECT_STATE; } +// TODO: check if WiFi scanning required for Amazon ecosystem +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD else if (!mBLERadioInitialized) { ThreadStackMgrImpl().StartThreadScan(mInternalScanCallback); } +#endif else { return StartAdvertisingProcess(); @@ -308,11 +321,13 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) if (!mBLERadioInitialized) { - /* Switch off Thread */ +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + // Deinit Thread ThreadStackMgrImpl().SetThreadEnabled(false); ThreadStackMgrImpl().SetRadioBlocked(true); +#endif - /* Init BLE stack */ + // Init BLE err = bt_enable(NULL); VerifyOrReturnError(err == 0, MapErrorZephyr(err)); @@ -379,9 +394,9 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { - if (ConnectivityMgr().IsThreadProvisioned()) + if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) { - ChipLogProgress(DeviceLayer, "Thread provisioned, StopAdvertising done"); + ChipLogProgress(DeviceLayer, "Device provisioned, StopAdvertising done"); return CHIP_ERROR_INCORRECT_STATE; } @@ -942,20 +957,22 @@ CHIP_ERROR BLEManagerImpl::HandleThreadStateChange(const ChipDeviceEvent * event CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * event) { +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (ThreadStackMgrImpl().IsReadyToAttach()) { SwitchToIeee802154(); } +#endif return CHIP_NO_ERROR; } -/* @todo: move to RadioSwitch module */ +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD void BLEManagerImpl::SwitchToIeee802154(void) { - ChipLogProgress(DeviceLayer, "SwitchToIeee802154"); + ChipLogProgress(DeviceLayer, "Switch context from BLE to Thread"); - /* Deinit BLE stack */ + // Deinit BLE bt_disable(); mBLERadioInitialized = false; @@ -963,10 +980,11 @@ void BLEManagerImpl::SwitchToIeee802154(void) pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); #endif - /* Init IEEE802154 */ + // Init Thread ThreadStackMgrImpl().SetRadioBlocked(false); ThreadStackMgrImpl().SetThreadEnabled(true); } +#endif } // namespace Internal } // namespace DeviceLayer From e2ac874ee32fc55d3a4ed3f6e11301580041001c Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 6 Jun 2024 21:53:58 +0300 Subject: [PATCH 10/21] [Telink] Alignment with NRF/Zephyr platform --- src/platform/telink/wifi/TelinkWiFiDriver.cpp | 7 +-- src/platform/telink/wifi/TelinkWiFiDriver.h | 2 +- src/platform/telink/wifi/WiFiManager.cpp | 58 +++++++++++++------ src/platform/telink/wifi/WiFiManager.h | 15 ++--- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.cpp b/src/platform/telink/wifi/TelinkWiFiDriver.cpp index 913aa61358bb3b..09757fe3619513 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.cpp +++ b/src/platform/telink/wifi/TelinkWiFiDriver.cpp @@ -264,11 +264,10 @@ void TelinkWiFiDriver::LoadFromStorage() mStagingNetwork = network; } -void TelinkWiFiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status) +void TelinkWiFiDriver::OnScanWiFiNetworkDone(const WiFiManager::ScanDoneStatus & status) { VerifyOrReturn(mScanCallback != nullptr); - mScanCallback->OnFinished(status == WiFiManager::WiFiRequestStatus::SUCCESS ? Status::kSuccess : Status::kUnknownError, - CharSpan(), &mScanResponseIterator); + mScanCallback->OnFinished(status ? Status::kUnknownError : Status::kSuccess, CharSpan(), &mScanResponseIterator); mScanCallback = nullptr; } @@ -282,7 +281,7 @@ void TelinkWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * ca mScanCallback = callback; CHIP_ERROR error = WiFiManager::Instance().Scan( ssid, [](const WiFiScanResponse & response) { Instance().OnScanWiFiNetworkResult(response); }, - [](WiFiManager::WiFiRequestStatus status) { Instance().OnScanWiFiNetworkDone(status); }); + [](const WiFiManager::ScanDoneStatus & status) { Instance().OnScanWiFiNetworkDone(status); }); if (error != CHIP_NO_ERROR) { diff --git a/src/platform/telink/wifi/TelinkWiFiDriver.h b/src/platform/telink/wifi/TelinkWiFiDriver.h index a3b8c5c032221c..9c5b1e61d1f0e1 100644 --- a/src/platform/telink/wifi/TelinkWiFiDriver.h +++ b/src/platform/telink/wifi/TelinkWiFiDriver.h @@ -96,7 +96,7 @@ class TelinkWiFiDriver final : public WiFiDriver void OnNetworkStatusChanged(Status status); void OnScanWiFiNetworkResult(const WiFiScanResponse & result); - void OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status); + void OnScanWiFiNetworkDone(const WiFiManager::ScanDoneStatus & status); void StartDefaultWiFiNetwork(void); diff --git a/src/platform/telink/wifi/WiFiManager.cpp b/src/platform/telink/wifi/WiFiManager.cpp index 9f7bac7f0c59b0..ed0fb2b4d69bca 100644 --- a/src/platform/telink/wifi/WiFiManager.cpp +++ b/src/platform/telink/wifi/WiFiManager.cpp @@ -125,11 +125,12 @@ const Map { WIFI_STATE_GROUP_HANDSHAKE, WiFiManager::StationStatus::PROVISIONING }, { WIFI_STATE_COMPLETED, WiFiManager::StationStatus::FULLY_PROVISIONED } }); -const Map - WiFiManager::sEventHandlerMap({ { NET_EVENT_WIFI_SCAN_RESULT, WiFiManager::ScanResultHandler }, - { NET_EVENT_WIFI_SCAN_DONE, WiFiManager::ScanDoneHandler }, - { NET_EVENT_WIFI_CONNECT_RESULT, WiFiManager::ConnectHandler }, - { NET_EVENT_WIFI_DISCONNECT_RESULT, WiFiManager::DisconnectHandler } }); +const Map WiFiManager::sEventHandlerMap({ + { NET_EVENT_WIFI_SCAN_RESULT, WiFiManager::ScanResultHandler }, + { NET_EVENT_WIFI_SCAN_DONE, WiFiManager::ScanDoneHandler }, + { NET_EVENT_WIFI_CONNECT_RESULT, WiFiManager::ConnectHandler }, + { NET_EVENT_WIFI_DISCONNECT_RESULT, WiFiManager::DisconnectHandler }, +}); void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface) { @@ -138,7 +139,7 @@ void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mg Platform::UniquePtr eventData(new uint8_t[cb->info_length]); VerifyOrReturn(eventData); memcpy(eventData.get(), cb->info, cb->info_length); - sEventHandlerMap[mgmtEvent](std::move(eventData)); + sEventHandlerMap[mgmtEvent](std::move(eventData), cb->info_length); } } @@ -270,10 +271,13 @@ CHIP_ERROR WiFiManager::GetNetworkStatistics(NetworkStatistics & stats) const return CHIP_NO_ERROR; } -void WiFiManager::ScanResultHandler(Platform::UniquePtr data) +void WiFiManager::ScanResultHandler(Platform::UniquePtr data, size_t length) { + // Validate that input data size matches the expected one. + VerifyOrReturn(length == sizeof(wifi_scan_result)); + // Contrary to other handlers, offload accumulating of the scan results from the CHIP thread to the caller's thread - const struct wifi_scan_result * scanResult = reinterpret_cast(data.get()); + const wifi_scan_result * scanResult = reinterpret_cast(data.get()); if (Instance().mInternalScan && Instance().mWantedNetwork.GetSsidSpan().data_equal(ByteSpan(scanResult->ssid, scanResult->ssid_length))) @@ -304,6 +308,7 @@ void WiFiManager::ScanResultHandler(Platform::UniquePtr data) Instance().mWiFiParams.mParams.timeout = Instance().mHandling.mConnectionTimeout.count(); Instance().mWiFiParams.mParams.channel = WIFI_CHANNEL_ANY; Instance().mWiFiParams.mRssi = scanResult->rssi; + Instance().mWiFiParams.mParams.band = WIFI_FREQ_BAND_UNKNOWN; Instance().mSsidFound = true; } } @@ -314,26 +319,29 @@ void WiFiManager::ScanResultHandler(Platform::UniquePtr data) } } -void WiFiManager::ScanDoneHandler(Platform::UniquePtr data) +void WiFiManager::ScanDoneHandler(Platform::UniquePtr data, size_t length) { + // Validate that input data size matches the expected one. + VerifyOrReturn(length == sizeof(wifi_status)); + CHIP_ERROR err = SystemLayer().ScheduleLambda([capturedData = data.get()] { Platform::UniquePtr safePtr(capturedData); - uint8_t * rawData = safePtr.get(); - const wifi_status * status = reinterpret_cast(rawData); - WiFiRequestStatus requestStatus = static_cast(status->status); + uint8_t * rawData = safePtr.get(); + const wifi_status * status = reinterpret_cast(rawData); + ScanDoneStatus scanDoneStatus = status->status; - if (requestStatus == WiFiRequestStatus::FAILURE) + if (scanDoneStatus) { - ChipLogError(DeviceLayer, "Wi-Fi scan finalization failure (%d)", status->status); + ChipLogError(DeviceLayer, "Wi-Fi scan finalization failure (%d)", scanDoneStatus); } else { - ChipLogProgress(DeviceLayer, "Wi-Fi scan done (%d)", status->status); + ChipLogProgress(DeviceLayer, "Wi-Fi scan done"); } if (Instance().mScanDoneCallback && !Instance().mInternalScan) { - Instance().mScanDoneCallback(requestStatus); + Instance().mScanDoneCallback(scanDoneStatus); // restore the connection state from before the scan request was issued Instance().mWiFiState = Instance().mCachedWiFiState; return; @@ -393,8 +401,11 @@ void WiFiManager::SendRouterSolicitation(System::Layer * layer, void * param) } } -void WiFiManager::ConnectHandler(Platform::UniquePtr data) +void WiFiManager::ConnectHandler(Platform::UniquePtr data, size_t length) { + // Validate that input data size matches the expected one. + VerifyOrReturn(length == sizeof(wifi_status)); + CHIP_ERROR err = SystemLayer().ScheduleLambda([capturedData = data.get()] { Platform::UniquePtr safePtr(capturedData); uint8_t * rawData = safePtr.get(); @@ -446,13 +457,22 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr data) } } -void WiFiManager::DisconnectHandler(Platform::UniquePtr) +void WiFiManager::DisconnectHandler(Platform::UniquePtr data, size_t length) { - SystemLayer().ScheduleLambda([] { + // Validate that input data size matches the expected one. + VerifyOrReturn(length == sizeof(wifi_status)); + + CHIP_ERROR err = SystemLayer().ScheduleLambda([] { ChipLogProgress(DeviceLayer, "WiFi station disconnected"); Instance().mWiFiState = WIFI_STATE_DISCONNECTED; Instance().PostConnectivityStatusChange(kConnectivity_Lost); }); + + if (CHIP_NO_ERROR == err) + { + // the ownership has been transferred to the worker thread - release the buffer + data.release(); + } } WiFiManager::StationStatus WiFiManager::GetStationStatus() const diff --git a/src/platform/telink/wifi/WiFiManager.h b/src/platform/telink/wifi/WiFiManager.h index 97a2a4fc0738cb..709f11ab5317ac 100644 --- a/src/platform/telink/wifi/WiFiManager.h +++ b/src/platform/telink/wifi/WiFiManager.h @@ -90,8 +90,9 @@ class WiFiManager TERMINATED = 2 }; + using ScanDoneStatus = decltype(wifi_status::status); using ScanResultCallback = void (*)(const NetworkCommissioning::WiFiScanResponse &); - using ScanDoneCallback = void (*)(WiFiRequestStatus); + using ScanDoneCallback = void (*)(const ScanDoneStatus &); using ConnectionCallback = void (*)(); enum class StationStatus : uint8_t @@ -183,7 +184,7 @@ class WiFiManager CHIP_ERROR SetLowPowerMode(bool onoff); private: - using NetEventHandler = void (*)(Platform::UniquePtr); + using NetEventHandler = void (*)(Platform::UniquePtr, size_t); struct ConnectionParams { @@ -196,10 +197,10 @@ class WiFiManager // Event handling static void WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface); - static void ScanResultHandler(Platform::UniquePtr data); - static void ScanDoneHandler(Platform::UniquePtr data); - static void ConnectHandler(Platform::UniquePtr data); - static void DisconnectHandler(Platform::UniquePtr data); + static void ScanResultHandler(Platform::UniquePtr data, size_t length); + static void ScanDoneHandler(Platform::UniquePtr data, size_t length); + static void ConnectHandler(Platform::UniquePtr data, size_t length); + static void DisconnectHandler(Platform::UniquePtr data, size_t length); static void PostConnectivityStatusChange(ConnectivityChange changeType); static void SendRouterSolicitation(System::Layer * layer, void * param); @@ -218,7 +219,7 @@ class WiFiManager net_if * mNetIf{ nullptr }; ConnectionParams mWiFiParams{}; - ConnectionHandling mHandling; + ConnectionHandling mHandling{}; wifi_iface_state mWiFiState; wifi_iface_state mCachedWiFiState; net_mgmt_event_callback mWiFiMgmtClbk{}; From 0aa9bd76bdce8babefd567d21cf4bd43e6534d63 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 22:05:32 +0300 Subject: [PATCH 11/21] [Telink] Fix minimal mDNS init issue --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/CMakeLists.txt | 29 ++++++++++--------- .../telink/common/src/AppTaskCommon.cpp | 2 ++ src/platform/telink/BUILD.gn | 2 +- src/platform/telink/ThreadStackManagerImpl.h | 4 +-- src/platform/telink/wifi/WiFiManager.cpp | 2 ++ 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 5eb05a6c007da3..14a69997f0e086 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -110,7 +110,7 @@ jobs: platform: telink - name: Update Zephyr to specific revision (for developers purpose) shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 9874a7fcd01168662208c52297b859ed88a8d9fd" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 107e7b646bc8f16c799f3fef2a4b2c55595be374" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 246513105e2aac..ae6aa73c33bbd8 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -57,7 +57,7 @@ jobs: gh-context: ${{ toJson(github) }} - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 9874a7fcd01168662208c52297b859ed88a8d9fd" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 107e7b646bc8f16c799f3fef2a4b2c55595be374" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index ee0f0ad6a878c1..f8986e7a954fb4 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -98,36 +98,37 @@ matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT) matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4) matter_add_gn_arg_bool ("chip_enable_nfc" CONFIG_CHIP_NFC_COMMISSIONING) matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) -matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) +matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" FALSE) matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1) matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3) matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4) matter_add_gn_arg_bool ("chip_automation_logging" FALSE) matter_add_gn_arg_bool ("chip_enable_wifi" CONFIG_WIFI_W91) matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_ENABLE_ICD_SUPPORT) +matter_add_gn_arg_bool ("chip_enable_factory_data" CONFIG_CHIP_FACTORY_DATA) +matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_WIFI_W91) +matter_add_gn_arg_bool ("chip_mdns_platform" CONFIG_NET_L2_OPENTHREAD) if (CONFIG_CHIP_ENABLE_ICD_SUPPORT) - matter_add_gn_arg_bool ("chip_enable_icd_lit" CONFIG_CHIP_ICD_LIT_SUPPORT) - matter_add_gn_arg_bool ("chip_enable_icd_checkin" CONFIG_CHIP_ICD_CHECK_IN_SUPPORT) - matter_add_gn_arg_bool ("chip_enable_icd_user_active_mode_trigger" CONFIG_CHIP_ICD_UAT_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_lit" CONFIG_CHIP_ICD_LIT_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_checkin" CONFIG_CHIP_ICD_CHECK_IN_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_user_active_mode_trigger" CONFIG_CHIP_ICD_UAT_SUPPORT) endif() -if (CONFIG_CHIP_FACTORY_DATA) - matter_add_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") - matter_add_gn_arg_bool ("chip_enable_factory_data" "true") -elseif (CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) - matter_add_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") +if (CONFIG_CHIP_FACTORY_DATA OR CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) + matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) + matter_add_gn_arg_bool("chip_use_transitional_device_instance_info_provider" FALSE) endif() if (CONFIG_CHIP_ROTATING_DEVICE_ID) - matter_add_gn_arg_bool("chip_enable_rotating_device_id" "true") - matter_add_gn_arg_bool("chip_enable_additional_data_advertising" "true") + matter_add_gn_arg_bool("chip_enable_rotating_device_id" TRUE) + matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE) endif() -if (CONFIG_NET_L2_OPENTHREAD) - matter_add_gn_arg_string("chip_mdns" "platform") -elseif(CONFIG_WIFI_W91) +if(CONFIG_WIFI_W91) matter_add_gn_arg_string("chip_mdns" "minimal") +elseif (CONFIG_NET_L2_OPENTHREAD) + matter_add_gn_arg_string("chip_mdns" "platform") else() matter_add_gn_arg_string("chip_mdns" "none") endif() diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 7f3509814820aa..ca2c1d0a8b1b6d 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -27,6 +27,7 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include "ThreadUtil.h" #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include #include #endif @@ -651,6 +652,7 @@ void AppTaskCommon::StartWiFiHandler(AppEvent * aEvent) if (!chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned()) { + net_if_up(InetUtils::GetWiFiInterface()); NetworkCommissioning::TelinkWiFiDriver().StartDefaultWiFiNetwork(); } else diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn index 787b45ca7c06eb..3165d114987b04 100644 --- a/src/platform/telink/BUILD.gn +++ b/src/platform/telink/BUILD.gn @@ -83,7 +83,7 @@ static_library("telink") { "ThreadStackManagerImpl.h", ] - if (chip_mdns == "platform") { + if (chip_mdns_platform) { sources += [ "../OpenThread/DnssdImpl.cpp", "../OpenThread/OpenThreadDnssdImpl.cpp", diff --git a/src/platform/telink/ThreadStackManagerImpl.h b/src/platform/telink/ThreadStackManagerImpl.h index b06e33d9f5e0b2..fd3dc6330f2fe7 100644 --- a/src/platform/telink/ThreadStackManagerImpl.h +++ b/src/platform/telink/ThreadStackManagerImpl.h @@ -39,7 +39,7 @@ class ThreadStackManager; class ThreadStackManagerImpl; /** - * Concrete implementation of the ThreadStackManager singleton object for nRF Connect platforms. + * Concrete implementation of the ThreadStackManager singleton object for Telink platforms. */ class ThreadStackManagerImpl final : public ThreadStackManager, public Internal::GenericThreadStackManagerImpl_OpenThread @@ -118,7 +118,7 @@ inline ThreadStackManager & ThreadStackMgr(void) * Returns the platform-specific implementation of the ThreadStackManager singleton object. * * chip applications can use this to gain access to features of the ThreadStackManager - * that are specific to nRF Connect platforms. + * that are specific to Telink platforms. */ inline ThreadStackManagerImpl & ThreadStackMgrImpl(void) { diff --git a/src/platform/telink/wifi/WiFiManager.cpp b/src/platform/telink/wifi/WiFiManager.cpp index ed0fb2b4d69bca..7e9c4adf593cbf 100644 --- a/src/platform/telink/wifi/WiFiManager.cpp +++ b/src/platform/telink/wifi/WiFiManager.cpp @@ -148,6 +148,8 @@ CHIP_ERROR WiFiManager::Init() mNetIf = InetUtils::GetWiFiInterface(); VerifyOrReturnError(mNetIf != nullptr, INET_ERROR_UNKNOWN_INTERFACE); + net_if_down(mNetIf); // block netif auto start + net_mgmt_init_event_callback(&mWiFiMgmtClbk, WifiMgmtEventHandler, kWifiManagementEvents); net_mgmt_add_event_callback(&mWiFiMgmtClbk); From b35429dd30ff3e777ad9c50d97a332753bfb44b5 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 22:31:37 +0300 Subject: [PATCH 12/21] [Telink] Add DNS server refresh after adding new IPv6 address --- src/platform/telink/wifi/WiFiManager.cpp | 30 ++++++++++++++++++++++++ src/platform/telink/wifi/WiFiManager.h | 5 ++++ 2 files changed, 35 insertions(+) diff --git a/src/platform/telink/wifi/WiFiManager.cpp b/src/platform/telink/wifi/WiFiManager.cpp index 7e9c4adf593cbf..50ea5cf5682089 100644 --- a/src/platform/telink/wifi/WiFiManager.cpp +++ b/src/platform/telink/wifi/WiFiManager.cpp @@ -143,6 +143,14 @@ void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mg } } +void WiFiManager::IPv6MgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface) +{ + if (((mgmtEvent == NET_EVENT_IPV6_ADDR_ADD) || (mgmtEvent == NET_EVENT_IPV6_ADDR_DEL)) && cb->info) + { + IPv6AddressChangeHandler(cb->info); + } +} + CHIP_ERROR WiFiManager::Init() { mNetIf = InetUtils::GetWiFiInterface(); @@ -151,7 +159,10 @@ CHIP_ERROR WiFiManager::Init() net_if_down(mNetIf); // block netif auto start net_mgmt_init_event_callback(&mWiFiMgmtClbk, WifiMgmtEventHandler, kWifiManagementEvents); + net_mgmt_init_event_callback(&mIPv6MgmtClbk, IPv6MgmtEventHandler, kIPv6ManagementEvents); + net_mgmt_add_event_callback(&mWiFiMgmtClbk); + net_mgmt_add_event_callback(&mIPv6MgmtClbk); ChipLogDetail(DeviceLayer, "WiFiManager has been initialized"); @@ -477,6 +488,25 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr data, size_t le } } +void WiFiManager::IPv6AddressChangeHandler(const void * data) +{ + const in6_addr * addr = reinterpret_cast(data); + + // Filter out link-local addresses that are not routable outside of a local network. + if (!net_ipv6_is_ll_addr(addr)) + { + // This is needed to send mDNS queries containing updated IPv6 addresses. + ChipDeviceEvent event; + event.Type = DeviceEventType::kDnssdRestartNeeded; + + CHIP_ERROR error = PlatformMgr().PostEvent(&event); + if (error != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Cannot post event: %" CHIP_ERROR_FORMAT, error.Format()); + } + } +} + WiFiManager::StationStatus WiFiManager::GetStationStatus() const { return WiFiManager::sStatusMap[mWiFiState]; diff --git a/src/platform/telink/wifi/WiFiManager.h b/src/platform/telink/wifi/WiFiManager.h index 709f11ab5317ac..49c9496f5d13be 100644 --- a/src/platform/telink/wifi/WiFiManager.h +++ b/src/platform/telink/wifi/WiFiManager.h @@ -195,14 +195,18 @@ class WiFiManager constexpr static uint32_t kWifiManagementEvents = NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE | NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT | NET_EVENT_WIFI_IFACE_STATUS; + constexpr static uint32_t kIPv6ManagementEvents = NET_EVENT_IPV6_ADDR_ADD | NET_EVENT_IPV6_ADDR_DEL; + // Event handling static void WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface); + static void IPv6MgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface); static void ScanResultHandler(Platform::UniquePtr data, size_t length); static void ScanDoneHandler(Platform::UniquePtr data, size_t length); static void ConnectHandler(Platform::UniquePtr data, size_t length); static void DisconnectHandler(Platform::UniquePtr data, size_t length); static void PostConnectivityStatusChange(ConnectivityChange changeType); static void SendRouterSolicitation(System::Layer * layer, void * param); + static void IPv6AddressChangeHandler(const void * data); // Connection Recovery feature // This feature allows re-scanning and re-connecting the connection to the known network after @@ -223,6 +227,7 @@ class WiFiManager wifi_iface_state mWiFiState; wifi_iface_state mCachedWiFiState; net_mgmt_event_callback mWiFiMgmtClbk{}; + net_mgmt_event_callback mIPv6MgmtClbk{}; ScanResultCallback mScanResultCallback{ nullptr }; ScanDoneCallback mScanDoneCallback{ nullptr }; WiFiNetwork mWantedNetwork{}; From bc36b48be75cc36dbf697e238d930e039bae28aa Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 22:40:38 +0300 Subject: [PATCH 13/21] [Telink] Move NFCManagerImpl.cpp under chip_enable_nfc --- src/platform/telink/BUILD.gn | 9 +++++++-- src/platform/telink/NFCManagerImpl.cpp | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn index 3165d114987b04..4d97b41bc2f0ef 100644 --- a/src/platform/telink/BUILD.gn +++ b/src/platform/telink/BUILD.gn @@ -45,8 +45,6 @@ static_library("telink") { "ConnectivityManagerImpl.h", "InetPlatformConfig.h", "KeyValueStoreManagerImpl.h", - "NFCManagerImpl.cpp", - "NFCManagerImpl.h", "PlatformManagerImpl.h", "SystemPlatformConfig.h", ] @@ -104,6 +102,13 @@ static_library("telink") { ] } + if (chip_enable_nfc) { + sources += [ + "NFCManagerImpl.cpp", + "NFCManagerImpl.h", + ] + } + if (chip_enable_ota_requestor) { sources += [ "OTAImageProcessorImpl.cpp", diff --git a/src/platform/telink/NFCManagerImpl.cpp b/src/platform/telink/NFCManagerImpl.cpp index bb40b55305da73..084b297dfb8c46 100644 --- a/src/platform/telink/NFCManagerImpl.cpp +++ b/src/platform/telink/NFCManagerImpl.cpp @@ -17,7 +17,6 @@ #include -#if CHIP_DEVICE_CONFIG_ENABLE_NFC #include #include @@ -102,4 +101,3 @@ CHIP_ERROR NFCManagerImpl::_StopTagEmulation() } // namespace DeviceLayer } // namespace chip -#endif From cd964e348ba49b2cda583fa40b15159e7431832f Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 23:17:31 +0300 Subject: [PATCH 14/21] [Telink] Add basic switch context from BLE to WiFi --- .../platform/telink/common/src/AppTaskCommon.cpp | 6 ++++++ src/platform/telink/BLEManagerImpl.cpp | 14 ++++++++++++++ src/platform/telink/BLEManagerImpl.h | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index ca2c1d0a8b1b6d..155ec525f4e2a1 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -652,7 +652,13 @@ void AppTaskCommon::StartWiFiHandler(AppEvent * aEvent) if (!chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned()) { + // Switch context from BLE to WiFi +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + Internal::BLEManagerImpl sInstance; + sInstance.SwitchToWiFi(); +#else net_if_up(InetUtils::GetWiFiInterface()); +#endif NetworkCommissioning::TelinkWiFiDriver().StartDefaultWiFiNetwork(); } else diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index f67238a49c122b..a98778824c6420 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -46,6 +46,7 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include #include #endif @@ -984,6 +985,19 @@ void BLEManagerImpl::SwitchToIeee802154(void) ThreadStackMgrImpl().SetRadioBlocked(false); ThreadStackMgrImpl().SetThreadEnabled(true); } + +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI +void BLEManagerImpl::SwitchToWiFi(void) +{ + ChipLogProgress(DeviceLayer, "Switch context from BLE to WiFi"); + + // Deinit BLE + bt_disable(); + mBLERadioInitialized = false; + + // Init WiFi + net_if_up(InetUtils::GetWiFiInterface()); +} #endif } // namespace Internal diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index 1e1c4c94d67638..0996a062bbda24 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2022-2024 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -168,8 +168,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla static ssize_t HandleC3Read(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, uint16_t offset); #endif - /* Switch to IEEE802154 interface. @todo: remove to other module? */ + // Switch context from BLE to Thread/WiFi void SwitchToIeee802154(void); + void SwitchToWiFi(void); CHIP_ERROR StartAdvertisingProcess(void); }; From f2df9d4b1385002f80496f4066087b8e9a07b9e1 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 23:20:15 +0300 Subject: [PATCH 15/21] [Telink] Enable Thread/WiFi start buttons with enabled BLE --- examples/platform/telink/common/include/AppTaskCommon.h | 2 -- examples/platform/telink/common/src/AppTaskCommon.cpp | 6 ------ examples/platform/telink/util/include/ThreadUtil.h | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 81cbe06508393a..ff3f7bf174a939 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -103,7 +103,6 @@ class AppTaskCommon static void StartBleAdvButtonEventHandler(void); static void StartBleAdvHandler(AppEvent * aEvent); -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD static void StartThreadButtonEventHandler(void); static void StartThreadHandler(AppEvent * aEvent); @@ -111,7 +110,6 @@ class AppTaskCommon static void StartWiFiButtonEventHandler(void); static void StartWiFiHandler(AppEvent * aEvent); #endif -#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ static void ExampleActionButtonEventHandler(void); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 155ec525f4e2a1..484e3a2d3a9ccd 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -368,7 +368,6 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) case kButtonId_FactoryReset: FactoryResetButtonEventHandler(); break; -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case kButtonId_StartThread: StartThreadButtonEventHandler(); @@ -378,7 +377,6 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) StartWiFiButtonEventHandler(); break; #endif -#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ case kButtonId_StartBleAdv: StartBleAdvButtonEventHandler(); break; @@ -448,13 +446,11 @@ void AppTaskCommon::LinkButtons(ButtonManager & buttonManager) buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD buttonManager.addCallback(StartThreadButtonEventHandler, 3, true); #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI buttonManager.addCallback(StartWiFiButtonEventHandler, 3, true); #endif -#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ } void AppTaskCommon::UpdateStatusLED() @@ -597,7 +593,6 @@ void AppTaskCommon::FactoryResetTimerEventHandler(AppEvent * aEvent) LOG_INF("Factory Reset Trigger Counter is cleared"); } -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD void AppTaskCommon::StartThreadButtonEventHandler(void) { @@ -667,7 +662,6 @@ void AppTaskCommon::StartWiFiHandler(AppEvent * aEvent) } } #endif -#endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ void AppTaskCommon::ExampleActionButtonEventHandler(void) { diff --git a/examples/platform/telink/util/include/ThreadUtil.h b/examples/platform/telink/util/include/ThreadUtil.h index df5e8d2eb147ba..429d114647b4d1 100644 --- a/examples/platform/telink/util/include/ThreadUtil.h +++ b/examples/platform/telink/util/include/ThreadUtil.h @@ -19,6 +19,6 @@ #include "AppConfig.h" -#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD void StartDefaultThreadNetwork(void); #endif From 8df3f6e9c4c7d5f49abbf5307b854ee5e3deac93 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 11 Jun 2024 23:41:03 +0300 Subject: [PATCH 16/21] [Telink] Places for SwitchToWiFi on finish BLE commisioning part --- src/platform/telink/BLEManagerImpl.cpp | 3 +++ src/platform/telink/BLEManagerImpl.h | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index a98778824c6420..b37c78af4b22a8 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -963,6 +963,9 @@ CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * eve { SwitchToIeee802154(); } +#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI + // TODO: Implement ReadyToAttach for WiFi if needed + SwitchToWiFi(); #endif return CHIP_NO_ERROR; diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index 0996a062bbda24..d71b290224a11e 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -124,12 +124,13 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla CHIP_ERROR HandleBleConnectionClosed(const ChipDeviceEvent * event); /* - @todo WORKAROUND: Due to abscense of non-cuncurrent mode in Matter - we are emulating connection to Thread with this events and manually + WORKAROUND: Due to abscense of non-cuncurrent mode in Matter + we are emulating connection to Thread/WiFi with this events and manually disconnect BLE ass soon as OperationalNetworkEnabled occures. This functionality shall be removed as soon as non-cuncurrent mode would be implemented */ + // TODO: Implement something like HandleThreadStateChange for WiFi if needed CHIP_ERROR HandleThreadStateChange(const ChipDeviceEvent * event); CHIP_ERROR HandleOperationalNetworkEnabled(const ChipDeviceEvent * event); From 87f7671d3b19e64aafb448e3c8e0219c5346f6c2 Mon Sep 17 00:00:00 2001 From: Serhii Salamakha Date: Wed, 12 Jun 2024 13:11:26 +0300 Subject: [PATCH 17/21] [Telink] Enable BLE for W91 --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/Kconfig.defaults | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 14a69997f0e086..75bf944e1b722d 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -110,7 +110,7 @@ jobs: platform: telink - name: Update Zephyr to specific revision (for developers purpose) shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 107e7b646bc8f16c799f3fef2a4b2c55595be374" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 3779e40e06fa9f430497ff00bf3b6c13c1764799" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index ae6aa73c33bbd8..1510d8bf38a9c6 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -57,7 +57,7 @@ jobs: gh-context: ${{ toJson(github) }} - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 107e7b646bc8f16c799f3fef2a4b2c55595be374" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 3779e40e06fa9f430497ff00bf3b6c13c1764799" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index d52e243d4fd80c..0ecfff47cd3db3 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -108,7 +108,6 @@ config GPIO # Bluetooth Low Energy configs config BT - default n if BOARD_TLSR9118BDK40D default y if BT From f683e8e3d6aed565c36a71ec8d4729f066822d90 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 13 Jun 2024 11:14:21 +0300 Subject: [PATCH 18/21] [Telink] fix CI error --- examples/platform/telink/common/src/AppTaskCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 484e3a2d3a9ccd..28c0198dbd3b9a 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -725,7 +725,7 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* case DeviceEventType::kThreadStateChange: sIsNetworkProvisioned = ConnectivityMgr().IsThreadProvisioned(); sIsNetworkEnabled = ConnectivityMgr().IsThreadEnabled(); - sIsThreadAttached = ConnectivityMgr().IsThreadAttached(); + sIsNetworkAttached = ConnectivityMgr().IsThreadAttached(); #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI case DeviceEventType::kWiFiConnectivityChange: sIsNetworkProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); From 995d8a0b955732ed994ff3b065d55be8bf92bb37 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Mon, 17 Jun 2024 21:47:15 +0300 Subject: [PATCH 19/21] [Telink] Use BLE/WiFi concurrent mode for W91 * [Telink] Use BLE/WiFi concurrent mode for W91 * [Telink] Remove unused includes --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 2 +- .../telink/common/src/AppTaskCommon.cpp | 17 ++----- src/platform/telink/BLEManagerImpl.cpp | 48 ++++++------------- src/platform/telink/BLEManagerImpl.h | 10 ++-- 5 files changed, 28 insertions(+), 51 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 75bf944e1b722d..1787cace30b0ba 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -110,7 +110,7 @@ jobs: platform: telink - name: Update Zephyr to specific revision (for developers purpose) shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 3779e40e06fa9f430497ff00bf3b6c13c1764799" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 5ae5db00ac820fcbbcda9d7e71f0133240aa2c87" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 1510d8bf38a9c6..3fc35f5b095eb0 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -57,7 +57,7 @@ jobs: gh-context: ${{ toJson(github) }} - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 3779e40e06fa9f430497ff00bf3b6c13c1764799" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 5ae5db00ac820fcbbcda9d7e71f0133240aa2c87" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 28c0198dbd3b9a..59ad41b3c45bde 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -227,8 +227,7 @@ CHIP_ERROR AppTaskCommon::StartApp(void) #endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */ #ifdef CONFIG_BOOTLOADER_MCUBOOT - if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && - !chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned()) + if (!sIsNetworkProvisioned) { LOG_INF("Confirm image."); OtaConfirmNewImage(); @@ -521,8 +520,8 @@ void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { LOG_INF("StartBleAdvHandler"); - // Don't allow on starting Matter service BLE advertising after device provisioning. - if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) + // Disable manual Matter service BLE advertising after device provisioning. + if (sIsNetworkProvisioned) { LOG_INF("Device already commissioned"); return; @@ -607,7 +606,7 @@ void AppTaskCommon::StartThreadButtonEventHandler(void) void AppTaskCommon::StartThreadHandler(AppEvent * aEvent) { LOG_INF("StartThreadHandler"); - if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned()) + if (!sIsNetworkProvisioned) { // Switch context from BLE to Thread #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE @@ -645,15 +644,9 @@ void AppTaskCommon::StartWiFiHandler(AppEvent * aEvent) LOG_ERR("default WiFi SSID/Password are not set"); } - if (!chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned()) + if (!sIsNetworkProvisioned) { - // Switch context from BLE to WiFi -#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - Internal::BLEManagerImpl sInstance; - sInstance.SwitchToWiFi(); -#else net_if_up(InetUtils::GetWiFiInterface()); -#endif NetworkCommissioning::TelinkWiFiDriver().StartDefaultWiFiNetwork(); } else diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index b37c78af4b22a8..90277a1a623d27 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -45,11 +45,6 @@ #include #include -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include -#include -#endif - // TODO: need common mac_init solution for B9X & W91 #ifndef CONFIG_BOARD_TLSR9118BDK40D extern "C" { @@ -295,25 +290,26 @@ inline CHIP_ERROR BLEManagerImpl::PrepareAdvertisingRequest(void) CHIP_ERROR BLEManagerImpl::StartAdvertising(void) { - if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) + CHIP_ERROR err = CHIP_NO_ERROR; + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (ConnectivityMgr().IsThreadProvisioned()) { ChipLogProgress(DeviceLayer, "Device provisioned, can't StartAdvertising"); - return CHIP_ERROR_INCORRECT_STATE; + err = CHIP_ERROR_INCORRECT_STATE; } -// TODO: check if WiFi scanning required for Amazon ecosystem -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD else if (!mBLERadioInitialized) { ThreadStackMgrImpl().StartThreadScan(mInternalScanCallback); } -#endif else +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD { - return StartAdvertisingProcess(); + err = StartAdvertisingProcess(); } - return CHIP_NO_ERROR; + return err; } CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) @@ -395,12 +391,14 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { - if (ConnectivityMgr().IsThreadProvisioned() || ConnectivityMgr().IsWiFiStationProvisioned()) +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (ConnectivityMgr().IsThreadProvisioned()) { ChipLogProgress(DeviceLayer, "Device provisioned, StopAdvertising done"); return CHIP_ERROR_INCORRECT_STATE; } +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD ReturnErrorOnFailure(System::MapErrorZephyr(bt_le_adv_stop())); @@ -671,6 +669,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) err = HandleTXCharComplete(event); break; +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kThreadStateChange: err = HandleThreadStateChange(event); break; @@ -682,6 +681,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) case DeviceEventType::kOperationalNetworkEnabled: err = HandleOperationalNetworkEnabled(event); break; +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD default: break; @@ -923,6 +923,7 @@ ssize_t BLEManagerImpl::HandleC3Read(struct bt_conn * conId, const struct bt_gat } #endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) { ChipLogDetail(DeviceLayer, "HandleOperationalNetworkEnabled"); @@ -958,20 +959,14 @@ CHIP_ERROR BLEManagerImpl::HandleThreadStateChange(const ChipDeviceEvent * event CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (ThreadStackMgrImpl().IsReadyToAttach()) { SwitchToIeee802154(); } -#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI - // TODO: Implement ReadyToAttach for WiFi if needed - SwitchToWiFi(); -#endif return CHIP_NO_ERROR; } -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD void BLEManagerImpl::SwitchToIeee802154(void) { ChipLogProgress(DeviceLayer, "Switch context from BLE to Thread"); @@ -988,20 +983,7 @@ void BLEManagerImpl::SwitchToIeee802154(void) ThreadStackMgrImpl().SetRadioBlocked(false); ThreadStackMgrImpl().SetThreadEnabled(true); } - -#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI -void BLEManagerImpl::SwitchToWiFi(void) -{ - ChipLogProgress(DeviceLayer, "Switch context from BLE to WiFi"); - - // Deinit BLE - bt_disable(); - mBLERadioInitialized = false; - - // Init WiFi - net_if_up(InetUtils::GetWiFiInterface()); -} -#endif +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD } // namespace Internal } // namespace DeviceLayer diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index d71b290224a11e..923d24f8380ff0 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -125,14 +125,15 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla /* WORKAROUND: Due to abscense of non-cuncurrent mode in Matter - we are emulating connection to Thread/WiFi with this events and manually + we are emulating connection to Thread with this events and manually disconnect BLE ass soon as OperationalNetworkEnabled occures. This functionality shall be removed as soon as non-cuncurrent mode would be implemented */ - // TODO: Implement something like HandleThreadStateChange for WiFi if needed +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR HandleThreadStateChange(const ChipDeviceEvent * event); CHIP_ERROR HandleOperationalNetworkEnabled(const ChipDeviceEvent * event); +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD InternalScanCallback * mInternalScanCallback; @@ -169,9 +170,10 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla static ssize_t HandleC3Read(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, uint16_t offset); #endif - // Switch context from BLE to Thread/WiFi +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + // Switch context from BLE to Thread void SwitchToIeee802154(void); - void SwitchToWiFi(void); +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR StartAdvertisingProcess(void); }; From f01eedac1b3d98456e10c882df60d00d59051e72 Mon Sep 17 00:00:00 2001 From: Serhii Salamakha Date: Wed, 19 Jun 2024 10:24:01 +0300 Subject: [PATCH 20/21] [Telink] Update set ble mac address for w91 and b9x --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/Kconfig.defaults | 6 ++++-- src/platform/telink/BLEManagerImpl.cpp | 10 ++-------- src/platform/telink/tlsr9118bdk40d_3m_flash.overlay | 3 ++- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 1787cace30b0ba..bbeb41e600559e 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -110,7 +110,7 @@ jobs: platform: telink - name: Update Zephyr to specific revision (for developers purpose) shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 5ae5db00ac820fcbbcda9d7e71f0133240aa2c87" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 3fc35f5b095eb0..ed959d2b73f79a 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -57,7 +57,7 @@ jobs: gh-context: ${{ toJson(github) }} - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 5ae5db00ac820fcbbcda9d7e71f0133240aa2c87" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 0ecfff47cd3db3..ea5a6822b74cb5 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -137,10 +137,12 @@ config BT_BUF_ACL_TX_SIZE default 251 config BT_RX_STACK_SIZE - default 810 + default 810 if BT_B9X + default 2048 if BT_W91 config BT_HCI_TX_STACK_SIZE - default 640 + default 640 if BT_B9X + default 2048 if BT_W91 config BT_DEVICE_NAME_GATT_WRITABLE bool diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index 90277a1a623d27..fa8611982d8b03 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -45,12 +45,9 @@ #include #include -// TODO: need common mac_init solution for B9X & W91 -#ifndef CONFIG_BOARD_TLSR9118BDK40D extern "C" { -#include +extern __attribute__((noinline)) void telink_bt_blc_mac_init(uint8_t *bt_mac); } -#endif #if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) #include @@ -120,10 +117,7 @@ CHIP_ERROR InitBLEMACAddress() int error = 0; bt_addr_le_t addr; -// TODO: need common mac_init solution for B9X & W91 -#ifndef CONFIG_BOARD_TLSR9118BDK40D - b9x_bt_blc_mac_init(addr.a.val); -#endif + telink_bt_blc_mac_init(addr.a.val); if (BT_ADDR_IS_STATIC(&addr.a)) // in case of Random static address, create a new id { diff --git a/src/platform/telink/tlsr9118bdk40d_3m_flash.overlay b/src/platform/telink/tlsr9118bdk40d_3m_flash.overlay index 3e42145fb44370..02cd3b6582c8e0 100644 --- a/src/platform/telink/tlsr9118bdk40d_3m_flash.overlay +++ b/src/platform/telink/tlsr9118bdk40d_3m_flash.overlay @@ -7,6 +7,7 @@ /delete-node/ partition@88000; /delete-node/ partition@f0000; /delete-node/ partition@f4000; + /delete-node/ partition@fe000; boot_partition: partition@0 { label = "mcuboot"; reg = <0x00000000 0x20000>; @@ -27,7 +28,7 @@ label = "image-1"; reg = <0x118000 0xe8000>; }; - reserved_partition: partition@200000 { + vendor_partition: partition@200000 { label = "vendor-data"; reg = <0x200000 0x100000>; }; From 8714155d6c9c2dca32a9307ee187bfff094d63b3 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Thu, 20 Jun 2024 11:40:42 +0300 Subject: [PATCH 21/21] [Telink] Update to docker version 57 --- .github/workflows/chef.yaml | 8 ++++---- .github/workflows/examples-telink.yaml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index bbeb41e600559e..b3d3f7f3a90f7c 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -98,7 +98,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:54 + image: ghcr.io/project-chip/chip-build-telink:57 options: --user root steps: @@ -108,9 +108,9 @@ jobs: uses: ./.github/actions/checkout-submodules-and-bootstrap with: platform: telink - - name: Update Zephyr to specific revision (for developers purpose) - shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" + # - name: Update Zephyr to specific revision (for developers purpose) + # shell: bash + # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index ed959d2b73f79a..15926e99cd470c 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -38,7 +38,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:54 + image: ghcr.io/project-chip/chip-build-telink:57 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" @@ -56,8 +56,8 @@ jobs: with: gh-context: ${{ toJson(github) }} - - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" + # - name: Update Zephyr to specific revision (for developers purpose) + # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab81a585fca6a83b30e1f4e58a021113d6a3acb8" - name: Build example Telink (B92 retention) Air Quality Sensor App run: |