Main MRPT website > C++ reference for MRPT 1.5.9
xswinusb.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifdef _WIN32 // patch for MRPT
10 
11 #include "xswinusb.h"
12 #include <xslibraryloader.h>
13 
14 /*! \class XsWinUsb
15  \brief Class for dynamic loading of winusb
16 */
18 {
20  initLibrary();
21 }
22 
24 {
25  delete m_libraryLoader;
26 }
27 
29 {
30  if (!m_libraryLoader->isLoaded())
31  m_libraryLoader->load("winusb.dll");
32 
33  m_winUsb.AbortPipe = NULL;
34  m_winUsb.Initialize = NULL;
35  m_winUsb.Free = NULL;
37  m_winUsb.GetDescriptor = NULL;
42  m_winUsb.QueryPipe = NULL;
43  m_winUsb.SetPipePolicy = NULL;
44  m_winUsb.GetPipePolicy = NULL;
45  m_winUsb.ReadPipe = NULL;
46  m_winUsb.WritePipe = NULL;
48  m_winUsb.ResetPipe = NULL;
49  m_winUsb.AbortPipe = NULL;
50  m_winUsb.FlushPipe = NULL;
51  m_winUsb.SetPowerPolicy = NULL;
52  m_winUsb.GetPowerPolicy = NULL;
54 
55  if (m_libraryLoader->isLoaded())
56  {
57  m_winUsb.AbortPipe = (WinUSB_AbortPipe*)m_libraryLoader->resolve("WinUsb_AbortPipe");
58  m_winUsb.Initialize = (WinUSB_Initialize*)m_libraryLoader->resolve("WinUsb_Initialize");
59  m_winUsb.Free = (WinUSB_Free*)m_libraryLoader->resolve("WinUsb_Free");
60  m_winUsb.GetAssociatedInterface = (WinUSB_GetAssociatedInterface*)m_libraryLoader->resolve("WinUsb_GetAssociatedInterface");
61  m_winUsb.GetDescriptor = (WinUSB_GetDescriptor*)m_libraryLoader->resolve("WinUsb_GetDescriptor");
62  m_winUsb.QueryInterfaceSettings = (WinUSB_QueryInterfaceSettings*)m_libraryLoader->resolve("WinUsb_QueryInterfaceSettings");
63  m_winUsb.QueryDeviceInformation = (WinUSB_QueryDeviceInformation*)m_libraryLoader->resolve("WinUsb_QueryDeviceInformation");
64  m_winUsb.SetCurrentAlternateSetting = (WinUSB_SetCurrentAlternateSetting*)m_libraryLoader->resolve("WinUsb_SetCurrentAlternateSetting");
65  m_winUsb.GetCurrentAlternateSetting = (WinUSB_GetCurrentAlternateSetting*)m_libraryLoader->resolve("WinUsb_GetCurrentAlternateSetting");
66  m_winUsb.QueryPipe = (WinUSB_QueryPipe*)m_libraryLoader->resolve("WinUsb_QueryPipe");
67  m_winUsb.SetPipePolicy = (WinUSB_SetPipePolicy*)m_libraryLoader->resolve("WinUsb_SetPipePolicy");
68  m_winUsb.GetPipePolicy = (WinUSB_GetPipePolicy*)m_libraryLoader->resolve("WinUsb_GetPipePolicy");
69  m_winUsb.ReadPipe = (WinUSB_ReadPipe*)m_libraryLoader->resolve("WinUsb_ReadPipe");
70  m_winUsb.WritePipe = (WinUSB_WritePipe*)m_libraryLoader->resolve("WinUsb_WritePipe");
71  m_winUsb.ControlTransfer = (WinUSB_ControlTransfer*)m_libraryLoader->resolve("WinUsb_ControlTransfer");
72  m_winUsb.ResetPipe = (WinUSB_ResetPipe*)m_libraryLoader->resolve("WinUsb_ResetPipe");
73  m_winUsb.AbortPipe = (WinUSB_AbortPipe*)m_libraryLoader->resolve("WinUsb_AbortPipe");
74  m_winUsb.FlushPipe = (WinUSB_FlushPipe*)m_libraryLoader->resolve("WinUsb_FlushPipe");
75  m_winUsb.SetPowerPolicy = (WinUSB_SetPowerPolicy*)m_libraryLoader->resolve("WinUsb_SetPowerPolicy");
76  m_winUsb.GetPowerPolicy = (WinUSB_GetPowerPolicy*)m_libraryLoader->resolve("WinUsb_GetPowerPolicy");
77  m_winUsb.GetOverlappedResult = (WinUSB_GetOverlappedResult*)m_libraryLoader->resolve("WinUsb_GetOverlappedResult");
78  }
79 }
80 
81 /*! \brief Creates/opens a WinUsb interface handle from the device list.
82 
83  \param[out] InterfaceHandle Receives a handle configured to the first (default) interface on the device. This handle is required by other WinUsb routines that perform operations on the default interface. The handle is opaque. To release this handle, call the \a Free function.
84  \param[in] DevInfo The device list element to open.
85 
86  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
87 */
88 BOOL XsWinUsb::Initialize(HANDLE DeviceHandle, PWINUSB_INTERFACE_HANDLE InterfaceHandle)
89 {
90  if (m_winUsb.Initialize)
91  return m_winUsb.Initialize(DeviceHandle, InterfaceHandle);
92  else
93  return FALSE;
94 }
95 
96 /*! \brief Frees a WinUsb interface handle.
97  \param[in] InterfaceHandle Handle to an interface on the device. This handle must be created by a previous call to see \a Initialize or \a GetAssociatedInterface.
98 
99  \returns TRUE
100 
101  \sa GetAssociatedInterface.
102 */
103 BOOL XsWinUsb::Free(WINUSB_INTERFACE_HANDLE InterfaceHandle)
104 {
105  if (m_winUsb.Free)
106  return m_winUsb.Free(InterfaceHandle);
107  else
108  return FALSE;
109 }
110 
111 /*! \brief Retrieves a handle for an associated interface.
112  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
113  \param[in] AssociatedInterfaceIndex An index that specifies the associated interface to retrieve. A value of 0 indicates the first associated interface, a value of 1 indicates the second associated interface, and so on.
114  \param[out] AssociatedInterfaceHandle A handle for the associated interface. Callers must pass this interface handle to WinUsb Functions exposed by WinUsb.dll. To close this handle, call Free.
115 
116  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
117 */
118 BOOL XsWinUsb::GetAssociatedInterface(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR AssociatedInterfaceIndex, PWINUSB_INTERFACE_HANDLE AssociatedInterfaceHandle)
119 {
121  return m_winUsb.GetAssociatedInterface(InterfaceHandle, AssociatedInterfaceIndex, AssociatedInterfaceHandle);
122  else
123  return FALSE;
124 }
125 
126 /*! \brief Gets the requested descriptor. This is a synchronous operation.
127  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
128  \param[in] DescriptorType A value that specifies the type of descriptor to return. This parameter corresponds to the bDescriptorType field of a standard device descriptor, whose values are described in the Universal Serial Bus specification.
129  \param[in] Index The descriptor index. For an explanation of the descriptor index, see the Universal Serial Bus specification (www.usb.org).
130  \param[in] LanguageID A value that specifies the language identifier, if the requested descriptor is a string descriptor.
131  \param[out] Buffer A caller-allocated buffer that receives the requested descriptor.
132  \param[in] BufferLength The length, in bytes, of Buffer.
133  \param[out] LengthTransferred The number of bytes that were copied into Buffer.
134 
135  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
136 */
137 BOOL XsWinUsb::GetDescriptor(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR DescriptorType, UCHAR Index,USHORT LanguageID,PUCHAR Buffer,ULONG BufferLength,PULONG LengthTransferred)
138 {
140  return m_winUsb.GetDescriptor(InterfaceHandle, DescriptorType, Index, LanguageID, Buffer, BufferLength, LengthTransferred);
141  else
142  return FALSE;
143 }
144 
145 /*! \brief Retrieves the interface descriptor for the specified alternate interface settings for a particular interface handle.
146 
147  The \a QueryInterfaceSettings call searches the current/default interface array for the alternate interface specified by the caller in the \a AltSettingIndex.
148  If the specified alternate interface is found, the function populates the caller-allocated USB_INTERFACE_DESCRIPTOR structure.
149  If the specified alternate interface is not found, then the call fails with the ERROR_NO_MORE_ITEMS code.
150 
151  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
152  \param[in] AltSettingIndex A value that indicates which alternate setting index to return. A value of 0 indicates the first alternate setting, a value of 1 indicates the second alternate setting, and so on.
153  \param[out] UsbAltInterfaceDescriptor A pointer to a caller-allocated USB_INTERFACE_DESCRIPTOR structure that contains information about the interface that AltSettingNumber specified.
154 
155  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
156 */
157 BOOL XsWinUsb::QueryInterfaceSettings(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR AlternateInterfaceNumber,PUSB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor)
158 {
160  return m_winUsb.QueryInterfaceSettings(InterfaceHandle, AlternateInterfaceNumber, UsbAltInterfaceDescriptor);
161  else
162  return FALSE;
163 }
164 
165 /*! \brief Retrieves information about the physical device that is associated with a WinUSB handle.
166  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
167  \param[in] InformationType A value that specifies which interface information value to retrieve. On input, InformationType must have the following value: DEVICE_SPEED (0x01).
168  \param[in,out] BufferLength The maximum number of bytes to read. This number must be less than or equal to the size, in bytes, of Buffer. On output, BufferLength is set to the actual number of bytes that were copied into Buffer.
169  \param[in,out] Buffer A caller-allocated buffer that receives the requested value. On output, Buffer indicates the device speed:
170  (0x01) low/full speed device.
171  (0x03) high speed device.
172 
173  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
174 */
175 BOOL XsWinUsb::QueryDeviceInformation(WINUSB_INTERFACE_HANDLE InterfaceHandle,ULONG InformationType,PULONG BufferLength,PVOID Buffer)
176 {
178  return m_winUsb.QueryDeviceInformation(InterfaceHandle, InformationType, BufferLength, Buffer);
179  else
180  return FALSE;
181 }
182 
183 /*! \brief Sets the alternate setting of an interface.
184  Sets the active \a bAlternateSetting for the current/default interface.
185 
186  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
187  \param[in] AltSettingNumber The value that is contained in the \a bAlternateSetting member of the USB_INTERFACE_DESCRIPTOR structure. This structure can be populated by the \a QueryInterfaceSettings routine.
188 
189  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
190 
191  \sa QueryInterfaceSettings
192 */
193 BOOL XsWinUsb::SetCurrentAlternateSetting(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR SettingNumber)
194 {
196  return m_winUsb.SetCurrentAlternateSetting(InterfaceHandle, SettingNumber);
197  else
198  return FALSE;
199 }
200 
201 /*! \brief Gets the current alternate interface setting for an interface.
202  Gets the active bAlternateSetting for the current/default interface.
203 
204  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
205  \param[out] AltSettingNumber A pointer to an unsigned character that receives an integer that indicates the current alternate setting.
206 
207  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
208 */
209 BOOL XsWinUsb::GetCurrentAlternateSetting(WINUSB_INTERFACE_HANDLE InterfaceHandle,PUCHAR SettingNumber)
210 {
212  return m_winUsb.GetCurrentAlternateSetting(InterfaceHandle, SettingNumber);
213  else
214  return FALSE;
215 }
216 
217 /*! \brief Retrieves information about a pipe that is associated with an interface.
218  The \a QueryPipe function does not retrieve information about the control pipe.
219 
220  Each interface on the USB device can have multiple endpoints. To communicate with each of these endpoints, the bus driver creates pipes for each endpoint on the interface.
221  The pipe indices are zero-based. Therefore for n number of endpoints, the pipes' indices are set from n-1.
222  \a QueryPipe parses the configuration descriptor to get the interface specified by the caller.
223  It searches the interface descriptor for the endpoint descriptor associated with the caller-specified pipe.
224  If the endpoint is found, the function populates the caller-allocated WINUSB_PIPE_INFORMATION structure with information from the endpoint descriptor.
225 
226  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
227  \param[in] AltSettingNumber A value that specifies the alternate interface to return the information for.
228  \param[in] PipeIndex A value that specifies the pipe to return information about. This value is not the same as the bEndpointAddress field in the endpoint descriptor.
229  A PipeIndex value of 0 signifies the first endpoint that is associated with the interface, a value of 1 signifies the second endpoint, and so on.
230  PipeIndex must be less than the value in the bNumEndpoints field of the interface descriptor.
231  \param[out] PipeInformation A pointer, on output, to a caller-allocated WINUSB_PIPE_INFORMATION structure that contains pipe information.
232 
233  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
234 */
235 BOOL XsWinUsb::QueryPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR AlternateInterfaceNumber,UCHAR PipeIndex,PWINUSB_PIPE_INFORMATION PipeInformation)
236 {
237  if (m_winUsb.QueryPipe)
238  return m_winUsb.QueryPipe(InterfaceHandle, AlternateInterfaceNumber, PipeIndex, PipeInformation);
239  else
240  return FALSE;
241 }
242 
243 /*! \brief Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous operation.
244  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
245  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
246  \param[in] PolicyType A UINT variable that specifies the policy parameter to change. The Value parameter contains the new value for the policy parameter.
247  See the remarks section for information about each of the pipe policies and the resulting behavior.
248  \param[in] ValueLength The size, in bytes, of the buffer at Value.
249  \param[in] Value The new value for the policy parameter that PolicyType specifies. The size of this input parameter depends on the policy to change. For information about the size of this parameter, see the description of the PolicyType parameter.
250 
251  \remarks
252  The following list describes symbolic constants for \a PolicyType
253 
254  - SHORT_PACKET_TERMINATE (0x01)
255  - The default value is FALSE.
256  - To enable SHORT_PACKET_TERMINATE, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
257  - Enabling SHORT_PACKET_TERMINATE causes the driver to send a zero-length packet at the end of every write request to the host controller.
258 
259  - AUTO_CLEAR_STALL (0x02)
260  - The default value is FALSE. To enable AUTO_CLEAR_STALL, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
261  - Enabling AUTO_CLEAR_STALL causes winUSB to reset the pipe in order to automatically clear the stall condition. Data continues to flow on the bulk and interrupt IN endpoints again as soon as a new or a queued transfer arrives on the endpoint. This policy parameter does not affect control pipes.
262  - Disabling AUTO_CLEAR_STALL causes all transfers (that arrive to the endpoint after the stalled transfer) to fail until the caller manually resets the endpoint's pipe by calling ResetPipe.
263 
264  - PIPE_TRANSFER_TIMEOUT (0x03)
265  - The default value is zero. To set a time-out value, in Value pass the address of a caller-allocated UINT variable that contains the time-out interval.
266  - The PIPE_TRANSFER_TIMEOUT value specifies the time-out interval, in milliseconds. The host controller cancels transfers that do not complete within the specified time-out interval.
267  - A value of zero (default) indicates that transfers do not time out because the host controller never cancels the transfer.
268 
269  - IGNORE_SHORT_PACKETS (0x04)
270  - The default value is FALSE. To enable IGNORE_SHORT_PACKETS, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
271  - Enabling IGNORE_SHORT_PACKETS causes the host controller to not complete a read operation after it receives a short packet. Instead, the host controller completes the operation only after the host has read the specified number of bytes.
272  - Disabling IGNORE_SHORT_PACKETS causes the host controller to complete a read operation when either the host has read the specified number of bytes or the host has received a short packet.
273 
274  - ALLOW_PARTIAL_READS (0x05)
275  - The default value is TRUE (nonzero). To disable ALLOW_PARTIAL_READS, in Value pass the address of a caller-allocated UCHAR variable set to FALSE (zero).
276  - Disabling ALLOW_PARTIAL_READS causes the read requests to fail whenever the device returns more data (on bulk and interrupt IN endpoints) than the caller requested.
277  - Enabling ALLOW_PARTIAL_READS causes winUSB to save or discard the extra data when the device returns more data (on bulk and interrupt IN endpoints) than the caller requested. This behavior is defined by setting the AUTO_FLUSH value.
278 
279  - AUTO_FLUSH (0x06)
280  - The default value is FALSE (zero). To enable AUTO_FLUSH, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
281  - AUTO_FLUSH must be used with ALLOW_PARTIAL_READS enabled. If ALLOW_PARTIAL_READS is TRUE, the value of AUTO_FLUSH determines the action taken by winUSB when the device returns more data than the caller requested.
282  - Disabling ALLOW_PARTIAL_READS causes winUSB to ignore the AUTO_FLUSH value.
283  - Disabling AUTO_FLUSH with ALLOW_PARTIAL_READS enabled causes winUSB to save the extra data, add the data to the beginning of the caller's next read request, and send it to the caller in the next read operation.
284  - Enabling AUTO_FLUSH with ALLOW_PARTIAL_READS enabled causes winUSB to discard the extra data remaining from the read request.
285 
286  - RAW_IO (0x07)
287  - The default value is FALSE (zero). To enable RAW_IO, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
288  - Enabling RAW_IO causes winUSB to send data directly to the USB driver stack, bypassing winUSB's queuing and error handling mechanism.
289  - The buffers that are passed to \a ReadPipe must be configured by the caller as follows:
290  - The buffer length must be a multiple of the maximum endpoint packet size.
291  - The length must be less than or equal to the value of MAXIMUM_TRANSFER_SIZE retrieved by GetPipePolicy.
292  - Disabling RAW_IO (FALSE) does not impose any restriction on the buffers that are passed to \a ReadPipe.
293 
294  - RESET_PIPE_ON_RESUME (0x09)
295  - The default value is FALSE (zero). To enable RESET_PIPE_ON_RESUME, in Value pass the address of a caller-allocated UCHAR variable set to TRUE (nonzero).
296  - TRUE (or a nonzero value) indicates that on resume from suspend, winUSB resets the endpoint before it allows the caller to send new requests to the endpoint.
297 
298 
299  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
300 */
301 BOOL XsWinUsb::SetPipePolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID,ULONG PolicyType,ULONG ValueLength,PVOID Value)
302 {
304  return m_winUsb.SetPipePolicy(InterfaceHandle, PipeID, PolicyType, ValueLength, Value);
305  else
306  return FALSE;
307 }
308 
309 /*! \brief Gets the policy for a specific pipe (endpoint).
310  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
311  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
312  \param[in] PolicyType A UINT variable that specifies the policy parameter to retrieve. The current value for the policy parameter is retrieved the Value parameter.
313  \param[in,out] ValueLength A pointer to the size, in bytes, of the buffer that Value points to. On output, ValueLength receives the size, in bytes, of the data that was copied into the Value buffer.
314  \param[out] Value A pointer to a buffer that receives the specified pipe policy value.
315 
316  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
317 */
318 BOOL XsWinUsb::GetPipePolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID,ULONG PolicyType,PULONG ValueLength,PVOID Value)
319 {
321  return m_winUsb.GetPipePolicy(InterfaceHandle, PipeID, PolicyType, ValueLength, Value);
322  else
323  return FALSE;
324 }
325 
326 /*! \brief Reads data from the specified pipe.
327  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
328  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
329  \param[out] Buffer A caller-allocated buffer that receives the data that is read.
330  \param[in] BufferLength The maximum number of bytes to read. This number must be less than or equal to the size, in bytes, of Buffer.
331  \param[out] LengthTransferred A pointer to a UINT variable that receives the actual number of bytes that were copied into Buffer. For more information, see Remarks.
332  \param[in] Overlapped An optional pointer to an overlapped structure for asynchronous operations. This can be a KOVL_HANDLE or a pointer to a standard windows OVERLAPPED structure.
333  If this parameter is specified, \a ReadPipe returns immediately rather than waiting synchronously for the operation to complete before returning. An event is signaled when the operation is complete.
334 
335  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
336 */
337 BOOL XsWinUsb::ReadPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID,PUCHAR Buffer,ULONG BufferLength,PULONG LengthTransferred,LPOVERLAPPED Overlapped)
338 {
339  if (m_winUsb.ReadPipe)
340  return m_winUsb.ReadPipe(InterfaceHandle, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped);
341  else
342  return FALSE;
343 }
344 
345 /*! \brief Writes data to a pipe.
346  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
347  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
348  \param[in] Buffer A caller-allocated buffer the data is written from.
349  \param[in] BufferLength The maximum number of bytes to write. This number must be less than or equal to the size, in bytes, of Buffer.
350  \param[out] LengthTransferred A pointer to a UINT variable that receives the actual number of bytes that were transferred from Buffer.
351  \param[in] Overlapped An optional pointer to an overlapped structure for asynchronous operations. This can be a KOVL_HANDLE or a pointer to a standard windows OVERLAPPED structure.
352  If this parameter is specified, \a WritePipe returns immediately rather than waiting synchronously for the operation to complete before returning. An event is signaled when the operation is complete.
353 
354  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
355 */
356 BOOL XsWinUsb::WritePipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID,PUCHAR Buffer,ULONG BufferLength,PULONG LengthTransferred,LPOVERLAPPED Overlapped)
357 {
358  if (m_winUsb.WritePipe)
359  return m_winUsb.WritePipe(InterfaceHandle, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped);
360  else
361  return FALSE;
362 }
363 
364 /*! \brief Transmits control data over a default control endpoint.
365  A ControlTransfer is never cached. These requests always go directly to the usb device.
366 
367  \param[in] InterfaceHandle A valid winUSB interface handle returned by:
368  - Initialize
369  - GetAssociatedInterface
370  \param[in] SetupPacket The 8-byte setup packet of type WINUSB_SETUP_PACKET.
371  \param[in,out] Buffer A caller-allocated buffer that contains the data to transfer.
372  \param[in] BufferLength The number of bytes to transfer, not including the setup packet. This number must be less than or equal to the size, in bytes, of Buffer.
373  \param[out] LengthTransferred A pointer to a UINT variable that receives the actual number of transferred bytes. If the application does not expect any data to be transferred during the data phase (BufferLength is zero), LengthTransferred can be NULL.
374  \param[in] Overlapped An optional pointer to an OVERLAPPED structure, which is used for asynchronous operations. If this parameter is specified, ControlTransfer immediately returns, and the event is signaled when the operation is complete. If Overlapped is not supplied, the ControlTransfer function transfers data synchronously.
375 
376  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information. If an Overlapped member is supplied and the operation succeeds this function returns FALSE and sets last error to ERROR_IO_PENDING.
377 */
378 BOOL XsWinUsb::ControlTransfer(WINUSB_INTERFACE_HANDLE InterfaceHandle,WINUSB_SETUP_PACKET SetupPacket,PUCHAR Buffer,ULONG BufferLength,PULONG LengthTransferred,LPOVERLAPPED Overlapped)
379 {
381  return m_winUsb.ControlTransfer(InterfaceHandle, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped);
382  else
383  return FALSE;
384 }
385 
386 /*! \brief Resets the data toggle and clears the stall condition on a pipe.
387  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
388  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the \a bEndpointAddress field in the endpoint descriptor.
389 
390  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
391 */
392 BOOL XsWinUsb::ResetPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID)
393 {
394  if (m_winUsb.ResetPipe)
395  return m_winUsb.ResetPipe(InterfaceHandle, PipeID);
396  else
397  return FALSE;
398 }
399 
400 /*! \brief Aborts all of the pending transfers for a pipe.
401  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
402  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the \a bEndpointAddress field in the endpoint descriptor.
403 
404  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
405 */
406 BOOL XsWinUsb::AbortPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID)
407 {
408  if (m_winUsb.AbortPipe)
409  return m_winUsb.AbortPipe(InterfaceHandle, PipeID);
410  else
411  return FALSE;
412 }
413 
414 /*! \brief Discards any data that is cached in a pipe.
415  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
416  \param[in] PipeID An 8-bit value that consists of a 7-bit address and a direction bit. This parameter corresponds to the \a bEndpointAddress field in the endpoint descriptor.
417 
418  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
419 */
420 BOOL XsWinUsb::FlushPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle,UCHAR PipeID)
421 {
422  if (m_winUsb.FlushPipe)
423  return m_winUsb.FlushPipe(InterfaceHandle, PipeID);
424  else
425  return FALSE;
426 }
427 
428 /*! \brief Sets the power policy for a device.
429  The following list summarizes the effects of changes to power management states:
430 
431  - All pipe handles, interface handles, locks, and alternate settings are preserved across power management events.
432  - Any transfers that are in progress are suspended when a device transfers to a low power state, and they are resumed when the device is restored to a working state.
433  - The device and system must be in a working state before the client can restore a device-specific configuration. Clients can determine whether the device and system are in a working state from the WM_POWERBROADCAST message.
434  - The client can indicate that an interface is idle by calling \a SetPowerPolicy.
435 
436  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize.
437  \param[in] PolicyType A value that specifies the power policy to set. The following table describes symbolic constants.
438  - AUTO_SUSPEND (0x81)
439  - Specifies the auto-suspend policy type; the power policy parameter must be specified by the caller in the Value parameter.
440  - For auto-suspend, the Value parameter must point to a UCHAR variable.
441  - If Value is TRUE (nonzero), the USB stack suspends the device if the device is idle. A device is idle if there are no transfers pending, or if the only pending transfers are IN transfers to interrupt or bulk endpoints.
442  - The default value is determined by the value set in the DefaultIdleState registry setting. By default, this value is TRUE.
443 
444  - SUSPEND_DELAY (0x83)
445  - Specifies the suspend-delay policy type; the power policy parameter must be specified by the caller in the Value parameter.
446  - For suspend-delay, Value must point to a UINT variable.
447  - Value specifies the minimum amount of time, in milliseconds, that the driver must wait post transfer before it can suspend the device.
448  - The default value is determined by the value set in the DefaultIdleTimeout registry setting. By default, this value is five seconds.
449 
450  \param[in] ValueLength The size, in bytes, of the buffer at Value.
451  \param[in] Value The new value for the power policy parameter. Data type and value for Value depends on the type of power policy passed in PolicyType. For more information, see PolicyType.
452 
453  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
454 */
455 BOOL XsWinUsb::SetPowerPolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle,ULONG PolicyType,ULONG ValueLength,PVOID Value)
456 {
458  return m_winUsb.SetPowerPolicy(InterfaceHandle, PolicyType, ValueLength, Value);
459  else
460  return FALSE;
461 }
462 
463 /*! \brief Gets the power policy for a device.
464  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize
465  \param[in] PolicyType A value that specifies the power policy parameter to retrieve in Value. The following table describes symbolic constants that are valid.
466  - AUTO_SUSPEND (0x81)
467  - If the caller specifies a power policy of AUTO_SUSPEND, \a GetPowerPolicy returns the value of the auto suspend policy parameter in the Value parameter.
468  - If Value is TRUE (that is, nonzero), the USB stack suspends the device when no transfers are pending or the only transfers pending are IN transfers on an interrupt or bulk endpoint.
469  - The value of the DefaultIdleState registry value determines the default value of the auto suspend policy parameter.
470  - The Value parameter must point to a UCHAR variable.
471 
472  - SUSPEND_DELAY (0x83)
473  - If the caller specifies a power policy of SUSPEND_DELAY, \a GetPowerPolicy returns the value of the suspend delay policy parameter in Value.
474  - The suspend delay policy parameter specifies the minimum amount of time, in milliseconds, that the driver must wait after any transfer before it can suspend the device.
475  - Value must point to a UINT variable.
476 
477  \param[in,out] ValueLength A pointer to the size of the buffer that Value. On output, ValueLength receives the size of the data that was copied into the Value buffer.
478  \param[out] Value A buffer that receives the specified power policy parameter. For more information, see PolicyType.
479 
480  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
481 */
482 BOOL XsWinUsb::GetPowerPolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle,ULONG PolicyType,PULONG ValueLength,PVOID Value)
483 {
485  return m_winUsb.GetPowerPolicy(InterfaceHandle, PolicyType, ValueLength, Value);
486  else
487  return FALSE;
488 }
489 
490 /*! \brief Retrieves the results of an overlapped operation on the specified winUSB handle.
491 
492  This function is like the Win32 API routine, GetOverlappedResult, with one difference; instead of passing a file handle that is returned from CreateFile, the caller passes an interface handle that is returned from \a Initialize, or \a GetAssociatedInterface. The caller can use either API routine, if the appropriate handle is passed. The \a GetOverlappedResult function extracts the file handle from the interface handle and then calls GetOverlappedResult.
493  The results that are reported by the GetOverlappedResult function are those from the specified handle's last overlapped operation to which the specified standard windows OVERLAPPED structure was provided, and for which the operation's results were pending. A pending operation is indicated when the function that started the operation returns FALSE, and the GetLastError routine returns ERROR_IO_PENDING. When an I/O operation is pending, the function that started the operation resets the hEvent member of the standard windows OVERLAPPED structure to the nonsignaled state. Then when the pending operation has been completed, the system sets the event object to the signaled state.
494  The caller can specify that an event object is manually reset in the standard windows OVERLAPPED structure. If an automatic reset event object is used, the event handle must not be specified in any other wait operation in the interval between starting the overlapped operation and the call to \a GetOverlappedResult. For example, the event object is sometimes specified in one of the wait routines to wait for the operation to be completed. When the wait routine returns, the system sets an auto-reset event's state to nonsignaled, and a successive call to \a GetOverlappedResult with the bWait parameter set to TRUE causes the function to be blocked indefinitely.
495  If the bWait parameter is TRUE, GetOverlappedResult determines whether the pending operation has been completed by waiting for the event object to be in the signaled state.
496 
497  If the hEvent member of the standard windows OVERLAPPED structure is NULL, the system uses the state of the file handle to signal when the operation has been completed. Do not use file handles for this purpose. It is better to use an event object because of the confusion that can occur when multiple concurrent overlapped operations are performed on the same file. In this situation, you cannot know which operation caused the state of the object to be signaled.
498 
499  \param[in] InterfaceHandle An initialized usb handle, see \a Initialize
500  \param[in] Overlapped A pointer to a standard windows OVERLAPPED structure that was specified when the overlapped operation was started.
501  \param[out] lpNumberOfBytesTransferred A pointer to a variable that receives the number of bytes that were actually transferred by a read or write operation.
502  \param[in] bWait If this parameter is TRUE, the function does not return until the operation has been completed. If this parameter is FALSE and the operation is still pending, the function returns FALSE and the GetLastError function returns ERROR_IO_INCOMPLETE.
503 
504  \returns On success, TRUE. Otherwise FALSE. Use GetLastError() to get extended error information.
505 */
506 BOOL XsWinUsb::GetOverlappedResult(WINUSB_INTERFACE_HANDLE InterfaceHandle,LPOVERLAPPED lpOverlapped,LPDWORD lpNumberOfBytesTransferred,BOOL bWait)
507 {
509  return m_winUsb.GetOverlappedResult(InterfaceHandle, lpOverlapped, lpNumberOfBytesTransferred, bWait);
510  else
511  return FALSE;
512 }
513 
514 #endif // patch for MRPT
BOOL __stdcall WinUSB_ResetPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID)
BOOL __stdcall WinUSB_GetPipePolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID, ULONG PolicyType, PULONG ValueLength, PVOID Value)
BOOL __stdcall WinUSB_GetCurrentAlternateSetting(WINUSB_INTERFACE_HANDLE InterfaceHandle, PUCHAR AltSettingNumber)
WinUSB_SetPipePolicy * SetPipePolicy
WinUSB_Free Free
Frees a WinUsb interface handle.
WinUSB_AbortPipe AbortPipe
Aborts all of the pending transfers for a pipe.
BOOL __stdcall WinUSB_GetAssociatedInterface(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR AssociatedInterfaceIndex, WINUSB_INTERFACE_HANDLE *AssociatedInterfaceHandle)
WinUSB_GetPipePolicy GetPipePolicy
Gets the policy for a specific pipe (endpoint).
WINUSB_API m_winUsb
WinUSB_GetAssociatedInterface * GetAssociatedInterface
BOOL __stdcall WinUSB_GetOverlappedResult(WINUSB_INTERFACE_HANDLE InterfaceHandle, LPOVERLAPPED Overlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
struct XsLibraryLoader XsLibraryLoader
XsLibraryLoader * m_libraryLoader
WinUSB_QueryPipe QueryPipe
Retrieves information about a pipe that is associated with an interface. The QueryPipe function does ...
WinUSB_SetCurrentAlternateSetting SetCurrentAlternateSetting
Sets the alternate setting of an interface. Sets the active bAlternateSetting for the current/default...
WinUSB_Initialize * Initialize
BOOL __stdcall WinUSB_Initialize(HANDLE DeviceHandle, WINUSB_INTERFACE_HANDLE *InterfaceHandle)
WinUSB_GetPowerPolicy GetPowerPolicy
Gets the power policy for a device.
WinUSB_GetDescriptor * GetDescriptor
int BOOL
Definition: xstypedefs.h:62
WinUSB_GetPowerPolicy * GetPowerPolicy
XsWinUsb(void)
Definition: xswinusb.cpp:17
BOOL __stdcall WinUSB_GetDescriptor(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR DescriptorType, UCHAR Index, USHORT LanguageID, PUCHAR Buffer, ULONG BufferLength, PULONG LengthTransferred)
WinUSB_SetCurrentAlternateSetting * SetCurrentAlternateSetting
BOOL __stdcall WinUSB_ReadPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID, PUCHAR Buffer, ULONG BufferLength, PULONG LengthTransferred, LPOVERLAPPED Overlapped)
BOOL __stdcall WinUSB_SetPowerPolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle, ULONG PolicyType, ULONG ValueLength, PVOID Value)
WinUSB_ReadPipe ReadPipe
Reads data from the specified pipe.
BOOL __stdcall WinUSB_FlushPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID)
BOOL __stdcall WinUSB_ControlTransfer(WINUSB_INTERFACE_HANDLE InterfaceHandle, WINUSB_SETUP_PACKET SetupPacket, PUCHAR Buffer, ULONG BufferLength, PULONG LengthTransferred, LPOVERLAPPED Overlapped)
BOOL __stdcall WinUSB_QueryInterfaceSettings(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR AltSettingIndex, PUSB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor)
WinUSB_Initialize Initialize
Creates/opens a WinUsb interface handle from the device list.
#define FALSE
Definition: jmorecfg.h:227
WinUSB_ResetPipe ResetPipe
Resets the data toggle and clears the stall condition on a pipe.
WinUSB_AbortPipe * AbortPipe
WinUSB_GetCurrentAlternateSetting * GetCurrentAlternateSetting
~XsWinUsb(void)
Definition: xswinusb.cpp:23
BOOL __stdcall WinUSB_GetPowerPolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle, ULONG PolicyType, PULONG ValueLength, PVOID Value)
WinUSB_GetOverlappedResult GetOverlappedResult
Retrieves the results of an overlapped operation on the specified winUSB handle.
WinUSB_FlushPipe FlushPipe
Discards any data that is cached in a pipe.
void initLibrary()
Definition: xswinusb.cpp:28
BOOL __stdcall WinUSB_SetCurrentAlternateSetting(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR AltSettingNumber)
WinUSB_GetDescriptor GetDescriptor
Gets the requested descriptor. This is a synchronous operation.
BOOL __stdcall WinUSB_AbortPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID)
WinUSB_QueryPipe * QueryPipe
WinUSB_SetPowerPolicy SetPowerPolicy
Sets the power policy for a device. The following list summarizes the effects of changes to power man...
WinUSB_QueryInterfaceSettings QueryInterfaceSettings
Retrieves the interface descriptor for the specified alternate interface settings for a particular in...
WinUSB_ResetPipe * ResetPipe
WinUSB_QueryDeviceInformation QueryDeviceInformation
Retrieves information about the physical device that is associated with a WinUSB handle.
WinUSB_WritePipe * WritePipe
WinUSB_GetAssociatedInterface GetAssociatedInterface
Retrieves a handle for an associated interface.
WinUSB_SetPipePolicy SetPipePolicy
Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous ...
WinUSB_ReadPipe * ReadPipe
WinUSB_QueryInterfaceSettings * QueryInterfaceSettings
BOOL __stdcall WinUSB_QueryPipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR AltSettingNumber, UCHAR PipeIndex, PWINUSB_PIPE_INFORMATION PipeInformation)
WinUSB_QueryDeviceInformation * QueryDeviceInformation
WinUSB_FlushPipe * FlushPipe
BOOL __stdcall WinUSB_SetPipePolicy(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID, ULONG PolicyType, ULONG ValueLength, PVOID Value)
WinUSB_ControlTransfer * ControlTransfer
WinUSB_GetPipePolicy * GetPipePolicy
WinUSB_SetPowerPolicy * SetPowerPolicy
WinUSB_WritePipe WritePipe
Writes data to a pipe.
BOOL __stdcall WinUSB_Free(WINUSB_INTERFACE_HANDLE InterfaceHandle)
WinUSB_ControlTransfer ControlTransfer
Transmits control data over a default control endpoint. A ControlTransfer is never cached...
BOOL __stdcall WinUSB_QueryDeviceInformation(WINUSB_INTERFACE_HANDLE InterfaceHandle, ULONG InformationType, PULONG BufferLength, PVOID Buffer)
WinUSB_GetOverlappedResult * GetOverlappedResult
BOOL __stdcall WinUSB_WritePipe(WINUSB_INTERFACE_HANDLE InterfaceHandle, UCHAR PipeID, PUCHAR Buffer, ULONG BufferLength, PULONG LengthTransferred, LPOVERLAPPED Overlapped)
WinUSB_GetCurrentAlternateSetting GetCurrentAlternateSetting
Gets the current alternate interface setting for an interface. Gets the active bAlternateSetting for ...



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020