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: Connection manager for DRM |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <es_sock.h> |
|
20 #include <cmconnectionmethod.h> |
|
21 #include <cmdestination.h> |
|
22 #include <cmconnectionmethoddef.h> |
|
23 #include <cmmanager.h> |
|
24 #include <extendedconnpref.h> |
|
25 #include <cmapplicationsettingsui.h> // CCmApplicationSettingsUi |
|
26 #include <es_enum.h> |
|
27 #include <cdbcols.h> // IAP, COMMDB_ID |
|
28 #include "drmutilityconnection.h" |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "drmutilityconnectionTraces.h" |
|
32 #endif |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // HasDefaultConnectionL |
|
39 // Finds default IAP id |
|
40 // @return Etrue: valid AP found |
|
41 // EFalse: valid AP not found |
|
42 // @leave system wide error codes |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 TBool DRM::CDrmUtilityConnection::HasDefaultConnectionL() |
|
46 { |
|
47 TBool hasDefault(EFalse); |
|
48 TCmDefConnValue defConn; |
|
49 RCmManager cmManager; |
|
50 cmManager.OpenLC(); |
|
51 cmManager.ReadDefConnL(defConn); |
|
52 if (defConn.iType == ECmDefConnConnectionMethod) |
|
53 { |
|
54 cmManager.GetConnectionMethodInfoIntL(defConn.iId, |
|
55 CMManager::ECmIapId); |
|
56 hasDefault = ETrue; |
|
57 } |
|
58 else if (defConn.iType == ECmDefConnDestination) |
|
59 { |
|
60 RCmDestination dest(cmManager.DestinationL(defConn.iId)); |
|
61 CleanupClosePushL(dest); |
|
62 |
|
63 if (dest.ConnectionMethodCount() <= 0) |
|
64 { |
|
65 User::Leave(KErrNotFound); |
|
66 } |
|
67 |
|
68 RCmConnectionMethod cMeth(dest.ConnectionMethodL(0)); |
|
69 CleanupClosePushL(cMeth); |
|
70 |
|
71 cMeth.GetIntAttributeL(CMManager::ECmIapId); |
|
72 CleanupStack::PopAndDestroy(&cMeth); |
|
73 CleanupStack::PopAndDestroy(&dest); |
|
74 hasDefault = ETrue; |
|
75 } |
|
76 CleanupStack::PopAndDestroy(&cmManager); |
|
77 return hasDefault; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CDrmUtilityConnection::HasAccessPointsL |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 TBool DRM::CDrmUtilityConnection::HasAccessPointsL() |
|
85 { |
|
86 TInt apCount(0); |
|
87 RCmManager cmManager; |
|
88 CleanupClosePushL(cmManager); |
|
89 cmManager.OpenL(); |
|
90 RArray<TUint32> aps; |
|
91 CleanupClosePushL(aps); |
|
92 cmManager.ConnectionMethodL(aps, EFalse, EFalse, ETrue); |
|
93 apCount = aps.Count(); |
|
94 CleanupStack::PopAndDestroy(2, &cmManager); //aps, cmManager |
|
95 return apCount > 0; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // DRM::CDrmUtilityConnection::NewLC |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 DRM::CDrmUtilityConnection* DRM::CDrmUtilityConnection::NewLC( |
|
103 const TBool aAllowQueries) |
|
104 { |
|
105 CDrmUtilityConnection* conn = new (ELeave) CDrmUtilityConnection( |
|
106 aAllowQueries); |
|
107 CleanupStack::PushL(conn); |
|
108 conn->ConstructL(); |
|
109 return conn; |
|
110 } |
|
111 // --------------------------------------------------------------------------- |
|
112 // DRM::CDrmUtilityConnection::NewL |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 DRM::CDrmUtilityConnection* DRM::CDrmUtilityConnection::NewL( |
|
116 const TBool aAllowQueries) |
|
117 { |
|
118 CDrmUtilityConnection* conn = CDrmUtilityConnection::NewLC(aAllowQueries); |
|
119 CleanupStack::Pop(conn); |
|
120 return conn; |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // DRM::CDrmUtilityConnection::~CDrmUtilityConnection |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 DRM::CDrmUtilityConnection::~CDrmUtilityConnection() |
|
128 { |
|
129 Cancel(); |
|
130 iConnection.Close(); |
|
131 iSocketServ.Close(); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // DRM::CDrmUtilityConnection::ConnectL |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void DRM::CDrmUtilityConnection::ConnectL(TRequestStatus* aStatus) |
|
139 { |
|
140 TInt error(KErrGeneral); |
|
141 iStatus = KRequestPending; |
|
142 |
|
143 if (iState == EInit) |
|
144 { |
|
145 |
|
146 // Make this part atomic by pushing closes on the stack. |
|
147 error = iSocketServ.Connect(); |
|
148 if (!error) |
|
149 { |
|
150 error = iConnection.Open(iSocketServ); |
|
151 } |
|
152 } |
|
153 |
|
154 if (iState == EConnected) |
|
155 { |
|
156 error=iConnection.Stop(); |
|
157 //error=iConnection.Stop(RConnection::EStopAuthoritative); //just in case still does not work |
|
158 // if autoriative stop does not work then must do something following follow |
|
159 // TNifProgressBuf iJalla; |
|
160 // loop iConnection.ProgressNotification(iJalla,iStatus,KConnProgressDefault); SetActive |
|
161 // at RunL if (iJalla.iStage < KConnectionDown) |
|
162 // reactiveteWaitClose(); |
|
163 //iConnection.ProgressNotification(iJalla,iStatus,(KConnectionDown); (should loop till state KConnectionDown seen) |
|
164 iConnection.Close(); |
|
165 iState = EInit; |
|
166 error = KErrNone; |
|
167 error = iConnection.Open(iSocketServ); |
|
168 } |
|
169 |
|
170 iParentStatus = aStatus; |
|
171 *iParentStatus = KRequestPending; |
|
172 |
|
173 CompleteSelf(error); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // DRM::CDrmUtilityConnection::HasMoreConnectionAttempts |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 TBool DRM::CDrmUtilityConnection::HasMoreConnectionAttempts() |
|
181 { |
|
182 TBool ret(EFalse); |
|
183 switch (iType) |
|
184 { |
|
185 case EUsingPurposeInternet: |
|
186 if (iAllowQueries) |
|
187 { |
|
188 ret = ETrue; |
|
189 } |
|
190 else |
|
191 { |
|
192 ret = EFalse; |
|
193 } |
|
194 break; |
|
195 case EUsingQuery: |
|
196 case EFail: |
|
197 ret = EFalse; |
|
198 break; |
|
199 default: |
|
200 ret = ETrue; |
|
201 } |
|
202 return ret; |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // DRM::CDrmUtilityConnection::IsConnected |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 TBool DRM::CDrmUtilityConnection::IsConnected(TUint32& aIap) |
|
210 { |
|
211 TBool ret(EFalse); |
|
212 |
|
213 if (iState == EConnected) |
|
214 { |
|
215 aIap = iIapId; |
|
216 ret = ETrue; |
|
217 } |
|
218 return ret; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // DRM::CDrmUtilityConnection::Close |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void DRM::CDrmUtilityConnection::Close() |
|
226 { |
|
227 //LOGLIT( "CDrmUtilityConnection::Close" ) |
|
228 |
|
229 Cancel(); |
|
230 iConnection.Close(); |
|
231 iSocketServ.Close(); |
|
232 iState = EInit; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // DRM::CDrmUtilityConnection:CDrmUtilityConnection: |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 DRM::CDrmUtilityConnection::CDrmUtilityConnection(const TBool aAllowQueries) : |
|
240 CActive(CActive::EPriorityStandard), iState(EInit), |
|
241 iType(EAttachExisting), iAllowQueries(aAllowQueries) |
|
242 { |
|
243 CActiveScheduler::Add(this); |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // DRM::CDrmUtilityConnection::ConstructL |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void DRM::CDrmUtilityConnection::ConstructL() |
|
251 { |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // DRM::CDrmUtilityConnection::DoCancel |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 void DRM::CDrmUtilityConnection::DoCancel() |
|
259 { |
|
260 iConnection.Close(); |
|
261 iSocketServ.Close(); |
|
262 CompleteParent(KErrCancel); |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // DRM::CDrmUtilityConnection::RunL |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void DRM::CDrmUtilityConnection::RunL() |
|
270 { |
|
271 TInt error(iStatus.Int()); |
|
272 if (iState == EInit) |
|
273 { |
|
274 User::LeaveIfError(error); // Handle errors in RunError(). |
|
275 if (iType == EAttachExisting) |
|
276 { |
|
277 AttachExistingConnectionL(); |
|
278 } |
|
279 else |
|
280 { |
|
281 iState = EConnecting; |
|
282 error = KErrNotFound; |
|
283 CompleteSelf(error); |
|
284 } |
|
285 } |
|
286 else if (iState == EConnecting) |
|
287 { |
|
288 if (!error) |
|
289 { |
|
290 iState = EConnected; |
|
291 CompleteSelf(error); |
|
292 } |
|
293 else if (error != KErrNotFound) |
|
294 { |
|
295 User::LeaveIfError(error); |
|
296 } |
|
297 else |
|
298 { |
|
299 switch (iType) |
|
300 { |
|
301 case EAttachExisting: |
|
302 iType = EUsingDefault; |
|
303 ConnectUsingDefaultL(); |
|
304 break; |
|
305 case EUsingDefault: |
|
306 iType = EUsingPurposeOperator; |
|
307 ConnectUsingSnapPurposeL(CMManager::ESnapPurposeOperator); |
|
308 break; |
|
309 case EUsingPurposeOperator: |
|
310 iType = EUsingPurposeInternet; |
|
311 ConnectUsingSnapPurposeL(CMManager::ESnapPurposeInternet); |
|
312 break; |
|
313 case EUsingPurposeInternet: |
|
314 iType = EUsingQuery; |
|
315 if (iAllowQueries) |
|
316 { |
|
317 ConnectUsingQueryL(); |
|
318 break; |
|
319 } |
|
320 case EUsingQuery: |
|
321 iType = EFail; |
|
322 case EFail: |
|
323 default: |
|
324 User::Leave(KErrCouldNotConnect); |
|
325 break; |
|
326 } |
|
327 } |
|
328 } |
|
329 else if (iState == EConnected) |
|
330 { |
|
331 UpdateIapIdL(); |
|
332 CompleteParent(iStatus.Int()); |
|
333 } |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // DRM::CDrmUtilityConnection::RunError |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 TInt DRM::CDrmUtilityConnection::RunError(TInt aError) |
|
341 { |
|
342 //LOGLIT( "CDrmUtilityConnection::RunError" ) |
|
343 |
|
344 iConnection.Close(); |
|
345 iSocketServ.Close(); |
|
346 |
|
347 CompleteParent(aError); |
|
348 iState = EInit; |
|
349 return KErrNone; |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // DRM::CDrmUtilityConnection::AttachExistingConnectionL |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void DRM::CDrmUtilityConnection::AttachExistingConnectionL() |
|
357 { |
|
358 TConnectionInfoBuf connInfo; |
|
359 TUint count(0); |
|
360 TInt error(KErrNotFound); |
|
361 iStatus = KRequestPending; |
|
362 |
|
363 User::LeaveIfError(iConnection.EnumerateConnections(count)); |
|
364 if (count) |
|
365 { |
|
366 // Select AP with largest index. (Latest created) |
|
367 User::LeaveIfError(iConnection.GetConnectionInfo(count, connInfo)); |
|
368 User::LeaveIfError(iConnection.Attach(connInfo, |
|
369 RConnection::EAttachTypeNormal)); |
|
370 iState = EConnected; |
|
371 error = KErrNone; |
|
372 } |
|
373 else |
|
374 { |
|
375 iState = EConnecting; |
|
376 } |
|
377 CompleteSelf(error); |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // DRM::CDrmUtilityConnection::ConnectUsingDefaultL |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 void DRM::CDrmUtilityConnection::ConnectUsingDefaultL() |
|
385 { |
|
386 // Create overrides |
|
387 TConnPrefList prefList; |
|
388 TExtendedConnPref prefs; |
|
389 |
|
390 if (!iAllowQueries) |
|
391 { |
|
392 prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent); |
|
393 } |
|
394 else |
|
395 { |
|
396 prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnDisableQueries); |
|
397 } |
|
398 |
|
399 //Fetch default connection |
|
400 TBool hasDefault(ETrue); |
|
401 TCmDefConnValue defConn; |
|
402 RCmManager cmManager; |
|
403 cmManager.OpenLC(); |
|
404 cmManager.ReadDefConnL(defConn); |
|
405 if (defConn.iType == ECmDefConnConnectionMethod) |
|
406 { |
|
407 prefs.SetIapId(defConn.iId); |
|
408 } |
|
409 else if (defConn.iType == ECmDefConnDestination) |
|
410 { |
|
411 prefs.SetSnapId(defConn.iId); |
|
412 } |
|
413 else |
|
414 { |
|
415 hasDefault = EFalse; |
|
416 } |
|
417 // End of fetch default connection |
|
418 CleanupStack::PopAndDestroy(&cmManager); |
|
419 if (hasDefault) |
|
420 { |
|
421 prefList.AppendL(&prefs); |
|
422 |
|
423 // Start an Outgoing Connection with overrides |
|
424 iState = EConnecting; |
|
425 iConnection.Start(prefList, iStatus); |
|
426 SetActive(); |
|
427 } |
|
428 else |
|
429 { |
|
430 // No default found --> next iteration needed |
|
431 CompleteSelf(KErrNotFound); |
|
432 } |
|
433 } |
|
434 |
|
435 // --------------------------------------------------------------------------- |
|
436 // DRM::CDrmUtilityConnection::ConnectUsingSnapOperatorL |
|
437 // --------------------------------------------------------------------------- |
|
438 // |
|
439 void DRM::CDrmUtilityConnection::ConnectUsingSnapPurposeL( |
|
440 const TUint32 aPurpose) |
|
441 { |
|
442 // Create overrides |
|
443 TConnPrefList prefList; |
|
444 TExtendedConnPref prefs; |
|
445 prefs.SetSnapPurpose(static_cast<CMManager::TSnapPurpose> (aPurpose)); |
|
446 if (aPurpose != CMManager::ESnapPurposeUnknown) |
|
447 { |
|
448 if (!iAllowQueries) |
|
449 { |
|
450 prefs.SetNoteBehaviour( |
|
451 TExtendedConnPref::ENoteBehaviourConnSilent); |
|
452 } |
|
453 else |
|
454 { |
|
455 prefs.SetNoteBehaviour( |
|
456 TExtendedConnPref::ENoteBehaviourConnDisableQueries); |
|
457 } |
|
458 } |
|
459 else |
|
460 { |
|
461 prefs.SetConnSelectionDialog(ETrue); |
|
462 prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourDefault); |
|
463 prefs.SetForcedRoaming(EFalse); |
|
464 prefs.SetBearerSet(TExtendedConnPref::EExtendedConnBearerUnknown); |
|
465 } |
|
466 prefList.AppendL(&prefs); |
|
467 iState = EConnecting; |
|
468 |
|
469 // Start an Outgoing Connection with overrides |
|
470 iConnection.Start(prefList, iStatus); |
|
471 SetActive(); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------------------------- |
|
475 // DRM::CDrmUtilityConnection::ConnectUsingQueryL |
|
476 // --------------------------------------------------------------------------- |
|
477 // |
|
478 void DRM::CDrmUtilityConnection::ConnectUsingQueryL() |
|
479 { |
|
480 // Create overrides |
|
481 TConnPrefList prefList; |
|
482 TExtendedConnPref prefs; |
|
483 |
|
484 CCmApplicationSettingsUi* ui(CCmApplicationSettingsUi::NewLC()); |
|
485 TCmSettingSelection selectedConn; |
|
486 |
|
487 TBool selected(ui->RunApplicationSettingsL(selectedConn)); |
|
488 CleanupStack::PopAndDestroy(ui); |
|
489 ui=NULL; |
|
490 if (selected) |
|
491 { |
|
492 if (selectedConn.iResult == CMManager::EConnectionMethod) |
|
493 { |
|
494 prefs.SetIapId(selectedConn.iId); |
|
495 } |
|
496 else if (selectedConn.iResult == CMManager::EDestination) |
|
497 { |
|
498 prefs.SetSnapId(selectedConn.iId); |
|
499 } |
|
500 else if (selectedConn.iResult != CMManager::EDefaultConnection) |
|
501 { |
|
502 selected=EFalse; |
|
503 } |
|
504 } |
|
505 if (selected) |
|
506 { |
|
507 if (selectedConn.iResult != CMManager::EDefaultConnection) |
|
508 { |
|
509 prefList.AppendL(&prefs); |
|
510 // For ensuring possibly stale connections get disconnected first; |
|
511 iConnection.Close(); |
|
512 iConnection.Open(iSocketServ); |
|
513 |
|
514 iConnection.Start(prefList, iStatus); |
|
515 } |
|
516 else |
|
517 { |
|
518 iConnection.Start(iStatus); |
|
519 } |
|
520 SetActive(); |
|
521 } |
|
522 else |
|
523 { |
|
524 CompleteSelf(KErrCancel); |
|
525 } |
|
526 } |
|
527 // --------------------------------------------------------------------------- |
|
528 // DRM::CDrmUtilityConnection::CompleteSelf |
|
529 // --------------------------------------------------------------------------- |
|
530 // |
|
531 void DRM::CDrmUtilityConnection::CompleteSelf(TInt aError) |
|
532 { |
|
533 TRequestStatus* status(&iStatus); |
|
534 User::RequestComplete(status, aError); |
|
535 SetActive(); |
|
536 } |
|
537 |
|
538 // --------------------------------------------------------------------------- |
|
539 // DRM::CDrmUtilityConnection::CompleteParent |
|
540 // --------------------------------------------------------------------------- |
|
541 // |
|
542 void DRM::CDrmUtilityConnection::CompleteParent(TInt aError) |
|
543 { |
|
544 if (iParentStatus) |
|
545 { |
|
546 User::RequestComplete(iParentStatus, aError); |
|
547 iParentStatus = NULL; |
|
548 } |
|
549 } |
|
550 |
|
551 // --------------------------------------------------------------------------- |
|
552 // DRM::CDrmUtilityConnection::UpdateIapId |
|
553 // --------------------------------------------------------------------------- |
|
554 // |
|
555 void DRM::CDrmUtilityConnection::UpdateIapIdL() |
|
556 { |
|
557 TBuf<16> query; |
|
558 |
|
559 query.Format(_L("%s\\%s"), IAP, COMMDB_ID); |
|
560 User::LeaveIfError(iConnection.GetIntSetting(query, iIapId)); |
|
561 |
|
562 } |
|