localconnectivityservice/dun/atext/src/DunAtCmdHandler.cpp
changeset 0 c3e98f10fcf4
child 5 11d83199e2d9
equal deleted inserted replaced
-1:000000000000 0:c3e98f10fcf4
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  AT command handler and notifier
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19  * Points to consider:
       
    20  * - Each of the AT commands sent to ATEXT are converted to upper case form.
       
    21  *   Thus the ATEXT plugins don't need to check for case. The conversion to
       
    22  *   upper case form stops when carriage return or '=' character is found.
       
    23  */
       
    24 
       
    25 /*
       
    26  * The AT command handling is splitted to two parts on high level:
       
    27  * 1) Splitter: splitting the sub-commands in a command line to multiple ones
       
    28  *    for ATEXT to process.
       
    29  * 2) Combiner: combining the replies coming from ATEXT using a filter
       
    30  *    (the filter categories are explained in DunAtCmdPusher.cpp)
       
    31  */
       
    32 
       
    33 #include "DunAtCmdHandler.h"
       
    34 #include "DunAtUrcHandler.h"
       
    35 #include "DunDownstream.h"
       
    36 #include "DunDebug.h"
       
    37 
       
    38 const TInt8 KDunCancel = 24;
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Two-phased constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CDunAtCmdHandler* CDunAtCmdHandler::NewL(
       
    45     MDunAtCmdStatusReporter* aUpstream,
       
    46     MDunStreamManipulator* aDownstream,
       
    47     const TDesC8* aConnectionName )
       
    48     {
       
    49     CDunAtCmdHandler* self = new (ELeave) CDunAtCmdHandler(
       
    50         aUpstream,
       
    51         aDownstream,
       
    52         aConnectionName );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Destructor.
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CDunAtCmdHandler::~CDunAtCmdHandler()
       
    64     {
       
    65     FTRACE(FPrint( _L("CDunAtCmdHandler::~CDunAtCmdHandler()") ));
       
    66     ResetData();
       
    67     FTRACE(FPrint( _L("CDunAtCmdHandler::~CDunAtCmdHandler() complete") ));
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Resets data to initial values
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C void CDunAtCmdHandler::ResetData()
       
    75     {
       
    76     FTRACE(FPrint( _L("CDunAtCmdHandler::ResetData()") ));
       
    77     // APIs affecting this:
       
    78     // IssueRequest()
       
    79     Stop();
       
    80     // NewL()
       
    81     DeletePluginHandlers();
       
    82     delete iNvramListen;
       
    83     iNvramListen = NULL;
       
    84     delete iModeListen;
       
    85     iModeListen = NULL;
       
    86     delete iEcomListen;
       
    87     iEcomListen = NULL;
       
    88     if ( iAtCmdExtCommon.Handle() )
       
    89         {
       
    90         iAtCmdExtCommon.SynchronousClose();
       
    91         iAtCmdExtCommon.Close();
       
    92         }
       
    93     if ( iAtCmdExt.Handle() )
       
    94         {
       
    95         iAtCmdExt.SynchronousClose();
       
    96         iAtCmdExt.Close();
       
    97         }
       
    98     iSpecials.ResetAndDestroy();
       
    99     iSpecials.Close();
       
   100     // AddCmdModeCallback()
       
   101     iCmdCallbacks.Close();
       
   102     // Internal
       
   103     Initialize();
       
   104     FTRACE(FPrint( _L("CDunAtCmdHandler::ResetData() complete") ));
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Adds callback for command mode notification
       
   109 // The callback will be called when command mode starts or ends
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C TInt CDunAtCmdHandler::AddCmdModeCallback( MDunCmdModeMonitor* aCallback )
       
   113     {
       
   114     FTRACE(FPrint( _L("CDunAtCmdHandler::AddCmdModeCallback()" ) ));
       
   115     if ( !aCallback )
       
   116         {
       
   117         FTRACE(FPrint( _L("CDunAtCmdHandler::AddCmdModeCallback() (aCallback) not initialized!" ) ));
       
   118         return KErrGeneral;
       
   119         }
       
   120     TInt retTemp = iCmdCallbacks.Find( aCallback );
       
   121     if ( retTemp != KErrNotFound )
       
   122         {
       
   123         FTRACE(FPrint( _L("CDunAtCmdHandler::AddCmdModeCallback() (already exists) complete" ) ));
       
   124         return KErrAlreadyExists;
       
   125         }
       
   126     retTemp = iCmdCallbacks.Append( aCallback );
       
   127     if ( retTemp != KErrNone )
       
   128         {
       
   129         FTRACE(FPrint( _L("CDunAtCmdHandler::AddCmdModeCallback() (append failed!) complete" ) ));
       
   130         return retTemp;
       
   131         }
       
   132     FTRACE(FPrint( _L("CDunAtCmdHandler::AddCmdModeCallback() complete" ) ));
       
   133     return KErrNone;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // Parses an AT command
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C TInt CDunAtCmdHandler::ParseCommand( TDesC8& aCommand,
       
   141                                               TBool& aPartialInput )
       
   142     {
       
   143     FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand()") ));
       
   144     FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() received:") ));
       
   145     FTRACE(FPrintRaw(aCommand) );
       
   146     iCommand = &aCommand;
       
   147     // Manage partial AT command
       
   148     TBool needsCarriage = ETrue;
       
   149     TBool okToExit = ManagePartialCommand( aCommand, needsCarriage );
       
   150     if ( okToExit )
       
   151         {
       
   152         FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() (ok to exit) complete") ));
       
   153         aPartialInput = ETrue;
       
   154         return KErrNone;
       
   155         }
       
   156     if ( iHandleState != EDunStateIdle )
       
   157         {
       
   158         aPartialInput = EFalse;
       
   159         ResetParseBuffers();
       
   160         FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() (not ready) complete") ));
       
   161         return KErrNotReady;
       
   162         }
       
   163     TBool pushStarted = HandleASlashCommand();
       
   164     if ( pushStarted )
       
   165         {
       
   166         // Note: return here with "partial input" status to fool CDunUpstream
       
   167         // into reissuing the read request. The AT command has not really
       
   168         // started yet so this is necessary.
       
   169         aPartialInput = ETrue;
       
   170         ResetParseBuffers();
       
   171         FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() (A/) complete") ));
       
   172         return KErrNone;
       
   173         }
       
   174     FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() received total:") ));
       
   175     FTRACE(FPrintRaw(iInputBuffer) );
       
   176     iHandleState = EDunStateAtCmdHandling;
       
   177     iUpstream->NotifyAtCmdHandlingStart();
       
   178     iDecodeInfo.iFirstDecode = ETrue;
       
   179     iDecodeInfo.iDecodeIndex = 0;
       
   180     HandleNextDecodedCommand();
       
   181     FTRACE(FPrint( _L("CDunAtCmdHandler::ParseCommand() (not supported) complete") ));
       
   182     aPartialInput = EFalse;
       
   183     return KErrNone;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Manages request to abort command handling
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C TInt CDunAtCmdHandler::ManageAbortRequest()
       
   191     {
       
   192     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageAbortRequest()") ));
       
   193     // Just forward the request, do no other own processing
       
   194     TInt retVal = iCmdPusher->ManageAbortRequest();
       
   195     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageAbortRequest() complete") ));
       
   196     return retVal;
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // Sets end of command line marker on for the possible series of AT commands.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 EXPORT_C void CDunAtCmdHandler::SetEndOfCmdLine( TBool aClearInput )
       
   204     {
       
   205     FTRACE(FPrint( _L("CDunAtCmdHandler::SetEndOfCmdLine()") ));
       
   206     ManageEndOfCmdHandling( EFalse, ETrue, aClearInput );
       
   207     FTRACE(FPrint( _L("CDunAtCmdHandler::SetEndOfCmdLine() complete") ));
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // Stops sending of AT command from parse buffer
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C TInt CDunAtCmdHandler::Stop()
       
   215     {
       
   216     FTRACE(FPrint( _L("CDunAtCmdHandler::Stop()") ));
       
   217     // Only stop iCmdPusher here, not iUrcHandlers!
       
   218     if ( iHandleState != EDunStateAtCmdHandling )
       
   219         {
       
   220         FTRACE(FPrint( _L("CDunAtCmdHandler::Stop() (not ready) complete" )));
       
   221         return KErrNotReady;
       
   222         }
       
   223     iCmdPusher->Stop();
       
   224     iHandleState = EDunStateIdle;
       
   225     FTRACE(FPrint( _L("CDunAtCmdHandler::Stop() complete") ));
       
   226     return KErrNone;
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // Starts URC message handling
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C TInt CDunAtCmdHandler::StartUrc()
       
   234     {
       
   235     FTRACE(FPrint( _L("CDunAtCmdHandler::StartUrc()") ));
       
   236     TInt i;
       
   237     TInt count = iUrcHandlers.Count();
       
   238     for ( i=0; i<count; i++ )
       
   239         {
       
   240         TInt retTemp = iUrcHandlers[i]->IssueRequest();
       
   241         if ( retTemp!=KErrNone && retTemp!=KErrNotReady )
       
   242             {
       
   243             FTRACE(FPrint( _L("CDunAtCmdHandler::StartUrc() (ERROR) complete") ));
       
   244             return retTemp;
       
   245             }
       
   246         }
       
   247     FTRACE(FPrint( _L("CDunAtCmdHandler::StartUrc() complete") ));
       
   248     return KErrNone;
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // Stops URC message handling
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C TInt CDunAtCmdHandler::StopUrc()
       
   256     {
       
   257     FTRACE(FPrint( _L("CDunAtCmdHandler::StopUrc()") ));
       
   258     TInt i;
       
   259     TInt retVal = KErrNone;
       
   260     TInt count = iUrcHandlers.Count();
       
   261     for ( i=0; i<count; i++ )
       
   262         {
       
   263         retVal = iUrcHandlers[i]->Stop();
       
   264         }
       
   265     FTRACE(FPrint( _L("CDunAtCmdHandler::StopUrc() complete") ));
       
   266     return retVal;
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CDunAtCmdHandler::CDunAtCmdHandler
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 CDunAtCmdHandler::CDunAtCmdHandler( MDunAtCmdStatusReporter* aUpstream,
       
   274                                     MDunStreamManipulator* aDownstream,
       
   275                                     const TDesC8* aConnectionName ) :
       
   276     iUpstream( aUpstream ),
       
   277     iDownstream( aDownstream ),
       
   278     iConnectionName( aConnectionName )
       
   279     {
       
   280     Initialize();
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CDunAtCmdHandler::ConstructL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CDunAtCmdHandler::ConstructL()
       
   288     {
       
   289     FTRACE(FPrint( _L("CDunAtCmdHandler::ConstructL()") ));
       
   290     if ( !iUpstream || !iDownstream || !iConnectionName )
       
   291         {
       
   292         User::Leave( KErrGeneral );
       
   293         }
       
   294     // Connect to AT command extension (must succeed)
       
   295     TInt retTemp = KErrNone;
       
   296     CleanupClosePushL( iAtCmdExt );
       
   297     retTemp = iAtCmdExt.Connect( EDunATExtension, *iConnectionName );
       
   298     if ( retTemp != KErrNone )
       
   299         {
       
   300         FTRACE(FPrint( _L("CDunAtCmdHandler::ConstructL() connect (%d)"), retTemp));
       
   301         User::Leave( retTemp );
       
   302         }
       
   303     CleanupClosePushL( iAtCmdExtCommon );
       
   304     retTemp = iAtCmdExtCommon.Connect( *iConnectionName );
       
   305     if ( retTemp != KErrNone )
       
   306         {
       
   307         FTRACE(FPrint( _L("CDunAtCmdHandler::ConstructL() common connect (%d)"), retTemp));
       
   308         User::Leave( retTemp );
       
   309         }
       
   310     // Create the array of special commands
       
   311     CreateSpecialCommandsL();
       
   312     // Create the plugin handlers
       
   313     CreatePluginHandlersL();
       
   314     // Create the listeners
       
   315     CDunAtEcomListen* ecomListen = CDunAtEcomListen::NewLC( &iAtCmdExt, this );
       
   316     CDunAtModeListen* modeListen = CDunAtModeListen::NewLC( &iAtCmdExtCommon,
       
   317                                                            this );
       
   318     CDunAtNvramListen* nvramListen = CDunAtNvramListen::NewLC( &iAtCmdExt,
       
   319                                                                &iAtCmdExtCommon );
       
   320     // Set the default modes (+report) and characters
       
   321     GetAndSetDefaultSettingsL();
       
   322     // Start listening
       
   323     ecomListen->IssueRequest();
       
   324     modeListen->IssueRequest();
       
   325     nvramListen->IssueRequest();
       
   326     CleanupStack::Pop( nvramListen );
       
   327     CleanupStack::Pop( modeListen );
       
   328     CleanupStack::Pop( ecomListen );
       
   329     CleanupStack::Pop( &iAtCmdExtCommon );
       
   330     CleanupStack::Pop( &iAtCmdExt );
       
   331     iEcomListen = ecomListen;
       
   332     iModeListen = modeListen;
       
   333     iNvramListen = nvramListen;
       
   334     FTRACE(FPrint( _L("CDunAtCmdHandler::ConstructL() complete") ));
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // Initializes this class
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 void CDunAtCmdHandler::Initialize()
       
   342     {
       
   343     // Don't initialize iUpstream here (it is set through NewL)
       
   344     // Don't initialize iDownstream here (it is set through NewL)
       
   345     // Don't initialize iConnectionName here (it is set through NewL)
       
   346     iHandleState = EDunStateIdle;
       
   347     iCarriageReturn = 0;
       
   348     iLineFeed = 0;
       
   349     iBackspace = 0;
       
   350     iCommand = NULL;
       
   351     iDecodeInfo.iFirstDecode = ETrue;
       
   352     iDecodeInfo.iDecodeIndex = KErrNotFound;
       
   353     iDecodeInfo.iPrevChar = 0;
       
   354     iDecodeInfo.iPrevExists = EFalse;
       
   355     iCmdPusher = NULL;
       
   356     iEcomListen = NULL;
       
   357     iModeListen = NULL;
       
   358     iNvramListen = NULL;
       
   359     iDataMode = EFalse;
       
   360     iEchoOn = EFalse;
       
   361     iQuietOn = EFalse;
       
   362     iVerboseOn = EFalse;
       
   363     iEndIndex = KErrNotFound;
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // Creates plugin handlers for this class
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CDunAtCmdHandler::CreatePluginHandlersL()
       
   371     {
       
   372     FTRACE(FPrint( _L("CDunAtCmdHandler::CreatePluginHandlersL()") ));
       
   373     if ( !iAtCmdExt.Handle() )
       
   374         {
       
   375         FTRACE(FPrint( _L("CDunAtCmdHandler::CreatePluginHandlersL() complete") ));
       
   376         User::Leave( KErrGeneral );
       
   377         }
       
   378     // First create the command reply pusher
       
   379     CDunAtCmdPusher* cmdPusher = CDunAtCmdPusher::NewLC( &iAtCmdExt,
       
   380                                                          this,
       
   381                                                          iDownstream,
       
   382                                                          &iOkBuffer );
       
   383     // Next create the URC handlers
       
   384     TInt i;
       
   385     TInt numOfPlugins = iAtCmdExt.NumberOfPlugins();
       
   386     for ( i=0; i<numOfPlugins; i++ )
       
   387         {
       
   388         AddOneUrcHandlerL();
       
   389         }
       
   390     CleanupStack::Pop( cmdPusher );
       
   391     iCmdPusher = cmdPusher;
       
   392     FTRACE(FPrint( _L("CDunAtCmdHandler::CreatePluginHandlersL() complete") ));
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // Creates an array of special commands
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 void CDunAtCmdHandler::CreateSpecialCommandsL()
       
   400     {
       
   401     FTRACE(FPrint( _L("CDunAtCmdHandler::CreateSpecialCommandsL()") ));
       
   402     TInt retTemp = KErrNone;
       
   403     TBool firstSearch = ETrue;
       
   404     for ( ;; )
       
   405         {
       
   406         retTemp = iAtCmdExt.GetNextSpecialCommand( iInputBuffer, firstSearch );
       
   407         if ( retTemp != KErrNone )
       
   408             {
       
   409             break;
       
   410             }
       
   411         HBufC8* specialCmd = HBufC8::NewMaxLC( iInputBuffer.Length() );
       
   412         TPtr8 specialCmdPtr = specialCmd->Des();
       
   413         specialCmdPtr.Copy( iInputBuffer );
       
   414         specialCmdPtr.UpperCase();
       
   415         iSpecials.AppendL( specialCmd );
       
   416         CleanupStack::Pop( specialCmd );
       
   417         }
       
   418     iInputBuffer.Zero();
       
   419     FTRACE(FPrint( _L("CDunAtCmdHandler::CreateSpecialCommandsL() complete") ));
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // Recreates special command data.
       
   424 // This is done when a plugin is installed or uninstalled.
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 TInt CDunAtCmdHandler::RecreateSpecialCommands()
       
   428     {
       
   429     FTRACE(FPrint( _L("CDunAtCmdHandler::RecreateSpecialCommands()") ));
       
   430     iSpecials.ResetAndDestroy();
       
   431     TRAPD( retTrap, CreateSpecialCommandsL() );
       
   432     FTRACE(FPrint( _L("CDunAtCmdHandler::RecreateSpecialCommands() complete") ));
       
   433     return retTrap;
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // Gets default settings from RATExtCommon and sets them to RATExt
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 void CDunAtCmdHandler::GetAndSetDefaultSettingsL()
       
   441     {
       
   442     FTRACE(FPrint( _L("CDunAtCmdHandler::GetAndSetDefaultSettingsL()") ));
       
   443     // Note: Let's assume command mode is off by default
       
   444     TUint modeSet = GetCurrentModeL( KModeEcho | KModeQuiet | KModeVerbose );
       
   445     iEchoOn    = ( modeSet & KEchoModeBase    ) ? ETrue : EFalse;
       
   446     iQuietOn   = ( modeSet & KQuietModeBase   ) ? ETrue : EFalse;
       
   447     iVerboseOn = ( modeSet & KVerboseModeBase ) ? ETrue : EFalse;
       
   448     iCarriageReturn = GetCurrentModeL( KModeCarriage );
       
   449     iLineFeed = GetCurrentModeL( KModeLineFeed );
       
   450     iBackspace = GetCurrentModeL( KModeBackspace );
       
   451     iAtCmdExt.ReportQuietModeChange( iQuietOn );
       
   452     iAtCmdExt.ReportVerboseModeChange( iVerboseOn );
       
   453     iAtCmdExt.ReportCharacterChange( ECharTypeCarriage, iCarriageReturn );
       
   454     iAtCmdExt.ReportCharacterChange( ECharTypeLineFeed, iLineFeed );
       
   455     iAtCmdExt.ReportCharacterChange( ECharTypeBackspace, iBackspace );
       
   456     RegenerateReplyStrings();
       
   457     FTRACE(FPrint( _L("CDunAtCmdHandler::GetAndSetDefaultSettingsL() settings: E=%d, Q=%d, V=%d"), iEchoOn, iQuietOn, iVerboseOn ));
       
   458     FTRACE(FPrint( _L("CDunAtCmdHandler::GetAndSetDefaultSettingsL() settings: CR=%u, LF=%u, BS=%u"), iCarriageReturn, iLineFeed, iBackspace ));
       
   459     FTRACE(FPrint( _L("CDunAtCmdHandler::GetAndSetDefaultSettingsL() complete") ));
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // Regenerates the reply strings based on settings
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 TBool CDunAtCmdHandler::RegenerateReplyStrings()
       
   467     {
       
   468     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateReplyStrings()") ));
       
   469     TBool retVal = EFalse;
       
   470     retVal |= RegenerateOkReply();
       
   471     retVal |= RegenerateErrorReply();
       
   472     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateReplyStrings() complete") ));
       
   473     return retVal;
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // Regenerates the ok reply based on settings
       
   478 // ---------------------------------------------------------------------------
       
   479 //
       
   480 TBool CDunAtCmdHandler::RegenerateOkReply()
       
   481     {
       
   482     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateOkReply()") ));
       
   483     iOkBuffer.Zero();
       
   484     if ( iQuietOn )
       
   485         {
       
   486         FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateOkReply() (quiet) complete") ));
       
   487         return ETrue;
       
   488         }
       
   489     if ( iVerboseOn )
       
   490         {
       
   491         _LIT8( KVerboseError, "OK" );
       
   492         iOkBuffer.Append( iCarriageReturn );
       
   493         iOkBuffer.Append( iLineFeed );
       
   494         iOkBuffer.Append( KVerboseError );
       
   495         iOkBuffer.Append( iCarriageReturn );
       
   496         iOkBuffer.Append( iLineFeed );
       
   497         }
       
   498     else
       
   499         {
       
   500         _LIT8( KNumericError, "4" );
       
   501         iOkBuffer.Append( KNumericError );
       
   502         iOkBuffer.Append( iCarriageReturn );
       
   503         }
       
   504     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateOkReply() complete") ));
       
   505     return EFalse;
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 // Regenerates the error reply based on settings
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 TBool CDunAtCmdHandler::RegenerateErrorReply()
       
   513     {
       
   514     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateErrorReply()") ));
       
   515     iErrorBuffer.Zero();
       
   516     if ( iQuietOn )
       
   517         {
       
   518         FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateErrorReply() (quiet) complete") ));
       
   519         return ETrue;
       
   520         }
       
   521     if ( iVerboseOn )
       
   522         {
       
   523         _LIT8( KVerboseError, "ERROR" );
       
   524         iErrorBuffer.Append( iCarriageReturn );
       
   525         iErrorBuffer.Append( iLineFeed );
       
   526         iErrorBuffer.Append( KVerboseError );
       
   527         iErrorBuffer.Append( iCarriageReturn );
       
   528         iErrorBuffer.Append( iLineFeed );
       
   529         }
       
   530     else
       
   531         {
       
   532         _LIT8( KNumericError, "4" );
       
   533         iErrorBuffer.Append( KNumericError );
       
   534         iErrorBuffer.Append( iCarriageReturn );
       
   535         }
       
   536     FTRACE(FPrint( _L("CDunAtCmdHandler::RegenerateErrorReply() complete") ));
       
   537     return EFalse;
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // Gets current mode
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 TUint CDunAtCmdHandler::GetCurrentModeL( TUint aMask )
       
   545     {
       
   546     FTRACE(FPrint( _L("CDunAtCmdHandler::GetCurrentModeL()") ));
       
   547     TUint maskCheck = aMask & ( ~KSupportedModes );
       
   548     if ( maskCheck != 0 )
       
   549         {
       
   550         FTRACE(FPrint( _L("CDunAtCmdHandler::GetCurrentModeL() (not supported) complete") ));
       
   551         User::Leave( KErrNotSupported );
       
   552         }
       
   553     TUint newMode = 0;
       
   554     TInt retTemp = iAtCmdExtCommon.GetMode( aMask, newMode );
       
   555     if ( retTemp != KErrNone )
       
   556         {
       
   557         FTRACE(FPrint( _L("CDunAtCmdHandler::GetCurrentModeL() (ERROR) complete") ));
       
   558         User::Leave( retTemp );
       
   559         }
       
   560     FTRACE(FPrint( _L("CDunAtCmdHandler::GetCurrentModeL() complete") ));
       
   561     return newMode & (KModeChanged-1);
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // Instantiates one URC message handling class instance and adds it to the URC
       
   566 // message handler array
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 CDunAtUrcHandler* CDunAtCmdHandler::AddOneUrcHandlerL()
       
   570     {
       
   571     FTRACE(FPrint( _L("CDunAtCmdHandler::AddOneUrcHandlerL()") ));
       
   572     CDunAtUrcHandler* urcHandler = CDunAtUrcHandler::NewLC( &iAtCmdExt,
       
   573                                                             iDownstream );
       
   574     iUrcHandlers.AppendL( urcHandler );
       
   575     CleanupStack::Pop( urcHandler );
       
   576     FTRACE(FPrint( _L("CDunAtCmdHandler::AddOneUrcHandlerL() complete") ));
       
   577     return urcHandler;
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // Deletes all instantiated URC message handlers
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CDunAtCmdHandler::DeletePluginHandlers()
       
   585     {
       
   586     FTRACE(FPrint( _L("CDunAtCmdHandler::DeletePluginHandlers()") ));
       
   587     delete iCmdPusher;
       
   588     iCmdPusher = NULL;
       
   589     TInt i;
       
   590     TInt count = iUrcHandlers.Count();
       
   591     for ( i=0; i<count; i++ )
       
   592         {
       
   593         delete iUrcHandlers[i];
       
   594         iUrcHandlers[i] = NULL;
       
   595         }
       
   596     iUrcHandlers.Reset();
       
   597     iUrcHandlers.Close();
       
   598     FTRACE(FPrint( _L("CDunAtCmdHandler::DeletePluginHandlers() complete") ));
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------------------------
       
   602 // Manages partial AT command
       
   603 // ---------------------------------------------------------------------------
       
   604 //
       
   605 TBool CDunAtCmdHandler::ManagePartialCommand( TDesC8& aCommand,
       
   606                                               TBool& aNeedsCarriage )
       
   607     {
       
   608     FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand()") ));
       
   609     aNeedsCarriage = ETrue;
       
   610     // Check length of command
       
   611     if ( aCommand.Length() == 0 )
       
   612         {
       
   613         FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (length zero) complete") ));
       
   614         return ETrue;
       
   615         }
       
   616     // Check one character (or unit) based input data
       
   617     if ( aCommand.Length() == KDunChSetMaxCharLen )
       
   618         {
       
   619         EchoCommand( aCommand );
       
   620         // Handle backspace and cancel characters
       
   621         TBool found = HandleSpecialCharacters( aCommand );
       
   622         if ( found )
       
   623             {
       
   624             FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (special) complete") ));
       
   625             return ETrue;
       
   626             }
       
   627         }
       
   628     TBool endFound = EFalse;
       
   629     TBool overflow = AppendCommandToInputBuffer( aCommand, endFound );
       
   630     if ( overflow )
       
   631         {
       
   632         // Overflow occurred so return ETrue (consumed) to skip all the rest
       
   633         // characters until carriage return is found
       
   634         FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (overflow) complete") ));
       
   635         return ETrue;
       
   636         }
       
   637     // If something went wrong, do nothing (return consumed)
       
   638     if ( iInputBuffer.Length() <= 0 )
       
   639         {
       
   640         FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (length) complete") ));
       
   641         return ETrue;
       
   642         }
       
   643     // If "A/", no carriage return is needed, check that now
       
   644     if ( IsASlashCommand() )
       
   645         {
       
   646         aNeedsCarriage = EFalse;
       
   647         FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (A/) complete") ));
       
   648         return EFalse;
       
   649         }
       
   650     // For other commands and if no end, just return with consumed
       
   651     if ( !endFound )
       
   652         {
       
   653         FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() (void) complete") ));
       
   654         return ETrue;
       
   655         }
       
   656     FTRACE(FPrint( _L("CDunAtCmdHandler::ManagePartialCommand() complete") ));
       
   657     return EFalse;
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------------------------
       
   661 // Echoes a command if echo is on
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 TBool CDunAtCmdHandler::EchoCommand( TDesC8& aDes )
       
   665     {
       
   666     FTRACE(FPrint( _L("CDunAtCmdHandler::EchoCommand()") ));
       
   667     if ( aDes.Length() > KDunChSetMaxCharLen )
       
   668         {
       
   669         FTRACE(FPrint( _L("CDunAtCmdHandler::EchoCommand() (wrong length) complete") ));
       
   670         return EFalse;
       
   671         }
       
   672     if ( iEchoOn )
       
   673         {
       
   674         iEchoBuffer.Copy( aDes );
       
   675         iDownstream->NotifyDataPushRequest( &iEchoBuffer, NULL );
       
   676         FTRACE(FPrint( _L("CDunAtCmdHandler::EchoCommand() complete") ));
       
   677         return ETrue;
       
   678         }
       
   679     FTRACE(FPrint( _L("CDunAtCmdHandler::EchoCommand() (not started) complete") ));
       
   680     return EFalse;
       
   681     }
       
   682 
       
   683 // ---------------------------------------------------------------------------
       
   684 // Handles backspace and cancel characters
       
   685 // ---------------------------------------------------------------------------
       
   686 //
       
   687 TBool CDunAtCmdHandler::HandleSpecialCharacters( TDesC8& aCommand )
       
   688     {
       
   689     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleSpecialCharacters()") ));
       
   690     if ( aCommand.Length() != KDunChSetMaxCharLen )
       
   691         {
       
   692         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleSpecialCharacters() (wrong length) complete") ));
       
   693         return EFalse;
       
   694         }
       
   695     if ( aCommand[0] == iBackspace )
       
   696         {
       
   697         TInt bufferLength = iInputBuffer.Length();
       
   698         if ( bufferLength > 0 )
       
   699             {
       
   700             iInputBuffer.SetLength( bufferLength-1 );
       
   701             }
       
   702         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleSpecialCharacters() (backspace) complete") ));
       
   703         return ETrue;
       
   704         }
       
   705     if ( aCommand[0] == KDunCancel )
       
   706         {
       
   707         ResetParseBuffers();  // More processing here?
       
   708         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleSpecialCharacters() (cancel) complete") ));
       
   709         return ETrue;
       
   710         }
       
   711     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleSpecialCharacters() complete") ));
       
   712     return EFalse;
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 // Appends command to parse buffer
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 TBool CDunAtCmdHandler::AppendCommandToInputBuffer( TDesC8& aCommand,
       
   720                                                     TBool& aEndFound )
       
   721     {
       
   722     FTRACE(FPrint( _L("CDunAtCmdHandler::AppendCommandToInputBuffer()") ));
       
   723     aEndFound = EFalse;
       
   724     TInt cmdBufIndex = 0;
       
   725     TInt cmdBufLim = aCommand.Length();
       
   726     while ( cmdBufIndex < cmdBufLim )
       
   727         {
       
   728         if ( iInputBuffer.Length() == iInputBuffer.MaxLength() )
       
   729             {
       
   730             // 1) If output is full and end found from input
       
   731             //    -> reset buffers and overflow found
       
   732             // 2) If output is full and end not found from input
       
   733             //    -> don't reset buffers and overflow found
       
   734             TInt foundIndex = FindEndOfCommand( aCommand );
       
   735             if ( foundIndex >= 0 )
       
   736                 {
       
   737                 aEndFound = ETrue;
       
   738                 ResetParseBuffers();
       
   739                 FTRACE(FPrint( _L("CDunAtCmdHandler::AppendCommandToInputBuffer() (reset) complete") ));
       
   740                 }
       
   741             FTRACE(FPrint( _L("CDunAtCmdHandler::AppendCommandToInputBuffer() (overflow) complete") ));
       
   742             return ETrue;
       
   743             }
       
   744         TChar character = aCommand[cmdBufIndex];
       
   745         if ( IsEndOfCommand(character) )
       
   746             {
       
   747             aEndFound = ETrue;
       
   748             iEndIndex = cmdBufIndex;
       
   749             break;
       
   750             }
       
   751         iInputBuffer.Append( aCommand[cmdBufIndex] );
       
   752         cmdBufIndex++;
       
   753         }
       
   754     FTRACE(FPrint( _L("CDunAtCmdHandler::AppendCommandToInputBuffer() complete") ));
       
   755     return EFalse;
       
   756     }
       
   757 
       
   758 // ---------------------------------------------------------------------------
       
   759 // Handles next decoded command from input buffer
       
   760 // ---------------------------------------------------------------------------
       
   761 //
       
   762 TBool CDunAtCmdHandler::HandleNextDecodedCommand()
       
   763     {
       
   764     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleNextDecodedCommand()") ));
       
   765     if ( iHandleState != EDunStateAtCmdHandling )
       
   766         {
       
   767         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleNextDecodedCommand() (not ready) complete") ));
       
   768         return ETrue;
       
   769         }
       
   770     TBool extracted = ExtractNextDecodedCommand();
       
   771     if ( !extracted )
       
   772         {
       
   773         ManageEndOfCmdHandling( ETrue, ETrue, ETrue );
       
   774         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleNextDecodedCommand() (last) complete") ));
       
   775         return ETrue;
       
   776         }
       
   777     // Next convert the decoded AT command to uppercase
       
   778     // Don't check for case status -> let mixed cases pass
       
   779     iParseInfo.iSendBuffer.Copy( iDecodeInfo.iDecodeBuffer );
       
   780     TInt maxLength = iParseInfo.iSendBuffer.MaxLength();
       
   781     TPtr8 upperDes( &iParseInfo.iSendBuffer[0], iParseInfo.iLimit, maxLength );
       
   782     upperDes.UpperCase();
       
   783     // Next always send the command to ATEXT
       
   784     iCmdPusher->IssueRequest( iParseInfo.iSendBuffer );
       
   785     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleNextDecodedCommand() complete") ));
       
   786     return EFalse;
       
   787     }
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // Manages end of AT command handling
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 void CDunAtCmdHandler::ManageEndOfCmdHandling( TBool aNotifyExternal,
       
   794                                                TBool aNotifyLocal,
       
   795                                                TBool aClearInput )
       
   796     {
       
   797     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEndOfCmdHandling()") ));
       
   798     if ( iInputBuffer.Length() > 0 )
       
   799         {
       
   800         iLastBuffer.Copy( iInputBuffer );
       
   801         }
       
   802     ResetParseBuffers( aClearInput );
       
   803     iHandleState = EDunStateIdle;
       
   804     if ( aNotifyLocal )
       
   805         {
       
   806         iCmdPusher->SetEndOfCmdLine();
       
   807         }
       
   808     if ( !aNotifyExternal )
       
   809         {
       
   810         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEndOfCmdHandling() (no external) complete") ));
       
   811         return;
       
   812         }
       
   813     // Note: here we need to avoid internal recursion when parsing the
       
   814     // multiple IsEndOfCommand() and IsDelimiterCharacter() markers inside the
       
   815     // same upstream block.
       
   816     // Skip all the extra markers except the one we already know to exist.
       
   817     TInt i;
       
   818     TInt startVal = iEndIndex + 1;
       
   819     TInt foundIndex = KErrNotFound;
       
   820     TInt count = iCommand->Length();
       
   821     for ( i=startVal; i<count; i++ )
       
   822         {
       
   823         TChar character = (*iCommand)[i];
       
   824         if ( !(IsEndOfCommand(character)||IsDelimiterCharacter(character)) )
       
   825             {
       
   826             foundIndex = i;
       
   827             break;
       
   828             }
       
   829         }
       
   830     iUpstream->NotifyAtCmdHandlingEnd( foundIndex );
       
   831     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEndOfCmdHandling() complete") ));
       
   832     }
       
   833 
       
   834 // ---------------------------------------------------------------------------
       
   835 // Extracts next decoded command from input buffer to decode buffer
       
   836 // ---------------------------------------------------------------------------
       
   837 //
       
   838 TBool CDunAtCmdHandler::ExtractNextDecodedCommand( TBool aPeek )
       
   839     {
       
   840     FTRACE(FPrint( _L("CDunAtCmdHandler::ExtractNextDecodedCommand()") ));
       
   841     iParseInfo.iLimit = KErrNotFound;
       
   842     TDunDecodeInfo oldInfo = iDecodeInfo;
       
   843     iDecodeInfo.iDecodeBuffer.Zero();
       
   844     // Find start of decode command from input buffer
       
   845     TBool extendedCmd = EFalse;
       
   846     TInt startIndex = iDecodeInfo.iDecodeIndex;
       
   847     startIndex = FindStartOfDecodedCommand( iInputBuffer,
       
   848                                             startIndex,
       
   849                                             extendedCmd );
       
   850     if ( startIndex < 0 )
       
   851         {
       
   852         RestoreOldDecodeInfo( aPeek, oldInfo );
       
   853         FTRACE(FPrint( _L("CDunAtCmdHandler::ExtractNextDecodedCommand() (no start) complete") ));
       
   854         return EFalse;
       
   855         }
       
   856     // Find end of decode command from input buffer
       
   857     TBool extendedEnd = EFalse;
       
   858     TBool oneCharCmd = EFalse;
       
   859     TBool specialCmd = EFalse;
       
   860     TInt endIndex = KErrNotFound;
       
   861     if ( extendedCmd )
       
   862         {
       
   863         extendedEnd = CheckExtendedCommand( startIndex, endIndex );
       
   864         }
       
   865     else
       
   866         {
       
   867         specialCmd = CheckSpecialCommand( startIndex, endIndex );
       
   868         if ( !specialCmd )
       
   869             {
       
   870             CheckBasicCommand( startIndex, endIndex, oneCharCmd );
       
   871             }
       
   872         }
       
   873     if ( endIndex < startIndex )
       
   874         {
       
   875         RestoreOldDecodeInfo( aPeek, oldInfo );
       
   876         FTRACE(FPrint( _L("CDunAtCmdHandler::ExtractNextDecodedCommand() (no end) complete") ));
       
   877         return EFalse;
       
   878         }
       
   879     TInt cmdLength = endIndex - startIndex + 1;
       
   880     // If the limit was not already set then do it now
       
   881     if ( iParseInfo.iLimit < 0 )
       
   882         {
       
   883         iParseInfo.iLimit = cmdLength;
       
   884         }
       
   885     // Next create a new command
       
   886     if ( !iDecodeInfo.iFirstDecode && !oneCharCmd && !specialCmd )
       
   887         {
       
   888         _LIT( KAtMsg, "AT" );
       
   889         iDecodeInfo.iDecodeBuffer.Append( KAtMsg );
       
   890         iParseInfo.iLimit += 2;  // Length of "AT"
       
   891         // Note: The length of iDecodeBuffer is not exceeded here because "AT"
       
   892         // is added only for the second commands after that.
       
   893         }
       
   894     TPtrC8 decodedCmd = iInputBuffer.Mid( startIndex, cmdLength );
       
   895     iDecodeInfo.iDecodeBuffer.Append( decodedCmd );
       
   896     // Set index for next round
       
   897     iDecodeInfo.iFirstDecode = EFalse;
       
   898     iDecodeInfo.iDecodeIndex = endIndex + 1;
       
   899     if ( extendedEnd )  // skip the extra ';'
       
   900         {
       
   901         iDecodeInfo.iDecodeIndex++;
       
   902         }
       
   903     RestoreOldDecodeInfo( aPeek, oldInfo );
       
   904     FTRACE(FPrint( _L("CDunAtCmdHandler::ExtractNextDecodedCommand() complete") ));
       
   905     return ETrue;
       
   906     }
       
   907 
       
   908 // ---------------------------------------------------------------------------
       
   909 // Restores old decode info. For ExtractNextDecodedCommand() when aPeeks is
       
   910 // ETrue.
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 void CDunAtCmdHandler::RestoreOldDecodeInfo( TBool aPeek,
       
   914                                              TDunDecodeInfo& aOldInfo )
       
   915     {
       
   916     FTRACE(FPrint( _L("CDunAtCmdHandler::RestoreOldDecodeInfo()") ));
       
   917     if ( aPeek )
       
   918         {
       
   919         iDecodeInfo = aOldInfo;
       
   920         }
       
   921     FTRACE(FPrint( _L("CDunAtCmdHandler::RestoreOldDecodeInfo() complete") ));
       
   922     }
       
   923 
       
   924 // ---------------------------------------------------------------------------
       
   925 // Finds end of an AT command
       
   926 // ---------------------------------------------------------------------------
       
   927 //
       
   928 TInt CDunAtCmdHandler::FindEndOfCommand( TDesC8& aDes, TInt aStartIndex )
       
   929     {
       
   930     FTRACE(FPrint( _L("CDunAtCmdHandler::FindEndOfCommand()") ));
       
   931     TInt i;
       
   932     TInt length = aDes.Length();
       
   933     for ( i=aStartIndex; i<length; i++ )
       
   934         {
       
   935         TChar character = aDes[i];
       
   936         if ( IsEndOfCommand(character) )
       
   937             {
       
   938             FTRACE(FPrint( _L("CDunAtCmdHandler::FindEndOfCommand() complete (%d)"), i ));
       
   939             return i;
       
   940             }
       
   941         }
       
   942     FTRACE(FPrint( _L("CDunAtCmdHandler::FindEndOfCommand() (not found) complete") ));
       
   943     return KErrNotFound;
       
   944     }
       
   945 
       
   946 // ---------------------------------------------------------------------------
       
   947 // Tests for end of AT command character
       
   948 // ---------------------------------------------------------------------------
       
   949 //
       
   950 TBool CDunAtCmdHandler::IsEndOfCommand( TChar& aCharacter )
       
   951     {
       
   952     FTRACE(FPrint( _L("CDunAtCmdHandler::IsEndOfCommand()") ));
       
   953     if ( aCharacter==iCarriageReturn || aCharacter==iLineFeed )
       
   954         {
       
   955         FTRACE(FPrint( _L("CDunAtCmdHandler::IsEndOfCommand() (found) complete") ));
       
   956         return ETrue;
       
   957         }
       
   958     FTRACE(FPrint( _L("CDunAtCmdHandler::IsEndOfCommand() (not found) complete") ));
       
   959     return EFalse;
       
   960     }
       
   961 
       
   962 // ---------------------------------------------------------------------------
       
   963 // Finds start of a decoded AT command
       
   964 // ---------------------------------------------------------------------------
       
   965 //
       
   966 TInt CDunAtCmdHandler::FindStartOfDecodedCommand( TDesC8& aDes,
       
   967                                                   TInt aStartIndex,
       
   968                                                   TBool& aExtended )
       
   969     {
       
   970     FTRACE(FPrint( _L("CDunAtCmdHandler::FindStartOfDecodedCommand()") ));
       
   971     aExtended = EFalse;
       
   972     TInt i;
       
   973     TInt count = aDes.Length();
       
   974     for ( i=aStartIndex; i<count; i++ )
       
   975         {
       
   976         TChar character = aDes[i];
       
   977         if ( IsDelimiterCharacter(character) && !IsOneCharacterCommand(i) )
       
   978             {
       
   979             continue;
       
   980             }
       
   981         if ( !iDecodeInfo.iFirstDecode && IsExtendedCharacter(character) )
       
   982             {
       
   983             aExtended = ETrue;
       
   984             }
       
   985         else if ( iDecodeInfo.iFirstDecode && i+2<count )
       
   986             {
       
   987             // i+2 is the position of '+' in "AT+" and other similar sets
       
   988             character = aDes[i+2];
       
   989             if ( IsExtendedCharacter(character) )
       
   990                 {
       
   991                 aExtended = ETrue;
       
   992                 }
       
   993             }
       
   994         FTRACE(FPrint( _L("CDunAtCmdHandler::FindStartOfDecodedCommand() complete (%d)"), i ));
       
   995         return i;
       
   996         }
       
   997     FTRACE(FPrint( _L("CDunAtCmdHandler::FindStartOfDecodedCommand() (not found) complete") ));
       
   998     return KErrNotFound;
       
   999     }
       
  1000 
       
  1001 // ---------------------------------------------------------------------------
       
  1002 // Checks if character is delimiter character
       
  1003 // ---------------------------------------------------------------------------
       
  1004 //
       
  1005 TBool CDunAtCmdHandler::IsDelimiterCharacter( TChar aCharacter )
       
  1006     {
       
  1007     FTRACE(FPrint( _L("CDunAtCmdHandler::IsDelimiterCharacter()") ));
       
  1008     if ( aCharacter.IsSpace() || aCharacter==';' || aCharacter==0x00 )
       
  1009         {
       
  1010         FTRACE(FPrint( _L("CDunAtCmdHandler::IsExtendedCharacter() complete") ));
       
  1011         return ETrue;
       
  1012         }
       
  1013     FTRACE(FPrint( _L("CDunAtCmdHandler::IsDelimiterCharacter() (not delimiter) complete") ));
       
  1014     return EFalse;
       
  1015     }
       
  1016 
       
  1017 // ---------------------------------------------------------------------------
       
  1018 // Checks if character is of extended group
       
  1019 // ---------------------------------------------------------------------------
       
  1020 //
       
  1021 TBool CDunAtCmdHandler::IsExtendedCharacter( TChar aCharacter )
       
  1022     {
       
  1023     FTRACE(FPrint( _L("CDunAtCmdHandler::IsExtendedCharacter()") ));
       
  1024     if ( aCharacter=='+'  || aCharacter=='&' || aCharacter=='%' ||
       
  1025          aCharacter=='\\' || aCharacter=='*' || aCharacter=='#' ||
       
  1026          aCharacter=='$'  || aCharacter=='^' )
       
  1027         {
       
  1028         FTRACE(FPrint( _L("CDunAtCmdHandler::IsExtendedCharacter() complete") ));
       
  1029         return ETrue;
       
  1030         }
       
  1031     FTRACE(FPrint( _L("CDunAtCmdHandler::IsExtendedCharacter() (not extended) complete") ));
       
  1032     return EFalse;
       
  1033     }
       
  1034 
       
  1035 // ---------------------------------------------------------------------------
       
  1036 // Checks extended command
       
  1037 // ---------------------------------------------------------------------------
       
  1038 //
       
  1039 TBool CDunAtCmdHandler::CheckExtendedCommand( TInt aStartIndex, TInt& aEndIndex )
       
  1040     {
       
  1041     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckExtendedCommand()") ));
       
  1042     iDecodeInfo.iPrevExists = EFalse;
       
  1043     TBool inQuotes = EFalse;
       
  1044     TBool endFound = EFalse;
       
  1045     TInt length = iInputBuffer.Length();
       
  1046     for ( aEndIndex=aStartIndex; aEndIndex<length; aEndIndex++ )
       
  1047         {
       
  1048         TChar character = iInputBuffer[aEndIndex];
       
  1049         if ( character == '"' )
       
  1050             {
       
  1051             if ( iDecodeInfo.iPrevExists && iParseInfo.iLimit<0 )
       
  1052                 {
       
  1053                 iParseInfo.iLimit = aEndIndex - aStartIndex;
       
  1054                 }
       
  1055             inQuotes ^= ETrue;  // EFalse to ETrue or ETrue to EFalse
       
  1056             iDecodeInfo.iPrevExists = ETrue;
       
  1057             iDecodeInfo.iPrevChar = character;
       
  1058             continue;
       
  1059             }
       
  1060         if ( inQuotes )
       
  1061             {
       
  1062             continue;
       
  1063             }
       
  1064         // The next ones are those that are not in quotes
       
  1065         if ( character == '=' && iParseInfo.iLimit<0 )
       
  1066             {
       
  1067             iParseInfo.iLimit = aEndIndex - aStartIndex;
       
  1068             }
       
  1069         if ( IsDelimiterCharacter(character) )
       
  1070             {
       
  1071             endFound = ETrue;
       
  1072             break;
       
  1073             }
       
  1074         iDecodeInfo.iPrevExists = ETrue;
       
  1075         iDecodeInfo.iPrevChar = character;
       
  1076         }
       
  1077     aEndIndex--;
       
  1078     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckExtendedCommand() complete") ));
       
  1079     return endFound;
       
  1080     }
       
  1081 
       
  1082 // ---------------------------------------------------------------------------
       
  1083 // Checks special command
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //
       
  1086 TBool CDunAtCmdHandler::CheckSpecialCommand( TInt aStartIndex,
       
  1087                                              TInt& aEndIndex )
       
  1088     {
       
  1089     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckSpecialCommand()") ));
       
  1090     TBuf8<KDunInputBufLength> upperBuf;
       
  1091     TInt newLength = iInputBuffer.Length() - aStartIndex;
       
  1092     upperBuf.Copy( &iInputBuffer[aStartIndex], newLength );
       
  1093     upperBuf.UpperCase();
       
  1094     TInt i;
       
  1095     TInt count = iSpecials.Count();
       
  1096     for ( i=0; i<count; i++ )
       
  1097         {
       
  1098         HBufC8* specialCmd = iSpecials[i];
       
  1099         TInt specialLength = specialCmd->Length();
       
  1100         if ( newLength < specialLength )
       
  1101             {
       
  1102             continue;
       
  1103             }
       
  1104         TInt origLength = newLength;
       
  1105         if ( newLength > specialLength )
       
  1106             {
       
  1107             upperBuf.SetLength( specialLength );
       
  1108             }
       
  1109         TInt cmpResult = upperBuf.Compare( *specialCmd );
       
  1110         upperBuf.SetLength( origLength );
       
  1111         if ( cmpResult == 0 )
       
  1112             {
       
  1113             iParseInfo.iLimit = specialLength;
       
  1114             aEndIndex = (origLength-1) + aStartIndex;
       
  1115             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckSpecialCommand() complete") ));
       
  1116             return ETrue;
       
  1117             }
       
  1118         }
       
  1119     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckSpecialCommand() (not found) complete") ));
       
  1120     return EFalse;
       
  1121     }
       
  1122 
       
  1123 // ---------------------------------------------------------------------------
       
  1124 // Checks extended command
       
  1125 // ---------------------------------------------------------------------------
       
  1126 //
       
  1127 TInt CDunAtCmdHandler::CheckBasicCommand( TInt aStartIndex,
       
  1128                                           TInt& aEndIndex,
       
  1129                                           TBool& aOneCharCmd )
       
  1130     {
       
  1131     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand()") ));
       
  1132     aEndIndex = aStartIndex;
       
  1133     aOneCharCmd = EFalse;
       
  1134     TBool inQuotes = EFalse;
       
  1135     TInt length = iInputBuffer.Length();
       
  1136     iDecodeInfo.iPrevExists = EFalse;
       
  1137     if ( aStartIndex < length )
       
  1138         {
       
  1139         TChar character = iInputBuffer[aStartIndex];
       
  1140         if ( IsOneCharacterCommand(aStartIndex) )
       
  1141             {
       
  1142             aOneCharCmd = ETrue;
       
  1143             // Without "endIndex++" here
       
  1144             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (X) complete") ));
       
  1145             return KErrNone;
       
  1146             }
       
  1147         }
       
  1148     for ( ; aEndIndex<length; aEndIndex++ )
       
  1149         {
       
  1150         TChar character = iInputBuffer[aEndIndex];
       
  1151         if ( character == '"' )
       
  1152             {
       
  1153             if ( iDecodeInfo.iPrevExists && iParseInfo.iLimit<0 )
       
  1154                 {
       
  1155                 iParseInfo.iLimit = aEndIndex - aStartIndex;
       
  1156                 }
       
  1157             inQuotes ^= ETrue;  // EFalse to ETrue or ETrue to EFalse
       
  1158             iDecodeInfo.iPrevExists = ETrue;
       
  1159             iDecodeInfo.iPrevChar = character;
       
  1160             continue;
       
  1161             }
       
  1162         if ( inQuotes )
       
  1163             {
       
  1164             continue;
       
  1165             }
       
  1166         if ( character == '?' )
       
  1167             {
       
  1168             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (?) complete") ));
       
  1169             return KErrNone;
       
  1170             }
       
  1171         if ( character.IsSpace() || IsExtendedCharacter(character) )
       
  1172             {
       
  1173             aEndIndex--;
       
  1174             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (S or extended) complete") ));
       
  1175             return KErrNone;
       
  1176             }
       
  1177         if ( !iDecodeInfo.iPrevExists )
       
  1178             {
       
  1179             iDecodeInfo.iPrevExists = ETrue;
       
  1180             iDecodeInfo.iPrevChar = character;
       
  1181             continue;
       
  1182             }
       
  1183         if ( IsOneCharacterCommand(aEndIndex) )
       
  1184             {
       
  1185             aEndIndex--;
       
  1186             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (one char) complete") ));
       
  1187             return KErrNone;
       
  1188             }
       
  1189         if ( character.IsAlpha() && !iDecodeInfo.iPrevChar.IsAlpha() )
       
  1190             {
       
  1191             aEndIndex--;
       
  1192             FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (boundary) complete") ));
       
  1193             return KErrNone;
       
  1194             }
       
  1195         iDecodeInfo.iPrevExists = ETrue;
       
  1196         iDecodeInfo.iPrevChar = character;
       
  1197         }
       
  1198     aEndIndex--;
       
  1199     FTRACE(FPrint( _L("CDunAtCmdHandler::CheckBasicCommand() (not found) complete") ));
       
  1200     return KErrNotFound;
       
  1201     }
       
  1202 
       
  1203 // ---------------------------------------------------------------------------
       
  1204 // Check if any one character command
       
  1205 // ---------------------------------------------------------------------------
       
  1206 //
       
  1207 TBool CDunAtCmdHandler::IsOneCharacterCommand( TInt aIndex )
       
  1208     {
       
  1209     FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterCommand()") ));
       
  1210     if ( aIndex<0 || aIndex>=iInputBuffer.Length() )
       
  1211         {
       
  1212         FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterCommand() (index out of bounds) complete") ));
       
  1213         return EFalse;
       
  1214         }
       
  1215     TChar character = iInputBuffer[aIndex];
       
  1216     if ( character==',' || character==';' || character=='@'  || character=='!' ||
       
  1217          IsOneCharacterACommand(aIndex) )
       
  1218         {
       
  1219         FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterCommand() complete") ));
       
  1220         return ETrue;
       
  1221         }
       
  1222     FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterCommand() (not found) complete") ));
       
  1223     return EFalse;
       
  1224     }
       
  1225 
       
  1226 // ---------------------------------------------------------------------------
       
  1227 // Check if one character "A" command
       
  1228 // ---------------------------------------------------------------------------
       
  1229 //
       
  1230 TBool CDunAtCmdHandler::IsOneCharacterACommand( TInt aIndex )
       
  1231     {
       
  1232     FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterACommand()") ));
       
  1233     if ( aIndex<0 || aIndex>=iInputBuffer.Length() )
       
  1234         {
       
  1235         FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterACommand() (index out of bounds) complete") ));
       
  1236         return EFalse;
       
  1237         }
       
  1238     if ( iInputBuffer[aIndex]!='a' && iInputBuffer[aIndex]!='A' )
       
  1239         {
       
  1240         FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterACommand() (not found) complete") ));
       
  1241         return EFalse;
       
  1242         }
       
  1243     TBool prevAlpha = EFalse;
       
  1244     TBool nextAlpha = EFalse;
       
  1245     TBool nextSlash = EFalse;
       
  1246     TInt length = iInputBuffer.Length();
       
  1247     if ( iDecodeInfo.iPrevExists && iDecodeInfo.iPrevChar.IsAlpha() )
       
  1248         {
       
  1249         prevAlpha = ETrue;
       
  1250         }
       
  1251     if ( aIndex+1 < length )
       
  1252         {
       
  1253         TChar nextChar = iInputBuffer[aIndex+1];
       
  1254         if ( nextChar.IsAlpha() )
       
  1255             {
       
  1256             nextAlpha = ETrue;
       
  1257             }
       
  1258         if ( nextChar == '/' )
       
  1259             {
       
  1260             nextSlash = ETrue;
       
  1261             }
       
  1262         }
       
  1263     if ( prevAlpha || nextAlpha || nextSlash )
       
  1264         {
       
  1265         FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterACommand() (not found) complete") ));
       
  1266         return EFalse;
       
  1267         }
       
  1268     FTRACE(FPrint( _L("CDunAtCmdHandler::IsOneCharacterACommand() (complete) complete") ));
       
  1269     return ETrue;
       
  1270     }
       
  1271 
       
  1272 // ---------------------------------------------------------------------------
       
  1273 // Check if "A/" command
       
  1274 // ---------------------------------------------------------------------------
       
  1275 //
       
  1276 TBool CDunAtCmdHandler::IsASlashCommand()
       
  1277     {
       
  1278     FTRACE(FPrint( _L("CDunAtCmdHandler::IsASlashCommand()") ));
       
  1279     if ( iInputBuffer.Length() == 2 )
       
  1280         {
       
  1281         if ( iInputBuffer[1] == '/' &&
       
  1282             (iInputBuffer[0] == 'A' || iInputBuffer[0] == 'a') )
       
  1283             {
       
  1284             FTRACE(FPrint( _L("CDunAtCmdHandler::IsASlashCommand() (found) complete") ));
       
  1285             return ETrue;
       
  1286             }
       
  1287         }
       
  1288     FTRACE(FPrint( _L("CDunAtCmdHandler::IsASlashCommand() (not found) complete") ));
       
  1289     return EFalse;
       
  1290     }
       
  1291 
       
  1292 // ---------------------------------------------------------------------------
       
  1293 // Handles "A/" command
       
  1294 // ---------------------------------------------------------------------------
       
  1295 //
       
  1296 TBool CDunAtCmdHandler::HandleASlashCommand()
       
  1297     {
       
  1298     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleASlashCommand()") ));
       
  1299     // If not "A/" command, return
       
  1300     if ( !IsASlashCommand() )
       
  1301         {
       
  1302         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleASlashCommand() (no push) complete") ));
       
  1303         return EFalse;
       
  1304         }
       
  1305     // If "A/" command and last buffer exist, set the last buffer as the current buffer
       
  1306     if ( iLastBuffer.Length() > 0 )
       
  1307         {
       
  1308         iInputBuffer.Copy( iLastBuffer );
       
  1309         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleASlashCommand() (copy) complete") ));
       
  1310         return EFalse;
       
  1311         }
       
  1312     // Last buffer not set so return "ERROR" if quiet mode not on
       
  1313     if ( iQuietOn )
       
  1314         {
       
  1315         FTRACE(FPrint( _L("CDunAtCmdHandler::HandleASlashCommand() (quiet) complete") ));
       
  1316         return EFalse;
       
  1317         }
       
  1318     iDownstream->NotifyDataPushRequest( &iErrorBuffer, NULL );
       
  1319     FTRACE(FPrint( _L("CDunAtCmdHandler::HandleASlashCommand() complete") ));
       
  1320     return ETrue;
       
  1321     }
       
  1322 
       
  1323 // ---------------------------------------------------------------------------
       
  1324 // Resets parse buffers
       
  1325 // ---------------------------------------------------------------------------
       
  1326 //
       
  1327 void CDunAtCmdHandler::ResetParseBuffers( TBool aClearInput )
       
  1328     {
       
  1329     FTRACE(FPrint( _L("CDunAtCmdHandler::ResetParseBuffers()") ));
       
  1330     if ( aClearInput )
       
  1331         {
       
  1332         iInputBuffer.Zero();
       
  1333         }
       
  1334     iDecodeInfo.iFirstDecode = ETrue;
       
  1335     iDecodeInfo.iDecodeIndex = 0;
       
  1336     iDecodeInfo.iPrevExists = EFalse;
       
  1337     iDecodeInfo.iDecodeBuffer.Zero();
       
  1338     FTRACE(FPrint( _L("CDunAtCmdHandler::ResetParseBuffers() complete") ));
       
  1339     }
       
  1340 
       
  1341 // ---------------------------------------------------------------------------
       
  1342 // Manages command mode change
       
  1343 // ---------------------------------------------------------------------------
       
  1344 //
       
  1345 TBool CDunAtCmdHandler::ManageCommandModeChange( TUint aMode )
       
  1346     {
       
  1347     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCommandModeChange()" ) ));
       
  1348     if ( aMode & KCommandModeChanged )
       
  1349         {
       
  1350         if ( aMode & KModeCommand )  // command mode ON
       
  1351             {
       
  1352             ReportCommandModeChange( ETrue );
       
  1353             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCommandModeChange() command mode changed ON" ) ));
       
  1354             }
       
  1355         else  // command mode OFF
       
  1356             {
       
  1357             ReportCommandModeChange( EFalse );
       
  1358             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCommandModeChange() command mode changed OFF" ) ));
       
  1359             }
       
  1360         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCommandModeChange() (change) complete" ) ));
       
  1361         return ETrue;
       
  1362         }
       
  1363     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCommandModeChange()" ) ));
       
  1364     return EFalse;
       
  1365     }
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // Reports command mode start/end change
       
  1369 // ---------------------------------------------------------------------------
       
  1370 //
       
  1371 void CDunAtCmdHandler::ReportCommandModeChange( TBool aStart )
       
  1372     {
       
  1373     FTRACE(FPrint( _L("CDunAtCmdHandler::ReportCommandModeChange()" ) ));
       
  1374     TInt i;
       
  1375     TInt count = iCmdCallbacks.Count();
       
  1376     if ( aStart )
       
  1377         {
       
  1378         if ( iDataMode )
       
  1379             {
       
  1380             for ( i=0; i<count; i++ )
       
  1381                 {
       
  1382                 iCmdCallbacks[i]->NotifyCommandModeStart();
       
  1383                 }
       
  1384             iDataMode = EFalse;
       
  1385             }
       
  1386         }
       
  1387     else  // end
       
  1388         {
       
  1389         if ( !iDataMode )
       
  1390             {
       
  1391             for ( i=0; i<count; i++ )
       
  1392                 {
       
  1393                 iCmdCallbacks[i]->NotifyCommandModeEnd();
       
  1394                 }
       
  1395             iDataMode = ETrue;
       
  1396             }
       
  1397         }
       
  1398     FTRACE(FPrint( _L("CDunAtCmdHandler::ReportCommandModeChange() complete" ) ));
       
  1399     }
       
  1400 
       
  1401 // ---------------------------------------------------------------------------
       
  1402 // Manages echo mode change
       
  1403 // ---------------------------------------------------------------------------
       
  1404 //
       
  1405 TBool CDunAtCmdHandler::ManageEchoModeChange( TUint aMode )
       
  1406     {
       
  1407     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange()" ) ));
       
  1408     if ( aMode & KEchoModeChanged )
       
  1409         {
       
  1410         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() checking echo mode..." ) ));
       
  1411         if ( aMode & KModeEcho )  // echo mode ON
       
  1412             {
       
  1413             iEchoOn = ETrue;
       
  1414             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() echo mode changed ON" ) ));
       
  1415             }
       
  1416         else  // echo mode OFF
       
  1417             {
       
  1418             iEchoOn = EFalse;
       
  1419             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() echo mode changed OFF" ) ));
       
  1420             }
       
  1421         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() (change) complete" ) ));
       
  1422         return ETrue;
       
  1423         }
       
  1424     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() complete" ) ));
       
  1425     return EFalse;
       
  1426     }
       
  1427 
       
  1428 // ---------------------------------------------------------------------------
       
  1429 // Manages quiet mode change
       
  1430 // ---------------------------------------------------------------------------
       
  1431 //
       
  1432 TBool CDunAtCmdHandler::ManageQuietModeChange( TUint aMode )
       
  1433     {
       
  1434     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageQuietModeChange()" ) ));
       
  1435     if ( aMode & KQuietModeChanged )
       
  1436         {
       
  1437         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageEchoModeChange() checking quiet mode..." ) ));
       
  1438         if ( aMode & KModeQuiet )  // quiet mode ON
       
  1439             {
       
  1440             iAtCmdExt.ReportQuietModeChange( ETrue );
       
  1441             iQuietOn = ETrue;
       
  1442             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageQuietModeChange() quiet mode changed ON" ) ));
       
  1443             }
       
  1444         else  // quiet mode OFF
       
  1445             {
       
  1446             iAtCmdExt.ReportQuietModeChange( EFalse );
       
  1447             iQuietOn = EFalse;
       
  1448             FTRACE(FPrint( _L("CDunAtCmdHandler::ManageQuietModeChange() quiet mode changed OFF" ) ));
       
  1449             }
       
  1450         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageQuietModeChange() (change) complete" ) ));
       
  1451         return ETrue;
       
  1452         }
       
  1453     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageQuietModeChange() complete" ) ));
       
  1454     return EFalse;
       
  1455     }
       
  1456 
       
  1457 // ---------------------------------------------------------------------------
       
  1458 // Manages quiet mode change
       
  1459 // ---------------------------------------------------------------------------
       
  1460 //
       
  1461 TBool CDunAtCmdHandler::ManageVerboseModeChange( TUint aMode )
       
  1462     {
       
  1463     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageVerboseModeChange()" ) ));
       
  1464     if ( aMode & KVerboseModeChanged )
       
  1465         {
       
  1466         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageVerboseModeChange() checking verbose mode..." ) ));
       
  1467         if ( aMode & KModeVerbose )  // verbose mode ON
       
  1468             {
       
  1469             iAtCmdExt.ReportVerboseModeChange( ETrue );
       
  1470             FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyVerboseStatusChange() verbose mode changed ON" ) ));
       
  1471             }
       
  1472         else  // verbose mode OFF
       
  1473             {
       
  1474             iAtCmdExt.ReportVerboseModeChange( EFalse );
       
  1475             FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyVerboseStatusChange() verbose mode changed OFF" ) ));
       
  1476             }
       
  1477         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageVerboseModeChange() (change) complete" ) ));
       
  1478         return ETrue;
       
  1479         }
       
  1480     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageVerboseModeChange() complete" ) ));
       
  1481     return EFalse;
       
  1482     }
       
  1483 
       
  1484 // ---------------------------------------------------------------------------
       
  1485 // Manages character change
       
  1486 // ---------------------------------------------------------------------------
       
  1487 //
       
  1488 void CDunAtCmdHandler::ManageCharacterChange( TUint aMode )
       
  1489     {
       
  1490     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCharacterChange()" ) ));
       
  1491     if ( aMode & KCarriageChanged )
       
  1492         {
       
  1493         iCarriageReturn = aMode & (KModeChanged-1);
       
  1494         iAtCmdExt.ReportCharacterChange( ECharTypeCarriage, iCarriageReturn );
       
  1495         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCharacterChange() carriage return changed" ) ));
       
  1496         }
       
  1497     else if ( aMode & KLineFeedChanged )
       
  1498         {
       
  1499         iLineFeed = aMode & (KModeChanged-1);
       
  1500         iAtCmdExt.ReportCharacterChange( ECharTypeLineFeed, iLineFeed );
       
  1501         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCharacterChange() line feed changed" ) ));
       
  1502         }
       
  1503     else if ( aMode & KBackspaceChanged )
       
  1504         {
       
  1505         iBackspace = aMode & (KModeChanged-1);
       
  1506         iAtCmdExt.ReportCharacterChange( ECharTypeBackspace, iBackspace );
       
  1507         FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCharacterChange() backspace changed" ) ));
       
  1508         }
       
  1509     FTRACE(FPrint( _L("CDunAtCmdHandler::ManageCharacterChange() complete" ) ));
       
  1510     }
       
  1511 
       
  1512 // ---------------------------------------------------------------------------
       
  1513 // From class MDunAtCmdPusher.
       
  1514 // Notifies about end of AT command processing. This is after all reply data
       
  1515 // for an AT command is multiplexed to the downstream.
       
  1516 // ---------------------------------------------------------------------------
       
  1517 //
       
  1518 TInt CDunAtCmdHandler::NotifyEndOfProcessing( TInt /*aError*/ )
       
  1519     {
       
  1520     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyEndOfProcessing()" ) ));
       
  1521     HandleNextDecodedCommand();
       
  1522     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyEndOfProcessing() complete" ) ));
       
  1523     return KErrNone;
       
  1524     }
       
  1525 
       
  1526 // ---------------------------------------------------------------------------
       
  1527 // From class MDunAtCmdPusher.
       
  1528 // Notifies about request to stop AT command handling for the rest of the
       
  1529 // command line data
       
  1530 // ---------------------------------------------------------------------------
       
  1531 //
       
  1532 TInt CDunAtCmdHandler::NotifyEndOfCmdLineProcessing()
       
  1533     {
       
  1534     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyEndOfCmdLineProcessing()" ) ));
       
  1535     TInt retVal = Stop();
       
  1536     ManageEndOfCmdHandling( ETrue, EFalse, ETrue );
       
  1537     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyEndOfCmdLineProcessing() complete" ) ));
       
  1538     return retVal;
       
  1539     }
       
  1540 
       
  1541 // ---------------------------------------------------------------------------
       
  1542 // From class MDunAtCmdPusher.
       
  1543 // Notifies about request to peek for the next command
       
  1544 // ---------------------------------------------------------------------------
       
  1545 //
       
  1546 TBool CDunAtCmdHandler::NotifyNextCommandPeekRequest()
       
  1547     {
       
  1548     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyNextCommandPeekRequest()") ));
       
  1549     TBool extracted = ExtractNextDecodedCommand( ETrue );
       
  1550     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyNextCommandPeekRequest() complete") ));
       
  1551     return extracted;
       
  1552     }
       
  1553 
       
  1554 // ---------------------------------------------------------------------------
       
  1555 // From class MDunAtEcomListen.
       
  1556 // Notifies about new plugin installation
       
  1557 // ---------------------------------------------------------------------------
       
  1558 //
       
  1559 TInt CDunAtCmdHandler::NotifyPluginInstallation( TUid& /*aPluginUid*/ )
       
  1560     {
       
  1561     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginInstallation()" ) ));
       
  1562     CDunAtUrcHandler* urcHandler = NULL;
       
  1563     TRAPD( retTrap, urcHandler=AddOneUrcHandlerL() );
       
  1564     if ( retTrap != KErrNone )
       
  1565         {
       
  1566         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginInstallation() (trapped!) complete" ) ));
       
  1567         return retTrap;
       
  1568         }
       
  1569     TInt retTemp = urcHandler->IssueRequest();
       
  1570     if ( retTemp != KErrNone )
       
  1571         {
       
  1572         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginInstallation() (issuerequest) complete" ) ));
       
  1573         return retTemp;
       
  1574         }
       
  1575     TUid ownerUid = urcHandler->OwnerUid();
       
  1576     iAtCmdExt.ReportListenerUpdateReady( ownerUid, EEcomTypeInstall );
       
  1577     // As a last step recreate the special command data
       
  1578     retTemp = RecreateSpecialCommands();
       
  1579     if ( retTemp != KErrNone )
       
  1580         {
       
  1581         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginInstallation() (recreate) complete" ) ));
       
  1582         return retTemp;
       
  1583         }
       
  1584     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginInstallation() complete" ) ));
       
  1585     return KErrNone;
       
  1586     }
       
  1587 
       
  1588 // ---------------------------------------------------------------------------
       
  1589 // From class MDunAtEcomListen.
       
  1590 // Notifies about existing plugin uninstallation
       
  1591 // ---------------------------------------------------------------------------
       
  1592 //
       
  1593 TInt CDunAtCmdHandler::NotifyPluginUninstallation( TUid& aPluginUid )
       
  1594     {
       
  1595     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginUninstallation()" ) ));
       
  1596     TInt i;
       
  1597     TInt count = iUrcHandlers.Count();
       
  1598     for ( i=count-1; i>=0; i-- )
       
  1599         {
       
  1600         TUid ownerUid = iUrcHandlers[i]->OwnerUid();
       
  1601         if ( ownerUid == aPluginUid )
       
  1602             {
       
  1603             delete iUrcHandlers[i];
       
  1604             iUrcHandlers.Remove( i );
       
  1605             iAtCmdExt.ReportListenerUpdateReady( ownerUid,
       
  1606                                                  EEcomTypeUninstall );
       
  1607             }
       
  1608         }
       
  1609     // As a last step recreate the special command data
       
  1610     TInt retTemp = RecreateSpecialCommands();
       
  1611     if ( retTemp != KErrNone )
       
  1612         {
       
  1613         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginUninstallation() (recreate) complete" ) ));
       
  1614         return retTemp;
       
  1615         }
       
  1616     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyPluginUninstallation() complete" ) ));
       
  1617     return KErrNone;
       
  1618     }
       
  1619 
       
  1620 // ---------------------------------------------------------------------------
       
  1621 // From class MDunAtModeListen.
       
  1622 // Gets called on mode status change
       
  1623 // ---------------------------------------------------------------------------
       
  1624 //
       
  1625 TInt CDunAtCmdHandler::NotifyModeStatusChange( TUint aMode )
       
  1626     {
       
  1627     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange()") ));
       
  1628     TBool commandModeSet = ManageCommandModeChange( aMode );
       
  1629     TBool echoModeSet = ManageEchoModeChange( aMode );
       
  1630     TBool quietModeSet = ManageQuietModeChange( aMode );
       
  1631     TBool verboseModeSet = ManageVerboseModeChange( aMode );
       
  1632     if ( quietModeSet || verboseModeSet )
       
  1633         {
       
  1634         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() new settings: E=%d, Q=%d, V=%d"), iEchoOn, iQuietOn, iVerboseOn ));
       
  1635         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() (regenerate) mode set" ) ));
       
  1636         RegenerateReplyStrings();
       
  1637         return KErrNone;
       
  1638         }
       
  1639     // Keep the following after "quietModeSet || verboseModeSet" in order to
       
  1640     // regenerate the reply also if two modes change at the same time
       
  1641     if ( commandModeSet || echoModeSet )
       
  1642         {
       
  1643         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() new settings: E=%d, Q=%d, V=%d"), iEchoOn, iQuietOn, iVerboseOn ));
       
  1644         FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() mode set" ) ));
       
  1645         return KErrNone;
       
  1646         }
       
  1647     ManageCharacterChange( aMode );
       
  1648     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() new settings: CR=%u, LF=%u, BS=%u"), iCarriageReturn, iLineFeed, iBackspace ));
       
  1649     RegenerateReplyStrings();
       
  1650     FTRACE(FPrint( _L("CDunAtCmdHandler::NotifyModeStatusChange() complete") ));
       
  1651     return KErrNone;
       
  1652     }