qtmobility/src/bearer/qnetworksession_s60_p.cpp
branchRCL_3
changeset 21 885c2596c964
parent 13 4203353e74ea
equal deleted inserted replaced
20:e2d33e235f7e 21:885c2596c964
    53 
    53 
    54 QNetworkSessionPrivate::QNetworkSessionPrivate()
    54 QNetworkSessionPrivate::QNetworkSessionPrivate()
    55     : CActive(CActive::EPriorityUserInput), state(QNetworkSession::Invalid),
    55     : CActive(CActive::EPriorityUserInput), state(QNetworkSession::Invalid),
    56       isOpen(false), iDynamicUnSetdefaultif(0), ipConnectionNotifier(0),
    56       isOpen(false), iDynamicUnSetdefaultif(0), ipConnectionNotifier(0),
    57       iHandleStateNotificationsFromManager(false), iFirstSync(true), iStoppedByUser(false),
    57       iHandleStateNotificationsFromManager(false), iFirstSync(true), iStoppedByUser(false),
    58       iClosedByUser(false), iDeprecatedConnectionId(0), iError(QNetworkSession::UnknownSessionError),
    58       iClosedByUser(false), iError(QNetworkSession::UnknownSessionError), iALREnabled(0),
    59       iALREnabled(0), iConnectInBackground(false)
    59       iConnectInBackground(false), isOpening(false)
    60 {
    60 {
    61     CActiveScheduler::Add(this);
    61     CActiveScheduler::Add(this);
    62 
    62 
    63 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
    63 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
    64     iMobility = NULL;
    64     iMobility = NULL;
    70         iDynamicUnSetdefaultif = (TOpenCUnSetdefaultifFunction)iOpenCLibrary.Lookup(597);
    70         iDynamicUnSetdefaultif = (TOpenCUnSetdefaultifFunction)iOpenCLibrary.Lookup(597);
    71     }
    71     }
    72 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
    72 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
    73     qDebug() << "QNS this : " << QString::number((uint)this) << " - ";
    73     qDebug() << "QNS this : " << QString::number((uint)this) << " - ";
    74     if (iDynamicUnSetdefaultif)
    74     if (iDynamicUnSetdefaultif)
    75         qDebug() << "dynamic setdefaultif() resolution succeeded. ";
    75         qDebug() << "dynamic unsetdefaultif() is present in PIPS library. ";
    76     else
    76     else
    77         qDebug() << "dynamic setdefaultif() resolution failed. ";
    77         qDebug() << "dynamic unsetdefaultif() not present in PIPS library. ";
    78 #endif
    78 #endif
    79 
    79 
    80     TRAP_IGNORE(iConnectionMonitor.ConnectL());
    80     TRAP_IGNORE(iConnectionMonitor.ConnectL());
    81 }
    81 }
    82 
    82 
    83 QNetworkSessionPrivate::~QNetworkSessionPrivate()
    83 QNetworkSessionPrivate::~QNetworkSessionPrivate()
    84 {
    84 {
    85     isOpen = false;
    85     isOpen = false;
       
    86     isOpening = false;
    86 
    87 
    87     // Cancel Connection Progress Notifications first.
    88     // Cancel Connection Progress Notifications first.
    88     // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start()
    89     // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start()
    89     //       => deleting ipConnectionNotifier results RConnection::CancelProgressNotification()
    90     //       => deleting ipConnectionNotifier results RConnection::CancelProgressNotification()
    90     delete ipConnectionNotifier;
    91     delete ipConnectionNotifier;
   105     // Clears also possible unsetdefaultif() flags.
   106     // Clears also possible unsetdefaultif() flags.
   106     setdefaultif(0);
   107     setdefaultif(0);
   107     
   108     
   108     iConnectionMonitor.Close();
   109     iConnectionMonitor.Close();
   109     iOpenCLibrary.Close();
   110     iOpenCLibrary.Close();
       
   111 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
       
   112     qDebug() << "QNS this : " << QString::number((uint)this) << " - destroyed (and setdefaultif(0))";
       
   113 #endif
   110 }
   114 }
   111 
   115 
   112 void QNetworkSessionPrivate::configurationStateChanged(TUint32 accessPointId, TUint32 connMonId, QNetworkSession::State newState)
   116 void QNetworkSessionPrivate::configurationStateChanged(TUint32 accessPointId, TUint32 connMonId, QNetworkSession::State newState)
   113 {
   117 {
   114     if (iHandleStateNotificationsFromManager) {
   118     if (iHandleStateNotificationsFromManager) {
   115 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   119 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   116         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   120         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   117                 << "configurationStateChanged from manager for IAP : " << QString::number(accessPointId)
   121                  << "configurationStateChanged from manager for IAP : " << QString::number(accessPointId)
   118                 << "configurationStateChanged connMon ID : " << QString::number(connMonId)
   122                  << "connMon ID : " << QString::number(connMonId) << " : to a state: " << newState
   119                 << " : to a state: " << newState
   123                  << "whereas my current state is: " << state;
   120                 << " whereas my current state is: " << state;
   124 #else
   121 #endif
   125       Q_UNUSED(connMonId);
   122         if (connMonId == iDeprecatedConnectionId) {
   126 #endif
   123 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
       
   124             qDebug() << "QNS this : " << QString::number((uint)this) << " - "
       
   125                     << "however status update from manager ignored because it related to already closed connection.";
       
   126 #endif
       
   127             return;
       
   128         }
       
   129         this->newState(newState, accessPointId);
   127         this->newState(newState, accessPointId);
   130     }
   128     }
   131 }
   129 }
   132 
   130 
   133 void QNetworkSessionPrivate::configurationRemoved(const QNetworkConfiguration& config)
   131 void QNetworkSessionPrivate::configurationRemoved(const QNetworkConfiguration& config)
   142 #endif
   140 #endif
   143         this->newState(QNetworkSession::Invalid, publicConfig.d.data()->numericId);
   141         this->newState(QNetworkSession::Invalid, publicConfig.d.data()->numericId);
   144     }
   142     }
   145 }
   143 }
   146 
   144 
       
   145 void QNetworkSessionPrivate::configurationAdded(const QNetworkConfiguration& config)
       
   146 {
       
   147     Q_UNUSED(config);
       
   148     // If session is based on service network, some other app may create new access points
       
   149     // to the SNAP --> synchronize session's state with that of interface's.
       
   150     if (!publicConfig.d.data() || publicConfig.type() != QNetworkConfiguration::ServiceNetwork) {
       
   151         return;
       
   152     }
       
   153 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
       
   154         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
       
   155                  << "configurationAdded IAP: " << QString::number(config.d.data()->numericId);
       
   156 #endif
       
   157         syncStateWithInterface();
       
   158 }
       
   159 
       
   160 // Function sets the state of the session to match the state
       
   161 // of the underlying interface (the configuration this session is based on)
   147 void QNetworkSessionPrivate::syncStateWithInterface()
   162 void QNetworkSessionPrivate::syncStateWithInterface()
   148 {
   163 {
   149     if (!publicConfig.d) {
   164     if (!publicConfig.d || !publicConfig.d.data()) {
   150         return;
   165         return;
   151     }
   166     }
   152 
   167     if (iFirstSync) {
   153     if (iFirstSync && publicConfig.d.data()) {
       
   154         QObject::connect(((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager), SIGNAL(configurationStateChanged(TUint32, TUint32, QNetworkSession::State)),
   168         QObject::connect(((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager), SIGNAL(configurationStateChanged(TUint32, TUint32, QNetworkSession::State)),
   155                          this, SLOT(configurationStateChanged(TUint32, TUint32, QNetworkSession::State)));
   169                          this, SLOT(configurationStateChanged(TUint32, TUint32, QNetworkSession::State)));
   156         // Listen to configuration removals, so that in case the configuration
   170         // Listen to configuration removals, so that in case the configuration
   157         // this session is based on is removed, session knows to enter Invalid -state.
   171         // this session is based on is removed, session knows to enter Invalid -state.
   158         QObject::connect(((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager),
   172         QObject::connect(((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager),
   159                          SIGNAL(configurationRemoved(QNetworkConfiguration)),
   173                          SIGNAL(configurationRemoved(QNetworkConfiguration)),
   160                          this, SLOT(configurationRemoved(QNetworkConfiguration)));
   174                          this, SLOT(configurationRemoved(QNetworkConfiguration)));
       
   175         // Connect to configuration additions, so that in case a configuration is added
       
   176         // in a SNAP this session is based on, the session knows to synch its state with its
       
   177         // interface.
       
   178         QObject::connect(((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager),
       
   179                          SIGNAL(configurationAdded(QNetworkConfiguration)),
       
   180                          this, SLOT(configurationAdded(QNetworkConfiguration)));
   161     }
   181     }
   162     // Start listening IAP state changes from QNetworkConfigurationManagerPrivate
   182     // Start listening IAP state changes from QNetworkConfigurationManagerPrivate
   163     iHandleStateNotificationsFromManager = true;    
   183     iHandleStateNotificationsFromManager = true;    
   164 
   184 
   165     // Check open connections to see if there is already
   185     // Check what is the state of the configuration this session is based on
   166     // an open connection to selected IAP or SNAP
   186     // and set the session in appropriate state.
   167     TUint count;
   187 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   168     TRequestStatus status;
   188     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   169     iConnectionMonitor.GetConnectionCount(count, status);
   189              << "syncStateWithInterface() state of publicConfig is: " << publicConfig.d.data()->state;
   170     User::WaitForRequest(status);
   190 #endif
   171     if (status.Int() != KErrNone) {
   191     switch (publicConfig.d.data()->state) {
   172         return;
   192     case QNetworkConfiguration::Active:
   173     }
   193         newState(QNetworkSession::Connected);
   174 
   194         break;
   175     TUint numSubConnections;
   195     case QNetworkConfiguration::Discovered:
   176     TUint connectionId;
   196         newState(QNetworkSession::Disconnected);
   177     for (TUint i = 1; i <= count; i++) {
   197         break;
   178         TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections);
   198     case QNetworkConfiguration::Defined:
   179         if (ret == KErrNone) {
   199         newState(QNetworkSession::NotAvailable);
   180             TUint apId;
   200         break;
   181             iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status);
   201     case QNetworkConfiguration::Undefined:
   182             User::WaitForRequest(status);
   202     default:
   183             if (status.Int() == KErrNone) {
   203         newState(QNetworkSession::Invalid);
   184                 TInt connectionStatus;
       
   185                 iConnectionMonitor.GetIntAttribute(connectionId, 0, KConnectionStatus, connectionStatus, status);
       
   186                 User::WaitForRequest(status);
       
   187                 if (connectionStatus == KLinkLayerOpen) {
       
   188                     if (state != QNetworkSession::Closing) {
       
   189                         if (newState(QNetworkSession::Connected, apId)) {
       
   190                             return;
       
   191                         }
       
   192                     }
       
   193                 }
       
   194             }
       
   195         }
       
   196     }
       
   197 
       
   198     if (state != QNetworkSession::Connected) {
       
   199         if ((publicConfig.d.data()->state & QNetworkConfiguration::Discovered) ==
       
   200             QNetworkConfiguration::Discovered) {
       
   201             newState(QNetworkSession::Disconnected);
       
   202         } else {
       
   203             newState(QNetworkSession::NotAvailable);
       
   204         }
       
   205     }
   204     }
   206 }
   205 }
   207 
   206 
   208 QNetworkInterface QNetworkSessionPrivate::interface(TUint iapId) const
   207 QNetworkInterface QNetworkSessionPrivate::interface(TUint iapId) const
   209 {
   208 {
   243     return QNetworkInterface::interfaceFromName(interfaceName);
   242     return QNetworkInterface::interfaceFromName(interfaceName);
   244 }
   243 }
   245 
   244 
   246 QNetworkInterface QNetworkSessionPrivate::currentInterface() const
   245 QNetworkInterface QNetworkSessionPrivate::currentInterface() const
   247 {
   246 {
       
   247 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
       
   248     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
       
   249              << "currentInterface() requested, state: " << state
       
   250              << "publicConfig validity: " << publicConfig.isValid();
       
   251     if (activeInterface.isValid())
       
   252         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
       
   253                  << "interface is: " << activeInterface.humanReadableName();
       
   254 #endif
       
   255 
   248     if (!publicConfig.isValid() || state != QNetworkSession::Connected) {
   256     if (!publicConfig.isValid() || state != QNetworkSession::Connected) {
   249         return QNetworkInterface();
   257         return QNetworkInterface();
   250     }
   258     }
   251     
   259     
   252     return activeInterface;
   260     return activeInterface;
   300 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   308 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   301         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   309         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   302                 << "open() called, session state is: " << state << " and isOpen is: "
   310                 << "open() called, session state is: " << state << " and isOpen is: "
   303                 << isOpen;
   311                 << isOpen;
   304 #endif
   312 #endif
   305     if (isOpen || (state == QNetworkSession::Connecting)) {
   313     if (isOpen || isOpening)
   306         return;
   314         return;
   307     }
   315     
   308     
   316     isOpening = true;
       
   317 
   309     // Stop handling IAP state change signals from QNetworkConfigurationManagerPrivate
   318     // Stop handling IAP state change signals from QNetworkConfigurationManagerPrivate
   310     // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring
   319     // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring
   311     iHandleStateNotificationsFromManager = false;
   320     iHandleStateNotificationsFromManager = false;
   312 
   321 
   313     // Configuration may have been invalidated after session creation by platform
   322     // Configuration may have been invalidated after session creation by platform
   331         return;
   340         return;
   332     }
   341     }
   333     // Clear possible previous states
   342     // Clear possible previous states
   334     iStoppedByUser = false;
   343     iStoppedByUser = false;
   335     iClosedByUser = false;
   344     iClosedByUser = false;
   336     iDeprecatedConnectionId = 0;
       
   337 
   345 
   338     TInt error = iSocketServ.Connect();
   346     TInt error = iSocketServ.Connect();
   339     if (error != KErrNone) {
   347     if (error != KErrNone) {
   340         // Could not open RSocketServ
   348         // Could not open RSocketServ
   341         newState(QNetworkSession::Invalid);
   349         newState(QNetworkSession::Invalid);
   364     if (ipConnectionNotifier) {
   372     if (ipConnectionNotifier) {
   365         ipConnectionNotifier->StartNotifications();
   373         ipConnectionNotifier->StartNotifications();
   366     }
   374     }
   367     
   375     
   368     if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) {
   376     if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) {
   369 #ifdef OCC_FUNCTIONALITY_AVAILABLE
   377 #if defined(OCC_FUNCTIONALITY_AVAILABLE) && defined(SNAP_FUNCTIONALITY_AVAILABLE)
   370             // With One Click Connectivity (Symbian^3 onwards) it is possible
   378             // With One Click Connectivity (Symbian^3 onwards) it is possible
   371             // to connect silently, without any popups.
   379             // to connect silently, without any popups.
   372             TConnPrefList pref;
   380             TConnPrefList pref;
   373             TExtendedConnPref prefs;
   381             TExtendedConnPref prefs;
   374             prefs.SetIapId(publicConfig.d.data()->numericId);
   382             prefs.SetIapId(publicConfig.d.data()->numericId);
   383 #endif
   391 #endif
   384             iConnection.Start(pref, iStatus);
   392             iConnection.Start(pref, iStatus);
   385             if (!IsActive()) {
   393             if (!IsActive()) {
   386                 SetActive();
   394                 SetActive();
   387             }
   395             }
   388             newState(QNetworkSession::Connecting);
   396             // Avoid flip flop of states if the configuration is already
       
   397             // active. IsOpen/opened() will indicate when ready.
       
   398             if (state != QNetworkSession::Connected) {
       
   399                 newState(QNetworkSession::Connecting);
       
   400             }
   389     } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
   401     } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
   390 #ifdef OCC_FUNCTIONALITY_AVAILABLE
   402 #if defined(OCC_FUNCTIONALITY_AVAILABLE) && defined(SNAP_FUNCTIONALITY_AVAILABLE)
   391         // On Symbian^3 if service network is not reachable, it triggers a UI (aka EasyWLAN) where
   403         // On Symbian^3 if service network is not reachable, it triggers a UI (aka EasyWLAN) where
   392         // user can create new IAPs. To detect this, we need to store the number of IAPs
   404         // user can create new IAPs. To detect this, we need to store the number of IAPs
   393         // there was before connection was started.
   405         // there was before connection was started.
   394         iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys();
   406         iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys();
   395         TConnPrefList snapPref;
   407         TConnPrefList snapPref;
   404 #endif
   416 #endif
   405         iConnection.Start(snapPref, iStatus);
   417         iConnection.Start(snapPref, iStatus);
   406         if (!IsActive()) {
   418         if (!IsActive()) {
   407             SetActive();
   419             SetActive();
   408         }
   420         }
   409         newState(QNetworkSession::Connecting);
   421         // Avoid flip flop of states if the configuration is already
       
   422         // active. IsOpen/opened() will indicate when ready.
       
   423         if (state != QNetworkSession::Connected) {
       
   424             newState(QNetworkSession::Connecting);
       
   425         }
   410     } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) {
   426     } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) {
   411         iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys();
   427         iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys();
   412         iConnection.Start(iStatus);
   428         iConnection.Start(iStatus);
   413         if (!IsActive()) {
   429         if (!IsActive()) {
   414             SetActive();
   430             SetActive();
   416         newState(QNetworkSession::Connecting);
   432         newState(QNetworkSession::Connecting);
   417     }
   433     }
   418  
   434  
   419     if (error != KErrNone) {
   435     if (error != KErrNone) {
   420         isOpen = false;
   436         isOpen = false;
       
   437         isOpening = false;
   421         iError = QNetworkSession::UnknownSessionError;
   438         iError = QNetworkSession::UnknownSessionError;
   422         emit q->error(iError);
   439         emit q->error(iError);
   423         if (ipConnectionNotifier) {
   440         if (ipConnectionNotifier) {
   424             ipConnectionNotifier->StopNotifications();
   441             ipConnectionNotifier->StopNotifications();
   425         }
   442         }
   468     // Mark this session as closed-by-user so that we are able to report
   485     // Mark this session as closed-by-user so that we are able to report
   469     // distinguish between stop() and close() state transitions
   486     // distinguish between stop() and close() state transitions
   470     // when reporting.
   487     // when reporting.
   471     iClosedByUser = true;
   488     iClosedByUser = true;
   472     isOpen = false;
   489     isOpen = false;
   473 
   490     isOpening = false;
   474 #ifndef OCC_FUNCTIONALITY_AVAILABLE
   491 
   475     // On Symbian^3 we need to keep track of active configuration longer
       
   476     // in case of empty-SNAP-triggered EasyWLAN.
       
   477     activeConfig = QNetworkConfiguration();
       
   478 #endif
       
   479     serviceConfig = QNetworkConfiguration();
   492     serviceConfig = QNetworkConfiguration();
   480     
   493     
   481 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   494 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   482     if (iMobility) {
   495     if (iMobility) {
   483         delete iMobility;
   496         delete iMobility;
   510     // KFinishedSelection event, and hence reports only after that event, but
   523     // KFinishedSelection event, and hence reports only after that event, but
   511     // that does not seem to be trusted on all Symbian versions --> safest
   524     // that does not seem to be trusted on all Symbian versions --> safest
   512     // to go down.
   525     // to go down.
   513     if (publicConfig.type() == QNetworkConfiguration::UserChoice || state == QNetworkSession::Connecting) {
   526     if (publicConfig.type() == QNetworkConfiguration::UserChoice || state == QNetworkSession::Connecting) {
   514 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   527 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   515     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   528         qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   516             << "going Disconnected right away. Deprecating connection monitor ID: " << publicConfig.d.data()->connectionId;
   529                  << "going disconnected right away, since either UserChoice or Connecting";
   517 #endif
   530 #endif
   518 
       
   519         // The connection has gone down, and processing of status updates must be
       
   520         // stopped. Depending on platform, there may come 'connecting/connected' states
       
   521         // considerably later (almost a second). Connection id is an increasing
       
   522         // number, so this does not affect next _real_ 'conneting/connected' states.
       
   523         iDeprecatedConnectionId = publicConfig.d.data()->connectionId;
       
   524         newState(QNetworkSession::Closing);
   531         newState(QNetworkSession::Closing);
   525         newState(QNetworkSession::Disconnected);
   532         newState(QNetworkSession::Disconnected);
   526     }
   533     }
   527     if (allowSignals) {
   534     if (allowSignals) {
   528         emit q->closed();
   535         emit q->closed();
   579     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   586     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   580             << "since session is open, using RConnection to stop() the interface";
   587             << "since session is open, using RConnection to stop() the interface";
   581 #endif
   588 #endif
   582         // Since we are open, use RConnection to stop the interface
   589         // Since we are open, use RConnection to stop the interface
   583         isOpen = false;
   590         isOpen = false;
       
   591         isOpening = false;
   584         iStoppedByUser = true;
   592         iStoppedByUser = true;
   585         newState(QNetworkSession::Closing);
   593         newState(QNetworkSession::Closing);
   586         if (ipConnectionNotifier) {
   594         if (ipConnectionNotifier) {
   587             ipConnectionNotifier->StopNotifications();
   595             ipConnectionNotifier->StopNotifications();
   588             // Start handling IAP state change signals from QNetworkConfigurationManagerPrivate
   596             // Start handling IAP state change signals from QNetworkConfigurationManagerPrivate
   589             iHandleStateNotificationsFromManager = true;
   597             iHandleStateNotificationsFromManager = true;
   590         }
   598         }
   591         iConnection.Stop(RConnection::EStopAuthoritative);
   599         iConnection.Stop(RConnection::EStopAuthoritative);
   592         isOpen = true;
   600         isOpen = true;
       
   601         isOpening = false;
   593         close(false);
   602         close(false);
   594         emit q->closed();
   603         emit q->closed();
   595     }
   604     }
   596 }
   605 }
   597 
   606 
   719     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   728     qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   720             << "roaming Error() occured, isOpen is: " << isOpen;
   729             << "roaming Error() occured, isOpen is: " << isOpen;
   721 #endif
   730 #endif
   722     if (isOpen) {
   731     if (isOpen) {
   723         isOpen = false;
   732         isOpen = false;
       
   733         isOpening = false;
   724         activeConfig = QNetworkConfiguration();
   734         activeConfig = QNetworkConfiguration();
   725         serviceConfig = QNetworkConfiguration();
   735         serviceConfig = QNetworkConfiguration();
   726         iError = QNetworkSession::RoamingError;
   736         iError = QNetworkSession::RoamingError;
   727         emit q->error(iError);
   737         emit q->error(iError);
   728         Cancel();
   738         Cancel();
   868 QNetworkConfiguration QNetworkSessionPrivate::activeConfiguration(TUint32 iapId) const
   878 QNetworkConfiguration QNetworkSessionPrivate::activeConfiguration(TUint32 iapId) const
   869 {
   879 {
   870     if (iapId == 0) {
   880     if (iapId == 0) {
   871         _LIT(KSetting, "IAP\\Id");
   881         _LIT(KSetting, "IAP\\Id");
   872         iConnection.GetIntSetting(KSetting, iapId);
   882         iConnection.GetIntSetting(KSetting, iapId);
       
   883 #if defined(OCC_FUNCTIONALITY_AVAILABLE) && defined(SNAP_FUNCTIONALITY_AVAILABLE)
       
   884         // Check if this is an Easy WLAN configuration. On Symbian^3 RConnection may report
       
   885         // the used configuration as 'EasyWLAN' IAP ID if someone has just opened the configuration
       
   886         // from WLAN Scan dialog, _and_ that connection is still up. We need to find the
       
   887         // real matching configuration. Function alters the Easy WLAN ID to real IAP ID (only if easy WLAN):
       
   888         ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->easyWlanTrueIapId(iapId);
       
   889 #endif
   873     }
   890     }
   874 
   891 
   875 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   892 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   876     if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
   893     if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
   877         // Try to search IAP from the used SNAP using IAP Id
   894         // Try to search IAP from the used SNAP using IAP Id
   898                 if (children[i].d.data()->mappingName == pt.d.data()->mappingName) {
   915                 if (children[i].d.data()->mappingName == pt.d.data()->mappingName) {
   899                     return children[i];
   916                     return children[i];
   900                 }
   917                 }
   901             }
   918             }
   902         } else {
   919         } else {
   903 #ifdef OCC_FUNCTIONALITY_AVAILABLE
   920 #if defined(OCC_FUNCTIONALITY_AVAILABLE) && defined(SNAP_FUNCTIONALITY_AVAILABLE)
   904             // On Symbian^3 (only, not earlier or Symbian^4) if the SNAP was not reachable, it triggers
   921             // On Symbian^3 (only, not earlier or Symbian^4) if the SNAP was not reachable, it triggers
   905             // user choice type of activity (EasyWLAN). As a result, a new IAP may be created, and
   922             // user choice type of activity (EasyWLAN). As a result, a new IAP may be created, and
   906             // hence if was not found yet. Therefore update configurations and see if there is something new.
   923             // hence if was not found yet. Therefore update configurations and see if there is something new.
   907             // 1. Update knowledge from the databases.
   924             // 1. Update knowledge from the databases.
   908             ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->updateConfigurations();
   925             ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->updateConfigurations();
   936             }
   953             }
   937 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   954 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
   938             qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   955             qDebug() << "QNS this : " << QString::number((uint)this) << " - "
   939                     << "configuration was not found, returning invalid.";
   956                     << "configuration was not found, returning invalid.";
   940 #endif
   957 #endif
   941 #endif // OCC_FUNCTIONALITY_AVAILABLE
   958 #endif
   942             // Given IAP Id was not found from known IAPs array
   959             // Given IAP Id was not found from known IAPs array
   943             return QNetworkConfiguration();
   960             return QNetworkConfiguration();
   944         }
   961         }
   945         // Matching IAP was not found from used SNAP
   962         // Matching IAP was not found from used SNAP
   946         // => IAP from another SNAP is returned
   963         // => IAP from another SNAP is returned
   999         case KErrNone: // Connection created successfully
  1016         case KErrNone: // Connection created successfully
  1000             {
  1017             {
  1001             TInt error = KErrNone;
  1018             TInt error = KErrNone;
  1002             QNetworkConfiguration newActiveConfig = activeConfiguration();
  1019             QNetworkConfiguration newActiveConfig = activeConfiguration();
  1003             if (!newActiveConfig.isValid()) {
  1020             if (!newActiveConfig.isValid()) {
       
  1021                 // RConnection startup was successfull but no configuration
       
  1022                 // was found. That indicates that user has chosen to create a
       
  1023                 // new WLAN configuration (from scan results), but that new
       
  1024                 // configuration does not have access to Internet (Internet
       
  1025                 // Connectivity Test, ICT, failed).
  1004                 error = KErrGeneral;
  1026                 error = KErrGeneral;
  1005             } else {
  1027             } else {
  1006                 // Use name of the IAP to open global 'Open C' RConnection
  1028                 // Use name of the IAP to open global 'Open C' RConnection
  1007                 ifreq ifr;
  1029                 ifreq ifr;
  1008                 memset(&ifr, 0, sizeof(struct ifreq));
  1030                 memset(&ifr, 0, sizeof(struct ifreq));
  1009                 QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
  1031                 QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
  1010                 strcpy(ifr.ifr_name, nameAsByteArray.constData());
  1032                 strcpy(ifr.ifr_name, nameAsByteArray.constData());
  1011                 error = setdefaultif(&ifr);
  1033                 error = setdefaultif(&ifr);
  1012             }
  1034             }
  1013             
       
  1014             if (error != KErrNone) {
  1035             if (error != KErrNone) {
  1015                 isOpen = false;
  1036                 isOpen = false;
       
  1037                 isOpening = false;
  1016                 iError = QNetworkSession::UnknownSessionError;
  1038                 iError = QNetworkSession::UnknownSessionError;
  1017                 QT_TRYCATCH_LEAVING(emit q->error(iError));
  1039                 QT_TRYCATCH_LEAVING(emit q->error(iError));
  1018                 Cancel();
       
  1019                 if (ipConnectionNotifier) {
  1040                 if (ipConnectionNotifier) {
  1020                     ipConnectionNotifier->StopNotifications();
  1041                     ipConnectionNotifier->StopNotifications();
       
  1042                 }
       
  1043                 if (!newActiveConfig.isValid()) {
       
  1044                     // No valid configuration, bail out.
       
  1045                     // Status updates from QNCM won't be received correctly
       
  1046                     // because there is no configuration to associate them with so transit here.
       
  1047                     iConnection.Close();
       
  1048                     newState(QNetworkSession::Closing);
       
  1049                     newState(QNetworkSession::Disconnected);
       
  1050                 } else {
       
  1051                     Cancel();
  1021                 }
  1052                 }
  1022                 QT_TRYCATCH_LEAVING(syncStateWithInterface());
  1053                 QT_TRYCATCH_LEAVING(syncStateWithInterface());
  1023                 return;
  1054                 return;
  1024             }
  1055             }
  1025  
  1056  
  1028                 // Activate ALR monitoring
  1059                 // Activate ALR monitoring
  1029                 iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this);
  1060                 iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this);
  1030             }
  1061             }
  1031 #endif
  1062 #endif
  1032             isOpen = true;
  1063             isOpen = true;
       
  1064             isOpening = false;
  1033             activeConfig = newActiveConfig;
  1065             activeConfig = newActiveConfig;
  1034             activeInterface = interface(activeConfig.d.data()->numericId);
  1066             activeInterface = interface(activeConfig.d.data()->numericId);
  1035             if (publicConfig.type() == QNetworkConfiguration::UserChoice) {
  1067             if (publicConfig.type() == QNetworkConfiguration::UserChoice) {
  1036                 QNetworkConfiguration pt;
  1068                 QNetworkConfiguration pt;
  1037                 pt.d = activeConfig.d.data()->serviceNetworkPtr;
  1069                 pt.d = activeConfig.d.data()->serviceNetworkPtr;
  1046                 });
  1078                 });
  1047             }
  1079             }
  1048             break;
  1080             break;
  1049         case KErrNotFound: // Connection failed
  1081         case KErrNotFound: // Connection failed
  1050             isOpen = false;
  1082             isOpen = false;
       
  1083             isOpening = false;
  1051             activeConfig = QNetworkConfiguration();
  1084             activeConfig = QNetworkConfiguration();
  1052             serviceConfig = QNetworkConfiguration();
  1085             serviceConfig = QNetworkConfiguration();
  1053             iError = QNetworkSession::InvalidConfigurationError;
  1086             iError = QNetworkSession::InvalidConfigurationError;
  1054             QT_TRYCATCH_LEAVING(emit q->error(iError));
  1087             QT_TRYCATCH_LEAVING(emit q->error(iError));
  1055             Cancel();
  1088             Cancel();
  1060             break;
  1093             break;
  1061         case KErrCancel: // Connection attempt cancelled
  1094         case KErrCancel: // Connection attempt cancelled
  1062         case KErrAlreadyExists: // Connection already exists
  1095         case KErrAlreadyExists: // Connection already exists
  1063         default:
  1096         default:
  1064             isOpen = false;
  1097             isOpen = false;
       
  1098             isOpening = false;
  1065             activeConfig = QNetworkConfiguration();
  1099             activeConfig = QNetworkConfiguration();
  1066             serviceConfig = QNetworkConfiguration();
  1100             serviceConfig = QNetworkConfiguration();
  1067             if (publicConfig.state() == QNetworkConfiguration::Undefined ||
  1101             if (statusCode == KErrCancel) {
       
  1102                 iError = QNetworkSession::SessionAbortedError;
       
  1103             } else if (publicConfig.state() == QNetworkConfiguration::Undefined ||
  1068                 publicConfig.state() == QNetworkConfiguration::Defined) {
  1104                 publicConfig.state() == QNetworkConfiguration::Defined) {
  1069                 iError = QNetworkSession::InvalidConfigurationError;
  1105                 iError = QNetworkSession::InvalidConfigurationError;
  1070             } else {
  1106             } else {
  1071                 iError = QNetworkSession::UnknownSessionError;
  1107                 iError = QNetworkSession::UnknownSessionError;
  1072             }
  1108             }
  1122     }
  1158     }
  1123 
  1159 
  1124     // Make sure that some lagging 'closing' state-changes do not overwrite
  1160     // Make sure that some lagging 'closing' state-changes do not overwrite
  1125     // if we are already disconnected or closed.
  1161     // if we are already disconnected or closed.
  1126     if (state == QNetworkSession::Disconnected && newState == QNetworkSession::Closing) {
  1162     if (state == QNetworkSession::Disconnected && newState == QNetworkSession::Closing) {
       
  1163         return false;
       
  1164     }
       
  1165 
       
  1166     // Make sure that some lagging 'connecting' state-changes do not overwrite
       
  1167     // if we are already connected (may righfully still happen with roaming though).
       
  1168     if (state == QNetworkSession::Connected && newState == QNetworkSession::Connecting) {
  1127         return false;
  1169         return false;
  1128     }
  1170     }
  1129 
  1171 
  1130     bool emitSessionClosed = false;
  1172     bool emitSessionClosed = false;
  1131 
  1173 
  1138         // Active & Connected state should change directly to Disconnected state
  1180         // Active & Connected state should change directly to Disconnected state
  1139         // only when something forces connection to close (eg. when another
  1181         // only when something forces connection to close (eg. when another
  1140         // application or session stops connection or when network drops
  1182         // application or session stops connection or when network drops
  1141         // unexpectedly).
  1183         // unexpectedly).
  1142         isOpen = false;
  1184         isOpen = false;
       
  1185         isOpening = false;
  1143         activeConfig = QNetworkConfiguration();
  1186         activeConfig = QNetworkConfiguration();
  1144         serviceConfig = QNetworkConfiguration();
  1187         serviceConfig = QNetworkConfiguration();
  1145         iError = QNetworkSession::SessionAbortedError;
  1188         iError = QNetworkSession::SessionAbortedError;
  1146         emit q->error(iError);
  1189         emit q->error(iError);
  1147         Cancel();
  1190         Cancel();
  1214 #endif
  1257 #endif
  1215                         }
  1258                         }
  1216                     }
  1259                     }
  1217                 }
  1260                 }
  1218             }
  1261             }
  1219 #ifdef OCC_FUNCTIONALITY_AVAILABLE
  1262 #if defined(OCC_FUNCTIONALITY_AVAILABLE) && defined(SNAP_FUNCTIONALITY_AVAILABLE)
  1220             // If the retVal is not true here, it means that the status update may apply to an IAP outside of
  1263             // If the retVal is not true here, it means that the status update may apply to an IAP outside of
  1221             // SNAP (session is based on SNAP but follows IAP outside of it), which may occur on Symbian^3 EasyWlan.
  1264             // SNAP (session is based on SNAP but follows IAP outside of it), which may occur on Symbian^3 EasyWlan.
  1222             if (retVal == false && activeConfig.d.data() && activeConfig.d.data()->numericId == accessPointId) {
  1265             if (retVal == false && activeConfig.d.data() && activeConfig.d.data()->numericId == accessPointId) {
  1223 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
  1266 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG
  1224                 qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "===> EMIT State changed G  to: " << state;
  1267                 qDebug() << "QNS this : " << QString::number((uint)this) << " - " << "===> EMIT State changed G  to: " << state;
  1231                 retVal = true;
  1274                 retVal = true;
  1232             }
  1275             }
  1233 #endif
  1276 #endif
  1234         }
  1277         }
  1235     }
  1278     }
  1236     
       
  1237     if (emitSessionClosed) {
  1279     if (emitSessionClosed) {
  1238         emit q->closed();
  1280         emit q->closed();
  1239     }
  1281     }
  1240     if (state == QNetworkSession::Disconnected) {
  1282     if (state == QNetworkSession::Disconnected) {
  1241         // The connection has gone down, and processing of status updates must be
       
  1242         // stopped. Depending on platform, there may come 'connecting/connected' states
       
  1243         // considerably later (almost a second). Connection id is an increasing
       
  1244         // number, so this does not affect next _real_ 'conneting/connected' states.
       
  1245         iDeprecatedConnectionId = publicConfig.d.data()->connectionId;
       
  1246 #ifdef OCC_FUNCTIONALITY_AVAILABLE
       
  1247         // Just in case clear activeConfiguration.
  1283         // Just in case clear activeConfiguration.
  1248         activeConfig = QNetworkConfiguration();
  1284         activeConfig = QNetworkConfiguration();
  1249 #endif
       
  1250     }
  1285     }
  1251     return retVal;
  1286     return retVal;
  1252 }
  1287 }
  1253 
  1288 
  1254 void QNetworkSessionPrivate::handleSymbianConnectionStatusChange(TInt aConnectionStatus,
  1289 void QNetworkSessionPrivate::handleSymbianConnectionStatusChange(TInt aConnectionStatus,