59 |
64 |
60 @publishedPartner @released |
65 @publishedPartner @released |
61 */ |
66 */ |
62 TUsbcEp0State DUsbClientController::EnquireEp0NextState(const TUint8* aSetupBuf) const |
67 TUsbcEp0State DUsbClientController::EnquireEp0NextState(const TUint8* aSetupBuf) const |
63 { |
68 { |
64 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnquireEp0NextState()")); |
69 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENQUIREEP0NEXTSTATE, |
|
70 "DUsbClientController::EnquireEp0NextState()" ); |
65 |
71 |
66 // This function may be called by the PSL from within an ISR -- so we have |
72 // 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 |
73 // to take care what we do here (and also in all functions that get called |
68 // from here). |
74 // from here). |
69 |
75 |
70 if (SWAP_BYTES_16((reinterpret_cast<const TUint16*>(aSetupBuf)[3])) == 0) // iLength |
76 if (SWAP_BYTES_16((reinterpret_cast<const TUint16*>(aSetupBuf)[3])) == 0) // iLength |
71 { |
77 { |
72 __KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateStatusIn")); |
78 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENQUIREEP0NEXTSTATE_DUP1, |
|
79 " --> EEp0StateStatusIn" ); |
|
80 |
73 return EEp0StateStatusIn; // No-data Control => Status_IN |
81 return EEp0StateStatusIn; // No-data Control => Status_IN |
74 } |
82 } |
75 else if ((aSetupBuf[0] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev) |
83 else if ((aSetupBuf[0] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev) |
76 { |
84 { |
77 __KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateDataOut")); |
85 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENQUIREEP0NEXTSTATE_DUP2, |
|
86 " --> EEp0StateDataOut" ); |
78 return EEp0StateDataOut; // Control Write => Data_OUT |
87 return EEp0StateDataOut; // Control Write => Data_OUT |
79 } |
88 } |
80 else |
89 else |
81 { |
90 { |
82 __KTRACE_OPT(KUSB, Kern::Printf(" --> EEp0StateDataIn")); |
91 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENQUIREEP0NEXTSTATE_DUP3, |
|
92 " --> EEp0StateDataIn" ); |
83 return EEp0StateDataIn; // Control Read => Data_IN |
93 return EEp0StateDataIn; // Control Read => Data_IN |
84 } |
94 } |
85 } |
95 } |
86 |
96 |
87 |
97 |
88 TInt DUsbClientController::ProcessEp0ReceiveDone(TInt aCount) |
98 TInt DUsbClientController::ProcessEp0ReceiveDone(TInt aCount) |
89 { |
99 { |
90 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessEp0ReceiveDone()")); |
100 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0RECEIVEDONE, |
|
101 "DUsbClientController::ProcessEp0ReceiveDone()" ); |
91 TInt r; |
102 TInt r; |
92 if (iEp0DataReceiving == EFalse) |
103 if (iEp0DataReceiving == EFalse) |
93 { |
104 { |
94 // It's obviously a Setup packet, so... |
105 // It's obviously a Setup packet, so... |
95 r = ProcessEp0SetupReceived(aCount); |
106 r = ProcessEp0SetupReceived(aCount); |
158 TUsbcSetup packet; |
163 TUsbcSetup packet; |
159 Buffer2Setup(iEp0_RxBuf, packet); |
164 Buffer2Setup(iEp0_RxBuf, packet); |
160 |
165 |
161 #if defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
166 #if defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
162 // let's see what we've got: |
167 // let's see what we've got: |
163 __KTRACE_OPT(KUSB, Kern::Printf(" bmRequestType = 0x%02x", packet.iRequestType)); |
168 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP1, |
|
169 " bmRequestType = 0x%02x", packet.iRequestType ); |
164 if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
170 if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
165 { |
171 { |
166 switch (packet.iRequest) |
172 switch (packet.iRequest) |
167 { |
173 { |
168 case KUsbRequest_GetStatus: |
174 case KUsbRequest_GetStatus: |
169 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_STATUS)", |
175 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP2, |
170 KUsbRequest_GetStatus)); |
176 " bRequest = 0x%02x (GET_STATUS)", KUsbRequest_GetStatus ); |
171 break; |
177 break; |
172 case KUsbRequest_ClearFeature: |
178 case KUsbRequest_ClearFeature: |
173 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (CLEAR_FEATURE)", |
179 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP3, |
174 KUsbRequest_ClearFeature)); |
180 " bRequest = 0x%02x (CLEAR_FEATURE)", KUsbRequest_ClearFeature ); |
175 break; |
181 break; |
176 case KUsbRequest_SetFeature: |
182 case KUsbRequest_SetFeature: |
177 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_FEATURE)", |
183 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP4, |
178 KUsbRequest_SetFeature)); |
184 " bRequest = 0x%02x (SET_FEATURE)", KUsbRequest_SetFeature ); |
179 break; |
185 break; |
180 case KUsbRequest_SetAddress: |
186 case KUsbRequest_SetAddress: |
181 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_ADDRESS)", |
187 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP5, |
182 KUsbRequest_SetAddress)); |
188 " bRequest = 0x%02x (SET_ADDRESS)", KUsbRequest_SetAddress ); |
183 break; |
189 break; |
184 case KUsbRequest_GetDescriptor: |
190 case KUsbRequest_GetDescriptor: |
185 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_DESCRIPTOR)", |
191 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP6, |
186 KUsbRequest_GetDescriptor)); |
192 " bRequest = 0x%02x (GET_DESCRIPTOR)", KUsbRequest_GetDescriptor ); |
187 break; |
193 break; |
188 case KUsbRequest_SetDescriptor: |
194 case KUsbRequest_SetDescriptor: |
189 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_DESCRIPTOR)", |
195 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP7, |
190 KUsbRequest_SetDescriptor)); |
196 " bRequest = 0x%02x (SET_DESCRIPTOR)", KUsbRequest_SetDescriptor ); |
191 break; |
197 break; |
192 case KUsbRequest_GetConfig: |
198 case KUsbRequest_GetConfig: |
193 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_CONFIGURATION)", |
199 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP8, |
194 KUsbRequest_GetConfig)); |
200 " bRequest = 0x%02x (GET_CONFIGURATION)", KUsbRequest_GetConfig ); |
195 break; |
201 break; |
196 case KUsbRequest_SetConfig: |
202 case KUsbRequest_SetConfig: |
197 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_CONFIGURATION)", |
203 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP9, |
198 KUsbRequest_SetConfig)); |
204 " bRequest = 0x%02x (SET_CONFIGURATION)", KUsbRequest_SetConfig ); |
199 break; |
205 break; |
200 case KUsbRequest_GetInterface: |
206 case KUsbRequest_GetInterface: |
201 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (GET_INTERFACE)", |
207 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP10, |
202 KUsbRequest_GetInterface)); |
208 " bRequest = 0x%02x (GET_INTERFACE)", KUsbRequest_GetInterface ); |
203 break; |
209 break; |
204 case KUsbRequest_SetInterface: |
210 case KUsbRequest_SetInterface: |
205 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SET_INTERFACE)", |
211 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP11, |
206 KUsbRequest_SetInterface)); |
212 " bRequest = 0x%02x (SET_INTERFACE)", KUsbRequest_SetInterface ); |
207 break; |
213 break; |
208 case KUsbRequest_SynchFrame: |
214 case KUsbRequest_SynchFrame: |
209 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (SYNCH_FRAME)", |
215 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP12, |
210 KUsbRequest_SynchFrame)); |
216 " bRequest = 0x%02x (SYNCH_FRAME)", KUsbRequest_SynchFrame ); |
211 break; |
217 break; |
212 default: |
218 default: |
213 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: bRequest = 0x%02x (UNKNWON STANDARD REQUEST)", |
219 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP13, |
214 packet.iRequest)); |
220 " Error: bRequest = 0x%02x (UNKNWON STANDARD REQUEST)", packet.iRequest ); |
215 break; |
221 break; |
216 } |
222 } |
217 } |
223 } |
218 else |
224 else |
219 { |
225 { |
220 __KTRACE_OPT(KUSB, Kern::Printf(" bRequest = 0x%02x (NON-STANDARD REQUEST)", |
226 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP14, |
221 packet.iRequest)); |
227 " bRequest = 0x%02x (NON-STANDARD REQUEST)", packet.iRequest ); |
222 } |
228 } |
223 __KTRACE_OPT(KUSB, Kern::Printf(" wValue = 0x%04x", packet.iValue)); |
229 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP15, |
224 __KTRACE_OPT(KUSB, Kern::Printf(" wIndex = 0x%04x", packet.iIndex)); |
230 " wValue = 0x%04x", packet.iValue ); |
225 __KTRACE_OPT(KUSB, Kern::Printf(" wLength = 0x%04x", packet.iLength)); |
231 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP16, |
|
232 " wIndex = 0x%04x", packet.iIndex ); |
|
233 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP17, |
|
234 " wLength = 0x%04x", packet.iLength ); |
226 #endif // defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
235 #endif // defined(_DEBUG) && defined(ENABLE_EXCESSIVE_DEBUG_OUTPUT) |
227 |
236 |
228 // now the actual analysis |
237 // now the actual analysis |
229 if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
238 if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd) |
230 { |
239 { |
233 { |
242 { |
234 case KUsbRequest_GetStatus: |
243 case KUsbRequest_GetStatus: |
235 switch (packet.iRequestType & KUsbRequestType_DestMask) |
244 switch (packet.iRequestType & KUsbRequestType_DestMask) |
236 { // Recipient |
245 { // Recipient |
237 case KUsbRequestType_DestDevice: |
246 case KUsbRequestType_DestDevice: |
238 USB_PROCESS_REQUEST(GetDeviceStatus); |
247 if (ProcessGetDeviceStatus(packet) != KErrNone) |
|
248 { |
|
249 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP18, |
|
250 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
251 StallEndpoint(KEp0_In); |
|
252 } |
239 break; |
253 break; |
240 case KUsbRequestType_DestIfc: |
254 case KUsbRequestType_DestIfc: |
241 USB_PROCESS_REQUEST(GetInterfaceStatus); |
255 if (ProcessGetInterfaceStatus(packet) != KErrNone) |
|
256 { |
|
257 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP19, |
|
258 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
259 StallEndpoint(KEp0_In); |
|
260 } |
242 break; |
261 break; |
243 case KUsbRequestType_DestEp: |
262 case KUsbRequestType_DestEp: |
244 USB_PROCESS_REQUEST(GetEndpointStatus); |
263 if (ProcessGetEndpointStatus(packet) != KErrNone) |
|
264 { |
|
265 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP20, |
|
266 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
267 StallEndpoint(KEp0_In); |
|
268 } |
245 break; |
269 break; |
246 default: |
270 default: |
247 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: GET STATUS - Other or Unknown recipient")); |
271 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP21, |
248 __KTRACE_OPT(KPANIC, Kern::Printf(" -> DUsbClientController::ProcessEp0SetupReceived: " |
272 " Error: GET STATUS - Other or Unknown recipient" ); |
249 "Stalling Ep0")); |
273 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP22, |
|
274 " -> DUsbClientController::ProcessEp0SetupReceived: Stalling Ep0" ); |
250 StallEndpoint(KEp0_In); |
275 StallEndpoint(KEp0_In); |
251 break; |
276 break; |
252 } |
277 } |
253 break; |
278 break; |
254 case KUsbRequest_ClearFeature: |
279 case KUsbRequest_ClearFeature: |
255 case KUsbRequest_SetFeature: |
280 case KUsbRequest_SetFeature: |
256 switch (packet.iRequestType & KUsbRequestType_DestMask) |
281 switch (packet.iRequestType & KUsbRequestType_DestMask) |
257 { // Recipient |
282 { // Recipient |
258 case KUsbRequestType_DestDevice: |
283 case KUsbRequestType_DestDevice: |
259 USB_PROCESS_REQUEST(SetClearDevFeature); |
284 if (ProcessSetClearDevFeature(packet) != KErrNone) |
|
285 { |
|
286 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP23, |
|
287 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
288 StallEndpoint(KEp0_In); |
|
289 } |
260 break; |
290 break; |
261 case KUsbRequestType_DestIfc: |
291 case KUsbRequestType_DestIfc: |
262 USB_PROCESS_REQUEST(SetClearIfcFeature); |
292 if (ProcessSetClearIfcFeature(packet) != KErrNone) |
|
293 { |
|
294 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP24, |
|
295 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
296 StallEndpoint(KEp0_In); |
|
297 } |
263 break; |
298 break; |
264 case KUsbRequestType_DestEp: |
299 case KUsbRequestType_DestEp: |
265 USB_PROCESS_REQUEST(SetClearEpFeature); |
300 if (ProcessSetClearEpFeature(packet) != KErrNone) |
|
301 { |
|
302 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP25, |
|
303 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
304 StallEndpoint(KEp0_In); |
|
305 } |
266 break; |
306 break; |
267 default: |
307 default: |
268 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: SET/CLEAR FEATURE - " |
308 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP26, |
269 "Other or Unknown recipient")); |
309 " Error: SET/CLEAR FEATURE - Other or Unknown recipient" ); |
270 __KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0")); |
310 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP27, |
|
311 " -> Stalling Ep0" ); |
271 StallEndpoint(KEp0_In); |
312 StallEndpoint(KEp0_In); |
272 break; |
313 break; |
273 } |
314 } |
274 break; |
315 break; |
275 case KUsbRequest_SetAddress: |
316 case KUsbRequest_SetAddress: |
276 USB_PROCESS_REQUEST(SetAddress); |
317 if (ProcessSetAddress(packet) != KErrNone) |
|
318 { |
|
319 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP28, |
|
320 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
321 StallEndpoint(KEp0_In); |
|
322 } |
277 break; |
323 break; |
278 case KUsbRequest_GetDescriptor: |
324 case KUsbRequest_GetDescriptor: |
279 USB_PROCESS_REQUEST(GetDescriptor); |
325 if (ProcessGetDescriptor(packet) != KErrNone) |
|
326 { |
|
327 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP29, |
|
328 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
329 StallEndpoint(KEp0_In); |
|
330 } |
280 break; |
331 break; |
281 case KUsbRequest_SetDescriptor: |
332 case KUsbRequest_SetDescriptor: |
282 USB_PROCESS_REQUEST(SetDescriptor); |
333 if (ProcessSetDescriptor(packet) != KErrNone) |
|
334 { |
|
335 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP30, |
|
336 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
337 StallEndpoint(KEp0_In); |
|
338 } |
283 break; |
339 break; |
284 case KUsbRequest_GetConfig: |
340 case KUsbRequest_GetConfig: |
285 USB_PROCESS_REQUEST(GetConfiguration); |
341 if (ProcessGetConfiguration(packet) != KErrNone) |
|
342 { |
|
343 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP31, |
|
344 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
345 StallEndpoint(KEp0_In); |
|
346 } |
286 break; |
347 break; |
287 case KUsbRequest_SetConfig: |
348 case KUsbRequest_SetConfig: |
288 USB_PROCESS_REQUEST(SetConfiguration); |
349 if (ProcessSetConfiguration(packet) != KErrNone) |
|
350 { |
|
351 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP32, |
|
352 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
353 StallEndpoint(KEp0_In); |
|
354 } |
289 break; |
355 break; |
290 case KUsbRequest_GetInterface: |
356 case KUsbRequest_GetInterface: |
291 USB_PROCESS_REQUEST(GetInterface); |
357 if (ProcessGetInterface(packet) != KErrNone) |
|
358 { |
|
359 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP33, |
|
360 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
361 StallEndpoint(KEp0_In); |
|
362 } |
292 break; |
363 break; |
293 case KUsbRequest_SetInterface: |
364 case KUsbRequest_SetInterface: |
294 USB_PROCESS_REQUEST(SetInterface); |
365 if (ProcessSetInterface(packet) != KErrNone) |
|
366 { |
|
367 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP34, |
|
368 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
369 StallEndpoint(KEp0_In); |
|
370 } |
295 break; |
371 break; |
296 case KUsbRequest_SynchFrame: |
372 case KUsbRequest_SynchFrame: |
297 USB_PROCESS_REQUEST(SynchFrame); |
373 if (ProcessSynchFrame(packet) != KErrNone) |
|
374 { |
|
375 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP35, |
|
376 "ProcessEp0SetupReceived: Stalling Ep0" ); |
|
377 StallEndpoint(KEp0_In); |
|
378 } |
298 break; |
379 break; |
299 default: |
380 default: |
300 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown/unsupported Std Setup Request")); |
381 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP36, |
301 __KTRACE_OPT(KPANIC, Kern::Printf(" -> Stalling Ep0")); |
382 " Error: Unknown/unsupported Std Setup Request" ); |
|
383 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSEP0SETUPRECEIVED_DUP37, |
|
384 " -> Stalling Ep0" ); |
302 StallEndpoint(KEp0_In); |
385 StallEndpoint(KEp0_In); |
303 break; |
386 break; |
304 } |
387 } |
305 } |
388 } |
306 else |
389 else |
601 switch (aPacket.iValue) |
707 switch (aPacket.iValue) |
602 { |
708 { |
603 case KUsbFeature_RemoteWakeup: |
709 case KUsbFeature_RemoteWakeup: |
604 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
710 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
605 { |
711 { |
606 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
712 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP2, |
|
713 " Error: Invalid device state" ); |
607 return KErrGeneral; |
714 return KErrGeneral; |
608 } |
715 } |
609 iRmWakeupStatus_Enabled = ETrue; |
716 iRmWakeupStatus_Enabled = ETrue; |
610 break; |
717 break; |
611 case KUsbFeature_TestMode: |
718 case KUsbFeature_TestMode: |
612 if (!iHighSpeed) |
719 if (!iHighSpeed) |
613 { |
720 { |
614 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported in High-Speed mode")); |
721 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP3, |
|
722 " Error: Request only supported in High-Speed mode" ); |
615 return KErrGeneral; |
723 return KErrGeneral; |
616 } |
724 } |
617 if (LowByte(aPacket.iIndex) != 0) |
725 if (LowByte(aPacket.iIndex) != 0) |
618 { |
726 { |
619 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Lower byte of wIndex must be zero")); |
727 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP4, |
|
728 " Error: Lower byte of wIndex must be zero" ); |
620 return KErrGeneral; |
729 return KErrGeneral; |
621 } |
730 } |
622 test_sel = HighByte(aPacket.iIndex); |
731 test_sel = HighByte(aPacket.iIndex); |
623 if ((test_sel < KUsbTestSelector_Test_J) || (test_sel > KUsbTestSelector_Test_Force_Enable)) |
732 if ((test_sel < KUsbTestSelector_Test_J) || (test_sel > KUsbTestSelector_Test_Force_Enable)) |
624 { |
733 { |
625 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid test selector: %d", test_sel)); |
734 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP5, |
|
735 " Error: Invalid test selector: %d", test_sel ); |
626 return KErrGeneral; |
736 return KErrGeneral; |
627 } |
737 } |
628 break; |
738 break; |
629 case KUsbFeature_B_HnpEnable: |
739 case KUsbFeature_B_HnpEnable: |
630 if (!iOtgSupport) |
740 if (!iOtgSupport) |
631 { |
741 { |
632 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
742 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP6, |
|
743 " Error: Request only supported on a OTG device" ); |
633 return KErrGeneral; |
744 return KErrGeneral; |
634 } |
745 } |
635 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
746 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
636 { |
747 { |
637 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
748 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP7, |
|
749 " Error: Request only valid if OTG device supports HNP" ); |
638 return KErrGeneral; |
750 return KErrGeneral; |
639 } |
751 } |
640 iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable; |
752 iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable; |
641 OtgFeaturesNotify(); |
753 OtgFeaturesNotify(); |
642 break; |
754 break; |
643 case KUsbFeature_A_HnpSupport: |
755 case KUsbFeature_A_HnpSupport: |
644 if (!iOtgSupport) |
756 if (!iOtgSupport) |
645 { |
757 { |
646 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
758 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP8, |
|
759 " Error: Request only supported on a OTG device" ); |
647 return KErrGeneral; |
760 return KErrGeneral; |
648 } |
761 } |
649 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
762 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
650 { |
763 { |
651 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
764 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP9, |
|
765 " Error: Request only valid if OTG device supports HNP" ); |
652 return KErrGeneral; |
766 return KErrGeneral; |
653 } |
767 } |
654 iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport; |
768 iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport; |
655 OtgFeaturesNotify(); |
769 OtgFeaturesNotify(); |
656 break; |
770 break; |
657 case KUsbFeature_A_AltHnpSupport: |
771 case KUsbFeature_A_AltHnpSupport: |
658 if (!iOtgSupport) |
772 if (!iOtgSupport) |
659 { |
773 { |
660 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only supported on a OTG device")); |
774 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP10, |
|
775 " Error: Request only supported on a OTG device" ); |
661 return KErrGeneral; |
776 return KErrGeneral; |
662 } |
777 } |
663 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
778 if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
664 { |
779 { |
665 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Request only valid if OTG device supports HNP")); |
780 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP11, |
|
781 " Error: Request only valid if OTG device supports HNP" ); |
666 return KErrGeneral; |
782 return KErrGeneral; |
667 } |
783 } |
668 iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport; |
784 iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport; |
669 OtgFeaturesNotify(); |
785 OtgFeaturesNotify(); |
670 break; |
786 break; |
671 default: |
787 default: |
672 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
788 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP12, |
|
789 " Error: Unknown feature requested" ); |
673 return KErrGeneral; |
790 return KErrGeneral; |
674 } |
791 } |
675 } |
792 } |
676 else // KUsbRequest_ClearFeature |
793 else // KUsbRequest_ClearFeature |
677 { |
794 { |
678 switch (aPacket.iValue) |
795 switch (aPacket.iValue) |
679 { |
796 { |
680 case KUsbFeature_RemoteWakeup: |
797 case KUsbFeature_RemoteWakeup: |
681 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
798 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
682 { |
799 { |
683 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
800 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP13, |
|
801 " Error: Invalid device state" ); |
684 return KErrGeneral; |
802 return KErrGeneral; |
685 } |
803 } |
686 iRmWakeupStatus_Enabled = EFalse; |
804 iRmWakeupStatus_Enabled = EFalse; |
687 break; |
805 break; |
688 default: |
806 default: |
689 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
807 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP14, |
|
808 " Error: Unknown feature requested" ); |
690 return KErrGeneral; |
809 return KErrGeneral; |
691 } |
810 } |
692 } |
811 } |
693 |
812 |
694 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
813 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
695 |
814 |
696 // 9.4.9: "The transition to test mode of an upstream facing port must not happen until |
815 // 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." |
816 // after the status stage of the request." |
698 if (test_sel) |
817 if (test_sel) |
699 { |
818 { |
700 __KTRACE_OPT(KPANIC, Kern::Printf(" Entering HS Test Mode %d", test_sel)); |
819 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARDEVFEATURE_DUP15, |
|
820 " Entering HS Test Mode %d", test_sel ); |
701 EnterTestMode(test_sel); |
821 EnterTestMode(test_sel); |
702 } |
822 } |
703 |
823 |
704 return KErrNone; |
824 return KErrNone; |
705 } |
825 } |
706 |
826 |
707 |
827 |
708 TInt DUsbClientController::ProcessSetClearIfcFeature(const TUsbcSetup& aPacket) |
828 TInt DUsbClientController::ProcessSetClearIfcFeature(const TUsbcSetup& aPacket) |
709 { |
829 { |
710 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearIfcFeature()")); |
830 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSETCLEARIFCFEATURE, |
|
831 "DUsbClientController::ProcessSetClearIfcFeature()" ); |
711 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
832 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
712 { |
833 { |
713 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
834 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEARIFCFEATURE_DUP1, |
|
835 " Error: Invalid device state" ); |
714 return KErrGeneral; |
836 return KErrGeneral; |
715 } |
837 } |
716 // No interface features defined in USB spec, thus |
838 // No interface features defined in USB spec, thus |
717 return KErrGeneral; |
839 return KErrGeneral; |
718 } |
840 } |
719 |
841 |
720 |
842 |
721 TInt DUsbClientController::ProcessSetClearEpFeature(const TUsbcSetup& aPacket) |
843 TInt DUsbClientController::ProcessSetClearEpFeature(const TUsbcSetup& aPacket) |
722 { |
844 { |
723 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearEpFeature()")); |
845 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSETCLEAREPFEATURE, |
|
846 "DUsbClientController::ProcessSetClearEpFeature()" ); |
724 if (iTrackDeviceState && |
847 if (iTrackDeviceState && |
725 ((iDeviceState < EUsbcDeviceStateAddress) || |
848 ((iDeviceState < EUsbcDeviceStateAddress) || |
726 (iDeviceState == EUsbcDeviceStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0))) |
849 (iDeviceState == EUsbcDeviceStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0))) |
727 { |
850 { |
728 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
851 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEAREPFEATURE_DUP1, |
|
852 " Error: Invalid device state" ); |
729 return KErrGeneral; |
853 return KErrGeneral; |
730 } |
854 } |
731 if (aPacket.iValue != KUsbFeature_EndpointHalt) |
855 if (aPacket.iValue != KUsbFeature_EndpointHalt) |
732 { |
856 { |
733 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown feature requested")); |
857 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEAREPFEATURE_DUP2, |
|
858 " Error: Unknown feature requested" ); |
734 return KErrGeneral; |
859 return KErrGeneral; |
735 } |
860 } |
736 if (EndpointExists(aPacket.iIndex) == EFalse) |
861 if (EndpointExists(aPacket.iIndex) == EFalse) |
737 { |
862 { |
738 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint does not exist")); |
863 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEAREPFEATURE_DUP3, |
|
864 " Error: Endpoint does not exist" ); |
739 return KErrGeneral; |
865 return KErrGeneral; |
740 } |
866 } |
741 const TInt ep = EpAddr2Idx(aPacket.iIndex); |
867 const TInt ep = EpAddr2Idx(aPacket.iIndex); |
742 if (iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeControl || |
868 if (iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeControl || |
743 iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeIsochronous) |
869 iRealEndpoints[ep].iLEndpoint->iInfo.iType == KUsbEpTypeIsochronous) |
744 { |
870 { |
745 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint is Control or Isochronous")); |
871 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCLEAREPFEATURE_DUP4, |
|
872 " Error: Endpoint is Control or Isochronous" ); |
746 return KErrGeneral; |
873 return KErrGeneral; |
747 } |
874 } |
748 SetClearHaltFeature(ep, aPacket.iRequest); |
875 SetClearHaltFeature(ep, aPacket.iRequest); |
749 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
876 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
750 return KErrNone; |
877 return KErrNone; |
751 } |
878 } |
752 |
879 |
753 |
880 |
754 TInt DUsbClientController::ProcessSetAddress(const TUsbcSetup& aPacket) |
881 TInt DUsbClientController::ProcessSetAddress(const TUsbcSetup& aPacket) |
755 { |
882 { |
756 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetAddress()")); |
883 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSETADDRESS, |
|
884 "DUsbClientController::ProcessSetAddress()" ); |
757 if (iTrackDeviceState && iDeviceState > EUsbcDeviceStateAddress) |
885 if (iTrackDeviceState && iDeviceState > EUsbcDeviceStateAddress) |
758 { |
886 { |
759 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
887 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETADDRESS_DUP1, |
|
888 " Error: Invalid device state" ); |
760 return KErrGeneral; |
889 return KErrGeneral; |
761 } |
890 } |
762 const TUint16 addr = aPacket.iValue; |
891 const TUint16 addr = aPacket.iValue; |
763 if (addr > 127) |
892 if (addr > 127) |
764 { |
893 { |
765 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad address value: %d (>127)", addr)); |
894 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETADDRESS_DUP2, |
|
895 " Error: Bad address value: %d (>127)", addr ); |
766 return KErrGeneral; |
896 return KErrGeneral; |
767 } |
897 } |
768 if (addr == 0) |
898 if (addr == 0) |
769 { |
899 { |
770 // Enter Default state (from Default or Address) |
900 // Enter Default state (from Default or Address) |
771 NextDeviceState(EUsbcDeviceStateDefault); |
901 NextDeviceState(EUsbcDeviceStateDefault); |
772 } |
902 } |
773 __KTRACE_OPT(KUSB, Kern::Printf(" USB address: %d", addr)); |
903 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSETADDRESS_DUP3, |
|
904 " USB address: %d", addr ); |
774 // The spec says, under section 9.4.6: |
905 // 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 |
906 // "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 |
907 // 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 |
908 // 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." |
909 // requests, the operation indicated must be completed before the Status stage." |
802 size); |
935 size); |
803 |
936 |
804 if ((result != KErrNone) || (size == 0)) |
937 if ((result != KErrNone) || (size == 0)) |
805 { |
938 { |
806 // This doesn't have to be an error - protocol-wise it's OK. |
939 // This doesn't have to be an error - protocol-wise it's OK. |
807 __KTRACE_OPT(KUSB, Kern::Printf(" Couldn't retrieve descriptor")); |
940 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETDESCRIPTOR_DUP2, |
808 return KErrGeneral; |
941 " Couldn't retrieve descriptor" ); |
809 } |
942 return KErrGeneral; |
810 |
943 } |
811 __KTRACE_OPT(KUSB, Kern::Printf(" Descriptor found, size: %d (requested: %d)", |
944 |
812 size, aPacket.iLength)); |
945 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETDESCRIPTOR_DUP3, |
|
946 " Descriptor found, size: %d (requested: %d)", size, aPacket.iLength ); |
813 if (size > KUsbcBufSz_Ep0Tx) |
947 if (size > KUsbcBufSz_Ep0Tx) |
814 { |
948 { |
815 // This should actually not be possible (i.e. we should never get here). |
949 // This should actually not be possible (i.e. we should never get here). |
816 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ep0_Tx buffer too small")); |
950 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETDESCRIPTOR_DUP4, |
|
951 " Error: Ep0_Tx buffer too small" ); |
817 } |
952 } |
818 if (size > aPacket.iLength) |
953 if (size > aPacket.iLength) |
819 { |
954 { |
820 // Send only as much data as requested by the host |
955 // Send only as much data as requested by the host |
821 size = aPacket.iLength; |
956 size = aPacket.iLength; |
822 } |
957 } |
823 |
958 |
824 #ifdef ENABLE_EXCESSIVE_DEBUG_OUTPUT |
959 #ifdef ENABLE_EXCESSIVE_DEBUG_OUTPUT |
825 __KTRACE_OPT(KUSB, |
960 OstTraceDefExt1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETDESCRIPTOR_DUP5, |
826 Kern::Printf(" Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x ...", |
961 " Data: %{uint8[]}", TOstArray<TUint8>(iEp0_TxBuf, 8) ); |
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])); |
|
829 #endif |
962 #endif |
830 // If we're about to send less bytes than expected by the host AND our number is a |
963 // 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, |
964 // 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): |
965 // we must finally send a zero length data packet (ZLP): |
833 const TBool zlp = ((size < aPacket.iLength) && (size % iEp0MaxPacketSize == 0)); |
966 const TBool zlp = ((size < aPacket.iLength) && (size % iEp0MaxPacketSize == 0)); |
864 } |
999 } |
865 |
1000 |
866 |
1001 |
867 TInt DUsbClientController::ProcessGetConfiguration(const TUsbcSetup& aPacket) |
1002 TInt DUsbClientController::ProcessGetConfiguration(const TUsbcSetup& aPacket) |
868 { |
1003 { |
869 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetConfiguration()")); |
1004 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION, |
|
1005 "DUsbClientController::ProcessGetConfiguration()" ); |
870 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
1006 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
871 { |
1007 { |
872 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
1008 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION_DUP1, |
|
1009 " Error: Invalid device state" ); |
873 return KErrGeneral; |
1010 return KErrGeneral; |
874 } |
1011 } |
875 if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateAddress && iCurrentConfig != 0) |
1012 if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateAddress && iCurrentConfig != 0) |
876 { |
1013 { |
877 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Address && Config != 0")); |
1014 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION_DUP2, |
|
1015 " Error: DeviceState Address && Config != 0" ); |
878 return KErrGeneral; |
1016 return KErrGeneral; |
879 } |
1017 } |
880 if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateConfigured && iCurrentConfig == 0) |
1018 if (iTrackDeviceState && iDeviceState == EUsbcDeviceStateConfigured && iCurrentConfig == 0) |
881 { |
1019 { |
882 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: DeviceState Configured && Config == 0")); |
1020 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION_DUP3, |
|
1021 " Error: DeviceState Configured && Config == 0" ); |
883 return KErrGeneral; |
1022 return KErrGeneral; |
884 } |
1023 } |
885 if (aPacket.iLength != 1) // "unspecified behavior" |
1024 if (aPacket.iLength != 1) // "unspecified behavior" |
886 { |
1025 { |
887 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: wLength != 1 (= %d)", aPacket.iLength)); |
1026 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION_DUP4, |
888 } |
1027 " Warning: wLength != 1 (= %d)", aPacket.iLength ); |
889 __KTRACE_OPT(KUSB, Kern::Printf(" Reporting configuration value %d", iCurrentConfig)); |
1028 } |
|
1029 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETCONFIGURATION_DUP5, |
|
1030 " Reporting configuration value %d", iCurrentConfig ); |
890 if (SetupEndpointZeroWrite(&iCurrentConfig, sizeof(iCurrentConfig)) == KErrNone) |
1031 if (SetupEndpointZeroWrite(&iCurrentConfig, sizeof(iCurrentConfig)) == KErrNone) |
891 { |
1032 { |
892 iEp0WritePending = ETrue; |
1033 iEp0WritePending = ETrue; |
893 } |
1034 } |
894 return KErrNone; |
1035 return KErrNone; |
904 |
1045 |
905 @publishedPartner @released |
1046 @publishedPartner @released |
906 */ |
1047 */ |
907 TInt DUsbClientController::ProcessSetConfiguration(const TUsbcSetup& aPacket) |
1048 TInt DUsbClientController::ProcessSetConfiguration(const TUsbcSetup& aPacket) |
908 { |
1049 { |
909 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetConfiguration()")); |
1050 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSETCONFIGURATION, |
910 |
1051 "DUsbClientController::ProcessSetConfiguration()" ); |
911 // This function may be called by the PSL from within an ISR -- so we have |
1052 // 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 |
1053 // to take care what we do here (and also in all functions that get called |
913 // from here). |
1054 // from here). |
914 |
1055 |
915 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
1056 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateAddress) |
916 { |
1057 { |
917 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
1058 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCONFIGURATION_DUP1, |
|
1059 " Error: Invalid device state" ); |
918 return KErrGeneral; |
1060 return KErrGeneral; |
919 } |
1061 } |
920 const TUint16 value = aPacket.iValue; |
1062 const TUint16 value = aPacket.iValue; |
921 if (value > 1) // we support only one configuration |
1063 if (value > 1) // we support only one configuration |
922 { |
1064 { |
923 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Configuration value too large: %d", value)); |
1065 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETCONFIGURATION_DUP2, |
924 return KErrGeneral; |
1066 " Error: Configuration value too large: %d", value ); |
925 } |
1067 return KErrGeneral; |
926 |
1068 } |
927 __KTRACE_OPT(KUSB, Kern::Printf(" Configuration value: %d", value)); |
1069 |
|
1070 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSETCONFIGURATION_DUP3, |
|
1071 " Configuration value: %d", value ); |
928 ChangeConfiguration(value); |
1072 ChangeConfiguration(value); |
929 |
1073 |
930 // In 9.4.5 under GET_STATUS we read, that after SET_CONFIGURATION the HALT feature |
1074 // In 9.4.5 under GET_STATUS we read, that after SET_CONFIGURATION the HALT feature |
931 // for all endpoints is reset to zero. |
1075 // for all endpoints is reset to zero. |
932 TInt num = 0; |
1076 TInt num = 0; |
933 (TAny) DoForEveryEndpointInUse(&DUsbClientController::ClearHaltFeature, num); |
1077 (TAny) DoForEveryEndpointInUse(&DUsbClientController::ClearHaltFeature, num); |
934 __KTRACE_OPT(KUSB, Kern::Printf(" Called ClearHaltFeature() for %d endpoints", num)); |
1078 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSETCONFIGURATION_DUP4, |
|
1079 " Called ClearHaltFeature() for %d endpoints", num ); |
935 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
1080 SendEp0ZeroByteStatusPacket(); // success: zero bytes data during status stage |
936 return KErrNone; |
1081 return KErrNone; |
937 } |
1082 } |
938 |
1083 |
939 |
1084 |
940 TInt DUsbClientController::ProcessGetInterface(const TUsbcSetup& aPacket) |
1085 TInt DUsbClientController::ProcessGetInterface(const TUsbcSetup& aPacket) |
941 { |
1086 { |
942 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterface()")); |
1087 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSGETINTERFACE, |
|
1088 "DUsbClientController::ProcessGetInterface()" ); |
943 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
1089 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
944 { |
1090 { |
945 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
1091 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETINTERFACE_DUP1, |
|
1092 " Error: Invalid device state" ); |
946 return KErrGeneral; |
1093 return KErrGeneral; |
947 } |
1094 } |
948 if (iCurrentConfig == 0) |
1095 if (iCurrentConfig == 0) |
949 { |
1096 { |
950 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured")); |
1097 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETINTERFACE_DUP2, |
|
1098 " Error: Device not configured" ); |
951 return KErrGeneral; |
1099 return KErrGeneral; |
952 } |
1100 } |
953 const TInt number = aPacket.iIndex; |
1101 const TInt number = aPacket.iIndex; |
954 if (!InterfaceExists(number)) |
1102 if (!InterfaceExists(number)) |
955 { |
1103 { |
956 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number)); |
1104 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSGETINTERFACE_DUP3, |
|
1105 " Error: Bad interface index: %d", number ); |
957 return KErrGeneral; |
1106 return KErrGeneral; |
958 } |
1107 } |
959 // Send alternate setting code of iCurrentInterface of Interface(set) <number> of the current |
1108 // Send alternate setting code of iCurrentInterface of Interface(set) <number> of the current |
960 // config (iCurrentConfig). |
1109 // config (iCurrentConfig). |
961 const TUint8 setting = InterfaceNumber2InterfacePointer(number)->iCurrentInterface; |
1110 const TUint8 setting = InterfaceNumber2InterfacePointer(number)->iCurrentInterface; |
962 __KTRACE_OPT(KUSB, Kern::Printf(" Reporting interface setting %d", setting)); |
1111 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSGETINTERFACE_DUP4, |
|
1112 " Reporting interface setting %d", setting ); |
963 if (SetupEndpointZeroWrite(&setting, 1) == KErrNone) |
1113 if (SetupEndpointZeroWrite(&setting, 1) == KErrNone) |
964 { |
1114 { |
965 iEp0WritePending = ETrue; |
1115 iEp0WritePending = ETrue; |
966 } |
1116 } |
967 return KErrNone; |
1117 return KErrNone; |
968 } |
1118 } |
969 |
1119 |
970 |
1120 |
971 TInt DUsbClientController::ProcessSetInterface(const TUsbcSetup& aPacket) |
1121 TInt DUsbClientController::ProcessSetInterface(const TUsbcSetup& aPacket) |
972 { |
1122 { |
973 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetInterface()")); |
1123 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE, |
|
1124 "DUsbClientController::ProcessSetInterface()" ); |
974 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
1125 if (iTrackDeviceState && iDeviceState < EUsbcDeviceStateConfigured) |
975 { |
1126 { |
976 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid device state")); |
1127 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE_DUP1, |
|
1128 " Error: Invalid device state" ); |
977 return KErrGeneral; |
1129 return KErrGeneral; |
978 } |
1130 } |
979 if (iCurrentConfig == 0) |
1131 if (iCurrentConfig == 0) |
980 { |
1132 { |
981 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Device not configured")); |
1133 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE_DUP2, |
|
1134 " Error: Device not configured" ); |
982 return KErrGeneral; |
1135 return KErrGeneral; |
983 } |
1136 } |
984 const TInt number = aPacket.iIndex; |
1137 const TInt number = aPacket.iIndex; |
985 if (!InterfaceExists(number)) |
1138 if (!InterfaceExists(number)) |
986 { |
1139 { |
987 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Bad interface index: %d", number)); |
1140 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE_DUP3, |
|
1141 " Error: Bad interface index: %d", number ); |
988 return KErrGeneral; |
1142 return KErrGeneral; |
989 } |
1143 } |
990 const TInt setting = aPacket.iValue; |
1144 const TInt setting = aPacket.iValue; |
991 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(number); |
1145 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(number); |
992 RPointerArray<TUsbcInterface>& ifcs = ifcset_ptr->iInterfaces; |
1146 RPointerArray<TUsbcInterface>& ifcs = ifcset_ptr->iInterfaces; |
993 if (setting >= ifcs.Count()) |
1147 if (setting >= ifcs.Count()) |
994 { |
1148 { |
995 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Alt Setting >= bNumAltSettings: %d", setting)); |
1149 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE_DUP4, |
996 return KErrGeneral; |
1150 " Error: Alt Setting >= bNumAltSettings: %d", setting ); |
997 } |
1151 return KErrGeneral; |
998 __KTRACE_OPT(KUSB, Kern::Printf(" Interface setting:: %d", setting)); |
1152 } |
|
1153 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSETINTERFACE_DUP5, |
|
1154 " Interface setting:: %d", setting ); |
999 // Set iCurrentInterface of Interface(set) <number> of the current config |
1155 // Set iCurrentInterface of Interface(set) <number> of the current config |
1000 // (iCurrentConfig) to alternate setting <setting>. |
1156 // (iCurrentConfig) to alternate setting <setting>. |
1001 ChangeInterface(ifcs[setting]); |
1157 ChangeInterface(ifcs[setting]); |
1002 // In 9.4.5 under GET_STATUS we read, that after SET_INTERFACE the HALT feature |
1158 // 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. |
1159 // for all endpoints (of the now current interface setting) is reset to zero. |
1076 |
1237 |
1077 // --- Secondary (Helper) Functions |
1238 // --- Secondary (Helper) Functions |
1078 |
1239 |
1079 void DUsbClientController::SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest) |
1240 void DUsbClientController::SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest) |
1080 { |
1241 { |
1081 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetClearHaltFeature()")); |
1242 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETCLEARHALTFEATURE, |
|
1243 "DUsbClientController::SetClearHaltFeature()" ); |
1082 if (aRequest == KUsbRequest_SetFeature) |
1244 if (aRequest == KUsbRequest_SetFeature) |
1083 { |
1245 { |
1084 if (iRealEndpoints[aRealEndpoint].iHalt) |
1246 if (iRealEndpoints[aRealEndpoint].iHalt) |
1085 { |
1247 { |
1086 // (This condition is not really an error) |
1248 // (This condition is not really an error) |
1087 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already set")); |
1249 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCLEARHALTFEATURE_DUP1, |
|
1250 " Warning: HALT feature already set" ); |
1088 return; |
1251 return; |
1089 } |
1252 } |
1090 __KTRACE_OPT(KUSB, Kern::Printf(" setting HALT feature for real endpoint %d", |
1253 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCLEARHALTFEATURE_DUP2, |
1091 aRealEndpoint)); |
1254 " setting HALT feature for real endpoint %d", aRealEndpoint ); |
1092 StallEndpoint(aRealEndpoint); |
1255 StallEndpoint(aRealEndpoint); |
1093 iRealEndpoints[aRealEndpoint].iHalt = ETrue; |
1256 iRealEndpoints[aRealEndpoint].iHalt = ETrue; |
1094 } |
1257 } |
1095 else // KUsbRequest_ClearFeature |
1258 else // KUsbRequest_ClearFeature |
1096 { |
1259 { |
1097 if (iRealEndpoints[aRealEndpoint].iHalt == EFalse) |
1260 if (iRealEndpoints[aRealEndpoint].iHalt == EFalse) |
1098 { |
1261 { |
1099 // In this case, before we return, the data toggles are reset to DATA0. |
1262 // In this case, before we return, the data toggles are reset to DATA0. |
1100 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: HALT feature already cleared")); |
1263 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCLEARHALTFEATURE_DUP3, |
|
1264 " Warning: HALT feature already cleared" ); |
1101 ResetDataToggle(aRealEndpoint); |
1265 ResetDataToggle(aRealEndpoint); |
1102 return; |
1266 return; |
1103 } |
1267 } |
1104 __KTRACE_OPT(KUSB, Kern::Printf(" clearing HALT feature for real endpoint %d", |
1268 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCLEARHALTFEATURE_DUP4, |
1105 aRealEndpoint)); |
1269 " clearing HALT feature for real endpoint %d", aRealEndpoint ); |
1106 ResetDataToggle(aRealEndpoint); |
1270 ResetDataToggle(aRealEndpoint); |
1107 ClearStallEndpoint(aRealEndpoint); |
1271 ClearStallEndpoint(aRealEndpoint); |
1108 iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
1272 iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
1109 } |
1273 } |
1110 EpStatusNotify(aRealEndpoint); // only called if actually something changed |
1274 EpStatusNotify(aRealEndpoint); // only called if actually something changed |
1111 } |
1275 } |
1112 |
1276 |
1113 |
1277 |
1114 TInt DUsbClientController::ClearHaltFeature(TInt aRealEndpoint) |
1278 TInt DUsbClientController::ClearHaltFeature(TInt aRealEndpoint) |
1115 { |
1279 { |
1116 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ClearHaltFeature()")); |
1280 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CLEARHALTFEATURE, |
|
1281 "DUsbClientController::ClearHaltFeature()" ); |
1117 if (iRealEndpoints[aRealEndpoint].iHalt != EFalse) |
1282 if (iRealEndpoints[aRealEndpoint].iHalt != EFalse) |
1118 { |
1283 { |
1119 ClearStallEndpoint(aRealEndpoint); |
1284 ClearStallEndpoint(aRealEndpoint); |
1120 iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
1285 iRealEndpoints[aRealEndpoint].iHalt = EFalse; |
1121 } |
1286 } |
1123 } |
1288 } |
1124 |
1289 |
1125 |
1290 |
1126 void DUsbClientController::ChangeConfiguration(TUint16 aValue) |
1291 void DUsbClientController::ChangeConfiguration(TUint16 aValue) |
1127 { |
1292 { |
1128 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeConfiguration()")); |
1293 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION, |
|
1294 "DUsbClientController::ChangeConfiguration()" ); |
1129 // New configuration is the same as the old one: 0 |
1295 // New configuration is the same as the old one: 0 |
1130 if (iCurrentConfig == 0 && aValue == 0) |
1296 if (iCurrentConfig == 0 && aValue == 0) |
1131 { |
1297 { |
1132 // no-op |
1298 // no-op |
1133 __KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == 0 --> exiting")); |
1299 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP1, |
|
1300 " Configuration: New == Old == 0 --> exiting" ); |
1134 return; |
1301 return; |
1135 } |
1302 } |
1136 // New configuration is the same as the old one (but not 0) |
1303 // New configuration is the same as the old one (but not 0) |
1137 if (iCurrentConfig == aValue) |
1304 if (iCurrentConfig == aValue) |
1138 { |
1305 { |
1139 __KTRACE_OPT(KUSB, Kern::Printf(" Configuration: New == Old == %d --> exiting", aValue)); |
1306 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP2, |
1140 |
1307 " Configuration: New == Old == %d --> exiting", aValue ); |
1141 // From the spec 9.1.1.5, Data toggle is reset to zero here when |
1308 // From the spec 9.1.1.5, Data toggle is reset to zero here when |
1142 // setconfiguration(x->x)(x!=0) received, although we only support |
1309 // setconfiguration(x->x)(x!=0) received, although we only support |
1143 // single configuration currently. |
1310 // single configuration currently. |
1144 TInt num = 0; |
1311 TInt num = 0; |
1145 TInt ret = DoForEveryEndpointInUse(&DUsbClientController::ResetDataToggle, num); |
1312 TInt ret = DoForEveryEndpointInUse(&DUsbClientController::ResetDataToggle, num); |
1146 if(ret != KErrNone) |
1313 if(ret != KErrNone) |
1147 { |
1314 { |
1148 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint data toggle reset failed")); |
1315 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP3, |
1149 } |
1316 " Error: Endpoint data toggle reset failed" ); |
1150 __KTRACE_OPT(KUSB, Kern::Printf(" Called ResetDataToggle()for %d endpoints", num)); |
1317 } |
1151 |
1318 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP4, |
|
1319 " Called ResetDataToggle()for %d endpoints", num ); |
1152 return; |
1320 return; |
1153 } |
1321 } |
1154 // Device is already configured |
1322 // Device is already configured |
1155 if (iCurrentConfig != 0) |
1323 if (iCurrentConfig != 0) |
1156 { |
1324 { |
1157 __KTRACE_OPT(KUSB, Kern::Printf(" Device was configured: %d", iCurrentConfig)); |
1325 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP5, |
|
1326 " Device was configured: %d", iCurrentConfig ); |
1158 // Tear down all interface(set)s of the old configuration |
1327 // Tear down all interface(set)s of the old configuration |
1159 RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
1328 RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
1160 for (TInt i = 0; i < ifcsets.Count(); ++i) |
1329 for (TInt i = 0; i < ifcsets.Count(); ++i) |
1161 { |
1330 { |
1162 __KTRACE_OPT(KUSB, Kern::Printf(" Tearing down InterfaceSet %d", i)); |
1331 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP6, |
|
1332 " Tearing down InterfaceSet %d", i ); |
1163 InterfaceSetTeardown(ifcsets[i]); |
1333 InterfaceSetTeardown(ifcsets[i]); |
1164 } |
1334 } |
1165 iCurrentConfig = 0; |
1335 iCurrentConfig = 0; |
1166 // Enter Address state (from Configured) |
1336 // Enter Address state (from Configured) |
1167 if (iDeviceState == EUsbcDeviceStateConfigured) |
1337 if (iDeviceState == EUsbcDeviceStateConfigured) |
1168 NextDeviceState(EUsbcDeviceStateAddress); |
1338 NextDeviceState(EUsbcDeviceStateAddress); |
1169 } |
1339 } |
1170 // Device gets a new configuration |
1340 // Device gets a new configuration |
1171 if (aValue != 0) |
1341 if (aValue != 0) |
1172 { |
1342 { |
1173 __KTRACE_OPT(KUSB, Kern::Printf(" Device gets new configuration...")); |
1343 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP7, |
|
1344 " Device gets new configuration..." ); |
1174 // Setup all alternate settings 0 of all interfaces |
1345 // Setup all alternate settings 0 of all interfaces |
1175 // (Don't separate the next two lines of code.) |
1346 // (Don't separate the next two lines of code.) |
1176 iCurrentConfig = aValue; |
1347 iCurrentConfig = aValue; |
1177 RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
1348 RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets; |
1178 const TInt n = ifcsets.Count(); |
1349 const TInt n = ifcsets.Count(); |
1179 for (TInt i = 0; i < n; ++i) |
1350 for (TInt i = 0; i < n; ++i) |
1180 { |
1351 { |
1181 __KTRACE_OPT(KUSB, Kern::Printf(" Setting up InterfaceSet %d", i)); |
1352 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP8, |
|
1353 " Setting up InterfaceSet %d", i ); |
1182 InterfaceSetup(ifcsets[i]->iInterfaces[0]); |
1354 InterfaceSetup(ifcsets[i]->iInterfaces[0]); |
1183 } |
1355 } |
1184 // Enter Configured state (from Address or Configured) |
1356 // Enter Configured state (from Address or Configured) |
1185 NextDeviceState(EUsbcDeviceStateConfigured); |
1357 NextDeviceState(EUsbcDeviceStateConfigured); |
1186 } |
1358 } |
1187 __KTRACE_OPT(KUSB, Kern::Printf(" New configuration: %d", iCurrentConfig)); |
1359 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHANGECONFIGURATION_DUP9, |
|
1360 " New configuration: %d", iCurrentConfig ); |
1188 return; |
1361 return; |
1189 } |
1362 } |
1190 |
1363 |
1191 |
1364 |
1192 void DUsbClientController::InterfaceSetup(TUsbcInterface* aIfc) |
1365 void DUsbClientController::InterfaceSetup(TUsbcInterface* aIfc) |
1193 { |
1366 { |
1194 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetup()")); |
1367 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_INTERFACESETUP, |
|
1368 "DUsbClientController::InterfaceSetup()" ); |
1195 const TInt num_eps = aIfc->iEndpoints.Count(); |
1369 const TInt num_eps = aIfc->iEndpoints.Count(); |
1196 for (TInt i = 0; i < num_eps; i++) |
1370 for (TInt i = 0; i < num_eps; i++) |
1197 { |
1371 { |
1198 // Prepare this endpoint for I/O |
1372 // Prepare this endpoint for I/O |
1199 TUsbcLogicalEndpoint* const ep = aIfc->iEndpoints[i]; |
1373 TUsbcLogicalEndpoint* const ep = aIfc->iEndpoints[i]; |
1200 // (TUsbcLogicalEndpoint's FS/HS endpoint sizes and interval values got |
1374 // (TUsbcLogicalEndpoint's FS/HS endpoint sizes and interval values got |
1201 // adjusted in its constructor.) |
1375 // adjusted in its constructor.) |
1202 if (iHighSpeed) |
1376 if (iHighSpeed) |
1203 { |
1377 { |
1204 __KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (HS)", ep->iEpSize_Hs)); |
1378 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INTERFACESETUP_DUP1, |
|
1379 " Setting Ep info size to %d (HS)", ep->iEpSize_Hs ); |
1205 ep->iInfo.iSize = ep->iEpSize_Hs; |
1380 ep->iInfo.iSize = ep->iEpSize_Hs; |
1206 } |
1381 } |
1207 else |
1382 else |
1208 { |
1383 { |
1209 __KTRACE_OPT(KUSB, Kern::Printf(" Setting Ep info size to %d (FS)", ep->iEpSize_Fs)); |
1384 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INTERFACESETUP_DUP2, |
|
1385 " Setting Ep info size to %d (FS)", ep->iEpSize_Fs ); |
1210 ep->iInfo.iSize = ep->iEpSize_Fs; |
1386 ep->iInfo.iSize = ep->iEpSize_Fs; |
1211 } |
1387 } |
1212 const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr); |
1388 const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr); |
1213 if (ConfigureEndpoint(idx, ep->iInfo) != KErrNone) |
1389 if (ConfigureEndpoint(idx, ep->iInfo) != KErrNone) |
1214 { |
1390 { |
1215 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint %d configuration failed", idx)); |
1391 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_INTERFACESETUP_DUP3, |
|
1392 " Error: Endpoint %d configuration failed", idx ); |
1216 continue; |
1393 continue; |
1217 } |
1394 } |
1218 // Should there be a problem with it then we could try resetting the ep |
1395 // 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. |
1396 // data toggle at this point (or before the Configure) as well. |
1220 __KTRACE_OPT(KUSB, Kern::Printf(" Connecting real ep addr 0x%02x & logical ep #%d", |
1397 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INTERFACESETUP_DUP4, |
1221 ep->iPEndpoint->iEndpointAddr, ep->iLEndpointNum)); |
1398 " Connecting real ep addr 0x%02x & logical ep #%d", ep->iPEndpoint->iEndpointAddr, ep->iLEndpointNum ); |
1222 ep->iPEndpoint->iLEndpoint = ep; |
1399 ep->iPEndpoint->iLEndpoint = ep; |
1223 } |
1400 } |
1224 aIfc->iInterfaceSet->iCurrentInterface = aIfc->iSettingCode; |
1401 aIfc->iInterfaceSet->iCurrentInterface = aIfc->iSettingCode; |
1225 return; |
1402 return; |
1226 } |
1403 } |
1227 |
1404 |
1228 |
1405 |
1229 void DUsbClientController::InterfaceSetTeardown(TUsbcInterfaceSet* aIfcSet) |
1406 void DUsbClientController::InterfaceSetTeardown(TUsbcInterfaceSet* aIfcSet) |
1230 { |
1407 { |
1231 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetTeardown()")); |
1408 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_INTERFACESETTEARDOWN, |
|
1409 "DUsbClientController::InterfaceSetTeardown()" ); |
1232 if (aIfcSet->iInterfaces.Count() == 0) |
1410 if (aIfcSet->iInterfaces.Count() == 0) |
1233 { |
1411 { |
1234 __KTRACE_OPT(KUSB, Kern::Printf(" No interfaces exist - returning")); |
1412 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INTERFACESETTEARDOWN_DUP1, |
|
1413 " No interfaces exist - returning" ); |
1235 return; |
1414 return; |
1236 } |
1415 } |
1237 RPointerArray<TUsbcLogicalEndpoint>& eps = aIfcSet->CurrentInterface()->iEndpoints; |
1416 RPointerArray<TUsbcLogicalEndpoint>& eps = aIfcSet->CurrentInterface()->iEndpoints; |
1238 const TInt num_eps = eps.Count(); |
1417 const TInt num_eps = eps.Count(); |
1239 for (TInt i = 0; i < num_eps; i++) |
1418 for (TInt i = 0; i < num_eps; i++) |