cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp
branchRCL_3
changeset 16 95674584745d
parent 15 53b7818cd282
child 21 0ba996a9b75d
equal deleted inserted replaced
15:53b7818cd282 16:95674584745d
    26 #include "cbccommandhandler.h"
    26 #include "cbccommandhandler.h"
    27 
    27 
    28 #include "atmisccmdpluginconsts.h"
    28 #include "atmisccmdpluginconsts.h"
    29 #include "debug.h"
    29 #include "debug.h"
    30 
    30 
    31 #include <exterror.h>           // Additional RMobilePhone error code
    31 #include <EXTERROR.H>           // Additional RMobilePhone error code
    32 
       
    33 
    32 
    34 // +CME error code
    33 // +CME error code
    35 _LIT8(KCMEIncorrectPassword, "+CME: 16\r\n"); // Incorrect password.\r\n
    34 _LIT8(KCMEIncorrectPassword, "+CME ERROR: 16\r\n"); // Incorrect password.\r\n
    36 _LIT8(KCMEPUKRequired, "+CME: 12\r\n"); // PUK required.\r\n
    35 _LIT8(KCMEPUKRequired, "+CME ERROR: 12\r\n"); // PUK required.\r\n
    37 _LIT8(KCMENotAllowed, "+CME: 3\r\n"); // Operation not allowed.\r\n
    36 _LIT8(KCMENotAllowed, "+CME ERROR: 3\r\n"); // Operation not allowed.\r\n
    38 _LIT8(KCMEPhoneError, "+CME: 0\r\n"); // Phone failure.\r\n
    37 _LIT8(KCMEPhoneError, "+CME ERROR: 0\r\n"); // Phone failure.\r\n
    39 _LIT8(KCMEPhoneUnknown, "+CME: 100\r\n"); // unknown error
    38 _LIT8(KCMEPhoneUnknown, "+CME ERROR: 100\r\n"); // unknown error
    40 
    39 
    41 const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
    40 const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
    42 
    41 
    43 CATMiscCmdPlugin* CATMiscCmdPlugin::NewL()
    42 CATMiscCmdPlugin* CATMiscCmdPlugin::NewL()
    44     {
    43     {
   147         case (TAtCommandParser::ECmdAtCbc):
   146         case (TAtCommandParser::ECmdAtCbc):
   148             {
   147             {
   149             iCurrentHandler = iCBCHandler;
   148             iCurrentHandler = iCBCHandler;
   150             break;
   149             break;
   151             }
   150             }
       
   151         case (TAtCommandParser::ECmdAtCmee):
       
   152             {
       
   153             iCurrentHandler = NULL;
       
   154             break;
       
   155             }
   152         case (TAtCommandParser::EUnknown):
   156         case (TAtCommandParser::EUnknown):
   153         default:
   157         default:
   154             {
   158             {
   155             supported = EFalse;
   159             supported = EFalse;
   156             break;
   160             break;
   168                                      RBuf8& aReply,
   172                                      RBuf8& aReply,
   169                                      TBool aReplyNeeded )
   173                                      TBool aReplyNeeded )
   170 	{
   174 	{
   171 	TRACE_FUNC_ENTRY
   175 	TRACE_FUNC_ENTRY
   172 	
   176 	
   173 	if (iCurrentHandler != NULL)
   177 	if(iCommandParser.Command() == TAtCommandParser::ECmdAtCmee)
       
   178 	    {
       
   179         HandleCMEECommand();
       
   180         HandleCommandCompleted( KErrNone, EReplyTypeOk);
       
   181 	    }
       
   182 	else if (iCurrentHandler != NULL)
   174 	    {
   183 	    {
   175 	    iHcCmd = &aCmd;
   184 	    iHcCmd = &aCmd;
   176 	    iHcReply = &aReply;
   185 	    iHcReply = &aReply;
       
   186 	    // No need to parse the command again as assumed that
       
   187 	    // it is always called from CATMiscCmdPlugin::IsCommandSupported()
   177 	    iCurrentHandler->HandleCommand( aCmd, aReply, aReplyNeeded );
   188 	    iCurrentHandler->HandleCommand( aCmd, aReply, aReplyNeeded );
   178 	    }
   189 	    }
   179 	TRACE_FUNC_EXIT
   190 	TRACE_FUNC_EXIT
   180     }
   191     }
   181 
   192 
   454 
   465 
   455 void CATMiscCmdPlugin::CreateCMEReplyAndComplete(TInt aError)
   466 void CATMiscCmdPlugin::CreateCMEReplyAndComplete(TInt aError)
   456     {
   467     {
   457     TRACE_FUNC_ENTRY
   468     TRACE_FUNC_ENTRY
   458     
   469     
   459     // TODO should return CME error according to CME state (and quiet mode?)
   470     // currently only support +CME error level 0 and 1
   460     RBuf8 response;
   471     ASSERT(iErrorLevel == 0 || iErrorLevel == 1 );
   461     response.Create(KDefaultCmdBufLength);
   472     
   462     
   473     // Log error code
   463     // log error code
   474     Trace(KDebugPrintD, "complete with error ", aError);
   464     response.AppendNum(aError);
   475     
   465     Trace(KDebugPrintD, "complete with error ", &response);
   476     if(iErrorLevel == 1 && !iQuietMode)
   466     
   477         {
   467     // return error code to AT client
   478         // return error code to AT client
   468     response.Zero(); // reuse RBuf
   479         RBuf8 response;
   469     response.Append(KCRLF);
   480         response.Create(KDefaultCmdBufLength);
   470     switch(aError)
   481         response.Append(KCRLF);
   471         {
   482         switch(aError)
   472         case KErrGsm0707IncorrectPassword:
   483             {
   473         case KErrAccessDenied:
   484             case KErrGsm0707IncorrectPassword:
   474             {    
   485             case KErrAccessDenied:
   475             // code was entered erroneously
   486                 {    
   476             response.Append(KCMEIncorrectPassword);
   487                 // code was entered erroneously
   477             break;
   488                 response.Append(KCMEIncorrectPassword);
   478             }    
   489                 break;
   479         case KErrGsmSSPasswordAttemptsViolation:
   490                 }
   480         case KErrLocked:
   491             case KErrGsmSSPasswordAttemptsViolation:
   481             {
   492             case KErrLocked:
   482             // Pin blocked 
   493                 {
   483             response.Append(KCMEPUKRequired);
   494                 // Pin blocked 
   484             break;
   495                 response.Append(KCMEPUKRequired);
   485             }
   496                 break;
   486         case KErrGsm0707OperationNotAllowed:
   497                 }
   487             {
   498             case KErrGsm0707OperationNotAllowed:
   488             // not allowed with this sim
   499                 {
   489             response.Append(KCMENotAllowed);
   500                 // not allowed with this sim
   490             break;
   501                 response.Append(KCMENotAllowed);
   491             }
   502                 break;
   492         case KErrUnknown:
   503                 }
   493             {
   504             case KErrUnknown:
   494             // unknown error
   505                 {
   495             response.Append(KCMEPhoneUnknown);
   506                 // unknown error
   496             break;
   507                 response.Append(KCMEPhoneUnknown);
   497             }
   508                 break;
   498         default:
   509                 }
   499             response.Append(KCMEPhoneError);
   510             default:
   500         }
   511                 {
   501     CreateReplyAndComplete( EReplyTypeError, response );
   512                 response.Append(KCMEPhoneError);
   502     response.Close();
   513                 break;
   503     TRACE_FUNC_EXIT
   514                 }
   504     }
   515             }
   505 
   516         CreateReplyAndComplete( EReplyTypeError, response );
       
   517         response.Close();
       
   518         }
       
   519     else
       
   520         {
       
   521         CreateReplyAndComplete( EReplyTypeError);
       
   522         }
       
   523 
       
   524     TRACE_FUNC_EXIT
       
   525     }
   506 
   526 
   507 TInt CATMiscCmdPlugin::HandleUnsolicitedRequest(const TDesC8& aAT )
   527 TInt CATMiscCmdPlugin::HandleUnsolicitedRequest(const TDesC8& aAT )
   508     {
   528     {
       
   529     TRACE_FUNC_ENTRY
       
   530     TRACE_FUNC_EXIT
   509     return SendUnsolicitedResult(aAT);
   531     return SendUnsolicitedResult(aAT);
       
   532     }
       
   533 
       
   534 void CATMiscCmdPlugin::HandleCMEECommand()
       
   535     {
       
   536     TRACE_FUNC_ENTRY
       
   537     TAtCommandParser::TCommandHandlerType cmdHandlerType = iCommandParser.CommandHandlerType();
       
   538     
       
   539     if (cmdHandlerType == TAtCommandParser::ECmdHandlerTypeSet)
       
   540         {
       
   541         // +CMEE=n
       
   542         TInt errLevel;
       
   543         TInt ret = iCommandParser.NextIntParam(errLevel);
       
   544         TPtrC8 param = iCommandParser.NextParam();
       
   545         _LIT8(KCMEDbg, "CME : NextIntParam returned %d, NextParam Length is %d, errLevel %d\r\n");
       
   546         Trace(KCMEDbg, ret, param.Length(), errLevel);
       
   547         if (ret == KErrNone && param.Length() == 0 &&
       
   548            (errLevel == 0 || errLevel == 1))
       
   549             {
       
   550             iErrorLevel = errLevel;
       
   551             _LIT8(KCMEErrorLevel, "CME error level: %d\r\n");
       
   552             Trace(KCMEErrorLevel, iErrorLevel);
       
   553             }
       
   554         }
       
   555     TRACE_FUNC_EXIT
   510     }
   556     }
   511 
   557 
   512 void CATMiscCmdPlugin::ConnectToEtelL(RTelServer& aTelServer, RMobilePhone& aPhone)
   558 void CATMiscCmdPlugin::ConnectToEtelL(RTelServer& aTelServer, RMobilePhone& aPhone)
   513     {
   559     {
   514     TRACE_FUNC_ENTRY
   560     TRACE_FUNC_ENTRY
   519     RTelServer::TPhoneInfo info;
   565     RTelServer::TPhoneInfo info;
   520 
   566 
   521     User::LeaveIfError(aTelServer.EnumeratePhones(phoneCount));  
   567     User::LeaveIfError(aTelServer.EnumeratePhones(phoneCount));  
   522     if (phoneCount < 1)
   568     if (phoneCount < 1)
   523         {
   569         {
   524         User::Leave(KErrNotFound); // TODO: appropriate error code
   570         User::Leave(KErrNotFound);
   525         }
   571         }
   526     User::LeaveIfError(aTelServer.GetPhoneInfo(0, info));
   572     User::LeaveIfError(aTelServer.GetPhoneInfo(0, info));
   527     User::LeaveIfError(aPhone.Open(aTelServer, info.iName));
   573     User::LeaveIfError(aPhone.Open(aTelServer, info.iName));
   528     TRACE_FUNC_EXIT
   574     TRACE_FUNC_EXIT
   529     }
   575     }
       
   576