1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/usbcdesc.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,360 @@
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 usbcdesc.h
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#ifndef __USBCDESC_H__
1.28 +#define __USBCDESC_H__
1.29 +
1.30 +#include <kernel/kernel.h>
1.31 +
1.32 +
1.33 +// Hard-wired positions of some descriptors in iDescriptors array (whether present or not):
1.34 +static const TInt KDescPosition_Device = 0;
1.35 +static const TInt KDescPosition_DeviceQualifier = 1;
1.36 +static const TInt KDescPosition_OtherSpeedConfig = 2;
1.37 +static const TInt KDescPosition_Config = 3;
1.38 +static const TInt KDescPosition_Otg = 4;
1.39 +static const TInt KDescPosition_FirstAvailable = 5;
1.40 +
1.41 +// Hard-wired positions of string descriptors in iStrings array (whether present or not):
1.42 +static const TInt KStringPosition_Langid = 0;
1.43 +static const TInt KStringPosition_Manufact = 1;
1.44 +static const TInt KStringPosition_Product = 2;
1.45 +static const TInt KStringPosition_Serial = 3;
1.46 +static const TInt KStringPosition_Config = 4;
1.47 +static const TInt KStringPosition_OtherSpeedConfig = 5;
1.48 +static const TInt KStringPosition_FirstAvailable = 6;
1.49 +
1.50 +
1.51 +class TUsbcDescriptorBase
1.52 + {
1.53 +public:
1.54 + virtual ~TUsbcDescriptorBase();
1.55 + void SetByte(TInt aPosition, TUint8 aValue);
1.56 + void SetWord(TInt aPosition, TUint16 aValue);
1.57 + TUint8 Byte(TInt aPosition) const;
1.58 + TUint16 Word(TInt aPosition) const;
1.59 + void GetDescriptorData(TDes8& aBuffer) const;
1.60 + TInt GetDescriptorData(TUint8* aBuffer) const;
1.61 + TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const;
1.62 + const TDes8& DescriptorData() const;
1.63 + TDes8& DescriptorData();
1.64 + TUint Size() const;
1.65 + TUint8 Type() const;
1.66 + virtual void UpdateFs();
1.67 + virtual void UpdateHs();
1.68 +protected:
1.69 + TUsbcDescriptorBase();
1.70 + void SetBufferPointer(const TDesC8& aDes);
1.71 +private:
1.72 +#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
1.73 + TUint8 iIndex; // only needed for SET_DESCRIPTOR
1.74 +#endif
1.75 + TPtr8 iBufPtr;
1.76 + };
1.77 +
1.78 +
1.79 +class TUsbcDeviceDescriptor : public TUsbcDescriptorBase
1.80 + {
1.81 +public:
1.82 + /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size
1.83 + is fixed and known).
1.84 + */
1.85 + static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
1.86 + TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
1.87 + TUint16 aVendorId, TUint16 aProductId,
1.88 + TUint16 aDeviceRelease, TUint8 aNumConfigurations);
1.89 + virtual void UpdateFs();
1.90 + virtual void UpdateHs();
1.91 +private:
1.92 + TUsbcDeviceDescriptor();
1.93 + TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
1.94 + TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
1.95 + TUint16 aDeviceRelease, TUint8 aNumConfigurations);
1.96 + TBuf8<KUsbDescSize_Device> iBuf;
1.97 + TUint8 iEp0Size_Fs; // holds Ep0 size for FS (could be < 64)
1.98 + };
1.99 +
1.100 +
1.101 +class TUsbcDeviceQualifierDescriptor : public TUsbcDescriptorBase
1.102 + {
1.103 +public:
1.104 + /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size
1.105 + is fixed and known).
1.106 + */
1.107 + static TUsbcDeviceQualifierDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
1.108 + TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
1.109 + TUint8 aNumConfigurations, TUint8 aReserved=0);
1.110 + virtual void UpdateFs();
1.111 + virtual void UpdateHs();
1.112 +private:
1.113 + TUsbcDeviceQualifierDescriptor();
1.114 + TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
1.115 + TUint8 aMaxPacketSize0, TUint8 aNumConfigurations, TUint8 aReserved);
1.116 + TBuf8<KUsbDescSize_DeviceQualifier> iBuf;
1.117 + TUint8 iEp0Size_Fs; // holds Ep0 size for FS (could be < 64)
1.118 + };
1.119 +
1.120 +
1.121 +class TUsbcConfigDescriptor : public TUsbcDescriptorBase
1.122 + {
1.123 +public:
1.124 + /** aMaxPower should be given here in milliamps (not mA/2). */
1.125 + static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup,
1.126 + TUint16 aMaxPower);
1.127 +private:
1.128 + TUsbcConfigDescriptor();
1.129 + TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint16 aMaxPower);
1.130 + TBuf8<KUsbDescSize_Config> iBuf;
1.131 + };
1.132 +
1.133 +
1.134 +// The Other_Speed_Configuration descriptor has same size and layout as the
1.135 +// standard Configuration descriptor, therefore we don't need a new definition.
1.136 +typedef TUsbcConfigDescriptor TUsbcOtherSpeedConfigDescriptor;
1.137 +
1.138 +
1.139 +class TUsbcInterfaceDescriptor : public TUsbcDescriptorBase
1.140 + {
1.141 +public:
1.142 + static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints,
1.143 + const TUsbcClassInfo& aClassInfo);
1.144 +private:
1.145 + TUsbcInterfaceDescriptor();
1.146 + TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints,
1.147 + const TUsbcClassInfo& aClassInfo);
1.148 + TBuf8<KUsbDescSize_Interface> iBuf;
1.149 + };
1.150 +
1.151 +
1.152 +class TUsbcEndpointDescriptorBase : public TUsbcDescriptorBase
1.153 + {
1.154 +public:
1.155 + virtual void UpdateFs();
1.156 + virtual void UpdateHs();
1.157 +protected:
1.158 + TInt Construct(const TUsbcEndpointInfo& aEpInfo);
1.159 + TUsbcEndpointDescriptorBase();
1.160 +protected:
1.161 + /** Stores the endpoint size to be used for FS. */
1.162 + TInt iEpSize_Fs;
1.163 + /** Stores the endpoint size to be used for HS. */
1.164 + TInt iEpSize_Hs;
1.165 + /** Stores the endpoint polling interval to be used for FS. */
1.166 + TInt iInterval_Fs;
1.167 + /** Stores the endpoint polling interval to be used for HS. */
1.168 + TInt iInterval_Hs;
1.169 + };
1.170 +
1.171 +
1.172 +class TUsbcEndpointDescriptor : public TUsbcEndpointDescriptorBase
1.173 + {
1.174 +public:
1.175 + static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
1.176 +private:
1.177 + TUsbcEndpointDescriptor();
1.178 + TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
1.179 + TBuf8<KUsbDescSize_Endpoint> iBuf;
1.180 + };
1.181 +
1.182 +
1.183 +class TUsbcAudioEndpointDescriptor : public TUsbcEndpointDescriptorBase
1.184 + {
1.185 +public:
1.186 + static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
1.187 +private:
1.188 + TUsbcAudioEndpointDescriptor();
1.189 + TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
1.190 + TBuf8<KUsbDescSize_AudioEndpoint> iBuf;
1.191 + };
1.192 +
1.193 +
1.194 +class TUsbcOtgDescriptor : public TUsbcDescriptorBase
1.195 + {
1.196 +public:
1.197 + static TUsbcOtgDescriptor* New(TBool aHnpSupport, TBool aSrpSupport);
1.198 +private:
1.199 + TUsbcOtgDescriptor();
1.200 + TInt Construct(TBool aHnpSupport, TBool aSrpSupport);
1.201 + TBuf8<KUsbDescSize_Otg> iBuf;
1.202 + };
1.203 +
1.204 +
1.205 +class TUsbcClassSpecificDescriptor : public TUsbcDescriptorBase
1.206 + {
1.207 +public:
1.208 + virtual ~TUsbcClassSpecificDescriptor();
1.209 + static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize);
1.210 +private:
1.211 + TUsbcClassSpecificDescriptor();
1.212 + TInt Construct(TUint8 aType, TInt aSize);
1.213 + HBuf8* iBuf;
1.214 + };
1.215 +
1.216 +
1.217 +class TUsbcStringDescriptorBase
1.218 + {
1.219 +public:
1.220 + virtual ~TUsbcStringDescriptorBase();
1.221 + TUint16 Word(TInt aPosition) const;
1.222 + void SetWord(TInt aPosition, TUint16 aValue);
1.223 + TInt GetDescriptorData(TUint8* aBuffer) const;
1.224 + TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const;
1.225 + const TDes8& StringData() const;
1.226 + TDes8& StringData();
1.227 + TUint Size() const;
1.228 + void SetBufferPointer(const TDesC8& aDes);
1.229 +protected:
1.230 + TUsbcStringDescriptorBase();
1.231 + TBuf8<2> iSBuf;
1.232 + TPtr8 iBufPtr;
1.233 +private:
1.234 +// TUint8 iIndex; // not needed in DescriptorPool: position == index
1.235 + };
1.236 +
1.237 +
1.238 +class TUsbcStringDescriptor : public TUsbcStringDescriptorBase
1.239 + {
1.240 +public:
1.241 + virtual ~TUsbcStringDescriptor();
1.242 + static TUsbcStringDescriptor* New(const TDesC8& aString);
1.243 +private:
1.244 + TUsbcStringDescriptor();
1.245 + TInt Construct(const TDesC8& aString);
1.246 + HBuf8* iBuf;
1.247 + };
1.248 +
1.249 +
1.250 +// Currently we support only one language, and thus there's no need to provide
1.251 +// a LangId string descriptor with more than one array element.
1.252 +class TUsbcLangIdDescriptor : public TUsbcStringDescriptorBase
1.253 + {
1.254 +public:
1.255 + virtual ~TUsbcLangIdDescriptor();
1.256 + static TUsbcLangIdDescriptor* New(TUint16 aLangId);
1.257 +private:
1.258 + TUsbcLangIdDescriptor();
1.259 + TInt Construct(TUint16 aLangId);
1.260 + TBuf8<2> iBuf;
1.261 + };
1.262 +
1.263 +
1.264 +class TUsbcDescriptorPool
1.265 + {
1.266 +public:
1.267 + TUsbcDescriptorPool(TUint8* aEp0_TxBuf);
1.268 + ~TUsbcDescriptorPool();
1.269 + TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
1.270 + TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
1.271 + TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
1.272 + TUsbcStringDescriptor* aConfig, TUsbcOtgDescriptor* aOtgDesc);
1.273 + TInt InitHs();
1.274 + TInt UpdateDescriptorsFs();
1.275 + TInt UpdateDescriptorsHs();
1.276 +
1.277 + // Descriptors
1.278 + TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const;
1.279 + void InsertDescriptor(TUsbcDescriptorBase* aDesc);
1.280 + void DeleteIfcDescriptor(TInt aNumber, TInt aSetting=0);
1.281 + // The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there.
1.282 + TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
1.283 + TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer);
1.284 + TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
1.285 + TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
1.286 + TInt GetOtgDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
1.287 + TInt SetOtgDescriptor(const TDesC8& aBuffer);
1.288 + TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
1.289 + TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting);
1.290 + TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
1.291 + TUint8 aEndpointAddress) const;
1.292 + TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
1.293 + TUint8 aEndpointAddress);
1.294 + TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
1.295 + TInt GetDeviceQualifierDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
1.296 + TInt SetDeviceQualifierDescriptorTC(DThread* aThread, const TDes8& aBuffer);
1.297 + TInt GetOtherSpeedConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
1.298 + TInt SetOtherSpeedConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
1.299 + TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
1.300 + TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
1.301 + TInt aSize);
1.302 + TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const;
1.303 + TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
1.304 + TUint8 aEndpointAddress) const;
1.305 + TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
1.306 + TUint8 aEndpointAddress, TInt aSize);
1.307 + TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
1.308 +
1.309 + // String descriptors
1.310 + void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting=0);
1.311 + TInt GetStringDescriptorLangIdTC(DThread* aThread, TDes8& aLangId) const;
1.312 + TInt SetStringDescriptorLangId(TUint16 aLangId);
1.313 + TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const;
1.314 + TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString);
1.315 + TInt RemoveManufacturerStringDescriptor();
1.316 + TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const;
1.317 + TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString);
1.318 + TInt RemoveProductStringDescriptor();
1.319 + TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const;
1.320 + TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString);
1.321 + TInt RemoveSerialNumberStringDescriptor();
1.322 + TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const;
1.323 + TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString);
1.324 + TInt RemoveConfigurationStringDescriptor();
1.325 + TInt GetStringDescriptorTC(DThread* aThread, TInt aIndex, TDes8& aString) const;
1.326 + TInt SetStringDescriptorTC(DThread* aThread, TInt aIndex, const TDes8& aString);
1.327 + TInt RemoveStringDescriptor(TInt aIndex);
1.328 +
1.329 +private:
1.330 + // Descriptors
1.331 + void InsertIfcDesc(TUsbcDescriptorBase* aDesc);
1.332 + void InsertEpDesc(TUsbcDescriptorBase* aDesc);
1.333 + TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const;
1.334 + TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const;
1.335 + void DeleteDescriptors(TInt aIndex, TInt aCount = 1);
1.336 + void UpdateConfigDescriptorLength(TInt aLength);
1.337 + void UpdateConfigDescriptorNumIfcs(TInt aNumber);
1.338 + void UpdateIfcNumbers(TInt aNumber);
1.339 + TInt GetDeviceDescriptor(TInt aIndex) const;
1.340 + TInt GetConfigurationDescriptor(TInt aIndex) const;
1.341 + TInt GetOtgDescriptor() const;
1.342 +
1.343 + // String descriptors
1.344 + TInt GetStringDescriptor(TInt aIndex) const;
1.345 + TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex, TInt aPosition) const;
1.346 + TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex, TInt aPosition);
1.347 + TInt RemoveDeviceStringDescriptor(TInt aIndex, TInt aPosition);
1.348 + void ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc);
1.349 + TBool AnyStringDescriptors() const;
1.350 + TBool StringDescriptorExists(TInt aIndex) const;
1.351 + TInt FindAvailableStringPos() const;
1.352 +
1.353 +private:
1.354 + // Data members
1.355 + RPointerArray<TUsbcDescriptorBase> iDescriptors;
1.356 + RPointerArray<TUsbcStringDescriptorBase> iStrings;
1.357 + TInt iIfcIdx;
1.358 + TUint8* const iEp0_TxBuf; // points to the controller's ep0 TX buffer
1.359 + TBool iHighSpeed; // true if currently operating at high-speed
1.360 + };
1.361 +
1.362 +
1.363 +#endif // __USBCDESC_H__