297
|
1 |
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalTechnology
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include <e32base.h>
|
|
24 |
#include <d32usbc.h>
|
|
25 |
|
|
26 |
#include "mstypes.h"
|
|
27 |
#include "msctypes.h"
|
|
28 |
#include "usbmsclientpanic.h"
|
|
29 |
#include "botmsctypes.h"
|
|
30 |
#include "testman.h"
|
|
31 |
#include "botmscserver.h"
|
|
32 |
#include "mdevicetransport.h"
|
|
33 |
#include "mserverprotocol.h"
|
|
34 |
#include "cbulkonlytransport.h"
|
|
35 |
|
|
36 |
#include "cusbmassstoragecontroller.h"
|
|
37 |
#include "botcontrolinterface.h"
|
|
38 |
#include "debug.h"
|
|
39 |
|
|
40 |
TTestConfig::TTestConfig()
|
|
41 |
: iTestMode(ENone)
|
|
42 |
{
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
////////////////////////////////////
|
|
47 |
/**
|
|
48 |
Called by CBulkOnlyTransport to create an instance of CControlInterface
|
|
49 |
|
|
50 |
@param aParent reference to the CBulkOnlyTransport
|
|
51 |
*/
|
|
52 |
CBotControlInterface* CBotControlInterface::NewL(CBulkOnlyTransport& aParent)
|
297
|
53 |
{
|
|
54 |
CBotControlInterface* self = new(ELeave) CBotControlInterface(aParent);
|
|
55 |
CleanupStack::PushL(self);
|
|
56 |
self->ConstructL();
|
|
57 |
CActiveScheduler::Add(self);
|
|
58 |
CleanupStack::Pop();
|
|
59 |
return self;
|
|
60 |
}
|
0
|
61 |
|
|
62 |
|
|
63 |
void CBotControlInterface::ConstructL()
|
297
|
64 |
{
|
|
65 |
}
|
0
|
66 |
|
|
67 |
|
|
68 |
/**
|
|
69 |
c'tor
|
|
70 |
|
|
71 |
@param aParent reference to the CBulkOnlyTransport
|
|
72 |
*/
|
|
73 |
CBotControlInterface::CBotControlInterface(CBulkOnlyTransport& aParent):
|
297
|
74 |
CActive(EPriorityStandard),
|
|
75 |
iParent(aParent),
|
|
76 |
iCurrentState(ENone)
|
|
77 |
{
|
|
78 |
}
|
0
|
79 |
|
|
80 |
|
|
81 |
/**
|
|
82 |
d'tor
|
|
83 |
*/
|
|
84 |
CBotControlInterface::~CBotControlInterface()
|
297
|
85 |
{
|
|
86 |
Cancel();
|
|
87 |
}
|
0
|
88 |
|
|
89 |
|
|
90 |
/**
|
|
91 |
Called by CBulkOnlyTransportStart to start control interface
|
|
92 |
*/
|
|
93 |
TInt CBotControlInterface::Start()
|
297
|
94 |
{
|
0
|
95 |
if (IsActive())
|
|
96 |
{
|
|
97 |
__PRINT(_L("Still active\n"));
|
|
98 |
return KErrServerBusy;
|
|
99 |
}
|
297
|
100 |
ReadEp0Data();
|
|
101 |
return KErrNone;
|
|
102 |
}
|
0
|
103 |
|
|
104 |
|
|
105 |
/**
|
|
106 |
Called by CBulkOnlyTransportStart to stop control interface
|
|
107 |
*/
|
|
108 |
void CBotControlInterface::Stop()
|
297
|
109 |
{
|
|
110 |
if (!IsActive())
|
|
111 |
{
|
|
112 |
__PRINT(_L("Not active\n"));
|
|
113 |
return;
|
|
114 |
}
|
0
|
115 |
|
297
|
116 |
__PRINT(_L("\nStopping...\n"));
|
|
117 |
iCurrentState = ENone;
|
|
118 |
Cancel();
|
|
119 |
}
|
0
|
120 |
|
|
121 |
|
|
122 |
/**
|
|
123 |
Cancel outstanding request (if any)
|
|
124 |
*/
|
|
125 |
void CBotControlInterface::DoCancel()
|
297
|
126 |
{
|
|
127 |
switch(iCurrentState)
|
|
128 |
{
|
|
129 |
case EReadEp0Data:
|
|
130 |
iParent.Ldd().ReadCancel(EEndpoint0);
|
|
131 |
break;
|
|
132 |
case ESendMaxLun:
|
|
133 |
iParent.Ldd().WriteCancel(EEndpoint0);
|
|
134 |
break;
|
|
135 |
default:
|
|
136 |
__PRINT(_L("\nWrong state !\n"));
|
|
137 |
__ASSERT_DEBUG(EFalse, User::Panic(KUsbMsClientPanicCat, EMsControlInterfaceBadState));
|
|
138 |
}
|
|
139 |
}
|
0
|
140 |
|
|
141 |
|
|
142 |
/**
|
|
143 |
Implement CBotControlInterface state machine
|
|
144 |
*/
|
|
145 |
void CBotControlInterface::RunL()
|
297
|
146 |
{
|
|
147 |
if (iStatus != KErrNone)
|
|
148 |
{
|
|
149 |
__PRINT1(_L("Error %d in RunL\n"), iStatus.Int());
|
0
|
150 |
|
297
|
151 |
//read EP0 again
|
|
152 |
ReadEp0Data();
|
|
153 |
return;
|
|
154 |
}
|
0
|
155 |
|
297
|
156 |
switch (iCurrentState)
|
|
157 |
{
|
|
158 |
case ESendMaxLun:
|
|
159 |
ReadEp0Data();
|
|
160 |
break;
|
0
|
161 |
|
297
|
162 |
case EReadEp0Data:
|
|
163 |
DecodeEp0Data();
|
|
164 |
break;
|
0
|
165 |
|
297
|
166 |
default:
|
|
167 |
__PRINT(_L(" error: (Shouldn't end up here...)\n"));
|
|
168 |
__ASSERT_DEBUG(EFalse, User::Panic(KUsbMsClientPanicCat, EMsControlInterfaceBadState));
|
|
169 |
break;
|
|
170 |
}
|
|
171 |
}
|
0
|
172 |
|
|
173 |
|
|
174 |
/**
|
|
175 |
Post a read request to EEndpoint0 to read request header
|
|
176 |
*/
|
|
177 |
void CBotControlInterface::ReadEp0Data()
|
297
|
178 |
{
|
|
179 |
iParent.Ldd().Read(iStatus, EEndpoint0, iData, KRequestHdrSize);
|
|
180 |
iCurrentState = EReadEp0Data;
|
|
181 |
SetActive();
|
|
182 |
}
|
0
|
183 |
|
|
184 |
|
|
185 |
/**
|
|
186 |
Decode request header and do appropriate action - get max LUN info or post a reset request
|
|
187 |
*/
|
|
188 |
void CBotControlInterface::DecodeEp0Data()
|
297
|
189 |
{
|
|
190 |
TInt err = iRequestHeader.Decode(iData);
|
|
191 |
if (err != KErrNone)
|
|
192 |
return;
|
0
|
193 |
|
|
194 |
switch(iRequestHeader.iRequest)
|
297
|
195 |
{
|
|
196 |
//
|
|
197 |
// GET MAX LUN (0xFE)
|
|
198 |
//
|
0
|
199 |
case TBotFunctionReqCb::EReqGetMaxLun:
|
297
|
200 |
{
|
|
201 |
__PRINT1(_L("DecodeEp0Data : 'Get Max LUN' Request MaxLun = %d"),iParent.MaxLun());
|
0
|
202 |
|
|
203 |
if ( iRequestHeader.iRequestType != 0xA1 //value from USB MS BOT spec
|
|
204 |
|| iRequestHeader.iIndex > 15
|
|
205 |
|| iRequestHeader.iValue != 0
|
|
206 |
|| iRequestHeader.iLength != 1)
|
|
207 |
{
|
297
|
208 |
__PRINT(_L("GetMaxLun command packet check error"));
|
0
|
209 |
iParent.Ldd().EndpointZeroRequestError();
|
|
210 |
ReadEp0Data(); //try to get another request
|
|
211 |
}
|
|
212 |
else
|
|
213 |
{
|
|
214 |
iData.FillZ(1); //Return only 1 byte to host
|
297
|
215 |
iData[0] = static_cast<TUint8>(iParent.MaxLun()); // Supported Units
|
0
|
216 |
iParent.Ldd().Write(iStatus, EEndpoint0, iData, 1);
|
|
217 |
|
|
218 |
iCurrentState = ESendMaxLun;
|
|
219 |
SetActive();
|
|
220 |
}
|
297
|
221 |
}
|
0
|
222 |
break;
|
297
|
223 |
//
|
|
224 |
// RESET (0xFF)
|
|
225 |
//
|
|
226 |
case TBotFunctionReqCb::EReqReset:
|
|
227 |
{
|
|
228 |
__PRINT(_L("DecodeEp0Data : 'Mass Storage Reset' Request"));
|
0
|
229 |
__TESTMODEPRINT("------- BOT RESET ------");
|
|
230 |
|
|
231 |
if ( iRequestHeader.iRequestType != 0x21 //value from USB MS BOT spec
|
|
232 |
|| iRequestHeader.iIndex > 15
|
|
233 |
|| iRequestHeader.iValue != 0
|
|
234 |
|| iRequestHeader.iLength != 0)
|
|
235 |
{
|
297
|
236 |
__PRINT(_L("MSC Reset command packet check error"));
|
0
|
237 |
iParent.Ldd().EndpointZeroRequestError();
|
|
238 |
ReadEp0Data(); //try to get another request
|
|
239 |
}
|
|
240 |
else
|
|
241 |
{
|
|
242 |
iParent.HwStop();
|
|
243 |
iParent.Controller().Reset();
|
|
244 |
iParent.HwStart(ETrue);
|
|
245 |
iParent.Ldd().SendEp0StatusPacket();
|
|
246 |
}
|
297
|
247 |
}
|
0
|
248 |
break;
|
297
|
249 |
//
|
|
250 |
// Unknown?
|
|
251 |
//
|
|
252 |
default:
|
|
253 |
__PRINT(_L("DecodeEp0Data : Unknown Request"));
|
0
|
254 |
ReadEp0Data(); //try to get another request
|
|
255 |
break;
|
|
256 |
}
|
297
|
257 |
}
|