sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalTechnology
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <e32base.h>
|
sl@0
|
22 |
#include <d32usbdi_hubdriver.h>
|
sl@0
|
23 |
#include <d32usbdi.h>
|
sl@0
|
24 |
#include <d32otgdi.h>
|
sl@0
|
25 |
#include <d32usbdescriptors.h>
|
sl@0
|
26 |
#include <d32usbtransfers.h>
|
sl@0
|
27 |
#include "botmsctypes.h"
|
sl@0
|
28 |
#include "msctypes.h"
|
sl@0
|
29 |
#include "mtransport.h"
|
sl@0
|
30 |
#include "mprotocol.h"
|
sl@0
|
31 |
#include "cusbifacehandler.h"
|
sl@0
|
32 |
#include "cbulkonlytransport.h"
|
sl@0
|
33 |
#include "debug.h"
|
sl@0
|
34 |
#include "msdebug.h"
|
sl@0
|
35 |
|
sl@0
|
36 |
CUsbInterfaceHandler* CUsbInterfaceHandler::NewL(RUsbInterface &aInterface)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
return new (ELeave) CUsbInterfaceHandler(aInterface);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
CUsbInterfaceHandler::CUsbInterfaceHandler(RUsbInterface &aInterface)
|
sl@0
|
42 |
: CActive(EPriorityStandard),
|
sl@0
|
43 |
iInterface(aInterface)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
__MSFNLOG
|
sl@0
|
46 |
CActiveScheduler::Add(this);
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
CUsbInterfaceHandler::~CUsbInterfaceHandler()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
__MSFNLOG
|
sl@0
|
52 |
if (iState != ENone)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
iState = ENone;
|
sl@0
|
55 |
iBotGetMaxLun.Complete(KErrCancel);
|
sl@0
|
56 |
Cancel();
|
sl@0
|
57 |
}
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
/**
|
sl@0
|
61 |
Cancellation of outstanding request
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
void CUsbInterfaceHandler::DoCancel()
|
sl@0
|
64 |
{
|
sl@0
|
65 |
__MSFNLOG
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
Completion of USB transport request.
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
void CUsbInterfaceHandler::RunL()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
__MSFNLOG
|
sl@0
|
74 |
TInt error = iStatus.Int();
|
sl@0
|
75 |
|
sl@0
|
76 |
if (error == KErrUsbStalled && iState == EGetMaxLun)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
__BOTPRINT(_L("...KErrUsbStalled"));
|
sl@0
|
79 |
iState = EReset;
|
sl@0
|
80 |
Reset();
|
sl@0
|
81 |
return;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
if (error == KErrNone)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
__BOTPRINT(_L("...KErrNone"));
|
sl@0
|
87 |
|
sl@0
|
88 |
if (iState == EGetMaxLun)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
__BOTPRINT(_L("...sending GetMaxLun response"));
|
sl@0
|
91 |
*ipGetMaxLun = iBuffer[0];
|
sl@0
|
92 |
}
|
sl@0
|
93 |
else
|
sl@0
|
94 |
{
|
sl@0
|
95 |
__BOTPRINT(_L("...defaulting to 0"));
|
sl@0
|
96 |
*ipGetMaxLun = 0;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
}
|
sl@0
|
99 |
else
|
sl@0
|
100 |
{
|
sl@0
|
101 |
__BOTPRINT(_L("...completeing with KErrGeneral"));
|
sl@0
|
102 |
error = KErrGeneral;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
iState = ENone;
|
sl@0
|
106 |
iBotGetMaxLun.Complete(error);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
void CUsbInterfaceHandler::GetMaxLun(TLun* aMaxLun, const RMessage2& aMessage)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
__MSFNLOG
|
sl@0
|
113 |
|
sl@0
|
114 |
/* Send the Get max lun command in the ep0 */
|
sl@0
|
115 |
RUsbInterface::TUsbTransferRequestDetails reqDetails;
|
sl@0
|
116 |
_LIT8(KNullDesC8,"");
|
sl@0
|
117 |
iBotGetMaxLun = aMessage;
|
sl@0
|
118 |
iState = EGetMaxLun;
|
sl@0
|
119 |
ipGetMaxLun = aMaxLun;
|
sl@0
|
120 |
|
sl@0
|
121 |
reqDetails.iRequestType = 0xA1;
|
sl@0
|
122 |
reqDetails.iRequest = 0xFE;
|
sl@0
|
123 |
reqDetails.iValue = 0x0000;
|
sl@0
|
124 |
reqDetails.iIndex = 0x0000;
|
sl@0
|
125 |
reqDetails.iFlags = 0x04; // Short transfer OK
|
sl@0
|
126 |
|
sl@0
|
127 |
iBuffer.SetLength(1);
|
sl@0
|
128 |
iInterface.Ep0Transfer(reqDetails, KNullDesC8, iBuffer, iStatus);
|
sl@0
|
129 |
SetActive();
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
void CUsbInterfaceHandler::Reset()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
__MSFNLOG
|
sl@0
|
136 |
RUsbInterface::TUsbTransferRequestDetails reqDetails;
|
sl@0
|
137 |
_LIT8(KNullDesC8,"");
|
sl@0
|
138 |
|
sl@0
|
139 |
reqDetails.iRequestType = 0x21;
|
sl@0
|
140 |
reqDetails.iRequest = 0xFF;
|
sl@0
|
141 |
reqDetails.iValue = 0x0000;
|
sl@0
|
142 |
reqDetails.iIndex = 0x0000;
|
sl@0
|
143 |
reqDetails.iFlags = 0x04; // Short transfer OK
|
sl@0
|
144 |
|
sl@0
|
145 |
iInterface.Ep0Transfer(reqDetails, KNullDesC8, (TDes8 &) KNullDesC8, iStatus);
|
sl@0
|
146 |
SetActive();
|
sl@0
|
147 |
}
|