59
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* e32/drivers/usbcc/chapter9.cpp
|
|
16 |
* Platform independent layer (PIL) of the USB Device controller driver:
|
|
17 |
* Processing of USB spec chapter 9 standard requests.
|
|
18 |
*
|
|
19 |
*/
|
33
|
20 |
|
|
21 |
/**
|
|
22 |
@file chapter9.cpp
|
|
23 |
@internalTechnology
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include <usb/usbc.h>
|
|
27 |
|
|
28 |
#include "controltransfersm.h"
|
|
29 |
|
|
30 |
//#define ENABLE_EXCESSIVE_DEBUG_OUTPUT
|
|
31 |
//
|
|
32 |
// === USB Controller member function implementation - PSL API (protected) ========================
|
|
33 |
//
|
|
34 |
|
|
35 |
/** Used to synchronize the Ep0 state machine between the PSL and PIL.
|
|
36 |
Accepts a SETUP packet and returns the next Ep0 state.
|
|
37 |
|
|
38 |
@param aSetupBuf The SETUP packet just received by the PSL.
|
|
39 |
@return The next Ep0 state.
|
|
40 |
|
|
41 |
@publishedPartner @released
|
|
42 |
*/
|
|
43 |
UsbShai::TControlStage DUsbClientController::EnquireEp0NextStage(const TUint8* aSetupBuf) const
|
|
44 |
{
|
|
45 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnquireEp0NextState()"));
|
|
46 |
|
|
47 |
// This function may be called by the PSL from within an ISR -- so we have
|
|
48 |
// to take care what we do here (and also in all functions that get called
|
|
49 |
// from here).
|
|
50 |
|
|
51 |
if (SWAP_BYTES_16((reinterpret_cast<const TUint16*>(aSetupBuf)[3])) == 0) // iLength
|
|
52 |
{
|
|
53 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EControlTransferStageStatusIn"));
|
|
54 |
return UsbShai::EControlTransferStageStatusIn; // No-data Control => Status_IN
|
|
55 |
}
|
|
56 |
else if ((aSetupBuf[0] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
|
|
57 |
{
|
|
58 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EControlTransferStageDataOut"));
|
|
59 |
return UsbShai::EControlTransferStageDataOut; // Control Write => Data_OUT
|
|
60 |
}
|
|
61 |
else
|
|
62 |
{
|
|
63 |
__KTRACE_OPT(KUSB, Kern::Printf(" --> EControlTransferStageDataIn"));
|
|
64 |
return UsbShai::EControlTransferStageDataIn; // Control Read => Data_IN
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
//
|
|
69 |
// About iLastError.
|
|
70 |
// This member is used to remember the last error happend during a
|
|
71 |
// processXXX likewise function.
|
|
72 |
//
|
|
73 |
// Before entry of each ProcessXXX, iLastError will be cleared to KErrNone.
|
|
74 |
//
|
|
75 |
|
|
76 |
// --- The USB Spec Chapter 9 Standard Endpoint Zero Device Requests ---
|
|
77 |
// Record error happend with iLastError, the value already been set to zero
|
|
78 |
// before entering ProcessSetupPacket call.
|
|
79 |
void DUsbClientController::ProcessGetDeviceStatus(const TUsbcSetup& aPacket)
|
|
80 |
{
|
|
81 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDeviceStatus()"));
|
|
82 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
83 |
{
|
|
84 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
85 |
iLastError = KErrGeneral;
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
// We always assume Device is bus-powered, even though mobile phone almost always
|
|
90 |
// has a battry there, because self-powered device can not required more then 100ma current
|
|
91 |
// which is not acceptable for Usb charging.
|
|
92 |
TBool selfPowered = EFalse;
|
|
93 |
|
|
94 |
/* FIXME: modify selfPowered to make it compilance with following rule.
|
|
95 |
|
|
96 |
1. If current draw exceeds 100mA, the device must report itself
|
|
97 |
as bus-powered during enumeration.
|
|
98 |
|
|
99 |
2. In all cases, the GetStatus(DEVICE) call must accurately report
|
|
100 |
whether the device is currently operating on self- or bus-power.
|
|
101 |
|
|
102 |
3. A device that is actively drawing more than 100mA from USB must
|
|
103 |
report itself as bus-powered in the GetStatus(DEVICE) call.
|
|
104 |
|
|
105 |
4. Peripherals that return "Self-powered" in the GetStatus(DEVICE)
|
|
106 |
call are prohibited from drawing more than 100mA at any time.
|
|
107 |
*/
|
|
108 |
/*
|
|
109 |
TBuf8<KUsbDescSize_Config> config;
|
|
110 |
|
|
111 |
if(iDescriptors.GetConfigurationDescriptorTC(&Kern::CurrentThread(),config) == KErrNone)
|
|
112 |
{
|
|
113 |
TUint8 maxPower = config[8];
|
|
114 |
if(maxPower <= 50)
|
|
115 |
{
|
|
116 |
selfPowered = EFalse;
|
|
117 |
}
|
|
118 |
}
|
|
119 |
*/
|
|
120 |
|
|
121 |
const TUint16 status = ((selfPowered ? KUsbDevStat_SelfPowered : 0) |
|
|
122 |
(iRmWakeupStatus_Enabled ? KUsbDevStat_RemoteWakeup : 0));
|
|
123 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting device status: 0x%02x", status));
|
|
124 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
|
|
125 |
if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone)
|
|
126 |
{
|
|
127 |
iEp0WritePending = ETrue;
|
|
128 |
}
|
|
129 |
else
|
|
130 |
{
|
|
131 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
132 |
}
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
void DUsbClientController::ProcessGetInterfaceStatus(const TUsbcSetup& aPacket)
|
|
137 |
{
|
|
138 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterfaceStatus()"));
|
|
139 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
140 |
{
|
|
141 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
142 |
iLastError = KErrGeneral;
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
if (InterfaceExists(aPacket.iIndex) == EFalse)
|
|
147 |
{
|
|
148 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface does not exist"));
|
|
149 |
iLastError = KErrGeneral;
|
|
150 |
}
|
|
151 |
else
|
|
152 |
{
|
|
153 |
const TUint16 status = 0x0000; // as of USB Spec 2.0
|
|
154 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting interface status: 0x%02x", status));
|
|
155 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
|
|
156 |
if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone)
|
|
157 |
{
|
|
158 |
iEp0WritePending = ETrue;
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
|
|
169 |
void DUsbClientController::ProcessGetEndpointStatus(const TUsbcSetup& aPacket)
|
|
170 |
{
|
|
171 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetEndpointStatus()"));
|
|
172 |
if (
|
|
173 |
((iDeviceState < UsbShai::EUsbPeripheralStateAddress) ||
|
|
174 |
(iDeviceState == UsbShai::EUsbPeripheralStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0)))
|
|
175 |
{
|
|
176 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
177 |
iLastError = KErrGeneral;
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
if (EndpointExists(aPacket.iIndex) == EFalse)
|
|
182 |
{
|
|
183 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist"));
|
|
184 |
iLastError = KErrGeneral;
|
|
185 |
}
|
|
186 |
else
|
|
187 |
{
|
|
188 |
const TInt ep = EpAddr2Idx(aPacket.iIndex);
|
|
189 |
const TUint16 status = (iRealEndpoints[ep].iHalt) ? KUsbEpStat_Halt : 0;
|
|
190 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting endpoint status 0x%02x for real endpoint %d",
|
|
191 |
status, ep));
|
|
192 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
|
|
193 |
if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone)
|
|
194 |
{
|
|
195 |
iEp0WritePending = ETrue;
|
|
196 |
}
|
|
197 |
else
|
|
198 |
{
|
|
199 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
200 |
}
|
|
201 |
}
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
void DUsbClientController::ProcessSetClearDevFeature(const TUsbcSetup& aPacket)
|
|
207 |
{
|
|
208 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearDevFeature()"));
|
|
209 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateDefault)
|
|
210 |
{
|
|
211 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
212 |
iLastError = KErrGeneral;
|
|
213 |
return;
|
|
214 |
}
|
|
215 |
|
|
216 |
TInt test_sel = 0;
|
|
217 |
|
|
218 |
if (aPacket.iRequest == KUsbRequest_SetFeature)
|
|
219 |
{
|
|
220 |
switch (aPacket.iValue)
|
|
221 |
{
|
|
222 |
case KUsbFeature_RemoteWakeup:
|
|
223 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
224 |
{
|
|
225 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
226 |
iLastError = KErrGeneral;
|
|
227 |
}
|
|
228 |
else
|
|
229 |
{
|
|
230 |
iRmWakeupStatus_Enabled = ETrue;
|
|
231 |
}
|
|
232 |
break;
|
|
233 |
|
|
234 |
case KUsbFeature_TestMode:
|
|
235 |
if (!iHighSpeed)
|
|
236 |
{
|
|
237 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported in High-Speed mode"));
|
|
238 |
iLastError = KErrGeneral;
|
|
239 |
}
|
|
240 |
else if (LowByte(aPacket.iIndex) != 0)
|
|
241 |
{
|
|
242 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Lower byte of wIndex must be zero"));
|
|
243 |
iLastError = KErrGeneral;
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
test_sel = HighByte(aPacket.iIndex);
|
|
248 |
if ((test_sel < UsbShai::EUsbTestSelector_Test_J) || (test_sel > UsbShai::EUsbTestSelector_Test_Force_Enable))
|
|
249 |
{
|
|
250 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid test selector: %d", test_sel));
|
|
251 |
iLastError = KErrGeneral;
|
|
252 |
}
|
|
253 |
}
|
|
254 |
break;
|
|
255 |
|
|
256 |
case KUsbFeature_B_HnpEnable:
|
|
257 |
if (!iOtgSupport)
|
|
258 |
{
|
|
259 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device"));
|
|
260 |
iLastError = KErrGeneral;
|
|
261 |
}
|
|
262 |
else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
|
|
263 |
{
|
|
264 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP"));
|
|
265 |
iLastError = KErrGeneral;
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable;
|
|
270 |
OtgFeaturesNotify();
|
|
271 |
}
|
|
272 |
break;
|
|
273 |
|
|
274 |
case KUsbFeature_A_HnpSupport:
|
|
275 |
if (!iOtgSupport)
|
|
276 |
{
|
|
277 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device"));
|
|
278 |
iLastError = KErrGeneral;
|
|
279 |
}
|
|
280 |
else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
|
|
281 |
{
|
|
282 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP"));
|
|
283 |
iLastError = KErrGeneral;
|
|
284 |
}
|
|
285 |
else
|
|
286 |
{
|
|
287 |
iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport;
|
|
288 |
OtgFeaturesNotify();
|
|
289 |
}
|
|
290 |
break;
|
|
291 |
|
|
292 |
case KUsbFeature_A_AltHnpSupport:
|
|
293 |
if (!iOtgSupport)
|
|
294 |
{
|
|
295 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device"));
|
|
296 |
iLastError = KErrGeneral;
|
|
297 |
}
|
|
298 |
else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
|
|
299 |
{
|
|
300 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP"));
|
|
301 |
iLastError = KErrGeneral;
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport;
|
|
306 |
OtgFeaturesNotify();
|
|
307 |
}
|
|
308 |
break;
|
|
309 |
|
|
310 |
default:
|
|
311 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested"));
|
|
312 |
iLastError = KErrGeneral;
|
|
313 |
}
|
|
314 |
}
|
|
315 |
else // KUsbRequest_ClearFeature
|
|
316 |
{
|
|
317 |
switch (aPacket.iValue)
|
|
318 |
{
|
|
319 |
case KUsbFeature_RemoteWakeup:
|
|
320 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
321 |
{
|
|
322 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
323 |
iLastError = KErrGeneral;
|
|
324 |
}
|
|
325 |
else
|
|
326 |
{
|
|
327 |
iRmWakeupStatus_Enabled = EFalse;
|
|
328 |
}
|
|
329 |
break;
|
|
330 |
|
|
331 |
default:
|
|
332 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested"));
|
|
333 |
iLastError = KErrGeneral;
|
|
334 |
}
|
|
335 |
}
|
|
336 |
|
|
337 |
if(iLastError == KErrNone)
|
|
338 |
{
|
|
339 |
// Sent out status packet if no error found.
|
|
340 |
iConTransferMgr->SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage
|
|
341 |
|
|
342 |
// 9.4.9: "The transition to test mode of an upstream facing port must not happen until
|
|
343 |
// after the status stage of the request."
|
|
344 |
if (test_sel)
|
|
345 |
{
|
|
346 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Entering HS Test Mode %d", test_sel));
|
|
347 |
iController.EnterTestMode((UsbShai::TUsbTestModeSelector)test_sel);
|
|
348 |
}
|
|
349 |
}
|
|
350 |
}
|
|
351 |
|
|
352 |
|
|
353 |
void DUsbClientController::ProcessSetClearIfcFeature(const TUsbcSetup& aPacket)
|
|
354 |
{
|
|
355 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearIfcFeature()"));
|
|
356 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
357 |
{
|
|
358 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
359 |
iLastError = KErrGeneral;
|
|
360 |
}
|
|
361 |
else
|
|
362 |
{
|
|
363 |
// No interface features defined in USB spec, thus
|
|
364 |
iLastError = KErrGeneral;
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
|
|
369 |
void DUsbClientController::ProcessSetClearEpFeature(const TUsbcSetup& aPacket)
|
|
370 |
{
|
|
371 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearEpFeature()"));
|
|
372 |
if (
|
|
373 |
((iDeviceState < UsbShai::EUsbPeripheralStateAddress) ||
|
|
374 |
(iDeviceState == UsbShai::EUsbPeripheralStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0)))
|
|
375 |
{
|
|
376 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
377 |
iLastError = KErrGeneral;
|
|
378 |
}
|
|
379 |
else if (aPacket.iValue != KUsbFeature_EndpointHalt)
|
|
380 |
{
|
|
381 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested"));
|
|
382 |
iLastError = KErrGeneral;
|
|
383 |
}
|
|
384 |
else if (EndpointExists(aPacket.iIndex) == EFalse)
|
|
385 |
{
|
|
386 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist"));
|
|
387 |
iLastError = KErrGeneral;
|
|
388 |
}
|
|
389 |
else
|
|
390 |
{
|
|
391 |
const TInt ep = EpAddr2Idx(aPacket.iIndex);
|
|
392 |
if (iRealEndpoints[ep].iLEndpoint->iInfo.iType == UsbShai::KUsbEpTypeControl ||
|
|
393 |
iRealEndpoints[ep].iLEndpoint->iInfo.iType == UsbShai::KUsbEpTypeIsochronous)
|
|
394 |
{
|
|
395 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint is Control or Isochronous"));
|
|
396 |
iLastError = KErrGeneral;
|
|
397 |
}
|
|
398 |
else
|
|
399 |
{
|
|
400 |
SetClearHaltFeature(ep, aPacket.iRequest);
|
|
401 |
|
|
402 |
// success: zero bytes data during status stage
|
|
403 |
iConTransferMgr->SendEp0ZeroByteStatusPacket();
|
|
404 |
}
|
|
405 |
}
|
|
406 |
}
|
|
407 |
|
|
408 |
|
|
409 |
void DUsbClientController::ProcessSetAddress(const TUsbcSetup& aPacket)
|
|
410 |
{
|
|
411 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetAddress()"));
|
|
412 |
if ( iDeviceState > UsbShai::EUsbPeripheralStateAddress)
|
|
413 |
{
|
|
414 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
415 |
iLastError = KErrGeneral;
|
|
416 |
}
|
|
417 |
else
|
|
418 |
{
|
|
419 |
const TUint16 addr = aPacket.iValue;
|
|
420 |
|
|
421 |
if (addr > 127)
|
|
422 |
{
|
|
423 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad address value: %d (>127)", addr));
|
|
424 |
iLastError = KErrGeneral;
|
|
425 |
}
|
|
426 |
else if (addr == 0)
|
|
427 |
{
|
|
428 |
// Enter Default state (from Default or Address)
|
|
429 |
NextDeviceState(UsbShai::EUsbPeripheralStateDefault);
|
|
430 |
}
|
|
431 |
|
|
432 |
__KTRACE_OPT(KUSB, Kern::Printf(" USB address: %d", addr));
|
|
433 |
|
|
434 |
// If controller support hw acceleration,call set address first and then status
|
|
435 |
if(iControllerProperties.iControllerCaps & UsbShai::KDevCapSetAddressAcceleration)
|
|
436 |
{
|
|
437 |
iController.SetDeviceAddress(addr);
|
|
438 |
}
|
|
439 |
|
|
440 |
// The spec says, under section 9.4.6:
|
|
441 |
// "Stages after the initial Setup packet assume the same device address as the Setup packet. The USB
|
|
442 |
// device does not change its device address until after the Status stage of this request is completed
|
|
443 |
// successfully. Note that this is a difference between this request and all other requests. For all other
|
|
444 |
// requests, the operation indicated must be completed before the Status stage."
|
|
445 |
// Therefore, here we first send the status packet and only then actually execute the request.
|
|
446 |
iConTransferMgr->SendEp0ZeroByteStatusPacket();
|
|
447 |
|
|
448 |
// If controller doesn't support hw acceleration, call set address after status
|
|
449 |
if((iControllerProperties.iControllerCaps & UsbShai::KDevCapSetAddressAcceleration) == 0)
|
|
450 |
{
|
|
451 |
iController.SetDeviceAddress(addr);
|
|
452 |
}
|
|
453 |
}
|
|
454 |
}
|
|
455 |
|
|
456 |
|
|
457 |
void DUsbClientController::ProcessGetDescriptor(const TUsbcSetup& aPacket)
|
|
458 |
{
|
|
459 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDescriptor()"));
|
|
460 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateDefault)
|
|
461 |
{
|
|
462 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
463 |
iLastError = KErrGeneral;
|
|
464 |
return ;
|
|
465 |
}
|
|
466 |
|
|
467 |
// Make sure we assume the correct speed
|
|
468 |
__ASSERT_DEBUG((iHighSpeed == CurrentlyUsingHighSpeed()), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
469 |
|
|
470 |
TInt size = 0;
|
|
471 |
const TInt result = iDescriptors.FindDescriptor(HighByte(aPacket.iValue), // Type
|
|
472 |
LowByte(aPacket.iValue), // Index
|
|
473 |
aPacket.iIndex, // Language ID
|
|
474 |
size);
|
|
475 |
|
|
476 |
if ((result != KErrNone) || (size == 0))
|
|
477 |
{
|
|
478 |
// This doesn't have to be an error - protocol-wise it's OK.
|
|
479 |
__KTRACE_OPT(KUSB, Kern::Printf(" Couldn't retrieve descriptor"));
|
|
480 |
iLastError = KErrGeneral;
|
|
481 |
return;
|
|
482 |
}
|
|
483 |
|
|
484 |
__KTRACE_OPT(KUSB, Kern::Printf(" Descriptor found, size: %d (requested: %d)",
|
|
485 |
size, aPacket.iLength));
|
|
486 |
if (size > KUsbcBufSz_Ep0Tx)
|
|
487 |
{
|
|
488 |
// This should actually not be possible (i.e. we should never get here).
|
|
489 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ep0_Tx buffer too small"));
|
|
490 |
}
|
|
491 |
if (size > aPacket.iLength)
|
|
492 |
{
|
|
493 |
// Send only as much data as requested by the host
|
|
494 |
size = aPacket.iLength;
|
|
495 |
}
|
|
496 |
|
|
497 |
#ifdef ENABLE_EXCESSIVE_DEBUG_OUTPUT
|
|
498 |
__KTRACE_OPT(KUSB,
|
|
499 |
Kern::Printf(" Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x ...",
|
|
500 |
iEp0_TxBuf[0], iEp0_TxBuf[1], iEp0_TxBuf[2], iEp0_TxBuf[3],
|
|
501 |
iEp0_TxBuf[4], iEp0_TxBuf[5], iEp0_TxBuf[6], iEp0_TxBuf[7]));
|
|
502 |
#endif
|
|
503 |
// If we're about to send less bytes than expected by the host AND our number is a
|
|
504 |
// multiple of the packet size, in order to indicate the end of the control transfer,
|
|
505 |
// we must finally send a zero length data packet (ZLP):
|
|
506 |
const TBool zlp = ((size < aPacket.iLength) && (size % iEp0MaxPacketSize == 0));
|
|
507 |
if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, size, zlp) == KErrNone)
|
|
508 |
{
|
|
509 |
iEp0WritePending = ETrue;
|
|
510 |
}
|
|
511 |
else
|
|
512 |
{
|
|
513 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
514 |
}
|
|
515 |
}
|
|
516 |
|
|
517 |
|
|
518 |
void DUsbClientController::ProcessSetDescriptor(const TUsbcSetup& aPacket)
|
|
519 |
{
|
|
520 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetDescriptor()"));
|
|
521 |
#ifndef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
522 |
iLastError = KErrGeneral;
|
|
523 |
return;
|
|
524 |
#else
|
|
525 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
526 |
{
|
|
527 |
// Error: Invalid device state!
|
|
528 |
iLastError = KErrGeneral;
|
|
529 |
}
|
|
530 |
else if (aPacket.iLength > KUsbcBufSz_Ep0Rx)
|
|
531 |
{
|
|
532 |
// Error: Our Rx buffer is too small! (Raise a defect to make it larger)
|
|
533 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ep0_Rx buffer too small"));
|
|
534 |
iLastError = KErrGeneral;
|
|
535 |
}
|
|
536 |
else
|
|
537 |
{
|
|
538 |
SetEp0DataOutVars();
|
|
539 |
iConTransferMgr->SetupEndpointZeroRead();
|
|
540 |
}
|
|
541 |
#endif
|
|
542 |
}
|
|
543 |
|
|
544 |
void DUsbClientController::ProcessGetConfiguration(const TUsbcSetup& aPacket)
|
|
545 |
{
|
|
546 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetConfiguration()"));
|
|
547 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
548 |
{
|
|
549 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
550 |
iLastError = KErrGeneral;
|
|
551 |
}
|
|
552 |
else if ( iDeviceState == UsbShai::EUsbPeripheralStateAddress && iCurrentConfig != 0)
|
|
553 |
{
|
|
554 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Address && Config != 0"));
|
|
555 |
iLastError = KErrGeneral;
|
|
556 |
}
|
|
557 |
else if ( iDeviceState == UsbShai::EUsbPeripheralStateConfigured && iCurrentConfig == 0)
|
|
558 |
{
|
|
559 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Configured && Config == 0"));
|
|
560 |
iLastError = KErrGeneral;
|
|
561 |
}
|
|
562 |
else
|
|
563 |
{
|
|
564 |
if (aPacket.iLength != 1) // "unspecified behavior"
|
|
565 |
{
|
|
566 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: wLength != 1 (= %d)", aPacket.iLength));
|
|
567 |
}
|
|
568 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting configuration value %d", iCurrentConfig));
|
|
569 |
if (iConTransferMgr->SetupEndpointZeroWrite(&iCurrentConfig, sizeof(iCurrentConfig)) == KErrNone)
|
|
570 |
{
|
|
571 |
iEp0WritePending = ETrue;
|
|
572 |
}
|
|
573 |
else
|
|
574 |
{
|
|
575 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
576 |
}
|
|
577 |
}
|
|
578 |
}
|
|
579 |
|
|
580 |
|
|
581 |
/** Changes the device's configuration value, including interface setup and/or
|
|
582 |
teardown and state change notification of higher-layer clients.
|
|
583 |
May also be called by the PSL in special cases - therefore publishedPartner.
|
|
584 |
|
|
585 |
@param aPacket The received Ep0 SET_CONFIGURATION setup request packet.
|
|
586 |
@return KErrGeneral in case of a protocol error, KErrNone otherwise.
|
|
587 |
|
|
588 |
@publishedPartner @released
|
|
589 |
*/
|
|
590 |
TInt DUsbClientController::ProcessSetConfiguration(const TUsbcSetup& aPacket)
|
|
591 |
{
|
|
592 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetConfiguration()"));
|
|
593 |
|
|
594 |
// This function may be called by the PSL from within an ISR -- so we have
|
|
595 |
// to take care what we do here (and also in all functions that get called
|
|
596 |
// from here).
|
|
597 |
const TInt value = aPacket.iValue;
|
|
598 |
|
|
599 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
|
|
600 |
{
|
|
601 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
602 |
iLastError = KErrGeneral;
|
|
603 |
}
|
|
604 |
else if (value > 1) // we support only one configuration
|
|
605 |
{
|
|
606 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Configuration value too large: %d", value));
|
|
607 |
iLastError = KErrGeneral;
|
|
608 |
}
|
|
609 |
else
|
|
610 |
{
|
|
611 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration value: %d", value));
|
|
612 |
ChangeConfiguration(value);
|
|
613 |
|
|
614 |
// In 9.4.5 under GET_STATUS we read, that after SET_CONFIGURATION the HALT feature
|
|
615 |
// for all endpoints is reset to zero.
|
|
616 |
TInt num = 0;
|
|
617 |
(TAny) DoForEveryEndpointInUse(&DUsbClientController::ClearHaltFeature, num);
|
|
618 |
__KTRACE_OPT(KUSB, Kern::Printf(" Called ClearHaltFeature() for %d endpoints", num));
|
|
619 |
// success: zero bytes data during status stage
|
|
620 |
iConTransferMgr->SendEp0ZeroByteStatusPacket();
|
|
621 |
}
|
|
622 |
|
|
623 |
return iLastError;
|
|
624 |
}
|
|
625 |
|
|
626 |
void DUsbClientController::ProcessGetInterface(const TUsbcSetup& aPacket)
|
|
627 |
{
|
|
628 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterface()"));
|
|
629 |
|
|
630 |
const TInt number = aPacket.iIndex;
|
|
631 |
|
|
632 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
633 |
{
|
|
634 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
635 |
iLastError = KErrGeneral;
|
|
636 |
}
|
|
637 |
else if (iCurrentConfig == 0)
|
|
638 |
{
|
|
639 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured"));
|
|
640 |
iLastError = KErrGeneral;
|
|
641 |
}
|
|
642 |
else if (!InterfaceExists(number))
|
|
643 |
{
|
|
644 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number));
|
|
645 |
iLastError = KErrGeneral;
|
|
646 |
}
|
|
647 |
else
|
|
648 |
{
|
|
649 |
// Send alternate setting code of iCurrentInterface of Interface(set) <number> of the current
|
|
650 |
// config (iCurrentConfig).
|
|
651 |
const TUint8 setting = InterfaceNumber2InterfacePointer(number)->iCurrentInterface;
|
|
652 |
__KTRACE_OPT(KUSB, Kern::Printf(" Reporting interface setting %d", setting));
|
|
653 |
if (iConTransferMgr->SetupEndpointZeroWrite(&setting, 1) == KErrNone)
|
|
654 |
{
|
|
655 |
iEp0WritePending = ETrue;
|
|
656 |
}
|
|
657 |
else
|
|
658 |
{
|
|
659 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
660 |
}
|
|
661 |
}
|
|
662 |
}
|
|
663 |
|
|
664 |
|
|
665 |
void DUsbClientController::ProcessSetInterface(const TUsbcSetup& aPacket)
|
|
666 |
{
|
|
667 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetInterface()"));
|
|
668 |
|
|
669 |
const TInt number = aPacket.iIndex;
|
|
670 |
|
|
671 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
672 |
{
|
|
673 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
674 |
iLastError = KErrGeneral;
|
|
675 |
}
|
|
676 |
else if (iCurrentConfig == 0)
|
|
677 |
{
|
|
678 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured"));
|
|
679 |
iLastError = KErrGeneral;
|
|
680 |
}
|
|
681 |
else if (!InterfaceExists(number))
|
|
682 |
{
|
|
683 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number));
|
|
684 |
iLastError = KErrGeneral;
|
|
685 |
}
|
|
686 |
else
|
|
687 |
{
|
|
688 |
const TInt setting = aPacket.iValue;
|
|
689 |
TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(number);
|
|
690 |
RPointerArray<TUsbcInterface>& ifcs = ifcset_ptr->iInterfaces;
|
|
691 |
if (setting >= ifcs.Count())
|
|
692 |
{
|
|
693 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Alt Setting >= bNumAltSettings: %d", setting));
|
|
694 |
iLastError = KErrGeneral;
|
|
695 |
}
|
|
696 |
else
|
|
697 |
{
|
|
698 |
__KTRACE_OPT(KUSB, Kern::Printf(" Interface setting:: %d", setting));
|
|
699 |
// Set iCurrentInterface of Interface(set) <number> of the current config
|
|
700 |
// (iCurrentConfig) to alternate setting <setting>.
|
|
701 |
ChangeInterface(ifcs[setting]);
|
|
702 |
// In 9.4.5 under GET_STATUS we read, that after SET_INTERFACE the HALT feature
|
|
703 |
// for all endpoints (of the now current interface setting) is reset to zero.
|
|
704 |
RPointerArray<TUsbcLogicalEndpoint>& eps = ifcset_ptr->CurrentInterface()->iEndpoints;
|
|
705 |
const TInt num_eps = eps.Count();
|
|
706 |
for (TInt i = 0; i < num_eps; i++)
|
|
707 |
{
|
|
708 |
const TInt ep_num = EpAddr2Idx(eps[i]->iPEndpoint->iEndpointAddr);
|
|
709 |
(TAny) ClearHaltFeature(ep_num);
|
|
710 |
}
|
|
711 |
// success: zero bytes data during status stage
|
|
712 |
iConTransferMgr->SendEp0ZeroByteStatusPacket();
|
|
713 |
}
|
|
714 |
}
|
|
715 |
}
|
|
716 |
|
|
717 |
|
|
718 |
void DUsbClientController::ProcessSynchFrame(const TUsbcSetup& aPacket)
|
|
719 |
{
|
|
720 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSynchFrame()"));
|
|
721 |
|
|
722 |
const TInt ep = aPacket.iIndex;
|
|
723 |
|
|
724 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
725 |
{
|
|
726 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
727 |
iLastError = KErrGeneral;
|
|
728 |
}
|
|
729 |
else if (EndpointExists(ep) == EFalse)
|
|
730 |
{
|
|
731 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist"));
|
|
732 |
iLastError = KErrGeneral;
|
|
733 |
}
|
|
734 |
else if (iRealEndpoints[EpAddr2Idx(ep)].iLEndpoint->iInfo.iType != UsbShai::KUsbEpTypeIsochronous)
|
|
735 |
{
|
|
736 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint is not isochronous"));
|
|
737 |
iLastError = KErrGeneral;
|
|
738 |
}
|
|
739 |
else
|
|
740 |
{
|
|
741 |
// We always send 0:
|
|
742 |
*reinterpret_cast<TUint16*>(iEp0_TxBuf) = 0x00;
|
|
743 |
if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone)
|
|
744 |
{
|
|
745 |
iEp0WritePending = ETrue;
|
|
746 |
}
|
|
747 |
else
|
|
748 |
{
|
|
749 |
__KTRACE_OPT(KUSB, Kern::Printf(" Wrong: Write to Ep0 Failed"));
|
|
750 |
}
|
|
751 |
}
|
|
752 |
}
|
|
753 |
|
|
754 |
|
|
755 |
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
756 |
void DUsbClientController::ProceedSetDescriptor()
|
|
757 |
{
|
|
758 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProceedSetDescriptor()"));
|
|
759 |
// iEp0DataReceived already reflects the current buffer state
|
|
760 |
if (iEp0DataReceived < iConTransferMgr->PktParser().DataLength())
|
|
761 |
{
|
|
762 |
// Not yet all data received => proceed
|
|
763 |
return;
|
|
764 |
}
|
|
765 |
if (iEp0DataReceived > iConTransferMgr->PktParser().DataLength())
|
|
766 |
{
|
|
767 |
// Error: more data received than expected
|
|
768 |
// but we don't care...
|
|
769 |
}
|
|
770 |
const TUint8 type = HighByte(iConTransferMgr->PktParser().Value());
|
|
771 |
if (type == KUsbDescType_String)
|
|
772 |
{
|
|
773 |
// set/add new string descriptor
|
|
774 |
}
|
|
775 |
else
|
|
776 |
{
|
|
777 |
// set/add new ordinary descriptor
|
|
778 |
}
|
|
779 |
TUint8 index = LowByte(iConTransferMgr->PktParser().Value());
|
|
780 |
TUint16 langid = iConTransferMgr->PktParser().Index();
|
|
781 |
TUint16 length_total = iConTransferMgr->PktParser().DataLength();
|
|
782 |
|
|
783 |
iConTransferMgr->SendEp0ZeroByteStatusPacket();
|
|
784 |
}
|
|
785 |
#endif
|
|
786 |
|
|
787 |
|
|
788 |
// --- Secondary (Helper) Functions
|
|
789 |
|
|
790 |
void DUsbClientController::SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest)
|
|
791 |
{
|
|
792 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetClearHaltFeature()"));
|
|
793 |
if (aRequest == KUsbRequest_SetFeature)
|
|
794 |
{
|
|
795 |
if (iRealEndpoints[aRealEndpoint].iHalt)
|
|
796 |
{
|
|
797 |
// (This condition is not really an error)
|
|
798 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already set"));
|
|
799 |
return;
|
|
800 |
}
|
|
801 |
__KTRACE_OPT(KUSB, Kern::Printf(" setting HALT feature for real endpoint %d",
|
|
802 |
aRealEndpoint));
|
|
803 |
iController.StallEndpoint(aRealEndpoint);
|
|
804 |
iRealEndpoints[aRealEndpoint].iHalt = ETrue;
|
|
805 |
}
|
|
806 |
else // KUsbRequest_ClearFeature
|
|
807 |
{
|
|
808 |
if (iRealEndpoints[aRealEndpoint].iHalt == EFalse)
|
|
809 |
{
|
|
810 |
// In this case, before we return, the data toggles are reset to DATA0.
|
|
811 |
__KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already cleared"));
|
|
812 |
iController.ResetDataToggle(aRealEndpoint);
|
|
813 |
return;
|
|
814 |
}
|
|
815 |
__KTRACE_OPT(KUSB, Kern::Printf(" clearing HALT feature for real endpoint %d",
|
|
816 |
aRealEndpoint));
|
|
817 |
iController.ResetDataToggle(aRealEndpoint);
|
|
818 |
iController.ClearStallEndpoint(aRealEndpoint);
|
|
819 |
iRealEndpoints[aRealEndpoint].iHalt = EFalse;
|
|
820 |
}
|
|
821 |
EpStatusNotify(aRealEndpoint); // only called if actually something changed
|
|
822 |
}
|
|
823 |
|
|
824 |
|
|
825 |
TInt DUsbClientController::ClearHaltFeature(TInt aRealEndpoint)
|
|
826 |
{
|
|
827 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ClearHaltFeature()"));
|
|
828 |
if (iRealEndpoints[aRealEndpoint].iHalt != EFalse)
|
|
829 |
{
|
|
830 |
iController.ClearStallEndpoint(aRealEndpoint);
|
|
831 |
iRealEndpoints[aRealEndpoint].iHalt = EFalse;
|
|
832 |
}
|
|
833 |
return KErrNone;
|
|
834 |
}
|
|
835 |
|
|
836 |
|
|
837 |
void DUsbClientController::ChangeConfiguration(TUint16 aValue)
|
|
838 |
{
|
|
839 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeConfiguration()"));
|
|
840 |
// New configuration is the same as the old one: 0
|
|
841 |
if (iCurrentConfig == 0 && aValue == 0)
|
|
842 |
{
|
|
843 |
// no-op
|
|
844 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == 0 --> exiting"));
|
|
845 |
return;
|
|
846 |
}
|
|
847 |
// New configuration is the same as the old one (but not 0)
|
|
848 |
if (iCurrentConfig == aValue)
|
|
849 |
{
|
|
850 |
// no-op
|
|
851 |
__KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == %d --> exiting", aValue));
|
|
852 |
return;
|
|
853 |
}
|
|
854 |
// Device is already configured
|
|
855 |
if (iCurrentConfig != 0)
|
|
856 |
{
|
|
857 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device was configured: %d", iCurrentConfig));
|
|
858 |
// Tear down all interface(set)s of the old configuration
|
|
859 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets;
|
|
860 |
for (TInt i = 0; i < ifcsets.Count(); ++i)
|
|
861 |
{
|
|
862 |
__KTRACE_OPT(KUSB, Kern::Printf(" Tearing down InterfaceSet %d", i));
|
|
863 |
InterfaceSetTeardown(ifcsets[i]);
|
|
864 |
}
|
|
865 |
iCurrentConfig = 0;
|
|
866 |
// Enter Address state (from Configured)
|
|
867 |
if (iDeviceState == UsbShai::EUsbPeripheralStateConfigured)
|
|
868 |
NextDeviceState(UsbShai::EUsbPeripheralStateAddress);
|
|
869 |
}
|
|
870 |
// Device gets a new configuration
|
|
871 |
if (aValue != 0)
|
|
872 |
{
|
|
873 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device gets new configuration..."));
|
|
874 |
// Setup all alternate settings 0 of all interfaces
|
|
875 |
// (Don't separate the next two lines of code.)
|
|
876 |
iCurrentConfig = aValue;
|
|
877 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets;
|
|
878 |
const TInt n = ifcsets.Count();
|
|
879 |
for (TInt i = 0; i < n; ++i)
|
|
880 |
{
|
|
881 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting up InterfaceSet %d", i));
|
|
882 |
InterfaceSetup(ifcsets[i]->iInterfaces[0]);
|
|
883 |
}
|
|
884 |
// Enter Configured state (from Address or Configured)
|
|
885 |
NextDeviceState(UsbShai::EUsbPeripheralStateConfigured);
|
|
886 |
}
|
|
887 |
__KTRACE_OPT(KUSB, Kern::Printf(" New configuration: %d", iCurrentConfig));
|
|
888 |
return;
|
|
889 |
}
|
|
890 |
|
|
891 |
|
|
892 |
void DUsbClientController::InterfaceSetup(TUsbcInterface* aIfc)
|
|
893 |
{
|
|
894 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetup()"));
|
|
895 |
const TInt num_eps = aIfc->iEndpoints.Count();
|
|
896 |
for (TInt i = 0; i < num_eps; i++)
|
|
897 |
{
|
|
898 |
// Prepare this endpoint for I/O
|
|
899 |
TUsbcLogicalEndpoint* const ep = aIfc->iEndpoints[i];
|
|
900 |
// (TUsbcLogicalEndpoint's FS/HS endpoint sizes and interval values got
|
|
901 |
// adjusted in its constructor.)
|
|
902 |
if (iHighSpeed)
|
|
903 |
{
|
|
904 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (HS)", ep->iEpSize_Hs));
|
|
905 |
ep->iInfo.iSize = ep->iEpSize_Hs;
|
|
906 |
}
|
|
907 |
else
|
|
908 |
{
|
|
909 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (FS)", ep->iEpSize_Fs));
|
|
910 |
ep->iInfo.iSize = ep->iEpSize_Fs;
|
|
911 |
}
|
|
912 |
const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr);
|
|
913 |
if (iController.ConfigureEndpoint(idx, ep->iInfo) != KErrNone)
|
|
914 |
{
|
|
915 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d configuration failed", idx));
|
|
916 |
continue;
|
|
917 |
}
|
|
918 |
// Should there be a problem with it then we could try resetting the ep
|
|
919 |
// data toggle at this point (or before the Configure) as well.
|
|
920 |
__KTRACE_OPT(KUSB, Kern::Printf(" Connecting real ep addr 0x%02x & logical ep #%d",
|
|
921 |
ep->iPEndpoint->iEndpointAddr, ep->iLEndpointNum));
|
|
922 |
ep->iPEndpoint->iLEndpoint = ep;
|
|
923 |
}
|
|
924 |
aIfc->iInterfaceSet->iCurrentInterface = aIfc->iSettingCode;
|
|
925 |
return;
|
|
926 |
}
|
|
927 |
|
|
928 |
|
|
929 |
void DUsbClientController::InterfaceSetTeardown(TUsbcInterfaceSet* aIfcSet)
|
|
930 |
{
|
|
931 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetTeardown()"));
|
|
932 |
if (aIfcSet->iInterfaces.Count() == 0)
|
|
933 |
{
|
|
934 |
__KTRACE_OPT(KUSB, Kern::Printf(" No interfaces exist - returning"));
|
|
935 |
return;
|
|
936 |
}
|
|
937 |
RPointerArray<TUsbcLogicalEndpoint>& eps = aIfcSet->CurrentInterface()->iEndpoints;
|
|
938 |
const TInt num_eps = eps.Count();
|
|
939 |
for (TInt i = 0; i < num_eps; i++)
|
|
940 |
{
|
|
941 |
TUsbcLogicalEndpoint* const ep = eps[i];
|
|
942 |
const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr);
|
|
943 |
|
|
944 |
CancelTransferRequests(idx);
|
|
945 |
|
|
946 |
if (!ep->iPEndpoint->iLEndpoint)
|
|
947 |
{
|
|
948 |
__KTRACE_OPT(KUSB, Kern::Printf(" real ep %d not configured: skipping", idx));
|
|
949 |
continue;
|
|
950 |
}
|
|
951 |
if (iController.ResetDataToggle(idx) != KErrNone)
|
|
952 |
{
|
|
953 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d data toggle reset failed", idx));
|
|
954 |
}
|
|
955 |
if (iController.DeConfigureEndpoint(idx) != KErrNone)
|
|
956 |
{
|
|
957 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d de-configuration failed", idx));
|
|
958 |
}
|
|
959 |
|
|
960 |
__KTRACE_OPT(KUSB, Kern::Printf(" disconnecting real ep & logical ep"));
|
|
961 |
ep->iPEndpoint->iLEndpoint = NULL;
|
|
962 |
}
|
|
963 |
if (aIfcSet->CurrentInterface() != 0)
|
|
964 |
{
|
|
965 |
__KTRACE_OPT(KUSB, Kern::Printf(" Resetting alternate interface setting to 0"));
|
|
966 |
//Add this mutex to protect the interface set data structure
|
|
967 |
if (NKern::CurrentContext() == EThread)
|
|
968 |
{
|
|
969 |
NKern::FMWait(&iMutex);
|
|
970 |
}
|
|
971 |
|
|
972 |
aIfcSet->iCurrentInterface = 0;
|
|
973 |
if (NKern::CurrentContext() == EThread)
|
|
974 |
{
|
|
975 |
NKern::FMSignal(&iMutex);
|
|
976 |
}
|
|
977 |
}
|
|
978 |
return;
|
|
979 |
}
|
|
980 |
|
|
981 |
|
|
982 |
void DUsbClientController::ChangeInterface(TUsbcInterface* aIfc)
|
|
983 |
{
|
|
984 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeInterface()"));
|
|
985 |
TUsbcInterfaceSet* ifcset = aIfc->iInterfaceSet;
|
|
986 |
const TUint8 setting = aIfc->iSettingCode;
|
|
987 |
if (ifcset->iCurrentInterface == setting)
|
|
988 |
{
|
|
989 |
__KTRACE_OPT(KUSB, Kern::Printf(" New Ifc == old Ifc: nothing to do"));
|
|
990 |
return;
|
|
991 |
}
|
|
992 |
__KTRACE_OPT(KUSB, Kern::Printf(" Setting new interface setting #%d", setting));
|
|
993 |
InterfaceSetTeardown(ifcset);
|
|
994 |
InterfaceSetup(aIfc);
|
|
995 |
StatusNotify(static_cast<UsbShai::TUsbPeripheralState>(KUsbAlternateSetting | setting), ifcset->iClientId);
|
|
996 |
}
|
|
997 |
|
|
998 |
|
|
999 |
// aFunction gets called, successively, with the endpoint index of every ep in-use as its argument.
|
|
1000 |
// (BTW: The declaration "type (class::*name)(params)" makes <name> a "pointer to element function".)
|
|
1001 |
//
|
|
1002 |
TInt DUsbClientController::DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount)
|
|
1003 |
{
|
|
1004 |
__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DoForEveryEndpointInUse()"));
|
|
1005 |
aCount = 0;
|
|
1006 |
TUsbcConfiguration* const config = CurrentConfig();
|
|
1007 |
if (!config)
|
|
1008 |
{
|
|
1009 |
__KTRACE_OPT(KUSB, Kern::Printf(" Device is not configured - returning"));
|
|
1010 |
return KErrNone;
|
|
1011 |
}
|
|
1012 |
RPointerArray<TUsbcInterfaceSet>& ifcsets = config->iInterfaceSets;
|
|
1013 |
const TInt num_ifcsets = ifcsets.Count();
|
|
1014 |
for (TInt i = 0; i < num_ifcsets; i++)
|
|
1015 |
{
|
|
1016 |
RPointerArray<TUsbcLogicalEndpoint>& eps = ifcsets[i]->CurrentInterface()->iEndpoints;
|
|
1017 |
const TInt num_eps = eps.Count();
|
|
1018 |
for (TInt j = 0; j < num_eps; j++)
|
|
1019 |
{
|
|
1020 |
const TInt ep_num = EpAddr2Idx(eps[j]->iPEndpoint->iEndpointAddr);
|
|
1021 |
const TInt result = (this->*aFunction)(ep_num);
|
|
1022 |
++aCount;
|
|
1023 |
if (result != KErrNone)
|
|
1024 |
{
|
|
1025 |
return result;
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
}
|
|
1029 |
return KErrNone;
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
// Data Tx is done.
|
|
1033 |
void DUsbClientController::ProcessDataInPacket(TInt aCount,TInt aErrCode)
|
|
1034 |
{
|
|
1035 |
// Clear Error Code
|
|
1036 |
iLastError = KErrNone;
|
|
1037 |
|
|
1038 |
// For tx, no premature end is allowed.
|
|
1039 |
if(aErrCode != KErrNone)
|
|
1040 |
{
|
|
1041 |
// something wrong in hardware, we can do nothing as remedy
|
|
1042 |
// just stall the endpoint.
|
|
1043 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1044 |
iConTransferMgr->SetupEndpointZeroRead();
|
|
1045 |
|
|
1046 |
// set err code to Error general if end point is stalled
|
|
1047 |
iLastError = KErrGeneral;
|
|
1048 |
}
|
|
1049 |
else
|
|
1050 |
{
|
|
1051 |
// no longer a write pending
|
|
1052 |
iEp0WritePending = EFalse;
|
|
1053 |
|
|
1054 |
// If it was a client who set up this transmission, we report to that client
|
|
1055 |
if (iEp0ClientDataTransmitting)
|
|
1056 |
{
|
|
1057 |
iEp0ClientDataTransmitting = EFalse;
|
|
1058 |
TUsbcRequestCallback* const p = iRequestCallbacks[KEp0_Tx];
|
|
1059 |
|
|
1060 |
if (p)
|
|
1061 |
{
|
|
1062 |
__ASSERT_DEBUG((p->iTransferDir == UsbShai::EControllerWrite), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
1063 |
p->iError = aErrCode;
|
|
1064 |
p->iTxBytes = aCount;
|
|
1065 |
|
|
1066 |
// tell the client that the sending is done
|
|
1067 |
// later, it is possible that a status out packet comes in,
|
|
1068 |
// just ignore it.
|
|
1069 |
ProcessDataTransferDone(*p);
|
|
1070 |
}
|
|
1071 |
else
|
|
1072 |
{
|
|
1073 |
// we should never goes here
|
|
1074 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1075 |
|
|
1076 |
// request not found
|
|
1077 |
iLastError = KErrNotFound;
|
|
1078 |
}
|
|
1079 |
}
|
|
1080 |
// else
|
|
1081 |
// it is our own who sending the data, no more action needed
|
|
1082 |
}
|
|
1083 |
}
|
|
1084 |
|
|
1085 |
// Status Rx is done
|
|
1086 |
void DUsbClientController::ProcessStatusOutPacket(TInt aErrCode)
|
|
1087 |
{
|
|
1088 |
// Clear Error Code
|
|
1089 |
iLastError = KErrNone;
|
|
1090 |
|
|
1091 |
// Dangdang, psl saying a status out packet recieved from
|
|
1092 |
// host, but, we already completed user's writting request, just ignore it.
|
|
1093 |
|
|
1094 |
// any way, receiving this means no write is pending.
|
|
1095 |
iEp0WritePending = EFalse;
|
|
1096 |
}
|
|
1097 |
|
|
1098 |
// Data Rx is (partial) done
|
|
1099 |
void DUsbClientController::ProcessDataOutPacket(TInt aCount,TInt aErrCode)
|
|
1100 |
{
|
|
1101 |
// Clear Error Code
|
|
1102 |
iLastError = KErrNone;
|
|
1103 |
|
|
1104 |
if (aErrCode != KErrNone && aErrCode != KErrPrematureEnd)
|
|
1105 |
{
|
|
1106 |
// something wrong in hardware, we can do nothing as remedy
|
|
1107 |
// just stall the endpoint.
|
|
1108 |
iConTransferMgr->StallEndpoint(KEp0_Out);
|
|
1109 |
iConTransferMgr->SetupEndpointZeroRead();
|
|
1110 |
|
|
1111 |
// set err code to Error general if end point is stalled
|
|
1112 |
iLastError = KErrGeneral;
|
|
1113 |
}
|
|
1114 |
else
|
|
1115 |
{
|
|
1116 |
// Trim aCount with iEp0MaxPacketSize per packet
|
|
1117 |
if (aCount > iEp0MaxPacketSize)
|
|
1118 |
{
|
|
1119 |
aCount = iEp0MaxPacketSize;
|
|
1120 |
}
|
|
1121 |
|
|
1122 |
iEp0DataReceived += aCount;
|
|
1123 |
|
|
1124 |
if (iEp0ClientId == NULL)
|
|
1125 |
{
|
|
1126 |
// it is us( not an app), who owns this transaction
|
|
1127 |
switch( iConTransferMgr->PktParser().Request())
|
|
1128 |
{
|
|
1129 |
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
1130 |
case KUsbRequest_SetDescriptor:
|
|
1131 |
{
|
|
1132 |
memcpy(iEp0_RxCollectionBuf + iEp0DataReceived, iEp0_RxBuf, aCount);
|
|
1133 |
|
|
1134 |
// Status will be sent in side this function
|
|
1135 |
// if we had recieved enough bytes
|
|
1136 |
ProceedSetDescriptor();
|
|
1137 |
}
|
|
1138 |
break;
|
|
1139 |
#endif
|
|
1140 |
default:
|
|
1141 |
{
|
|
1142 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1143 |
ResetEp0DataOutVars();
|
|
1144 |
|
|
1145 |
// set err code to Error general if end point is stalled
|
|
1146 |
iLastError = KErrGeneral;
|
|
1147 |
}
|
|
1148 |
break;
|
|
1149 |
}
|
|
1150 |
|
|
1151 |
if (iEp0DataReceived >= iConTransferMgr->PktParser().DataLength())
|
|
1152 |
{
|
|
1153 |
// all data seems now to be here
|
|
1154 |
ResetEp0DataOutVars();
|
|
1155 |
}
|
|
1156 |
}
|
|
1157 |
else
|
|
1158 |
{
|
|
1159 |
// it is an application who is requesting this data
|
|
1160 |
// pass the data on to a client
|
|
1161 |
|
|
1162 |
// it is the client's responsibility of sending a status
|
|
1163 |
// packet back to host to indicate the whole transfer is
|
|
1164 |
// done
|
|
1165 |
|
|
1166 |
// Find the client Request callback
|
|
1167 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
|
|
1168 |
TUsbcRequestCallback* p;
|
|
1169 |
while ((p = iter++) != NULL)
|
|
1170 |
{
|
|
1171 |
if (p->Owner() == iEp0ClientId)
|
|
1172 |
{
|
|
1173 |
memcpy(p->iBufferStart, iEp0_RxBuf, aCount);
|
|
1174 |
p->iError = KErrNone;
|
|
1175 |
*(p->iPacketSize) = aCount;
|
|
1176 |
p->iRxPackets = 1;
|
|
1177 |
*(p->iPacketIndex) = 0;
|
|
1178 |
break;
|
|
1179 |
}
|
|
1180 |
}
|
|
1181 |
|
|
1182 |
// pass data to client if found one.
|
|
1183 |
if ( p != NULL)
|
|
1184 |
{
|
|
1185 |
ProcessDataTransferDone(*p);
|
|
1186 |
|
|
1187 |
if (iEp0DataReceived >= iConTransferMgr->PktParser().DataLength())
|
|
1188 |
{
|
|
1189 |
// all data seems now to be here
|
|
1190 |
ResetEp0DataOutVars();
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
iLastError = KErrNone;
|
|
1194 |
|
|
1195 |
}
|
|
1196 |
else
|
|
1197 |
{
|
|
1198 |
// that's bad, we found a client is request this data
|
|
1199 |
// but no matching request callback found.
|
|
1200 |
|
|
1201 |
iEp0_RxExtraCount = aCount;
|
|
1202 |
//iEp0_RxExtraData = ETrue;
|
|
1203 |
//iEp0_RxExtraError = aErrCode;
|
|
1204 |
iEp0DataReceived -= aCount;
|
|
1205 |
|
|
1206 |
// No status packet will be send to host since no client is reading this data,
|
|
1207 |
// waiting client to send a status packet.
|
|
1208 |
|
|
1209 |
iLastError = KErrNotFound;
|
|
1210 |
}
|
|
1211 |
}
|
|
1212 |
}
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
// Status Tx is done
|
|
1216 |
void DUsbClientController::ProcessStatusInPacket(TInt aErrCode)
|
|
1217 |
{
|
|
1218 |
// Clear Error Code
|
|
1219 |
iLastError = KErrNone;
|
|
1220 |
|
|
1221 |
// it is time to start a new read
|
|
1222 |
iEp0WritePending = EFalse;
|
|
1223 |
}
|
|
1224 |
|
|
1225 |
//
|
|
1226 |
// Setup Rx is done
|
|
1227 |
//
|
|
1228 |
void DUsbClientController::ProcessSetupPacket(TInt aCount,TInt aErrCode)
|
|
1229 |
{
|
|
1230 |
|
|
1231 |
if (aErrCode != KErrNone)
|
|
1232 |
{
|
|
1233 |
// something wrong in hardware, we can do nothing as remedy
|
|
1234 |
// just stall the endpoint.
|
|
1235 |
iConTransferMgr->StallEndpoint(KEp0_Out);
|
|
1236 |
iConTransferMgr->SetupEndpointZeroRead();
|
|
1237 |
|
|
1238 |
// set err code to Error general if end point is stalled
|
|
1239 |
iLastError = KErrGeneral;
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
TUsbcSetup packet;
|
|
1243 |
Buffer2Setup(iEp0_RxBuf, packet);
|
|
1244 |
|
|
1245 |
// Clear Error Code
|
|
1246 |
iLastError = KErrNone;
|
|
1247 |
|
|
1248 |
// If this is a standard request, we can handle it here
|
|
1249 |
// not need to bother app layer
|
|
1250 |
if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd)
|
|
1251 |
{
|
|
1252 |
// Fixme: this may not needed any more
|
|
1253 |
iEp0ReceivedNonStdRequest = EFalse;
|
|
1254 |
ProcessStandardRequest(aCount,packet);
|
|
1255 |
}
|
|
1256 |
else
|
|
1257 |
{
|
|
1258 |
// Fixme: This may not needed anymore
|
|
1259 |
iEp0ReceivedNonStdRequest = ETrue;
|
|
1260 |
ProcessNonStandardRequest(aCount,packet);
|
|
1261 |
}
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
#define USB_PROCESS_REQUEST(request,param) \
|
|
1265 |
do \
|
|
1266 |
{ \
|
|
1267 |
Process ## request(param); \
|
|
1268 |
if (iLastError != KErrNone) \
|
|
1269 |
{ \
|
|
1270 |
__KTRACE_OPT(KUSB, \
|
|
1271 |
Kern::Printf(" ProcessEp0SetupReceived: Stalling Ep0")); \
|
|
1272 |
iConTransferMgr->StallEndpoint(KEp0_In); \
|
|
1273 |
} \
|
|
1274 |
}while(0)
|
|
1275 |
|
|
1276 |
|
|
1277 |
//
|
|
1278 |
// Standard request
|
|
1279 |
// Please note that:Macro USB_PROCESS_REQUEST(xxx) will stall endpoint
|
|
1280 |
// if anything wrong during the process, in which case status packet is
|
|
1281 |
// not needed.
|
|
1282 |
//
|
|
1283 |
void DUsbClientController::ProcessStandardRequest(TInt /*aCount*/,const TUsbcSetup& aPacket)
|
|
1284 |
{
|
|
1285 |
switch (aPacket.iRequest)
|
|
1286 |
{
|
|
1287 |
case KUsbRequest_GetStatus:
|
|
1288 |
switch (aPacket.iRequestType & KUsbRequestType_DestMask)
|
|
1289 |
{ // Recipient
|
|
1290 |
case KUsbRequestType_DestDevice:
|
|
1291 |
USB_PROCESS_REQUEST(GetDeviceStatus,aPacket);
|
|
1292 |
break;
|
|
1293 |
|
|
1294 |
case KUsbRequestType_DestIfc:
|
|
1295 |
USB_PROCESS_REQUEST(GetInterfaceStatus,aPacket);
|
|
1296 |
break;
|
|
1297 |
|
|
1298 |
case KUsbRequestType_DestEp:
|
|
1299 |
USB_PROCESS_REQUEST(GetEndpointStatus,aPacket);
|
|
1300 |
break;
|
|
1301 |
|
|
1302 |
default:
|
|
1303 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: GET STATUS - Other or Unknown recipient"));
|
|
1304 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> DUsbClientController::ProcessEp0SetupReceived: "
|
|
1305 |
"Stalling Ep0"));
|
|
1306 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1307 |
iLastError = KErrGeneral;
|
|
1308 |
break;
|
|
1309 |
}
|
|
1310 |
break;
|
|
1311 |
|
|
1312 |
case KUsbRequest_ClearFeature:
|
|
1313 |
case KUsbRequest_SetFeature:
|
|
1314 |
switch (aPacket.iRequestType & KUsbRequestType_DestMask)
|
|
1315 |
{ // Recipient
|
|
1316 |
case KUsbRequestType_DestDevice:
|
|
1317 |
USB_PROCESS_REQUEST(SetClearDevFeature,aPacket);
|
|
1318 |
break;
|
|
1319 |
case KUsbRequestType_DestIfc:
|
|
1320 |
// will 100% stall endpoint
|
|
1321 |
USB_PROCESS_REQUEST(SetClearIfcFeature,aPacket);
|
|
1322 |
break;
|
|
1323 |
case KUsbRequestType_DestEp:
|
|
1324 |
USB_PROCESS_REQUEST(SetClearEpFeature,aPacket);
|
|
1325 |
break;
|
|
1326 |
default:
|
|
1327 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: SET/CLEAR FEATURE - "
|
|
1328 |
"Other or Unknown recipient"));
|
|
1329 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0"));
|
|
1330 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1331 |
iLastError = KErrGeneral;
|
|
1332 |
break;
|
|
1333 |
}
|
|
1334 |
break;
|
|
1335 |
|
|
1336 |
case KUsbRequest_SetAddress:
|
|
1337 |
USB_PROCESS_REQUEST(SetAddress,aPacket);
|
|
1338 |
break;
|
|
1339 |
|
|
1340 |
case KUsbRequest_GetDescriptor:
|
|
1341 |
USB_PROCESS_REQUEST(GetDescriptor,aPacket);
|
|
1342 |
break;
|
|
1343 |
|
|
1344 |
case KUsbRequest_SetDescriptor:
|
|
1345 |
USB_PROCESS_REQUEST(SetDescriptor,aPacket);
|
|
1346 |
break;
|
|
1347 |
|
|
1348 |
case KUsbRequest_GetConfig:
|
|
1349 |
USB_PROCESS_REQUEST(GetConfiguration,aPacket);
|
|
1350 |
break;
|
|
1351 |
|
|
1352 |
case KUsbRequest_SetConfig:
|
|
1353 |
USB_PROCESS_REQUEST(SetConfiguration,aPacket);
|
|
1354 |
break;
|
|
1355 |
|
|
1356 |
case KUsbRequest_GetInterface:
|
|
1357 |
USB_PROCESS_REQUEST(GetInterface,aPacket);
|
|
1358 |
break;
|
|
1359 |
|
|
1360 |
case KUsbRequest_SetInterface:
|
|
1361 |
USB_PROCESS_REQUEST(SetInterface,aPacket);
|
|
1362 |
break;
|
|
1363 |
|
|
1364 |
case KUsbRequest_SynchFrame:
|
|
1365 |
USB_PROCESS_REQUEST(SynchFrame,aPacket);
|
|
1366 |
break;
|
|
1367 |
|
|
1368 |
default:
|
|
1369 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown/unsupported Std Setup Request"));
|
|
1370 |
__KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0"));
|
|
1371 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1372 |
iLastError = KErrGeneral;
|
|
1373 |
break;
|
|
1374 |
}
|
|
1375 |
}
|
|
1376 |
|
|
1377 |
#undef USB_PROCESS_REQUEST
|
|
1378 |
|
|
1379 |
//
|
|
1380 |
// class- or vendor-specific request
|
|
1381 |
// we dont send back any status to host in PIL for class- or vendor-specific request
|
|
1382 |
// if no client is waiting, stall the endpoint
|
|
1383 |
// if client is not ready, just record them and waiting for client to read them
|
|
1384 |
// (and, send a status packet)
|
|
1385 |
//
|
|
1386 |
void DUsbClientController::ProcessNonStandardRequest(TInt aCount,const TUsbcSetup& aPacket)
|
|
1387 |
{
|
|
1388 |
// Find out which client can handle this request
|
|
1389 |
const DBase* client = FindNonStandardRequestClient(aPacket.iRequestType & KUsbRequestType_DestMask,aPacket);
|
|
1390 |
|
|
1391 |
// If client is valide
|
|
1392 |
if (client != NULL)
|
|
1393 |
{
|
|
1394 |
// Try to relay aPacket to the real recipient
|
|
1395 |
TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
|
|
1396 |
TUsbcRequestCallback* p;
|
|
1397 |
|
|
1398 |
// Find out the request callback with match the client
|
|
1399 |
// returned from last FindNonStandardRequestClient().
|
|
1400 |
while ((p = iter++) != NULL)
|
|
1401 |
{
|
|
1402 |
if (p->Owner() == client)
|
|
1403 |
{
|
|
1404 |
__ASSERT_DEBUG((p->iEndpointNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
1405 |
__ASSERT_DEBUG((p->iTransferDir == UsbShai::EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
1406 |
__KTRACE_OPT(KUSB, Kern::Printf(" Found Ep0 read request"));
|
|
1407 |
if (aPacket.iLength != 0)
|
|
1408 |
{
|
|
1409 |
if ((aPacket.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
|
|
1410 |
{
|
|
1411 |
// Data transfer & direction OUT => there'll be a DATA_OUT stage
|
|
1412 |
__KTRACE_OPT(KUSB, Kern::Printf(" Next is DATA_OUT: setting up DataOutVars"));
|
|
1413 |
SetEp0DataOutVars(client);
|
|
1414 |
}
|
|
1415 |
else if ((aPacket.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToHost)
|
|
1416 |
{
|
|
1417 |
// For possible later use (ZLP).
|
|
1418 |
iEp0_TxNonStdCount = aPacket.iLength;
|
|
1419 |
}
|
|
1420 |
}
|
|
1421 |
|
|
1422 |
// Found the request callback, jump out now
|
|
1423 |
break;
|
|
1424 |
}
|
|
1425 |
}
|
|
1426 |
|
|
1427 |
// if a request callback matching the client is found,
|
|
1428 |
// complete the request
|
|
1429 |
if( p != NULL)
|
|
1430 |
{
|
|
1431 |
__KTRACE_OPT(KUSB, Kern::Printf(" Ep0 read request completed to client"));
|
|
1432 |
memcpy(p->iBufferStart, iEp0_RxBuf, aCount);
|
|
1433 |
p->iError = KErrNone;
|
|
1434 |
*(p->iPacketSize) = aCount;
|
|
1435 |
p->iRxPackets = 1;
|
|
1436 |
*(p->iPacketIndex) = 0;
|
|
1437 |
ProcessDataTransferDone(*p);
|
|
1438 |
}
|
|
1439 |
else
|
|
1440 |
{
|
|
1441 |
__KTRACE_OPT(KUSB, Kern::Printf(" Ep0 read request not found: setting RxExtra vars (Setup)"));
|
|
1442 |
iEp0_RxExtraCount = aCount;
|
|
1443 |
//iEp0_RxExtraData = ETrue;
|
|
1444 |
//iEp0_RxExtraError = aErrCode;
|
|
1445 |
iSetupPacketPending = ETrue;
|
|
1446 |
|
|
1447 |
// For setup packet,a zero bytes status is always needed
|
|
1448 |
iLastError = KErrNotFound;
|
|
1449 |
}
|
|
1450 |
}
|
|
1451 |
else // if (client == NULL)
|
|
1452 |
{
|
|
1453 |
// Pil don't know how to deal with non-standard request, stall endpoint
|
|
1454 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Ep0 request error: Stalling Ep0"));
|
|
1455 |
iConTransferMgr->StallEndpoint(KEp0_In);
|
|
1456 |
iLastError = KErrGeneral;
|
|
1457 |
}
|
|
1458 |
}
|
|
1459 |
|
|
1460 |
const DBase* DUsbClientController::FindNonStandardRequestClient(TUint8 aPacketTypeDestination,const TUsbcSetup& aPacket)
|
|
1461 |
{
|
|
1462 |
const DBase* client = NULL;
|
|
1463 |
|
|
1464 |
switch (aPacketTypeDestination)
|
|
1465 |
{ // Recipient
|
|
1466 |
case KUsbRequestType_DestDevice:
|
|
1467 |
{
|
|
1468 |
client = iEp0DeviceControl;
|
|
1469 |
}
|
|
1470 |
break;
|
|
1471 |
|
|
1472 |
case KUsbRequestType_DestIfc:
|
|
1473 |
{
|
|
1474 |
//Add this mutex to protect the interface set data structure
|
|
1475 |
if (NKern::CurrentContext() == EThread)
|
|
1476 |
{
|
|
1477 |
NKern::FMWait(&iMutex);
|
|
1478 |
}
|
|
1479 |
|
|
1480 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
1481 |
{
|
|
1482 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
1483 |
}
|
|
1484 |
else
|
|
1485 |
{
|
|
1486 |
const TUsbcInterfaceSet* const ifcset_ptr =
|
|
1487 |
InterfaceNumber2InterfacePointer(aPacket.iIndex);
|
|
1488 |
|
|
1489 |
//In some rare case, ifcset_ptr is not NULL but the ifcset_ptr->iInterfaces.Count() is 0,
|
|
1490 |
//so panic will happen when excute the following line. so I add the conditon
|
|
1491 |
//0 != ifcset_ptr->iInterfaces.Count() here.
|
|
1492 |
if (ifcset_ptr && 0 != ifcset_ptr->iInterfaces.Count())
|
|
1493 |
{
|
|
1494 |
if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
|
|
1495 |
{
|
|
1496 |
__KTRACE_OPT(KUSB, Kern::Printf(" Recipient says: NoEp0RequestsPlease"));
|
|
1497 |
}
|
|
1498 |
else
|
|
1499 |
{
|
|
1500 |
client = ifcset_ptr->iClientId;
|
|
1501 |
}
|
|
1502 |
}
|
|
1503 |
else
|
|
1504 |
{
|
|
1505 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface 0x%02x does not exist",
|
|
1506 |
aPacket.iIndex));
|
|
1507 |
}
|
|
1508 |
}
|
|
1509 |
|
|
1510 |
if (NKern::CurrentContext() == EThread)
|
|
1511 |
{
|
|
1512 |
NKern::FMSignal(&iMutex);
|
|
1513 |
}
|
|
1514 |
}
|
|
1515 |
break;
|
|
1516 |
|
|
1517 |
case KUsbRequestType_DestEp:
|
|
1518 |
{
|
|
1519 |
//Add this mutex to protect the interface set data structure
|
|
1520 |
if (NKern::CurrentContext() == EThread)
|
|
1521 |
{
|
|
1522 |
NKern::FMWait(&iMutex);
|
|
1523 |
}
|
|
1524 |
if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
|
|
1525 |
{
|
|
1526 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state"));
|
|
1527 |
}
|
|
1528 |
else if (EndpointExists(aPacket.iIndex) == EFalse)
|
|
1529 |
{
|
|
1530 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint 0x%02x does not exist",
|
|
1531 |
aPacket.iIndex));
|
|
1532 |
}
|
|
1533 |
else
|
|
1534 |
{
|
|
1535 |
const TInt idx = EpAddr2Idx(aPacket.iIndex);
|
|
1536 |
const TUsbcInterfaceSet* const ifcset_ptr =
|
|
1537 |
iRealEndpoints[idx].iLEndpoint->iInterface->iInterfaceSet;
|
|
1538 |
if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
|
|
1539 |
{
|
|
1540 |
__KTRACE_OPT(KUSB, Kern::Printf(" Recipient says: NoEp0RequestsPlease"));
|
|
1541 |
}
|
|
1542 |
else
|
|
1543 |
{
|
|
1544 |
client = ifcset_ptr->iClientId;
|
|
1545 |
}
|
|
1546 |
}
|
|
1547 |
if (NKern::CurrentContext() == EThread)
|
|
1548 |
{
|
|
1549 |
NKern::FMSignal(&iMutex);
|
|
1550 |
}
|
|
1551 |
}
|
|
1552 |
break;
|
|
1553 |
|
|
1554 |
default:
|
|
1555 |
{
|
|
1556 |
__KTRACE_OPT(KPANIC, Kern::Printf(" Error: Other or Unknown recipient"));
|
|
1557 |
break;
|
|
1558 |
}
|
|
1559 |
}
|
|
1560 |
|
|
1561 |
return client;
|
|
1562 |
}
|
|
1563 |
|
|
1564 |
TInt DUsbClientController::ProcessSetupEndpointZeroRead()
|
|
1565 |
{
|
|
1566 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Read EP0 Issued"));
|
|
1567 |
return iController.SetupEndpointZeroRead();
|
|
1568 |
}
|
|
1569 |
|
|
1570 |
TInt DUsbClientController::ProcessSetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd)
|
|
1571 |
{
|
|
1572 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Write EP0 Issued"));
|
|
1573 |
return iController.SetupEndpointZeroWrite(aBuffer,aLength,aZlpReqd);
|
|
1574 |
}
|
|
1575 |
|
|
1576 |
TInt DUsbClientController::ProcessSendEp0ZeroByteStatusPacket()
|
|
1577 |
{
|
|
1578 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Zero Status to EP0 Issued"));
|
|
1579 |
return iController.SendEp0ZeroByteStatusPacket();
|
|
1580 |
}
|
|
1581 |
|
|
1582 |
TInt DUsbClientController::ProcessStallEndpoint(TInt aRealEndpoint)
|
|
1583 |
{
|
|
1584 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: EP0(%d) Stall Issued",aRealEndpoint));
|
|
1585 |
return iController.StallEndpoint(aRealEndpoint);
|
|
1586 |
}
|
|
1587 |
|
|
1588 |
void DUsbClientController::ProcessEp0SetupPacketProceed()
|
|
1589 |
{
|
|
1590 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Missed setup packet procced"));
|
|
1591 |
iController.Ep0ReadSetupPktProceed();
|
|
1592 |
}
|
|
1593 |
|
|
1594 |
void DUsbClientController::ProcessEp0DataPacketProceed()
|
|
1595 |
{
|
|
1596 |
__KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Missed data packet procced"));
|
|
1597 |
iController.Ep0ReadDataPktProceed();
|
|
1598 |
}
|
|
1599 |
|
|
1600 |
// -eof-
|