0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
#ifndef D32USBDI_H
|
|
17 |
#define D32USBDI_H
|
|
18 |
|
|
19 |
#ifdef __KERNEL_MODE__
|
|
20 |
#include <kernel/klib.h>
|
|
21 |
#else
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <d32usbdescriptors.h>
|
|
24 |
#endif
|
|
25 |
#include <e32ver.h>
|
|
26 |
#include <d32usbdi_errors.h>
|
|
27 |
|
|
28 |
/**
|
|
29 |
@file
|
|
30 |
@publishedPartner
|
|
31 |
@prototype
|
|
32 |
Intended to be available to 3rd parties later
|
|
33 |
*/
|
|
34 |
|
|
35 |
|
|
36 |
class RUsbPipe;
|
|
37 |
class RUsbTransferDescriptor;
|
|
38 |
class RUsbTransferStrategy;
|
|
39 |
|
|
40 |
typedef TUint32 TUsbBusId;
|
|
41 |
typedef void* TUsbBus; // handle for an os_bus
|
|
42 |
|
|
43 |
/**
|
|
44 |
Functions which act on a specific interface on a remote device.
|
|
45 |
*/
|
|
46 |
class RUsbInterface : public RBusLogicalChannel
|
|
47 |
{
|
|
48 |
public:
|
|
49 |
NONSHARABLE_CLASS(TUsbTransferRequestDetails)
|
|
50 |
{
|
|
51 |
public:
|
|
52 |
enum TEp0TransferFlags
|
|
53 |
{
|
|
54 |
EShortTransferOk = 0x04,
|
|
55 |
};
|
|
56 |
|
|
57 |
public:
|
|
58 |
TUint8 iRequestType;
|
|
59 |
TUint8 iRequest;
|
|
60 |
TUint16 iValue;
|
|
61 |
TUint16 iIndex;
|
|
62 |
TInt iFlags;
|
|
63 |
|
|
64 |
// Internal: these should not be set or used, however making them private
|
|
65 |
// would require the internal DUsbChannel class be exposed as a friend in
|
|
66 |
// userside
|
|
67 |
const TDesC8* iSend;
|
|
68 |
TDes8* iRecv;
|
|
69 |
};
|
|
70 |
|
|
71 |
NONSHARABLE_CLASS(TChunkRequestDetails)
|
|
72 |
{
|
|
73 |
public:
|
|
74 |
// In
|
|
75 |
TInt iRequestSize;
|
|
76 |
//Out
|
|
77 |
TInt* iChunkHandle;
|
|
78 |
TInt* iOffset;
|
|
79 |
};
|
|
80 |
|
|
81 |
NONSHARABLE_CLASS(TTransferMemoryDetails)
|
|
82 |
{
|
|
83 |
public:
|
|
84 |
TInt iType;
|
|
85 |
TUint iAlignment;
|
|
86 |
TInt iSize;
|
|
87 |
TInt iMaxPackets;
|
|
88 |
};
|
|
89 |
|
|
90 |
enum TDeviceSpeed
|
|
91 |
{
|
|
92 |
ELowSpeed,
|
|
93 |
EFullSpeed,
|
|
94 |
EHighSpeed
|
|
95 |
};
|
|
96 |
enum TUsbInterfaceRequest
|
|
97 |
{
|
|
98 |
ESuspend,
|
|
99 |
EEp0Transfer,
|
|
100 |
};
|
|
101 |
enum TUsbInterfaceControl
|
|
102 |
{
|
|
103 |
EOpenPipe,
|
|
104 |
EPermitRemoteWakeup,
|
|
105 |
EGetInterfaceDescriptorSize,
|
|
106 |
EGetInterfaceDescriptor,
|
|
107 |
EGetStringDescriptor,
|
|
108 |
ESelectAlternateInterface,
|
|
109 |
EAllocChunk,
|
|
110 |
EGetDeviceSpeed,
|
|
111 |
EGetBusId,
|
|
112 |
EHcdPageSize,
|
|
113 |
EGetSizeAndAlignment,
|
|
114 |
};
|
|
115 |
enum TUsbInterfaceCancel
|
|
116 |
{
|
|
117 |
ECancelSuspend = 0x00000001,
|
|
118 |
ECancelWaitForResume = 0x00000002,
|
|
119 |
ECancelEp0Transfer = 0x00000004
|
|
120 |
};
|
|
121 |
|
|
122 |
public:
|
|
123 |
inline static const TDesC& Name();
|
|
124 |
inline static TVersion VersionRequired();
|
|
125 |
|
|
126 |
#ifndef __KERNEL_MODE__
|
|
127 |
friend class RUsbPipe;
|
|
128 |
friend class RUsbZeroCopyTransferStrategy;
|
|
129 |
|
|
130 |
public:
|
|
131 |
inline RUsbInterface();
|
|
132 |
|
|
133 |
//
|
|
134 |
// Standard R-class lifetime controls
|
|
135 |
//
|
|
136 |
IMPORT_C TInt Open(TUint32 aToken, TOwnerType aType = EOwnerProcess);
|
|
137 |
IMPORT_C void Close();
|
|
138 |
|
|
139 |
//
|
|
140 |
// Transfer allocation/initialisation functions
|
|
141 |
//
|
|
142 |
IMPORT_C TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer);
|
|
143 |
IMPORT_C void ResetTransferDescriptors();
|
|
144 |
IMPORT_C TInt InitialiseTransferDescriptors();
|
|
145 |
|
|
146 |
//
|
|
147 |
// Endpoint Zero transfer utilities
|
|
148 |
//
|
|
149 |
inline void Ep0Transfer(TUsbTransferRequestDetails& aDetails, const TDesC8& aSend, TDes8& aRecv, TRequestStatus& aRequest);
|
|
150 |
inline void CancelEP0Transfer();
|
|
151 |
inline TInt GetStringDescriptor(TDes8& aStringDescriptor, TUint8 aIndex, TUint16 aLangId);
|
|
152 |
|
|
153 |
//
|
|
154 |
// Suspend/Resume functionality
|
|
155 |
//
|
|
156 |
inline void PermitSuspendAndWaitForResume(TRequestStatus& aResumeSignal);
|
|
157 |
inline void CancelPermitSuspend();
|
|
158 |
inline void CancelWaitForResume();
|
|
159 |
inline TInt PermitRemoteWakeup(TBool aPermitted);
|
|
160 |
|
|
161 |
|
|
162 |
//
|
|
163 |
// Descriptor access functions
|
|
164 |
//
|
|
165 |
inline TInt GetInterfaceDescriptor(TUsbInterfaceDescriptor& aDescriptor);
|
|
166 |
inline TInt GetAlternateInterfaceDescriptor(TInt aAlternateInterface, TUsbInterfaceDescriptor& aDescriptor);
|
|
167 |
inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor& aDescriptor);
|
|
168 |
|
|
169 |
// Utility functions to avoid having to parse the entire descriptor tree in simple cases.
|
|
170 |
inline TInt GetAlternateInterfaceCount();
|
|
171 |
inline TInt EnumerateEndpointsOnInterface(TInt aAlternateInterface);
|
|
172 |
|
|
173 |
//
|
|
174 |
// Interface configuration functions
|
|
175 |
//
|
|
176 |
inline TInt SelectAlternateInterface(TInt aAlternateInterface);
|
|
177 |
inline TInt OpenPipeForEndpoint(RUsbPipe& aPipe, TInt aEndpoint, TBool aUseDMA);
|
|
178 |
|
|
179 |
//
|
|
180 |
// Some utility functions
|
|
181 |
//
|
|
182 |
inline TInt GetBusId(TUsbBusId& aBusId);
|
|
183 |
inline TInt HcdPageSize();
|
|
184 |
inline TInt GetDeviceSpeed(TDeviceSpeed& aDeviceSpeed);
|
|
185 |
|
|
186 |
private:
|
|
187 |
inline TInt AllocateSharedChunk(RChunk& aChunk, TInt aSize, TInt& aOffset);
|
|
188 |
TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer, TUsbBusId aBusId);
|
|
189 |
inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor*& aDescriptor);
|
|
190 |
|
|
191 |
private:
|
|
192 |
TUsbInterfaceDescriptor* iHeadInterfaceDescriptor;
|
|
193 |
HBufC8* iInterfaceDescriptorData;
|
|
194 |
|
|
195 |
RUsbTransferStrategy* iTransferStrategy;
|
|
196 |
|
|
197 |
TInt iAlternateSetting;
|
|
198 |
#endif
|
|
199 |
};
|
|
200 |
|
|
201 |
typedef TUint64 TUsbEndpointId;
|
|
202 |
|
|
203 |
/**
|
|
204 |
Functions which act on an individual pipe established between the local host and a remote device.
|
|
205 |
*/
|
|
206 |
class RUsbPipe
|
|
207 |
{
|
|
208 |
public:
|
|
209 |
enum TUsbPipeRequest
|
|
210 |
{
|
|
211 |
EIssueTransfer = 0x4000000, // Start from a different value compared to interfaces
|
|
212 |
// to allow them to be distinguished while debugging
|
|
213 |
};
|
|
214 |
enum TUsbPipeControl
|
|
215 |
{
|
|
216 |
EClose = 0x4000000, // Start from a different value compared to interfaces
|
|
217 |
// to allow them to be distinguished while debugging
|
|
218 |
EAbort,
|
|
219 |
EClearRemoteStall,
|
|
220 |
EGetEndpointId,
|
|
221 |
};
|
|
222 |
|
|
223 |
#ifndef __KERNEL_MODE__
|
|
224 |
friend class RUsbInterface;
|
|
225 |
friend class RUsbTransferStrategy;
|
|
226 |
friend class RUsbZeroCopyTransferStrategy;
|
|
227 |
public:
|
|
228 |
inline RUsbPipe();
|
|
229 |
|
|
230 |
inline void Close();
|
|
231 |
inline TUint32 Handle() const;
|
|
232 |
|
|
233 |
inline TInt GetEndpointId(TUsbEndpointId& aEndpointId);
|
|
234 |
inline TInt GetBusId(TUsbBusId& aBusId);
|
|
235 |
|
|
236 |
inline TInt GetEndpointDescriptor(TUsbEndpointDescriptor& aDescriptor);
|
|
237 |
|
|
238 |
IMPORT_C void Transfer(RUsbTransferDescriptor& aTransfer, TRequestStatus& aRequest);
|
|
239 |
inline void CancelAllTransfers();
|
|
240 |
|
|
241 |
inline TInt ClearRemoteStall();
|
|
242 |
|
|
243 |
private:
|
|
244 |
inline void IssueTransfer(TInt aTransferHandle, TRequestStatus& aRequest);
|
|
245 |
|
|
246 |
private:
|
|
247 |
TUint32 iHandle;
|
|
248 |
RUsbInterface* iInterface;
|
|
249 |
TUsbEndpointDescriptor* iHeadEndpointDescriptor;
|
|
250 |
#endif
|
|
251 |
};
|
|
252 |
|
|
253 |
|
|
254 |
#include <d32usbdi.inl>
|
|
255 |
|
|
256 |
#endif // D32USBDI_H
|