williamr@4: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@4: // All rights reserved. williamr@4: // This component and the accompanying materials are made available williamr@4: // under the terms of the License "Eclipse Public License v1.0" williamr@4: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@4: // williamr@4: // Initial Contributors: williamr@4: // Nokia Corporation - initial contribution. williamr@4: // williamr@4: // Contributors: williamr@4: // williamr@4: // Description: williamr@4: // e32/include/drivers/usbcdesc.h williamr@4: // USB descriptors and their management. williamr@4: // williamr@4: // williamr@4: williamr@4: /** williamr@4: @file usbcdesc.h williamr@4: @internalTechnology williamr@4: */ williamr@4: williamr@4: #ifndef __USBCDESC_H__ williamr@4: #define __USBCDESC_H__ williamr@4: williamr@4: #include williamr@4: williamr@4: williamr@4: // Hard-wired positions of some descriptors in iDescriptors array (whether present or not): williamr@4: static const TInt KDescPosition_Device = 0; williamr@4: static const TInt KDescPosition_DeviceQualifier = 1; williamr@4: static const TInt KDescPosition_OtherSpeedConfig = 2; williamr@4: static const TInt KDescPosition_Config = 3; williamr@4: static const TInt KDescPosition_Otg = 4; williamr@4: static const TInt KDescPosition_FirstAvailable = 5; williamr@4: williamr@4: // Hard-wired positions of string descriptors in iStrings array (whether present or not): williamr@4: static const TInt KStringPosition_Langid = 0; williamr@4: static const TInt KStringPosition_Manufact = 1; williamr@4: static const TInt KStringPosition_Product = 2; williamr@4: static const TInt KStringPosition_Serial = 3; williamr@4: static const TInt KStringPosition_Config = 4; williamr@4: static const TInt KStringPosition_OtherSpeedConfig = 5; williamr@4: static const TInt KStringPosition_FirstAvailable = 6; williamr@4: williamr@4: williamr@4: class TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual ~TUsbcDescriptorBase(); williamr@4: void SetByte(TInt aPosition, TUint8 aValue); williamr@4: void SetWord(TInt aPosition, TUint16 aValue); williamr@4: TUint8 Byte(TInt aPosition) const; williamr@4: TUint16 Word(TInt aPosition) const; williamr@4: void GetDescriptorData(TDes8& aBuffer) const; williamr@4: TInt GetDescriptorData(TUint8* aBuffer) const; williamr@4: TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const; williamr@4: const TDes8& DescriptorData() const; williamr@4: TDes8& DescriptorData(); williamr@4: TUint Size() const; williamr@4: TUint8 Type() const; williamr@4: virtual void UpdateFs(); williamr@4: virtual void UpdateHs(); williamr@4: protected: williamr@4: TUsbcDescriptorBase(); williamr@4: void SetBufferPointer(const TDesC8& aDes); williamr@4: private: williamr@4: #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST williamr@4: TUint8 iIndex; // only needed for SET_DESCRIPTOR williamr@4: #endif williamr@4: TPtr8 iBufPtr; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcDeviceDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size williamr@4: is fixed and known). williamr@4: */ williamr@4: static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass, williamr@4: TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0, williamr@4: TUint16 aVendorId, TUint16 aProductId, williamr@4: TUint16 aDeviceRelease, TUint8 aNumConfigurations); williamr@4: virtual void UpdateFs(); williamr@4: virtual void UpdateHs(); williamr@4: private: williamr@4: TUsbcDeviceDescriptor(); williamr@4: TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol, williamr@4: TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId, williamr@4: TUint16 aDeviceRelease, TUint8 aNumConfigurations); williamr@4: TBuf8 iBuf; williamr@4: TUint8 iEp0Size_Fs; // holds Ep0 size for FS (could be < 64) williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcDeviceQualifierDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size williamr@4: is fixed and known). williamr@4: */ williamr@4: static TUsbcDeviceQualifierDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass, williamr@4: TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0, williamr@4: TUint8 aNumConfigurations, TUint8 aReserved=0); williamr@4: virtual void UpdateFs(); williamr@4: virtual void UpdateHs(); williamr@4: private: williamr@4: TUsbcDeviceQualifierDescriptor(); williamr@4: TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol, williamr@4: TUint8 aMaxPacketSize0, TUint8 aNumConfigurations, TUint8 aReserved); williamr@4: TBuf8 iBuf; williamr@4: TUint8 iEp0Size_Fs; // holds Ep0 size for FS (could be < 64) williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcConfigDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: /** aMaxPower should be given here in milliamps (not mA/2). */ williamr@4: static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, williamr@4: TUint16 aMaxPower); williamr@4: private: williamr@4: TUsbcConfigDescriptor(); williamr@4: TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint16 aMaxPower); williamr@4: TBuf8 iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: // The Other_Speed_Configuration descriptor has same size and layout as the williamr@4: // standard Configuration descriptor, therefore we don't need a new definition. williamr@4: typedef TUsbcConfigDescriptor TUsbcOtherSpeedConfigDescriptor; williamr@4: williamr@4: williamr@4: class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints, williamr@4: const TUsbcClassInfo& aClassInfo); williamr@4: private: williamr@4: TUsbcInterfaceDescriptor(); williamr@4: TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints, williamr@4: const TUsbcClassInfo& aClassInfo); williamr@4: TBuf8 iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcEndpointDescriptorBase : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual void UpdateFs(); williamr@4: virtual void UpdateHs(); williamr@4: protected: williamr@4: TInt Construct(const TUsbcEndpointInfo& aEpInfo); williamr@4: TUsbcEndpointDescriptorBase(); williamr@4: protected: williamr@4: /** Stores the endpoint size to be used for FS. */ williamr@4: TInt iEpSize_Fs; williamr@4: /** Stores the endpoint size to be used for HS. */ williamr@4: TInt iEpSize_Hs; williamr@4: /** Stores the endpoint polling interval to be used for FS. */ williamr@4: TInt iInterval_Fs; williamr@4: /** Stores the endpoint polling interval to be used for HS. */ williamr@4: TInt iInterval_Hs; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcEndpointDescriptor : public TUsbcEndpointDescriptorBase williamr@4: { williamr@4: public: williamr@4: static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); williamr@4: private: williamr@4: TUsbcEndpointDescriptor(); williamr@4: TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); williamr@4: TBuf8 iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcAudioEndpointDescriptor : public TUsbcEndpointDescriptorBase williamr@4: { williamr@4: public: williamr@4: static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); williamr@4: private: williamr@4: TUsbcAudioEndpointDescriptor(); williamr@4: TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); williamr@4: TBuf8 iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcOtgDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: static TUsbcOtgDescriptor* New(TBool aHnpSupport, TBool aSrpSupport); williamr@4: private: williamr@4: TUsbcOtgDescriptor(); williamr@4: TInt Construct(TBool aHnpSupport, TBool aSrpSupport); williamr@4: TBuf8 iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual ~TUsbcClassSpecificDescriptor(); williamr@4: static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize); williamr@4: private: williamr@4: TUsbcClassSpecificDescriptor(); williamr@4: TInt Construct(TUint8 aType, TInt aSize); williamr@4: HBuf8* iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcStringDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual ~TUsbcStringDescriptorBase(); williamr@4: TUint16 Word(TInt aPosition) const; williamr@4: void SetWord(TInt aPosition, TUint16 aValue); williamr@4: TInt GetDescriptorData(TUint8* aBuffer) const; williamr@4: TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const; williamr@4: const TDes8& StringData() const; williamr@4: TDes8& StringData(); williamr@4: TUint Size() const; williamr@4: void SetBufferPointer(const TDesC8& aDes); williamr@4: protected: williamr@4: TUsbcStringDescriptorBase(); williamr@4: TBuf8<2> iSBuf; williamr@4: TPtr8 iBufPtr; williamr@4: private: williamr@4: // TUint8 iIndex; // not needed in DescriptorPool: position == index williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcStringDescriptor : public TUsbcStringDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual ~TUsbcStringDescriptor(); williamr@4: static TUsbcStringDescriptor* New(const TDesC8& aString); williamr@4: private: williamr@4: TUsbcStringDescriptor(); williamr@4: TInt Construct(const TDesC8& aString); williamr@4: HBuf8* iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: // Currently we support only one language, and thus there's no need to provide williamr@4: // a LangId string descriptor with more than one array element. williamr@4: class TUsbcLangIdDescriptor : public TUsbcStringDescriptorBase williamr@4: { williamr@4: public: williamr@4: virtual ~TUsbcLangIdDescriptor(); williamr@4: static TUsbcLangIdDescriptor* New(TUint16 aLangId); williamr@4: private: williamr@4: TUsbcLangIdDescriptor(); williamr@4: TInt Construct(TUint16 aLangId); williamr@4: TBuf8<2> iBuf; williamr@4: }; williamr@4: williamr@4: williamr@4: class TUsbcDescriptorPool williamr@4: { williamr@4: public: williamr@4: TUsbcDescriptorPool(TUint8* aEp0_TxBuf); williamr@4: ~TUsbcDescriptorPool(); williamr@4: TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc, williamr@4: TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer, williamr@4: TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum, williamr@4: TUsbcStringDescriptor* aConfig, TUsbcOtgDescriptor* aOtgDesc); williamr@4: TInt InitHs(); williamr@4: TInt UpdateDescriptorsFs(); williamr@4: TInt UpdateDescriptorsHs(); williamr@4: williamr@4: // Descriptors williamr@4: TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const; williamr@4: void InsertDescriptor(TUsbcDescriptorBase* aDesc); williamr@4: void DeleteIfcDescriptor(TInt aNumber, TInt aSetting=0); williamr@4: // The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there. williamr@4: TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const; williamr@4: TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer); williamr@4: TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const; williamr@4: TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer); williamr@4: TInt GetOtgDescriptorTC(DThread* aThread, TDes8& aBuffer) const; williamr@4: TInt SetOtgDescriptor(const TDesC8& aBuffer); williamr@4: TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const; williamr@4: TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting); williamr@4: TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting, williamr@4: TUint8 aEndpointAddress) const; williamr@4: TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, williamr@4: TUint8 aEndpointAddress); williamr@4: TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const; williamr@4: TInt GetDeviceQualifierDescriptorTC(DThread* aThread, TDes8& aBuffer) const; williamr@4: TInt SetDeviceQualifierDescriptorTC(DThread* aThread, const TDes8& aBuffer); williamr@4: TInt GetOtherSpeedConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const; williamr@4: TInt SetOtherSpeedConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer); williamr@4: TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const; williamr@4: TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, williamr@4: TInt aSize); williamr@4: TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const; williamr@4: TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting, williamr@4: TUint8 aEndpointAddress) const; williamr@4: TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, williamr@4: TUint8 aEndpointAddress, TInt aSize); williamr@4: TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const; williamr@4: williamr@4: // String descriptors williamr@4: void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting=0); williamr@4: TInt GetStringDescriptorLangIdTC(DThread* aThread, TDes8& aLangId) const; williamr@4: TInt SetStringDescriptorLangId(TUint16 aLangId); williamr@4: TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const; williamr@4: TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString); williamr@4: TInt RemoveManufacturerStringDescriptor(); williamr@4: TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const; williamr@4: TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString); williamr@4: TInt RemoveProductStringDescriptor(); williamr@4: TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const; williamr@4: TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString); williamr@4: TInt RemoveSerialNumberStringDescriptor(); williamr@4: TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const; williamr@4: TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString); williamr@4: TInt RemoveConfigurationStringDescriptor(); williamr@4: TInt GetStringDescriptorTC(DThread* aThread, TInt aIndex, TDes8& aString) const; williamr@4: TInt SetStringDescriptorTC(DThread* aThread, TInt aIndex, const TDes8& aString); williamr@4: TInt RemoveStringDescriptor(TInt aIndex); williamr@4: williamr@4: private: williamr@4: // Descriptors williamr@4: void InsertIfcDesc(TUsbcDescriptorBase* aDesc); williamr@4: void InsertEpDesc(TUsbcDescriptorBase* aDesc); williamr@4: TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const; williamr@4: TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const; williamr@4: void DeleteDescriptors(TInt aIndex, TInt aCount = 1); williamr@4: void UpdateConfigDescriptorLength(TInt aLength); williamr@4: void UpdateConfigDescriptorNumIfcs(TInt aNumber); williamr@4: void UpdateIfcNumbers(TInt aNumber); williamr@4: TInt GetDeviceDescriptor(TInt aIndex) const; williamr@4: TInt GetConfigurationDescriptor(TInt aIndex) const; williamr@4: TInt GetOtgDescriptor() const; williamr@4: williamr@4: // String descriptors williamr@4: TInt GetStringDescriptor(TInt aIndex) const; williamr@4: TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex, TInt aPosition) const; williamr@4: TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex, TInt aPosition); williamr@4: TInt RemoveDeviceStringDescriptor(TInt aIndex, TInt aPosition); williamr@4: void ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc); williamr@4: TBool AnyStringDescriptors() const; williamr@4: TBool StringDescriptorExists(TInt aIndex) const; williamr@4: TInt FindAvailableStringPos() const; williamr@4: williamr@4: private: williamr@4: // Data members williamr@4: RPointerArray iDescriptors; williamr@4: RPointerArray iStrings; williamr@4: TInt iIfcIdx; williamr@4: TUint8* const iEp0_TxBuf; // points to the controller's ep0 TX buffer williamr@4: TBool iHighSpeed; // true if currently operating at high-speed williamr@4: }; williamr@4: williamr@4: williamr@4: #endif // __USBCDESC_H__