usbdrv/peripheral/public/usbcdesc.h
author hgs
Mon, 06 Sep 2010 11:27:08 +0800
changeset 48 21625e5de155
parent 33 089413cdde3c
child 59 bbdce6bffaad
permissions -rw-r--r--
201035_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33
089413cdde3c 201028_02
hgs
parents:
diff changeset
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
089413cdde3c 201028_02
hgs
parents:
diff changeset
     2
// All rights reserved.
089413cdde3c 201028_02
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
089413cdde3c 201028_02
hgs
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
089413cdde3c 201028_02
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
089413cdde3c 201028_02
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
089413cdde3c 201028_02
hgs
parents:
diff changeset
     7
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
     8
// Initial Contributors:
089413cdde3c 201028_02
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    10
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    11
// Contributors:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    12
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    13
// Description:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    14
// e32/include/drivers/usbcdesc.h
089413cdde3c 201028_02
hgs
parents:
diff changeset
    15
// USB descriptors and their management.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    16
// 
089413cdde3c 201028_02
hgs
parents:
diff changeset
    17
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    18
089413cdde3c 201028_02
hgs
parents:
diff changeset
    19
/**
089413cdde3c 201028_02
hgs
parents:
diff changeset
    20
 @file usbcdesc.h
089413cdde3c 201028_02
hgs
parents:
diff changeset
    21
 @internalTechnology
089413cdde3c 201028_02
hgs
parents:
diff changeset
    22
*/
089413cdde3c 201028_02
hgs
parents:
diff changeset
    23
089413cdde3c 201028_02
hgs
parents:
diff changeset
    24
#ifndef __USBCDESC_H__
089413cdde3c 201028_02
hgs
parents:
diff changeset
    25
#define __USBCDESC_H__
089413cdde3c 201028_02
hgs
parents:
diff changeset
    26
089413cdde3c 201028_02
hgs
parents:
diff changeset
    27
#include <kernel/kernel.h>
089413cdde3c 201028_02
hgs
parents:
diff changeset
    28
089413cdde3c 201028_02
hgs
parents:
diff changeset
    29
089413cdde3c 201028_02
hgs
parents:
diff changeset
    30
// Hard-wired positions of some descriptors in iDescriptors array (whether present or not):
089413cdde3c 201028_02
hgs
parents:
diff changeset
    31
static const TInt KDescPosition_Device           = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    32
static const TInt KDescPosition_DeviceQualifier  = 1;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    33
static const TInt KDescPosition_OtherSpeedConfig = 2;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    34
static const TInt KDescPosition_Config           = 3;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    35
static const TInt KDescPosition_Otg              = 4;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    36
static const TInt KDescPosition_FirstAvailable   = 5;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    37
089413cdde3c 201028_02
hgs
parents:
diff changeset
    38
// Hard-wired positions of string descriptors in iStrings array (whether present or not):
089413cdde3c 201028_02
hgs
parents:
diff changeset
    39
static const TInt KStringPosition_Langid           = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    40
static const TInt KStringPosition_Manufact         = 1;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    41
static const TInt KStringPosition_Product          = 2;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    42
static const TInt KStringPosition_Serial           = 3;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    43
static const TInt KStringPosition_Config           = 4;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    44
static const TInt KStringPosition_OtherSpeedConfig = 5;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    45
static const TInt KStringPosition_FirstAvailable   = 6;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    46
089413cdde3c 201028_02
hgs
parents:
diff changeset
    47
089413cdde3c 201028_02
hgs
parents:
diff changeset
    48
NONSHARABLE_CLASS(TUsbcDescriptorBase)
089413cdde3c 201028_02
hgs
parents:
diff changeset
    49
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    50
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    51
    virtual ~TUsbcDescriptorBase();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    52
    void SetByte(TInt aPosition, TUint8 aValue);
089413cdde3c 201028_02
hgs
parents:
diff changeset
    53
    void SetWord(TInt aPosition, TUint16 aValue);
089413cdde3c 201028_02
hgs
parents:
diff changeset
    54
    TUint8 Byte(TInt aPosition) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    55
    TUint16 Word(TInt aPosition) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    56
    void GetDescriptorData(TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    57
    TInt GetDescriptorData(TUint8* aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    58
    TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    59
    const TDes8& DescriptorData() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    60
    TDes8& DescriptorData();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    61
    TUint Size() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    62
    TUint8 Type() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    63
    virtual void UpdateFs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    64
    virtual void UpdateHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    65
protected:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    66
    TUsbcDescriptorBase();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    67
    void SetBufferPointer(const TDesC8& aDes);
089413cdde3c 201028_02
hgs
parents:
diff changeset
    68
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    69
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
089413cdde3c 201028_02
hgs
parents:
diff changeset
    70
    TUint8 iIndex;                                            // only needed for SET_DESCRIPTOR
089413cdde3c 201028_02
hgs
parents:
diff changeset
    71
#endif
089413cdde3c 201028_02
hgs
parents:
diff changeset
    72
    TPtr8 iBufPtr;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    73
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
    74
089413cdde3c 201028_02
hgs
parents:
diff changeset
    75
089413cdde3c 201028_02
hgs
parents:
diff changeset
    76
NONSHARABLE_CLASS(TUsbcDeviceDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
    77
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    78
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    79
    /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size
089413cdde3c 201028_02
hgs
parents:
diff changeset
    80
        is fixed and known).
089413cdde3c 201028_02
hgs
parents:
diff changeset
    81
    */
089413cdde3c 201028_02
hgs
parents:
diff changeset
    82
    static TUsbcDeviceDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
089413cdde3c 201028_02
hgs
parents:
diff changeset
    83
                                      TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
089413cdde3c 201028_02
hgs
parents:
diff changeset
    84
                                      TUint16 aVendorId, TUint16 aProductId,
089413cdde3c 201028_02
hgs
parents:
diff changeset
    85
                                      TUint16 aDeviceRelease, TUint8 aNumConfigurations);
089413cdde3c 201028_02
hgs
parents:
diff changeset
    86
    virtual void UpdateFs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    87
    virtual void UpdateHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    88
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
    89
    TUsbcDeviceDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
    90
    TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
089413cdde3c 201028_02
hgs
parents:
diff changeset
    91
                   TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
089413cdde3c 201028_02
hgs
parents:
diff changeset
    92
                   TUint16 aDeviceRelease, TUint8 aNumConfigurations);
089413cdde3c 201028_02
hgs
parents:
diff changeset
    93
    TBuf8<KUsbDescSize_Device> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    94
    TUint8 iEp0Size_Fs;                                        // holds Ep0 size for FS (could be < 64)
089413cdde3c 201028_02
hgs
parents:
diff changeset
    95
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
    96
089413cdde3c 201028_02
hgs
parents:
diff changeset
    97
089413cdde3c 201028_02
hgs
parents:
diff changeset
    98
NONSHARABLE_CLASS(TUsbcDeviceQualifierDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
    99
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   100
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   101
    /** aMaxPacketSize0 should be the Ep0 max packet size for FS operation (as the HS size
089413cdde3c 201028_02
hgs
parents:
diff changeset
   102
        is fixed and known).
089413cdde3c 201028_02
hgs
parents:
diff changeset
   103
    */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   104
    static TUsbcDeviceQualifierDescriptor* New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   105
                                               TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   106
                                               TUint8 aNumConfigurations, TUint8 aReserved=0);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   107
    virtual void UpdateFs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   108
    virtual void UpdateHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   109
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   110
    TUsbcDeviceQualifierDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   111
    TInt Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   112
                   TUint8 aMaxPacketSize0, TUint8 aNumConfigurations, TUint8 aReserved);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   113
    TBuf8<KUsbDescSize_DeviceQualifier> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   114
    TUint8 iEp0Size_Fs;                                        // holds Ep0 size for FS (could be < 64)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   115
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   116
089413cdde3c 201028_02
hgs
parents:
diff changeset
   117
089413cdde3c 201028_02
hgs
parents:
diff changeset
   118
NONSHARABLE_CLASS(TUsbcConfigDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   119
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   120
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   121
    /** aMaxPower should be given here in milliamps (not mA/2). */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   122
    static TUsbcConfigDescriptor* New(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   123
                                      TUint16 aMaxPower);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   124
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   125
    TUsbcConfigDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   126
    TInt Construct(TUint8 aConfigurationValue, TBool aSelfPowered, TBool aRemoteWakeup, TUint16 aMaxPower);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   127
    TBuf8<KUsbDescSize_Config> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   128
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   129
089413cdde3c 201028_02
hgs
parents:
diff changeset
   130
089413cdde3c 201028_02
hgs
parents:
diff changeset
   131
// The Other_Speed_Configuration descriptor has same size and layout as the
089413cdde3c 201028_02
hgs
parents:
diff changeset
   132
// standard Configuration descriptor, therefore we don't need a new definition.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   133
typedef TUsbcConfigDescriptor TUsbcOtherSpeedConfigDescriptor;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   134
089413cdde3c 201028_02
hgs
parents:
diff changeset
   135
089413cdde3c 201028_02
hgs
parents:
diff changeset
   136
NONSHARABLE_CLASS(TUsbcInterfaceDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   137
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   138
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   139
    static TUsbcInterfaceDescriptor* New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt NumEndpoints,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   140
                                         const TUsbcClassInfo& aClassInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   141
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   142
    TUsbcInterfaceDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   143
    TInt Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting, TInt aNumEndpoints,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   144
                   const TUsbcClassInfo& aClassInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   145
    TBuf8<KUsbDescSize_Interface> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   146
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   147
089413cdde3c 201028_02
hgs
parents:
diff changeset
   148
089413cdde3c 201028_02
hgs
parents:
diff changeset
   149
NONSHARABLE_CLASS(TUsbcEndpointDescriptorBase) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   150
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   151
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   152
    virtual void UpdateFs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   153
    virtual void UpdateHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   154
protected:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   155
    TInt Construct(const TUsbcEndpointInfo& aEpInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   156
    TUsbcEndpointDescriptorBase();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   157
protected:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   158
    /** Stores the endpoint size to be used for FS. */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   159
    TInt iEpSize_Fs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   160
    /** Stores the endpoint size to be used for HS. */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   161
    TInt iEpSize_Hs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   162
    /** Stores the endpoint polling interval to be used for FS. */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   163
    TInt iInterval_Fs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   164
    /** Stores the endpoint polling interval to be used for HS. */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   165
    TInt iInterval_Hs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   166
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   167
089413cdde3c 201028_02
hgs
parents:
diff changeset
   168
089413cdde3c 201028_02
hgs
parents:
diff changeset
   169
NONSHARABLE_CLASS(TUsbcEndpointDescriptor) : public TUsbcEndpointDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   170
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   171
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   172
    static TUsbcEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   173
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   174
    TUsbcEndpointDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   175
    TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   176
    TBuf8<KUsbDescSize_Endpoint> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   177
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   178
089413cdde3c 201028_02
hgs
parents:
diff changeset
   179
089413cdde3c 201028_02
hgs
parents:
diff changeset
   180
class TUsbcAudioEndpointDescriptor : public TUsbcEndpointDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   181
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   182
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   183
    static TUsbcAudioEndpointDescriptor* New(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   184
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   185
    TUsbcAudioEndpointDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   186
    TInt Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   187
    TBuf8<KUsbDescSize_AudioEndpoint> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   188
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   189
089413cdde3c 201028_02
hgs
parents:
diff changeset
   190
089413cdde3c 201028_02
hgs
parents:
diff changeset
   191
NONSHARABLE_CLASS(TUsbcOtgDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   192
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   193
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   194
    static TUsbcOtgDescriptor* New(TBool aHnpSupport, TBool aSrpSupport);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   195
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   196
    TUsbcOtgDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   197
    TInt Construct(TBool aHnpSupport, TBool aSrpSupport);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   198
    TBuf8<KUsbDescSize_Otg> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   199
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   200
089413cdde3c 201028_02
hgs
parents:
diff changeset
   201
089413cdde3c 201028_02
hgs
parents:
diff changeset
   202
NONSHARABLE_CLASS(TUsbcClassSpecificDescriptor) : public TUsbcDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   203
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   204
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   205
    virtual ~TUsbcClassSpecificDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   206
    static TUsbcClassSpecificDescriptor* New(TUint8 aType, TInt aSize);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   207
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   208
    TUsbcClassSpecificDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   209
    TInt Construct(TUint8 aType, TInt aSize);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   210
    HBuf8* iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   211
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   212
089413cdde3c 201028_02
hgs
parents:
diff changeset
   213
089413cdde3c 201028_02
hgs
parents:
diff changeset
   214
NONSHARABLE_CLASS(TUsbcStringDescriptorBase)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   215
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   216
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   217
    virtual ~TUsbcStringDescriptorBase();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   218
    TUint16 Word(TInt aPosition) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   219
    void SetWord(TInt aPosition, TUint16 aValue);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   220
    TInt GetDescriptorData(TUint8* aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   221
    TInt GetDescriptorData(TUint8* aBuffer, TUint aMaxSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   222
    const TDes8& StringData() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   223
    TDes8& StringData();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   224
    TUint Size() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   225
    void SetBufferPointer(const TDesC8& aDes);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   226
protected:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   227
    TUsbcStringDescriptorBase();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   228
    TBuf8<2> iSBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   229
    TPtr8 iBufPtr;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   230
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   231
//    TUint8 iIndex;                                            // not needed in DescriptorPool: position == index
089413cdde3c 201028_02
hgs
parents:
diff changeset
   232
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   233
089413cdde3c 201028_02
hgs
parents:
diff changeset
   234
089413cdde3c 201028_02
hgs
parents:
diff changeset
   235
NONSHARABLE_CLASS(TUsbcStringDescriptor) : public TUsbcStringDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   236
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   237
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   238
    virtual ~TUsbcStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   239
    static TUsbcStringDescriptor* New(const TDesC8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   240
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   241
    TUsbcStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   242
    TInt Construct(const TDesC8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   243
    HBuf8* iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   244
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   245
089413cdde3c 201028_02
hgs
parents:
diff changeset
   246
089413cdde3c 201028_02
hgs
parents:
diff changeset
   247
// Currently we support only one language, and thus there's no need to provide
089413cdde3c 201028_02
hgs
parents:
diff changeset
   248
// a LangId string descriptor with more than one array element.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   249
NONSHARABLE_CLASS(TUsbcLangIdDescriptor) : public TUsbcStringDescriptorBase
089413cdde3c 201028_02
hgs
parents:
diff changeset
   250
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   251
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   252
    virtual ~TUsbcLangIdDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   253
    static TUsbcLangIdDescriptor* New(TUint16 aLangId);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   254
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   255
    TUsbcLangIdDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   256
    TInt Construct(TUint16 aLangId);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   257
    TBuf8<2> iBuf;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   258
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   259
089413cdde3c 201028_02
hgs
parents:
diff changeset
   260
089413cdde3c 201028_02
hgs
parents:
diff changeset
   261
class TUsbcDescriptorPool
089413cdde3c 201028_02
hgs
parents:
diff changeset
   262
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   263
public:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   264
    TUsbcDescriptorPool(TUint8* aEp0_TxBuf);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   265
    ~TUsbcDescriptorPool();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   266
    TInt Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   267
              TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   268
              TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   269
              TUsbcStringDescriptor* aConfig, TUsbcOtgDescriptor* aOtgDesc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   270
    TInt InitHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   271
    TInt UpdateDescriptorsFs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   272
    TInt UpdateDescriptorsHs();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   273
089413cdde3c 201028_02
hgs
parents:
diff changeset
   274
    // Descriptors
089413cdde3c 201028_02
hgs
parents:
diff changeset
   275
    TInt FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   276
    void InsertDescriptor(TUsbcDescriptorBase* aDesc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   277
    void DeleteIfcDescriptor(TInt aNumber, TInt aSetting=0);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   278
    // The TC in many of the following functions stands for 'ThreadCopy' because that's what happens there.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   279
    TInt GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   280
    TInt SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   281
    TInt GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   282
    TInt SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   283
    TInt GetOtgDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   284
    TInt SetOtgDescriptor(const TDesC8& aBuffer);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   285
    TInt GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   286
    TInt SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   287
    TInt GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   288
                                 TUint8 aEndpointAddress) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   289
    TInt SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   290
                                 TUint8 aEndpointAddress);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   291
    TInt GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   292
    TInt GetDeviceQualifierDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   293
    TInt SetDeviceQualifierDescriptorTC(DThread* aThread, const TDes8& aBuffer);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   294
    TInt GetOtherSpeedConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   295
    TInt SetOtherSpeedConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   296
    TInt GetCSInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   297
    TInt SetCSInterfaceDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   298
                                    TInt aSize);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   299
    TInt GetCSInterfaceDescriptorSize(TInt aInterface, TInt aSetting, TInt& aSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   300
    TInt GetCSEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer, TInt aInterface, TInt aSetting,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   301
                                   TUint8 aEndpointAddress) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   302
    TInt SetCSEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer, TInt aInterface, TInt aSetting,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   303
                                   TUint8 aEndpointAddress, TInt aSize);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   304
    TInt GetCSEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress, TInt& aSize) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   305
089413cdde3c 201028_02
hgs
parents:
diff changeset
   306
    // String descriptors
089413cdde3c 201028_02
hgs
parents:
diff changeset
   307
    void SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting=0);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   308
    TInt GetStringDescriptorLangIdTC(DThread* aThread, TDes8& aLangId) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   309
    TInt SetStringDescriptorLangId(TUint16 aLangId);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   310
    TInt GetManufacturerStringDescriptorTC(DThread* aThread, TDes8& aString) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   311
    TInt SetManufacturerStringDescriptorTC(DThread* aThread, const TDes8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   312
    TInt RemoveManufacturerStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   313
    TInt GetProductStringDescriptorTC(DThread* aThread, TDes8& aString) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   314
    TInt SetProductStringDescriptorTC(DThread* aThread, const TDes8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   315
    TInt RemoveProductStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   316
    TInt GetSerialNumberStringDescriptorTC(DThread* aThread, TDes8& aString) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   317
    TInt SetSerialNumberStringDescriptorTC(DThread* aThread, const TDes8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   318
    TInt RemoveSerialNumberStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   319
    TInt GetConfigurationStringDescriptorTC(DThread* aThread, TDes8& aString) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   320
    TInt SetConfigurationStringDescriptorTC(DThread* aThread, const TDes8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   321
    TInt RemoveConfigurationStringDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   322
    TInt GetStringDescriptorTC(DThread* aThread, TInt aIndex, TDes8& aString) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   323
    TInt SetStringDescriptorTC(DThread* aThread, TInt aIndex, const TDes8& aString);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   324
    TInt RemoveStringDescriptor(TInt aIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   325
089413cdde3c 201028_02
hgs
parents:
diff changeset
   326
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   327
    // Descriptors
089413cdde3c 201028_02
hgs
parents:
diff changeset
   328
    void InsertIfcDesc(TUsbcDescriptorBase* aDesc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   329
    void InsertEpDesc(TUsbcDescriptorBase* aDesc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   330
    TInt FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   331
    TInt FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   332
    void DeleteDescriptors(TInt aIndex, TInt aCount = 1);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   333
    void UpdateConfigDescriptorLength(TInt aLength);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   334
    void UpdateConfigDescriptorNumIfcs(TInt aNumber);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   335
    void UpdateIfcNumbers(TInt aNumber);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   336
    TInt GetDeviceDescriptor(TInt aIndex) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   337
    TInt GetConfigurationDescriptor(TInt aIndex) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   338
    TInt GetOtgDescriptor() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   339
089413cdde3c 201028_02
hgs
parents:
diff changeset
   340
    // String descriptors
089413cdde3c 201028_02
hgs
parents:
diff changeset
   341
    TInt GetStringDescriptor(TInt aIndex) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   342
    TInt GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString, TInt aIndex, TInt aPosition) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   343
    TInt SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString, TInt aIndex, TInt aPosition);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   344
    TInt RemoveDeviceStringDescriptor(TInt aIndex, TInt aPosition);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   345
    void ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   346
    TBool AnyStringDescriptors() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   347
    TBool StringDescriptorExists(TInt aIndex) const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   348
    TInt FindAvailableStringPos() const;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   349
089413cdde3c 201028_02
hgs
parents:
diff changeset
   350
private:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   351
    // Data members
089413cdde3c 201028_02
hgs
parents:
diff changeset
   352
    RPointerArray<TUsbcDescriptorBase> iDescriptors;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   353
    RPointerArray<TUsbcStringDescriptorBase> iStrings;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   354
    TInt iIfcIdx;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   355
    TUint8* const iEp0_TxBuf;                                // points to the controller's ep0 TX buffer
089413cdde3c 201028_02
hgs
parents:
diff changeset
   356
    TBool iHighSpeed;                                        // true if currently operating at high-speed
089413cdde3c 201028_02
hgs
parents:
diff changeset
   357
    };
089413cdde3c 201028_02
hgs
parents:
diff changeset
   358
089413cdde3c 201028_02
hgs
parents:
diff changeset
   359
089413cdde3c 201028_02
hgs
parents:
diff changeset
   360
#endif    // __USBCDESC_H__