39
|
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 "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 |
* WLAN Management API stubbing for WLAN Qt Utilities use in emulator.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32base.h>
|
|
19 |
#include "wlanscaninfo.h"
|
|
20 |
|
|
21 |
#include <cmmanager_shim.h>
|
|
22 |
|
|
23 |
#include "wlanqtutilsap.h"
|
|
24 |
|
|
25 |
// Information Element ID for SSID as specified in 802.11.
|
|
26 |
static const TUint8 KWlan802Dot11SsidIE = 0;
|
|
27 |
|
|
28 |
// Bit mask for Capability info field to get type (Infra/AdHoc).
|
|
29 |
static const TUint8 KWlan802Dot11CapabilityEssMask = 0x0001;
|
|
30 |
|
|
31 |
// Scan result list iterator. Holds the current index, starting from zero (0).
|
|
32 |
static int ScanResultIterator = 0;
|
|
33 |
|
|
34 |
// Scan result toggler. Used for switching between two different scan result lists.
|
|
35 |
static bool ScanResultPrimary = true;
|
|
36 |
|
|
37 |
// ---------------------------------------------------------
|
|
38 |
// CWlanScanInfo::NewL
|
|
39 |
// ---------------------------------------------------------
|
|
40 |
//
|
|
41 |
CWlanScanInfo* CWlanScanInfo::NewL()
|
|
42 |
{
|
|
43 |
CWlanScanInfo* self = new CWlanScanInfo;
|
|
44 |
return self;
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------
|
|
48 |
// CWlanScanInfo::~CWlanScanInfo
|
|
49 |
// ---------------------------------------------------------
|
|
50 |
//
|
|
51 |
CWlanScanInfo::~CWlanScanInfo()
|
|
52 |
{
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------
|
|
56 |
// CWlanScanInfo::~First
|
|
57 |
// ---------------------------------------------------------
|
|
58 |
//
|
|
59 |
const TWlanScanInfoFrame* CWlanScanInfo::First()
|
|
60 |
{
|
|
61 |
// Rewind to the beginning of scan result list
|
|
62 |
ScanResultIterator = 0;
|
|
63 |
|
|
64 |
return (TWlanScanInfoFrame*)1; // Info frame is not supported
|
|
65 |
}
|
|
66 |
|
|
67 |
// ---------------------------------------------------------
|
|
68 |
// CWlanScanInfo::~Next
|
|
69 |
// ---------------------------------------------------------
|
|
70 |
//
|
|
71 |
const TWlanScanInfoFrame* CWlanScanInfo::Next()
|
|
72 |
{
|
|
73 |
// Go to next AP in scan results
|
|
74 |
ScanResultIterator++;
|
|
75 |
|
|
76 |
return (TWlanScanInfoFrame*)1; // Info frame is not supported
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------
|
|
80 |
// CWlanScanInfo::~IsDone
|
|
81 |
// ---------------------------------------------------------
|
|
82 |
//
|
|
83 |
TBool CWlanScanInfo::IsDone() const
|
|
84 |
{
|
|
85 |
TBool result = EFalse;
|
|
86 |
|
|
87 |
// Amount of scan results is toggled for every scan
|
|
88 |
int scanResultCount;
|
|
89 |
if (ScanResultPrimary) {
|
|
90 |
scanResultCount = 6;
|
|
91 |
} else {
|
|
92 |
scanResultCount = 3;
|
|
93 |
}
|
|
94 |
|
|
95 |
// Iterating is complete when iterator is one past the last item
|
|
96 |
if (ScanResultIterator >= scanResultCount) {
|
|
97 |
result = ETrue;
|
|
98 |
|
|
99 |
// Toggle scan result count
|
|
100 |
ScanResultPrimary = !ScanResultPrimary;
|
|
101 |
}
|
|
102 |
|
|
103 |
return result;
|
|
104 |
}
|
|
105 |
|
|
106 |
// ---------------------------------------------------------
|
|
107 |
// CWlanScanInfo::RXLevel
|
|
108 |
// ---------------------------------------------------------
|
|
109 |
//
|
|
110 |
TUint8 CWlanScanInfo::RXLevel() const
|
|
111 |
{
|
|
112 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
113 |
int rxlevel = ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt();
|
|
114 |
|
|
115 |
return (TUint8)rxlevel;
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------
|
|
119 |
// CWlanScanInfo::Bssid
|
|
120 |
// ---------------------------------------------------------
|
|
121 |
//
|
|
122 |
void CWlanScanInfo::Bssid(
|
|
123 |
TWlanBssid& aBssid ) const
|
|
124 |
{
|
|
125 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
126 |
QByteArray bssid = ap->value(WlanQtUtilsAp::ConfIdBssid).toByteArray();
|
|
127 |
|
|
128 |
// Length must match, since BSSID is always the same length
|
|
129 |
Q_ASSERT(bssid.length() == KWlanMaxBssidLength);
|
|
130 |
|
|
131 |
// Copy the BSSID
|
|
132 |
aBssid.Copy((const unsigned char *)bssid.constData(), bssid.length());
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
// CWlanScanInfo::Capability
|
|
137 |
// ---------------------------------------------------------
|
|
138 |
//
|
|
139 |
TUint16 CWlanScanInfo::Capability() const
|
|
140 |
{
|
|
141 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
142 |
|
|
143 |
TUint16 capabilities = 0;
|
|
144 |
|
|
145 |
// Only connection mode cabability is supported
|
|
146 |
int connMode = ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
|
|
147 |
if (connMode == CMManagerShim::Infra) {
|
|
148 |
capabilities |= KWlan802Dot11CapabilityEssMask;
|
|
149 |
}
|
|
150 |
|
|
151 |
return capabilities;
|
|
152 |
}
|
|
153 |
|
|
154 |
// ---------------------------------------------------------
|
|
155 |
// CWlanScanInfo::InformationElement
|
|
156 |
// ---------------------------------------------------------
|
|
157 |
//
|
|
158 |
TInt CWlanScanInfo::InformationElement(
|
|
159 |
TUint8 aIE,
|
|
160 |
TUint8& aLength,
|
|
161 |
const TUint8** aData )
|
|
162 |
{
|
|
163 |
// Static SSID buffer
|
|
164 |
static TBuf8<255> ssidBuffer;
|
|
165 |
|
|
166 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
167 |
|
|
168 |
aLength = 0;
|
|
169 |
|
|
170 |
// Only SSID IE is supported
|
|
171 |
Q_ASSERT(aIE == KWlan802Dot11SsidIE);
|
|
172 |
(void)aIE;
|
|
173 |
|
|
174 |
// Cypy the SSID
|
|
175 |
QString ssid = ap->value(WlanQtUtilsAp::ConfIdSsid).toString();
|
|
176 |
QByteArray ssidData(ssid.toUtf8());
|
|
177 |
ssidBuffer.Copy(
|
|
178 |
(TUint8*)ssidData.data(),
|
|
179 |
ssidData.length());
|
|
180 |
|
|
181 |
// Give reference to the buffer to the caller
|
|
182 |
*aData = ssidBuffer.Ptr();
|
|
183 |
aLength = (TUint8)ssidBuffer.Length();
|
|
184 |
|
|
185 |
return KErrNone;
|
|
186 |
}
|
|
187 |
|
|
188 |
// ---------------------------------------------------------
|
|
189 |
// CWlanScanInfo::IsProtectedSetupSupported
|
|
190 |
// ---------------------------------------------------------
|
|
191 |
//
|
|
192 |
TBool CWlanScanInfo::IsProtectedSetupSupported()
|
|
193 |
{
|
|
194 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
195 |
|
|
196 |
TBool wpsSupport;
|
|
197 |
bool wps = ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
|
|
198 |
if (wps) {
|
|
199 |
wpsSupport = ETrue;
|
|
200 |
} else {
|
|
201 |
wpsSupport = EFalse;
|
|
202 |
}
|
|
203 |
|
|
204 |
return wpsSupport;
|
|
205 |
}
|
|
206 |
|
|
207 |
// ---------------------------------------------------------
|
|
208 |
// CWlanScanInfo::ExtendedSecurityMode
|
|
209 |
// ---------------------------------------------------------
|
|
210 |
//
|
|
211 |
TWlanConnectionExtentedSecurityMode CWlanScanInfo::ExtendedSecurityMode() const
|
|
212 |
{
|
|
213 |
QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
|
|
214 |
int secMode = ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
|
|
215 |
bool pskUse = ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
|
|
216 |
|
|
217 |
TWlanConnectionExtentedSecurityMode ret;
|
|
218 |
switch (secMode) {
|
|
219 |
case CMManagerShim::WlanSecModeWep:
|
|
220 |
// Both WEP security modes are mapped to same WEP sec mode value.
|
|
221 |
// We test both of them, and toggle the used value each time.
|
|
222 |
static bool wepOpen = true;
|
|
223 |
if (wepOpen) {
|
|
224 |
ret = EWlanConnectionExtentedSecurityModeWepOpen;
|
|
225 |
} else {
|
|
226 |
ret = EWlanConnectionExtentedSecurityModeWepShared;
|
|
227 |
}
|
|
228 |
wepOpen = !wepOpen;
|
|
229 |
break;
|
|
230 |
|
|
231 |
case CMManagerShim::WlanSecMode802_1x:
|
|
232 |
ret = EWlanConnectionExtentedSecurityMode802d1x;
|
|
233 |
break;
|
|
234 |
|
|
235 |
case CMManagerShim::WlanSecModeWpa:
|
|
236 |
if (pskUse)
|
|
237 |
{
|
|
238 |
ret = EWlanConnectionExtentedSecurityModeWpaPsk;
|
|
239 |
}
|
|
240 |
else
|
|
241 |
{
|
|
242 |
ret = EWlanConnectionExtentedSecurityModeWpa;
|
|
243 |
}
|
|
244 |
break;
|
|
245 |
|
|
246 |
case CMManagerShim::WlanSecModeWpa2:
|
|
247 |
if (pskUse)
|
|
248 |
{
|
|
249 |
ret = EWlanConnectionExtentedSecurityModeWpa2Psk;
|
|
250 |
}
|
|
251 |
else
|
|
252 |
{
|
|
253 |
ret = EWlanConnectionExtentedSecurityModeWpa2;
|
|
254 |
}
|
|
255 |
break;
|
|
256 |
|
|
257 |
case CMManagerShim::WlanSecModeWapi:
|
|
258 |
if (pskUse)
|
|
259 |
{
|
|
260 |
ret = EWlanConnectionExtentedSecurityModeWapiPsk;
|
|
261 |
}
|
|
262 |
else
|
|
263 |
{
|
|
264 |
ret = EWlanConnectionExtentedSecurityModeWapi;
|
|
265 |
}
|
|
266 |
break;
|
|
267 |
|
|
268 |
default:
|
|
269 |
ret = EWlanConnectionExtentedSecurityModeOpen;
|
|
270 |
break;
|
|
271 |
}
|
|
272 |
|
|
273 |
return ret;
|
|
274 |
}
|
|
275 |
|
|
276 |
// ---------------------------------------------------------
|
|
277 |
// CWlanScanInfo::CWlanScanInfo
|
|
278 |
// ---------------------------------------------------------
|
|
279 |
//
|
|
280 |
CWlanScanInfo::CWlanScanInfo()
|
|
281 |
{
|
|
282 |
}
|
|
283 |
|
|
284 |
// ---------------------------------------------------------
|
|
285 |
// CWlanScanInfo::GetCurrentAp
|
|
286 |
// ---------------------------------------------------------
|
|
287 |
//
|
|
288 |
QSharedPointer<WlanQtUtilsAp> CWlanScanInfo::GetCurrentAp() const
|
|
289 |
{
|
|
290 |
// If this fails, client iterates erroneously
|
|
291 |
Q_ASSERT(!IsDone());
|
|
292 |
|
|
293 |
// Get the currently iterated AP
|
|
294 |
QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp());
|
|
295 |
|
|
296 |
// Store default setting data
|
|
297 |
QString ssid("Test AP ");
|
|
298 |
ssid.append(QString::number(ScanResultIterator + 1));
|
|
299 |
ap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid);
|
|
300 |
ap->setValue(WlanQtUtilsAp::ConfIdBssid, QByteArray("123456"));
|
|
301 |
ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 20);
|
|
302 |
ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
|
|
303 |
ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
|
|
304 |
ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
|
|
305 |
ap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, false);
|
|
306 |
|
|
307 |
// Custom settings for AP # 1
|
|
308 |
if (ScanResultIterator == 0) {
|
|
309 |
ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
|
|
310 |
ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
|
|
311 |
}
|
|
312 |
|
|
313 |
// Custom settings for AP # 2
|
|
314 |
if (ScanResultIterator == 1) {
|
|
315 |
if (ScanResultPrimary) {
|
|
316 |
ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 70);
|
|
317 |
} else {
|
|
318 |
ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
|
|
319 |
}
|
|
320 |
}
|
|
321 |
|
|
322 |
// Custom settings for AP # 3
|
|
323 |
if (ScanResultIterator == 2) {
|
|
324 |
ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
|
|
325 |
ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
|
|
326 |
ap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, true);
|
|
327 |
}
|
|
328 |
|
|
329 |
// Custom settings for AP's above 3
|
|
330 |
if (ScanResultIterator >= 3) {
|
|
331 |
ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
|
|
332 |
}
|
|
333 |
|
|
334 |
return ap;
|
|
335 |
}
|