sl@0: // Copyright (c) 2002-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: // e32\include\drivers\usbcdesc.h sl@0: // USB descriptors and their management. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #if !defined(__USBCDESC_H__) sl@0: #define __USBCDESC_H__ sl@0: sl@0: #include "kerndefs.h" sl@0: #include sl@0: sl@0: class TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: virtual ~TUsbcDescriptorBase(); sl@0: void SetByte(TUint aPosition, TUint8 aValue); sl@0: void SetWord(TUint aPosition, TUint16 aValue); sl@0: TUint8 Byte(TUint aPosition) const; sl@0: TUint16 Word(TUint aPosition) const; sl@0: void GetDescriptorData(TDes8& aBuffer) const; sl@0: TInt GetDescriptorData(TUint8* aBuffer) const; sl@0: TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const; sl@0: const TDes8& DescriptorData() const; sl@0: TDes8& DescriptorData(); sl@0: TInt Size() const; sl@0: TUint8 Type() const; sl@0: protected: sl@0: TUsbcDescriptorBase(); sl@0: void SetBufferPointer(const TDesC8& aDes); sl@0: private: sl@0: #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST sl@0: TUint8 iIndex; // only needed for SET_DESCRIPTOR sl@0: #endif sl@0: TPtr8 iBufPtr; sl@0: }; sl@0: sl@0: sl@0: class TUsbcDeviceDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass, sl@0: TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0, sl@0: TUint16 aVendorId, TUint16 aProductId, sl@0: TUint16 aDeviceRelease, TUint8 aNumConfigurations); sl@0: private: sl@0: TUsbcDeviceDescriptor(); sl@0: TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol, sl@0: TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId, sl@0: TUint16 aDeviceRelease, TUint8 aNumConfigurations); sl@0: TBuf8 iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcConfigDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, sl@0: TUint8 aMaxPower); // give MaxPower in milliamps! sl@0: private: sl@0: TUsbcConfigDescriptor(); sl@0: TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint8 aMaxPower); sl@0: TBuf8 iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints, sl@0: const TUsbcClassInfo& aClassInfo); sl@0: private: sl@0: TUsbcInterfaceDescriptor(); sl@0: TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints, sl@0: const TUsbcClassInfo& aClassInfo); sl@0: TBuf8 iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcEndpointDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); sl@0: private: sl@0: TUsbcEndpointDescriptor(); sl@0: TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); sl@0: TBuf8 iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcAudioEndpointDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); sl@0: private: sl@0: TUsbcAudioEndpointDescriptor(); sl@0: TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo); sl@0: TBuf8 iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase sl@0: { sl@0: public: sl@0: virtual ~TUsbcClassSpecificDescriptor(); sl@0: static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize); sl@0: private: sl@0: TUsbcClassSpecificDescriptor(); sl@0: TInt Construct(TUint8 aType, TInt aSize); sl@0: HBuf8Plat* iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcStringDescriptorBase sl@0: { sl@0: public: sl@0: virtual ~TUsbcStringDescriptorBase(); sl@0: TUint16 Word(TUint aPosition) const; sl@0: TInt GetDescriptorData(TUint8* aBuffer) const; sl@0: TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const; sl@0: const TDes8& StringData() const; sl@0: TDes8& StringData(); sl@0: TInt Size() const; sl@0: void SetBufferPointer(const TDesC8& aDes); sl@0: protected: sl@0: TUsbcStringDescriptorBase(); sl@0: TBuf8<2> iSBuf; sl@0: TPtr8 iBufPtr; sl@0: private: sl@0: // TUint8 iIndex; // not needed in DescriptorPool: position == index sl@0: }; sl@0: sl@0: sl@0: class TUsbcStringDescriptor : public TUsbcStringDescriptorBase sl@0: { sl@0: public: sl@0: virtual ~TUsbcStringDescriptor(); sl@0: static TUsbcStringDescriptor* New(const TDesC8& aString); sl@0: private: sl@0: TUsbcStringDescriptor(); // use static New sl@0: TInt Construct(const TDesC8& aString); sl@0: HBuf8Plat* iBuf; sl@0: }; sl@0: sl@0: sl@0: // Currently we support only one language, and thus there's no need to provide sl@0: // a LangId string descriptor with more than one array element. sl@0: class TUsbcLangIdDescriptor : public TUsbcStringDescriptorBase sl@0: { sl@0: public: sl@0: virtual ~TUsbcLangIdDescriptor(); sl@0: static TUsbcLangIdDescriptor* New(TUint16 aLangId); sl@0: private: sl@0: TUsbcLangIdDescriptor(); // use static New sl@0: TInt Construct(TUint16 aLangId); sl@0: TBuf8<2> iBuf; sl@0: }; sl@0: sl@0: sl@0: class TUsbcDescriptorPool sl@0: { sl@0: public: sl@0: TUsbcDescriptorPool(TUint8* aEp0_TxBuf); sl@0: ~TUsbcDescriptorPool(); sl@0: TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc, sl@0: TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer, sl@0: TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum, sl@0: TUsbcStringDescriptor* aConfig); sl@0: // Descriptors sl@0: TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const; sl@0: void InsertDescriptor(TUsbcDescriptorBase* aDesc); sl@0: void DeleteIfcDescriptor(TInt aNumber, TInt aSetting = 0); sl@0: sl@0: // The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there. sl@0: TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const; sl@0: TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer); sl@0: TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const; sl@0: TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer); sl@0: TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const; sl@0: TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting); sl@0: TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting, sl@0: TUint8 aEndpointAddress) const; sl@0: TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, sl@0: TUint8 aEndpointAddress); sl@0: TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const; sl@0: TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const; sl@0: TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, sl@0: TInt aSize); sl@0: TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const; sl@0: TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting, sl@0: TUint8 aEndpointAddress) const; sl@0: TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting, sl@0: TUint8 aEndpointAddress, TInt aSize); sl@0: TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const; sl@0: sl@0: // String descriptors sl@0: void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting = 0); sl@0: TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const; sl@0: TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString); sl@0: TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const; sl@0: TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString); sl@0: TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const; sl@0: TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString); sl@0: TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const; sl@0: TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString); sl@0: private: sl@0: void InsertDevDesc(TUsbcDescriptorBase* aDesc); sl@0: void InsertConfigDesc(TUsbcDescriptorBase* aDesc); sl@0: void InsertIfcDesc(TUsbcDescriptorBase* aDesc); sl@0: void InsertEpDesc(TUsbcDescriptorBase* aDesc); sl@0: TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const; sl@0: TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const; sl@0: void DeleteDescriptors(TInt aIndex, TInt aCount = 1); sl@0: void DeleteString(TInt aIndex); sl@0: void UpdateIfcNumbers(TInt aNumber); sl@0: void UpdateIfcStringIndexes(TInt aStringIndex); sl@0: TInt GetDeviceDescriptor() const; sl@0: TInt GetConfigDescriptor() const; sl@0: TInt GetStringDescriptor(TInt aIndex) const; sl@0: TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex) const; sl@0: TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex); sl@0: TInt ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc); sl@0: private: sl@0: // Data members sl@0: RPointerArray iDescriptors; sl@0: RPointerArray iStrings; sl@0: TInt iIfcIdx; sl@0: TUint8* const iEp0_TxBuf; // points to the controller's Ep0 Tx buffer sl@0: }; sl@0: sl@0: sl@0: #endif // __USBCDESC_H__