cbsatplugin/atmisccmdplugin/src/atcommandparser.cpp
author hgs
Fri, 23 Jul 2010 15:57:13 +0300
changeset 47 9e2a905b887f
parent 45 b0aebde9b1fb
child 51 625f43ae9362
permissions -rw-r--r--
201029_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
// This file contains the implementation of the AT command parser and common utilities
hgs
parents:
diff changeset
    15
// 
hgs
parents:
diff changeset
    16
//
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "atcommandparser.h"
hgs
parents:
diff changeset
    19
#include <hash.h>
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include "debug.h"
32
hgs
parents: 26
diff changeset
    22
#include "atmisccmdpluginconsts.h"
26
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
TAtCommandParser::TAtCommandParser()
hgs
parents:
diff changeset
    25
    : iCmdType(EUnknown), iCmdHandlerType(ECmdHandlerTypeUndefined)  
hgs
parents:
diff changeset
    26
    {
32
hgs
parents: 26
diff changeset
    27
    TRACE_FUNC_ENTRY
hgs
parents: 26
diff changeset
    28
    TRACE_FUNC_EXIT
26
hgs
parents:
diff changeset
    29
    }
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
TAtCommandParser::TAtCommandParser(const TDesC8& aCmd)
hgs
parents:
diff changeset
    32
    : iCmdType(EUnknown), iCmdHandlerType(ECmdHandlerTypeUndefined)  
hgs
parents:
diff changeset
    33
    {
32
hgs
parents: 26
diff changeset
    34
    TRACE_FUNC_ENTRY
26
hgs
parents:
diff changeset
    35
    ParseAtCommand(aCmd);
32
hgs
parents: 26
diff changeset
    36
    TRACE_FUNC_EXIT
26
hgs
parents:
diff changeset
    37
    }
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
void TAtCommandParser::ParseAtCommand(const TDesC8& aCmd)
hgs
parents:
diff changeset
    40
    {
hgs
parents:
diff changeset
    41
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    42
    iCmd.Assign(aCmd);
hgs
parents:
diff changeset
    43
    iCmd.Mark();
hgs
parents:
diff changeset
    44
    TChar c = 0;
hgs
parents:
diff changeset
    45
    // First extract the AT command "AT+COMMAND"
hgs
parents:
diff changeset
    46
    while(!iCmd.Eos() && !(c=='=' || c=='?'))
hgs
parents:
diff changeset
    47
        {
hgs
parents:
diff changeset
    48
        iCmd.Inc();
hgs
parents:
diff changeset
    49
        c = iCmd.Peek();
hgs
parents:
diff changeset
    50
        }
hgs
parents:
diff changeset
    51
          
hgs
parents:
diff changeset
    52
    TPtrC8 token = iCmd.MarkedToken();   
hgs
parents:
diff changeset
    53
    
hgs
parents:
diff changeset
    54
    _LIT8(KAtCfun, "AT+CFUN");
hgs
parents:
diff changeset
    55
    _LIT8(KAtCbc, "AT+CBC");
hgs
parents:
diff changeset
    56
    _LIT8(KAtClck, "AT+CLCK");
hgs
parents:
diff changeset
    57
    _LIT8(KAtCpwd, "AT+CPWD");
hgs
parents:
diff changeset
    58
    _LIT8(KAtCpin, "AT+CPIN");
hgs
parents:
diff changeset
    59
    _LIT8(KAtCusd, "AT+CUSD");
hgs
parents:
diff changeset
    60
    _LIT8(KAtCnum, "AT+CNUM");
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    61
	_LIT8(KAtCmee, "AT+CMEE");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    62
#ifdef PROTOCOL_TDSCDMA
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    63
    _LIT8(KAtHver, "AT^HVER");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    64
    _LIT8(KAtCgsn, "AT+CGSN");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    65
    _LIT8(KAtCgmr, "AT+CGMR");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    66
    _LIT8(KAtCgmi, "AT+CGMI");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    67
    _LIT8(KAtCmgw, "AT+CMGW");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    68
	_LIT8(KAtCmgd, "AT+CMGD");
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    69
	_LIT8(KAtCmgf, "AT+CMGF");
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    70
	_LIT8(KAtiBase, "ATI");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    71
	_LIT8(KAti0, "ATI0");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    72
	_LIT8(KAti1, "ATI1");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    73
	_LIT8(KAti2, "ATI2");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    74
	_LIT8(KAti3, "ATI3");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    75
	_LIT8(KAti4, "ATI4");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    76
	_LIT8(KAtGmr, "AT+GMR");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    77
	_LIT8(KAtGmi, "AT+GMI");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    78
	_LIT8(KAtGsn, "AT+GSN");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    79
	_LIT8(KAtCgmm, "AT+CGMM");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    80
	_LIT8(KAtGmm, "AT+GMM");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    81
	_LIT8(KAtScpbr, "AT^SCPBR");
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
    82
	_LIT8(KAtScpbw, "AT^SCPBW");
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
    83
#endif
26
hgs
parents:
diff changeset
    84
    
hgs
parents:
diff changeset
    85
    Trace(KDebugPrintS, "token: ", &token);
hgs
parents:
diff changeset
    86
    // Determine the AT command type
32
hgs
parents: 26
diff changeset
    87
    if(!token.CompareF(KAtCfun))
26
hgs
parents:
diff changeset
    88
        {
hgs
parents:
diff changeset
    89
        iCmdType = ECmdAtCfun;
hgs
parents:
diff changeset
    90
        }
32
hgs
parents: 26
diff changeset
    91
    else if(!token.CompareF(KAtCbc))
26
hgs
parents:
diff changeset
    92
        {
hgs
parents:
diff changeset
    93
        iCmdType = ECmdAtCbc;
hgs
parents:
diff changeset
    94
        }
32
hgs
parents: 26
diff changeset
    95
    else if(!token.CompareF(KAtClck))
26
hgs
parents:
diff changeset
    96
        {
hgs
parents:
diff changeset
    97
        iCmdType = ECmdAtClck;
hgs
parents:
diff changeset
    98
        }
32
hgs
parents: 26
diff changeset
    99
    else if(!token.CompareF(KAtCpwd))
26
hgs
parents:
diff changeset
   100
        {
hgs
parents:
diff changeset
   101
        iCmdType = ECmdAtCpwd;
hgs
parents:
diff changeset
   102
        }
32
hgs
parents: 26
diff changeset
   103
    else if(!token.CompareF(KAtCpin))
26
hgs
parents:
diff changeset
   104
        {
hgs
parents:
diff changeset
   105
        iCmdType = ECmdAtCpin;
hgs
parents:
diff changeset
   106
        }
32
hgs
parents: 26
diff changeset
   107
    else if(!token.CompareF(KAtCusd))
26
hgs
parents:
diff changeset
   108
        {
hgs
parents:
diff changeset
   109
        iCmdType = ECmdAtCusd;
hgs
parents:
diff changeset
   110
        }
32
hgs
parents: 26
diff changeset
   111
    else if(!token.CompareF(KAtCnum))
26
hgs
parents:
diff changeset
   112
        {
hgs
parents:
diff changeset
   113
        iCmdType = ECmdAtCnum;
hgs
parents:
diff changeset
   114
        }
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   115
    else if(!token.CompareF(KAtCmee))
32
hgs
parents: 26
diff changeset
   116
        {
hgs
parents: 26
diff changeset
   117
        iCmdType = ECmdAtCmee;
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   118
		}
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   119
#ifdef PROTOCOL_TDSCDMA
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   120
    else if(!token.CompareF(KAtHver))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   121
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   122
        iCmdType = ECmdAtHver;
32
hgs
parents: 26
diff changeset
   123
        }
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   124
    else if(!token.CompareF(KAtCgsn))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   125
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   126
        iCmdType = ECmdAtCgsn;
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   127
        }
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   128
    else if(!token.CompareF(KAtGsn))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   129
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   130
        iCmdType = ECmdAtGsn;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   131
        }
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   132
    else if(!token.CompareF(KAtCgmr))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   133
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   134
        iCmdType = ECmdAtCgmr;
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   135
        }
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   136
    else if(!token.CompareF(KAtGmr))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   137
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   138
        iCmdType = ECmdAtGmr;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   139
        }
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   140
    else if(!token.CompareF(KAtCgmi))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   141
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   142
        iCmdType = ECmdAtCgmi;
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   143
        }    
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   144
    else if(!token.CompareF(KAtGmi))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   145
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   146
        iCmdType = ECmdAtGmi;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   147
        } 
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   148
    else if(!token.CompareF(KAtCmgw))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   149
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   150
        iCmdType = ECmdAtCmgw;
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   151
        }
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   152
    else if(!token.CompareF(KAtCmgd))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   153
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   154
        iCmdType = ECmdAtCmgd;
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   155
        }
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   156
    else if(!token.CompareF(KAtCmgf))
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   157
        {
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   158
        iCmdType = ECmdAtCmgf;
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   159
        }
47
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   160
    else if(!token.CompareF(KAtCgmm))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   161
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   162
        iCmdType = ECmdAtCgmm;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   163
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   164
    else if(!token.CompareF(KAtGmm))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   165
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   166
        iCmdType = ECmdAtGmm;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   167
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   168
    else if(!token.CompareF(KAtiBase))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   169
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   170
        iCmdType = ECmdAtI;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   171
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   172
    else if(!token.CompareF(KAti0))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   173
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   174
        iCmdType = ECmdAtI0;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   175
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   176
    else if(!token.CompareF(KAti1))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   177
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   178
        iCmdType = ECmdAtI1;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   179
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   180
    else if(!token.CompareF(KAti2))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   181
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   182
        iCmdType = ECmdAtI2;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   183
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   184
    else if(!token.CompareF(KAti3))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   185
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   186
        iCmdType = ECmdAtI3;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   187
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   188
    else if(!token.CompareF(KAti4))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   189
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   190
        iCmdType = ECmdAtI4;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   191
        }
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   192
	else if(!token.CompareF(KAtScpbr))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   193
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   194
        iCmdType = ECmdAtScpbr;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   195
        } 
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   196
    else if(!token.CompareF(KAtScpbw))
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   197
        {
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   198
        iCmdType = ECmdAtScpbw;
9e2a905b887f 201029_02
hgs
parents: 45
diff changeset
   199
        }
45
b0aebde9b1fb 201027_02
hgs
parents: 32
diff changeset
   200
#endif    
26
hgs
parents:
diff changeset
   201
    else
hgs
parents:
diff changeset
   202
        {
hgs
parents:
diff changeset
   203
        iCmdType = EUnknown;
hgs
parents:
diff changeset
   204
        TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   205
        return;
hgs
parents:
diff changeset
   206
        }
hgs
parents:
diff changeset
   207
        
hgs
parents:
diff changeset
   208
    // Now find out the AT command handler type
hgs
parents:
diff changeset
   209
    if(iCmd.Eos())
hgs
parents:
diff changeset
   210
        {
hgs
parents:
diff changeset
   211
        iCmdHandlerType = ECmdHandlerTypeBase;
hgs
parents:
diff changeset
   212
        }
hgs
parents:
diff changeset
   213
    else if(iCmd.Peek() == '?')
hgs
parents:
diff changeset
   214
        {
hgs
parents:
diff changeset
   215
        iCmdHandlerType = ECmdHandlerTypeRead;
hgs
parents:
diff changeset
   216
        }
hgs
parents:
diff changeset
   217
    else if(iCmd.Peek() == '=')
hgs
parents:
diff changeset
   218
        {
hgs
parents:
diff changeset
   219
        iCmd.Inc();
hgs
parents:
diff changeset
   220
        if(iCmd.Peek() == '?')
hgs
parents:
diff changeset
   221
            {
hgs
parents:
diff changeset
   222
            iCmd.Inc();
hgs
parents:
diff changeset
   223
            iCmdHandlerType = ECmdHandlerTypeTest;
hgs
parents:
diff changeset
   224
            }
hgs
parents:
diff changeset
   225
        else
hgs
parents:
diff changeset
   226
            {
hgs
parents:
diff changeset
   227
            iCmdHandlerType = ECmdHandlerTypeSet;
hgs
parents:
diff changeset
   228
            }
hgs
parents:
diff changeset
   229
        }
hgs
parents:
diff changeset
   230
    else
hgs
parents:
diff changeset
   231
        {
hgs
parents:
diff changeset
   232
        iCmdHandlerType = ECmdHandlerTypeUndefined;
hgs
parents:
diff changeset
   233
        }
hgs
parents:
diff changeset
   234
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   235
    }
hgs
parents:
diff changeset
   236
hgs
parents:
diff changeset
   237
TAtCommandParser::TCommandType TAtCommandParser::Command() const
hgs
parents:
diff changeset
   238
    {
32
hgs
parents: 26
diff changeset
   239
    TRACE_FUNC_ENTRY
hgs
parents: 26
diff changeset
   240
    TRACE_FUNC_EXIT
26
hgs
parents:
diff changeset
   241
    return iCmdType;
hgs
parents:
diff changeset
   242
    }
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
TAtCommandParser::TCommandHandlerType TAtCommandParser::CommandHandlerType() const
hgs
parents:
diff changeset
   245
    {
32
hgs
parents: 26
diff changeset
   246
    TRACE_FUNC_ENTRY
hgs
parents: 26
diff changeset
   247
    TRACE_FUNC_EXIT
26
hgs
parents:
diff changeset
   248
    return iCmdHandlerType;
hgs
parents:
diff changeset
   249
    }
hgs
parents:
diff changeset
   250
hgs
parents:
diff changeset
   251
TPtrC8 TAtCommandParser::NextParam()
hgs
parents:
diff changeset
   252
    {
hgs
parents:
diff changeset
   253
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   254
    iCmd.SkipSpace(); // Skip front spaces
hgs
parents:
diff changeset
   255
    iCmd.Mark();
hgs
parents:
diff changeset
   256
    TChar chr = 0;
hgs
parents:
diff changeset
   257
    
hgs
parents:
diff changeset
   258
    if(!iCmd.Eos())
hgs
parents:
diff changeset
   259
        {
hgs
parents:
diff changeset
   260
        chr = iCmd.Peek();
hgs
parents:
diff changeset
   261
        while(!iCmd.Eos() && chr != ',' && !chr.IsSpace() && !chr.IsControl())
hgs
parents:
diff changeset
   262
            {// Stop at any of those chars: comma, space or control
hgs
parents:
diff changeset
   263
            iCmd.Inc();
hgs
parents:
diff changeset
   264
            chr = iCmd.Peek();
hgs
parents:
diff changeset
   265
            }
hgs
parents:
diff changeset
   266
        }
hgs
parents:
diff changeset
   267
    
hgs
parents:
diff changeset
   268
    // Extract the token at this point            
hgs
parents:
diff changeset
   269
    TPtrC8 retVal = iCmd.MarkedToken();
hgs
parents:
diff changeset
   270
    
hgs
parents:
diff changeset
   271
    // Skip comma, space and control chars
hgs
parents:
diff changeset
   272
    while(!iCmd.Eos() && (chr == ',' || chr.IsSpace() || chr.IsControl()))
hgs
parents:
diff changeset
   273
        {
hgs
parents:
diff changeset
   274
        iCmd.Inc();
hgs
parents:
diff changeset
   275
        chr = iCmd.Peek();
hgs
parents:
diff changeset
   276
        }
hgs
parents:
diff changeset
   277
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   278
    return retVal;
hgs
parents:
diff changeset
   279
    }
hgs
parents:
diff changeset
   280
32
hgs
parents: 26
diff changeset
   281
TInt TAtCommandParser::NextTextParam(TPtrC8& aParam)
26
hgs
parents:
diff changeset
   282
    {
32
hgs
parents: 26
diff changeset
   283
    TRACE_FUNC_ENTRY
hgs
parents: 26
diff changeset
   284
    TInt ret = KErrNone;
26
hgs
parents:
diff changeset
   285
    TPtrC8 param = NextParam();
hgs
parents:
diff changeset
   286
    
32
hgs
parents: 26
diff changeset
   287
    if (param.Length() == 0)
26
hgs
parents:
diff changeset
   288
        {
32
hgs
parents: 26
diff changeset
   289
        aParam.Set(NULL,0);
hgs
parents: 26
diff changeset
   290
        ret = KErrNotFound;
26
hgs
parents:
diff changeset
   291
        }
32
hgs
parents: 26
diff changeset
   292
    else if(param.Length() < 2 || param[0] != '"'
26
hgs
parents:
diff changeset
   293
            || param[param.Length()-1] != '"')
hgs
parents:
diff changeset
   294
        {
32
hgs
parents: 26
diff changeset
   295
        aParam.Set(NULL,0);
hgs
parents: 26
diff changeset
   296
        ret = KErrArgument;
26
hgs
parents:
diff changeset
   297
        }
32
hgs
parents: 26
diff changeset
   298
    else
hgs
parents: 26
diff changeset
   299
        {
hgs
parents: 26
diff changeset
   300
        aParam.Set(param.Mid(1, param.Length() - 2));
hgs
parents: 26
diff changeset
   301
        }
hgs
parents: 26
diff changeset
   302
    TRACE_FUNC_EXIT
hgs
parents: 26
diff changeset
   303
    return ret;
26
hgs
parents:
diff changeset
   304
    }
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
TInt TAtCommandParser::NextIntParam(TInt& aValue)
hgs
parents:
diff changeset
   307
    {
hgs
parents:
diff changeset
   308
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   309
    TInt retVal =KErrNone;
hgs
parents:
diff changeset
   310
    TPtrC8 param = NextParam();
32
hgs
parents: 26
diff changeset
   311
    if (param.Length() == 0)
26
hgs
parents:
diff changeset
   312
        {
hgs
parents:
diff changeset
   313
        retVal = KErrNotFound;
hgs
parents:
diff changeset
   314
        }
hgs
parents:
diff changeset
   315
    else
hgs
parents:
diff changeset
   316
        {
hgs
parents:
diff changeset
   317
        TLex8 lex(param);
hgs
parents:
diff changeset
   318
        retVal = lex.Val(aValue);
hgs
parents:
diff changeset
   319
        }
hgs
parents:
diff changeset
   320
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   321
    return retVal;
hgs
parents:
diff changeset
   322
    }
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
TInt TAtCommandParser::HashSecurityCode(const TDesC8& aPasscode, TDes8& aHashCode)
hgs
parents:
diff changeset
   325
    {
hgs
parents:
diff changeset
   326
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   327
    TInt ret = KErrNone;
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
    // Get MD5 Hash
hgs
parents:
diff changeset
   330
    // see remotemgmt component CSCPServer::HashISACode() for encoding algorithm
hgs
parents:
diff changeset
   331
    CMD5* hashObject = NULL;
hgs
parents:
diff changeset
   332
    TRAP( ret, hashObject = CMD5::NewL() );
hgs
parents:
diff changeset
   333
hgs
parents:
diff changeset
   334
    if(ret != KErrNone)
hgs
parents:
diff changeset
   335
        {
hgs
parents:
diff changeset
   336
        TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   337
        return ret;
hgs
parents:
diff changeset
   338
        }
hgs
parents:
diff changeset
   339
    
hgs
parents:
diff changeset
   340
    RBuf pwdBuffer;
hgs
parents:
diff changeset
   341
    ret = pwdBuffer.Create(KSCPMaxHashLength);
hgs
parents:
diff changeset
   342
    if(ret != KErrNone)
hgs
parents:
diff changeset
   343
        {
hgs
parents:
diff changeset
   344
        delete hashObject;
hgs
parents:
diff changeset
   345
        TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   346
        return ret;
hgs
parents:
diff changeset
   347
        }
hgs
parents:
diff changeset
   348
    pwdBuffer.Copy(aPasscode); // convert to TDes16
hgs
parents:
diff changeset
   349
hgs
parents:
diff changeset
   350
    // add TDes16 to a binary buffer
hgs
parents:
diff changeset
   351
    TUint16* inputPtr = const_cast<TUint16*>( pwdBuffer.Ptr() ); 
hgs
parents:
diff changeset
   352
    TPtrC8 inputData( reinterpret_cast<TUint8*>(inputPtr), pwdBuffer.Length()*2 );
hgs
parents:
diff changeset
   353
    
hgs
parents:
diff changeset
   354
    TPtrC8 hash = hashObject->Final( inputData );
hgs
parents:
diff changeset
   355
    delete hashObject;
hgs
parents:
diff changeset
   356
hgs
parents:
diff changeset
   357
    pwdBuffer.Zero();
hgs
parents:
diff changeset
   358
    pwdBuffer.Copy(hash);
hgs
parents:
diff changeset
   359
hgs
parents:
diff changeset
   360
    // Compute the hash sum as four 32-bit integers.
hgs
parents:
diff changeset
   361
    TInt64 hashSum = *(reinterpret_cast<TInt32*>(&pwdBuffer[0])) + 
hgs
parents:
diff changeset
   362
                     *(reinterpret_cast<TInt32*>(&pwdBuffer[4])) + 
hgs
parents:
diff changeset
   363
                     *(reinterpret_cast<TInt32*>(&pwdBuffer[8])) +
hgs
parents:
diff changeset
   364
                     *(reinterpret_cast<TInt32*>(&pwdBuffer[12]));
hgs
parents:
diff changeset
   365
    pwdBuffer.Close();
hgs
parents:
diff changeset
   366
     
hgs
parents:
diff changeset
   367
    // Create a five-digit security code from this number
hgs
parents:
diff changeset
   368
    TInt isaCode = ( hashSum % 90000 ) + 10000;
hgs
parents:
diff changeset
   369
hgs
parents:
diff changeset
   370
    // save encoded security code to TDes
hgs
parents:
diff changeset
   371
    aHashCode.Zero();
hgs
parents:
diff changeset
   372
    aHashCode.AppendNum(isaCode);
hgs
parents:
diff changeset
   373
hgs
parents:
diff changeset
   374
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   375
    return KErrNone;
hgs
parents:
diff changeset
   376
    }
hgs
parents:
diff changeset
   377