author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
44 | 1 |
// Copyright (c) 2000-2009 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/chapter9.cpp |
|
15 |
// Platform independent layer (PIL) of the USB Device controller driver: |
|
16 |
// Processing of USB spec chapter 9 standard requests. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
/** |
|
21 |
@file chapter9.cpp |
|
22 |
@internalTechnology |
|
23 |
*/ |
|
24 |
||
25 |
#include <drivers/usbc.h> |
|
26 |
||
27 |
||
28 |
//#define ENABLE_EXCESSIVE_DEBUG_OUTPUT |
|
29 |
||
30 |
// |
|
31 |
// The way functions are called after an request has been completed by the PSL: |
|
32 |
// |
|
33 |
// Ep0RequestComplete |
|
34 |
// | |
|
35 |
// ------------------------------------------------ |
|
36 |
// | | |
|
37 |
// ProcessEp0ReceiveDone ProcessEp0TransmitDone |
|
38 |
// | | |
|
39 |
// --------------------------------------- | |
|
40 |
// | | | |
|
41 |
// ProcessEp0SetupReceived ProcessEp0DataReceived ProcessDataTransferDone |
|
42 |
// | | |
|
43 |
// --------------------- --------------- |
|
44 |
// | | | | |
|
45 |
// ProcessXXX ProcessDataTransferDone ProceedXXX ProcessDataTransferDone |
|
46 |
// |
|
47 |
// XXX = Specific_Request |
|
48 |
// |
|
49 |
||
50 |
// |
|
51 |
// === USB Controller member function implementation - PSL API (protected) ======================== |
|
52 |
// |
|
53 |
||
54 |
/** Used to synchronize the Ep0 state machine between the PSL and PIL. |
|
55 |
Accepts a SETUP packet and returns the next Ep0 state. |
|
56 |
||
57 |
@param aSetupBuf The SETUP packet just received by the PSL. |
|
58 |
@return The next Ep0 state. |
|
59 |
||
60 |
@publishedPartner @released |
|
61 |
*/ |
|
62 |
TUsbcEp0State DUsbClientController::EnquireEp0NextState(const TUint8* aSetupBuf) const |
|
63 |
{ |
|
44 | 64 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnquireEp0NextState()")); |
0 | 65 |
|
66 |
// This function may be called by the PSL from within an ISR -- so we have |
|
67 |
// to take care what we do here (and also in all functions that get called |
|
68 |
// from here). |
|
69 |
||
70 |
if (SWAP_BYTES_16((reinterpret_cast<const TUint16*>(aSetupBuf)[3])) == 0) // iLength |
|
71 |
{ |
|
44 | 72 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateStatusIn")); |
0 | 73 |
return EEp0StateStatusIn; // No-data Control => Status_IN |
74 |
} |
|
75 |
else if ((aSetupBuf[0] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev) |
|
76 |
{ |
|
44 | 77 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateDataOut")); |
0 | 78 |
return EEp0StateDataOut; // Control Write => Data_OUT |
79 |
} |
|
80 |
else |
|
81 |
{ |
|
44 | 82 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateDataIn")); |
0 | 83 |
return EEp0StateDataIn; // Control Read => Data_IN |
84 |
} |
|
85 |
} |
|
86 |
||
87 |
||
88 |
TInt DUsbClientController::ProcessEp0ReceiveDone(TInt aCount) |
|
89 |
{ |
|
44 | 90 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessEp0ReceiveDone()")); |
0 | 91 |
TInt r; |
92 |
if (iEp0DataReceiving == EFalse) |
|
93 |
{ |
|
94 |
// It's obviously a Setup packet, so... |
|
95 |
r = ProcessEp0SetupReceived(aCount); |
|
96 |
} |
|
97 |
else |
|
98 |
{ |
|
99 |
// If it isn't a Setup, it must be data... |
|
100 |
// (This is actually not quite true, as it could also be - in theory - a new Setup packet |
|
101 |
// when the host has abandoned, for whatever reason, the previous one which was still |
|
102 |
// in progress. However no such case is known to have occurred with this driver, or at |
|
103 |
// least it didn't lead to problems. |
|
104 |
// Some UDCs have a dedicated interrupt for Setup packets, but so far this driver hasn't |
|
105 |
// made use of such a feature (as it would require a PSL/PIL API change).) |
|
106 |
r = ProcessEp0DataReceived(aCount); |
|
107 |
} |
|
108 |
return r; |
|
109 |
} |
|
110 |
||
111 |
||
112 |
TInt DUsbClientController::ProcessEp0TransmitDone(TInt aCount, TInt aError) |
|
113 |
{ |
|
44 | 114 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessEp0TransmitDone()")); |
0 | 115 |
// In any case: there's now no longer a write pending |
116 |
iEp0WritePending = EFalse; |
|
117 |
// If it was a client who set up this transmission, we report to that client |
|
118 |
if (iEp0ClientDataTransmitting) |
|
119 |
{ |
|
120 |
iEp0ClientDataTransmitting = EFalse; |
|
121 |
TUsbcRequestCallback* const p = iRequestCallbacks[KEp0_Tx]; |
|
122 |
if (p) |
|
123 |
{ |
|
124 |
__ASSERT_DEBUG((p->iTransferDir == EControllerWrite), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
125 |
p->iError = aError; |
|
126 |
p->iTxBytes = aCount; |
|
127 |
ProcessDataTransferDone(*p); |
|
128 |
return KErrNone; |
|
129 |
} |
|
44 | 130 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: DUsbClientController::ProcessEpTransmitDone: Stalling Ep0")); |
0 | 131 |
StallEndpoint(KEp0_In); // request not found |
132 |
return KErrNotFound; |
|
133 |
} |
|
134 |
// If _we_ sent the data, we simply do nothing here... |
|
135 |
return KErrNone; |
|
136 |
} |
|
137 |
||
44 | 138 |
|
139 |
#define USB_PROCESS_REQUEST(request) \ |
|
140 |
if (Process ## request(packet) != KErrNone) \ |
|
141 |
{ \ |
|
142 |
__KTRACE_OPT(KUSB, \ |
|
143 |
Kern::Printf(" ProcessEp0SetupReceived: Stalling Ep0")); \ |
|
144 |
StallEndpoint(KEp0_In); \ |
|
145 |
} |
|
146 |
||
0 | 147 |
TInt DUsbClientController::ProcessEp0SetupReceived(TInt aCount) |
148 |
{ |
|
44 | 149 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessEp0SetupReceived()")); |
0 | 150 |
|
151 |
if (aCount > iEp0MaxPacketSize) |
|
152 |
{ |
|
153 |
// Fatal error: too much data! |
|
154 |
aCount = iEp0MaxPacketSize; |
|
155 |
} |
|
156 |
||
157 |
// first we split the data into meaningful units: |
|
158 |
TUsbcSetup packet; |
|
159 |
Buffer2Setup(iEp0_RxBuf, packet); |
|
160 |
||
161 |
#if defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
|
162 |
// let's see what we've got: |
|
44 | 163 |
__KTRACE_OPT(KUSB, Kern::Printf(" bmRequestType = 0x%02x", packet.iRequestType)); |
0 | 164 |
if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
165 |
{ |
|
166 |
switch (packet.iRequest) |
|
167 |
{ |
|
168 |
case KUsbRequest_GetStatus: |
|
44 | 169 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_STATUS)", |
170 |
KUsbRequest_GetStatus)); |
|
0 | 171 |
break; |
172 |
case KUsbRequest_ClearFeature: |
|
44 | 173 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (CLEAR_FEATURE)", |
174 |
KUsbRequest_ClearFeature)); |
|
0 | 175 |
break; |
176 |
case KUsbRequest_SetFeature: |
|
44 | 177 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_FEATURE)", |
178 |
KUsbRequest_SetFeature)); |
|
0 | 179 |
break; |
180 |
case KUsbRequest_SetAddress: |
|
44 | 181 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_ADDRESS)", |
182 |
KUsbRequest_SetAddress)); |
|
0 | 183 |
break; |
184 |
case KUsbRequest_GetDescriptor: |
|
44 | 185 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_DESCRIPTOR)", |
186 |
KUsbRequest_GetDescriptor)); |
|
0 | 187 |
break; |
188 |
case KUsbRequest_SetDescriptor: |
|
44 | 189 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_DESCRIPTOR)", |
190 |
KUsbRequest_SetDescriptor)); |
|
0 | 191 |
break; |
192 |
case KUsbRequest_GetConfig: |
|
44 | 193 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_CONFIGURATION)", |
194 |
KUsbRequest_GetConfig)); |
|
0 | 195 |
break; |
196 |
case KUsbRequest_SetConfig: |
|
44 | 197 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_CONFIGURATION)", |
198 |
KUsbRequest_SetConfig)); |
|
0 | 199 |
break; |
200 |
case KUsbRequest_GetInterface: |
|
44 | 201 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_INTERFACE)", |
202 |
KUsbRequest_GetInterface)); |
|
0 | 203 |
break; |
204 |
case KUsbRequest_SetInterface: |
|
44 | 205 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_INTERFACE)", |
206 |
KUsbRequest_SetInterface)); |
|
0 | 207 |
break; |
208 |
case KUsbRequest_SynchFrame: |
|
44 | 209 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SYNCH_FRAME)", |
210 |
KUsbRequest_SynchFrame)); |
|
0 | 211 |
break; |
212 |
default: |
|
44 | 213 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: bRequest = 0x%02x (UNKNWON STANDARD REQUEST)", |
214 |
packet.iRequest)); |
|
0 | 215 |
break; |
216 |
} |
|
217 |
} |
|
218 |
else |
|
219 |
{ |
|
44 | 220 |
__KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (NON-STANDARD REQUEST)", |
221 |
packet.iRequest)); |
|
0 | 222 |
} |
44 | 223 |
__KTRACE_OPT(KUSB, Kern::Printf(" wValue = 0x%04x", packet.iValue)); |
224 |
__KTRACE_OPT(KUSB, Kern::Printf(" wIndex = 0x%04x", packet.iIndex)); |
|
225 |
__KTRACE_OPT(KUSB, Kern::Printf(" wLength = 0x%04x", packet.iLength)); |
|
0 | 226 |
#endif // defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
227 |
||
228 |
// now the actual analysis |
|
229 |
if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
|
230 |
{ |
|
231 |
iEp0ReceivedNonStdRequest = EFalse; |
|
232 |
switch (packet.iRequest) |
|
233 |
{ |
|
234 |
case KUsbRequest_GetStatus: |
|
235 |
switch (packet.iRequestType & KUsbRequestType_DestMask) |
|
236 |
{ // Recipient |
|
237 |
case KUsbRequestType_DestDevice: |
|
44 | 238 |
USB_PROCESS_REQUEST(GetDeviceStatus); |
0 | 239 |
break; |
240 |
case KUsbRequestType_DestIfc: |
|
44 | 241 |
USB_PROCESS_REQUEST(GetInterfaceStatus); |
0 | 242 |
break; |
243 |
case KUsbRequestType_DestEp: |
|
44 | 244 |
USB_PROCESS_REQUEST(GetEndpointStatus); |
0 | 245 |
break; |
246 |
default: |
|
44 | 247 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: GET STATUS - Other or Unknown recipient")); |
248 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> DUsbClientController::ProcessEp0SetupReceived: " |
|
249 |
"Stalling Ep0")); |
|
0 | 250 |
StallEndpoint(KEp0_In); |
251 |
break; |
|
252 |
} |
|
253 |
break; |
|
254 |
case KUsbRequest_ClearFeature: |
|
255 |
case KUsbRequest_SetFeature: |
|
256 |
switch (packet.iRequestType & KUsbRequestType_DestMask) |
|
257 |
{ // Recipient |
|
258 |
case KUsbRequestType_DestDevice: |
|
44 | 259 |
USB_PROCESS_REQUEST(SetClearDevFeature); |
0 | 260 |
break; |
261 |
case KUsbRequestType_DestIfc: |
|
44 | 262 |
USB_PROCESS_REQUEST(SetClearIfcFeature); |
0 | 263 |
break; |
264 |
case KUsbRequestType_DestEp: |
|
44 | 265 |
USB_PROCESS_REQUEST(SetClearEpFeature); |
0 | 266 |
break; |
267 |
default: |
|
44 | 268 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: SET/CLEAR FEATURE - " |
269 |
"Other or Unknown recipient")); |
|
270 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0")); |
|
0 | 271 |
StallEndpoint(KEp0_In); |
272 |
break; |
|
273 |
} |
|
274 |
break; |
|
275 |
case KUsbRequest_SetAddress: |
|
44 | 276 |
USB_PROCESS_REQUEST(SetAddress); |
0 | 277 |
break; |
278 |
case KUsbRequest_GetDescriptor: |
|
44 | 279 |
USB_PROCESS_REQUEST(GetDescriptor); |
0 | 280 |
break; |
281 |
case KUsbRequest_SetDescriptor: |
|
44 | 282 |
USB_PROCESS_REQUEST(SetDescriptor); |
0 | 283 |
break; |
284 |
case KUsbRequest_GetConfig: |
|
44 | 285 |
USB_PROCESS_REQUEST(GetConfiguration); |
0 | 286 |
break; |
287 |
case KUsbRequest_SetConfig: |
|
44 | 288 |
USB_PROCESS_REQUEST(SetConfiguration); |
0 | 289 |
break; |
290 |
case KUsbRequest_GetInterface: |
|
44 | 291 |
USB_PROCESS_REQUEST(GetInterface); |
0 | 292 |
break; |
293 |
case KUsbRequest_SetInterface: |
|
44 | 294 |
USB_PROCESS_REQUEST(SetInterface); |
0 | 295 |
break; |
296 |
case KUsbRequest_SynchFrame: |
|
44 | 297 |
USB_PROCESS_REQUEST(SynchFrame); |
0 | 298 |
break; |
299 |
default: |
|
44 | 300 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown/unsupported Std Setup Request")); |
301 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0")); |
|
0 | 302 |
StallEndpoint(KEp0_In); |
303 |
break; |
|
304 |
} |
|
305 |
} |
|
306 |
else |
|
307 |
{ |
|
308 |
// Type mask != KUsbRequestType_TypeStd => class- or vendor-specific request |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
iEp0ReceivedNonStdRequest = ETrue; |
0 | 310 |
const DBase* client = NULL; |
311 |
switch (packet.iRequestType & KUsbRequestType_DestMask) |
|
312 |
{ // Recipient |
|
313 |
case KUsbRequestType_DestDevice: |
|
314 |
client = iEp0DeviceControl; |
|
315 |
break; |
|
316 |
case KUsbRequestType_DestIfc: |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
//Add this mutex to protect the interface set data structure |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
NKern::FMWait(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
} |
0 | 322 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
323 |
{ |
|
44 | 324 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 325 |
} |
326 |
else |
|
327 |
{ |
|
328 |
const TUsbcInterfaceSet* const ifcset_ptr = |
|
329 |
InterfaceNumber2InterfacePointer(packet.iIndex); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
//In some rare case, ifcset_ptr is not NULL but the ifcset_ptr->iInterfaces.Count() is 0, |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
//so panic will happen when excute the following line. so I add the conditon |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
//0 != ifcset_ptr->iInterfaces.Count() here. |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
if (ifcset_ptr && 0 != ifcset_ptr->iInterfaces.Count()) |
0 | 334 |
{ |
335 |
if (ifcset_ptr->CurrentInterface()->iNoEp0Requests) |
|
336 |
{ |
|
44 | 337 |
__KTRACE_OPT(KUSB, Kern::Printf(" Recipient says: NoEp0RequestsPlease")); |
0 | 338 |
} |
339 |
else |
|
340 |
{ |
|
341 |
client = ifcset_ptr->iClientId; |
|
342 |
} |
|
343 |
} |
|
344 |
else |
|
345 |
{ |
|
44 | 346 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface 0x%02x does not exist", |
347 |
packet.iIndex)); |
|
0 | 348 |
} |
349 |
} |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
NKern::FMSignal(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
} |
0 | 354 |
break; |
355 |
case KUsbRequestType_DestEp: |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
//Add this mutex to protect the interface set data structure |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
NKern::FMWait(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
} |
0 | 361 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
362 |
{ |
|
44 | 363 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 364 |
} |
365 |
else if (EndpointExists(packet.iIndex) == EFalse) |
|
366 |
{ |
|
44 | 367 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint 0x%02x does not exist", |
368 |
packet.iIndex)); |
|
0 | 369 |
} |
370 |
else |
|
371 |
{ |
|
372 |
const TInt idx = EpAddr2Idx(packet.iIndex); |
|
373 |
const TUsbcInterfaceSet* const ifcset_ptr = |
|
374 |
iRealEndpoints[idx].iLEndpoint->iInterface->iInterfaceSet; |
|
375 |
if (ifcset_ptr->CurrentInterface()->iNoEp0Requests) |
|
376 |
{ |
|
44 | 377 |
__KTRACE_OPT(KUSB, Kern::Printf(" Recipient says: NoEp0RequestsPlease")); |
0 | 378 |
} |
379 |
else |
|
380 |
{ |
|
381 |
client = ifcset_ptr->iClientId; |
|
382 |
} |
|
383 |
} |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
NKern::FMSignal(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
} |
0 | 388 |
break; |
389 |
default: |
|
44 | 390 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Other or Unknown recipient")); |
0 | 391 |
break; |
392 |
} |
|
393 |
if (client != NULL) |
|
394 |
{ |
|
395 |
// Try to relay packet to the appropriate recipient |
|
396 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
|
397 |
TUsbcRequestCallback* p; |
|
398 |
while ((p = iter++) != NULL) |
|
399 |
{ |
|
400 |
if (p->Owner() == client) |
|
401 |
{ |
|
402 |
__ASSERT_DEBUG((p->iEndpointNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
403 |
__ASSERT_DEBUG((p->iTransferDir == EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
44 | 404 |
__KTRACE_OPT(KUSB, Kern::Printf(" Found Ep0 read request")); |
0 | 405 |
if (packet.iLength != 0) |
406 |
{ |
|
407 |
if ((packet.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev) |
|
408 |
{ |
|
409 |
// Data transfer & direction OUT => there'll be a DATA_OUT stage |
|
44 | 410 |
__KTRACE_OPT(KUSB, Kern::Printf(" Next is DATA_OUT: setting up DataOutVars")); |
0 | 411 |
SetEp0DataOutVars(packet, client); |
412 |
} |
|
413 |
else if ((packet.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToHost) |
|
414 |
{ |
|
415 |
// For possible later use (ZLP). |
|
416 |
iEp0_TxNonStdCount = packet.iLength; |
|
417 |
} |
|
418 |
} |
|
419 |
memcpy(p->iBufferStart, iEp0_RxBuf, aCount); |
|
420 |
p->iError = KErrNone; // if it wasn't 'KErrNone' we wouldn't be here |
|
421 |
*(p->iPacketSize) = aCount; |
|
422 |
p->iRxPackets = 1; |
|
423 |
*(p->iPacketIndex) = 0; |
|
424 |
ProcessDataTransferDone(*p); |
|
425 |
return KErrNone; |
|
426 |
} |
|
427 |
} |
|
44 | 428 |
__KTRACE_OPT(KUSB, Kern::Printf(" Ep0 read request not found: setting RxExtra vars (Setup)")); |
0 | 429 |
iEp0_RxExtraCount = aCount; |
430 |
iEp0_RxExtraData = ETrue; |
|
431 |
return KErrNotFound; |
|
432 |
} |
|
433 |
else // if (client == NULL) |
|
434 |
{ |
|
44 | 435 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Ep0 request error: Stalling Ep0")); |
0 | 436 |
StallEndpoint(KEp0_In); |
437 |
return KErrGeneral; |
|
438 |
} |
|
439 |
} |
|
440 |
return KErrNone; |
|
441 |
} |
|
442 |
||
44 | 443 |
#undef USB_PROCESS_REQUEST |
444 |
||
445 |
||
0 | 446 |
TInt DUsbClientController::ProcessEp0DataReceived(TInt aCount) |
447 |
{ |
|
44 | 448 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessEp0DataReceived()")); |
449 |
||
450 |
__KTRACE_OPT(KUSB, Kern::Printf(" : %d bytes", aCount)); |
|
451 |
||
0 | 452 |
if (aCount > iEp0MaxPacketSize) |
453 |
{ |
|
44 | 454 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Too much data")); |
0 | 455 |
aCount = iEp0MaxPacketSize; |
456 |
} |
|
457 |
iEp0DataReceived += aCount; |
|
458 |
if (iEp0ClientId == NULL) |
|
459 |
{ |
|
460 |
// it is us (not an app), who owns this transaction |
|
461 |
switch (iSetup.iRequest) |
|
462 |
{ |
|
463 |
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST |
|
464 |
case KUsbRequest_SetDescriptor: |
|
465 |
memcpy(iEp0_RxCollectionBuf + iEp0DataReceived, iEp0_RxBuf, aCount); |
|
466 |
ProceedSetDescriptor(); |
|
467 |
break; |
|
468 |
#endif |
|
469 |
default: |
|
44 | 470 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: invalid request in iSetup")); |
471 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> DUsbClientController::ProcessEp0DataReceived: Stalling Ep0")); |
|
0 | 472 |
StallEndpoint(KEp0_In); |
473 |
ResetEp0DataOutVars(); |
|
474 |
break; |
|
475 |
} |
|
476 |
} |
|
477 |
else |
|
478 |
{ |
|
479 |
// pass the data on to a client |
|
480 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
|
481 |
TUsbcRequestCallback* p; |
|
482 |
while ((p = iter++) != NULL) |
|
483 |
{ |
|
484 |
if (p->Owner() == iEp0ClientId) |
|
485 |
{ |
|
486 |
__ASSERT_DEBUG((p->iEndpointNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
487 |
__ASSERT_DEBUG((p->iTransferDir == EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
44 | 488 |
__KTRACE_OPT(KUSB, Kern::Printf(" Found Ep0 read request")); |
0 | 489 |
memcpy(p->iBufferStart, iEp0_RxBuf, aCount); |
490 |
p->iError = KErrNone; // if it wasn't 'KErrNone' we wouldn't be here |
|
491 |
*(p->iPacketSize) = aCount; |
|
492 |
p->iRxPackets = 1; |
|
493 |
*(p->iPacketIndex) = 0; |
|
494 |
ProcessDataTransferDone(*p); |
|
495 |
goto found; |
|
496 |
} |
|
497 |
} |
|
44 | 498 |
__KTRACE_OPT(KUSB, Kern::Printf(" Ep0 read request not found: setting RxExtra vars (Data)")); |
0 | 499 |
iEp0_RxExtraCount = aCount; |
500 |
iEp0_RxExtraData = ETrue; |
|
501 |
iEp0DataReceived -= aCount; |
|
502 |
return KErrNotFound; |
|
503 |
} |
|
504 |
found: |
|
505 |
if (iEp0DataReceived >= iSetup.iLength) |
|
506 |
{ |
|
507 |
// all data seems now to be here |
|
508 |
ResetEp0DataOutVars(); |
|
509 |
} |
|
510 |
return KErrNone; |
|
511 |
} |
|
512 |
||
513 |
||
514 |
// --- The USB Spec Chapter 9 Standard Endpoint Zero Device Requests --- |
|
515 |
||
516 |
TInt DUsbClientController::ProcessGetDeviceStatus(const TUsbcSetup& aPacket) |
|
517 |
{ |
|
44 | 518 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDeviceStatus()")); |
0 | 519 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
520 |
{ |
|
44 | 521 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 522 |
return KErrGeneral; |
523 |
} |
|
524 |
const TUint16 status = ((DeviceSelfPowered() ? KUsbDevStat_SelfPowered : 0) | |
|
525 |
(iRmWakeupStatus_Enabled ? KUsbDevStat_RemoteWakeup : 0)); |
|
44 | 526 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting device status: 0x%02x", status)); |
0 | 527 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status); |
528 |
if (SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone) |
|
529 |
{ |
|
530 |
iEp0WritePending = ETrue; |
|
531 |
} |
|
532 |
return KErrNone; |
|
533 |
} |
|
534 |
||
535 |
||
536 |
TInt DUsbClientController::ProcessGetInterfaceStatus(const TUsbcSetup& aPacket) |
|
537 |
{ |
|
44 | 538 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterfaceStatus()")); |
0 | 539 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
540 |
{ |
|
44 | 541 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 542 |
return KErrGeneral; |
543 |
} |
|
544 |
if (InterfaceExists(aPacket.iIndex) == EFalse) |
|
545 |
{ |
|
44 | 546 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface does not exist")); |
0 | 547 |
return KErrGeneral; |
548 |
} |
|
549 |
const TUint16 status = 0x0000; // as of USB Spec 2.0 |
|
44 | 550 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting interface status: 0x%02x", status)); |
0 | 551 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status); |
552 |
if (SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone) |
|
553 |
{ |
|
554 |
iEp0WritePending = ETrue; |
|
555 |
} |
|
556 |
return KErrNone; |
|
557 |
} |
|
558 |
||
559 |
||
560 |
TInt DUsbClientController::ProcessGetEndpointStatus(const TUsbcSetup& aPacket) |
|
561 |
{ |
|
44 | 562 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetEndpointStatus()")); |
0 | 563 |
if (iTrackDeviceState && |
564 |
((iDeviceState < EUsbcDeviceStateAddress) || |
|
565 |
(iDeviceState == EUsbcDeviceStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0))) |
|
566 |
{ |
|
44 | 567 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 568 |
return KErrGeneral; |
569 |
} |
|
570 |
if (EndpointExists(aPacket.iIndex) == EFalse) |
|
571 |
{ |
|
44 | 572 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist")); |
0 | 573 |
return KErrGeneral; |
574 |
} |
|
575 |
const TInt ep = EpAddr2Idx(aPacket.iIndex); |
|
576 |
const TUint16 status = (iRealEndpoints[ep].iHalt) ? KUsbEpStat_Halt : 0; |
|
44 | 577 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting endpoint status 0x%02x for real endpoint %d", |
578 |
status, ep)); |
|
0 | 579 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status); |
580 |
if (SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone) |
|
581 |
{ |
|
582 |
iEp0WritePending = ETrue; |
|
583 |
} |
|
584 |
return KErrNone; |
|
585 |
} |
|
586 |
||
587 |
||
588 |
TInt DUsbClientController::ProcessSetClearDevFeature(const TUsbcSetup& aPacket) |
|
589 |
{ |
|
44 | 590 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearDevFeature()")); |
0 | 591 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateDefault) |
592 |
{ |
|
44 | 593 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 594 |
return KErrGeneral; |
595 |
} |
|
596 |
||
597 |
TUint test_sel = 0; |
|
598 |
||
599 |
if (aPacket.iRequest == KUsbRequest_SetFeature) |
|
600 |
{ |
|
601 |
switch (aPacket.iValue) |
|
602 |
{ |
|
603 |
case KUsbFeature_RemoteWakeup: |
|
604 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
|
605 |
{ |
|
44 | 606 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 607 |
return KErrGeneral; |
608 |
} |
|
609 |
iRmWakeupStatus_Enabled = ETrue; |
|
610 |
break; |
|
611 |
case KUsbFeature_TestMode: |
|
612 |
if (!iHighSpeed) |
|
613 |
{ |
|
44 | 614 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported in High-Speed mode")); |
0 | 615 |
return KErrGeneral; |
616 |
} |
|
617 |
if (LowByte(aPacket.iIndex) != 0) |
|
618 |
{ |
|
44 | 619 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Lower byte of wIndex must be zero")); |
0 | 620 |
return KErrGeneral; |
621 |
} |
|
622 |
test_sel = HighByte(aPacket.iIndex); |
|
623 |
if ((test_sel < KUsbTestSelector_Test_J) || (test_sel > KUsbTestSelector_Test_Force_Enable)) |
|
624 |
{ |
|
44 | 625 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid test selector: %d", test_sel)); |
0 | 626 |
return KErrGeneral; |
627 |
} |
|
628 |
break; |
|
629 |
case KUsbFeature_B_HnpEnable: |
|
630 |
if (!iOtgSupport) |
|
631 |
{ |
|
44 | 632 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
0 | 633 |
return KErrGeneral; |
634 |
} |
|
635 |
if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
636 |
{ |
|
44 | 637 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
0 | 638 |
return KErrGeneral; |
639 |
} |
|
640 |
iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable; |
|
641 |
OtgFeaturesNotify(); |
|
642 |
break; |
|
643 |
case KUsbFeature_A_HnpSupport: |
|
644 |
if (!iOtgSupport) |
|
645 |
{ |
|
44 | 646 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
0 | 647 |
return KErrGeneral; |
648 |
} |
|
649 |
if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
650 |
{ |
|
44 | 651 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
0 | 652 |
return KErrGeneral; |
653 |
} |
|
654 |
iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport; |
|
655 |
OtgFeaturesNotify(); |
|
656 |
break; |
|
657 |
case KUsbFeature_A_AltHnpSupport: |
|
658 |
if (!iOtgSupport) |
|
659 |
{ |
|
44 | 660 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
0 | 661 |
return KErrGeneral; |
662 |
} |
|
663 |
if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
|
664 |
{ |
|
44 | 665 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
0 | 666 |
return KErrGeneral; |
667 |
} |
|
668 |
iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport; |
|
669 |
OtgFeaturesNotify(); |
|
670 |
break; |
|
671 |
default: |
|
44 | 672 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
0 | 673 |
return KErrGeneral; |
674 |
} |
|
675 |
} |
|
676 |
else // KUsbRequest_ClearFeature |
|
677 |
{ |
|
678 |
switch (aPacket.iValue) |
|
679 |
{ |
|
680 |
case KUsbFeature_RemoteWakeup: |
|
681 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
|
682 |
{ |
|
44 | 683 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 684 |
return KErrGeneral; |
685 |
} |
|
686 |
iRmWakeupStatus_Enabled = EFalse; |
|
687 |
break; |
|
688 |
default: |
|
44 | 689 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
0 | 690 |
return KErrGeneral; |
691 |
} |
|
692 |
} |
|
693 |
||
694 |
SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
|
695 |
||
696 |
// 9.4.9: "The transition to test mode of an upstream facing port must not happen until |
|
697 |
// after the status stage of the request." |
|
698 |
if (test_sel) |
|
699 |
{ |
|
44 | 700 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Entering HS Test Mode %d", test_sel)); |
0 | 701 |
EnterTestMode(test_sel); |
702 |
} |
|
703 |
||
704 |
return KErrNone; |
|
705 |
} |
|
706 |
||
707 |
||
708 |
TInt DUsbClientController::ProcessSetClearIfcFeature(const TUsbcSetup& aPacket) |
|
709 |
{ |
|
44 | 710 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearIfcFeature()")); |
0 | 711 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
712 |
{ |
|
44 | 713 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 714 |
return KErrGeneral; |
715 |
} |
|
716 |
// No interface features defined in USB spec, thus |
|
717 |
return KErrGeneral; |
|
718 |
} |
|
719 |
||
720 |
||
721 |
TInt DUsbClientController::ProcessSetClearEpFeature(const TUsbcSetup& aPacket) |
|
722 |
{ |
|
44 | 723 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearEpFeature()")); |
0 | 724 |
if (iTrackDeviceState && |
725 |
((iDeviceState < EUsbcDeviceStateAddress) || |
|
726 |
(iDeviceState == EUsbcDeviceStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0))) |
|
727 |
{ |
|
44 | 728 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 729 |
return KErrGeneral; |
730 |
} |
|
731 |
if (aPacket.iValue != KUsbFeature_EndpointHalt) |
|
732 |
{ |
|
44 | 733 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
0 | 734 |
return KErrGeneral; |
735 |
} |
|
736 |
if (EndpointExists(aPacket.iIndex) == EFalse) |
|
737 |
{ |
|
44 | 738 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist")); |
0 | 739 |
return KErrGeneral; |
740 |
} |
|
741 |
const TInt ep = EpAddr2Idx(aPacket.iIndex); |
|
742 |
if (iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeControl || |
|
743 |
iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeIsochronous) |
|
744 |
{ |
|
44 | 745 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint is Control or Isochronous")); |
0 | 746 |
return KErrGeneral; |
747 |
} |
|
748 |
SetClearHaltFeature(ep, aPacket.iRequest); |
|
749 |
SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
|
750 |
return KErrNone; |
|
751 |
} |
|
752 |
||
753 |
||
754 |
TInt DUsbClientController::ProcessSetAddress(const TUsbcSetup& aPacket) |
|
755 |
{ |
|
44 | 756 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetAddress()")); |
0 | 757 |
if (iTrackDeviceState && iDeviceState > EUsbcDeviceStateAddress) |
758 |
{ |
|
44 | 759 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 760 |
return KErrGeneral; |
761 |
} |
|
762 |
const TUint16 addr = aPacket.iValue; |
|
763 |
if (addr > 127) |
|
764 |
{ |
|
44 | 765 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad address value: %d (>127)", addr)); |
0 | 766 |
return KErrGeneral; |
767 |
} |
|
768 |
if (addr == 0) |
|
769 |
{ |
|
770 |
// Enter Default state (from Default or Address) |
|
771 |
NextDeviceState(EUsbcDeviceStateDefault); |
|
772 |
} |
|
44 | 773 |
__KTRACE_OPT(KUSB, Kern::Printf(" USB address: %d", addr)); |
0 | 774 |
// The spec says, under section 9.4.6: |
775 |
// "Stages after the initial Setup packet assume the same device address as the Setup packet. The USB |
|
776 |
// device does not change its device address until after the Status stage of this request is completed |
|
777 |
// successfully. Note that this is a difference between this request and all other requests. For all other |
|
778 |
// requests, the operation indicated must be completed before the Status stage." |
|
779 |
// Therefore, here we first send the status packet and only then actually execute the request. |
|
780 |
SendEp0ZeroByteStatusPacket(); |
|
781 |
SetDeviceAddress(addr); |
|
782 |
return KErrNone; |
|
783 |
} |
|
784 |
||
785 |
||
786 |
TInt DUsbClientController::ProcessGetDescriptor(const TUsbcSetup& aPacket) |
|
787 |
{ |
|
44 | 788 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDescriptor()")); |
0 | 789 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateDefault) |
790 |
{ |
|
44 | 791 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 792 |
return KErrGeneral; |
793 |
} |
|
794 |
||
795 |
// Make sure we assume the correct speed |
|
796 |
__ASSERT_DEBUG((iHighSpeed == CurrentlyUsingHighSpeed()), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
797 |
||
798 |
TInt size = 0; |
|
799 |
const TInt result = iDescriptors.FindDescriptor(HighByte(aPacket.iValue), // Type |
|
800 |
LowByte(aPacket.iValue), // Index |
|
801 |
aPacket.iIndex, // Language ID |
|
802 |
size); |
|
803 |
||
804 |
if ((result != KErrNone) || (size == 0)) |
|
805 |
{ |
|
806 |
// This doesn't have to be an error - protocol-wise it's OK. |
|
44 | 807 |
__KTRACE_OPT(KUSB, Kern::Printf(" Couldn't retrieve descriptor")); |
0 | 808 |
return KErrGeneral; |
809 |
} |
|
810 |
||
44 | 811 |
__KTRACE_OPT(KUSB, Kern::Printf(" Descriptor found, size: %d (requested: %d)", |
812 |
size, aPacket.iLength)); |
|
0 | 813 |
if (size > KUsbcBufSz_Ep0Tx) |
814 |
{ |
|
815 |
// This should actually not be possible (i.e. we should never get here). |
|
44 | 816 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ep0_Tx buffer too small")); |
0 | 817 |
} |
818 |
if (size > aPacket.iLength) |
|
819 |
{ |
|
820 |
// Send only as much data as requested by the host |
|
821 |
size = aPacket.iLength; |
|
822 |
} |
|
823 |
||
824 |
#ifdef ENABLE_EXCESSIVE_DEBUG_OUTPUT |
|
44 | 825 |
__KTRACE_OPT(KUSB, |
826 |
Kern::Printf(" Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x ...", |
|
827 |
iEp0_TxBuf[0], iEp0_TxBuf[1], iEp0_TxBuf[2], iEp0_TxBuf[3], |
|
828 |
iEp0_TxBuf[4], iEp0_TxBuf[5], iEp0_TxBuf[6], iEp0_TxBuf[7])); |
|
0 | 829 |
#endif |
830 |
// If we're about to send less bytes than expected by the host AND our number is a |
|
831 |
// multiple of the packet size, in order to indicate the end of the control transfer, |
|
832 |
// we must finally send a zero length data packet (ZLP): |
|
833 |
const TBool zlp = ((size < aPacket.iLength) && (size % iEp0MaxPacketSize == 0)); |
|
834 |
if (SetupEndpointZeroWrite(iEp0_TxBuf, size, zlp) == KErrNone) |
|
835 |
{ |
|
836 |
iEp0WritePending = ETrue; |
|
837 |
} |
|
838 |
||
839 |
return KErrNone; |
|
840 |
} |
|
841 |
||
842 |
||
843 |
TInt DUsbClientController::ProcessSetDescriptor(const TUsbcSetup& aPacket) |
|
844 |
{ |
|
44 | 845 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetDescriptor()")); |
0 | 846 |
#ifndef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST |
847 |
return KErrGeneral; |
|
848 |
#else |
|
849 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
|
850 |
{ |
|
851 |
// Error: Invalid device state! |
|
852 |
return KErrGeneral; |
|
853 |
} |
|
854 |
if (aPacket.iLength > KUsbcBufSz_Ep0Rx) |
|
855 |
{ |
|
856 |
// Error: Our Rx buffer is too small! (Raise a defect to make it larger) |
|
44 | 857 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ep0_Rx buffer too small")); |
0 | 858 |
return KErrGeneral; |
859 |
} |
|
860 |
SetEp0DataOutVars(aPacket); |
|
861 |
SetupEndpointZeroRead(); |
|
862 |
return KErrNone; |
|
863 |
#endif |
|
864 |
} |
|
865 |
||
866 |
||
867 |
TInt DUsbClientController::ProcessGetConfiguration(const TUsbcSetup& aPacket) |
|
868 |
{ |
|
44 | 869 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetConfiguration()")); |
0 | 870 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
871 |
{ |
|
44 | 872 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 873 |
return KErrGeneral; |
874 |
} |
|
875 |
if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateAddress && iCurrentConfig != 0) |
|
876 |
{ |
|
44 | 877 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Address && Config != 0")); |
0 | 878 |
return KErrGeneral; |
879 |
} |
|
880 |
if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateConfigured && iCurrentConfig == 0) |
|
881 |
{ |
|
44 | 882 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Configured && Config == 0")); |
0 | 883 |
return KErrGeneral; |
884 |
} |
|
885 |
if (aPacket.iLength != 1) // "unspecified behavior" |
|
886 |
{ |
|
44 | 887 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: wLength != 1 (= %d)", aPacket.iLength)); |
0 | 888 |
} |
44 | 889 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting configuration value %d", iCurrentConfig)); |
0 | 890 |
if (SetupEndpointZeroWrite(&iCurrentConfig, sizeof(iCurrentConfig)) == KErrNone) |
891 |
{ |
|
892 |
iEp0WritePending = ETrue; |
|
893 |
} |
|
894 |
return KErrNone; |
|
895 |
} |
|
896 |
||
897 |
||
898 |
/** Changes the device's configuration value, including interface setup and/or |
|
899 |
teardown and state change notification of higher-layer clients. |
|
900 |
May also be called by the PSL in special cases - therefore publishedPartner. |
|
901 |
||
902 |
@param aPacket The received Ep0 SET_CONFIGURATION setup request packet. |
|
903 |
@return KErrGeneral in case of a protocol error, KErrNone otherwise. |
|
904 |
||
905 |
@publishedPartner @released |
|
906 |
*/ |
|
907 |
TInt DUsbClientController::ProcessSetConfiguration(const TUsbcSetup& aPacket) |
|
908 |
{ |
|
44 | 909 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetConfiguration()")); |
910 |
||
0 | 911 |
// This function may be called by the PSL from within an ISR -- so we have |
912 |
// to take care what we do here (and also in all functions that get called |
|
913 |
// from here). |
|
914 |
||
915 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
|
916 |
{ |
|
44 | 917 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 918 |
return KErrGeneral; |
919 |
} |
|
920 |
const TUint16 value = aPacket.iValue; |
|
921 |
if (value > 1) // we support only one configuration |
|
922 |
{ |
|
44 | 923 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Configuration value too large: %d", value)); |
0 | 924 |
return KErrGeneral; |
925 |
} |
|
926 |
||
44 | 927 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration value: %d", value)); |
0 | 928 |
ChangeConfiguration(value); |
929 |
||
930 |
// In 9.4.5 under GET_STATUS we read, that after SET_CONFIGURATION the HALT feature |
|
931 |
// for all endpoints is reset to zero. |
|
932 |
TInt num = 0; |
|
933 |
(TAny) DoForEveryEndpointInUse(&DUsbClientController::ClearHaltFeature, num); |
|
44 | 934 |
__KTRACE_OPT(KUSB, Kern::Printf(" Called ClearHaltFeature() for %d endpoints", num)); |
0 | 935 |
SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
936 |
return KErrNone; |
|
937 |
} |
|
938 |
||
939 |
||
940 |
TInt DUsbClientController::ProcessGetInterface(const TUsbcSetup& aPacket) |
|
941 |
{ |
|
44 | 942 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterface()")); |
0 | 943 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
944 |
{ |
|
44 | 945 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 946 |
return KErrGeneral; |
947 |
} |
|
948 |
if (iCurrentConfig == 0) |
|
949 |
{ |
|
44 | 950 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured")); |
0 | 951 |
return KErrGeneral; |
952 |
} |
|
953 |
const TInt number = aPacket.iIndex; |
|
954 |
if (!InterfaceExists(number)) |
|
955 |
{ |
|
44 | 956 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number)); |
0 | 957 |
return KErrGeneral; |
958 |
} |
|
959 |
// Send alternate setting code of iCurrentInterface of Interface(set) <number> of the current |
|
960 |
// config (iCurrentConfig). |
|
961 |
const TUint8 setting = InterfaceNumber2InterfacePointer(number)->iCurrentInterface; |
|
44 | 962 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting interface setting %d", setting)); |
0 | 963 |
if (SetupEndpointZeroWrite(&setting, 1) == KErrNone) |
964 |
{ |
|
965 |
iEp0WritePending = ETrue; |
|
966 |
} |
|
967 |
return KErrNone; |
|
968 |
} |
|
969 |
||
970 |
||
971 |
TInt DUsbClientController::ProcessSetInterface(const TUsbcSetup& aPacket) |
|
972 |
{ |
|
44 | 973 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetInterface()")); |
0 | 974 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
975 |
{ |
|
44 | 976 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 977 |
return KErrGeneral; |
978 |
} |
|
979 |
if (iCurrentConfig == 0) |
|
980 |
{ |
|
44 | 981 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured")); |
0 | 982 |
return KErrGeneral; |
983 |
} |
|
984 |
const TInt number = aPacket.iIndex; |
|
985 |
if (!InterfaceExists(number)) |
|
986 |
{ |
|
44 | 987 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number)); |
0 | 988 |
return KErrGeneral; |
989 |
} |
|
990 |
const TInt setting = aPacket.iValue; |
|
991 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(number); |
|
992 |
RPointerArray<TUsbcInterface>& ifcs = ifcset_ptr->iInterfaces; |
|
993 |
if (setting >= ifcs.Count()) |
|
994 |
{ |
|
44 | 995 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Alt Setting >= bNumAltSettings: %d", setting)); |
0 | 996 |
return KErrGeneral; |
997 |
} |
|
44 | 998 |
__KTRACE_OPT(KUSB, Kern::Printf(" Interface setting:: %d", setting)); |
0 | 999 |
// Set iCurrentInterface of Interface(set) <number> of the current config |
1000 |
// (iCurrentConfig) to alternate setting <setting>. |
|
1001 |
ChangeInterface(ifcs[setting]); |
|
1002 |
// In 9.4.5 under GET_STATUS we read, that after SET_INTERFACE the HALT feature |
|
1003 |
// for all endpoints (of the now current interface setting) is reset to zero. |
|
1004 |
RPointerArray<TUsbcLogicalEndpoint>& eps = ifcset_ptr->CurrentInterface()->iEndpoints; |
|
1005 |
const TInt num_eps = eps.Count(); |
|
1006 |
for (TInt i = 0; i < num_eps; i++) |
|
1007 |
{ |
|
1008 |
const TInt ep_num = EpAddr2Idx(eps[i]->iPEndpoint->iEndpointAddr); |
|
1009 |
(TAny) ClearHaltFeature(ep_num); |
|
1010 |
} |
|
1011 |
SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
|
1012 |
return KErrNone; |
|
1013 |
} |
|
1014 |
||
1015 |
||
1016 |
TInt DUsbClientController::ProcessSynchFrame(const TUsbcSetup& aPacket) |
|
1017 |
{ |
|
44 | 1018 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSynchFrame()")); |
0 | 1019 |
if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
1020 |
{ |
|
44 | 1021 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
0 | 1022 |
return KErrGeneral; |
1023 |
} |
|
1024 |
const TInt ep = aPacket.iIndex; |
|
1025 |
if (EndpointExists(ep) == EFalse) |
|
1026 |
{ |
|
44 | 1027 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist")); |
0 | 1028 |
return KErrGeneral; |
1029 |
} |
|
1030 |
if (iRealEndpoints[EpAddr2Idx(ep)].iLEndpoint->iInfo.iType != KUsbEpTypeIsochronous) |
|
1031 |
{ |
|
44 | 1032 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint is not isochronous")); |
0 | 1033 |
return KErrGeneral; |
1034 |
} |
|
1035 |
// We always send 0: |
|
1036 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = 0x00; |
|
1037 |
if (SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone) |
|
1038 |
{ |
|
1039 |
iEp0WritePending = ETrue; |
|
1040 |
} |
|
1041 |
return KErrNone; |
|
1042 |
} |
|
1043 |
||
1044 |
||
1045 |
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST |
|
1046 |
void DUsbClientController::ProceedSetDescriptor() |
|
1047 |
{ |
|
44 | 1048 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProceedSetDescriptor()")); |
0 | 1049 |
// iEp0DataReceived already reflects the current buffer state |
1050 |
if (iEp0DataReceived < iSetup.iLength) |
|
1051 |
{ |
|
1052 |
// Not yet all data received => proceed |
|
1053 |
return; |
|
1054 |
} |
|
1055 |
if (iEp0DataReceived > iSetup.iLength) |
|
1056 |
{ |
|
1057 |
// Error: more data received than expected |
|
1058 |
// but we don't care... |
|
1059 |
} |
|
1060 |
// at this point: iEp0DataReceived == iSetup.iLength |
|
1061 |
const TUint8 type = HighByte(iSetup.iValue); |
|
1062 |
if (type == KUsbDescType_String) |
|
1063 |
{ |
|
1064 |
// set/add new string descriptor |
|
1065 |
} |
|
1066 |
else |
|
1067 |
{ |
|
1068 |
// set/add new ordinary descriptor |
|
1069 |
} |
|
1070 |
TUint8 index = LowByte(iSetup.iValue); |
|
1071 |
TUint16 langid = iSetup.iIndex; |
|
1072 |
TUint16 length_total = iSetup.iLength; |
|
1073 |
} |
|
1074 |
#endif |
|
1075 |
||
1076 |
||
1077 |
// --- Secondary (Helper) Functions |
|
1078 |
||
1079 |
void DUsbClientController::SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest) |
|
1080 |
{ |
|
44 | 1081 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetClearHaltFeature()")); |
0 | 1082 |
if (aRequest == KUsbRequest_SetFeature) |
1083 |
{ |
|
1084 |
if (iRealEndpoints[aRealEndpoint].iHalt) |
|
1085 |
{ |
|
1086 |
// (This condition is not really an error) |
|
44 | 1087 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already set")); |
0 | 1088 |
return; |
1089 |
} |
|
44 | 1090 |
__KTRACE_OPT(KUSB, Kern::Printf(" setting HALT feature for real endpoint %d", |
1091 |
aRealEndpoint)); |
|
0 | 1092 |
StallEndpoint(aRealEndpoint); |
1093 |
iRealEndpoints[aRealEndpoint].iHalt = ETrue; |
|
1094 |
} |
|
1095 |
else // KUsbRequest_ClearFeature |
|
1096 |
{ |
|
1097 |
if (iRealEndpoints[aRealEndpoint].iHalt == EFalse) |
|
1098 |
{ |
|
1099 |
// In this case, before we return, the data toggles are reset to DATA0. |
|
44 | 1100 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already cleared")); |
0 | 1101 |
ResetDataToggle(aRealEndpoint); |
1102 |
return; |
|
1103 |
} |
|
44 | 1104 |
__KTRACE_OPT(KUSB, Kern::Printf(" clearing HALT feature for real endpoint %d", |
1105 |
aRealEndpoint)); |
|
0 | 1106 |
ResetDataToggle(aRealEndpoint); |
1107 |
ClearStallEndpoint(aRealEndpoint); |
|
1108 |
iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
|
1109 |
} |
|
1110 |
EpStatusNotify(aRealEndpoint); // only called if actually something changed |
|
1111 |
} |
|
1112 |
||
1113 |
||
1114 |
TInt DUsbClientController::ClearHaltFeature(TInt aRealEndpoint) |
|
1115 |
{ |
|
44 | 1116 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ClearHaltFeature()")); |
0 | 1117 |
if (iRealEndpoints[aRealEndpoint].iHalt != EFalse) |
1118 |
{ |
|
1119 |
ClearStallEndpoint(aRealEndpoint); |
|
1120 |
iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
|
1121 |
} |
|
1122 |
return KErrNone; |
|
1123 |
} |
|
1124 |
||
1125 |
||
1126 |
void DUsbClientController::ChangeConfiguration(TUint16 aValue) |
|
1127 |
{ |
|
44 | 1128 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeConfiguration()")); |
0 | 1129 |
// New configuration is the same as the old one: 0 |
1130 |
if (iCurrentConfig == 0 && aValue == 0) |
|
1131 |
{ |
|
1132 |
// no-op |
|
44 | 1133 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == 0 --> exiting")); |
0 | 1134 |
return; |
1135 |
} |
|
1136 |
// New configuration is the same as the old one (but not 0) |
|
1137 |
if (iCurrentConfig == aValue) |
|
1138 |
{ |
|
44 | 1139 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == %d --> exiting", aValue)); |
1140 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1141 |
// From the spec 9.1.1.5, Data toggle is reset to zero here when |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1142 |
// setconfiguration(x->x)(x!=0) received, although we only support |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1143 |
// single configuration currently. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1144 |
TInt num = 0; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1145 |
TInt ret = DoForEveryEndpointInUse(&DUsbClientController::ResetDataToggle, num); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1146 |
if(ret != KErrNone) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1147 |
{ |
44 | 1148 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint data toggle reset failed")); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1149 |
} |
44 | 1150 |
__KTRACE_OPT(KUSB, Kern::Printf(" Called ResetDataToggle()for %d endpoints", num)); |
1151 |
||
0 | 1152 |
return; |
1153 |
} |
|
1154 |
// Device is already configured |
|
1155 |
if (iCurrentConfig != 0) |
|
1156 |
{ |
|
44 | 1157 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device was configured: %d", iCurrentConfig)); |
0 | 1158 |
// Tear down all interface(set)s of the old configuration |
1159 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
|
1160 |
for (TInt i = 0; i < ifcsets.Count(); ++i) |
|
1161 |
{ |
|
44 | 1162 |
__KTRACE_OPT(KUSB, Kern::Printf(" Tearing down InterfaceSet %d", i)); |
0 | 1163 |
InterfaceSetTeardown(ifcsets[i]); |
1164 |
} |
|
1165 |
iCurrentConfig = 0; |
|
1166 |
// Enter Address state (from Configured) |
|
1167 |
if (iDeviceState == EUsbcDeviceStateConfigured) |
|
1168 |
NextDeviceState(EUsbcDeviceStateAddress); |
|
1169 |
} |
|
1170 |
// Device gets a new configuration |
|
1171 |
if (aValue != 0) |
|
1172 |
{ |
|
44 | 1173 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device gets new configuration...")); |
0 | 1174 |
// Setup all alternate settings 0 of all interfaces |
1175 |
// (Don't separate the next two lines of code.) |
|
1176 |
iCurrentConfig = aValue; |
|
1177 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
|
1178 |
const TInt n = ifcsets.Count(); |
|
1179 |
for (TInt i = 0; i < n; ++i) |
|
1180 |
{ |
|
44 | 1181 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting up InterfaceSet %d", i)); |
0 | 1182 |
InterfaceSetup(ifcsets[i]->iInterfaces[0]); |
1183 |
} |
|
1184 |
// Enter Configured state (from Address or Configured) |
|
1185 |
NextDeviceState(EUsbcDeviceStateConfigured); |
|
1186 |
} |
|
44 | 1187 |
__KTRACE_OPT(KUSB, Kern::Printf(" New configuration: %d", iCurrentConfig)); |
0 | 1188 |
return; |
1189 |
} |
|
1190 |
||
1191 |
||
1192 |
void DUsbClientController::InterfaceSetup(TUsbcInterface* aIfc) |
|
1193 |
{ |
|
44 | 1194 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetup()")); |
0 | 1195 |
const TInt num_eps = aIfc->iEndpoints.Count(); |
1196 |
for (TInt i = 0; i < num_eps; i++) |
|
1197 |
{ |
|
1198 |
// Prepare this endpoint for I/O |
|
1199 |
TUsbcLogicalEndpoint* const ep = aIfc->iEndpoints[i]; |
|
1200 |
// (TUsbcLogicalEndpoint's FS/HS endpoint sizes and interval values got |
|
1201 |
// adjusted in its constructor.) |
|
1202 |
if (iHighSpeed) |
|
1203 |
{ |
|
44 | 1204 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (HS)", ep->iEpSize_Hs)); |
0 | 1205 |
ep->iInfo.iSize = ep->iEpSize_Hs; |
1206 |
} |
|
1207 |
else |
|
1208 |
{ |
|
44 | 1209 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (FS)", ep->iEpSize_Fs)); |
0 | 1210 |
ep->iInfo.iSize = ep->iEpSize_Fs; |
1211 |
} |
|
1212 |
const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr); |
|
1213 |
if (ConfigureEndpoint(idx, ep->iInfo) != KErrNone) |
|
1214 |
{ |
|
44 | 1215 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d configuration failed", idx)); |
0 | 1216 |
continue; |
1217 |
} |
|
1218 |
// Should there be a problem with it then we could try resetting the ep |
|
1219 |
// data toggle at this point (or before the Configure) as well. |
|
44 | 1220 |
__KTRACE_OPT(KUSB, Kern::Printf(" Connecting real ep addr 0x%02x & logical ep #%d", |
1221 |
ep->iPEndpoint->iEndpointAddr, ep->iLEndpointNum)); |
|
0 | 1222 |
ep->iPEndpoint->iLEndpoint = ep; |
1223 |
} |
|
1224 |
aIfc->iInterfaceSet->iCurrentInterface = aIfc->iSettingCode; |
|
1225 |
return; |
|
1226 |
} |
|
1227 |
||
1228 |
||
1229 |
void DUsbClientController::InterfaceSetTeardown(TUsbcInterfaceSet* aIfcSet) |
|
1230 |
{ |
|
44 | 1231 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetTeardown()")); |
0 | 1232 |
if (aIfcSet->iInterfaces.Count() == 0) |
1233 |
{ |
|
44 | 1234 |
__KTRACE_OPT(KUSB, Kern::Printf(" No interfaces exist - returning")); |
0 | 1235 |
return; |
1236 |
} |
|
1237 |
RPointerArray<TUsbcLogicalEndpoint>& eps = aIfcSet->CurrentInterface()->iEndpoints; |
|
1238 |
const TInt num_eps = eps.Count(); |
|
1239 |
for (TInt i = 0; i < num_eps; i++) |
|
1240 |
{ |
|
1241 |
TUsbcLogicalEndpoint* const ep = eps[i]; |
|
1242 |
const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr); |
|
1243 |
||
1244 |
CancelTransferRequests(idx); |
|
1245 |
||
1246 |
if (!ep->iPEndpoint->iLEndpoint) |
|
1247 |
{ |
|
44 | 1248 |
__KTRACE_OPT(KUSB, Kern::Printf(" real ep %d not configured: skipping", idx)); |
0 | 1249 |
continue; |
1250 |
} |
|
1251 |
if (ResetDataToggle(idx) != KErrNone) |
|
1252 |
{ |
|
44 | 1253 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d data toggle reset failed", idx)); |
0 | 1254 |
} |
1255 |
if (DeConfigureEndpoint(idx) != KErrNone) |
|
1256 |
{ |
|
44 | 1257 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d de-configuration failed", idx)); |
0 | 1258 |
} |
1259 |
||
44 | 1260 |
__KTRACE_OPT(KUSB, Kern::Printf(" disconnecting real ep & logical ep")); |
0 | 1261 |
ep->iPEndpoint->iLEndpoint = NULL; |
1262 |
} |
|
1263 |
if (aIfcSet->CurrentInterface() != 0) |
|
1264 |
{ |
|
44 | 1265 |
__KTRACE_OPT(KUSB, Kern::Printf(" Resetting alternate interface setting to 0")); |
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
//Add this mutex to protect the interface set data structure |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1267 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
NKern::FMWait(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
|
0 | 1272 |
aIfcSet->iCurrentInterface = 0; |
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
if (NKern::CurrentContext() == EThread) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1275 |
NKern::FMSignal(&iMutex); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
} |
0 | 1277 |
} |
1278 |
return; |
|
1279 |
} |
|
1280 |
||
1281 |
||
1282 |
void DUsbClientController::ChangeInterface(TUsbcInterface* aIfc) |
|
1283 |
{ |
|
44 | 1284 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeInterface()")); |
0 | 1285 |
TUsbcInterfaceSet* ifcset = aIfc->iInterfaceSet; |
1286 |
const TUint8 setting = aIfc->iSettingCode; |
|
1287 |
if (ifcset->iCurrentInterface == setting) |
|
1288 |
{ |
|
44 | 1289 |
__KTRACE_OPT(KUSB, Kern::Printf(" New Ifc == old Ifc: nothing to do")); |
0 | 1290 |
return; |
1291 |
} |
|
44 | 1292 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting new interface setting #%d", setting)); |
0 | 1293 |
InterfaceSetTeardown(ifcset); |
1294 |
InterfaceSetup(aIfc); |
|
1295 |
StatusNotify(static_cast<TUsbcDeviceState>(KUsbAlternateSetting | setting), ifcset->iClientId); |
|
1296 |
} |
|
1297 |
||
1298 |
||
1299 |
// aFunction gets called, successively, with the endpoint index of every ep in-use as its argument. |
|
1300 |
// (BTW: The declaration "type (class::*name)(params)" makes <name> a "pointer to element function".) |
|
1301 |
// |
|
1302 |
TInt DUsbClientController::DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount) |
|
1303 |
{ |
|
44 | 1304 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DoForEveryEndpointInUse()")); |
0 | 1305 |
aCount = 0; |
1306 |
TUsbcConfiguration* const config = CurrentConfig(); |
|
1307 |
if (!config) |
|
1308 |
{ |
|
44 | 1309 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device is not configured - returning")); |
0 | 1310 |
return KErrNone; |
1311 |
} |
|
1312 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = config->iInterfaceSets; |
|
1313 |
const TInt num_ifcsets = ifcsets.Count(); |
|
1314 |
for (TInt i = 0; i < num_ifcsets; i++) |
|
1315 |
{ |
|
1316 |
RPointerArray<TUsbcLogicalEndpoint>& eps = ifcsets[i]->CurrentInterface()->iEndpoints; |
|
1317 |
const TInt num_eps = eps.Count(); |
|
1318 |
for (TInt j = 0; j < num_eps; j++) |
|
1319 |
{ |
|
1320 |
const TInt ep_num = EpAddr2Idx(eps[j]->iPEndpoint->iEndpointAddr); |
|
1321 |
const TInt result = (this->*aFunction)(ep_num); |
|
1322 |
++aCount; |
|
1323 |
if (result != KErrNone) |
|
1324 |
{ |
|
1325 |
return result; |
|
1326 |
} |
|
1327 |
} |
|
1328 |
} |
|
1329 |
return KErrNone; |
|
1330 |
} |
|
1331 |
||
1332 |
||
1333 |
// -eof- |