162 * |
159 * |
163 * @param aStatus The caller's request status, filled in with an error code |
160 * @param aStatus The caller's request status, filled in with an error code |
164 */ |
161 */ |
165 void CUsbstub2ClassController::Start(TRequestStatus& aStatus) |
162 void CUsbstub2ClassController::Start(TRequestStatus& aStatus) |
166 { |
163 { |
167 OstTraceFunctionEntry0( CUSBSTUB2CLASSCONTROLLER_START_ENTRY ); |
164 LOG_FUNC |
168 |
165 |
169 aStatus = KRequestPending; |
166 aStatus = KRequestPending; |
170 iReportStatus = &aStatus; |
167 iReportStatus = &aStatus; |
171 //If we are already started then just complete the request. |
168 //If we are already started then just complete the request. |
172 if (iState == EUsbServiceStarted) |
169 if (iState == EUsbServiceStarted) |
173 { |
170 { |
174 User::RequestComplete(iReportStatus, KErrNone); |
171 User::RequestComplete(iReportStatus, KErrNone); |
175 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_START_EXIT ); |
|
176 return; |
172 return; |
177 } |
173 } |
178 |
174 |
179 if (iFailToStart) |
175 if (iFailToStart) |
180 { |
176 { |
181 User::RequestComplete(iReportStatus, KErrGeneral); |
177 User::RequestComplete(iReportStatus, KErrGeneral); |
182 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_START_EXIT_DUP1 ); |
|
183 return; |
178 return; |
184 } |
179 } |
185 |
180 |
186 iState = EUsbServiceStarting; |
181 iState = EUsbServiceStarting; |
187 #ifndef __WINS__ |
182 #ifndef __WINS__ |
188 TInt ret = iLdd.Open(0); |
183 TInt ret = iLdd.Open(0); |
189 OstTrace1( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_START,_L8("Open LDD, ret=%d"),ret); |
184 LOGTEXT2(_L8("Open LDD, ret=%d"), ret); |
190 ret = SetUpInterface(); |
185 ret = SetUpInterface(); |
191 OstTrace1( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_START_DUP1, |
186 LOGTEXT2(_L8("SetUpInterface(), ret=%d"), ret); |
192 _L8("SetUpInterface(),ret=%d"),ret); |
|
193 |
|
194 #endif |
187 #endif |
195 |
188 |
196 |
189 |
197 iTimer.After(iStatus, iStartDelay*1000); //convert from usec to msec |
190 iTimer.After(iStatus, iStartDelay*1000); //convert from usec to msec |
198 SetActive(); |
191 SetActive(); |
199 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_START_EXIT_DUP2 ); |
|
200 } |
192 } |
201 |
193 |
202 /** |
194 /** |
203 * Called by UsbMan when it wants to stop the USB stub2 class. |
195 * Called by UsbMan when it wants to stop the USB stub2 class. |
204 * |
196 * |
205 * @param aStatus The caller's request status: always set to KErrNone |
197 * @param aStatus The caller's request status: always set to KErrNone |
206 */ |
198 */ |
207 void CUsbstub2ClassController::Stop(TRequestStatus& aStatus) |
199 void CUsbstub2ClassController::Stop(TRequestStatus& aStatus) |
208 { |
200 { |
209 OstTraceFunctionEntry0( CUSBSTUB2CLASSCONTROLLER_STOP_ENTRY ); |
201 LOG_FUNC |
|
202 |
210 aStatus = KRequestPending; |
203 aStatus = KRequestPending; |
211 iReportStatus = &aStatus; |
204 iReportStatus = &aStatus; |
212 //If we are already idle then just complete the request. |
205 //If we are already idle then just complete the request. |
213 if (iState == EUsbServiceIdle) |
206 if (iState == EUsbServiceIdle) |
214 { |
207 { |
215 User::RequestComplete(iReportStatus, KErrNone); |
208 User::RequestComplete(iReportStatus, KErrNone); |
216 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_STOP_EXIT ); |
|
217 return; |
209 return; |
218 } |
210 } |
219 |
211 |
220 if (iFailToStop) |
212 if (iFailToStop) |
221 { |
213 { |
222 User::RequestComplete(iReportStatus, KErrGeneral); |
214 User::RequestComplete(iReportStatus, KErrGeneral); |
223 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_STOP_EXIT_DUP1 ); |
|
224 return; |
215 return; |
225 } |
216 } |
226 |
217 |
227 iState = EUsbServiceStopping; |
218 iState = EUsbServiceStopping; |
228 |
219 |
230 iLdd.Close(); |
221 iLdd.Close(); |
231 #endif |
222 #endif |
232 |
223 |
233 iTimer.After(iStatus, iStopDelay*1000); //convert from usec to msec |
224 iTimer.After(iStatus, iStopDelay*1000); //convert from usec to msec |
234 SetActive(); |
225 SetActive(); |
235 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_STOP_EXIT_DUP2 ); |
|
236 } |
226 } |
237 |
227 |
238 /** |
228 /** |
239 * Gets information about the descriptor which this class provides. |
229 * Gets information about the descriptor which this class provides. |
240 * |
230 * |
241 * @param aDescriptorInfo Descriptor info structure filled in by this function |
231 * @param aDescriptorInfo Descriptor info structure filled in by this function |
242 */ |
232 */ |
243 void CUsbstub2ClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const |
233 void CUsbstub2ClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const |
244 { |
234 { |
245 OstTraceFunctionEntry0( CUSBSTUB2CLASSCONTROLLER_GETDESCRIPTORINFO_ENTRY ); |
235 LOG_FUNC |
246 |
236 |
247 aDescriptorInfo.iLength = Kstub2DescriptorLength; |
237 aDescriptorInfo.iLength = Kstub2DescriptorLength; |
248 aDescriptorInfo.iNumInterfaces = Kstub2NumberOfInterfacesPerstub2Function; |
238 aDescriptorInfo.iNumInterfaces = Kstub2NumberOfInterfacesPerstub2Function; |
249 |
|
250 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_GETDESCRIPTORINFO_EXIT ); |
|
251 } |
239 } |
252 |
240 |
253 |
241 |
254 /** |
242 /** |
255 * Standard active object RunL. |
243 * Standard active object RunL. |
256 */ |
244 */ |
257 void CUsbstub2ClassController::RunL() |
245 void CUsbstub2ClassController::RunL() |
258 { |
246 { |
259 OstTraceFunctionEntry0( CUSBSTUB2CLASSCONTROLLER_RUNL_ENTRY ); |
247 LOG_FUNC |
260 |
248 |
261 if(iStatus != KErrNone) |
249 __ASSERT_DEBUG( iStatus == KErrNone, _USB_PANIC(Kstub2CcPanicCategory, EPanicUnexpectedStatus) ); |
262 { |
|
263 OstTrace1( TRACE_FATAL, CUSBSTUB2CLASSCONTROLLER_RUNL, |
|
264 "CUsbstub2ClassController::RunL panic with error %d", EPanicUnexpectedStatus); |
|
265 __ASSERT_DEBUG(EFalse,User::Panic(Kstub2CcPanicCategory,EPanicUnexpectedStatus)); |
|
266 } |
|
267 switch (iState) |
250 switch (iState) |
268 { |
251 { |
269 case EUsbServiceStarting: |
252 case EUsbServiceStarting: |
270 iState = EUsbServiceStarted; |
253 iState = EUsbServiceStarted; |
271 break; |
254 break; |
272 case EUsbServiceStopping: |
255 case EUsbServiceStopping: |
273 iState = EUsbServiceIdle; |
256 iState = EUsbServiceIdle; |
274 break; |
257 break; |
275 default: |
258 default: |
276 OstTrace1( TRACE_FATAL, CUSBSTUB2CLASSCONTROLLER_RUNL_DUP1, |
259 _USB_PANIC(Kstub2CcPanicCategory, EPanicUnexpectedState); |
277 "CUsbstub2ClassController::RunL panic with error %d", EPanicUnexpectedStatus); |
|
278 User::Panic(Kstub2CcPanicCategory, EPanicUnexpectedState); |
|
279 } |
260 } |
280 *iReportStatus = KErrNone; |
261 *iReportStatus = KErrNone; |
281 User::RequestComplete(iReportStatus, iStatus.Int()); |
262 User::RequestComplete(iReportStatus, iStatus.Int()); |
282 OstTraceFunctionExit0( CUSBSTUB2CLASSCONTROLLER_RUNL_EXIT ); |
|
283 } |
263 } |
284 |
264 |
285 /** |
265 /** |
286 * Standard active object cancellation function. Never called because this |
266 * Standard active object cancellation function. Never called because this |
287 * class has no asynchronous requests. |
267 * class has no asynchronous requests. |
317 * @param aError The error code (unused) |
295 * @param aError The error code (unused) |
318 * @return Always KErrNone to avoid an active scheduler panic |
296 * @return Always KErrNone to avoid an active scheduler panic |
319 */ |
297 */ |
320 TInt CUsbstub2ClassController::RunError(TInt /*aError*/) |
298 TInt CUsbstub2ClassController::RunError(TInt /*aError*/) |
321 { |
299 { |
322 OstTrace1( TRACE_FATAL, CUSBSTUB2CLASSCONTROLLER_RUNERROR, |
300 __ASSERT_DEBUG( EFalse, _USB_PANIC(Kstub2CcPanicCategory, EUnusedFunction) ); |
323 "CUsbstub2ClassController::RunError panic with error %d", |
|
324 EUnusedFunction); |
|
325 __ASSERT_DEBUG(EFalse,User::Panic(Kstub2CcPanicCategory, EUnusedFunction)); |
|
326 return KErrNone; |
301 return KErrNone; |
327 } |
302 } |
328 |
303 |
329 TInt CUsbstub2ClassController::SetUpInterface() |
304 TInt CUsbstub2ClassController::SetUpInterface() |
330 /** |
305 /** |
331 * Set up the interface for use. This involves finding a "Interrupt IN" |
306 * Set up the interface for use. This involves finding a "Interrupt IN" |
332 * endpoint and, if found, configuring the interface. |
307 * endpoint and, if found, configuring the interface. |
333 */ |
308 */ |
334 { |
309 { |
335 OstTrace0( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE, |
310 LOGTEXT(_L8(">>CCdcControlInterface::SetUpInterface")); |
336 _L8(">>CCdcControlInterface::SetUpInterface")); |
311 |
337 |
|
338 TUsbDeviceCaps dCaps; |
312 TUsbDeviceCaps dCaps; |
339 TInt ret = iLdd.DeviceCaps(dCaps); |
313 TInt ret = iLdd.DeviceCaps(dCaps); |
340 OstTrace0( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP1, |
314 LOGTEXT(_L8("\tchecking result of DeviceCaps")); |
341 _L8("\tchecking result of DeviceCaps")); |
|
342 |
|
343 if ( ret ) |
315 if ( ret ) |
344 { |
316 { |
345 OstTrace1( TRACE_ERROR, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP2, |
317 LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret); |
346 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret ); |
|
347 |
|
348 return ret; |
318 return ret; |
349 } |
319 } |
350 |
320 |
351 const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0. |
321 const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0. |
352 |
322 |
353 const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints); |
323 const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints); |
354 OstTrace1( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP3, |
324 LOGTEXT2(_L8("\tiTotalEndpoints = %d"), totalEndpoints); |
355 _L8("\tiTotalEndpoints = %d"), totalEndpoints ); |
|
356 |
|
357 if ( totalEndpoints < KRequiredNumberOfEndpoints ) |
325 if ( totalEndpoints < KRequiredNumberOfEndpoints ) |
358 { |
326 { |
359 OstTrace1( TRACE_ERROR, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP4, |
327 LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), |
360 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), KErrGeneral); |
328 KErrGeneral); |
361 |
|
362 return KErrGeneral; |
329 return KErrGeneral; |
363 } |
330 } |
364 |
331 |
365 // Endpoints |
332 // Endpoints |
366 TUsbcEndpointData data[KUsbcMaxEndpoints]; |
333 TUsbcEndpointData data[KUsbcMaxEndpoints]; |
367 TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
334 TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
368 ret = iLdd.EndpointCaps(dataptr); |
335 ret = iLdd.EndpointCaps(dataptr); |
369 OstTrace0( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP5, |
336 LOGTEXT(_L8("\tchecking result of EndpointCaps")); |
370 _L8("\tchecking result of EndpointCaps")); |
|
371 |
|
372 if ( ret ) |
337 if ( ret ) |
373 { |
338 { |
374 OstTrace1( TRACE_ERROR, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP6, |
339 LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret); |
375 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret ); |
|
376 |
|
377 return ret; |
340 return ret; |
378 } |
341 } |
379 |
342 |
380 // Set the active interface |
343 // Set the active interface |
381 TUsbcInterfaceInfoBuf ifc; |
344 TUsbcInterfaceInfoBuf ifc; |
382 TBool epFound = EFalse; |
345 TBool epFound = EFalse; |
383 for ( TUint i = 0 ; i < totalEndpoints ; i++ ) |
346 for ( TUint i = 0 ; i < totalEndpoints ; i++ ) |
384 { |
347 { |
385 const TUsbcEndpointCaps* caps = &data[i].iCaps; |
348 const TUsbcEndpointCaps* caps = &data[i].iCaps; |
386 if(!caps) |
349 __ASSERT_DEBUG(caps,_USB_PANIC(Kstub2CcPanicCategory, EPanicUnexpectedStatus)); |
387 { |
350 |
388 OstTrace1( TRACE_FATAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP7, |
|
389 "CUsbstub2ClassController::SetUpInterface panic with error %d", |
|
390 EPanicUnexpectedStatus); |
|
391 __ASSERT_DEBUG(EFalse,User::Panic(Kstub2CcPanicCategory,EPanicUnexpectedStatus)); |
|
392 } |
|
393 if (data[i].iInUse) |
351 if (data[i].iInUse) |
394 { |
352 { |
395 continue; |
353 continue; |
396 } |
354 } |
397 |
355 |
430 // Codes taken from USBCDC 1.1. |
386 // Codes taken from USBCDC 1.1. |
431 ifc().iClass.iClassNum = 0x02; // Table 15- Communication Interface Class |
387 ifc().iClass.iClassNum = 0x02; // Table 15- Communication Interface Class |
432 ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model |
388 ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model |
433 ifc().iClass.iProtocolNum = 0x01; // Table 17- Hayes compatible |
389 ifc().iClass.iProtocolNum = 0x01; // Table 17- Hayes compatible |
434 |
390 |
435 OstTrace0( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP10, |
391 LOGTEXT(_L8("\tabout to call SetInterface")); |
436 _L8("\tabout to call SetInterface")); |
|
437 |
|
438 // Zero effectively indicates that alternate interfaces are not used. |
392 // Zero effectively indicates that alternate interfaces are not used. |
439 ret = iLdd.SetInterface(0, ifc); |
393 ret = iLdd.SetInterface(0, ifc); |
440 |
394 |
441 OstTrace1( TRACE_NORMAL, CUSBSTUB2CLASSCONTROLLER_SETUPINTERFACE_DUP11, |
395 LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret); |
442 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret ); |
|
443 |
|
444 return ret; |
396 return ret; |
445 } |
397 } |
446 |
398 |
447 // |
399 // |
448 // End of file |
400 // End of file |