From 8e3a49631a6bc1780db66eac8eaeb520bab6e985 Mon Sep 17 00:00:00 2001 From: Jaehwan Lee Date: Tue, 30 Apr 2013 14:35:20 +0900 Subject: [PATCH] Modified to return an exception(E_INVALID_STATE) when you try to connect to a speicific AP that is already connected Change-Id: Ibe472b12e738bbee3b3199b55350679a322f2efe Signed-off-by: Jaehwan Lee --- src/inc/FNetWifi_WifiBssInfoImpl.h | 6 +- src/inc/FNetWifi_WifiSystemAdapter.h | 20 +- src/inc/FNetWifi_WifiUtility.h | 53 +- src/wifi/FNetWifi_WifiBssInfoImpl.cpp | 52 +- src/wifi/FNetWifi_WifiSystemAdapter.cpp | 826 ++++++++++++----------- src/wifi/FNetWifi_WifiUtility.cpp | 1086 ++++++++++++++++--------------- 6 files changed, 1058 insertions(+), 985 deletions(-) diff --git a/src/inc/FNetWifi_WifiBssInfoImpl.h b/src/inc/FNetWifi_WifiBssInfoImpl.h index 7487b55..ffec939 100644 --- a/src/inc/FNetWifi_WifiBssInfoImpl.h +++ b/src/inc/FNetWifi_WifiBssInfoImpl.h @@ -173,9 +173,9 @@ public: /** * Sets the halder for wifi ap. * - * @param[in] apHandler Handle to acces point + * @param[in] pApHandle A handle of access point */ - void SetBssHandle(void* apHandler); + void SetBssHandle(void* pApHandle); /** * @see WifiBssInfo::IsKnown() @@ -324,7 +324,7 @@ private: Tizen::Net::IpAddress* __pSecDnsAddress; Tizen::Net::NetProxyType __proxyType; Tizen::Base::String __proxyAddress; - void* __pApHandler; + void* __pApHandle; }; // _WifiBssInfoImpl diff --git a/src/inc/FNetWifi_WifiSystemAdapter.h b/src/inc/FNetWifi_WifiSystemAdapter.h index c8eb38d..730e4f0 100644 --- a/src/inc/FNetWifi_WifiSystemAdapter.h +++ b/src/inc/FNetWifi_WifiSystemAdapter.h @@ -105,6 +105,16 @@ public: bool IsConnected(void) const; /** + * Checks whether the local device is already connected with a specific remote STA. + * + * @return @c true, if the local device is already connected with a specific remote STA @n + * @c false, otherwise + * @param[in] pApHandle a handle of access point + * + */ + bool IsConnected(wifi_ap_h pApHandle) const; + + /** * Requests a scan for nearby BSS with both infrastructure and independent mode. * * @return An error code @@ -164,23 +174,23 @@ public: * Called when the connection state is changed. * * @param[in] state Connection status - * @param[in] apHanlder Access point handler + * @param[in] pApHandle A handle of access point * @param[in] pUserData The user data passed from the callback registration function */ - static void OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h ap, void* pUserData); + static void OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void* pUserData); /** * Called when each access point is found. * - * @param[in] pApHandler Access point - * @param[in] pUserData The user data passed from the callback registration function + * @param[in] pApHandle A handle of access point + * @param[in] pUserData The user data passed from the callback registration function */ static bool OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData); /** * Called when each access point is checked. * - * @param[in] pApHandle Access point + * @param[in] pApHandle A handle of access point * @param[in] pUserData The user data passed from the callback registration function */ static bool OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUserData); diff --git a/src/inc/FNetWifi_WifiUtility.h b/src/inc/FNetWifi_WifiUtility.h index 2a37aeb..0599225 100644 --- a/src/inc/FNetWifi_WifiUtility.h +++ b/src/inc/FNetWifi_WifiUtility.h @@ -84,8 +84,8 @@ public: * Converts wlan_security_mode_type_t to WifiAuthentication Type * * @return WifiAuthenticationType - * @param[in] securityMode Security Mode - * @param[in] encType Encryption Type + * @param[in] securityMode Security Mode + * @param[in] encType Encryption Type */ static WifiAuthenticationType ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption_type_e encType); @@ -93,7 +93,7 @@ public: * Converts WifiAuthenticationType to wifi_security_type_e * * @return wifi_security_type_e - * @param[in] authMode Authentication Mode + * @param[in] authMode Authentication Mode */ static wifi_security_type_e ConvertSecurityType(WifiAuthenticationType authMode); @@ -101,7 +101,7 @@ public: * Converts frequency to RadioChannel. * * @return WifiRadioChannel - * @param[in] frequency radio frequency value + * @param[in] frequency radio frequency value */ static WifiRadioChannel ConvertRadioChannel(int frequency); @@ -109,7 +109,7 @@ public: * Converts Rssi value from level * * @return long - * @param[in] val rssi value + * @param[in] val rssi value */ static long ConvertLeveltoRssiValue(wifi_rssi_level_e val); @@ -117,7 +117,7 @@ public: * Converts Rssi value from percentage * * @return long - * @param[in] val Rssi percentage value + * @param[in] val Rssi percentage value */ static long ConvertPercentagetoRssiValue(char val); @@ -126,7 +126,7 @@ public: * Converts Encryption Type * * @return WifiEncryptionType - * @param[in] encType Encryption Type + * @param[in] encType Encryption Type */ static WifiEncryptionType ConvertEncryptionType(wifi_encryption_type_e encType); @@ -134,7 +134,7 @@ public: * Converts Encryption Type * * @return wifi_encryption_type_e - * @param[in] encryptionMode Encryption Type + * @param[in] encryptionMode Encryption Type */ static wifi_encryption_type_e ConvertEncryptionType(WifiEncryptionType encryptionMode); @@ -142,8 +142,8 @@ public: * Converts EAP Type * * @return WifiEapType - * @param[in] eapType EAP Type - * @param[in] eapAuthType EAP authentication type + * @param[in] eapType EAP Type + * @param[in] eapAuthType EAP authentication type */ static WifiEapType ConvertEapType(wifi_eap_type_e eapType, wifi_eap_auth_type_e eapAuthType); @@ -151,7 +151,7 @@ public: * Converts EAP Type * * @return wlan_eap_type_t - * @param[in] eapType EAP Type + * @param[in] eapType EAP Type */ static wifi_eap_type_e ConvertEapType(WifiEapType eapType); @@ -159,7 +159,7 @@ public: * Converts EAP Authentication Type * * @return wlan_eap_auth_type_t - * @param[in] eapType EAP authentication type + * @param[in] eapType EAP authentication type */ static wifi_eap_auth_type_e ConvertEapAuthType(WifiEapType eapype); @@ -167,38 +167,51 @@ public: * Converts Mac Address * * @return String - * @param[in] macAddress mac address + * @param[in] macAddress mac address */ static Tizen::Base::String ConvertMacAddress(char macAddress[]); /** + * Gets BSS ID from handle of access point + * + * @return String + * @param[in] pApHandle A handle of access point + * + */ + static Tizen::Base::String GetBssIdFromApHandle(wifi_ap_h pApHandle); + + /** * Converts profile info to bssinfo * * @return WifiBssInfo bss information - * @param[in] apHandler Access Point Handler + * @param[in] pApHandle A handle of access point */ - static WifiBssInfo* CreateWifiBssInfoInstanceN(wifi_ap_h& apHandler); + static WifiBssInfo* CreateWifiBssInfoInstanceN(wifi_ap_h& pApHandle); /** * Releases memory for wifi aphandler and sets it to null * - * @param[in] apHandler Access Point Handler + * @param[in] pDestHandle The destination handle of access point + * @param[in] pSrcHandle The source handle of access point */ - static void WifiApClone(void** pDest, void* pSrc); + static void WifiApClone(void*& pDestHandle, void* pSrcHandle); /** * Clones access point handler * - * @param[in] apHandler Access Point Handler + * @param[in] apHandler A handle of access point */ - static void WifiApDestory(void** pApHandler); + static void WifiApDestory(void*& pApHandler); /** * Checks whether the values of the two %IpAddress objects are equal. */ static bool CheckAddressEquality(Tizen::Net::IpAddress* pFirstAddress, Tizen::Net::IpAddress* pSecondAddress); - static Tizen::Base::Collection::IList* GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList); + /** + * Gets the copy of list of WifiBssInfo. + */ + static Tizen::Base::Collection::IList* GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList); private: /** diff --git a/src/wifi/FNetWifi_WifiBssInfoImpl.cpp b/src/wifi/FNetWifi_WifiBssInfoImpl.cpp index e19b2e0..482c21d 100644 --- a/src/wifi/FNetWifi_WifiBssInfoImpl.cpp +++ b/src/wifi/FNetWifi_WifiBssInfoImpl.cpp @@ -50,18 +50,18 @@ _WifiBssInfoImpl::_WifiBssInfoImpl(void) , __pSecDnsAddress(null) , __proxyType(NET_PROXY_TYPE_NONE) , __proxyAddress() - , __pApHandler(null) + , __pApHandle(null) { } _WifiBssInfoImpl::_WifiBssInfoImpl(const _WifiBssInfoImpl& value) - : __ssid(value.__ssid) - , __bssid(value.__bssid) - , __bssType(value.__bssType) - , __channel(value.__channel) - , __securityInfo(value.__securityInfo) - , __rssi(value.__rssi) - , __dataRate(value.__dataRate) + : __ssid(value.__ssid) + , __bssid(value.__bssid) + , __bssType(value.__bssType) + , __channel(value.__channel) + , __securityInfo(value.__securityInfo) + , __rssi(value.__rssi) + , __dataRate(value.__dataRate) , __isKnown(value.__isKnown) , __scheme(value.__scheme) , __pLocalAddress(null) @@ -71,7 +71,7 @@ _WifiBssInfoImpl::_WifiBssInfoImpl(const _WifiBssInfoImpl& value) , __pSecDnsAddress(null) , __proxyType(NET_PROXY_TYPE_NONE) , __proxyAddress(value.__proxyAddress) - , __pApHandler(null) + , __pApHandle(null) { result r = E_SUCCESS; unique_ptr pTempAddress; @@ -116,11 +116,11 @@ _WifiBssInfoImpl::_WifiBssInfoImpl(const _WifiBssInfoImpl& value) __pSecDnsAddress = pTempAddress.release(); } - if(value.__pApHandler != null) - { - _WifiUtility::WifiApDestory(&__pApHandler); - _WifiUtility::WifiApClone(&__pApHandler, value.__pApHandler); - } + if(value.__pApHandle != null) + { + _WifiUtility::WifiApDestory(__pApHandle); + _WifiUtility::WifiApClone(__pApHandle, value.__pApHandle); + } } _WifiBssInfoImpl::~_WifiBssInfoImpl(void) @@ -130,7 +130,7 @@ _WifiBssInfoImpl::~_WifiBssInfoImpl(void) delete __pGatewayAddress; delete __pPriDnsAddress; delete __pSecDnsAddress; - _WifiUtility::WifiApDestory(&__pApHandler); + _WifiUtility::WifiApDestory(__pApHandle); } String @@ -179,7 +179,7 @@ _WifiBssInfoImpl::GetDataRate(void) const void* _WifiBssInfoImpl::GetBssHandle(void) const { - return __pApHandler; + return __pApHandle; } WifiBssInfo* @@ -234,9 +234,9 @@ _WifiBssInfoImpl::SetDataRate(float dataRate) } void -_WifiBssInfoImpl::SetBssHandle(void* apHandler) +_WifiBssInfoImpl::SetBssHandle(void* pApHandle) { - __pApHandler = apHandler; + __pApHandle = pApHandle; } bool @@ -490,10 +490,10 @@ _WifiBssInfoImpl::GetInstance(const WifiBssInfo& wifiBssInfo) _WifiBssInfoImpl& _WifiBssInfoImpl::operator=(const _WifiBssInfoImpl& rhs) { - if (this == &rhs) - { - return *this; - } + if (this == &rhs) + { + return *this; + } unique_ptr pTempAddress; @@ -550,13 +550,13 @@ _WifiBssInfoImpl::operator=(const _WifiBssInfoImpl& rhs) __proxyType = rhs.__proxyType; __proxyAddress = rhs.__proxyAddress; - if(rhs.__pApHandler != null) + if(rhs.__pApHandle != null) { - _WifiUtility::WifiApDestory(&__pApHandler); - _WifiUtility::WifiApClone(&__pApHandler, rhs.__pApHandler); + _WifiUtility::WifiApDestory(__pApHandle); + _WifiUtility::WifiApClone(__pApHandle, rhs.__pApHandle); } - return *this; + return *this; } } } } // Tizen::Net::Wifi diff --git a/src/wifi/FNetWifi_WifiSystemAdapter.cpp b/src/wifi/FNetWifi_WifiSystemAdapter.cpp index c824165..4ea4974 100644 --- a/src/wifi/FNetWifi_WifiSystemAdapter.cpp +++ b/src/wifi/FNetWifi_WifiSystemAdapter.cpp @@ -52,8 +52,8 @@ namespace Tizen { namespace Net { namespace Wifi { static _WifiSystemAdapter* pInstance = null; _WifiSystemAdapter::_WifiSystemAdapter(void) - : __mgrEvtListenerList() - , __pBssInfo(null) + : __mgrEvtListenerList() + , __pBssInfo(null) { } @@ -64,40 +64,40 @@ _WifiSystemAdapter::~_WifiSystemAdapter(void) result _WifiSystemAdapter::Construct(void) { - int err = WIFI_ERROR_NONE; + int err = WIFI_ERROR_NONE; - err = wifi_initialize(); - SysTryReturnResult(NID_NET_WIFI, ((err == WIFI_ERROR_NONE) || (err == WIFI_ERROR_INVALID_OPERATION)), E_SYSTEM, "Failed to wifi_initialize()"); + err = wifi_initialize(); + SysTryReturnResult(NID_NET_WIFI, ((err == WIFI_ERROR_NONE) || (err == WIFI_ERROR_INVALID_OPERATION)), E_SYSTEM, "Failed to wifi_initialize()"); - err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, null); - SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_device_state_changed_cb()"); + err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, null); + SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_device_state_changed_cb()"); - err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, null); - SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_connection_state_changed_cb()"); + err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, null); + SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_connection_state_changed_cb()"); - err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, null); - SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_rssi_level_changed_cb()"); + err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, null); + SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_rssi_level_changed_cb()"); - err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, null); - SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_background_scan_cb()"); + err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, null); + SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_background_scan_cb()"); - return E_SUCCESS; + return E_SUCCESS; } void _WifiSystemAdapter::InitSingleton(void) { - result r = E_SUCCESS; - unique_ptr<_WifiSystemAdapter> pInst(new (std::nothrow) _WifiSystemAdapter()); - - SysTryReturnVoidResult(NID_NET_WIFI, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + result r = E_SUCCESS; + unique_ptr<_WifiSystemAdapter> pInst(new (std::nothrow) _WifiSystemAdapter()); + + SysTryReturnVoidResult(NID_NET_WIFI, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - r = pInst->Construct(); - SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, r, "[%s] Error occurred in construct.", GetErrorMessage(r)); + r = pInst->Construct(); + SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, r, "[%s] Error occurred in construct.", GetErrorMessage(r)); - pInstance = pInst.release(); + pInstance = pInst.release(); - std::atexit(DestroySingleton); + std::atexit(DestroySingleton); } void @@ -133,93 +133,126 @@ _WifiSystemAdapter::GetInstance(void) result _WifiSystemAdapter::RegisterManagerEventListener(_IWifiManagerEventListener& listener) { - return __mgrEvtListenerList.Add(&listener); + return __mgrEvtListenerList.Add(&listener); } result _WifiSystemAdapter::UnregisterManagerEventListener(_IWifiManagerEventListener& listener) { - return __mgrEvtListenerList.Remove(&listener); + return __mgrEvtListenerList.Remove(&listener); } result _WifiSystemAdapter::Activate(void) { - result r = E_SYSTEM; - int err = WIFI_ERROR_NONE; + result r = E_SYSTEM; + int err = WIFI_ERROR_NONE; - err = wifi_activate(OnWifiActivated, null); - _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); - _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); - _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to activate Wi-Fi. [0x%08X]", err); + err = wifi_activate(OnWifiActivated, null); + _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); + _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); + _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to activate Wi-Fi. [0x%08X]", err); - return E_SUCCESS; + return E_SUCCESS; } result _WifiSystemAdapter::Deactivate(void) { - result r = E_SYSTEM; - int err = WIFI_ERROR_NONE; + result r = E_SYSTEM; + int err = WIFI_ERROR_NONE; - err = wifi_deactivate(OnWifiDeactivated, null); - _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); - _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); - _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to deactivate Wi-Fi. [0x%08X]", err); + err = wifi_deactivate(OnWifiDeactivated, null); + _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); + _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); + _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to deactivate Wi-Fi. [0x%08X]", err); - return E_SUCCESS; + return E_SUCCESS; } String _WifiSystemAdapter::GetMacAddress(void) const { - int err = 0; - char *pMacAddress; - err = wifi_get_mac_address(&pMacAddress); - String macAddress(_WifiUtility::ConvertMacAddress(pMacAddress)); - free(pMacAddress); + int err = 0; + char *pMacAddress; + err = wifi_get_mac_address(&pMacAddress); + String macAddress(_WifiUtility::ConvertMacAddress(pMacAddress)); + free(pMacAddress); - return macAddress; + return macAddress; } bool _WifiSystemAdapter::IsActivated(void) const { - bool val = false; - wifi_is_activated(&val); + bool val = false; + wifi_is_activated(&val); - return val; + return val; } bool _WifiSystemAdapter::IsConnected(void) const { - wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED; + wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED; + + wifi_get_connection_state(&connectionState); + + switch (connectionState) + { + case WIFI_CONNECTION_STATE_CONNECTED: + return true; + default: + return false; + } +} + + +bool +_WifiSystemAdapter::IsConnected(wifi_ap_h pApHandle) const +{ + int err = WIFI_ERROR_NONE; + bool isSame = false; + + if (IsConnected()) + { + wifi_ap_h pConnectedApHandle = null; + err = wifi_get_connected_ap(&pConnectedApHandle); + + if (err != WIFI_ERROR_NONE && pConnectedApHandle == null) + { + SysLog(NID_NET_WIFI, "Failed result from wifi_get_connected_ap() is 0x%x", err); + return false; + } + + String connectedBssId(_WifiUtility::GetBssIdFromApHandle(pConnectedApHandle)); + String targetBssId(_WifiUtility::GetBssIdFromApHandle(pApHandle)); - wifi_get_connection_state(&connectionState); + if (connectedBssId.CompareTo(targetBssId) == 0) + { + isSame = true; + } + + (void)wifi_ap_destroy(pConnectedApHandle); + } - switch (connectionState) - { - case WIFI_CONNECTION_STATE_CONNECTED: - return true; - default: - return false; - } + return isSame; } + result _WifiSystemAdapter::Scan(void) { - result r = E_FAILURE; - int err = WIFI_ERROR_NONE; + result r = E_FAILURE; + int err = WIFI_ERROR_NONE; - err = wifi_scan(OnWifiScanCompleted, null); - _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err); + err = wifi_scan(OnWifiScanCompleted, null); + _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err); - return E_SUCCESS; + return E_SUCCESS; } WifiConnectionState @@ -227,7 +260,7 @@ _WifiSystemAdapter::GetConnectionState(void) const { WifiConnectionState currentState = WIFI_CONN_STATE_NOT_CONNECTED; - wifi_foreach_found_aps(OnWifiEachAccessPointChecked, ¤tState); + wifi_foreach_found_aps(OnWifiEachAccessPointChecked, ¤tState); return currentState; } @@ -235,17 +268,17 @@ _WifiSystemAdapter::GetConnectionState(void) const WifiBssInfo* _WifiSystemAdapter::GetConnectionTargetInfoN(void) const { - WifiBssInfo* pBssInfo = null; - int apRes = WIFI_ERROR_NONE; - wifi_ap_h pApHandle = null; + WifiBssInfo* pBssInfo = null; + int apRes = WIFI_ERROR_NONE; + wifi_ap_h pApHandle = null; - apRes = wifi_get_connected_ap(&pApHandle); - SysTryReturn(NID_NET_WIFI, apRes != WIFI_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, - "[E_OUT_OF_MEMORY] Memory allocation failed."); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Failed to get the connected AP handle."); + apRes = wifi_get_connected_ap(&pApHandle); + SysTryReturn(NID_NET_WIFI, apRes != WIFI_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Memory allocation failed."); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Failed to get the connected AP handle."); - pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandle); - (void)wifi_ap_destroy(pApHandle); + pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandle); + (void)wifi_ap_destroy(pApHandle); SysTryReturn(NID_NET_WIFI, pBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); return pBssInfo; @@ -254,248 +287,248 @@ _WifiSystemAdapter::GetConnectionTargetInfoN(void) const Tizen::Base::Collection::IList* _WifiSystemAdapter::GetSystemScanResultN(void) const { - LinkedList* pBssInfoList = null; + LinkedList* pBssInfoList = null; - pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); - SysTryReturn(NID_NET_WIFI, pBssInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); + SysTryReturn(NID_NET_WIFI, pBssInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); + wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); - return pBssInfoList; + return pBssInfoList; } void _WifiSystemAdapter::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData) { - result r = E_SUCCESS; - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - if(state == WIFI_DEVICE_STATE_ACTIVATED) - { - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiActivated(r); - } - else - { - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiDeactivated(r); - } - } - - delete pEnum; + result r = E_SUCCESS; + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + if(state == WIFI_DEVICE_STATE_ACTIVATED) + { + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiActivated(r); + } + else + { + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiDeactivated(r); + } + } + + delete pEnum; } void _WifiSystemAdapter::OnWifiActivated(wifi_error_e errorCode, void* pUserData) { - result r = E_FAILURE; - _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiActivated(r); - } - - delete pEnum; + result r = E_FAILURE; + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); + + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiActivated(r); + } + + delete pEnum; } void _WifiSystemAdapter::OnWifiDeactivated(wifi_error_e errorCode, void* pUserData) { - result r = E_FAILURE; - _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiDeactivated(r); - } - - delete pEnum; + result r = E_FAILURE; + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); + + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiDeactivated(r); + } + + delete pEnum; } void _WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData) { - result r = E_SUCCESS; - _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); - _WifiConvertErrorResult(errorCode == WIFI_ERROR_ALREADY_EXISTS, r, E_SUCCESS); - _WifiConvertErrorResult(errorCode == WIFI_ERROR_INVALID_KEY, r, E_AUTHENTICATION); - _WifiConvertErrorResult(errorCode == WIFI_ERROR_NO_REPLY, r, E_NOT_RESPONDING); - _WifiConvertErrorResult(errorCode == WIFI_ERROR_DHCP_FAILED, r, E_DHCP); - SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Failed result from OnWifiConnected() is 0x%x.", errorCode); - - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - if(r == E_SUCCESS) - { - char* pEssid = null; - wifi_ap_h apHandler; - int err = wifi_get_connected_ap(&apHandler); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_get_connected_ap() is 0x%x.", err); - _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); - _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); - - err = wifi_ap_get_essid(apHandler, &pEssid); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err); - String ssid(pEssid); - free(pEssid); - - (void)wifi_ap_destroy(apHandler); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiConnected(ssid, r); - } - else - { - String ssid(L""); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiConnected(ssid, r); - } - } - - delete pEnum; + result r = E_SUCCESS; + _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_ALREADY_EXISTS, r, E_SUCCESS); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_INVALID_KEY, r, E_AUTHENTICATION); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NO_REPLY, r, E_NOT_RESPONDING); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_DHCP_FAILED, r, E_DHCP); + SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Failed result from OnWifiConnected() is 0x%x.", errorCode); + + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + if(r == E_SUCCESS) + { + char* pEssid = null; + wifi_ap_h apHandler; + int err = wifi_get_connected_ap(&apHandler); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_get_connected_ap() is 0x%x.", err); + _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + + err = wifi_ap_get_essid(apHandler, &pEssid); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err); + String ssid(pEssid); + free(pEssid); + + (void)wifi_ap_destroy(apHandler); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiConnected(ssid, r); + } + else + { + String ssid(L""); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiConnected(ssid, r); + } + } + + delete pEnum; } void -_WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h apHandler, void *pUserData) +_WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void *pUserData) { - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - switch(state) - { - case WIFI_CONNECTION_STATE_CONNECTED: - { - char* pEssid = null; - int err = wifi_ap_get_essid(apHandler, &pEssid); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err); - String ssid(pEssid); - free(pEssid); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - // Fire a CONNECTED event for notifying that the connection is established not by this system adapter. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:E_SUCCESS]"); - pMgrEvtListener->OnWifiConnected(ssid, E_SUCCESS); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state. - // This seems a little redundant but the purpose of it is quite different from CONNECTED event. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONNECTION_STATE_CONNECTED]"); - pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONNECTED); - } - } - break; - - case WIFI_CONNECTION_STATE_DISCONNECTED: - { - wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED; - wifi_get_connection_state(&connectionState); - - // Ignore if wifi state is connected. - if (connectionState == WIFI_CONNECTION_STATE_CONNECTED) - break; - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]"); - pMgrEvtListener->OnWifiDisconnected(); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state. - // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_NOT_CONNECTED]"); - pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_NOT_CONNECTED); - } - } - break; - - case WIFI_CONNECTION_STATE_ASSOCIATION: - { - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_ASSOCIATING]"); - pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_ASSOCIATING); - } - } - break; - - case WIFI_CONNECTION_STATE_CONFIGURATION: - { - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state. - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_CONFIGURING]"); - pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONFIGURING); - } - } - break; - - default: - break; - } - - delete pEnum; + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + switch(state) + { + case WIFI_CONNECTION_STATE_CONNECTED: + { + char* pEssid = null; + int err = wifi_ap_get_essid(pApHandle, &pEssid); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err); + String ssid(pEssid); + free(pEssid); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTED event for notifying that the connection is established not by this system adapter. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:E_SUCCESS]"); + pMgrEvtListener->OnWifiConnected(ssid, E_SUCCESS); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state. + // This seems a little redundant but the purpose of it is quite different from CONNECTED event. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONNECTION_STATE_CONNECTED]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONNECTED); + } + } + break; + + case WIFI_CONNECTION_STATE_DISCONNECTED: + { + wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED; + wifi_get_connection_state(&connectionState); + + // Ignore if wifi state is connected. + if (connectionState == WIFI_CONNECTION_STATE_CONNECTED) + break; + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]"); + pMgrEvtListener->OnWifiDisconnected(); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state. + // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_NOT_CONNECTED]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_NOT_CONNECTED); + } + } + break; + + case WIFI_CONNECTION_STATE_ASSOCIATION: + { + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_ASSOCIATING]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_ASSOCIATING); + } + } + break; + + case WIFI_CONNECTION_STATE_CONFIGURATION: + { + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_CONFIGURING]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONFIGURING); + } + } + break; + + default: + break; + } + + delete pEnum; } bool _WifiSystemAdapter::OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData) { - WifiBssInfo* pBssInfo = null; - LinkedList* pBssInfoList = static_cast(pUserData); - wifi_ap_h pApHandleClone = null; + WifiBssInfo* pBssInfo = null; + LinkedList* pBssInfoList = static_cast(pUserData); + wifi_ap_h pApHandleClone = null; - int err = wifi_ap_clone(&pApHandleClone, pApHandle); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_clone() is 0x%x.", err); - pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandleClone); - // keep gonig even though creating one WifiBssInfo instance. - SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, GetLastResult(), - "[%s] Propagating because of creating a new WifiBssInfo fails.", GetErrorMessage(GetLastResult())); + int err = wifi_ap_clone(&pApHandleClone, pApHandle); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_clone() is 0x%x.", err); + pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandleClone); + // keep gonig even though creating one WifiBssInfo instance. + SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, GetLastResult(), + "[%s] Propagating because of creating a new WifiBssInfo fails.", GetErrorMessage(GetLastResult())); - pBssInfoList->Add(*pBssInfo); + pBssInfoList->Add(*pBssInfo); - return true; + return true; } bool @@ -534,103 +567,106 @@ _WifiSystemAdapter::OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUse void _WifiSystemAdapter::OnWifiScanCompleted(wifi_error_e errorCode, void *pUserData) { - LinkedList* pBssInfoList = null; - result r = E_FAILURE; - _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); + LinkedList* pBssInfoList = null; + result r = E_FAILURE; + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); - SysTryReturnVoidResult(NID_NET_WIFI, pBssInfoList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); + SysTryReturnVoidResult(NID_NET_WIFI, pBssInfoList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - int err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_foreach_found_aps() is 0x%x.", err); + int err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_foreach_found_aps() is 0x%x.", err); - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r)); - pMgrEvtListener->OnWifiScanCompleted(pBssInfoList, r); - } + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiScanCompleted(pBssInfoList, r); + } - delete pBssInfoList; - delete pEnum; + delete pBssInfoList; + delete pEnum; } void _WifiSystemAdapter::OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData) { - if (errorCode == WIFI_ERROR_NONE) - { - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED]"); - pMgrEvtListener->OnWifiSystemScanResultUpdated(); - } - - delete pEnum; - } + if (errorCode == WIFI_ERROR_NONE) + { + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED]"); + pMgrEvtListener->OnWifiSystemScanResultUpdated(); + } + + delete pEnum; + } } result _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) { result r = E_SUCCESS; - int err = WIFI_ERROR_NONE; - - wifi_ap_h ap; - wifi_security_type_e securityType; - const _WifiBssInfoImpl* pBssInfoImpl = _WifiBssInfoImpl::GetInstance(targetApInfo); - const WifiSecurityInfo* pSecurityInfo = targetApInfo.GetSecurityInfo(); - const _WifiSecurityInfoImpl* pSecurityInfoImpl = _WifiSecurityInfoImpl::GetInstance(*pSecurityInfo); - - if(pBssInfoImpl->GetBssHandle() == null) - { - SysLog(NID_NET_WIFI, "It's Hidden AP"); - - // Sets SSID - unique_ptr pSsidTemp(_StringConverter::CopyToCharArrayN(targetApInfo.GetSsid())); - SysTryReturnResult(NID_NET_WIFI, pSsidTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - err = wifi_ap_create(pSsidTemp.get(), &ap); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_create() is 0x%x.", err); - _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); - _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to create handle of ap."); - - // Sets Authentication Type - securityType = _WifiUtility::ConvertSecurityType(pSecurityInfo->GetAuthenticationType()); - err = wifi_ap_set_security_type(ap, securityType); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_security_type() is 0x%x.", err); - _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set authenticatino type."); - - // Sets Network Key - unique_ptr pKeyTemp(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey())); - SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - err = wifi_ap_set_passphrase(ap,pKeyTemp.get()); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err); - _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key."); - } - else - { - ap = static_cast (pBssInfoImpl->GetBssHandle()); - - unique_ptr pKeyTemp; - const char* pSecurityKey = null; - if (pSecurityInfoImpl->GetNetworkKey().IsEmpty()) - { + int err = WIFI_ERROR_NONE; + + wifi_ap_h pApHandle; + wifi_security_type_e securityType; + const _WifiBssInfoImpl* pBssInfoImpl = _WifiBssInfoImpl::GetInstance(targetApInfo); + const WifiSecurityInfo* pSecurityInfo = targetApInfo.GetSecurityInfo(); + const _WifiSecurityInfoImpl* pSecurityInfoImpl = _WifiSecurityInfoImpl::GetInstance(*pSecurityInfo); + + pApHandle = static_cast (pBssInfoImpl->GetBssHandle()); + + if(pApHandle == null) + { + SysLog(NID_NET_WIFI, "It's Hidden AP"); + + // Sets SSID + unique_ptr pSsidTemp(_StringConverter::CopyToCharArrayN(targetApInfo.GetSsid())); + SysTryReturnResult(NID_NET_WIFI, pSsidTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + err = wifi_ap_create(pSsidTemp.get(), &pApHandle); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_create() is 0x%x.", err); + _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to create handle of ap."); + + // Sets Authentication Type + securityType = _WifiUtility::ConvertSecurityType(pSecurityInfo->GetAuthenticationType()); + err = wifi_ap_set_security_type(pApHandle, securityType); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_security_type() is 0x%x.", err); + _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set authenticatino type."); + + // Sets Network Key + unique_ptr pKeyTemp(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey())); + SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + err = wifi_ap_set_passphrase(pApHandle,pKeyTemp.get()); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err); + _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key."); + } + else + { + SysTryReturnResult(NID_NET_WIFI, !IsConnected(pApHandle), E_INVALID_STATE, + "There is already connected to the same access point."); + + unique_ptr pKeyTemp; + const char* pSecurityKey = null; + if (pSecurityInfoImpl->GetNetworkKey().IsEmpty()) + { switch (targetApInfo.GetSecurityInfo()->GetEncryptionType()) { case WIFI_ENCRYPTION_NONE: @@ -641,11 +677,11 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) break; case WIFI_ENCRYPTION_TKIP: - pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyTkip()); + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyTkip()); break; case WIFI_ENCRYPTION_AES: - pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyAes()); + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyAes()); break; case WIFI_ENCRYPTION_TKIP_AES_MIXED: @@ -659,48 +695,48 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) default: break; } - } - else - { - if (targetApInfo.GetSecurityInfo()->GetEncryptionType() != WIFI_ENCRYPTION_NONE) - { - pKeyTemp.reset(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey())); - SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - pSecurityKey = pKeyTemp.get(); - } - } - - err = wifi_ap_set_passphrase(ap, pSecurityKey); - SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err); - _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key."); - } + } + else + { + if (targetApInfo.GetSecurityInfo()->GetEncryptionType() != WIFI_ENCRYPTION_NONE) + { + pKeyTemp.reset(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey())); + SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + pSecurityKey = pKeyTemp.get(); + } + } + + err = wifi_ap_set_passphrase(pApHandle, pSecurityKey); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err); + _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key."); + } if (pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA || pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA2) { wifi_eap_type_e eapType = _WifiUtility::ConvertEapType(pSecurityInfoImpl->GetEapType()); - err = wifi_ap_set_eap_type(ap, eapType); + err = wifi_ap_set_eap_type(pApHandle, eapType); SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_type() is 0x%x.", err); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap type."); wifi_eap_auth_type_e eapAuthType = _WifiUtility::ConvertEapAuthType(pSecurityInfoImpl->GetEapType()); - err = wifi_ap_set_eap_auth_type(ap, eapAuthType); + err = wifi_ap_set_eap_auth_type(pApHandle, eapAuthType); SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_auth_type() is 0x%x.", err); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type."); - err = wifi_ap_set_eap_passphrase(ap, pSecurityInfoImpl->GetEapUserId(), pSecurityInfoImpl->GetEapPassword()); + err = wifi_ap_set_eap_passphrase(pApHandle, pSecurityInfoImpl->GetEapUserId(), pSecurityInfoImpl->GetEapPassword()); SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_passphrase() is 0x%x.", err); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type."); } - err = wifi_connect(ap, OnWifiConnected, null); + err = wifi_connect(pApHandle, OnWifiConnected, null); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); return E_SUCCESS; @@ -709,21 +745,21 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) void _WifiSystemAdapter::OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void *pUserData) { - long rssi = _WifiUtility::ConvertLeveltoRssiValue(rssiLevel); - _IWifiManagerEventListener* pMgrEvtListener = null; - IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; - _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); - pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + long rssi = _WifiUtility::ConvertLeveltoRssiValue(rssiLevel); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - while (pEnum->MoveNext() == E_SUCCESS) - { - pEnum->GetCurrent(pMgrEvtListener); + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_RSSI_LEVEL_CHANGED]"); - pMgrEvtListener->OnWifiRssiChanged(rssi); - } + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_RSSI_LEVEL_CHANGED]"); + pMgrEvtListener->OnWifiRssiChanged(rssi); + } - delete pEnum; + delete pEnum; } } } } // Tizen::Net::Wifi diff --git a/src/wifi/FNetWifi_WifiUtility.cpp b/src/wifi/FNetWifi_WifiUtility.cpp index ca3f811..ce9d73f 100644 --- a/src/wifi/FNetWifi_WifiUtility.cpp +++ b/src/wifi/FNetWifi_WifiUtility.cpp @@ -52,615 +52,629 @@ _WifiUtility::~_WifiUtility(void) WifiAuthenticationType _WifiUtility::ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption_type_e encryptionMode) { - WifiAuthenticationType authenticationType = WIFI_AUTHENTICATION_OPEN; - - switch (securityMode) - { - case WIFI_SECURITY_TYPE_NONE: - authenticationType = WIFI_AUTHENTICATION_OPEN; - break; - - case WIFI_SECURITY_TYPE_WEP: - authenticationType = WIFI_AUTHENTICATION_SHARED; - break; - - case WIFI_SECURITY_TYPE_EAP: - - if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP) - { - authenticationType = WIFI_AUTHENTICATION_WPA; - } - else if (encryptionMode == WIFI_ENCRYPTION_TYPE_AES - || encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED) - { - authenticationType = WIFI_AUTHENTICATION_WPA2; - } - break; - - case WIFI_SECURITY_TYPE_WPA_PSK: - if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP) - { - authenticationType = WIFI_AUTHENTICATION_WPA_PSK; - } - else if (encryptionMode == WIFI_ENCRYPTION_TYPE_AES) - { - authenticationType = WIFI_AUTHENTICATION_WPA2_PSK; - } - else - { - authenticationType = WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK; - } - break; - default: - break; - } - - return authenticationType; + WifiAuthenticationType authenticationType = WIFI_AUTHENTICATION_OPEN; + + switch (securityMode) + { + case WIFI_SECURITY_TYPE_NONE: + authenticationType = WIFI_AUTHENTICATION_OPEN; + break; + + case WIFI_SECURITY_TYPE_WEP: + authenticationType = WIFI_AUTHENTICATION_SHARED; + break; + + case WIFI_SECURITY_TYPE_EAP: + + if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP) + { + authenticationType = WIFI_AUTHENTICATION_WPA; + } + else if (encryptionMode == WIFI_ENCRYPTION_TYPE_AES + || encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED) + { + authenticationType = WIFI_AUTHENTICATION_WPA2; + } + break; + + case WIFI_SECURITY_TYPE_WPA_PSK: + if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP) + { + authenticationType = WIFI_AUTHENTICATION_WPA_PSK; + } + else if (encryptionMode == WIFI_ENCRYPTION_TYPE_AES) + { + authenticationType = WIFI_AUTHENTICATION_WPA2_PSK; + } + else + { + authenticationType = WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK; + } + break; + default: + break; + } + + return authenticationType; } wifi_security_type_e _WifiUtility::ConvertSecurityType(WifiAuthenticationType authMode) { - wifi_security_type_e authenticationType = WIFI_SECURITY_TYPE_NONE; - - switch (authMode) - { - case WIFI_AUTHENTICATION_OPEN: - { - authenticationType = WIFI_SECURITY_TYPE_NONE; - break; - } - case WIFI_AUTHENTICATION_SHARED: - { - authenticationType = WIFI_SECURITY_TYPE_WEP; - break; - } - case WIFI_AUTHENTICATION_WPA: - case WIFI_AUTHENTICATION_WPA2: - { - authenticationType = WIFI_SECURITY_TYPE_EAP; - break; - } - case WIFI_AUTHENTICATION_WPA_PSK: - { - authenticationType = WIFI_SECURITY_TYPE_WPA_PSK; - break; - } - case WIFI_AUTHENTICATION_WPA2_PSK: - { - authenticationType = WIFI_SECURITY_TYPE_WPA_PSK; - break; - } - default: - break; - } - - return authenticationType; + wifi_security_type_e authenticationType = WIFI_SECURITY_TYPE_NONE; + + switch (authMode) + { + case WIFI_AUTHENTICATION_OPEN: + { + authenticationType = WIFI_SECURITY_TYPE_NONE; + break; + } + case WIFI_AUTHENTICATION_SHARED: + { + authenticationType = WIFI_SECURITY_TYPE_WEP; + break; + } + case WIFI_AUTHENTICATION_WPA: + case WIFI_AUTHENTICATION_WPA2: + { + authenticationType = WIFI_SECURITY_TYPE_EAP; + break; + } + case WIFI_AUTHENTICATION_WPA_PSK: + { + authenticationType = WIFI_SECURITY_TYPE_WPA_PSK; + break; + } + case WIFI_AUTHENTICATION_WPA2_PSK: + { + authenticationType = WIFI_SECURITY_TYPE_WPA_PSK; + break; + } + default: + break; + } + + return authenticationType; } WifiRadioChannel _WifiUtility::ConvertRadioChannel(int frequency) { - WifiRadioChannel radioChannel = WIFI_RADIO_CHANNEL_UNKNOWN; - - switch (frequency) - { - case 2412: - radioChannel = WIFI_RADIO_CHANNEL_1; - break; - case 2417: - radioChannel = WIFI_RADIO_CHANNEL_2; - break; - case 2422: - radioChannel = WIFI_RADIO_CHANNEL_3; - break; - case 2427: - radioChannel = WIFI_RADIO_CHANNEL_4; - break; - case 2432: - radioChannel = WIFI_RADIO_CHANNEL_5; - break; - case 2437: - radioChannel = WIFI_RADIO_CHANNEL_6; - break; - case 2442: - radioChannel = WIFI_RADIO_CHANNEL_7; - break; - case 2447: - radioChannel = WIFI_RADIO_CHANNEL_8; - break; - case 2452: - radioChannel = WIFI_RADIO_CHANNEL_9; - break; - case 2457: - radioChannel = WIFI_RADIO_CHANNEL_10; - break; - case 2462: - radioChannel = WIFI_RADIO_CHANNEL_11; - break; - case 2467: - radioChannel = WIFI_RADIO_CHANNEL_12; - break; - case 2472: - radioChannel = WIFI_RADIO_CHANNEL_13; - break; - case 2484: - radioChannel = WIFI_RADIO_CHANNEL_14; - break; - default: - radioChannel = WIFI_RADIO_CHANNEL_UNKNOWN; - break; - } - - return radioChannel; + WifiRadioChannel radioChannel = WIFI_RADIO_CHANNEL_UNKNOWN; + + switch (frequency) + { + case 2412: + radioChannel = WIFI_RADIO_CHANNEL_1; + break; + case 2417: + radioChannel = WIFI_RADIO_CHANNEL_2; + break; + case 2422: + radioChannel = WIFI_RADIO_CHANNEL_3; + break; + case 2427: + radioChannel = WIFI_RADIO_CHANNEL_4; + break; + case 2432: + radioChannel = WIFI_RADIO_CHANNEL_5; + break; + case 2437: + radioChannel = WIFI_RADIO_CHANNEL_6; + break; + case 2442: + radioChannel = WIFI_RADIO_CHANNEL_7; + break; + case 2447: + radioChannel = WIFI_RADIO_CHANNEL_8; + break; + case 2452: + radioChannel = WIFI_RADIO_CHANNEL_9; + break; + case 2457: + radioChannel = WIFI_RADIO_CHANNEL_10; + break; + case 2462: + radioChannel = WIFI_RADIO_CHANNEL_11; + break; + case 2467: + radioChannel = WIFI_RADIO_CHANNEL_12; + break; + case 2472: + radioChannel = WIFI_RADIO_CHANNEL_13; + break; + case 2484: + radioChannel = WIFI_RADIO_CHANNEL_14; + break; + default: + radioChannel = WIFI_RADIO_CHANNEL_UNKNOWN; + break; + } + + return radioChannel; } long _WifiUtility::ConvertPercentagetoRssiValue(char val) { - if (val >= 75) - { - return -55; - } - else if (val > 50) - { - return -70; - } - else if (val > 25) - { - return -85; - } - else - { - return -100; - } + if (val >= 75) + { + return -55; + } + else if (val > 50) + { + return -70; + } + else if (val > 25) + { + return -85; + } + else + { + return -100; + } } long _WifiUtility::ConvertLeveltoRssiValue(wifi_rssi_level_e val) { - long rssiValue = 0; - SysLog(NID_NET_WIFI, "Enter: [Rssi Level %d]", val); - - switch (val) - { - case WIFI_RSSI_LEVEL_4: - rssiValue = -55; - break; - case WIFI_RSSI_LEVEL_3: - rssiValue = -70; - break; - case WIFI_RSSI_LEVEL_2: - rssiValue = -85; - break; - case WIFI_RSSI_LEVEL_1: - rssiValue = -100; - break; - default: - rssiValue = 0; - break; - } - SysLog(NID_NET_WIFI, "Exit: [Rssi dbm %ld]", rssiValue); - - return rssiValue; + long rssiValue = 0; + SysLog(NID_NET_WIFI, "Enter: [Rssi Level %d]", val); + + switch (val) + { + case WIFI_RSSI_LEVEL_4: + rssiValue = -55; + break; + case WIFI_RSSI_LEVEL_3: + rssiValue = -70; + break; + case WIFI_RSSI_LEVEL_2: + rssiValue = -85; + break; + case WIFI_RSSI_LEVEL_1: + rssiValue = -100; + break; + default: + rssiValue = 0; + break; + } + SysLog(NID_NET_WIFI, "Exit: [Rssi dbm %ld]", rssiValue); + + return rssiValue; } WifiEncryptionType _WifiUtility::ConvertEncryptionType(wifi_encryption_type_e encryptionMode) { - WifiEncryptionType encryptionType = WIFI_ENCRYPTION_NONE; - - switch (encryptionMode) - { - case WIFI_ENCRYPTION_TYPE_NONE: - { - encryptionType = WIFI_ENCRYPTION_NONE; - break; - } - case WIFI_ENCRYPTION_TYPE_WEP: - { - encryptionType = WIFI_ENCRYPTION_WEP; - break; - } - case WIFI_ENCRYPTION_TYPE_TKIP: - { - encryptionType = WIFI_ENCRYPTION_TKIP; - break; - } - case WIFI_ENCRYPTION_TYPE_AES: - { - encryptionType = WIFI_ENCRYPTION_AES; - break; - } - case WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED: - { - encryptionType = WIFI_ENCRYPTION_TKIP_AES_MIXED; - break; - } - default: - break; - } - - return encryptionType; + WifiEncryptionType encryptionType = WIFI_ENCRYPTION_NONE; + + switch (encryptionMode) + { + case WIFI_ENCRYPTION_TYPE_NONE: + { + encryptionType = WIFI_ENCRYPTION_NONE; + break; + } + case WIFI_ENCRYPTION_TYPE_WEP: + { + encryptionType = WIFI_ENCRYPTION_WEP; + break; + } + case WIFI_ENCRYPTION_TYPE_TKIP: + { + encryptionType = WIFI_ENCRYPTION_TKIP; + break; + } + case WIFI_ENCRYPTION_TYPE_AES: + { + encryptionType = WIFI_ENCRYPTION_AES; + break; + } + case WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED: + { + encryptionType = WIFI_ENCRYPTION_TKIP_AES_MIXED; + break; + } + default: + break; + } + + return encryptionType; } wifi_encryption_type_e _WifiUtility::ConvertEncryptionType(WifiEncryptionType encryptionMode) { - wifi_encryption_type_e encryptionType = WIFI_ENCRYPTION_TYPE_NONE; - - switch (encryptionMode) - { - case WIFI_ENCRYPTION_NONE: - { - encryptionType = WIFI_ENCRYPTION_TYPE_NONE; - break; - } - case WIFI_ENCRYPTION_WEP: - { - encryptionType = WIFI_ENCRYPTION_TYPE_WEP; - break; - } - case WIFI_ENCRYPTION_TKIP: - { - encryptionType = WIFI_ENCRYPTION_TYPE_TKIP; - break; - } - case WIFI_ENCRYPTION_AES: - { - encryptionType = WIFI_ENCRYPTION_TYPE_AES; - break; - } - case WIFI_ENCRYPTION_TKIP_AES_MIXED: - { - encryptionType = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; - break; - } - default: - break; - } - - return encryptionType; + wifi_encryption_type_e encryptionType = WIFI_ENCRYPTION_TYPE_NONE; + + switch (encryptionMode) + { + case WIFI_ENCRYPTION_NONE: + { + encryptionType = WIFI_ENCRYPTION_TYPE_NONE; + break; + } + case WIFI_ENCRYPTION_WEP: + { + encryptionType = WIFI_ENCRYPTION_TYPE_WEP; + break; + } + case WIFI_ENCRYPTION_TKIP: + { + encryptionType = WIFI_ENCRYPTION_TYPE_TKIP; + break; + } + case WIFI_ENCRYPTION_AES: + { + encryptionType = WIFI_ENCRYPTION_TYPE_AES; + break; + } + case WIFI_ENCRYPTION_TKIP_AES_MIXED: + { + encryptionType = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; + break; + } + default: + break; + } + + return encryptionType; } WifiEapType _WifiUtility::ConvertEapType(wifi_eap_type_e eapType, wifi_eap_auth_type_e eapAuthType) { - WifiEapType eapReturnType = WIFI_EAP_NONE; - - switch (eapType) - { - case WIFI_EAP_TYPE_PEAP: - if (eapAuthType == WIFI_EAP_AUTH_TYPE_MSCHAPV2) - { - eapReturnType = WIFI_EAP_PEAP_MSCHAPV2; - } - else if(eapAuthType == WIFI_EAP_AUTH_TYPE_GTC) - { - eapReturnType = WIFI_EAP_PEAP_GTC; - } - else - { - SysLog(NID_NET_WIFI,"Not supported EAP authentication type."); - } - break; - case WIFI_EAP_TYPE_TLS: - SysLog(NID_NET_WIFI,"Not supported EAP TLS."); - break; - case WIFI_EAP_TYPE_TTLS: - if (eapAuthType == WIFI_EAP_AUTH_TYPE_MSCHAPV2) - { - eapReturnType = WIFI_EAP_TTLS_MSCHAPV2; - } - else - { - SysLog(NID_NET_WIFI,"Not supported EAP authentication type."); - } - break; - case WIFI_EAP_TYPE_SIM: - eapReturnType = WIFI_EAP_SIM; - break; - case WIFI_EAP_TYPE_AKA: - eapReturnType = WIFI_EAP_AKA; - break; - default: - break; - } - - return eapReturnType; + WifiEapType eapReturnType = WIFI_EAP_NONE; + + switch (eapType) + { + case WIFI_EAP_TYPE_PEAP: + if (eapAuthType == WIFI_EAP_AUTH_TYPE_MSCHAPV2) + { + eapReturnType = WIFI_EAP_PEAP_MSCHAPV2; + } + else if(eapAuthType == WIFI_EAP_AUTH_TYPE_GTC) + { + eapReturnType = WIFI_EAP_PEAP_GTC; + } + else + { + SysLog(NID_NET_WIFI,"Not supported EAP authentication type."); + } + break; + case WIFI_EAP_TYPE_TLS: + SysLog(NID_NET_WIFI,"Not supported EAP TLS."); + break; + case WIFI_EAP_TYPE_TTLS: + if (eapAuthType == WIFI_EAP_AUTH_TYPE_MSCHAPV2) + { + eapReturnType = WIFI_EAP_TTLS_MSCHAPV2; + } + else + { + SysLog(NID_NET_WIFI,"Not supported EAP authentication type."); + } + break; + case WIFI_EAP_TYPE_SIM: + eapReturnType = WIFI_EAP_SIM; + break; + case WIFI_EAP_TYPE_AKA: + eapReturnType = WIFI_EAP_AKA; + break; + default: + break; + } + + return eapReturnType; } wifi_eap_type_e _WifiUtility::ConvertEapType(WifiEapType eapType) { - wifi_eap_type_e eapReturnType = WIFI_EAP_TYPE_PEAP; - switch(eapType) - { - case WIFI_EAP_SIM: - eapReturnType = WIFI_EAP_TYPE_SIM; - break; - case WIFI_EAP_AKA: - eapReturnType = WIFI_EAP_TYPE_AKA; - break; - case WIFI_EAP_TTLS_MSCHAPV2: - eapReturnType = WIFI_EAP_TYPE_TTLS; - break; - case WIFI_EAP_PEAP_MSCHAPV2: - eapReturnType = WIFI_EAP_TYPE_PEAP; - break; - case WIFI_EAP_PEAP_GTC: - eapReturnType = WIFI_EAP_TYPE_PEAP; - break; - case WIFI_EAP_TLS: - eapReturnType = WIFI_EAP_TYPE_TLS; - break; - default: - break; - } - - return eapReturnType; + wifi_eap_type_e eapReturnType = WIFI_EAP_TYPE_PEAP; + switch(eapType) + { + case WIFI_EAP_SIM: + eapReturnType = WIFI_EAP_TYPE_SIM; + break; + case WIFI_EAP_AKA: + eapReturnType = WIFI_EAP_TYPE_AKA; + break; + case WIFI_EAP_TTLS_MSCHAPV2: + eapReturnType = WIFI_EAP_TYPE_TTLS; + break; + case WIFI_EAP_PEAP_MSCHAPV2: + eapReturnType = WIFI_EAP_TYPE_PEAP; + break; + case WIFI_EAP_PEAP_GTC: + eapReturnType = WIFI_EAP_TYPE_PEAP; + break; + case WIFI_EAP_TLS: + eapReturnType = WIFI_EAP_TYPE_TLS; + break; + default: + break; + } + + return eapReturnType; } wifi_eap_auth_type_e _WifiUtility::ConvertEapAuthType(WifiEapType eapType) { - wifi_eap_auth_type_e eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; - switch(eapType) - { - case WIFI_EAP_SIM: - eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; - break; - case WIFI_EAP_AKA: - eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; - break; - case WIFI_EAP_TTLS_MSCHAPV2: - eapAuthType = WIFI_EAP_AUTH_TYPE_MSCHAPV2; - break; - case WIFI_EAP_PEAP_MSCHAPV2: - eapAuthType = WIFI_EAP_AUTH_TYPE_MSCHAPV2; - break; - case WIFI_EAP_PEAP_GTC: - eapAuthType = WIFI_EAP_AUTH_TYPE_GTC; - break; - case WIFI_EAP_TLS: - eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; - break; - default: - break; - } - return eapAuthType; + wifi_eap_auth_type_e eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; + switch(eapType) + { + case WIFI_EAP_SIM: + eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; + break; + case WIFI_EAP_AKA: + eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; + break; + case WIFI_EAP_TTLS_MSCHAPV2: + eapAuthType = WIFI_EAP_AUTH_TYPE_MSCHAPV2; + break; + case WIFI_EAP_PEAP_MSCHAPV2: + eapAuthType = WIFI_EAP_AUTH_TYPE_MSCHAPV2; + break; + case WIFI_EAP_PEAP_GTC: + eapAuthType = WIFI_EAP_AUTH_TYPE_GTC; + break; + case WIFI_EAP_TLS: + eapAuthType = WIFI_EAP_AUTH_TYPE_NONE; + break; + default: + break; + } + return eapAuthType; } String _WifiUtility::ConvertMacAddress(char macAddress[]) { - static const int MAX_MAC_ADDRESS_LENGTH = 17; - String convertMacAddress; - - for (int i = 0; i < MAX_MAC_ADDRESS_LENGTH; i++) - { - if (macAddress[i] == ':') - { - convertMacAddress.Append('-'); - } - else - { - convertMacAddress.Append(macAddress[i]); - } - } - - return convertMacAddress; + static const int MAX_MAC_ADDRESS_LENGTH = 17; + String convertMacAddress; + + for (int i = 0; i < MAX_MAC_ADDRESS_LENGTH; i++) + { + if (macAddress[i] == ':') + { + convertMacAddress.Append('-'); + } + else + { + convertMacAddress.Append(macAddress[i]); + } + } + + return convertMacAddress; +} + +String +_WifiUtility::GetBssIdFromApHandle(wifi_ap_h pApHandle) +{ + char* pBssid = null; + int error = wifi_ap_get_bssid(pApHandle, &pBssid); + SysTryReturn(NID_NET_WIFI, error == WIFI_ERROR_NONE && pBssid != null, String(), E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the BSSID of the AP has failed. [0x%08X].", error); + + String bssId(pBssid); + free(pBssid); + + return bssId; } WifiBssInfo* -_WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) +_WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& pApHandle) { - unique_ptr pBssInfo; - _WifiBssInfoImpl* pBssInfoImpl = null; - result r = E_SUCCESS; - int apRes = WIFI_ERROR_NONE; - - WifiSecurityInfo secuInfo; - _WifiSecurityInfoImpl* pSecuInfoImpl = null; - - wifi_ip_config_type_e ipType = WIFI_IP_CONFIG_TYPE_NONE; - NetAddressScheme netIpScheme = NET_ADDRESS_SCHEME_NONE; - char* pAddrStr = null; - unique_ptr pAddress; - wifi_proxy_type_e proxyType = WIFI_PROXY_TYPE_DIRECT; - NetProxyType netProxyType = NET_PROXY_TYPE_NONE; - - pBssInfo.reset(_WifiBssInfoImpl::CreateWifiBssInfoN()); - SysTryReturn(NID_NET_WIFI, pBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - - pBssInfoImpl = _WifiBssInfoImpl::GetInstance(*pBssInfo); - pBssInfoImpl->SetBssHandle(apHandle); - - // SSID - char* pSsid = null; - apRes = wifi_ap_get_essid(apHandle, &pSsid); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the SSID of the AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetSsid(String(pSsid)); - free(pSsid); - - // BSSID - char* pBssid = null; - apRes = wifi_ap_get_bssid(apHandle, &pBssid); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the BSSID of the AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetBssId(ConvertMacAddress(pBssid)); - free(pBssid); - - // Security type - Authentication type & Encryption type - wifi_security_type_e secType; - apRes = wifi_ap_get_security_type(apHandle, &secType); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the security type of the AP has failed. [0x%08X].", apRes); - - wifi_encryption_type_e encType; - apRes = wifi_ap_get_encryption_type(apHandle, &encType); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the encryption type of the AP has failed. [0x%08X].", apRes); - - SysLog(NID_NET_WIFI, "SSID : %ls security type : %d encryption type : %d", pBssInfoImpl->GetSsid().GetPointer(), secType, encType); - - pSecuInfoImpl = _WifiSecurityInfoImpl::GetInstance(secuInfo); - pSecuInfoImpl->SetAuthenticationType(ConvertAuthType(secType, encType)); - pSecuInfoImpl->SetEncryptionType(ConvertEncryptionType(encType)); - pBssInfoImpl->SetSecurityInfo(secuInfo); - - // BSS Type - pBssInfoImpl->SetBssType(WIFI_BSS_TYPE_INFRASTRUCTURE); - - // Radio Channel - int frequency = -1; - apRes = wifi_ap_get_frequency(apHandle, &frequency); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the frequency band of the AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetRadioChannel(ConvertRadioChannel(frequency)); - - // RSSI - int rssi = -1; - apRes = wifi_ap_get_rssi(apHandle, &rssi); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the RSSI value of the AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetRssi(ConvertPercentagetoRssiValue(rssi)); - - // Data Rate - int dataRate = -1; - apRes = wifi_ap_get_max_speed(apHandle, &dataRate); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the MAX speed of the AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetDataRate(dataRate); - - // Known. - bool isKnown = false; - apRes = wifi_ap_is_favorite(apHandle, &isKnown); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Checking the AP is a known device has failed. [0x%08X].", apRes); - pBssInfoImpl->SetKnown(isKnown); - - // IP Address Scheme. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_ip_config_type(apHandle, WIFI_ADDRESS_FAMILY_IPV4, &ipType); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE && ipType != WIFI_IP_CONFIG_TYPE_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the IP address scheme to AP has failed. [0x%08X].", apRes); - netIpScheme = (ipType == WIFI_IP_CONFIG_TYPE_STATIC) ? NET_ADDRESS_SCHEME_STATIC : NET_ADDRESS_SCHEME_DYNAMIC; - pBssInfoImpl->SetLocalAddressScheme(netIpScheme); - - if (netIpScheme == NET_ADDRESS_SCHEME_STATIC) - { - // IP Address. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_ip_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the IP address to AP has failed. [0x%08X].", apRes); - pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); - r = GetLastResult(); - free(pAddrStr); - SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); - pBssInfoImpl->SetLocalAddress(pAddress.release()); // ignore result - - // Subnet Mask. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_subnet_mask(apHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the subnet mask to AP has failed. [0x%08X].", apRes); - pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); - r = GetLastResult(); - free(pAddrStr); - SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); - pBssInfoImpl->SetSubnetMaskAddress(pAddress.release()); // ignore result - - // Default Gateway Address. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_gateway_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the default gateway address to AP has failed. [0x%08X].", apRes); - pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); - r = GetLastResult(); - free(pAddrStr); - SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); - pBssInfoImpl->SetDefaultGatewayAddress(pAddress.release()); // ignore result - - // Primary DNS Address. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_dns_address(apHandle, 1, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the primary DNS address to AP has failed. [0x%08X].", apRes); - pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); - r = GetLastResult(); - free(pAddrStr); - SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); - pBssInfoImpl->SetPrimaryDnsAddress(pAddress.release()); // ignore result - - // Secondary DNS Address. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_dns_address(apHandle, 2, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Getting the secondary DNS address to AP has failed. [0x%08X].", apRes); - pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); - r = GetLastResult(); - free(pAddrStr); - SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, - "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); - pBssInfoImpl->SetSecondaryDnsAddress(pAddress.release()); // ignore result - } - - // Proxy Type. - apRes = wifi_ap_get_proxy_type(apHandle, &proxyType); - SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + unique_ptr pBssInfo; + _WifiBssInfoImpl* pBssInfoImpl = null; + result r = E_SUCCESS; + int apRes = WIFI_ERROR_NONE; + + WifiSecurityInfo secuInfo; + _WifiSecurityInfoImpl* pSecuInfoImpl = null; + + wifi_ip_config_type_e ipType = WIFI_IP_CONFIG_TYPE_NONE; + NetAddressScheme netIpScheme = NET_ADDRESS_SCHEME_NONE; + char* pAddrStr = null; + unique_ptr pAddress; + wifi_proxy_type_e proxyType = WIFI_PROXY_TYPE_DIRECT; + NetProxyType netProxyType = NET_PROXY_TYPE_NONE; + + pBssInfo.reset(_WifiBssInfoImpl::CreateWifiBssInfoN()); + SysTryReturn(NID_NET_WIFI, pBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pBssInfoImpl = _WifiBssInfoImpl::GetInstance(*pBssInfo); + pBssInfoImpl->SetBssHandle(pApHandle); + + // SSID + char* pSsid = null; + apRes = wifi_ap_get_essid(pApHandle, &pSsid); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the SSID of the AP has failed. [0x%08X].", apRes); + pBssInfoImpl->SetSsid(String(pSsid)); + free(pSsid); + + // BSSID + char* pBssid = null; + apRes = wifi_ap_get_bssid(pApHandle, &pBssid); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the BSSID of the AP has failed. [0x%08X].", apRes); + pBssInfoImpl->SetBssId(ConvertMacAddress(pBssid)); + free(pBssid); + + // Security type - Authentication type & Encryption type + wifi_security_type_e secType; + apRes = wifi_ap_get_security_type(pApHandle, &secType); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the security type of the AP has failed. [0x%08X].", apRes); + + wifi_encryption_type_e encType; + apRes = wifi_ap_get_encryption_type(pApHandle, &encType); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the encryption type of the AP has failed. [0x%08X].", apRes); + + SysLog(NID_NET_WIFI, "SSID : %ls security type : %d encryption type : %d", pBssInfoImpl->GetSsid().GetPointer(), secType, encType); + + pSecuInfoImpl = _WifiSecurityInfoImpl::GetInstance(secuInfo); + pSecuInfoImpl->SetAuthenticationType(ConvertAuthType(secType, encType)); + pSecuInfoImpl->SetEncryptionType(ConvertEncryptionType(encType)); + pBssInfoImpl->SetSecurityInfo(secuInfo); + + // BSS Type + pBssInfoImpl->SetBssType(WIFI_BSS_TYPE_INFRASTRUCTURE); + + // Radio Channel + int frequency = -1; + apRes = wifi_ap_get_frequency(pApHandle, &frequency); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the frequency band of the AP has failed. [0x%08X].", apRes); + pBssInfoImpl->SetRadioChannel(ConvertRadioChannel(frequency)); + + // RSSI + int rssi = -1; + apRes = wifi_ap_get_rssi(pApHandle, &rssi); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the RSSI value of the AP has failed. [0x%08X].", apRes); + pBssInfoImpl->SetRssi(ConvertPercentagetoRssiValue(rssi)); + + // Data Rate + int dataRate = -1; + apRes = wifi_ap_get_max_speed(pApHandle, &dataRate); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the MAX speed of the AP has failed. [0x%08X].", apRes); + pBssInfoImpl->SetDataRate(dataRate); + + // Known. + bool isKnown = false; + apRes = wifi_ap_is_favorite(pApHandle, &isKnown); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Checking the AP is a known device has failed. [0x%08X].", apRes); + pBssInfoImpl->SetKnown(isKnown); + + // IP Address Scheme. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_ip_config_type(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, &ipType); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE && ipType != WIFI_IP_CONFIG_TYPE_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the IP address scheme to AP has failed. [0x%08X].", apRes); + netIpScheme = (ipType == WIFI_IP_CONFIG_TYPE_STATIC) ? NET_ADDRESS_SCHEME_STATIC : NET_ADDRESS_SCHEME_DYNAMIC; + pBssInfoImpl->SetLocalAddressScheme(netIpScheme); + + if (netIpScheme == NET_ADDRESS_SCHEME_STATIC) + { + // IP Address. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_ip_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the IP address to AP has failed. [0x%08X].", apRes); + pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); + r = GetLastResult(); + free(pAddrStr); + SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); + pBssInfoImpl->SetLocalAddress(pAddress.release()); // ignore result + + // Subnet Mask. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_subnet_mask(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the subnet mask to AP has failed. [0x%08X].", apRes); + pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); + r = GetLastResult(); + free(pAddrStr); + SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); + pBssInfoImpl->SetSubnetMaskAddress(pAddress.release()); // ignore result + + // Default Gateway Address. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_gateway_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the default gateway address to AP has failed. [0x%08X].", apRes); + pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); + r = GetLastResult(); + free(pAddrStr); + SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); + pBssInfoImpl->SetDefaultGatewayAddress(pAddress.release()); // ignore result + + // Primary DNS Address. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_dns_address(pApHandle, 1, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the primary DNS address to AP has failed. [0x%08X].", apRes); + pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); + r = GetLastResult(); + free(pAddrStr); + SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); + pBssInfoImpl->SetPrimaryDnsAddress(pAddress.release()); // ignore result + + // Secondary DNS Address. Only IPv4 as the address family is taken into consideration for now. + apRes = wifi_ap_get_dns_address(pApHandle, 2, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Getting the secondary DNS address to AP has failed. [0x%08X].", apRes); + pAddress.reset(new (std::nothrow) Ip4Address(String(pAddrStr))); + r = GetLastResult(); + free(pAddrStr); + SysTryReturn(NID_NET_WIFI, pAddress != null && r == E_SUCCESS, null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Creating an Ip4Address instance has faield. (from [%s])", GetErrorMessage(r)); + pBssInfoImpl->SetSecondaryDnsAddress(pAddress.release()); // ignore result + } + + // Proxy Type. + apRes = wifi_ap_get_proxy_type(pApHandle, &proxyType); + SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Getting the proxy type to AP has failed. [0x%08X].", apRes); - netProxyType = (proxyType == WIFI_PROXY_TYPE_MANUAL) ? NET_PROXY_TYPE_MANUAL : NET_PROXY_TYPE_NONE; - pBssInfoImpl->SetProxyType(netProxyType); + netProxyType = (proxyType == WIFI_PROXY_TYPE_MANUAL) ? NET_PROXY_TYPE_MANUAL : NET_PROXY_TYPE_NONE; + pBssInfoImpl->SetProxyType(netProxyType); - if (netProxyType != NET_PROXY_TYPE_NONE) - { + if (netProxyType != NET_PROXY_TYPE_NONE) + { // Proxy Address. Only IPv4 as the address family is taken into consideration for now. - apRes = wifi_ap_get_proxy_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); + apRes = wifi_ap_get_proxy_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, &pAddrStr); SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Getting the proxy address to AP has failed. [0x%08X].", apRes); - pBssInfoImpl->SetProxyAddress(String(pAddrStr)); // ignore result - free(pAddrStr); - } + pBssInfoImpl->SetProxyAddress(String(pAddrStr)); // ignore result + free(pAddrStr); + } - return pBssInfo.release(); + return pBssInfo.release(); } void -_WifiUtility::WifiApClone(void** pDest, void* pSrc) +_WifiUtility::WifiApClone(void*& pDestHandle, void* pSrcHandle) { - wifi_ap_h *pDestAp = static_cast(pDest); - wifi_ap_h pSrcAp = static_cast(pSrc); - wifi_ap_clone(pDestAp, pSrcAp); + wifi_ap_h& pDestAp = static_cast(pDestHandle); + wifi_ap_h pSrcAp = static_cast(pSrcHandle); + wifi_ap_clone(&pDestAp, pSrcAp); } void -_WifiUtility::WifiApDestory(void** pApHandler) +_WifiUtility::WifiApDestory(void*& pApApHandler) { - wifi_ap_destroy(*pApHandler); - *pApHandler = null; + wifi_ap_destroy(pApApHandler); + pApApHandler = null; } bool _WifiUtility::CheckAddressEquality(Tizen::Net::IpAddress* pFirstAddress, Tizen::Net::IpAddress* pSecondAddress) { - if (pFirstAddress == null && pSecondAddress == null) - { - SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) true"); - return true; - } - else if(pFirstAddress == null && pSecondAddress != null) - { - SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) false"); - return false; - } - else if(pFirstAddress != null && pSecondAddress == null) - { - SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) false"); - return false; - } - - return pFirstAddress->Equals(*pSecondAddress); + if (pFirstAddress == null && pSecondAddress == null) + { + SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) true"); + return true; + } + else if(pFirstAddress == null && pSecondAddress != null) + { + SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) false"); + return false; + } + else if(pFirstAddress != null && pSecondAddress == null) + { + SysLog(NID_NET_WIFI, "if (pFirstAddress == null && pSecondAddress == null) false"); + return false; + } + + return pFirstAddress->Equals(*pSecondAddress); } Tizen::Base::Collection::IList* -- 2.7.4