1 /* |
1 /* |
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 #include "CdcControlInterfaceReader.h" |
20 #include "CdcControlInterfaceReader.h" |
21 #include "AcmPanic.h" |
21 #include "AcmPanic.h" |
22 #include "AcmUtils.h" |
22 #include "AcmUtils.h" |
23 #include "CdcControlInterfaceRequestHandler.h" |
23 #include "CdcControlInterfaceRequestHandler.h" |
24 #include "AcmConstants.h" |
24 #include "AcmConstants.h" |
25 #include <usb/usblogger.h> |
25 #include "OstTraceDefinitions.h" |
26 |
26 #ifdef OST_TRACE_COMPILER_IN_USE |
27 #ifdef __FLOG_ACTIVE |
27 #include "CdcControlInterfaceReaderTraces.h" |
28 _LIT8(KLogComponent, "ECACM"); |
|
29 #endif |
28 #endif |
|
29 |
30 |
30 |
31 CCdcControlInterfaceReader::CCdcControlInterfaceReader( |
31 CCdcControlInterfaceReader::CCdcControlInterfaceReader( |
32 MCdcCommsClassRequestHandler& aParent, |
32 MCdcCommsClassRequestHandler& aParent, |
33 RDevUsbcClient& aLdd) |
33 RDevUsbcClient& aLdd) |
34 : CActive(KEcacmAOPriority), |
34 : CActive(KEcacmAOPriority), |
39 * |
39 * |
40 * @param aParent Observer (ACM port) |
40 * @param aParent Observer (ACM port) |
41 * @param aLdd The USB LDD handle to be used. |
41 * @param aLdd The USB LDD handle to be used. |
42 */ |
42 */ |
43 { |
43 { |
|
44 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_CONS_ENTRY ); |
44 CActiveScheduler::Add(this); |
45 CActiveScheduler::Add(this); |
45 ReadMessageHeader(); |
46 ReadMessageHeader(); |
|
47 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_CONS_EXIT ); |
46 } |
48 } |
47 |
49 |
48 CCdcControlInterfaceReader::~CCdcControlInterfaceReader() |
50 CCdcControlInterfaceReader::~CCdcControlInterfaceReader() |
49 /** |
51 /** |
50 * Destructor |
52 * Destructor |
51 */ |
53 */ |
52 { |
54 { |
53 LOG_FUNC |
55 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_DES_ENTRY ); |
54 |
|
55 Cancel(); //Call CActive::Cancel() |
56 Cancel(); //Call CActive::Cancel() |
|
57 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_DES_EXIT ); |
56 } |
58 } |
57 |
59 |
58 CCdcControlInterfaceReader* CCdcControlInterfaceReader::NewL( |
60 CCdcControlInterfaceReader* CCdcControlInterfaceReader::NewL( |
59 MCdcCommsClassRequestHandler& aParent, |
61 MCdcCommsClassRequestHandler& aParent, |
60 RDevUsbcClient& aLdd) |
62 RDevUsbcClient& aLdd) |
63 * |
65 * |
64 * @param aParent Observer (ACM port) |
66 * @param aParent Observer (ACM port) |
65 * @param aLdd The USB LDD handle to be used. |
67 * @param aLdd The USB LDD handle to be used. |
66 */ |
68 */ |
67 { |
69 { |
68 LOG_STATIC_FUNC_ENTRY |
70 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_NEWL_ENTRY ); |
69 |
|
70 CCdcControlInterfaceReader* self = new(ELeave) CCdcControlInterfaceReader( |
71 CCdcControlInterfaceReader* self = new(ELeave) CCdcControlInterfaceReader( |
71 aParent, |
72 aParent, |
72 aLdd); |
73 aLdd); |
|
74 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_NEWL_EXIT ); |
73 return self; |
75 return self; |
74 } |
76 } |
75 |
77 |
76 void CCdcControlInterfaceReader::RunL() |
78 void CCdcControlInterfaceReader::RunL() |
77 /** |
79 /** |
78 * This function will be called when a read completes. |
80 * This function will be called when a read completes. |
79 */ |
81 */ |
80 { |
82 { |
81 LOGTEXT2(_L8(">>CCdcControlInterfaceReader::RunL iStatus=%d"), iStatus.Int()); |
83 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_RUNL_ENTRY ); |
|
84 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_RUNL, "CCdcControlInterfaceReader::RunL;iStatus=%d", iStatus.Int() ); |
82 HandleReadCompletion(iStatus.Int()); |
85 HandleReadCompletion(iStatus.Int()); |
83 LOGTEXT(_L8("<<CCdcControlInterfaceReader::RunL")); |
86 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_RUNL_EXIT ); |
84 } |
87 } |
85 |
88 |
86 void CCdcControlInterfaceReader::DoCancel() |
89 void CCdcControlInterfaceReader::DoCancel() |
87 /** |
90 /** |
88 * Cancel an outstanding read. |
91 * Cancel an outstanding read. |
89 */ |
92 */ |
90 { |
93 { |
91 LOG_FUNC |
94 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DOCANCEL_ENTRY ); |
92 iLdd.ReadCancel(EEndpoint0); |
95 iLdd.ReadCancel(EEndpoint0); |
|
96 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DOCANCEL_EXIT ); |
93 } |
97 } |
94 |
98 |
95 void CCdcControlInterfaceReader::HandleReadCompletion(TInt aError) |
99 void CCdcControlInterfaceReader::HandleReadCompletion(TInt aError) |
96 /** |
100 /** |
97 * This will be called when a new packet has been received. |
101 * This will be called when a new packet has been received. |
101 * packets have been received before decoding. |
105 * packets have been received before decoding. |
102 * |
106 * |
103 * @param aError Error |
107 * @param aError Error |
104 */ |
108 */ |
105 { |
109 { |
106 LOGTEXT2(_L8(">>CCdcControlInterfaceReader::HandleReadCompletion " |
110 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_ENTRY ); |
107 "aError=%d"), aError); |
111 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION, |
|
112 "CCdcControlInterfaceReader::HandleReadCompletion;aError=%d", aError ); |
108 |
113 |
109 if ( aError ) |
114 if ( aError ) |
110 { |
115 { |
111 ReadMessageHeader(); |
116 ReadMessageHeader(); |
112 LOGTEXT(_L8("<<CCdcControlInterfaceReader::HandleReadCompletion")); |
117 OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP1, |
|
118 "CCdcControlInterfaceReader::HandleReadCompletion" ); |
|
119 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_EXIT ); |
113 return; |
120 return; |
114 } |
121 } |
115 |
122 |
116 LOGTEXT2(_L8("\tcompleted with iState=%d"),iState); |
123 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP2, |
|
124 "CCdcControlInterfaceReader::HandleReadCompletion;iState=%d", (TInt)iState ); |
|
125 |
117 switch ( iState) |
126 switch ( iState) |
118 { |
127 { |
119 case EWaitingForHeader: |
128 case EWaitingForHeader: |
120 { |
129 { |
121 DecodeMessageHeader(); |
130 DecodeMessageHeader(); |
128 } |
137 } |
129 break; |
138 break; |
130 |
139 |
131 default: |
140 default: |
132 { |
141 { |
133 _USB_PANIC(KAcmPanicCat, EPanicIllegalState); |
142 OstTrace1( TRACE_FATAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP3, |
134 } |
143 "CCdcControlInterfaceReader::HandleReadCompletion;iState=%d", (TInt)iState ); |
135 break; |
144 User::Panic(KAcmPanicCat, EPanicIllegalState); |
136 } |
145 } |
137 |
146 break; |
138 LOGTEXT(_L8("<<CCdcControlInterfaceReader::HandleReadCompletion")); |
147 } |
|
148 |
|
149 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_EXIT_DUP1 ); |
139 } |
150 } |
140 |
151 |
141 void CCdcControlInterfaceReader::DecodeMessageHeader() |
152 void CCdcControlInterfaceReader::DecodeMessageHeader() |
142 /** |
153 /** |
143 * This function decodes a message header. It determines whether the host |
154 * This function decodes a message header. It determines whether the host |
144 * requires some data in response and dispatches the request appropriately. |
155 * requires some data in response and dispatches the request appropriately. |
145 */ |
156 */ |
146 { |
157 { |
147 LOG_FUNC |
158 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_ENTRY ); |
148 |
|
149 if ( TUsbRequestHdr::Decode(iMessageHeader, iRequestHeader) != KErrNone ) |
159 if ( TUsbRequestHdr::Decode(iMessageHeader, iRequestHeader) != KErrNone ) |
150 { |
160 { |
151 LOGTEXT(_L8("\t- Unable to decode request header!")); |
161 OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER, |
|
162 "CCdcControlInterfaceReader::DecodeMessageHeader;\t- Unable to decode request header!" ); |
|
163 |
152 // Stall bus- unknown message. If this fails, there's nothing we can |
164 // Stall bus- unknown message. If this fails, there's nothing we can |
153 // do. |
165 // do. |
154 static_cast<void>(iLdd.EndpointZeroRequestError()); |
166 static_cast<void>(iLdd.EndpointZeroRequestError()); |
155 ReadMessageHeader(); |
167 ReadMessageHeader(); |
|
168 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_EXIT ); |
156 return; |
169 return; |
157 } |
170 } |
158 |
171 |
159 LOGTEXT2(_L8("\t- New read! Request 0x%x"), iRequestHeader.iRequest); |
172 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_DUP1, |
160 |
173 "CCdcControlInterfaceReader::DecodeMessageHeader;\t- New read! Request %d", (TInt)iRequestHeader.iRequest ); |
|
174 |
161 if ( iRequestHeader.IsDataResponseRequired() ) |
175 if ( iRequestHeader.IsDataResponseRequired() ) |
162 { |
176 { |
163 DecodeMessageDataWithResponseRequired(); |
177 DecodeMessageDataWithResponseRequired(); |
164 } |
178 } |
165 else if ( iRequestHeader.iLength == 0 ) |
179 else if ( iRequestHeader.iLength == 0 ) |
169 } |
183 } |
170 else |
184 else |
171 { |
185 { |
172 ReadMessageData(iRequestHeader.iLength); |
186 ReadMessageData(iRequestHeader.iLength); |
173 } |
187 } |
|
188 OstTraceFunctionExit0( DUP1_CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_EXIT ); |
174 } |
189 } |
175 |
190 |
176 void CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired() |
191 void CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired() |
177 /** |
192 /** |
178 * Decode a message which requires data to be sent to the host in response. |
193 * Decode a message which requires data to be sent to the host in response. |
179 */ |
194 */ |
180 { |
195 { |
181 LOG_FUNC |
196 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_ENTRY ); |
182 |
197 OstTraceExt1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED, |
183 LOGTEXT2(_L8("\t- New read! Request 0x%x"), iRequestHeader.iRequest); |
198 "CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired;\t- New read! Request=%hhx", iRequestHeader.iRequest ); |
|
199 |
184 TBuf8<KAcmControlReadBufferLength> returnBuffer; |
200 TBuf8<KAcmControlReadBufferLength> returnBuffer; |
185 |
|
186 switch ( iRequestHeader.iRequest ) |
201 switch ( iRequestHeader.iRequest ) |
187 { |
202 { |
188 case KGetEncapsulated: |
203 case KGetEncapsulated: |
189 { |
204 { |
190 if ( iParent.HandleGetEncapResponse(returnBuffer) == KErrNone ) |
205 if ( iParent.HandleGetEncapResponse(returnBuffer) == KErrNone ) |
246 } |
261 } |
247 break; |
262 break; |
248 |
263 |
249 default: |
264 default: |
250 { |
265 { |
251 LOGTEXT2(_L8("\t- request number not recognised (%d)"), |
266 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_DUP1, |
252 iRequestHeader.iRequest); |
267 "CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired;\t- request number not recognised (%d)", |
|
268 (TInt)(iRequestHeader.iRequest) ); |
|
269 |
253 // Stall bus- unknown message. If this fails, there's nothing we can |
270 // Stall bus- unknown message. If this fails, there's nothing we can |
254 // do. |
271 // do. |
255 static_cast<void>(iLdd.EndpointZeroRequestError()); |
272 static_cast<void>(iLdd.EndpointZeroRequestError()); |
256 } |
273 } |
257 break; |
274 break; |
258 } |
275 } |
259 |
276 |
260 ReadMessageHeader(); |
277 ReadMessageHeader(); |
|
278 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_EXIT ); |
261 } |
279 } |
262 |
280 |
263 void CCdcControlInterfaceReader::DecodeMessageData() |
281 void CCdcControlInterfaceReader::DecodeMessageData() |
264 /** |
282 /** |
265 * Decode a message that does not require any data to be sent to the host in |
283 * Decode a message that does not require any data to be sent to the host in |
266 * response. In all the requests here, the completion of the class-specific |
284 * response. In all the requests here, the completion of the class-specific |
267 * function is ack'ed by sending an endpoint zero status packet. The request |
285 * function is ack'ed by sending an endpoint zero status packet. The request |
268 * can be nack'ed by signalling an endpoint zero request error. |
286 * can be nack'ed by signalling an endpoint zero request error. |
269 */ |
287 */ |
270 { |
288 { |
271 LOG_FUNC |
289 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_ENTRY ); |
272 |
|
273 if ( iMessageData.Length() != iRequestHeader.iLength ) |
290 if ( iMessageData.Length() != iRequestHeader.iLength ) |
274 { |
291 { |
275 LOGTEXT(_L8("\t- Data length is incorrect")); |
292 OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA, |
|
293 "CCdcControlInterfaceReader::DecodeMessageData;\t- Data length is incorrect" ); |
|
294 |
276 ReadMessageHeader(); |
295 ReadMessageHeader(); |
|
296 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_EXIT ); |
277 return; |
297 return; |
278 } |
298 } |
279 |
299 |
280 LOGTEXT2(_L8("\tNew read! Request %d"), iRequestHeader.iRequest); |
300 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_DUP1, |
281 |
301 "CCdcControlInterfaceReader::DecodeMessageData;\tNew read! Request %d", (TInt)(iRequestHeader.iRequest) ); |
|
302 |
282 switch ( iRequestHeader.iRequest ) |
303 switch ( iRequestHeader.iRequest ) |
283 { |
304 { |
284 case KSendEncapsulated: |
305 case KSendEncapsulated: |
285 if(iParent.HandleSendEncapCommand(iMessageData) == KErrNone) |
306 if(iParent.HandleSendEncapCommand(iMessageData) == KErrNone) |
286 { |
307 { |
364 // can do. |
385 // can do. |
365 static_cast<void>(iLdd.EndpointZeroRequestError()); |
386 static_cast<void>(iLdd.EndpointZeroRequestError()); |
366 } |
387 } |
367 break; |
388 break; |
368 default: |
389 default: |
369 LOGTEXT2(_L8("\t***request number not recognised (%d)"), |
390 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_DUP2, |
370 iRequestHeader.iRequest); |
391 "CCdcControlInterfaceReader::DecodeMessageData;\t***request number not recognised (%d)", (TInt)(iRequestHeader.iRequest) ); |
|
392 |
371 // Stall bus- unknown message. If this fails, there's nothing we can |
393 // Stall bus- unknown message. If this fails, there's nothing we can |
372 // do. |
394 // do. |
373 static_cast<void>(iLdd.EndpointZeroRequestError()); |
395 static_cast<void>(iLdd.EndpointZeroRequestError()); |
374 break; |
396 break; |
375 } |
397 } |
376 |
398 |
377 ReadMessageHeader(); |
399 ReadMessageHeader(); |
|
400 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_EXIT_DUP1 ); |
378 } |
401 } |
379 |
402 |
380 void CCdcControlInterfaceReader::ReadMessageHeader() |
403 void CCdcControlInterfaceReader::ReadMessageHeader() |
381 /** |
404 /** |
382 * Post a read request and set the state to indicate that we're waiting for a |
405 * Post a read request and set the state to indicate that we're waiting for a |
383 * message header. |
406 * message header. |
384 */ |
407 */ |
385 { |
408 { |
386 LOG_FUNC |
409 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_READMESSAGEHEADER_ENTRY ); |
387 |
|
388 iState = EWaitingForHeader; |
410 iState = EWaitingForHeader; |
389 |
|
390 iLdd.ReadPacket(iStatus, EEndpoint0, iMessageHeader, KUsbRequestHdrSize); |
411 iLdd.ReadPacket(iStatus, EEndpoint0, iMessageHeader, KUsbRequestHdrSize); |
391 SetActive(); |
412 SetActive(); |
|
413 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_READMESSAGEHEADER_EXIT ); |
392 } |
414 } |
393 |
415 |
394 void CCdcControlInterfaceReader::ReadMessageData(TUint aLength) |
416 void CCdcControlInterfaceReader::ReadMessageData(TUint aLength) |
395 /** |
417 /** |
396 * Post a read request and set the state to indicate that we're waiting for |
418 * Post a read request and set the state to indicate that we're waiting for |
397 * some message data. |
419 * some message data. |
398 * |
420 * |
399 * @param aLength Length of data to read. |
421 * @param aLength Length of data to read. |
400 */ |
422 */ |
401 { |
423 { |
402 LOG_FUNC |
424 OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_READMESSAGEDATA_ENTRY ); |
403 |
425 OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_READMESSAGEDATA, |
404 LOGTEXT2(_L8("\tqueuing read, length = %d"),aLength); |
426 "CCdcControlInterfaceReader::ReadMessageData;\tqueuing read, length = %d", (TInt)aLength ); |
405 |
427 |
406 iState = EWaitingForData; |
428 iState = EWaitingForData; |
407 |
|
408 iLdd.Read(iStatus, EEndpoint0, iMessageData, static_cast<TInt>(aLength)); |
429 iLdd.Read(iStatus, EEndpoint0, iMessageData, static_cast<TInt>(aLength)); |
409 SetActive(); |
430 SetActive(); |
|
431 OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_READMESSAGEDATA_EXIT ); |
410 } |
432 } |
411 |
433 |
412 // |
434 // |
413 // End of file |
435 // End of file |