From 063d97f33d21f0dd4520e3f5cb5e41bfe9dae55e Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 29 Sep 2021 17:36:32 +0900 Subject: [PATCH 1/9] Add wifi ap and station functionality Signed-off-by: hyunuktak --- src/platform/Tizen/BUILD.gn | 4 + src/platform/Tizen/CHIPDevicePlatformConfig.h | 4 +- .../Tizen/ConnectivityManagerImpl.cpp | 200 ++++- src/platform/Tizen/ConnectivityManagerImpl.h | 22 +- .../DeviceNetworkProvisioningDelegateImpl.cpp | 12 +- src/platform/Tizen/SoftAPManager.cpp | 565 ++++++++++++ src/platform/Tizen/SoftAPManager.h | 71 ++ src/platform/Tizen/WiFiManager.cpp | 820 ++++++++++++++++++ src/platform/Tizen/WiFiManager.h | 93 ++ 9 files changed, 1766 insertions(+), 25 deletions(-) create mode 100644 src/platform/Tizen/SoftAPManager.cpp create mode 100644 src/platform/Tizen/SoftAPManager.h create mode 100644 src/platform/Tizen/WiFiManager.cpp create mode 100644 src/platform/Tizen/WiFiManager.h diff --git a/src/platform/Tizen/BUILD.gn b/src/platform/Tizen/BUILD.gn index c30f733107de57..b46269b7f9ffd7 100644 --- a/src/platform/Tizen/BUILD.gn +++ b/src/platform/Tizen/BUILD.gn @@ -50,8 +50,12 @@ static_library("Tizen") { "PlatformManagerImpl.h", "PosixConfig.cpp", "PosixConfig.h", + "SoftAPManager.cpp", + "SoftAPManager.h", "SystemPlatformConfig.h", "SystemTimeSupport.cpp", + "WiFiManager.cpp", + "WiFiManager.h", ] deps = [ "${chip_root}/src/setup_payload" ] diff --git a/src/platform/Tizen/CHIPDevicePlatformConfig.h b/src/platform/Tizen/CHIPDevicePlatformConfig.h index dac49181253831..35e80c6ee5415c 100644 --- a/src/platform/Tizen/CHIPDevicePlatformConfig.h +++ b/src/platform/Tizen/CHIPDevicePlatformConfig.h @@ -26,8 +26,8 @@ // ==================== Platform Adaptations ==================== -#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 -#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0 diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp index 0e869e567b1052..0364628bb59d3e 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -51,6 +51,19 @@ 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 + Internal::WiFiManager::Init(); + Internal::SoftAPManager::Init(); +#endif + return err; } @@ -60,68 +73,223 @@ 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; + + if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) + { + err = Internal::WiFiManager::GetDeviceState(&deviceState); + SuccessOrExit(err); + + if (deviceState == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) + { + mWiFiStationMode = kWiFiStationMode_Enabled; + } + else + { + mWiFiStationMode = kWiFiStationMode_Disabled; + } + } + +exit: + 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; + + VerifyOrExit(val != kWiFiStationMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrExit(val != kWiFiStationMode_ApplicationControlled, ); + + deviceState = (val == kWiFiStationMode_Disabled) ? WIFI_MANAGER_DEVICE_STATE_DEACTIVATED : WIFI_MANAGER_DEVICE_STATE_ACTIVATED; + err = Internal::WiFiManager::SetDeviceState(deviceState); + SuccessOrExit(err); + + if (mWiFiStationMode != val) + { + ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode), + WiFiStationModeToStr(val)); + + mWiFiStationMode = val; + } + +exit: + 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; + + Internal::WiFiManager::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 = Internal::WiFiManager::GetConnectionState(&connectionState); + SuccessOrExit(err); + + if (connectionState == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) + isWifiStationConnected = true; + +exit: + 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 = Internal::WiFiManager::GetConnectionState(&connectionState); + SuccessOrExit(err); + + if (connectionState >= WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION) + isWifiStationProvisioned = true; + +exit: + return isWifiStationProvisioned; } -void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) {} +void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) +{ + Internal::WiFiManager::RemoveAllConfigs(); +} bool ConnectivityManagerImpl::_CanStartWiFiScan(void) { return false; } +ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + bool apState = false; + + if (mWiFiAPMode != kWiFiAPMode_ApplicationControlled) + { + err = Internal::SoftAPManager::GetAPState(&apState); + VerifyOrExit(err != CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE, mWiFiAPMode = kWiFiAPMode_NotSupported); + VerifyOrExit(err == CHIP_NO_ERROR, mWiFiAPMode = kWiFiAPMode_Disabled); + + if (apState == true) + { + mWiFiAPMode = kWiFiAPMode_Enabled; + } + else + { + mWiFiAPMode = kWiFiAPMode_Disabled; + } + } + +exit: + return mWiFiAPMode; +} + CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) { - return CHIP_ERROR_NOT_IMPLEMENTED; + CHIP_ERROR err = CHIP_NO_ERROR; + bool apState = false; + + VerifyOrExit(val != kWiFiAPMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrExit(val != kWiFiAPMode_ApplicationControlled, ); + + if (val == kWiFiAPMode_Disabled || val == kWiFiAPMode_Enabled) + { + apState = (val == kWiFiAPMode_Disabled) ? false : true; + err = Internal::SoftAPManager::SetAPState(apState); + VerifyOrReturnError(err == CHIP_NO_ERROR, err); + + if (mWiFiAPMode != val) + { + ChipLogProgress(DeviceLayer, "WiFi AP mode change: %s -> %s", WiFiAPModeToStr(mWiFiAPMode), WiFiAPModeToStr(val)); + + mWiFiAPMode = val; + } + } + +exit: + return err; +} + +bool ConnectivityManagerImpl::_IsWiFiAPActive() +{ + bool isWiFiAPEnabled = false; + + Internal::SoftAPManager::IsEnabled(&isWiFiAPEnabled); + + return isWiFiAPEnabled; } -void ConnectivityManagerImpl::_DemandStartWiFiAP(void) {} +void ConnectivityManagerImpl::_DemandStartWiFiAP(void) +{ + SystemLayer().ScheduleWork(EnableSoftAPManager, NULL); +} -void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) {} +void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) +{ + SystemLayer().ScheduleWork(DisableSoftAPManager, NULL); +} 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) +{ + Internal::WiFiManager::Activate(); +} + +void ConnectivityManagerImpl::DeactivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState) +{ + Internal::WiFiManager::Deactivate(); +} + +void ConnectivityManagerImpl::EnableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState) +{ + Internal::SoftAPManager::Enable(); +} + +void ConnectivityManagerImpl::DisableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState) +{ + Internal::SoftAPManager::Disable(); +} #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) { - return CHIP_ERROR_NOT_IMPLEMENTED; + return Internal::WiFiManager::Connect(ssid, key); } } // namespace DeviceLayer diff --git a/src/platform/Tizen/ConnectivityManagerImpl.h b/src/platform/Tizen/ConnectivityManagerImpl.h index 1175600fee22ef..c83b8a19f5f273 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.h +++ b/src/platform/Tizen/ConnectivityManagerImpl.h @@ -37,6 +37,11 @@ #include #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include "SoftAPManager.h" +#include "WiFiManager.h" +#endif + namespace chip { namespace Inet { class IPAddress; @@ -74,6 +79,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. @@ -101,6 +111,11 @@ 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); + static void EnableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState); + static void DisableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState); #endif // ===== Members for internal use by the following friends. @@ -121,12 +136,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; } diff --git a/src/platform/Tizen/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/Tizen/DeviceNetworkProvisioningDelegateImpl.cpp index 21f0c0fe3c9741..423a5b030a9f70 100644 --- a/src/platform/Tizen/DeviceNetworkProvisioningDelegateImpl.cpp +++ b/src/platform/Tizen/DeviceNetworkProvisioningDelegateImpl.cpp @@ -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 diff --git a/src/platform/Tizen/SoftAPManager.cpp b/src/platform/Tizen/SoftAPManager.cpp new file mode 100644 index 00000000000000..6f58cf96817bf8 --- /dev/null +++ b/src/platform/Tizen/SoftAPManager.cpp @@ -0,0 +1,565 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include "MainLoop.h" +#include "SoftAPManager.h" + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +SoftAPManager SoftAPManager::sInstance; + +const char * softap_feature_key = "tizen.org/feature/network.wifi.softap"; + +static const char * __SoftAPDisabledCauseToStr(softap_disabled_cause_e disabledCode) +{ + switch (disabledCode) + { + case SOFTAP_DISABLED_BY_FLIGHT_MODE: + return "disabled due to flight mode on"; + case SOFTAP_DISABLED_BY_LOW_BATTERY: + return "disabled due to low battery"; + case SOFTAP_DISABLED_BY_NETWORK_CLOSE: + return "disabled due to pdp network close"; + case SOFTAP_DISABLED_BY_TIMEOUT: + return "disabled due to timeout"; + case SOFTAP_DISABLED_BY_OTHERS: + return "disabled by other apps"; + case SOFTAP_DISABLED_BY_REQUEST: + return "disabled by my request"; + case SOFTAP_DISABLED_BY_WIFI_ON: + return "disabled by Wi-Fi station on"; + default: + return "disabled by unknown reason"; + } +} + +static const char * __SoftAPSecurityTypeToStr(softap_security_type_e securityType) +{ + switch (securityType) + { + case SOFTAP_SECURITY_TYPE_NONE: + return "None"; + case SOFTAP_SECURITY_TYPE_WPA2_PSK: + return "WPA2 PSK"; + case SOFTAP_SECURITY_TYPE_WPS: + return "WPS"; + default: + return "(unknown)"; + } +} + +void SoftAPManager::_EnabledCb(softap_error_e softAPErr, bool isRequested, void * userData) +{ + if (softAPErr != SOFTAP_ERROR_NONE) + { + VerifyOrReturn(isRequested == true); + + ChipLogProgress(DeviceLayer, "FAIL: enable SoftAP [%s]", get_error_message(softAPErr)); + + if (sInstance.mEnableLoop) + { + g_main_loop_quit(sInstance.mEnableLoop); + sInstance.mEnableLoop = NULL; + } + return; + } + + if (isRequested) + { + ChipLogProgress(DeviceLayer, "SoftAP is enabled by my request"); + + if (sInstance.mEnableLoop) + { + g_main_loop_quit(sInstance.mEnableLoop); + sInstance.mEnableLoop = NULL; + } + } + else + { + ChipLogProgress(DeviceLayer, "SoftAP is enabled by other App"); + } +} + +void SoftAPManager::_DisabledCb(softap_error_e softAPErr, softap_disabled_cause_e disabledCause, void * userData) +{ + if (softAPErr != SOFTAP_ERROR_NONE) + { + VerifyOrReturn(disabledCause == SOFTAP_DISABLED_BY_REQUEST); + + ChipLogProgress(DeviceLayer, "FAIL: enable SoftAP [%s]", get_error_message(softAPErr)); + + if (sInstance.mDisableLoop) + { + g_main_loop_quit(sInstance.mDisableLoop); + sInstance.mDisableLoop = NULL; + } + return; + } + + ChipLogProgress(DeviceLayer, "SoftAP is %s", __SoftAPDisabledCauseToStr(disabledCause)); + + if (disabledCause == SOFTAP_DISABLED_BY_REQUEST) + { + if (sInstance.mDisableLoop) + { + g_main_loop_quit(sInstance.mDisableLoop); + sInstance.mDisableLoop = NULL; + } + } +} + +void SoftAPManager::_SecurityTypeChangedCb(softap_security_type_e securityType, void * userData) +{ + ChipLogProgress(DeviceLayer, "SoftAP security type changed [%s]", __SoftAPSecurityTypeToStr(securityType)); +} + +void SoftAPManager::_SsidVisibilityChangedCb(bool visibility, void * userData) +{ + ChipLogProgress(DeviceLayer, "SoftAP ssid visibility changed [%s]", visibility ? "Visible" : "Invisible"); +} + +void SoftAPManager::_PassphraseChangedCb(void * userData) +{ + ChipLogProgress(DeviceLayer, "SoftAP passphrase is changed"); +} + +void SoftAPManager::_ClientConnectionStateChangedCb(softap_client_h client, bool open, void * userData) +{ + int softAPErr = SOFTAP_ERROR_NONE; + softap_client_h cloneClient = NULL; + char * ipAddress = NULL; + char * macAddress = NULL; + char * hostName = NULL; + + softAPErr = softap_client_clone(&cloneClient, client); + VerifyOrReturn(softAPErr == SOFTAP_ERROR_NONE); + + softap_client_get_ip_address(cloneClient, SOFTAP_ADDRESS_FAMILY_IPV4, &ipAddress); + softap_client_get_mac_address(cloneClient, &macAddress); + softap_client_get_name(cloneClient, &hostName); + + ChipLogProgress(DeviceLayer, "%s station IP [%s] MAC [%s] Hostname [%s]", open ? "Connected" : "Disconnected", ipAddress, + macAddress, hostName); + + free(ipAddress); + free(macAddress); + free(hostName); + + softap_client_destroy(cloneClient); +} + +gboolean SoftAPManager::_SoftAPInitialize(gpointer userData) +{ + int softAPErr = SOFTAP_ERROR_NONE; + + softAPErr = softap_create(&(sInstance.mSoftAPHandle)); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP is created"); + sInstance._SoftAPSetCallbacks(); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: create SoftAP [%s]", get_error_message(softAPErr)); + return false; + } + + return true; +} + +gboolean SoftAPManager::_SoftAPEnable(GMainLoop * mainLoop, gpointer userData) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + + sInstance.mEnableLoop = mainLoop; + + err = sInstance._SoftAPConfigure(); + VerifyOrReturnError(err == CHIP_NO_ERROR, false); + + softAPErr = softap_enable(sInstance.mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP enable is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request SoftAP enable [%s]", get_error_message(softAPErr)); + return false; + } + + return true; +} + +gboolean SoftAPManager::_SoftAPDisable(GMainLoop * mainLoop, gpointer userData) +{ + int softAPErr = SOFTAP_ERROR_NONE; + + sInstance.mDisableLoop = mainLoop; + + softAPErr = softap_disable(sInstance.mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP disable is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request SoftAP disable [%s]", get_error_message(softAPErr)); + return false; + } + + return true; +} + +void SoftAPManager::_SoftAPCheckSupportedFeature(void) +{ + int sysInfoErr = SYSTEM_INFO_ERROR_NONE; + + mSupportedFeature = false; + sysInfoErr = system_info_get_platform_bool(softap_feature_key, &mSupportedFeature); + if (sysInfoErr == SYSTEM_INFO_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP feature: %s", mSupportedFeature ? "Supported" : "Unsupported"); + } + else + { + ChipLogError(DeviceLayer, "FAIL: get platform system info [%d]", sysInfoErr); + } +} + +CHIP_ERROR SoftAPManager::_SoftAPConfigure(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + uint16_t discriminator = 0; + uint32_t setupPinCode = 0; + uint16_t vendorID = 0; + uint16_t productID = 0; + char softAPSsid[kMaxWiFiSSIDLength] = { + 0, + }; + + err = ConfigurationMgr().GetSetupDiscriminator(discriminator); + if (err == CHIP_NO_ERROR) + { + ChipLogProgress(DeviceLayer, "discriminator[0x%03x]", discriminator & 0xFFF); + } + + err = ConfigurationMgr().GetSetupPinCode(setupPinCode); + if (err == CHIP_NO_ERROR) + { + ChipLogProgress(DeviceLayer, "PinCode[%09xlu]", setupPinCode); + } + + /* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID */ + err = ConfigurationMgr().GetVendorId(vendorID); + if (err == CHIP_NO_ERROR) + { + ChipLogProgress(DeviceLayer, "VendorId[%hu (0x%hx)]", vendorID, vendorID); + } + + /* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID */ + err = ConfigurationMgr().GetProductId(productID); + if (err == CHIP_NO_ERROR) + { + ChipLogProgress(DeviceLayer, "ProductId[%hu (0x%hx)]", productID, productID); + } + + /* + * 5.4.2.9.2. AP Operating Parameters + * SSID : CHIP-ddd-vvvv-pppp + * ddd is the 12-bit Discriminator in hex digits + * vvvv is the 16-bit Vendor ID (VID) in hex digits + * pppp is the 16-bit Product ID (PID) in hex digits + */ + snprintf(softAPSsid, kMaxWiFiSSIDLength, "%s%03X-%04X-%04X", CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX, discriminator, vendorID, + productID); + ChipLogProgress(DeviceLayer, "Configuring WiFi AP: SSID %s", softAPSsid); + + softAPErr = softap_set_ssid(mSoftAPHandle, softAPSsid); + VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); + + softAPErr = softap_set_ssid_visibility(mSoftAPHandle, true); + VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); + + softAPErr = softap_set_channel(mSoftAPHandle, CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL); + VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); + + softAPErr = softap_set_security_type(mSoftAPHandle, SOFTAP_SECURITY_TYPE_NONE); + VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); + + return err; +} + +void SoftAPManager::_SoftAPDeinitialize(void) +{ + int softAPErr = SOFTAP_ERROR_NONE; + + sInstance._SoftAPUnsetCallbacks(); + + softAPErr = softap_destroy(sInstance.mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP is destroyed"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: destroy SoftAP [%s]", get_error_message(softAPErr)); + } +} + +void SoftAPManager::_SoftAPSetCallbacks(void) +{ + int softAPErr = SOFTAP_ERROR_NONE; + + softAPErr = softap_set_enabled_cb(mSoftAPHandle, _EnabledCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP enabled callback"); + } + + softAPErr = softap_set_disabled_cb(mSoftAPHandle, _DisabledCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP disabled callback"); + } + + softAPErr = softap_set_security_type_changed_cb(mSoftAPHandle, _SecurityTypeChangedCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP security type changed callback"); + } + + softAPErr = softap_set_ssid_visibility_changed_cb(mSoftAPHandle, _SsidVisibilityChangedCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP ssid visibility changed callback"); + } + + softAPErr = softap_set_passphrase_changed_cb(mSoftAPHandle, _PassphraseChangedCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP passphrase changed callback"); + } + + softAPErr = softap_set_client_connection_state_changed_cb(mSoftAPHandle, _ClientConnectionStateChangedCb, NULL); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set SoftAP client connection state changed callback"); + } +} + +void SoftAPManager::_SoftAPUnsetCallbacks(void) +{ + int softAPErr = SOFTAP_ERROR_NONE; + + softAPErr = softap_unset_enabled_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP enabled callback"); + } + + softAPErr = softap_unset_disabled_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP disabled callback"); + } + + softAPErr = softap_unset_security_type_changed_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP security type changed callback"); + } + + softAPErr = softap_unset_ssid_visibility_changed_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP ssid visibility changed callback"); + } + + softAPErr = softap_unset_passphrase_changed_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP passphrase changed callback"); + } + + softAPErr = softap_unset_client_connection_state_changed_cb(mSoftAPHandle); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset SoftAP client connection state changed callback"); + } +} + +void SoftAPManager::Init(void) +{ + sInstance.mEnableLoop = NULL; + sInstance.mDisableLoop = NULL; + + sInstance._SoftAPCheckSupportedFeature(); + VerifyOrReturn(sInstance.mSupportedFeature); + + MainLoop::Instance().Init(_SoftAPInitialize); +} + +void SoftAPManager::Deinit(void) +{ + VerifyOrReturn(sInstance.mSupportedFeature); + + sInstance._SoftAPDeinitialize(); + MainLoop::Instance().Deinit(); +} + +CHIP_ERROR SoftAPManager::IsEnabled(bool * isSoftAPEnabled) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + + VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, isSoftAPEnabled); + if (softAPErr == SOFTAP_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "SoftAP is %s", *isSoftAPEnabled ? "enabled" : "disabled"); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is activated [%s]", get_error_message(softAPErr)); + } + + return err; +} + +CHIP_ERROR SoftAPManager::Enable(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + bool isSoftAPEnabled = false; + bool dbusAsyncErr = false; + + VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); + if (softAPErr == SOFTAP_ERROR_NONE) + { + if (isSoftAPEnabled == false) + { + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_SoftAPEnable); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + } + else + { + ChipLogProgress(DeviceLayer, "SoftAP is already enabled"); + } + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); + } + + return err; +} + +CHIP_ERROR SoftAPManager::Disable(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + bool isSoftAPEnabled = false; + bool dbusAsyncErr = false; + + VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); + if (softAPErr == SOFTAP_ERROR_NONE) + { + if (isSoftAPEnabled == true) + { + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_SoftAPDisable); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + } + else + { + ChipLogProgress(DeviceLayer, "SoftAP is already disabled"); + } + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); + } + + return err; +} + +CHIP_ERROR SoftAPManager::GetAPState(bool * apState) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int softAPErr = SOFTAP_ERROR_NONE; + bool isSoftAPEnabled = false; + + VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); + if (softAPErr == SOFTAP_ERROR_NONE) + { + *apState = isSoftAPEnabled; + ChipLogProgress(DeviceLayer, "Get AP state [%s]", isSoftAPEnabled ? "Enabled" : "Disabled"); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); + } + + return err; +} + +CHIP_ERROR SoftAPManager::SetAPState(bool apState) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + if (apState == false) + { + err = Disable(); + } + else + { + err = Enable(); + } + + return err; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/Tizen/SoftAPManager.h b/src/platform/Tizen/SoftAPManager.h new file mode 100644 index 00000000000000..81fe9454348f0e --- /dev/null +++ b/src/platform/Tizen/SoftAPManager.h @@ -0,0 +1,71 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +class SoftAPManager +{ +public: + static void Init(void); + static void Deinit(void); + + static CHIP_ERROR IsEnabled(bool * isSoftAPEnabled); + static CHIP_ERROR Enable(void); + static CHIP_ERROR Disable(void); + + static CHIP_ERROR GetAPState(bool * apState); + static CHIP_ERROR SetAPState(bool apState); + +private: + static void _EnabledCb(softap_error_e softAPErr, bool isRequested, void * userData); + static void _DisabledCb(softap_error_e softAPErr, softap_disabled_cause_e disabledCode, void * userData); + static void _SecurityTypeChangedCb(softap_security_type_e securityType, void * userData); + static void _SsidVisibilityChangedCb(bool visibility, void * userData); + static void _PassphraseChangedCb(void * userData); + static void _ClientConnectionStateChangedCb(softap_client_h client, bool open, void * userData); + + static gboolean _SoftAPInitialize(gpointer userData); + static gboolean _SoftAPEnable(GMainLoop * mainLoop, gpointer userData); + static gboolean _SoftAPDisable(GMainLoop * mainLoop, gpointer userData); + + void _SoftAPCheckSupportedFeature(void); + CHIP_ERROR _SoftAPConfigure(void); + void _SoftAPDeinitialize(void); + void _SoftAPSetCallbacks(void); + void _SoftAPUnsetCallbacks(void); + + static SoftAPManager sInstance; + + softap_h mSoftAPHandle; + GMainLoop * mEnableLoop; + GMainLoop * mDisableLoop; + bool mSupportedFeature; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp new file mode 100644 index 00000000000000..541dc291b499d0 --- /dev/null +++ b/src/platform/Tizen/WiFiManager.cpp @@ -0,0 +1,820 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include "MainLoop.h" +#include "WiFiManager.h" + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +WiFiManager WiFiManager::sInstance; + +static const char * __WiFiDeviceStateToStr(wifi_manager_device_state_e state) +{ + switch (state) + { + case WIFI_MANAGER_DEVICE_STATE_DEACTIVATED: + return "Deactivated"; + case WIFI_MANAGER_DEVICE_STATE_ACTIVATED: + return "Activated"; + default: + return "(unknown)"; + } +} + +static const char * __WiFiScanStateToStr(wifi_manager_scan_state_e state) +{ + switch (state) + { + case WIFI_MANAGER_SCAN_STATE_NOT_SCANNING: + return "Not scanning"; + case WIFI_MANAGER_SCAN_STATE_SCANNING: + return "Scanning"; + default: + return "(unknown)"; + } +} + +static const char * __WiFiConnectionStateToStr(wifi_manager_connection_state_e state) +{ + switch (state) + { + case WIFI_MANAGER_CONNECTION_STATE_FAILURE: + return "Failure"; + case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED: + return "Disconnected"; + case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION: + return "Association"; + case WIFI_MANAGER_CONNECTION_STATE_CONNECTED: + return "Connected"; + case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION: + return "Configuration"; + default: + return "(unknown)"; + } +} + +static const char * __WiFiIPConflictStateToStr(wifi_manager_ip_conflict_state_e state) +{ + switch (state) + { + case WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED: + return "Removed"; + case WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_DETECTED: + return "Detacted"; + default: + return "(unknown)"; + } +} + +static const char * __WiFiModuleStateToStr(wifi_manager_module_state_e state) +{ + switch (state) + { + case WIFI_MANAGER_MODULE_STATE_DETACHED: + return "Detached"; + case WIFI_MANAGER_MODULE_STATE_ATTACHED: + return "Attached"; + default: + return "(unknown)"; + } +} + +static const char * __WiFiSecurityTypeToStr(wifi_manager_security_type_e type) +{ + switch (type) + { + case WIFI_MANAGER_SECURITY_TYPE_NONE: + return "None"; + case WIFI_MANAGER_SECURITY_TYPE_WEP: + return "WEP"; + case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK: + return "WPA"; + case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK: + return "WPA2"; + case WIFI_MANAGER_SECURITY_TYPE_EAP: + return "EAP"; + case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: + return "FT_PSK"; + case WIFI_MANAGER_SECURITY_TYPE_SAE: + return "WPA3"; + case WIFI_MANAGER_SECURITY_TYPE_OWE: + return "OWE"; + case WIFI_MANAGER_SECURITY_TYPE_DPP: + return "DPP"; + default: + return "(unknown)"; + } +} + +void WiFiManager::_DeviceStateChangedCb(wifi_manager_device_state_e deviceState, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi device state changed [%s]", __WiFiDeviceStateToStr(deviceState)); + sInstance._WiFiSetDeviceState(deviceState); +} + +void WiFiManager::_ModuleStateChangedCb(wifi_manager_module_state_e moduleState, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi module state changed [%s]", __WiFiModuleStateToStr(moduleState)); + sInstance._WiFiSetModuleState(moduleState); +} + +void WiFiManager::_ConnectionStateChangedCb(wifi_manager_connection_state_e connectionState, wifi_manager_ap_h ap, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi connection state changed [%s]", __WiFiConnectionStateToStr(connectionState)); + sInstance._WiFiSetConnectionState(connectionState); +} + +void WiFiManager::_ScanStateChangedCb(wifi_manager_scan_state_e scanState, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi scan state changed [%s]", __WiFiScanStateToStr(scanState)); +} + +void WiFiManager::_RssiLevelChangedCb(wifi_manager_rssi_level_e rssiLevel, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi rssi level changed [%d]", rssiLevel); +} + +void WiFiManager::_BackgroundScanCb(wifi_manager_error_e wifiErr, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi background scan completed [%s]", get_error_message(wifiErr)); +} + +void WiFiManager::_IPConflictCb(char * mac, wifi_manager_ip_conflict_state_e ipConflictState, void * userData) +{ + ChipLogProgress(DeviceLayer, "WiFi ip conflict [%s %s]", mac, __WiFiIPConflictStateToStr(ipConflictState)); +} + +void WiFiManager::_ActivateCb(wifi_manager_error_e wifiErr, void * userData) +{ + GMainLoop * loop = (GMainLoop *) userData; + + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is activated"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: activate WiFi [%s]", get_error_message(wifiErr)); + } + + g_main_loop_quit(loop); +} + +void WiFiManager::_DeactivateCb(wifi_manager_error_e wifiErr, void * userData) +{ + GMainLoop * loop = (GMainLoop *) userData; + + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is deactivated"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: deactivate WiFi [%s]", get_error_message(wifiErr)); + } + + g_main_loop_quit(loop); +} + +void WiFiManager::_ScanFinishedCb(wifi_manager_error_e wifiErr, void * userData) +{ + GMainLoop * loop = (GMainLoop *) userData; + wifi_manager_ap_h foundAp = NULL; + + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi scan finished"); + + foundAp = sInstance._WiFiGetFoundAP(); + if (foundAp != NULL) + { + MainLoop::Instance().AsyncRequest(_WiFiConnect, static_cast(foundAp)); + } + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: scan WiFi [%s]", get_error_message(wifiErr)); + } + + g_main_loop_quit(loop); +} + +bool WiFiManager::_FoundAPCb(wifi_manager_ap_h ap, void * userData) +{ + bool cbRet = true; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + char * essid = NULL; + bool isPassphraseRequired = false; + wifi_manager_ap_h * clonedAp = (wifi_manager_ap_h *) userData; + + wifiErr = wifi_manager_ap_get_essid(ap, &essid); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogProgress(DeviceLayer, "FAIL: get AP essid [%s]", get_error_message(wifiErr))); + + VerifyOrExit(strcmp(sInstance.mWiFiSSID, essid) == 0, ); + + wifiErr = wifi_manager_ap_is_passphrase_required(ap, &isPassphraseRequired); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogProgress(DeviceLayer, "FAIL: get AP passphrase required [%s]", get_error_message(wifiErr))); + + if (isPassphraseRequired) + { + wifiErr = wifi_manager_ap_set_passphrase(ap, sInstance.mWiFiKey); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogProgress(DeviceLayer, "FAIL: set AP passphrase [%s]", get_error_message(wifiErr))); + } + + wifiErr = wifi_manager_ap_clone(clonedAp, ap); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogProgress(DeviceLayer, "FAIL: clone AP [%s]", get_error_message(wifiErr))); + + cbRet = false; + +exit: + g_free(essid); + return cbRet; +} + +void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData) +{ + GMainLoop * loop = (GMainLoop *) userData; + + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is connected [%s]", sInstance.mWiFiSSID); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: connect WiFi [%s]", get_error_message(wifiErr)); + } + + g_main_loop_quit(loop); +} + +bool WiFiManager::_ConfigListCb(const wifi_manager_config_h config, void * userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + char * name = NULL; + wifi_manager_security_type_e securityType = WIFI_MANAGER_SECURITY_TYPE_NONE; + + wifi_manager_config_get_name(config, &name); + wifi_manager_config_get_security_type(config, &securityType); + + wifiErr = wifi_manager_config_remove(sInstance.mWiFiManagerHandle, config); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Remove config [%s:%s]", name, __WiFiSecurityTypeToStr(securityType)); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: remove config [%s]", get_error_message(wifiErr)); + } + + g_free(name); + return true; +} + +gboolean WiFiManager::_WiFiInitialize(gpointer userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_initialize(&(sInstance.mWiFiManagerHandle)); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is initialized"); + sInstance._WiFiSetStates(); + sInstance._WiFiSetCallbacks(); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: initialize WiFi [%s]", get_error_message(wifiErr)); + return false; + } + + return true; +} + +void WiFiManager::_WiFiDeinitialize(void) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + _WiFiUnsetCallbacks(); + + wifiErr = wifi_manager_deinitialize(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is deinitialized"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: deinitialize WiFi [%s]", get_error_message(wifiErr)); + } +} + +gboolean WiFiManager::_WiFiActivate(GMainLoop * mainLoop, gpointer userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_activate(sInstance.mWiFiManagerHandle, _ActivateCb, mainLoop); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi activation is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request WiFi activation [%s]", get_error_message(wifiErr)); + return false; + } + + return true; +} + +gboolean WiFiManager::_WiFiDeactivate(GMainLoop * mainLoop, gpointer userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_deactivate(sInstance.mWiFiManagerHandle, _DeactivateCb, mainLoop); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi deactivation is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request WiFi deactivation [%s]", get_error_message(wifiErr)); + return false; + } + + return true; +} + +gboolean WiFiManager::_WiFiScan(GMainLoop * mainLoop, gpointer userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_scan(sInstance.mWiFiManagerHandle, _ScanFinishedCb, mainLoop); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi scan is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request WiFi scan [%s]", get_error_message(wifiErr)); + return false; + } + + return true; +} + +gboolean WiFiManager::_WiFiConnect(GMainLoop * mainLoop, gpointer userData) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + wifi_manager_ap_h ap = static_cast(userData); + + wifiErr = wifi_manager_connect(sInstance.mWiFiManagerHandle, ap, _ConnectedCb, mainLoop); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi connect is requested"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: request WiFi connect [%s]", get_error_message(wifiErr)); + wifi_manager_ap_destroy(ap); + return false; + } + + wifi_manager_ap_destroy(ap); + return true; +} + +void WiFiManager::_WiFiSetStates(void) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + bool isWifiActivated = false; + + wifiErr = wifi_manager_is_activated(mWiFiManagerHandle, &isWifiActivated); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + mDeviceState = isWifiActivated ? WIFI_MANAGER_DEVICE_STATE_ACTIVATED : WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; + ChipLogProgress(DeviceLayer, "Set WiFi device state [%s]", __WiFiDeviceStateToStr(mDeviceState)); + } + + wifiErr = wifi_manager_get_module_state(mWiFiManagerHandle, &mModuleState); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi module state [%s]", __WiFiModuleStateToStr(mModuleState)); + } + + wifiErr = wifi_manager_get_connection_state(mWiFiManagerHandle, &mConnectionState); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi connection state [%s]", __WiFiConnectionStateToStr(mConnectionState)); + } +} + +void WiFiManager::_WiFiSetCallbacks(void) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_set_device_state_changed_cb(mWiFiManagerHandle, _DeviceStateChangedCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi device state changed callback"); + } + + wifiErr = wifi_manager_set_module_state_changed_cb(mWiFiManagerHandle, _ModuleStateChangedCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi module state changed callback"); + } + + wifiErr = wifi_manager_set_connection_state_changed_cb(mWiFiManagerHandle, _ConnectionStateChangedCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi connection state changed callback"); + } + + wifiErr = wifi_manager_set_scan_state_changed_cb(mWiFiManagerHandle, _ScanStateChangedCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi scan state changed callback"); + } + + wifiErr = wifi_manager_set_rssi_level_changed_cb(mWiFiManagerHandle, _RssiLevelChangedCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi rssi level changed callback"); + } + + wifiErr = wifi_manager_set_background_scan_cb(mWiFiManagerHandle, _BackgroundScanCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi background scan callback"); + } + + wifiErr = wifi_manager_set_ip_conflict_cb(mWiFiManagerHandle, _IPConflictCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Set WiFi IP conflict callback"); + } +} + +void WiFiManager::_WiFiUnsetCallbacks(void) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_unset_device_state_changed_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi device state changed callback"); + } + + wifiErr = wifi_manager_unset_module_state_changed_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi module state changed callback"); + } + + wifiErr = wifi_manager_unset_connection_state_changed_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi connection state changed callback"); + } + + wifiErr = wifi_manager_unset_scan_state_changed_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi scan state changed callback"); + } + + wifiErr = wifi_manager_unset_rssi_level_changed_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi rssi level changed callback"); + } + + wifiErr = wifi_manager_unset_background_scan_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi background scan callback"); + } + + wifiErr = wifi_manager_unset_ip_conflict_cb(mWiFiManagerHandle); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Unset WiFi IP conflict callback"); + } +} + +void WiFiManager::_WiFiSetDeviceState(wifi_manager_device_state_e deviceState) +{ + mDeviceState = deviceState; + ChipLogProgress(DeviceLayer, "Set WiFi device state [%s]", __WiFiDeviceStateToStr(mDeviceState)); +} + +void WiFiManager::_WiFiSetModuleState(wifi_manager_module_state_e moduleState) +{ + mModuleState = moduleState; + ChipLogProgress(DeviceLayer, "Set WiFi module state [%s]", __WiFiModuleStateToStr(mModuleState)); +} + +void WiFiManager::_WiFiSetConnectionState(wifi_manager_connection_state_e connectionState) +{ + mConnectionState = connectionState; + ChipLogProgress(DeviceLayer, "Set WiFi connection state [%s]", __WiFiConnectionStateToStr(mConnectionState)); +} + +wifi_manager_ap_h WiFiManager::_WiFiGetFoundAP(void) +{ + int wifiErr = WIFI_MANAGER_ERROR_NONE; + wifi_manager_ap_h foundAp = NULL; + + wifiErr = wifi_manager_foreach_found_ap(mWiFiManagerHandle, _FoundAPCb, &foundAp); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Get found AP list finished"); + } + else + { + ChipLogProgress(DeviceLayer, "FAIL: get found AP list [%s]", get_error_message(wifiErr)); + } + + return foundAp; +} + +void WiFiManager::Init(void) +{ + sInstance.mDeviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; + sInstance.mModuleState = WIFI_MANAGER_MODULE_STATE_DETACHED; + sInstance.mConnectionState = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED; + + MainLoop::Instance().Init(_WiFiInitialize); +} + +void WiFiManager::Deinit(void) +{ + sInstance._WiFiDeinitialize(); + MainLoop::Instance().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; + ChipLogProgress(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr)); + } + + return err; +} + +CHIP_ERROR WiFiManager::Activate(void) +{ + 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; + ChipLogProgress(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr))); + + VerifyOrExit(isWifiActivated == false, ChipLogProgress(DeviceLayer, "WiFi is already activated")); + + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiActivate); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + +exit: + return err; +} + +CHIP_ERROR WiFiManager::Deactivate(void) +{ + 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; + ChipLogProgress(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr))); + + VerifyOrExit(isWifiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is already deactivated")); + + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiDeactivate); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + +exit: + return err; +} + +CHIP_ERROR WiFiManager::Connect(const char * ssid, const char * key) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + bool isWifiActivated = false; + bool dbusAsyncErr = false; + wifi_manager_ap_h foundAp = NULL; + + g_strlcpy(sInstance.mWiFiSSID, ssid, kMaxWiFiSSIDLength + 1); + g_strlcpy(sInstance.mWiFiKey, key, kMaxWiFiKeyLength); + + wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWifiActivated); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr))); + + VerifyOrExit(isWifiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is deactivated")); + + foundAp = sInstance._WiFiGetFoundAP(); + if (foundAp != NULL) + { + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiConnect, static_cast(foundAp)); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + } + else + { + dbusAsyncErr = MainLoop::Instance().AsyncRequest(_WiFiScan); + if (dbusAsyncErr == false) + { + err = CHIP_ERROR_INCORRECT_STATE; + } + } + +exit: + return err; +} + +CHIP_ERROR WiFiManager::Disconnect(const char * ssid) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + bool isWifiActivated = false; + wifi_manager_ap_h foundAp = NULL; + + g_strlcpy(sInstance.mWiFiSSID, ssid, kMaxWiFiSSIDLength + 1); + + wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWifiActivated); + VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr))); + + VerifyOrExit(isWifiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is deactivated")); + + foundAp = sInstance._WiFiGetFoundAP(); + VerifyOrExit(foundAp != NULL, ); + + wifiErr = wifi_manager_forget_ap(sInstance.mWiFiManagerHandle, foundAp); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "WiFi is disconnected [%s]", sInstance.mWiFiSSID); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: disconnect WiFi [%s]", get_error_message(wifiErr)); + } + + wifi_manager_ap_destroy(foundAp); + +exit: + return err; +} + +CHIP_ERROR WiFiManager::RemoveAllConfigs(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + wifiErr = wifi_manager_config_foreach_configuration(sInstance.mWiFiManagerHandle, _ConfigListCb, NULL); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Get config list finished"); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: get config list [%s]", get_error_message(wifiErr)); + } + + return err; +} + +CHIP_ERROR WiFiManager::GetDeviceState(wifi_manager_device_state_e * deviceState) +{ + *deviceState = sInstance.mDeviceState; + ChipLogProgress(DeviceLayer, "Get WiFi device state [%s]", __WiFiDeviceStateToStr(*deviceState)); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR WiFiManager::SetDeviceState(wifi_manager_device_state_e deviceState) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + VerifyOrExit(sInstance.mDeviceState != deviceState, ); + + if (deviceState == WIFI_MANAGER_DEVICE_STATE_DEACTIVATED) + { + err = Deactivate(); + } + else + { + err = Activate(); + } + +exit: + return err; +} + +CHIP_ERROR WiFiManager::GetModuleState(wifi_manager_module_state_e * moduleState) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + if (sInstance.mModuleState != WIFI_MANAGER_MODULE_STATE_DETACHED) + { + *moduleState = sInstance.mModuleState; + ChipLogProgress(DeviceLayer, "Get WiFi module state [%s]", __WiFiModuleStateToStr(*moduleState)); + } + else + { + wifiErr = wifi_manager_get_module_state(sInstance.mWiFiManagerHandle, moduleState); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Get WiFi module state [%s]", __WiFiModuleStateToStr(*moduleState)); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: get WiFi module state [%s]", get_error_message(wifiErr)); + } + } + + return err; +} + +CHIP_ERROR WiFiManager::GetConnectionState(wifi_manager_connection_state_e * connectionState) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int wifiErr = WIFI_MANAGER_ERROR_NONE; + + if (sInstance.mConnectionState != WIFI_MANAGER_CONNECTION_STATE_FAILURE) + { + *connectionState = sInstance.mConnectionState; + ChipLogProgress(DeviceLayer, "Get WiFi connection state [%s]", __WiFiConnectionStateToStr(*connectionState)); + } + else + { + wifiErr = wifi_manager_get_connection_state(sInstance.mWiFiManagerHandle, connectionState); + if (wifiErr == WIFI_MANAGER_ERROR_NONE) + { + ChipLogProgress(DeviceLayer, "Get WiFi connection state [%s]", __WiFiConnectionStateToStr(*connectionState)); + } + else + { + err = CHIP_ERROR_INCORRECT_STATE; + ChipLogProgress(DeviceLayer, "FAIL: get WiFi connection state [%s]", get_error_message(wifiErr)); + } + } + + return err; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/Tizen/WiFiManager.h b/src/platform/Tizen/WiFiManager.h new file mode 100644 index 00000000000000..6d5453415675f0 --- /dev/null +++ b/src/platform/Tizen/WiFiManager.h @@ -0,0 +1,93 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include + +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +class WiFiManager +{ +public: + static void Init(void); + static void Deinit(void); + + static CHIP_ERROR IsActivated(bool * isWifiActivated); + static CHIP_ERROR Activate(void); + static CHIP_ERROR Deactivate(void); + static CHIP_ERROR Connect(const char * ssid, const char * key); + static CHIP_ERROR Disconnect(const char * ssid); + static CHIP_ERROR RemoveAllConfigs(void); + + static CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState); + static CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState); + static CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState); + static CHIP_ERROR GetConnectionState(wifi_manager_connection_state_e * connectionState); + +private: + static void _DeviceStateChangedCb(wifi_manager_device_state_e deviceState, void * userData); + static void _ModuleStateChangedCb(wifi_manager_module_state_e moduleState, void * userData); + static void _ConnectionStateChangedCb(wifi_manager_connection_state_e connectionState, wifi_manager_ap_h ap, void * userData); + static void _ScanStateChangedCb(wifi_manager_scan_state_e scanState, void * userData); + static void _RssiLevelChangedCb(wifi_manager_rssi_level_e rssiLevel, void * userData); + static void _BackgroundScanCb(wifi_manager_error_e wifiErr, void * userData); + static void _IPConflictCb(char * mac, wifi_manager_ip_conflict_state_e ipConflictState, void * userData); + static void _ActivateCb(wifi_manager_error_e wifiErr, void * userData); + static void _DeactivateCb(wifi_manager_error_e wifiErr, void * userData); + static void _ScanFinishedCb(wifi_manager_error_e wifiErr, void * userData); + static bool _FoundAPCb(wifi_manager_ap_h ap, void * userData); + static void _ConnectedCb(wifi_manager_error_e wifiErr, void * userData); + static bool _ConfigListCb(const wifi_manager_config_h config, void * userData); + + static gboolean _WiFiInitialize(gpointer userData); + static gboolean _WiFiActivate(GMainLoop * mainLoop, gpointer userData); + static gboolean _WiFiDeactivate(GMainLoop * mainLoop, gpointer userData); + 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 _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); + + static WiFiManager sInstance; + + wifi_manager_h mWiFiManagerHandle; + wifi_manager_device_state_e mDeviceState; + wifi_manager_module_state_e mModuleState; + wifi_manager_connection_state_e mConnectionState; + + char mWiFiSSID[kMaxWiFiSSIDLength + 1]; + char mWiFiKey[kMaxWiFiKeyLength]; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI From ff48a2e79609cdafb16778299eda27724adce226 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Oct 2021 09:41:36 +0900 Subject: [PATCH 2/9] Apply comment for WiFi --- .../Tizen/ConnectivityManagerImpl.cpp | 20 +++++------ src/platform/Tizen/WiFiManager.cpp | 32 ++++++++++-------- src/platform/Tizen/WiFiManager.h | 33 ++++++++++++------- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp index 0364628bb59d3e..3fb820264bb202 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -60,7 +60,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init(void) mWiFiAPIdleTimeoutMS = CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT; #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - Internal::WiFiManager::Init(); + WiFiMgr().Init(); Internal::SoftAPManager::Init(); #endif @@ -78,7 +78,7 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) { - err = Internal::WiFiManager::GetDeviceState(&deviceState); + err = WiFiMgr().GetDeviceState(&deviceState); SuccessOrExit(err); if (deviceState == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) @@ -104,7 +104,7 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiF VerifyOrExit(val != kWiFiStationMode_ApplicationControlled, ); deviceState = (val == kWiFiStationMode_Disabled) ? WIFI_MANAGER_DEVICE_STATE_DEACTIVATED : WIFI_MANAGER_DEVICE_STATE_ACTIVATED; - err = Internal::WiFiManager::SetDeviceState(deviceState); + err = WiFiMgr().SetDeviceState(deviceState); SuccessOrExit(err); if (mWiFiStationMode != val) @@ -135,7 +135,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) { bool isWifiStationEnabled = false; - Internal::WiFiManager::IsActivated(&isWifiStationEnabled); + WiFiMgr().IsActivated(&isWifiStationEnabled); return isWifiStationEnabled; } @@ -146,7 +146,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) wifi_manager_connection_state_e connectionState = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED; bool isWifiStationConnected = false; - err = Internal::WiFiManager::GetConnectionState(&connectionState); + err = WiFiMgr().GetConnectionState(&connectionState); SuccessOrExit(err); if (connectionState == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) @@ -162,7 +162,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) wifi_manager_connection_state_e connectionState = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED; bool isWifiStationProvisioned = false; - err = Internal::WiFiManager::GetConnectionState(&connectionState); + err = WiFiMgr().GetConnectionState(&connectionState); SuccessOrExit(err); if (connectionState >= WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION) @@ -174,7 +174,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) { - Internal::WiFiManager::RemoveAllConfigs(); + WiFiMgr().RemoveAllConfigs(); } bool ConnectivityManagerImpl::_CanStartWiFiScan(void) @@ -268,12 +268,12 @@ void ConnectivityManagerImpl::StopWiFiManagement(void) void ConnectivityManagerImpl::ActivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState) { - Internal::WiFiManager::Activate(); + WiFiMgr().Activate(); } void ConnectivityManagerImpl::DeactivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState) { - Internal::WiFiManager::Deactivate(); + WiFiMgr().Deactivate(); } void ConnectivityManagerImpl::EnableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState) @@ -289,7 +289,7 @@ void ConnectivityManagerImpl::DisableSoftAPManager(::chip::System::Layer * aLaye CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) { - return Internal::WiFiManager::Connect(ssid, key); + return WiFiMgr().Connect(ssid, key); } } // namespace DeviceLayer diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index 541dc291b499d0..f10d31b61290de 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -21,13 +21,8 @@ #include "MainLoop.h" #include "WiFiManager.h" -namespace chip { -namespace DeviceLayer { -namespace Internal { - -WiFiManager WiFiManager::sInstance; - -static const char * __WiFiDeviceStateToStr(wifi_manager_device_state_e state) +namespace { +const char * __WiFiDeviceStateToStr(wifi_manager_device_state_e state) { switch (state) { @@ -40,7 +35,7 @@ static const char * __WiFiDeviceStateToStr(wifi_manager_device_state_e state) } } -static const char * __WiFiScanStateToStr(wifi_manager_scan_state_e state) +const char * __WiFiScanStateToStr(wifi_manager_scan_state_e state) { switch (state) { @@ -53,7 +48,7 @@ static const char * __WiFiScanStateToStr(wifi_manager_scan_state_e state) } } -static const char * __WiFiConnectionStateToStr(wifi_manager_connection_state_e state) +const char * __WiFiConnectionStateToStr(wifi_manager_connection_state_e state) { switch (state) { @@ -72,7 +67,7 @@ static const char * __WiFiConnectionStateToStr(wifi_manager_connection_state_e s } } -static const char * __WiFiIPConflictStateToStr(wifi_manager_ip_conflict_state_e state) +const char * __WiFiIPConflictStateToStr(wifi_manager_ip_conflict_state_e state) { switch (state) { @@ -85,7 +80,7 @@ static const char * __WiFiIPConflictStateToStr(wifi_manager_ip_conflict_state_e } } -static const char * __WiFiModuleStateToStr(wifi_manager_module_state_e state) +const char * __WiFiModuleStateToStr(wifi_manager_module_state_e state) { switch (state) { @@ -98,7 +93,7 @@ static const char * __WiFiModuleStateToStr(wifi_manager_module_state_e state) } } -static const char * __WiFiSecurityTypeToStr(wifi_manager_security_type_e type) +const char * __WiFiSecurityTypeToStr(wifi_manager_security_type_e type) { switch (type) { @@ -124,6 +119,13 @@ static const char * __WiFiSecurityTypeToStr(wifi_manager_security_type_e type) return "(unknown)"; } } +} + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +WiFiManager WiFiManager::sInstance; void WiFiManager::_DeviceStateChangedCb(wifi_manager_device_state_e deviceState, void * userData) { @@ -250,6 +252,8 @@ bool WiFiManager::_FoundAPCb(wifi_manager_ap_h ap, void * userData) cbRet = false; exit: + memset(sInstance.mWiFiSSID, 0, sizeof(sInstance.mWiFiSSID)); + memset(sInstance.mWiFiKey, 0, sizeof(sInstance.mWiFiKey)); g_free(essid); return cbRet; } @@ -260,7 +264,7 @@ void WiFiManager::_ConnectedCb(wifi_manager_error_e wifiErr, void * userData) if (wifiErr == WIFI_MANAGER_ERROR_NONE) { - ChipLogProgress(DeviceLayer, "WiFi is connected [%s]", sInstance.mWiFiSSID); + ChipLogProgress(DeviceLayer, "WiFi is connected"); } else { @@ -700,7 +704,7 @@ CHIP_ERROR WiFiManager::Disconnect(const char * ssid) wifiErr = wifi_manager_forget_ap(sInstance.mWiFiManagerHandle, foundAp); if (wifiErr == WIFI_MANAGER_ERROR_NONE) { - ChipLogProgress(DeviceLayer, "WiFi is disconnected [%s]", sInstance.mWiFiSSID); + ChipLogProgress(DeviceLayer, "WiFi is disconnected"); } else { diff --git a/src/platform/Tizen/WiFiManager.h b/src/platform/Tizen/WiFiManager.h index 6d5453415675f0..b39d6787ee35d9 100644 --- a/src/platform/Tizen/WiFiManager.h +++ b/src/platform/Tizen/WiFiManager.h @@ -29,21 +29,23 @@ namespace Internal { class WiFiManager { + friend class ConnectivityManagerImpl; + public: - static void Init(void); - static void Deinit(void); + void Init(void); + void Deinit(void); - static CHIP_ERROR IsActivated(bool * isWifiActivated); - static CHIP_ERROR Activate(void); - static CHIP_ERROR Deactivate(void); - static CHIP_ERROR Connect(const char * ssid, const char * key); - static CHIP_ERROR Disconnect(const char * ssid); - static CHIP_ERROR RemoveAllConfigs(void); + CHIP_ERROR IsActivated(bool * isWifiActivated); + CHIP_ERROR Activate(void); + CHIP_ERROR Deactivate(void); + CHIP_ERROR Connect(const char * ssid, const char * key); + CHIP_ERROR Disconnect(const char * ssid); + CHIP_ERROR RemoveAllConfigs(void); - static CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState); - static CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState); - static CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState); - static CHIP_ERROR GetConnectionState(wifi_manager_connection_state_e * connectionState); + CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState); + CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState); + CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState); + CHIP_ERROR GetConnectionState(wifi_manager_connection_state_e * connectionState); private: static void _DeviceStateChangedCb(wifi_manager_device_state_e deviceState, void * userData); @@ -75,6 +77,8 @@ class WiFiManager void _WiFiSetConnectionState(wifi_manager_connection_state_e connectionState); wifi_manager_ap_h _WiFiGetFoundAP(void); + friend WiFiManager & WiFiMgr(void); + static WiFiManager sInstance; wifi_manager_h mWiFiManagerHandle; @@ -86,6 +90,11 @@ class WiFiManager char mWiFiKey[kMaxWiFiKeyLength]; }; +inline WiFiManager & WiFiMgr() +{ + return WiFiManager::sInstance; +} + } // namespace Internal } // namespace DeviceLayer } // namespace chip From 15175513833b3ef092fec3937fbb05324b723fd4 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Oct 2021 10:12:09 +0900 Subject: [PATCH 3/9] Apply comment for SoftAP --- src/platform/Tizen/BUILD.gn | 2 - .../Tizen/ConnectivityManagerImpl.cpp | 70 +-- src/platform/Tizen/ConnectivityManagerImpl.h | 3 - src/platform/Tizen/SoftAPManager.cpp | 565 ------------------ src/platform/Tizen/SoftAPManager.h | 71 --- 5 files changed, 4 insertions(+), 707 deletions(-) mode change 100644 => 100755 src/platform/Tizen/ConnectivityManagerImpl.cpp mode change 100644 => 100755 src/platform/Tizen/ConnectivityManagerImpl.h delete mode 100644 src/platform/Tizen/SoftAPManager.cpp delete mode 100644 src/platform/Tizen/SoftAPManager.h diff --git a/src/platform/Tizen/BUILD.gn b/src/platform/Tizen/BUILD.gn index b46269b7f9ffd7..6c3a046ad052d1 100644 --- a/src/platform/Tizen/BUILD.gn +++ b/src/platform/Tizen/BUILD.gn @@ -50,8 +50,6 @@ static_library("Tizen") { "PlatformManagerImpl.h", "PosixConfig.cpp", "PosixConfig.h", - "SoftAPManager.cpp", - "SoftAPManager.h", "SystemPlatformConfig.h", "SystemTimeSupport.cpp", "WiFiManager.cpp", diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp old mode 100644 new mode 100755 index 3fb820264bb202..57419aceee9a3c --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -61,7 +61,6 @@ CHIP_ERROR ConnectivityManagerImpl::_Init(void) #if CHIP_DEVICE_CONFIG_ENABLE_WIFI WiFiMgr().Init(); - Internal::SoftAPManager::Init(); #endif return err; @@ -184,73 +183,22 @@ bool ConnectivityManagerImpl::_CanStartWiFiScan(void) ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode() { - CHIP_ERROR err = CHIP_NO_ERROR; - bool apState = false; - - if (mWiFiAPMode != kWiFiAPMode_ApplicationControlled) - { - err = Internal::SoftAPManager::GetAPState(&apState); - VerifyOrExit(err != CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE, mWiFiAPMode = kWiFiAPMode_NotSupported); - VerifyOrExit(err == CHIP_NO_ERROR, mWiFiAPMode = kWiFiAPMode_Disabled); - - if (apState == true) - { - mWiFiAPMode = kWiFiAPMode_Enabled; - } - else - { - mWiFiAPMode = kWiFiAPMode_Disabled; - } - } - -exit: return mWiFiAPMode; } CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) { - CHIP_ERROR err = CHIP_NO_ERROR; - bool apState = false; - - VerifyOrExit(val != kWiFiAPMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(val != kWiFiAPMode_ApplicationControlled, ); - - if (val == kWiFiAPMode_Disabled || val == kWiFiAPMode_Enabled) - { - apState = (val == kWiFiAPMode_Disabled) ? false : true; - err = Internal::SoftAPManager::SetAPState(apState); - VerifyOrReturnError(err == CHIP_NO_ERROR, err); - - if (mWiFiAPMode != val) - { - ChipLogProgress(DeviceLayer, "WiFi AP mode change: %s -> %s", WiFiAPModeToStr(mWiFiAPMode), WiFiAPModeToStr(val)); - - mWiFiAPMode = val; - } - } - -exit: - return err; + return CHIP_ERROR_NOT_IMPLEMENTED; } bool ConnectivityManagerImpl::_IsWiFiAPActive() { - bool isWiFiAPEnabled = false; - - Internal::SoftAPManager::IsEnabled(&isWiFiAPEnabled); - - return isWiFiAPEnabled; + return mWiFiAPState == kWiFiAPState_Active; } -void ConnectivityManagerImpl::_DemandStartWiFiAP(void) -{ - SystemLayer().ScheduleWork(EnableSoftAPManager, NULL); -} +void ConnectivityManagerImpl::_DemandStartWiFiAP(void) {} -void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) -{ - SystemLayer().ScheduleWork(DisableSoftAPManager, NULL); -} +void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) {} void ConnectivityManagerImpl::_MaintainOnDemandWiFiAP(void) {} @@ -275,16 +223,6 @@ void ConnectivityManagerImpl::DeactivateWiFiManager(::chip::System::Layer * aLay { WiFiMgr().Deactivate(); } - -void ConnectivityManagerImpl::EnableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState) -{ - Internal::SoftAPManager::Enable(); -} - -void ConnectivityManagerImpl::DisableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState) -{ - Internal::SoftAPManager::Disable(); -} #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) diff --git a/src/platform/Tizen/ConnectivityManagerImpl.h b/src/platform/Tizen/ConnectivityManagerImpl.h old mode 100644 new mode 100755 index c83b8a19f5f273..6eabba52a0f997 --- a/src/platform/Tizen/ConnectivityManagerImpl.h +++ b/src/platform/Tizen/ConnectivityManagerImpl.h @@ -38,7 +38,6 @@ #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include "SoftAPManager.h" #include "WiFiManager.h" #endif @@ -114,8 +113,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, static void ActivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState); static void DeactivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState); - static void EnableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState); - static void DisableSoftAPManager(::chip::System::Layer * aLayer, void * aAppState); #endif // ===== Members for internal use by the following friends. diff --git a/src/platform/Tizen/SoftAPManager.cpp b/src/platform/Tizen/SoftAPManager.cpp deleted file mode 100644 index 6f58cf96817bf8..00000000000000 --- a/src/platform/Tizen/SoftAPManager.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include "MainLoop.h" -#include "SoftAPManager.h" - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -SoftAPManager SoftAPManager::sInstance; - -const char * softap_feature_key = "tizen.org/feature/network.wifi.softap"; - -static const char * __SoftAPDisabledCauseToStr(softap_disabled_cause_e disabledCode) -{ - switch (disabledCode) - { - case SOFTAP_DISABLED_BY_FLIGHT_MODE: - return "disabled due to flight mode on"; - case SOFTAP_DISABLED_BY_LOW_BATTERY: - return "disabled due to low battery"; - case SOFTAP_DISABLED_BY_NETWORK_CLOSE: - return "disabled due to pdp network close"; - case SOFTAP_DISABLED_BY_TIMEOUT: - return "disabled due to timeout"; - case SOFTAP_DISABLED_BY_OTHERS: - return "disabled by other apps"; - case SOFTAP_DISABLED_BY_REQUEST: - return "disabled by my request"; - case SOFTAP_DISABLED_BY_WIFI_ON: - return "disabled by Wi-Fi station on"; - default: - return "disabled by unknown reason"; - } -} - -static const char * __SoftAPSecurityTypeToStr(softap_security_type_e securityType) -{ - switch (securityType) - { - case SOFTAP_SECURITY_TYPE_NONE: - return "None"; - case SOFTAP_SECURITY_TYPE_WPA2_PSK: - return "WPA2 PSK"; - case SOFTAP_SECURITY_TYPE_WPS: - return "WPS"; - default: - return "(unknown)"; - } -} - -void SoftAPManager::_EnabledCb(softap_error_e softAPErr, bool isRequested, void * userData) -{ - if (softAPErr != SOFTAP_ERROR_NONE) - { - VerifyOrReturn(isRequested == true); - - ChipLogProgress(DeviceLayer, "FAIL: enable SoftAP [%s]", get_error_message(softAPErr)); - - if (sInstance.mEnableLoop) - { - g_main_loop_quit(sInstance.mEnableLoop); - sInstance.mEnableLoop = NULL; - } - return; - } - - if (isRequested) - { - ChipLogProgress(DeviceLayer, "SoftAP is enabled by my request"); - - if (sInstance.mEnableLoop) - { - g_main_loop_quit(sInstance.mEnableLoop); - sInstance.mEnableLoop = NULL; - } - } - else - { - ChipLogProgress(DeviceLayer, "SoftAP is enabled by other App"); - } -} - -void SoftAPManager::_DisabledCb(softap_error_e softAPErr, softap_disabled_cause_e disabledCause, void * userData) -{ - if (softAPErr != SOFTAP_ERROR_NONE) - { - VerifyOrReturn(disabledCause == SOFTAP_DISABLED_BY_REQUEST); - - ChipLogProgress(DeviceLayer, "FAIL: enable SoftAP [%s]", get_error_message(softAPErr)); - - if (sInstance.mDisableLoop) - { - g_main_loop_quit(sInstance.mDisableLoop); - sInstance.mDisableLoop = NULL; - } - return; - } - - ChipLogProgress(DeviceLayer, "SoftAP is %s", __SoftAPDisabledCauseToStr(disabledCause)); - - if (disabledCause == SOFTAP_DISABLED_BY_REQUEST) - { - if (sInstance.mDisableLoop) - { - g_main_loop_quit(sInstance.mDisableLoop); - sInstance.mDisableLoop = NULL; - } - } -} - -void SoftAPManager::_SecurityTypeChangedCb(softap_security_type_e securityType, void * userData) -{ - ChipLogProgress(DeviceLayer, "SoftAP security type changed [%s]", __SoftAPSecurityTypeToStr(securityType)); -} - -void SoftAPManager::_SsidVisibilityChangedCb(bool visibility, void * userData) -{ - ChipLogProgress(DeviceLayer, "SoftAP ssid visibility changed [%s]", visibility ? "Visible" : "Invisible"); -} - -void SoftAPManager::_PassphraseChangedCb(void * userData) -{ - ChipLogProgress(DeviceLayer, "SoftAP passphrase is changed"); -} - -void SoftAPManager::_ClientConnectionStateChangedCb(softap_client_h client, bool open, void * userData) -{ - int softAPErr = SOFTAP_ERROR_NONE; - softap_client_h cloneClient = NULL; - char * ipAddress = NULL; - char * macAddress = NULL; - char * hostName = NULL; - - softAPErr = softap_client_clone(&cloneClient, client); - VerifyOrReturn(softAPErr == SOFTAP_ERROR_NONE); - - softap_client_get_ip_address(cloneClient, SOFTAP_ADDRESS_FAMILY_IPV4, &ipAddress); - softap_client_get_mac_address(cloneClient, &macAddress); - softap_client_get_name(cloneClient, &hostName); - - ChipLogProgress(DeviceLayer, "%s station IP [%s] MAC [%s] Hostname [%s]", open ? "Connected" : "Disconnected", ipAddress, - macAddress, hostName); - - free(ipAddress); - free(macAddress); - free(hostName); - - softap_client_destroy(cloneClient); -} - -gboolean SoftAPManager::_SoftAPInitialize(gpointer userData) -{ - int softAPErr = SOFTAP_ERROR_NONE; - - softAPErr = softap_create(&(sInstance.mSoftAPHandle)); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP is created"); - sInstance._SoftAPSetCallbacks(); - } - else - { - ChipLogProgress(DeviceLayer, "FAIL: create SoftAP [%s]", get_error_message(softAPErr)); - return false; - } - - return true; -} - -gboolean SoftAPManager::_SoftAPEnable(GMainLoop * mainLoop, gpointer userData) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - - sInstance.mEnableLoop = mainLoop; - - err = sInstance._SoftAPConfigure(); - VerifyOrReturnError(err == CHIP_NO_ERROR, false); - - softAPErr = softap_enable(sInstance.mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP enable is requested"); - } - else - { - ChipLogProgress(DeviceLayer, "FAIL: request SoftAP enable [%s]", get_error_message(softAPErr)); - return false; - } - - return true; -} - -gboolean SoftAPManager::_SoftAPDisable(GMainLoop * mainLoop, gpointer userData) -{ - int softAPErr = SOFTAP_ERROR_NONE; - - sInstance.mDisableLoop = mainLoop; - - softAPErr = softap_disable(sInstance.mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP disable is requested"); - } - else - { - ChipLogProgress(DeviceLayer, "FAIL: request SoftAP disable [%s]", get_error_message(softAPErr)); - return false; - } - - return true; -} - -void SoftAPManager::_SoftAPCheckSupportedFeature(void) -{ - int sysInfoErr = SYSTEM_INFO_ERROR_NONE; - - mSupportedFeature = false; - sysInfoErr = system_info_get_platform_bool(softap_feature_key, &mSupportedFeature); - if (sysInfoErr == SYSTEM_INFO_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP feature: %s", mSupportedFeature ? "Supported" : "Unsupported"); - } - else - { - ChipLogError(DeviceLayer, "FAIL: get platform system info [%d]", sysInfoErr); - } -} - -CHIP_ERROR SoftAPManager::_SoftAPConfigure(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - uint16_t discriminator = 0; - uint32_t setupPinCode = 0; - uint16_t vendorID = 0; - uint16_t productID = 0; - char softAPSsid[kMaxWiFiSSIDLength] = { - 0, - }; - - err = ConfigurationMgr().GetSetupDiscriminator(discriminator); - if (err == CHIP_NO_ERROR) - { - ChipLogProgress(DeviceLayer, "discriminator[0x%03x]", discriminator & 0xFFF); - } - - err = ConfigurationMgr().GetSetupPinCode(setupPinCode); - if (err == CHIP_NO_ERROR) - { - ChipLogProgress(DeviceLayer, "PinCode[%09xlu]", setupPinCode); - } - - /* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID */ - err = ConfigurationMgr().GetVendorId(vendorID); - if (err == CHIP_NO_ERROR) - { - ChipLogProgress(DeviceLayer, "VendorId[%hu (0x%hx)]", vendorID, vendorID); - } - - /* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID */ - err = ConfigurationMgr().GetProductId(productID); - if (err == CHIP_NO_ERROR) - { - ChipLogProgress(DeviceLayer, "ProductId[%hu (0x%hx)]", productID, productID); - } - - /* - * 5.4.2.9.2. AP Operating Parameters - * SSID : CHIP-ddd-vvvv-pppp - * ddd is the 12-bit Discriminator in hex digits - * vvvv is the 16-bit Vendor ID (VID) in hex digits - * pppp is the 16-bit Product ID (PID) in hex digits - */ - snprintf(softAPSsid, kMaxWiFiSSIDLength, "%s%03X-%04X-%04X", CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX, discriminator, vendorID, - productID); - ChipLogProgress(DeviceLayer, "Configuring WiFi AP: SSID %s", softAPSsid); - - softAPErr = softap_set_ssid(mSoftAPHandle, softAPSsid); - VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); - - softAPErr = softap_set_ssid_visibility(mSoftAPHandle, true); - VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); - - softAPErr = softap_set_channel(mSoftAPHandle, CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL); - VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); - - softAPErr = softap_set_security_type(mSoftAPHandle, SOFTAP_SECURITY_TYPE_NONE); - VerifyOrReturnError(softAPErr == SOFTAP_ERROR_NONE, CHIP_ERROR_INCORRECT_STATE); - - return err; -} - -void SoftAPManager::_SoftAPDeinitialize(void) -{ - int softAPErr = SOFTAP_ERROR_NONE; - - sInstance._SoftAPUnsetCallbacks(); - - softAPErr = softap_destroy(sInstance.mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP is destroyed"); - } - else - { - ChipLogProgress(DeviceLayer, "FAIL: destroy SoftAP [%s]", get_error_message(softAPErr)); - } -} - -void SoftAPManager::_SoftAPSetCallbacks(void) -{ - int softAPErr = SOFTAP_ERROR_NONE; - - softAPErr = softap_set_enabled_cb(mSoftAPHandle, _EnabledCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP enabled callback"); - } - - softAPErr = softap_set_disabled_cb(mSoftAPHandle, _DisabledCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP disabled callback"); - } - - softAPErr = softap_set_security_type_changed_cb(mSoftAPHandle, _SecurityTypeChangedCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP security type changed callback"); - } - - softAPErr = softap_set_ssid_visibility_changed_cb(mSoftAPHandle, _SsidVisibilityChangedCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP ssid visibility changed callback"); - } - - softAPErr = softap_set_passphrase_changed_cb(mSoftAPHandle, _PassphraseChangedCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP passphrase changed callback"); - } - - softAPErr = softap_set_client_connection_state_changed_cb(mSoftAPHandle, _ClientConnectionStateChangedCb, NULL); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Set SoftAP client connection state changed callback"); - } -} - -void SoftAPManager::_SoftAPUnsetCallbacks(void) -{ - int softAPErr = SOFTAP_ERROR_NONE; - - softAPErr = softap_unset_enabled_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP enabled callback"); - } - - softAPErr = softap_unset_disabled_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP disabled callback"); - } - - softAPErr = softap_unset_security_type_changed_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP security type changed callback"); - } - - softAPErr = softap_unset_ssid_visibility_changed_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP ssid visibility changed callback"); - } - - softAPErr = softap_unset_passphrase_changed_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP passphrase changed callback"); - } - - softAPErr = softap_unset_client_connection_state_changed_cb(mSoftAPHandle); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "Unset SoftAP client connection state changed callback"); - } -} - -void SoftAPManager::Init(void) -{ - sInstance.mEnableLoop = NULL; - sInstance.mDisableLoop = NULL; - - sInstance._SoftAPCheckSupportedFeature(); - VerifyOrReturn(sInstance.mSupportedFeature); - - MainLoop::Instance().Init(_SoftAPInitialize); -} - -void SoftAPManager::Deinit(void) -{ - VerifyOrReturn(sInstance.mSupportedFeature); - - sInstance._SoftAPDeinitialize(); - MainLoop::Instance().Deinit(); -} - -CHIP_ERROR SoftAPManager::IsEnabled(bool * isSoftAPEnabled) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - - VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, isSoftAPEnabled); - if (softAPErr == SOFTAP_ERROR_NONE) - { - ChipLogProgress(DeviceLayer, "SoftAP is %s", *isSoftAPEnabled ? "enabled" : "disabled"); - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is activated [%s]", get_error_message(softAPErr)); - } - - return err; -} - -CHIP_ERROR SoftAPManager::Enable(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - bool isSoftAPEnabled = false; - bool dbusAsyncErr = false; - - VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); - if (softAPErr == SOFTAP_ERROR_NONE) - { - if (isSoftAPEnabled == false) - { - dbusAsyncErr = MainLoop::Instance().AsyncRequest(_SoftAPEnable); - if (dbusAsyncErr == false) - { - err = CHIP_ERROR_INCORRECT_STATE; - } - } - else - { - ChipLogProgress(DeviceLayer, "SoftAP is already enabled"); - } - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); - } - - return err; -} - -CHIP_ERROR SoftAPManager::Disable(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - bool isSoftAPEnabled = false; - bool dbusAsyncErr = false; - - VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); - if (softAPErr == SOFTAP_ERROR_NONE) - { - if (isSoftAPEnabled == true) - { - dbusAsyncErr = MainLoop::Instance().AsyncRequest(_SoftAPDisable); - if (dbusAsyncErr == false) - { - err = CHIP_ERROR_INCORRECT_STATE; - } - } - else - { - ChipLogProgress(DeviceLayer, "SoftAP is already disabled"); - } - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); - } - - return err; -} - -CHIP_ERROR SoftAPManager::GetAPState(bool * apState) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int softAPErr = SOFTAP_ERROR_NONE; - bool isSoftAPEnabled = false; - - VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - softAPErr = softap_is_enabled(sInstance.mSoftAPHandle, &isSoftAPEnabled); - if (softAPErr == SOFTAP_ERROR_NONE) - { - *apState = isSoftAPEnabled; - ChipLogProgress(DeviceLayer, "Get AP state [%s]", isSoftAPEnabled ? "Enabled" : "Disabled"); - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - ChipLogProgress(DeviceLayer, "FAIL: check whether SoftAP is enabled [%s]", get_error_message(softAPErr)); - } - - return err; -} - -CHIP_ERROR SoftAPManager::SetAPState(bool apState) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrReturnError(sInstance.mSupportedFeature, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - if (apState == false) - { - err = Disable(); - } - else - { - err = Enable(); - } - - return err; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip -#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/Tizen/SoftAPManager.h b/src/platform/Tizen/SoftAPManager.h deleted file mode 100644 index 81fe9454348f0e..00000000000000 --- a/src/platform/Tizen/SoftAPManager.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -class SoftAPManager -{ -public: - static void Init(void); - static void Deinit(void); - - static CHIP_ERROR IsEnabled(bool * isSoftAPEnabled); - static CHIP_ERROR Enable(void); - static CHIP_ERROR Disable(void); - - static CHIP_ERROR GetAPState(bool * apState); - static CHIP_ERROR SetAPState(bool apState); - -private: - static void _EnabledCb(softap_error_e softAPErr, bool isRequested, void * userData); - static void _DisabledCb(softap_error_e softAPErr, softap_disabled_cause_e disabledCode, void * userData); - static void _SecurityTypeChangedCb(softap_security_type_e securityType, void * userData); - static void _SsidVisibilityChangedCb(bool visibility, void * userData); - static void _PassphraseChangedCb(void * userData); - static void _ClientConnectionStateChangedCb(softap_client_h client, bool open, void * userData); - - static gboolean _SoftAPInitialize(gpointer userData); - static gboolean _SoftAPEnable(GMainLoop * mainLoop, gpointer userData); - static gboolean _SoftAPDisable(GMainLoop * mainLoop, gpointer userData); - - void _SoftAPCheckSupportedFeature(void); - CHIP_ERROR _SoftAPConfigure(void); - void _SoftAPDeinitialize(void); - void _SoftAPSetCallbacks(void); - void _SoftAPUnsetCallbacks(void); - - static SoftAPManager sInstance; - - softap_h mSoftAPHandle; - GMainLoop * mEnableLoop; - GMainLoop * mDisableLoop; - bool mSupportedFeature; -}; - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI From aa983b65f6e345376e86d96d2715168c6e0c4c15 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Oct 2021 10:23:56 +0900 Subject: [PATCH 4/9] Apply a comment --- src/platform/Tizen/ConnectivityManagerImpl.cpp | 0 src/platform/Tizen/ConnectivityManagerImpl.h | 0 src/platform/Tizen/WiFiManager.cpp | 1 + 3 files changed, 1 insertion(+) mode change 100755 => 100644 src/platform/Tizen/ConnectivityManagerImpl.cpp mode change 100755 => 100644 src/platform/Tizen/ConnectivityManagerImpl.h diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp old mode 100755 new mode 100644 diff --git a/src/platform/Tizen/ConnectivityManagerImpl.h b/src/platform/Tizen/ConnectivityManagerImpl.h old mode 100755 new mode 100644 diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index f10d31b61290de..9e888182197779 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -653,6 +653,7 @@ CHIP_ERROR WiFiManager::Connect(const char * ssid, const char * key) wifi_manager_ap_h foundAp = NULL; g_strlcpy(sInstance.mWiFiSSID, ssid, kMaxWiFiSSIDLength + 1); + sInstance.mWiFiSSID[kMaxWiFiSSIDLength] = '\0'; g_strlcpy(sInstance.mWiFiKey, key, kMaxWiFiKeyLength); wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWifiActivated); From 919102bb4150d2fb5fa425f9f610b3c92cea9897 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Oct 2021 10:32:21 +0900 Subject: [PATCH 5/9] Restyle --- src/platform/Tizen/WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index 9e888182197779..d3d76a4932c6bb 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -119,7 +119,7 @@ const char * __WiFiSecurityTypeToStr(wifi_manager_security_type_e type) return "(unknown)"; } } -} +} // namespace namespace chip { namespace DeviceLayer { From 91297fcc9b8f4189121a222371dc4656f7c8033e Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Oct 2021 13:02:20 +0900 Subject: [PATCH 6/9] Apply a comment for key length --- src/platform/Tizen/WiFiManager.cpp | 3 +-- src/platform/Tizen/WiFiManager.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index d3d76a4932c6bb..8a06d7a0e7336f 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -653,8 +653,7 @@ CHIP_ERROR WiFiManager::Connect(const char * ssid, const char * key) wifi_manager_ap_h foundAp = NULL; g_strlcpy(sInstance.mWiFiSSID, ssid, kMaxWiFiSSIDLength + 1); - sInstance.mWiFiSSID[kMaxWiFiSSIDLength] = '\0'; - g_strlcpy(sInstance.mWiFiKey, key, kMaxWiFiKeyLength); + g_strlcpy(sInstance.mWiFiKey, key, kMaxWiFiKeyLength + 1); wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWifiActivated); VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE; diff --git a/src/platform/Tizen/WiFiManager.h b/src/platform/Tizen/WiFiManager.h index b39d6787ee35d9..eb46e9b8e4fbd9 100644 --- a/src/platform/Tizen/WiFiManager.h +++ b/src/platform/Tizen/WiFiManager.h @@ -87,7 +87,7 @@ class WiFiManager wifi_manager_connection_state_e mConnectionState; char mWiFiSSID[kMaxWiFiSSIDLength + 1]; - char mWiFiKey[kMaxWiFiKeyLength]; + char mWiFiKey[kMaxWiFiKeyLength + 1]; }; inline WiFiManager & WiFiMgr() From 012f5d57269577a7b732c26e3f8ea4f67403d755 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Tue, 5 Oct 2021 09:21:59 +0900 Subject: [PATCH 7/9] Remove exit section --- .../Tizen/ConnectivityManagerImpl.cpp | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp index 57419aceee9a3c..e5bd774e59bd47 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -75,22 +75,13 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod CHIP_ERROR err = CHIP_NO_ERROR; wifi_manager_device_state_e deviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; - if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) - { - err = WiFiMgr().GetDeviceState(&deviceState); - SuccessOrExit(err); - - if (deviceState == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) - { - mWiFiStationMode = kWiFiStationMode_Enabled; - } - else - { - mWiFiStationMode = kWiFiStationMode_Disabled; - } - } + 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; -exit: return mWiFiStationMode; } @@ -99,12 +90,12 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiF CHIP_ERROR err = CHIP_NO_ERROR; wifi_manager_device_state_e deviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; - VerifyOrExit(val != kWiFiStationMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(val != kWiFiStationMode_ApplicationControlled, ); + ReturnErrorCodeIf(val == kWiFiStationMode_NotSupported, CHIP_ERROR_INVALID_ARGUMENT); + ReturnErrorCodeIf(val == kWiFiStationMode_ApplicationControlled, CHIP_NO_ERROR); deviceState = (val == kWiFiStationMode_Disabled) ? WIFI_MANAGER_DEVICE_STATE_DEACTIVATED : WIFI_MANAGER_DEVICE_STATE_ACTIVATED; err = WiFiMgr().SetDeviceState(deviceState); - SuccessOrExit(err); + VerifyOrReturnError(err == CHIP_NO_ERROR, err); if (mWiFiStationMode != val) { @@ -114,7 +105,6 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiF mWiFiStationMode = val; } -exit: return err; } @@ -146,12 +136,11 @@ bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) bool isWifiStationConnected = false; err = WiFiMgr().GetConnectionState(&connectionState); - SuccessOrExit(err); + VerifyOrReturnError(err == CHIP_NO_ERROR, isWifiStationConnected); if (connectionState == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) isWifiStationConnected = true; -exit: return isWifiStationConnected; } @@ -162,12 +151,11 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) bool isWifiStationProvisioned = false; err = WiFiMgr().GetConnectionState(&connectionState); - SuccessOrExit(err); + VerifyOrReturnError(err == CHIP_NO_ERROR, isWifiStationProvisioned); if (connectionState >= WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION) isWifiStationProvisioned = true; -exit: return isWifiStationProvisioned; } From 69bd9b951aedc41e223a186cc5b576f19295ceab Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Thu, 7 Oct 2021 09:56:49 +0900 Subject: [PATCH 8/9] Set flag as 0 for WIFI_AP --- src/platform/Tizen/CHIPDevicePlatformConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/Tizen/CHIPDevicePlatformConfig.h b/src/platform/Tizen/CHIPDevicePlatformConfig.h index 35e80c6ee5415c..685887004defa9 100644 --- a/src/platform/Tizen/CHIPDevicePlatformConfig.h +++ b/src/platform/Tizen/CHIPDevicePlatformConfig.h @@ -27,7 +27,7 @@ // ==================== Platform Adaptations ==================== #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 -#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0 From 11aa9ffa32977c8d0793ec6dcc7dcaf5def7e902 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Tue, 19 Oct 2021 13:49:25 +0900 Subject: [PATCH 9/9] Apply a comment for setting wifi station mode --- src/platform/Tizen/ConnectivityManagerImpl.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp index e5bd774e59bd47..c9f27c41c08360 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -91,11 +91,14 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiF wifi_manager_device_state_e deviceState = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; ReturnErrorCodeIf(val == kWiFiStationMode_NotSupported, CHIP_ERROR_INVALID_ARGUMENT); - ReturnErrorCodeIf(val == kWiFiStationMode_ApplicationControlled, CHIP_NO_ERROR); - 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 (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) {