Skip to content

Commit 3951efb

Browse files
authored
Tizen WiFi and bluetooth fix (project-chip#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
1 parent e64736c commit 3951efb

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

examples/all-clusters-app/tizen/tizen-manifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<privilege>http://tizen.org/privilege/internet</privilege>
1010
<privilege>http://tizen.org/privilege/network.get</privilege>
1111
<privilege>http://tizen.org/privilege/network.set</privilege>
12+
<privilege>http://tizen.org/privilege/network.profile</privilege>
1213
</privileges>
1314
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
1415
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>

examples/all-clusters-minimal-app/tizen/tizen-manifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<privilege>http://tizen.org/privilege/internet</privilege>
1010
<privilege>http://tizen.org/privilege/network.get</privilege>
1111
<privilege>http://tizen.org/privilege/network.set</privilege>
12+
<privilege>http://tizen.org/privilege/network.profile</privilege>
1213
</privileges>
1314
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
1415
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>

examples/lighting-app/tizen/src/main.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <app-common/zap-generated/ids/Attributes.h>
2020
#include <app-common/zap-generated/ids/Clusters.h>
2121
#include <app/ConcreteAttributePath.h>
22+
#include <app/clusters/network-commissioning/network-commissioning.h>
23+
#include <platform/Tizen/NetworkCommissioningDriver.h>
2224

2325
#include <LightingManager.h>
2426
#include <TizenServiceAppMain.h>
@@ -27,6 +29,13 @@ using namespace chip;
2729
using namespace chip::app;
2830
using namespace chip::app::Clusters;
2931

32+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
33+
namespace {
34+
DeviceLayer::NetworkCommissioning::TizenWiFiDriver sTizenWiFiDriver;
35+
Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sTizenWiFiDriver);
36+
} // namespace
37+
#endif
38+
3039
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
3140
uint8_t * value)
3241
{
@@ -36,7 +45,12 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
3645
}
3746
}
3847

39-
void ApplicationInit() {}
48+
void ApplicationInit()
49+
{
50+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
51+
sWiFiNetworkCommissioningInstance.Init();
52+
#endif
53+
}
4054

4155
int main(int argc, char * argv[])
4256
{

examples/lighting-app/tizen/tizen-manifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<privilege>http://tizen.org/privilege/internet</privilege>
1010
<privilege>http://tizen.org/privilege/network.get</privilege>
1111
<privilege>http://tizen.org/privilege/network.set</privilege>
12+
<privilege>http://tizen.org/privilege/network.profile</privilege>
1213
</privileges>
1314
<feature name="http://tizen.org/feature/network.bluetooth">true</feature>
1415
<feature name="http://tizen.org/feature/network.bluetooth.le">true</feature>

src/platform/Tizen/BLEManagerImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ int BLEManagerImpl::StartBLEAdvertising()
668668
VerifyOrExit(ret == BT_ERROR_NONE,
669669
ChipLogError(DeviceLayer, "bt_adapter_le_add_advertising_service_data() failed. ret: %d", ret));
670670

671+
ret = bt_adapter_le_set_advertising_device_name(mAdvertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, true);
672+
VerifyOrExit(ret == BT_ERROR_NONE,
673+
ChipLogError(DeviceLayer, "bt_adapter_le_set_advertising_device_name() failed. ret: %d", ret));
674+
671675
BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(true, nullptr);
672676

673677
ret = bt_adapter_le_start_advertising_new(mAdvertiser, AdvertisingStateChangedCb, nullptr);

src/platform/Tizen/WiFiManager.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <lib/support/CodeUtils.h>
3030
#include <lib/support/Span.h>
3131
#include <lib/support/logging/CHIPLogging.h>
32+
#include <platform/PlatformManager.h>
3233

3334
#include "MainLoop.h"
3435

@@ -272,22 +273,26 @@ void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData)
272273
{
273274
auto loop = reinterpret_cast<GMainLoop *>(userData);
274275

275-
if (wifiErr == WIFI_MANAGER_ERROR_NONE)
276+
if (wifiErr == WIFI_MANAGER_ERROR_NONE || wifiErr == WIFI_MANAGER_ERROR_ALREADY_EXISTS)
276277
{
277278
ChipLogProgress(DeviceLayer, "WiFi is connected");
278279
if (sInstance.mpConnectCallback != nullptr)
279280
{
281+
chip::DeviceLayer::PlatformMgr().LockChipStack();
280282
sInstance.mpConnectCallback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0);
281283
sInstance.mpConnectCallback = nullptr;
284+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
282285
}
283286
}
284287
else
285288
{
286289
ChipLogError(DeviceLayer, "FAIL: connect WiFi [%s]", get_error_message(wifiErr));
287290
if (sInstance.mpConnectCallback != nullptr)
288291
{
292+
chip::DeviceLayer::PlatformMgr().LockChipStack();
289293
sInstance.mpConnectCallback->OnResult(NetworkCommissioning::Status::kUnknownError, CharSpan(), 0);
290294
sInstance.mpConnectCallback = nullptr;
295+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
291296
}
292297
}
293298

0 commit comments

Comments
 (0)