|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * WPS Wizard: Private implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <HbTranslator> |
|
21 #include <HbDocumentLoader> |
|
22 #include <QGraphicsWidget> |
|
23 #include <HbMainWindow> |
|
24 #include <HbView> |
|
25 #include <HbStackedWidget> |
|
26 #include <HbLabel> |
|
27 #include <HbAction> |
|
28 #include <QApplication> |
|
29 #include <cmmanagerdefines_shim.h> |
|
30 |
|
31 // Trace includes |
|
32 #include "OstTraceDefinitions.h" |
|
33 #ifdef OST_TRACE_COMPILER_IN_USE |
|
34 #include "wpswizard_pTraces.h" |
|
35 #endif |
|
36 |
|
37 // User includes |
|
38 #include "wlanwizardhelper.h" |
|
39 // WPS Wizard |
|
40 #include "wpswizard.h" |
|
41 #include "wpswizard_p.h" |
|
42 // Wizard Pages |
|
43 #include "wpswizardsteptwo.h" |
|
44 #include "wpswizardstepthreebutton.h" |
|
45 #include "wpswizardstepthreenumber.h" |
|
46 #include "wpswizardstepfour.h" |
|
47 #include "wpswizardstepfive.h" |
|
48 |
|
49 //Forward Decalrations |
|
50 |
|
51 // External function prototypes |
|
52 |
|
53 // Local constants |
|
54 |
|
55 |
|
56 /*! |
|
57 \class WpsWizardPrivate |
|
58 \brief This class providesthe private class implementation for WPS wizard |
|
59 */ |
|
60 |
|
61 // ======== LOCAL FUNCTIONS ======== |
|
62 |
|
63 // ======== MEMBER FUNCTIONS ======== |
|
64 |
|
65 /*! |
|
66 Constructor for the private implementation of wps wizard |
|
67 |
|
68 @param [in] wizard WpsWizard* pointer to the framework object |
|
69 @param [in] wizardHelper WlanWizardHelper * pointer to the wizard helpper class |
|
70 |
|
71 @return WpsWizardPrivate |
|
72 */ |
|
73 WpsWizardPrivate::WpsWizardPrivate(WpsWizard* wizard, |
|
74 WlanWizardHelper *wizardHelper) : |
|
75 q_ptr(wizard), |
|
76 mWizardHelper(wizardHelper), |
|
77 mTranslator(new HbTranslator("wpswizardplugin")), |
|
78 mRandomNumber(0) |
|
79 { |
|
80 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_WPSWIZARDPRIVATE_ENTRY, this); |
|
81 createPages(); |
|
82 OstTraceFunctionExit1(WPSWIZARDPRIVATE_WPSWIZARDPRIVATE_EXIT, this); |
|
83 } |
|
84 |
|
85 /*! |
|
86 Destructor |
|
87 */ |
|
88 WpsWizardPrivate::~WpsWizardPrivate() |
|
89 { |
|
90 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_WPSWIZARDPRIVATE_DESTRUCTOR_ENTRY, this); |
|
91 // have to delete the memory that was allocated in this object |
|
92 mIapList.clear(); |
|
93 OstTraceFunctionExit1(WPSWIZARDPRIVATE_WPSWIZARDPRIVATE_DESTRUCTOR_EXIT, this); |
|
94 } |
|
95 |
|
96 /*! |
|
97 Provides the caller with the functionality to enable/disable the 'Next' button |
|
98 |
|
99 @param [in] enable bool to indicate whether to enable or disable the 'next button' |
|
100 */ |
|
101 void WpsWizardPrivate::enableNextButton(bool enable) |
|
102 { |
|
103 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_ENABLENEXTBUTTON_ENTRY, this); |
|
104 mWizardHelper->enableNextButton(enable); |
|
105 OstTraceFunctionExit1(WPSWIZARDPRIVATE_ENABLENEXTBUTTON_EXIT, this); |
|
106 } |
|
107 |
|
108 /*! |
|
109 Provides the functionality to automatically move to the next page. |
|
110 */ |
|
111 void WpsWizardPrivate::nextPage() |
|
112 { |
|
113 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_NEXTPAGE_ENTRY, this); |
|
114 mWizardHelper->nextPage(); |
|
115 OstTraceFunctionExit1(WPSWIZARDPRIVATE_NEXTPAGE_EXIT, this); |
|
116 } |
|
117 |
|
118 /*! |
|
119 Provides access to the main window |
|
120 |
|
121 @return HbMainWindow* An instance of HbMainWindow. |
|
122 */ |
|
123 HbMainWindow* WpsWizardPrivate::mainWindow() |
|
124 { |
|
125 return mWizardHelper->mainWindow(); |
|
126 } |
|
127 |
|
128 /*! |
|
129 Provides the functionality to store the received settings |
|
130 |
|
131 @param [in] index int indicates the index in the array of received |
|
132 settings to be stored |
|
133 */ |
|
134 void WpsWizardPrivate::storeSettings(int index) |
|
135 { |
|
136 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_STORESETTINGS_ENTRY, this); |
|
137 |
|
138 if (mIapList.count() > index) |
|
139 { |
|
140 mWpsAttr = mIapList[index]; |
|
141 |
|
142 // SSID |
|
143 QString ssid = QString::fromUtf8(reinterpret_cast<const char*> (mWpsAttr.iSsid.Ptr()), |
|
144 mWpsAttr.iSsid.Length()); |
|
145 mWizardHelper->setConfiguration(WlanWizardHelper::ConfSsid, ssid); |
|
146 // WEP Key1 |
|
147 QString str = QString::fromUtf8(reinterpret_cast<const char*>(mWpsAttr.iWepKey1.Ptr()), |
|
148 mWpsAttr.iWepKey1.Length()); |
|
149 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWep1, str); |
|
150 // WEP Key2 |
|
151 str = QString::fromUtf8(reinterpret_cast<const char*> (mWpsAttr.iWepKey2.Ptr()), |
|
152 mWpsAttr.iWepKey2.Length()); |
|
153 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWep2, str); |
|
154 // WEP Key3 |
|
155 str = QString::fromUtf8(reinterpret_cast<const char*> (mWpsAttr.iWepKey3.Ptr()), |
|
156 mWpsAttr.iWepKey3.Length()); |
|
157 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWep3, str); |
|
158 // WEP Key4 |
|
159 str = QString::fromUtf8(reinterpret_cast<const char*> (mWpsAttr.iWepKey4.Ptr()), |
|
160 mWpsAttr.iWepKey4.Length()); |
|
161 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWep4, str); |
|
162 //Default WEP key in use |
|
163 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWepDefault, |
|
164 convertDefaultWepKey(mWpsAttr.iWepDefaultKey)); |
|
165 //Key WPA |
|
166 str = QString::fromUtf8(reinterpret_cast<const char*> (mWpsAttr.iWpaPreSharedKey.Ptr()), |
|
167 mWpsAttr.iWpaPreSharedKey.Length()); |
|
168 mWizardHelper->setConfiguration(WlanWizardHelper::ConfKeyWpa, str); |
|
169 // security mode |
|
170 mWizardHelper->setConfiguration(WlanWizardHelper::ConfSecurityMode, |
|
171 convertSecurityModes(mWpsAttr.iSecurityMode)); |
|
172 // Network Mode |
|
173 mWizardHelper->setConfiguration(WlanWizardHelper::ConfNetworkMode, |
|
174 convertNetworkModes(mWpsAttr.iOperatingMode)); |
|
175 |
|
176 mWizardHelper->setConfiguration(WlanWizardHelper::ConfUsePsk, true); |
|
177 } |
|
178 |
|
179 OstTraceFunctionExit1(WPSWIZARDPRIVATE_STORESETTINGS_EXIT, this); |
|
180 } |
|
181 |
|
182 /*! |
|
183 Provides the functionality to retrieve the ssid of the network to connect |
|
184 |
|
185 @return returns the SSID as a QString |
|
186 */ |
|
187 QString WpsWizardPrivate::getSsid() |
|
188 { |
|
189 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_GETSSID_ENTRY, this); |
|
190 QString ssid; |
|
191 ssid = mWizardHelper->configuration(WlanWizardHelper::ConfSsid).toString(); |
|
192 OstTraceFunctionExit1(WPSWIZARDPRIVATE_GETSSID_EXIT, this); |
|
193 return ssid; |
|
194 } |
|
195 |
|
196 /*! |
|
197 Provides functionality for the caller to store the array of |
|
198 recieved settings from AP |
|
199 |
|
200 @param [in] credentials QList<TWlanProtectedSetupCredentialAttribute>& |
|
201 received settings from wps enabled AP |
|
202 */ |
|
203 void WpsWizardPrivate::storeSettingsArray(QList< |
|
204 TWlanProtectedSetupCredentialAttribute>& credentials) |
|
205 { |
|
206 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_STORESETTINGSARRAY_ENTRY, this); |
|
207 mIapList = credentials; |
|
208 OstTraceFunctionExit1(WPSWIZARDPRIVATE_STORESETTINGSARRAY_EXIT, this); |
|
209 } |
|
210 |
|
211 /*! |
|
212 Returns the array of settings received from the AP |
|
213 |
|
214 @return Array containing the settings |
|
215 */ |
|
216 QList<TWlanProtectedSetupCredentialAttribute> WpsWizardPrivate::getSettingsArray() |
|
217 { |
|
218 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_GETSETTINGSARRAY_ENTRY, this); |
|
219 OstTraceFunctionExit1(WPSWIZARDPRIVATE_GETSETTINGSARRAY_EXIT, this); |
|
220 return mIapList; |
|
221 } |
|
222 |
|
223 /*! |
|
224 Creates the required pages for WPS setup |
|
225 */ |
|
226 void WpsWizardPrivate::createPages() |
|
227 { |
|
228 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_CREATEPAGES_ENTRY, this); |
|
229 |
|
230 mWizardHelper->addPage(WpsWizardPage::PageWpsWizardStep2, |
|
231 new WpsPageStepTwo(this)); |
|
232 |
|
233 mWizardHelper->addPage(WpsWizardPage::PageWpsWizardStep3_Button, |
|
234 new WpsPageStepThreeButton(this)); |
|
235 |
|
236 mWizardHelper->addPage(WpsWizardPage::PageWpsWizardStep3_Number, |
|
237 new WpsPageStepThreeNumber(this)); |
|
238 |
|
239 mWizardHelper->addPage(WpsWizardPage::PageWpsWizardStep4, |
|
240 new WpsPageStepFour(this)); |
|
241 |
|
242 mWizardHelper->addPage(WpsWizardPage::PageWpsWizardStep5, |
|
243 new WpsPageStepFive(this)); |
|
244 |
|
245 OstTraceFunctionExit1(WPSWIZARDPRIVATE_CREATEPAGES_EXIT, this); |
|
246 } |
|
247 |
|
248 /*! |
|
249 Converts enums between wlan security mode to cm manager enums. |
|
250 |
|
251 @param [in] securityMode Security operating mode from wlanmgmt api |
|
252 |
|
253 @return int converted CMManagerShim::WlanSecMode codes |
|
254 */ |
|
255 int WpsWizardPrivate::convertSecurityModes(TWlanIapSecurityMode securityMode) |
|
256 { |
|
257 CMManagerShim::WlanSecMode cmManagerSecurityMode; |
|
258 switch(securityMode) { |
|
259 case EWlanIapSecurityModeWep: |
|
260 cmManagerSecurityMode = CMManagerShim::WlanSecModeWep; |
|
261 break; |
|
262 |
|
263 case EWlanIapSecurityModeWpa: |
|
264 cmManagerSecurityMode = CMManagerShim::WlanSecModeWpa; |
|
265 break; |
|
266 |
|
267 case EWlanIapSecurityModeWpa2Only: |
|
268 cmManagerSecurityMode = CMManagerShim::WlanSecModeWpa2; |
|
269 break; |
|
270 |
|
271 default: |
|
272 // invalid securityMode. |
|
273 // Not possible to get EWlanIapSecurityMode802d1x here. Since not |
|
274 // supported with wps |
|
275 Q_ASSERT(EWlanIapSecurityModeAllowUnsecure == securityMode); |
|
276 cmManagerSecurityMode = CMManagerShim::WlanSecModeOpen; |
|
277 break; |
|
278 } |
|
279 |
|
280 return cmManagerSecurityMode; |
|
281 } |
|
282 |
|
283 /*! |
|
284 Converts enums between wlan wep key index to cm manager enums. |
|
285 |
|
286 @param [in] defaultWepKey Default wep key used in wlanmgmt api |
|
287 |
|
288 @return int converted CMManagerShim::WlanWepKeyIndex codes |
|
289 */ |
|
290 int WpsWizardPrivate::convertDefaultWepKey(TWlanDefaultWepKey defaultWepKey) |
|
291 { |
|
292 int cmManagerWepKeyIndex; |
|
293 |
|
294 switch (defaultWepKey) { |
|
295 case EWlanDefaultWepKey2: |
|
296 cmManagerWepKeyIndex = CMManagerShim::WepKeyIndex2; |
|
297 break; |
|
298 |
|
299 case EWlanDefaultWepKey3: |
|
300 cmManagerWepKeyIndex = CMManagerShim::WepKeyIndex3; |
|
301 break; |
|
302 |
|
303 case EWlanDefaultWepKey4: |
|
304 cmManagerWepKeyIndex = CMManagerShim::WepKeyIndex4; |
|
305 break; |
|
306 |
|
307 case EWlanDefaultWepKey1: |
|
308 default: |
|
309 // It is possible that the value of defaultWepKey is not initialized |
|
310 // when security mode is Open. That's why we cannot assert here. |
|
311 cmManagerWepKeyIndex = CMManagerShim::WepKeyIndex1; |
|
312 break; |
|
313 } |
|
314 return cmManagerWepKeyIndex; |
|
315 } |
|
316 |
|
317 /*! |
|
318 Converts enums between wlan network mode to cm manager enums. |
|
319 |
|
320 @param [in] networkMode Networking operating mode from wlanmgmt api |
|
321 |
|
322 @return int converted CMManagerShim::WlanConnMode codes |
|
323 */ |
|
324 int WpsWizardPrivate::convertNetworkModes(TWlanOperatingMode networkMode) |
|
325 { |
|
326 CMManagerShim::WlanConnMode wlanConnMode; |
|
327 switch (networkMode) { |
|
328 case EWlanOperatingModeAdhoc: |
|
329 wlanConnMode = CMManagerShim::Adhoc; |
|
330 break; |
|
331 |
|
332 default: |
|
333 Q_ASSERT(EWlanOperatingModeInfrastructure == networkMode); |
|
334 wlanConnMode = CMManagerShim::Infra; |
|
335 break; |
|
336 } |
|
337 return wlanConnMode; |
|
338 } |
|
339 |
|
340 /*! |
|
341 Provides with the functionality to store the PIN generated |
|
342 |
|
343 @param [in] random The generated PIN code to be used in succesive steps |
|
344 |
|
345 */ |
|
346 void WpsWizardPrivate::setPin(int random) |
|
347 { |
|
348 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_SETPIN_ENTRY, this); |
|
349 mRandomNumber = random; |
|
350 OstTraceFunctionExit1(WPSWIZARDPRIVATE_SETPIN_EXIT, this); |
|
351 } |
|
352 |
|
353 /*! |
|
354 Returns the PIN code stored in one of the WPS Pages |
|
355 |
|
356 @return PIN code to be used in the WPS operation. |
|
357 */ |
|
358 int WpsWizardPrivate::getPin() |
|
359 { |
|
360 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_GETPIN_ENTRY, this); |
|
361 OstTraceFunctionExit1(WPSWIZARDPRIVATE_GETPIN_EXIT, this); |
|
362 return mRandomNumber; |
|
363 } |
|
364 |
|
365 /*! |
|
366 Returns page id when manual configuration is chosen |
|
367 |
|
368 @param [in] useWps is WPS used or not? |
|
369 |
|
370 @return new page id |
|
371 */ |
|
372 int WpsWizardPrivate::nextPageId(bool useWps) |
|
373 { |
|
374 OstTraceFunctionEntry1(WPSWIZARDPRIVATE_NEXTPAGEID_ENTRY, this); |
|
375 OstTraceFunctionExit1(WPSWIZARDPRIVATE_NEXTPAGEID_EXIT, this); |
|
376 return mWizardHelper->nextPageId(useWps); |
|
377 } |
|
378 |
|
379 /*! |
|
380 Sets wlan configuration value for given configuration identifier. |
|
381 See ConfigurationId for further details about the data types in QVariant. |
|
382 |
|
383 @param [in] confId Configuration Identifier do to be set |
|
384 @param [in] value Value for configuration. |
|
385 */ |
|
386 void WpsWizardPrivate::setConfiguration( |
|
387 WlanWizardHelper::ConfigurationId confId, |
|
388 const QVariant &value) |
|
389 { |
|
390 mWizardHelper->setConfiguration(confId, value); |
|
391 } |