hotspotfw/hsserver/src/hotspotsession.cpp
changeset 39 7b3e49e4608a
parent 22 498f36116140
child 61 e1d68407ed06
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
    23 #include "hssnotif.h"
    23 #include "hssnotif.h"
    24 #include "hsslogintimer.h"
    24 #include "hsslogintimer.h"
    25 #include "hsslogouttimer.h"
    25 #include "hsslogouttimer.h"
    26 #include "hssclientinterface.h"
    26 #include "hssclientinterface.h"
    27 #include "am_debug.h"
    27 #include "am_debug.h"
    28 #include <internetconnectivitycrkeys.h>
       
    29 #include <WlanCdbCols.h>
    28 #include <WlanCdbCols.h>
    30 #include <starterclient.h>
    29 #include <starterclient.h>
    31 #include <cmmanagerext.h>
       
    32 #include <e32std.h>
    30 #include <e32std.h>
    33 #include <ecom.h>
    31 #include <ecom.h>
    34 #include <f32file.h>
    32 #include <f32file.h>
    35 #include <apgcli.h>
       
    36 
    33 
    37 // Forward declarations
    34 // Forward declarations
    38 class CWlanMgmtClient;
    35 class CWlanMgmtClient;
    39 class MWlanMgmtNotifications;
    36 class MWlanMgmtNotifications;
    40 
    37 
   116     if ( iLogoutTimer != NULL )
   113     if ( iLogoutTimer != NULL )
   117         {
   114         {
   118         iLogoutTimer->Cancel();
   115         iLogoutTimer->Cancel();
   119         delete iLogoutTimer;
   116         delete iLogoutTimer;
   120         }
   117         }
   121     
   118 
   122     if ( iIcts != NULL )
       
   123         {
       
   124         delete iIcts;
       
   125         }
       
   126     DEBUG( "CHotSpotSession::~CHotSpotSession() Done" );
   119     DEBUG( "CHotSpotSession::~CHotSpotSession() Done" );
   127     }
   120     }
   128     
   121     
   129 // ----------------------------------------------------------------------------------------
   122 // ----------------------------------------------------------------------------------------
   130 // ServiceL
   123 // ServiceL
   177                 }
   170                 }
   178             iNotifications = NULL;
   171             iNotifications = NULL;
   179             HandleCancelNotifications( aMessage );
   172             HandleCancelNotifications( aMessage );
   180             break;
   173             break;
   181         case EHssRegister :
   174         case EHssRegister :
   182             ProcessRegisterL( aMessage );
   175             ProcessRegister( aMessage );
   183             break;
   176             break;
   184         case EHssUnRegister :
   177         case EHssUnRegister :
   185             ProcessUnRegisterL( aMessage );
   178             ProcessUnRegister( aMessage );
   186             break;
   179             break;
   187         case EHssJoin :
   180         case EHssJoin :
   188             iAllowNotifications = EFalse;
   181             iAllowNotifications = EFalse;
   189             iIapId = ( TInt )aMessage.Int0();
   182             iIapId = ( TInt )aMessage.Int0();
   190      
   183      
   292                 {
   285                 {
   293                 aMessage.Complete( err );  
   286                 aMessage.Complete( err );  
   294                 }
   287                 }
   295             else
   288             else
   296                 {
   289                 {
   297                 err = ProcessStartLoginL( iIapId, iNetId );
   290                 err = ProcessStartLogin( iIapId, iNetId );
   298                 // If client not found, an error was returned. 
   291                 // If client not found, an error was returned. 
   299                 // Otherwise message completed elsewhere. 
   292                 // Otherwise message completed elsewhere. 
   300                 if ( KErrNone != err )
   293                 if ( KErrNone != err )
   301                     {
   294                     {
   302                     indx = iServer.FindMessage(iIapId, EHssStartLogin );
   295                     indx = iServer.FindMessage(iIapId, EHssStartLogin );
   460         case EHssGetIAP:
   453         case EHssGetIAP:
   461             aMessage.WriteL( 0, iapPackage );
   454             aMessage.WriteL( 0, iapPackage );
   462             aMessage.Complete( KErrNone );
   455             aMessage.Complete( KErrNone );
   463             break;
   456             break;
   464         case EHssUiState:
   457         case EHssUiState:
   465             ProcessUiState( aMessage );
   458             aMessage.Complete( KErrNotSupported );
   466             break;
   459             break;
   467         case EHssStartBrowser:
   460         case EHssStartBrowser:
   468             {
   461             {
   469             TInt len = aMessage.GetDesLength( 0 );
   462             aMessage.Complete( KErrNotSupported );
   470             iIapId = ( TInt )aMessage.Int1();
       
   471             iNetId = ( TInt )aMessage.Int2();
       
   472             err = iServer.SaveMessage( iIapId, aMessage, EHssStartBrowser );
       
   473             HBufC* buf = HBufC::NewLC( len ); 
       
   474             TPtr ptr( buf->Des() );
       
   475             User::LeaveIfError( aMessage.Read( 0, ptr ) );     
       
   476             
       
   477             AuthenticateL( ptr );
       
   478             
       
   479             CleanupStack::PopAndDestroy(buf);
       
   480             break;
   463             break;
   481             }
   464             }
   482         case EHssSetTimerValues:
   465         case EHssSetTimerValues:
   483             {
   466             {
   484             TUid clientUid( TUid::Uid( aMessage.Int0() ) );
   467             TUid clientUid( TUid::Uid( aMessage.Int0() ) );
   595             }
   578             }
   596         }
   579         }
   597     }
   580     }
   598 
   581 
   599 // -----------------------------------------------------------------------------
   582 // -----------------------------------------------------------------------------
   600 // TestInternetConnectivityL
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 void CHotSpotSession::TestInternetConnectivityL()
       
   604     {
       
   605     DEBUG("CHotSpotSession::TestInternetConnectivityL");
       
   606     if ( iIcts != NULL )
       
   607         {
       
   608         delete iIcts;
       
   609         iIcts = NULL;
       
   610         }
       
   611    
       
   612     iIcts = CIctsClientInterface::NewL( iIapId, iNetId, *this );
       
   613     iIcts->StartL();
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // ConnectivityObserver
       
   618 // -----------------------------------------------------------------------------
       
   619 //    
       
   620 void CHotSpotSession::ConnectivityObserver( TIctsTestResult aResult, 
       
   621                                             const TDesC& aString )
       
   622     {
       
   623     DEBUG1("CHotSpotSession::ConnectivityObserver result: %d", aResult);
       
   624     TInt indx( KErrNone );
       
   625     switch ( aResult )
       
   626         {
       
   627         case EConnectionOk :
       
   628             indx = iServer.FindMessage( iIapId, EHssStartLogin );
       
   629             if ( KErrNotFound != indx )
       
   630                 {
       
   631                 iServer.CompleteMessage( indx, KErrNone );    
       
   632                 }
       
   633             TRAPD( trap, iIapSettingsHandler->CreateIapL() );
       
   634             if ( trap != KErrNone )
       
   635                 {
       
   636                 DEBUG1("CHotSpotSession::ConnectivityObserver trap: %d", trap);
       
   637                 }
       
   638             break;
       
   639         case EHttpAuthenticationNeeded :
       
   640             // Start browser for authentication
       
   641             TRAP_IGNORE( AuthenticateL( aString ) );
       
   642             break;
       
   643         case EConnectionNotOk :
       
   644             indx = iServer.FindMessage( iIapId, EHssStartLogin );
       
   645             if ( KErrNotFound != indx )
       
   646                 {
       
   647                 iServer.CompleteMessage( indx, KErrNone );    
       
   648                 }
       
   649             break;
       
   650         case ETimeout :
       
   651             indx = iServer.FindMessage( iIapId, EHssStartLogin );
       
   652             if ( KErrNotFound != indx )
       
   653                 {
       
   654                 iServer.CompleteMessage( indx, KErrNone );    
       
   655                 }
       
   656             
       
   657             break;
       
   658         default:
       
   659             break;
       
   660         }
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // LoginTimeout
   583 // LoginTimeout
   665 // -----------------------------------------------------------------------------
   584 // -----------------------------------------------------------------------------
   666 //   
   585 //   
   667 void CHotSpotSession::LoginTimeout()
   586 void CHotSpotSession::LoginTimeout()
   668     {
   587     {
   711         iServer.CompleteMessage( indx, KErrNone );    
   630         iServer.CompleteMessage( indx, KErrNone );    
   712         }
   631         }
   713     }
   632     }
   714 
   633 
   715 // ---------------------------------------------------------
   634 // ---------------------------------------------------------
   716 // ProcessRegisterL
   635 // ProcessRegister
   717 // ---------------------------------------------------------
   636 // ---------------------------------------------------------
   718 //
   637 //
   719 void CHotSpotSession::ProcessRegisterL( const RMessage2& aMessage )
   638 void CHotSpotSession::ProcessRegister( const RMessage2& aMessage )
   720     {
   639     {
   721     DEBUG("CHotSpotSession::ProcessRegisterL");
   640     DEBUG("CHotSpotSession::ProcessRegister");
   722     
   641     
   723     iAllowNotifications = EFalse;
   642     iAllowNotifications = EFalse;
   724     TBufC< KIapNameLength > iapName;
   643     TBufC< KIapNameLength > iapName;
   725     TPckgBuf< TIapName > iapPckg;
   644     TPckgBuf< TIapName > iapPckg;
   726     TUid clientUid;
   645     TUid clientUid;
   756         aMessage.Complete( KErrNone );
   675         aMessage.Complete( KErrNone );
   757         }
   676         }
   758     }
   677     }
   759 
   678 
   760 // ---------------------------------------------------------
   679 // ---------------------------------------------------------
   761 // ProcessUnRegisterL
   680 // ProcessUnRegister
   762 // ---------------------------------------------------------
   681 // ---------------------------------------------------------
   763 //
   682 //
   764 void CHotSpotSession::ProcessUnRegisterL( const RMessage2& aMessage )
   683 void CHotSpotSession::ProcessUnRegister( const RMessage2& aMessage )
   765     {
   684     {
   766     DEBUG("CHotSpotSession::ProcessUnRegisterL");
   685     DEBUG("CHotSpotSession::ProcessUnRegister");
   767     iAllowNotifications = EFalse;
   686     iAllowNotifications = EFalse;
   768     TInt ret( KErrNone );
   687     TInt ret( KErrNone );
   769 
   688 
   770     // Read message
   689     // Read message
   771     TInt iapId = ( TInt )aMessage.Int0();
   690     TInt iapId = ( TInt )aMessage.Int0();
   772     iServer.RemoveClientIap( iapId );
   691     iServer.RemoveClientIap( iapId );
   773     // Check that this is not Easy WLAN
   692    
   774     TInt easyWlan = iServer.GetEasyWlanId();
   693     TRAPD( err, iIapSettingsHandler->DeleteIapL( iapId ) );
   775     if ( easyWlan != iapId  )
   694     // return KErrGeneral if IAP removal is not successful
   776         {
   695     if ( err != KErrNone )
   777         TRAPD( err, iIapSettingsHandler->DeleteIapL( iapId ) );
   696         {
   778         // return KErrGeneral if IAP removal is not successful
   697         ret = KErrGeneral;
   779         if ( err != KErrNone )
   698         }
   780             {
       
   781             ret = KErrGeneral;
       
   782             }
       
   783         }
       
   784     else
       
   785         {
       
   786         ret = KErrPermissionDenied;
       
   787         }    
       
   788     aMessage.Complete( ret ); 
   699     aMessage.Complete( ret ); 
   789     DEBUG("CHotSpotSession::ProcessUnRegisterL DONE");
   700     DEBUG("CHotSpotSession::ProcessUnRegisterL DONE");
   790     }
   701     }
   791 
   702 
   792 // -----------------------------------------------------------------------------
   703 // -----------------------------------------------------------------------------
   793 // ProcessStartLogin
   704 // ProcessStartLogin
   794 // -----------------------------------------------------------------------------
   705 // -----------------------------------------------------------------------------
   795 //   
   706 //   
   796 TInt CHotSpotSession::ProcessStartLoginL( const TUint aIapId, const TUint aNetId )
   707 TInt CHotSpotSession::ProcessStartLogin( const TUint aIapId, const TUint aNetId )
   797     {
   708     {
   798     DEBUG("CHotSpotSession::ProcessStartLogin");
   709     DEBUG("CHotSpotSession::ProcessStartLogin");
   799     TInt ret( KErrNotFound );
   710     TInt ret( KErrNotFound );
   800     TBuf8<KExtensionAPILength> extAPI;
   711     TBuf8<KExtensionAPILength> extAPI;
   801     iIapId = aIapId;
   712     iIapId = aIapId;
   802     
   713     
   803     // Check if Easy WLAN.
       
   804     TInt easyWlan = iServer.GetEasyWlanId();
       
   805     if ( easyWlan == aIapId )
       
   806         {
       
   807          DEBUG("CHotSpotSession::ProcessStartLogin Easy WLAN detected");
       
   808         // Just test internet connectivity and complete message later
       
   809         TestInternetConnectivityL();
       
   810         ret = KErrNone;
       
   811         return ret;
       
   812         }
       
   813     
       
   814     TBuf<KUidLength> clientUid;
   714     TBuf<KUidLength> clientUid;
   815     TInt err = iServer.GetClientUid( aIapId, clientUid );
   715     TInt err = iServer.GetClientUid( aIapId, clientUid );
   816     
   716     
   817     if ( err != KErrNotFound )
   717     if ( err != KErrNotFound )
   818         {
   718         {
   837     DEBUG("CHotSpotSession::ProcessStartLogin DONE");
   737     DEBUG("CHotSpotSession::ProcessStartLogin DONE");
   838     return ret;
   738     return ret;
   839     }
   739     }
   840 
   740 
   841 // -----------------------------------------------------------------------------
   741 // -----------------------------------------------------------------------------
   842 // ProcessStart
   742 // ProcessStartL
   843 // -----------------------------------------------------------------------------
   743 // -----------------------------------------------------------------------------
   844 //   
   744 //   
   845 TInt CHotSpotSession::ProcessStartL( const TUint aIapId )
   745 TInt CHotSpotSession::ProcessStartL( const TUint aIapId )
   846     {
   746     {
   847     DEBUG("CHotSpotSession::ProcessStart");
   747     DEBUG("CHotSpotSession::ProcessStart");
  1033         aMessage.Complete( KErrNone );
   933         aMessage.Complete( KErrNone );
  1034         }
   934         }
  1035     }
   935     }
  1036     
   936     
  1037 // -----------------------------------------------------------------------------
   937 // -----------------------------------------------------------------------------
  1038 // ProcessUiState
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //    
       
  1041 void CHotSpotSession::ProcessUiState( const RMessage2& aMessage )
       
  1042     {
       
  1043     DEBUG( "CHotSpotSession::ProcessUiState()" );
       
  1044     TBool completeMsg = EFalse;
       
  1045     TInt indx( KErrNone );
       
  1046     TInt indxBrowser( KErrNone );
       
  1047     TInt ret( KErrNone );
       
  1048     iIapId = ( TInt )aMessage.Int0();
       
  1049 
       
  1050     indx = iServer.FindMessage( iIapId, EHssStartLogin );
       
  1051     indxBrowser = iServer.FindMessage( iIapId, EHssStartBrowser );
       
  1052     THsBrowserUiStates uiState = ( THsBrowserUiStates ) aMessage.Int1(); // UI state
       
  1053     switch ( uiState )
       
  1054         {
       
  1055         case EHsBrowserUiRunning:
       
  1056             {
       
  1057             DEBUG( "CHotSpotSession::ProcessUiState() EHsBrowserUiRunning" );
       
  1058             break;
       
  1059             }
       
  1060         case EHsBrowserUiAuthenticatedOk:
       
  1061             {
       
  1062             DEBUG( "CHotSpotSession::ProcessUiState() EHsBrowserUiAuthenticatedOk" );
       
  1063 
       
  1064             completeMsg = ETrue;
       
  1065             break;
       
  1066                }
       
  1067         case EHsBrowserUiAuthenticatedNok:
       
  1068             {
       
  1069             DEBUG( "CHotSpotSession::ProcessUiState() EHsBrowserUiAuthenticatedNok" );
       
  1070             completeMsg = ETrue;
       
  1071             break;
       
  1072             }
       
  1073         case EHsBrowserUiClosed:
       
  1074             {
       
  1075             DEBUG( "CHotSpotSession::ProcessUiState() EHsBrowserUiClosed" );
       
  1076             completeMsg = ETrue;
       
  1077             break;
       
  1078             }
       
  1079         default:
       
  1080             {
       
  1081             DEBUG( "CHotSpotSession::ProcessUiState() default" );
       
  1082             completeMsg = ETrue;
       
  1083             }
       
  1084         }
       
  1085 		
       
  1086     if ( completeMsg )
       
  1087         {
       
  1088         // complete messages EHssStartLogin/EHssStartBrowser
       
  1089         if ( indx >= 0 )
       
  1090             {
       
  1091             DEBUG( "CHotSpotSession::ProcessUiState() completing EHssStartLogin" );
       
  1092             iServer.CompleteMessage( indx , KErrNone );
       
  1093             aMessage.Complete( KErrNone );
       
  1094             }
       
  1095         else if ( indxBrowser >= 0 )
       
  1096             {
       
  1097             DEBUG( "CHotSpotSession::ProcessUiState() completing EHssStartBrowser" );
       
  1098             iServer.CompleteMessage( indxBrowser, ret );
       
  1099             aMessage.Complete( KErrNone );
       
  1100             }
       
  1101         else
       
  1102             {
       
  1103             DEBUG( "CHotSpotSession::ProcessUiState() completing EHssUiState" );
       
  1104             aMessage.Complete( KErrNotFound );
       
  1105             }
       
  1106         }
       
  1107     }    
       
  1108     
       
  1109 // -----------------------------------------------------------------------------
       
  1110 // Authenticate()
       
  1111 // -----------------------------------------------------------------------------
       
  1112 //    
       
  1113 void CHotSpotSession::AuthenticateL( const TDesC& aString )
       
  1114     {
       
  1115     DEBUG("CHotSpotSession::AuthenticateL()");
       
  1116 
       
  1117     const TInt KBrowserUid = 0x2000AFCC; // hotspot browser application
       
  1118     HBufC* param = HBufC::NewLC( KMaxFileName );
       
  1119     _LIT(tmpString, "%d, %d, %S");
       
  1120     param->Des().Format( tmpString, iIapId, iNetId, &aString );
       
  1121     TUid uid( TUid::Uid( KBrowserUid ) );
       
  1122     RApaLsSession appArcSession;
       
  1123     User::LeaveIfError( appArcSession.Connect() ); // connect to AppArc server
       
  1124     CleanupClosePushL( appArcSession );
       
  1125     TThreadId id;
       
  1126     TInt err = appArcSession.StartDocument( *param, TUid::Uid( KBrowserUid ), id );
       
  1127     if ( err != KErrNone )
       
  1128         {
       
  1129         DEBUG1( "CHotSpotSession::AuthenticateL() StartDocument: %d", err );
       
  1130         }
       
  1131     CleanupStack::PopAndDestroy( &appArcSession );
       
  1132     CleanupStack::PopAndDestroy( param );
       
  1133 
       
  1134     DEBUG("CHotSpotSession::AuthenticateLC() done");
       
  1135     }
       
  1136 
       
  1137 // -----------------------------------------------------------------------------
       
  1138 // ModifyClientUid
   938 // ModifyClientUid
  1139 // -----------------------------------------------------------------------------
   939 // -----------------------------------------------------------------------------
  1140 //
   940 //
  1141 void CHotSpotSession::ModifyClientUid( TDes& aUid )
   941 void CHotSpotSession::ModifyClientUid( TDes& aUid )
  1142     {
   942     {