1 /* |
|
2 * Copyright (c) 2009-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 "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 * Private implementation of wrapper for Symbian Connection Monitor |
|
16 * library's scan interface. |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 |
|
21 #include <QSharedPointer> |
|
22 #include <QVariant> |
|
23 #include <rconnmon.h> |
|
24 #include <cmmanagerdefines_shim.h> |
|
25 |
|
26 // User includes |
|
27 |
|
28 #include "wlanqtutilsap.h" |
|
29 #include "wlanqtutilsconmonwrapper.h" |
|
30 #include "wlanqtutilsconmonwrapperscan_s60_p.h" |
|
31 |
|
32 #include "OstTraceDefinitions.h" |
|
33 #ifdef OST_TRACE_COMPILER_IN_USE |
|
34 #include "wlanqtutilsconmonwrapperscan_s60Traces.h" |
|
35 #endif |
|
36 |
|
37 /*! |
|
38 \class WlanQtUtilsConMonWrapperScan |
|
39 \brief Private wrapper for Symbian Connection Monitor library. |
|
40 |
|
41 Provides functionality to scan WLAN networks. |
|
42 */ |
|
43 |
|
44 // External function prototypes |
|
45 |
|
46 // Local constants |
|
47 |
|
48 //! Size of the scan result buffer. Good for about 100 networks. |
|
49 #define SCAN_RESULT_BUFFER_SIZE 15000 |
|
50 |
|
51 // ======== LOCAL FUNCTIONS ======== |
|
52 |
|
53 // ======== MEMBER FUNCTIONS ======== |
|
54 |
|
55 /*! |
|
56 Constructor. |
|
57 |
|
58 @param [in] wrapper Wrapper to report progress to. |
|
59 */ |
|
60 |
|
61 WlanQtUtilsConMonWrapperScan::WlanQtUtilsConMonWrapperScan( |
|
62 WlanQtUtilsConMonWrapper *wrapper) : |
|
63 CActive(EPriorityStandard), |
|
64 iWlanBuf(NULL), |
|
65 iWlanPtr(0, 0), |
|
66 iScanCancelled(EFalse), |
|
67 q_ptr(wrapper) |
|
68 { |
|
69 OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERSCAN_WLANQTUTILSCONMONWRAPPERSCAN_ENTRY, this); |
|
70 |
|
71 CActiveScheduler::Add(this); |
|
72 // Errors in Connection Monitor Server connection are fatal so just |
|
73 // throw them as exceptions |
|
74 QT_TRAP_THROWING(iMonitor.ConnectL()); |
|
75 |
|
76 OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERSCAN_WLANQTUTILSCONMONWRAPPERSCAN_EXIT, this); |
|
77 } |
|
78 |
|
79 /*! |
|
80 Destructor. |
|
81 */ |
|
82 |
|
83 WlanQtUtilsConMonWrapperScan::~WlanQtUtilsConMonWrapperScan() |
|
84 { |
|
85 OstTraceFunctionEntry1(DUP1_WLANQTUTILSCONMONWRAPPERSCAN_WLANQTUTILSCONMONWRAPPERSCAN_ENTRY, this); |
|
86 |
|
87 // Cancel possibly ongoing scan |
|
88 Cancel(); |
|
89 // Cancel notifications and close connection monitor session |
|
90 iMonitor.Close(); |
|
91 delete iWlanBuf; |
|
92 |
|
93 OstTraceFunctionExit1(DUP1_WLANQTUTILSCONMONWRAPPERSCAN_WLANQTUTILSCONMONWRAPPERSCAN_EXIT, this); |
|
94 } |
|
95 |
|
96 /*! |
|
97 Request a scan for available WLAN networks. |
|
98 */ |
|
99 |
|
100 void WlanQtUtilsConMonWrapperScan::ScanAvailableWlanAPs() |
|
101 { |
|
102 OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERSCAN_SCANAVAILABLEWLANAPS_ENTRY, this); |
|
103 |
|
104 if (!IsActive()) { |
|
105 // Reserve the scan result buffer, if this is the first scan |
|
106 // request. Same buffer is used for the lifetime of this object. |
|
107 if (iWlanBuf == NULL) { |
|
108 iWlanBuf = new CConnMonWlanNetworksPtrArrayPckg( |
|
109 SCAN_RESULT_BUFFER_SIZE); |
|
110 iWlanPtr.Set(iWlanBuf->Buf()->Des()); |
|
111 } |
|
112 |
|
113 iScanCancelled = EFalse; |
|
114 iMonitor.GetPckgAttribute( |
|
115 EBearerIdWLAN, |
|
116 0, |
|
117 KWlanNetworks, |
|
118 iWlanPtr, |
|
119 iStatus); |
|
120 SetActive(); |
|
121 } |
|
122 |
|
123 OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERSCAN_SCANAVAILABLEWLANAPS_EXIT, this); |
|
124 } |
|
125 |
|
126 /*! |
|
127 Stops a possibly ongoing WLAN scan. |
|
128 */ |
|
129 |
|
130 void WlanQtUtilsConMonWrapperScan::StopScan() |
|
131 { |
|
132 OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERSCAN_STOPSCAN_ENTRY, this); |
|
133 |
|
134 iScanCancelled = ETrue; |
|
135 Cancel(); |
|
136 |
|
137 OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERSCAN_STOPSCAN_EXIT, this); |
|
138 } |
|
139 |
|
140 /*! |
|
141 From CActive: called when active object is cancelled. |
|
142 */ |
|
143 |
|
144 void WlanQtUtilsConMonWrapperScan::DoCancel() |
|
145 { |
|
146 OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERSCAN_DOCANCEL_ENTRY, this); |
|
147 |
|
148 // Stop scan request, if one is active |
|
149 iMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute); |
|
150 |
|
151 OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERSCAN_DOCANCEL_EXIT, this); |
|
152 } |
|
153 |
|
154 /*! |
|
155 From CActive: called when async scan request has been completed. |
|
156 Reports results to owning wrapper. |
|
157 */ |
|
158 |
|
159 void WlanQtUtilsConMonWrapperScan::RunL() |
|
160 { |
|
161 OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERSCAN_RUNL_ENTRY, this); |
|
162 |
|
163 OstTrace1( |
|
164 TRACE_NORMAL, |
|
165 WLANQTUTILSCONMONWRAPPERSCAN_RUNL_STATUS, |
|
166 "WlanQtUtilsConMonWrapperScan::RunL;iStatus=%d", iStatus.Int() ); |
|
167 |
|
168 if (iStatus == KErrNone) { |
|
169 RConnMonWlanNetworksPtrArray wlanPtrArray; |
|
170 iWlanBuf->UnpackToL(wlanPtrArray); |
|
171 QList< QSharedPointer<WlanQtUtilsAp> > wlanScanResult; |
|
172 |
|
173 OstTrace1( |
|
174 TRACE_NORMAL, |
|
175 WLANQTUTILSCONMONWRAPPERSCAN_RUNL_COUNT, |
|
176 "WlanQtUtilsConMonWrapperScan::RunL;count=%d", |
|
177 wlanPtrArray.Count()); |
|
178 |
|
179 for (TInt i = 0; i < wlanPtrArray.Count(); i++) { |
|
180 // Convert name to QString |
|
181 TBuf<CConnMonWlanNetwork::KMaxNameLength> wlanName = |
|
182 wlanPtrArray[i]->Name(); |
|
183 QString wlanNameInQt = |
|
184 QString::fromUtf16(wlanName.Ptr(), wlanName.Length()); |
|
185 |
|
186 OstTraceExt1( |
|
187 TRACE_DUMP, |
|
188 WLANQTUTILSCONMONWRAPPERSCAN_RUNL, |
|
189 "WlanQtUtilsConMonWrapperScan::RunL;name=%S", |
|
190 wlanPtrArray[i]->Name()); |
|
191 |
|
192 // Skip over hidden networks. There is no spec for what |
|
193 // their names will contain, but at least names with only |
|
194 // null characters and whitespace characters are seen |
|
195 // in real life. |
|
196 wlanNameInQt.remove(QChar()); |
|
197 if (wlanNameInQt.trimmed().isEmpty()) { |
|
198 delete wlanPtrArray[i]; |
|
199 continue; |
|
200 } |
|
201 |
|
202 // Go ahead and create the access point |
|
203 QSharedPointer<WlanQtUtilsAp> ap = |
|
204 QSharedPointer<WlanQtUtilsAp>(new WlanQtUtilsAp()); |
|
205 |
|
206 ap->setValue(WlanQtUtilsAp::ConfIdSsid, wlanNameInQt); |
|
207 |
|
208 StoreConMonConnMode(ap, wlanPtrArray[i]->ConnectionMode()); |
|
209 ap->setValue( |
|
210 WlanQtUtilsAp::ConfIdSignalStrength, |
|
211 wlanPtrArray[i]->SignalStrength()); |
|
212 |
|
213 // Security mode values defined in enum TConnMonSecurityModeV2, |
|
214 // rconnmon.h. |
|
215 StoreConMonSecMode(ap, wlanPtrArray[i]->SecurityModeV2()); |
|
216 |
|
217 // TODO: "Adding WLAN network manually" subfreature: |
|
218 // wps (Wifi Protected Setup) support, read this from connmon |
|
219 ap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, false); |
|
220 // TODO: "Adding WLAN network manually" subfreature: |
|
221 // different scan requests needed to identify hidden networks |
|
222 ap->setValue(WlanQtUtilsAp::ConfIdHidden, false); |
|
223 |
|
224 wlanScanResult.append(ap); |
|
225 delete wlanPtrArray[i]; |
|
226 } |
|
227 // Don't report results, if scan was cancelled |
|
228 if (!iScanCancelled) { |
|
229 emit q_ptr->availableWlanApsFromWrapper(wlanScanResult); |
|
230 } |
|
231 // else: scan was probably stopped before results were reveived |
|
232 |
|
233 wlanPtrArray.Close(); |
|
234 |
|
235 // QSharedPointer takes care of memory deallocation |
|
236 wlanScanResult.clear(); |
|
237 } |
|
238 |
|
239 OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERSCAN_RUNL_EXIT, this); |
|
240 } |
|
241 |
|
242 /*! |
|
243 Stores Security mode parameters received from ConnMon to \a ap class. |
|
244 |
|
245 @param ap Access Point object to where the configuration is stored |
|
246 @param conMonSecMode Security mode to store. |
|
247 */ |
|
248 |
|
249 void WlanQtUtilsConMonWrapperScan::StoreConMonSecMode( |
|
250 QSharedPointer<WlanQtUtilsAp> ap, |
|
251 TUint conMonSecMode) |
|
252 { |
|
253 // Entry-exit traces left out on purpose, because this is a simple |
|
254 // function and called many times inside a loop. |
|
255 |
|
256 CMManagerShim::WlanSecMode secMode; |
|
257 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false); |
|
258 |
|
259 switch (conMonSecMode) { |
|
260 case EConnMonSecurityV2WepOpen: |
|
261 case EConnMonSecurityV2WepShared: |
|
262 secMode = CMManagerShim::WlanSecModeWep; |
|
263 break; |
|
264 |
|
265 case EConnMonSecurityV2802d1x: |
|
266 secMode = CMManagerShim::WlanSecMode802_1x; |
|
267 break; |
|
268 |
|
269 case EConnMonSecurityV2Wpa: |
|
270 secMode = CMManagerShim::WlanSecModeWpa; |
|
271 break; |
|
272 |
|
273 case EConnMonSecurityV2WpaPsk: |
|
274 secMode = CMManagerShim::WlanSecModeWpa; |
|
275 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true); |
|
276 break; |
|
277 |
|
278 case EConnMonSecurityV2Wpa2: |
|
279 secMode = CMManagerShim::WlanSecModeWpa2; |
|
280 break; |
|
281 |
|
282 case EConnMonSecurityV2Wpa2Psk: |
|
283 secMode = CMManagerShim::WlanSecModeWpa2; |
|
284 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true); |
|
285 break; |
|
286 |
|
287 case EConnMonSecurityV2Wapi: |
|
288 case EConnMonSecurityV2WapiPsk: |
|
289 secMode = CMManagerShim::WlanSecModeWapi; |
|
290 break; |
|
291 |
|
292 default: |
|
293 Q_ASSERT(conMonSecMode == EConnMonSecurityV2Open); |
|
294 secMode = CMManagerShim::WlanSecModeOpen; |
|
295 break; |
|
296 } |
|
297 |
|
298 ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, secMode); |
|
299 } |
|
300 |
|
301 /*! |
|
302 Stores connection mode parameters received from ConnMon to \a ap class. |
|
303 |
|
304 @param ap Access Point object to where the configuration is stored |
|
305 @param conMonConnMode Connection mode to store. |
|
306 */ |
|
307 |
|
308 void WlanQtUtilsConMonWrapperScan::StoreConMonConnMode( |
|
309 QSharedPointer<WlanQtUtilsAp> ap, |
|
310 TInt conMonConnMode) |
|
311 { |
|
312 // Entry-exit traces left out on purpose, because this is a simple |
|
313 // function and called many times inside a loop. |
|
314 |
|
315 CMManagerShim::WlanConnMode connMode; |
|
316 |
|
317 switch (conMonConnMode){ |
|
318 case EConnMonInfraStructure: |
|
319 case EConnMonSecureInfra: |
|
320 connMode = CMManagerShim::Infra; |
|
321 break; |
|
322 |
|
323 default: |
|
324 Q_ASSERT(conMonConnMode == EConnMonAdHoc); |
|
325 connMode = CMManagerShim::Adhoc; |
|
326 break; |
|
327 } |
|
328 |
|
329 ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, connMode); |
|
330 } |
|