38 // ----------------------------------------------------------------------------- |
37 // ----------------------------------------------------------------------------- |
39 // CHotSpotPluginSession |
38 // CHotSpotPluginSession |
40 // ----------------------------------------------------------------------------- |
39 // ----------------------------------------------------------------------------- |
41 // |
40 // |
42 CHssIapHandler::CHssIapHandler( ) |
41 CHssIapHandler::CHssIapHandler( ) |
43 { |
42 { |
44 DEBUG("CHssIapHandler::CHssIapHandler"); |
43 DEBUG("CHssIapHandler::CHssIapHandler"); |
45 } |
44 } |
46 |
45 |
47 // ----------------------------------------------------------------------------- |
46 // ----------------------------------------------------------------------------- |
48 // ConstructL |
47 // ConstructL |
49 // ----------------------------------------------------------------------------- |
48 // ----------------------------------------------------------------------------- |
50 // |
49 // |
69 // ----------------------------------------------------------------------------- |
68 // ----------------------------------------------------------------------------- |
70 // ~CHssIapHandler |
69 // ~CHssIapHandler |
71 // ----------------------------------------------------------------------------- |
70 // ----------------------------------------------------------------------------- |
72 // |
71 // |
73 CHssIapHandler::~CHssIapHandler() |
72 CHssIapHandler::~CHssIapHandler() |
74 { |
73 { |
75 DEBUG("CHssIapHandler::~CHssIapHandler()"); |
74 DEBUG("CHssIapHandler::~CHssIapHandler()"); |
76 |
75 |
77 if ( iWLANRecord != NULL ) |
76 if ( iWLANRecord != NULL ) |
78 { |
77 { |
79 delete iWLANRecord; |
78 delete iWLANRecord; |
80 } |
79 } |
81 iWLANRecord = NULL; |
80 iWLANRecord = NULL; |
82 } |
81 } |
83 |
82 |
84 // ----------------------------------------------------------------------------- |
83 // ----------------------------------------------------------------------------- |
85 // ChangeSettingsL |
84 // ChangeSettingsL |
86 // ----------------------------------------------------------------------------- |
85 // ----------------------------------------------------------------------------- |
87 // |
86 // |
106 return KErrPermissionDenied; |
105 return KErrPermissionDenied; |
107 } |
106 } |
108 |
107 |
109 // Read WLAN table service id |
108 // Read WLAN table service id |
110 TUint32 serviceId(0); |
109 TUint32 serviceId(0); |
111 RCmConnectionMethodExt plugin = cmManager.ConnectionMethodL( aIapID ); |
110 RCmConnectionMethodExt plugin = cmManager.ConnectionMethodL( aIapID ); |
112 CleanupClosePushL( plugin ); |
111 CleanupClosePushL( plugin ); |
113 serviceId = plugin.GetIntAttributeL( EWlanServiceId ); |
112 serviceId = plugin.GetIntAttributeL( EWlanServiceId ); |
114 DEBUG1("CHssIapHandler::ChangeSettingsL WLAN serviceId: %d", serviceId); |
113 DEBUG1("CHssIapHandler::ChangeSettingsL WLAN serviceId: %d", serviceId); |
115 |
114 |
116 if ( aSettings.Name.Length() > 0 ) |
115 if ( aSettings.Name.Length() > 0 ) |
117 { |
116 { |
123 |
122 |
124 // CommsDat section starts |
123 // CommsDat section starts |
125 CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
124 CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
126 CleanupStack::PushL( dbSession ); |
125 CleanupStack::PushL( dbSession ); |
127 iWLANRecord = static_cast<CMDBGenericRecord*> |
126 iWLANRecord = static_cast<CMDBGenericRecord*> |
128 ( CCDRecordBase::RecordFactoryL( 0)); |
127 ( CCDRecordBase::RecordFactoryL( 0 ) ); |
129 |
128 |
130 iWLANRecord->InitializeL( KGenericTable(),NULL ); |
129 iWLANRecord->InitializeL( KGenericTable(),NULL ); |
131 iWLANRecord->SetRecordId( serviceId ); |
130 iWLANRecord->SetRecordId( serviceId ); |
132 iWLANRecord->LoadL( *dbSession ); |
131 iWLANRecord->LoadL( *dbSession ); |
133 |
132 |
154 // Check if THssIapSettings is created wrong (dynamically). |
153 // Check if THssIapSettings is created wrong (dynamically). |
155 // -> Then default value is not set to security mode and it will be huge. |
154 // -> Then default value is not set to security mode and it will be huge. |
156 // -> Destination can become unusable. |
155 // -> Destination can become unusable. |
157 TInt secMode = aSettings.iSecurityMode; |
156 TInt secMode = aSettings.iSecurityMode; |
158 if ( secMode > EHssWpa2Only ) |
157 if ( secMode > EHssWpa2Only ) |
159 { |
158 { |
160 secMode = EHssAllowUnsecure; |
159 secMode = EHssAllowUnsecure; |
161 } |
160 } |
162 |
161 |
163 if( secMode == EHssWep ) |
162 if( secMode == EHssWep ) |
164 { |
163 { |
165 DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode == EHssWep"); |
164 DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode == EHssWep"); |
166 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanAuthMode)) = aSettings.iAuthenticationMode; |
165 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanAuthMode)) = aSettings.iAuthenticationMode; |
192 binField->SetL( buf); |
191 binField->SetL( buf); |
193 |
192 |
194 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanWpaKeyLength)) = aSettings.iWPAKeyLength; |
193 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanWpaKeyLength)) = aSettings.iWPAKeyLength; |
195 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk; |
194 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk; |
196 } |
195 } |
197 else // Use EAP |
196 else // Use EAP. EAP settings can be set with EAP API. |
198 { |
197 { |
199 DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep -> EAP"); |
198 DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep -> EAP"); |
200 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk; |
199 *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk; |
201 } |
200 } |
202 } |
201 } |
203 |
|
204 // access point updated EAP data can be now set if needed |
|
205 if ( ( !aSettings.iEnableWpaPsk ) && secMode > EHssWep ) |
|
206 { |
|
207 DEBUG("CHssIapHandler::ChangeSettingsL -> Set EAP data"); |
|
208 TBuf8<KEapListMaxLength> enabledEapList; |
|
209 for (TInt i=0;i<aSettings.iEapDataArray.Count();i++) |
|
210 { |
|
211 TBuf8< KEapExpandedIdLength > eapTypeCue; |
|
212 TChar eapCode; |
|
213 GetEapTypeDesC(aSettings.iEapDataArray[i]->iEAPType, eapTypeCue, eapCode ); |
|
214 |
|
215 CEapType* eapType = NULL; |
|
216 TRAPD( error, ( eapType = CEapType::NewL( eapTypeCue, ELan, serviceId ) ) ); |
|
217 DEBUG1(" CEapType::NewL error: %d", error); |
|
218 if ( ( error == KErrNone ) && eapType ) |
|
219 { |
|
220 CleanupStack::PushL( eapType ); |
|
221 EAPSettings* eapSettings = new (ELeave) EAPSettings; |
|
222 |
|
223 ConvertEApSettings( *aSettings.iEapDataArray[i], *eapSettings ); |
|
224 |
|
225 // Set EAP tunneling |
|
226 if ( aSettings.iEapDataArray[i]->iEncapsulatedInside != EAPSettings::EEapNone ) |
|
227 { |
|
228 DEBUG("iEncapsulatedInside != EAPSettings::EEapNone"); |
|
229 eapType->SetTunnelingType( |
|
230 static_cast<TInt> ( aSettings.iEapDataArray[i]->iEncapsulatedInside ) ); |
|
231 } |
|
232 else // Write to EAP list |
|
233 { |
|
234 DEBUG("CHssIapHandler::ChangeSettingsL -> Add to EAP list"); |
|
235 TBuf8<8> expandedForm; |
|
236 expandedForm.AppendFill( 0xFE, 1 ); |
|
237 if ( THssEapSettings::EEapPlainMschapv2 == aSettings.iEapDataArray[i]->iEAPType ) |
|
238 { |
|
239 expandedForm.AppendFill( 0xFF, 3 ); |
|
240 } |
|
241 else{ |
|
242 expandedForm.AppendFill( 0x00, 6 ); |
|
243 } |
|
244 |
|
245 expandedForm.AppendFill( eapCode, 1 ); |
|
246 |
|
247 enabledEapList.Append( expandedForm ); |
|
248 } |
|
249 |
|
250 DEBUG("CHssIapHandler::ChangeSettingsL -> eapType->SetConfigurationL"); |
|
251 TRAPD( eapErr, eapType->SetConfigurationL( *eapSettings ) ); |
|
252 DEBUG1(" eapType->SetConfigurationL error: %d", eapErr); |
|
253 if( eapErr != KErrNone ) |
|
254 { |
|
255 CleanupStack::PopAndDestroy( eapType ); |
|
256 CleanupStack::PopAndDestroy( dbSession ); |
|
257 DEBUG("CHssIapHandler::ChangeSettingsL EapError DONE"); |
|
258 return eapErr; |
|
259 } |
|
260 CleanupStack::PopAndDestroy( eapType ); |
|
261 } |
|
262 if ( error != KErrNone ) |
|
263 { |
|
264 DEBUG("CHssIapHandler::ChangeSettingsL Eap error"); |
|
265 CleanupStack::PopAndDestroy( dbSession ); |
|
266 return error; |
|
267 } |
|
268 } |
|
269 |
|
270 // Set enabled EAP list |
|
271 if ( enabledEapList.Length() > 0 ) |
|
272 { |
|
273 DEBUG("CHssIapHandler::ChangeSettingsL -> Set EAP list"); |
|
274 CMDBField<TDesC8>* eaps = (CMDBField<TDesC8>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanEnabledEaps ); |
|
275 //eaps->SetMaxLengthL( eapList16.Length() ) |
|
276 eaps->SetL( enabledEapList ); |
|
277 } |
|
278 } |
|
279 // now update the access point |
202 // now update the access point |
280 iWLANRecord->ModifyL( *dbSession ); |
203 iWLANRecord->ModifyL( *dbSession ); |
281 |
204 |
282 CleanupStack::PopAndDestroy( dbSession ); |
205 CleanupStack::PopAndDestroy( dbSession ); |
283 DEBUG("CHssIapHandler::ChangeSettingsL DONE"); |
206 DEBUG("CHssIapHandler::ChangeSettingsL DONE"); |
372 wepBuf.Copy( buf8Conv->Des() ); |
295 wepBuf.Copy( buf8Conv->Des() ); |
373 CleanupStack::PopAndDestroy( buf8Conv ); |
296 CleanupStack::PopAndDestroy( buf8Conv ); |
374 } |
297 } |
375 |
298 |
376 aPackedKey->SetL( wepBuf); |
299 aPackedKey->SetL( wepBuf); |
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // ConvertEApSettings |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 void CHssIapHandler::ConvertEApSettings( THssEapSettings& aHssEap, EAPSettings& aEap ) |
|
384 { |
|
385 DEBUG("CHssIapHandler::ConvertEApSettings"); |
|
386 aEap.iEAPType = static_cast<EAPSettings::TEapType>(aHssEap.iEAPType); |
|
387 aEap.iUsernamePresent = aHssEap.iUsernamePresent; |
|
388 aEap.iUsername = aHssEap.iUsername; |
|
389 aEap.iPasswordPresent = aHssEap.iPasswordPresent; |
|
390 aEap.iPassword = aHssEap.iPassword; |
|
391 aEap.iRealmPresent = aHssEap.iRealmPresent; |
|
392 aEap.iRealm = aHssEap.iRealm; |
|
393 aEap.iUsePseudonymsPresent = aHssEap.iUsePseudonymsPresent; |
|
394 aEap.iUsePseudonyms = aHssEap.iUsePseudonyms; |
|
395 aEap.iVerifyServerRealmPresent = aHssEap.iVerifyServerRealmPresent; |
|
396 aEap.iVerifyServerRealm = aHssEap.iVerifyServerRealm; |
|
397 aEap.iRequireClientAuthenticationPresent = aHssEap.iRequireClientAuthenticationPresent; |
|
398 aEap.iRequireClientAuthentication = aHssEap.iRequireClientAuthentication; |
|
399 aEap.iSessionValidityTimePresent = aHssEap.iSessionValidityTimePresent; |
|
400 aEap.iSessionValidityTime = aHssEap.iSessionValidityTime; |
|
401 aEap.iCipherSuitesPresent = aHssEap.iCipherSuitesPresent; |
|
402 |
|
403 for( TInt i = 0; i < aHssEap.iCipherSuitesCount; i++ ) |
|
404 { |
|
405 aEap.iCipherSuites.Append( aHssEap.iCipherSuites[i] ); |
|
406 } |
|
407 aEap.iPEAPVersionsPresent = aHssEap.iPEAPVersionsPresent; |
|
408 aEap.iPEAPv0Allowed = aHssEap.iPEAPv0Allowed; |
|
409 aEap.iPEAPv1Allowed = aHssEap.iPEAPv1Allowed; |
|
410 aEap.iPEAPv2Allowed = aHssEap.iPEAPv2Allowed; |
|
411 aEap.iCertificatesPresent = aHssEap.iCertificatesPresent; |
|
412 for( TInt i = 0; i < aHssEap.iCertificatesCount; i++ ) |
|
413 { |
|
414 DEBUG("CHssIapHandler::ConvertEApSettings Certificates present"); |
|
415 CertificateEntry entry; |
|
416 |
|
417 entry.iCertType = static_cast<CertificateEntry::TCertType>( aHssEap.iCertificates[i]->iCertType ); |
|
418 entry.iSubjectNamePresent = aHssEap.iCertificates[i]->iSubjectNamePresent; |
|
419 entry.iSubjectName = aHssEap.iCertificates[i]->iSubjectName; |
|
420 entry.iIssuerNamePresent = aHssEap.iCertificates[i]->iIssuerNamePresent; |
|
421 entry.iIssuerName = aHssEap.iCertificates[i]->iIssuerName; |
|
422 entry.iSerialNumberPresent= aHssEap.iCertificates[i]->iSerialNumberPresent; |
|
423 entry.iSerialNumber = aHssEap.iCertificates[i]->iSerialNumber; |
|
424 entry.iSubjectKeyIDPresent = aHssEap.iCertificates[i]->iSubjectKeyIDPresent; |
|
425 entry.iSubjectKeyID = aHssEap.iCertificates[i]->iSubjectKeyID; |
|
426 |
|
427 entry.iThumbprintPresent = aHssEap.iCertificates[i]->iThumbprintPresent; |
|
428 entry.iThumbprint = aHssEap.iCertificates[i]->iThumbprint; |
|
429 TRAP_IGNORE( aEap.iCertificates.AppendL( entry ) ); // Memory problem, ignored... |
|
430 } |
|
431 aEap.iEncapsulatedEAPTypesPresent = aHssEap.iEncapsulatedEAPTypesPresent; |
|
432 for( TInt i = 0; i < aHssEap.iEncapsulatedEAPTypesCount; i++ ) |
|
433 { |
|
434 aEap.iEncapsulatedEAPTypes.Append( aHssEap.iEncapsulatedEAPTypes[i] ); |
|
435 } |
|
436 } |
300 } |
437 |
301 |
438 // ----------------------------------------------------------------------------- |
302 // ----------------------------------------------------------------------------- |
439 // ConvertAsciiToHex |
303 // ConvertAsciiToHex |
440 // ----------------------------------------------------------------------------- |
304 // ----------------------------------------------------------------------------- |
450 { |
314 { |
451 TText8 ch = aSource[ii]; |
315 TText8 ch = aSource[ii]; |
452 ptr.Append( hex()[(ch/16)&0x0f] ); |
316 ptr.Append( hex()[(ch/16)&0x0f] ); |
453 ptr.Append( hex()[ch&0x0f] ); |
317 ptr.Append( hex()[ch&0x0f] ); |
454 } |
318 } |
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // GetEapTypeDesC |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 void CHssIapHandler::GetEapTypeDesC( TUint aEapType, TDes8& aEapString, TChar& aEapCode ) |
|
462 { |
|
463 DEBUG1( "CHssIapHandler::GetEapTypeDesC aEapType: %d", aEapType ); |
|
464 switch ( aEapType ) |
|
465 { |
|
466 // EapNone |
|
467 case 0: |
|
468 aEapString.Copy( KEapNoneId, KEapExpandedIdLength ); |
|
469 aEapCode = KEapNoneId[7]; |
|
470 break; |
|
471 // KEapGtc |
|
472 case 6: |
|
473 aEapString.Copy( KEapGtcId, KEapExpandedIdLength ); |
|
474 aEapCode = KEapGtcId[7]; |
|
475 break; |
|
476 // KEapTls |
|
477 case 13: |
|
478 aEapString.Copy( KEapTlsId, KEapExpandedIdLength ); |
|
479 aEapCode = KEapTlsId[7]; |
|
480 break; |
|
481 // KEapLeap |
|
482 case 17: |
|
483 aEapString.Copy( KEapLeapId, KEapExpandedIdLength ); |
|
484 aEapCode = KEapLeapId[7]; |
|
485 break; |
|
486 // KEapSim |
|
487 case 18: |
|
488 aEapString.Copy( KEapSimId, KEapExpandedIdLength ); |
|
489 aEapCode = KEapSimId[7]; |
|
490 break; |
|
491 // KEapTtls |
|
492 case 21: |
|
493 aEapString.Copy( KEapTtlsId, KEapExpandedIdLength ); |
|
494 aEapCode = KEapTtlsId[7]; |
|
495 break; |
|
496 // KEapAka |
|
497 case 23: |
|
498 aEapString.Copy( KEapAkaId, KEapExpandedIdLength ); |
|
499 aEapCode = KEapAkaId[7]; |
|
500 break; |
|
501 // KEapPeap |
|
502 case 25: |
|
503 aEapString.Copy( KEapPeapId, KEapExpandedIdLength ); |
|
504 aEapCode = KEapPeapId[7]; |
|
505 break; |
|
506 // KEapMschapv2 |
|
507 case 26: |
|
508 aEapString.Copy( KEapMschapv2Id, KEapExpandedIdLength ); |
|
509 aEapCode = KEapMschapv2Id[7]; |
|
510 break; |
|
511 // KEapSecurid |
|
512 case 32: |
|
513 aEapString.Copy( KEapSecuridId, KEapExpandedIdLength ); |
|
514 aEapCode = KEapSecuridId[7]; |
|
515 break; |
|
516 // KEapPlainMschapv2 |
|
517 case 99: |
|
518 aEapString.Copy( KEapPlainMschapv2Id, KEapExpandedIdLength ); |
|
519 aEapCode = KEapPlainMschapv2Id[7]; |
|
520 break; |
|
521 default: |
|
522 aEapString.Copy( KEapNoneId, KEapExpandedIdLength ); |
|
523 aEapCode = KEapNoneId[7]; |
|
524 break; |
|
525 } |
|
526 DEBUG( "CHssIapHandler::GetEapTypeDesC DONE" ); |
|
527 } |
319 } |
528 |
320 |
529 // ----------------------------------------------------------------------------- |
321 // ----------------------------------------------------------------------------- |
530 // GetNetworkIdL |
322 // GetNetworkIdL |
531 // ----------------------------------------------------------------------------- |
323 // ----------------------------------------------------------------------------- |