cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp
author hgs
Sat, 24 Apr 2010 00:30:17 +0300
changeset 26 b78e66e88238
child 21 53b7818cd282
permissions -rw-r--r--
201015
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Main handler for incoming requests
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "atmisccmdplugin.h"
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include "clckcommandhandler.h"
hgs
parents:
diff changeset
    21
#include "cpwdcommandhandler.h"
hgs
parents:
diff changeset
    22
#include "cpincommandhandler.h"
hgs
parents:
diff changeset
    23
#include "cusdcommandhandler.h"
hgs
parents:
diff changeset
    24
#include "cnumcommandhandler.h"
hgs
parents:
diff changeset
    25
#include "cfuncommandhandler.h"
hgs
parents:
diff changeset
    26
#include "cbccommandhandler.h"
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include "atmisccmdpluginconsts.h"
hgs
parents:
diff changeset
    29
#include "debug.h"
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
#include <EXTERROR.H>           // Additional RMobilePhone error code
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
// +CME error code
hgs
parents:
diff changeset
    35
_LIT8(KCMEIncorrectPassword, "+CME: 16\r\n"); // Incorrect password.\r\n
hgs
parents:
diff changeset
    36
_LIT8(KCMEPUKRequired, "+CME: 12\r\n"); // PUK required.\r\n
hgs
parents:
diff changeset
    37
_LIT8(KCMENotAllowed, "+CME: 3\r\n"); // Operation not allowed.\r\n
hgs
parents:
diff changeset
    38
_LIT8(KCMEPhoneError, "+CME: 0\r\n"); // Phone failure.\r\n
hgs
parents:
diff changeset
    39
_LIT8(KCMEPhoneUnknown, "+CME: 100\r\n"); // unknown error
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
CATMiscCmdPlugin* CATMiscCmdPlugin::NewL()
hgs
parents:
diff changeset
    44
    {
hgs
parents:
diff changeset
    45
    CATMiscCmdPlugin* self = new (ELeave) CATMiscCmdPlugin();
hgs
parents:
diff changeset
    46
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    47
    self->ConstructL();
hgs
parents:
diff changeset
    48
    CleanupStack::Pop(self);
hgs
parents:
diff changeset
    49
    return self;
hgs
parents:
diff changeset
    50
    }
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
CATMiscCmdPlugin::~CATMiscCmdPlugin()
hgs
parents:
diff changeset
    53
	{
hgs
parents:
diff changeset
    54
    iReplyBuffer.Close();
hgs
parents:
diff changeset
    55
    
hgs
parents:
diff changeset
    56
    delete iCLCKHandler;
hgs
parents:
diff changeset
    57
    delete iCPWDHandler;
hgs
parents:
diff changeset
    58
    delete iCPINHandler;
hgs
parents:
diff changeset
    59
    delete iCUSDHandler;
hgs
parents:
diff changeset
    60
    delete iCNUMHandler;
hgs
parents:
diff changeset
    61
    delete iCFUNHandler;
hgs
parents:
diff changeset
    62
    delete iCBCHandler;
hgs
parents:
diff changeset
    63
    
hgs
parents:
diff changeset
    64
    iPhone.Close();
hgs
parents:
diff changeset
    65
    iTelServer.Close();
hgs
parents:
diff changeset
    66
	}
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
CATMiscCmdPlugin::CATMiscCmdPlugin() : 
hgs
parents:
diff changeset
    69
    CATExtPluginBase()
hgs
parents:
diff changeset
    70
    {
hgs
parents:
diff changeset
    71
    }
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
void CATMiscCmdPlugin::ConstructL()
hgs
parents:
diff changeset
    74
    {
hgs
parents:
diff changeset
    75
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    76
    ConnectToEtelL(iTelServer, iPhone);
hgs
parents:
diff changeset
    77
    
hgs
parents:
diff changeset
    78
    iCLCKHandler = CCLCKCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    79
    iCPWDHandler = CCPWDCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    80
    iCUSDHandler = CCUSDCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    81
    iCPINHandler = CCPINCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    82
    iCNUMHandler = CCNUMCommandHandler::NewL(this, iCommandParser, iPhone, iTelServer);
hgs
parents:
diff changeset
    83
    iCFUNHandler = CCFUNCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    84
    iCBCHandler = CCBCCommandHandler::NewL(this, iCommandParser, iPhone);
hgs
parents:
diff changeset
    85
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    86
   	}
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
/**
hgs
parents:
diff changeset
    89
 * @see CATExtPluginBase::ReportConnectionName
hgs
parents:
diff changeset
    90
 */
hgs
parents:
diff changeset
    91
void CATMiscCmdPlugin::ReportConnectionName( const TDesC8& /*aName*/ )
hgs
parents:
diff changeset
    92
    {
hgs
parents:
diff changeset
    93
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    94
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    95
    }
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
/**
hgs
parents:
diff changeset
    98
 * @see CATExtPluginBase::IsCommandSupported
hgs
parents:
diff changeset
    99
 */
hgs
parents:
diff changeset
   100
TBool CATMiscCmdPlugin::IsCommandSupported( const TDesC8& aCmd )
hgs
parents:
diff changeset
   101
    {
hgs
parents:
diff changeset
   102
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   103
    iHcCmd = NULL;
hgs
parents:
diff changeset
   104
    iHcReply = NULL;
hgs
parents:
diff changeset
   105
    iCurrentHandler = NULL;
hgs
parents:
diff changeset
   106
    TBool supported = ETrue;
hgs
parents:
diff changeset
   107
    
hgs
parents:
diff changeset
   108
    Trace(KDebugPrintS, "aCmd: ", &aCmd);
hgs
parents:
diff changeset
   109
    
hgs
parents:
diff changeset
   110
    iCommandParser.ParseAtCommand(aCmd);
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
    Trace(KDebugPrintD, "Command: ", iCommandParser.Command());
hgs
parents:
diff changeset
   113
    // TODO: check if the type is supported?
hgs
parents:
diff changeset
   114
    // iCommandParser.CommandHandlerType() != TAtCommandParser::ECmdHandlerTypeUndefined
hgs
parents:
diff changeset
   115
    switch (iCommandParser.Command())
hgs
parents:
diff changeset
   116
        {
hgs
parents:
diff changeset
   117
        case (TAtCommandParser::ECmdAtClck):
hgs
parents:
diff changeset
   118
            {
hgs
parents:
diff changeset
   119
            iCurrentHandler = iCLCKHandler;
hgs
parents:
diff changeset
   120
            break;
hgs
parents:
diff changeset
   121
            }
hgs
parents:
diff changeset
   122
        case (TAtCommandParser::ECmdAtCpwd):
hgs
parents:
diff changeset
   123
            {
hgs
parents:
diff changeset
   124
            iCurrentHandler = iCPWDHandler;
hgs
parents:
diff changeset
   125
            break;
hgs
parents:
diff changeset
   126
            }
hgs
parents:
diff changeset
   127
        case (TAtCommandParser::ECmdAtCpin):
hgs
parents:
diff changeset
   128
            {
hgs
parents:
diff changeset
   129
            iCurrentHandler = iCPINHandler;
hgs
parents:
diff changeset
   130
            break;
hgs
parents:
diff changeset
   131
            }
hgs
parents:
diff changeset
   132
        case (TAtCommandParser::ECmdAtCusd):
hgs
parents:
diff changeset
   133
            {
hgs
parents:
diff changeset
   134
            iCurrentHandler = iCUSDHandler;
hgs
parents:
diff changeset
   135
            break;
hgs
parents:
diff changeset
   136
            }   
hgs
parents:
diff changeset
   137
        case (TAtCommandParser::ECmdAtCnum):
hgs
parents:
diff changeset
   138
            {
hgs
parents:
diff changeset
   139
            iCurrentHandler = iCNUMHandler;
hgs
parents:
diff changeset
   140
            break;
hgs
parents:
diff changeset
   141
            }
hgs
parents:
diff changeset
   142
        case (TAtCommandParser::ECmdAtCfun):
hgs
parents:
diff changeset
   143
            {
hgs
parents:
diff changeset
   144
            iCurrentHandler = iCFUNHandler;
hgs
parents:
diff changeset
   145
            break;
hgs
parents:
diff changeset
   146
            }
hgs
parents:
diff changeset
   147
        case (TAtCommandParser::ECmdAtCbc):
hgs
parents:
diff changeset
   148
            {
hgs
parents:
diff changeset
   149
            iCurrentHandler = iCBCHandler;
hgs
parents:
diff changeset
   150
            break;
hgs
parents:
diff changeset
   151
            }
hgs
parents:
diff changeset
   152
        case (TAtCommandParser::EUnknown):
hgs
parents:
diff changeset
   153
        default:
hgs
parents:
diff changeset
   154
            {
hgs
parents:
diff changeset
   155
            supported = EFalse;
hgs
parents:
diff changeset
   156
            break;
hgs
parents:
diff changeset
   157
            }
hgs
parents:
diff changeset
   158
        }
hgs
parents:
diff changeset
   159
    Trace(KDebugPrintD, "supported: ", supported);
hgs
parents:
diff changeset
   160
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   161
    return supported;
hgs
parents:
diff changeset
   162
	}
hgs
parents:
diff changeset
   163
hgs
parents:
diff changeset
   164
/**
hgs
parents:
diff changeset
   165
 * @see CATExtPluginBase::HandleCommand
hgs
parents:
diff changeset
   166
 */
hgs
parents:
diff changeset
   167
void CATMiscCmdPlugin::HandleCommand( const TDesC8& aCmd,
hgs
parents:
diff changeset
   168
                                     RBuf8& aReply,
hgs
parents:
diff changeset
   169
                                     TBool aReplyNeeded )
hgs
parents:
diff changeset
   170
	{
hgs
parents:
diff changeset
   171
	TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   172
	
hgs
parents:
diff changeset
   173
	if (iCurrentHandler != NULL)
hgs
parents:
diff changeset
   174
	    {
hgs
parents:
diff changeset
   175
	    iHcCmd = &aCmd;
hgs
parents:
diff changeset
   176
	    iHcReply = &aReply;
hgs
parents:
diff changeset
   177
	    iCurrentHandler->HandleCommand( aCmd, aReply, aReplyNeeded );
hgs
parents:
diff changeset
   178
	    }
hgs
parents:
diff changeset
   179
	TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   180
    }
hgs
parents:
diff changeset
   181
hgs
parents:
diff changeset
   182
/**
hgs
parents:
diff changeset
   183
 * @see CATExtPluginBase::HandleCommandCancel
hgs
parents:
diff changeset
   184
 */
hgs
parents:
diff changeset
   185
void CATMiscCmdPlugin::HandleCommandCancel()
hgs
parents:
diff changeset
   186
    {
hgs
parents:
diff changeset
   187
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   188
    if (iCurrentHandler != NULL)
hgs
parents:
diff changeset
   189
	    {
hgs
parents:
diff changeset
   190
	    iCurrentHandler->HandleCommandCancel();
hgs
parents:
diff changeset
   191
	    }
hgs
parents:
diff changeset
   192
	TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   193
    }
hgs
parents:
diff changeset
   194
hgs
parents:
diff changeset
   195
/**
hgs
parents:
diff changeset
   196
 * @see CATExtPluginBase::NextReplyPartLength
hgs
parents:
diff changeset
   197
 */
hgs
parents:
diff changeset
   198
TInt CATMiscCmdPlugin::NextReplyPartLength()
hgs
parents:
diff changeset
   199
    {
hgs
parents:
diff changeset
   200
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   201
    TInt length = iReplyBuffer.Length();
hgs
parents:
diff changeset
   202
    if ( length >= KDefaultCmdBufLength )
hgs
parents:
diff changeset
   203
        {
hgs
parents:
diff changeset
   204
        length = KDefaultCmdBufLength;
hgs
parents:
diff changeset
   205
        }
hgs
parents:
diff changeset
   206
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   207
    return length;
hgs
parents:
diff changeset
   208
    }
hgs
parents:
diff changeset
   209
hgs
parents:
diff changeset
   210
/**
hgs
parents:
diff changeset
   211
 * @see CATExtPluginBase::GetNextPartOfReply
hgs
parents:
diff changeset
   212
 */
hgs
parents:
diff changeset
   213
TInt CATMiscCmdPlugin::GetNextPartOfReply( RBuf8& aNextReply )
hgs
parents:
diff changeset
   214
    {
hgs
parents:
diff changeset
   215
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   216
    TInt retVal = CreatePartOfReply( aNextReply );
hgs
parents:
diff changeset
   217
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   218
    return retVal;
hgs
parents:
diff changeset
   219
    }
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
/**
hgs
parents:
diff changeset
   222
 * @see CATExtPluginBase::ReceiveUnsolicitedResult
hgs
parents:
diff changeset
   223
 */
hgs
parents:
diff changeset
   224
void CATMiscCmdPlugin::ReceiveUnsolicitedResult()
hgs
parents:
diff changeset
   225
    {
hgs
parents:
diff changeset
   226
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   227
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   228
    }
hgs
parents:
diff changeset
   229
hgs
parents:
diff changeset
   230
/**
hgs
parents:
diff changeset
   231
 * @see CATExtPluginBase::ReceiveUnsolicitedResultCancel
hgs
parents:
diff changeset
   232
 */
hgs
parents:
diff changeset
   233
void CATMiscCmdPlugin::ReceiveUnsolicitedResultCancel()
hgs
parents:
diff changeset
   234
    {
hgs
parents:
diff changeset
   235
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   236
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   237
    }
hgs
parents:
diff changeset
   238
hgs
parents:
diff changeset
   239
/**
hgs
parents:
diff changeset
   240
 * @see CATExtPluginBase::ReportNvramStatusChange
hgs
parents:
diff changeset
   241
 */
hgs
parents:
diff changeset
   242
void CATMiscCmdPlugin::ReportNvramStatusChange( const TDesC8& /*aNvram*/ )
hgs
parents:
diff changeset
   243
    {
hgs
parents:
diff changeset
   244
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   245
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   246
    }
hgs
parents:
diff changeset
   247
hgs
parents:
diff changeset
   248
/**
hgs
parents:
diff changeset
   249
 * @see CATExtPluginBase::ReportExternalHandleCommandError
hgs
parents:
diff changeset
   250
 */
hgs
parents:
diff changeset
   251
void CATMiscCmdPlugin::ReportExternalHandleCommandError()
hgs
parents:
diff changeset
   252
    {
hgs
parents:
diff changeset
   253
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   254
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   255
    }
hgs
parents:
diff changeset
   256
hgs
parents:
diff changeset
   257
/**
hgs
parents:
diff changeset
   258
 * Creates part of reply from the global reply buffer to the destination
hgs
parents:
diff changeset
   259
 * buffer. Used with APIs which need the next part of reply in multipart
hgs
parents:
diff changeset
   260
 * reply requests.
hgs
parents:
diff changeset
   261
 *
hgs
parents:
diff changeset
   262
 * @param aBuffer Destination buffer; the next part of reply is stored to
hgs
parents:
diff changeset
   263
 *                   this buffer.
hgs
parents:
diff changeset
   264
 * @return None
hgs
parents:
diff changeset
   265
 */
hgs
parents:
diff changeset
   266
TInt CATMiscCmdPlugin::CreatePartOfReply( RBuf8& aBuffer )
hgs
parents:
diff changeset
   267
    {
hgs
parents:
diff changeset
   268
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   269
    TInt ret = KErrNone;
hgs
parents:
diff changeset
   270
    TInt partLength;
hgs
parents:
diff changeset
   271
    if ( iReplyBuffer.Length() <= 0 )
hgs
parents:
diff changeset
   272
        {
hgs
parents:
diff changeset
   273
        ret = KErrGeneral;
hgs
parents:
diff changeset
   274
        }
hgs
parents:
diff changeset
   275
    else
hgs
parents:
diff changeset
   276
        {
hgs
parents:
diff changeset
   277
        partLength = NextReplyPartLength();
hgs
parents:
diff changeset
   278
        if ( iReplyBuffer.Length() < partLength )
hgs
parents:
diff changeset
   279
            {
hgs
parents:
diff changeset
   280
            ret =  KErrNotFound;
hgs
parents:
diff changeset
   281
            }
hgs
parents:
diff changeset
   282
        }
hgs
parents:
diff changeset
   283
    Trace(KDebugPrintD, "ret: ", ret);
hgs
parents:
diff changeset
   284
    if (ret == KErrNone)
hgs
parents:
diff changeset
   285
        {
hgs
parents:
diff changeset
   286
        aBuffer.Create( iReplyBuffer, partLength );
hgs
parents:
diff changeset
   287
        iReplyBuffer.Delete( 0, partLength );
hgs
parents:
diff changeset
   288
        if ( iReplyBuffer.Length() == 0 )
hgs
parents:
diff changeset
   289
            {
hgs
parents:
diff changeset
   290
            iReplyBuffer.Close();
hgs
parents:
diff changeset
   291
            }
hgs
parents:
diff changeset
   292
        }
hgs
parents:
diff changeset
   293
hgs
parents:
diff changeset
   294
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   295
    return ret;
hgs
parents:
diff changeset
   296
    }
hgs
parents:
diff changeset
   297
hgs
parents:
diff changeset
   298
/**
hgs
parents:
diff changeset
   299
 * @see MATMiscCmdPlugin::CreateReplyAndComplete
hgs
parents:
diff changeset
   300
 */
hgs
parents:
diff changeset
   301
TInt CATMiscCmdPlugin::CreateReplyAndComplete( TATExtensionReplyType aReplyType,
hgs
parents:
diff changeset
   302
                                              const TDesC8& aSrcBuffer,
hgs
parents:
diff changeset
   303
											  TInt aError )
hgs
parents:
diff changeset
   304
    {
hgs
parents:
diff changeset
   305
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   306
    iReplyBuffer.Close();
hgs
parents:
diff changeset
   307
    Trace(KDebugPrintD, "aError: ", aError);
hgs
parents:
diff changeset
   308
    if ( aError != KErrNone )
hgs
parents:
diff changeset
   309
        {
hgs
parents:
diff changeset
   310
        HandleCommandCompleted( aError, EReplyTypeUndefined );
hgs
parents:
diff changeset
   311
        iHcCmd = NULL;
hgs
parents:
diff changeset
   312
        iHcReply = NULL;
hgs
parents:
diff changeset
   313
        iCurrentHandler = NULL;
hgs
parents:
diff changeset
   314
        TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   315
        return KErrNone;
hgs
parents:
diff changeset
   316
        }
hgs
parents:
diff changeset
   317
    
hgs
parents:
diff changeset
   318
    Trace(KDebugPrintS, "iHcReply: ", &iHcReply);
hgs
parents:
diff changeset
   319
    if (iHcReply == NULL)
hgs
parents:
diff changeset
   320
        {
hgs
parents:
diff changeset
   321
        TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   322
        return KErrGeneral;
hgs
parents:
diff changeset
   323
        }
hgs
parents:
diff changeset
   324
    
hgs
parents:
diff changeset
   325
    Trace(KDebugPrintD, "iQuietMode: ", iQuietMode);
hgs
parents:
diff changeset
   326
    if ( iQuietMode )
hgs
parents:
diff changeset
   327
        {
hgs
parents:
diff changeset
   328
        iReplyBuffer.Create( KNullDesC8 );
hgs
parents:
diff changeset
   329
        }
hgs
parents:
diff changeset
   330
    else
hgs
parents:
diff changeset
   331
        {
hgs
parents:
diff changeset
   332
        iReplyBuffer.Create( aSrcBuffer );
hgs
parents:
diff changeset
   333
        }
hgs
parents:
diff changeset
   334
    
hgs
parents:
diff changeset
   335
    Trace(KDebugPrintD, "aReplyType: ", aReplyType);
hgs
parents:
diff changeset
   336
    switch ( aReplyType )
hgs
parents:
diff changeset
   337
        {
hgs
parents:
diff changeset
   338
        case EReplyTypeOther:
hgs
parents:
diff changeset
   339
            break;
hgs
parents:
diff changeset
   340
        case EReplyTypeOk:
hgs
parents:
diff changeset
   341
            CreateOkOrErrorReply( iReplyBuffer, ETrue );
hgs
parents:
diff changeset
   342
            break;
hgs
parents:
diff changeset
   343
        case EReplyTypeError:
hgs
parents:
diff changeset
   344
            CreateOkOrErrorReply( iReplyBuffer, EFalse );
hgs
parents:
diff changeset
   345
            break;
hgs
parents:
diff changeset
   346
        default:
hgs
parents:
diff changeset
   347
            TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   348
            return KErrGeneral;
hgs
parents:
diff changeset
   349
        }
hgs
parents:
diff changeset
   350
    CreatePartOfReply( *iHcReply );
hgs
parents:
diff changeset
   351
    HandleCommandCompleted( KErrNone, aReplyType );
hgs
parents:
diff changeset
   352
    iHcCmd = NULL;
hgs
parents:
diff changeset
   353
    iHcReply = NULL;
hgs
parents:
diff changeset
   354
    iCurrentHandler = NULL;
hgs
parents:
diff changeset
   355
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   356
    return KErrNone;
hgs
parents:
diff changeset
   357
    }
hgs
parents:
diff changeset
   358
hgs
parents:
diff changeset
   359
/**
hgs
parents:
diff changeset
   360
 * @see MATMiscCmdPlugin::CreateOkOrErrorReply
hgs
parents:
diff changeset
   361
 */
hgs
parents:
diff changeset
   362
TInt CATMiscCmdPlugin::CreateOkOrErrorReply( RBuf8& aReplyBuffer,
hgs
parents:
diff changeset
   363
                                            TBool aOkReply )
hgs
parents:
diff changeset
   364
    {
hgs
parents:
diff changeset
   365
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   366
    _LIT8( KErrorReplyVerbose, "ERROR" );
hgs
parents:
diff changeset
   367
    _LIT8( KOkReplyVerbose,    "OK" );
hgs
parents:
diff changeset
   368
    _LIT8( KErrorReplyNumeric, "4" );
hgs
parents:
diff changeset
   369
    _LIT8( KOkReplyNumeric,    "0" );
hgs
parents:
diff changeset
   370
    TBuf8<KErrorReplyLength> replyBuffer;
hgs
parents:
diff changeset
   371
    if ( iVerboseMode )
hgs
parents:
diff changeset
   372
        {
hgs
parents:
diff changeset
   373
        replyBuffer.Append( iCarriageReturn );
hgs
parents:
diff changeset
   374
        replyBuffer.Append( iLineFeed );
hgs
parents:
diff changeset
   375
        if ( aOkReply )
hgs
parents:
diff changeset
   376
            {
hgs
parents:
diff changeset
   377
            replyBuffer.Append( KOkReplyVerbose );
hgs
parents:
diff changeset
   378
            }
hgs
parents:
diff changeset
   379
        else
hgs
parents:
diff changeset
   380
            {
hgs
parents:
diff changeset
   381
            replyBuffer.Append( KErrorReplyVerbose );
hgs
parents:
diff changeset
   382
            }
hgs
parents:
diff changeset
   383
        replyBuffer.Append( iCarriageReturn );
hgs
parents:
diff changeset
   384
        replyBuffer.Append( iLineFeed );
hgs
parents:
diff changeset
   385
        }
hgs
parents:
diff changeset
   386
    else
hgs
parents:
diff changeset
   387
        {
hgs
parents:
diff changeset
   388
        if ( aOkReply )
hgs
parents:
diff changeset
   389
            {
hgs
parents:
diff changeset
   390
            replyBuffer.Append( KOkReplyNumeric );
hgs
parents:
diff changeset
   391
            }
hgs
parents:
diff changeset
   392
        else
hgs
parents:
diff changeset
   393
            {
hgs
parents:
diff changeset
   394
            replyBuffer.Append( KErrorReplyNumeric );
hgs
parents:
diff changeset
   395
            }
hgs
parents:
diff changeset
   396
        replyBuffer.Append( iCarriageReturn );
hgs
parents:
diff changeset
   397
        }
hgs
parents:
diff changeset
   398
hgs
parents:
diff changeset
   399
    aReplyBuffer.ReAlloc(aReplyBuffer.Length() + replyBuffer.Length());
hgs
parents:
diff changeset
   400
    aReplyBuffer.Append( replyBuffer );
hgs
parents:
diff changeset
   401
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   402
    return KErrNone;
hgs
parents:
diff changeset
   403
    }
hgs
parents:
diff changeset
   404
hgs
parents:
diff changeset
   405
/**
hgs
parents:
diff changeset
   406
 * @see MATMiscCmdPlugin::GetCharacterValue
hgs
parents:
diff changeset
   407
 */
hgs
parents:
diff changeset
   408
TInt CATMiscCmdPlugin::GetCharacterValue( TCharacterTypes aCharType,
hgs
parents:
diff changeset
   409
                                         TChar& aChar )
hgs
parents:
diff changeset
   410
    {
hgs
parents:
diff changeset
   411
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   412
    TInt retVal = KErrNone;
hgs
parents:
diff changeset
   413
    switch ( aCharType )
hgs
parents:
diff changeset
   414
        {
hgs
parents:
diff changeset
   415
        case ECharTypeCR:
hgs
parents:
diff changeset
   416
            aChar = iCarriageReturn;
hgs
parents:
diff changeset
   417
            break;
hgs
parents:
diff changeset
   418
        case ECharTypeLF:
hgs
parents:
diff changeset
   419
            aChar = iLineFeed;
hgs
parents:
diff changeset
   420
            break;
hgs
parents:
diff changeset
   421
        case ECharTypeBS:
hgs
parents:
diff changeset
   422
            aChar = iBackspace;
hgs
parents:
diff changeset
   423
            break;
hgs
parents:
diff changeset
   424
        default:
hgs
parents:
diff changeset
   425
            retVal = KErrNotFound;
hgs
parents:
diff changeset
   426
            break;
hgs
parents:
diff changeset
   427
        }
hgs
parents:
diff changeset
   428
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   429
    return retVal;
hgs
parents:
diff changeset
   430
    }
hgs
parents:
diff changeset
   431
hgs
parents:
diff changeset
   432
/**
hgs
parents:
diff changeset
   433
 * @see MATMiscCmdPlugin::GetModeValue
hgs
parents:
diff changeset
   434
 */
hgs
parents:
diff changeset
   435
TInt CATMiscCmdPlugin::GetModeValue( TModeTypes aModeType, TBool& aMode )
hgs
parents:
diff changeset
   436
    {
hgs
parents:
diff changeset
   437
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   438
    TInt retVal = KErrNone;
hgs
parents:
diff changeset
   439
    switch ( aModeType )
hgs
parents:
diff changeset
   440
        {
hgs
parents:
diff changeset
   441
        case EModeTypeQuiet:
hgs
parents:
diff changeset
   442
            aMode = iQuietMode;
hgs
parents:
diff changeset
   443
            break;
hgs
parents:
diff changeset
   444
        case EModeTypeVerbose:
hgs
parents:
diff changeset
   445
            aMode = iVerboseMode;
hgs
parents:
diff changeset
   446
            break;
hgs
parents:
diff changeset
   447
        default:
hgs
parents:
diff changeset
   448
            retVal = KErrNotFound;
hgs
parents:
diff changeset
   449
            break;
hgs
parents:
diff changeset
   450
        }
hgs
parents:
diff changeset
   451
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   452
    return retVal;
hgs
parents:
diff changeset
   453
    }
hgs
parents:
diff changeset
   454
hgs
parents:
diff changeset
   455
void CATMiscCmdPlugin::CreateCMEReplyAndComplete(TInt aError)
hgs
parents:
diff changeset
   456
    {
hgs
parents:
diff changeset
   457
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   458
    
hgs
parents:
diff changeset
   459
    // TODO should return CME error according to CME state (and quiet mode?)
hgs
parents:
diff changeset
   460
    RBuf8 response;
hgs
parents:
diff changeset
   461
    response.Create(KDefaultCmdBufLength);
hgs
parents:
diff changeset
   462
    
hgs
parents:
diff changeset
   463
    // log error code
hgs
parents:
diff changeset
   464
    response.AppendNum(aError);
hgs
parents:
diff changeset
   465
    Trace(KDebugPrintD, "complete with error ", &response);
hgs
parents:
diff changeset
   466
    
hgs
parents:
diff changeset
   467
    // return error code to AT client
hgs
parents:
diff changeset
   468
    response.Zero(); // reuse RBuf
hgs
parents:
diff changeset
   469
    response.Append(KCRLF);
hgs
parents:
diff changeset
   470
    switch(aError)
hgs
parents:
diff changeset
   471
        {
hgs
parents:
diff changeset
   472
        case KErrGsm0707IncorrectPassword:
hgs
parents:
diff changeset
   473
        case KErrAccessDenied:
hgs
parents:
diff changeset
   474
            {    
hgs
parents:
diff changeset
   475
            // code was entered erroneously
hgs
parents:
diff changeset
   476
            response.Append(KCMEIncorrectPassword);
hgs
parents:
diff changeset
   477
            break;
hgs
parents:
diff changeset
   478
            }    
hgs
parents:
diff changeset
   479
        case KErrGsmSSPasswordAttemptsViolation:
hgs
parents:
diff changeset
   480
        case KErrLocked:
hgs
parents:
diff changeset
   481
            {
hgs
parents:
diff changeset
   482
            // Pin blocked 
hgs
parents:
diff changeset
   483
            response.Append(KCMEPUKRequired);
hgs
parents:
diff changeset
   484
            break;
hgs
parents:
diff changeset
   485
            }
hgs
parents:
diff changeset
   486
        case KErrGsm0707OperationNotAllowed:
hgs
parents:
diff changeset
   487
            {
hgs
parents:
diff changeset
   488
            // not allowed with this sim
hgs
parents:
diff changeset
   489
            response.Append(KCMENotAllowed);
hgs
parents:
diff changeset
   490
            break;
hgs
parents:
diff changeset
   491
            }
hgs
parents:
diff changeset
   492
        case KErrUnknown:
hgs
parents:
diff changeset
   493
            {
hgs
parents:
diff changeset
   494
            // unknown error
hgs
parents:
diff changeset
   495
            response.Append(KCMEPhoneUnknown);
hgs
parents:
diff changeset
   496
            break;
hgs
parents:
diff changeset
   497
            }
hgs
parents:
diff changeset
   498
        default:
hgs
parents:
diff changeset
   499
            response.Append(KCMEPhoneError);
hgs
parents:
diff changeset
   500
        }
hgs
parents:
diff changeset
   501
    CreateReplyAndComplete( EReplyTypeError, response );
hgs
parents:
diff changeset
   502
    response.Close();
hgs
parents:
diff changeset
   503
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   504
    }
hgs
parents:
diff changeset
   505
hgs
parents:
diff changeset
   506
hgs
parents:
diff changeset
   507
TInt CATMiscCmdPlugin::HandleUnsolicitedRequest(const TDesC8& aAT )
hgs
parents:
diff changeset
   508
    {
hgs
parents:
diff changeset
   509
    return SendUnsolicitedResult(aAT);
hgs
parents:
diff changeset
   510
    }
hgs
parents:
diff changeset
   511
hgs
parents:
diff changeset
   512
void CATMiscCmdPlugin::ConnectToEtelL(RTelServer& aTelServer, RMobilePhone& aPhone)
hgs
parents:
diff changeset
   513
    {
hgs
parents:
diff changeset
   514
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   515
    User::LeaveIfError(aTelServer.Connect());
hgs
parents:
diff changeset
   516
hgs
parents:
diff changeset
   517
    // get the name of the first available phone
hgs
parents:
diff changeset
   518
    TInt phoneCount;
hgs
parents:
diff changeset
   519
    RTelServer::TPhoneInfo info;
hgs
parents:
diff changeset
   520
hgs
parents:
diff changeset
   521
    User::LeaveIfError(aTelServer.EnumeratePhones(phoneCount));  
hgs
parents:
diff changeset
   522
    if (phoneCount < 1)
hgs
parents:
diff changeset
   523
        {
hgs
parents:
diff changeset
   524
        User::Leave(KErrNotFound); // TODO: appropriate error code
hgs
parents:
diff changeset
   525
        }
hgs
parents:
diff changeset
   526
    User::LeaveIfError(aTelServer.GetPhoneInfo(0, info));
hgs
parents:
diff changeset
   527
    User::LeaveIfError(aPhone.Open(aTelServer, info.iName));
hgs
parents:
diff changeset
   528
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   529
    }