Skip to content

Commit

Permalink
[Tizen] Add wifi ap and station functionality (#10049)
Browse files Browse the repository at this point in the history
* Add wifi ap and station functionality

Signed-off-by: hyunuktak <[email protected]>

* Apply comment for WiFi

* Apply comment for SoftAP

* Apply a comment

* Restyle

* Apply a comment for key length

* Remove exit section

* Set flag as 0 for WIFI_AP

* Apply a comment for setting wifi station mode
  • Loading branch information
hyunuktak authored Oct 19, 2021
1 parent 1623b4b commit 4c7f664
Show file tree
Hide file tree
Showing 7 changed files with 1,063 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/platform/Tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ static_library("Tizen") {
"PosixConfig.h",
"SystemPlatformConfig.h",
"SystemTimeSupport.cpp",
"WiFiManager.cpp",
"WiFiManager.h",
]

deps = [ "${chip_root}/src/setup_payload" ]
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Tizen/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// ==================== Platform Adaptations ====================

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0

#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0
Expand Down
123 changes: 110 additions & 13 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;
CHIP_ERROR ConnectivityManagerImpl::_Init(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;

mWiFiStationMode = kWiFiStationMode_Disabled;
mWiFiAPMode = kWiFiAPMode_Disabled;
mWiFiAPState = kWiFiAPState_NotActive;
mLastAPDemandTime = 0;
mWiFiStationReconnectIntervalMS = CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL;
mWiFiAPIdleTimeoutMS = CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT;

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
WiFiMgr().Init();
#endif

return err;
}

Expand All @@ -60,68 +72,153 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {}

ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void)
{
return ConnectivityManager::kWiFiStationMode_NotSupported;
CHIP_ERROR err = CHIP_NO_ERROR;
wifi_manager_device_state_e deviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;

ReturnErrorCodeIf(mWiFiStationMode == kWiFiStationMode_ApplicationControlled, mWiFiStationMode);

err = WiFiMgr().GetDeviceState(&deviceState);
VerifyOrReturnError(err == CHIP_NO_ERROR, mWiFiStationMode);

mWiFiStationMode = (deviceState == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) ? kWiFiStationMode_Enabled : kWiFiStationMode_Disabled;

return mWiFiStationMode;
}

CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
CHIP_ERROR err = CHIP_NO_ERROR;
wifi_manager_device_state_e deviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;

ReturnErrorCodeIf(val == kWiFiStationMode_NotSupported, CHIP_ERROR_INVALID_ARGUMENT);

if (val != kWiFiStationMode_ApplicationControlled)
{
deviceState =
(val == kWiFiStationMode_Disabled) ? WIFI_MANAGER_DEVICE_STATE_DEACTIVATED : WIFI_MANAGER_DEVICE_STATE_ACTIVATED;
err = WiFiMgr().SetDeviceState(deviceState);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
}

if (mWiFiStationMode != val)
{
ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode),
WiFiStationModeToStr(val));

mWiFiStationMode = val;
}

return err;
}

uint32_t ConnectivityManagerImpl::_GetWiFiStationReconnectIntervalMS(void)
{
return 0;
return mWiFiStationReconnectIntervalMS;
}

CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationReconnectIntervalMS(uint32_t val)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
mWiFiStationReconnectIntervalMS = val;

return CHIP_NO_ERROR;
}

bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void)
{
return false;
bool isWifiStationEnabled = false;

WiFiMgr().IsActivated(&isWifiStationEnabled);

return isWifiStationEnabled;
}

bool ConnectivityManagerImpl::_IsWiFiStationConnected(void)
{
return false;
}
CHIP_ERROR err = CHIP_NO_ERROR;
wifi_manager_connection_state_e connectionState = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
bool isWifiStationConnected = false;

bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled(void)
{
return false;
err = WiFiMgr().GetConnectionState(&connectionState);
VerifyOrReturnError(err == CHIP_NO_ERROR, isWifiStationConnected);

if (connectionState == WIFI_MANAGER_CONNECTION_STATE_CONNECTED)
isWifiStationConnected = true;

return isWifiStationConnected;
}

bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void)
{
return false;
CHIP_ERROR err = CHIP_NO_ERROR;
wifi_manager_connection_state_e connectionState = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
bool isWifiStationProvisioned = false;

err = WiFiMgr().GetConnectionState(&connectionState);
VerifyOrReturnError(err == CHIP_NO_ERROR, isWifiStationProvisioned);

if (connectionState >= WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION)
isWifiStationProvisioned = true;

return isWifiStationProvisioned;
}

void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) {}
void ConnectivityManagerImpl::_ClearWiFiStationProvision(void)
{
WiFiMgr().RemoveAllConfigs();
}

bool ConnectivityManagerImpl::_CanStartWiFiScan(void)
{
return false;
}

ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode()
{
return mWiFiAPMode;
}

CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

bool ConnectivityManagerImpl::_IsWiFiAPActive()
{
return mWiFiAPState == kWiFiAPState_Active;
}

void ConnectivityManagerImpl::_DemandStartWiFiAP(void) {}

void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) {}

void ConnectivityManagerImpl::_MaintainOnDemandWiFiAP(void) {}

void ConnectivityManagerImpl::_SetWiFiAPIdleTimeoutMS(uint32_t val) {}

void ConnectivityManagerImpl::StartWiFiManagement(void)
{
SystemLayer().ScheduleWork(ActivateWiFiManager, NULL);
}

void ConnectivityManagerImpl::StopWiFiManagement(void)
{
SystemLayer().ScheduleWork(DeactivateWiFiManager, NULL);
}

void ConnectivityManagerImpl::ActivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState)
{
WiFiMgr().Activate();
}

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

CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
return WiFiMgr().Connect(ssid, key);
}

} // namespace DeviceLayer
Expand Down
19 changes: 13 additions & 6 deletions src/platform/Tizen/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include <platform/internal/GenericConnectivityManagerImpl_NoWiFi.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include "WiFiManager.h"
#endif

namespace chip {
namespace Inet {
class IPAddress;
Expand Down Expand Up @@ -74,6 +78,11 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
public:
CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key);

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
void StartWiFiManagement(void);
void StopWiFiManagement(void);
#endif

private:
// ===== Members that implement the ConnectivityManager abstract interface.

Expand Down Expand Up @@ -101,6 +110,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void _MaintainOnDemandWiFiAP(void);
uint32_t _GetWiFiAPIdleTimeoutMS(void);
void _SetWiFiAPIdleTimeoutMS(uint32_t val);

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

// ===== Members for internal use by the following friends.
Expand All @@ -121,12 +133,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
};

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
inline ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode()
{
return ConnectivityManager::kWiFiAPMode_NotSupported;
}

inline bool ConnectivityManagerImpl::_IsWiFiAPActive()
inline bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled(void)
{
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion src/platform/Tizen/DeviceNetworkProvisioningDelegateImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ namespace DeviceLayer {

CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionWiFiNetwork(const char * ssid, const char * key)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NetworkProvisioning, "TizenNetworkProvisioningDelegate: SSID: %s", ssid);

err = ConnectivityMgrImpl().ProvisionWiFiNetwork(ssid, key);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NetworkProvisioning, "Failed to connect to WiFi network: %s", chip::ErrorStr(err));
}

return err;
}

} // namespace DeviceLayer
Expand Down
Loading

0 comments on commit 4c7f664

Please sign in to comment.