First public contribution.
1 // Copyright (c) 2004-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 // f32test\testusbcldd\inc\dtestusblogdev.h
15 // Test USB logical channel classes.
24 #ifndef __DTESTUSBCLOGDEVICE_H_
25 #define __DTESTUSBCLOGDEVICE_H_
30 const TInt KTestUsbcMajorVersion = 0;
31 const TInt KTestUsbcMinorVersion = 1;
32 const TInt KTestUsbcBuildVersion = 1;
33 const TInt KTestUsbcMaxRequests = 10;
35 /** The USB version we are compliant with (BCD) */
36 const TUint16 KUsbcUsbVersion = 0x0110;
38 /** The Ep0 tx buffer area */
39 const TInt KUsbcBufSz_Ep0Tx = 1024;
41 /** Size of buffer for transferring data from client and host */
42 const TInt KTransferBufSize = 1024;
44 /** Must correspond to the max enum of TRequest + 1;
45 currently this is ERequestEndpointStatusNotify = 9 */
46 const TInt KUsbcMaxRequests = 10;
48 /** Maximum number of endpoints an Interface may have */
49 const TInt KUsbcMaxEpNumber = 5;
51 /** Size of endpoint buffers */
52 const TInt KEndpointBufferSize = 16 * 1024;
54 class DTestUsbcEndpoint;
55 class DTestUsbcLogDevice : public DLogicalDevice
59 ~DTestUsbcLogDevice();
61 void GetCaps(TDes8& aDes) const;
62 TInt Create(DLogicalChannelBase*& aChannel);
63 DLogicalChannel* CreateL();
66 RPointerArray<DTestUsbcEndpoint> iEndpoints;
69 class TUsbcInterfaceSet;
70 class TUsbcLogicalEndpoint;
72 /** This is one 'Alternate Setting' of an interface. */
76 TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting);
79 /** Array of endpoints making up (belonging to) this setting. */
80 RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
81 /** 'Back' pointer. */
82 TUsbcInterfaceSet* const iInterfaceSet;
83 /** bAlternateSetting (zero-based). */
84 const TUint8 iSettingCode;
87 /** This is an 'Interface' (owning 1 or more alternate settings TUsbcInterface). */
88 class TUsbcInterfaceSet
91 TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
93 const TUsbcInterface* CurrentInterface() const;
94 TUsbcInterface* CurrentInterface();
96 /** Array of alternate settings provided by (belonging to) this interface. */
97 RPointerArray<TUsbcInterface> iInterfaces;
98 /** Pointer to the LDD which created and owns this interface. */
99 const DBase* const iClientId;
100 /** bInterfaceNumber (zero-based). */
101 TUint8 iInterfaceNumber;
102 /** bAlternateSetting (zero-based). */
103 TUint8 iCurrentInterface;
106 /** This is a logical 'Endpoint', as used by our device configuration model. */
107 class TUsbcLogicalEndpoint
110 TUsbcLogicalEndpoint(TUint aEndpointNum, const TUsbcEndpointInfo& aInfo,
111 TUsbcInterface* aInterface);
112 ~TUsbcLogicalEndpoint();
114 /** The virtual (logical) endpoint number. */
115 const TInt iLEndpointNum;
116 /** This endpoint's info structure. */
117 TUsbcEndpointInfo iInfo;
118 /** 'Back' pointer. */
119 const TUsbcInterface* iInterface;
122 class DLddTestUsbcChannel : public DLogicalChannel
125 DLddTestUsbcChannel(RPointerArray<DTestUsbcEndpoint>& aEndpoints);
126 void HandleMsg(TMessageBase* aMsg);
127 TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
128 ~DLddTestUsbcChannel();
131 TInt DoCancel(TInt aReqNo);
132 void DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
133 TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
134 TBool ValidateEndpoint(TUsbcEndpointInfo* aEndpointInfo);
135 TInt SetInterface(TInt aInterfaceNumber, TUsbcInterfaceInfoBuf *aUserInterfaceInfoBuf, TPtr8* aInterfaceString);
136 TInt SetInterface(TInt aInterfaceNumber, TUsbcClassInfo& aClass, TDesC8* aString,
137 TInt aTotalEndpointsUsed, const TUsbcEndpointInfo aEndpointData[]);
138 TUsbcInterface* CreateInterface(TInt aIfc);
139 void DeleteInterface(TInt aIfc);
140 void DeleteInterfaceSet();
141 TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfo aEndpointData[]);
142 TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass,
143 TDesC8* aString, const TUsbcEndpointInfo aEndpointData[]);
144 TInt ReleaseInterface(TInt aInterfaceNumber);
145 TInt HostEndpointStatusNotify(TInt aEndpointNumber, TRequestStatus* aStatus);
146 TInt EndpointStatusNotify(TUint* aEndpointMask, TRequestStatus* aStatus);
147 void EndpointStatusNotifyCallback();
148 TInt ClearEndpoint(TInt aEndpointNumber);
149 TInt DoTransferAsyncReq(TInt aEndpointNumber, TAny* a1, TAny* a2, TRequestStatus& aStatus);
150 TBool ValidEndpoint(TInt aEndpointNumber);
151 TInt FindRealEndpoint(TInt aEndpointNumber);
152 TInt HaltClearEndpoint(TBool aHalt, TInt aEndpointNumber);
153 void AlternateDeviceStatusNotify();
154 TInt SetAlternateDeviceStatusNotify(TRequestStatus* aStatus, TUint* aValue);
155 void CancelAlternateDeviceStatusNotify();
156 TInt ReEnumerate(TRequestStatus* aStatus);
157 void SetDeviceState(TUsbcDeviceState aState);
160 TUsbcDescriptorPool iDescriptors;
161 TUsbcInterfaceSet iIfcSet;
162 RPointerArray<DTestUsbcEndpoint>& iEndpoints;
163 TUint* iEndpointStatusMask;
164 TRequestStatus* iEndpointStatusNotifyRequest;
165 TRequestStatus* iAlternateDeviceStatusNotifyRequest;
166 TUint* iAlternateDeviceStatusNotifyValue;
167 TUsbcDeviceState iDeviceState;
170 static const TUsbcEndpointData iEndpointData[];
172 friend class DTestUsbcEndpoint;
175 class DTestUsbcEndpoint : public DBase
179 ~DTestUsbcEndpoint();
180 TInt Create(const TUsbcEndpointCaps& aCaps);
181 TInt TryToComplete();
182 TInt CopyData(TInt aSrcOffset, DThread* aDestClient, TDesC8* aDest,
183 TInt aDestOffset, TInt aLen);
184 TBool SupportsDir(TUint aDir);
185 TBool EndpointSuitable(const TUsbcEndpointInfo& aInfo);
190 void SetClearCallback(DLddTestUsbcChannel* aCallback);
191 TInt HostStatusNotify(DThread* aHost, TRequestStatus* aStatus);
192 TInt NewRequest(DThread* aClient, TRequestStatus* aStatus, TEndpointTransferInfo& aInfo, TTransferType aType);
193 TInt NewHostRequest(DThread* aHost, TRequestStatus* aStatus, TEndpointTransferInfo& aInfo, TTransferType aType);
195 TRequestStatus* iClientStatus;
196 TRequestStatus* iHostStatus;
197 TRequestStatus* iHostNotifyStatus;
200 DThread* iNotifyHost;
201 TUsbcEndpointCaps iCaps;
202 TBool iRequestPending;
203 TBool iHostRequestPending;
204 TEndpointTransferInfo iClientTransferInfo;
205 TEndpointTransferInfo iHostTransferInfo;
206 TInt iDataTransferred;
207 TInt iHostDataTransferred;
208 TTransferType iRequestType;
209 TTransferType iHostRequestType;
212 DLddTestUsbcChannel* iClearCallback;
218 #endif // __DTESTUSBCLOGDEVICE_H_