|
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 "lccustomplugin.h" |
|
19 #include "lclistallcmd.h" |
|
20 #include "debug.h" |
|
21 |
|
22 const TInt KErrorReplyLength = 9; // CR+LF+"ERROR"+CR+LF |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // Two-phased constructor. |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CLcCustomPlugin* CLcCustomPlugin::NewL() |
|
29 { |
|
30 CLcCustomPlugin* self = new (ELeave) CLcCustomPlugin(); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Destructor. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CLcCustomPlugin::~CLcCustomPlugin() |
|
42 { |
|
43 iHandlers.ResetAndDestroy(); |
|
44 iHandlers.Close(); |
|
45 iReplyBuffer.Close(); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CLcCustomPlugin::CLcCustomPlugin |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CLcCustomPlugin::CLcCustomPlugin() : CATExtPluginBase() |
|
53 { |
|
54 iHandler = NULL; |
|
55 iHcCmd = NULL; |
|
56 iHcReply = NULL; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CLcCustomPlugin::ConstructL |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CLcCustomPlugin::ConstructL() |
|
64 { |
|
65 CLcCustomPluginBase* handler = NULL; |
|
66 handler = CLcListAllCmd::NewL( this ); |
|
67 CleanupStack::PushL( handler ); |
|
68 iHandlers.AppendL( handler ); |
|
69 CleanupStack::Pop( handler ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Reports connection identifier name to the extension plugin. |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CLcCustomPlugin::ReportConnectionName( const TDesC8& /*aName*/ ) |
|
77 { |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // Reports the support status of an AT command. This is a synchronous API. |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 TBool CLcCustomPlugin::IsCommandSupported( const TDesC8& aCmd ) |
|
85 { |
|
86 TRACE_FUNC_ENTRY |
|
87 iHcCmd = NULL; |
|
88 iHcReply = NULL; |
|
89 TInt i; |
|
90 TInt count = iHandlers.Count(); |
|
91 for ( i=0; i<count; i++ ) |
|
92 { |
|
93 CLcCustomPluginBase* handler = iHandlers[i]; |
|
94 TBool supported = handler->IsCommandSupported( aCmd ); |
|
95 if ( supported ) |
|
96 { |
|
97 iHandler = handler; |
|
98 TRACE_FUNC_EXIT |
|
99 return ETrue; |
|
100 } |
|
101 } |
|
102 iHandler = NULL; |
|
103 TRACE_FUNC_EXIT |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Handles an AT command. Cancelling of the pending request is done by |
|
109 // HandleCommandCancel(). The implementation in the extension plugin should |
|
110 // be asynchronous. |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CLcCustomPlugin::HandleCommand( const TDesC8& aCmd, |
|
114 RBuf8& aReply, |
|
115 TBool aReplyNeeded ) |
|
116 { |
|
117 TRACE_FUNC_ENTRY |
|
118 if ( iHandler ) |
|
119 { |
|
120 iHcCmd = &aCmd; |
|
121 iHcReply = &aReply; |
|
122 iHandler->HandleCommand( aCmd, aReply, aReplyNeeded ); |
|
123 } |
|
124 TRACE_FUNC_EXIT |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Cancels a pending HandleCommand request. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CLcCustomPlugin::HandleCommandCancel() |
|
132 { |
|
133 TRACE_FUNC_ENTRY |
|
134 if ( iHandler ) |
|
135 { |
|
136 iHandler->HandleCommandCancel(); |
|
137 } |
|
138 TRACE_FUNC_EXIT |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // Next reply part's length. |
|
143 // The value must be equal or less than KDefaultCmdBufLength. |
|
144 // When the reply from this method is zero, ATEXT stops calling |
|
145 // GetNextPartOfReply(). |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CLcCustomPlugin::NextReplyPartLength() |
|
149 { |
|
150 TRACE_FUNC_ENTRY |
|
151 if ( iReplyBuffer.Length() < KDefaultCmdBufLength ) |
|
152 { |
|
153 TRACE_FUNC_EXIT |
|
154 return iReplyBuffer.Length(); |
|
155 } |
|
156 TRACE_FUNC_EXIT |
|
157 return KDefaultCmdBufLength; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // Gets the next part of reply initially set by HandleCommandComplete(). |
|
162 // Length of aNextReply must be equal or less than KDefaultCmdBufLength. |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 TInt CLcCustomPlugin::GetNextPartOfReply( RBuf8& aNextReply ) |
|
166 { |
|
167 TRACE_FUNC_ENTRY |
|
168 TInt retVal = CreatePartOfReply( aNextReply ); |
|
169 TRACE_FUNC_EXIT |
|
170 return retVal; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Receives unsolicited results. Cancelling of the pending request is done by |
|
175 // by ReceiveUnsolicitedResultCancel(). The implementation in the extension |
|
176 // plugin should be asynchronous. |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CLcCustomPlugin::ReceiveUnsolicitedResult() |
|
180 { |
|
181 TRACE_FUNC_ENTRY |
|
182 TRACE_FUNC_EXIT |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Cancels a pending ReceiveUnsolicitedResult request. |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CLcCustomPlugin::ReceiveUnsolicitedResultCancel() |
|
190 { |
|
191 TRACE_FUNC_ENTRY |
|
192 TRACE_FUNC_EXIT |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Reports NVRAM status change to the plugins. |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CLcCustomPlugin::ReportNvramStatusChange( const TDesC8& /*aNvram*/ ) |
|
200 { |
|
201 TRACE_FUNC_ENTRY |
|
202 TRACE_FUNC_EXIT |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // Reports about external handle command error condition. |
|
207 // This is for cases when for example DUN decided the reply contained an |
|
208 // error condition but the plugin is still handling the command internally. |
|
209 // Example: "AT+TEST;+TEST2" was given in command line; "AT+TEST" returns |
|
210 // non-EReplyTypeError condition and "AT+TEST2" returns EReplyTypeError. |
|
211 // As the plugin(s) returning the non-EReplyTypeError may still have some |
|
212 // ongoing operation then these plugins are notified about the external |
|
213 // EReplyTypeError in command line processing. It is to be noted that |
|
214 // HandleCommandCancel() is not sufficient to stop the processing as the |
|
215 // command handling has already finished. |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CLcCustomPlugin::ReportExternalHandleCommandError() |
|
219 { |
|
220 TRACE_FUNC_ENTRY |
|
221 TRACE_FUNC_EXIT |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // Creates part of reply from the global reply buffer to the destination |
|
226 // buffer. Used with APIs which need the next part of reply in multipart reply |
|
227 // requests. |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CLcCustomPlugin::CreatePartOfReply( RBuf8& aDstBuffer ) |
|
231 { |
|
232 TRACE_FUNC_ENTRY |
|
233 if ( iReplyBuffer.Length() <= 0 ) |
|
234 { |
|
235 TRACE_FUNC_EXIT |
|
236 return KErrGeneral; |
|
237 } |
|
238 TInt partLength = NextReplyPartLength(); |
|
239 if ( iReplyBuffer.Length() < partLength ) |
|
240 { |
|
241 TRACE_FUNC_EXIT |
|
242 return KErrNotFound; |
|
243 } |
|
244 aDstBuffer.Create( iReplyBuffer, partLength ); |
|
245 iReplyBuffer.Delete( 0, partLength ); |
|
246 if ( iReplyBuffer.Length() == 0 ) |
|
247 { |
|
248 iReplyBuffer.Close(); |
|
249 } |
|
250 TRACE_FUNC_EXIT |
|
251 return KErrNone; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Creates an AT command reply based on the reply type and completes the |
|
256 // request to ATEXT. Uses iReplyBuffer for reply storage. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CLcCustomPlugin::CreateReplyAndComplete( TATExtensionReplyType aReplyType, |
|
260 const TDesC8& aSrcBuffer, |
|
261 TInt aError ) |
|
262 { |
|
263 TRACE_FUNC_ENTRY |
|
264 iReplyBuffer.Close(); |
|
265 if ( aError != KErrNone ) |
|
266 { |
|
267 HandleCommandCompleted( aError, EReplyTypeUndefined ); |
|
268 iHcCmd = NULL; |
|
269 iHcReply = NULL; |
|
270 TRACE_FUNC_EXIT |
|
271 return KErrNone; |
|
272 } |
|
273 if ( !iHcReply ) |
|
274 { |
|
275 TRACE_FUNC_EXIT |
|
276 return KErrGeneral; |
|
277 } |
|
278 switch ( aReplyType ) |
|
279 { |
|
280 case EReplyTypeOther: |
|
281 if ( iQuietMode ) |
|
282 { |
|
283 iReplyBuffer.Create( KNullDesC8 ); |
|
284 } |
|
285 else |
|
286 { |
|
287 iReplyBuffer.Create( aSrcBuffer ); |
|
288 } |
|
289 break; |
|
290 case EReplyTypeOk: |
|
291 CreateOkOrErrorReply( iReplyBuffer, ETrue ); |
|
292 break; |
|
293 case EReplyTypeError: |
|
294 CreateOkOrErrorReply( iReplyBuffer, EFalse ); |
|
295 break; |
|
296 default: |
|
297 TRACE_FUNC_EXIT |
|
298 return KErrGeneral; |
|
299 } |
|
300 CreatePartOfReply( *iHcReply ); |
|
301 HandleCommandCompleted( KErrNone, aReplyType ); |
|
302 iHcCmd = NULL; |
|
303 iHcReply = NULL; |
|
304 TRACE_FUNC_EXIT |
|
305 return KErrNone; |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Creates a buffer for "OK" or "ERROR" reply based on the line settings |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 TInt CLcCustomPlugin::CreateOkOrErrorReply( RBuf8& aReplyBuffer, |
|
313 TBool aOkReply ) |
|
314 { |
|
315 TRACE_FUNC_ENTRY |
|
316 if ( iQuietMode ) |
|
317 { |
|
318 TRACE_FUNC_EXIT |
|
319 return iReplyBuffer.Create( KNullDesC8 ); |
|
320 } |
|
321 _LIT8( KErrorReplyVerbose, "ERROR" ); |
|
322 _LIT8( KOkReplyVerbose, "OK" ); |
|
323 _LIT8( KErrorReplyNumeric, "4" ); |
|
324 _LIT8( KOkReplyNumeric, "0" ); |
|
325 TBuf8<KErrorReplyLength> replyBuffer; |
|
326 if ( iVerboseMode ) |
|
327 { |
|
328 replyBuffer.Append( iCarriageReturn ); |
|
329 replyBuffer.Append( iLineFeed ); |
|
330 if ( aOkReply ) |
|
331 { |
|
332 replyBuffer.Append( KOkReplyVerbose ); |
|
333 } |
|
334 else |
|
335 { |
|
336 replyBuffer.Append( KErrorReplyVerbose ); |
|
337 } |
|
338 replyBuffer.Append( iCarriageReturn ); |
|
339 replyBuffer.Append( iLineFeed ); |
|
340 } |
|
341 else |
|
342 { |
|
343 if ( aOkReply ) |
|
344 { |
|
345 replyBuffer.Append( KOkReplyNumeric ); |
|
346 } |
|
347 else |
|
348 { |
|
349 replyBuffer.Append( KErrorReplyNumeric ); |
|
350 } |
|
351 replyBuffer.Append( iCarriageReturn ); |
|
352 } |
|
353 TInt retVal = aReplyBuffer.Create( replyBuffer ); |
|
354 TRACE_FUNC_EXIT |
|
355 return retVal; |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // From MLcCustomPlugin. |
|
360 // Checks if the command is a base, set, read or test type of command |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 TCmdHandlerType CLcCustomPlugin::CheckCommandType( |
|
364 const TDesC8& aCmdBase, |
|
365 const TDesC8& aCmdFull ) |
|
366 { |
|
367 TRACE_FUNC_ENTRY |
|
368 TInt retTemp = KErrNone; |
|
369 TBuf8<KDefaultCmdBufLength> atCmdBuffer; |
|
370 atCmdBuffer.Copy( aCmdBase ); |
|
371 // Check "base" command ("AT+COMMAND") |
|
372 retTemp = aCmdFull.Compare( atCmdBuffer ); |
|
373 if ( retTemp == 0 ) |
|
374 { |
|
375 TRACE_FUNC_EXIT |
|
376 return ECmdHandlerTypeBase; |
|
377 } |
|
378 // Check "read" command ("AT+COMMAND?") |
|
379 // Add last question mark |
|
380 atCmdBuffer.Append( '?' ); |
|
381 retTemp = aCmdFull.Compare( atCmdBuffer ); |
|
382 if ( retTemp == 0 ) |
|
383 { |
|
384 TRACE_FUNC_EXIT |
|
385 return ECmdHandlerTypeRead; |
|
386 } |
|
387 // Check "test" command ("AT+COMMAND=?") |
|
388 // Add "=" before the question mark |
|
389 _LIT8( KAssignmentMark, "=" ); |
|
390 atCmdBuffer.Insert( atCmdBuffer.Length()-1, KAssignmentMark ); |
|
391 retTemp = aCmdFull.Compare( atCmdBuffer ); |
|
392 if ( retTemp == 0 ) |
|
393 { |
|
394 TRACE_FUNC_EXIT |
|
395 return ECmdHandlerTypeTest; |
|
396 } |
|
397 // Check "set" command ("AT+COMMAND=") |
|
398 // Remove last question mark |
|
399 atCmdBuffer.SetLength( atCmdBuffer.Length() - 1 ); |
|
400 retTemp = aCmdFull.Compare( atCmdBuffer ); |
|
401 if ( retTemp == 0 ) |
|
402 { |
|
403 TRACE_FUNC_EXIT |
|
404 return ECmdHandlerTypeSet; |
|
405 } |
|
406 TRACE_FUNC_EXIT |
|
407 return ECmdHandlerTypeUndefined; |
|
408 } |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // From MLcCustomPlugin. |
|
412 // Returns the array of supported commands |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 TInt CLcCustomPlugin::GetSupportedCommands( RPointerArray<HBufC8>& aCmds ) |
|
416 { |
|
417 TRACE_FUNC_ENTRY |
|
418 // Force superclass call here: |
|
419 TInt retVal = CATExtPluginBase::GetSupportedCommands( aCmds ); |
|
420 TRACE_FUNC_EXIT |
|
421 return retVal; |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // From MLcCustomPlugin. |
|
426 // Returns plugin's character value settings (from CATExtPluginBase) |
|
427 // --------------------------------------------------------------------------- |
|
428 // |
|
429 TInt CLcCustomPlugin::GetCharacterValue( TCharacterTypes aCharType, |
|
430 TChar& aChar ) |
|
431 { |
|
432 TRACE_FUNC_ENTRY |
|
433 TInt retVal = KErrNone; |
|
434 switch ( aCharType ) |
|
435 { |
|
436 case ECharTypeCR: |
|
437 aChar = iCarriageReturn; |
|
438 break; |
|
439 case ECharTypeLF: |
|
440 aChar = iLineFeed; |
|
441 break; |
|
442 case ECharTypeBS: |
|
443 aChar = iBackspace; |
|
444 break; |
|
445 default: |
|
446 retVal = KErrNotFound; |
|
447 break; |
|
448 } |
|
449 TRACE_FUNC_EXIT |
|
450 return retVal; |
|
451 } |
|
452 |
|
453 // --------------------------------------------------------------------------- |
|
454 // From MLcCustomPlugin. |
|
455 // Returns plugin's mode value settings (from CATExtPluginBase) |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 TInt CLcCustomPlugin::GetModeValue( TModeTypes aModeType, TBool& aMode ) |
|
459 { |
|
460 TRACE_FUNC_ENTRY |
|
461 TInt retVal = KErrNone; |
|
462 switch ( aModeType ) |
|
463 { |
|
464 case EModeTypeQuiet: |
|
465 aMode = iQuietMode; |
|
466 break; |
|
467 case EModeTypeVerbose: |
|
468 aMode = iVerboseMode; |
|
469 break; |
|
470 default: |
|
471 retVal = KErrNotFound; |
|
472 break; |
|
473 } |
|
474 TRACE_FUNC_EXIT |
|
475 return retVal; |
|
476 } |