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