usbclasses/usbphoneasmodem/classimplementation/atplugin/src/pamplugin.cpp
changeset 88 c3d148cdbed2
parent 0 1e05558e2206
child 89 3592750162a5
equal deleted inserted replaced
85:ad9d655827ef 88:c3d148cdbed2
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   100 
   100 
   101 	TInt err(KErrNotSupported);
   101 	TInt err(KErrNotSupported);
   102 
   102 
   103     if (aCmd.FindF(KNqapTestString) >= 0)
   103     if (aCmd.FindF(KNqapTestString) >= 0)
   104         {
   104         {
   105         SupportedAccessPointL( aReply );
   105         err = SupportedAccessPoint( aReply );
   106         err = KErrNone;
       
   107         }
   106         }
   108         
   107         
   109     else if (aCmd.FindF(KNqapInternetString) >= 0)
   108     else if (aCmd.FindF(KNqapInternetString) >= 0)
   110         {
   109         {
   111         ReadAccessPointL( KInternet, aReply );
   110         err = ReadAccessPoint( KInternet, aReply );
   112         err = KErrNone;
       
   113         }
   111         }
   114     else if (aCmd.FindF(KNqapWapString) >= 0)
   112     else if (aCmd.FindF(KNqapWapString) >= 0)
   115         {
   113         {
   116         ReadAccessPointL( KWap, aReply );
   114         err = ReadAccessPoint( KWap, aReply );
   117         err = KErrNone;
       
   118         }
   115         }
   119     else if (aCmd.FindF(KNqapInternetAndWapString) >= 0)
   116     else if (aCmd.FindF(KNqapInternetAndWapString) >= 0)
   120         {
   117         {
   121         ReadAccessPointL( KWapInternet, aReply );
   118         err = ReadAccessPoint( KWapInternet, aReply );
   122         err = KErrNone;
       
   123         }
   119         }
   124     else if (aCmd.FindF(KNcnnString) >= 0)
   120     else if (aCmd.FindF(KNcnnString) >= 0)
   125         {
   121         {
   126         iReply = &aReply;
   122         iReply = &aReply;
   127         iPAMEngine->GetServiceProviderName();
   123         iPAMEngine->GetServiceProviderName();
   131         {
   127         {
   132         err = KErrNotSupported;
   128         err = KErrNotSupported;
   133         }
   129         }
   134 
   130 
   135     if(err != KErrNone)
   131     if(err != KErrNone)
   136         HandleCommandCompleted(err, EReplyTypeUndefined);
   132         {
   137     else
   133         HandleCommandCompleted(err, EReplyTypeUndefined); 
   138         HandleCommandCompleted(KErrNone, EReplyTypeOk);
   134         }
   139         
   135      else
       
   136         {
       
   137         HandleCommandCompleted(KErrNone, EReplyTypeOk);  
       
   138         }
       
   139               
   140     TRACE_FUNC_EXIT
   140     TRACE_FUNC_EXIT
   141     }
   141     }
   142 
   142 
   143 
   143 
   144 void CPamPlugin::NameReqCallback( const TDesC8& aName )
   144 void CPamPlugin::NameReqCallback( const TDesC8& aName )
   145     {
   145     {
   146     TRACE_FUNC_ENTRY
   146     TRACE_FUNC_ENTRY
       
   147     
       
   148     TInt err;
   147     if ( aName == KNullDesC8() )
   149     if ( aName == KNullDesC8() )
   148         {
   150         {
   149         iReply->Zero();
   151         iReply->Zero();
   150         iReply->Create( KErrorString );
   152         err = iReply->Create( KErrorString );
   151         }
   153         }
   152     else
   154     else
   153         {
   155         {
   154         TBuf8<32> buf;
   156         TBuf8<32> buf;
   155         buf.Zero();
   157         buf.Zero();
   156         buf.Append( KCrlfString );
   158         buf.Append( KCrlfString );
   157         buf.Append( aName );
   159         buf.Append( aName );
   158         buf.Append( KCrlfString );
   160         buf.Append( KCrlfString );
   159         buf.Append( KOkString );
   161         buf.Append( KOkString );
   160         iReply->Zero();
   162         iReply->Zero();
   161         iReply->Create( buf );
   163         err = iReply->Create( buf );
   162         }
   164         }
   163     HandleCommandCompleted(KErrNone, EReplyTypeOk);
   165    
       
   166      if(err != KErrNone)
       
   167         {
       
   168         HandleCommandCompleted(err, EReplyTypeUndefined); 
       
   169         }
       
   170      else
       
   171         {
       
   172         HandleCommandCompleted(KErrNone, EReplyTypeOk);  
       
   173         }
       
   174    
   164 	TRACE_FUNC_EXIT
   175 	TRACE_FUNC_EXIT
   165     }
   176     }
   166 
   177 
   167 /**
   178 /**
   168  Used by AT*NQAP=?
   179  Used by AT*NQAP=?
   169  */
   180  */
   170 void CPamPlugin::SupportedAccessPointL( RBuf8& aReply )
   181 TInt CPamPlugin::SupportedAccessPoint( RBuf8& aReply )
   171 	{
   182 	{
   172 	TRACE_FUNC_ENTRY
   183 	TRACE_FUNC_ENTRY
   173 
   184 
   174     const TInt Kbufsize = 16;
   185     const TInt Kbufsize = 16;
   175     const TInt Kresponcebufsize = 64;
   186     const TInt Kresponcebufsize = 64;
       
   187     TInt err = KErrNone;
   176 	
   188 	
   177     HBufC16* supportedAp = HBufC16::NewL( Kbufsize );
   189     HBufC16* supportedAp = HBufC16::New( Kbufsize );
   178     iPAMEngine->SupportedAccessPoints( supportedAp );
   190     if (supportedAp)
   179     TBuf8<Kresponcebufsize> buf;
   191         {
       
   192         iPAMEngine->SupportedAccessPoints( supportedAp );
       
   193         TBuf8<Kresponcebufsize> buf;
   180     
   194     
   181 	buf.Zero();
   195 	    buf.Zero();
   182     buf.Append( KCrlfString );
   196         buf.Append( KCrlfString );
   183     buf.Append( KNqapString );
   197         buf.Append( KNqapString );
   184     buf.Append( *supportedAp );
   198         buf.Append( *supportedAp );
   185     buf.Append( KCrlfString );
   199         buf.Append( KCrlfString );
   186     buf.Append( KOkString );
   200         buf.Append( KOkString );
   187 
   201 
   188     aReply.Zero();
   202     	delete supportedAp;
   189     aReply.Create( buf ); 
   203         aReply.Zero();
       
   204         err = aReply.Create( buf );           
       
   205         }     
       
   206     else
       
   207         {
       
   208         err = KErrNoMemory;    
       
   209         }
   190 
   210 
   191 	TRACE_FUNC_EXIT
   211 	TRACE_FUNC_EXIT
   192  	return;
   212  	return err;
   193     }           
   213     }           
   194 
   214 
   195 /**
   215 /**
   196  Used by AT*NQAP=<>
   216  Used by AT*NQAP=<>
   197  */
   217  */
   198 void CPamPlugin::ReadAccessPointL(TInt aAccessPoint, RBuf8& aReply )
   218 TInt CPamPlugin::ReadAccessPoint(TInt aAccessPoint, RBuf8& aReply )
   199 	{
   219 	{
   200 	TRACE_FUNC_ENTRY
   220 	TRACE_FUNC_ENTRY
   201 
   221 
   202     const TInt KreplyBufferLength = 1024;
   222     const TInt KreplyBufferLength = 1024;
       
   223     TInt error = KErrNone;
   203 	
   224 	
   204    	CDesC8ArrayFlat* apArray = new(ELeave) CDesC8ArrayFlat(4);
   225    	CDesC8ArrayFlat* apArray = new(ELeave) CDesC8ArrayFlat(4);
   205     CleanupStack::PushL( apArray );
   226    	if (apArray)
   206    	
   227    	    {
   207     iPAMEngine->ReadAccessPointTableL( aAccessPoint, apArray );
   228         TRAP(error, iPAMEngine->ReadAccessPointTableL( aAccessPoint, apArray ));
   208 
   229         if (!error)
   209     TInt apArrayLength = apArray->Count();
   230             {        
   210     if ( apArrayLength > 0)
   231             TInt apArrayLength = apArray->Count();
   211         {
   232             if ( apArrayLength > 0)
   212         HBufC8* buf = HBufC8::NewL( KreplyBufferLength );
   233                 {
   213         buf->Des().Zero();
   234                 HBufC8* buf = HBufC8::New( KreplyBufferLength );
   214         buf->Des().Append( KCrlfString );
   235                 if (buf)
   215         for (TInt i=0; i < apArrayLength; i++ )
   236                     {
   216             {
   237                     buf->Des().Zero();
   217             // AT*NQAP=<n> responce
   238                     buf->Des().Append( KCrlfString );
   218             buf->Des().Append( KNqapString );
   239                     for (TInt i=0; i < apArrayLength; i++ )
   219             buf->Des().Append( (*apArray)[i] );
   240                         {
   220             buf->Des().Append( KCrlfString );
   241                         // AT*NQAP=<n> responce
   221             }
   242                         buf->Des().Append( KNqapString );
   222         buf->Des().Append( KOkString );
   243                         buf->Des().Append( (*apArray)[i] );
   223         aReply.Zero();
   244                         buf->Des().Append( KCrlfString );
   224         aReply.Create( *buf );
   245                         }
       
   246                     buf->Des().Append( KOkString );
       
   247                     aReply.Zero();
       
   248                     error = aReply.Create( *buf );
       
   249 					delete buf;
       
   250                     }
       
   251                 else 
       
   252                     {
       
   253                     error = KErrNoMemory;      
       
   254                     }
       
   255                 }    
       
   256             else
       
   257                 {
       
   258                 aReply.Zero();
       
   259                 error = aReply.Create( KOkString );
       
   260                 }
       
   261             }   
       
   262         delete apArray;
   225         }
   263         }
   226     else
   264     else
   227         {
   265         {
   228         aReply.Zero();
   266         error = KErrNoMemory;    
   229         aReply.Create( KOkString );
   267         } 
   230         }
       
   231     CleanupStack::PopAndDestroy( apArray );
       
   232     TRACE_FUNC_EXIT
   268     TRACE_FUNC_EXIT
   233 	return;
   269 	return error;
   234     }           
   270     }           
   235         
   271         
   236 
   272 
   237 TInt CPamPlugin::HandleRunError(TInt /*aErr*/)
   273 TInt CPamPlugin::HandleRunError(TInt /*aErr*/)
   238     {
   274     {