1 /* |
1 /* |
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-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". |
89 |
89 |
90 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
91 // Starts state machine |
91 // Starts state machine |
92 // --------------------------------------------------------------------------- |
92 // --------------------------------------------------------------------------- |
93 // |
93 // |
94 void CStateMachine::Start() |
94 void CStateMachine::StartL() |
95 { |
95 { |
96 |
96 |
97 FLOG( _L( "[USBDEVCON]\tCStateMachine::Start" ) ); |
97 FLOG( _L( "[USBDEVCON]\tCStateMachine::Start" ) ); |
98 |
98 |
99 // resetting, if it's been already started |
99 // resetting, if it's been already started |
144 |
144 |
145 // --------------------------------------------------------------------------- |
145 // --------------------------------------------------------------------------- |
146 // Something has been read from EP0 |
146 // Something has been read from EP0 |
147 // --------------------------------------------------------------------------- |
147 // --------------------------------------------------------------------------- |
148 // |
148 // |
149 void CStateMachine::ReadEP0(RBuf8& aBuffer, const TRequestStatus& aStatus) |
149 void CStateMachine::ReadEP0L(RBuf8& aBuffer, const TRequestStatus& aStatus) |
150 { |
150 { |
151 |
151 |
152 FTRACE(FPrint( |
152 FTRACE(FPrint( |
153 _L("[USBDEVCON]\tCStateMachine::ReadEP0: BufferLength = %d, aStatus = %d" ),aBuffer.Length(), aStatus.Int())); |
153 _L("[USBDEVCON]\tCStateMachine::ReadEP0: BufferLength = %d, aStatus = %d" ),aBuffer.Length(), aStatus.Int())); |
154 |
154 |
155 // all errors while reading data lead to idle state (ESetupStage in our case) |
155 // all errors while reading data lead to idle state (ESetupStage in our case) |
156 if(KErrNone != aStatus.Int()) |
156 if(KErrNone != aStatus.Int()) |
157 { |
157 { |
158 // restart |
158 // restart |
159 Start(); |
159 StartL(); |
160 return; |
160 return; |
161 } |
161 } |
162 |
162 |
163 TInt err(KErrNone); |
163 TInt err(KErrNone); |
164 |
164 |
169 |
169 |
170 FLOG( _L( "[USBDEVCON]\tCStateMachine::ReadEP0 processing ESetupStage" ) ); |
170 FLOG( _L( "[USBDEVCON]\tCStateMachine::ReadEP0 processing ESetupStage" ) ); |
171 |
171 |
172 if(aBuffer.Length() != KSetupPacketLength) // SetupPacket is always 8 bytes |
172 if(aBuffer.Length() != KSetupPacketLength) // SetupPacket is always 8 bytes |
173 { |
173 { |
174 Start(); |
174 StartL(); |
175 return; |
175 return; |
176 } |
176 } |
177 |
177 |
178 ProcessSetupPacket(aBuffer); |
178 ProcessSetupPacketL(aBuffer); |
179 |
179 |
180 break; |
180 break; |
181 } |
181 } |
182 case EDataStage: // some data received from host. This data is required for the request, received on setup stage |
182 case EDataStage: // some data received from host. This data is required for the request, received on setup stage |
183 { |
183 { |
216 |
216 |
217 // --------------------------------------------------------------------------- |
217 // --------------------------------------------------------------------------- |
218 // Processing setup packet |
218 // Processing setup packet |
219 // --------------------------------------------------------------------------- |
219 // --------------------------------------------------------------------------- |
220 // |
220 // |
221 void CStateMachine::ProcessSetupPacket(RBuf8& aSetupPacket) |
221 void CStateMachine::ProcessSetupPacketL(RBuf8& aSetupPacket) |
222 { |
222 { |
223 |
223 |
224 FLOG( _L( "[USBDEVCON]\tCStateMachine::ProcessSetupPacket" ) ); |
224 FLOG( _L( "[USBDEVCON]\tCStateMachine::ProcessSetupPacket" ) ); |
225 |
225 |
226 TUint datalength(0); // data length, to be received from host |
226 TUint datalength(0); // data length, to be received from host |
231 FTRACE(FPrint( |
231 FTRACE(FPrint( |
232 _L("[USBDEVCON]\tCStateMachine::ProcessSetupPacket. Data from host is required: %d bytes" ),datalength)); |
232 _L("[USBDEVCON]\tCStateMachine::ProcessSetupPacket. Data from host is required: %d bytes" ),datalength)); |
233 |
233 |
234 // save request, until receiving following data |
234 // save request, until receiving following data |
235 iBuffer.Close(); |
235 iBuffer.Close(); |
236 iBuffer.Create(aSetupPacket); |
236 iBuffer.CreateL(aSetupPacket); |
237 |
237 |
238 // switch to Data state |
238 // switch to Data state |
239 iState = EDataStage; |
239 iState = EDataStage; |
240 iEP0Reader->Read(datalength); |
240 iEP0Reader->ReadL(datalength); |
241 |
241 |
242 return; |
242 return; |
243 |
243 |
244 } |
244 } |
245 |
245 |
270 |
270 |
271 FTRACE(FPrint( |
271 FTRACE(FPrint( |
272 _L("[USBDEVCON]\tCStateMachine::ProcessSetupPacket. Data from device is required: %d bytes" ),datalength)); |
272 _L("[USBDEVCON]\tCStateMachine::ProcessSetupPacket. Data from device is required: %d bytes" ),datalength)); |
273 |
273 |
274 iState = EStatusStage; |
274 iState = EStatusStage; |
275 iEP0Writer->Write(iBuffer, datalength); |
275 iEP0Writer->WriteL(iBuffer, datalength); |
276 |
276 |
277 return; |
277 return; |
278 |
278 |
279 } |
279 } |
280 |
280 |
281 // status stage |
281 // status stage |
282 iLdd.SendEp0StatusPacket(); |
282 iLdd.SendEp0StatusPacket(); |
283 |
283 |
284 // all is done, listen to EP0, in setup stage |
284 // all is done, listen to EP0, in setup stage |
285 iState = ESetupStage; |
285 iState = ESetupStage; |
286 iEP0Reader->ReadSetupPacket(); |
286 iEP0Reader->ReadSetupPacketL(); |
287 |
287 |
288 } |
288 } |
289 |
289 |
290 |
290 |
291 // --------------------------------------------------------------------------- |
291 // --------------------------------------------------------------------------- |
292 // Something has been written to EP0 |
292 // Something has been written to EP0 |
293 // --------------------------------------------------------------------------- |
293 // --------------------------------------------------------------------------- |
294 // |
294 // |
295 void CStateMachine::WroteEP0(const TRequestStatus& aStatus) |
295 void CStateMachine::WroteEP0L(const TRequestStatus& aStatus) |
296 { |
296 { |
297 |
297 |
298 FTRACE(FPrint( |
298 FTRACE(FPrint( |
299 _L("[USBDEVCON]\tCStateMachine::WroteEP0: iStatus = %d" ), aStatus.Int())); |
299 _L("[USBDEVCON]\tCStateMachine::WroteEP0: iStatus = %d" ), aStatus.Int())); |
300 |
300 |
301 // all errors while writing data lead to idle state (ESetupStage in our case) |
301 // all errors while writing data lead to idle state (ESetupStage in our case) |
302 if(KErrNone != aStatus.Int()) |
302 if(KErrNone != aStatus.Int()) |
303 { |
303 { |
304 // restart |
304 // restart |
305 Start(); |
305 StartL(); |
306 } |
306 } |
307 |
307 |
308 switch(iState) |
308 switch(iState) |
309 { |
309 { |
310 case EStatusStage: |
310 case EStatusStage: |