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