author | hgs |
Mon, 04 Oct 2010 12:03:52 +0100 | |
changeset 279 | 957c583b417b |
parent 269 | d57b86b1867a |
permissions | -rw-r--r-- |
253 | 1 |
// Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32/drivers/usbcc/ps_usbc.cpp |
|
15 |
// Platform independent layer (PIL) of the USB Device controller driver (PDD). |
|
16 |
// Interface to the USB LDD. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
/** |
|
21 |
@file ps_usbc.cpp |
|
22 |
@internalTechnology |
|
23 |
*/ |
|
24 |
||
25 |
#include <drivers/usbc.h> |
|
253 | 26 |
#include "OstTraceDefinitions.h" |
27 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
28 |
#include "ps_usbcTraces.h" |
|
29 |
#endif |
|
30 |
||
0 | 31 |
|
32 |
||
33 |
/** |
|
34 |
TUsbcInterfaceSet and TUsbcInterface |
|
35 |
==================================== |
|
36 |
||
37 |
TUsbcInterfaceSet represents a 'USB Interface' and TUsbcInterface |
|
38 |
represents an 'Alternate Setting of a USB Interface'. |
|
39 |
||
40 |
Since every LDD governs exactly one interface, the above distinction is |
|
41 |
made only within the USB implementation. At the LDD API, there is/are |
|
42 |
simply one or more settings for this single interface, numbered from '0' |
|
43 |
(the default) to 'n', and specified by the parameter 'TInt aInterfaceNum'. |
|
44 |
||
45 |
Within the PDD implementation, for a TUsbcInterfaceSet number the parameter |
|
46 |
'TInt aIfcSet' is used (local variable ifcset); for a TUsbcInterface number |
|
47 |
the parameter 'TInt aIfc' is used (local variable ifc). |
|
48 |
||
49 |
||
50 |
iConfigs[0] and CurrentConfig() |
|
51 |
=============================== |
|
52 |
||
53 |
One problem with this file is that it always uses iConfigs[0] and not |
|
54 |
CurrentConfig(). This is mainly because the API to the LDD doesn't know |
|
55 |
about the concept of multiple configurations, and thus always assumes one |
|
56 |
single configuration (which is also always active: a further problem). |
|
57 |
||
58 |
In the file chapter9.cpp this issue doesn't exist, since there we always |
|
59 |
have to obey the USB protocol, and in this way will use the configuration |
|
60 |
which is selected by the host (which will then again currently always be |
|
61 |
iConfigs[0].) |
|
62 |
||
63 |
||
64 |
iEp0ClientId and iEp0DataReceiving |
|
65 |
================================== |
|
66 |
||
67 |
The purpose of these two members of class DUsbClientController is the |
|
68 |
following. |
|
69 |
||
70 |
They are used only during Ep0 control transactions which have an OUT (Rx) |
|
71 |
data stage. The special problem with these transactions is twofold. For one |
|
72 |
thing we have to know that what we are receiving is data and not a Setup |
|
73 |
packet. Furthermore we cannot deduce from the received data itself to whom |
|
74 |
it is addressed (that's because of the shared nature of Ep0). |
|
75 |
||
76 |
So in order to recognize data packets we use iEp0DataReceiving. This |
|
77 |
variable is set to TRUE either 1) upon processing a standard request which |
|
78 |
has a DATA_OUT phase (only SET_DESCRIPTOR), or 2) if we have identified a |
|
79 |
class-specific request which has a DATA_OUT phase and we have also found |
|
80 |
the recipient for that request. |
|
81 |
||
82 |
In order to be able to tell whether received Ep0 data is to be processed by |
|
83 |
the PIL or a LDD, we use iEp0ClientId. iEp0ClientId is usually NULL, which |
|
84 |
means it is our data. However it is set to the client ID of an LDD in case |
|
85 |
2) above. That way we can subsequently hand over received data to the |
|
86 |
correct client LDD. |
|
87 |
||
88 |
iEp0DataReceived tracks the amount of data already received - it is used to |
|
89 |
determine the end of the DATA_OUT phase, irrespective of the owner of the |
|
90 |
data. The total amount that is to be received can be obtained via |
|
91 |
iSetup.iLength. (iSetup holds in that case the Setup packet of the current |
|
92 |
Control transfer.) |
|
93 |
||
94 |
iEp0ClientDataTransmitting is only set to TRUE if a client sets up an Ep0 |
|
95 |
write. After that transmission has completed we use this value to decide |
|
96 |
whether we have to report the completion to a client or not. (If this |
|
97 |
variable is FALSE, we did set up the write and thus no client notification |
|
98 |
is necessary.) |
|
99 |
||
100 |
*/ |
|
101 |
||
102 |
// |
|
103 |
// === Global and Local Variables ================================================================== |
|
104 |
// |
|
105 |
||
106 |
GLDEF_D DUsbClientController* DUsbClientController::UsbClientController[] = {NULL, NULL}; |
|
107 |
||
108 |
static const TInt KUsbReconnectDelay = 500; // milliseconds |
|
109 |
static const TInt KUsbCableStatusDelay = 500; // milliseconds |
|
110 |
||
111 |
||
112 |
// |
|
113 |
// === USB Controller member function implementations - LDD API (public) =========================== |
|
114 |
// |
|
115 |
||
116 |
||
117 |
/** The class destructor. |
|
118 |
||
119 |
This rarely gets called, except, for example when something goes |
|
120 |
wrong during construction. |
|
121 |
||
122 |
It's not exported because it is virtual. |
|
123 |
*/ |
|
124 |
DUsbClientController::~DUsbClientController() |
|
125 |
{ |
|
253 | 126 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_DES, "DUsbClientController::~DUsbClientController()" ); |
127 |
||
0 | 128 |
if (iPowerHandler) |
129 |
{ |
|
130 |
iPowerHandler->Remove(); |
|
131 |
delete iPowerHandler; |
|
132 |
} |
|
133 |
// ResetAndDestroy() will call for every array element the destructor of the pointed-to object, |
|
134 |
// before deleting the element itself, and closing the array. |
|
135 |
iConfigs.ResetAndDestroy(); |
|
253 | 136 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_DES_DUP1, "DUsbClientController::~DUsbClientController(): Done." ); |
0 | 137 |
} |
138 |
||
139 |
||
140 |
/** To be called by the OTG/Host stack in an OTG setup to disable USB device |
|
141 |
functionality. |
|
142 |
||
143 |
The OTG stack calls this function when VBus is no longer valid, when the |
|
144 |
B-device swaps out of peripheral mode, or when moving out of the |
|
145 |
A_PERIPHERAL state. |
|
146 |
||
147 |
The Client stack will disable the D+ pull-up immediately when the function |
|
148 |
is called. |
|
149 |
||
150 |
During DisableClientStack() the Client stack will notify its registered |
|
151 |
applications on the user-side (including the USB Manager) about a USB |
|
152 |
device state change event, a transition to the "Undefined" state. |
|
153 |
*/ |
|
154 |
EXPORT_C void DUsbClientController::DisableClientStack() |
|
155 |
{ |
|
253 | 156 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK, "DUsbClientController::DisableClientStack()" ); |
0 | 157 |
if (!iStackIsActive) |
158 |
{ |
|
253 | 159 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK_DUP1, " Already disabled - returning" ); |
0 | 160 |
return; |
161 |
} |
|
162 |
iOtgClientConnect = EFalse; |
|
163 |
TInt r = EvaluateOtgConnectFlags(); // will disconnect UDC |
|
164 |
if (r != KErrNone) |
|
165 |
{ |
|
253 | 166 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK_DUP2, " Error: EvaluateOtgConnectFlags() failed: %d", r ); |
0 | 167 |
} |
168 |
||
169 |
// Reset OTG features, leave attributes as is (just as in USB Reset case) |
|
170 |
// (OTG spec 1.3 sections 6.5.x all say "... on a bus reset or at the end |
|
171 |
// of a session." VBus drop is the end of a session.) |
|
172 |
iOtgFuncMap &= KUsbOtgAttr_SrpSupp | KUsbOtgAttr_HnpSupp; |
|
173 |
OtgFeaturesNotify(); |
|
174 |
// Tear down the current configuration (if any) |
|
175 |
ChangeConfiguration(0); |
|
176 |
||
177 |
if (iDeviceState != EUsbcDeviceStateUndefined) |
|
178 |
{ |
|
179 |
// Not being in state UNDEFINED implies that the cable is inserted. |
|
180 |
if (iHardwareActivated) |
|
181 |
{ |
|
182 |
NextDeviceState(EUsbcDeviceStatePowered); |
|
183 |
} |
|
184 |
// (If the hardware is NOT activated at this point, we can only be in |
|
185 |
// state EUsbcDeviceStateAttached, so we don't have to move to it.) |
|
186 |
} |
|
187 |
DeActivateHardwareController(); // turn off UDC altogether |
|
188 |
iStackIsActive = EFalse; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
// Notify registered clients on the user side about a USB device state |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
// change event and a transition to the "Undefined" state. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
// Note: the state should be changed to "Undefined" before calling RunClientCallbacks(), |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
// otherwise the "Undefined" state will probably be lost. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
NextDeviceState(EUsbcDeviceStateUndefined); |
0 | 194 |
// Complete all pending requests, returning KErrDisconnected |
195 |
RunClientCallbacks(); |
|
196 |
} |
|
197 |
||
198 |
||
199 |
/** To be called by the OTG/Host stack in an OTG setup to enable USB device |
|
200 |
functionality. |
|
201 |
||
202 |
Once called, the function will return quickly, but it will by then not |
|
203 |
necessarily have enabled the D+ pull-up*. The Client stack can enable the D+ |
|
204 |
pull-up (via the transceiver) from that moment on and as long as the OTG |
|
205 |
stack doesn't call DisableClientStack(). |
|
206 |
||
207 |
*) It will enable the D+ pull-up immediately if the user-side USB support |
|
208 |
has already been loaded. This should always be the case when the OTG stack |
|
209 |
is calling this function during the transition to the A_PERIPHERAL state, |
|
210 |
i.e. when acting as an A-device. |
|
211 |
*/ |
|
212 |
EXPORT_C void DUsbClientController::EnableClientStack() |
|
213 |
{ |
|
253 | 214 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK, "DUsbClientController::EnableClientStack()" ); |
0 | 215 |
if (iStackIsActive) |
216 |
{ |
|
253 | 217 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP1, " Already enabled - returning" ); |
0 | 218 |
return; |
219 |
} |
|
220 |
iStackIsActive = ETrue; |
|
221 |
// If the UDC is still off, we switch it on here. |
|
222 |
TInt r = ActivateHardwareController(); |
|
223 |
if (r != KErrNone) |
|
224 |
{ |
|
253 | 225 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP2, " Error: ActivateHardwareController() failed: %d", r); |
0 | 226 |
} |
227 |
iOtgClientConnect = ETrue; |
|
228 |
r = EvaluateOtgConnectFlags(); // may connect UDC |
|
229 |
if (r != KErrNone) |
|
230 |
{ |
|
253 | 231 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP3, " Error: EvaluateOtgConnectFlags() failed: %d", r); |
0 | 232 |
} |
233 |
} |
|
234 |
||
235 |
||
236 |
/** Called by LDD to see if controller is usable. |
|
237 |
||
238 |
@return ETrue if controller is in normal state, EFalse if it is disabled. |
|
239 |
*/ |
|
240 |
EXPORT_C TBool DUsbClientController::IsActive() |
|
241 |
{ |
|
253 | 242 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ISACTIVE, "DUsbClientController::IsActive()" ); |
0 | 243 |
return iStackIsActive; |
244 |
} |
|
245 |
||
246 |
||
247 |
/** Called by LDD to register client callbacks. |
|
248 |
||
249 |
@return KErrNone if successful, KErrAlreadyExists callback exists. |
|
250 |
*/ |
|
251 |
EXPORT_C TInt DUsbClientController::RegisterClientCallback(TUsbcClientCallback& aCallback) |
|
252 |
{ |
|
253 | 253 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK, "DUsbClientController::RegisterClientCallback()" ); |
0 | 254 |
if (iClientCallbacks.Elements() == KUsbcMaxListLength) |
255 |
{ |
|
253 | 256 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP1, " Error: Maximum list length reached: %d", |
257 |
KUsbcMaxListLength); |
|
258 |
||
0 | 259 |
return KErrGeneral; |
260 |
} |
|
261 |
TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
|
262 |
TUsbcClientCallback* p; |
|
263 |
while ((p = iter++) != NULL) |
|
264 |
if (p == &aCallback) |
|
265 |
{ |
|
253 | 266 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP2, " Error: ClientCallback @ 0x%x already registered", &aCallback); |
0 | 267 |
return KErrAlreadyExists; |
268 |
} |
|
269 |
iClientCallbacks.AddLast(aCallback); |
|
270 |
return KErrNone; |
|
271 |
} |
|
272 |
||
273 |
||
274 |
/** Returns a pointer to the USB client controller object. |
|
275 |
||
276 |
This function is static. |
|
277 |
||
278 |
@param aUdc The number of the UDC (0..n) for which the pointer is to be returned. |
|
279 |
||
280 |
@return A pointer to the USB client controller object. |
|
281 |
*/ |
|
282 |
EXPORT_C DUsbClientController* DUsbClientController::UsbcControllerPointer(TInt aUdc) |
|
283 |
{ |
|
253 | 284 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBCCONTROLLERPOINTER, "DUsbClientController::UsbcControllerPointer()" ); |
0 | 285 |
if (aUdc < 0 || aUdc > 1) |
286 |
{ |
|
253 | 287 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_USBCCONTROLLERPOINTER_DUP1, " Error: aUdc out of range (%d)", aUdc); |
0 | 288 |
return NULL; |
289 |
} |
|
290 |
return UsbClientController[aUdc]; |
|
291 |
} |
|
292 |
||
293 |
||
294 |
/** Fills the buffer passed in as an argument with endpoint capability information. |
|
295 |
||
296 |
@see DUsbClientController::DeviceCaps() |
|
297 |
@see TUsbcEndpointData |
|
298 |
@see TUsbDeviceCaps |
|
299 |
||
300 |
@param aClientId A pointer to the LDD making the enquiry. |
|
301 |
@param aCapsBuf A reference to a descriptor buffer, which, on return, contains an array of |
|
302 |
TUsbcEndpointData elements; there are TUsbDeviceCaps::iTotalEndpoints elements in the array; |
|
303 |
call DeviceCaps() to get the number of elements required. |
|
304 |
*/ |
|
305 |
EXPORT_C void DUsbClientController::EndpointCaps(const DBase* aClientId, TDes8& aCapsBuf) const |
|
306 |
{ |
|
253 | 307 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENDPOINTCAPS, "DUsbClientController::EndpointCaps()" ); |
0 | 308 |
// Here we do not simply call DUsbClientController::DeviceEndpointCaps(), |
309 |
// because that function fills an array which comprises of _all_ endpoints, |
|
310 |
// whereas this function omits ep0 and all unusable endpoints. |
|
311 |
// Apart from that, we have to fill an array of TUsbcEndpointData, not TUsbcEndpointCaps. |
|
312 |
TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
313 |
const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
|
314 |
for (TInt i = 2, j = 0; i < iDeviceTotalEndpoints; ++i) |
|
315 |
{ |
|
253 | 316 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP1, "DUsbClientController::Caps: RealEndpoint #%d", i); |
0 | 317 |
if (iRealEndpoints[i].iCaps.iTypesAndDir != KUsbEpNotAvailable) |
318 |
{ |
|
253 | 319 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP2, "DUsbClientController::Caps: --> UsableEndpoint #%d", j); |
0 | 320 |
data[j].iCaps = iRealEndpoints[i].iCaps; |
321 |
if (ifcset_num < 0) |
|
322 |
{ |
|
323 |
// If this LDD doesn't own an interface, but the Ep points to one, |
|
324 |
// then that must be the interface of a different LDD. Hence the Ep |
|
325 |
// is not available for this LDD. |
|
326 |
data[j].iInUse = (iRealEndpoints[i].iIfcNumber != NULL); |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
// If this LDD does already own an interface, and the Ep also points to one, |
|
331 |
// then the Ep is not available for this LDD only if that interface is owned |
|
332 |
// by a different LDD (i.e. if the interface number is different). |
|
333 |
// Reason: Even though the endpoint might already be part of an interface setting, |
|
334 |
// it is still available for a different alternate setting of the same interface. |
|
335 |
data[j].iInUse = ((iRealEndpoints[i].iIfcNumber != NULL) && |
|
336 |
(*(iRealEndpoints[i].iIfcNumber) != ifcset_num)); |
|
337 |
} |
|
338 |
j++; |
|
339 |
} |
|
340 |
} |
|
341 |
// aCapsBuf resides in userland |
|
342 |
TPtrC8 des((TUint8*)data, sizeof(data)); |
|
343 |
const TInt r = Kern::ThreadDesWrite((reinterpret_cast<const DLddUsbcChannel*>(aClientId))->Client(), |
|
344 |
&aCapsBuf, des, 0, KChunkShiftBy0, NULL); |
|
345 |
if (r != KErrNone) |
|
346 |
{ |
|
347 |
Kern::ThreadKill((reinterpret_cast<const DLddUsbcChannel*>(aClientId))->Client(), |
|
348 |
EExitPanic, r, KUsbPILKillCat); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
||
353 |
/** Fills the buffer passed in as an argument with device capability information. |
|
354 |
||
355 |
@see TUsbDeviceCaps |
|
356 |
@see TUsbDeviceCapsV01 |
|
357 |
||
358 |
@param aClientId A pointer to the LDD making the enquiry. |
|
359 |
@param aCapsBuf A reference to a descriptor buffer which, on return, contains |
|
360 |
a TUsbDeviceCaps structure. |
|
361 |
*/ |
|
362 |
EXPORT_C void DUsbClientController::DeviceCaps(const DBase* aClientId, TDes8& aCapsBuf) const |
|
363 |
{ |
|
253 | 364 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICECAPS, "DUsbClientController::DeviceCaps()" ); |
0 | 365 |
TUsbDeviceCaps caps; |
366 |
caps().iTotalEndpoints = iDeviceUsableEndpoints; // not DeviceTotalEndpoints()! |
|
367 |
caps().iConnect = SoftConnectCaps(); |
|
368 |
caps().iSelfPowered = iSelfPowered; |
|
369 |
caps().iRemoteWakeup = iRemoteWakeup; |
|
370 |
caps().iHighSpeed = DeviceHighSpeedCaps(); |
|
371 |
caps().iFeatureWord1 = CableDetectWithoutPowerCaps() ? |
|
372 |
caps().iFeatureWord1 | KUsbDevCapsFeatureWord1_CableDetectWithoutPower : |
|
373 |
caps().iFeatureWord1 & ~KUsbDevCapsFeatureWord1_CableDetectWithoutPower; |
|
374 |
caps().iFeatureWord1 = DeviceResourceAllocV2Caps() ? |
|
375 |
caps().iFeatureWord1 | KUsbDevCapsFeatureWord1_EndpointResourceAllocV2 : |
|
376 |
caps().iFeatureWord1 & ~KUsbDevCapsFeatureWord1_EndpointResourceAllocV2; |
|
377 |
caps().iReserved = 0; |
|
378 |
||
379 |
// aCapsBuf resides in userland |
|
380 |
const TInt r = Kern::ThreadDesWrite((reinterpret_cast<const DLddUsbcChannel*>(aClientId))->Client(), |
|
381 |
&aCapsBuf, caps, 0, KChunkShiftBy0, NULL); |
|
382 |
if (r != KErrNone) |
|
383 |
{ |
|
384 |
Kern::ThreadKill((reinterpret_cast<const DLddUsbcChannel*>(aClientId))->Client(), |
|
385 |
EExitPanic, r, KUsbPILKillCat); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
||
390 |
TUsbcEndpointInfoArray::TUsbcEndpointInfoArray(const TUsbcEndpointInfo* aData, TInt aDataSize) |
|
391 |
{ |
|
392 |
iType = EUsbcEndpointInfo; |
|
393 |
iData = (TUint8*) aData; |
|
394 |
if (aDataSize > 0) |
|
395 |
iDataSize = aDataSize; |
|
396 |
else |
|
397 |
iDataSize = sizeof(TUsbcEndpointInfo); |
|
398 |
} |
|
399 |
||
400 |
||
401 |
inline TUsbcEndpointInfo& TUsbcEndpointInfoArray::operator[](TInt aIndex) const |
|
402 |
{ |
|
403 |
return *(TUsbcEndpointInfo*) &iData[aIndex * iDataSize]; |
|
404 |
} |
|
405 |
||
406 |
||
407 |
EXPORT_C TInt DUsbClientController::SetInterface(const DBase* aClientId, DThread* aThread, |
|
408 |
TInt aInterfaceNum, TUsbcClassInfo& aClass, |
|
409 |
TDesC8* aString, TInt aTotalEndpointsUsed, |
|
410 |
const TUsbcEndpointInfo aEndpointData[], |
|
411 |
TInt (*aRealEpNumbers)[6], TUint32 aFeatureWord) |
|
412 |
{ |
|
413 |
TUsbcEndpointInfoArray endpointData = TUsbcEndpointInfoArray(aEndpointData); |
|
414 |
return SetInterface(aClientId, aThread, aInterfaceNum, aClass, aString, aTotalEndpointsUsed, |
|
415 |
endpointData, (TInt*) aRealEpNumbers, aFeatureWord); |
|
416 |
} |
|
417 |
||
418 |
||
419 |
/** Creates a new USB interface (one setting), complete with endpoints, descriptors, etc., |
|
420 |
and chains it into the internal device configuration tree. |
|
421 |
||
422 |
@param aClientId A pointer to the LDD owning the new interface. |
|
423 |
@param aThread A pointer to the thread the owning LDD is running in. |
|
424 |
@param aInterfaceNum The interface setting number of the new interface setting. This must be 0 |
|
425 |
if it is the first setting of the interface that gets created, or 1 more than the last setting |
|
426 |
that was created for this interface. |
|
427 |
@param aClass Contains information about the device class this interface might belong to. |
|
428 |
@param aString A pointer to a string that is used for the string descriptor of this interface. |
|
429 |
@param aTotalEndpointsUsed The number of endpoints used by this interface (and also the number of |
|
430 |
elements of the following array). |
|
431 |
@param aEndpointData An array with aTotalEndpointsUsed elements, containing information about the |
|
432 |
endpoints of this interface. |
|
433 |
||
434 |
@return KErrNotSupported if Control endpoints are requested by the LDD but aren't supported by the PIL, |
|
435 |
KErrInUse if at least one requested endpoint is - temporarily or permanently - not available for use, |
|
436 |
KErrNoMemory if (endpoint, interface, string) descriptor allocation fails, KErrGeneral if something else |
|
437 |
goes wrong during endpoint or interface or descriptor creation, KErrNone if interface successfully set up. |
|
438 |
*/ |
|
439 |
EXPORT_C TInt DUsbClientController::SetInterface(const DBase* aClientId, DThread* aThread, |
|
440 |
TInt aInterfaceNum, TUsbcClassInfo& aClass, |
|
441 |
TDesC8* aString, TInt aTotalEndpointsUsed, |
|
442 |
const TUsbcEndpointInfoArray aEndpointData, |
|
443 |
TInt aRealEpNumbers[], TUint32 aFeatureWord) |
|
444 |
{ |
|
253 | 445 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETINTERFACE, "DUsbClientController::SetInterface()" ); |
0 | 446 |
if (aInterfaceNum != 0) |
447 |
{ |
|
253 | 448 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP1, " alternate interface setting request: #%d", aInterfaceNum); |
449 |
||
0 | 450 |
} |
451 |
#ifndef USB_SUPPORTS_CONTROLENDPOINTS |
|
452 |
for (TInt i = 0; i < aTotalEndpointsUsed; ++i) |
|
453 |
{ |
|
454 |
if (aEndpointData[i].iType == KUsbEpTypeControl) |
|
455 |
{ |
|
253 | 456 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP2, " Error: control endpoints not supported"); |
0 | 457 |
return KErrNotSupported; |
458 |
} |
|
459 |
} |
|
460 |
#endif |
|
461 |
// Check for endpoint availability & check those endpoint's capabilities |
|
462 |
const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
|
463 |
// The passed-in ifcset_num may be -1 now, but that's intended. |
|
464 |
if (!CheckEpAvailability(aTotalEndpointsUsed, aEndpointData, ifcset_num)) |
|
465 |
{ |
|
253 | 466 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP3, " Error: endpoints not (all) available"); |
0 | 467 |
return KErrInUse; |
468 |
} |
|
469 |
// Create & setup new interface |
|
470 |
TUsbcInterface* ifc = CreateInterface(aClientId, aInterfaceNum, aFeatureWord); |
|
471 |
if (ifc == NULL) |
|
472 |
{ |
|
253 | 473 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP4, " Error: ifc == NULL"); |
0 | 474 |
return KErrGeneral; |
475 |
} |
|
476 |
// Create logical endpoints |
|
477 |
TInt r = CreateEndpoints(ifc, aTotalEndpointsUsed, aEndpointData, aRealEpNumbers); |
|
478 |
if (r != KErrNone) |
|
479 |
{ |
|
253 | 480 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP5, " Error: CreateEndpoints() != KErrNone"); |
0 | 481 |
DeleteInterface(ifc->iInterfaceSet->iInterfaceNumber, aInterfaceNum); |
482 |
return r; |
|
483 |
} |
|
484 |
// Create & setup interface, string, and endpoint descriptors |
|
485 |
r = SetupIfcDescriptor(ifc, aClass, aThread, aString, aEndpointData); |
|
486 |
if (r != KErrNone) |
|
487 |
{ |
|
488 |
return r; |
|
489 |
} |
|
490 |
return KErrNone; |
|
491 |
} |
|
492 |
||
493 |
||
494 |
/** Releases an existing USB interface (one setting), complete with endpoints, descriptors, etc., |
|
495 |
and removes it from the internal device configuration tree. |
|
496 |
||
497 |
@param aClientId A pointer to the LDD owning the interface. |
|
498 |
@param aInterfaceNum The setting number of the interface setting to be deleted. This must be |
|
499 |
the highest numbered (or 'last') setting for this interface. |
|
500 |
||
501 |
@return KErrNotFound if interface (not setting) for some reason cannot be found, KErrArgument if an |
|
502 |
invalid interface setting number is specified (not existing or existing but too small), KErrNone if |
|
503 |
interface successfully released or if this client doesn't own any interface. |
|
504 |
*/ |
|
505 |
EXPORT_C TInt DUsbClientController::ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum) |
|
506 |
{ |
|
253 | 507 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE, "DUsbClientController::ReleaseInterface(..., %d)", aInterfaceNum); |
508 |
||
0 | 509 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
510 |
if (ifcset < 0) |
|
511 |
{ |
|
253 | 512 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP1, " interface not found"); |
0 | 513 |
return KErrNone; |
514 |
} |
|
515 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
|
516 |
if (!ifcset_ptr) |
|
517 |
{ |
|
253 | 518 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP2, "Error: interface number %d doesn't exist", ifcset); |
0 | 519 |
return KErrNotFound; |
520 |
} |
|
521 |
const TInt setting_count = ifcset_ptr->iInterfaces.Count(); |
|
522 |
if ((setting_count - 1) != aInterfaceNum) |
|
523 |
{ |
|
253 | 524 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP3, "> Error: interface settings must be released in descending order:\n\r" |
525 |
" %d setting(s) exist, #%d was requested to be released.\n\r" |
|
526 |
" (#%d has to be released first)", |
|
527 |
setting_count, aInterfaceNum, setting_count - 1); |
|
0 | 528 |
return KErrArgument; |
529 |
} |
|
530 |
// Tear down current setting (invalidate configured state) |
|
253 | 531 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP4, " > tearing down InterfaceSet %d", ifcset); |
0 | 532 |
// Cancel all transfers on the current setting of this interface and deconfigure all its endpoints. |
533 |
InterfaceSetTeardown(ifcset_ptr); |
|
534 |
// 'Setting 0' means: delete all existing settings. |
|
535 |
if (aInterfaceNum == 0) |
|
536 |
{ |
|
537 |
TInt m = ifcset_ptr->iInterfaces.Count(); |
|
538 |
while (m > 0) |
|
539 |
{ |
|
540 |
m--; |
|
541 |
// Ground the physical endpoints' logical_endpoint_pointers |
|
542 |
const TInt n = ifcset_ptr->iInterfaces[m]->iEndpoints.Count(); |
|
543 |
for (TInt i = 0; i < n; ++i) |
|
544 |
{ |
|
545 |
TUsbcPhysicalEndpoint* ptr = const_cast<TUsbcPhysicalEndpoint*> |
|
546 |
(ifcset_ptr->iInterfaces[m]->iEndpoints[i]->iPEndpoint); |
|
547 |
ptr->iLEndpoint = NULL; |
|
548 |
} |
|
549 |
// Delete the setting itself + its ifc & ep descriptors |
|
550 |
DeleteInterface(ifcset, m); |
|
551 |
iDescriptors.DeleteIfcDescriptor(ifcset, m); |
|
552 |
} |
|
553 |
} |
|
554 |
else |
|
555 |
{ |
|
556 |
// Ground the physical endpoints' logical_endpoint_pointers |
|
557 |
const TInt n = ifcset_ptr->iInterfaces[aInterfaceNum]->iEndpoints.Count(); |
|
558 |
for (TInt i = 0; i < n; ++i) |
|
559 |
{ |
|
560 |
TUsbcPhysicalEndpoint* ptr = const_cast<TUsbcPhysicalEndpoint*> |
|
561 |
(ifcset_ptr->iInterfaces[aInterfaceNum]->iEndpoints[i]->iPEndpoint); |
|
562 |
ptr->iLEndpoint = NULL; |
|
563 |
} |
|
564 |
// Delete the setting itself + its ifc & ep descriptors |
|
565 |
DeleteInterface(ifcset, aInterfaceNum); |
|
566 |
iDescriptors.DeleteIfcDescriptor(ifcset, aInterfaceNum); |
|
567 |
} |
|
568 |
// Delete the whole interface if all settings are gone |
|
569 |
if (ifcset_ptr->iInterfaces.Count() == 0) |
|
570 |
{ |
|
571 |
DeleteInterfaceSet(ifcset); |
|
572 |
} |
|
573 |
// We now no longer have a valid current configuration |
|
574 |
iCurrentConfig = 0; |
|
575 |
if (iDeviceState == EUsbcDeviceStateConfigured) |
|
576 |
{ |
|
577 |
NextDeviceState(EUsbcDeviceStateAddress); |
|
578 |
} |
|
579 |
// If it was the last interface(set)... |
|
580 |
if (iConfigs[0]->iInterfaceSets.Count() == 0) |
|
581 |
{ |
|
253 | 582 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP5, " No ifc left -> turning off UDC"); |
0 | 583 |
// First disconnect the device from the bus |
584 |
UsbDisconnect(); |
|
585 |
DeActivateHardwareController(); |
|
586 |
// (this also disables endpoint zero; we cannot have a USB device w/o interface, see 9.6.3) |
|
587 |
} |
|
588 |
return KErrNone; |
|
589 |
} |
|
590 |
||
591 |
||
592 |
/** Enforces a USB re-enumeration by disconnecting the UDC from the bus (if it is currently connected) and |
|
593 |
re-connecting it. |
|
594 |
||
595 |
This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue. |
|
596 |
*/ |
|
597 |
EXPORT_C TInt DUsbClientController::ReEnumerate() |
|
598 |
{ |
|
253 | 599 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REENUMERATE, "DUsbClientController::ReEnumerate()" ); |
0 | 600 |
// If, in an OTG setup, the client stack is disabled, there's no point in |
601 |
// trying to reenumerate the device. In fact, we then don't even want to |
|
602 |
// turn on the UDC via ActivateHardwareController(). |
|
603 |
if (!iStackIsActive) |
|
604 |
{ |
|
253 | 605 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP1, " Client stack disabled -> returning here" ); |
0 | 606 |
return KErrNotReady; |
607 |
} |
|
608 |
// We probably don't check here whether SoftConnectCaps() is ETrue, and |
|
609 |
// return if not, because we might still want to execute |
|
610 |
// ActivateHardwareController(). UsbConnect() and UsbDisconnect() should be |
|
611 |
// no-ops if not supported by the PSL. |
|
612 |
if (iConfigs[0]->iInterfaceSets.Count() == 0) |
|
613 |
{ |
|
253 | 614 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP2, " > No interface registered -> no need to re-enumerate" ); |
0 | 615 |
return KErrNone;; |
616 |
} |
|
617 |
if (!iHardwareActivated) |
|
618 |
{ |
|
619 |
// If the UDC is still off, we switch it on here. |
|
620 |
const TInt r = ActivateHardwareController(); |
|
621 |
if (r != KErrNone) |
|
622 |
{ |
|
253 | 623 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP3, " Error: ActivateHardwareController() failed: %d", r); |
0 | 624 |
return r; |
625 |
} |
|
626 |
// Finally connect the device to the bus |
|
627 |
UsbConnect(); |
|
628 |
} |
|
629 |
else |
|
630 |
{ |
|
631 |
UsbDisconnect(); |
|
632 |
// Now we have to wait a certain amount of time, in order to give the host the opportunity |
|
633 |
// to come to terms with the new situation. |
|
634 |
// (The ETrue parameter makes the callback get called in DFC instead of in ISR context.) |
|
635 |
iReconnectTimer.OneShot(KUsbReconnectDelay, ETrue); |
|
636 |
} |
|
637 |
return KErrNone;; |
|
638 |
} |
|
639 |
||
640 |
||
641 |
/** Powers up the UDC if one or more interfaces exist. |
|
642 |
||
643 |
@return KErrNone if UDC successfully powered up, KErrNotReady if no |
|
644 |
interfaces have been registered yet, KErrHardwareNotAvailable if UDC |
|
645 |
couldn't be activated. |
|
646 |
*/ |
|
647 |
EXPORT_C TInt DUsbClientController::PowerUpUdc() |
|
648 |
{ |
|
253 | 649 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUPUDC, "DUsbClientController::PowerUpUdc()" ); |
0 | 650 |
// If, in an OTG setup, the client stack is disabled, we mustn't turn on |
651 |
// the UDC via ActivateHardwareController() as that would already configure |
|
652 |
// Ep0. |
|
653 |
if (!iStackIsActive) |
|
654 |
{ |
|
253 | 655 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP1, " Client stack disabled -> returning here" ); |
0 | 656 |
return KErrNotReady; |
657 |
} |
|
658 |
if (iConfigs[0]->iInterfaceSets.Count() == 0) |
|
659 |
{ |
|
253 | 660 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP2, " > No interface registered -> won't power up UDC" ); |
0 | 661 |
return KErrNotReady; |
662 |
} |
|
663 |
// If the UDC is still off, we switch it on here. |
|
664 |
const TInt r = ActivateHardwareController(); |
|
665 |
if (r != KErrNone) |
|
666 |
{ |
|
253 | 667 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP3, " Error: ActivateHardwareController() failed: %d", r); |
0 | 668 |
} |
669 |
return r; |
|
670 |
} |
|
671 |
||
672 |
||
673 |
/** Connects the UDC to the bus. |
|
674 |
||
675 |
This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue. |
|
676 |
||
677 |
@return KErrNone if UDC successfully connected, KErrGeneral if there was an error. |
|
678 |
*/ |
|
679 |
EXPORT_C TInt DUsbClientController::UsbConnect() |
|
680 |
{ |
|
253 | 681 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBCONNECT, "DUsbClientController::UsbConnect()" ); |
0 | 682 |
#ifdef USB_OTG_CLIENT |
683 |
iClientSupportReady = ETrue; |
|
684 |
const TInt r = EvaluateOtgConnectFlags(); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 686 |
if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue) |
687 |
{ |
|
253 | 688 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_USBCONNECT_DUP1, " Resetting USB Reset 'defer' flag" ); |
0 | 689 |
iUsbResetDeferred = EFalse; |
690 |
(void) ProcessResetEvent(EFalse); |
|
691 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
692 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 693 |
#else |
694 |
const TInt r = UdcConnect(); |
|
695 |
#endif // USB_OTG_CLIENT |
|
696 |
return r; |
|
697 |
} |
|
698 |
||
699 |
||
700 |
/** Disconnects the UDC from the bus. |
|
701 |
||
702 |
This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue. |
|
703 |
||
704 |
@return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error. |
|
705 |
*/ |
|
706 |
EXPORT_C TInt DUsbClientController::UsbDisconnect() |
|
707 |
{ |
|
253 | 708 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBDISCONNECT, "DUsbClientController::UsbDisconnect()" ); |
0 | 709 |
#ifdef USB_OTG_CLIENT |
710 |
iClientSupportReady = EFalse; |
|
711 |
const TInt r = EvaluateOtgConnectFlags(); |
|
712 |
#else |
|
713 |
const TInt r = UdcDisconnect(); |
|
714 |
#endif // USB_OTG_CLIENT |
|
715 |
// There won't be any notification by the PSL about this, |
|
716 |
// so we have to notify the LDD/user ourselves: |
|
717 |
if ((r == KErrNone) && (iDeviceState != EUsbcDeviceStateUndefined)) |
|
718 |
{ |
|
719 |
// Not being in state UNDEFINED implies that the cable is inserted. |
|
720 |
if (iHardwareActivated) |
|
721 |
{ |
|
722 |
NextDeviceState(EUsbcDeviceStatePowered); |
|
723 |
} |
|
724 |
// (If the hardware is NOT activated at this point, we can only be in |
|
725 |
// state EUsbcDeviceStateAttached, so we don't have to move to it.) |
|
726 |
} |
|
727 |
return r; |
|
728 |
} |
|
729 |
||
730 |
||
731 |
/** Registers a notification callback for changes of the USB device state. |
|
732 |
||
733 |
In the event of a device state change, the callback's state member gets updated (using SetState) with a |
|
734 |
new TUsbcDeviceState value, and then the callback is executed (DoCallback). 'USB device state' here refers |
|
735 |
to the Visible Device States as defined in chapter 9 of the USB specification. |
|
736 |
||
737 |
@param aCallback A reference to a properly filled in status callback structure. |
|
738 |
||
739 |
@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered |
|
740 |
(it won't be registered twice). |
|
741 |
*/ |
|
742 |
EXPORT_C TInt DUsbClientController::RegisterForStatusChange(TUsbcStatusCallback& aCallback) |
|
743 |
{ |
|
253 | 744 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE, "DUsbClientController::RegisterForStatusChange()" ); |
0 | 745 |
if (iStatusCallbacks.Elements() == KUsbcMaxListLength) |
746 |
{ |
|
253 | 747 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE_DUP1, " Error: Maximum list length reached: %d", |
748 |
KUsbcMaxListLength); |
|
0 | 749 |
return KErrGeneral; |
750 |
} |
|
751 |
if (IsInTheStatusList(aCallback)) |
|
752 |
{ |
|
253 | 753 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE_DUP2, " Error: StatusCallback @ 0x%x already registered", &aCallback); |
0 | 754 |
return KErrGeneral; |
755 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 757 |
iStatusCallbacks.AddLast(aCallback); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 759 |
return KErrNone; |
760 |
} |
|
761 |
||
762 |
||
763 |
/** De-registers (removes from the list of pending requests) a notification callback for the USB device |
|
764 |
status. |
|
765 |
||
766 |
@param aClientId A pointer to the LDD owning the status change callback. |
|
767 |
||
768 |
@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
|
769 |
*/ |
|
770 |
EXPORT_C TInt DUsbClientController::DeRegisterForStatusChange(const DBase* aClientId) |
|
771 |
{ |
|
253 | 772 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE, "DUsbClientController::DeRegisterForStatusChange()" ); |
0 | 773 |
__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 775 |
TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks); |
776 |
TUsbcStatusCallback* p; |
|
777 |
while ((p = iter++) != NULL) |
|
778 |
{ |
|
779 |
if (p->Owner() == aClientId) |
|
780 |
{ |
|
253 | 781 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP1, " removing StatusCallback @ 0x%x", p); |
0 | 782 |
iStatusCallbacks.Remove(*p); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 784 |
return KErrNone; |
785 |
} |
|
786 |
} |
|
253 | 787 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP2, " client not found"); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 789 |
return KErrNotFound; |
790 |
} |
|
791 |
||
792 |
||
793 |
/** Registers a notification callback for changes of the state of endpoints. |
|
794 |
||
795 |
In the event of a state change of an endpoint that is spart of an interface which is owned by the LDD |
|
796 |
specified in the callback structure, the callback's state member gets updated (using SetState) with a new |
|
797 |
value, and the callback is executed (DoCallback). 'Endpoint state' here refers to the state of the |
|
798 |
ENDPOINT_HALT feature of an endpoint as described in chapter 9 of the USB specification. The contents of |
|
799 |
the state variable reflects the state of the halt features for all endpoints of the current interface |
|
800 |
setting: bit 0 represents endpoint 1, bit 1 endpoint 2, etc. A set bit means 'endpoint halted', a cleared |
|
801 |
bit 'endpoint not halted'. |
|
802 |
||
803 |
@param aCallback A reference to a properly filled in endpoint status callback structure. |
|
804 |
||
805 |
@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered |
|
806 |
(it won't be registered twice). |
|
807 |
*/ |
|
808 |
EXPORT_C TInt DUsbClientController::RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback) |
|
809 |
{ |
|
253 | 810 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::RegisterForEndpointStatusChange()" ); |
0 | 811 |
if (iEpStatusCallbacks.Elements() == KUsbcMaxListLength) |
812 |
{ |
|
253 | 813 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP1, " Error: Maximum list length reached: %d", |
814 |
KUsbcMaxListLength); |
|
815 |
||
0 | 816 |
return KErrGeneral; |
817 |
} |
|
818 |
if (IsInTheEpStatusList(aCallback)) |
|
819 |
{ |
|
253 | 820 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP2, " Error: EpStatusCallback @ 0x%x already registered", &aCallback); |
0 | 821 |
return KErrGeneral; |
822 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
823 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 824 |
iEpStatusCallbacks.AddLast(aCallback); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 826 |
return KErrNone; |
827 |
} |
|
828 |
||
829 |
||
830 |
/** De-registers (removes from the list of pending requests) a notification callback for changes of the state |
|
831 |
of endpoints. |
|
832 |
||
833 |
@param aClientId A pointer to the LDD owning the endpoint status change callback. |
|
834 |
||
835 |
@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
|
836 |
*/ |
|
837 |
EXPORT_C TInt DUsbClientController::DeRegisterForEndpointStatusChange(const DBase* aClientId) |
|
838 |
{ |
|
253 | 839 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::DeRegisterForEndpointStatusChange()" ); |
0 | 840 |
__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 842 |
TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
843 |
TUsbcEndpointStatusCallback* p; |
|
844 |
while ((p = iter++) != NULL) |
|
845 |
{ |
|
846 |
if (p->Owner() == aClientId) |
|
847 |
{ |
|
253 | 848 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP1, " removing EpStatusCallback @ 0x%x", p); |
0 | 849 |
iEpStatusCallbacks.Remove(*p); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
850 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 851 |
return KErrNone; |
852 |
} |
|
853 |
} |
|
253 | 854 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP2, " client not found"); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
855 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 856 |
return KErrNotFound; |
857 |
} |
|
858 |
||
859 |
||
860 |
/** Returns the number of the currently active alternate interface setting for this interface. |
|
861 |
||
862 |
@param aClientId A pointer to the LDD owning the interface. |
|
863 |
@param aInterfaceNum Here the interface gets written to. |
|
864 |
||
865 |
@return KErrNotFound if an interface for this client couldn't be found, KErrNone if setting value was |
|
866 |
successfully written. |
|
867 |
*/ |
|
868 |
EXPORT_C TInt DUsbClientController::GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const |
|
869 |
{ |
|
253 | 870 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER, "DUsbClientController::GetInterfaceNumber()" ); |
871 |
||
0 | 872 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
873 |
if (ifcset < 0) |
|
874 |
{ |
|
253 | 875 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER_DUP1, " Error (ifc < 0)"); |
0 | 876 |
return KErrNotFound; |
877 |
} |
|
878 |
const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
|
879 |
if (!ifcset_ptr) |
|
880 |
{ |
|
253 | 881 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER_DUP2, " Error: interface number %d doesn't exist", ifcset); |
0 | 882 |
return KErrNotFound; |
883 |
} |
|
884 |
aInterfaceNum = ifcset_ptr->iCurrentInterface; |
|
885 |
return KErrNone; |
|
886 |
} |
|
887 |
||
888 |
||
889 |
/** This is normally called once by an LDD's destructor, either after a Close() on the user side, |
|
890 |
or during general cleanup. |
|
891 |
||
892 |
It might also be called by the LDD when some internal unrecoverable error occurs. |
|
893 |
||
894 |
This function |
|
895 |
- de-registers a possibly pending device state change notification request, |
|
896 |
- de-registers a possibly pending endpoint state change notification request, |
|
897 |
- releases all interfaces + settings owned by this LDD, |
|
898 |
- cancels all remaining (if any) read/write requests. |
|
899 |
||
900 |
@param aClientId A pointer to the LDD to be unregistered. |
|
901 |
||
902 |
@return KErrNone. |
|
903 |
*/ |
|
904 |
EXPORT_C TInt DUsbClientController::DeRegisterClient(const DBase* aClientId) |
|
905 |
{ |
|
253 | 906 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENT, "DUsbClientController::DeRegisterClient(0x%x)", aClientId); |
907 |
||
0 | 908 |
// Cancel all device state notification requests |
909 |
DeRegisterForStatusChange(aClientId); |
|
910 |
// Cancel all endpoint state notification requests |
|
911 |
DeRegisterForEndpointStatusChange(aClientId); |
|
912 |
DeRegisterForOtgFeatureChange(aClientId); |
|
913 |
DeRegisterClientCallback(aClientId); |
|
914 |
// Delete the interface including all its alternate settings which might exist. |
|
915 |
// (If we release the default setting (0), all alternate settings are deleted as well.) |
|
916 |
const TInt r = ReleaseInterface(aClientId, 0); |
|
917 |
// Cancel all remaining (if any) read/write requests |
|
918 |
DeleteRequestCallbacks(aClientId); |
|
253 | 919 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENT_DUP1, "DUsbClientController::DeRegisterClient: Done."); |
0 | 920 |
return r; |
921 |
} |
|
922 |
||
923 |
||
924 |
/** Returns the currently used Ep0 max packet size. |
|
925 |
||
926 |
@return The currently used Ep0 max packet size. |
|
927 |
*/ |
|
928 |
EXPORT_C TInt DUsbClientController::Ep0PacketSize() const |
|
929 |
{ |
|
930 |
const TUsbcLogicalEndpoint* const ep = iRealEndpoints[0].iLEndpoint; |
|
931 |
if (iHighSpeed) |
|
932 |
{ |
|
253 | 933 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0PACKETSIZE, " Ep0 size = %d (HS)", ep->iEpSize_Hs); |
934 |
||
0 | 935 |
return ep->iEpSize_Hs; |
936 |
} |
|
937 |
else |
|
938 |
{ |
|
253 | 939 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0PACKETSIZE_DUP1, " Ep0 size = %d (FS)", ep->iEpSize_Fs); |
0 | 940 |
return ep->iEpSize_Fs; |
941 |
} |
|
942 |
} |
|
943 |
||
944 |
||
945 |
/** Stalls Ep0. |
|
946 |
||
947 |
@param aClientId A pointer to the LDD wishing to stall Ep0 (this is for PIL internal purposes only). |
|
948 |
||
949 |
@return KErrNone if endpoint zero successfully stalled, KErrGeneral otherwise. |
|
950 |
*/ |
|
951 |
EXPORT_C TInt DUsbClientController::Ep0Stall(const DBase* aClientId) |
|
952 |
{ |
|
253 | 953 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EP0STALL, "DUsbClientController::Ep0Stall()" ); |
0 | 954 |
if (aClientId == iEp0ClientId) |
955 |
{ |
|
956 |
ResetEp0DataOutVars(); |
|
957 |
} |
|
958 |
const TInt err = StallEndpoint(KEp0_Out); |
|
959 |
if (err < 0) |
|
960 |
{ |
|
961 |
return err; |
|
962 |
} |
|
963 |
else |
|
964 |
return StallEndpoint(KEp0_In); |
|
965 |
} |
|
966 |
||
967 |
||
968 |
/** Sends a zero-byte status packet on Ep0. |
|
969 |
||
970 |
@param aClientId A pointer to the LDD wishing to send the status packet (not used at present). |
|
971 |
*/ |
|
972 |
EXPORT_C void DUsbClientController::SendEp0StatusPacket(const DBase* /* aClientId */) |
|
973 |
{ |
|
253 | 974 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SENDEP0STATUSPACKET, "DUsbClientController::SendEp0StatusPacket()" ); |
0 | 975 |
SendEp0ZeroByteStatusPacket(); |
976 |
} |
|
977 |
||
978 |
||
979 |
/** Returns the current USB device state. |
|
980 |
||
981 |
'USB device state' here refers to the Visible Device States as defined in chapter 9 of the USB |
|
982 |
specification. |
|
983 |
||
984 |
@return The current USB device state, or EUsbcDeviceStateUndefined if the UDC doesn't allow device state |
|
985 |
tracking (PSL's DeviceStateChangeCaps() returns EFalse). |
|
986 |
*/ |
|
987 |
EXPORT_C TUsbcDeviceState DUsbClientController::GetDeviceStatus() const |
|
988 |
{ |
|
253 | 989 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICESTATUS, "DUsbClientController::GetDeviceStatus()" ); |
0 | 990 |
return iDeviceState; |
991 |
} |
|
992 |
||
993 |
||
994 |
/** Returns the state of an endpoint. |
|
995 |
||
996 |
'Endpoint state' here refers to the state of the ENDPOINT_HALT feature of |
|
997 |
an endpoint as described in chapter 9 of the USB specification. |
|
998 |
||
999 |
@param aClientId A pointer to the LDD owning the interface which contains the endpoint to be queried. |
|
1000 |
@param aEndpointNum The number of the endpoint to be queried. |
|
1001 |
||
1002 |
@return The current endpoint state, or EEndpointStateUnknown if the endpoint couldn't be found. |
|
1003 |
*/ |
|
1004 |
EXPORT_C TEndpointState DUsbClientController::GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const |
|
1005 |
{ |
|
253 | 1006 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETENDPOINTSTATUS, "DUsbClientController::GetEndpointStatus()" ); |
0 | 1007 |
return EndpointStallStatus(aEndpointNum) ? |
1008 |
EEndpointStateStalled : |
|
1009 |
EEndpointStateNotStalled; |
|
1010 |
} |
|
1011 |
||
1012 |
||
1013 |
/** Sets up a data read request for an endpoint. |
|
1014 |
||
1015 |
@param aCallback A reference to a properly filled in data transfer request callback structure. |
|
1016 |
||
1017 |
@return KErrNone if callback successfully registered or if this callback is already registered |
|
1018 |
(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
|
1019 |
endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
|
1020 |
*/ |
|
1021 |
EXPORT_C TInt DUsbClientController::SetupReadBuffer(TUsbcRequestCallback& aCallback) |
|
1022 |
{ |
|
253 | 1023 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPREADBUFFER, "DUsbClientController::SetupReadBuffer()" ); |
0 | 1024 |
const TInt ep = aCallback.iRealEpNum; |
253 | 1025 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP1, " logical ep: #%d", aCallback.iEndpointNum); |
1026 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP2, " real ep: #%d", ep); |
|
0 | 1027 |
TInt err = KErrGeneral; |
1028 |
if (ep != 0) |
|
1029 |
{ |
|
1030 |
if (iRequestCallbacks[ep]) |
|
1031 |
{ |
|
253 | 1032 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP3, " Warning: RequestCallback already registered for that ep"); |
0 | 1033 |
if (iRequestCallbacks[ep] == &aCallback) |
1034 |
{ |
|
253 | 1035 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP4, " (this same RequestCallback @ 0x%x)", &aCallback); |
0 | 1036 |
} |
1037 |
else |
|
1038 |
{ |
|
253 | 1039 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP5, " (a different RequestCallback @ 0x%x)", &aCallback); |
0 | 1040 |
} |
1041 |
return KErrNone; |
|
1042 |
} |
|
1043 |
// This may seem awkward: |
|
1044 |
// First we add a callback, and then, in case of an error, we remove it again. |
|
1045 |
// However this is necessary because the transfer request might complete (through |
|
1046 |
// an ISR) _before_ the SetupEndpointRead function returns. Since we don't know the |
|
1047 |
// outcome, we have to provide the callback before making the setup call. |
|
1048 |
// |
|
253 | 1049 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP6, " adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback); |
0 | 1050 |
iRequestCallbacks[ep] = &aCallback; |
1051 |
if ((err = SetupEndpointRead(ep, aCallback)) != KErrNone) |
|
1052 |
{ |
|
253 | 1053 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP7, " removing RequestCallback @ 0x%x (due to error)", |
1054 |
&aCallback); |
|
0 | 1055 |
iRequestCallbacks[ep] = NULL; |
1056 |
} |
|
1057 |
} |
|
1058 |
else // (ep == 0) |
|
1059 |
{ |
|
1060 |
if (iEp0ReadRequestCallbacks.Elements() == KUsbcMaxListLength) |
|
1061 |
{ |
|
253 | 1062 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP8, " Error: Maximum list length reached: %d", |
1063 |
KUsbcMaxListLength); |
|
0 | 1064 |
return KErrGeneral; |
1065 |
} |
|
1066 |
if (IsInTheRequestList(aCallback)) |
|
1067 |
{ |
|
253 | 1068 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP9, " RequestCallback @ 0x%x already registered", &aCallback); |
0 | 1069 |
return KErrNone; |
1070 |
} |
|
1071 |
// Ep0 reads don't need to be prepared - there's always one pending |
|
253 | 1072 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP10, " adding RequestCallback @ 0x%x (ep0)", &aCallback); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1073 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 1074 |
iEp0ReadRequestCallbacks.AddLast(aCallback); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1075 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 1076 |
err = KErrNone; |
1077 |
if (iEp0_RxExtraData) |
|
1078 |
{ |
|
253 | 1079 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP11, " iEp0_RxExtraData: trying again..."); |
0 | 1080 |
const TBool rx_data = iEp0DataReceiving; |
269 | 1081 |
|
1082 |
//Note: Currently, ProcessEp0ReceiveDone() is only called in the thread context, |
|
1083 |
// but in the future, if this ProcessEp0ReceiveDone() is called in IRQ context, |
|
1084 |
// we have to notice that ProcessEp0ReceiveDone() has hold a fast mutex already. |
|
0 | 1085 |
err = ProcessEp0ReceiveDone(iEp0_RxExtraCount); |
1086 |
if (err == KErrNone) |
|
1087 |
{ |
|
1088 |
iEp0_RxExtraData = EFalse; |
|
1089 |
// Queue a new Ep0 read (because xxxProceed only re-enables the interrupt) |
|
1090 |
SetupEndpointZeroRead(); |
|
1091 |
if (rx_data) |
|
1092 |
{ |
|
1093 |
Ep0ReceiveProceed(); |
|
1094 |
} |
|
1095 |
else |
|
1096 |
{ |
|
1097 |
Ep0ReadSetupPktProceed(); |
|
1098 |
} |
|
253 | 1099 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP12, " :-)"); |
0 | 1100 |
} |
1101 |
else |
|
1102 |
{ |
|
253 | 1103 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP13, " Error: :-("); |
0 | 1104 |
err = KErrGeneral; |
1105 |
} |
|
1106 |
return err; |
|
1107 |
} |
|
1108 |
} |
|
1109 |
return err; |
|
1110 |
} |
|
1111 |
||
1112 |
||
1113 |
/** Sets up a data write request for an endpoint. |
|
1114 |
||
1115 |
@param aCallback A reference to a properly filled in data transfer request callback structure. |
|
1116 |
||
1117 |
@return KErrNone if callback successfully registered or if this callback is already registered |
|
1118 |
(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
|
1119 |
endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
|
1120 |
*/ |
|
1121 |
EXPORT_C TInt DUsbClientController::SetupWriteBuffer(TUsbcRequestCallback& aCallback) |
|
1122 |
{ |
|
253 | 1123 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER, "DUsbClientController::SetupWriteBuffer()" ); |
0 | 1124 |
TInt ep = aCallback.iRealEpNum; |
253 | 1125 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP1, " logical ep: #%d", aCallback.iEndpointNum); |
1126 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP2, " real ep: #%d", ep); |
|
1127 |
||
0 | 1128 |
if (iRequestCallbacks[ep]) |
1129 |
{ |
|
253 | 1130 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP3, " Warning: RequestCallback already registered for that ep"); |
0 | 1131 |
if (iRequestCallbacks[ep] == &aCallback) |
1132 |
{ |
|
253 | 1133 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP4, " (this same RequestCallback @ 0x%x)", &aCallback); |
0 | 1134 |
return KErrNone; |
1135 |
} |
|
1136 |
else |
|
1137 |
{ |
|
253 | 1138 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP5, " (a different RequestCallback @ 0x%x - poss. error)", |
1139 |
&aCallback); |
|
0 | 1140 |
return KErrGeneral; |
1141 |
} |
|
1142 |
} |
|
1143 |
if (ep == 0) |
|
1144 |
{ |
|
1145 |
if (iEp0_TxNonStdCount) |
|
1146 |
{ |
|
1147 |
if (iEp0_TxNonStdCount > aCallback.iLength) |
|
1148 |
{ |
|
253 | 1149 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP6, " Warning: Ep0 is sending less data than requested"); |
0 | 1150 |
if ((aCallback.iLength % iEp0MaxPacketSize == 0) && !aCallback.iZlpReqd) |
1151 |
{ |
|
253 | 1152 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP7, " Warning: Zlp should probably be requested"); |
0 | 1153 |
} |
1154 |
} |
|
1155 |
else if (iEp0_TxNonStdCount < aCallback.iLength) |
|
1156 |
{ |
|
253 | 1157 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP8, " Warning: Ep0 is sending more data than requested"); |
0 | 1158 |
} |
1159 |
iEp0_TxNonStdCount = 0; |
|
1160 |
} |
|
1161 |
// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions. |
|
1162 |
ep = KEp0_Tx; |
|
1163 |
} |
|
1164 |
// This may seem awkward: |
|
1165 |
// First we add a callback, and then, in case of an error, we remove it again. |
|
1166 |
// However this is necessary because the transfer request might complete (through |
|
1167 |
// an ISR) _before_ the SetupEndpointWrite function returns. Since we don't know the |
|
1168 |
// outcome, we have to provide the callback before making the setup call. |
|
253 | 1169 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP9, " adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback); |
0 | 1170 |
iRequestCallbacks[ep] = &aCallback; |
1171 |
if (ep == KEp0_Tx) |
|
1172 |
{ |
|
1173 |
iEp0ClientDataTransmitting = ETrue; // this must be set before calling SetupEndpointZeroWrite |
|
1174 |
if (SetupEndpointZeroWrite(aCallback.iBufferStart, aCallback.iLength, aCallback.iZlpReqd) != KErrNone) |
|
1175 |
{ |
|
253 | 1176 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP10, " removing RequestCallback @ 0x%x (due to error)", &aCallback); |
0 | 1177 |
iRequestCallbacks[ep] = NULL; |
1178 |
iEp0ClientDataTransmitting = EFalse; |
|
1179 |
} |
|
1180 |
} |
|
1181 |
else if (SetupEndpointWrite(ep, aCallback) != KErrNone) |
|
1182 |
{ |
|
253 | 1183 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP11, " removing RequestCallback @ 0x%x (due to error)", &aCallback); |
0 | 1184 |
iRequestCallbacks[ep] = NULL; |
1185 |
} |
|
1186 |
return KErrNone; |
|
1187 |
} |
|
1188 |
||
1189 |
||
1190 |
/** Cancels a data read request for an endpoint. |
|
1191 |
||
1192 |
The request callback will be removed from the queue and the |
|
1193 |
callback function won't be executed. |
|
1194 |
||
1195 |
@param aClientId A pointer to the LDD owning the interface which contains the endpoint. |
|
1196 |
@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled. |
|
1197 |
*/ |
|
1198 |
EXPORT_C void DUsbClientController::CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint) |
|
1199 |
{ |
|
253 | 1200 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELREADBUFFER, "DUsbClientController::CancelReadBuffer(%d)", aRealEndpoint); |
1201 |
||
0 | 1202 |
if (aRealEndpoint < 0) |
1203 |
{ |
|
253 | 1204 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CANCELREADBUFFER_DUP1, " Error: ep # < 0: %d", aRealEndpoint); |
0 | 1205 |
return; |
1206 |
} |
|
1207 |
// Note that we here don't cancel Ep0 read requests at the PSL level! |
|
1208 |
if (aRealEndpoint > 0) |
|
1209 |
{ |
|
1210 |
CancelEndpointRead(aRealEndpoint); |
|
1211 |
} |
|
1212 |
DeleteRequestCallback(aClientId, aRealEndpoint, EControllerRead); |
|
1213 |
} |
|
1214 |
||
1215 |
||
1216 |
/** Cancels a data write request for an endpoint. |
|
1217 |
||
1218 |
It cannot be guaranteed that the data is not sent nonetheless, as some UDCs don't permit a flushing of a |
|
1219 |
TX FIFO once it has been filled. The request callback will be removed from the queue in any case and the |
|
1220 |
callback function won't be executed. |
|
1221 |
||
1222 |
@param aClientId A pointer to the LDD owning the interface which contains the endpoint. |
|
1223 |
@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled. |
|
1224 |
*/ |
|
1225 |
EXPORT_C void DUsbClientController::CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint) |
|
1226 |
{ |
|
253 | 1227 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELWRITEBUFFER, "DUsbClientController::CancelWriteBuffer(%d)", aRealEndpoint); |
1228 |
||
0 | 1229 |
if (aRealEndpoint < 0) |
1230 |
{ |
|
253 | 1231 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CANCELWRITEBUFFER_DUP1, " Error: ep # < 0: %d", aRealEndpoint); |
0 | 1232 |
return; |
1233 |
} |
|
1234 |
if (aRealEndpoint == 0) |
|
1235 |
{ |
|
1236 |
// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions. |
|
1237 |
aRealEndpoint = KEp0_Tx; |
|
1238 |
} |
|
1239 |
CancelEndpointWrite(aRealEndpoint); |
|
1240 |
if (aRealEndpoint == KEp0_Tx) |
|
1241 |
{ |
|
1242 |
// Since Ep0 is shared among clients, we don't have to care about the client id. |
|
1243 |
iEp0WritePending = EFalse; |
|
1244 |
} |
|
1245 |
DeleteRequestCallback(aClientId, aRealEndpoint, EControllerWrite); |
|
1246 |
} |
|
1247 |
||
1248 |
||
1249 |
/** Halts (stalls) an endpoint (but not Ep0). |
|
1250 |
||
1251 |
@param aClientId A pointer to the LDD owning the interface which contains the endpoint to be stalled. |
|
1252 |
@param aEndpointNum The number of the endpoint. |
|
1253 |
||
1254 |
@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully |
|
1255 |
stalled, KErrGeneral otherwise. |
|
1256 |
*/ |
|
1257 |
EXPORT_C TInt DUsbClientController::HaltEndpoint(const DBase* aClientId, TInt aEndpointNum) |
|
1258 |
{ |
|
253 | 1259 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_HALTENDPOINT, "DUsbClientController::HaltEndpoint(%d)", aEndpointNum); |
1260 |
||
0 | 1261 |
const TInt r = StallEndpoint(aEndpointNum); |
1262 |
if (r == KErrNone) |
|
1263 |
{ |
|
1264 |
iRealEndpoints[aEndpointNum].iHalt = ETrue; |
|
1265 |
} |
|
1266 |
else if (r == KErrArgument) |
|
1267 |
{ |
|
1268 |
return KErrNotFound; |
|
1269 |
} |
|
1270 |
return r; |
|
1271 |
} |
|
1272 |
||
1273 |
||
1274 |
/** Clears the halt condition of an endpoint (but not Ep0). |
|
1275 |
||
1276 |
@param aClientId A pointer to the LDD owning the interface which contains the endpoint to be un-stalled. |
|
1277 |
@param aEndpointNum The number of the endpoint. |
|
1278 |
||
1279 |
@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully |
|
1280 |
stalled, KErrGeneral otherwise. |
|
1281 |
*/ |
|
1282 |
EXPORT_C TInt DUsbClientController::ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum) |
|
1283 |
{ |
|
253 | 1284 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CLEARHALTENDPOINT, "DUsbClientController::ClearHaltEndpoint(%d)", aEndpointNum); |
0 | 1285 |
const TInt r = ClearStallEndpoint(aEndpointNum); |
1286 |
if (r == KErrNone) |
|
1287 |
{ |
|
1288 |
iRealEndpoints[aEndpointNum].iHalt = EFalse; |
|
1289 |
} |
|
1290 |
else if (r == KErrArgument) |
|
1291 |
{ |
|
1292 |
return KErrNotFound; |
|
1293 |
} |
|
1294 |
return r; |
|
1295 |
} |
|
1296 |
||
1297 |
||
1298 |
/** This function requests 'device control' for an LDD. |
|
1299 |
||
1300 |
Class or vendor specific Ep0 requests addressed to the USB device as a whole (Recipient field in |
|
1301 |
bmRequestType byte of a Setup packet set to zero) are delivered to the LDD that owns device control. For |
|
1302 |
obvious reasons only one USB LDD can have device control at any given time. |
|
1303 |
||
1304 |
@param aClientId A pointer to the LDD requesting device control. |
|
1305 |
||
1306 |
@return KErrNone if device control successfully claimed or if this LDD already owns it, KErrGeneral if |
|
1307 |
device control already owned by a different client. |
|
1308 |
*/ |
|
1309 |
EXPORT_C TInt DUsbClientController::SetDeviceControl(const DBase* aClientId) |
|
1310 |
{ |
|
253 | 1311 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICECONTROL, "DUsbClientController::SetDeviceControl()" ); |
0 | 1312 |
if (iEp0DeviceControl) |
1313 |
{ |
|
1314 |
if (iEp0DeviceControl == aClientId) |
|
1315 |
{ |
|
253 | 1316 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETDEVICECONTROL_DUP1, " Warning: Device Control already owned by this client" ); |
0 | 1317 |
return KErrNone; |
1318 |
} |
|
253 | 1319 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETDEVICECONTROL_DUP2, " Error: Device Control already claimed by a different client"); |
0 | 1320 |
return KErrGeneral; |
1321 |
} |
|
1322 |
iEp0DeviceControl = aClientId; |
|
1323 |
return KErrNone; |
|
1324 |
} |
|
1325 |
||
1326 |
||
1327 |
/** This function releases device control for an LDD. |
|
1328 |
||
1329 |
@see DUsbClientController::SetDeviceControl() |
|
1330 |
||
1331 |
@param aClientId A pointer to the LDD releasing device control. |
|
1332 |
||
1333 |
@return KErrNone if device control successfully released, KErrGeneral if device control owned by a |
|
1334 |
different client or by no client at all. |
|
1335 |
*/ |
|
1336 |
EXPORT_C TInt DUsbClientController::ReleaseDeviceControl(const DBase* aClientId) |
|
1337 |
{ |
|
253 | 1338 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL, "DUsbClientController::ReleaseDeviceControl()" ); |
0 | 1339 |
if (iEp0DeviceControl) |
1340 |
{ |
|
1341 |
if (iEp0DeviceControl == aClientId) |
|
1342 |
{ |
|
253 | 1343 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP1, " Releasing Device Control" ); |
0 | 1344 |
iEp0DeviceControl = NULL; |
1345 |
return KErrNone; |
|
1346 |
} |
|
253 | 1347 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP2, " Error: Device Control owned by a different client" ); |
0 | 1348 |
} |
1349 |
else |
|
1350 |
{ |
|
253 | 1351 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP3, " Error: Device Control not owned by any client" ); |
0 | 1352 |
} |
1353 |
return KErrGeneral; |
|
1354 |
} |
|
1355 |
||
1356 |
||
1357 |
/** Returns all available (configurable) max packet sizes for Ep0. |
|
1358 |
||
1359 |
The information is coded as bitwise OR'ed values of KUsbEpSizeXXX constants (the bitmap format used for |
|
1360 |
TUsbcEndpointCaps.iSupportedSizes). |
|
1361 |
||
1362 |
@return All available (configurable) max packet sizes for Ep0. |
|
1363 |
*/ |
|
1364 |
EXPORT_C TUint DUsbClientController::EndpointZeroMaxPacketSizes() const |
|
1365 |
{ |
|
253 | 1366 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENDPOINTZEROMAXPACKETSIZES, "DUsbClientController::EndpointZeroMaxPacketSizes()" ); |
0 | 1367 |
return iRealEndpoints[0].iCaps.iSizes; |
1368 |
} |
|
1369 |
||
1370 |
||
1371 |
/** Sets (configures) the max packet size for Ep0. |
|
1372 |
||
1373 |
For available sizes as returned by DUsbClientController::EndpointZeroMaxPacketSizes() |
|
1374 |
||
1375 |
Note that for HS operation the Ep0 size cannot be chosen, but is fixed at 64 bytes. |
|
1376 |
||
1377 |
@return KErrNotSupported if invalid size specified, KErrNone if new max packet size successfully set or |
|
1378 |
requested size was already set. |
|
1379 |
*/ |
|
1380 |
EXPORT_C TInt DUsbClientController::SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize) |
|
1381 |
{ |
|
253 | 1382 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE, "DUsbClientController::SetEndpointZeroMaxPacketSize(%d)", |
1383 |
aMaxPacketSize); |
|
1384 |
||
0 | 1385 |
|
1386 |
if (DeviceHighSpeedCaps()) |
|
1387 |
{ |
|
1388 |
// We're not going to mess with this on a HS device. |
|
1389 |
return KErrNone; |
|
1390 |
} |
|
1391 |
||
1392 |
if (!(iRealEndpoints[0].iCaps.iSizes & PacketSize2Mask(aMaxPacketSize))) |
|
1393 |
{ |
|
253 | 1394 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP1, " Error: invalid size"); |
0 | 1395 |
return KErrNotSupported; |
1396 |
} |
|
1397 |
if (iRealEndpoints[0].iLEndpoint->iEpSize_Fs == aMaxPacketSize) |
|
1398 |
{ |
|
253 | 1399 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP2, " this packet size already set -> returning"); |
0 | 1400 |
return KErrNone; |
1401 |
} |
|
1402 |
const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint; |
|
1403 |
const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint; |
|
1404 |
const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iEpSize_Fs = aMaxPacketSize; |
|
1405 |
const_cast<TUsbcLogicalEndpoint*>(ep0_1)->iEpSize_Fs = aMaxPacketSize; |
|
1406 |
||
1407 |
// @@@ We should probably modify the device descriptor here as well... |
|
1408 |
||
1409 |
if (iHardwareActivated) |
|
1410 |
{ |
|
1411 |
// De-configure endpoint zero |
|
1412 |
DeConfigureEndpoint(KEp0_Out); |
|
1413 |
DeConfigureEndpoint(KEp0_In); |
|
1414 |
// Re-configure endpoint zero |
|
1415 |
const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iInfo.iSize = ep0_0->iEpSize_Fs; |
|
1416 |
const_cast<TUsbcLogicalEndpoint*>(ep0_1)->iInfo.iSize = ep0_1->iEpSize_Fs; |
|
1417 |
ConfigureEndpoint(0, ep0_0->iInfo); |
|
1418 |
ConfigureEndpoint(1, ep0_1->iInfo); |
|
1419 |
iEp0MaxPacketSize = ep0_0->iInfo.iSize; |
|
1420 |
} |
|
1421 |
return KErrNone; |
|
1422 |
} |
|
1423 |
||
1424 |
||
1425 |
/** Returns the current USB Device descriptor. |
|
1426 |
||
1427 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1428 |
@param aDeviceDescriptor A reference to a buffer into which the requested descriptor should be written |
|
1429 |
(most likely located user-side). |
|
1430 |
||
1431 |
@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target |
|
1432 |
buffer. |
|
1433 |
*/ |
|
1434 |
EXPORT_C TInt DUsbClientController::GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor) |
|
1435 |
{ |
|
253 | 1436 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEDESCRIPTOR, "DUsbClientController::GetDeviceDescriptor()" ); |
0 | 1437 |
return iDescriptors.GetDeviceDescriptorTC(aThread, aDeviceDescriptor); |
1438 |
} |
|
1439 |
||
1440 |
||
1441 |
/** Sets a new USB Device descriptor. |
|
1442 |
||
1443 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
1444 |
@param aDeviceDescriptor A reference to a buffer which contains the descriptor to be set (most likely |
|
1445 |
located user-side). |
|
1446 |
||
1447 |
@return The return value of the thread read operation, Kern::ThreadRead(), when reading from the source |
|
1448 |
buffer in case of a failure, KErrNone if the new descriptor was successfully set. |
|
1449 |
*/ |
|
1450 |
EXPORT_C TInt DUsbClientController::SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor) |
|
1451 |
{ |
|
253 | 1452 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICEDESCRIPTOR, "DUsbClientController::SetDeviceDescriptor()" ); |
0 | 1453 |
return iDescriptors.SetDeviceDescriptorTC(aThread, aDeviceDescriptor); |
1454 |
} |
|
1455 |
||
1456 |
||
1457 |
/** Returns the current USB Device descriptor size. |
|
1458 |
||
1459 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1460 |
@param aSize A reference to a buffer into which the requested descriptor size should be written |
|
1461 |
(most likely located user-side). |
|
1462 |
||
1463 |
@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target |
|
1464 |
buffer. |
|
1465 |
*/ |
|
1466 |
EXPORT_C TInt DUsbClientController::GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize) |
|
1467 |
{ |
|
253 | 1468 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEDESCRIPTORSIZE, "DUsbClientController::GetDeviceDescriptorSize()" ); |
0 | 1469 |
// We do not really enquire here.... |
1470 |
const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Device), sizeof(KUsbDescSize_Device)); |
|
1471 |
return Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
1472 |
} |
|
1473 |
||
1474 |
||
1475 |
/** Returns the current USB configuration descriptor. |
|
1476 |
||
1477 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1478 |
@param aConfigurationDescriptor A reference to a buffer into which the requested descriptor should be |
|
1479 |
written (most likely located user-side). |
|
1480 |
||
1481 |
@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target |
|
1482 |
buffer. |
|
1483 |
*/ |
|
1484 |
EXPORT_C TInt DUsbClientController::GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor) |
|
1485 |
{ |
|
253 | 1486 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONDESCRIPTOR, "DUsbClientController::GetConfigurationDescriptor()" ); |
0 | 1487 |
return iDescriptors.GetConfigurationDescriptorTC(aThread, aConfigurationDescriptor); |
1488 |
} |
|
1489 |
||
1490 |
||
1491 |
/** Sets a new USB configuration descriptor. |
|
1492 |
||
1493 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
1494 |
@param aConfigurationDescriptor A reference to a buffer which contains the descriptor to be set (most |
|
1495 |
likely located user-side). |
|
1496 |
||
1497 |
@return The return value of the thread read operation, Kern::ThreadRead() when reading from the source |
|
1498 |
buffer in case of a failure, KErrNone if the new descriptor was successfully set. |
|
1499 |
*/ |
|
1500 |
EXPORT_C TInt DUsbClientController::SetConfigurationDescriptor(DThread* aThread, |
|
1501 |
const TDes8& aConfigurationDescriptor) |
|
1502 |
{ |
|
253 | 1503 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETCONFIGURATIONDESCRIPTOR, "DUsbClientController::SetConfigurationDescriptor()" ); |
0 | 1504 |
return iDescriptors.SetConfigurationDescriptorTC(aThread, aConfigurationDescriptor); |
1505 |
} |
|
1506 |
||
1507 |
||
1508 |
/** Returns the current USB configuration descriptor size. |
|
1509 |
||
1510 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1511 |
@param aSize A reference to a buffer into which the requested descriptor size should be written |
|
1512 |
(most likely located user-side). |
|
1513 |
||
1514 |
@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target |
|
1515 |
buffer. |
|
1516 |
*/ |
|
1517 |
EXPORT_C TInt DUsbClientController::GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize) |
|
1518 |
{ |
|
253 | 1519 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONDESCRIPTORSIZE, "DUsbClientController::GetConfigurationDescriptorSize()" ); |
0 | 1520 |
// We do not really enquire here.... |
1521 |
const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Config), sizeof(KUsbDescSize_Config)); |
|
1522 |
return Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
1523 |
} |
|
1524 |
||
1525 |
||
1526 |
/** Returns the current USB OTG descriptor. |
|
1527 |
||
1528 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1529 |
@param aOtgDesc A reference to a buffer into which the requested descriptor should be |
|
1530 |
written (most likely located user-side). |
|
1531 |
||
1532 |
@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite(), |
|
1533 |
when writing to the target buffer. |
|
1534 |
*/ |
|
1535 |
EXPORT_C TInt DUsbClientController::GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const |
|
1536 |
{ |
|
253 | 1537 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTGDESCRIPTOR, "DUsbClientController::GetOtgDescriptor()" ); |
0 | 1538 |
if (!iOtgSupport) |
1539 |
{ |
|
1540 |
return KErrNotSupported; |
|
1541 |
} |
|
1542 |
return iDescriptors.GetOtgDescriptorTC(aThread, aOtgDesc); |
|
1543 |
} |
|
1544 |
||
1545 |
||
1546 |
/** Sets a new OTG descriptor. |
|
1547 |
||
1548 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1549 |
@param aOtgDesc A reference to a buffer which contains new OTG descriptor. |
|
1550 |
||
1551 |
@return KErrNotSupported or the return value of the thread read operation, Kern::ThreadDesRead(). |
|
1552 |
*/ |
|
1553 |
EXPORT_C TInt DUsbClientController::SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc) |
|
1554 |
{ |
|
253 | 1555 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR, "DUsbClientController::SetOtgDescriptor()" ); |
0 | 1556 |
if (!iOtgSupport) |
1557 |
{ |
|
1558 |
return KErrNotSupported; |
|
1559 |
} |
|
1560 |
TBuf8<KUsbDescSize_Otg> otg; |
|
1561 |
const TInt r = Kern::ThreadDesRead(aThread, &aOtgDesc, otg, 0); |
|
1562 |
if (r != KErrNone) |
|
1563 |
{ |
|
1564 |
return r; |
|
1565 |
} |
|
1566 |
// Check descriptor validity |
|
1567 |
if (otg[0] != KUsbDescSize_Otg || otg[1] != KUsbDescType_Otg || otg[2] > 3) |
|
1568 |
{ |
|
253 | 1569 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP1, " Error: Invalid OTG descriptor" ); |
0 | 1570 |
return KErrGeneral; |
1571 |
} |
|
253 | 1572 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP2, " iOtgFuncMap before: 0x%x", iOtgFuncMap); |
0 | 1573 |
// Update value in controller as well |
1574 |
const TUint8 hnp = otg[2] & KUsbOtgAttr_HnpSupp; |
|
1575 |
const TUint8 srp = otg[2] & KUsbOtgAttr_SrpSupp; |
|
1576 |
if (hnp && !srp) |
|
1577 |
{ |
|
253 | 1578 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP3, " Warning: Invalid OTG attribute combination (HNP && !SRP"); |
0 | 1579 |
} |
1580 |
if (hnp && !(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
1581 |
{ |
|
253 | 1582 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP4, " Setting attribute KUsbOtgAttr_HnpSupp"); |
0 | 1583 |
iOtgFuncMap |= KUsbOtgAttr_HnpSupp; |
1584 |
} |
|
1585 |
else if (!hnp && (iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
1586 |
{ |
|
253 | 1587 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP5, " Removing attribute KUsbOtgAttr_HnpSupp"); |
0 | 1588 |
iOtgFuncMap &= ~KUsbOtgAttr_HnpSupp; |
1589 |
} |
|
1590 |
if (srp && !(iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
|
1591 |
{ |
|
253 | 1592 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP6, " Setting attribute KUsbOtgAttr_SrpSupp"); |
0 | 1593 |
iOtgFuncMap |= KUsbOtgAttr_SrpSupp; |
1594 |
} |
|
1595 |
else if (!srp && (iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
|
1596 |
{ |
|
253 | 1597 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP7, " Removing attribute KUsbOtgAttr_SrpSupp"); |
0 | 1598 |
iOtgFuncMap &= ~KUsbOtgAttr_SrpSupp; |
1599 |
} |
|
253 | 1600 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP8, " iOtgFuncMap after: 0x%x", iOtgFuncMap); |
0 | 1601 |
return iDescriptors.SetOtgDescriptor(otg); |
1602 |
} |
|
1603 |
||
1604 |
||
1605 |
/** Returns current OTG features of USB device. |
|
1606 |
||
1607 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1608 |
@param aFeatures A reference to a buffer into which the requested OTG features should be written. |
|
1609 |
||
1610 |
@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite(). |
|
1611 |
*/ |
|
1612 |
EXPORT_C TInt DUsbClientController::GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const |
|
1613 |
{ |
|
253 | 1614 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTGFEATURES, "DUsbClientController::GetOtgFeatures()" ); |
0 | 1615 |
if (!iOtgSupport) |
1616 |
{ |
|
1617 |
return KErrNotSupported; |
|
1618 |
} |
|
1619 |
TBuf8<1> features(1); |
|
1620 |
features[0] = iOtgFuncMap & 0x1C; |
|
1621 |
return Kern::ThreadDesWrite(aThread, &aFeatures, features, 0); |
|
1622 |
} |
|
1623 |
||
1624 |
||
1625 |
/** Returns current OTG features of USB device. This function is intended to be |
|
1626 |
called only from kernel side. |
|
1627 |
||
1628 |
@param aFeatures The reference to which the current features should be set at. |
|
1629 |
@return KErrNone if successful, KErrNotSupported if OTG is unavailable. |
|
1630 |
*/ |
|
1631 |
EXPORT_C TInt DUsbClientController::GetCurrentOtgFeatures(TUint8& aFeatures) const |
|
1632 |
{ |
|
253 | 1633 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCURRENTOTGFEATURES, "DUsbClientController::GetCurrentOtgFeatures()" ); |
0 | 1634 |
if (!iOtgSupport) |
1635 |
{ |
|
1636 |
return KErrNotSupported; |
|
1637 |
} |
|
1638 |
aFeatures = iOtgFuncMap & 0x1C; |
|
1639 |
return KErrNone; |
|
1640 |
} |
|
1641 |
||
1642 |
||
1643 |
/** Registers client request for OTG feature change. Client is notified when any OTG |
|
1644 |
feature is changed. |
|
1645 |
||
1646 |
@see KUsbOtgAttr_B_HnpEnable, KUsbOtgAttr_A_HnpSupport, KUsbOtgAttr_A_AltHnpSupport |
|
1647 |
||
1648 |
@param aCallback Callback function. Gets called when OTG features change |
|
1649 |
||
1650 |
@return KErrNone if successful, KErrAlreadyExists if aCallback is already in the queue. |
|
1651 |
*/ |
|
1652 |
EXPORT_C TInt DUsbClientController::RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback) |
|
1653 |
{ |
|
253 | 1654 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE, "DUsbClientController::RegisterForOtgFeatureChange()" ); |
0 | 1655 |
if (iOtgCallbacks.Elements() == KUsbcMaxListLength) |
1656 |
{ |
|
253 | 1657 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE_DUP1, " Error: Maximum list length reached: %d", |
1658 |
KUsbcMaxListLength); |
|
0 | 1659 |
return KErrGeneral; |
1660 |
} |
|
1661 |
if (IsInTheOtgFeatureList(aCallback)) |
|
1662 |
{ |
|
253 | 1663 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE_DUP2, " Error: OtgFeatureCallback @ 0x%x already registered", &aCallback); |
0 | 1664 |
return KErrAlreadyExists; |
1665 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1666 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 1667 |
iOtgCallbacks.AddLast(aCallback); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1668 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 1669 |
return KErrNone; |
1670 |
} |
|
1671 |
||
1672 |
||
1673 |
/** De-registers (removes from the list of pending requests) a notification callback for |
|
1674 |
OTG feature change. |
|
1675 |
||
1676 |
@param aClientId A pointer to the LDD owning the endpoint status change callback. |
|
1677 |
||
1678 |
@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
|
1679 |
*/ |
|
1680 |
EXPORT_C TInt DUsbClientController::DeRegisterForOtgFeatureChange(const DBase* aClientId) |
|
1681 |
{ |
|
253 | 1682 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE, "DUsbClientController::DeRegisterForOtgFeatureChange()" ); |
0 | 1683 |
__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1684 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 1685 |
TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks); |
1686 |
TUsbcOtgFeatureCallback* p; |
|
1687 |
while ((p = iter++) != NULL) |
|
1688 |
{ |
|
1689 |
if (!aClientId || p->Owner() == aClientId) |
|
1690 |
{ |
|
253 | 1691 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP1, " removing OtgFeatureCallback @ 0x%x", p); |
0 | 1692 |
iOtgCallbacks.Remove(*p); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1693 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 1694 |
return KErrNone; |
1695 |
} |
|
1696 |
} |
|
253 | 1697 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP2, " client not found"); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1698 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 1699 |
return KErrNotFound; |
1700 |
} |
|
1701 |
||
1702 |
||
1703 |
/** Returns a specific standard USB interface descriptor. |
|
1704 |
||
1705 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1706 |
@param aClientId A pointer to the LDD requesting the descriptor. |
|
1707 |
@param aSettingNum The setting number of the interface for which the descriptor is requested. |
|
1708 |
@param aInterfaceDescriptor A reference to a buffer into which the requested descriptor should be written |
|
1709 |
(most likely located user-side). |
|
1710 |
||
1711 |
@return KErrNotFound if the specified interface couldn't be found, otherwise the return value of the thread |
|
1712 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
1713 |
*/ |
|
1714 |
EXPORT_C TInt DUsbClientController::GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, |
|
1715 |
TInt aSettingNum, TDes8& aInterfaceDescriptor) |
|
1716 |
{ |
|
253 | 1717 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTOR, "DUsbClientController::GetInterfaceDescriptor(x, 0x%08x, %d, y)", |
1718 |
(TUint)aClientId, aSettingNum); |
|
1719 |
||
0 | 1720 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1721 |
if (ifcset < 0) |
|
1722 |
{ |
|
253 | 1723 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
0 | 1724 |
return KErrNotFound; |
1725 |
} |
|
1726 |
return iDescriptors.GetInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum); |
|
1727 |
} |
|
1728 |
||
1729 |
||
1730 |
/** Sets a new standard USB interface descriptor. |
|
1731 |
||
1732 |
This function can also be used, by the user, and under certain conditions, to change an interface's number |
|
1733 |
(reported as bInterfaceNumber in the descriptor). The conditions are: 1) We cannot accept a number that is |
|
1734 |
already used by another interface, 2) We allow the interface number to be changed only when it's still the |
|
1735 |
only setting, and 3) We allow the interface number to be changed only for the default setting (0). (All |
|
1736 |
alternate settings created for that interface thereafter will inherit the new, changed number.) |
|
1737 |
||
1738 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
1739 |
@param aClientId A pointer to the LDD requesting the setting of the descriptor. |
|
1740 |
@param aSettingNum The setting number of the interface for which the descriptor is to be set. |
|
1741 |
@param aInterfaceDescriptor A reference to a buffer which contains the descriptor to be set (most |
|
1742 |
likely located user-side). |
|
1743 |
||
1744 |
@return KErrNotFound if the specified interface couldn't be found, the return value of the thread read |
|
1745 |
operation, Kern::ThreadRead(), when reading from the source buffer in case of a failure, KErrArgument if the |
|
1746 |
interface number is to be changed (via bInterfaceNumber in the descriptor) and either the requested |
|
1747 |
interface number is already used by another interface or the interface has more than one setting. KErrNone |
|
1748 |
if the new descriptor was successfully set. |
|
1749 |
*/ |
|
1750 |
EXPORT_C TInt DUsbClientController::SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, |
|
1751 |
TInt aSettingNum, const TDes8& aInterfaceDescriptor) |
|
1752 |
{ |
|
253 | 1753 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR, "DUsbClientController::SetInterfaceDescriptor(x, 0x%08x, %d, y)", |
1754 |
(TUint)aClientId, aSettingNum); |
|
0 | 1755 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1756 |
if (ifcset < 0) |
|
1757 |
{ |
|
253 | 1758 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
0 | 1759 |
return KErrNotFound; |
1760 |
} |
|
1761 |
TBuf8<KUsbDescSize_Interface> new_ifc; |
|
1762 |
TInt r = Kern::ThreadDesRead(aThread, &aInterfaceDescriptor, new_ifc, 0); |
|
1763 |
if (r != KErrNone) |
|
1764 |
{ |
|
253 | 1765 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP2, " Error: Copying interface descriptor buffer failed (%d)", r); |
0 | 1766 |
return r; |
1767 |
} |
|
1768 |
const TInt ifcset_new = new_ifc[2]; |
|
1769 |
const TBool ifc_num_changes = (ifcset != ifcset_new); |
|
1770 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
|
1771 |
if (!ifcset_ptr) |
|
1772 |
{ |
|
253 | 1773 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP3, " Error: interface number %d doesn't exist", ifcset); |
0 | 1774 |
return KErrNotFound; |
1775 |
} |
|
1776 |
if (ifc_num_changes) |
|
1777 |
{ |
|
1778 |
// If the user wants to change the interface number, we need to do some sanity checks: |
|
1779 |
if (InterfaceExists(ifcset_new)) |
|
1780 |
{ |
|
1781 |
// Obviously we cannot accept a number that is already used by another interface. |
|
253 | 1782 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP4, " Error: interface number %d already in use", ifcset_new); |
0 | 1783 |
return KErrArgument; |
1784 |
} |
|
1785 |
if (ifcset_ptr->iInterfaces.Count() > 1) |
|
1786 |
{ |
|
1787 |
// We allow the interface number to be changed only when it's the only setting. |
|
253 | 1788 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP5, " Error: interface has more than one alternate setting"); |
0 | 1789 |
return KErrArgument; |
1790 |
} |
|
1791 |
if (aSettingNum != 0) |
|
1792 |
{ |
|
1793 |
// We allow the interface number to be changed only when it's the default setting. |
|
253 | 1794 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP6, " Error: interface number can only be changed for setting 0"); |
0 | 1795 |
return KErrArgument; |
1796 |
} |
|
1797 |
} |
|
1798 |
if ((r = iDescriptors.SetInterfaceDescriptor(new_ifc, ifcset, aSettingNum)) != KErrNone) |
|
1799 |
{ |
|
253 | 1800 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP7, " Error: iDescriptors.SetInterfaceDescriptorfailed"); |
0 | 1801 |
return r; |
1802 |
} |
|
1803 |
if (ifc_num_changes) |
|
1804 |
{ |
|
1805 |
// Alright then, let's do it... |
|
253 | 1806 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP8, " about to change interface number from %d to %d", |
1807 |
ifcset, ifcset_new); |
|
0 | 1808 |
ifcset_ptr->iInterfaceNumber = ifcset_new; |
1809 |
} |
|
1810 |
return KErrNone; |
|
1811 |
} |
|
1812 |
||
1813 |
||
1814 |
/** Returns the size of a specific standard USB interface descriptor. |
|
1815 |
||
1816 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1817 |
@param aClientId A pointer to the LDD requesting the descriptor size. |
|
1818 |
@param aSettingNum The setting number of the interface for which the descriptor size is requested. |
|
1819 |
@param aSize A reference to a buffer into which the requested descriptor size should be written (most |
|
1820 |
likely located user-side). |
|
1821 |
||
1822 |
@return KErrNotFound if the specified interface couldn't be found, otherwise the return value of the thread |
|
1823 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
1824 |
*/ |
|
1825 |
EXPORT_C TInt DUsbClientController::GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId, |
|
1826 |
TInt /*aSettingNum*/, TDes8& aSize) |
|
1827 |
{ |
|
253 | 1828 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTORSIZE, "DUsbClientController::GetInterfaceDescriptorSize()" ); |
0 | 1829 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1830 |
if (ifcset < 0) |
|
1831 |
{ |
|
253 | 1832 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTORSIZE_DUP1, " Error: Interface not found from client ID" ); |
0 | 1833 |
return KErrNotFound; |
1834 |
} |
|
1835 |
// Actually, we do not really enquire here.... |
|
1836 |
const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Interface), sizeof(KUsbDescSize_Interface)); |
|
1837 |
Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
1838 |
return KErrNone; |
|
1839 |
} |
|
1840 |
||
1841 |
||
1842 |
/** Returns a specific standard USB endpoint descriptor. |
|
1843 |
||
1844 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1845 |
@param aClientId A pointer to the LDD requesting the descriptor. |
|
1846 |
@param aSettingNum The setting number of the interface that contains the endpoint for which the |
|
1847 |
descriptor is requested. |
|
1848 |
@param aEndpointNum The endpoint for which the descriptor is requested. |
|
1849 |
@param aEndpointDescriptor A reference to a buffer into which the requested descriptor should be written |
|
1850 |
(most likely located user-side). |
|
1851 |
||
1852 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, otherwise the return value |
|
1853 |
of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
1854 |
*/ |
|
1855 |
EXPORT_C TInt DUsbClientController::GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
|
1856 |
TInt aSettingNum, TInt aEndpointNum, |
|
1857 |
TDes8& aEndpointDescriptor) |
|
1858 |
{ |
|
253 | 1859 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR, "DUsbClientController::GetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1860 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 1861 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1862 |
if (ifcset < 0) |
|
1863 |
{ |
|
253 | 1864 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
0 | 1865 |
return KErrNotFound; |
1866 |
} |
|
1867 |
return iDescriptors.GetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
|
1868 |
aSettingNum, EpIdx2Addr(aEndpointNum)); |
|
1869 |
} |
|
1870 |
||
1871 |
||
1872 |
/** Sets a new standard USB endpoint descriptor. |
|
1873 |
||
1874 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
1875 |
@param aClientId A pointer to the LDD requesting the setting of the descriptor. |
|
1876 |
@param aSettingNum The setting number of the interface that contains the endpoint for which the |
|
1877 |
descriptor is to be set. |
|
1878 |
@param aEndpointNum The endpoint for which the descriptor is to be set. |
|
1879 |
@param aEndpointDescriptor A reference to a buffer which contains the descriptor to be set (most |
|
1880 |
likely located user-side). |
|
1881 |
||
1882 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, the return value of the |
|
1883 |
thread read operation, Kern::ThreadRead(), when reading from the source buffer in case of a read failure, |
|
1884 |
KErrNone if the new descriptor was successfully set. |
|
1885 |
*/ |
|
1886 |
EXPORT_C TInt DUsbClientController::SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
|
1887 |
TInt aSettingNum, TInt aEndpointNum, |
|
1888 |
const TDes8& aEndpointDescriptor) |
|
1889 |
{ |
|
253 | 1890 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR, "DUsbClientController::SetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1891 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 1892 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1893 |
if (ifcset < 0) |
|
1894 |
{ |
|
253 | 1895 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
0 | 1896 |
return KErrNotFound; |
1897 |
} |
|
1898 |
return iDescriptors.SetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
|
1899 |
aSettingNum, EpIdx2Addr(aEndpointNum)); |
|
1900 |
} |
|
1901 |
||
1902 |
||
1903 |
/** Returns the size of a specific standard USB endpoint descriptor. |
|
1904 |
||
1905 |
@param aThread A pointer to the thread the LDD requesting the descriptor size is running in. |
|
1906 |
@param aClientId A pointer to the LDD requesting the descriptor size. |
|
1907 |
@param aSettingNum The setting number of the interface that contains the endpoint for which the |
|
1908 |
descriptor size is requested. |
|
1909 |
@param aEndpointNum The endpoint for which the descriptor size is requested. |
|
1910 |
@param aEndpointDescriptor A reference to a buffer into which the requested descriptor size should be |
|
1911 |
written (most likely located user-side). |
|
1912 |
||
1913 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, otherwise the return value |
|
1914 |
of the thread write operation, kern::ThreadWrite(), when writing to the target buffer. |
|
1915 |
*/ |
|
1916 |
EXPORT_C TInt DUsbClientController::GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId, |
|
1917 |
TInt aSettingNum, TInt aEndpointNum, |
|
1918 |
TDes8& aSize) |
|
1919 |
{ |
|
253 | 1920 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE, "DUsbClientController::GetEndpointDescriptorSize(x, 0x%08x, %d, %d, y)", |
1921 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 1922 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1923 |
if (ifcset < 0) |
|
1924 |
{ |
|
253 | 1925 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE_DUP1, "D Error: Interface not found from client ID"); |
0 | 1926 |
return KErrNotFound; |
1927 |
} |
|
1928 |
TInt s; |
|
1929 |
TInt r = iDescriptors.GetEndpointDescriptorSize(ifcset, aSettingNum, |
|
1930 |
EpIdx2Addr(aEndpointNum), s); |
|
1931 |
if (r == KErrNone) |
|
1932 |
{ |
|
1933 |
TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s)); |
|
1934 |
r = Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
1935 |
} |
|
1936 |
else |
|
1937 |
{ |
|
253 | 1938 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE_DUP2, " Error: endpoint descriptor not found"); |
0 | 1939 |
} |
1940 |
return r; |
|
1941 |
} |
|
1942 |
||
1943 |
||
1944 |
/** Returns the current Device_Qualifier descriptor. On a USB device which doesn't support high-speed |
|
1945 |
operation this function will return an error. Note that the contents of the descriptor depend on |
|
1946 |
the current device speed (full-speed or high-speed). |
|
1947 |
||
1948 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1949 |
@param aDeviceQualifierDescriptor A reference to a buffer into which the requested descriptor |
|
1950 |
should be written (most likely located user-side). |
|
1951 |
||
1952 |
@return KErrNotSupported if this descriptor is not supported, otherwise the return value of the thread |
|
1953 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
1954 |
*/ |
|
1955 |
EXPORT_C TInt DUsbClientController::GetDeviceQualifierDescriptor(DThread* aThread, |
|
1956 |
TDes8& aDeviceQualifierDescriptor) |
|
1957 |
{ |
|
253 | 1958 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEQUALIFIERDESCRIPTOR, "DUsbClientController::GetDeviceQualifierDescriptor()" ); |
0 | 1959 |
return iDescriptors.GetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor); |
1960 |
} |
|
1961 |
||
1962 |
||
1963 |
/** Sets a new Device_Qualifier descriptor. On a USB device which doesn't support high-speed |
|
1964 |
operation this function will return an error. Note that the contents of the descriptor should take |
|
1965 |
into account the current device speed (full-speed or high-speed) as it is dependent on it. |
|
1966 |
||
1967 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
1968 |
@param aDeviceQualifierDescriptor A reference to a buffer which contains the descriptor to be set (most |
|
1969 |
likely located user-side). |
|
1970 |
||
1971 |
@return KErrNotSupported if this descriptor is not supported, otherwise the return value of the thread |
|
1972 |
read operation, Kern::ThreadRead(), when reading from the source buffer in case of a failure, KErrNone if |
|
1973 |
the new descriptor was successfully set. |
|
1974 |
*/ |
|
1975 |
EXPORT_C TInt DUsbClientController::SetDeviceQualifierDescriptor(DThread* aThread, |
|
1976 |
const TDes8& aDeviceQualifierDescriptor) |
|
1977 |
{ |
|
253 | 1978 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICEQUALIFIERDESCRIPTOR, "DUsbClientController::SetDeviceQualifierDescriptor()" ); |
0 | 1979 |
return iDescriptors.SetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor); |
1980 |
} |
|
1981 |
||
1982 |
||
1983 |
/** Returns the current Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed |
|
1984 |
operation this function will return an error. Note that the contents of the descriptor depend on the |
|
1985 |
current device speed (full-speed or high-speed). |
|
1986 |
||
1987 |
@param aThread A pointer to the thread the LDD requesting the descriptor is running in. |
|
1988 |
@param aConfigurationDescriptor A reference to a buffer into which the requested descriptor |
|
1989 |
should be written (most likely located user-side). |
|
1990 |
||
1991 |
@return KErrNotSupported if this descriptor is not supported, otherwise the return value of the thread |
|
1992 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
1993 |
*/ |
|
1994 |
EXPORT_C TInt DUsbClientController::GetOtherSpeedConfigurationDescriptor(DThread* aThread, |
|
1995 |
TDes8& aConfigurationDescriptor) |
|
1996 |
{ |
|
253 | 1997 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTHERSPEEDCONFIGURATIONDESCRIPTOR, "DUsbClientController::GetOtherSpeedConfigurationDescriptor()" ); |
0 | 1998 |
return iDescriptors.GetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor); |
1999 |
} |
|
2000 |
||
2001 |
||
2002 |
/** Sets a new Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed |
|
2003 |
operation this function will return an error. Note that the contents of the descriptor should take |
|
2004 |
into account the current device speed (full-speed or high-speed) as it is dependent on it. |
|
2005 |
||
2006 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor is running in. |
|
2007 |
@param aConfigurationDescriptor A reference to a buffer which contains the descriptor to be set (most |
|
2008 |
likely located user-side). |
|
2009 |
||
2010 |
@return KErrNotSupported if this descriptor is not supported, otherwise the return value of the thread |
|
2011 |
read operation, Kern::ThreadRead(), when reading from the source buffer in case of a failure, KErrNone if |
|
2012 |
the new descriptor was successfully set. |
|
2013 |
*/ |
|
2014 |
EXPORT_C TInt DUsbClientController::SetOtherSpeedConfigurationDescriptor(DThread* aThread, |
|
2015 |
const TDes8& aConfigurationDescriptor) |
|
2016 |
{ |
|
253 | 2017 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETOTHERSPEEDCONFIGURATIONDESCRIPTOR, "DUsbClientController::SetOtherSpeedConfigurationDescriptor()" ); |
0 | 2018 |
return iDescriptors.SetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor); |
2019 |
} |
|
2020 |
||
2021 |
||
2022 |
/** Returns a block of all available non-standard (class-specific) interface descriptors for a specific |
|
2023 |
interface. |
|
2024 |
||
2025 |
@param aThread A pointer to the thread the LDD requesting the descriptor block is running in. |
|
2026 |
@param aClientId A pointer to the LDD requesting the descriptor block. |
|
2027 |
@param aSettingNum The setting number of the interface for which the descriptor block is requested. |
|
2028 |
@param aInterfaceDescriptor A reference to a buffer into which the requested descriptor(s) should be |
|
2029 |
written (most likely located user-side). |
|
2030 |
||
2031 |
@return KErrNotFound if the specified interface couldn't be found, otherwise the return value of the thread |
|
2032 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2033 |
*/ |
|
2034 |
EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, |
|
2035 |
TInt aSettingNum, |
|
2036 |
TDes8& aInterfaceDescriptor) |
|
2037 |
{ |
|
253 | 2038 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCK, "DUsbClientController::GetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y)", |
2039 |
(TUint)aClientId, aSettingNum); |
|
0 | 2040 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2041 |
if (ifcset < 0) |
|
2042 |
{ |
|
253 | 2043 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCK_DUP1, "D Error: Interface not found from client ID"); |
0 | 2044 |
return KErrNotFound; |
2045 |
} |
|
2046 |
return iDescriptors.GetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum); |
|
2047 |
} |
|
2048 |
||
2049 |
||
2050 |
/** Sets a block of (i.e. one or more) non-standard (class-specific) interface descriptors for a specific |
|
2051 |
interface. |
|
2052 |
||
2053 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor block is running |
|
2054 |
in. |
|
2055 |
@param aClientId A pointer to the LDD requesting the setting of the descriptor block. |
|
2056 |
@param aSettingNum The setting number of the interface for which the setting of the descriptor block is |
|
2057 |
requested. |
|
2058 |
@param aInterfaceDescriptor A reference to a buffer which contains the descriptor block to be set (most |
|
2059 |
likely located user-side). |
|
2060 |
@param aSize The size of the descriptor block to be set. |
|
2061 |
||
2062 |
@return KErrNotFound if the specified interface couldn't be found, KErrArgument if aSize is less than 2, |
|
2063 |
KErrNoMemory if enough memory for the new descriptor(s) couldn't be allocated, otherwise the return value |
|
2064 |
of the thread read operation, Kern::ThreadRead(), when reading from the source buffer. |
|
2065 |
*/ |
|
2066 |
EXPORT_C TInt DUsbClientController::SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, |
|
2067 |
TInt aSettingNum, |
|
2068 |
const TDes8& aInterfaceDescriptor, TInt aSize) |
|
2069 |
{ |
|
253 | 2070 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK, "DUsbClientController::SetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y, %d)", |
2071 |
(TUint)aClientId, aSettingNum, aSize); |
|
0 | 2072 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2073 |
if (ifcset < 0) |
|
2074 |
{ |
|
253 | 2075 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
0 | 2076 |
return KErrNotFound; |
2077 |
} |
|
2078 |
if (aSize < 2) |
|
2079 |
{ |
|
253 | 2080 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP2, " Error: aSize < 2 (%d)", aSize); |
0 | 2081 |
return KErrArgument; |
2082 |
} |
|
2083 |
return iDescriptors.SetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum, aSize); |
|
2084 |
} |
|
2085 |
||
2086 |
||
2087 |
/** Returns the total size all non-standard (class-specific) interface descriptors for a specific interface. |
|
2088 |
||
2089 |
@param aThread A pointer to the thread the LDD requesting the descriptor block size is running in. |
|
2090 |
@param aClientId A pointer to the LDD requesting the descriptor block size. |
|
2091 |
@param aSettingNum The setting number of the interface for which the descriptor block size is |
|
2092 |
requested. |
|
2093 |
@param aSize A reference to a buffer into which the requested descriptor block size should be written (most |
|
2094 |
likely located user-side). |
|
2095 |
||
2096 |
@return KErrNotFound if the specified interface couldn't be found, otherwise the return value of the thread |
|
2097 |
write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2098 |
*/ |
|
2099 |
EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId, |
|
2100 |
TInt aSettingNum, TDes8& aSize) |
|
2101 |
{ |
|
253 | 2102 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE, "DUsbClientController::GetCSInterfaceDescriptorBlockSize(x, 0x%08x, %d, y)", |
2103 |
(TUint)aClientId, aSettingNum); |
|
0 | 2104 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2105 |
if (ifcset < 0) |
|
2106 |
{ |
|
253 | 2107 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE_DUP1, " Error: Interface not found from client ID"); |
0 | 2108 |
return KErrNotFound; |
2109 |
} |
|
2110 |
TInt s; |
|
2111 |
const TInt r = iDescriptors.GetCSInterfaceDescriptorSize(ifcset, aSettingNum, s); |
|
2112 |
if (r == KErrNone) |
|
2113 |
{ |
|
2114 |
const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s)); |
|
2115 |
Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
2116 |
} |
|
2117 |
else |
|
2118 |
{ |
|
253 | 2119 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE_DUP2, " Error: cs interface descriptor not found"); |
0 | 2120 |
} |
2121 |
return r; |
|
2122 |
} |
|
2123 |
||
2124 |
||
2125 |
/** Returns a block of all available non-standard (class-specific) endpoint descriptors for a specific endpoint. |
|
2126 |
||
2127 |
@param aThread A pointer to the thread the LDD requesting the descriptor block is running in. |
|
2128 |
@param aClientId A pointer to the LDD requesting the descriptor block. |
|
2129 |
@param aSettingNum The setting number of the interface that contains the endpoint for which the |
|
2130 |
descriptor block is requested. |
|
2131 |
@param aEndpointNum The endpoint for which the descriptor block is requested. |
|
2132 |
@param aEndpointDescriptor A reference to a buffer into which the requested descriptor(s) should be written |
|
2133 |
(most likely located user-side). |
|
2134 |
||
2135 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, otherwise the return value |
|
2136 |
of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2137 |
*/ |
|
2138 |
EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
|
2139 |
TInt aSettingNum, TInt aEndpointNum, |
|
2140 |
TDes8& aEndpointDescriptor) |
|
2141 |
{ |
|
253 | 2142 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::GetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2143 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 2144 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2145 |
if (ifcset < 0) |
|
2146 |
{ |
|
253 | 2147 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
0 | 2148 |
return KErrNotFound; |
2149 |
} |
|
2150 |
return iDescriptors.GetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
|
2151 |
aSettingNum, EpIdx2Addr(aEndpointNum)); |
|
2152 |
} |
|
2153 |
||
2154 |
||
2155 |
/** Sets a block of (i.e. one or more) non-standard (class-specific) endpoint descriptors for a specific |
|
2156 |
endpoint. |
|
2157 |
||
2158 |
@param aThread A pointer to the thread the LDD requesting the setting of the descriptor block is running |
|
2159 |
in. |
|
2160 |
@param aClientId A pointer to the LDD requesting the setting of the descriptor block. |
|
2161 |
@param aSettingNum The setting number of the interface that contains the endpoint for which the |
|
2162 |
descriptor block is to be set. |
|
2163 |
@param aEndpointNum The endpoint for which the descriptor block is to be set. |
|
2164 |
@param aEndpointDescriptor A reference to a buffer which contains the descriptor block to be set (most |
|
2165 |
likely located user-side). |
|
2166 |
@param aSize The size of the descriptor block to be set. |
|
2167 |
||
2168 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, KErrArgument if aSize is |
|
2169 |
less than 2, KErrNoMemory if enough memory for the new descriptor(s) couldn't be allocated, otherwise the |
|
2170 |
return value of the thread read operation, Kern::ThreadRead(), when reading from the source buffer. |
|
2171 |
*/ |
|
2172 |
EXPORT_C TInt DUsbClientController::SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
|
2173 |
TInt aSettingNum, TInt aEndpointNum, |
|
2174 |
const TDes8& aEndpointDescriptor, TInt aSize) |
|
2175 |
{ |
|
253 | 2176 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::SetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2177 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 2178 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2179 |
if (ifcset < 0) |
|
2180 |
{ |
|
253 | 2181 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
0 | 2182 |
return KErrNotFound; |
2183 |
} |
|
2184 |
if (aSize < 2) |
|
2185 |
{ |
|
253 | 2186 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP2, " Error: aSize < 2 (%d)", aSize); |
0 | 2187 |
return KErrArgument; |
2188 |
} |
|
2189 |
return iDescriptors.SetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
|
2190 |
aSettingNum, EpIdx2Addr(aEndpointNum), aSize); |
|
2191 |
} |
|
2192 |
||
2193 |
||
2194 |
/** Returns the total size all non-standard (class-specific) endpoint descriptors for a specific endpoint. |
|
2195 |
||
2196 |
@param aThread A pointer to the thread the LDD requesting the descriptor block size is running in. |
|
2197 |
@param aClientId A pointer to the LDD requesting the descriptor block size. |
|
2198 |
@param aSettingNum The setting number of the interface for which the descriptor block size is |
|
2199 |
requested. |
|
2200 |
@param aEndpointNum The endpoint for which the descriptor block size is requested. |
|
2201 |
@param aSize A reference to a buffer into which the requested descriptor block size should be written (most |
|
2202 |
likely located user-side). |
|
2203 |
||
2204 |
@return KErrNotFound if the specified interface or endpoint couldn't be found, otherwise the return value |
|
2205 |
of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2206 |
*/ |
|
2207 |
EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId, |
|
2208 |
TInt aSettingNum, TInt aEndpointNum, |
|
2209 |
TDes8& aSize) |
|
2210 |
{ |
|
253 | 2211 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE, "DUsbClientController::GetCSEndpointDescriptorBlockSize(x, 0x%08x, %d, %d, y)", |
2212 |
(TUint)aClientId, aSettingNum, aEndpointNum); |
|
0 | 2213 |
const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2214 |
if (ifcset < 0) |
|
2215 |
{ |
|
253 | 2216 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE_DUP1, " Error: Interface not found from client ID"); |
0 | 2217 |
return KErrNotFound; |
2218 |
} |
|
2219 |
TInt s; |
|
2220 |
const TInt r = iDescriptors.GetCSEndpointDescriptorSize(ifcset, aSettingNum, |
|
2221 |
EpIdx2Addr(aEndpointNum), s); |
|
2222 |
if (r == KErrNone) |
|
2223 |
{ |
|
2224 |
const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s)); |
|
2225 |
Kern::ThreadDesWrite(aThread, &aSize, size, 0); |
|
2226 |
} |
|
2227 |
else |
|
2228 |
{ |
|
253 | 2229 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE_DUP2, " Error: cs endpoint descriptor not found"); |
0 | 2230 |
} |
2231 |
return r; |
|
2232 |
} |
|
2233 |
||
2234 |
||
2235 |
/** Returns the currently set string descriptor language ID (LANGID) code. |
|
2236 |
||
2237 |
@param aThread A pointer to the thread the LDD requesting the LANGID is running in. |
|
2238 |
@param aLangId A reference to a buffer into which the requested code should be written (most likely |
|
2239 |
located user-side). |
|
2240 |
||
2241 |
@return The return value of the thread write operation, Kern::ThreadDesWrite(), |
|
2242 |
when writing to the target buffer. |
|
2243 |
*/ |
|
2244 |
EXPORT_C TInt DUsbClientController::GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId) |
|
2245 |
{ |
|
253 | 2246 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETSTRINGDESCRIPTORLANGID, "DUsbClientController::GetStringDescriptorLangId()" ); |
0 | 2247 |
return iDescriptors.GetStringDescriptorLangIdTC(aThread, aLangId); |
2248 |
} |
|
2249 |
||
2250 |
||
2251 |
/** Sets the string descriptor language ID (LANGID) code. |
|
2252 |
||
2253 |
@param aLangId The langauge ID code to be written. |
|
2254 |
||
2255 |
@return KErrNone. |
|
2256 |
*/ |
|
2257 |
EXPORT_C TInt DUsbClientController::SetStringDescriptorLangId(TUint16 aLangId) |
|
2258 |
{ |
|
253 | 2259 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETSTRINGDESCRIPTORLANGID, "DUsbClientController::SetStringDescriptorLangId()" ); |
0 | 2260 |
return iDescriptors.SetStringDescriptorLangId(aLangId); |
2261 |
} |
|
2262 |
||
2263 |
||
2264 |
/** Returns the currently set Manufacturer string (which is referenced by the iManufacturer field in the device |
|
2265 |
descriptor). |
|
2266 |
||
2267 |
(Thus, the function should actually be called either 'GetManufacturerString' |
|
2268 |
or 'GetManufacturerStringDescriptorString'.) |
|
2269 |
||
2270 |
@param aThread A pointer to the thread the LDD requesting the string is running in. |
|
2271 |
@param aString A reference to a buffer into which the requested string should be written (most likely |
|
2272 |
located user-side). |
|
2273 |
||
2274 |
@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return |
|
2275 |
value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2276 |
*/ |
|
2277 |
EXPORT_C TInt DUsbClientController::GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString) |
|
2278 |
{ |
|
253 | 2279 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::GetManufacturerStringDescriptor()" ); |
0 | 2280 |
return iDescriptors.GetManufacturerStringDescriptorTC(aThread, aString); |
2281 |
} |
|
2282 |
||
2283 |
||
2284 |
/** Sets a new Manufacturer string in the Manufacturer string descriptor (which is referenced by the |
|
2285 |
iManufacturer field in the device descriptor). |
|
2286 |
||
2287 |
(Thus, the function should actually be called either |
|
2288 |
'SetManufacturerString' or 'SetManufacturerStringDescriptorString'.) |
|
2289 |
||
2290 |
@param aThread A pointer to the thread the LDD requesting the setting of the string is running in. |
|
2291 |
@param aString A reference to a buffer which contains the string to be set (most likely located |
|
2292 |
user-side). |
|
2293 |
||
2294 |
@return KErrNoMemory if not enough memory for the new descriptor or the string could be allocated, the |
|
2295 |
return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong, |
|
2296 |
KErrNone if new string descriptor successfully set. |
|
2297 |
*/ |
|
2298 |
EXPORT_C TInt DUsbClientController::SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString) |
|
2299 |
{ |
|
253 | 2300 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::SetManufacturerStringDescriptor()" ); |
0 | 2301 |
return iDescriptors.SetManufacturerStringDescriptorTC(aThread, aString); |
2302 |
} |
|
2303 |
||
2304 |
||
2305 |
/** Removes (deletes) the Manufacturer string descriptor (which is referenced by the |
|
2306 |
iManufacturer field in the device descriptor). |
|
2307 |
||
2308 |
@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found |
|
2309 |
*/ |
|
2310 |
EXPORT_C TInt DUsbClientController::RemoveManufacturerStringDescriptor() |
|
2311 |
{ |
|
253 | 2312 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVEMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::RemoveManufacturerStringDescriptor()" ); |
0 | 2313 |
return iDescriptors.RemoveManufacturerStringDescriptor(); |
2314 |
} |
|
2315 |
||
2316 |
||
2317 |
/** Returns the currently set Product string (which is referenced by the iProduct field in the device |
|
2318 |
descriptor). |
|
2319 |
||
2320 |
(Thus, the function should actually be called either 'GetProductString' or |
|
2321 |
'GetProductStringDescriptorString'.) |
|
2322 |
||
2323 |
@param aThread A pointer to the thread the LDD requesting the string is running in. |
|
2324 |
@param aString A reference to a buffer into which the requested string should be written (most likely |
|
2325 |
located user-side). |
|
2326 |
||
2327 |
@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return |
|
2328 |
value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2329 |
*/ |
|
2330 |
EXPORT_C TInt DUsbClientController::GetProductStringDescriptor(DThread* aThread, TDes8& aString) |
|
2331 |
{ |
|
253 | 2332 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::GetProductStringDescriptor()" ); |
0 | 2333 |
return iDescriptors.GetProductStringDescriptorTC(aThread, aString); |
2334 |
} |
|
2335 |
||
2336 |
||
2337 |
/** Sets a new Product string in the Product string descriptor (which is referenced by the iProduct field in |
|
2338 |
the device descriptor). |
|
2339 |
||
2340 |
(Thus, the function should actually be called either 'SetProductString' or |
|
2341 |
'SetProductStringDescriptorString'.) |
|
2342 |
||
2343 |
@param aThread A pointer to the thread the LDD requesting the setting of the string is running in. |
|
2344 |
@param aString A reference to a buffer which contains the string to be set (most likely located |
|
2345 |
user-side). |
|
2346 |
||
2347 |
@return KErrNoMemory if not enough memory for the new descriptor or the string could be allocated, the |
|
2348 |
return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong, |
|
2349 |
KErrNone if new string descriptor successfully set. |
|
2350 |
*/ |
|
2351 |
EXPORT_C TInt DUsbClientController::SetProductStringDescriptor(DThread* aThread, const TDes8& aString) |
|
2352 |
{ |
|
253 | 2353 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::SetProductStringDescriptor()" ); |
0 | 2354 |
return iDescriptors.SetProductStringDescriptorTC(aThread, aString); |
2355 |
} |
|
2356 |
||
2357 |
||
2358 |
/** Removes (deletes) the Product string descriptor (which is referenced by the |
|
2359 |
iProduct field in the device descriptor). |
|
2360 |
||
2361 |
@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found |
|
2362 |
*/ |
|
2363 |
EXPORT_C TInt DUsbClientController::RemoveProductStringDescriptor() |
|
2364 |
{ |
|
253 | 2365 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVEPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::RemoveProductStringDescriptor()" ); |
0 | 2366 |
return iDescriptors.RemoveProductStringDescriptor(); |
2367 |
} |
|
2368 |
||
2369 |
||
2370 |
/** Returns the currently set SerialNumber string (which is referenced by the iSerialNumber field in the device |
|
2371 |
descriptor). |
|
2372 |
||
2373 |
(Thus, the function should actually be called either 'GetSerialNumberString' or |
|
2374 |
'GetSerialNumberStringDescriptorString'.) |
|
2375 |
||
2376 |
@param aThread A pointer to the thread the LDD requesting the string is running in. |
|
2377 |
@param aString A reference to a buffer into which the requested string should be written (most likely |
|
2378 |
located user-side). |
|
2379 |
||
2380 |
@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return |
|
2381 |
value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2382 |
*/ |
|
2383 |
EXPORT_C TInt DUsbClientController::GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString) |
|
2384 |
{ |
|
253 | 2385 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETSERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::GetSerialNumberStringDescriptor()" ); |
0 | 2386 |
return iDescriptors.GetSerialNumberStringDescriptorTC(aThread, aString); |
2387 |
} |
|
2388 |
||
2389 |
||
2390 |
/** Sets a new SerialNumber string in the SerialNumber string descriptor (which is referenced by the |
|
2391 |
iSerialNumber field in the device descriptor). |
|
2392 |
||
2393 |
(Thus, the function should actually be called either |
|
2394 |
'SetSerialNumberString' or 'SetSerialNumberStringDescriptorString'.) |
|
2395 |
||
2396 |
@param aThread A pointer to the thread the LDD requesting the setting of the string is running in. |
|
2397 |
@param aString A reference to a buffer which contains the string to be set (most likely located |
|
2398 |
user-side). |
|
2399 |
||
2400 |
@return KErrNoMemory if not enough memory for the new descriptor or the string could be allocated, the |
|
2401 |
return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong, |
|
2402 |
KErrNone if new string descriptor successfully set. |
|
2403 |
*/ |
|
2404 |
EXPORT_C TInt DUsbClientController::SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString) |
|
2405 |
{ |
|
253 | 2406 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETSERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::SetSerialNumberStringDescriptor()" ); |
0 | 2407 |
return iDescriptors.SetSerialNumberStringDescriptorTC(aThread, aString); |
2408 |
} |
|
2409 |
||
2410 |
||
2411 |
/** Removes (deletes) the Serial Number string descriptor (which is referenced by the |
|
2412 |
iSerialNumber field in the device descriptor). |
|
2413 |
||
2414 |
@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found |
|
2415 |
*/ |
|
2416 |
EXPORT_C TInt DUsbClientController::RemoveSerialNumberStringDescriptor() |
|
2417 |
{ |
|
253 | 2418 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVESERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::RemoveSerialNumberStringDescriptor()" ); |
0 | 2419 |
return iDescriptors.RemoveSerialNumberStringDescriptor(); |
2420 |
} |
|
2421 |
||
2422 |
||
2423 |
/** Returns the currently set Configuration string (which is referenced by the iConfiguration field in the |
|
2424 |
configuration descriptor). |
|
2425 |
||
2426 |
(Thus, the function should actually be called either 'GetConfigurationString' or |
|
2427 |
'GetConfigurationStringDescriptorString'.) |
|
2428 |
||
2429 |
@param aThread A pointer to the thread the LDD requesting the string is running in. |
|
2430 |
@param aString A reference to a buffer into which the requested string should be written (most likely |
|
2431 |
located user-side). |
|
2432 |
||
2433 |
@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return |
|
2434 |
value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2435 |
*/ |
|
2436 |
EXPORT_C TInt DUsbClientController::GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString) |
|
2437 |
{ |
|
253 | 2438 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::GetConfigurationStringDescriptor()" ); |
0 | 2439 |
return iDescriptors.GetConfigurationStringDescriptorTC(aThread, aString); |
2440 |
} |
|
2441 |
||
2442 |
||
2443 |
/** Sets a new Configuration string in the Configuration string descriptor (which is referenced by the |
|
2444 |
iConfiguration field in the configuration descriptor). |
|
2445 |
||
2446 |
(Thus, the function should actually be called either |
|
2447 |
'SetConfigurationString' or 'SetConfigurationStringDescriptorString'.) |
|
2448 |
||
2449 |
@param aThread A pointer to the thread the LDD requesting the setting of the string is running in. |
|
2450 |
@param aString A reference to a buffer which contains the string to be set (most likely located |
|
2451 |
user-side). |
|
2452 |
||
2453 |
@return KErrNoMemory if not enough memory for the new descriptor or the string could be allocated, the |
|
2454 |
return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong, |
|
2455 |
KErrNone if new string descriptor successfully set. |
|
2456 |
*/ |
|
2457 |
EXPORT_C TInt DUsbClientController::SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString) |
|
2458 |
{ |
|
253 | 2459 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETCONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::SetConfigurationStringDescriptor()" ); |
0 | 2460 |
return iDescriptors.SetConfigurationStringDescriptorTC(aThread, aString); |
2461 |
} |
|
2462 |
||
2463 |
||
2464 |
/** Removes (deletes) the Configuration string descriptor (which is referenced by the |
|
2465 |
iConfiguration field in the configuration descriptor). |
|
2466 |
||
2467 |
@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found. |
|
2468 |
*/ |
|
2469 |
EXPORT_C TInt DUsbClientController::RemoveConfigurationStringDescriptor() |
|
2470 |
{ |
|
253 | 2471 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVECONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::RemoveConfigurationStringDescriptor()" ); |
0 | 2472 |
return iDescriptors.RemoveConfigurationStringDescriptor(); |
2473 |
} |
|
2474 |
||
2475 |
||
2476 |
/** Copies the string descriptor at the specified index in the string descriptor array into |
|
2477 |
the aString argument. |
|
2478 |
||
2479 |
@param aIndex The position of the string descriptor in the string descriptor array. |
|
2480 |
@param aThread A pointer to the thread the LDD requesting the string is running in. |
|
2481 |
@param aString A reference to a buffer into which the requested string should be written (most likely |
|
2482 |
located user-side). |
|
2483 |
||
2484 |
@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index, or the |
|
2485 |
return value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer. |
|
2486 |
*/ |
|
2487 |
EXPORT_C TInt DUsbClientController::GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString) |
|
2488 |
{ |
|
253 | 2489 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETSTRINGDESCRIPTOR, "DUsbClientController::GetStringDescriptor(%d)", aIndex); |
2490 |
||
0 | 2491 |
return iDescriptors.GetStringDescriptorTC(aThread, aIndex, aString); |
2492 |
} |
|
2493 |
||
2494 |
||
2495 |
/** Sets the aString argument to be a string descriptor at the specified index in the string |
|
2496 |
descriptor array. If a string descriptor already exists at that position then it will be replaced. |
|
2497 |
||
2498 |
@param aIndex The position of the string descriptor in the string descriptor array. |
|
2499 |
@param aThread A pointer to the thread the LDD requesting the setting of the string is running in. |
|
2500 |
@param aString A reference to a buffer which contains the string to be set (most likely located |
|
2501 |
user-side). |
|
2502 |
||
2503 |
@return KErrNone if successful, KErrArgument if aIndex is invalid, KErrNoMemory if no memory is available |
|
2504 |
to store the new string (an existing descriptor at that index will be preserved), or the return value of |
|
2505 |
the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong. |
|
2506 |
*/ |
|
2507 |
EXPORT_C TInt DUsbClientController::SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString) |
|
2508 |
{ |
|
253 | 2509 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETSTRINGDESCRIPTOR, "DUsbClientController::SetStringDescriptor(%d)", aIndex); |
2510 |
||
0 | 2511 |
return iDescriptors.SetStringDescriptorTC(aThread, aIndex, aString); |
2512 |
} |
|
2513 |
||
2514 |
||
2515 |
/** Removes (deletes) the string descriptor at the specified index in the string descriptor array. |
|
2516 |
||
2517 |
@param aIndex The position of the string descriptor in the string descriptor array. |
|
2518 |
||
2519 |
@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index. |
|
2520 |
*/ |
|
2521 |
EXPORT_C TInt DUsbClientController::RemoveStringDescriptor(TUint8 aIndex) |
|
2522 |
{ |
|
253 | 2523 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REMOVESTRINGDESCRIPTOR, "DUsbClientController::RemoveStringDescriptor(%d)", aIndex); |
2524 |
||
0 | 2525 |
return iDescriptors.RemoveStringDescriptor(aIndex); |
2526 |
} |
|
2527 |
||
2528 |
||
2529 |
/** Allocates an endpoint resource. |
|
2530 |
||
2531 |
If the resource gets successfully allocated, it will be used from when the current bus transfer |
|
2532 |
has been completed. |
|
2533 |
||
2534 |
@param aClientId A pointer to the LDD requesting the endpoint resource. |
|
2535 |
@param aEndpointNum The number of the endpoint. |
|
2536 |
@param aResource The endpoint resource to be allocated. |
|
2537 |
||
2538 |
@return KErrNone if the resource has been successfully allocated, KErrNotSupported if the endpoint |
|
2539 |
does not support the resource requested, and KErrInUse if the resource is already consumed and |
|
2540 |
cannot be allocated. KErrArgument if the endpoint number is invalid. |
|
2541 |
*/ |
|
2542 |
EXPORT_C TInt DUsbClientController::AllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum, |
|
2543 |
TUsbcEndpointResource aResource) |
|
2544 |
{ |
|
253 | 2545 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ALLOCATEENDPOINTRESOURCE, "DUsbClientController::AllocateEndpointResource()" ); |
0 | 2546 |
return AllocateEndpointResource(aEndpointNum, aResource); |
2547 |
} |
|
2548 |
||
2549 |
||
2550 |
/** Deallocates (frees) an endpoint resource. |
|
2551 |
||
2552 |
The resource will be removed from when the current bus transfer has been completed. |
|
2553 |
||
2554 |
@param aClientId A pointer to the LDD requesting the freeing of the endpoint resource. |
|
2555 |
@param aEndpointNum The number of the endpoint. |
|
2556 |
@param aResource The endpoint resource to be deallocated. |
|
2557 |
||
2558 |
@return KErrNone if the resource has been successfully deallocated, KErrNotSupported if the endpoint |
|
2559 |
does not support the resource requested. KErrArgument if the endpoint number is invalid. |
|
2560 |
*/ |
|
2561 |
EXPORT_C TInt DUsbClientController::DeAllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum, |
|
2562 |
TUsbcEndpointResource aResource) |
|
2563 |
{ |
|
253 | 2564 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEALLOCATEENDPOINTRESOURCE, "DUsbClientController::DeAllocateEndpointResource()" ); |
0 | 2565 |
return DeAllocateEndpointResource(aEndpointNum, aResource); |
2566 |
} |
|
2567 |
||
2568 |
||
2569 |
/** Queries the use of and endpoint resource. |
|
2570 |
||
2571 |
If the resource gets successfully allocated, it will be used from when the current bus transfer |
|
2572 |
has been completed. |
|
2573 |
||
2574 |
@param aClientId A pointer to the LDD querying the endpoint resource. |
|
2575 |
@param aEndpointNum The number of the endpoint. |
|
2576 |
@param aResource The endpoint resource to be queried. |
|
2577 |
||
2578 |
@return ETrue if the specified resource is in use at the endpoint, EFalse if not or if there was any error |
|
2579 |
during the execution of the function. |
|
2580 |
*/ |
|
2581 |
EXPORT_C TBool DUsbClientController::QueryEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum, |
|
2582 |
TUsbcEndpointResource aResource) |
|
2583 |
{ |
|
253 | 2584 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_QUERYENDPOINTRESOURCE, "DUsbClientController::QueryEndpointResource()" ); |
0 | 2585 |
return QueryEndpointResource(aEndpointNum, aResource); |
2586 |
} |
|
2587 |
||
2588 |
||
2589 |
EXPORT_C TInt DUsbClientController::EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum) |
|
2590 |
{ |
|
253 | 2591 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE, "DUsbClientController::EndpointPacketSize(0x%08x, %d)", |
2592 |
(TUint)aClientId, aEndpointNum); |
|
0 | 2593 |
const TUsbcInterfaceSet* const ifcset_ptr = ClientId2InterfacePointer(aClientId); |
2594 |
if (!ifcset_ptr) |
|
2595 |
{ |
|
253 | 2596 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP1, " Error: interface or clientid not found"); |
0 | 2597 |
return -1; |
2598 |
} |
|
2599 |
const TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[ifcset_ptr->iCurrentInterface]; |
|
2600 |
const RPointerArray<TUsbcLogicalEndpoint>& ep_array = ifc_ptr->iEndpoints; |
|
2601 |
const TInt n = ep_array.Count(); |
|
2602 |
for (TInt i = 0; i < n; i++) |
|
2603 |
{ |
|
2604 |
const TUsbcLogicalEndpoint* const ep = ep_array[i]; |
|
2605 |
if (EpAddr2Idx(ep->iPEndpoint->iEndpointAddr) == static_cast<TUint>(aEndpointNum)) |
|
2606 |
{ |
|
253 | 2607 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP2, " Endpoint packet sizes: FS = %d HS = %d", |
2608 |
ep->iEpSize_Fs, ep->iEpSize_Hs); |
|
0 | 2609 |
const TInt size = iHighSpeed ? ep->iEpSize_Hs : ep->iEpSize_Fs; |
253 | 2610 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP3, " Returning %d", size); |
0 | 2611 |
return size; |
2612 |
} |
|
2613 |
} |
|
253 | 2614 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP4, " Error: endpoint not found"); |
0 | 2615 |
return -1; |
2616 |
} |
|
2617 |
||
2618 |
||
2619 |
// |
|
2620 |
// === USB Controller member function implementations - LDD API (public) =========================== |
|
2621 |
// |
|
2622 |
||
2623 |
EXPORT_C TBool DUsbClientController::CurrentlyUsingHighSpeed() |
|
2624 |
{ |
|
253 | 2625 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CURRENTLYUSINGHIGHSPEED, "DUsbClientController::CurrentlyUsingHighSpeed()" ); |
0 | 2626 |
return EFalse; |
2627 |
} |
|
2628 |
||
2629 |
||
2630 |
// |
|
2631 |
// === USB Controller member function implementations - PSL API (public) =========================== |
|
2632 |
// |
|
2633 |
||
2634 |
/** Gets called by the PSL to register a newly created derived class controller object. |
|
2635 |
||
2636 |
@param aUdc The number of the new UDC. It should be 0 for the first (or only) UDC in the system, 1 for the |
|
2637 |
second one, and so forth. KUsbcMaxUdcs determines how many UDCs are supported. |
|
2638 |
||
2639 |
@return A pointer to the controller if successfully registered, NULL if aUdc out of (static) range. |
|
2640 |
||
2641 |
@publishedPartner @released |
|
2642 |
*/ |
|
2643 |
DUsbClientController* DUsbClientController::RegisterUdc(TInt aUdc) |
|
2644 |
{ |
|
253 | 2645 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERUDC, "DUsbClientController::RegisterUdc()" ); |
0 | 2646 |
if (aUdc < 0 || aUdc > (KUsbcMaxUdcs - 1)) |
2647 |
{ |
|
253 | 2648 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERUDC_DUP1, " Error: aUdc out of range (%d)", aUdc); |
0 | 2649 |
return NULL; |
2650 |
} |
|
2651 |
return UsbClientController[aUdc] = this; |
|
2652 |
} |
|
2653 |
||
2654 |
||
2655 |
// |
|
2656 |
// === USB Controller member function implementations - PSL API (protected) ======================== |
|
2657 |
// |
|
2658 |
||
2659 |
/** Initialises an instance of this class, which is the base class of the derived class (= PSL, which is |
|
2660 |
supposed to call this function). |
|
2661 |
||
2662 |
It does the following things: |
|
2663 |
||
2664 |
- disconnects the UDC from the bus, |
|
2665 |
- initialises the USB descriptor pool, uses data from the PSL (see function argument list) |
|
2666 |
- creates and initialises the basic USB device configuration |
|
2667 |
- initialises the array of physical endpoints |
|
2668 |
- initialises Ep0 structures (but doesn't configure & enable Ep0 yet) |
|
2669 |
- creates and installs the USB power handler |
|
2670 |
||
2671 |
@param aDeviceDesc A pointer to a valid standard USB device descriptor or NULL. The values initially |
|
2672 |
required in the descriptor follow from its constructor. The descriptor is not copied over, but rather this |
|
2673 |
pointer is queued directly into the descriptor pool. Must be writable memory. |
|
2674 |
||
2675 |
@param aConfigDesc A pointer to a valid standard USB configuration descriptor or NULL. The values |
|
2676 |
initially required in the descriptor follow from its constructor. The descriptor is not copied over, but |
|
2677 |
rather this pointer is queued directly into the descriptor pool. Must be writable memory. |
|
2678 |
||
2679 |
@param aLangId A pointer to a valid USB language ID (string) descriptor. The values initially required in |
|
2680 |
the descriptor follow from its constructor. The descriptor is not copied over, but rather this pointer is |
|
2681 |
queued directly into the descriptor pool. Must be writable memory. Other than the remaining four string |
|
2682 |
descriptors, this one is not optional. The reason is that the USB spec mandates a LangId descriptor as |
|
2683 |
soon as a single string descriptor gets returned by the device. So, even though the device might omit the |
|
2684 |
Manufacturer, Product, SerialNumber, and Configuration string descriptors, it is at this point not known |
|
2685 |
whether there will be any Interface string descriptors. Since any USB API user can create an interface |
|
2686 |
with an Interface string descriptor, we have to insist here on the provision of a LangId string |
|
2687 |
descriptor. (The PIL decides at run-time whether or not to return the LangId string descriptor to the |
|
2688 |
host, depending on whether there exist any string descriptors at that time.) |
|
2689 |
||
2690 |
@param aManufacturer A pointer to a valid USB string descriptor or NULL. The values initially required in |
|
2691 |
the descriptor follow from its constructor. The descriptor is not copied over, but rather this pointer is |
|
2692 |
queued directly into the descriptor pool. Must be writable memory. This descriptor will be referenced by |
|
2693 |
the iManufacturer field in the device descriptor. |
|
2694 |
||
2695 |
@param aProduct A pointer to a valid USB string descriptor or NULL. The values initially required in the |
|
2696 |
descriptor follow from its constructor. The descriptor is not copied over, but rather this pointer is |
|
2697 |
queued directly into the descriptor pool. Must be writable memory. This descriptor will be referenced by |
|
2698 |
the iProduct field in the device descriptor. |
|
2699 |
||
2700 |
@param aSerialNum A pointer to a valid USB string descriptor or NULL. The values initially required in the |
|
2701 |
descriptor follow from its constructor. The descriptor is not copied over, but rather this pointer is |
|
2702 |
queued directly into the descriptor pool. Must be writable memory. This descriptor will be referenced by |
|
2703 |
the iSerialNumber field in the device descriptor. |
|
2704 |
||
2705 |
@param aConfig A pointer to a valid USB string descriptor or NULL. The values initially required in the |
|
2706 |
descriptor follow from its constructor. The descriptor is not copied over, but rather this pointer is |
|
2707 |
queued directly into the descriptor pool. Must be writable memory. This descriptor will be referenced by |
|
2708 |
the iConfiguration field in the configuration descriptor. |
|
2709 |
||
2710 |
@param aOtgDesc A pointer to a valid USB OTG descriptor (if OTG is supported by this device and is to be |
|
2711 |
supported by the driver) or NULL. The values initially required in the descriptor follow from its |
|
2712 |
constructor. The descriptor is not copied over, but rather this pointer is queued directly into the |
|
2713 |
descriptor pool. Must be writable memory. |
|
2714 |
||
2715 |
@return EFalse, if USB descriptor pool initialisation fails, or if configuration creation fails, or if the |
|
2716 |
PSL reports more endpoints than the constant KUsbcMaxEndpoints permits, or if the Ep0 logical endpoint |
|
2717 |
creation fails, or if the creation of the power handler fails; ETrue, if base class object successfully |
|
2718 |
initialised. |
|
2719 |
||
2720 |
@publishedPartner @released |
|
2721 |
*/ |
|
2722 |
TBool DUsbClientController::InitialiseBaseClass(TUsbcDeviceDescriptor* aDeviceDesc, |
|
2723 |
TUsbcConfigDescriptor* aConfigDesc, |
|
2724 |
TUsbcLangIdDescriptor* aLangId, |
|
2725 |
TUsbcStringDescriptor* aManufacturer, |
|
2726 |
TUsbcStringDescriptor* aProduct, |
|
2727 |
TUsbcStringDescriptor* aSerialNum, |
|
2728 |
TUsbcStringDescriptor* aConfig, |
|
2729 |
TUsbcOtgDescriptor* aOtgDesc) |
|
2730 |
{ |
|
253 | 2731 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS, "DUsbClientController::InitialiseBaseClass()" ); |
0 | 2732 |
// We don't want the host to see us (at least not yet): |
2733 |
UsbDisconnect(); |
|
2734 |
||
2735 |
// Initialise USB descriptor pool |
|
2736 |
if (iDescriptors.Init(aDeviceDesc, aConfigDesc, aLangId, aManufacturer, aProduct, |
|
2737 |
aSerialNum, aConfig, aOtgDesc) != KErrNone) |
|
2738 |
{ |
|
253 | 2739 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP1, " Error: Descriptor initialization failed"); |
0 | 2740 |
return EFalse; |
2741 |
} |
|
2742 |
||
2743 |
if (aOtgDesc) |
|
2744 |
{ |
|
2745 |
iOtgSupport = ETrue; |
|
2746 |
iOtgFuncMap = aOtgDesc->DescriptorData()[2]; |
|
2747 |
// We're only interested in the following capability if this is |
|
2748 |
// actually an OTG device. |
|
2749 |
iOtgHnpHandledByHw = DeviceHnpHandledByHardwareCaps(); |
|
2750 |
} |
|
2751 |
||
2752 |
// Some member variables |
|
2753 |
iSelfPowered = aConfigDesc->Byte(7) & (1 << 6); // Byte 7: bmAttributes |
|
2754 |
iRemoteWakeup = aConfigDesc->Byte(7) & (1 << 5); |
|
2755 |
iRmWakeupStatus_Enabled = EFalse; // default |
|
2756 |
||
2757 |
if (DeviceHighSpeedCaps()) |
|
2758 |
{ |
|
2759 |
if (iDescriptors.InitHs() != KErrNone) |
|
2760 |
{ |
|
2761 |
return EFalse; |
|
2762 |
} |
|
2763 |
} |
|
2764 |
||
2765 |
// Create and initialise our first (and only) configuration |
|
2766 |
TUsbcConfiguration* config = new TUsbcConfiguration(1); |
|
2767 |
if (!config) |
|
2768 |
{ |
|
2769 |
return EFalse; |
|
2770 |
} |
|
2771 |
iConfigs.Append(config); |
|
2772 |
||
2773 |
// Some variable initializations (needed here because of the goto's) |
|
2774 |
const TUsbcEndpointCaps* caps = NULL; |
|
2775 |
TUsbcEndpointInfo info(KUsbEpTypeControl, KUsbEpDirOut, 0); |
|
2776 |
TUsbcLogicalEndpoint* ep = NULL; |
|
2777 |
||
2778 |
// Initialise the array of physical endpoints |
|
2779 |
iDeviceTotalEndpoints = DeviceTotalEndpoints(); |
|
253 | 2780 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP2, " DeviceTotalEndpoints: %d", iDeviceTotalEndpoints); |
0 | 2781 |
// KUsbcMaxEndpoints doesn't include ep 0 |
2782 |
if ((iDeviceTotalEndpoints > (KUsbcMaxEndpoints + 2)) || |
|
2783 |
((iDeviceTotalEndpoints * sizeof(TUsbcPhysicalEndpoint)) > sizeof(iRealEndpoints))) |
|
2784 |
{ |
|
253 | 2785 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP3, " Error: too many endpoints! (change KUsbcMaxEndpoints: %d)", |
2786 |
KUsbcMaxEndpoints); |
|
0 | 2787 |
goto exit_1; |
2788 |
} |
|
2789 |
caps = DeviceEndpointCaps(); |
|
2790 |
for (TInt i = 0; i < iDeviceTotalEndpoints; ++i) |
|
2791 |
{ |
|
2792 |
iRealEndpoints[i].iEndpointAddr = EpIdx2Addr(i); |
|
253 | 2793 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP4, " Caps[%02d] - iTypes: 0x%08x iSizes: 0x%08x", |
2794 |
i, caps[i].iTypesAndDir, caps[i].iSizes); |
|
0 | 2795 |
iRealEndpoints[i].iCaps = caps[i]; |
2796 |
iRealEndpoints[i].iCaps.iReserved[0] = 0; |
|
2797 |
iRealEndpoints[i].iCaps.iReserved[1] = 0; |
|
2798 |
if ((i > 1) && (caps[i].iTypesAndDir != KUsbEpNotAvailable)) |
|
2799 |
{ |
|
253 | 2800 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP5, " --> UsableEndpoint: #%d", i); |
0 | 2801 |
iDeviceUsableEndpoints++; |
2802 |
} |
|
2803 |
} |
|
2804 |
||
2805 |
// Initialise Ep0 structures (logical endpoints are numbered 1..KMaxEndpointsPerClient, |
|
2806 |
// and virtual 0 is real 0): |
|
2807 |
// -- Ep0 OUT |
|
2808 |
iEp0MaxPacketSize = caps[0].MaxPacketSize(); |
|
253 | 2809 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP6, " using Ep0 maxpacketsize of %d bytes", iEp0MaxPacketSize); |
0 | 2810 |
info.iSize = iEp0MaxPacketSize; |
2811 |
ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_Out]); |
|
2812 |
if (!ep) |
|
2813 |
{ |
|
2814 |
goto exit_1; |
|
2815 |
} |
|
253 | 2816 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP7, " creating ep: mapping real ep %d --> logical ep 0", KEp0_Out); |
0 | 2817 |
iRealEndpoints[KEp0_Out].iLEndpoint = ep; |
2818 |
// -- Ep0 IN |
|
2819 |
info.iDir = KUsbEpDirIn; |
|
2820 |
ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_In]); |
|
2821 |
if (!ep) |
|
2822 |
{ |
|
2823 |
goto exit_2; |
|
2824 |
} |
|
253 | 2825 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP8, " creating ep: mapping real ep %d --> logical ep 0", KEp0_In); |
0 | 2826 |
iRealEndpoints[KEp0_In].iLEndpoint = ep; |
2827 |
||
2828 |
// Create the power handler |
|
2829 |
iPowerHandler = new DUsbcPowerHandler(this); |
|
2830 |
if (!iPowerHandler) |
|
2831 |
{ |
|
2832 |
goto exit_3; |
|
2833 |
} |
|
2834 |
iPowerHandler->Add(); |
|
2835 |
||
2836 |
// Misc stuff |
|
2837 |
iTrackDeviceState = DeviceStateChangeCaps(); |
|
2838 |
if (!iTrackDeviceState) |
|
2839 |
{ |
|
2840 |
// There shouldn't really be any PSL that doesn't support Device State |
|
2841 |
// tracking, but we cannot simply enforce it as we have to preserve |
|
2842 |
// backwards compatibility. |
|
253 | 2843 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP9, " Warning: USB Device State tracking not supported by PSL"); |
0 | 2844 |
} |
2845 |
||
2846 |
return ETrue; |
|
2847 |
||
2848 |
exit_3: |
|
2849 |
delete iRealEndpoints[KEp0_In].iLEndpoint; |
|
2850 |
exit_2: |
|
2851 |
delete iRealEndpoints[KEp0_Out].iLEndpoint; |
|
2852 |
exit_1: |
|
2853 |
iConfigs.ResetAndDestroy(); |
|
2854 |
||
2855 |
return EFalse; |
|
2856 |
} |
|
2857 |
||
2858 |
||
2859 |
/** The standard constructor for this class. |
|
2860 |
||
2861 |
@publishedPartner @released |
|
2862 |
*/ |
|
2863 |
DUsbClientController::DUsbClientController() |
|
2864 |
: iEp0ReceivedNonStdRequest(EFalse), |
|
2865 |
iRmWakeupStatus_Enabled(EFalse), |
|
2866 |
iEp0_RxBuf(), |
|
2867 |
iDeviceTotalEndpoints(0), |
|
2868 |
iDeviceUsableEndpoints(0), |
|
2869 |
iDeviceState(EUsbcDeviceStateUndefined), |
|
2870 |
iDeviceStateB4Suspend(EUsbcDeviceStateUndefined), |
|
2871 |
iSelfPowered(EFalse), |
|
2872 |
iRemoteWakeup(EFalse), |
|
2873 |
iTrackDeviceState(EFalse), |
|
2874 |
iHardwareActivated(EFalse), |
|
2875 |
iOtgSupport(EFalse), |
|
2876 |
iOtgHnpHandledByHw(EFalse), |
|
2877 |
iOtgFuncMap(0), |
|
2878 |
iHighSpeed(EFalse), |
|
2879 |
iSetup(), |
|
2880 |
iEp0MaxPacketSize(0), |
|
2881 |
iEp0ClientId(NULL), |
|
2882 |
iEp0DataReceived(0), |
|
2883 |
iEp0DataReceiving(EFalse), |
|
2884 |
iEp0WritePending(EFalse), |
|
2885 |
iEp0ClientDataTransmitting(EFalse), |
|
2886 |
iEp0DeviceControl(NULL), |
|
2887 |
iDescriptors(iEp0_TxBuf), |
|
2888 |
iCurrentConfig(0), |
|
2889 |
iConfigs(1), |
|
2890 |
iRealEndpoints(), |
|
2891 |
iEp0_TxBuf(), |
|
2892 |
iEp0_RxExtraCount(0), |
|
2893 |
iEp0_RxExtraData(EFalse), |
|
2894 |
iEp0_TxNonStdCount(0), |
|
2895 |
iEp0ReadRequestCallbacks(_FOFF(TUsbcRequestCallback, iLink)), |
|
2896 |
iClientCallbacks(_FOFF(TUsbcClientCallback, iLink)), |
|
2897 |
iStatusCallbacks(_FOFF(TUsbcStatusCallback, iLink)), |
|
2898 |
iEpStatusCallbacks(_FOFF(TUsbcEndpointStatusCallback, iLink)), |
|
2899 |
iOtgCallbacks(_FOFF(TUsbcOtgFeatureCallback, iLink)), |
|
2900 |
iReconnectTimer(ReconnectTimerCallback, this), |
|
2901 |
iCableStatusTimer(CableStatusTimerCallback, this), |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2902 |
iUsbLock(TSpinLock::EOrderGenericIrqLow3), |
0 | 2903 |
iPowerUpDfc(PowerUpDfc, this, 3), |
2904 |
iPowerDownDfc(PowerDownDfc, this, 3), |
|
2905 |
iStandby(EFalse), |
|
2906 |
#ifdef USB_OTG_CLIENT |
|
2907 |
// In the OTG case the device starts out disabled |
|
2908 |
iStackIsActive(EFalse), |
|
2909 |
#else |
|
2910 |
iStackIsActive(ETrue), |
|
2911 |
#endif // USB_OTG_CLIENT |
|
2912 |
iOtgClientConnect(EFalse), |
|
2913 |
iClientSupportReady(EFalse), |
|
2914 |
iDPlusEnabled(EFalse), |
|
2915 |
iUsbResetDeferred(EFalse), |
|
2916 |
iEnablePullUpOnDPlus(NULL), |
|
2917 |
iDisablePullUpOnDPlus(NULL), |
|
2918 |
iOtgContext(NULL) |
|
2919 |
{ |
|
253 | 2920 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_CONS, "DUsbClientController::DUsbClientController()" ); |
0 | 2921 |
|
2922 |
#ifndef SEPARATE_USB_DFC_QUEUE |
|
2923 |
iPowerUpDfc.SetDfcQ(Kern::DfcQue0()); |
|
2924 |
iPowerDownDfc.SetDfcQ(Kern::DfcQue0()); |
|
2925 |
#endif // SEPARATE_USB_DFC_QUEUE |
|
2926 |
||
2927 |
for (TInt i = 0; i < KUsbcEpArraySize; i++) |
|
2928 |
iRequestCallbacks[i] = NULL; |
|
2929 |
} |
|
2930 |
||
2931 |
||
2932 |
/** This function gets called by the PSL upon detection of either of the following events: |
|
2933 |
- USB Reset, |
|
2934 |
- USB Suspend event, |
|
2935 |
- USB Resume signalling, |
|
2936 |
- The USB cable has been attached (inserted) or detached (removed). |
|
2937 |
||
2938 |
@param anEvent An enum denoting the event that has occured. |
|
2939 |
||
2940 |
@return KErrArgument if the event is not recognized, otherwise KErrNone. |
|
2941 |
||
2942 |
@publishedPartner @released |
|
2943 |
*/ |
|
2944 |
TInt DUsbClientController::DeviceEventNotification(TUsbcDeviceEvent anEvent) |
|
2945 |
{ |
|
253 | 2946 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEEVENTNOTIFICATION, "DUsbClientController::DeviceEventNotification()" ); |
0 | 2947 |
|
2948 |
// This function may be called by the PSL from within an ISR -- so we have |
|
2949 |
// to take care what we do here (and also in all functions that get called |
|
2950 |
// from here). |
|
2951 |
||
2952 |
switch (anEvent) |
|
2953 |
{ |
|
2954 |
case EUsbEventSuspend: |
|
2955 |
return ProcessSuspendEvent(); |
|
2956 |
case EUsbEventResume: |
|
2957 |
return ProcessResumeEvent(); |
|
2958 |
case EUsbEventReset: |
|
2959 |
return ProcessResetEvent(); |
|
2960 |
case EUsbEventCableInserted: |
|
2961 |
return ProcessCableInsertEvent(); |
|
2962 |
case EUsbEventCableRemoved: |
|
2963 |
return ProcessCableRemoveEvent(); |
|
2964 |
} |
|
2965 |
return KErrArgument; |
|
2966 |
} |
|
2967 |
||
2968 |
||
2969 |
/** This function gets called by the PSL upon completion of a pending data transfer request. |
|
2970 |
||
2971 |
This function is not to be used for endpoint zero completions (use Ep0RequestComplete instead). |
|
2972 |
||
2973 |
@param aCallback A pointer to a data transfer request callback structure which was previously passed to |
|
2974 |
the PSL in a SetupReadBuffer() or SetupWriteBuffer() call. |
|
2975 |
||
2976 |
@publishedPartner @released |
|
2977 |
*/ |
|
2978 |
void DUsbClientController::EndpointRequestComplete(TUsbcRequestCallback* aCallback) |
|
2979 |
{ |
|
253 | 2980 |
OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTREQUESTCOMPLETE, "DUsbClientController::EndpointRequestComplete(%p)", aCallback); |
2981 |
||
0 | 2982 |
// This function may be called by the PSL from within an ISR -- so we have |
2983 |
// to take care what we do here (and also in all functions that get called |
|
2984 |
// from here). |
|
2985 |
||
2986 |
// We don't test aCallback for NULL here (and therefore risk a crash) |
|
2987 |
// because the PSL should never give us a NULL argument. If it does it |
|
2988 |
// means the PSL is buggy and ought to be fixed. |
|
2989 |
ProcessDataTransferDone(*aCallback); |
|
2990 |
} |
|
2991 |
||
2992 |
||
2993 |
/** This function should be called by the PSL after reception of an Ep0 |
|
2994 |
SET_FEATURE request with a feature selector of either {b_hnp_enable, |
|
2995 |
a_hnp_support, a_alt_hnp_support}, but only when that Setup packet is not |
|
2996 |
handed up to the PIL (for instance because it is auto-decoded and |
|
2997 |
'swallowed' by the UDC hardware). |
|
2998 |
||
2999 |
@param aHnpState A bitmask indicating the present state of the three OTG |
|
3000 |
feature selectors as follows: |
|
3001 |
||
3002 |
bit.0 == a_alt_hnp_support |
|
3003 |
bit.1 == a_hnp_support |
|
3004 |
bit.2 == b_hnp_enable |
|
3005 |
||
3006 |
@see DUsbClientController::ProcessSetClearDevFeature() |
|
3007 |
||
3008 |
@publishedPartner @released |
|
3009 |
*/ |
|
3010 |
void DUsbClientController::HandleHnpRequest(TInt aHnpState) |
|
3011 |
// This function is called by the PSL from within an ISR -- so we have to take care what we do here |
|
3012 |
// (and also in all functions that get called from here). |
|
3013 |
{ |
|
253 | 3014 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST, "DUsbClientController::HandleHnpRequest(%d)", aHnpState); |
3015 |
||
0 | 3016 |
|
3017 |
if (!iOtgSupport) |
|
3018 |
{ |
|
253 | 3019 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST_DUP1, " Error: Request only supported on a OTG device"); |
0 | 3020 |
return; |
3021 |
} |
|
3022 |
if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
3023 |
{ |
|
253 | 3024 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST_DUP2, " Error: Request only valid if OTG device supports HNP"); |
0 | 3025 |
return; |
3026 |
} |
|
3027 |
// (case KUsbFeature_B_HnpEnable:) |
|
3028 |
if (aHnpState & 0x04) |
|
3029 |
{ |
|
3030 |
iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable; |
|
3031 |
} |
|
3032 |
// (case KUsbFeature_A_HnpSupport:) |
|
3033 |
if (aHnpState & 0x02) |
|
3034 |
{ |
|
3035 |
iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport; |
|
3036 |
} |
|
3037 |
// (case KUsbFeature_A_AltHnpSupport:) |
|
3038 |
if (aHnpState & 0x01) |
|
3039 |
{ |
|
3040 |
iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport; |
|
3041 |
} |
|
3042 |
OtgFeaturesNotify(); |
|
3043 |
} |
|
3044 |
||
3045 |
||
3046 |
/** This function gets called by the PSL upon completion of a pending endpoint zero data transfer request. |
|
3047 |
||
3048 |
@param aRealEndpoint Either 0 for Ep0 OUT (= Read), or 1 for Ep0 IN (= Write). |
|
3049 |
@param aCount The number of bytes received or transmitted, respectively. |
|
3050 |
@param aError The error status of the completed transfer request. Can be KErrNone if no error, KErrCancel |
|
3051 |
if transfer was cancelled, or KErrPrematureEnd if a premature status end was encountered. |
|
3052 |
||
3053 |
@return KErrNone if no error during transfer completion processing, KErrGeneral if the request was a read & |
|
3054 |
a Setup packet was received & the recipient for that packet couldn't be found (invalid packet: Ep0 has been |
|
3055 |
stalled), KErrNotFound if the request was a read & the recipient for that packet (Setup or data) _was_ |
|
3056 |
found - however no read had been set up by that recipient (this case should be used by the PSL to disable |
|
3057 |
the Ep0 interrupt at that point and give the LDD time to set up a new Ep0 read; once the 'missing' read |
|
3058 |
was set up either Ep0ReceiveProceed or Ep0ReadSetupPktProceed will be called by the PIL). |
|
3059 |
||
3060 |
@publishedPartner @released |
|
3061 |
*/ |
|
3062 |
TInt DUsbClientController::Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError) |
|
3063 |
{ |
|
253 | 3064 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE, "DUsbClientController::Ep0RequestComplete(%d)", aRealEndpoint); |
3065 |
||
0 | 3066 |
// This function may be called by the PSL from within an ISR -- so we have |
3067 |
// to take care what we do here (and also in all functions that get called |
|
3068 |
// from here). |
|
3069 |
||
3070 |
__ASSERT_DEBUG((aRealEndpoint < 2), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
3071 |
if (aError != KErrNone && aError != KErrPrematureEnd) |
|
3072 |
{ |
|
253 | 3073 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP1, " Error: Ep0 request failed (code %d). " |
3074 |
"Setting up new Read request.", aError); |
|
3075 |
||
0 | 3076 |
if (aRealEndpoint == KEp0_Rx) |
3077 |
{ |
|
253 | 3078 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP2, " (RX request failed)"); |
0 | 3079 |
StallEndpoint(KEp0_Out); |
3080 |
} |
|
3081 |
else |
|
3082 |
{ |
|
253 | 3083 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP3, " (TX request failed)"); |
0 | 3084 |
iEp0WritePending = EFalse; |
3085 |
StallEndpoint(KEp0_In); |
|
3086 |
} |
|
3087 |
// our only remedy: set up a new read request |
|
3088 |
SetupEndpointZeroRead(); |
|
3089 |
return KErrNone; |
|
3090 |
} |
|
3091 |
TInt r; |
|
3092 |
if (aRealEndpoint & 0x01) |
|
3093 |
{ |
|
3094 |
r = ProcessEp0TransmitDone(aCount, aError); |
|
3095 |
} |
|
3096 |
else |
|
3097 |
{ |
|
3098 |
r = ProcessEp0ReceiveDone(aCount); |
|
3099 |
if (r == KErrNotFound) |
|
3100 |
{ |
|
3101 |
// Don't set up new read yet if data weren't delivered. |
|
3102 |
// (The PSL is supposed, upon encountering this return value, |
|
3103 |
// to turn off Ep0's interrupt.) |
|
3104 |
return r; |
|
3105 |
} |
|
3106 |
} |
|
3107 |
if (iEp0WritePending == EFalse) |
|
3108 |
{ |
|
3109 |
// we're done & no write request has been set up. |
|
3110 |
// so: setup an Ep0 read again |
|
253 | 3111 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP4, " Setting up new Ep0 read request."); |
0 | 3112 |
SetupEndpointZeroRead(); |
3113 |
} |
|
3114 |
return r; |
|
3115 |
} |
|
3116 |
||
3117 |
||
3118 |
/** This function should be called by the PSL once the UDC (and thus the USB device) is in the Address state. |
|
3119 |
||
3120 |
@publishedPartner @released |
|
3121 |
*/ |
|
3122 |
void DUsbClientController::MoveToAddressState() |
|
3123 |
{ |
|
253 | 3124 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_MOVETOADDRESSSTATE, "DUsbClientController::MoveToAddressState()" ); |
0 | 3125 |
|
3126 |
// This function may be called by the PSL from within an ISR -- so we have |
|
3127 |
// to take care what we do here (and also in all functions that get called |
|
3128 |
// from here). |
|
3129 |
||
3130 |
NextDeviceState(EUsbcDeviceStateAddress); |
|
3131 |
} |
|
3132 |
||
3133 |
||
3134 |
/** This function should be called by the PSL before certain UDC operations to inform the power model about |
|
3135 |
the electrical current requirements. |
|
3136 |
||
3137 |
(The exact use of this function is currently not quite clear, so not calling it probably won't harm.) |
|
3138 |
||
3139 |
@param aCurrent The required electrical current. |
|
3140 |
||
3141 |
@publishedPartner @released |
|
3142 |
*/ |
|
3143 |
void DUsbClientController::SetCurrent(TInt aCurrent) |
|
3144 |
{ |
|
253 | 3145 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCURRENT, "DUsbClientController::SetCurrent(%d)", aCurrent); |
3146 |
||
0 | 3147 |
// Not much for the moment... (What should we do here?) |
3148 |
return; |
|
3149 |
} |
|
3150 |
||
3151 |
||
3152 |
// |
|
3153 |
// === Platform Specific Layer (PSL) - private/virtual ============================================= |
|
3154 |
// |
|
3155 |
||
3156 |
TInt DUsbClientController::OpenDmaChannel(TInt aRealEndpoint) |
|
3157 |
{ |
|
253 | 3158 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_OPENDMACHANNEL, "DUsbClientController::OpenDmaChannel(%d)", aRealEndpoint); |
3159 |
||
0 | 3160 |
return KErrNone; |
3161 |
} |
|
3162 |
||
3163 |
||
3164 |
void DUsbClientController::CloseDmaChannel(TInt aRealEndpoint) |
|
3165 |
{ |
|
253 | 3166 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CLOSEDMACHANNEL, "DUsbClientController::CloseDmaChannel(%d)", aRealEndpoint); |
0 | 3167 |
} |
3168 |
||
3169 |
||
3170 |
TBool DUsbClientController::CableDetectWithoutPowerCaps() const |
|
3171 |
{ |
|
253 | 3172 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CABLEDETECTWITHOUTPOWERCAPS, "DUsbClientController::CableDetectWithoutPowerCaps()" ); |
0 | 3173 |
// Should be overridden in PSL if applicable. |
3174 |
return EFalse; |
|
3175 |
} |
|
3176 |
||
3177 |
||
3178 |
TBool DUsbClientController::DeviceHighSpeedCaps() const |
|
3179 |
{ |
|
253 | 3180 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHIGHSPEEDCAPS, "DUsbClientController::DeviceHighSpeedCaps()" ); |
0 | 3181 |
// Should be overridden in PSL if applicable. |
3182 |
return EFalse; |
|
3183 |
} |
|
3184 |
||
3185 |
||
3186 |
TBool DUsbClientController::DeviceResourceAllocV2Caps() const |
|
3187 |
{ |
|
253 | 3188 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICERESOURCEALLOCV2CAPS, "DUsbClientController::DeviceResourceAllocV2Caps()" ); |
0 | 3189 |
// Should be overridden in PSL if applicable. |
3190 |
return EFalse; |
|
3191 |
} |
|
3192 |
||
3193 |
||
3194 |
TBool DUsbClientController::DeviceHnpHandledByHardwareCaps() const |
|
3195 |
{ |
|
253 | 3196 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHNPHANDLEDBYHARDWARECAPS, "DUsbClientController::DeviceHnpHandledByHardwareCaps()" ); |
0 | 3197 |
// Should be overridden in PSL if applicable. |
3198 |
return EFalse; |
|
3199 |
} |
|
3200 |
||
3201 |
||
3202 |
TInt DUsbClientController::EnterTestMode(TInt aTestSelector) |
|
3203 |
{ |
|
253 | 3204 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENTERTESTMODE, "DUsbClientController::EnterTestMode(%d)", aTestSelector); |
3205 |
||
0 | 3206 |
// Should be overridden in PSL if applicable. |
3207 |
return KErrNotSupported; |
|
3208 |
} |
|
3209 |
||
3210 |
||
3211 |
TBool DUsbClientController::PowerDownWhenActive() const |
|
3212 |
{ |
|
253 | 3213 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNWHENACTIVE, "DUsbClientController::PowerDownWhenActive()" ); |
0 | 3214 |
return EFalse; |
3215 |
} |
|
3216 |
||
3217 |
||
3218 |
TInt DUsbClientController::PowerDown() |
|
3219 |
{ |
|
253 | 3220 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWN, "DUsbClientController::PowerDown()" ); |
0 | 3221 |
return KErrNone; |
3222 |
} |
|
3223 |
||
3224 |
||
3225 |
TInt DUsbClientController::PowerUp() |
|
3226 |
{ |
|
253 | 3227 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUP, "DUsbClientController::PowerUp()" ); |
0 | 3228 |
return KErrNone; |
3229 |
} |
|
3230 |
||
3231 |
||
3232 |
TInt DUsbClientController::OtgEnableUdc() |
|
3233 |
{ |
|
253 | 3234 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGENABLEUDC, "DUsbClientController::OtgEnableUdc()" ); |
0 | 3235 |
return KErrNone; |
3236 |
} |
|
3237 |
||
3238 |
||
3239 |
TInt DUsbClientController::OtgDisableUdc() |
|
3240 |
{ |
|
253 | 3241 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGDISABLEUDC, "DUsbClientController::OtgDisableUdc()" ); |
0 | 3242 |
return KErrNone; |
3243 |
} |
|
3244 |
||
3245 |
||
3246 |
// |
|
3247 |
// === USB Controller member function implementations - Internal utility functions (private) ======= |
|
3248 |
// |
|
3249 |
||
3250 |
TInt DUsbClientController::DeRegisterClientCallback(const DBase* aClientId) |
|
3251 |
{ |
|
253 | 3252 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK, "DUsbClientController::DeRegisterClientCallback()" ); |
0 | 3253 |
__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3254 |
TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
|
3255 |
TUsbcClientCallback* p; |
|
3256 |
while ((p = iter++) != NULL) |
|
3257 |
if (p->Owner() == aClientId) |
|
3258 |
{ |
|
253 | 3259 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP1, " removing ClientCallback @ 0x%x", p); |
0 | 3260 |
iClientCallbacks.Remove(*p); |
3261 |
return KErrNone; |
|
3262 |
} |
|
253 | 3263 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP2, " Client not found"); |
0 | 3264 |
return KErrNotFound; |
3265 |
} |
|
3266 |
||
3267 |
||
3268 |
TBool DUsbClientController::CheckEpAvailability(TInt aEndpointsUsed, |
|
3269 |
const TUsbcEndpointInfoArray& aEndpointData, |
|
3270 |
TInt aIfcNumber) const |
|
3271 |
{ |
|
253 | 3272 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY, "DUsbClientController::CheckEpAvailability()" ); |
0 | 3273 |
if (aEndpointsUsed > KMaxEndpointsPerClient) |
3274 |
{ |
|
253 | 3275 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP1, " Error: too many endpoints claimed (%d)", aEndpointsUsed); |
0 | 3276 |
return EFalse; |
3277 |
} |
|
3278 |
TBool reserve[KUsbcEpArraySize]; // iDeviceTotalEndpoints can be equal to 32 |
|
3279 |
memset(reserve, EFalse, sizeof(reserve)); // reset the array |
|
3280 |
for (TInt i = 0; i < aEndpointsUsed; ++i) |
|
3281 |
{ |
|
253 | 3282 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP2, " checking for (user) endpoint #%d availability...", i + 1); |
0 | 3283 |
TInt j = 2; |
3284 |
while (j < iDeviceTotalEndpoints) |
|
3285 |
{ |
|
3286 |
if ((iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], aIfcNumber)) && |
|
3287 |
(reserve[j] == EFalse)) |
|
3288 |
{ |
|
253 | 3289 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP3, " ---> found suitable endpoint: RealEndpoint #%d", j); |
0 | 3290 |
reserve[j] = ETrue; // found one: mark this ep as reserved |
3291 |
break; |
|
3292 |
} |
|
253 | 3293 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP4, " -> endpoint not suitable: RealEndpoint #%d", j); |
0 | 3294 |
j++; |
3295 |
} |
|
3296 |
if (j == iDeviceTotalEndpoints) |
|
3297 |
{ |
|
3298 |
return EFalse; |
|
3299 |
} |
|
3300 |
} |
|
3301 |
return ETrue; |
|
3302 |
} |
|
3303 |
||
3304 |
||
3305 |
TUsbcInterface* DUsbClientController::CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord) |
|
3306 |
// We know that 9.2.3 says: "Interfaces are numbered from zero to one less than the number of |
|
3307 |
// concurrent interfaces supported by the configuration." But since we permit the user to |
|
3308 |
// change interface numbers, we can neither assume nor enforce anything about them here. |
|
3309 |
{ |
|
253 | 3310 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE, "DUsbClientController::CreateInterface(x, aIfc=%d)", aIfc); |
3311 |
||
0 | 3312 |
TUsbcInterfaceSet* ifcset_ptr = NULL; |
3313 |
TInt ifcset = ClientId2InterfaceNumber(aClientId); |
|
3314 |
TBool new_ifc; |
|
3315 |
if (ifcset < 0) |
|
3316 |
{ |
|
3317 |
// New interface(set), so we need to find a number for it. |
|
3318 |
new_ifc = ETrue; |
|
3319 |
const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
|
3320 |
if (num_ifcsets == 255) |
|
3321 |
{ |
|
253 | 3322 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP1, " Error: Too many interfaces already exist: 255"); |
0 | 3323 |
return NULL; |
3324 |
} |
|
3325 |
// Find the smallest interface number that has not yet been used. |
|
3326 |
for (ifcset = 0; ifcset < 256; ++ifcset) |
|
3327 |
{ |
|
3328 |
TBool n_used = EFalse; |
|
3329 |
for (TInt i = 0; i < num_ifcsets; ++i) |
|
3330 |
{ |
|
3331 |
if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == ifcset) |
|
3332 |
{ |
|
253 | 3333 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP2, " interface number %d already used", ifcset); |
0 | 3334 |
n_used = ETrue; |
3335 |
break; |
|
3336 |
} |
|
3337 |
} |
|
3338 |
if (!n_used) |
|
3339 |
{ |
|
3340 |
break; |
|
3341 |
} |
|
3342 |
} |
|
3343 |
if (ifcset == 256) |
|
3344 |
{ |
|
253 | 3345 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP3, " Error: no available interface number found"); |
0 | 3346 |
return NULL; |
3347 |
} |
|
3348 |
// append the ifcset |
|
253 | 3349 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP4, " creating new InterfaceSet %d first", ifcset); |
0 | 3350 |
if (aIfc != 0) |
3351 |
{ |
|
253 | 3352 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP5, " Error: invalid interface setting number (1): %d", aIfc); |
0 | 3353 |
return NULL; |
3354 |
} |
|
3355 |
if ((ifcset_ptr = new TUsbcInterfaceSet(aClientId, ifcset)) == NULL) |
|
3356 |
{ |
|
253 | 3357 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP6, " Error: new TUsbcInterfaceSet(aClientId, ifcset_num) failed"); |
0 | 3358 |
return NULL; |
3359 |
} |
|
3360 |
iConfigs[0]->iInterfaceSets.Append(ifcset_ptr); |
|
3361 |
} |
|
3362 |
else /* if (ifcset_num >= 0) */ |
|
3363 |
{ |
|
3364 |
// use an existent ifcset |
|
3365 |
new_ifc = EFalse; |
|
253 | 3366 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP7, " using existing InterfaceSet %d", ifcset); |
0 | 3367 |
ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
3368 |
if (aIfc != ifcset_ptr->iInterfaces.Count()) |
|
3369 |
{ |
|
3370 |
// 9.2.3: "Alternate settings range from zero to one less than the number of alternate |
|
3371 |
// settings for a specific interface." (Thus we can here only append a setting.) |
|
253 | 3372 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP8, " Error: invalid interface setting number (2): %d", aIfc); |
0 | 3373 |
return NULL; |
3374 |
} |
|
3375 |
// Check whether the existing interface belongs indeed to this client |
|
3376 |
if (ifcset_ptr->iClientId != aClientId) |
|
3377 |
{ |
|
253 | 3378 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP9, " Error: iClientId (%p) != aClientId (%p)", |
3379 |
ifcset_ptr->iClientId, aClientId); |
|
0 | 3380 |
return NULL; |
3381 |
} |
|
3382 |
} |
|
3383 |
const TBool no_ep0_requests = aFeatureWord & KUsbcInterfaceInfo_NoEp0RequestsPlease; |
|
3384 |
TUsbcInterface* const ifc_ptr = new TUsbcInterface(ifcset_ptr, aIfc, no_ep0_requests); |
|
3385 |
if (!ifc_ptr) |
|
3386 |
{ |
|
253 | 3387 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP10, " Error: new TUsbcInterface(ifcset, aIfc) failed"); |
0 | 3388 |
if (new_ifc) |
3389 |
{ |
|
3390 |
DeleteInterfaceSet(ifcset); |
|
3391 |
} |
|
3392 |
return NULL; |
|
3393 |
} |
|
3394 |
ifcset_ptr->iInterfaces.Append(ifc_ptr); |
|
3395 |
return ifc_ptr; |
|
3396 |
} |
|
3397 |
||
3398 |
||
3399 |
#define RESET_SETTINGRESERVE \ |
|
3400 |
for (TInt i = start_ep; i < iDeviceTotalEndpoints; i++) \ |
|
3401 |
{ \ |
|
3402 |
if (iRealEndpoints[i].iSettingReserve) \ |
|
3403 |
iRealEndpoints[i].iSettingReserve = EFalse; \ |
|
3404 |
} \ |
|
3405 |
||
3406 |
TInt DUsbClientController::CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, |
|
3407 |
const TUsbcEndpointInfoArray& aEndpointData, |
|
3408 |
TInt aRealEpNumbers[]) |
|
3409 |
{ |
|
253 | 3410 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CREATEENDPOINTS, "DUsbClientController::CreateEndpoints()" ); |
0 | 3411 |
const TInt ifc_num = aIfc->iInterfaceSet->iInterfaceNumber; |
3412 |
const TInt start_ep = 2; |
|
3413 |
for (TInt i = 0; i < aEndpointsUsed; ++i) |
|
3414 |
{ |
|
3415 |
for (TInt j = start_ep; j < iDeviceTotalEndpoints; ++j) |
|
3416 |
{ |
|
3417 |
if (iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], ifc_num)) |
|
3418 |
{ |
|
3419 |
// Logical endpoints are numbered 1..KMaxEndpointsPerClient (virtual 0 is real 0 and 1) |
|
3420 |
TUsbcLogicalEndpoint* const ep = new TUsbcLogicalEndpoint(this, i + 1, aEndpointData[i], |
|
3421 |
aIfc, &iRealEndpoints[j]); |
|
3422 |
if (!ep) |
|
3423 |
{ |
|
253 | 3424 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP1, " Error: new TUsbcLogicalEndpoint() failed"); |
0 | 3425 |
aIfc->iEndpoints.ResetAndDestroy(); |
3426 |
RESET_SETTINGRESERVE; |
|
3427 |
return KErrNoMemory; |
|
3428 |
} |
|
3429 |
aIfc->iEndpoints.Append(ep); |
|
3430 |
// Check on logical endpoint's sizes for compliance with special restrictions. |
|
3431 |
if (aIfc->iSettingCode == 0) |
|
3432 |
{ |
|
3433 |
// For details see last paragraph of 5.7.3 "Interrupt Transfer Packet Size Constraints". |
|
3434 |
if ((ep->iInfo.iType == KUsbEpTypeInterrupt) && (ep->iEpSize_Hs > 64)) |
|
3435 |
{ |
|
253 | 3436 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP2, " Warning: INT ep HS size = %d on default ifc setting", |
3437 |
ep->iEpSize_Hs); |
|
3438 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP3, " (should be <= 64)"); |
|
0 | 3439 |
} |
3440 |
// For details see last paragraph of 5.6.3 "Isochronous Transfer Packet Size Constraints". |
|
3441 |
else if ((ep->iInfo.iType == KUsbEpTypeIsochronous) && (ep->iInfo.iSize > 0)) |
|
3442 |
{ |
|
253 | 3443 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP4, " Warning: ISO ep size = %d on default ifc setting", |
3444 |
ep->iInfo.iSize); |
|
3445 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP5, " (should be zero or ep non-existent)"); |
|
0 | 3446 |
} |
3447 |
} |
|
3448 |
// If the endpoint doesn't support DMA (now or never) the next operation |
|
3449 |
// will be a successful no-op. |
|
3450 |
const TInt r = OpenDmaChannel(j); |
|
3451 |
if (r != KErrNone) |
|
3452 |
{ |
|
253 | 3453 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP6, " Error: Opening of DMA channel failed"); |
0 | 3454 |
aIfc->iEndpoints.ResetAndDestroy(); |
3455 |
RESET_SETTINGRESERVE; |
|
3456 |
return r; |
|
3457 |
} |
|
253 | 3458 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP7, " creating ep: mapping real ep %d -> logical ep %d", |
3459 |
j, i + 1); |
|
0 | 3460 |
iRealEndpoints[j].iIfcNumber = &aIfc->iInterfaceSet->iInterfaceNumber; |
3461 |
iRealEndpoints[j].iSettingReserve = ETrue; |
|
253 | 3462 |
OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP8, " ep->iInfo: iType=0x%x iDir=0x%x iSize=%d iInterval=%d", |
3463 |
ep->iInfo.iType, ep->iInfo.iDir, ep->iInfo.iSize, |
|
3464 |
ep->iInfo.iInterval); |
|
3465 |
OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP9, " ep->iInfo: iInterval_Hs=%d iTransactions=%d iExtra=%d", |
|
3466 |
ep->iInfo.iInterval_Hs, ep->iInfo.iTransactions, |
|
3467 |
ep->iInfo.iExtra); |
|
0 | 3468 |
// Store real endpoint numbers: |
3469 |
// array[x] holds the number for logical ep x. |
|
3470 |
aRealEpNumbers[i + 1] = j; |
|
3471 |
break; |
|
3472 |
} |
|
3473 |
} |
|
3474 |
} |
|
3475 |
aRealEpNumbers[0] = 0; // ep0: 0. |
|
253 | 3476 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP10, " Endpoint Mapping for Interface %d / Setting %d:", ifc_num, aIfc->iSettingCode); |
3477 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP11, "Logical | Real"); |
|
3478 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP12, "Endpoint | Endpoint"); |
|
3479 |
for (TInt ep = 0; ep <= aEndpointsUsed; ++ep) |
|
3480 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP13, " %2d %3d",ep, aRealEpNumbers[ep]); |
|
3481 |
||
0 | 3482 |
RESET_SETTINGRESERVE; |
3483 |
return KErrNone; |
|
3484 |
} |
|
3485 |
||
3486 |
||
3487 |
TInt DUsbClientController::SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, |
|
3488 |
TDesC8* aString, const TUsbcEndpointInfoArray& aEndpointData) |
|
3489 |
{ |
|
253 | 3490 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR, "DUsbClientController::SetupIfcDescriptor()" ); |
0 | 3491 |
|
3492 |
// Interface descriptor |
|
3493 |
TUsbcDescriptorBase* d = TUsbcInterfaceDescriptor::New(aIfc->iInterfaceSet->iInterfaceNumber, |
|
3494 |
aIfc->iSettingCode, |
|
3495 |
aIfc->iEndpoints.Count(), |
|
3496 |
aClass); |
|
3497 |
if (!d) |
|
3498 |
{ |
|
253 | 3499 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP1, " Error: Memory allocation for ifc desc failed." ); |
0 | 3500 |
return KErrNoMemory; |
3501 |
} |
|
3502 |
iDescriptors.InsertDescriptor(d); |
|
3503 |
||
3504 |
// Interface string descriptor |
|
3505 |
if (aString) |
|
3506 |
{ |
|
3507 |
// we don't know the length of the string, so we have to allocate memory dynamically |
|
3508 |
TUint strlen = Kern::ThreadGetDesLength(aThread, aString); |
|
3509 |
if (strlen > KUsbStringDescStringMaxSize) |
|
3510 |
{ |
|
253 | 3511 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP2, " Warning: $ descriptor too long - string will be truncated" ); |
0 | 3512 |
strlen = KUsbStringDescStringMaxSize; |
3513 |
} |
|
3514 |
HBuf8* const stringbuf = HBuf8::New(strlen); |
|
3515 |
if (!stringbuf) |
|
3516 |
{ |
|
253 | 3517 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP3, " Error: Memory allocation for ifc $ desc string failed." ); |
0 | 3518 |
iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3519 |
aIfc->iSettingCode); |
|
3520 |
return KErrNoMemory; |
|
3521 |
} |
|
3522 |
stringbuf->SetMax(); |
|
3523 |
// the aString points to data that lives in user memory, so we have to copy it: |
|
3524 |
TInt r = Kern::ThreadDesRead(aThread, aString, *stringbuf, 0); |
|
3525 |
if (r != KErrNone) |
|
3526 |
{ |
|
253 | 3527 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP4, " Error: Thread read error" ); |
0 | 3528 |
iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3529 |
aIfc->iSettingCode); |
|
3530 |
delete stringbuf; |
|
3531 |
return r; |
|
3532 |
} |
|
3533 |
TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*stringbuf); |
|
3534 |
if (!sd) |
|
3535 |
{ |
|
253 | 3536 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP5, " Error: Memory allocation for ifc $ desc failed." ); |
0 | 3537 |
iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3538 |
aIfc->iSettingCode); |
|
3539 |
delete stringbuf; |
|
3540 |
return KErrNoMemory; |
|
3541 |
} |
|
3542 |
iDescriptors.SetIfcStringDescriptor(sd, aIfc->iInterfaceSet->iInterfaceNumber, aIfc->iSettingCode); |
|
3543 |
delete stringbuf; // the (EPOC) descriptor was copied by New() |
|
3544 |
} |
|
3545 |
||
3546 |
// Endpoint descriptors |
|
3547 |
for (TInt i = 0; i < aIfc->iEndpoints.Count(); ++i) |
|
3548 |
{ |
|
3549 |
// The reason for using another function argument for Endpoint Info |
|
3550 |
// (and not possibly - similar to the Endpoint Address - |
|
3551 |
// "aIfc->iEndpoints[i]->iPEndpoint->iLEndpoint->iInfo") is that this time |
|
3552 |
// there are no logical endpoints associated with our real endpoints, |
|
3553 |
// i.e. iLEndpoint is NULL!. |
|
3554 |
if (aEndpointData[i].iExtra) |
|
3555 |
{ |
|
3556 |
// if a non-standard endpoint descriptor is requested... |
|
3557 |
if (aEndpointData[i].iExtra != 2) |
|
3558 |
{ |
|
3559 |
// ...then it must be a Audio Class endpoint descriptor. Else... |
|
253 | 3560 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP6, " Error: EP desc extension > 2 bytes (%d)", |
3561 |
aEndpointData[i].iExtra); |
|
0 | 3562 |
iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3563 |
aIfc->iSettingCode); |
|
3564 |
return KErrArgument; |
|
3565 |
} |
|
3566 |
d = TUsbcAudioEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr, |
|
3567 |
aEndpointData[i]); |
|
3568 |
} |
|
3569 |
else |
|
3570 |
{ |
|
3571 |
d = TUsbcEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr, |
|
3572 |
aEndpointData[i]); |
|
3573 |
} |
|
3574 |
if (!d) |
|
3575 |
{ |
|
253 | 3576 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP7, " Error: Memory allocation for ep desc #%d failed.", i); |
0 | 3577 |
iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3578 |
aIfc->iSettingCode); |
|
3579 |
return KErrNoMemory; |
|
3580 |
} |
|
3581 |
iDescriptors.InsertDescriptor(d); |
|
3582 |
} |
|
3583 |
||
3584 |
return KErrNone; |
|
3585 |
} |
|
3586 |
||
3587 |
||
3588 |
TInt DUsbClientController::ClientId2InterfaceNumber(const DBase* aClientId) const |
|
3589 |
{ |
|
3590 |
const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
|
3591 |
for (TInt i = 0; i < num_ifcsets; ++i) |
|
3592 |
{ |
|
3593 |
if (iConfigs[0]->iInterfaceSets[i]->iClientId == aClientId) |
|
3594 |
{ |
|
3595 |
return iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber; |
|
3596 |
} |
|
3597 |
} |
|
3598 |
return -1; |
|
3599 |
} |
|
3600 |
||
3601 |
||
3602 |
TUsbcInterfaceSet* DUsbClientController::ClientId2InterfacePointer(const DBase* aClientId) const |
|
3603 |
{ |
|
3604 |
const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
|
3605 |
for (TInt i = 0; i < num_ifcsets; ++i) |
|
3606 |
{ |
|
3607 |
if (iConfigs[0]->iInterfaceSets[i]->iClientId == aClientId) |
|
3608 |
{ |
|
3609 |
return iConfigs[0]->iInterfaceSets[i]; |
|
3610 |
} |
|
3611 |
} |
|
3612 |
return NULL; |
|
3613 |
} |
|
3614 |
||
3615 |
||
3616 |
const DBase* DUsbClientController::InterfaceNumber2ClientId(TInt aIfcSet) const |
|
3617 |
{ |
|
3618 |
if (!InterfaceExists(aIfcSet)) |
|
3619 |
{ |
|
3620 |
return NULL; |
|
3621 |
} |
|
3622 |
return InterfaceNumber2InterfacePointer(aIfcSet)->iClientId; |
|
3623 |
} |
|
3624 |
||
3625 |
||
3626 |
TUsbcInterfaceSet* DUsbClientController::InterfaceNumber2InterfacePointer(TInt aIfcSet) const |
|
3627 |
{ |
|
3628 |
const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
|
3629 |
for (TInt i = 0; i < num_ifcsets; ++i) |
|
3630 |
{ |
|
3631 |
if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == aIfcSet) |
|
3632 |
{ |
|
3633 |
return iConfigs[0]->iInterfaceSets[i]; |
|
3634 |
} |
|
3635 |
} |
|
3636 |
return NULL; |
|
3637 |
} |
|
3638 |
||
3639 |
||
3640 |
TInt DUsbClientController::ActivateHardwareController() |
|
3641 |
{ |
|
253 | 3642 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER, "DUsbClientController::ActivateHardwareController()" ); |
0 | 3643 |
if (iHardwareActivated) |
3644 |
{ |
|
253 | 3645 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP1, " already active -> returning" ); |
0 | 3646 |
return KErrNone; |
3647 |
} |
|
3648 |
// Initialise HW |
|
3649 |
TInt r = StartUdc(); |
|
3650 |
if (r != KErrNone) |
|
3651 |
{ |
|
253 | 3652 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP2, " Error: StartUdc() failed" ); |
0 | 3653 |
return KErrHardwareNotAvailable; |
3654 |
} |
|
3655 |
r = OtgEnableUdc(); // turn on UDC (OTG flavour) |
|
3656 |
if (r != KErrNone) |
|
3657 |
{ |
|
253 | 3658 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP3, " Error: OtgEnableUdc() failed: %d", r); |
0 | 3659 |
} |
3660 |
iHardwareActivated = ETrue; |
|
3661 |
||
3662 |
// Configure & enable endpoint zero |
|
3663 |
const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint; |
|
3664 |
const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint; |
|
3665 |
if (iHighSpeed) |
|
3666 |
{ |
|
3667 |
const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iInfo.iSize = ep0_0->iEpSize_Hs; |
|
3668 |
const_cast<TUsbcLogicalEndpoint*>(ep0_1)->iInfo.iSize = ep0_1->iEpSize_Hs; |
|
3669 |
} |
|
3670 |
else |
|
3671 |
{ |
|
3672 |
const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iInfo.iSize = ep0_0->iEpSize_Fs; |
|
3673 |
const_cast<TUsbcLogicalEndpoint*>(ep0_1)->iInfo.iSize = ep0_1->iEpSize_Fs; |
|
3674 |
} |
|
3675 |
ConfigureEndpoint(0, ep0_0->iInfo); |
|
3676 |
ConfigureEndpoint(1, ep0_1->iInfo); |
|
3677 |
iEp0MaxPacketSize = ep0_0->iInfo.iSize; |
|
3678 |
||
253 | 3679 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP4, " Controller activated."); |
0 | 3680 |
if (UsbConnectionStatus()) |
3681 |
{ |
|
3682 |
if (iDeviceState == EUsbcDeviceStateUndefined) |
|
3683 |
{ |
|
3684 |
NextDeviceState(EUsbcDeviceStateAttached); |
|
3685 |
} |
|
3686 |
NextDeviceState(EUsbcDeviceStatePowered); |
|
3687 |
} |
|
3688 |
return KErrNone;; |
|
3689 |
} |
|
3690 |
||
3691 |
||
3692 |
void DUsbClientController::DeActivateHardwareController() |
|
3693 |
{ |
|
253 | 3694 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER, "DUsbClientController::DeActivateHardwareController()" ); |
0 | 3695 |
if (!iHardwareActivated) |
3696 |
{ |
|
253 | 3697 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP1, " not active -> returning" ); |
0 | 3698 |
return; |
3699 |
} |
|
3700 |
// Deconfigure & disable endpoint zero |
|
3701 |
DeConfigureEndpoint(KEp0_Out); |
|
3702 |
DeConfigureEndpoint(KEp0_In); |
|
3703 |
// Stop HW |
|
3704 |
TInt r = OtgDisableUdc(); // turn off UDC (OTG flavour) |
|
3705 |
if (r != KErrNone) |
|
3706 |
{ |
|
253 | 3707 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP2, " Error: OtgDisableUdc() failed: %d", r); |
0 | 3708 |
} |
3709 |
StopUdc(); |
|
3710 |
iHardwareActivated = EFalse; |
|
253 | 3711 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP3, " Controller deactivated."); |
0 | 3712 |
if (UsbConnectionStatus()) |
3713 |
{ |
|
3714 |
NextDeviceState(EUsbcDeviceStateAttached); |
|
3715 |
} |
|
3716 |
return; |
|
3717 |
} |
|
3718 |
||
3719 |
||
3720 |
void DUsbClientController::DeleteInterfaceSet(TInt aIfcSet) |
|
3721 |
{ |
|
253 | 3722 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET, "DUsbClientController::DeleteInterfaceSet(%d)", aIfcSet); |
3723 |
||
0 | 3724 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet); |
3725 |
if (!ifcset_ptr) |
|
3726 |
{ |
|
253 | 3727 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP1, " Error: invalid interface number: %d", aIfcSet); |
0 | 3728 |
return; |
3729 |
} |
|
3730 |
const TInt idx = iConfigs[0]->iInterfaceSets.Find(ifcset_ptr); |
|
3731 |
if (idx == KErrNotFound) |
|
3732 |
{ |
|
253 | 3733 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP2, " Error: interface not found in array"); |
0 | 3734 |
return; |
3735 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3736 |
//Add this mutex to protect the interface set data structure |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3737 |
if (NKern::CurrentContext() == EThread) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3738 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3739 |
NKern::FMWait(&iMutex); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3740 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3741 |
|
0 | 3742 |
iConfigs[0]->iInterfaceSets.Remove(idx); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3743 |
if (NKern::CurrentContext() == EThread) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3744 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3745 |
NKern::FMSignal(&iMutex); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3746 |
} |
0 | 3747 |
delete ifcset_ptr; |
3748 |
} |
|
3749 |
||
3750 |
||
3751 |
void DUsbClientController::DeleteInterface(TInt aIfcSet, TInt aIfc) |
|
3752 |
{ |
|
253 | 3753 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE, "DUsbClientController::DeleteInterface(%d, %d)", aIfcSet, aIfc); |
3754 |
||
0 | 3755 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet); |
3756 |
if (!ifcset_ptr) |
|
3757 |
{ |
|
253 | 3758 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP1, " Error: invalid interface number: %d", aIfcSet); |
0 | 3759 |
return; |
3760 |
} |
|
3761 |
if (ifcset_ptr->iInterfaces.Count() <= aIfc) |
|
3762 |
{ |
|
253 | 3763 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP2, " Error: invalid interface setting: %d", aIfc); |
0 | 3764 |
return; |
3765 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3766 |
//Add this mutex to protect the interface set data structure |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3767 |
if (NKern::CurrentContext() == EThread) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3768 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3769 |
NKern::FMWait(&iMutex); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3770 |
} |
0 | 3771 |
TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[aIfc]; |
3772 |
// Always first remove, then delete (see ~TUsbcLogicalEndpoint() for the reason why) |
|
3773 |
ifcset_ptr->iInterfaces.Remove(aIfc); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3774 |
|
0 | 3775 |
if (aIfc == ifcset_ptr->iCurrentInterface) |
3776 |
{ |
|
253 | 3777 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP3, " > Warning: deleting current interface setting"); |
0 | 3778 |
ifcset_ptr->iCurrentInterface = 0; |
3779 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3780 |
if (NKern::CurrentContext() == EThread) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3781 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3782 |
NKern::FMSignal(&iMutex); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3783 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3784 |
delete ifc_ptr; |
0 | 3785 |
} |
3786 |
||
3787 |
||
3788 |
void DUsbClientController::CancelTransferRequests(TInt aRealEndpoint) |
|
3789 |
{ |
|
253 | 3790 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELTRANSFERREQUESTS, "DUsbClientController::CancelTransferRequests(aRealEndpoint=%d)", |
3791 |
aRealEndpoint); |
|
3792 |
||
0 | 3793 |
const DBase* const clientId = PEndpoint2ClientId(aRealEndpoint); |
3794 |
if (EpIdx2Addr(aRealEndpoint) & KUsbEpAddress_In) |
|
3795 |
{ |
|
3796 |
CancelWriteBuffer(clientId, aRealEndpoint); |
|
3797 |
} |
|
3798 |
else |
|
3799 |
{ |
|
3800 |
CancelReadBuffer(clientId, aRealEndpoint); |
|
3801 |
} |
|
3802 |
} |
|
3803 |
||
3804 |
||
3805 |
void DUsbClientController::DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum, |
|
3806 |
TTransferDirection aTransferDir) |
|
3807 |
{ |
|
253 | 3808 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK, "DUsbClientController::DeleteRequestCallback()" ); |
0 | 3809 |
// Ep0 OUT |
3810 |
if (aEndpointNum == 0) |
|
3811 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3812 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 3813 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
3814 |
TUsbcRequestCallback* p; |
|
3815 |
while ((p = iter++) != NULL) |
|
3816 |
{ |
|
3817 |
if (p->Owner() == aClientId) |
|
3818 |
{ |
|
3819 |
__ASSERT_DEBUG((p->iRealEpNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
3820 |
__ASSERT_DEBUG((p->iTransferDir == EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
253 | 3821 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK_DUP1, " removing RequestCallback @ 0x%x (ep0)", p); |
0 | 3822 |
iEp0ReadRequestCallbacks.Remove(*p); |
3823 |
} |
|
3824 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3825 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 3826 |
return; |
3827 |
} |
|
3828 |
// Other endpoints |
|
3829 |
TUsbcRequestCallback* const p = iRequestCallbacks[aEndpointNum]; |
|
3830 |
if (p) |
|
3831 |
{ |
|
3832 |
__ASSERT_DEBUG((p->Owner() == aClientId), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
3833 |
__ASSERT_DEBUG((p->iTransferDir == aTransferDir), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
253 | 3834 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK_DUP2, " removing RequestCallback @ 0x%x", p); |
0 | 3835 |
iRequestCallbacks[aEndpointNum] = NULL; |
3836 |
} |
|
3837 |
} |
|
3838 |
||
3839 |
||
3840 |
void DUsbClientController::DeleteRequestCallbacks(const DBase* aClientId) |
|
3841 |
{ |
|
3842 |
// aClientId being NULL means: delete all requests for *all* clients. |
|
253 | 3843 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS, "DUsbClientController::DeleteRequestCallbacks()" ); |
0 | 3844 |
// Ep0 OUT |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3845 |
const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
0 | 3846 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
3847 |
TUsbcRequestCallback* p; |
|
3848 |
while ((p = iter++) != NULL) |
|
3849 |
{ |
|
3850 |
if (!aClientId || p->Owner() == aClientId) |
|
3851 |
{ |
|
253 | 3852 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP1, " removing RequestCallback @ 0x%x (ep0)", p); |
0 | 3853 |
iEp0ReadRequestCallbacks.Remove(*p); |
3854 |
} |
|
3855 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3856 |
__SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
0 | 3857 |
// Other endpoints |
3858 |
for (TInt i = 1; i < KUsbcEpArraySize; i++) |
|
3859 |
{ |
|
3860 |
TUsbcRequestCallback* const p = iRequestCallbacks[i]; |
|
3861 |
if (p && (!aClientId || p->Owner() == aClientId)) |
|
3862 |
{ |
|
253 | 3863 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP2, " removing RequestCallback @ 0x%x", p); |
0 | 3864 |
iRequestCallbacks[i] = NULL; |
3865 |
} |
|
3866 |
} |
|
3867 |
} |
|
3868 |
||
3869 |
||
3870 |
void DUsbClientController::StatusNotify(TUsbcDeviceState aState, const DBase* aClientId) |
|
3871 |
{ |
|
253 | 3872 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_STATUSNOTIFY, "DUsbClientController::StatusNotify()" ); |
0 | 3873 |
|
3874 |
// This function may be called by the PSL (via chapter9.cpp) from within an |
|
3875 |
// ISR -- so we have to take care what we do here (and also in all |
|
3876 |
// functions that get called from here). |
|
3877 |
||
3878 |
TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks); |
|
3879 |
TUsbcStatusCallback* p; |
|
3880 |
while ((p = iter++) != NULL) |
|
3881 |
{ |
|
3882 |
if (!aClientId || aClientId == p->Owner()) |
|
3883 |
{ |
|
253 | 3884 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_STATUSNOTIFY_DUP1, " notifying LDD @ 0x%x about %d", (TUint)p->Owner(), (TUint)aState); |
0 | 3885 |
p->SetState(aState); |
3886 |
p->DoCallback(); |
|
3887 |
} |
|
3888 |
} |
|
3889 |
} |
|
3890 |
||
3891 |
||
3892 |
void DUsbClientController::EpStatusNotify(TInt aRealEndpoint) |
|
3893 |
{ |
|
253 | 3894 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY, "DUsbClientController::EpStatusNotify()" ); |
0 | 3895 |
|
3896 |
// This function may be called by the PSL (via chapter9.cpp) from within an |
|
3897 |
// ISR -- so we have to take care what we do here (and also in all |
|
3898 |
// functions that get called from here). |
|
3899 |
||
3900 |
const DBase* const client_id = PEndpoint2ClientId(aRealEndpoint); |
|
3901 |
if (!client_id) |
|
3902 |
{ |
|
253 | 3903 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP1, " Error: Client not found for real ep %d", aRealEndpoint); |
0 | 3904 |
return; |
3905 |
} |
|
3906 |
// Check if there is a notification request queued for that client (if not, we can return here). |
|
3907 |
TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
|
3908 |
TUsbcEndpointStatusCallback* p; |
|
3909 |
while ((p = iter++) != NULL) |
|
3910 |
{ |
|
3911 |
if (p->Owner() == client_id) |
|
3912 |
{ |
|
3913 |
break; |
|
3914 |
} |
|
3915 |
} |
|
3916 |
if (!p) |
|
3917 |
{ |
|
253 | 3918 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP2, " No notification request for that client, returning"); |
0 | 3919 |
return; |
3920 |
} |
|
3921 |
const TInt ifcset = ClientId2InterfaceNumber(client_id); |
|
3922 |
if (ifcset < 0) |
|
3923 |
{ |
|
253 | 3924 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP3, " Error: Ifcset not found for clientid %d", client_id); |
0 | 3925 |
return; |
3926 |
} |
|
3927 |
const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
|
3928 |
if (!ifcset_ptr) |
|
3929 |
{ |
|
253 | 3930 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP4, " Error: Ifcset pointer not found for ifcset %d", ifcset); |
0 | 3931 |
return; |
3932 |
} |
|
3933 |
const TUsbcInterface* const ifc_ptr = ifcset_ptr->CurrentInterface(); |
|
3934 |
if (!ifc_ptr) |
|
3935 |
{ |
|
253 | 3936 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP5, " Error: Current ifc pointer not found for ifcset %d", ifcset); |
0 | 3937 |
return; |
3938 |
} |
|
3939 |
TUint state = 0; |
|
3940 |
const TInt eps = ifc_ptr->iEndpoints.Count(); |
|
3941 |
for (TInt i = 0; i < eps; i++) |
|
3942 |
{ |
|
3943 |
const TUsbcLogicalEndpoint* const ep_ptr = ifc_ptr->iEndpoints[i]; |
|
253 | 3944 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP6, " checking logical ep #%d for stall state...", |
3945 |
ep_ptr->iLEndpointNum); |
|
0 | 3946 |
if (ep_ptr->iPEndpoint->iHalt) |
3947 |
{ |
|
253 | 3948 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP7, " -- stalled"); |
0 | 3949 |
// set the bit n to 1, where n is the logical endpoint number minus one |
3950 |
state |= (1 << (ep_ptr->iLEndpointNum - 1)); |
|
3951 |
} |
|
3952 |
else |
|
3953 |
{ |
|
253 | 3954 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP8, " -- not stalled"); |
0 | 3955 |
} |
3956 |
} |
|
253 | 3957 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP9, " passing ep state 0x%x on to LDD @ 0x%x", (TUint)state, (TUint)client_id); |
0 | 3958 |
p->SetState(state); |
3959 |
p->DoCallback(); |
|
3960 |
} |
|
3961 |
||
3962 |
||
3963 |
void DUsbClientController::OtgFeaturesNotify() |
|
3964 |
{ |
|
253 | 3965 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGFEATURESNOTIFY, "DUsbClientController::OtgFeaturesNotify()" ); |
0 | 3966 |
|
3967 |
// This function may be called from the PSL (via PIL's chapter9.cpp) from |
|
3968 |
// within an ISR -- so we have to take care what we do here (and also in |
|
3969 |
// all functions that get called from here). |
|
3970 |
||
3971 |
TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks); |
|
3972 |
TUsbcOtgFeatureCallback* p; |
|
3973 |
while ((p = iter++) != NULL) |
|
3974 |
{ |
|
3975 |
p->SetFeatures(iOtgFuncMap & 0x1C); |
|
3976 |
p->DoCallback(); |
|
3977 |
} |
|
3978 |
} |
|
3979 |
||
3980 |
||
3981 |
void DUsbClientController::RunClientCallbacks() |
|
3982 |
{ |
|
253 | 3983 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RUNCLIENTCALLBACKS, "DUsbClientController::RunClientCallbacks()" ); |
0 | 3984 |
TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
3985 |
TUsbcClientCallback* p; |
|
3986 |
while ((p = iter++) != NULL) |
|
3987 |
{ |
|
253 | 3988 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RUNCLIENTCALLBACKS_DUP1, "Callback 0x%x", p); |
0 | 3989 |
p->DoCallback(); |
3990 |
} |
|
3991 |
} |
|
3992 |
||
3993 |
||
3994 |
void DUsbClientController::ProcessDataTransferDone(TUsbcRequestCallback& aRcb) |
|
3995 |
{ |
|
253 | 3996 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSDATATRANSFERDONE, "DUsbClientController::ProcessDataTransferDone()" ); |
0 | 3997 |
// This piece can only be called in thread context from ProcessEp0DataReceived() / |
3998 |
// ProcessEp0SetupReceived() via the call to ProcessEp0ReceiveDone() in |
|
3999 |
// SetupReadBuffer(), which is guarded by an interrupt lock. |
|
4000 |
TInt ep = aRcb.iRealEpNum; |
|
4001 |
if (ep == 0) |
|
4002 |
{ |
|
4003 |
if (aRcb.iTransferDir == EControllerRead) |
|
4004 |
{ |
|
4005 |
// Ep0 OUT is special |
|
4006 |
iEp0ReadRequestCallbacks.Remove(aRcb); |
|
4007 |
} |
|
4008 |
else // EControllerWrite |
|
4009 |
{ |
|
4010 |
// Ep0 IN needs to be adjusted: it's '1' within the PIL. |
|
4011 |
ep = KEp0_Tx; |
|
4012 |
} |
|
4013 |
} |
|
4014 |
if (ep > 0) // not 'else'! |
|
4015 |
{ |
|
4016 |
__ASSERT_DEBUG((iRequestCallbacks[ep] == &aRcb), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
253 | 4017 |
OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSDATATRANSFERDONE_DUP1, " > removing RequestCallback[%d] @ 0x%x", ep, (TUint)&aRcb); |
0 | 4018 |
iRequestCallbacks[ep] = NULL; |
4019 |
} |
|
4020 |
aRcb.DoCallback(); |
|
4021 |
} |
|
4022 |
||
4023 |
||
4024 |
void DUsbClientController::NextDeviceState(TUsbcDeviceState aNextState) |
|
4025 |
{ |
|
253 | 4026 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE, "DUsbClientController::NextDeviceState()" ); |
4027 |
||
0 | 4028 |
#ifdef _DEBUG |
253 | 4029 |
#ifdef OST_TRACE_COMPILER_IN_USE |
0 | 4030 |
const char* const states[] = {"Undefined", "Attached", "Powered", "Default", |
4031 |
"Address", "Configured", "Suspended"}; |
|
253 | 4032 |
#endif |
0 | 4033 |
if ((aNextState >= EUsbcDeviceStateUndefined) && |
4034 |
(aNextState <= EUsbcDeviceStateSuspended)) |
|
4035 |
{ |
|
253 | 4036 |
OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP1, " next device state: %s", states[aNextState]); |
0 | 4037 |
} |
4038 |
else |
|
4039 |
{ |
|
253 | 4040 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP2, " Error: Unknown next device state: %d", aNextState); |
0 | 4041 |
} |
4042 |
// Print a warning when an invalid state transition is detected |
|
4043 |
// 'Undefined' is not a state that is mentioned in the USB spec, but |
|
4044 |
// that's what we're in once the cable gets pulled (for instance). |
|
4045 |
switch (iDeviceState) |
|
4046 |
{ |
|
4047 |
case EUsbcDeviceStateUndefined: |
|
4048 |
// valid: Undefined -> Attached |
|
4049 |
if (aNextState != EUsbcDeviceStateAttached) |
|
4050 |
break; |
|
4051 |
goto OK; |
|
4052 |
case EUsbcDeviceStateAttached: |
|
4053 |
// valid: Attached -> {Undefined, Powered} |
|
4054 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4055 |
(aNextState != EUsbcDeviceStatePowered)) |
|
4056 |
break; |
|
4057 |
goto OK; |
|
4058 |
case EUsbcDeviceStatePowered: |
|
4059 |
// valid: Powered -> {Undefined, Attached, Default, Suspended} |
|
4060 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4061 |
(aNextState != EUsbcDeviceStateAttached) && |
|
4062 |
(aNextState != EUsbcDeviceStateDefault) && |
|
4063 |
(aNextState != EUsbcDeviceStateSuspended)) |
|
4064 |
break; |
|
4065 |
goto OK; |
|
4066 |
case EUsbcDeviceStateDefault: |
|
4067 |
// valid: Default -> {Undefined, Powered, Default, Address, Suspended} |
|
4068 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4069 |
(aNextState != EUsbcDeviceStatePowered) && |
|
4070 |
(aNextState != EUsbcDeviceStateDefault) && |
|
4071 |
(aNextState != EUsbcDeviceStateAddress) && |
|
4072 |
(aNextState != EUsbcDeviceStateSuspended)) |
|
4073 |
break; |
|
4074 |
goto OK; |
|
4075 |
case EUsbcDeviceStateAddress: |
|
4076 |
// valid: Address -> {Undefined, Powered, Default, Configured, Suspended} |
|
4077 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4078 |
(aNextState != EUsbcDeviceStatePowered) && |
|
4079 |
(aNextState != EUsbcDeviceStateDefault) && |
|
4080 |
(aNextState != EUsbcDeviceStateConfigured) && |
|
4081 |
(aNextState != EUsbcDeviceStateSuspended)) |
|
4082 |
break; |
|
4083 |
goto OK; |
|
4084 |
case EUsbcDeviceStateConfigured: |
|
4085 |
// valid: Configured -> {Undefined, Powered, Default, Address, Suspended} |
|
4086 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4087 |
(aNextState != EUsbcDeviceStatePowered) && |
|
4088 |
(aNextState != EUsbcDeviceStateDefault) && |
|
4089 |
(aNextState != EUsbcDeviceStateAddress) && |
|
4090 |
(aNextState != EUsbcDeviceStateSuspended)) |
|
4091 |
break; |
|
4092 |
goto OK; |
|
4093 |
case EUsbcDeviceStateSuspended: |
|
4094 |
// valid: Suspended -> {Undefined, Powered, Default, Address, Configured} |
|
4095 |
if ((aNextState != EUsbcDeviceStateUndefined) && |
|
4096 |
(aNextState != EUsbcDeviceStatePowered) && |
|
4097 |
(aNextState != EUsbcDeviceStateDefault) && |
|
4098 |
(aNextState != EUsbcDeviceStateAddress) && |
|
4099 |
(aNextState != EUsbcDeviceStateConfigured)) |
|
4100 |
break; |
|
4101 |
goto OK; |
|
4102 |
default: |
|
253 | 4103 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP3, " Error: Unknown current device state: %d", iDeviceState); |
0 | 4104 |
goto OK; |
4105 |
} |
|
4106 |
// KUSB only (instead of KPANIC) so as not to worry people too much where |
|
4107 |
// a particular h/w regularly enforces invalid (but harmless) transitions |
|
253 | 4108 |
OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP4, " Warning: Invalid next state from %s", states[iDeviceState]); |
0 | 4109 |
OK: |
4110 |
#endif // _DEBUG |
|
4111 |
||
4112 |
iDeviceState = aNextState; |
|
4113 |
StatusNotify(iDeviceState); |
|
4114 |
} |
|
4115 |
||
4116 |
||
4117 |
TInt DUsbClientController::ProcessSuspendEvent() |
|
4118 |
{ |
|
253 | 4119 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENT, "DUsbClientController::ProcessSuspendEvent()" ); |
0 | 4120 |
// A suspend interrupt has been received and needs attention. |
4121 |
iDeviceStateB4Suspend = iDeviceState; |
|
4122 |
// We have to move to the Suspend state immediately (in case it's a genuine Suspend) |
|
4123 |
// because 7.1.7.6 says: "The device must actually be suspended, [...] after no more |
|
4124 |
// than 10ms of bus inactivity [...]." Assuming we got the interrupt 3ms after the |
|
4125 |
// Suspend condition arose, we have now 7ms left. |
|
4126 |
NextDeviceState(EUsbcDeviceStateSuspended); |
|
4127 |
Suspend(); |
|
4128 |
// For some reason we get this interrupt also when the USB cable has been pulled. |
|
4129 |
// So we want to see if that is the case in order to move to the Undefined state instead. |
|
4130 |
// However, instead of immediately checking the status of the USB cable we wait for a |
|
4131 |
// short moment (KUsbCableStatusDelay, see top of file), until things have become stable. |
|
4132 |
// Then, in the timer callback, we can change the device state once more if necessary. |
|
4133 |
iCableStatusTimer.OneShot(KUsbCableStatusDelay); |
|
4134 |
return KErrNone; |
|
4135 |
} |
|
4136 |
||
4137 |
||
4138 |
// |
|
4139 |
// ISR (from CableStatusTimerCallback) |
|
4140 |
// |
|
4141 |
TInt DUsbClientController::ProcessSuspendEventProceed() |
|
4142 |
{ |
|
253 | 4143 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENTPROCEED, "DUsbClientController::ProcessSuspendEventProceed()" ); |
0 | 4144 |
if (!UsbConnectionStatus()) |
4145 |
{ |
|
4146 |
// If we are no longer connected to the bus, we go into Undefined state (from Suspend). |
|
253 | 4147 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENTPROCEED_DUP1, " > USB cable detached" ); |
0 | 4148 |
NextDeviceState(EUsbcDeviceStateUndefined); |
4149 |
} |
|
4150 |
return KErrNone; |
|
4151 |
} |
|
4152 |
||
4153 |
||
4154 |
TInt DUsbClientController::ProcessResumeEvent() |
|
4155 |
{ |
|
253 | 4156 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSRESUMEEVENT, "DUsbClientController::ProcessResumeEvent()" ); |
0 | 4157 |
iCableStatusTimer.Cancel(); |
4158 |
if (iDeviceState == EUsbcDeviceStateSuspended) |
|
4159 |
{ |
|
4160 |
NextDeviceState(iDeviceStateB4Suspend); |
|
4161 |
} |
|
4162 |
Resume(); |
|
4163 |
return KErrNone; |
|
4164 |
} |
|
4165 |
||
4166 |
||
4167 |
TInt DUsbClientController::ProcessResetEvent(TBool aPslUpcall) |
|
4168 |
{ |
|
253 | 4169 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT, "DUsbClientController::ProcessResetEvent()" ); |
0 | 4170 |
|
4171 |
if (aPslUpcall) |
|
4172 |
{ |
|
4173 |
// Call back into PSL if we're coming from there. |
|
4174 |
// Also, do it always, even when PIL processing will be deferred. |
|
4175 |
Reset(); |
|
4176 |
} |
|
4177 |
#ifdef USB_OTG_CLIENT |
|
4178 |
if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue) |
|
4179 |
{ |
|
253 | 4180 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP1, " User-side (still) not ready -> returning" ); |
0 | 4181 |
return KErrNone; |
4182 |
} |
|
4183 |
else if (iOtgHnpHandledByHw && !iClientSupportReady) |
|
4184 |
{ |
|
4185 |
// Wait with the PIL Reset processing until user-side is ready |
|
253 | 4186 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP2, " User-side not ready -> deferring" ); |
0 | 4187 |
iUsbResetDeferred = ETrue; |
4188 |
return KErrNone; |
|
4189 |
} |
|
4190 |
#endif // USB_OTG_CLIENT |
|
4191 |
||
4192 |
iCableStatusTimer.Cancel(); |
|
4193 |
if (iDeviceState == EUsbcDeviceStateAttached) |
|
4194 |
{ |
|
4195 |
NextDeviceState(EUsbcDeviceStatePowered); |
|
4196 |
} |
|
4197 |
// Notify the world. (This will just queue a DFC, so users won't actually be |
|
4198 |
// notified before we return. But we change the device state already here so |
|
4199 |
// ChangeConfiguration will see the correct one.) |
|
4200 |
NextDeviceState(EUsbcDeviceStateDefault); |
|
4201 |
// Tear down the current configuration (never called from thread) |
|
4202 |
ChangeConfiguration(0); |
|
4203 |
// Reset essential vars |
|
4204 |
iRmWakeupStatus_Enabled = EFalse; |
|
4205 |
ResetEp0DataOutVars(); |
|
4206 |
iEp0_RxExtraData = EFalse; |
|
4207 |
iEp0WritePending = EFalse; |
|
4208 |
iEp0ClientDataTransmitting = EFalse; |
|
4209 |
// Reset OTG features, leave attributes as is |
|
4210 |
iOtgFuncMap &= KUsbOtgAttr_SrpSupp | KUsbOtgAttr_HnpSupp; |
|
4211 |
if (iOtgSupport) |
|
4212 |
{ |
|
4213 |
OtgFeaturesNotify(); |
|
4214 |
} |
|
4215 |
||
4216 |
// Check whether there's a speed change |
|
4217 |
const TBool was_hs = iHighSpeed; |
|
4218 |
iHighSpeed = CurrentlyUsingHighSpeed(); |
|
4219 |
if (!was_hs && iHighSpeed) |
|
4220 |
{ |
|
253 | 4221 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP3, " Moving to High-speed" ); |
0 | 4222 |
EnterHighSpeed(); |
4223 |
} |
|
4224 |
else if (was_hs && !iHighSpeed) |
|
4225 |
{ |
|
253 | 4226 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP4, " Moving to Full-speed" ); |
0 | 4227 |
EnterFullSpeed(); |
4228 |
} |
|
4229 |
||
4230 |
// Setup initial Ep0 read (SetupEndpointZeroRead never called from thread) |
|
4231 |
if (SetupEndpointZeroRead() != KErrNone) |
|
4232 |
{ |
|
253 | 4233 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP5, " Error: while setting up Ep0 read" ); |
0 | 4234 |
return KErrGeneral; |
4235 |
} |
|
4236 |
||
4237 |
return KErrNone; |
|
4238 |
} |
|
4239 |
||
4240 |
||
4241 |
TInt DUsbClientController::ProcessCableInsertEvent() |
|
4242 |
{ |
|
253 | 4243 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT, "DUsbClientController::ProcessCableInsertEvent()" ); |
4244 |
||
0 | 4245 |
#ifdef USB_OTG_CLIENT |
253 | 4246 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT_DUP1, " Error: EUsbEventCableInsert shouldn't be sent by an OTG Client PSL" ); |
0 | 4247 |
return KErrArgument; |
4248 |
#else |
|
4249 |
NextDeviceState(EUsbcDeviceStateAttached); |
|
4250 |
if (iHardwareActivated) |
|
4251 |
{ |
|
4252 |
NextDeviceState(EUsbcDeviceStatePowered); |
|
4253 |
} |
|
4254 |
return KErrNone; |
|
4255 |
#endif // #ifdef USB_OTG_CLIENT |
|
4256 |
} |
|
4257 |
||
4258 |
||
4259 |
TInt DUsbClientController::ProcessCableRemoveEvent() |
|
4260 |
{ |
|
253 | 4261 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSCABLEREMOVEEVENT, "DUsbClientController::ProcessCableRemoveEvent()" ); |
0 | 4262 |
#ifdef USB_OTG_CLIENT |
253 | 4263 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSCABLEREMOVEEVENT_DUP1, " Error: EUsbEventCableRemoved shouldn't be sent by an OTG Client PSL" ); |
0 | 4264 |
return KErrArgument; |
4265 |
#else |
|
4266 |
// Tear down the current configuration (if any) |
|
4267 |
ChangeConfiguration(0); |
|
4268 |
NextDeviceState(EUsbcDeviceStateUndefined); |
|
4269 |
return KErrNone; |
|
4270 |
#endif // #ifdef USB_OTG_CLIENT |
|
4271 |
} |
|
4272 |
||
4273 |
||
4274 |
void DUsbClientController::EnterFullSpeed() |
|
4275 |
{ |
|
253 | 4276 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENTERFULLSPEED, "DUsbClientController::EnterFullSpeed()" ); |
0 | 4277 |
iDescriptors.UpdateDescriptorsFs(); |
4278 |
} |
|
4279 |
||
4280 |
||
4281 |
void DUsbClientController::EnterHighSpeed() |
|
4282 |
{ |
|
253 | 4283 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENTERHIGHSPEED, "DUsbClientController::EnterHighSpeed()" ); |
0 | 4284 |
iDescriptors.UpdateDescriptorsHs(); |
4285 |
} |
|
4286 |
||
4287 |
||
4288 |
// |
|
4289 |
// Called whenever either iOtgClientConnect or iClientSupportReady changes value. |
|
4290 |
// |
|
4291 |
TInt DUsbClientController::EvaluateOtgConnectFlags() |
|
4292 |
{ |
|
253 | 4293 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS, "DUsbClientController::EvaluateOtgConnectFlags()" ); |
0 | 4294 |
|
4295 |
TInt r = KErrNone; |
|
4296 |
||
4297 |
// Check to see if the current flag states result in a change to the |
|
4298 |
// need to activate the DPLUS pull-up |
|
4299 |
TBool enableDPlus; |
|
4300 |
if (!iOtgHnpHandledByHw) |
|
4301 |
{ |
|
4302 |
// the default |
|
4303 |
enableDPlus = (iOtgClientConnect && iClientSupportReady); |
|
4304 |
} |
|
4305 |
else |
|
4306 |
{ |
|
4307 |
// certain h/w: handles HNP connect/disconnect automatically |
|
253 | 4308 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP1, " HNP-handling h/w: only considering user-side readiness" ); |
0 | 4309 |
enableDPlus = iClientSupportReady; |
4310 |
} |
|
4311 |
||
4312 |
if (enableDPlus == iDPlusEnabled) |
|
4313 |
{ |
|
4314 |
return r; |
|
4315 |
} |
|
4316 |
||
4317 |
// There has been a changed requirement that must be serviced... |
|
4318 |
if (enableDPlus) |
|
4319 |
{ |
|
253 | 4320 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP2, " calling (*iEnablePullUpOnDPlus)()" ); |
0 | 4321 |
if (iEnablePullUpOnDPlus != NULL) |
4322 |
{ |
|
4323 |
iDPlusEnabled = enableDPlus; |
|
4324 |
// First we move to Suspend state to trigger a state change |
|
4325 |
// notification in any case, even if no cable and/or host are |
|
4326 |
// connected. The next Reset will get us out of it again. |
|
4327 |
iDeviceStateB4Suspend = iDeviceState; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4328 |
// Please pay attention to that the above comment now is not accurate! |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4329 |
// It's not updated according the below modification just for keeping the original comment! |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4330 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4331 |
// Moving to Suspend state arbitrarily will cause DEFECT EDHO-7Y3AAD. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4332 |
// DEFECT EDHO-7Y3AAD: Connected to the USB Charger, the UI displayed wrongly connected as default mode |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4333 |
// since the iDeviceState changed wrongly from Undefined to Suspended, and keep |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4334 |
// always Suspended becauseof NO Reset coming next! |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4335 |
// So, to fix this defect, the state change notification is modified to be triggerred by loop the current state again |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4336 |
// if the current state is Undefined! |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4337 |
if (EUsbcDeviceStateUndefined != iDeviceState) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4338 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4339 |
NextDeviceState(EUsbcDeviceStateSuspended); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4340 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4341 |
else |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4342 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4343 |
NextDeviceState(iDeviceState); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4344 |
} |
0 | 4345 |
r = (*iEnablePullUpOnDPlus)(iOtgContext); |
4346 |
if (r != KErrNone) |
|
4347 |
{ |
|
253 | 4348 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP3, " Error: iEnablePullUpOnDPlus() = %d", r); |
0 | 4349 |
} |
4350 |
} |
|
4351 |
else |
|
4352 |
{ |
|
253 | 4353 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP4, " Warning: iEnablePullUpOnDPlus pointer not ready"); |
0 | 4354 |
// We cannot enforce the presence of the pointer (via an ASSERT) |
4355 |
// since it might only be available at a later point. |
|
4356 |
// We shouldn't return an error at this point either, since the |
|
4357 |
// problem will be a systematic one. |
|
4358 |
} |
|
4359 |
} |
|
4360 |
else |
|
4361 |
{ |
|
253 | 4362 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP5, " calling (*iDisablePullUpOnDPlus)()"); |
0 | 4363 |
if (iDisablePullUpOnDPlus != NULL) |
4364 |
{ |
|
4365 |
iDPlusEnabled = enableDPlus; |
|
4366 |
r = (*iDisablePullUpOnDPlus)(iOtgContext); |
|
4367 |
if (r != KErrNone) |
|
4368 |
{ |
|
253 | 4369 |
OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP6, " Error: iDisablePullUpOnDPlus() = %d", r); |
0 | 4370 |
} |
4371 |
} |
|
4372 |
else |
|
4373 |
{ |
|
253 | 4374 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP7, " Warning: iDisablePullUpOnDPlus pointer not ready"); |
0 | 4375 |
// We cannot enforce the presence of the pointer (via an ASSERT) |
4376 |
// since it might only be available at a later point. |
|
4377 |
// We shouldn't return an error at this point either, since the |
|
4378 |
// problem will be a systematic one. |
|
4379 |
} |
|
4380 |
} |
|
4381 |
return r; |
|
4382 |
} |
|
4383 |
||
4384 |
||
4385 |
// |
|
4386 |
// DFC (static) |
|
4387 |
// |
|
4388 |
void DUsbClientController::ReconnectTimerCallback(TAny *aPtr) |
|
4389 |
{ |
|
253 | 4390 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RECONNECTTIMERCALLBACK, "DUsbClientController::ReconnectTimerCallback()" ); |
0 | 4391 |
if (!aPtr) |
4392 |
{ |
|
253 | 4393 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RECONNECTTIMERCALLBACK_DUP1, " Error: !aPtr"); |
0 | 4394 |
return; |
4395 |
} |
|
4396 |
DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
|
4397 |
ptr->UsbConnect(); |
|
4398 |
} |
|
4399 |
||
4400 |
||
4401 |
// |
|
4402 |
// ISR (static) |
|
4403 |
// |
|
4404 |
void DUsbClientController::CableStatusTimerCallback(TAny *aPtr) |
|
4405 |
{ |
|
253 | 4406 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CABLESTATUSTIMERCALLBACK, "DUsbClientController::CableStatusTimerCallback()" ); |
0 | 4407 |
if (!aPtr) |
4408 |
{ |
|
253 | 4409 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CABLESTATUSTIMERCALLBACK_DUP1, " Error: !aPtr" ); |
0 | 4410 |
return; |
4411 |
} |
|
4412 |
DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
|
4413 |
ptr->ProcessSuspendEventProceed(); |
|
4414 |
} |
|
4415 |
||
4416 |
||
4417 |
// |
|
4418 |
// static |
|
4419 |
// |
|
4420 |
void DUsbClientController::PowerUpDfc(TAny* aPtr) |
|
4421 |
{ |
|
253 | 4422 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUPDFC, "DUsbClientController::PowerUpDfc" ); |
0 | 4423 |
if (!aPtr) |
4424 |
{ |
|
253 | 4425 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERUPDFC_DUP1, " Error: !aPtr" ); |
0 | 4426 |
return; |
4427 |
} |
|
4428 |
DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
|
4429 |
__PM_ASSERT(ptr->iStandby); |
|
4430 |
(void) ptr->PowerUp(); |
|
4431 |
ptr->iStandby = EFalse; |
|
4432 |
ptr->iPowerHandler->PowerUpDone(); |
|
4433 |
} |
|
4434 |
||
4435 |
||
4436 |
// |
|
4437 |
// static |
|
4438 |
// |
|
4439 |
void DUsbClientController::PowerDownDfc(TAny* aPtr) |
|
4440 |
{ |
|
253 | 4441 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNDFC, "DUsbClientController::PowerDownDfc" ); |
0 | 4442 |
if (!aPtr) |
4443 |
{ |
|
253 | 4444 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP1, " Error: !aPtr" ); |
0 | 4445 |
return; |
4446 |
} |
|
4447 |
DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
|
4448 |
__PM_ASSERT(!ptr->iStandby); |
|
4449 |
ptr->iStandby = ETrue; |
|
4450 |
// We might not want to power down when the UDC is active: |
|
4451 |
if (!ptr->iHardwareActivated || ptr->PowerDownWhenActive()) |
|
4452 |
{ |
|
4453 |
(void) ptr->PowerDown(); |
|
253 | 4454 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP2, "Calling PowerHandler->PowerDownDone()" ); |
0 | 4455 |
ptr->iPowerHandler->PowerDownDone(); |
4456 |
} |
|
4457 |
else |
|
4458 |
{ |
|
253 | 4459 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP3, "Not calling PowerHandler->PowerDownDone()" ); |
4460 |
OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP4, " because UDC is active." ); |
|
0 | 4461 |
} |
4462 |
} |
|
4463 |
||
4464 |
||
4465 |
// -EOF- |