From 5d018dd5e7f0c9473acb2da8b1ccec3c03cf7da1 Mon Sep 17 00:00:00 2001 From: Jaehwan Lee Date: Fri, 29 Mar 2013 01:21:10 +0900 Subject: [PATCH] Fixed issue(DCM-1110) Modified to set the correct passphrase Change-Id: I8d9fbc321aa507a2e27f52e1eda43cc85fc34aed Signed-off-by: Jaehwan Lee --- src/wifi/FNetWifi_WifiSystemAdapter.cpp | 126 +++++++++++++++++--------------- src/wifi/FNetWifi_WifiUtility.cpp | 47 ++++++------ 2 files changed, 91 insertions(+), 82 deletions(-) diff --git a/src/wifi/FNetWifi_WifiSystemAdapter.cpp b/src/wifi/FNetWifi_WifiSystemAdapter.cpp index 8d887e0..9e4bb71 100644 --- a/src/wifi/FNetWifi_WifiSystemAdapter.cpp +++ b/src/wifi/FNetWifi_WifiSystemAdapter.cpp @@ -344,6 +344,7 @@ _WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData) _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, errorCode == WIFI_ERROR_NONE, "Failed result from OnWifiConnected() is 0x%x.", errorCode); _IWifiManagerEventListener* pMgrEvtListener = null; IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; @@ -359,10 +360,12 @@ _WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData) char* pEssid = null; wifi_ap_h apHandler; int err = wifi_get_connected_ap(&apHandler); - _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); + 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); - wifi_ap_get_essid(apHandler, &pEssid); + 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); @@ -396,7 +399,8 @@ _WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, case WIFI_CONNECTION_STATE_CONNECTED: { char* pEssid = null; - wifi_ap_get_essid(apHandler, &pEssid); + 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); @@ -474,7 +478,8 @@ _WifiSystemAdapter::OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserD LinkedList* pBssInfoList = static_cast(pUserData); wifi_ap_h pApHandleClone = null; - wifi_ap_clone(&pApHandleClone, pApHandle); + 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(), @@ -492,7 +497,8 @@ _WifiSystemAdapter::OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUse WifiConnectionState* pLocalState = static_cast(pUserData); bool isContinued = true; - wifi_ap_get_connection_state(pApHandle, &apState); + int err = wifi_ap_get_connection_state(pApHandle, &apState); + SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_connection_state() is 0x%x.", err); switch (apState) { @@ -527,7 +533,8 @@ _WifiSystemAdapter::OnWifiScanCompleted(wifi_error_e errorCode, void *pUserData) pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); SysTryReturnVoidResult(NID_NET_WIFI, pBssInfoList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); + 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; @@ -571,7 +578,7 @@ _WifiSystemAdapter::OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, vo result _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) { - result r = E_SUCCESS; + result r = E_SUCCESS; int err = WIFI_ERROR_NONE; wifi_ap_h ap; @@ -588,6 +595,7 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) 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."); @@ -595,6 +603,7 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) // 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."); @@ -602,6 +611,7 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) 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."); } @@ -609,59 +619,53 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) { ap = static_cast (pBssInfoImpl->GetBssHandle()); - const unsigned char* pSecurityKey = null; + unique_ptr pKeyTemp; + const char* pSecurityKey = null; + if (pSecurityInfoImpl->GetNetworkKey().IsEmpty()) + { + switch (targetApInfo.GetSecurityInfo()->GetEncryptionType()) + { + case WIFI_ENCRYPTION_NONE: + break; + + case WIFI_ENCRYPTION_WEP: + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyWep()); + break; + + case WIFI_ENCRYPTION_TKIP: + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyTkip()); + break; + + case WIFI_ENCRYPTION_AES: + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyAes()); + break; + + case WIFI_ENCRYPTION_TKIP_AES_MIXED: + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyTkip()); + + if (strlen(pSecurityKey) == 0) + { + pSecurityKey = reinterpret_cast (pSecurityInfoImpl->GetNetworkKeyAes()); + } + break; + 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(); + } + } - switch (targetApInfo.GetSecurityInfo()->GetEncryptionType()) - { - case WIFI_ENCRYPTION_NONE: - break; - - case WIFI_ENCRYPTION_WEP: - { - pSecurityKey = pSecurityInfoImpl->GetNetworkKeyWep(); - wifi_ap_set_passphrase(ap,reinterpret_cast (pSecurityKey)); - } - break; - - case WIFI_ENCRYPTION_TKIP: - { - SysLog(NID_NET_WIFI, "WIFI_ENCRYPTION_TKIP"); - - pSecurityKey = pSecurityInfoImpl->GetNetworkKeyTkip(); - - wifi_ap_set_passphrase(ap,reinterpret_cast (pSecurityKey)); - } - break; - - case WIFI_ENCRYPTION_AES: - { - pSecurityKey = pSecurityInfoImpl->GetNetworkKeyAes(); - - wifi_ap_set_passphrase(ap,reinterpret_cast (pSecurityKey)); } - break; - - case WIFI_ENCRYPTION_TKIP_AES_MIXED: - { - pSecurityKey = pSecurityInfoImpl->GetNetworkKeyTkip(); - - if (strlen(reinterpret_cast (pSecurityKey)) == 0) - { - pSecurityKey = pSecurityInfoImpl->GetNetworkKeyAes(); - - if (strlen(reinterpret_cast (pSecurityKey)) > 0) - { - wifi_ap_set_passphrase(ap,reinterpret_cast (pSecurityKey)); - } - } - else - { - wifi_ap_set_passphrase(ap,reinterpret_cast (pSecurityKey)); - } - } - break; - default: - break; - } + 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."); } if (pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA || @@ -669,17 +673,20 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) { wifi_eap_type_e eapType = _WifiUtility::ConvertEapType(pSecurityInfoImpl->GetEapType()); err = wifi_ap_set_eap_type(ap, 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); + 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()); + 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."); @@ -687,6 +694,7 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) err = wifi_connect(ap, OnWifiConnected, null); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); + return E_SUCCESS; } diff --git a/src/wifi/FNetWifi_WifiUtility.cpp b/src/wifi/FNetWifi_WifiUtility.cpp index 9ef7ebe..b1a4a3e 100644 --- a/src/wifi/FNetWifi_WifiUtility.cpp +++ b/src/wifi/FNetWifi_WifiUtility.cpp @@ -57,17 +57,15 @@ _WifiUtility::ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption switch (securityMode) { case WIFI_SECURITY_TYPE_NONE: - { - authenticationType = WIFI_AUTHENTICATION_OPEN; + authenticationType = WIFI_AUTHENTICATION_OPEN; break; - } + case WIFI_SECURITY_TYPE_WEP: - { - authenticationType = WIFI_AUTHENTICATION_SHARED; + authenticationType = WIFI_AUTHENTICATION_SHARED; break; - } + case WIFI_SECURITY_TYPE_EAP: - { + if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP) { authenticationType = WIFI_AUTHENTICATION_WPA; @@ -77,10 +75,9 @@ _WifiUtility::ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption { authenticationType = WIFI_AUTHENTICATION_WPA2; } - break; - } + break; + case WIFI_SECURITY_TYPE_WPA_PSK: - { if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED) { authenticationType = WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK; @@ -90,9 +87,9 @@ _WifiUtility::ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption authenticationType = WIFI_AUTHENTICATION_WPA_PSK; } break; - } + case WIFI_SECURITY_TYPE_WPA2_PSK: - { + if (encryptionMode == WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED) { authenticationType = WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK; @@ -102,7 +99,7 @@ _WifiUtility::ConvertAuthType(wifi_security_type_e securityMode, wifi_encryption authenticationType = WIFI_AUTHENTICATION_WPA2_PSK; } break; - } + default: break; } @@ -471,16 +468,10 @@ _WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) _WifiBssInfoImpl* pBssInfoImpl = null; result r = E_SUCCESS; int apRes = WIFI_ERROR_NONE; - bool isKnown = false; - char* pSsid = null; - char* pBssid = null; + WifiSecurityInfo secuInfo; _WifiSecurityInfoImpl* pSecuInfoImpl = null; - wifi_security_type_e secType; - wifi_encryption_type_e encType; - int frequency = -1; - int rssi = -1; - int speed = -1; + wifi_ip_config_type_e ipType = WIFI_IP_CONFIG_TYPE_NONE; NetAddressScheme netIpScheme = NET_ADDRESS_SCHEME_NONE; char* pAddrStr = null; @@ -495,6 +486,7 @@ _WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) 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); @@ -502,6 +494,7 @@ _WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) 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); @@ -509,14 +502,18 @@ _WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) 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)); @@ -526,24 +523,28 @@ _WifiUtility::CreateWifiBssInfoInstanceN(wifi_ap_h& apHandle) 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 - apRes = wifi_ap_get_max_speed(apHandle, &speed); + 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(speed); + 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); -- 2.7.4