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