os/kernelhwsrv/kerneltest/e32utils/testusbcldd/inc/usbcdesc.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/testusbcldd/inc/usbcdesc.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,249 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\drivers\usbcdesc.h
    1.18 +// USB descriptors and their management.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalTechnology
    1.25 +*/
    1.26 +
    1.27 +#if !defined(__USBCDESC_H__)
    1.28 +#define __USBCDESC_H__
    1.29 +
    1.30 +#include "kerndefs.h"
    1.31 +#include <d32usbc.h>
    1.32 +
    1.33 +class TUsbcDescriptorBase
    1.34 +	{
    1.35 +public:
    1.36 +	virtual ~TUsbcDescriptorBase();
    1.37 +	void SetByte(TUint aPosition, TUint8 aValue);
    1.38 +	void SetWord(TUint aPosition, TUint16 aValue);
    1.39 +	TUint8 Byte(TUint aPosition) const;
    1.40 +	TUint16 Word(TUint aPosition) const;
    1.41 +	void GetDescriptorData(TDes8& aBuffer) const;
    1.42 +	TInt GetDescriptorData(TUint8* aBuffer) const;
    1.43 +	TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const;
    1.44 +	const TDes8& DescriptorData() const;
    1.45 +	TDes8& DescriptorData();
    1.46 +	TInt Size() const;
    1.47 +	TUint8 Type() const;
    1.48 +protected:
    1.49 +	TUsbcDescriptorBase();
    1.50 +	void SetBufferPointer(const TDesC8& aDes);
    1.51 +private:
    1.52 +#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
    1.53 +	TUint8 iIndex;											// only needed for SET_DESCRIPTOR
    1.54 +#endif
    1.55 +	TPtr8 iBufPtr;
    1.56 +	};
    1.57 +
    1.58 +
    1.59 +class TUsbcDeviceDescriptor : public TUsbcDescriptorBase
    1.60 +	{
    1.61 +public:
    1.62 +	static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
    1.63 +									  TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
    1.64 +									  TUint16 aVendorId, TUint16 aProductId,
    1.65 +									  TUint16 aDeviceRelease, TUint8 aNumConfigurations);
    1.66 +private:
    1.67 +	TUsbcDeviceDescriptor();
    1.68 +	TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
    1.69 +				   TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
    1.70 +				   TUint16 aDeviceRelease, TUint8 aNumConfigurations);
    1.71 +	TBuf8<KUsbDescSize_Device> iBuf;
    1.72 +	};
    1.73 +
    1.74 +
    1.75 +class TUsbcConfigDescriptor : public TUsbcDescriptorBase
    1.76 +	{
    1.77 +public:
    1.78 +	static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup,
    1.79 +									  TUint8 aMaxPower);	// give MaxPower in milliamps!
    1.80 +private:
    1.81 +	TUsbcConfigDescriptor();
    1.82 +	TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint8 aMaxPower);
    1.83 +	TBuf8<KUsbDescSize_Config> iBuf;
    1.84 +	};
    1.85 +
    1.86 +
    1.87 +class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase
    1.88 +	{
    1.89 +public:
    1.90 +	static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints,
    1.91 +										 const TUsbcClassInfo& aClassInfo);
    1.92 +private:
    1.93 +	TUsbcInterfaceDescriptor();
    1.94 +	TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints,
    1.95 +				   const TUsbcClassInfo& aClassInfo);
    1.96 +	TBuf8<KUsbDescSize_Interface> iBuf;
    1.97 +	};
    1.98 +
    1.99 +
   1.100 +class TUsbcEndpointDescriptor : public TUsbcDescriptorBase
   1.101 +	{
   1.102 +public:
   1.103 +	static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
   1.104 +private:
   1.105 +	TUsbcEndpointDescriptor();
   1.106 +	TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
   1.107 +	TBuf8<KUsbDescSize_Endpoint> iBuf;
   1.108 +	};
   1.109 +
   1.110 +
   1.111 +class TUsbcAudioEndpointDescriptor : public TUsbcDescriptorBase
   1.112 +	{
   1.113 +public:
   1.114 +	static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
   1.115 +private:
   1.116 +	TUsbcAudioEndpointDescriptor();
   1.117 +	TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
   1.118 +	TBuf8<KUsbDescSize_AudioEndpoint> iBuf;
   1.119 +	};
   1.120 +
   1.121 +
   1.122 +class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase
   1.123 +	{
   1.124 +public:
   1.125 +	virtual ~TUsbcClassSpecificDescriptor();
   1.126 +	static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize);
   1.127 +private:
   1.128 +	TUsbcClassSpecificDescriptor();
   1.129 +	TInt Construct(TUint8 aType, TInt aSize);
   1.130 +	HBuf8Plat* iBuf;
   1.131 +	};
   1.132 +
   1.133 +
   1.134 +class TUsbcStringDescriptorBase
   1.135 +	{
   1.136 +public:
   1.137 +	virtual ~TUsbcStringDescriptorBase();
   1.138 +	TUint16 Word(TUint aPosition) const;
   1.139 +	TInt GetDescriptorData(TUint8* aBuffer) const;
   1.140 +	TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const;
   1.141 +	const TDes8& StringData() const;
   1.142 +	TDes8& StringData();
   1.143 +	TInt Size() const;
   1.144 +	void SetBufferPointer(const TDesC8& aDes);
   1.145 +protected:
   1.146 +	TUsbcStringDescriptorBase();
   1.147 +	TBuf8<2> iSBuf;
   1.148 +	TPtr8 iBufPtr;
   1.149 +private:
   1.150 +//	TUint8 iIndex;											// not needed in DescriptorPool: position == index
   1.151 +	};
   1.152 +
   1.153 +
   1.154 +class TUsbcStringDescriptor : public TUsbcStringDescriptorBase
   1.155 +	{
   1.156 +public:
   1.157 +	virtual ~TUsbcStringDescriptor();
   1.158 +	static TUsbcStringDescriptor* New(const TDesC8& aString);
   1.159 +private:
   1.160 +	TUsbcStringDescriptor();								// use static New
   1.161 +	TInt Construct(const TDesC8& aString);
   1.162 +	HBuf8Plat* iBuf;
   1.163 +	};
   1.164 +
   1.165 +
   1.166 +// Currently we support only one language, and thus there's no need to provide
   1.167 +// a LangId string descriptor with more than one array element.
   1.168 +class TUsbcLangIdDescriptor : public TUsbcStringDescriptorBase
   1.169 +	{
   1.170 +public:
   1.171 +	virtual ~TUsbcLangIdDescriptor();
   1.172 +	static TUsbcLangIdDescriptor* New(TUint16 aLangId);
   1.173 +private:
   1.174 +	TUsbcLangIdDescriptor();								// use static New
   1.175 +	TInt Construct(TUint16 aLangId);
   1.176 +	TBuf8<2> iBuf;
   1.177 +	};
   1.178 +
   1.179 +
   1.180 +class TUsbcDescriptorPool
   1.181 +	{
   1.182 +public:
   1.183 +	TUsbcDescriptorPool(TUint8* aEp0_TxBuf);
   1.184 +	~TUsbcDescriptorPool();
   1.185 +	TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
   1.186 +			  TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
   1.187 +			  TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
   1.188 +			  TUsbcStringDescriptor* aConfig);
   1.189 +	// Descriptors
   1.190 +	TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const;
   1.191 +	void InsertDescriptor(TUsbcDescriptorBase* aDesc);
   1.192 +	void DeleteIfcDescriptor(TInt aNumber, TInt aSetting = 0);
   1.193 +
   1.194 +	// The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there.
   1.195 +	TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
   1.196 +	TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer);
   1.197 +	TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
   1.198 +	TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
   1.199 +	TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
   1.200 +	TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting);
   1.201 +	TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
   1.202 +								 TUint8 aEndpointAddress) const;
   1.203 +	TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
   1.204 +								 TUint8 aEndpointAddress);
   1.205 +	TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
   1.206 +	TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
   1.207 +	TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
   1.208 +									TInt aSize);
   1.209 +	TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const;
   1.210 +	TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
   1.211 +								   TUint8 aEndpointAddress) const;
   1.212 +	TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
   1.213 +								   TUint8 aEndpointAddress, TInt aSize);
   1.214 +	TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
   1.215 +
   1.216 +	// String descriptors
   1.217 +	void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting = 0);
   1.218 +	TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const;
   1.219 +	TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString);
   1.220 +	TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const;
   1.221 +	TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString);
   1.222 +	TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const;
   1.223 +	TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString);
   1.224 +	TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const;
   1.225 +	TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString);
   1.226 +private:
   1.227 +	void InsertDevDesc(TUsbcDescriptorBase* aDesc);
   1.228 +	void InsertConfigDesc(TUsbcDescriptorBase* aDesc);
   1.229 +	void InsertIfcDesc(TUsbcDescriptorBase* aDesc);
   1.230 +	void InsertEpDesc(TUsbcDescriptorBase* aDesc);
   1.231 +	TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const;
   1.232 +	TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const;
   1.233 +	void DeleteDescriptors(TInt aIndex, TInt aCount = 1);
   1.234 +	void DeleteString(TInt aIndex);
   1.235 +	void UpdateIfcNumbers(TInt aNumber);
   1.236 +	void UpdateIfcStringIndexes(TInt aStringIndex);
   1.237 +	TInt GetDeviceDescriptor() const;
   1.238 +	TInt GetConfigDescriptor() const;
   1.239 +	TInt GetStringDescriptor(TInt aIndex) const;
   1.240 +	TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex) const;
   1.241 +	TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex);
   1.242 +	TInt ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc);
   1.243 +private:
   1.244 +	// Data members
   1.245 +	RPointerArray<TUsbcDescriptorBase> iDescriptors;
   1.246 +	RPointerArray<TUsbcStringDescriptorBase> iStrings;
   1.247 +	TInt iIfcIdx;
   1.248 +	TUint8* const iEp0_TxBuf;								// points to the controller's Ep0 Tx buffer
   1.249 +	};
   1.250 +
   1.251 +
   1.252 +#endif	// __USBCDESC_H__