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: //
sl@0: 
sl@0: #ifndef D32USBDI_H
sl@0: #define D32USBDI_H
sl@0: 
sl@0: #ifdef __KERNEL_MODE__
sl@0: #include <kernel/klib.h>
sl@0: #else
sl@0: #include <e32base.h>
sl@0: #include <d32usbdescriptors.h>
sl@0: #endif
sl@0: #include <e32ver.h>
sl@0: #include <d32usbdi_errors.h>
sl@0: 
sl@0: /**
sl@0: @file
sl@0: @publishedPartner
sl@0: @prototype
sl@0: Intended to be available to 3rd parties later
sl@0: */
sl@0: 
sl@0: 
sl@0: class RUsbPipe;
sl@0: class RUsbTransferDescriptor;
sl@0: class RUsbTransferStrategy;
sl@0: 
sl@0: typedef TUint32 TUsbBusId;
sl@0: typedef void* TUsbBus; // handle for an os_bus
sl@0: 
sl@0: /**
sl@0: Functions which act on a specific interface on a remote device.
sl@0: */
sl@0: class RUsbInterface : public RBusLogicalChannel
sl@0: 	{
sl@0: public:
sl@0: 	NONSHARABLE_CLASS(TUsbTransferRequestDetails)
sl@0: 		{
sl@0: 	public:
sl@0: 		enum TEp0TransferFlags
sl@0: 			{
sl@0: 			EShortTransferOk	= 0x04,
sl@0: 			};
sl@0: 
sl@0: 	public:
sl@0: 		TUint8			iRequestType;
sl@0: 		TUint8			iRequest;
sl@0: 		TUint16			iValue;
sl@0: 		TUint16			iIndex;
sl@0: 		TInt			iFlags;
sl@0: 
sl@0:         // Internal: these should not be set or used, however making them private
sl@0:         // would require the internal DUsbChannel class be exposed as a friend in
sl@0:         // userside
sl@0: 		const TDesC8*	iSend;
sl@0: 		TDes8*			iRecv;
sl@0: 		};
sl@0: 
sl@0: 	NONSHARABLE_CLASS(TChunkRequestDetails)
sl@0: 		{
sl@0: 	public:
sl@0: 		// In
sl@0: 		TInt iRequestSize;
sl@0: 		//Out
sl@0: 		TInt* iChunkHandle;
sl@0: 		TInt* iOffset;
sl@0: 		};
sl@0: 
sl@0: 	NONSHARABLE_CLASS(TTransferMemoryDetails)
sl@0: 		{
sl@0: 	public:
sl@0: 		TInt	iType;
sl@0: 		TUint	iAlignment;
sl@0: 		TInt	iSize;
sl@0: 		TInt	iMaxPackets;
sl@0: 		};
sl@0: 
sl@0: 	enum TDeviceSpeed
sl@0: 		{
sl@0: 		ELowSpeed,
sl@0: 		EFullSpeed,
sl@0: 		EHighSpeed
sl@0: 		};
sl@0: 	enum TUsbInterfaceRequest
sl@0: 		{
sl@0: 		ESuspend,
sl@0: 		EEp0Transfer,
sl@0: 		};
sl@0: 	enum TUsbInterfaceControl
sl@0: 		{
sl@0: 		EOpenPipe,
sl@0: 		EPermitRemoteWakeup,
sl@0: 		EGetInterfaceDescriptorSize,
sl@0: 		EGetInterfaceDescriptor,
sl@0: 		EGetStringDescriptor,
sl@0: 		ESelectAlternateInterface,
sl@0: 		EAllocChunk,
sl@0: 		EGetDeviceSpeed,
sl@0: 		EGetBusId,
sl@0: 		EHcdPageSize,
sl@0: 		EGetSizeAndAlignment,
sl@0: 		};
sl@0: 	enum TUsbInterfaceCancel
sl@0: 		{
sl@0: 		ECancelSuspend			= 0x00000001,
sl@0: 		ECancelWaitForResume    = 0x00000002,
sl@0: 		ECancelEp0Transfer		= 0x00000004
sl@0: 		};
sl@0: 
sl@0: public:
sl@0: 	inline static const TDesC& Name();
sl@0: 	inline static TVersion VersionRequired();
sl@0: 
sl@0: #ifndef __KERNEL_MODE__
sl@0: friend class RUsbPipe;
sl@0: friend class RUsbZeroCopyTransferStrategy;
sl@0: 
sl@0: public:
sl@0: 	inline RUsbInterface();
sl@0: 
sl@0: 	//
sl@0: 	// Standard R-class lifetime controls
sl@0: 	//
sl@0: 	IMPORT_C TInt Open(TUint32 aToken, TOwnerType aType = EOwnerProcess);
sl@0: 	IMPORT_C void Close();
sl@0: 
sl@0: 	//
sl@0: 	// Transfer allocation/initialisation functions
sl@0: 	//
sl@0: 	IMPORT_C TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer);
sl@0: 	IMPORT_C void ResetTransferDescriptors();
sl@0: 	IMPORT_C TInt InitialiseTransferDescriptors();
sl@0: 
sl@0: 	//
sl@0: 	// Endpoint Zero transfer utilities
sl@0: 	//
sl@0: 	inline void Ep0Transfer(TUsbTransferRequestDetails& aDetails, const TDesC8& aSend, TDes8& aRecv, TRequestStatus& aRequest);
sl@0: 	inline void CancelEP0Transfer();
sl@0: 	inline TInt GetStringDescriptor(TDes8& aStringDescriptor, TUint8 aIndex, TUint16 aLangId);
sl@0: 
sl@0: 	//
sl@0: 	// Suspend/Resume functionality
sl@0: 	//
sl@0: 	inline void PermitSuspendAndWaitForResume(TRequestStatus& aResumeSignal);
sl@0: 	inline void CancelPermitSuspend();
sl@0: 	inline void CancelWaitForResume();
sl@0: 	inline TInt PermitRemoteWakeup(TBool aPermitted);
sl@0: 	
sl@0: 	
sl@0: 	//
sl@0: 	// Descriptor access functions
sl@0: 	//
sl@0: 	inline TInt GetInterfaceDescriptor(TUsbInterfaceDescriptor& aDescriptor);
sl@0: 	inline TInt GetAlternateInterfaceDescriptor(TInt aAlternateInterface, TUsbInterfaceDescriptor& aDescriptor);
sl@0: 	inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor& aDescriptor);
sl@0: 
sl@0: 	// Utility functions to avoid having to parse the entire descriptor tree in simple cases.
sl@0: 	inline TInt GetAlternateInterfaceCount();
sl@0: 	inline TInt EnumerateEndpointsOnInterface(TInt aAlternateInterface);
sl@0: 
sl@0: 	//
sl@0: 	// Interface configuration functions
sl@0: 	//
sl@0: 	inline TInt SelectAlternateInterface(TInt aAlternateInterface);
sl@0: 	inline TInt OpenPipeForEndpoint(RUsbPipe& aPipe, TInt aEndpoint, TBool aUseDMA);
sl@0: 	
sl@0: 	//
sl@0: 	// Some utility functions
sl@0: 	//
sl@0: 	inline TInt GetBusId(TUsbBusId& aBusId);
sl@0: 	inline TInt HcdPageSize();
sl@0: 	inline TInt GetDeviceSpeed(TDeviceSpeed& aDeviceSpeed);
sl@0: 
sl@0: private:
sl@0: 	inline TInt AllocateSharedChunk(RChunk& aChunk, TInt aSize, TInt& aOffset);
sl@0: 	TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer, TUsbBusId aBusId);
sl@0: 	inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor*& aDescriptor);
sl@0: 
sl@0: private:
sl@0: 	TUsbInterfaceDescriptor* iHeadInterfaceDescriptor;
sl@0: 	HBufC8* iInterfaceDescriptorData;
sl@0: 	
sl@0: 	RUsbTransferStrategy* iTransferStrategy;
sl@0: 	
sl@0: 	TInt iAlternateSetting;
sl@0: #endif
sl@0: 	};
sl@0: 
sl@0: typedef TUint64 TUsbEndpointId;
sl@0: 
sl@0: /**
sl@0: Functions which act on an individual pipe established between the local host and a remote device.
sl@0: */
sl@0: class RUsbPipe
sl@0: 	{
sl@0: public:
sl@0: 	enum TUsbPipeRequest
sl@0: 		{
sl@0:         EIssueTransfer		= 0x4000000,            // Start from a different value compared to interfaces
sl@0:                                                     // to allow them to be distinguished while debugging
sl@0: 		};
sl@0: 	enum TUsbPipeControl
sl@0: 		{
sl@0: 		EClose					= 0x4000000,        // Start from a different value compared to interfaces
sl@0:                                                     // to allow them to be distinguished while debugging
sl@0: 		EAbort,
sl@0: 		EClearRemoteStall,
sl@0: 		EGetEndpointId,
sl@0: 		};
sl@0: 
sl@0: #ifndef __KERNEL_MODE__
sl@0: friend class RUsbInterface;
sl@0: friend class RUsbTransferStrategy;
sl@0: friend class RUsbZeroCopyTransferStrategy;
sl@0: public:
sl@0: 	inline RUsbPipe();
sl@0: 
sl@0: 	inline void Close();
sl@0: 	inline TUint32 Handle() const;
sl@0: 
sl@0: 	inline TInt GetEndpointId(TUsbEndpointId& aEndpointId);
sl@0: 	inline TInt GetBusId(TUsbBusId& aBusId);
sl@0: 
sl@0: 	inline TInt GetEndpointDescriptor(TUsbEndpointDescriptor& aDescriptor);
sl@0: 
sl@0: 	IMPORT_C void Transfer(RUsbTransferDescriptor& aTransfer, TRequestStatus& aRequest);
sl@0: 	inline void CancelAllTransfers();
sl@0: 
sl@0: 	inline TInt ClearRemoteStall();
sl@0: 	
sl@0: private:
sl@0: 	inline void IssueTransfer(TInt aTransferHandle, TRequestStatus& aRequest);
sl@0: 
sl@0: private:
sl@0: 	TUint32 iHandle;
sl@0: 	RUsbInterface* iInterface;
sl@0: 	TUsbEndpointDescriptor* iHeadEndpointDescriptor;
sl@0: #endif
sl@0: 	};
sl@0: 
sl@0: 
sl@0: #include <d32usbdi.inl>
sl@0: 
sl@0: #endif	// D32USBDI_H