merge with master
[framework/osp/net.git] / src / wifi / FNetWifi_WifiNetAccountInfoImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file   FNetWifi_WifiNetAccountInfoImpl.cpp
20  * @brief  This is the implementation file for the _WifiNetAccountInfoImpl
21  * @version     1.0
22  *
23  * This file contains the implementation of the _WifiNetAccountInfoImpl Class.
24  */
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"
33
34 using namespace Tizen::Base;
35
36 namespace Tizen { namespace Net { namespace Wifi {
37
38 _WifiNetAccountInfoImpl::_WifiNetAccountInfoImpl(void)
39     :__bssType(WIFI_BSS_TYPE_INFRASTRUCTURE)
40     ,__ssid("")
41     ,__bssid("")
42     ,__channel(WIFI_RADIO_CHANNEL_UNKNOWN)
43 {
44
45 }
46
47 _WifiNetAccountInfoImpl::_WifiNetAccountInfoImpl(const _WifiNetAccountInfoImpl &value)
48     :__bssType(value.__bssType)
49     ,__ssid(value.__ssid)
50     ,__securityInfo(value.__securityInfo)
51     ,__bssid(value.__bssid)
52     ,__channel(value.__channel)
53 {
54 }
55
56 _WifiNetAccountInfoImpl::~_WifiNetAccountInfoImpl(void)
57 {
58 }
59
60 String
61 _WifiNetAccountInfoImpl::GetBssId(void) const
62 {
63     return __bssid;
64 }
65
66 String
67 _WifiNetAccountInfoImpl::GetSsid(void) const
68 {
69     return __ssid;
70 }
71
72 WifiBssType
73 _WifiNetAccountInfoImpl::GetBssType(void) const
74 {
75     return __bssType;
76 }
77
78 const WifiSecurityInfo*
79 _WifiNetAccountInfoImpl::GetSecurityInfo(void) const
80 {
81     return &__securityInfo;
82 }
83
84 WifiRadioChannel
85 _WifiNetAccountInfoImpl::GetRadioChannel(void) const
86 {
87     return __channel;
88 }
89
90 void
91 _WifiNetAccountInfoImpl::SetBssId(String& bssid)
92 {
93     __bssid = bssid;
94 }
95
96 void
97 _WifiNetAccountInfoImpl::SetSsid(String& ssid)
98 {
99     __ssid = ssid;
100 }
101
102 void
103 _WifiNetAccountInfoImpl::SetBssType(WifiBssType bssType)
104 {
105     __bssType = bssType;
106 }
107
108 void
109 _WifiNetAccountInfoImpl::SetSecurityInfo(const WifiSecurityInfo& securityInfo)
110 {
111     __securityInfo = securityInfo;
112 }
113
114 void
115 _WifiNetAccountInfoImpl::SetRadioChannel(WifiRadioChannel channel)
116 {
117     __channel = channel;
118 }
119
120
121 bool
122 _WifiNetAccountInfoImpl::Equals(const Tizen::Base::Object& obj) const
123 {
124     const _WifiNetAccountInfoImpl* pOther = dynamic_cast<const _WifiNetAccountInfoImpl*>(&obj);
125
126     if (pOther == null
127         || __bssType != pOther->__bssType
128         || __ssid != pOther->__ssid
129         || !__securityInfo.Equals(pOther->__securityInfo)
130         || __bssid != pOther->__bssid
131         || __channel != pOther->__channel)
132     {
133         return false;
134     }
135
136     return true;
137 }
138 int
139 _WifiNetAccountInfoImpl::GetHashCode(void) const
140 {
141     return __bssid.GetHashCode();
142 }
143
144
145 WifiNetAccountInfo*
146 _WifiNetAccountInfoImpl::CreateWifiNetAccountInfoN(void* pProfileInfo)
147 {
148         result r = E_SUCCESS;
149         WifiNetAccountInfo* pWifiNetAccountInfo = null;
150         _WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl = null;
151     connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileInfo);
152
153     char *pSsid = null;
154     char *pBssid = null;
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;
158         String ssid;
159         String bssid;
160
161         WifiBssType wifiBssType = WIFI_BSS_TYPE_INFRASTRUCTURE;
162         WifiRadioChannel wifiRadioChannel = WIFI_RADIO_CHANNEL_UNKNOWN;
163         WifiSecurityInfo securityInfo;
164         _WifiSecurityInfoImpl* pSecuInfoImpl = _WifiSecurityInfoImpl::GetInstance(securityInfo);
165
166         SysTryCatch(NID_NET_WIFI, pProfileInfo, , E_INVALID_ARG, "[E_INVALID_ARG] A profile is NULL.");
167
168         pWifiNetAccountInfo = new (std::nothrow) WifiNetAccountInfo();
169         SysTryCatch(NID_NET_WIFI, pWifiNetAccountInfo, , E_OUT_OF_MEMORY,
170                                      "[E_OUT_OF_MEMORY] Memory allocation failed.");
171
172         pWifiNetAccountInfoImpl = _WifiNetAccountInfoImpl::GetInstance(*pWifiNetAccountInfo);
173         SysTryCatch(NID_NET_WIFI, pWifiNetAccountInfoImpl, , E_OUT_OF_MEMORY,
174                                     "[E_OUT_OF_MEMORY] Memory allocation failed.");
175
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);
180     free(pSsid);
181
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);
186     free(pBssid);
187
188         wifiBssType = WIFI_BSS_TYPE_INFRASTRUCTURE;
189     connection_profile_get_wifi_frequency(profileHandle, &radioChannel);
190
191         wifiRadioChannel = Tizen::Net::Wifi::_WifiUtility::ConvertRadioChannel(radioChannel);
192
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)));
197
198     pWifiNetAccountInfoImpl->SetSsid(ssid);
199     pWifiNetAccountInfoImpl->SetBssType(wifiBssType);
200     pWifiNetAccountInfoImpl->SetBssId(bssid);
201     pWifiNetAccountInfoImpl->SetRadioChannel(wifiRadioChannel);
202     pWifiNetAccountInfoImpl->SetSecurityInfo(securityInfo);
203
204         r = _NetExporter::InitializeNetAccountInfo(pWifiNetAccountInfo, pProfileInfo);
205
206         return pWifiNetAccountInfo;
207
208 CATCH:
209         if (pWifiNetAccountInfo)
210         {
211                 delete pWifiNetAccountInfo;
212         }
213
214         return null;
215 }
216
217 _WifiNetAccountInfoImpl*
218 _WifiNetAccountInfoImpl::GetInstance(WifiNetAccountInfo& wifiNetAccountInfo)
219 {
220     return wifiNetAccountInfo.__pWifiNetAccountInfoImpl;
221 }
222
223 const _WifiNetAccountInfoImpl*
224 _WifiNetAccountInfoImpl::GetInstance(const WifiNetAccountInfo& wifiNetAccountInfo)
225 {
226     return wifiNetAccountInfo.__pWifiNetAccountInfoImpl;
227 }
228
229 } } } // Tizen::Net::Wifi
230
231 #ifdef __cplusplus
232 extern "C"
233 {
234 #endif
235
236 _OSP_EXPORT_ Tizen::Net::Wifi::WifiNetAccountInfo*
237 _WifiNetAccountInfoImpl_CreateWifiNetAccountInfoN(void* pProfileInfo)
238 {
239         return Tizen::Net::Wifi::_WifiNetAccountInfoImpl::CreateWifiNetAccountInfoN(pProfileInfo);
240 }
241
242 #ifdef __cplusplus
243 }
244 #endif