36 iNewAltSetting = 0; |
36 iNewAltSetting = 0; |
37 iAltSettingSeq = 0; |
37 iAltSettingSeq = 0; |
38 return r; |
38 return r; |
39 } |
39 } |
40 |
40 |
|
41 // empty a endpoint buffer, this is called when device state enter undefined |
|
42 TInt RDevUsbcScClient::Empty(TUint aBufferOffset) |
|
43 { |
|
44 TUint8* base = iSharedChunk.Base(); |
|
45 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset + base); |
|
46 TUint localTail = endpointHdr->iBilTail; |
|
47 TUsbcScTransferHeader* currentTransfer; |
|
48 TInt err=KErrNone; |
|
49 |
|
50 while (ETrue) |
|
51 { |
|
52 if (localTail == (TUint) endpointHdr->iHead) |
|
53 { |
|
54 err = KErrNone; |
|
55 break; |
|
56 } |
|
57 currentTransfer = (TUsbcScTransferHeader*) (base + localTail); |
|
58 localTail = currentTransfer->iNext; |
|
59 } // end while |
|
60 endpointHdr->iBilTail = localTail; |
|
61 endpointHdr->iTail = localTail; |
|
62 return err; |
|
63 } |
|
64 |
|
65 |
41 |
66 |
42 EXPORT_C TInt RDevUsbcScClient::FinalizeInterface(RChunk*& aChunk) |
67 EXPORT_C TInt RDevUsbcScClient::FinalizeInterface(RChunk*& aChunk) |
43 { |
68 { |
44 TInt errorOrhandle = DoControl(EControlRealizeInterface); |
69 TInt errorOrhandle = DoControl(EControlRealizeInterface); |
45 iSharedChunk.SetReturnedHandle(errorOrhandle); |
70 iSharedChunk.SetReturnedHandle(errorOrhandle); |
46 iEndpointStatus = 0x00; //all endpoints are closed at the moment |
71 iEndpointStatus = 0x00; //all endpoints are closed at the moment |
47 iAlternateSetting = 0; |
72 iAlternateSetting = 0; |
48 return aChunk->SetReturnedHandle(errorOrhandle); |
73 return aChunk->SetReturnedHandle(errorOrhandle); |
|
74 } |
|
75 |
|
76 |
|
77 EXPORT_C void RDevUsbcScClient::ResetAltSetting() |
|
78 { |
|
79 if (iAlternateSetting == 0) |
|
80 return; |
|
81 TUsbcScChunkHeader chunkHeader(iSharedChunk); |
|
82 |
|
83 TInt ep; |
|
84 TInt noEp; |
|
85 TUint bufOff; |
|
86 TUsbcScHdrEndpointRecord* endpointInf = NULL; |
|
87 |
|
88 // check if alternate setting contains all IN endpoints |
|
89 noEp = chunkHeader.GetNumberOfEndpoints(iAlternateSetting); |
|
90 |
|
91 // for each used buffer. |
|
92 for (ep=1;ep<=noEp;ep++) |
|
93 { |
|
94 bufOff = chunkHeader.GetBuffer(iAlternateSetting,ep,endpointInf)->Offset(); |
|
95 |
|
96 if (endpointInf->Direction() & KUsbScHdrEpDirectionOut) |
|
97 { |
|
98 Empty(bufOff); // we need to remove anythng in the way, and get it ready for reading. |
|
99 } |
|
100 } |
|
101 |
|
102 iAlternateSetting = 0; |
49 } |
103 } |
50 |
104 |
51 |
105 |
52 EXPORT_C TInt RDevUsbcScClient::OpenEndpoint(TEndpointBuffer& aEpB, TInt aEpI) |
106 EXPORT_C TInt RDevUsbcScClient::OpenEndpoint(TEndpointBuffer& aEpB, TInt aEpI) |
53 { |
107 { |
116 //This drains any old data from an OUT buffer, and gets it ready for reading an ep. |
170 //This drains any old data from an OUT buffer, and gets it ready for reading an ep. |
117 //aBufferOffset - The offset, into the chunk, that the buffer in question, may be found. |
171 //aBufferOffset - The offset, into the chunk, that the buffer in question, may be found. |
118 |
172 |
119 TInt RDevUsbcScClient::Drain(TUint aBufferOffset) |
173 TInt RDevUsbcScClient::Drain(TUint aBufferOffset) |
120 { |
174 { |
|
175 |
121 TUint8* base = iSharedChunk.Base(); |
176 TUint8* base = iSharedChunk.Base(); |
122 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset+base); |
177 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset+base); |
123 TUint localTail = endpointHdr->iBilTail; |
178 TUint localTail = endpointHdr->iBilTail; |
124 TUsbcScTransferHeader* currentTransfer; |
179 TUsbcScTransferHeader* currentTransfer; |
125 TUint16 next = (iAltSettingSeq+1)&0xFFFF; |
180 TUint16 next = (iAltSettingSeq+1)&0xFFFF; |
126 TInt err=KErrNone; |
181 TInt err=KErrNone; |
|
182 TBool aZLP; |
127 |
183 |
128 while (ETrue) |
184 while (ETrue) |
129 { |
185 { |
130 if (localTail == (TUint) endpointHdr->iHead) |
186 if (localTail == (TUint) endpointHdr->iHead) |
131 { |
187 { |
403 if (iOutState) |
464 if (iOutState) |
404 return iOutState; |
465 return iOutState; |
405 |
466 |
406 TUsbcScTransferHeader* currentTransfer; |
467 TUsbcScTransferHeader* currentTransfer; |
407 TInt r; |
468 TInt r; |
|
469 TInt aBilTail; |
408 do // until we have a transfer with data. |
470 do // until we have a transfer with data. |
409 { |
471 { |
410 iEndpointHdr->iTail = iEndpointHdr->iBilTail; |
472 iEndpointHdr->iTail = iEndpointHdr->iBilTail; |
411 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
473 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
412 { |
474 { |
413 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
475 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
414 if (r!=KErrCompletion) // Data could arrive since we checked. |
476 if (r!=KErrCompletion) // Data could arrive since we checked. |
415 return r; |
477 return r; |
416 } |
478 } |
417 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
479 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
418 |
480 aBilTail = iEndpointHdr->iBilTail; |
419 iEndpointHdr->iBilTail = currentTransfer->iNext; |
481 iEndpointHdr->iBilTail = currentTransfer->iNext; |
420 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; |
482 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; |
|
483 |
|
484 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
|
485 { |
|
486 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
|
487 { |
|
488 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
|
489 //this variable will reflect the latest requested AlternateSetting |
|
490 } |
|
491 |
|
492 |
|
493 if (iEndpointNumber != KEp0Number) |
|
494 { |
|
495 iEndpointHdr->iBilTail = aBilTail; |
|
496 // iOutState = EEOF; |
|
497 return KErrEof; |
|
498 } |
|
499 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
|
500 { |
|
501 return KErrAlternateSettingChanged; |
|
502 } |
|
503 } |
|
504 |
|
505 } |
|
506 while ((currentTransfer->iBytes==0) && (!aZLP)); // ignore empty transfers |
|
507 |
|
508 aBuffer = currentTransfer->iData.i; |
|
509 aSize = currentTransfer->iBytes; |
|
510 return (currentTransfer->iFlags & KUsbcScStateChange)?KStateChange:KErrCompletion; |
|
511 } |
|
512 |
|
513 EXPORT_C TInt TEndpointBuffer::TakeBuffer(TAny*& aBuffer,TUint& aSize,TBool& aZLP,TRequestStatus& aStatus,TUint aLength) |
|
514 { |
|
515 if (iOutState) |
|
516 return iOutState; |
|
517 |
|
518 |
|
519 TUsbcScTransferHeader* currentTransfer; |
|
520 TInt r; |
|
521 TInt aBilTail; |
|
522 do // until we have a transfer with data. |
|
523 { |
|
524 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
|
525 { |
|
526 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
|
527 if (r!=KErrCompletion) // Data could arrive since we checked. |
|
528 { |
|
529 return r; |
|
530 } |
|
531 } |
|
532 |
|
533 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
|
534 aBilTail = iEndpointHdr->iBilTail; |
|
535 iEndpointHdr->iBilTail = currentTransfer->iNext; |
|
536 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; // True if short packet else false |
421 |
537 |
422 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
538 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
423 { |
539 { |
424 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
540 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
425 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
541 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
426 //this variable will reflect the latest requested AlternateSetting |
542 //this variable will reflect the latest requested AlternateSetting |
427 |
543 |
428 |
|
429 if (iEndpointNumber != KEp0Number) |
544 if (iEndpointNumber != KEp0Number) |
430 { |
545 { |
431 // iOutState = EEOF; |
546 iEndpointHdr->iBilTail = aBilTail; |
432 return KErrEof; |
|
433 } |
|
434 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
|
435 { |
|
436 return KErrAlternateSettingChanged; |
|
437 } |
|
438 } |
|
439 |
|
440 } |
|
441 while ((currentTransfer->iBytes==0) && (!aZLP)); // ignore empty transfers |
|
442 |
|
443 aBuffer = currentTransfer->iData.i; |
|
444 aSize = currentTransfer->iBytes; |
|
445 return (currentTransfer->iFlags & KUsbcScStateChange)?KStateChange:KErrCompletion; |
|
446 } |
|
447 |
|
448 EXPORT_C TInt TEndpointBuffer::TakeBuffer(TAny*& aBuffer,TUint& aSize,TBool& aZLP,TRequestStatus& aStatus,TUint aLength) |
|
449 { |
|
450 if (iOutState) |
|
451 return iOutState; |
|
452 |
|
453 TUsbcScTransferHeader* currentTransfer; |
|
454 TInt r; |
|
455 do // until we have a transfer with data. |
|
456 { |
|
457 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
|
458 { |
|
459 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
|
460 if (r!=KErrCompletion) // Data could arrive since we checked. |
|
461 { |
|
462 return r; |
|
463 } |
|
464 } |
|
465 |
|
466 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
|
467 iEndpointHdr->iBilTail = currentTransfer->iNext; |
|
468 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; // True if short packet else false |
|
469 |
|
470 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
|
471 { |
|
472 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
|
473 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
|
474 //this variable will reflect the latest requested AlternateSetting |
|
475 Expire(currentTransfer->iData.i); |
|
476 if (iEndpointNumber != KEp0Number) |
|
477 { |
|
478 // iOutState = EEOF; |
547 // iOutState = EEOF; |
479 return KErrEof; |
548 return KErrEof; |
480 } |
549 } |
481 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
550 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
482 { |
551 { |
|
552 Expire(currentTransfer->iData.i); |
483 return KErrAlternateSettingChanged; |
553 return KErrAlternateSettingChanged; |
484 } |
554 } |
|
555 Expire(currentTransfer->iData.i); |
485 |
556 |
486 } |
557 } |
487 |
558 |
488 if ((currentTransfer->iBytes==0) && (!aZLP)) // here , if empty transfer with alt setting information, Call expire |
559 if ((currentTransfer->iBytes==0) && (!aZLP)) // here , if empty transfer with alt setting information, Call expire |
489 { |
560 { |