author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:35:46 +0300 | |
branch | RCL_3 |
changeset 55 | 9c2aa05919d9 |
parent 46 | c74b3d9f6b9e |
permissions | -rw-r--r-- |
46 | 1 |
/* |
2 |
* Copyright (c) 2001-2009 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 License "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: Implementation of class CWPASecuritySettingsImpl. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
/* |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
19 |
* %version: tr1cfwln#27 % |
46 | 20 |
*/ |
21 |
||
22 |
// INCLUDE FILES |
|
23 |
||
24 |
#include "WPASecuritySettingsUiPanic.h" |
|
25 |
||
26 |
#include "WPASecuritySettingsUI.hrh" |
|
27 |
||
28 |
#include <WPASecuritySettingsUI.h> |
|
29 |
#include <commdb.h> |
|
30 |
#include <EAPPluginConfigurationIf.h> |
|
31 |
#include "WPASecuritySettingsImpl.h" |
|
32 |
||
33 |
#include <commsdattypesv1_1.h> |
|
34 |
#include <cmmanagertablefields.h> |
|
35 |
#include <wlancontainer.h> |
|
36 |
||
37 |
||
38 |
// CONSTANTS |
|
39 |
LOCAL_D const TUint32 KUidNone = 0; // Invalid id |
|
40 |
LOCAL_D const TUint32 E8021X = 4; // 802.1X security mode |
|
41 |
LOCAL_D const TUint32 EWpa = 8; // Wpa security mode |
|
42 |
LOCAL_D const TUint32 EWpa2 = 16; // Wpa2 only security mode |
|
43 |
||
44 |
LOCAL_D const TUint32 KExpEapTypeLength = 8; // expanded EAP type length |
|
45 |
||
46 |
// ================= MEMBER FUNCTIONS ======================= |
|
47 |
||
48 |
// --------------------------------------------------------- |
|
49 |
// CWPASecuritySettingsImpl::NewL |
|
50 |
// --------------------------------------------------------- |
|
51 |
// |
|
52 |
CWPASecuritySettingsImpl* CWPASecuritySettingsImpl::NewL( |
|
53 |
TSecurityMode aSecurityMode ) |
|
54 |
{ |
|
55 |
CWPASecuritySettingsImpl* settings = new ( ELeave ) |
|
56 |
CWPASecuritySettingsImpl( aSecurityMode ); |
|
57 |
CleanupStack::PushL( settings ); |
|
58 |
settings->ConstructL(); |
|
59 |
CleanupStack::Pop( settings ); |
|
60 |
return settings; |
|
61 |
} |
|
62 |
||
63 |
||
64 |
// --------------------------------------------------------- |
|
65 |
// CWPASecuritySettingsImpl::CWPASecuritySettingsImpl |
|
66 |
// --------------------------------------------------------- |
|
67 |
// |
|
68 |
CWPASecuritySettingsImpl::CWPASecuritySettingsImpl( |
|
69 |
TSecurityMode aSecurityMode ) |
|
70 |
: iSecurityMode( aSecurityMode ), |
|
71 |
iWPAMode( EFalse ), |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
72 |
iWpa2Only( EFalse ) |
46 | 73 |
{ |
74 |
iWPAEAPPlugin.Zero(); |
|
75 |
iWPAPreSharedKey.Zero(); |
|
76 |
} |
|
77 |
||
78 |
||
79 |
// --------------------------------------------------------- |
|
80 |
// CWPASecuritySettingsImpl::ConstructL |
|
81 |
// --------------------------------------------------------- |
|
82 |
// |
|
83 |
void CWPASecuritySettingsImpl::ConstructL() |
|
84 |
{ |
|
85 |
_LIT8( KMatchString, "EAPPConfig" ); |
|
86 |
TRAPD( err, iPlugin = CEAPPluginConfigurationIf::NewL( KMatchString ) ); |
|
87 |
if ( err != KErrNone && err != KEComErrNoInterfaceIdentified ) |
|
88 |
{ |
|
89 |
User::Leave( err ); |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
||
94 |
// --------------------------------------------------------- |
|
95 |
// CWPASecuritySettingsImpl::~CWPASecuritySettingsImpl |
|
96 |
// --------------------------------------------------------- |
|
97 |
// |
|
98 |
CWPASecuritySettingsImpl::~CWPASecuritySettingsImpl() |
|
99 |
{ |
|
100 |
delete iWPAEnabledEAPPlugin; |
|
101 |
delete iWPADisabledEAPPlugin; |
|
102 |
delete iPlugin; |
|
103 |
} |
|
104 |
||
105 |
||
106 |
// --------------------------------------------------------- |
|
107 |
// CWPASecuritySettingsImpl::LoadL |
|
108 |
// --------------------------------------------------------- |
|
109 |
// |
|
110 |
void CWPASecuritySettingsImpl::LoadL( TUint32 aIapId, |
|
111 |
CCommsDatabase& aCommsDb ) |
|
112 |
{ |
|
113 |
if ( aIapId == KUidNone ) |
|
114 |
{ |
|
115 |
return; |
|
116 |
} |
|
117 |
||
118 |
CCommsDbTableView* wLanServiceTable; |
|
119 |
||
120 |
wLanServiceTable = aCommsDb.OpenViewMatchingUintLC( |
|
121 |
TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId ); |
|
122 |
||
123 |
TInt errorCode = wLanServiceTable->GotoFirstRecord(); |
|
124 |
if ( errorCode == KErrNone ) |
|
125 |
{ |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
126 |
// Get WPA Mode |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
127 |
TRAPD( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_ENABLE_WPA_PSK ), |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
128 |
( TUint32& ) iWPAMode ) ); |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
129 |
if ( err != KErrNone ) |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
130 |
{ // do not leave if value is not present in table... |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
131 |
if ( err != KErrUnknown ) |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
132 |
User::Leave( err ); |
46 | 133 |
} |
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
134 |
|
46 | 135 |
TUint32 secMode = 0; |
136 |
// Get WPA2 Only Mode |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
137 |
TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_SECURITY_MODE ), |
46 | 138 |
secMode ) ); |
139 |
if ( err != KErrNone ) |
|
140 |
{ // do not leave if value is not present in table... |
|
141 |
if ( err != KErrUnknown ) |
|
142 |
User::Leave( err ); |
|
143 |
} |
|
144 |
||
145 |
iWpa2Only = secMode == EWpa2; |
|
146 |
||
147 |
// Get EAP list |
|
148 |
iWPAEAPPlugin.Copy( *wLanServiceTable->ReadLongTextLC( |
|
149 |
TPtrC( WLAN_EAPS ) ) ); |
|
150 |
CleanupStack::PopAndDestroy(); |
|
151 |
||
152 |
if ( !iWPAEAPPlugin.Length() ) |
|
153 |
{ |
|
154 |
// no data found in the old column, use the new ones |
|
155 |
||
156 |
// enabled EAP types |
|
157 |
HBufC *data = wLanServiceTable->ReadLongTextLC( |
|
158 |
TPtrC( WLAN_ENABLED_EAPS ) ); |
|
159 |
||
160 |
TPtrC8 reint( reinterpret_cast<const TUint8*>( data->Ptr() ), |
|
161 |
data->Size() ); |
|
162 |
||
163 |
delete iWPAEnabledEAPPlugin; iWPAEnabledEAPPlugin = NULL; |
|
164 |
iWPAEnabledEAPPlugin = reint.AllocL(); |
|
165 |
||
166 |
CleanupStack::PopAndDestroy( data ); |
|
167 |
||
168 |
||
169 |
// 2. disabled EAP types |
|
170 |
data = wLanServiceTable->ReadLongTextLC( |
|
171 |
TPtrC( WLAN_DISABLED_EAPS ) ); |
|
172 |
||
173 |
reint.Set( reinterpret_cast<const TUint8*>( data->Ptr() ), |
|
174 |
data->Size() ); |
|
175 |
||
176 |
delete iWPADisabledEAPPlugin; iWPADisabledEAPPlugin = NULL; |
|
177 |
iWPADisabledEAPPlugin = reint.AllocL(); |
|
178 |
||
179 |
CleanupStack::PopAndDestroy( data ); |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
// generate appropriate entries in the new enabled and disabled list, |
|
184 |
// overwriting those values |
|
185 |
||
186 |
// count the + and - signs to determine the size of enabled and |
|
187 |
// disabled descriptors |
|
188 |
TLex lex( iWPAEAPPlugin ); |
|
189 |
||
190 |
TInt numPlus = 0; |
|
191 |
TInt numMinus = 0; |
|
192 |
TChar ch; |
|
193 |
while ( !lex.Eos() ) |
|
194 |
{ |
|
195 |
ch = lex.Get(); |
|
196 |
if ( ch == '+' ) ++numPlus; |
|
197 |
else if ( ch == '-' ) ++numMinus; |
|
198 |
} |
|
199 |
||
200 |
// each entry consumes 8 bytes in binary format |
|
201 |
delete iWPAEnabledEAPPlugin; iWPAEnabledEAPPlugin = NULL; |
|
202 |
iWPAEnabledEAPPlugin = HBufC8::NewL( 8 * numPlus ); |
|
203 |
||
204 |
delete iWPADisabledEAPPlugin; iWPADisabledEAPPlugin = NULL; |
|
205 |
iWPADisabledEAPPlugin = HBufC8::NewL( 8 * numMinus ); |
|
206 |
||
207 |
lex.Assign( iWPAEAPPlugin ); |
|
208 |
||
209 |
while ( !lex.Eos() ) |
|
210 |
{ |
|
211 |
// beginning of implementation UID |
|
212 |
TInt16 implUid = 0; |
|
213 |
||
214 |
if ( lex.Val( implUid ) != KErrNone || !implUid ) |
|
215 |
{ |
|
216 |
// if the old string is corrupted, null out both lists |
|
217 |
iWPAEnabledEAPPlugin->Des().Zero(); |
|
218 |
iWPADisabledEAPPlugin->Des().Zero(); |
|
219 |
break; |
|
220 |
} |
|
221 |
||
222 |
// append it to the appropriate list ('+' enabled, '-' disabled) |
|
223 |
_LIT8( KPadding, "\xFE\0\0\0\0\0\0" ); |
|
224 |
_LIT8( KMsChapV2Padding, "\xFE\xFF\xFF\xFF\0\0\0"); |
|
225 |
const TInt KPlainMsChapV2ImplUid = 99; |
|
226 |
||
227 |
if ( implUid > 0 ) |
|
228 |
{ |
|
229 |
iWPAEnabledEAPPlugin->Des().Append( |
|
230 |
Abs( implUid ) == KPlainMsChapV2ImplUid? |
|
231 |
KMsChapV2Padding: KPadding ); |
|
232 |
iWPAEnabledEAPPlugin->Des().Append( Abs( implUid ) ); |
|
233 |
} |
|
234 |
else if (implUid < 0 ) |
|
235 |
{ |
|
236 |
iWPADisabledEAPPlugin->Des().Append( |
|
237 |
Abs( implUid ) == KPlainMsChapV2ImplUid? |
|
238 |
KMsChapV2Padding: KPadding ); |
|
239 |
iWPADisabledEAPPlugin->Des().Append( Abs( implUid ) ); |
|
240 |
} |
|
241 |
||
242 |
// swallow the delimiter (',') |
|
243 |
lex.Get(); |
|
244 |
} |
|
245 |
||
246 |
// finally, wipe old column data |
|
247 |
iWPAEAPPlugin.Zero(); |
|
248 |
} |
|
249 |
||
250 |
// Get PreShared Key |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
251 |
wLanServiceTable->ReadTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), |
46 | 252 |
iWPAPreSharedKey ); |
253 |
||
254 |
if ( !IsValidPsk( iWPAPreSharedKey ) ) |
|
255 |
{ |
|
256 |
// invalid key format |
|
257 |
iWPAPreSharedKey.Zero(); |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
CleanupStack::PopAndDestroy( wLanServiceTable ); // wLanServiceTable |
|
262 |
} |
|
263 |
||
264 |
||
265 |
// --------------------------------------------------------- |
|
266 |
// CWPASecuritySettingsImpl::SaveL |
|
267 |
// --------------------------------------------------------- |
|
268 |
// |
|
269 |
void CWPASecuritySettingsImpl::SaveL( TUint32 aIapId, |
|
270 |
CCommsDatabase& aCommsDb, |
|
271 |
TTypeOfSaving aTypeOfSaving, |
|
272 |
TUint32 aOldIapId ) |
|
273 |
{ |
|
274 |
CCommsDbTableView* wLanServiceTable; |
|
275 |
||
276 |
// Caller MUST initiate a transaction, WE WILL NOT. |
|
277 |
||
278 |
wLanServiceTable = aCommsDb.OpenViewMatchingUintLC( |
|
279 |
TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId ); |
|
280 |
TInt errorCode = wLanServiceTable->GotoFirstRecord(); |
|
281 |
||
282 |
if ( errorCode == KErrNone ) |
|
283 |
{ |
|
284 |
wLanServiceTable->UpdateRecord(); |
|
285 |
} |
|
286 |
else |
|
287 |
{ |
|
288 |
TUint32 dummyUid( KUidNone ); |
|
289 |
User::LeaveIfError( wLanServiceTable->InsertRecord( dummyUid ) ); |
|
290 |
||
291 |
// Save link to LAN service |
|
292 |
wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), aIapId ); |
|
293 |
} |
|
294 |
||
295 |
// Save WPA Mode |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
296 |
wLanServiceTable->WriteUintL( TPtrC( WLAN_ENABLE_WPA_PSK ), |
46 | 297 |
( TUint32& ) iWPAMode ); |
298 |
||
299 |
TUint32 secMode; |
|
300 |
||
301 |
if ( iSecurityMode == ESecurityMode8021x ) |
|
302 |
{ |
|
303 |
secMode = E8021X; |
|
304 |
} |
|
305 |
else if ( iWpa2Only ) |
|
306 |
{ |
|
307 |
secMode = EWpa2; |
|
308 |
} |
|
309 |
else |
|
310 |
{ |
|
311 |
secMode = EWpa; |
|
312 |
} |
|
313 |
||
314 |
// Save security mode |
|
315 |
wLanServiceTable->WriteUintL( TPtrC( WLAN_SECURITY_MODE ), secMode ); |
|
316 |
||
317 |
// With expanded EAP types allowed we no longer need the old column |
|
318 |
iWPAEAPPlugin.Zero(); |
|
319 |
||
320 |
// Save EAP list |
|
321 |
wLanServiceTable->WriteLongTextL( TPtrC( WLAN_EAPS ), iWPAEAPPlugin ); |
|
322 |
||
323 |
||
324 |
// Save the expanded EAPs |
|
325 |
wLanServiceTable->WriteTextL( TPtrC( WLAN_ENABLED_EAPS ), |
|
326 |
iWPAEnabledEAPPlugin? |
|
327 |
(const TDesC8&)*iWPAEnabledEAPPlugin: |
|
328 |
(const TDesC8&)KNullDesC8 ); |
|
329 |
||
330 |
wLanServiceTable->WriteTextL( TPtrC( WLAN_DISABLED_EAPS ), |
|
331 |
iWPADisabledEAPPlugin? |
|
332 |
(const TDesC8&)*iWPADisabledEAPPlugin: |
|
333 |
(const TDesC8&)KNullDesC8 ); |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
334 |
// Save PreShared Key |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
335 |
wLanServiceTable->WriteTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
336 |
iWPAPreSharedKey ); |
46 | 337 |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
338 |
// Save PreShared Key Length |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
339 |
wLanServiceTable->WriteUintL( TPtrC( WLAN_WPA_KEY_LENGTH ), |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
340 |
iWPAPreSharedKey.Length() ); |
46 | 341 |
|
342 |
wLanServiceTable->PutRecordChanges(); |
|
343 |
||
344 |
if ( iPlugin ) |
|
345 |
{ |
|
346 |
if ( aTypeOfSaving == ESavingBrandNewAP ) |
|
347 |
{ |
|
348 |
iPlugin->ChangeIapIDL( aOldIapId, aIapId ); |
|
349 |
} |
|
350 |
else if ( aTypeOfSaving == ESavingNewAPAsACopy ) |
|
351 |
{ |
|
352 |
iPlugin->CopySettingsL( aOldIapId, aIapId ); |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
CleanupStack::PopAndDestroy( wLanServiceTable ); // wLanServiceTable |
|
357 |
} |
|
358 |
||
359 |
||
360 |
// --------------------------------------------------------- |
|
361 |
// CWPASecuritySettingsImpl::DeleteL |
|
362 |
// --------------------------------------------------------- |
|
363 |
// |
|
364 |
void CWPASecuritySettingsImpl::DeleteL( TUint32 aIapId ) |
|
365 |
{ |
|
366 |
if ( iPlugin ) |
|
367 |
{ |
|
368 |
iPlugin->DeleteSettingsL( aIapId ); |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
||
373 |
// --------------------------------------------------------- |
|
374 |
// CWPASecuritySettingsImpl::IsValid |
|
375 |
// --------------------------------------------------------- |
|
376 |
// |
|
377 |
TBool CWPASecuritySettingsImpl::IsValid() |
|
378 |
{ |
|
379 |
TBool retval = ETrue; |
|
380 |
if ( iWPAMode || !iPlugin ) |
|
381 |
{ |
|
382 |
retval = IsValidPsk( iWPAPreSharedKey ); |
|
383 |
} |
|
384 |
||
385 |
return retval; |
|
386 |
} |
|
387 |
||
388 |
||
389 |
// --------------------------------------------------------- |
|
390 |
// CWPASecuritySettingsImpl::IsValidPsk |
|
391 |
// --------------------------------------------------------- |
|
392 |
// |
|
393 |
TBool CWPASecuritySettingsImpl::IsValidPsk( const TDesC8& aPsk ) |
|
394 |
{ |
|
395 |
TBool ret( EFalse ); |
|
396 |
||
397 |
TInt len = aPsk.Length(); |
|
398 |
||
399 |
ret = ( len >= EMinLengthOfPreSharedKeyAscii && |
|
400 |
len <= EMaxLengthOfPreSharedKeyAscii ); |
|
401 |
||
402 |
if ( !ret && len == ELengthOfPreSharedKeyHex ) |
|
403 |
{ |
|
404 |
// perhaps it is hex |
|
405 |
ret = ETrue; |
|
406 |
||
407 |
for ( TInt i = 0; i < len; ++i ) |
|
408 |
{ |
|
409 |
TChar ch( aPsk[i] ); |
|
410 |
if ( !ch.IsHexDigit() ) |
|
411 |
{ |
|
412 |
// got a bad character |
|
413 |
ret = EFalse; |
|
414 |
break; |
|
415 |
} |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
return ret; |
|
420 |
} |
|
421 |
||
422 |
||
423 |
// --------------------------------------------------------- |
|
424 |
// CWPASecuritySettingsImpl::SetWPAPreSharedKey |
|
425 |
// --------------------------------------------------------- |
|
426 |
// |
|
427 |
TInt CWPASecuritySettingsImpl::SetWPAPreSharedKey( |
|
428 |
const TDesC& aPreSharedKey ) |
|
429 |
{ |
|
430 |
TInt ret( KErrNone ); |
|
431 |
||
432 |
HBufC8* buf8 = HBufC8::New( aPreSharedKey.Length() ); |
|
433 |
||
434 |
if ( buf8 ) |
|
435 |
{ |
|
436 |
TPtr8 pskPtr( buf8->Des() ); |
|
437 |
pskPtr.Copy( aPreSharedKey ); |
|
438 |
||
439 |
if ( IsValidPsk( pskPtr ) ) |
|
440 |
{ |
|
441 |
SetWPAPreSharedKey( pskPtr ); |
|
442 |
SetWPAMode( ETrue ); |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
ret = KErrArgument; |
|
447 |
} |
|
448 |
||
449 |
delete buf8; |
|
450 |
} |
|
451 |
else |
|
452 |
{ |
|
453 |
ret = KErrNoMemory; |
|
454 |
} |
|
455 |
||
456 |
return ret; |
|
457 |
} |
|
458 |
||
459 |
||
460 |
// --------------------------------------------------------- |
|
461 |
// CWPASecuritySettingsImpl::SetWPAEnabledEAPPlugin |
|
462 |
// --------------------------------------------------------- |
|
463 |
// |
|
464 |
TInt CWPASecuritySettingsImpl::SetWPAEnabledEAPPlugin( |
|
465 |
const TDesC8& aEnabledPluginList ) |
|
466 |
{ |
|
467 |
delete iWPAEnabledEAPPlugin; iWPAEnabledEAPPlugin = NULL; |
|
468 |
||
469 |
if ( aEnabledPluginList.Length() % KExpEapTypeLength ) |
|
470 |
{ |
|
471 |
// valid expanded EAP types occupy 8 bytes each |
|
472 |
return KErrArgument; |
|
473 |
} |
|
474 |
||
475 |
if ( aEnabledPluginList.Length() ) |
|
476 |
{ |
|
477 |
iWPAEnabledEAPPlugin = aEnabledPluginList.Alloc(); |
|
478 |
if ( !iWPAEnabledEAPPlugin ) |
|
479 |
{ |
|
480 |
return KErrNoMemory; |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
return KErrNone; |
|
485 |
} |
|
486 |
||
487 |
||
488 |
// --------------------------------------------------------- |
|
489 |
// CWPASecuritySettingsImpl::SetWPADisabledEAPPlugin |
|
490 |
// --------------------------------------------------------- |
|
491 |
// |
|
492 |
TInt CWPASecuritySettingsImpl::SetWPADisabledEAPPlugin( |
|
493 |
const TDesC8& aDisabledPluginList ) |
|
494 |
{ |
|
495 |
delete iWPADisabledEAPPlugin; iWPADisabledEAPPlugin = NULL; |
|
496 |
||
497 |
if ( aDisabledPluginList.Length() % KExpEapTypeLength ) |
|
498 |
{ |
|
499 |
// valid expanded EAP types occupy 8 bytes each |
|
500 |
return KErrArgument; |
|
501 |
} |
|
502 |
||
503 |
if ( aDisabledPluginList.Length() ) |
|
504 |
{ |
|
505 |
iWPADisabledEAPPlugin = aDisabledPluginList.Alloc(); |
|
506 |
if ( !iWPADisabledEAPPlugin ) |
|
507 |
{ |
|
508 |
return KErrNoMemory; |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
return KErrNone; |
|
513 |
} |
|
514 |
||
515 |
||
516 |
// --------------------------------------------------------- |
|
517 |
// CWPASecuritySettingsImpl::LoadL |
|
518 |
// --------------------------------------------------------- |
|
519 |
// |
|
520 |
void CWPASecuritySettingsImpl::LoadL( TUint32 aIapId, |
|
521 |
CMDBSession& aSession ) |
|
522 |
{ |
|
523 |
if ( aIapId == KUidNone ) |
|
524 |
{ |
|
525 |
return; |
|
526 |
} |
|
527 |
||
528 |
// Load WLAN service table |
|
529 |
// first get WLAN table id |
|
530 |
CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*> |
|
531 |
( CCDRecordBase::RecordFactoryL( 0 ) ); |
|
532 |
CleanupStack::PushL( generic ); |
|
533 |
generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL ); |
|
534 |
generic->LoadL( aSession ); |
|
535 |
TMDBElementId wlanTableId = generic->TableId(); |
|
536 |
||
537 |
CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*> |
|
538 |
( generic->GetFieldByIdL( KCDTIdWlanServiceId ) ); |
|
539 |
||
540 |
// prime with service id |
|
541 |
*sidField = aIapId; |
|
542 |
||
543 |
if( generic->FindL( aSession) ) |
|
544 |
{ |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
545 |
// Get WPA mode |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
546 |
CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*> |
46 | 547 |
( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) ); |
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
548 |
iWPAMode = *enableWpaPskField; |
46 | 549 |
|
550 |
// Get WPA2 Only Mode |
|
551 |
CMDBField<TUint>* secModeField = static_cast<CMDBField<TUint>*> |
|
552 |
( generic->GetFieldByIdL( KCDTIdWlanSecMode ) ); |
|
553 |
TUint32 secMode = *secModeField; |
|
554 |
iWpa2Only = secMode == EWpa2; |
|
555 |
||
556 |
// Get EAP plugins |
|
557 |
CMDBField<TDesC>* wlanEapsField = static_cast<CMDBField<TDesC>*> |
|
558 |
( generic->GetFieldByIdL( KCDTIdWlanEaps ) ); |
|
559 |
iWPAEAPPlugin = *wlanEapsField; |
|
560 |
||
561 |
if ( !iWPAEAPPlugin.Length() ) |
|
562 |
{ |
|
563 |
// no data found in the old column, use the new ones |
|
564 |
||
565 |
// enabled EAP types |
|
566 |
CMDBField<TDesC8>* wlanEnabledEapsField = |
|
567 |
static_cast<CMDBField<TDesC8>*> |
|
568 |
( generic->GetFieldByIdL( KCDTIdWlanEnabledEaps ) ); |
|
569 |
||
570 |
delete iWPAEnabledEAPPlugin; iWPAEnabledEAPPlugin = NULL; |
|
571 |
iWPAEnabledEAPPlugin = |
|
572 |
( ( const TDesC8& ) *wlanEnabledEapsField ).AllocL(); |
|
573 |
||
574 |
||
575 |
// disabled EAP types |
|
576 |
CMDBField<TDesC8>* wlanDisabledEapsField = |
|
577 |
static_cast<CMDBField<TDesC8>*> |
|
578 |
( generic->GetFieldByIdL( KCDTIdWlanDisabledEaps ) ); |
|
579 |
||
580 |
delete iWPADisabledEAPPlugin; iWPADisabledEAPPlugin = NULL; |
|
581 |
iWPADisabledEAPPlugin = |
|
582 |
( ( const TDesC8& ) *wlanDisabledEapsField ).AllocL(); |
|
583 |
||
584 |
} |
|
585 |
else |
|
586 |
{ |
|
587 |
// generate appropriate entries in the new enabled and disabled list, |
|
588 |
// overwriting those values |
|
589 |
||
590 |
// count the + and - signs to determine the size of enabled and |
|
591 |
// disabled descriptors |
|
592 |
TLex lex( iWPAEAPPlugin ); |
|
593 |
||
594 |
TInt numPlus = 0; |
|
595 |
TInt numMinus = 0; |
|
596 |
TChar ch; |
|
597 |
while ( !lex.Eos() ) |
|
598 |
{ |
|
599 |
ch = lex.Get(); |
|
600 |
if ( ch == '+' ) ++numPlus; |
|
601 |
else if ( ch == '-' ) ++numMinus; |
|
602 |
} |
|
603 |
||
604 |
// each entry consumes 8 bytes in binary format |
|
605 |
delete iWPAEnabledEAPPlugin; iWPAEnabledEAPPlugin = NULL; |
|
606 |
iWPAEnabledEAPPlugin = HBufC8::NewL( 8 * numPlus ); |
|
607 |
||
608 |
delete iWPADisabledEAPPlugin; iWPADisabledEAPPlugin = NULL; |
|
609 |
iWPADisabledEAPPlugin = HBufC8::NewL( 8 * numMinus ); |
|
610 |
||
611 |
lex.Assign( iWPAEAPPlugin ); |
|
612 |
||
613 |
while ( !lex.Eos() ) |
|
614 |
{ |
|
615 |
// beginning of implementation UID |
|
616 |
TInt16 implUid = 0; |
|
617 |
||
618 |
if ( lex.Val( implUid ) != KErrNone || !implUid ) |
|
619 |
{ |
|
620 |
// if the old string is corrupted, null out both lists |
|
621 |
iWPAEnabledEAPPlugin->Des().Zero(); |
|
622 |
iWPADisabledEAPPlugin->Des().Zero(); |
|
623 |
break; |
|
624 |
} |
|
625 |
||
626 |
// append it to the appropriate list ('+' enabled, '-' disabled) |
|
627 |
_LIT8( KPadding, "\xFE\0\0\0\0\0\0" ); |
|
628 |
_LIT8( KMsChapV2Padding, "\xFE\xFF\xFF\xFF\0\0\0"); |
|
629 |
const TInt KPlainMsChapV2ImplUid = 99; |
|
630 |
||
631 |
if ( implUid > 0 ) |
|
632 |
{ |
|
633 |
iWPAEnabledEAPPlugin->Des().Append( |
|
634 |
Abs( implUid ) == KPlainMsChapV2ImplUid? |
|
635 |
KMsChapV2Padding: KPadding ); |
|
636 |
iWPAEnabledEAPPlugin->Des().Append( Abs( implUid ) ); |
|
637 |
} |
|
638 |
else if (implUid < 0 ) |
|
639 |
{ |
|
640 |
iWPADisabledEAPPlugin->Des().Append( |
|
641 |
Abs( implUid ) == KPlainMsChapV2ImplUid? |
|
642 |
KMsChapV2Padding: KPadding ); |
|
643 |
iWPADisabledEAPPlugin->Des().Append( Abs( implUid ) ); |
|
644 |
} |
|
645 |
||
646 |
// swallow the delimiter (',') |
|
647 |
lex.Get(); |
|
648 |
} |
|
649 |
||
650 |
// finally, wipe old column data |
|
651 |
iWPAEAPPlugin.Zero(); |
|
652 |
} |
|
653 |
||
654 |
// GetWPA preshared key |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
655 |
CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*> |
46 | 656 |
( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) ); |
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
657 |
iWPAPreSharedKey = *wpaPskField; |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
658 |
|
46 | 659 |
if ( !IsValidPsk( iWPAPreSharedKey ) ) |
660 |
{ |
|
661 |
// invalid key format |
|
662 |
iWPAPreSharedKey.Zero(); |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
CleanupStack::PopAndDestroy( generic ); |
|
667 |
} |
|
668 |
||
669 |
||
670 |
// --------------------------------------------------------- |
|
671 |
// CWPASecuritySettingsImpl::SaveL |
|
672 |
// --------------------------------------------------------- |
|
673 |
// |
|
674 |
void CWPASecuritySettingsImpl::SaveL( TUint32 aIapId, |
|
675 |
CMDBSession& aSession, |
|
676 |
TTypeOfSaving aTypeOfSaving, |
|
677 |
TUint32 aOldIapId ) |
|
678 |
{ |
|
679 |
const TInt KRetryWait = 100000; // Wait time between retries in TTimeIntervalMicroSeconds32 |
|
680 |
const TInt KRetryCount = 50; // Max retry count |
|
681 |
||
682 |
// Load WLAN service table |
|
683 |
// first get WLAN table id |
|
684 |
CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*> |
|
685 |
( CCDRecordBase::RecordFactoryL( 0 ) ); |
|
686 |
CleanupStack::PushL( generic ); |
|
687 |
generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL ); |
|
688 |
generic->LoadL( aSession ); |
|
689 |
TMDBElementId wlanTableId = generic->TableId(); |
|
690 |
||
691 |
CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*> |
|
692 |
( generic->GetFieldByIdL( KCDTIdWlanServiceId ) ); |
|
693 |
||
694 |
// prime with service id |
|
695 |
*sidField = aIapId; |
|
696 |
||
697 |
TBool found = generic->FindL( aSession); |
|
698 |
||
699 |
// If loading failed, WLAN service record will be |
|
700 |
// created and StoreL()-d, otherwise, ModifyL() |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
701 |
|
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
702 |
// Set WPA mode |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
703 |
CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*> |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
704 |
( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) ); |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
705 |
enableWpaPskField->SetL( iWPAMode ); |
46 | 706 |
|
707 |
// Set security mode |
|
708 |
TUint32 secMode; |
|
709 |
if ( iSecurityMode == ESecurityMode8021x ) |
|
710 |
{ |
|
711 |
secMode = E8021X; |
|
712 |
} |
|
713 |
else if ( iWpa2Only ) |
|
714 |
{ |
|
715 |
secMode = EWpa2; |
|
716 |
} |
|
717 |
else |
|
718 |
{ |
|
719 |
secMode = EWpa; |
|
720 |
} |
|
721 |
CMDBField<TUint>* secModeField = static_cast<CMDBField<TUint>*> |
|
722 |
( generic->GetFieldByIdL( KCDTIdWlanSecMode ) ); |
|
723 |
secModeField->SetL( secMode ); |
|
724 |
||
725 |
// Save EAP list |
|
726 |
CMDBField<TDesC>* wlanEapsField = static_cast<CMDBField<TDesC>*> |
|
727 |
( generic->GetFieldByIdL( KCDTIdWlanEaps ) ); |
|
728 |
||
729 |
// when using the expanded EAP types, wipe out data in the old column |
|
730 |
iWPAEAPPlugin.Zero(); |
|
731 |
||
732 |
wlanEapsField->SetL( iWPAEAPPlugin ); |
|
733 |
||
734 |
// Save the expanded EAPs |
|
735 |
CMDBField<TDesC8>* wlanEnabledEapsField = static_cast<CMDBField<TDesC8>*> |
|
736 |
( generic->GetFieldByIdL( KCDTIdWlanEnabledEaps ) ); |
|
737 |
wlanEnabledEapsField->SetL( iWPAEnabledEAPPlugin? |
|
738 |
(const TDesC8&)*iWPAEnabledEAPPlugin: |
|
739 |
(const TDesC8&)KNullDesC8 ); |
|
740 |
||
741 |
||
742 |
CMDBField<TDesC8>* wlanDisabledEapsField = static_cast<CMDBField<TDesC8>*> |
|
743 |
( generic->GetFieldByIdL( KCDTIdWlanDisabledEaps ) ); |
|
744 |
wlanDisabledEapsField->SetL( iWPADisabledEAPPlugin? |
|
745 |
(const TDesC8&)*iWPADisabledEAPPlugin: |
|
746 |
(const TDesC8&)KNullDesC8 ); |
|
747 |
||
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
748 |
// Save PreShared Key |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
749 |
CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*> |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
750 |
( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) ); |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
751 |
wpaPskField->SetL( iWPAPreSharedKey ); |
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
752 |
|
46 | 753 |
// Save PreShared Key length |
754 |
CMDBField<TUint>* keyLengthField = static_cast<CMDBField<TUint>*> |
|
755 |
( generic->GetFieldByIdL( KCDTIdWlanWpaKeyLength ) ); |
|
55
9c2aa05919d9
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
756 |
keyLengthField->SetL( iWPAPreSharedKey.Length() ); |
46 | 757 |
|
758 |
TInt error( KErrNone ); |
|
759 |
||
760 |
// Saving changes |
|
761 |
for ( TInt i( 0 ); i < KRetryCount; i++ ) |
|
762 |
{ |
|
763 |
||
764 |
// If table existed modify it |
|
765 |
if( found ) |
|
766 |
{ |
|
767 |
TRAP( error, generic->ModifyL( aSession ) ); |
|
768 |
} |
|
769 |
||
770 |
// Otherwise store a new record |
|
771 |
else |
|
772 |
{ |
|
773 |
generic->SetRecordId( KCDNewRecordRequest ); |
|
774 |
TRAP( error, generic->StoreL( aSession ) ); |
|
775 |
} |
|
776 |
||
777 |
// If operation failed with KErrLocked, we'll retry. |
|
778 |
if ( KErrLocked == error ) |
|
779 |
{ |
|
780 |
User::After( KRetryWait ); |
|
781 |
} |
|
782 |
||
783 |
// Otherwise break the retry loop. |
|
784 |
else |
|
785 |
{ |
|
786 |
break; |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
// If the save operation failed, leave now. |
|
791 |
User::LeaveIfError( error ); |
|
792 |
||
793 |
CleanupStack::PopAndDestroy( generic ); |
|
794 |
||
795 |
if ( iPlugin ) |
|
796 |
{ |
|
797 |
if ( aTypeOfSaving == ESavingBrandNewAP ) |
|
798 |
{ |
|
799 |
iPlugin->ChangeIapIDL( aOldIapId, aIapId ); |
|
800 |
} |
|
801 |
else if ( aTypeOfSaving == ESavingNewAPAsACopy ) |
|
802 |
{ |
|
803 |
iPlugin->CopySettingsL( aOldIapId, aIapId ); |
|
804 |
} |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
// End of File |