From 18850256fd69928c6930a88cb45e4794ab2009b3 Mon Sep 17 00:00:00 2001 From: Jakub Date: Tue, 21 Feb 2023 08:25:20 +0100 Subject: [PATCH] Tizen WiFi and bluetooth fix (#25186) * Add missing privileges * Init network commissioning interface * add LockChipStack wifi in callback thread * Advertise device name * Add privilege to allow wifi managment in app * Allow the device to be already connected to the wifi * Fix includes --- .../all-clusters-app/tizen/tizen-manifest.xml | 1 + .../tizen/tizen-manifest.xml | 1 + examples/lighting-app/tizen/src/main.cpp | 16 +++++++++++++++- examples/lighting-app/tizen/tizen-manifest.xml | 1 + src/platform/Tizen/BLEManagerImpl.cpp | 4 ++++ src/platform/Tizen/WiFiManager.cpp | 7 ++++++- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/all-clusters-app/tizen/tizen-manifest.xml b/examples/all-clusters-app/tizen/tizen-manifest.xml index c96e765d907f09..5ad377712037e7 100644 --- a/examples/all-clusters-app/tizen/tizen-manifest.xml +++ b/examples/all-clusters-app/tizen/tizen-manifest.xml @@ -9,6 +9,7 @@ http://tizen.org/privilege/internet http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set + http://tizen.org/privilege/network.profile true true diff --git a/examples/all-clusters-minimal-app/tizen/tizen-manifest.xml b/examples/all-clusters-minimal-app/tizen/tizen-manifest.xml index f97f57a53591fe..cbd365aec78e74 100644 --- a/examples/all-clusters-minimal-app/tizen/tizen-manifest.xml +++ b/examples/all-clusters-minimal-app/tizen/tizen-manifest.xml @@ -9,6 +9,7 @@ http://tizen.org/privilege/internet http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set + http://tizen.org/privilege/network.profile true true diff --git a/examples/lighting-app/tizen/src/main.cpp b/examples/lighting-app/tizen/src/main.cpp index 5c9ba03b675bd1..e69bc25fdc1c7a 100644 --- a/examples/lighting-app/tizen/src/main.cpp +++ b/examples/lighting-app/tizen/src/main.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -27,6 +29,13 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +namespace { +DeviceLayer::NetworkCommissioning::TizenWiFiDriver sTizenWiFiDriver; +Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sTizenWiFiDriver); +} // namespace +#endif + void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) { @@ -36,7 +45,12 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & } } -void ApplicationInit() {} +void ApplicationInit() +{ +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + sWiFiNetworkCommissioningInstance.Init(); +#endif +} int main(int argc, char * argv[]) { diff --git a/examples/lighting-app/tizen/tizen-manifest.xml b/examples/lighting-app/tizen/tizen-manifest.xml index 68b034c9fd66cc..4cb6047b528173 100644 --- a/examples/lighting-app/tizen/tizen-manifest.xml +++ b/examples/lighting-app/tizen/tizen-manifest.xml @@ -9,6 +9,7 @@ http://tizen.org/privilege/internet http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set + http://tizen.org/privilege/network.profile true true diff --git a/src/platform/Tizen/BLEManagerImpl.cpp b/src/platform/Tizen/BLEManagerImpl.cpp index 9b2d5e2537fe51..c33326f659a9ee 100644 --- a/src/platform/Tizen/BLEManagerImpl.cpp +++ b/src/platform/Tizen/BLEManagerImpl.cpp @@ -668,6 +668,10 @@ int BLEManagerImpl::StartBLEAdvertising() VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_add_advertising_service_data() failed. ret: %d", ret)); + ret = bt_adapter_le_set_advertising_device_name(mAdvertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, true); + VerifyOrExit(ret == BT_ERROR_NONE, + ChipLogError(DeviceLayer, "bt_adapter_le_set_advertising_device_name() failed. ret: %d", ret)); + BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(true, nullptr); ret = bt_adapter_le_start_advertising_new(mAdvertiser, AdvertisingStateChangedCb, nullptr); diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index 10678d271dbdfd..13c27dd541576e 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "MainLoop.h" @@ -272,13 +273,15 @@ void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData) { auto loop = reinterpret_cast(userData); - if (wifiErr == WIFI_MANAGER_ERROR_NONE) + if (wifiErr == WIFI_MANAGER_ERROR_NONE || wifiErr == WIFI_MANAGER_ERROR_ALREADY_EXISTS) { ChipLogProgress(DeviceLayer, "WiFi is connected"); if (sInstance.mpConnectCallback != nullptr) { + chip::DeviceLayer::PlatformMgr().LockChipStack(); sInstance.mpConnectCallback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0); sInstance.mpConnectCallback = nullptr; + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); } } else @@ -286,8 +289,10 @@ void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData) ChipLogError(DeviceLayer, "FAIL: connect WiFi [%s]", get_error_message(wifiErr)); if (sInstance.mpConnectCallback != nullptr) { + chip::DeviceLayer::PlatformMgr().LockChipStack(); sInstance.mpConnectCallback->OnResult(NetworkCommissioning::Status::kUnknownError, CharSpan(), 0); sInstance.mpConnectCallback = nullptr; + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); } }