44
|
1 |
// Copyright (c) 2007-2009 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"
|
|
21 |
|
|
22 |
namespace NUnitTesting_USBDI
|
|
23 |
{
|
|
24 |
|
|
25 |
CControlEndpointReader::CControlEndpointReader(RDevUsbcClient& aClientDriver,MRequestHandler& aRequestHandler)
|
|
26 |
: CEndpointReader(aClientDriver,EEndpoint0),
|
|
27 |
iDeviceToHost(EFalse),
|
|
28 |
iDataPhase(EFalse),
|
|
29 |
iRequestHandler(aRequestHandler)
|
|
30 |
{
|
|
31 |
}
|
|
32 |
|
|
33 |
|
|
34 |
CControlEndpointReader::~CControlEndpointReader()
|
|
35 |
{
|
44
|
36 |
LOG_FUNC
|
0
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
void CControlEndpointReader::ReadRequestsL()
|
|
41 |
{
|
44
|
42 |
LOG_FUNC
|
0
|
43 |
|
|
44 |
// Read a packet from endpoint 0 (this should incorporate a request)
|
|
45 |
|
|
46 |
ReadPacketL(this);
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
void CControlEndpointReader::EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode)
|
|
51 |
{
|
44
|
52 |
LOG_FUNC
|
0
|
53 |
|
44
|
54 |
RDebug::Printf("<Error %d> Asynchronous read on endpoint %d",aErrorCode,aEndpointNumber);
|
0
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
void CControlEndpointReader::DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData)
|
|
59 |
{
|
44
|
60 |
LOG_FUNC
|
0
|
61 |
|
44
|
62 |
RDebug::Printf("ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength);
|
|
63 |
RDebug::Printf("iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase);
|
0
|
64 |
if(iDeviceToHost && iDataPhase)
|
|
65 |
{
|
|
66 |
TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,aData);
|
44
|
67 |
RDebug::Printf("ProdessRequestL returned %d",err);
|
0
|
68 |
|
|
69 |
if(err != KErrAbort)
|
|
70 |
{
|
|
71 |
iDeviceToHost = EFalse;
|
|
72 |
iDataPhase = EFalse;
|
|
73 |
|
|
74 |
// After processing the request keep reading for more requests
|
|
75 |
// from the host
|
|
76 |
ReadPacketL(this);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
else
|
|
80 |
{
|
|
81 |
// Understand the setup packet
|
|
82 |
ibRequestType = aData[0];
|
|
83 |
iDeviceToHost = (ibRequestType & 0x80) == 0x00;
|
|
84 |
|
|
85 |
// The request
|
|
86 |
ibRequest = aData[1];
|
|
87 |
|
|
88 |
// The request parameter
|
|
89 |
TUint8* p = reinterpret_cast<TUint8*>(&iwValue);
|
|
90 |
*p = aData[2];
|
|
91 |
*(p+1) = aData[3];
|
|
92 |
|
|
93 |
// The index for the request
|
|
94 |
p = reinterpret_cast<TUint8*>(&iwIndex);
|
|
95 |
*p = aData[4];
|
|
96 |
*(p+1) = aData[5];
|
|
97 |
|
|
98 |
// The length of data transfer
|
|
99 |
p = reinterpret_cast<TUint8*>(&iwLength);
|
|
100 |
*p = aData[6];
|
|
101 |
*(p+1) = aData[7];
|
|
102 |
|
|
103 |
iDataPhase = (iwLength > 0);
|
|
104 |
|
|
105 |
// Read all information about the request sent by the host
|
|
106 |
// i.e. any DATA1 packets sent after the setup DATA0 packet
|
44
|
107 |
RDebug::Printf("AFTER UPDATES");
|
|
108 |
RDebug::Printf("ibRequestType = %d, ibRequest = %d, iwValue = %d, iwIndex = %d, iwLength = %d",ibRequestType, ibRequest, iwValue, iwIndex, iwLength);
|
|
109 |
RDebug::Printf("iDeviceToHost = %d, iDataPhase = %d",iDeviceToHost,iDataPhase);
|
0
|
110 |
if(iDeviceToHost && iDataPhase)
|
|
111 |
{
|
44
|
112 |
RDebug::Printf("Issuing another read of %d bytes",iwLength);
|
0
|
113 |
ReadL(iwLength);
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
TInt err = iRequestHandler.ProcessRequestL(ibRequest,iwValue,iwIndex,iwLength,KNullDesC8);
|
|
118 |
|
|
119 |
if(err != KErrAbort)
|
|
120 |
{
|
|
121 |
// After processing the request keep reading for more requests
|
|
122 |
// from the host
|
|
123 |
ReadPacketL(this);
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
}
|