kerneltest/e32utils/testusbcldd/inc/usbcdesc.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\include\drivers\usbcdesc.h
       
    15 // USB descriptors and their management.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 
       
    24 #if !defined(__USBCDESC_H__)
       
    25 #define __USBCDESC_H__
       
    26 
       
    27 #include "kerndefs.h"
       
    28 #include <d32usbc.h>
       
    29 
       
    30 class TUsbcDescriptorBase
       
    31 	{
       
    32 public:
       
    33 	virtual ~TUsbcDescriptorBase();
       
    34 	void SetByte(TUint aPosition, TUint8 aValue);
       
    35 	void SetWord(TUint aPosition, TUint16 aValue);
       
    36 	TUint8 Byte(TUint aPosition) const;
       
    37 	TUint16 Word(TUint aPosition) const;
       
    38 	void GetDescriptorData(TDes8& aBuffer) const;
       
    39 	TInt GetDescriptorData(TUint8* aBuffer) const;
       
    40 	TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const;
       
    41 	const TDes8& DescriptorData() const;
       
    42 	TDes8& DescriptorData();
       
    43 	TInt Size() const;
       
    44 	TUint8 Type() const;
       
    45 protected:
       
    46 	TUsbcDescriptorBase();
       
    47 	void SetBufferPointer(const TDesC8& aDes);
       
    48 private:
       
    49 #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
       
    50 	TUint8 iIndex;											// only needed for SET_DESCRIPTOR
       
    51 #endif
       
    52 	TPtr8 iBufPtr;
       
    53 	};
       
    54 
       
    55 
       
    56 class TUsbcDeviceDescriptor : public TUsbcDescriptorBase
       
    57 	{
       
    58 public:
       
    59 	static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
       
    60 									  TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
       
    61 									  TUint16 aVendorId, TUint16 aProductId,
       
    62 									  TUint16 aDeviceRelease, TUint8 aNumConfigurations);
       
    63 private:
       
    64 	TUsbcDeviceDescriptor();
       
    65 	TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
       
    66 				   TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
       
    67 				   TUint16 aDeviceRelease, TUint8 aNumConfigurations);
       
    68 	TBuf8<KUsbDescSize_Device> iBuf;
       
    69 	};
       
    70 
       
    71 
       
    72 class TUsbcConfigDescriptor : public TUsbcDescriptorBase
       
    73 	{
       
    74 public:
       
    75 	static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup,
       
    76 									  TUint8 aMaxPower);	// give MaxPower in milliamps!
       
    77 private:
       
    78 	TUsbcConfigDescriptor();
       
    79 	TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint8 aMaxPower);
       
    80 	TBuf8<KUsbDescSize_Config> iBuf;
       
    81 	};
       
    82 
       
    83 
       
    84 class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase
       
    85 	{
       
    86 public:
       
    87 	static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints,
       
    88 										 const TUsbcClassInfo& aClassInfo);
       
    89 private:
       
    90 	TUsbcInterfaceDescriptor();
       
    91 	TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints,
       
    92 				   const TUsbcClassInfo& aClassInfo);
       
    93 	TBuf8<KUsbDescSize_Interface> iBuf;
       
    94 	};
       
    95 
       
    96 
       
    97 class TUsbcEndpointDescriptor : public TUsbcDescriptorBase
       
    98 	{
       
    99 public:
       
   100 	static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
       
   101 private:
       
   102 	TUsbcEndpointDescriptor();
       
   103 	TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
       
   104 	TBuf8<KUsbDescSize_Endpoint> iBuf;
       
   105 	};
       
   106 
       
   107 
       
   108 class TUsbcAudioEndpointDescriptor : public TUsbcDescriptorBase
       
   109 	{
       
   110 public:
       
   111 	static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
       
   112 private:
       
   113 	TUsbcAudioEndpointDescriptor();
       
   114 	TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
       
   115 	TBuf8<KUsbDescSize_AudioEndpoint> iBuf;
       
   116 	};
       
   117 
       
   118 
       
   119 class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase
       
   120 	{
       
   121 public:
       
   122 	virtual ~TUsbcClassSpecificDescriptor();
       
   123 	static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize);
       
   124 private:
       
   125 	TUsbcClassSpecificDescriptor();
       
   126 	TInt Construct(TUint8 aType, TInt aSize);
       
   127 	HBuf8Plat* iBuf;
       
   128 	};
       
   129 
       
   130 
       
   131 class TUsbcStringDescriptorBase
       
   132 	{
       
   133 public:
       
   134 	virtual ~TUsbcStringDescriptorBase();
       
   135 	TUint16 Word(TUint aPosition) const;
       
   136 	TInt GetDescriptorData(TUint8* aBuffer) const;
       
   137 	TInt GetDescriptorData(TUint8* aBuffer, TInt aMaxSize) const;
       
   138 	const TDes8& StringData() const;
       
   139 	TDes8& StringData();
       
   140 	TInt Size() const;
       
   141 	void SetBufferPointer(const TDesC8& aDes);
       
   142 protected:
       
   143 	TUsbcStringDescriptorBase();
       
   144 	TBuf8<2> iSBuf;
       
   145 	TPtr8 iBufPtr;
       
   146 private:
       
   147 //	TUint8 iIndex;											// not needed in DescriptorPool: position == index
       
   148 	};
       
   149 
       
   150 
       
   151 class TUsbcStringDescriptor : public TUsbcStringDescriptorBase
       
   152 	{
       
   153 public:
       
   154 	virtual ~TUsbcStringDescriptor();
       
   155 	static TUsbcStringDescriptor* New(const TDesC8& aString);
       
   156 private:
       
   157 	TUsbcStringDescriptor();								// use static New
       
   158 	TInt Construct(const TDesC8& aString);
       
   159 	HBuf8Plat* iBuf;
       
   160 	};
       
   161 
       
   162 
       
   163 // Currently we support only one language, and thus there's no need to provide
       
   164 // a LangId string descriptor with more than one array element.
       
   165 class TUsbcLangIdDescriptor : public TUsbcStringDescriptorBase
       
   166 	{
       
   167 public:
       
   168 	virtual ~TUsbcLangIdDescriptor();
       
   169 	static TUsbcLangIdDescriptor* New(TUint16 aLangId);
       
   170 private:
       
   171 	TUsbcLangIdDescriptor();								// use static New
       
   172 	TInt Construct(TUint16 aLangId);
       
   173 	TBuf8<2> iBuf;
       
   174 	};
       
   175 
       
   176 
       
   177 class TUsbcDescriptorPool
       
   178 	{
       
   179 public:
       
   180 	TUsbcDescriptorPool(TUint8* aEp0_TxBuf);
       
   181 	~TUsbcDescriptorPool();
       
   182 	TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
       
   183 			  TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
       
   184 			  TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
       
   185 			  TUsbcStringDescriptor* aConfig);
       
   186 	// Descriptors
       
   187 	TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const;
       
   188 	void InsertDescriptor(TUsbcDescriptorBase* aDesc);
       
   189 	void DeleteIfcDescriptor(TInt aNumber, TInt aSetting = 0);
       
   190 
       
   191 	// The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there.
       
   192 	TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
       
   193 	TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer);
       
   194 	TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
       
   195 	TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
       
   196 	TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
       
   197 	TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting);
       
   198 	TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
       
   199 								 TUint8 aEndpointAddress) const;
       
   200 	TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
       
   201 								 TUint8 aEndpointAddress);
       
   202 	TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
       
   203 	TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
       
   204 	TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
       
   205 									TInt aSize);
       
   206 	TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const;
       
   207 	TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
       
   208 								   TUint8 aEndpointAddress) const;
       
   209 	TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
       
   210 								   TUint8 aEndpointAddress, TInt aSize);
       
   211 	TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
       
   212 
       
   213 	// String descriptors
       
   214 	void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting = 0);
       
   215 	TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const;
       
   216 	TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString);
       
   217 	TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const;
       
   218 	TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString);
       
   219 	TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const;
       
   220 	TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString);
       
   221 	TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const;
       
   222 	TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString);
       
   223 private:
       
   224 	void InsertDevDesc(TUsbcDescriptorBase* aDesc);
       
   225 	void InsertConfigDesc(TUsbcDescriptorBase* aDesc);
       
   226 	void InsertIfcDesc(TUsbcDescriptorBase* aDesc);
       
   227 	void InsertEpDesc(TUsbcDescriptorBase* aDesc);
       
   228 	TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const;
       
   229 	TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const;
       
   230 	void DeleteDescriptors(TInt aIndex, TInt aCount = 1);
       
   231 	void DeleteString(TInt aIndex);
       
   232 	void UpdateIfcNumbers(TInt aNumber);
       
   233 	void UpdateIfcStringIndexes(TInt aStringIndex);
       
   234 	TInt GetDeviceDescriptor() const;
       
   235 	TInt GetConfigDescriptor() const;
       
   236 	TInt GetStringDescriptor(TInt aIndex) const;
       
   237 	TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex) const;
       
   238 	TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex);
       
   239 	TInt ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc);
       
   240 private:
       
   241 	// Data members
       
   242 	RPointerArray<TUsbcDescriptorBase> iDescriptors;
       
   243 	RPointerArray<TUsbcStringDescriptorBase> iStrings;
       
   244 	TInt iIfcIdx;
       
   245 	TUint8* const iEp0_TxBuf;								// points to the controller's Ep0 Tx buffer
       
   246 	};
       
   247 
       
   248 
       
   249 #endif	// __USBCDESC_H__