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