253
|
1 |
// Copyright (c) 2007-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 |
// @file controlendpointreader.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "controlendpointreader.h"
|
|
20 |
#include "testdebug.h"
|
253
|
21 |
#include "OstTraceDefinitions.h"
|
|
22 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
23 |
#include "controlendpointreaderTraces.h"
|
|
24 |
#endif
|
0
|
25 |
|
|
26 |
namespace NUnitTesting_USBDI
|
|
27 |
{
|
|
28 |
|
|
29 |
CControlEndpointReader::CControlEndpointReader(RDevUsbcClient& aClientDriver,MRequestHandler& aRequestHandler)
|
|
30 |
: CEndpointReader(aClientDriver,EEndpoint0),
|
|
31 |
iDeviceToHost(EFalse),
|
|
32 |
iDataPhase(EFalse),
|
|
33 |
iRequestHandler(aRequestHandler)
|
|
34 |
{
|
253
|
35 |
OstTraceFunctionEntryExt( CCONTROLENDPOINTREADER_CCONTROLENDPOINTREADER_ENTRY, this );
|
|
36 |
OstTraceFunctionExit1( CCONTROLENDPOINTREADER_CCONTROLENDPOINTREADER_EXIT, this );
|
0
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
CControlEndpointReader::~CControlEndpointReader()
|
|
41 |
{
|
253
|
42 |
OstTraceFunctionEntry1( CCONTROLENDPOINTREADER_CCONTROLENDPOINTREADER_ENTRY_DUP01, this );
|
|
43 |
OstTraceFunctionExit1( CCONTROLENDPOINTREADER_CCONTROLENDPOINTREADER_EXIT_DUP01, this );
|
0
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
void CControlEndpointReader::ReadRequestsL()
|
|
48 |
{
|
253
|
49 |
OstTraceFunctionEntry1( CCONTROLENDPOINTREADER_READREQUESTSL_ENTRY, this );
|
0
|
50 |
|
|
51 |
// Read a packet from endpoint 0 (this should incorporate a request)
|
|
52 |
|
|
53 |
ReadPacketL(this);
|
253
|
54 |
OstTraceFunctionExit1( CCONTROLENDPOINTREADER_READREQUESTSL_EXIT, this );
|
0
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
void CControlEndpointReader::EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode)
|
|
59 |
{
|
253
|
60 |
OstTraceFunctionEntryExt( CCONTROLENDPOINTREADER_ENDPOINTREADERROR_ENTRY, this );
|
0
|
61 |
|
253
|
62 |
OstTraceExt2(TRACE_NORMAL, CCONTROLENDPOINTREADER_ENDPOINTREADERROR, "<Error %d> Asynchronous read on endpoint %d",aErrorCode,aEndpointNumber);
|
|
63 |
OstTraceFunctionExit1( CCONTROLENDPOINTREADER_ENDPOINTREADERROR_EXIT, this );
|
0
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
void CControlEndpointReader::DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData)
|
|
68 |
{
|
253
|
69 |
OstTraceFunctionEntryExt( CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_ENTRY, this );
|
0
|
70 |
|
253
|
71 |
OstTraceExt5(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL, "ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength);
|
|
72 |
OstTraceExt2(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP01, "iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase);
|
0
|
73 |
if(iDeviceToHost && iDataPhase)
|
|
74 |
{
|
|
75 |
TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,aData);
|
253
|
76 |
OstTrace1(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP02, "ProdessRequestL returned %d",err);
|
0
|
77 |
|
|
78 |
if(err != KErrAbort)
|
|
79 |
{
|
|
80 |
iDeviceToHost = EFalse;
|
|
81 |
iDataPhase = EFalse;
|
|
82 |
|
|
83 |
// After processing the request keep reading for more requests
|
|
84 |
// from the host
|
|
85 |
ReadPacketL(this);
|
|
86 |
}
|
|
87 |
}
|
|
88 |
else
|
|
89 |
{
|
|
90 |
// Understand the setup packet
|
|
91 |
ibRequestType = aData[0];
|
|
92 |
iDeviceToHost = (ibRequestType & 0x80) == 0x00;
|
|
93 |
|
|
94 |
// The request
|
|
95 |
ibRequest = aData[1];
|
|
96 |
|
|
97 |
// The request parameter
|
|
98 |
TUint8* p = reinterpret_cast<TUint8*>(&iwValue);
|
|
99 |
*p = aData[2];
|
|
100 |
*(p+1) = aData[3];
|
|
101 |
|
|
102 |
// The index for the request
|
|
103 |
p = reinterpret_cast<TUint8*>(&iwIndex);
|
|
104 |
*p = aData[4];
|
|
105 |
*(p+1) = aData[5];
|
|
106 |
|
|
107 |
// The length of data transfer
|
|
108 |
p = reinterpret_cast<TUint8*>(&iwLength);
|
|
109 |
*p = aData[6];
|
|
110 |
*(p+1) = aData[7];
|
|
111 |
|
|
112 |
iDataPhase = (iwLength > 0);
|
|
113 |
|
|
114 |
// Read all information about the request sent by the host
|
|
115 |
// i.e. any DATA1 packets sent after the setup DATA0 packet
|
253
|
116 |
OstTrace0(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP03, "AFTER UPDATES");
|
|
117 |
OstTraceExt5(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP04, "ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength);
|
|
118 |
OstTraceExt2(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP05, "iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase);
|
0
|
119 |
if(iDeviceToHost && iDataPhase)
|
|
120 |
{
|
253
|
121 |
OstTrace1(TRACE_NORMAL, CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_DUP06, "Issuing another read of %d bytes",iwLength);
|
0
|
122 |
ReadL(iwLength);
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,KNullDesC8);
|
|
127 |
|
|
128 |
if(err != KErrAbort)
|
|
129 |
{
|
|
130 |
// After processing the request keep reading for more requests
|
|
131 |
// from the host
|
|
132 |
ReadPacketL(this);
|
|
133 |
}
|
|
134 |
}
|
|
135 |
}
|
253
|
136 |
OstTraceFunctionExit1( CCONTROLENDPOINTREADER_DATARECEIVEDFROMENDPOINTL_EXIT, this );
|
0
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
}
|