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