2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetWifi_WifiNetAccountInfoImpl.cpp
20 * @brief This is the implementation file for the _WifiNetAccountInfoImpl
23 * This file contains the implementation of the _WifiNetAccountInfoImpl Class.
25 #include <net_connection.h>
26 #include <FOspConfig.h>
27 #include <FNetWifiWifiNetAccountInfo.h>
28 #include <FBaseSysLog.h>
29 #include "FNet_NetExporter.h"
30 #include "FNetWifi_WifiNetAccountInfoImpl.h"
31 #include "FNetWifi_WifiSecurityInfoImpl.h"
32 #include "FNetWifi_WifiUtility.h"
34 using namespace Tizen::Base;
36 namespace Tizen { namespace Net { namespace Wifi {
38 _WifiNetAccountInfoImpl::_WifiNetAccountInfoImpl(void)
39 :__bssType(WIFI_BSS_TYPE_INFRASTRUCTURE)
42 ,__channel(WIFI_RADIO_CHANNEL_UNKNOWN)
47 _WifiNetAccountInfoImpl::_WifiNetAccountInfoImpl(const _WifiNetAccountInfoImpl &value)
48 :__bssType(value.__bssType)
50 ,__securityInfo(value.__securityInfo)
51 ,__bssid(value.__bssid)
52 ,__channel(value.__channel)
56 _WifiNetAccountInfoImpl::~_WifiNetAccountInfoImpl(void)
61 _WifiNetAccountInfoImpl::GetBssId(void) const
67 _WifiNetAccountInfoImpl::GetSsid(void) const
73 _WifiNetAccountInfoImpl::GetBssType(void) const
78 const WifiSecurityInfo*
79 _WifiNetAccountInfoImpl::GetSecurityInfo(void) const
81 return &__securityInfo;
85 _WifiNetAccountInfoImpl::GetRadioChannel(void) const
91 _WifiNetAccountInfoImpl::SetBssId(String& bssid)
97 _WifiNetAccountInfoImpl::SetSsid(String& ssid)
103 _WifiNetAccountInfoImpl::SetBssType(WifiBssType bssType)
109 _WifiNetAccountInfoImpl::SetSecurityInfo(const WifiSecurityInfo& securityInfo)
111 __securityInfo = securityInfo;
115 _WifiNetAccountInfoImpl::SetRadioChannel(WifiRadioChannel channel)
122 _WifiNetAccountInfoImpl::Equals(const Tizen::Base::Object& obj) const
124 const _WifiNetAccountInfoImpl* pOther = dynamic_cast<const _WifiNetAccountInfoImpl*>(&obj);
127 || __bssType != pOther->__bssType
128 || __ssid != pOther->__ssid
129 || !__securityInfo.Equals(pOther->__securityInfo)
130 || __bssid != pOther->__bssid
131 || __channel != pOther->__channel)
139 _WifiNetAccountInfoImpl::GetHashCode(void) const
141 return __bssid.GetHashCode();
146 _WifiNetAccountInfoImpl::CreateWifiNetAccountInfoN(void* pProfileInfo)
148 result r = E_SUCCESS;
149 WifiNetAccountInfo* pWifiNetAccountInfo = null;
150 _WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl = null;
151 connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileInfo);
155 int radioChannel = 0;
156 connection_wifi_security_type_e secType = CONNECTION_WIFI_SECURITY_TYPE_NONE;
157 connection_wifi_encryption_type_e encType = CONNECTION_WIFI_ENCRYPTION_TYPE_NONE;
161 WifiBssType wifiBssType = WIFI_BSS_TYPE_INFRASTRUCTURE;
162 WifiRadioChannel wifiRadioChannel = WIFI_RADIO_CHANNEL_UNKNOWN;
163 WifiSecurityInfo securityInfo;
164 _WifiSecurityInfoImpl* pSecuInfoImpl = _WifiSecurityInfoImpl::GetInstance(securityInfo);
166 SysTryCatch(NID_NET_WIFI, pProfileInfo, , E_INVALID_ARG, "[E_INVALID_ARG] A profile is NULL.");
168 pWifiNetAccountInfo = new (std::nothrow) WifiNetAccountInfo();
169 SysTryCatch(NID_NET_WIFI, pWifiNetAccountInfo, , E_OUT_OF_MEMORY,
170 "[E_OUT_OF_MEMORY] Memory allocation failed.");
172 pWifiNetAccountInfoImpl = _WifiNetAccountInfoImpl::GetInstance(*pWifiNetAccountInfo);
173 SysTryCatch(NID_NET_WIFI, pWifiNetAccountInfoImpl, , E_OUT_OF_MEMORY,
174 "[E_OUT_OF_MEMORY] Memory allocation failed.");
176 connection_profile_get_wifi_essid(profileHandle, &pSsid);
177 SysTryCatch(NID_NET_WIFI, pSsid, , E_SYSTEM,
178 "[E_SYSTEM] connection_profile_get_wifi_essid failed.");
179 ssid = String(pSsid);
182 connection_profile_get_wifi_bssid(profileHandle, &pBssid);
183 SysTryCatch(NID_NET_WIFI, pBssid, , E_SYSTEM,
184 "[E_SYSTEM] connection_profile_get_wifi_essid failed.");
185 bssid = _WifiUtility::ConvertMacAddress(pBssid);
188 wifiBssType = WIFI_BSS_TYPE_INFRASTRUCTURE;
189 connection_profile_get_wifi_frequency(profileHandle, &radioChannel);
191 wifiRadioChannel = Tizen::Net::Wifi::_WifiUtility::ConvertRadioChannel(radioChannel);
193 connection_profile_get_wifi_security_type(profileHandle,&secType);
194 connection_profile_get_wifi_encryption_type(profileHandle,&encType);
195 pSecuInfoImpl->SetAuthenticationType(_WifiUtility::ConvertAuthType(static_cast <wifi_security_type_e>(secType), static_cast <wifi_encryption_type_e>(encType)));
196 pSecuInfoImpl->SetEncryptionType(_WifiUtility::ConvertEncryptionType(static_cast <wifi_encryption_type_e>(encType)));
198 pWifiNetAccountInfoImpl->SetSsid(ssid);
199 pWifiNetAccountInfoImpl->SetBssType(wifiBssType);
200 pWifiNetAccountInfoImpl->SetBssId(bssid);
201 pWifiNetAccountInfoImpl->SetRadioChannel(wifiRadioChannel);
202 pWifiNetAccountInfoImpl->SetSecurityInfo(securityInfo);
204 r = _NetExporter::InitializeNetAccountInfo(pWifiNetAccountInfo, pProfileInfo);
206 return pWifiNetAccountInfo;
209 if (pWifiNetAccountInfo)
211 delete pWifiNetAccountInfo;
217 _WifiNetAccountInfoImpl*
218 _WifiNetAccountInfoImpl::GetInstance(WifiNetAccountInfo& wifiNetAccountInfo)
220 return wifiNetAccountInfo.__pWifiNetAccountInfoImpl;
223 const _WifiNetAccountInfoImpl*
224 _WifiNetAccountInfoImpl::GetInstance(const WifiNetAccountInfo& wifiNetAccountInfo)
226 return wifiNetAccountInfo.__pWifiNetAccountInfoImpl;
229 } } } // Tizen::Net::Wifi
236 _OSP_EXPORT_ Tizen::Net::Wifi::WifiNetAccountInfo*
237 _WifiNetAccountInfoImpl_CreateWifiNetAccountInfoN(void* pProfileInfo)
239 return Tizen::Net::Wifi::_WifiNetAccountInfoImpl::CreateWifiNetAccountInfoN(pProfileInfo);