usbclasses/usbphoneasmodem/classimplementation/atplugin/src/pamengine.cpp
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements a AT extension plugin
       
    15 // 
       
    16 //
       
    17 
       
    18 // INCLUDES
       
    19 #include <utf.h>
       
    20 #include "atcmdpam_debug.h"
       
    21 #include "pamengine.h"
       
    22 #include "pamplugin.h"
       
    23 #include "pamplugindebug.h"
       
    24 
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 
       
    29 // ============================= LOCAL FUNCTIONS  =============================
       
    30 
       
    31 // ============================= MEMBER FUNCTIONS =============================
       
    32 
       
    33 /**
       
    34  Create a new instance
       
    35  */
       
    36 CPamEngine* CPamEngine::NewL( CPamPlugin* aOwner )
       
    37 	{
       
    38 	CPamEngine* self = CPamEngine::NewLC( aOwner );
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop();
       
    41 
       
    42     ATDEBUG( DebugPrint( _L( "CPamEngine::NewL()" )))
       
    43 	return self;
       
    44 	}
       
    45 	
       
    46 
       
    47 /**
       
    48  Create a new instance and push in cleanup stack
       
    49  */
       
    50 CPamEngine* CPamEngine::NewLC( CPamPlugin* aOwner )
       
    51 	{
       
    52 	CPamEngine* self = new ( ELeave ) CPamEngine( aOwner );
       
    53 	CleanupStack::PushL( self );
       
    54 
       
    55     ATDEBUG( DebugPrint( _L( "CPamEngine::NewLC()" )))
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 
       
    60 /**
       
    61  Destructor
       
    62  */
       
    63 CPamEngine::~CPamEngine()
       
    64 	{
       
    65 	ATDEBUG( DebugPrint( _L( "CPamEngine::~CPamEngine()" ) ) )
       
    66     delete iTelephony;
       
    67     }
       
    68 
       
    69 /**
       
    70  2nd phase Constructor
       
    71  (may leave)
       
    72  */
       
    73 void CPamEngine::ConstructL()
       
    74 	{
       
    75     ATDEBUG( DebugPrint( _L( "CPamEngine::ConstructL()" ) ) )
       
    76     
       
    77     CActiveScheduler::Add( this );
       
    78     iTelephony = CTelephony::NewL();
       
    79     }
       
    80 
       
    81 
       
    82 /**
       
    83  C++ Contructror
       
    84  */
       
    85 CPamEngine::CPamEngine( CPamPlugin* aOwner ) 
       
    86     : CActive( EPriorityNormal ), iOwner( aOwner )
       
    87 	{
       
    88 	ATDEBUG( DebugPrint( _L( "CPamEngine::CPamEngine()" )))
       
    89 	return;
       
    90     }
       
    91 
       
    92 
       
    93 /**
       
    94  Get the service provider name
       
    95  */
       
    96 void CPamEngine::GetServiceProviderName()
       
    97     {
       
    98     TRACE_FUNC_ENTRY
       
    99     if ( !IsActive() )
       
   100         {
       
   101         CTelephony::TNetworkNameV1Pckg namePckg( iNWName );
       
   102         iTelephony->GetCurrentNetworkName( iStatus, namePckg );
       
   103         SetActive();
       
   104         }
       
   105 	TRACE_FUNC_EXIT
       
   106     }
       
   107 
       
   108 /**
       
   109  From CActive
       
   110  */
       
   111 void CPamEngine::RunL()
       
   112 	{
       
   113 	TRACE_FUNC_ENTRY
       
   114 	ATDEBUG( DebugPrint( _L( "CPamEngine::RunL()" ) ) )
       
   115     if ( iStatus.Int() != KErrNone )
       
   116         {
       
   117         iOwner->NameReqCallback( KNullDesC8() );
       
   118         return;
       
   119         }
       
   120     TBuf8<20> out;
       
   121     CnvUtfConverter::ConvertFromUnicodeToUtf8( out, iNWName.iNetworkName );
       
   122 	iOwner->NameReqCallback( out );
       
   123 	TRACE_FUNC_EXIT
       
   124     return;
       
   125     }
       
   126 
       
   127 
       
   128 /**
       
   129  From CActive
       
   130  */
       
   131 void CPamEngine::DoCancel()
       
   132 	{
       
   133 	ATDEBUG( DebugPrint( _L( "CPamEngine::DoCancel()" ) ) )
       
   134 	iTelephony->CancelAsync( CTelephony::EGetCurrentNetworkNameCancel );
       
   135     return;
       
   136     }
       
   137 
       
   138 
       
   139 /**
       
   140  Get Access point table by the specified access point type
       
   141  */
       
   142 void CPamEngine::ReadAccessPointTableL(TInt aAccessPointType,  CDesC8ArrayFlat*& apArray )
       
   143     {
       
   144     TRACE_FUNC_ENTRY
       
   145 
       
   146     switch ( aAccessPointType )
       
   147         {
       
   148         case EINTERNETACCESSPOINT:      
       
   149             {
       
   150             //Internet access point;
       
   151             ReadPacketServicetableL( CMManager::EPacketDataInternetOnly, apArray );
       
   152             }
       
   153             break;
       
   154         case EWAPACCESSPOINT:
       
   155             {
       
   156             //Wap access point;
       
   157             ReadPacketServicetableL( CMManager::EPacketDataWAPOnly, apArray );
       
   158             break;
       
   159             }
       
   160         case EBOTHACCESSPOINT:
       
   161             {
       
   162             //Internet and wap access point only;
       
   163             ReadPacketServicetableL( CMManager::EPacketDataBoth, apArray );
       
   164             }
       
   165             break;
       
   166         default:
       
   167             {
       
   168             User::Leave( KErrArgument );
       
   169             }
       
   170             break;
       
   171         }
       
   172 	TRACE_FUNC_EXIT
       
   173     return;
       
   174     }
       
   175 
       
   176 
       
   177 /**
       
   178  Get supported access point type
       
   179  */
       
   180 void CPamEngine::SupportedAccessPoints(HBufC16*& aBuf)
       
   181     {
       
   182     TRACE_FUNC_ENTRY
       
   183     _LIT( KAccessTypeString, "(%d,%d,%d)" );
       
   184     aBuf->Des().AppendFormat( KAccessTypeString, CMManager::EPacketDataInternetOnly, 
       
   185                                                  CMManager::EPacketDataWAPOnly, 
       
   186                                                  CMManager::EPacketDataBoth );
       
   187     TRACE_FUNC_EXIT
       
   188     return;
       
   189     }
       
   190 
       
   191 
       
   192 /**
       
   193  Get service names by the specified access point type
       
   194  */
       
   195 void CPamEngine::ReadPacketServicetableL( CMManager::TPacketDataApType aAccessPointType,  CDesC8ArrayFlat*& apArray  )
       
   196     {
       
   197     TRACE_FUNC_ENTRY
       
   198 	ATDEBUG( DebugPrint( _L( "CPamEngine::ReadPacketServicetable()" ) ) )
       
   199 
       
   200     _LIT( KIP, "IP" );
       
   201     _LIT( KIPV6, "IPV6" );
       
   202     _LIT( KComma, "," );
       
   203     _LIT( KNumber, "%d" );
       
   204     TBuf<1> apsecure_auth;
       
   205     TBuf<3> apnumber;
       
   206     const TInt KBufsize = 256;
       
   207 
       
   208     RCmManager cmManager;
       
   209     cmManager.OpenL();
       
   210     CleanupClosePushL(cmManager);
       
   211     RArray<TUint32> destinations;
       
   212     cmManager.AllDestinationsL(destinations);
       
   213     CleanupClosePushL(destinations);
       
   214     RCmDestination destination;
       
   215 
       
   216     HBufC16 *tmpName = NULL;
       
   217     HBufC16* buf = HBufC16::NewLC( KBufsize );
       
   218     TBuf<4> apPDP_Type;
       
   219 
       
   220 
       
   221     for(TInt i = 0; i < destinations.Count(); i++)
       
   222         {
       
   223         destination = cmManager.DestinationL(destinations[i]);
       
   224         CleanupClosePushL(destination);
       
   225         tmpName = destination.NameLC();
       
   226        	ATDEBUG( DebugPrint( _L( "CPamEngine::ReadPacketServicetable() destination.name: %S" ), tmpName ) )
       
   227 
       
   228         RCmConnectionMethod connectionMethod;
       
   229         for(TInt j = 0; j < destination.ConnectionMethodCount(); j++)
       
   230             {
       
   231             connectionMethod = destination.ConnectionMethodL(j);
       
   232             CleanupClosePushL(connectionMethod);
       
   233 
       
   234             TUint32 bearerType = connectionMethod.GetIntAttributeL( CMManager::ECmBearerType );
       
   235             if (bearerType == KUidPacketDataBearerType)
       
   236                 {
       
   237                 TUint32 connectionType = connectionMethod.GetIntAttributeL( CMManager::EPacketDataApType );
       
   238                 if (connectionType == aAccessPointType)
       
   239                     {
       
   240                     // ap number
       
   241                     TUint32 id = connectionMethod.GetIntAttributeL( CMManager::ECmIapId );
       
   242                     apnumber.Format( KNumber, id );
       
   243                     buf->Des().Copy( apnumber );
       
   244                     buf->Des().Append( KComma );
       
   245 
       
   246                     // IAP name
       
   247                     tmpName = connectionMethod.GetStringAttributeL(CMManager::ECmName);
       
   248                     AddQuotationmarks( *tmpName, buf );
       
   249                     buf->Des().Append( KComma );
       
   250 
       
   251                     // gprs_accesspointname
       
   252                     tmpName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName);
       
   253                     AddQuotationmarks( *tmpName, buf );
       
   254 
       
   255                     // PDP_type
       
   256                     TInt isIPv6Supported = connectionMethod.GetBoolAttributeL(CMManager::EPacketDataPDPType);
       
   257                     if ( isIPv6Supported )
       
   258                         {
       
   259                         apPDP_Type = KIPV6;
       
   260                         }
       
   261                     else
       
   262                         {
       
   263                         apPDP_Type = KIP;
       
   264                         }
       
   265                     buf->Des().Append( KComma );
       
   266                     AddQuotationmarks( apPDP_Type, buf );
       
   267 
       
   268                     // username
       
   269                     tmpName = connectionMethod.GetStringAttributeL(CMManager::ECmIFAuthName);
       
   270                     buf->Des().Append( KComma );
       
   271                     AddQuotationmarks( *tmpName, buf );
       
   272 
       
   273                     // password
       
   274                     tmpName = connectionMethod.GetStringAttributeL(CMManager::ECmIFAuthPass);
       
   275                     buf->Des().Append( KComma );
       
   276                     AddQuotationmarks( *tmpName, buf );
       
   277 
       
   278                     // secure_auth
       
   279                     TBool tmp_apsecure_auth = connectionMethod.GetBoolAttributeL(CMManager::ECmDisablePlainTextAuth);
       
   280                     if ( tmp_apsecure_auth )
       
   281                         {
       
   282                         apsecure_auth.Format( KNumber, 1 );
       
   283                         }
       
   284                     else
       
   285                         {
       
   286                         apsecure_auth.Format( KNumber, 0 );
       
   287                         }
       
   288                     buf->Des().Append( KComma );
       
   289                     buf->Des().Append( apsecure_auth );
       
   290 
       
   291                 	ATDEBUG( DebugPrint( _L( "CPamEngine::ReadPacketServicetable() ATCommand items fetched" ) ) )
       
   292 
       
   293                     TBuf8<KBufsize> text8;
       
   294                     if ( CnvUtfConverter::ConvertFromUnicodeToUtf8( text8, *buf ) )
       
   295                         {
       
   296                         ATDEBUG( DebugPrint( _L( "CnvUtfConverter::ConvertFromUnicodeToUtf8 failed" ) ) )
       
   297                         }
       
   298                     else
       
   299                         {
       
   300                         // Conversion succeeded
       
   301                         // Add data to sending table
       
   302                         apArray->AppendL(text8);
       
   303                         }
       
   304                     }
       
   305                 }
       
   306             CleanupStack::PopAndDestroy(); // connectionMethod
       
   307             }
       
   308         tmpName = NULL;
       
   309         CleanupStack::PopAndDestroy(2); // destination
       
   310         }
       
   311     CleanupStack::PopAndDestroy(3); // cmManager
       
   312     TRACE_FUNC_EXIT
       
   313     return;
       
   314     }
       
   315 
       
   316 /**
       
   317  Add quotation marks
       
   318  */
       
   319 void CPamEngine::AddQuotationmarks( const TDesC& aString, HBufC16*& aBuf )
       
   320     {
       
   321     TRACE_FUNC_ENTRY
       
   322     _LIT( KQuotationmark, "\"" );
       
   323 
       
   324     if ( aString.Length() > 0 )
       
   325         {
       
   326         aBuf->Des().Append( KQuotationmark );
       
   327         aBuf->Des().Append( aString );
       
   328         aBuf->Des().Append( KQuotationmark );
       
   329         }
       
   330 	TRACE_FUNC_EXIT
       
   331     return;
       
   332     }
       
   333 
       
   334 
       
   335 // End of File
       
   336