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