271 if ( iObserver ) |
251 if ( iObserver ) |
272 { |
252 { |
273 iObserver->ConnectingFinishedL( err ); |
253 iObserver->ConnectingFinishedL( err ); |
274 } |
254 } |
275 |
255 |
276 iRefreshing = iSession.RequestScanL(); |
256 iRefreshing = iSession.RequestScanL(); |
277 |
257 |
278 return err; |
258 return err; |
279 } |
259 } |
280 |
260 |
281 |
261 |
282 // ---------------------------------------------------------------------------- |
262 // ---------------------------------------------------------------------------- |
283 // CWsfModel::ConnectL |
263 // CWsfModel::ConnectL |
284 // ---------------------------------------------------------------------------- |
264 // ---------------------------------------------------------------------------- |
285 // |
265 // |
286 EXPORT_C void CWsfModel::ConnectL( TPckgBuf<TBool>& aPckg, TUint32 aIapId, |
266 EXPORT_C void CWsfModel::ConnectL( TPckgBuf<TBool>& aPckg, TUint32 aIapId, |
287 TWsfIapPersistence aPersistence, |
267 TBool aConnectOnly, |
288 TRequestStatus& aStatus ) |
268 TWsfIapPersistence aPersistence, |
|
269 TRequestStatus& aStatus ) |
289 { |
270 { |
290 LOG_ENTERFN( "CWsfModel::ConnectL" ); |
271 LOG_ENTERFN( "CWsfModel::ConnectL" ); |
291 |
272 |
292 if ( iObserver ) |
273 if ( iObserver ) |
293 { |
274 { |
294 iObserver->ConnectingL( aIapId ); |
275 iObserver->ConnectingL( aIapId ); |
295 } |
276 } |
296 |
277 |
297 iSession.ConnectWlanBearer( aPckg, aIapId, aPersistence, aStatus ); |
278 iSession.ConnectWlanBearer( aPckg, aIapId, aConnectOnly, aPersistence, aStatus ); |
298 } |
279 } |
299 |
280 |
300 // ---------------------------------------------------------------------------- |
281 // ---------------------------------------------------------------------------- |
301 // CWsfModel::SetConnectResultL |
282 // CWsfModel::SetConnectResultL |
302 // ---------------------------------------------------------------------------- |
283 // ---------------------------------------------------------------------------- |
455 iBrowserLauncher->ContinueBrowsingL( *this, aIapId ); |
432 iBrowserLauncher->ContinueBrowsingL( *this, aIapId ); |
456 } |
433 } |
457 |
434 |
458 |
435 |
459 // ---------------------------------------------------------------------------- |
436 // ---------------------------------------------------------------------------- |
460 // CWsfModel::ConnectivityObserver |
|
461 // ---------------------------------------------------------------------------- |
|
462 // |
|
463 void CWsfModel::ConnectivityObserver( TIctsTestResult aResult, |
|
464 const TDesC& aString ) |
|
465 { |
|
466 LOG_ENTERFN( "CWsfModel::ConnectivityObserver" ); |
|
467 LOG_WRITEF( "ICTS result: %d", aResult ); |
|
468 |
|
469 TBool makePersistent( EFalse ); |
|
470 // check the result |
|
471 switch ( aResult ) |
|
472 { |
|
473 case EConnectionOk: |
|
474 { |
|
475 // test succeeded |
|
476 TRAP_IGNORE( MoveToInternetSnapL( iConnectedIapId ) ); |
|
477 makePersistent = ETrue; |
|
478 LOG_WRITE( "ICT: EConnectionOk" ); |
|
479 break; |
|
480 } |
|
481 |
|
482 case EConnectionNotOk: |
|
483 { |
|
484 // test was run but it failed |
|
485 LOG_WRITE( "ICT: EConnectionNotOk" ); |
|
486 break; |
|
487 } |
|
488 case EHttpAuthenticationNeeded: |
|
489 { |
|
490 // test was run but HTTP authentication is required |
|
491 LOG_WRITE( "ICT: EHttpAuthenticationNeeded" ); |
|
492 if ( iConnectOnly ) |
|
493 { |
|
494 // Connect selected. WLAN Login needed. |
|
495 TRAP_IGNORE( LaunchWlanLoginL(aString) ); |
|
496 } |
|
497 break; |
|
498 } |
|
499 case ETimeout: |
|
500 { |
|
501 LOG_WRITE( "ICT: ETimeout" ); |
|
502 break; |
|
503 } |
|
504 |
|
505 default: |
|
506 { |
|
507 _LIT( KIctPanic, "ICT result" ); |
|
508 User::Panic( KIctPanic, aResult ); |
|
509 } |
|
510 } |
|
511 |
|
512 if ( makePersistent ) |
|
513 { |
|
514 TWsfIapPersistence pt = ( iConnectedIapId )? |
|
515 EIapPersistent: |
|
516 EIapExpireOnShutdown; |
|
517 |
|
518 TRAPD( err, MakeIctIapPersistentL( pt ) ); |
|
519 if ( err ) |
|
520 { |
|
521 LOG_WRITEF( "MakeIctIapPersistentL leaved with error = %d", err ); |
|
522 } |
|
523 } |
|
524 |
|
525 LOG_WRITE( "before AsyncStop" ); |
|
526 // finally stop blocking the caller |
|
527 iIctEnded = ETrue; |
|
528 if ( iIctWait.IsStarted() ) |
|
529 { |
|
530 LOG_WRITE( "ICT: AsyncStop" ); |
|
531 iIctWait.AsyncStop(); |
|
532 } |
|
533 |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CWsfModel::LaunchWlanLoginL() |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CWsfModel::LaunchWlanLoginL( const TDesC& aString ) |
|
541 { |
|
542 LOG_ENTERFN( "WsfModel::LaunchWlanLoginL" ); |
|
543 HBufC* param = HBufC::NewLC( KMaxFileName ); |
|
544 _LIT(tmpString, "%d, %d, %S"); |
|
545 param->Des().Format( tmpString, |
|
546 iConnectedIapId, |
|
547 iConnectedNetId, |
|
548 &aString ); |
|
549 TUid uid( TUid::Uid( KBrowserUid ) ); |
|
550 TThreadId id; |
|
551 |
|
552 RApaLsSession appArcSession; |
|
553 User::LeaveIfError( appArcSession.Connect() ); |
|
554 CleanupClosePushL( appArcSession ); |
|
555 |
|
556 TInt err = appArcSession.StartDocument( *param, TUid::Uid( KBrowserUid ), id ); |
|
557 if ( err != KErrNone ) |
|
558 { |
|
559 LOG_ENTERFN( "WsfModel::LaunchWlanLoginL failed" ); |
|
560 } |
|
561 CleanupStack::PopAndDestroy( &appArcSession ); |
|
562 CleanupStack::PopAndDestroy( param ); |
|
563 } |
|
564 |
|
565 // ---------------------------------------------------------------------------- |
|
566 // CWsfModel::MakeIctIapPersistentL |
|
567 // ---------------------------------------------------------------------------- |
|
568 // |
|
569 void CWsfModel::MakeIctIapPersistentL( TWsfIapPersistence aPersistence ) |
|
570 { |
|
571 LOG_ENTERFN( "CWsfModel::MakeIctIapPersistentL" ); |
|
572 LOG_WRITEF( "temp ICT IAP id = %d", iIctWlanInfo.iIapId ); |
|
573 |
|
574 if ( !iSession.SetIapPersistenceL( aPersistence ) ) |
|
575 { |
|
576 LOG_WRITE( "setting temporary flag FAILED" ); |
|
577 } |
|
578 |
|
579 } |
|
580 |
|
581 // ---------------------------------------------------------------------------- |
|
582 // CWsfModel::MoveToInternetSnapL |
|
583 // ---------------------------------------------------------------------------- |
|
584 // |
|
585 void CWsfModel::MoveToInternetSnapL( const TUint32 aIapId ) |
|
586 { |
|
587 LOG_ENTERFN( "CWsfModel::MoveToInternetSnapL" ); |
|
588 // Read all destination(SNAP) settings into an array |
|
589 RArray<TUint32> destinations; |
|
590 CleanupClosePushL(destinations); |
|
591 RCmManagerExt cmManager; |
|
592 cmManager.OpenL(); |
|
593 CleanupClosePushL( cmManager ); |
|
594 cmManager.AllDestinationsL(destinations); |
|
595 RCmDestinationExt destination; |
|
596 // Loop through each destination |
|
597 for(TInt i = 0; i < destinations.Count(); i++) |
|
598 { |
|
599 destination = cmManager.DestinationL(destinations[i]); |
|
600 CleanupClosePushL(destination); |
|
601 // Internet destination will always exist in the system. |
|
602 // Internet destination will have ESnapPurposeInternet set in its metadata. |
|
603 if (destination.MetadataL(CMManager::ESnapMetadataPurpose) == CMManager::ESnapPurposeInternet) |
|
604 { |
|
605 RCmConnectionMethodExt iap = cmManager.ConnectionMethodL( aIapId ); |
|
606 CleanupClosePushL( iap ); |
|
607 LOG_WRITE( "Move Iap to internet destination" ); |
|
608 destination.AddConnectionMethodL( iap ); |
|
609 destination.UpdateL(); |
|
610 CleanupStack::PopAndDestroy( &iap ); |
|
611 } |
|
612 CleanupStack::PopAndDestroy( &destination ); |
|
613 } |
|
614 CleanupStack::PopAndDestroy( &cmManager ); |
|
615 CleanupStack::PopAndDestroy( &destinations ); |
|
616 } |
|
617 |
|
618 // ---------------------------------------------------------------------------- |
|
619 // CWsfModel::CreateAccessPointL |
437 // CWsfModel::CreateAccessPointL |
620 // ---------------------------------------------------------------------------- |
438 // ---------------------------------------------------------------------------- |
621 // |
439 // |
622 EXPORT_C TBool CWsfModel::CreateAccessPointL( TWsfWlanInfo& aWlan, |
440 EXPORT_C TBool CWsfModel::CreateAccessPointL( TWsfWlanInfo& aWlan, |
623 TBool aExplicitDefine ) |
441 TBool aExplicitDefine ) |
665 return ret; |
482 return ret; |
666 } |
483 } |
667 |
484 |
668 |
485 |
669 // ---------------------------------------------------------------------------- |
486 // ---------------------------------------------------------------------------- |
670 // CWsfModel::IctsTestPermission |
|
671 // ---------------------------------------------------------------------------- |
|
672 // |
|
673 EXPORT_C TInt CWsfModel::IctsTestPermission() |
|
674 { |
|
675 LOG_ENTERFN( "CWsfModel::IctsTestPermission" ); |
|
676 TInt ictTestPermission( 0 ); |
|
677 CRepository* repository( NULL ); |
|
678 |
|
679 TRAPD( err, repository = CRepository::NewL( |
|
680 KCRUidInternetConnectivitySettings ) ); |
|
681 if ( err == KErrNone ) |
|
682 { |
|
683 repository->Get( KIctsTestPermission, ictTestPermission ); |
|
684 delete repository; |
|
685 LOG_WRITEF( "ICT is set to %d", ictTestPermission ); |
|
686 } |
|
687 return ictTestPermission; |
|
688 } |
|
689 |
|
690 |
|
691 // ---------------------------------------------------------------------------- |
|
692 // CWsfModel::TestAccessPointL |
|
693 // ---------------------------------------------------------------------------- |
|
694 // |
|
695 EXPORT_C TInt CWsfModel::TestAccessPointL( TWsfWlanInfo& aWlan, |
|
696 TBool aKeepConnection, |
|
697 TBool aConnectOnly ) |
|
698 { |
|
699 LOG_ENTERFN( "CWsfModel::TestAccessPointL" ); |
|
700 TInt err( KErrNone ); |
|
701 iKeepConnection = aKeepConnection; |
|
702 iConnectOnly = aConnectOnly; |
|
703 if ( !aWlan.iIapId ) |
|
704 { |
|
705 // the wlaninfo must already contain a valid IAP id |
|
706 LOG_WRITE( "invalid IAP id" ); |
|
707 return KErrCorrupt; |
|
708 } |
|
709 |
|
710 // the wlaninfo must be persistent to avoid nullpointer crashes due to |
|
711 // background refreshing |
|
712 iIctWlanInfo = aWlan; |
|
713 |
|
714 // create connection and test connectivity if needed |
|
715 |
|
716 // check ICT settings |
|
717 TInt ictTestPermission( IctsTestPermission() ); |
|
718 |
|
719 |
|
720 if ( aKeepConnection || ictTestPermission != EIctsNeverRun ) |
|
721 { |
|
722 // make connection if Connect was selected or if ICT needs it |
|
723 LOG_WRITE( "creating connection..." ); |
|
724 if ( iObserver ) |
|
725 { |
|
726 iObserver->ConnectingL( iIctWlanInfo.iIapId ); |
|
727 } |
|
728 |
|
729 // create the connection with temporary IAP by default |
|
730 err = iSession.ConnectWlanBearerL( iIctWlanInfo.iIapId, |
|
731 EIapExpireOnDisconnect ); |
|
732 |
|
733 if ( err == KErrNone ) |
|
734 { |
|
735 LOG_WRITE( "connection OK." ) |
|
736 } |
|
737 else |
|
738 { |
|
739 LOG_WRITEF( "connection creation failed with error = %d", err ); |
|
740 // either the connection creation failed or was aborted, |
|
741 // the server already cleaned up the mess, so nothing to do |
|
742 } |
|
743 |
|
744 if ( iObserver ) |
|
745 { |
|
746 iObserver->ConnectingFinishedL( err ); |
|
747 } |
|
748 |
|
749 } |
|
750 |
|
751 if ( err == KErrNone && ictTestPermission != EIctsNeverRun ) |
|
752 { |
|
753 // do the connectivity test |
|
754 iConnectedIapId = iIctWlanInfo.iIapId; |
|
755 |
|
756 RCmManagerExt cmManager; |
|
757 cmManager.OpenL(); |
|
758 CleanupClosePushL( cmManager ); |
|
759 |
|
760 RCmConnectionMethodExt cm = cmManager.ConnectionMethodL( |
|
761 iConnectedIapId ); |
|
762 CleanupClosePushL( cm ); |
|
763 |
|
764 iConnectedNetId = cm.GetIntAttributeL( CMManager::ECmNetworkId ); |
|
765 |
|
766 CleanupStack::PopAndDestroy( &cm ); |
|
767 CleanupStack::PopAndDestroy( &cmManager ); |
|
768 |
|
769 LOG_WRITE( "starting ICT test..." ); |
|
770 CIctsClientInterface* ict = CIctsClientInterface::NewL( |
|
771 iConnectedIapId, |
|
772 iConnectedNetId, |
|
773 *this ); |
|
774 LOG_WRITE( "ICT created" ); |
|
775 CleanupStack::PushL( ict ); |
|
776 ict->StartL(); |
|
777 LOG_WRITE( "ICT: started" ); |
|
778 |
|
779 // enter a waitloop since ICT is a kind of asynchronous service |
|
780 if ( !iIctEnded ) |
|
781 { |
|
782 LOG_WRITE( "ICT: iIctWait started" ); |
|
783 iIctWait.Start(); |
|
784 } |
|
785 |
|
786 iIctEnded = EFalse; |
|
787 CleanupStack::PopAndDestroy( ict ); |
|
788 LOG_WRITE( "ICT test done." ); |
|
789 } |
|
790 |
|
791 |
|
792 if ( ( err == KErrNone && !aKeepConnection && |
|
793 ictTestPermission != EIctsNeverRun ) || |
|
794 ( err != KErrNone && err != KErrCancel ) ) |
|
795 { |
|
796 // drop the connection in case of Start web browsing, and if an error |
|
797 // different from KErrCancel occured (on cancel the connection is |
|
798 // closed automatically) |
|
799 LOG_WRITE( "disconnecting..." ); |
|
800 iSession.DisconnectWlanBearerL(); |
|
801 LOG_WRITE( "Disconnected." ); |
|
802 } |
|
803 |
|
804 |
|
805 |
|
806 if ( err == KErrNone && ictTestPermission == EIctsNeverRun ) |
|
807 { |
|
808 LOG_WRITE( "ICT is set to never run, IAP remains temporary" ); |
|
809 |
|
810 ConnectivityObserver( EConnectionNotOk, KNullDesC ); |
|
811 } |
|
812 |
|
813 return err; |
|
814 } |
|
815 |
|
816 |
|
817 // ---------------------------------------------------------------------------- |
|
818 // CWsfModel::TestConnectedAccessPointL |
|
819 // ---------------------------------------------------------------------------- |
|
820 // |
|
821 EXPORT_C TInt CWsfModel::TestConnectedAccessPointL( TWsfWlanInfo& aWlan, |
|
822 TBool aConnectOnly ) |
|
823 { |
|
824 LOG_ENTERFN( "CWsfModel::TestConnectedAccessPointL" ); |
|
825 TInt err( KErrNone ); |
|
826 iConnectOnly = aConnectOnly; |
|
827 if ( !aWlan.iIapId ) |
|
828 { |
|
829 // the wlaninfo must already contain a valid IAP id |
|
830 LOG_WRITE( "invalid IAP id" ); |
|
831 return KErrCorrupt; |
|
832 } |
|
833 |
|
834 // the wlaninfo must be persistent to avoid nullpointer crashes due to |
|
835 // background refreshing |
|
836 iIctWlanInfo = aWlan; |
|
837 |
|
838 // check ICT settings |
|
839 TInt ictTestPermission( IctsTestPermission() ); |
|
840 |
|
841 if ( ictTestPermission != EIctsNeverRun ) |
|
842 { |
|
843 // do the connectivity test |
|
844 iConnectedIapId = iIctWlanInfo.iIapId; |
|
845 |
|
846 RCmManagerExt cmManager; |
|
847 cmManager.OpenL(); |
|
848 CleanupClosePushL( cmManager ); |
|
849 |
|
850 RCmConnectionMethodExt cm = cmManager.ConnectionMethodL( |
|
851 iConnectedIapId ); |
|
852 CleanupClosePushL( cm ); |
|
853 |
|
854 iConnectedNetId = cm.GetIntAttributeL( CMManager::ECmNetworkId ); |
|
855 |
|
856 CleanupStack::PopAndDestroy( &cm ); |
|
857 CleanupStack::PopAndDestroy( &cmManager ); |
|
858 |
|
859 LOG_WRITE( "starting ICT test..." ); |
|
860 |
|
861 if ( iIct ) |
|
862 { |
|
863 iIct->CancelStartL(); |
|
864 delete iIct; |
|
865 iIct = NULL; |
|
866 } |
|
867 |
|
868 iIct = CIctsClientInterface::NewL( iConnectedIapId, |
|
869 iConnectedNetId, |
|
870 *this ); |
|
871 LOG_WRITE( "ICT created" ); |
|
872 iIct->StartL(); |
|
873 LOG_WRITE( "ICT: started" ); |
|
874 |
|
875 // enter a waitloop since ICT is a kind of asynchronous service |
|
876 if ( !iIctEnded ) |
|
877 { |
|
878 LOG_WRITE( "ICT: iIctWait started" ); |
|
879 iIctWait.Start(); |
|
880 } |
|
881 |
|
882 iIctEnded = EFalse; |
|
883 LOG_WRITE( "ICT test done." ); |
|
884 } |
|
885 |
|
886 if ( ictTestPermission == EIctsNeverRun ) |
|
887 { |
|
888 LOG_WRITE( "ICT is set to never run, IAP remains temporary" ); |
|
889 ConnectivityObserver( EConnectionNotOk, KNullDesC ); |
|
890 } |
|
891 |
|
892 return err; |
|
893 } |
|
894 |
|
895 |
|
896 // ---------------------------------------------------------------------------- |
|
897 // CWsfModel::RefreshScanL |
487 // CWsfModel::RefreshScanL |
898 // ---------------------------------------------------------------------------- |
488 // ---------------------------------------------------------------------------- |
899 // |
489 // |
900 EXPORT_C TBool CWsfModel::RefreshScanL() |
490 EXPORT_C TBool CWsfModel::RefreshScanL() |
901 { |
491 { |