sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // @file controlendpointreader.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "controlendpointreader.h" sl@0: #include "testdebug.h" sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: CControlEndpointReader::CControlEndpointReader(RDevUsbcClient& aClientDriver,MRequestHandler& aRequestHandler) sl@0: : CEndpointReader(aClientDriver,EEndpoint0), sl@0: iDeviceToHost(EFalse), sl@0: iDataPhase(EFalse), sl@0: iRequestHandler(aRequestHandler) sl@0: { sl@0: } sl@0: sl@0: sl@0: CControlEndpointReader::~CControlEndpointReader() sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: sl@0: void CControlEndpointReader::ReadRequestsL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Read a packet from endpoint 0 (this should incorporate a request) sl@0: sl@0: ReadPacketL(this); sl@0: } sl@0: sl@0: sl@0: void CControlEndpointReader::EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: RDebug::Printf(" Asynchronous read on endpoint %d",aErrorCode,aEndpointNumber); sl@0: } sl@0: sl@0: sl@0: void CControlEndpointReader::DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: RDebug::Printf("ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength); sl@0: RDebug::Printf("iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase); sl@0: if(iDeviceToHost && iDataPhase) sl@0: { sl@0: TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,aData); sl@0: RDebug::Printf("ProdessRequestL returned %d",err); sl@0: sl@0: if(err != KErrAbort) sl@0: { sl@0: iDeviceToHost = EFalse; sl@0: iDataPhase = EFalse; sl@0: sl@0: // After processing the request keep reading for more requests sl@0: // from the host sl@0: ReadPacketL(this); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Understand the setup packet sl@0: ibRequestType = aData[0]; sl@0: iDeviceToHost = (ibRequestType & 0x80) == 0x00; sl@0: sl@0: // The request sl@0: ibRequest = aData[1]; sl@0: sl@0: // The request parameter sl@0: TUint8* p = reinterpret_cast(&iwValue); sl@0: *p = aData[2]; sl@0: *(p+1) = aData[3]; sl@0: sl@0: // The index for the request sl@0: p = reinterpret_cast(&iwIndex); sl@0: *p = aData[4]; sl@0: *(p+1) = aData[5]; sl@0: sl@0: // The length of data transfer sl@0: p = reinterpret_cast(&iwLength); sl@0: *p = aData[6]; sl@0: *(p+1) = aData[7]; sl@0: sl@0: iDataPhase = (iwLength > 0); sl@0: sl@0: // Read all information about the request sent by the host sl@0: // i.e. any DATA1 packets sent after the setup DATA0 packet sl@0: RDebug::Printf("AFTER UPDATES"); sl@0: RDebug::Printf("ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength); sl@0: RDebug::Printf("iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase); sl@0: if(iDeviceToHost && iDataPhase) sl@0: { sl@0: RDebug::Printf("Issuing another read of %d bytes",iwLength); sl@0: ReadL(iwLength); sl@0: } sl@0: else sl@0: { sl@0: TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,KNullDesC8); sl@0: sl@0: if(err != KErrAbort) sl@0: { sl@0: // After processing the request keep reading for more requests sl@0: // from the host sl@0: ReadPacketL(this); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: }