os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cbulkonlytransportusbcscldd.cpp
First public contribution.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "cbulkonlytransport.h"
25 #include "cbulkonlytransportusbcscldd.h"
26 #include "usbmsshared.h"
27 #include "massstoragedebug.h"
28 #include "cusbmassstorageserver.h"
31 //This value defined in USB Mass Storage Bulk Only Transrt spec and not supposed to be changed
32 LOCAL_D const TInt KRequiredNumberOfEndpoints = 2; // in addition to endpoint 0.
34 LOCAL_D const TInt KUsbNumInterfacesOffset = 4;
36 #ifdef MSDC_MULTITHREADED
37 //Only used in DB. The first 2K of KMaxScBufferSize for sending CSW
38 static const TUint32 KCswBufferSize = 2 * 1024;
41 ////////////////////////////////////
43 Called by CBulkOnlyTransportUsbcScLdd to create an instance of CControlInterfaceUsbcScLdd
45 @param aParent reference to the CBulkOnlyTransportUsbcScLdd
49 CControlInterfaceUsbcScLdd* CControlInterfaceUsbcScLdd::NewL(CBulkOnlyTransportUsbcScLdd& aParent)
51 CControlInterfaceUsbcScLdd* self = new(ELeave) CControlInterfaceUsbcScLdd(aParent);
52 CleanupStack::PushL(self);
54 CActiveScheduler::Add(self);
60 void CControlInterfaceUsbcScLdd::ConstructL()
68 @param aParent reference to the CBulkOnlyTransportUsbcScLdd
70 CControlInterfaceUsbcScLdd::CControlInterfaceUsbcScLdd(CBulkOnlyTransportUsbcScLdd& aParent)
71 :CActive(EPriorityStandard),
81 CControlInterfaceUsbcScLdd::~CControlInterfaceUsbcScLdd()
83 __FNLOG("CControlInterfaceUsbcScLdd::~CControlInterfaceUsbcScLdd ");
88 TInt CControlInterfaceUsbcScLdd::OpenEp0()
90 TInt res = iParent.Ldd().OpenEndpoint(iEp0Buf,0);
95 Called by CBulkOnlyTransport HwStart to start control interface
97 TInt CControlInterfaceUsbcScLdd::Start()
99 __FNLOG("CControlInterfaceUsbcScLdd::Start ");
100 TInt res = ReadEp0Data();
106 Called by desctructor of CBulkOnlyTransportUsbcScLdd to stop control interface
108 void CControlInterfaceUsbcScLdd::Stop()
110 __FNLOG("CControlInterfaceUsbcScLdd::Stop ");
113 __PRINT(_L("Not active\n"));
117 __PRINT(_L("\nStopping...\n"));
120 iCurrentState = ENone;
127 Cancel outstanding request (if any)
129 void CControlInterfaceUsbcScLdd::DoCancel()
131 __FNLOG("CControlInterfaceUsbcScLdd::DoCancel ");
132 switch(iCurrentState)
135 iParent.Ldd().ReadCancel(KUsbcScEndpointZero);
138 iParent.Ldd().WriteCancel(KUsbcScEndpointZero);
141 __PRINT(_L("\nWrong state !\n"));
142 __ASSERT_DEBUG(EFalse, User::Panic(KUsbMsSvrPncCat, EMsControlInterfaceBadState));
148 Implement CControlInterfaceUsbcScLdd state machine
150 void CControlInterfaceUsbcScLdd::RunL()
152 __FNLOG("CControlInterfaceUsbcScLdd::RunL ");
153 if (iStatus != KErrNone)
155 __PRINT1(_L("Error %d in RunL\n"), iStatus.Int());
166 Actual Read to RDevUsbcScClient BIL
168 TInt CControlInterfaceUsbcScLdd::ReadUsbEp0()
170 iCurrentState = EReadEp0Data;
171 iStatus = KRequestPending;
172 return iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,iStatus);
177 Post a read request to EEndpoint0 to read request header
179 TInt CControlInterfaceUsbcScLdd::ReadEp0Data()
181 __FNLOG("CControlInterfaceUsbcScLdd::ReadEp0Data ");
184 __PRINT(_L("Still active\n"));
185 return KErrServerBusy;
192 if (r == KErrCompletion)
197 else if (r == KErrNone)
201 } while (((r == KErrCompletion) || (r == TEndpointBuffer::KStateChange)) && (!IsActive()));
207 Decode request header and do appropriate action - get max LUN info or post a reset request
209 void CControlInterfaceUsbcScLdd::DecodeEp0Data()
211 __FNLOG("CControlInterfaceUsbcScLdd::DecodeEp0Data ");
215 __PRINT(_L("Still active\n"));
216 __ASSERT_DEBUG(EFalse, User::Panic(KUsbMsSvrPncCat, EMsControlInterfaceStillActive));
220 TPtrC8 ep0ReadDataPtr((TUint8*)iEp0Packet, iEp0Size);
221 TInt err = iRequestHeader.Decode(ep0ReadDataPtr);
226 switch(iRequestHeader.iRequest)
229 // GET MAX LUN (0xFE)
231 case TUsbRequestHdr::EReqGetMaxLun:
233 __PRINT1(_L("DecodeEp0Data : 'Get Max LUN' Request MaxLun = %d"),iParent.MaxLun() );
235 if ( iRequestHeader.iRequestType != 0xA1 //value from USB MS BOT spec
236 || iRequestHeader.iIndex > 15
237 || iRequestHeader.iValue != 0
238 || iRequestHeader.iLength != 1)
240 __PRINT(_L("GetMaxLun command packet check error"));
241 iParent.Ldd().EndpointZeroRequestError();
245 TPtr8* ep0WriteDataPtr = NULL;
247 iEp0Buf.GetInBufferRange(((TAny*&)ep0WriteDataPtr),ep0Length);
248 ep0WriteDataPtr->SetLength(1); //Return only 1 byte to host
249 ep0WriteDataPtr->Fill(0);
250 ep0WriteDataPtr->Fill(iParent.MaxLun()); // Supported Units
251 TInt length = ep0WriteDataPtr->Length();
252 err = iEp0Buf.WriteBuffer((TPtr8*)(ep0WriteDataPtr->Ptr()),length,ETrue,iStatus);
254 iCurrentState = ESendMaxLun;
262 case TUsbRequestHdr::EReqReset:
264 __PRINT(_L("DecodeEp0Data : 'Mass Storage Reset' Request"));
266 if ( iRequestHeader.iRequestType != 0x21 //value from USB MS BOT spec
267 || iRequestHeader.iIndex > 15
268 || iRequestHeader.iValue != 0
269 || iRequestHeader.iLength != 0)
271 __PRINT(_L("MSC Reset command packet check error"));
272 iParent.Ldd().EndpointZeroRequestError();
277 iParent.Controller().Reset();
278 iParent.HwStart(ETrue);
280 err = iParent.Ldd().SendEp0StatusPacket();
288 __PRINT(_L("DecodeEp0Data : Unknown Request"));
292 ReadEp0Data(); //try to get another request
297 // --- class CBulkOnlyTransportUsbcScLdd ---------------------------------------------------------
300 CBulkOnlyTransportUsbcScLdd::CBulkOnlyTransportUsbcScLdd(TInt aNumDrives,CUsbMassStorageController& aController)
301 :CBulkOnlyTransport(aNumDrives, aController)
303 __FNLOG("CBulkOnlyTransportUsbcScLdd::CBulkOnlyTransportUsbcScLdd");
307 Constructs the CBulkOnlyTransportUsbcScLdd object
309 void CBulkOnlyTransportUsbcScLdd::ConstructL()
311 __FNLOG("CBulkOnlyTransportUsbcScLdd::ConstructL()");
312 iControlInterface = CControlInterfaceUsbcScLdd::NewL(*this);
313 iDeviceStateNotifier = CActiveDeviceStateNotifierBase::NewL(*this, *this);
314 iChunk = new RChunk();
315 CActiveScheduler::Add(this);
319 CBulkOnlyTransportUsbcScLdd::~CBulkOnlyTransportUsbcScLdd()
321 __FNLOG("CBulkOnlyTransportUsbcScLdd::~CBulkOnlyTransportUsbcScLdd");
322 if (iInterfaceConfigured)
324 TInt err = iSCReadEndpointBuf.Close();
325 err = iSCWriteEndpointBuf.Close();
326 delete iControlInterface ;
327 delete iDeviceStateNotifier;
332 RDevUsbcScClient& CBulkOnlyTransportUsbcScLdd::Ldd()
338 Set or unset configuration descriptor for USB MassStorage Bulk Only transport
340 @param aUnset indicate whether set or unset descriptor
341 @return KErrNone if operation was completed successfully, errorcode otherwise
343 TInt CBulkOnlyTransportUsbcScLdd::SetupConfigurationDescriptor(TBool aUnset)
345 __FNLOG("CBulkOnlyTransportUsbcScLdd::SetupConfigurationDescriptor");
348 if ((ret = iLdd.Open(0)) != KErrNone)
351 TInt configDescriptorSize(0);
352 iLdd.GetConfigurationDescriptorSize(configDescriptorSize);
353 if (static_cast<TUint>(configDescriptorSize) != KUsbDescSize_Config)
358 TBuf8<KUsbDescSize_Config> configDescriptor;
359 ret = iLdd.GetConfigurationDescriptor(configDescriptor);
365 // I beleive that other fields setted up during LDD initialisation
368 --configDescriptor[KUsbNumInterfacesOffset];
372 ++configDescriptor[KUsbNumInterfacesOffset];
374 ret = iLdd.SetConfigurationDescriptor(configDescriptor);
385 Set up interface descriptor
387 @return KErrNone if operation was completed successfully, errorcode otherwise
389 TInt CBulkOnlyTransportUsbcScLdd::SetupInterfaceDescriptors()
391 __FNLOG("CBulkOnlyTransportUsbcScLdd::SetupInterfaceDescriptors");
393 TUsbDeviceCaps d_caps;
394 TInt ret = iLdd.DeviceCaps(d_caps);
399 TInt totalEndpoints = d_caps().iTotalEndpoints;
400 if (totalEndpoints < KRequiredNumberOfEndpoints)
402 return KErrHardwareNotAvailable;
406 TUsbcEndpointData data[KUsbcMaxEndpoints];
407 TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
408 ret = iLdd.EndpointCaps(dataptr);
414 // Set the active interface
415 TUsbcScInterfaceInfoBuf ifc;
417 TBool foundBulkIN = EFalse;
418 TBool foundBulkOUT = EFalse;
420 for (TInt i = 0; i < totalEndpoints ; i++)
422 const TUsbcEndpointCaps* caps = &data[i].iCaps;
423 const TInt maxPacketSize = caps->MaxPacketSize();
425 (caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) == (KUsbEpTypeBulk | KUsbEpDirIn))
427 // InEndpoint is going to be our TX (IN, write) endpoint
428 ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
429 if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) == KUsbDevCapsFeatureWord1_EndpointResourceAllocV2)
430 ifc().iEndpointData[0].iFeatureWord1 = KUsbcEndpointInfoFeatureWord1_DMA|KUsbcEndpointInfoFeatureWord1_DoubleBuffering;
431 ifc().iEndpointData[0].iDir = KUsbEpDirIn;
432 ifc().iEndpointData[0].iSize = maxPacketSize;
433 ifc().iEndpointData[0].iInterval_Hs = 0;
434 ifc().iEndpointData[0].iBufferSize = KMaxScBufferSize;
436 if (++ep_found == KRequiredNumberOfEndpoints)
443 (caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) == (KUsbEpTypeBulk | KUsbEpDirOut))
445 // OutEndpoint is going to be our RX (OUT, read) endpoint
446 ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
447 if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) == KUsbDevCapsFeatureWord1_EndpointResourceAllocV2)
448 ifc().iEndpointData[1].iFeatureWord1 = KUsbcEndpointInfoFeatureWord1_DMA|KUsbcEndpointInfoFeatureWord1_DoubleBuffering;
449 ifc().iEndpointData[1].iDir = KUsbEpDirOut;
450 ifc().iEndpointData[1].iSize = maxPacketSize;
451 ifc().iEndpointData[1].iInterval_Hs = 0;
452 ifc().iEndpointData[1].iBufferSize = KMaxScBufferSize;
453 ifc().iEndpointData[1].iReadSize = KMaxScReadSize;
455 foundBulkOUT = ETrue;
456 if (++ep_found == KRequiredNumberOfEndpoints)
463 if (ep_found != KRequiredNumberOfEndpoints)
465 return KErrHardwareNotAvailable;
468 _LIT16(string, "USB Mass Storage Interface");
469 ifc().iString = const_cast<TDesC16*>(&string);
470 ifc().iTotalEndpointsUsed = KRequiredNumberOfEndpoints;
471 ifc().iClass.iClassNum = 0x08; // Mass Storage
472 ifc().iClass.iSubClassNum = 0x06; // SCSI Transparent Command Set
473 ifc().iClass.iProtocolNum = 0x50; // Bulk Only Transport
475 if (d_caps().iHighSpeed)
477 // Tell the Protocol about it, because it might want to do some
479 iProtocol->ReportHighSpeedDevice();
482 if ((ret = iLdd.SetInterface(0, ifc)) == KErrNone)
484 return (iLdd.FinalizeInterface(iChunk));
489 void CBulkOnlyTransportUsbcScLdd::ReleaseInterface()
491 iLdd.ReleaseInterface(0);
495 TInt CBulkOnlyTransportUsbcScLdd::StartControlInterface()
497 return iControlInterface->Start();
500 void CBulkOnlyTransportUsbcScLdd::CancelControlInterface()
502 iControlInterface->Cancel();
505 void CBulkOnlyTransportUsbcScLdd::ActivateDeviceStateNotifier()
507 iDeviceStateNotifier->Activate();
510 void CBulkOnlyTransportUsbcScLdd::CancelDeviceStateNotifier()
512 iDeviceStateNotifier->Cancel();
516 void CBulkOnlyTransportUsbcScLdd::CancelReadWriteRequests()
518 __FNLOG("CBulkOnlyTransportUsbcScLdd::CancelReadWriteRequests");
519 TUsbcScChunkHeader chunkHeader(*iChunk);
520 for (TInt i = 0; i < chunkHeader.iAltSettings->iNumOfAltSettings; i++)
522 TInt8* endpoint = (TInt8*) (chunkHeader.iAltSettings->iAltTableOffset[i] + (TInt) iChunk->Base());
523 TInt numOfEps = chunkHeader.GetNumberOfEndpoints(i);
524 __ASSERT_DEBUG(numOfEps >= 0, User::Invariant());
525 for (TInt j = 1; j <= numOfEps; j++)
527 TUsbcScHdrEndpointRecord* endpointInf = (TUsbcScHdrEndpointRecord*) &(endpoint[j * chunkHeader.iAltSettings->iEpRecordSize]);
528 if (endpointInf->Direction() == KUsbScHdrEpDirectionOut)
530 iLdd.ReadCancel(endpointInf->iBufferNo);
532 if (endpointInf->Direction() == KUsbScHdrEpDirectionIn)
534 iLdd.WriteCancel(endpointInf->iBufferNo);
540 void CBulkOnlyTransportUsbcScLdd::AllocateEndpointResources()
542 TUsbcScChunkHeader chunkHeader(*iChunk);
543 for (TInt i = 0; i < chunkHeader.iAltSettings->iNumOfAltSettings; i++)
545 TInt8* endpoint = (TInt8*) (chunkHeader.iAltSettings->iAltTableOffset[i] + (TInt) iChunk->Base());
547 for (TInt j = 1; j <= chunkHeader.GetNumberOfEndpoints(i); j++)
549 TUsbcScHdrEndpointRecord* endpointInf = (TUsbcScHdrEndpointRecord*) &(endpoint[j * chunkHeader.iAltSettings->iEpRecordSize]);
550 if (endpointInf->Direction() == KUsbScHdrEpDirectionOut)
554 if (endpointInf->Direction() == KUsbScHdrEpDirectionIn)
561 TUsbDeviceCaps d_caps;
563 TInt ret = iLdd.DeviceCaps(d_caps);
566 if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != KUsbDevCapsFeatureWord1_EndpointResourceAllocV2)
568 __PRINT(_L("CBulkOnlyTransportUsbcScLdd::Start - Setting up DMA and double buffering\n"));
569 // Set up DMA if possible (errors are non-critical)
570 err = iLdd.AllocateEndpointResource(iOutEndpoint, EUsbcEndpointResourceDMA);
573 __PRINT1(_L("Set DMA on OUT endpoint failed with error code: %d"), err);
575 err = iLdd.AllocateEndpointResource(iInEndpoint, EUsbcEndpointResourceDMA);
578 __PRINT1(_L("Set DMA on IN endpoint failed with error code: %d"), err);
581 // Set up Double Buffering if possible (errors are non-critical)
582 err = iLdd.AllocateEndpointResource(iOutEndpoint, EUsbcEndpointResourceDoubleBuffering);
585 __PRINT1(_L("Set Double Buffering on OUT endpoint failed with error code: %d"), err);
587 err = iLdd.AllocateEndpointResource(iInEndpoint, EUsbcEndpointResourceDoubleBuffering);
590 __PRINT1(_L("Set Double Buffering on IN endpoint failed with error code: %d"), err);
595 err = OpenEndpoints();
598 TInt CBulkOnlyTransportUsbcScLdd::OpenEndpoints()
600 TInt res = iLdd.OpenEndpoint(iSCReadEndpointBuf, iOutEndpoint);
603 res = iLdd.OpenEndpoint(iSCWriteEndpointBuf, iInEndpoint);
606 iSCWriteEndpointBuf.GetInBufferRange((TAny*&)iDataPtr, iInBufferLength);
607 res = iControlInterface->OpenEp0();
616 TInt CBulkOnlyTransportUsbcScLdd::GetDeviceStatus(TUsbcDeviceState& deviceStatus)
618 return iLdd.DeviceStatus(deviceStatus);
621 void CBulkOnlyTransportUsbcScLdd::FlushData()
623 // Intentionally Left Blank Do Nothing
627 * Read out rest data from OutEndpoint and discard them
629 void CBulkOnlyTransportUsbcScLdd::ReadAndDiscardData(TInt /*aBytes*/)
631 __FNLOG("CBulkOnlyTransport::ReadAndDiscardData");
632 TRequestStatus status;
633 TInt r = KErrNone; // Lets assume there is no data
638 r = iSCReadEndpointBuf.TakeBuffer(iSCReadData,iSCReadSize,iReadZlp,status);
639 iSCReadEndpointBuf.Expire();
641 while (r == KErrCompletion);
645 TRequestStatus* stat = &status;
646 User::RequestComplete(stat, KErrNone);
651 Called by the protocol to determine how many bytes of data are available in the read buffer.
653 @return The number of bytes available in the read buffer
655 TInt CBulkOnlyTransportUsbcScLdd::BytesAvailable()
657 // Intentionally Left Blank Do Nothing
661 void CBulkOnlyTransportUsbcScLdd::StallEndpointAndWaitForClear()
663 __FNLOG("CBulkOnlyTransportUsbcScLdd::StallEndpointAndWaitForClear");
665 // Now stall this endpoint
666 __PRINT1(_L("Stalling endpoint %d"), iInEndpoint);
667 TInt r = iLdd.HaltEndpoint(iInEndpoint);
670 __PRINT2(_L("Error: stalling ep %d failed: %d"), iInEndpoint, r);
672 TEndpointState ep_state;
676 // Wait for 10ms before checking the ep status
678 iLdd.EndpointStatus(iInEndpoint, ep_state);
681 // 5.5 secs should be enough (see 9.2.6.1 Request Processing Timing)
682 __PRINT1(_L("Error: Checked for ep %d de-stall for 5.5s - giving up now"), iInEndpoint);
683 // We can now only hope for a Reset Recovery
686 } while ((ep_state == EEndpointStateStalled) && iStarted);
687 __PRINT2(_L("Checked for ep %d de-stall: %d time(s)"), iInEndpoint, i);
691 Read CBW data from the host and decode it.
693 void CBulkOnlyTransportUsbcScLdd::ReadCBW()
695 __FNLOG("CBulkOnlyTransportUsbcScLdd::ReadCBW");
698 __PRINT(_L("Still active\n"));
699 __ASSERT_DEBUG(EFalse, User::Panic(KUsbMsSvrPncCat, EMsBulkOnlyStillActive));
706 if ((r == KErrCompletion) && (iSCReadSize == KCbwLength))
708 iCurrentState = EWaitForCBW;
713 else if (r == KErrNone)
715 iCurrentState = EWaitForCBW;
718 else if ((r == KErrCompletion) && (iSCReadSize != KCbwLength))
720 ExpireData(iSCReadData);
722 }while ((r == KErrCompletion) && (!IsActive()));
725 void CBulkOnlyTransportUsbcScLdd::ExpireData(TAny* aAddress)
729 iSCReadEndpointBuf.Expire(aAddress);
733 iSCReadEndpointBuf.Expire();
737 void CBulkOnlyTransportUsbcScLdd::ProcessCbwEvent()
743 Request data form the host for the protocol
745 @param aLength amount of data (in bytes) to be received from the host
747 void CBulkOnlyTransportUsbcScLdd::ReadData(TUint /*aLength*/)
749 __FNLOG("CBulkOnlyTransportUsbcScLdd::ReadData");
752 __PRINT(_L("Still active\n"));
753 __ASSERT_DEBUG(EFalse, User::Panic(KUsbMsSvrPncCat, EMsBulkOnlyStillActive));
760 iCurrentState = EReadingData;
761 if (r == KErrCompletion)
763 iReadBufPtr.Set((TUint8*) iSCReadData, iSCReadSize, iSCReadSize);
765 ProcessDataFromHost();
768 else if (r == KErrNone)
774 }while ((r == KErrCompletion) && (!IsActive()));
777 void CBulkOnlyTransportUsbcScLdd::ProcessDataFromHost()
783 ret = iProtocol->ReadComplete(KErrNone);
785 #ifndef MSDC_MULTITHREADED
786 ExpireData(iSCReadData);
788 TUint deviceDataLength = iSCReadSize; // What was written to the disk // static_cast<TUint>(iReadBuf.Length());
789 if(ret == KErrCompletion)
791 // The protocol has indicated with KErrCompletion that sufficient
792 // data is available in the buffer to process the transfer immediately.
794 //iDataResidue is initially set to host data length as we do not know how much data is there in the 'LDD transfer'.
795 //After a TakeBuffer call, iSCReadSize in updated and set to deviceDataLength
796 iDataResidue -= deviceDataLength;
800 iDataResidue -= deviceDataLength;
802 // The protocol has indicated that transfer is
803 // complete, so send the CSW response to the host.
808 iCmdStatus = ECommandFailed;
813 __PRINT(_L("Discarding residue"));
814 // we have to read as much data as available that host PC sends;
815 // otherwise, bulk-out endpoint will need to keep sending NAK back.
816 ReadAndDiscardData(iDataResidue);
819 SendCSW(iCbwTag, iDataResidue, iCmdStatus);
824 void CBulkOnlyTransportUsbcScLdd::WriteUsb(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired)
826 TUint aOffset = (TUint) aDes.Ptr() - (TUint) iChunk->Base();
827 iSCWriteEndpointBuf.WriteBuffer(aOffset, aLength, aZlpRequired, aStatus);
830 void CBulkOnlyTransportUsbcScLdd::SetCbwPtr()
832 iCbwBufPtr.Set((TUint8*)iSCReadData, iSCReadSize);
835 TPtr8& CBulkOnlyTransportUsbcScLdd::SetCommandBufPtr(TUint aLength)
837 TPtr8 writeBuf((TUint8*) iDataPtr, aLength);
838 iCommandBufPtr.Set(writeBuf);
839 return iCommandBufPtr;
842 void CBulkOnlyTransportUsbcScLdd::SetReadDataBufPtr(TUint /*aLength*/)
844 // Do nothing for now
847 TPtr8& CBulkOnlyTransportUsbcScLdd::SetDataBufPtr()
849 TPtr8 writeBuf((TUint8*) iDataPtr, iInBufferLength);
850 iDataBufPtr.Set(writeBuf);
854 void CBulkOnlyTransportUsbcScLdd::SetPaddingBufPtr(TUint aLength)
856 TPtr8 writeBuf((TUint8*) iDataPtr, aLength, aLength);
857 iPaddingBufPtr.Set(writeBuf);
860 void CBulkOnlyTransportUsbcScLdd::SetCswBufPtr(TUint aLength)
862 TPtr8 writeBuf((TUint8*) iDataPtr, aLength, aLength);
863 iCswBufPtr.Set(writeBuf);
866 void CBulkOnlyTransportUsbcScLdd::ProcessReadingDataEvent()
871 TInt CBulkOnlyTransportUsbcScLdd::ReadUsb(TUint /*aLength*/)
873 __FNLOG("CBulkOnlyTransportUsbcScLdd::ReadUSB");
874 return iSCReadEndpointBuf.TakeBuffer(iSCReadData,iSCReadSize,iReadZlp,iStatus);
877 void CBulkOnlyTransportUsbcScLdd::DiscardData(TUint aLength)
880 TRequestStatus status;
886 r = iSCReadEndpointBuf.TakeBuffer(iSCReadData,iSCReadSize,iReadZlp,status);
889 User::WaitForRequest(status);
890 if (r == KErrCompletion)
892 iSCReadEndpointBuf.Expire();
898 void CBulkOnlyTransportUsbcScLdd::WriteToClient(TUint aLength)
901 TRequestStatus status;
907 r = iSCReadEndpointBuf.TakeBuffer(iSCReadData,iSCReadSize,iReadZlp,status);
909 iProtocol->ReadComplete(KErrGeneral);
911 User::WaitForRequest(status);
912 if (r == KErrCompletion)
914 iSCReadEndpointBuf.Expire();
920 #ifdef MSDC_MULTITHREADED
921 void CBulkOnlyTransportUsbcScLdd::GetBufferPointers(TPtr8& aDes1, TPtr8& aDes2)
924 TUint length = (TUint) (iInBufferLength - KCswBufferSize) / 2;
926 TUint8* start = (TUint8*) (iDataPtr) + KCswBufferSize ; // 'first' buffer
927 aDes1.Set(start, length, length);
929 start = (TUint8*) (iDataPtr) + KCswBufferSize + length; // 'second' buffer
930 aDes2.Set(start, length, length);
934 void CBulkOnlyTransportUsbcScLdd::Activate(TRequestStatus& aStatus, TUint& aDeviceState)
936 iLdd.AlternateDeviceStatusNotify(aStatus, aDeviceState);
940 void CBulkOnlyTransportUsbcScLdd::Cancel()
942 iLdd.AlternateDeviceStatusNotifyCancel();