hotspotfw/hsserver/src/hotspotsession.cpp
changeset 19 10810c91db26
parent 3 ff3b37722600
child 22 498f36116140
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
   146 // ----------------------------------------------------------------------------------------
   146 // ----------------------------------------------------------------------------------------
   147 //
   147 //
   148 void CHotSpotSession::DispatchMessageL( const RMessage2& aMessage )
   148 void CHotSpotSession::DispatchMessageL( const RMessage2& aMessage )
   149     {
   149     {
   150     DEBUG( "CHotSpotSession::DispatchMessageL()" );
   150     DEBUG( "CHotSpotSession::DispatchMessageL()" );
   151     TUint value1(NULL);
   151     TInt value( NULL );
   152     TInt value2(NULL);
   152     TInt err( KErrNone );
   153     TInt err(KErrNone);
   153     TInt indx( KErrNone );
   154     TInt indx(KErrNone);
       
   155     TPckgBuf<TInt> iapPackage( iIapId );
   154     TPckgBuf<TInt> iapPackage( iIapId );
   156     
   155     
   157     switch ( aMessage.Function() )
   156     switch ( aMessage.Function() )
   158         {
   157         {
   159         case EHssActivateNotifications :
   158         case EHssActivateNotifications :
       
   159             DEBUG( "CHotSpotSession::ActivateNotificationsL" );
   160             iAllowNotifications = EFalse;
   160             iAllowNotifications = EFalse;
   161             DEBUG( "CHotSpotSession::ActivateNotificationsL" );
   161             
   162             if ( iNotifications == NULL )
   162             if ( iNotifications == NULL )
   163                 {
   163                 {
   164                 DEBUG( "CHotSpotSession::DispatchMessageL activated !!!" );
   164                 iNotifications = new ( ELeave ) HssNotifications( *this );
   165                 iNotifications = new (ELeave) HssNotifications(*this);
       
   166                 iMgtClient->ActivateNotificationsL( *iNotifications );
   165                 iMgtClient->ActivateNotificationsL( *iNotifications );
   167                 }
   166                 }
   168             HandleOrderNotifications( aMessage );
   167             HandleOrderNotifications( aMessage );
   169             break;
   168             break;
   170         case EHssCancelNotifications :
   169         case EHssCancelNotifications :
       
   170             DEBUG( "CHotSpotSession::CancelNotifications" );
   171             iAllowNotifications = EFalse;
   171             iAllowNotifications = EFalse;
   172             DEBUG( "CHotSpotSession::CancelNotifications" );
       
   173             iMgtClient->CancelNotifications( );
   172             iMgtClient->CancelNotifications( );
       
   173         
   174             if ( iNotifications != NULL )
   174             if ( iNotifications != NULL )
   175                 {
   175                 {
   176                 delete iNotifications;
   176                 delete iNotifications;
   177                 }
   177                 }
   178             iNotifications = NULL;
   178             iNotifications = NULL;
   179             HandleCancelNotifications( aMessage );
   179             HandleCancelNotifications( aMessage );
   180             break;
   180             break;
   181         case EHssGetScanResults :
       
   182             // Handled now in client side. Left here for future use.
       
   183             break;
       
   184         case EHssRegister :
   181         case EHssRegister :
   185             ProcessRegisterL( aMessage );
   182             ProcessRegisterL( aMessage );
   186             break;
   183             break;
   187         case EHssUnRegister :
   184         case EHssUnRegister :
   188             ProcessUnRegisterL( aMessage );
   185             ProcessUnRegisterL( aMessage );
   189             break;
   186             break;
   190         case EHssJoin :
   187         case EHssJoin :
   191             iAllowNotifications = EFalse;
   188             iAllowNotifications = EFalse;
   192             // IAP id
   189             iIapId = ( TInt )aMessage.Int0();
   193             value1 = ( TInt )aMessage.Int0();
   190      
   194             iIapId = value1;
   191             indx = iServer.FindMessage( iIapId, EHssStart );
   195             indx = iServer.FindMessage(value1, EHssStart );
       
   196             if ( indx >= 0 )
   192             if ( indx >= 0 )
   197                 {
   193                 {
   198                 iServer.CompleteMessage( indx , KErrNone );
   194                 iServer.CompleteMessage( indx , KErrNone );
   199                 }
   195                 }
   200             else
   196             else
   201                 {
   197                 {
   202                 indx = iServer.FindMessage(value1, EHssStartAgain );
   198                 indx = iServer.FindMessage( iIapId, EHssStartAgain );
   203                 if ( indx >= 0 )
   199                 if ( indx >= 0 )
   204                     {
   200                     {
   205                     iServer.CompleteMessage( indx , KErrNone );
   201                     iServer.CompleteMessage( indx , KErrNone );
   206                     }
   202                     }
   207                 }
   203                 }
   209             break;
   205             break;
   210         case EHssCancelStart :
   206         case EHssCancelStart :
   211             iServer.SetLogoutFlag( ETrue );
   207             iServer.SetLogoutFlag( ETrue );
   212             // Do not send association status to client
   208             // Do not send association status to client
   213             iServer.SetAssociationFlag( EFalse ); 
   209             iServer.SetAssociationFlag( EFalse ); 
   214              // IAP id
       
   215             iIapId = ( TInt )aMessage.Int0();
   210             iIapId = ( TInt )aMessage.Int0();
       
   211     
   216             indx = iServer.FindMessage(iIapId, EHssStart );
   212             indx = iServer.FindMessage(iIapId, EHssStart );
   217             if ( indx >= 0 )
   213             if ( indx >= 0 )
   218                 {
   214                 {
   219                 iServer.CompleteMessage( indx , KErrAbort);
   215                 iServer.CompleteMessage( indx , KErrAbort);
   220                 }
   216                 }
   224                 if ( indx >= 0 )
   220                 if ( indx >= 0 )
   225                     {
   221                     {
   226                     iServer.CompleteMessage( indx , KErrAbort );
   222                     iServer.CompleteMessage( indx , KErrAbort );
   227                     }
   223                     }
   228                 }
   224                 }
   229             
       
   230             aMessage.Complete( KErrNone );
   225             aMessage.Complete( KErrNone );
   231             break;
   226             break;
   232         case EHssStop :
   227         case EHssStop :
   233             iAllowNotifications = EFalse;
   228             iAllowNotifications = EFalse;
   234             iServer.SetLogoutFlag( ETrue );
   229             iServer.SetLogoutFlag( ETrue );
   235                    
       
   236             iLoginTimer->Cancel();
   230             iLoginTimer->Cancel();
   237             iLogoutTimer->Cancel();
   231             iLogoutTimer->Cancel();
   238             // IAP id
   232             iIapId = ( TInt )aMessage.Int0();
   239             value1 = ( TInt )aMessage.Int0();
   233     
   240             for (TInt counter = EHssGetScanResults; counter <EHssServerShutdown ;counter++)
   234             for ( TInt counter = EHssGetScanResults; 
   241                 {
   235                   counter <EHssServerShutdown ;counter++ )
   242                 indx = iServer.FindMessage(value1, THotSpotCommands(counter ));
   236                 {
       
   237                 indx = iServer.FindMessage( iIapId, 
       
   238                                             THotSpotCommands( counter ) );
   243                 if ( indx >= 0 )
   239                 if ( indx >= 0 )
   244                     {
   240                     {
   245                     iServer.CompleteMessage( indx , KErrCancel);
   241                     iServer.CompleteMessage( indx , KErrCancel );
   246                     }
   242                     }
   247                 }
   243                 }
   248                         
       
   249             aMessage.Complete( KErrNone );
   244             aMessage.Complete( KErrNone );
   250             break;
   245             break;
   251         case EHssLoginComplete :
   246         case EHssLoginComplete :
   252             iAllowNotifications = EFalse;
   247             iAllowNotifications = EFalse;
   253             // IAP id
   248             iLoginTimer->Cancel();
   254             value1 = ( TInt )aMessage.Int0();
   249             iIapId = ( TInt )aMessage.Int0();
   255             // ret value
   250             value = ( TInt )aMessage.Int1();
   256             value2 = ( TInt )aMessage.Int1();
       
   257             
   251             
   258             iLoginTimer->Cancel();
   252             DEBUG1( "EHssLoginComplete return value: %d", value );
   259             
   253             indx = iServer.FindMessage( iIapId, EHssStartLogin );
   260             DEBUG1( "EHssLoginComplete value2: %d", value2 );
       
   261             indx = iServer.FindMessage( value1, EHssStartLogin );
       
   262             if ( KErrNotFound != indx )
   254             if ( KErrNotFound != indx )
   263                 {
   255                 {
   264                 if (value2 == KErrNone)
   256                 if ( value == KErrNone )
   265                     {
   257                     {
   266                     DEBUG( "EHssLoginComplete1" );
   258                     DEBUG( "EHssLoginComplete1" );
   267                     iServer.CompleteMessage( indx, KErrNone );
   259                     iServer.CompleteMessage( indx, KErrNone );
   268                     }
   260                     }
   269                 else
   261                 else
   277             aMessage.Complete( KErrNone );
   269             aMessage.Complete( KErrNone );
   278             break;
   270             break;
   279         case EHssLogoutComplete :
   271         case EHssLogoutComplete :
   280             iAllowNotifications = EFalse;
   272             iAllowNotifications = EFalse;
   281             iLogoutTimer->Cancel();
   273             iLogoutTimer->Cancel();
       
   274             iIapId = ( TInt )aMessage.Int0();
   282             
   275             
   283             // IAP id
   276             indx = iServer.FindMessage( iIapId, EHssCloseConnection );
   284             value1 = ( TInt )aMessage.Int0();
       
   285             
       
   286             indx = iServer.FindMessage( value1, EHssCloseConnection );
       
   287             if ( KErrNotFound != indx )
   277             if ( KErrNotFound != indx )
   288                 {
   278                 {
   289                 iServer.CompleteMessage( indx, KErrNone );    
   279                 iServer.CompleteMessage( indx, KErrNone );    
   290                 }
   280                 }
   291             
   281             
   292             aMessage.Complete( KErrNone );
   282             aMessage.Complete( KErrNone );
   293             break;
   283             break;
   294         case EHssStartLogin :
   284         case EHssStartLogin :
   295             // Do not send association status, since it's already done.
   285             // Do not send association status, since it's already done.
   296             iServer.SetAssociationFlag( EFalse ); 
   286             iServer.SetAssociationFlag( EFalse ); 
   297             // IAP id
       
   298             iIapId = ( TInt )aMessage.Int0();
   287             iIapId = ( TInt )aMessage.Int0();
   299             // Network id
       
   300             iNetId = ( TInt )aMessage.Int1();
   288             iNetId = ( TInt )aMessage.Int1();
       
   289      
   301             err = iServer.SaveMessage( iIapId, aMessage, EHssStartLogin ); 
   290             err = iServer.SaveMessage( iIapId, aMessage, EHssStartLogin ); 
   302             if ( KErrNone != err )
   291             if ( KErrNone != err )
   303                 {
   292                 {
   304                 aMessage.Complete( err );  
   293                 aMessage.Complete( err );  
   305                 }
   294                 }
   337                 iServer.CompleteMessage( indx , err );
   326                 iServer.CompleteMessage( indx , err );
   338                 }
   327                 }
   339             aMessage.Complete( KErrNone );
   328             aMessage.Complete( KErrNone );
   340             break;
   329             break;
   341         case EHssStart:
   330         case EHssStart:
   342             // IAP id
       
   343             iServer.SetLoginFlag( ETrue );
   331             iServer.SetLoginFlag( ETrue );
   344             iIapId = ( TInt )aMessage.Int0();
   332             iIapId = ( TInt )aMessage.Int0();
   345             err = iServer.SaveMessage( iIapId, aMessage, EHssStart ); 
   333             err = iServer.SaveMessage( iIapId, aMessage, EHssStart ); 
   346            if ( err != KErrNone)
   334     
       
   335             if ( err != KErrNone)
   347                 {
   336                 {
   348                 aMessage.Complete( err );  
   337                 aMessage.Complete( err );  
   349                 }
   338                 }
   350             else
   339             else
   351                 {
   340                 {
   352                 TRAPD( startLeaved, err = ProcessStartL( iIapId ) );
   341                 TRAPD( startLeaved, err = ProcessStartL( iIapId ) );
   353                 
       
   354                 if ( startLeaved != KErrNone)
   342                 if ( startLeaved != KErrNone)
   355                     {
   343                     {
   356                     indx = iServer.FindMessage(iIapId, EHssStart );
   344                     indx = iServer.FindMessage(iIapId, EHssStart );
   357                     if ( indx >= 0 )
   345                     if ( indx >= 0 )
   358                         {
   346                         {
   361                     else
   349                     else
   362                         {
   350                         {
   363                         aMessage.Complete( KErrNotSupported );
   351                         aMessage.Complete( KErrNotSupported );
   364                         }
   352                         }
   365                     }
   353                     }
   366                 
       
   367                 else if ( err != KErrNone)
   354                 else if ( err != KErrNone)
   368                     {
   355                     {
   369                     indx = iServer.FindMessage(iIapId, EHssStart );
   356                     indx = iServer.FindMessage(iIapId, EHssStart );
   370                     if ( indx >= 0 )
   357                     if ( indx >= 0 )
   371                         {
   358                         {
   374                     else
   361                     else
   375                         {
   362                         {
   376                         aMessage.Complete( KErrNotSupported );
   363                         aMessage.Complete( KErrNotSupported );
   377                         }
   364                         }
   378                     }
   365                     }
   379                 // else -> client is created and called 
       
   380                 // WLAN agent waits for 30 seconds before continuing connection setup.
       
   381                 }
   366                 }
   382             break;
   367             break;
   383         case EHssStartAgain:
   368         case EHssStartAgain:
   384             // IAP id
       
   385             iServer.SetLoginFlag( ETrue );
   369             iServer.SetLoginFlag( ETrue );
   386             iIapId = ( TInt )aMessage.Int0();
   370             iIapId = ( TInt )aMessage.Int0();
   387             err = iServer.SaveMessage( iIapId, aMessage, EHssStartAgain ); 
   371             err = iServer.SaveMessage( iIapId, aMessage, EHssStartAgain ); 
   388            if ( err != KErrNone)
   372             
       
   373             if ( err != KErrNone)
   389                 {
   374                 {
   390                 aMessage.Complete( err );  
   375                 aMessage.Complete( err );  
   391                 }
   376                 }
   392             else
   377             else
   393                 {
   378                 {
   404                         aMessage.Complete( err );
   389                         aMessage.Complete( err );
   405                         }
   390                         }
   406                     }
   391                     }
   407                 }
   392                 }
   408             break;
   393             break;
       
   394         case EHssCancel:
       
   395             iLoginTimer->Cancel();
       
   396             iLogoutTimer->Cancel();
       
   397             iIapId = ( TInt )aMessage.Int0();
   409             
   398             
   410         case EHssCancel:
       
   411                iLoginTimer->Cancel();
       
   412             iLogoutTimer->Cancel();
       
   413             // IAP id
       
   414             iIapId = ( TInt )aMessage.Int0();
       
   415             if ( iServer.GetAssociationFlagValue() )
   399             if ( iServer.GetAssociationFlagValue() )
   416                 {
   400                 {
   417                 // We are in association phase and Agent failed it for some reason
   401                 // We are in association phase and Agent failed it for some reason
   418                 ProcessAssociationStatus( iIapId, EFalse );
   402                 ProcessAssociationStatus( iIapId, EFalse );
   419                 }
   403                 }
   431             indx = iServer.FindMessage(iIapId, EHssCloseConnection );
   415             indx = iServer.FindMessage(iIapId, EHssCloseConnection );
   432             if ( indx >= 0 )
   416             if ( indx >= 0 )
   433                 {
   417                 {
   434                 iServer.CompleteMessage( indx , KErrCancel );
   418                 iServer.CompleteMessage( indx , KErrCancel );
   435                 }
   419                 }
   436             //Not needed to send Logout()
       
   437             //iServer.SetLogoutFlag( ETrue )
       
   438             //ProcessCloseL( iIapId )
       
   439             aMessage.Complete( KErrNone );
   420             aMessage.Complete( KErrNone );
   440         break;
   421             break;
   441         
       
   442         case EHssCloseConnection:
   422         case EHssCloseConnection:
   443             iLoginTimer->Cancel();
   423             iLoginTimer->Cancel();
   444             iLogoutTimer->Cancel();           
   424             iLogoutTimer->Cancel();           
   445         
       
   446             // IAP id
       
   447             iIapId = ( TInt )aMessage.Int0();
   425             iIapId = ( TInt )aMessage.Int0();
   448 
   426 
   449             if ( iServer.GetAssociationFlagValue() )
   427             if ( iServer.GetAssociationFlagValue() )
   450                 {
   428                 {
   451                 // We are in association phase and Agent failed it for some reason
   429                 // We are in association phase and Agent failed it for some reason
   474                         aMessage.Complete( KErrNone );
   452                         aMessage.Complete( KErrNone );
   475                         }
   453                         }
   476                     }
   454                     }
   477                 }
   455                 }
   478             break;
   456             break;
   479 
       
   480         case EHssServerShutdown:
   457         case EHssServerShutdown:
   481             ProcessServerShutdown( aMessage );
   458             ProcessServerShutdown( aMessage );
   482             break;
   459             break;
   483             
       
   484         case EHssGetIAP:
   460         case EHssGetIAP:
   485             aMessage.WriteL( 0, iapPackage );
   461             aMessage.WriteL( 0, iapPackage );
   486             aMessage.Complete( KErrNone );
   462             aMessage.Complete( KErrNone );
   487             break;
   463             break;
   488             
       
   489         case EHssUiState:
   464         case EHssUiState:
   490             ProcessUiState( aMessage );
   465             ProcessUiState( aMessage );
   491             break;
   466             break;
   492         case EHssStartBrowser:
   467         case EHssStartBrowser:
   493             {   
   468             {
   494             TInt len = aMessage.GetDesLength( 0 );
   469             TInt len = aMessage.GetDesLength( 0 );
   495             iIapId = ( TInt )aMessage.Int1();
   470             iIapId = ( TInt )aMessage.Int1();
   496             iNetId = ( TInt )aMessage.Int2();
   471             iNetId = ( TInt )aMessage.Int2();
   497             err = iServer.SaveMessage( iIapId, aMessage, EHssStartBrowser );
   472             err = iServer.SaveMessage( iIapId, aMessage, EHssStartBrowser );
   498             HBufC* buf = HBufC::NewLC( len ); 
   473             HBufC* buf = HBufC::NewLC( len ); 
   500             User::LeaveIfError( aMessage.Read( 0, ptr ) );     
   475             User::LeaveIfError( aMessage.Read( 0, ptr ) );     
   501             
   476             
   502             AuthenticateL( ptr );
   477             AuthenticateL( ptr );
   503             
   478             
   504             CleanupStack::PopAndDestroy(buf);
   479             CleanupStack::PopAndDestroy(buf);
   505             }
   480             break;
   506             break;
   481             }
   507             
       
   508         case EHssSetTimerValues:
   482         case EHssSetTimerValues:
   509             {
   483             {
   510             TUid clientUid( TUid::Uid( aMessage.Int0() ) );
   484             TUid clientUid( TUid::Uid( aMessage.Int0() ) );
       
   485             TBuf<KUidLength> uid;
       
   486             uid.Copy( clientUid.Name() );
       
   487             ModifyClientUid( uid );
   511             TUint loginTimerValue = aMessage.Int1();
   488             TUint loginTimerValue = aMessage.Int1();
   512             TUint logoutTimerValue = aMessage.Int2();
   489             TUint logoutTimerValue = aMessage.Int2();
   513             iServer.SetTimerValues( clientUid, loginTimerValue, logoutTimerValue );
   490             iServer.SetTimerValues( uid, loginTimerValue, logoutTimerValue );
   514             aMessage.Complete( KErrNone );
   491             aMessage.Complete( KErrNone );
   515             }
   492             break;
   516             break;
   493             }
   517 
       
   518         default:
   494         default:
   519             aMessage.Complete( KErrNotSupported );  
   495             aMessage.Complete( KErrNotSupported );  
   520             //PanicClient( aMessage, EBadRequest )
       
   521             break;
   496             break;
   522         }
   497         }
   523        iAllowNotifications = TRUE;
   498        iAllowNotifications = TRUE;
   524 
       
   525     }
   499     }
   526 
   500 
   527 // ---------------------------------------------------------
   501 // ---------------------------------------------------------
   528 // HandleOrderNotifications
   502 // HandleOrderNotifications
   529 // ---------------------------------------------------------
   503 // ---------------------------------------------------------
   696     if ( KErrNotFound != indx )
   670     if ( KErrNotFound != indx )
   697         {
   671         {
   698         iServer.CompleteMessage( indx, KErrCancel );    
   672         iServer.CompleteMessage( indx, KErrCancel );    
   699         }
   673         }
   700         
   674         
   701     TUid clientUid;
       
   702     TBuf8<KExtensionAPILength> extAPI;
   675     TBuf8<KExtensionAPILength> extAPI;
   703     TRAP_IGNORE( iIapSettingsHandler->FindClientL( iIapId, clientUid, extAPI ) );
   676     TBuf<KUidLength> clientUid;
   704     
   677     TInt err = iServer.GetClientUid( iIapId, clientUid );
   705     // 3rd party client was found
   678         
   706     if ( clientUid != TUid::Null() )
   679     if ( err != KErrNotFound )
   707         {
   680         {
   708         DEBUG("CHotSpotSession::LoginTimeout clientUid = CLIENT");
   681         DEBUG("CHotSpotSession::LoginTimeout clientUid = CLIENT");
       
   682         ConvertTBufToTUid( clientUid ); 
   709         TBuf8<KExtensionAPILength> nullBuf;
   683         TBuf8<KExtensionAPILength> nullBuf;
   710         TInt ret = CreateClient( clientUid, nullBuf );
   684         
       
   685         TInt ret = CreateClient( iClientUid, nullBuf );
   711         DEBUG1("CHotSpotSession::LoginTimeout CreateClient ret: %d", ret);
   686         DEBUG1("CHotSpotSession::LoginTimeout CreateClient ret: %d", ret);
   712         if ( KErrNone == ret )
   687         if ( KErrNone == ret )
   713             {
   688             {
   714             iClient->CancelLogin( iIapId );           
   689             iClient->CancelLogin( iIapId );           
   715             }
   690             }
   752     aMessage.ReadL( 0, uidPckg );
   727     aMessage.ReadL( 0, uidPckg );
   753     clientUid = uidPckg().ClientUid();
   728     clientUid = uidPckg().ClientUid();
   754     aMessage.ReadL( 1, iapPckg );
   729     aMessage.ReadL( 1, iapPckg );
   755     iapName = iapPckg().IapName();
   730     iapName = iapPckg().IapName();
   756     
   731     
       
   732     TBuf<KIapNameLength> bufUid;
       
   733     bufUid.Copy( clientUid.Name() );
       
   734     ModifyClientUid( bufUid );
       
   735         
   757     TUint32 iapId( 0 );
   736     TUint32 iapId( 0 );
   758     // TRAPD needed here so that 0 can be returned if DeleteIapL leaves
   737     
   759     TInt ret( KErrNone );
   738     TInt ret( KErrNone );
   760     TRAP( ret, iIapSettingsHandler->CreateClientIapL( iapName, iapId, clientUid ));
   739     TRAP( ret, iIapSettingsHandler->CreateClientIapL( iapName, iapId, bufUid ));
   761     DEBUG1( "CHotSpotSession::EHssRegister iapId: %d", iapId );
   740     DEBUG1( "CHotSpotSession::EHssRegister iapId: %d", iapId );
   762     DEBUG1( "CHotSpotSession::EHssRegister ret: %d", ret );
   741     DEBUG1( "CHotSpotSession::EHssRegister ret: %d", ret );
   763     if ( KErrNone == ret )
   742     if ( KErrNone == ret )
   764         {
   743         {
       
   744         iServer.SetClientIap( iapId, bufUid );
   765         aMessage.Complete( iapId );
   745         aMessage.Complete( iapId );
   766         }
   746         }
   767 
   747 
   768     else 
   748     else 
   769         {
   749         {
   770         // TRAP needed here so that 0 can be returned if DeleteIapL leaves
       
   771         //TRAP(err, iIapSettingsHandler->DeleteIapL( iapId ))
       
   772         // Error, we are returning 0 to client
   750         // Error, we are returning 0 to client
   773         // and no IAP is created
   751         // and no IAP is created
   774         aMessage.Complete( KErrNone );
   752         aMessage.Complete( KErrNone );
   775         }
   753         }
   776     }
   754     }
   785     iAllowNotifications = EFalse;
   763     iAllowNotifications = EFalse;
   786     TInt ret( KErrNone );
   764     TInt ret( KErrNone );
   787 
   765 
   788     // Read message
   766     // Read message
   789     TInt iapId = ( TInt )aMessage.Int0();
   767     TInt iapId = ( TInt )aMessage.Int0();
   790     
   768     iServer.RemoveClientIap( iapId );
   791     // Check that this is not Easy WLAN
   769     // Check that this is not Easy WLAN
   792     TRAP_IGNORE( EasyWlanIdL() );
   770     TInt easyWlan = iServer.GetEasyWlanId();
   793     if ( iEasyWlanId != iapId  )
   771     if ( easyWlan != iapId  )
   794         {
   772         {
   795         TRAPD( err, iIapSettingsHandler->DeleteIapL( iapId ) );
   773         TRAPD( err, iIapSettingsHandler->DeleteIapL( iapId ) );
   796         // return KErrGeneral if IAP removal is not successful
   774         // return KErrGeneral if IAP removal is not successful
   797         if ( err != KErrNone )
   775         if ( err != KErrNone )
   798             {
   776             {
   800             }
   778             }
   801         }
   779         }
   802     else
   780     else
   803         {
   781         {
   804         ret = KErrPermissionDenied;
   782         ret = KErrPermissionDenied;
   805         }
   783         }    
   806         
       
   807     aMessage.Complete( ret ); 
   784     aMessage.Complete( ret ); 
       
   785     DEBUG("CHotSpotSession::ProcessUnRegisterL DONE");
   808     }
   786     }
   809 
   787 
   810 // -----------------------------------------------------------------------------
   788 // -----------------------------------------------------------------------------
   811 // ProcessStartLogin
   789 // ProcessStartLogin
   812 // -----------------------------------------------------------------------------
   790 // -----------------------------------------------------------------------------
   813 //   
   791 //   
   814 TInt CHotSpotSession::ProcessStartLoginL( const TUint aIapId, const TUint aNetId )
   792 TInt CHotSpotSession::ProcessStartLoginL( const TUint aIapId, const TUint aNetId )
   815     {
   793     {
   816     DEBUG("CHotSpotSession::ProcessStartLogin");
   794     DEBUG("CHotSpotSession::ProcessStartLogin");
   817     TInt ret( KErrNotFound );
   795     TInt ret( KErrNotFound );
   818     TUid clientUid;
       
   819     TBuf8<KExtensionAPILength> extAPI;
   796     TBuf8<KExtensionAPILength> extAPI;
   820     iIapId = aIapId;
   797     iIapId = aIapId;
   821     
   798     
   822     // Check if Easy WLAN.
   799     // Check if Easy WLAN.
   823     TRAP_IGNORE( EasyWlanIdL() );
   800     TInt easyWlan = iServer.GetEasyWlanId();
   824     if ( iEasyWlanId == aIapId )
   801     if ( easyWlan == aIapId )
   825         {
   802         {
   826          DEBUG("CHotSpotSession::ProcessStartLogin Easy WLAN detected");
   803          DEBUG("CHotSpotSession::ProcessStartLogin Easy WLAN detected");
   827         // Just test internet connectivity and complete message later
   804         // Just test internet connectivity and complete message later
   828         TestInternetConnectivityL();
   805         TestInternetConnectivityL();
   829         ret = KErrNone;
   806         ret = KErrNone;
   830         return ret;
   807         return ret;
   831         }
   808         }
   832     
   809     
   833     iIapSettingsHandler->FindClientL( aIapId, clientUid, extAPI );
   810     TBuf<KUidLength> clientUid;
   834     
   811     TInt err = iServer.GetClientUid( aIapId, clientUid );
   835     // 3rd party client was found
   812     
   836     if ( clientUid != TUid::Null() )
   813     if ( err != KErrNotFound )
   837         {
   814         {
   838         DEBUG("CHotSpotSession::ProcessStartLogin clientUid = CLIENT");
   815         DEBUG("CHotSpotSession::ProcessStartLogin clientUid = CLIENT");
       
   816         ConvertTBufToTUid( clientUid ); 
   839         TBuf8<KExtensionAPILength> nullBuf;
   817         TBuf8<KExtensionAPILength> nullBuf;
   840         ret = CreateClient( clientUid, nullBuf );
   818         
       
   819         ret = CreateClient( iClientUid, nullBuf );
   841         
   820         
   842         if ( KErrNone == ret && iServer.GetLoginFlagValue() )
   821         if ( KErrNone == ret && iServer.GetLoginFlagValue() )
   843             {
   822             {
   844             iLoginTimer->After( iServer.GetLoginTimeMicroSecs( clientUid ) );
   823             iLoginTimer->After( iServer.GetLoginTimeMicroSecs( clientUid ) );
   845             DEBUG("CHotSpotSession::ProcessStartLogin iClient->Login( iIapId, iNetId );");
   824             DEBUG("CHotSpotSession::ProcessStartLogin iClient->Login( iIapId, iNetId );");
   863     {
   842     {
   864     DEBUG("CHotSpotSession::ProcessStart");
   843     DEBUG("CHotSpotSession::ProcessStart");
   865     
   844     
   866     TInt ret( KErrNone );
   845     TInt ret( KErrNone );
   867     TBuf8<KExtensionAPILength> extAPI;
   846     TBuf8<KExtensionAPILength> extAPI;
   868     
   847     TBuf<KUidLength> clientUid;
   869     iIapSettingsHandler->FindClientL( aIapId, iClientUid, extAPI );
   848     
   870     if ( iClientUid == TUid::Null() )
   849     TInt err = iServer.GetClientUid( aIapId, clientUid );
       
   850     if ( err != KErrNone )
   871         {
   851         {
   872         DEBUG("CHotSpotSession::ProcessStartL clientUid = EMPTY");
   852         DEBUG("CHotSpotSession::ProcessStartL clientUid = EMPTY");
   873         
   853         
   874         ret = KErrNotSupported;
   854         ret = KErrNotSupported;
   875         }
   855         }
   876     else
   856     else
   877         {
   857         {
   878         DEBUG("CHotSpotSession::ProcessStartL clientUid = CLIENT");
   858         DEBUG("CHotSpotSession::ProcessStartL clientUid = CLIENT");
       
   859         ConvertTBufToTUid( clientUid ); 
       
   860         TBuf8<KExtensionAPILength> nullBuf;
   879         
   861         
   880         // Try first with API extension defined
   862         // Try first with API extension defined
   881         ret = CreateClient( iClientUid, extAPI );
   863         ret = CreateClient( iClientUid, extAPI );
   882         
   864         
   883         if ( ret != KErrNone )
   865         if ( ret != KErrNone )
   909     TInt ret( KErrNone );
   891     TInt ret( KErrNone );
   910       
   892       
   911     // Client exists if StartAgain is called.
   893     // Client exists if StartAgain is called.
   912     if ( iClient == NULL )
   894     if ( iClient == NULL )
   913         {    
   895         {    
   914            TBuf8<KExtensionAPILength> nullBuf;
   896         TBuf8<KExtensionAPILength> nullBuf;
   915         ret = CreateClient( iClientUid, nullBuf );
   897         ret = CreateClient( iClientUid, nullBuf );
   916         }
   898         }
   917     
   899     
   918     if (  ret == KErrNone )
   900     if (  ret == KErrNone )
   919         {
   901         {
   976 //   
   958 //   
   977 TInt CHotSpotSession::ProcessCloseL( const TUint aIapId )
   959 TInt CHotSpotSession::ProcessCloseL( const TUint aIapId )
   978     {
   960     {
   979     DEBUG("CHotSpotSession::ProcessCloseL");
   961     DEBUG("CHotSpotSession::ProcessCloseL");
   980     TInt ret( KErrNone );
   962     TInt ret( KErrNone );
   981     TUid clientUid;
       
   982     TBuf8<KExtensionAPILength> extAPI;
   963     TBuf8<KExtensionAPILength> extAPI;
   983   
   964     TBuf<KUidLength> clientUid;
   984     iIapSettingsHandler->FindClientL( aIapId, clientUid, extAPI );
   965     
   985     if ( clientUid == TUid::Null() )
   966     TInt err = iServer.GetClientUid( aIapId, clientUid );
       
   967     if ( err != KErrNone )
   986         {
   968         {
   987         DEBUG("CHotSpotSession::ProcessCloseL clientUid = EMPTY");
   969         DEBUG("CHotSpotSession::ProcessCloseL clientUid = EMPTY");
   988         // do nothing
   970         // do nothing
   989         ret = KErrNotSupported;
   971         ret = KErrNotSupported;
   990         }
   972         }
   991     else
   973     else
   992         {
   974         {
   993         DEBUG("CHotSpotSession::ProcessCloseL clientUid = CLIENT");
   975         DEBUG("CHotSpotSession::ProcessCloseL clientUid = CLIENT");
   994         if ( iClient == NULL )
   976         if ( iClient == NULL )
   995             {
   977             {
       
   978             //Convert TBuf to TUid
       
   979             TLex lex( clientUid );
       
   980             TUint value( 0 );
       
   981             lex.Val( value, EHex );
       
   982             iClientUid = TUid::Null();
       
   983             iClientUid.iUid = value;
   996             TBuf8<KExtensionAPILength> nullBuf;
   984             TBuf8<KExtensionAPILength> nullBuf;
   997             ret = CreateClient( clientUid, nullBuf );
   985 
       
   986             ret = CreateClient( iClientUid, nullBuf );
   998             }
   987             }
   999         else
   988         else
  1000             {
   989             {
  1001             ret = KErrNone;   
   990             ret = KErrNone;   
  1002             }
   991             }
  1140 
  1129 
  1141     DEBUG("CHotSpotSession::AuthenticateLC() done");
  1130     DEBUG("CHotSpotSession::AuthenticateLC() done");
  1142     }
  1131     }
  1143 
  1132 
  1144 // -----------------------------------------------------------------------------
  1133 // -----------------------------------------------------------------------------
  1145 // EasyWlanIdL
  1134 // ModifyClientUid
  1146 // -----------------------------------------------------------------------------
  1135 // -----------------------------------------------------------------------------
  1147 //
  1136 //
  1148 void CHotSpotSession::EasyWlanIdL()
  1137 void CHotSpotSession::ModifyClientUid( TDes& aUid )
  1149     {
  1138     {
  1150     DEBUG("CHotSpotSession::EasyWlanIdL()");
  1139     DEBUG("CHotSpotSession::ModifyClientUid");
  1151     // Set to default value just in case
  1140     TInt indx = aUid.Find( KMark1 );
  1152     iEasyWlanId = KEasyWlanServiceId; 
  1141     if ( KErrNotFound != indx )
  1153     
  1142         {
  1154     RCmManagerExt cmManager;
  1143         aUid.Delete( indx, 1 );
  1155     cmManager.OpenL();
  1144         indx = aUid.Find( KMark2 );
  1156     CleanupClosePushL( cmManager );
  1145         if ( KErrNotFound != indx )
  1157     
  1146             {
  1158     iEasyWlanId = cmManager.EasyWlanIdL();
  1147             aUid.Delete( indx, 1 );
  1159     DEBUG1("CHotSpotSession::EasyWlanIdL() ret: % d", iEasyWlanId);
  1148             }
  1160     CleanupStack::PopAndDestroy( &cmManager );
  1149         }
       
  1150     }
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // ConvertTBufToTUid
       
  1154 // -----------------------------------------------------------------------------
       
  1155 //
       
  1156 void CHotSpotSession::ConvertTBufToTUid( TDes& aUid )
       
  1157     {
       
  1158     DEBUG("CHotSpotSession::ConvertTBufToTUid");
       
  1159     TLex lex( aUid );
       
  1160     TUint value( 0 );
       
  1161     lex.Val( value, EHex );
       
  1162     iClientUid = TUid::Null();
       
  1163     iClientUid.iUid = value;
  1161     }
  1164     }
  1162 
  1165 
  1163 // -----------------------------------------------------------------------------
  1166 // -----------------------------------------------------------------------------
  1164 // ConnectionStateChanged
  1167 // ConnectionStateChanged
  1165 // -----------------------------------------------------------------------------
  1168 // -----------------------------------------------------------------------------
  1166 //
  1169 //
  1167 void CHotSpotSession::ConnectionStateChanged( TWlanConnectionMode  aNewState ) 
  1170 void CHotSpotSession::ConnectionStateChanged( TWlanConnectionMode  aNewState ) 
  1168     {
  1171     {
  1169     DEBUG1( "CHotSpotSession::ConnectionStateChanged() aNewState=%d", aNewState );
  1172     DEBUG1( "CHotSpotSession::ConnectionStateChanged() aNewState=%d", aNewState );
  1170     switch ( aNewState )
  1173     switch ( aNewState )
  1171             {
  1174         {
  1172             case EWlanConnectionModeSearching:
  1175         case EWlanConnectionModeSearching:
  1173                 {
  1176             {
  1174                 break;
  1177             break;
  1175                 }
  1178             }
  1176             case EWlanConnectionModeInfrastructure:
  1179         case EWlanConnectionModeInfrastructure:
  1177             case EWlanConnectionModeSecureInfra:
  1180         case EWlanConnectionModeSecureInfra:
  1178                 {
  1181             {
  1179                 iMgtClient->CancelNotifications();
  1182             iMgtClient->CancelNotifications();
  1180                 ProcessAssociationStatus( iIapId, ETrue );
  1183             ProcessAssociationStatus( iIapId, ETrue );
  1181                 break;
  1184             break;
  1182                 }
  1185             }
  1183             case EWlanConnectionModeAdhoc:
  1186         case EWlanConnectionModeAdhoc:
  1184             case EWlanConnectionModeNotConnected:
  1187         case EWlanConnectionModeNotConnected:
  1185                 {
  1188             {
  1186                 iMgtClient->CancelNotifications();
  1189             iMgtClient->CancelNotifications();
  1187                 iServer.SetAssociationFlag( EFalse );
  1190             iServer.SetAssociationFlag( EFalse );
  1188                 break;
  1191             break;
  1189                 }
  1192             }
  1190             default:
  1193         default:
  1191                 {
  1194             {
  1192                 iMgtClient->CancelNotifications();
  1195             iMgtClient->CancelNotifications();
  1193                 iServer.SetAssociationFlag( EFalse );
  1196             iServer.SetAssociationFlag( EFalse );
  1194                 }
  1197             }
  1195             }
  1198         }
  1196     
  1199 
  1197     }
  1200     }
  1198 
  1201 
  1199 // end of file
  1202 // end of file
  1200 
  1203