1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "symbianengine.h"
#include "qnetworksession_impl.h"
#include <commdb.h>
#include <cdbcols.h>
#include <d32dbms.h>
#include <nifvar.h>
#include <QTimer>
#include <QTime> // For randgen seeding
#include <QtCore> // For randgen seeding
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
#include <QDebug>
#endif
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
#include <cmdestination.h>
#include <cmconnectionmethod.h>
#include <cmconnectionmethoddef.h>
#include <cmpluginwlandef.h>
#include <cmpluginpacketdatadef.h>
#include <cmplugindialcommondefs.h>
#else
#include <ApAccessPointItem.h>
#include <ApDataHandler.h>
#include <ApUtils.h>
#endif
#ifndef QT_NO_BEARERMANAGEMENT
QT_BEGIN_NAMESPACE
static const int KUserChoiceIAPId = 0;
SymbianNetworkConfigurationPrivate::SymbianNetworkConfigurationPrivate()
: numericId(0), connectionId(0)
{
}
SymbianNetworkConfigurationPrivate::~SymbianNetworkConfigurationPrivate()
{
}
SymbianEngine::SymbianEngine(QObject *parent)
: QBearerEngine(parent), CActive(CActive::EPriorityHigh), iFirstUpdate(true), ipCommsDB(0),
iInitOk(true), iUpdatePending(false), ipAccessPointsAvailabilityScanner(0)
{
}
void SymbianEngine::initialize()
{
QMutexLocker locker(&mutex);
CActiveScheduler::Add(this);
// Seed the randomgenerator
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()) + QCoreApplication::applicationPid());
TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP));
if (error != KErrNone) {
iInitOk = false;
return;
}
TRAP_IGNORE(iConnectionMonitor.ConnectL());
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
TRAP_IGNORE(iConnectionMonitor.SetUintAttribute(EBearerIdAll, 0, KBearerGroupThreshold, 1));
#endif
TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this));
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
TRAP(error, iCmManager.OpenL());
if (error != KErrNone) {
iInitOk = false;
return;
}
#endif
SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate;
cpPriv->name = "UserChoice";
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
cpPriv->state = QNetworkConfiguration::Discovered;
cpPriv->isValid = true;
cpPriv->id = QString::number(qHash(KUserChoiceIAPId));
cpPriv->numericId = KUserChoiceIAPId;
cpPriv->connectionId = 0;
cpPriv->type = QNetworkConfiguration::UserChoice;
cpPriv->purpose = QNetworkConfiguration::UnknownPurpose;
cpPriv->roamingSupported = false;
QNetworkConfigurationPrivatePointer ptr(cpPriv);
userChoiceConfigurations.insert(ptr->id, ptr);
updateConfigurations();
updateStatesToSnaps();
updateAvailableAccessPoints(); // On first time updates synchronously (without WLAN scans)
// Start monitoring IAP and/or SNAP changes in Symbian CommsDB
startCommsDatabaseNotifications();
iFirstUpdate = false;
}
SymbianEngine::~SymbianEngine()
{
Cancel();
iConnectionMonitor.CancelNotifications();
iConnectionMonitor.Close();
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
iCmManager.Close();
#endif
delete ipAccessPointsAvailabilityScanner;
// CCommsDatabase destructor uses cleanup stack. Since QNetworkConfigurationManager
// is a global static, but the time we are here, E32Main() has been exited already and
// the thread's default cleanup stack has been deleted. Without this line, a
// 'E32USER-CBase 69' -panic will occur.
CTrapCleanup* cleanup = CTrapCleanup::New();
delete ipCommsDB;
delete cleanup;
}
void SymbianEngine::delayedConfigurationUpdate()
{
QMutexLocker locker(&mutex);
if (iUpdatePending) {
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug("QNCM delayed configuration update (ECommit or ERecover occurred).");
#endif
TRAPD(error, updateConfigurationsL());
if (error == KErrNone) {
updateStatesToSnaps();
}
iUpdatePending = false;
// Start monitoring again.
if (!IsActive()) {
SetActive();
// Start waiting for new notification
ipCommsDB->RequestNotification(iStatus);
}
}
}
bool SymbianEngine::hasIdentifier(const QString &id)
{
QMutexLocker locker(&mutex);
return accessPointConfigurations.contains(id) ||
snapConfigurations.contains(id) ||
userChoiceConfigurations.contains(id);
}
QNetworkConfigurationManager::Capabilities SymbianEngine::capabilities() const
{
QNetworkConfigurationManager::Capabilities capFlags;
capFlags = QNetworkConfigurationManager::CanStartAndStopInterfaces |
QNetworkConfigurationManager::DirectConnectionRouting |
QNetworkConfigurationManager::SystemSessionSupport |
QNetworkConfigurationManager::DataStatistics |
QNetworkConfigurationManager::NetworkSessionRequired;
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
capFlags |= QNetworkConfigurationManager::ApplicationLevelRoaming |
QNetworkConfigurationManager::ForcedRoaming;
#endif
return capFlags;
}
QNetworkSessionPrivate *SymbianEngine::createSessionBackend()
{
return new QNetworkSessionPrivateImpl(this);
}
void SymbianEngine::requestUpdate()
{
QMutexLocker locker(&mutex);
if (!iInitOk || iUpdateGoingOn) {
return;
}
iUpdateGoingOn = true;
stopCommsDatabaseNotifications();
updateConfigurations(); // Synchronous call
updateAvailableAccessPoints(); // Asynchronous call
}
void SymbianEngine::updateConfigurations()
{
if (!iInitOk)
return;
TRAP_IGNORE(updateConfigurationsL());
}
void SymbianEngine::updateConfigurationsL()
{
QList<QString> knownConfigs = accessPointConfigurations.keys();
QList<QString> knownSnapConfigs = snapConfigurations.keys();
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
// S60 version is >= Series60 3rd Edition Feature Pack 2
TInt error = KErrNone;
// Loop through all IAPs
RArray<TUint32> connectionMethods; // IAPs
CleanupClosePushL(connectionMethods);
iCmManager.ConnectionMethodL(connectionMethods);
for(int i = 0; i < connectionMethods.Count(); i++) {
RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]);
CleanupClosePushL(connectionMethod);
TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId));
if (accessPointConfigurations.contains(ident)) {
knownConfigs.removeOne(ident);
} else {
SymbianNetworkConfigurationPrivate* cpPriv = NULL;
TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod));
if (error == KErrNone) {
QNetworkConfigurationPrivatePointer ptr(cpPriv);
accessPointConfigurations.insert(ptr->id, ptr);
if (!iFirstUpdate) {
// Emit configuration added. Connected slots may throw execptions
// which propagate here --> must be converted to leaves (standard
// std::exception would cause any TRAP trapping this function to terminate
// program).
QT_TRYCATCH_LEAVING(updateActiveAccessPoints());
updateStatesToSnaps();
mutex.unlock();
QT_TRYCATCH_LEAVING(emit configurationAdded(ptr));
mutex.lock();
}
}
}
CleanupStack::PopAndDestroy(&connectionMethod);
}
CleanupStack::PopAndDestroy(&connectionMethods);
// Loop through all SNAPs
RArray<TUint32> destinations;
CleanupClosePushL(destinations);
iCmManager.AllDestinationsL(destinations);
for(int i = 0; i < destinations.Count(); i++) {
RCmDestination destination;
// Some destinatsions require ReadDeviceData -capability (MMS/WAP)
// The below function will leave in these cases. Don't. Proceed to
// next destination (if any).
TRAPD(error, destination = iCmManager.DestinationL(destinations[i]));
if (error == KErrPermissionDenied) {
continue;
} else {
User::LeaveIfError(error);
}
CleanupClosePushL(destination);
QString ident = QT_BEARERMGMT_CONFIGURATION_SNAP_PREFIX +
QString::number(qHash(destination.Id()));
if (snapConfigurations.contains(ident)) {
knownSnapConfigs.removeOne(ident);
} else {
SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate;
HBufC *pName = destination.NameLC();
QT_TRYCATCH_LEAVING(cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()));
CleanupStack::PopAndDestroy(pName);
pName = NULL;
cpPriv->isValid = true;
cpPriv->id = ident;
cpPriv->numericId = destination.Id();
cpPriv->connectionId = 0;
cpPriv->state = QNetworkConfiguration::Defined;
cpPriv->type = QNetworkConfiguration::ServiceNetwork;
cpPriv->purpose = QNetworkConfiguration::UnknownPurpose;
cpPriv->roamingSupported = false;
QNetworkConfigurationPrivatePointer ptr(cpPriv);
snapConfigurations.insert(ident, ptr);
if (!iFirstUpdate) {
QT_TRYCATCH_LEAVING(updateActiveAccessPoints());
updateStatesToSnaps();
mutex.unlock();
QT_TRYCATCH_LEAVING(emit configurationAdded(ptr));
mutex.lock();
}
}
// Loop through all connection methods in this SNAP
QMap<unsigned int, QNetworkConfigurationPrivatePointer> connections;
for (int j=0; j < destination.ConnectionMethodCount(); j++) {
RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j);
CleanupClosePushL(connectionMethod);
TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId);
QString iface = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId));
// Check that IAP can be found from accessPointConfigurations list
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface);
if (!ptr) {
SymbianNetworkConfigurationPrivate *cpPriv = NULL;
TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod));
if (error == KErrNone) {
ptr = QNetworkConfigurationPrivatePointer(cpPriv);
accessPointConfigurations.insert(ptr->id, ptr);
if (!iFirstUpdate) {
QT_TRYCATCH_LEAVING(updateActiveAccessPoints());
updateStatesToSnaps();
mutex.unlock();
QT_TRYCATCH_LEAVING(emit configurationAdded(ptr));
mutex.lock();
}
}
} else {
knownConfigs.removeOne(iface);
}
if (ptr) {
unsigned int priority;
TRAPD(error, priority = destination.PriorityL(connectionMethod));
if (!error)
connections.insert(priority, ptr);
}
CleanupStack::PopAndDestroy(&connectionMethod);
}
QNetworkConfigurationPrivatePointer privSNAP = snapConfigurations.value(ident);
QMutexLocker snapConfigLocker(&privSNAP->mutex);
if (privSNAP->serviceNetworkMembers != connections) {
privSNAP->serviceNetworkMembers = connections;
// Roaming is supported only if SNAP contains more than one IAP
privSNAP->roamingSupported = privSNAP->serviceNetworkMembers.count() > 1;
snapConfigLocker.unlock();
updateStatesToSnaps();
mutex.unlock();
QT_TRYCATCH_LEAVING(emit configurationChanged(privSNAP));
mutex.lock();
}
CleanupStack::PopAndDestroy(&destination);
}
CleanupStack::PopAndDestroy(&destinations);
#else
// S60 version is < Series60 3rd Edition Feature Pack 2
CCommsDbTableView* pDbTView = ipCommsDB->OpenTableLC(TPtrC(IAP));
// Loop through all IAPs
TUint32 apId = 0;
TInt retVal = pDbTView->GotoFirstRecord();
while (retVal == KErrNone) {
pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId));
if (accessPointConfigurations.contains(ident)) {
knownConfigs.removeOne(ident);
} else {
SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate;
if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) {
QNetworkConfigurationPrivatePointer ptr(cpPriv);
accessPointConfigurations.insert(ident, ptr);
if (!iFirstUpdate) {
QT_TRYCATCH_LEAVING(updateActiveAccessPoints());
updateStatesToSnaps();
mutex.unlock();
QT_TRYCATCH_LEAVING(emit configurationAdded(ptr));
mutex.lock();
}
} else {
delete cpPriv;
}
}
retVal = pDbTView->GotoNextRecord();
}
CleanupStack::PopAndDestroy(pDbTView);
#endif
QT_TRYCATCH_LEAVING(updateActiveAccessPoints());
foreach (const QString &oldIface, knownConfigs) {
//remove non existing IAP
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldIface);
mutex.unlock();
emit configurationRemoved(ptr);
QT_TRYCATCH_LEAVING(emit configurationRemoved(ptr));
mutex.lock();
// Remove non existing IAP from SNAPs
foreach (const QString &iface, snapConfigurations.keys()) {
QNetworkConfigurationPrivatePointer ptr2 = snapConfigurations.value(iface);
// => Check if one of the IAPs of the SNAP is active
QMutexLocker snapConfigLocker(&ptr2->mutex);
QMutableMapIterator<unsigned int, QNetworkConfigurationPrivatePointer> i(ptr2->serviceNetworkMembers);
while (i.hasNext()) {
i.next();
if (toSymbianConfig(i.value())->numericIdentifier() ==
toSymbianConfig(ptr)->numericIdentifier()) {
i.remove();
break;
}
}
}
}
foreach (const QString &oldIface, knownSnapConfigs) {
//remove non existing SNAPs
QNetworkConfigurationPrivatePointer ptr = snapConfigurations.take(oldIface);
mutex.unlock();
emit configurationRemoved(ptr);
QT_TRYCATCH_LEAVING(emit configurationRemoved(ptr));
mutex.lock();
}
// find default configuration.
stopCommsDatabaseNotifications();
TRAP_IGNORE(defaultConfig = defaultConfigurationL());
startCommsDatabaseNotifications();
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
updateStatesToSnaps();
#endif
}
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL(
RCmConnectionMethod& connectionMethod)
{
SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate;
TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId));
HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName);
CleanupStack::PushL(pName);
QT_TRYCATCH_LEAVING(cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()));
CleanupStack::PopAndDestroy(pName);
pName = NULL;
TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType);
switch (bearerId) {
case KCommDbBearerCSD:
cpPriv->bearerType = QNetworkConfiguration::Bearer2G;
break;
case KCommDbBearerWcdma:
cpPriv->bearerType = QNetworkConfiguration::BearerWCDMA;
break;
case KCommDbBearerLAN:
cpPriv->bearerType = QNetworkConfiguration::BearerEthernet;
break;
case KCommDbBearerVirtual:
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
break;
case KCommDbBearerPAN:
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
break;
case KCommDbBearerWLAN:
cpPriv->bearerType = QNetworkConfiguration::BearerWLAN;
break;
default:
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
break;
}
TInt error = KErrNone;
TUint32 bearerType = connectionMethod.GetIntAttributeL(CMManager::ECmBearerType);
switch (bearerType) {
case KUidPacketDataBearerType:
// "Packet data" Bearer => Mapping is done using "Access point name"
TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName));
break;
case KUidWlanBearerType:
// "Wireless LAN" Bearer => Mapping is done using "WLAN network name" = SSID
TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EWlanSSID));
break;
}
if (!pName) {
// "Data call" Bearer or "High Speed (GSM)" Bearer => Mapping is done using "Dial-up number"
TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EDialDefaultTelNum));
}
if (error == KErrNone && pName) {
CleanupStack::PushL(pName);
QT_TRYCATCH_LEAVING(cpPriv->mappingName = QString::fromUtf16(pName->Ptr(),pName->Length()));
CleanupStack::PopAndDestroy(pName);
pName = NULL;
}
cpPriv->state = QNetworkConfiguration::Defined;
TBool isConnected = connectionMethod.GetBoolAttributeL(CMManager::ECmConnected);
if (isConnected) {
cpPriv->state = QNetworkConfiguration::Active;
}
cpPriv->isValid = true;
cpPriv->id = ident;
cpPriv->numericId = iapId;
cpPriv->connectionId = 0;
cpPriv->type = QNetworkConfiguration::InternetAccessPoint;
cpPriv->purpose = QNetworkConfiguration::UnknownPurpose;
cpPriv->roamingSupported = false;
return cpPriv;
}
#else
bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb(
TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration)
{
TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration));
if (error != KErrNone) {
return false;
}
return true;
}
void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL(
TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration)
{
CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB);
CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC();
TBuf<KCommsDbSvrMaxColumnNameLength> name;
CApUtils* pApUtils = CApUtils::NewLC(*ipCommsDB);
TUint32 apId = pApUtils->WapIdFromIapIdL(aApId);
pDataHandler->AccessPointDataL(apId,*pAPItem);
pAPItem->ReadTextL(EApIapName, name);
if (name.Compare(_L("Easy WLAN")) == 0) {
// "Easy WLAN" won't be accepted to the Configurations list
User::Leave(KErrNotFound);
}
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(aApId));
QT_TRYCATCH_LEAVING(apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()));
apNetworkConfiguration->isValid = true;
apNetworkConfiguration->id = ident;
apNetworkConfiguration->numericId = aApId;
apNetworkConfiguration->connectionId = 0;
apNetworkConfiguration->state = (QNetworkConfiguration::Defined);
apNetworkConfiguration->type = QNetworkConfiguration::InternetAccessPoint;
apNetworkConfiguration->purpose = QNetworkConfiguration::UnknownPurpose;
apNetworkConfiguration->roamingSupported = false;
switch (pAPItem->BearerTypeL()) {
case EApBearerTypeCSD:
apNetworkConfiguration->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EApBearerTypeGPRS:
apNetworkConfiguration->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EApBearerTypeHSCSD:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerHSPA;
break;
case EApBearerTypeCDMA:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerCDMA2000;
break;
case EApBearerTypeWLAN:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerWLAN;
break;
case EApBearerTypeLAN:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerEthernet;
break;
case EApBearerTypeLANModem:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerEthernet;
break;
default:
apNetworkConfiguration->bearerType = QNetworkConfiguration::BearerUnknown;
break;
}
CleanupStack::PopAndDestroy(pApUtils);
CleanupStack::PopAndDestroy(pAPItem);
CleanupStack::PopAndDestroy(pDataHandler);
}
#endif
QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration()
{
QMutexLocker locker(&mutex);
return defaultConfig;
}
QStringList SymbianEngine::accessPointConfigurationIdentifiers()
{
QMutexLocker locker(&mutex);
return accessPointConfigurations.keys();
}
QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL()
{
QNetworkConfigurationPrivatePointer ptr;
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
// Check Default Connection (SNAP or IAP)
TCmDefConnValue defaultConnectionValue;
iCmManager.ReadDefConnL(defaultConnectionValue);
if (defaultConnectionValue.iType == ECmDefConnDestination) {
QString iface = QT_BEARERMGMT_CONFIGURATION_SNAP_PREFIX +
QString::number(qHash(defaultConnectionValue.iId));
ptr = snapConfigurations.value(iface);
} else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) {
QString iface = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX +
QString::number(qHash(defaultConnectionValue.iId));
ptr = accessPointConfigurations.value(iface);
}
#endif
if (ptr) {
QMutexLocker configLocker(&ptr->mutex);
if (ptr->isValid)
return ptr;
}
QString iface = QString::number(qHash(KUserChoiceIAPId));
return userChoiceConfigurations.value(iface);
}
void SymbianEngine::updateActiveAccessPoints()
{
bool online = false;
QList<QString> inactiveConfigs = accessPointConfigurations.keys();
TRequestStatus status;
TUint connectionCount;
iConnectionMonitor.GetConnectionCount(connectionCount, status);
User::WaitForRequest(status);
// Go through all connections and set state of related IAPs to Active.
// Status needs to be checked carefully, because ConnMon lists also e.g.
// WLAN connections that are being currently tried --> we don't want to
// state these as active.
TUint connectionId;
TUint subConnectionCount;
TUint apId;
TInt connectionStatus;
if (status.Int() == KErrNone) {
for (TUint i = 1; i <= connectionCount; i++) {
iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount);
iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status);
User::WaitForRequest(status);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
if (!ptr) {
// If IAP was not found, check if the update was about EasyWLAN
ptr = configurationFromEasyWlan(apId, connectionId);
// Change the ident correspondingly
if (ptr) {
ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX +
QString::number(qHash(toSymbianConfig(ptr)->numericIdentifier()));
}
}
#endif
if (ptr) {
iConnectionMonitor.GetIntAttribute(connectionId, subConnectionCount, KConnectionStatus, connectionStatus, status);
User::WaitForRequest(status);
if (connectionStatus == KLinkLayerOpen) {
online = true;
inactiveConfigs.removeOne(ident);
ptr->mutex.lock();
toSymbianConfig(ptr)->connectionId = connectionId;
ptr->mutex.unlock();
// Configuration is Active
changeConfigurationStateTo(ptr, QNetworkConfiguration::Active);
}
}
}
}
// Make sure that state of rest of the IAPs won't be Active
foreach (const QString &iface, inactiveConfigs) {
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface);
if (ptr) {
// Configuration is either Defined or Discovered
changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered);
}
}
if (iOnline != online) {
iOnline = online;
mutex.unlock();
emit this->onlineStateChanged(online);
mutex.lock();
}
}
void SymbianEngine::updateAvailableAccessPoints()
{
if (!ipAccessPointsAvailabilityScanner) {
ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor);
}
if (ipAccessPointsAvailabilityScanner) {
// Scanning may take a while because WLAN scanning will be done (if device supports WLAN).
ipAccessPointsAvailabilityScanner->StartScanning();
}
}
void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo)
{
iUpdateGoingOn = false;
if (scanSuccessful) {
QList<QString> unavailableConfigs = accessPointConfigurations.keys();
// Set state of returned IAPs to Discovered
// if state is not already Active
for(TUint i=0; i<iapInfo.iCount; i++) {
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX +
QString::number(qHash(iapInfo.iIap[i].iIapId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
if (ptr) {
unavailableConfigs.removeOne(ident);
QMutexLocker configLocker(&ptr->mutex);
if (ptr->state < QNetworkConfiguration::Active) {
// Configuration is either Discovered or Active
changeConfigurationStateAtMinTo(ptr, QNetworkConfiguration::Discovered);
}
}
}
// Make sure that state of rest of the IAPs won't be Active
foreach (const QString &iface, unavailableConfigs) {
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface);
if (ptr) {
// Configuration is Defined
changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered);
}
}
}
updateStatesToSnaps();
if (!iFirstUpdate) {
startCommsDatabaseNotifications();
mutex.unlock();
emit updateCompleted();
mutex.lock();
}
}
void SymbianEngine::updateStatesToSnaps()
{
// Go through SNAPs and set correct state to SNAPs
foreach (const QString &iface, snapConfigurations.keys()) {
bool discovered = false;
bool active = false;
QNetworkConfigurationPrivatePointer ptr = snapConfigurations.value(iface);
QMutexLocker snapConfigLocker(&ptr->mutex);
// => Check if one of the IAPs of the SNAP is discovered or active
// => If one of IAPs is active, also SNAP is active
// => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered
QMapIterator<unsigned int, QNetworkConfigurationPrivatePointer> i(ptr->serviceNetworkMembers);
while (i.hasNext()) {
i.next();
const QNetworkConfigurationPrivatePointer child = i.value();
QMutexLocker configLocker(&child->mutex);
if ((child->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
active = true;
break;
} else if ((child->state & QNetworkConfiguration::Discovered) ==
QNetworkConfiguration::Discovered) {
discovered = true;
}
}
if (active) {
changeConfigurationStateTo(ptr, QNetworkConfiguration::Active);
} else if (discovered) {
changeConfigurationStateTo(ptr, QNetworkConfiguration::Discovered);
} else {
changeConfigurationStateTo(ptr, QNetworkConfiguration::Defined);
}
}
}
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
void SymbianEngine::updateMobileBearerToConfigs(TConnMonBearerInfo bearerInfo)
{
QHash<QString, QNetworkConfigurationPrivatePointer>::const_iterator i =
accessPointConfigurations.constBegin();
while (i != accessPointConfigurations.constEnd()) {
QNetworkConfigurationPrivatePointer ptr = i.value();
QMutexLocker locker(&ptr->mutex);
SymbianNetworkConfigurationPrivate *p = toSymbianConfig(ptr);
if (p->bearerType >= QNetworkConfiguration::Bearer2G &&
p->bearerType <= QNetworkConfiguration::BearerHSPA) {
switch (bearerInfo) {
case EBearerInfoCSD:
p->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EBearerInfoWCDMA:
p->bearerType = QNetworkConfiguration::BearerWCDMA;
break;
case EBearerInfoCDMA2000:
p->bearerType = QNetworkConfiguration::BearerCDMA2000;
break;
case EBearerInfoGPRS:
p->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EBearerInfoHSCSD:
p->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EBearerInfoEdgeGPRS:
p->bearerType = QNetworkConfiguration::Bearer2G;
break;
case EBearerInfoWcdmaCSD:
p->bearerType = QNetworkConfiguration::BearerWCDMA;
break;
case EBearerInfoHSDPA:
p->bearerType = QNetworkConfiguration::BearerHSPA;
break;
case EBearerInfoHSUPA:
p->bearerType = QNetworkConfiguration::BearerHSPA;
break;
case EBearerInfoHSxPA:
p->bearerType = QNetworkConfiguration::BearerHSPA;
break;
}
}
++i;
}
}
#endif
bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr,
QNetworkConfiguration::StateFlags newState)
{
ptr->mutex.lock();
if (newState != ptr->state) {
ptr->state = newState;
ptr->mutex.unlock();
mutex.unlock();
emit configurationChanged(ptr);
mutex.lock();
return true;
} else {
ptr->mutex.unlock();
}
return false;
}
/* changeConfigurationStateAtMinTo function does not overwrite possible better
* state (e.g. Discovered state does not overwrite Active state) but
* makes sure that state is at minimum given state.
*/
bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr,
QNetworkConfiguration::StateFlags newState)
{
ptr->mutex.lock();
if ((newState | ptr->state) != ptr->state) {
ptr->state = (ptr->state | newState);
ptr->mutex.unlock();
mutex.unlock();
emit configurationChanged(ptr);
mutex.lock();
return true;
} else {
ptr->mutex.unlock();
}
return false;
}
/* changeConfigurationStateAtMaxTo function overwrites possible better
* state (e.g. Discovered state overwrites Active state) and
* makes sure that state is at maximum given state (e.g. Discovered state
* does not overwrite Defined state).
*/
bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr,
QNetworkConfiguration::StateFlags newState)
{
ptr->mutex.lock();
if ((newState & ptr->state) != ptr->state) {
ptr->state = (newState & ptr->state);
ptr->mutex.unlock();
mutex.unlock();
emit configurationChanged(ptr);
mutex.lock();
return true;
} else {
ptr->mutex.unlock();
}
return false;
}
void SymbianEngine::startCommsDatabaseNotifications()
{
if (!iWaitingCommsDatabaseNotifications) {
iWaitingCommsDatabaseNotifications = ETrue;
if (!IsActive()) {
SetActive();
// Start waiting for new notification
ipCommsDB->RequestNotification(iStatus);
}
}
}
void SymbianEngine::stopCommsDatabaseNotifications()
{
if (iWaitingCommsDatabaseNotifications) {
iWaitingCommsDatabaseNotifications = EFalse;
Cancel();
}
}
void SymbianEngine::RunL()
{
QMutexLocker locker(&mutex);
if (iStatus != KErrCancel) {
// By default, start relistening notifications. Stop only if interesting event occured.
iWaitingCommsDatabaseNotifications = true;
RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int());
switch (event) {
case RDbNotifier::ECommit: /** A transaction has been committed. */
case RDbNotifier::ERecover: /** The database has been recovered */
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug("QNCM CommsDB event (of type RDbNotifier::TEvent) received: %d", iStatus.Int());
#endif
// Mark that there is update pending. No need to ask more events,
// as we know we will be updating anyway when the timer expires.
if (!iUpdatePending) {
iUpdatePending = true;
iWaitingCommsDatabaseNotifications = false;
// Update after random time, so that many processes won't
// start updating simultaneously
updateConfigurationsAfterRandomTime();
}
break;
default:
// Do nothing
break;
}
}
if (iWaitingCommsDatabaseNotifications) {
if (!IsActive()) {
SetActive();
// Start waiting for new notification
ipCommsDB->RequestNotification(iStatus);
}
}
}
void SymbianEngine::DoCancel()
{
QMutexLocker locker(&mutex);
ipCommsDB->CancelRequestNotification();
}
void SymbianEngine::EventL(const CConnMonEventBase& aEvent)
{
QMutexLocker locker(&mutex);
switch (aEvent.EventType()) {
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
case EConnMonBearerInfoChange:
{
CConnMonBearerInfoChange* realEvent;
realEvent = (CConnMonBearerInfoChange*) &aEvent;
TUint connectionId = realEvent->ConnectionId();
if (connectionId == EBearerIdAll) {
//Network level event
TConnMonBearerInfo bearerInfo = (TConnMonBearerInfo)realEvent->BearerInfo();
updateMobileBearerToConfigs(bearerInfo);
}
break;
}
#endif
case EConnMonConnectionStatusChange:
{
CConnMonConnectionStatusChange* realEvent;
realEvent = (CConnMonConnectionStatusChange*) &aEvent;
TInt connectionStatus = realEvent->ConnectionStatus();
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug() << "QNCM Connection status : " << QString::number(connectionStatus) << " , connection monitor Id : " << realEvent->ConnectionId();
#endif
if (connectionStatus == KConfigDaemonStartingRegistration) {
TUint connectionId = realEvent->ConnectionId();
TUint subConnectionCount = 0;
TUint apId;
TRequestStatus status;
iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status);
User::WaitForRequest(status);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
if (!ptr) {
// Check if status was regarding EasyWLAN
ptr = configurationFromEasyWlan(apId, connectionId);
}
#endif
if (ptr) {
ptr->mutex.lock();
toSymbianConfig(ptr)->connectionId = connectionId;
ptr->mutex.unlock();
QT_TRYCATCH_LEAVING(
emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(),
connectionId, QNetworkSession::Connecting)
);
}
} else if (connectionStatus == KLinkLayerOpen) {
// Connection has been successfully opened
TUint connectionId = realEvent->ConnectionId();
TUint subConnectionCount = 0;
TUint apId;
TRequestStatus status;
iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status);
User::WaitForRequest(status);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
if (!ptr) {
// Check for EasyWLAN
ptr = configurationFromEasyWlan(apId, connectionId);
}
#endif
if (ptr) {
ptr->mutex.lock();
toSymbianConfig(ptr)->connectionId = connectionId;
ptr->mutex.unlock();
// Configuration is Active
QT_TRYCATCH_LEAVING(
if (changeConfigurationStateTo(ptr, QNetworkConfiguration::Active)) {
updateStatesToSnaps();
}
emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(),
connectionId, QNetworkSession::Connected);
if (!iOnline) {
iOnline = true;
emit this->onlineStateChanged(iOnline);
}
);
}
} else if (connectionStatus == KConfigDaemonStartingDeregistration) {
TUint connectionId = realEvent->ConnectionId();
QNetworkConfigurationPrivatePointer ptr = dataByConnectionId(connectionId);
if (ptr) {
QT_TRYCATCH_LEAVING(
emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(),
connectionId, QNetworkSession::Closing)
);
}
} else if (connectionStatus == KLinkLayerClosed ||
connectionStatus == KConnectionClosed) {
// Connection has been closed. Which of the above events is reported, depends on the Symbian
// platform.
TUint connectionId = realEvent->ConnectionId();
QNetworkConfigurationPrivatePointer ptr = dataByConnectionId(connectionId);
if (ptr) {
// Configuration is either Defined or Discovered
QT_TRYCATCH_LEAVING(
if (changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered)) {
updateStatesToSnaps();
}
emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(),
connectionId, QNetworkSession::Disconnected);
);
}
bool online = false;
foreach (const QString &iface, accessPointConfigurations.keys()) {
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface);
QMutexLocker configLocker(&ptr->mutex);
if (ptr->state == QNetworkConfiguration::Active) {
online = true;
break;
}
}
if (iOnline != online) {
iOnline = online;
QT_TRYCATCH_LEAVING(emit this->onlineStateChanged(iOnline));
}
}
}
break;
case EConnMonIapAvailabilityChange:
{
CConnMonIapAvailabilityChange* realEvent;
realEvent = (CConnMonIapAvailabilityChange*) &aEvent;
TConnMonIapInfo iaps = realEvent->IapAvailability();
QList<QString> unDiscoveredConfigs = accessPointConfigurations.keys();
for ( TUint i = 0; i < iaps.Count(); i++ ) {
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX +
QString::number(qHash(iaps.iIap[i].iIapId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
if (ptr) {
// Configuration is either Discovered or Active
QT_TRYCATCH_LEAVING(changeConfigurationStateAtMinTo(ptr, QNetworkConfiguration::Discovered));
unDiscoveredConfigs.removeOne(ident);
}
}
foreach (const QString &iface, unDiscoveredConfigs) {
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface);
if (ptr) {
// Configuration is Defined
QT_TRYCATCH_LEAVING(changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Defined));
}
}
// Something has in IAPs, update states to SNAPs
updateStatesToSnaps();
}
break;
case EConnMonCreateConnection:
{
// This event is caught to keep connection monitor IDs up-to-date.
CConnMonCreateConnection* realEvent;
realEvent = (CConnMonCreateConnection*) &aEvent;
TUint subConnectionCount = 0;
TUint apId;
TUint connectionId = realEvent->ConnectionId();
TRequestStatus status;
iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status);
User::WaitForRequest(status);
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
if (!ptr) {
// If IAP was not found, check if the update was about EasyWLAN
ptr = configurationFromEasyWlan(apId, connectionId);
}
#endif
if (ptr) {
QMutexLocker configLocker(&ptr->mutex);
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug() << "QNCM updating connection monitor ID : from, to, whose: " << toSymbianConfig(ptr)->connectionId << connectionId << ptr->name;
#endif
toSymbianConfig(ptr)->connectionId = connectionId;
}
}
break;
default:
// For unrecognized events
break;
}
}
/*
Returns the network configuration that matches the given SSID.
*/
QNetworkConfigurationPrivatePointer SymbianEngine::configurationFromSsid(const QString &ssid)
{
QMutexLocker locker(&mutex);
// Browser through all items and check their name for match
QHash<QString, QNetworkConfigurationPrivatePointer>::ConstIterator i =
accessPointConfigurations.constBegin();
while (i != accessPointConfigurations.constEnd()) {
QNetworkConfigurationPrivatePointer ptr = i.value();
QMutexLocker configLocker(&ptr->mutex);
if (ptr->name == ssid) {
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug() << "QNCM EasyWlan uses real SSID: " << ssid;
#endif
return ptr;
}
++i;
}
return QNetworkConfigurationPrivatePointer();
}
#ifdef SNAP_FUNCTIONALITY_AVAILABLE
// Tries to derive configuration from EasyWLAN.
// First checks if the interface brought up was EasyWLAN, then derives the real SSID,
// and looks up configuration based on that one.
QNetworkConfigurationPrivatePointer SymbianEngine::configurationFromEasyWlan(TUint32 apId,
TUint connectionId)
{
if (apId == iCmManager.EasyWlanIdL()) {
TRequestStatus status;
TBuf<50> easyWlanNetworkName;
iConnectionMonitor.GetStringAttribute( connectionId, 0, KNetworkName,
easyWlanNetworkName, status );
User::WaitForRequest(status);
if (status.Int() == KErrNone) {
const QString realSSID = QString::fromUtf16(easyWlanNetworkName.Ptr(),
easyWlanNetworkName.Length());
// Browser through all items and check their name for match
QHash<QString, QNetworkConfigurationPrivatePointer>::ConstIterator i =
accessPointConfigurations.constBegin();
while (i != accessPointConfigurations.constEnd()) {
QNetworkConfigurationPrivatePointer ptr = i.value();
QMutexLocker configLocker(&ptr->mutex);
if (ptr->name == realSSID) {
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug() << "QNCM EasyWlan uses real SSID: " << realSSID;
#endif
return ptr;
}
++i;
}
}
}
return QNetworkConfigurationPrivatePointer();
}
#endif
// Sessions may use this function to report configuration state changes,
// because on some Symbian platforms (especially Symbian^3) all state changes are not
// reported by the RConnectionMonitor, in particular in relation to stop() call,
// whereas they _are_ reported on RConnection progress notifier used by sessions --> centralize
// this data here so that other sessions may benefit from it too (not all sessions necessarily have
// RConnection progress notifiers available but they relay on having e.g. disconnected information from
// manager). Currently only 'Disconnected' state is of interest because it has proven to be troublesome.
void SymbianEngine::configurationStateChangeReport(TUint32 accessPointId, QNetworkSession::State newState)
{
QMutexLocker locker(&mutex);
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug() << "QNCM A session reported state change for IAP ID: " << accessPointId << " whose new state is: " << newState;
#endif
switch (newState) {
case QNetworkSession::Disconnected:
{
QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX +
QString::number(qHash(accessPointId));
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident);
if (ptr) {
// Configuration is either Defined or Discovered
if (changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered)) {
updateStatesToSnaps();
}
locker.unlock();
emit configurationStateChanged(toSymbianConfig(ptr)->numericIdentifier(),
toSymbianConfig(ptr)->connectionIdentifier(),
QNetworkSession::Disconnected);
locker.relock();
}
}
break;
default:
break;
}
}
// Waits for 2..6 seconds.
void SymbianEngine::updateConfigurationsAfterRandomTime()
{
int iTimeToWait = qMax(1000, (qAbs(qrand()) % 68) * 100);
#ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
qDebug("QNCM waiting random time: %d ms", iTimeToWait);
#endif
QTimer::singleShot(iTimeToWait, this, SLOT(delayedConfigurationUpdate()));
}
QNetworkConfigurationPrivatePointer SymbianEngine::dataByConnectionId(TUint aConnectionId)
{
QNetworkConfiguration item;
QHash<QString, QNetworkConfigurationPrivatePointer>::const_iterator i =
accessPointConfigurations.constBegin();
while (i != accessPointConfigurations.constEnd()) {
QNetworkConfigurationPrivatePointer ptr = i.value();
if (toSymbianConfig(ptr)->connectionIdentifier() == aConnectionId)
return ptr;
++i;
}
return QNetworkConfigurationPrivatePointer();
}
AccessPointsAvailabilityScanner::AccessPointsAvailabilityScanner(SymbianEngine& owner,
RConnectionMonitor& connectionMonitor)
: CActive(CActive::EPriorityHigh), iOwner(owner), iConnectionMonitor(connectionMonitor)
{
CActiveScheduler::Add(this);
}
AccessPointsAvailabilityScanner::~AccessPointsAvailabilityScanner()
{
Cancel();
}
void AccessPointsAvailabilityScanner::DoCancel()
{
iConnectionMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute);
}
void AccessPointsAvailabilityScanner::StartScanning()
{
if (iOwner.iFirstUpdate) {
// On first update (the mgr is being instantiated) update only those bearers who
// don't need time-consuming scans (WLAN).
// Note: EBearerIdWCDMA covers also GPRS bearer
iConnectionMonitor.GetPckgAttribute(EBearerIdWCDMA, 0, KIapAvailability, iIapBuf, iStatus);
} else {
iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus);
}
if (!IsActive())
SetActive();
}
void AccessPointsAvailabilityScanner::RunL()
{
QMutexLocker locker(&iOwner.mutex);
if (iStatus.Int() != KErrNone) {
iIapBuf().iCount = 0;
QT_TRYCATCH_LEAVING(iOwner.accessPointScanningReady(false,iIapBuf()));
} else {
QT_TRYCATCH_LEAVING(iOwner.accessPointScanningReady(true,iIapBuf()));
}
}
QT_END_NAMESPACE
#endif // QT_NO_BEARERMANAGEMENT
|