Skip to content

Commit

Permalink
[Tizen] Enable WiFi management from example app (#23633)
Browse files Browse the repository at this point in the history
* [Tizen] Simplify WiFiManager::IsActivated usage

* Apply clang-tidy modernize-redundant-void-arg

* Fix incorrect feature flag for enabling WiFi

* [Tizen] Implement WiFi started check function

The IsWiFiManagementStarted is used by the example Linux applications to
check whether CHIP applications is connected with wpa_supplicant WiFi
manager. Since Tizen examples are based on Linux code and Tizen uses
wpa_supplicant as well, Tizen should also implement such check function.

* Activate/deactivate WiFi without async wrapper

* Add network.set privilege required for WiFi management

* Fix compilation failure after syncing with master
  • Loading branch information
arkq authored and pull[bot] committed Sep 13, 2023
1 parent 304b0a9 commit 2581709
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 80 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 @@ -8,6 +8,7 @@
<privilege>http://tizen.org/privilege/bluetooth</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</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 @@ -8,6 +8,7 @@
<privilege>http://tizen.org/privilege/bluetooth</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</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/lighting-app/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<privilege>http://tizen.org/privilege/bluetooth</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</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
2 changes: 1 addition & 1 deletion examples/platform/tizen/OptionsProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static constexpr Option sOptions[] = {
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
{ "ble-device", false },
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
{ "wifi", true },
#endif
#if CHIP_ENABLE_OPENTHREAD
Expand Down
2 changes: 0 additions & 2 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
"CHIP_DEVICE_LAYER_TARGET=Tizen",
"CHIP_DEVICE_CONFIG_ENABLE_WIFI=${chip_enable_wifi}",
]
defines -=
[ "CHIP_DEVICE_CONFIG_ENABLE_WPA=${chip_device_config_enable_wpa}" ]
} else if (chip_device_platform == "nrfconnect") {
defines += [
"CHIP_DEVICE_LAYER_TARGET_NRFCONNECT=1",
Expand Down
14 changes: 6 additions & 8 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,21 @@ void ConnectivityManagerImpl::_SetWiFiAPIdleTimeout(System::Clock::Timeout val)

void ConnectivityManagerImpl::StartWiFiManagement()
{
SystemLayer().ScheduleWork(ActivateWiFiManager, nullptr);
Internal::WiFiMgr().Activate();
}

void ConnectivityManagerImpl::StopWiFiManagement()
{
SystemLayer().ScheduleWork(DeactivateWiFiManager, nullptr);
Internal::WiFiMgr().Deactivate();
}

void ConnectivityManagerImpl::ActivateWiFiManager(System::Layer * aLayer, void * aAppState)
bool ConnectivityManagerImpl::IsWiFiManagementStarted()
{
Internal::WiFiMgr().Activate();
bool isActivated = false;
Internal::WiFiMgr().IsActivated(&isActivated);
return isActivated;
}

void ConnectivityManagerImpl::DeactivateWiFiManager(System::Layer * aLayer, void * aAppState)
{
Internal::WiFiMgr().Deactivate();
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

} // namespace DeviceLayer
Expand Down
8 changes: 3 additions & 5 deletions src/platform/Tizen/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

public:
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
void StartWiFiManagement(void);
void StopWiFiManagement(void);
void StartWiFiManagement();
void StopWiFiManagement();
bool IsWiFiManagementStarted();
#endif

private:
Expand Down Expand Up @@ -115,9 +116,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void _MaintainOnDemandWiFiAP(void);
System::Clock::Timeout _GetWiFiAPIdleTimeout(void);
void _SetWiFiAPIdleTimeout(System::Clock::Timeout val);

static void ActivateWiFiManager(System::Layer * aLayer, void * aAppState);
static void DeactivateWiFiManager(System::Layer * aLayer, void * aAppState);
#endif

// ===== Members for internal use by the following friends.
Expand Down
86 changes: 33 additions & 53 deletions src/platform/Tizen/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,41 +601,26 @@ void WiFiManager::Deinit()

CHIP_ERROR WiFiManager::IsActivated(bool * isWiFiActivated)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int wifiErr = WIFI_MANAGER_ERROR_NONE;

wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, isWiFiActivated);
if (wifiErr == WIFI_MANAGER_ERROR_NONE)
{
ChipLogProgress(DeviceLayer, "WiFi is %s", *isWiFiActivated ? "activated" : "deactivated");
}
else
{
err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr));
}

return err;
int wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, isWiFiActivated);
VerifyOrReturnError(wifiErr == WIFI_MANAGER_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE,
ChipLogError(DeviceLayer, "FAIL: Check whether WiFi is activated: %s", get_error_message(wifiErr)));
return CHIP_NO_ERROR;
}

CHIP_ERROR WiFiManager::Activate()
{
CHIP_ERROR err = CHIP_NO_ERROR;
int wifiErr = WIFI_MANAGER_ERROR_NONE;
bool isWiFiActivated = false;
bool dbusAsyncErr = false;

wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWiFiActivated);
VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr)));

VerifyOrExit((err = IsActivated(&isWiFiActivated)) == CHIP_NO_ERROR, );
VerifyOrExit(isWiFiActivated == false, ChipLogProgress(DeviceLayer, "WiFi is already activated"));

dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiActivate);
if (dbusAsyncErr == false)
{
err = CHIP_ERROR_INCORRECT_STATE;
}
VerifyOrExit(dbusAsyncErr == true, {
ChipLogError(DeviceLayer, "FAIL: Async request: Activate WiFi");
err = CHIP_ERROR_INTERNAL;
});

exit:
return err;
Expand All @@ -644,21 +629,17 @@ CHIP_ERROR WiFiManager::Activate()
CHIP_ERROR WiFiManager::Deactivate()
{
CHIP_ERROR err = CHIP_NO_ERROR;
int wifiErr = WIFI_MANAGER_ERROR_NONE;
bool isWiFiActivated = false;
bool dbusAsyncErr = false;

wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWiFiActivated);
VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr)));

VerifyOrExit((err = IsActivated(&isWiFiActivated)) == CHIP_NO_ERROR, );
VerifyOrExit(isWiFiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is already deactivated"));

dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiDeactivate);
if (dbusAsyncErr == false)
{
err = CHIP_ERROR_INCORRECT_STATE;
}
VerifyOrExit(dbusAsyncErr == true, {
ChipLogError(DeviceLayer, "FAIL: Async request: Deactivate WiFi");
err = CHIP_ERROR_INTERNAL;
});

exit:
return err;
Expand All @@ -668,38 +649,37 @@ CHIP_ERROR WiFiManager::Connect(const char * ssid, const char * key,
DeviceLayer::NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * apCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int wifiErr = WIFI_MANAGER_ERROR_NONE;
bool isWiFiActivated = false;
bool dbusAsyncErr = false;
wifi_manager_ap_h foundAp = nullptr;

g_strlcpy(sInstance.mWiFiSSID, ssid, sizeof(sInstance.mWiFiSSID));
g_strlcpy(sInstance.mWiFiKey, key, sizeof(sInstance.mWiFiKey));

wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWiFiActivated);
VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr)));

VerifyOrExit(isWiFiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is deactivated"));
VerifyOrExit((err = IsActivated(&isWiFiActivated)) == CHIP_NO_ERROR, );
VerifyOrExit(isWiFiActivated == true, {
ChipLogProgress(DeviceLayer, "WiFi is not activated");
err = CHIP_ERROR_INCORRECT_STATE;
});

sInstance.mpConnectCallback = apCallback;

foundAp = sInstance._WiFiGetFoundAP();
if (foundAp != nullptr)
{
dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiConnect, static_cast<gpointer>(foundAp));
if (dbusAsyncErr == false)
{
err = CHIP_ERROR_INCORRECT_STATE;
}
dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiConnect, foundAp);
VerifyOrExit(dbusAsyncErr == true, {
ChipLogError(DeviceLayer, "FAIL: Async request: Connect WiFi");
err = CHIP_ERROR_INTERNAL;
});
}
else
{
dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiScan);
if (dbusAsyncErr == false)
{
err = CHIP_ERROR_INCORRECT_STATE;
}
VerifyOrExit(dbusAsyncErr == true, {
ChipLogError(DeviceLayer, "FAIL: Async request: Scan WiFi");
err = CHIP_ERROR_INTERNAL;
});
}

exit:
Expand All @@ -715,11 +695,11 @@ CHIP_ERROR WiFiManager::Disconnect(const char * ssid)

g_strlcpy(sInstance.mWiFiSSID, ssid, sizeof(sInstance.mWiFiSSID));

wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWiFiActivated);
VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr)));

VerifyOrExit(isWiFiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is deactivated"));
VerifyOrExit((err = IsActivated(&isWiFiActivated)) == CHIP_NO_ERROR, );
VerifyOrExit(isWiFiActivated == true, {
ChipLogProgress(DeviceLayer, "WiFi is not activated");
err = CHIP_ERROR_INCORRECT_STATE;
});

foundAp = sInstance._WiFiGetFoundAP();
VerifyOrExit(foundAp != nullptr, );
Expand Down
22 changes: 11 additions & 11 deletions src/platform/Tizen/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class WiFiManager
friend class ConnectivityManagerImpl;

public:
void Init(void);
void Deinit(void);
void Init();
void Deinit();

CHIP_ERROR IsActivated(bool * isWiFiActivated);
CHIP_ERROR Activate(void);
CHIP_ERROR Deactivate(void);
CHIP_ERROR Activate();
CHIP_ERROR Deactivate();
CHIP_ERROR Connect(const char * ssid, const char * key,
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * apCallback = nullptr);
CHIP_ERROR Disconnect(const char * ssid);
CHIP_ERROR RemoveAllConfigs(void);
CHIP_ERROR RemoveAllConfigs();

CHIP_ERROR GetDeviceMACAddress(uint8_t * macAddress, size_t macAddressLen);
CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState);
Expand Down Expand Up @@ -75,16 +75,16 @@ class WiFiManager
static gboolean _WiFiScan(GMainLoop * mainLoop, gpointer userData);
static gboolean _WiFiConnect(GMainLoop * mainLoop, gpointer userData);

void _WiFiDeinitialize(void);
void _WiFiSetStates(void);
void _WiFiSetCallbacks(void);
void _WiFiUnsetCallbacks(void);
void _WiFiDeinitialize();
void _WiFiSetStates();
void _WiFiSetCallbacks();
void _WiFiUnsetCallbacks();
void _WiFiSetDeviceState(wifi_manager_device_state_e deviceState);
void _WiFiSetModuleState(wifi_manager_module_state_e moduleState);
void _WiFiSetConnectionState(wifi_manager_connection_state_e connectionState);
wifi_manager_ap_h _WiFiGetFoundAP(void);
wifi_manager_ap_h _WiFiGetFoundAP();

friend WiFiManager & WiFiMgr(void);
friend WiFiManager & WiFiMgr();

static WiFiManager sInstance;

Expand Down

0 comments on commit 2581709

Please sign in to comment.