|
1 #ifndef __TEST_DEVICE_BASE_H |
|
2 #define __TEST_DEVICE_BASE_H |
|
3 |
|
4 /* |
|
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 * All rights reserved. |
|
7 * This component and the accompanying materials are made available |
|
8 * under the terms of the License "Eclipse Public License v1.0" |
|
9 * which accompanies this distribution, and is available |
|
10 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 * |
|
12 * Initial Contributors: |
|
13 * Nokia Corporation - initial contribution. |
|
14 * |
|
15 * Contributors: |
|
16 * |
|
17 * Description: |
|
18 * @file TestDeviceBase.h |
|
19 * @internalComponent |
|
20 * |
|
21 * |
|
22 */ |
|
23 |
|
24 |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <d32usbc.h> |
|
28 #include "UsbClientStateWatcher.h" |
|
29 #include "ep0reader.h" |
|
30 #include "BaseTestCase.h" |
|
31 #include <d32otgdi.h> |
|
32 |
|
33 namespace NUnitTesting_USBDI |
|
34 { |
|
35 |
|
36 // Forward declarations |
|
37 |
|
38 class CInterfaceBase; |
|
39 class CSoftwareConnectTimer; |
|
40 class CRemoteWakeupTimer; |
|
41 |
|
42 /** |
|
43 This class represents a test USB device. There is only one configuration supported |
|
44 for this representation |
|
45 */ |
|
46 class RUsbTestDevice : public MUsbClientStateObserver, |
|
47 public MRequestHandler |
|
48 { |
|
49 public: |
|
50 /** |
|
51 Destructor |
|
52 */ |
|
53 |
|
54 virtual ~RUsbTestDevice(); |
|
55 |
|
56 // ctor |
|
57 RUsbTestDevice(CBaseTestCase* aTestCase); |
|
58 |
|
59 void ResetState(); |
|
60 |
|
61 /** |
|
62 Requests error/reports from this test device |
|
63 @param aObserverStatus the status of the entity that requests error reports |
|
64 */ |
|
65 |
|
66 void SubscribeToReports(TRequestStatus& aOberverStatus); |
|
67 |
|
68 /** |
|
69 Cancel request for any errors from operations from this device |
|
70 */ |
|
71 |
|
72 void CancelSubscriptionToReports(); |
|
73 |
|
74 /** |
|
75 Open a basic device |
|
76 @leave KErrNoMemory |
|
77 */ |
|
78 |
|
79 void OpenL(); |
|
80 |
|
81 /** |
|
82 Close this device, releaseing all resources |
|
83 */ |
|
84 |
|
85 void Close(); |
|
86 |
|
87 /** |
|
88 Sets specific information for the device |
|
89 @param aClassCode the class code that is specified by the standard |
|
90 00h Use class information in the Interface Descriptors |
|
91 02h Communications and CDC Control (together with interface descriptor) |
|
92 09h Hub |
|
93 DCh Diagnostic Device (together with interface descriptors) |
|
94 EFh Miscellaneous (together with interface descriptors) |
|
95 FFh Vendor Specific (together with interface descriptors) |
|
96 @param aSubClassCode the subclass code specified by the USB org |
|
97 @param aDeviceProtocol |
|
98 */ |
|
99 |
|
100 TInt SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol); |
|
101 |
|
102 /** |
|
103 Set the USB specification that this device complies to |
|
104 @param aSpecification the specificatio nnumber |
|
105 */ |
|
106 |
|
107 TInt SetUsbSpecification(TUint16 aSpecification); |
|
108 |
|
109 /** |
|
110 Set the information for the vendor of this device |
|
111 @param aVendorId the identity number for the vendor |
|
112 */ |
|
113 |
|
114 TInt SetVendor(TUint16 aVendorId); |
|
115 |
|
116 /** |
|
117 Set the product information |
|
118 @param aProductId the identity of the product |
|
119 @param aProductString the string used to describe the product |
|
120 @param aManufacturerString the string used to describe the manufacturer |
|
121 @param aSerialNumberString the product serial number as string |
|
122 */ |
|
123 |
|
124 TInt SetProduct(TUint16 aProductId,const TDesC16& aProductString,const TDesC16& aManufacturerString, |
|
125 const TDesC16& aSerialNumberString); |
|
126 |
|
127 /** |
|
128 Establishes the configuration string for the device |
|
129 @param aConfigString the string for the configuration |
|
130 */ |
|
131 |
|
132 TInt SetConfigurationString(const TDesC16& aConfigString); |
|
133 |
|
134 /** |
|
135 Adds an test interface to the test device |
|
136 @param aInterface a pointer to the interface |
|
137 */ |
|
138 |
|
139 void AddInterface(CInterfaceBase* aInterface); |
|
140 |
|
141 /** |
|
142 Access the interfacefor this device identified by the interface index number |
|
143 @param aIndex the index of the interface |
|
144 @return the interface |
|
145 */ |
|
146 |
|
147 CInterfaceBase& Interface(TInt aIndex); |
|
148 |
|
149 /** |
|
150 Software connect this test device to the host bus. |
|
151 The device must already by physically connected. |
|
152 */ |
|
153 |
|
154 void SoftwareConnect(); |
|
155 |
|
156 /** |
|
157 Software dis-connect this test device from the host bus. |
|
158 The device can be left physically connected |
|
159 */ |
|
160 |
|
161 void SoftwareDisconnect(); |
|
162 |
|
163 /** |
|
164 Perform a remote wake-up for the device |
|
165 */ |
|
166 |
|
167 void RemoteWakeup(); |
|
168 |
|
169 /** |
|
170 Notifies the test case of any errors in operations for this test device |
|
171 @param aCompletionCode the error code to complete the test case with |
|
172 */ |
|
173 |
|
174 void ReportError(TInt aCompletionCode); |
|
175 |
|
176 /** |
|
177 Sends a zero length data packet to acknowledge the request |
|
178 */ |
|
179 |
|
180 void AcknowledgeRequestReceived(); |
|
181 |
|
182 public: // From MUsbClientStateObserver |
|
183 |
|
184 /** |
|
185 Called when the device has changed state |
|
186 @param aNewState will hold the new state the device has been placed into by the host |
|
187 @param aChangeCompletionCode the operation comletion code |
|
188 */ |
|
189 void StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode); |
|
190 |
|
191 public: // From MRequestHandler |
|
192 |
|
193 /** |
|
194 Process control requests from device endpoint 0 |
|
195 @param aRequest the control request value |
|
196 @param aValue a parameter value for the request |
|
197 @param aIndex an index parameter for the request |
|
198 @param aDataReqLength the length of the data to be returned to the host |
|
199 @param aPayload the data payload sent to the device by the host in a data phase |
|
200 */ |
|
201 |
|
202 virtual TInt ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex, |
|
203 TUint16 aDataReqLength,const TDesC8& aPayload); |
|
204 |
|
205 protected: |
|
206 |
|
207 /** |
|
208 Constructor, build a test device |
|
209 */ |
|
210 |
|
211 RUsbTestDevice(); |
|
212 |
|
213 /** |
|
214 Start listening for control requests sent by the host |
|
215 */ |
|
216 |
|
217 void StartEp0Reading(); |
|
218 |
|
219 /** |
|
220 Stop reading control requests from endpoint 0 |
|
221 */ |
|
222 |
|
223 void StopEp0Reading(); |
|
224 |
|
225 /** |
|
226 Derived devices will be notified through this function when the device has changed state |
|
227 and this base class has performed basic functionality |
|
228 @param aNewState the new state of the device |
|
229 */ |
|
230 |
|
231 virtual void OnStateChangeL(TUsbcDeviceState aNewState) = 0; |
|
232 |
|
233 |
|
234 protected: |
|
235 |
|
236 RDevUsbcClient iClientDriver; // The USB client driver object |
|
237 |
|
238 /** |
|
239 The device can have many interfaces offering different functions (part functions) |
|
240 They are kept and owned by the device |
|
241 */ |
|
242 RPointerArray<CInterfaceBase> iInterfaces; |
|
243 |
|
244 /** |
|
245 The watcher of states for the USB client |
|
246 */ |
|
247 CUsbClientStateWatcher* iStateWatcher; |
|
248 TUsbcDeviceState iCurrentState; |
|
249 |
|
250 /** |
|
251 The information about the capabilities of the device. |
|
252 This is mostly hardware specific information |
|
253 */ |
|
254 TUsbDeviceCaps iDeviceCaps; |
|
255 |
|
256 /** |
|
257 The control endpoint 0, reading device directed requests |
|
258 */ |
|
259 CDeviceEndpoint0* iDeviceEp0; |
|
260 |
|
261 /** |
|
262 The timer required perform any connect, disconnect or re-connections |
|
263 */ |
|
264 CSoftwareConnectTimer* iConnectTimer; |
|
265 |
|
266 /** |
|
267 The timer that performs any remote wakeups |
|
268 */ |
|
269 CRemoteWakeupTimer* iWakeupTimer; |
|
270 |
|
271 /** |
|
272 */ |
|
273 TRequestStatus* iObserverStatus; |
|
274 |
|
275 /** |
|
276 A Aux buffer |
|
277 */ |
|
278 HBufC8* iAuxBuffer; |
|
279 |
|
280 CBaseTestCase* iTestCase; |
|
281 |
|
282 RProcess iOtgUsbMan; |
|
283 }; |
|
284 |
|
285 |
|
286 } |
|
287 |
|
288 |
|
289 #endif |