300
|
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 |
#include <e32def.h>
|
|
18 |
#include <e32cmn.h>
|
|
19 |
#include <e32des8.h>
|
|
20 |
#include <e32std.h>
|
|
21 |
|
|
22 |
|
|
23 |
#include "msctypes.h"
|
|
24 |
#include "mscutils.h"
|
|
25 |
#include "botmsctypes.h"
|
|
26 |
#include "testman.h"
|
|
27 |
#include "botmscserver.h"
|
|
28 |
#include "debug.h"
|
|
29 |
|
|
30 |
TDataTransferMan::TDataTransferMan()
|
300
|
31 |
: iReadBuf(NULL, 0),
|
|
32 |
iWriteBuf(NULL, 0)
|
0
|
33 |
{
|
|
34 |
}
|
|
35 |
|
|
36 |
|
|
37 |
void TDataTransferMan::Init()
|
|
38 |
{
|
|
39 |
iMode = EDataTransferNoData;
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
/**
|
|
44 |
Called by the protocol after processing the packet to indicate that more data is
|
|
45 |
required.
|
|
46 |
|
|
47 |
@param aData reference to the data buffer.
|
|
48 |
*/
|
|
49 |
void TDataTransferMan::SetModeDataOut(TPtr8& aData)
|
300
|
50 |
{
|
|
51 |
__PRINT1(_L("Length = %d (bytes)\n"), aData.Length());
|
|
52 |
iReadBuf.Set(aData);
|
|
53 |
iMode = EDataTransferOut;
|
|
54 |
}
|
0
|
55 |
|
|
56 |
|
|
57 |
/**
|
|
58 |
Called by the protocol after processing the packet to indicate that data should
|
|
59 |
be written to the host.
|
|
60 |
|
|
61 |
@param aData reference to the data buffer.
|
|
62 |
*/
|
|
63 |
void TDataTransferMan::SetModeDataIn(TPtrC8& aData)
|
300
|
64 |
{
|
|
65 |
__PRINT1(_L("Length = %d (bytes)\n"), aData.Length());
|
|
66 |
iWriteBuf.Set(aData);
|
|
67 |
iMode = EDataTransferIn;
|
|
68 |
}
|
0
|
69 |
|
|
70 |
|
|
71 |
TBotServerReq::TBotServerReq()
|
|
72 |
{
|
|
73 |
}
|
|
74 |
|
|
75 |
|
|
76 |
void TBotServerReq::DecodeL(const TDesC8& aPtr)
|
|
77 |
{
|
|
78 |
if (aPtr.Length() != KCbwLength)
|
|
79 |
{
|
|
80 |
User::Leave(KErrUnderflow);
|
|
81 |
}
|
|
82 |
|
|
83 |
// Check reserved bits (must be zero)
|
|
84 |
if ((aPtr[KCbwLunOffset] & 0xF0) || (aPtr[KCbwCbLengthOffset] & 0xE0))
|
300
|
85 |
{
|
|
86 |
__PRINT(_L("Reserved bits not zero\n"));
|
0
|
87 |
User::Leave(KErrArgument);
|
300
|
88 |
}
|
0
|
89 |
|
|
90 |
iSignature = LittleEndian::Get32(&aPtr[KCbwSignatureOffset]);
|
|
91 |
iTag = LittleEndian::Get32(&aPtr[KCbwTagOffset]);
|
|
92 |
iDataTransferLength = LittleEndian::Get32(&aPtr[KCbwDataTransferLengthOffset]);
|
|
93 |
iDirection = aPtr[KCbwFlagOffset] ? EDataIn : EDataOut;
|
|
94 |
iLun = aPtr[KCbwLunOffset] & 0x0F;
|
|
95 |
iCbLength = aPtr[KCbwCbLengthOffset];
|
|
96 |
}
|
|
97 |
|
|
98 |
TBool TBotServerReq::IsValidCbw() const
|
|
99 |
{
|
|
100 |
if (iSignature != 0x43425355)
|
|
101 |
{
|
|
102 |
return EFalse;
|
|
103 |
}
|
|
104 |
|
|
105 |
// CBW length checked in DecodeL
|
|
106 |
return ETrue;
|
|
107 |
}
|
|
108 |
|
|
109 |
TBool TBotServerReq::IsMeaningfulCbw(TInt aMaxLun) const
|
|
110 |
{
|
|
111 |
if (iLun > aMaxLun)
|
|
112 |
{
|
|
113 |
return EFalse;
|
|
114 |
}
|
|
115 |
|
|
116 |
if (iCbLength < 1 || iCbLength > KMaxCbwcbLength)
|
|
117 |
{
|
|
118 |
return EFalse;
|
|
119 |
}
|
|
120 |
return ETrue;
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
TBotCsw::TBotCsw(TUint32 aTag, TUint32 aDataResidue, TCswStatus aStatus)
|
|
125 |
: iTag(aTag),
|
|
126 |
iDataResidue(aDataResidue),
|
|
127 |
iStatus(aStatus)
|
|
128 |
{
|
|
129 |
}
|
|
130 |
|
|
131 |
TBotServerResp::TBotServerResp(TUint32 aTag, TUint32 aDataResidue, TCswStatus aStatus)
|
|
132 |
: TBotCsw(aTag, aDataResidue, aStatus)
|
|
133 |
{
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
void TBotServerResp::EncodeL(TDes8& aBuffer) const
|
|
138 |
{
|
300
|
139 |
TUint8* ptr = const_cast<TUint8*>(aBuffer.Ptr());
|
0
|
140 |
|
|
141 |
// dCBWSignature
|
|
142 |
ptr += KCswSignatureOffset;
|
|
143 |
*ptr++ = 0x55;
|
|
144 |
*ptr++ = 0x53;
|
|
145 |
*ptr++ = 0x42;
|
|
146 |
*ptr++ = 0x53;
|
|
147 |
|
|
148 |
LittleEndian::Put32(&aBuffer[KCswTagOffset], iTag);
|
|
149 |
LittleEndian::Put32(&aBuffer[KCswDataResidueOffset], iDataResidue);
|
|
150 |
|
|
151 |
aBuffer[KCswStatusOffset] = static_cast<TUint8>(iStatus);
|
|
152 |
}
|
|
153 |
|
|
154 |
#ifdef MSDC_TESTMODE
|
|
155 |
void TBotServerResp::EncodeL(TDes8& aBuffer, TTestParser* aTestParser) const
|
|
156 |
{
|
|
157 |
// dCBWSignature
|
|
158 |
TInt index = KCswSignatureOffset;
|
|
159 |
aBuffer[index++] = 0x55;
|
|
160 |
aBuffer[index++] = 0x53;
|
|
161 |
aBuffer[index++] = 0x42;
|
|
162 |
aBuffer[index++] = 0x53;
|
|
163 |
|
|
164 |
TUint32 tag = iTag;
|
|
165 |
TCswStatus status = iStatus;
|
|
166 |
|
|
167 |
if (aTestParser && aTestParser->Enabled())
|
|
168 |
{
|
|
169 |
TTestParser::TTestCase testCase = aTestParser->TestCase();
|
|
170 |
|
|
171 |
if (testCase == TTestParser::ETestCaseInvalidSignature)
|
|
172 |
{
|
|
173 |
__TESTMODEPRINT1("[x%x] Setting Invalid Signature in CSW", tag);
|
|
174 |
aTestParser->ClrTestCase();
|
|
175 |
|
|
176 |
index = KCswSignatureOffset;
|
|
177 |
aBuffer[index++] = 0x50;
|
|
178 |
aBuffer[index++] = 0x50;
|
|
179 |
aBuffer[index++] = 0x50;
|
|
180 |
aBuffer[index++] = 0x50;
|
|
181 |
}
|
|
182 |
else if (testCase == TTestParser::ETestCaseTagMismatch)
|
|
183 |
{
|
|
184 |
__TESTMODEPRINT1("[x%x] Setting invalid tag in CSW", tag);
|
|
185 |
aTestParser->ClrTestCase();
|
|
186 |
tag = ~iTag;
|
|
187 |
}
|
|
188 |
|
|
189 |
if (aTestParser->Enabled())
|
|
190 |
{
|
|
191 |
if (testCase == TTestParser::ETestCaseDoPhaseError)
|
|
192 |
{
|
|
193 |
aTestParser->ClrTestCase();
|
|
194 |
__TESTMODEPRINT1("[x%x] Setting CSW Phase Error (Data-Out)", tag);
|
|
195 |
status = TBotCsw::EPhaseError;
|
|
196 |
}
|
|
197 |
else if (testCase == TTestParser::ETestCaseDiPhaseError)
|
|
198 |
{
|
|
199 |
aTestParser->ClrTestCase();
|
|
200 |
__TESTMODEPRINT1("[x%x] Setting CSW Phase Error (Data-In)", tag);
|
|
201 |
status = TBotCsw::EPhaseError;
|
|
202 |
}
|
|
203 |
else if (testCase == TTestParser::ETestCaseNoDataPhaseError &&
|
|
204 |
aTestParser->PhaseErrorEnabled())
|
|
205 |
{
|
|
206 |
aTestParser->ClrTestCase();
|
|
207 |
__TESTMODEPRINT1("[x%x] Setting CSW Phase (no data)", tag);
|
|
208 |
status = TBotCsw::EPhaseError;
|
|
209 |
}
|
|
210 |
else
|
|
211 |
; // do nothing
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
LittleEndian::Put32(&aBuffer[KCswTagOffset], tag);
|
|
216 |
LittleEndian::Put32(&aBuffer[KCswDataResidueOffset], iDataResidue);
|
|
217 |
|
|
218 |
|
|
219 |
aBuffer[KCswStatusOffset] = static_cast<TUint8>(status);
|
|
220 |
}
|
|
221 |
#endif
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
/**
|
|
226 |
This function unpacks into the TUsbRequestHdr class from a descriptor with
|
|
227 |
the alignment that would be introduced on the USB bus.
|
|
228 |
|
|
229 |
@param aBuffer Input buffer
|
|
230 |
@param aTarget Unpacked header.
|
|
231 |
@return Error.
|
|
232 |
*/
|
|
233 |
TInt TBotServerFunctionReq::Decode(const TDesC8& aBuffer)
|
|
234 |
|
300
|
235 |
{
|
|
236 |
if (aBuffer.Length() < static_cast<TInt>(KRequestHdrSize))
|
|
237 |
{
|
0
|
238 |
__PRINT1(_L("TBotServerFunctionReq::Decode buffer invalid length %d"), aBuffer.Length());
|
300
|
239 |
return KErrGeneral;
|
|
240 |
}
|
0
|
241 |
|
300
|
242 |
iRequestType = aBuffer[0];
|
|
243 |
iRequest = static_cast<TEp0Request>(aBuffer[1]);
|
|
244 |
iValue = static_cast<TUint16>(aBuffer[2] + (aBuffer[3] << 8));
|
|
245 |
iIndex = static_cast<TUint16>(aBuffer[4] + (aBuffer[5] << 8));
|
|
246 |
iLength = static_cast<TUint16>(aBuffer[6] + (aBuffer[7] << 8));
|
0
|
247 |
__PRINT5(_L("type=%d request=%d value=%d index=%d length=%d"), iRequestType,iRequest,iValue,iIndex,iLength);
|
|
248 |
|
300
|
249 |
return KErrNone;
|
|
250 |
}
|
0
|
251 |
|
|
252 |
|
|
253 |
/**
|
|
254 |
This function determines whether data is required by the host in response
|
|
255 |
to a message header.
|
|
256 |
|
300
|
257 |
@return TBool Flag indicating whether a data response required.
|
0
|
258 |
*/
|
|
259 |
TBool TBotServerFunctionReq::IsDataResponseRequired() const
|
|
260 |
|
300
|
261 |
{
|
|
262 |
return (iRequestType & 0x80) ? ETrue : EFalse;
|
|
263 |
}
|