traceservices/tracefw/integ_test/ulogger/TEF/device-driver/src/d_usbc.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
   276 		    return;
   276 		    return;
   277 		    }
   277 		    }
   278 		}
   278 		}
   279 	if (id < 0)
   279 	if (id < 0)
   280 		{
   280 		{
   281 		// DoRequestL
   281 		// DoRequest
   282 		TRequestStatus* pS = (TRequestStatus*) m.Ptr0();
   282 		TRequestStatus* pS = (TRequestStatus*) m.Ptr0();
   283 		DoRequestL(~id, pS, m.Ptr1(), m.Ptr2());
   283 		DoRequest(~id, pS, m.Ptr1(), m.Ptr2());
   284 		m.Complete(KErrNone, ETrue);
   284 		m.Complete(KErrNone, ETrue);
   285 		}
   285 		}
   286 	else
   286 	else
   287 		{
   287 		{
   288 		// DoControl
   288 		// DoControl
   312 		return KErrAccessDenied;
   312 		return KErrAccessDenied;
   313 		}
   313 		}
   314 	}
   314 	}
   315 // Asynchronous requests - overriding pure virtual
   315 // Asynchronous requests - overriding pure virtual
   316 //
   316 //
   317 void DLddUsbcChannel::DoRequestL(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
   317 void DLddUsbcChannel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
   318 	{
   318 	{
   319 	// Check on request status
   319 	// Check on request status
   320 	//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL 0x%08x", aReqNo));
   320 	//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest 0x%08x", aReqNo));
   321 	if (aReqNo <= KUsbcMaxRequests)
   321 	if (aReqNo <= KUsbcMaxRequests)
   322 		{
   322 		{
   323 		TInt r = KErrNone;
   323 		TInt r = KErrNone;
   324 		if (iRequestStatus[aReqNo] != NULL)
   324 		if (iRequestStatus[aReqNo] != NULL)
   325 			{
   325 			{
   440 	if (aEndpointNum == 0)
   440 	if (aEndpointNum == 0)
   441 		{
   441 		{
   442 		// ep0 requests
   442 		// ep0 requests
   443 		if (!(iValidInterface || iOwnsDeviceControl))
   443 		if (!(iValidInterface || iOwnsDeviceControl))
   444 			{
   444 			{
   445 			//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL rejected: not configured (Ep0)"));
   445 			//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest rejected: not configured (Ep0)"));
   446 			r = KErrUsbInterfaceNotReady;
   446 			r = KErrUsbInterfaceNotReady;
   447 			goto exit;
   447 			goto exit;
   448 			}
   448 			}
   449 		}
   449 		}
   450 	else
   450 	else
   452 		// other eps
   452 		// other eps
   453 		if (!(iValidInterface && (iDeviceState == EUsbcDeviceStateConfigured ||
   453 		if (!(iValidInterface && (iDeviceState == EUsbcDeviceStateConfigured ||
   454 		                          iDeviceState == EUsbcDeviceStateSuspended))
   454 		                          iDeviceState == EUsbcDeviceStateSuspended))
   455 		   )
   455 		   )
   456 			{
   456 			{
   457 			//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL rejected not configured (Ep %d)", aEndpointNum));
   457 			//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest rejected not configured (Ep %d)", aEndpointNum));
   458 			r = KErrUsbInterfaceNotReady;
   458 			r = KErrUsbInterfaceNotReady;
   459 			goto exit;
   459 			goto exit;
   460 			}
   460 			}
   461 		}
   461 		}
   462 
   462 
   463 	if (!ValidEndpoint(aEndpointNum))
   463 	if (!ValidEndpoint(aEndpointNum))
   464 		{
   464 		{
   465 		//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Read: in error complete"));
   465 		//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Read: in error complete"));
   466 		r = KErrUsbEpNotInInterface;
   466 		r = KErrUsbEpNotInInterface;
   467 		goto exit;
   467 		goto exit;
   468  		}
   468  		}
   469 
   469 
   470 	if (a1 == NULL)
   470 	if (a1 == NULL)
   479 	if (r != KErrNone)
   479 	if (r != KErrNone)
   480 		PanicClientThread(r);
   480 		PanicClientThread(r);
   481 	pEndpoint = iEndpoint[aEndpointNum];
   481 	pEndpoint = iEndpoint[aEndpointNum];
   482 	if (!pEndpoint)
   482 	if (!pEndpoint)
   483 		{
   483 		{
   484 		//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Read: in error complete"));
   484 		//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Read: in error complete"));
   485 		r = KErrUsbEpNotInInterface;
   485 		r = KErrUsbEpNotInInterface;
   486 		goto exit;
   486 		goto exit;
   487 		}
   487 		}
   488 
   488 
   489 	pEndpointInfo = pEndpoint->EndpointInfo();
   489 	pEndpointInfo = pEndpoint->EndpointInfo();
   490 	//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL %d", aEndpointNum));
   490 	//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest %d", aEndpointNum));
   491 
   491 
   492 	switch (pTfr->iTransferType)
   492 	switch (pTfr->iTransferType)
   493 		{
   493 		{
   494 
   494 
   495 	case ETransferTypeReadData:
   495 	case ETransferTypeReadData:
   496 	case ETransferTypeReadPacket:
   496 	case ETransferTypeReadPacket:
   497 	case ETransferTypeReadUntilShort:
   497 	case ETransferTypeReadUntilShort:
   498 	case ETransferTypeReadOneOrMore:
   498 	case ETransferTypeReadOneOrMore:
   499 		{
   499 		{
   500 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Read"));
   500 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Read"));
   501 		if (pEndpoint->iDmaBuffers->RxIsActive())
   501 		if (pEndpoint->iDmaBuffers->RxIsActive())
   502 			{
   502 			{
   503 			//__KTRACE_OPT(KUSB, Kern::Printf("**** ReadReq ep%d RxActive", aEndpointNum));
   503 			//__KTRACE_OPT(KUSB, Kern::Printf("**** ReadReq ep%d RxActive", aEndpointNum));
   504 			}
   504 			}
   505 		else
   505 		else
   509 
   509 
   510 		if (pEndpointInfo->iDir != KUsbEpDirOut &&
   510 		if (pEndpointInfo->iDir != KUsbEpDirOut &&
   511 			pEndpointInfo->iDir != KUsbEpDirBidirect)
   511 			pEndpointInfo->iDir != KUsbEpDirBidirect)
   512 			{
   512 			{
   513 			// Trying to do the wrong thing
   513 			// Trying to do the wrong thing
   514 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Read: in error complete"));
   514 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Read: in error complete"));
   515 			r = KErrUsbEpBadDirection;
   515 			r = KErrUsbEpBadDirection;
   516 			break;
   516 			break;
   517 			}
   517 			}
   518 		// Set the length of data to zero now to catch all cases
   518 		// Set the length of data to zero now to catch all cases
   519 		TPtrC8 pZeroDesc(NULL, 0);
   519 		TPtrC8 pZeroDesc(NULL, 0);
   528 			}
   528 			}
   529 		else
   529 		else
   530 			{
   530 			{
   531 			if (pTfr->iTransferType == ETransferTypeReadPacket)
   531 			if (pTfr->iTransferType == ETransferTypeReadPacket)
   532 				{
   532 				{
   533 				//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Read packet: data available complete"));
   533 				//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Read packet: data available complete"));
   534 				r = pEndpoint->CopyToClient(iClient);
   534 				r = pEndpoint->CopyToClient(iClient);
   535 				aNeedsCompletion = ETrue;
   535 				aNeedsCompletion = ETrue;
   536 				break;
   536 				break;
   537 				}
   537 				}
   538 			else if (pTfr->iTransferType == ETransferTypeReadData)
   538 			else if (pTfr->iTransferType == ETransferTypeReadData)
   539 				{
   539 				{
   540 				if (pTfr->iTransferSize <= pEndpoint->RxBytesAvailable())
   540 				if (pTfr->iTransferSize <= pEndpoint->RxBytesAvailable())
   541 					{
   541 					{
   542 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Read data: data available complete"));
   542 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Read data: data available complete"));
   543 					r = pEndpoint->CopyToClient(iClient);
   543 					r = pEndpoint->CopyToClient(iClient);
   544 					aNeedsCompletion = ETrue;
   544 					aNeedsCompletion = ETrue;
   545 					break;
   545 					break;
   546 					}
   546 					}
   547 				else
   547 				else
   551 				}
   551 				}
   552 			else if (pTfr->iTransferType == ETransferTypeReadOneOrMore)
   552 			else if (pTfr->iTransferType == ETransferTypeReadOneOrMore)
   553 				{
   553 				{
   554 				if (pEndpoint->RxBytesAvailable() > 0)
   554 				if (pEndpoint->RxBytesAvailable() > 0)
   555 					{
   555 					{
   556 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Read data: data available complete"));
   556 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Read data: data available complete"));
   557 					r = pEndpoint->CopyToClient(iClient);
   557 					r = pEndpoint->CopyToClient(iClient);
   558 					aNeedsCompletion = ETrue;
   558 					aNeedsCompletion = ETrue;
   559 					break;
   559 					break;
   560 					}
   560 					}
   561 				else
   561 				else
   569 				TInt maxPacketSize = pEndpoint->EndpointInfo()->iSize;
   569 				TInt maxPacketSize = pEndpoint->EndpointInfo()->iSize;
   570 				if( (pTfr->iTransferSize <= nRx) ||
   570 				if( (pTfr->iTransferSize <= nRx) ||
   571 					(nRx < maxPacketSize) ||
   571 					(nRx < maxPacketSize) ||
   572 					pEndpoint->iDmaBuffers->ShortPacketExists())
   572 					pEndpoint->iDmaBuffers->ShortPacketExists())
   573 					{
   573 					{
   574 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Read data: data available complete"));
   574 					//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Read data: data available complete"));
   575 					r = pEndpoint->CopyToClient(iClient);
   575 					r = pEndpoint->CopyToClient(iClient);
   576 					aNeedsCompletion = ETrue;
   576 					aNeedsCompletion = ETrue;
   577 					}
   577 					}
   578 				else
   578 				else
   579 					{
   579 					{
   582 				}
   582 				}
   583 			}
   583 			}
   584 		r = pEndpoint->TryToStartRead(EFalse);
   584 		r = pEndpoint->TryToStartRead(EFalse);
   585 		if (r != KErrNone)
   585 		if (r != KErrNone)
   586 			{
   586 			{
   587 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Read: couldn't start read"));
   587 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Read: couldn't start read"));
   588 			r = KErrNone;									// Reader full isn't a userside error;
   588 			r = KErrNone;									// Reader full isn't a userside error;
   589 			}
   589 			}
   590 		break;
   590 		break;
   591 		}
   591 		}
   592 
   592 
   593 	case ETransferTypeWrite:
   593 	case ETransferTypeWrite:
   594 		{
   594 		{
   595 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Write 1"));
   595 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Write 1"));
   596 		if (pEndpointInfo->iDir != KUsbEpDirIn &&
   596 		if (pEndpointInfo->iDir != KUsbEpDirIn &&
   597 			pEndpointInfo->iDir != KUsbEpDirBidirect)
   597 			pEndpointInfo->iDir != KUsbEpDirBidirect)
   598 			{
   598 			{
   599 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Write: wrong direction complete"));
   599 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Write: wrong direction complete"));
   600 			r = KErrUsbEpBadDirection;
   600 			r = KErrUsbEpBadDirection;
   601 			break;
   601 			break;
   602 			}
   602 			}
   603 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Write 2"));
   603 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Write 2"));
   604 
   604 
   605 		TAny* logicalSrc = pTfr->iDes;
   605 		TAny* logicalSrc = pTfr->iDes;
   606 		TInt desLength = Kern::ThreadGetDesLength(iClient, logicalSrc);
   606 		TInt desLength = Kern::ThreadGetDesLength(iClient, logicalSrc);
   607 		if (desLength < pTfr->iTransferSize)
   607 		if (desLength < pTfr->iTransferSize)
   608 			{
   608 			{
   609 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Write: user buffer too short"));
   609 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Write: user buffer too short"));
   610 			r = KErrUsbTransferSize;
   610 			r = KErrUsbTransferSize;
   611 			break;
   611 			break;
   612 			}
   612 			}
   613 
   613 
   614 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequestL Write 3 length=%d maxlength=%d",
   614 		//__KTRACE_OPT(KUSB, Kern::Printf("DoRequest Write 3 length=%d maxlength=%d",
   615 									//	pTfr->iTransferSize, desLength));
   615 									//	pTfr->iTransferSize, desLength));
   616 		// Zero length writes are acceptable
   616 		// Zero length writes are acceptable
   617 		pEndpoint->SetClientWritePending(ETrue);
   617 		pEndpoint->SetClientWritePending(ETrue);
   618 		r = pEndpoint->TryToStartWrite(pTfr);
   618 		r = pEndpoint->TryToStartWrite(pTfr);
   619 		if (r != KErrNone)
   619 		if (r != KErrNone)
   620 			{
   620 			{
   621 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequestL Write: couldn't start write"));
   621 			//__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DoRequest Write: couldn't start write"));
   622 			pEndpoint->SetClientWritePending(EFalse);
   622 			pEndpoint->SetClientWritePending(EFalse);
   623 			}
   623 			}
   624 		break;
   624 		break;
   625 		}
   625 		}
   626 
   626