First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\drivers\usbcdesc.h
15 // USB descriptors and their management.
24 #if !defined(__USBCDESC_H__)
25 #define __USBCDESC_H__
30 class TUsbcDescriptorBase
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();
46 TUsbcDescriptorBase();
47 void SetBufferPointer(const TDesC8& aDes);
49 #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
50 TUint8 iIndex; // only needed for SET_DESCRIPTOR
56 class TUsbcDeviceDescriptor : public TUsbcDescriptorBase
59 static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
60 TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
61 TUint16 aVendorId, TUint16 aProductId,
62 TUint16 aDeviceRelease, TUint8 aNumConfigurations);
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;
72 class TUsbcConfigDescriptor : public TUsbcDescriptorBase
75 static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup,
76 TUint8 aMaxPower); // give MaxPower in milliamps!
78 TUsbcConfigDescriptor();
79 TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint8 aMaxPower);
80 TBuf8<KUsbDescSize_Config> iBuf;
84 class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase
87 static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints,
88 const TUsbcClassInfo& aClassInfo);
90 TUsbcInterfaceDescriptor();
91 TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints,
92 const TUsbcClassInfo& aClassInfo);
93 TBuf8<KUsbDescSize_Interface> iBuf;
97 class TUsbcEndpointDescriptor : public TUsbcDescriptorBase
100 static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
102 TUsbcEndpointDescriptor();
103 TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
104 TBuf8<KUsbDescSize_Endpoint> iBuf;
108 class TUsbcAudioEndpointDescriptor : public TUsbcDescriptorBase
111 static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
113 TUsbcAudioEndpointDescriptor();
114 TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
115 TBuf8<KUsbDescSize_AudioEndpoint> iBuf;
119 class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase
122 virtual ~TUsbcClassSpecificDescriptor();
123 static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize);
125 TUsbcClassSpecificDescriptor();
126 TInt Construct(TUint8 aType, TInt aSize);
131 class TUsbcStringDescriptorBase
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;
141 void SetBufferPointer(const TDesC8& aDes);
143 TUsbcStringDescriptorBase();
147 // TUint8 iIndex; // not needed in DescriptorPool: position == index
151 class TUsbcStringDescriptor : public TUsbcStringDescriptorBase
154 virtual ~TUsbcStringDescriptor();
155 static TUsbcStringDescriptor* New(const TDesC8& aString);
157 TUsbcStringDescriptor(); // use static New
158 TInt Construct(const TDesC8& aString);
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
168 virtual ~TUsbcLangIdDescriptor();
169 static TUsbcLangIdDescriptor* New(TUint16 aLangId);
171 TUsbcLangIdDescriptor(); // use static New
172 TInt Construct(TUint16 aLangId);
177 class TUsbcDescriptorPool
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);
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);
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,
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;
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);
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);
242 RPointerArray<TUsbcDescriptorBase> iDescriptors;
243 RPointerArray<TUsbcStringDescriptorBase> iStrings;
245 TUint8* const iEp0_TxBuf; // points to the controller's Ep0 Tx buffer
249 #endif // __USBCDESC_H__