1 /* |
|
2 * Copyright (c) 2005-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 "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 * |
|
16 */ |
|
17 #include <e32std.h> |
|
18 #include <escapeutils.h> |
|
19 #include <cmmanager.h> |
|
20 #include <cmdestination.h> |
|
21 #include <cmconnectionmethoddef.h> |
|
22 #include <cmpluginwlandef.h> |
|
23 |
|
24 #include "scpservicemanager.h" |
|
25 #include "scpsettinghandler.h" |
|
26 #include "scpservicestorage.h" |
|
27 #include "scputility.h" |
|
28 #include "scplogger.h" |
|
29 #include "scpprofilehandler.h" |
|
30 #include "scpservice.h" |
|
31 #include "scpsubservice.h" |
|
32 #include "scpsipconnection.h" |
|
33 #include "scpstatecontainer.h" |
|
34 |
|
35 const TInt KUsernameMaxLength = 255; |
|
36 const TInt KDomainMaxLength = 255; |
|
37 const TInt KTempBufMaxLength = 255; |
|
38 |
|
39 const TUint32 KBearerWlanOnly = 1; |
|
40 |
|
41 #ifdef _DEBUG |
|
42 const TInt KDebugInfoMaxLength = 255; |
|
43 #endif |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CScpServiceManager::CScpServiceManager() |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CScpServiceManager::CScpServiceManager( MCchServiceObserver& aServiceObserver ) : |
|
50 iServiceObserver( aServiceObserver ) |
|
51 { |
|
52 SCPLOGSTRING( "CScpServiceManager::CScpServiceManager"); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CScpServiceManager::NewL |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CScpServiceManager* CScpServiceManager::NewL( MCchServiceObserver& aServiceObserver ) |
|
60 { |
|
61 SCPLOGSTRING( "CScpServiceManager::NewL"); |
|
62 |
|
63 CScpServiceManager* self = new ( ELeave ) CScpServiceManager( aServiceObserver ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CScpServiceManager::ConstructL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CScpServiceManager::ConstructL() |
|
75 { |
|
76 SCPLOGSTRING( "CScpServiceManager::ConstructL"); |
|
77 |
|
78 iProfileHandler = CScpProfileHandler::NewL(); |
|
79 iSettingHandler = CScpSettingHandler::NewL( *iProfileHandler ); |
|
80 iServiceStorage = CScpServiceStorage::NewL( *iSettingHandler ); |
|
81 |
|
82 |
|
83 iStateContainer.InitializeL(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CScpServiceManager::~CScpServiceManager |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CScpServiceManager::~CScpServiceManager() |
|
91 { |
|
92 SCPLOGSTRING( "CScpServiceManager::~CScpServiceManager"); |
|
93 |
|
94 delete iServiceStorage; |
|
95 delete iSettingHandler; |
|
96 delete iProfileHandler; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CScpServiceManager::GetServiceL |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CScpService* CScpServiceManager::GetServiceL( TUint aServiceId, |
|
104 TCCHSubserviceType aSubServiceType ) |
|
105 { |
|
106 SCPLOGSTRING2( "CScpServiceManager::GetService: %i", aServiceId ); |
|
107 |
|
108 CScpService* service( NULL ); |
|
109 |
|
110 if( iSettingHandler->ServiceExistsL( aServiceId ) ) |
|
111 { |
|
112 service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
113 |
|
114 if( service ) |
|
115 { |
|
116 TRAPD( result, iSettingHandler->UpdateSettingsL( *service, aSubServiceType ) ); |
|
117 |
|
118 if( result != KErrNone ) |
|
119 { |
|
120 #ifndef SCP_UNIT_TEST |
|
121 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrGeneral ) ); |
|
122 #endif |
|
123 service = NULL; |
|
124 } |
|
125 if ( KErrNoMemory == result ) |
|
126 { |
|
127 User::Leave( KErrNoMemory ); |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 return service; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CScpServiceManager::CreateServiceL |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 CScpService* CScpServiceManager::CreateServiceL( TUint aServiceId, |
|
140 TCCHSubserviceType aSubServiceType ) |
|
141 { |
|
142 SCPLOGSTRING2( "CScpServiceManager::CreateServiceL: %i", aServiceId ); |
|
143 |
|
144 if( !iSettingHandler->ServiceExistsL( aServiceId ) ) |
|
145 { |
|
146 User::Leave( KErrNotFound ); |
|
147 } |
|
148 |
|
149 // Check if it is already available |
|
150 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
151 |
|
152 if( !service ) |
|
153 { |
|
154 CScpService& createdService = |
|
155 iServiceStorage->CreateServiceL( aServiceId, |
|
156 *iProfileHandler, |
|
157 iServiceObserver ); |
|
158 |
|
159 service = &createdService; |
|
160 |
|
161 TRAPD( result, iSettingHandler->UpdateSettingsL( *service, aSubServiceType ) ); |
|
162 |
|
163 if( result != KErrNone ) |
|
164 { |
|
165 // Remove the service if something went wrong |
|
166 iServiceStorage->RemoveService( service->Id() ); |
|
167 User::Leave( result ); |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 #ifndef SCP_UNIT_TEST |
|
173 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrAlreadyExists ) ); |
|
174 #endif |
|
175 } |
|
176 |
|
177 return service; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CScpServiceManager::EnableServiceL |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CScpServiceManager::EnableServiceL( TUint aServiceId, |
|
185 TCCHSubserviceType aSubServiceType ) |
|
186 { |
|
187 SCPLOGSTRING2( "CScpServiceManager::EnableServiceL service:%i", aServiceId ); |
|
188 SCPLOGSTRING2( "CScpServiceManager::EnableServiceL type:%i", aSubServiceType ); |
|
189 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
190 |
|
191 CheckRestrictedConnectionsL( aServiceId ); |
|
192 |
|
193 CScpService* service = GetServiceL( aServiceId, aSubServiceType ); |
|
194 |
|
195 if( !service ) |
|
196 { |
|
197 service = CreateServiceL( aServiceId, aSubServiceType ); |
|
198 } |
|
199 |
|
200 RArray< TInt > subServiceIds; |
|
201 CleanupClosePushL( subServiceIds ); |
|
202 service->GetSubServiceIds( subServiceIds ); |
|
203 |
|
204 for( TInt i=0 ;i<subServiceIds.Count(); i++ ) |
|
205 { |
|
206 CScpSubService* subService = |
|
207 service->GetSubService( subServiceIds[ i ] ); |
|
208 |
|
209 if( subService ) |
|
210 { |
|
211 SCPLOGSTRING2( "Subservice's type: %d", subService->SubServiceType() ); |
|
212 |
|
213 // Check is VoIP supported |
|
214 if ( !iSettingHandler->IsVoIPSupported() && |
|
215 ECCHVoIPSub == subService->SubServiceType() ) |
|
216 { |
|
217 SCPLOGSTRING( "No support for VoIP" ); |
|
218 subService = NULL; |
|
219 } |
|
220 |
|
221 if ( subService && |
|
222 ( aSubServiceType == subService->SubServiceType() || |
|
223 ECCHUnknown == aSubServiceType ) ) |
|
224 { |
|
225 UpdateProfileValuesL( aServiceId, aSubServiceType ); |
|
226 subService->EnableL(); |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 CleanupStack::PopAndDestroy( &subServiceIds ); |
|
232 |
|
233 SCPLOGSTRING( "CScpServiceManager::EnableServiceL out" ); |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CScpServiceManager::EnableServiceL |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CScpServiceManager::EnableServiceL( TUint aServiceId, |
|
241 TCCHSubserviceType aSubServiceType, |
|
242 TUint /*aIapId*/ ) |
|
243 { |
|
244 // : Change sip profiles IAP settings, but |
|
245 // If SNAP != 0 add the IAP to SNAP (CommsDB) |
|
246 EnableServiceL( aServiceId, aSubServiceType ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CScpServiceManager::DisableServiceL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CScpServiceManager::DisableServiceL( TUint aServiceId, |
|
254 TCCHSubserviceType aSubServiceType ) |
|
255 { |
|
256 SCPLOGSTRING2( "CScpServiceManager::DisableService service:%i", aServiceId ); |
|
257 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
258 |
|
259 CScpService* service = GetServiceL( aServiceId, aSubServiceType ); |
|
260 if( !service ) |
|
261 { |
|
262 service = CreateServiceL( aServiceId, aSubServiceType ); |
|
263 } |
|
264 |
|
265 RArray< TInt > subServiceIds; |
|
266 CleanupClosePushL( subServiceIds ); |
|
267 service->GetSubServiceIds( subServiceIds ); |
|
268 |
|
269 if( subServiceIds.Count() == 0 ) |
|
270 { |
|
271 // Nothing to disable |
|
272 User::Leave( KErrNotFound ); |
|
273 } |
|
274 |
|
275 TBool atLeastOneDisableSucceeded = EFalse; |
|
276 |
|
277 for( TInt i=0 ;i<subServiceIds.Count(); i++ ) |
|
278 { |
|
279 CScpSubService* subService = service->GetSubService( subServiceIds[ i ] ); |
|
280 if( subService && ( aSubServiceType == subService->SubServiceType() || |
|
281 aSubServiceType == ECCHUnknown ) ) |
|
282 { |
|
283 TInt result = subService->Disable(); |
|
284 if( result == KErrNone ) |
|
285 { |
|
286 atLeastOneDisableSucceeded = ETrue; |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 if( !atLeastOneDisableSucceeded ) |
|
292 { |
|
293 User::Leave( KErrNotSupported ); |
|
294 } |
|
295 |
|
296 CleanupStack::PopAndDestroy( &subServiceIds ); |
|
297 |
|
298 // After the disabling there might be some cleaning to do |
|
299 iServiceStorage->RemoveDisabledServices(); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CScpServiceManager::IsAvailableL |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 TBool CScpServiceManager::IsAvailableL( TUint /*aServiceId*/, |
|
307 TCCHSubserviceType /*a*/, |
|
308 const RArray<TUint32>& /*aIapIdArray*/ ) const |
|
309 { |
|
310 SCPLOGSTRING( "CScpServiceManager::IsAvailableL" ); |
|
311 // : |
|
312 return ETrue; |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CScpServiceManager::GetServiceState |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 TInt CScpServiceManager::GetServiceState( TUint aServiceId, |
|
320 TCCHSubserviceType aSubServiceType, |
|
321 TCCHSubserviceState& aState ) const |
|
322 { |
|
323 SCPLOGSTRING2( "CScpServiceManager::GetServiceState service:%i", aServiceId ); |
|
324 |
|
325 TInt result( KErrNone ); |
|
326 aState = ECCHDisabled; |
|
327 |
|
328 CScpServiceManager* self = const_cast<CScpServiceManager*>(this); |
|
329 CScpService* service = NULL; |
|
330 TRAPD( err, service = self->GetServiceL( aServiceId, aSubServiceType ) ); |
|
331 if ( KErrNoMemory == err ) |
|
332 { |
|
333 return err; |
|
334 } |
|
335 |
|
336 if( service ) |
|
337 { |
|
338 result = service->State( aSubServiceType, aState ); |
|
339 } |
|
340 else |
|
341 { |
|
342 TRAP( result, service = CreateTemporaryServiceL( aServiceId, aSubServiceType ) ); |
|
343 |
|
344 if( result == KErrNone && service ) |
|
345 { |
|
346 result = service->State( aSubServiceType, aState ); |
|
347 delete service; |
|
348 } |
|
349 } |
|
350 |
|
351 return result; |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CScpServiceManager::GetServiceNetworkInfo |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 TInt CScpServiceManager::GetServiceNetworkInfo( TUint aServiceId, |
|
359 TCCHSubserviceType aSubServiceType, |
|
360 TUint32& aSnapId, |
|
361 TUint32& aIapId, |
|
362 TBool& aSnapLocked, |
|
363 TBool& aPasswordSet ) const |
|
364 { |
|
365 SCPLOGSTRING( "CScpServiceManager::GetServiceNetworkInfo" ); |
|
366 |
|
367 // Get service network info |
|
368 TRAPD( ret, GetServiceNetworkInfoL( aServiceId, |
|
369 aSubServiceType, |
|
370 aSnapId, |
|
371 aIapId, |
|
372 aSnapLocked, |
|
373 aPasswordSet) ); |
|
374 |
|
375 return ret; |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CScpServiceManager::SetSnapId |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 TInt CScpServiceManager::SetSnapId( TUint aServiceId, |
|
383 TCCHSubserviceType aSubServiceType, |
|
384 const TUint aSnapId ) |
|
385 { |
|
386 SCPLOGSTRING4( "CScpServiceManager::SetSnapId service id: %d type: %d snap: %d", |
|
387 aServiceId, aSubServiceType, aSnapId ); |
|
388 |
|
389 return SetAccessPointId( aServiceId, aSubServiceType, EScpSnap, aSnapId ); |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CScpServiceManager::SetIapId |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 TInt CScpServiceManager::SetIapId( TUint aServiceId, |
|
397 TCCHSubserviceType aSubServiceType, |
|
398 TUint aIapId ) |
|
399 { |
|
400 SCPLOGSTRING4( "CScpServiceManager::SetIapId service id: %d type: %d iap: %d", |
|
401 aServiceId, aSubServiceType, aIapId ); |
|
402 |
|
403 return SetAccessPointId( aServiceId, aSubServiceType, EScpIap, aIapId ); |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CScpServiceManager::SetAccessPointId |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 TInt CScpServiceManager::SetAccessPointId( TUint aServiceId, |
|
411 TCCHSubserviceType aSubServiceType, |
|
412 TScpAccessPointType aAccessPointType, |
|
413 TInt aAccessPointId ) |
|
414 { |
|
415 SCPLOGSTRING4( "CScpServiceManager[0x%x]::SetAccessPointId: type: %d id: %d", |
|
416 this, aSubServiceType, aAccessPointId ); |
|
417 |
|
418 TBool serviceCreated = EFalse; |
|
419 TInt result = KErrNone; |
|
420 |
|
421 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
422 |
|
423 if( !service ) |
|
424 { |
|
425 TRAP( result, service = CreateTemporaryServiceL( aServiceId, |
|
426 ECCHUnknown ) ); |
|
427 |
|
428 if( result == KErrNone ) |
|
429 { |
|
430 serviceCreated = ETrue; |
|
431 } |
|
432 } |
|
433 |
|
434 if( result == KErrNone ) |
|
435 { |
|
436 result = service->SetAccessPointId( aSubServiceType, |
|
437 aAccessPointType, |
|
438 aAccessPointId ); |
|
439 } |
|
440 |
|
441 if( serviceCreated ) |
|
442 { |
|
443 delete service; |
|
444 } |
|
445 |
|
446 return result; |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // CScpServiceManager::CreateTemporaryServiceL |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 CScpService* CScpServiceManager::CreateTemporaryServiceL( TInt aServiceId, |
|
454 TCCHSubserviceType aSubServiceType ) const |
|
455 { |
|
456 SCPLOGSTRING3( "CScpServiceManager::CreateTemporaryServiceL service id: %d type: %d", |
|
457 aServiceId, |
|
458 aSubServiceType ); |
|
459 |
|
460 // Create a temporary service |
|
461 CScpService* service = CScpService::NewL( aServiceId, |
|
462 aSubServiceType, |
|
463 *iProfileHandler, |
|
464 *iServiceStorage, |
|
465 iServiceObserver ); |
|
466 |
|
467 CleanupStack::PushL( service ); |
|
468 |
|
469 service->SetServiceId( aServiceId ); |
|
470 |
|
471 iSettingHandler->UpdateSettingsL( *service, aSubServiceType ); |
|
472 |
|
473 CleanupStack::Pop( service ); |
|
474 |
|
475 return service; |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CScpServiceManager::GetServiceInfoL |
|
480 // ----------------------------------------------------------------------------- |
|
481 // |
|
482 void CScpServiceManager::GetServiceInfoL( TUint aServiceId, |
|
483 TCCHSubserviceType aSubServiceType, |
|
484 RBuf& aBuffer ) const |
|
485 { |
|
486 SCPLOGSTRING3( "CScpServiceManager::GetServiceInfoL service id: %d type: %d", |
|
487 aServiceId, aSubServiceType ); |
|
488 |
|
489 // Info request about the state of SCP for debugging purposes |
|
490 #ifdef _DEBUG |
|
491 |
|
492 TInt infoCode = 0xAAA; |
|
493 if( aServiceId == infoCode ) |
|
494 { |
|
495 aBuffer.Close(); |
|
496 HBufC* buf = HBufC::NewL( KDebugInfoMaxLength ); |
|
497 TPtr ptr = buf->Des(); |
|
498 |
|
499 iServiceStorage->GetDebugInfo( ptr ); |
|
500 iProfileHandler->GetDebugInfo( ptr ); |
|
501 |
|
502 aBuffer.Assign( buf ); |
|
503 |
|
504 return; |
|
505 } |
|
506 #endif |
|
507 |
|
508 TBool sipConnectionCreated( EFalse ); |
|
509 |
|
510 CScpSipConnection* sipConnection = GetSipConnectionL( aServiceId, |
|
511 aSubServiceType, |
|
512 sipConnectionCreated ); |
|
513 |
|
514 if( sipConnectionCreated ) |
|
515 { |
|
516 CleanupStack::PushL( sipConnection ); |
|
517 } |
|
518 |
|
519 TBuf8<KUsernameMaxLength> username; |
|
520 TBuf8<KDomainMaxLength> domain; |
|
521 TBuf16<KTempBufMaxLength> tempBuf; |
|
522 |
|
523 User::LeaveIfError( sipConnection->GetUsername( username ) ); |
|
524 User::LeaveIfError( sipConnection->GetDomain( domain ) ); |
|
525 |
|
526 _LIT16( KUsername, "username="); |
|
527 _LIT16( KDomain, "domain="); |
|
528 _LIT16( KSpace, " "); |
|
529 |
|
530 HBufC* buffer = HBufC::NewL( KUsername().Length() + |
|
531 KDomain().Length() + |
|
532 ( KSpace().Length() * 2) + |
|
533 username.Length() + |
|
534 domain.Length() ); |
|
535 |
|
536 buffer->Des().Copy( KUsername ); |
|
537 tempBuf.Copy( username ); |
|
538 buffer->Des().Append( tempBuf ); |
|
539 buffer->Des().Append( KSpace ); |
|
540 buffer->Des().Append( KDomain ); |
|
541 tempBuf.Copy( domain ); |
|
542 buffer->Des().Append( tempBuf ); |
|
543 buffer->Des().Append( KSpace ); |
|
544 |
|
545 aBuffer.Assign( buffer ); |
|
546 |
|
547 if( sipConnectionCreated ) |
|
548 { |
|
549 CleanupStack::PopAndDestroy( sipConnection ); |
|
550 } |
|
551 |
|
552 SCPLOGSTRING2( "Result: %S", &aBuffer ); |
|
553 } |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CScpServiceManager::GetSipConnectionL |
|
557 // ----------------------------------------------------------------------------- |
|
558 // |
|
559 CScpSipConnection* CScpServiceManager::GetSipConnectionL( |
|
560 TUint aServiceId, |
|
561 TCCHSubserviceType aSubServiceType, |
|
562 TBool& aConnectionCreated ) const |
|
563 { |
|
564 SCPLOGSTRING2( "CScpServiceManager::GetSipConnectionL service:%i", |
|
565 aServiceId ); |
|
566 |
|
567 CScpSipConnection* sipConnection( NULL ); |
|
568 aConnectionCreated = EFalse; |
|
569 TUint32 profileId( 0 ); |
|
570 |
|
571 // Get SIP profile for service |
|
572 iSettingHandler->GetSipProfileIdByTypeL( aServiceId, |
|
573 aSubServiceType, |
|
574 profileId ); |
|
575 |
|
576 if( profileId != 0 ) |
|
577 { |
|
578 if( iProfileHandler->SipConnectionExists( profileId ) ) |
|
579 { |
|
580 sipConnection = iProfileHandler->GetSipConnection( profileId ); |
|
581 } |
|
582 else |
|
583 { |
|
584 if( iProfileHandler->ProfileExists( profileId ) ) |
|
585 { |
|
586 sipConnection = iProfileHandler->CreateSipConnectionL( profileId ); |
|
587 aConnectionCreated = ETrue; |
|
588 } |
|
589 } |
|
590 } |
|
591 |
|
592 if( !sipConnection ) |
|
593 { |
|
594 User::Leave( KErrNotFound ); |
|
595 } |
|
596 |
|
597 return sipConnection; |
|
598 } |
|
599 |
|
600 // ----------------------------------------------------------------------------- |
|
601 // CScpServiceManager::GetServiceNetworkInfoL |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 void CScpServiceManager::GetServiceNetworkInfoL( TUint aServiceId, |
|
605 TCCHSubserviceType aSubServiceType, |
|
606 TUint32& aSnapId, |
|
607 TUint32& aIapId, |
|
608 TBool& aSnapLocked, |
|
609 TBool& aPasswordSet ) const |
|
610 { |
|
611 SCPLOGSTRING2( "CScpServiceManager::GetServiceNetworkInfoL service:%i", |
|
612 aServiceId ); |
|
613 __ASSERT_DEBUG( (TInt)aServiceId > KErrNotFound, User::Panic( KNullDesC, KErrGeneral ) ); |
|
614 |
|
615 TBool serviceCreated = EFalse; |
|
616 |
|
617 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
618 |
|
619 if( !service ) |
|
620 { |
|
621 service = CreateTemporaryServiceL( aServiceId, ECCHUnknown ); |
|
622 |
|
623 serviceCreated = ETrue; |
|
624 CleanupStack::PushL( service ); |
|
625 } |
|
626 |
|
627 if( aSubServiceType == ECCHUnknown && |
|
628 service->SubServicesContainSameSipProfile() == EFalse ) |
|
629 { |
|
630 // We can't return any valid snap/iap values if different |
|
631 // sip profiles are in use |
|
632 User::Leave( KErrNotSupported ); |
|
633 } |
|
634 |
|
635 TBool sipConnectionCreated( EFalse ); |
|
636 CScpSipConnection* sipConnection = GetSipConnectionL( aServiceId, |
|
637 aSubServiceType, |
|
638 sipConnectionCreated ); |
|
639 |
|
640 TInt result = sipConnection->GetIap( aIapId ); |
|
641 if( result != KErrNone ) |
|
642 { |
|
643 aIapId = 0; |
|
644 } |
|
645 |
|
646 result = sipConnection->GetSnap( aSnapId ); |
|
647 if( result != KErrNone ) |
|
648 { |
|
649 aSnapId = 0; |
|
650 } |
|
651 |
|
652 aPasswordSet = sipConnection->IsPasswordSet(); |
|
653 |
|
654 if( sipConnectionCreated ) |
|
655 { |
|
656 delete sipConnection; |
|
657 } |
|
658 |
|
659 // Decide if snap is locked |
|
660 aSnapLocked = ETrue; |
|
661 |
|
662 if( aSubServiceType == ECCHUnknown || |
|
663 aSubServiceType == ECCHVoIPSub ) |
|
664 { |
|
665 aSnapLocked = EFalse; |
|
666 } |
|
667 else |
|
668 { |
|
669 CScpSubService* voipSubService = service->GetSubServiceByType( ECCHVoIPSub ); |
|
670 if( voipSubService ) |
|
671 { |
|
672 TInt sipProfileId = voipSubService->SipProfileId(); |
|
673 |
|
674 CScpSubService* subService = service->GetSubServiceByType( aSubServiceType ); |
|
675 |
|
676 if( subService ) |
|
677 { |
|
678 // If profiles are same the snap can't be changed |
|
679 if( subService->SipProfileId() != sipProfileId ) |
|
680 { |
|
681 aSnapLocked = EFalse; |
|
682 } |
|
683 } |
|
684 else |
|
685 { |
|
686 User::Leave( KErrNotFound ); |
|
687 } |
|
688 } |
|
689 else |
|
690 { |
|
691 aSnapLocked = EFalse; |
|
692 } |
|
693 } |
|
694 |
|
695 if( serviceCreated ) |
|
696 { |
|
697 CleanupStack::PopAndDestroy( service ); |
|
698 } |
|
699 |
|
700 SCPLOGSTRING2( "CScpServiceManager::ServiceNetworkInfo snap:%i", aSnapId ); |
|
701 SCPLOGSTRING2( "CScpServiceManager::ServiceNetworkInfo iap:%i", aIapId ); |
|
702 } |
|
703 |
|
704 // ----------------------------------------------------------------------------- |
|
705 // CScpServiceManager::ReserveService |
|
706 // ----------------------------------------------------------------------------- |
|
707 // |
|
708 TInt CScpServiceManager::SetServiceReserved( TBool aReserved, |
|
709 TUint aServiceId, |
|
710 TCCHSubserviceType aSubServiceType ) |
|
711 { |
|
712 SCPLOGSTRING4( "CScpServiceManager::SetServiceReserved: %d service: %d type: %d", |
|
713 aReserved, aServiceId, aSubServiceType ); |
|
714 |
|
715 TInt result = KErrNone; |
|
716 |
|
717 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
718 |
|
719 if( service ) |
|
720 { |
|
721 result = service->SetReserved( aReserved, aSubServiceType ); |
|
722 } |
|
723 else |
|
724 { |
|
725 result = KErrNotFound; |
|
726 } |
|
727 |
|
728 return result; |
|
729 } |
|
730 |
|
731 // ----------------------------------------------------------------------------- |
|
732 // CScpServiceManager::IsReserved |
|
733 // ----------------------------------------------------------------------------- |
|
734 // |
|
735 TInt CScpServiceManager::IsReserved( TUint aServiceId, |
|
736 TCCHSubserviceType aSubServiceType ) const |
|
737 { |
|
738 SCPLOGSTRING3( "CScpServiceManager::IsReserved service: %d type: %d", |
|
739 aServiceId, aSubServiceType ); |
|
740 |
|
741 TBool result = EFalse; |
|
742 |
|
743 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
744 |
|
745 if( service ) |
|
746 { |
|
747 result = service->IsReserved( aSubServiceType ); |
|
748 } |
|
749 |
|
750 return result; |
|
751 } |
|
752 |
|
753 // ----------------------------------------------------------------------------- |
|
754 // CScpServiceManager::UpdateProfileValuesL |
|
755 // ----------------------------------------------------------------------------- |
|
756 // |
|
757 void CScpServiceManager::UpdateProfileValuesL( |
|
758 TUint aServiceId, |
|
759 TCCHSubserviceType aSubServiceType ) const |
|
760 { |
|
761 TUint32 sipId( KErrNone ); |
|
762 iSettingHandler->GetSipProfileIdByTypeL( aServiceId, aSubServiceType, sipId ); |
|
763 iProfileHandler->UpdateSipProfileL( sipId, |
|
764 iSettingHandler->IsUahTerminalTypeDefinedL( aServiceId ), |
|
765 iSettingHandler->IsUahWLANMacDefinedL( aServiceId ), |
|
766 iSettingHandler->UahStringLengthL( aServiceId ) ); |
|
767 } |
|
768 |
|
769 // ----------------------------------------------------------------------------- |
|
770 // CScpServiceManager::GetConnectionParameter |
|
771 // ----------------------------------------------------------------------------- |
|
772 // |
|
773 void CScpServiceManager::GetConnectionParameterL( |
|
774 const TServiceSelection& /*aServiceSelection*/, |
|
775 TCchConnectionParameter /*aParameter*/, |
|
776 TInt& /*aValue*/ ) const |
|
777 { |
|
778 SCPLOGSTRING( "CScpServiceManager::GetConnectionParameter (int return)\ |
|
779 Not supported yet. GetServiceNetworkInfoL is used at the moment." ); |
|
780 User::Leave( KErrNotSupported ); |
|
781 } |
|
782 |
|
783 // ----------------------------------------------------------------------------- |
|
784 // CScpServiceManager::GetConnectionParameter |
|
785 // ----------------------------------------------------------------------------- |
|
786 // |
|
787 void CScpServiceManager::GetConnectionParameterL( |
|
788 const TServiceSelection& aServiceSelection, |
|
789 TCchConnectionParameter aParameter, |
|
790 RBuf& aValue ) const |
|
791 { |
|
792 SCPLOGSTRING3( "CScpServiceManager::GetConnectionParameter (TBuf return) service id: %d type: %d", |
|
793 aServiceSelection.iServiceId, aServiceSelection.iType ); |
|
794 |
|
795 // check supported get values here, to avoid unnecessary object creation |
|
796 if( aParameter!=ECchUsername ) |
|
797 { |
|
798 SCPLOGSTRING2( "CScpServiceManager::GetConnectionParameter: not supported parameter:%d", aParameter ); |
|
799 User::Leave(KErrArgument ); |
|
800 } |
|
801 |
|
802 TBool sipConnectionCreated( EFalse ); |
|
803 |
|
804 CScpSipConnection* sipConnection = GetSipConnectionL( |
|
805 aServiceSelection.iServiceId, |
|
806 aServiceSelection.iType, |
|
807 sipConnectionCreated ); |
|
808 if( sipConnectionCreated ) |
|
809 { |
|
810 CleanupStack::PushL( sipConnection ); |
|
811 } |
|
812 |
|
813 |
|
814 if( aParameter==ECchUsername ) |
|
815 { |
|
816 TBuf16<KTempBufMaxLength> tempBuf; |
|
817 TBuf8<KUsernameMaxLength> username; |
|
818 |
|
819 if( sipConnection->GetUsername( username ) == KErrNone ) |
|
820 { |
|
821 // Decode encoded username (spaces to %20). |
|
822 HBufC8* decodedUsername = EscapeUtils::EscapeDecodeL( username ); |
|
823 CleanupStack::PushL( decodedUsername ); |
|
824 |
|
825 HBufC* userName16 = |
|
826 EscapeUtils::ConvertToUnicodeFromUtf8L( decodedUsername->Des() ); |
|
827 |
|
828 CleanupStack::PopAndDestroy( decodedUsername ); |
|
829 |
|
830 if ( userName16 ) |
|
831 { |
|
832 aValue.Copy( userName16->Des() ); |
|
833 delete userName16; |
|
834 userName16 = NULL; |
|
835 } |
|
836 else |
|
837 { |
|
838 aValue.Copy( KNullDesC ); |
|
839 } |
|
840 } |
|
841 } |
|
842 |
|
843 if( sipConnectionCreated ) |
|
844 { |
|
845 CleanupStack::PopAndDestroy( sipConnection ); |
|
846 } |
|
847 |
|
848 SCPLOGSTRING2( "Username: %S", &aValue ); |
|
849 } |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // CScpServiceManager::SetConnectionParameter |
|
853 // ----------------------------------------------------------------------------- |
|
854 // |
|
855 void CScpServiceManager::SetConnectionParameterL( |
|
856 const TServiceSelection& /*aServiceSelection*/, |
|
857 TCchConnectionParameter /*aParameter*/, |
|
858 TInt /*aValue*/ ) |
|
859 { |
|
860 SCPLOGSTRING( "CScpServiceManager::SetConnectionParameter(TInt) \ |
|
861 Not supported yet. Separate set methods used." ); |
|
862 |
|
863 // this is not implemented yet, separate functions are used. |
|
864 User::Leave( KErrNotSupported ); |
|
865 } |
|
866 |
|
867 // ----------------------------------------------------------------------------- |
|
868 // CScpServiceManager::SetConnectionParameter |
|
869 // ----------------------------------------------------------------------------- |
|
870 // |
|
871 void CScpServiceManager::SetConnectionParameterL( |
|
872 const TServiceSelection& aServiceSelection, |
|
873 TCchConnectionParameter aParameter, |
|
874 const TDesC& aValue ) |
|
875 { |
|
876 SCPLOGSTRING3( "CScpServiceManager::SetConnectionParameter (TDesC) service id: %d type: %d", |
|
877 aServiceSelection.iServiceId, aServiceSelection.iType ); |
|
878 |
|
879 if( aParameter!=ECchUsername && aParameter!=ECchPassword ) |
|
880 { |
|
881 User::Leave( KErrArgument ); |
|
882 } |
|
883 |
|
884 HBufC8* buf8 = NULL; |
|
885 buf8 = EscapeUtils::ConvertFromUnicodeToUtf8L( aValue ); |
|
886 CleanupStack::PushL( buf8 ); |
|
887 |
|
888 TBool sipConnectionCreated( EFalse ); |
|
889 |
|
890 CScpSipConnection* sipConnection = |
|
891 GetSipConnectionL( aServiceSelection.iServiceId, |
|
892 aServiceSelection.iType, |
|
893 sipConnectionCreated ); |
|
894 |
|
895 if( sipConnectionCreated ) |
|
896 { |
|
897 CleanupStack::PushL( sipConnection ); |
|
898 } |
|
899 |
|
900 // Get presence settings id. |
|
901 TInt presenceSettingsId( KErrNotFound ); |
|
902 TRAP_IGNORE( iSettingHandler->GetSPSettingsIntPropertyL( |
|
903 aServiceSelection.iServiceId, |
|
904 ESubPropertyPresenceSettingsId, |
|
905 presenceSettingsId ) ); |
|
906 |
|
907 if( aParameter == ECchUsername ) |
|
908 { |
|
909 // Use EscapeUtils to convert spaces to %20. |
|
910 HBufC8* encodedUsername = EscapeUtils::EscapeEncodeL( |
|
911 buf8->Des(), EscapeUtils::EEscapeNormal ); |
|
912 |
|
913 if ( encodedUsername ) |
|
914 { |
|
915 CleanupStack::PushL( encodedUsername ); |
|
916 |
|
917 // Set username to SIP-profile |
|
918 iProfileHandler->SetUsernameAndPasswordL( |
|
919 sipConnection->ProfileId(), |
|
920 encodedUsername->Des(), ETrue, KNullDesC8, EFalse ); |
|
921 |
|
922 // Set username to XDM-setting if setting exists |
|
923 if ( KErrNotFound != presenceSettingsId ) |
|
924 { |
|
925 SetUsernameAndPasswordToXdmL( |
|
926 aServiceSelection.iServiceId, |
|
927 *encodedUsername, |
|
928 ETrue, |
|
929 KNullDesC8, |
|
930 EFalse ); |
|
931 } |
|
932 |
|
933 CleanupStack::PopAndDestroy( encodedUsername ); |
|
934 |
|
935 SCPLOGSTRING2( "Username is set: %S", &aValue ); |
|
936 } |
|
937 } |
|
938 else if( aParameter == ECchPassword ) |
|
939 { |
|
940 // Set password to SIP-profile |
|
941 iProfileHandler->SetUsernameAndPasswordL( |
|
942 sipConnection->ProfileId(), |
|
943 KNullDesC8, EFalse, buf8->Des(), ETrue ); |
|
944 |
|
945 // Set password to XDM-setting if setting exists |
|
946 if ( KErrNotFound != presenceSettingsId ) |
|
947 { |
|
948 SetUsernameAndPasswordToXdmL( |
|
949 aServiceSelection.iServiceId, |
|
950 KNullDesC8, |
|
951 EFalse, |
|
952 buf8->Des(), |
|
953 ETrue ); |
|
954 } |
|
955 |
|
956 SCPLOGSTRING2( "Password is set: %S", &aValue ); |
|
957 } |
|
958 else |
|
959 { |
|
960 User::Leave( KErrArgument ); |
|
961 } |
|
962 |
|
963 if( sipConnectionCreated ) |
|
964 { |
|
965 CleanupStack::PopAndDestroy( sipConnection ); |
|
966 } |
|
967 |
|
968 CleanupStack::PopAndDestroy( buf8 ); |
|
969 } |
|
970 |
|
971 // ----------------------------------------------------------------------------- |
|
972 // CScpServiceManager::SetUsernameAndPasswordToXdmL |
|
973 // ----------------------------------------------------------------------------- |
|
974 // |
|
975 void CScpServiceManager::SetUsernameAndPasswordToXdmL( |
|
976 TUint aServiceId, |
|
977 const TDesC8& aUsername, |
|
978 TBool aSetUsername, |
|
979 const TDesC8& aPassword, |
|
980 TBool aSetPassword ) |
|
981 { |
|
982 CScpService* service = GetServiceL( |
|
983 aServiceId, ECCHPresenceSub ); |
|
984 |
|
985 TBool deleteTemporaryService( EFalse ); |
|
986 if ( !service ) |
|
987 { |
|
988 TRAPD( err, service = CreateTemporaryServiceL( |
|
989 aServiceId, |
|
990 ECCHPresenceSub ) ); |
|
991 |
|
992 if( err == KErrNone && service ) |
|
993 { |
|
994 deleteTemporaryService = ETrue; |
|
995 } |
|
996 } |
|
997 |
|
998 if ( service && aSetUsername ) |
|
999 { |
|
1000 iSettingHandler->UpdateXdmUsernameL( |
|
1001 *service, |
|
1002 ECCHPresenceSub, |
|
1003 aUsername ); |
|
1004 } |
|
1005 |
|
1006 if ( service && aSetPassword ) |
|
1007 { |
|
1008 iSettingHandler->UpdateXdmPasswordL( |
|
1009 *service, |
|
1010 ECCHPresenceSub, |
|
1011 aPassword ); |
|
1012 } |
|
1013 |
|
1014 if ( deleteTemporaryService ) |
|
1015 { |
|
1016 delete service; |
|
1017 service = NULL; |
|
1018 } |
|
1019 } |
|
1020 |
|
1021 // ----------------------------------------------------------------------------- |
|
1022 // CScpServiceManager::CheckRestrictedConnectionsL |
|
1023 // ----------------------------------------------------------------------------- |
|
1024 // |
|
1025 void CScpServiceManager::CheckRestrictedConnectionsL( TUint aServiceId ) |
|
1026 { |
|
1027 TBool sipConnectionCreated( EFalse ); |
|
1028 CScpSipConnection* sipConnection = GetSipConnectionL( |
|
1029 aServiceId, |
|
1030 ECCHVoIPSub, |
|
1031 sipConnectionCreated ); |
|
1032 |
|
1033 if( sipConnectionCreated ) |
|
1034 { |
|
1035 CleanupStack::PushL( sipConnection ); |
|
1036 } |
|
1037 // Check bearer filttering setting from sip |
|
1038 TUint32 bearerFilttering( 0 ); |
|
1039 TInt err = sipConnection->BearerFiltteringSetting( bearerFilttering ); |
|
1040 |
|
1041 SCPLOGSTRING2( "CScpServiceManager::CheckAvailableConnectionsL bearerFilttering = %d", bearerFilttering ); |
|
1042 |
|
1043 if ( ( KErrNone == err ) && ( KBearerWlanOnly == bearerFilttering ) ) |
|
1044 { |
|
1045 SCPLOGSTRING( "CScpServiceManager::CheckAvailableConnectionsL WLAN only" ); |
|
1046 TUint32 snapId( KErrNone ); |
|
1047 sipConnection->GetSnap( snapId ); |
|
1048 |
|
1049 RArray<TInt> iaps; |
|
1050 CleanupClosePushL( iaps ); |
|
1051 // get first iap and iap's bearer, there must be atleast |
|
1052 // one iap if not cch does not work as it should |
|
1053 RCmManager cmm; |
|
1054 cmm.OpenL(); |
|
1055 CleanupClosePushL( cmm ); |
|
1056 RCmDestination destination( cmm.DestinationL( snapId ) ); |
|
1057 CleanupClosePushL( destination ); |
|
1058 |
|
1059 TBool wlanIapFound( EFalse ); |
|
1060 |
|
1061 for ( TInt i = 0; i < destination.ConnectionMethodCount(); i++ ) |
|
1062 { |
|
1063 RCmConnectionMethod cm = destination.ConnectionMethodL( i ); |
|
1064 CleanupClosePushL( cm ); |
|
1065 |
|
1066 if( KUidWlanBearerType == |
|
1067 cm.GetIntAttributeL( CMManager::ECmBearerType ) ) |
|
1068 { |
|
1069 SCPLOGSTRING( "CScpServiceManager::CheckAvailableConnectionsL WLAN IAP found" ); |
|
1070 iaps.Append( cm.GetIntAttributeL( CMManager::ECmIapId ) ); |
|
1071 wlanIapFound = ETrue; |
|
1072 } |
|
1073 else |
|
1074 { |
|
1075 SCPLOGSTRING2( "CScpServiceManager::CheckAvailableConnectionsL iaps count = %d", iaps.Count() ); |
|
1076 SCPLOGSTRING( "CScpServiceManager::CheckAvailableConnectionsL 3G IAP found break the loop" ); |
|
1077 i = destination.ConnectionMethodCount(); |
|
1078 } |
|
1079 |
|
1080 CleanupStack::PopAndDestroy( &cm ); |
|
1081 } |
|
1082 |
|
1083 TBool available( EFalse ); |
|
1084 for ( TInt j( 0 ); j < iaps.Count(); j++ ) |
|
1085 { |
|
1086 if ( sipConnection->IsIapConnectionAvailable( iaps[ j ] ) ) |
|
1087 { |
|
1088 SCPLOGSTRING( "CScpServiceManager::CheckAvailableConnectionsL WLAN IAP available" ); |
|
1089 available = ETrue; |
|
1090 break; |
|
1091 } |
|
1092 } |
|
1093 |
|
1094 CleanupStack::PopAndDestroy( &destination ); |
|
1095 CleanupStack::PopAndDestroy( &cmm ); |
|
1096 CleanupStack::PopAndDestroy( &iaps ); |
|
1097 |
|
1098 |
|
1099 |
|
1100 if ( !available && wlanIapFound ) |
|
1101 { |
|
1102 User::Leave( KCCHErrorNetworkLost ); |
|
1103 } |
|
1104 |
|
1105 else if( !wlanIapFound ) |
|
1106 { |
|
1107 User::Leave( KCCHErrorAccessPointNotDefined ); |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 if( sipConnectionCreated ) |
|
1112 { |
|
1113 CleanupStack::PopAndDestroy( sipConnection ); |
|
1114 } |
|
1115 } |
|
1116 |
|
1117 // End of file |
|