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 69252b66a0ecef..2599dc1f0f31a3 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 @@ -123,7 +130,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 { @@ -290,16 +300,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(); @@ -314,11 +327,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)); @@ -385,9 +400,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; } @@ -948,20 +963,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; @@ -969,10 +986,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