Skip to content

Commit

Permalink
Tizen WiFi and bluetooth fix (#25186)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jlatusek authored and pull[bot] committed Jul 8, 2023
1 parent fa47bbb commit 3668022
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/all-clusters-app/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>
</privileges>
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-minimal-app/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>
</privileges>
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>
Expand Down
16 changes: 15 additions & 1 deletion examples/lighting-app/tizen/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <platform/Tizen/NetworkCommissioningDriver.h>

#include <LightingManager.h>
#include <TizenServiceAppMain.h>
Expand All @@ -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)
{
Expand All @@ -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[])
{
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>
</privileges>
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/platform/Tizen/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/PlatformManager.h>

#include "MainLoop.h"

Expand Down Expand Up @@ -272,22 +273,26 @@ void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData)
{
auto loop = reinterpret_cast<GMainLoop *>(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
{
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();
}
}

Expand Down

0 comments on commit 3668022

Please sign in to comment.