• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_USB_API_ADBWINAPI_H__
18 #define ANDROID_USB_API_ADBWINAPI_H__
19 
20 #include <windows.h>
21 #include <usb100.h>
22 
23 /** \file
24   This file consists of declarations of routines exported by the API as well
25   as types, structures, and constants definitions used in the API.
26 */
27 
28 // Enables compillation for "straight" C
29 #ifdef __cplusplus
30   #define EXTERN_C    extern "C"
31 #else
32   #define EXTERN_C    extern
33   typedef int bool;
34   #define true  1
35   #define false 0
36 #endif
37 
38 /** \brief Enumerates ADB endpoint types.
39 
40   This enum is taken from WDF_USB_PIPE_TYPE enum found in WDK.
41 */
42 typedef enum _AdbEndpointType {
43   /// Unknown (invalid, or not initialized) endpoint type.
44   AdbEndpointTypeInvalid = 0,
45 
46   /// Endpoint is device control pipe.
47   AdbEndpointTypeControl,
48 
49   /// Endpoint is isochronous r/w pipe.
50   AdbEndpointTypeIsochronous,
51 
52   /// Endpoint is a bulk r/w pipe.
53   AdbEndpointTypeBulk,
54 
55   /// Endpoint is an interrupt r/w pipe.
56   AdbEndpointTypeInterrupt,
57 } AdbEndpointType;
58 
59 /** \brief Endpoint desriptor.
60 
61   This structure is based on WDF_USB_PIPE_INFORMATION structure found in WDK.
62 */
63 typedef struct _AdbEndpointInformation {
64   /// Maximum packet size this endpoint is capable of.
65   unsigned long max_packet_size;
66 
67   /// Maximum size of one transfer which should be sent to the host controller.
68   unsigned long max_transfer_size;
69 
70   /// ADB endpoint type.
71   AdbEndpointType endpoint_type;
72 
73   /// Raw endpoint address on the device as described by its descriptor.
74   unsigned char endpoint_address;
75 
76   /// Polling interval.
77   unsigned char polling_interval;
78 
79   /// Which alternate setting this structure is relevant for.
80   unsigned char setting_index;
81 } AdbEndpointInformation;
82 
83 /// Shortcut to default write bulk endpoint in zero-based endpoint index API.
84 #define ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX  0xFC
85 
86 /// Shortcut to default read bulk endpoint in zero-based endpoint index API.
87 #define ADB_QUERY_BULK_READ_ENDPOINT_INDEX  0xFE
88 
89 // {F72FE0D4-CBCB-407d-8814-9ED673D0DD6B}
90 /// Our USB class id that driver uses to register our device.
91 #define ANDROID_USB_CLASS_ID \
92 {0xf72fe0d4, 0xcbcb, 0x407d, {0x88, 0x14, 0x9e, 0xd6, 0x73, 0xd0, 0xdd, 0x6b}};
93 
94 /// Defines vendor ID for HCT devices.
95 #define DEVICE_VENDOR_ID                  0x0BB4
96 
97 /// Defines product ID for the device with single interface.
98 #define DEVICE_SINGLE_PRODUCT_ID          0x0C01
99 
100 /// Defines product ID for the Dream composite device.
101 #define DEVICE_COMPOSITE_PRODUCT_ID       0x0C02
102 
103 /// Defines product ID for the Magic composite device.
104 #define DEVICE_MAGIC_COMPOSITE_PRODUCT_ID 0x0C03
105 
106 /// Defines interface ID for the device.
107 #define DEVICE_INTERFACE_ID               0x01
108 
109 /// Defines vendor ID for the device
110 #define DEVICE_EMULATOR_VENDOR_ID         0x18D1
111 
112 /// Defines product ID for a SoftUSB device simulator that is used to test
113 /// the driver in isolation from hardware.
114 #define DEVICE_EMULATOR_PROD_ID           0xDDDD
115 
116 // The following ifdef block is the standard way of creating macros which make
117 // exporting  from a DLL simpler. All files within this DLL are compiled with
118 // the ADBWIN_EXPORTS symbol defined on the command line. this symbol should
119 // not be defined on any project that uses this DLL. This way any other project
120 // whose source files include this file see ADBWIN_API functions as being
121 // imported from a DLL, whereas this DLL sees symbols defined with this macro
122 // as being exported.
123 #ifdef ADBWIN_EXPORTS
124 #define ADBWIN_API EXTERN_C __declspec(dllexport)
125 #define ADBWIN_API_CLASS     __declspec(dllexport)
126 #else
127 #define ADBWIN_API EXTERN_C __declspec(dllimport)
128 #define ADBWIN_API_CLASS     __declspec(dllimport)
129 #endif
130 
131 /** \brief Handle to an API object.
132 
133   To access USB interface and its components clients must first obtain a
134   handle to the required object. API Objects that are represented by a
135   handle are:
136   1. Interface enumerator that provides access to a list of interfaces that
137      match certain criterias that were specified when interface enumerator
138      has been created. This handle is created in AdbEnumInterfaces routine.
139   2. Interface that is the major object this API deals with. In Windows
140      model of the USB stack each USB device (that is physical device,
141      attached to a USB port) exposes one or more interfaces that become the
142      major entities through which that device gets accessed. Each of these
143      interfaces are represented as Windows Device Objects on the USB stack.
144      So, to this extent, at least as this API is concerned, terms "interface"
145      and "device" are interchangeable, since each interface is represented by
146      a device object on the Windows USB stack. This handle is created in
147      either AdbCreateInterface or AdbCreateInterfaceByName routines.
148   3. Endpoint object (also called a pipe) represents an endpoint on interface
149      through which all I/O operations are performed. This handle is created in
150      one of these routines: AdbOpenEndpoint, AdbOpenDefaultBulkReadEndpoint,
151      or AdbOpenDefaultBulkWriteEndpoint.
152   4. I/O completion object that tracks completion information of asynchronous
153      I/O performed on an endpoint. When an endpoint object gets opened through
154      this API it is opened for asynchronous (or overlapped) I/O. And each time
155      an asynchronous I/O is performed by this API an I/O completion object is
156      created to track the result of that I/O when it gets completed. Clients
157      of the API can then use a handle to I/O completion object to query for
158      the status and result of asynchronous I/O as well as wait for this I/O
159      completion. This handle is created in one of these routines:
160      AdbReadEndpointAsync, or AdbWriteEndpointAsync.
161   After object is no longer needed by the client, its handle must be closed
162   using AdbCloseHandle routine.
163 */
164 typedef void* ADBAPIHANDLE;
165 
166 /** \brief Defines access type with which an I/O object (endpoint)
167   should be opened.
168 */
169 typedef enum _AdbOpenAccessType {
170   /// Opens for read and write access.
171   AdbOpenAccessTypeReadWrite,
172 
173   /// Opens for read only access.
174   AdbOpenAccessTypeRead,
175 
176   /// Opens for write only access.
177   AdbOpenAccessTypeWrite,
178 
179   /// Opens for querying information.
180   AdbOpenAccessTypeQueryInfo,
181 } AdbOpenAccessType;
182 
183 /** \brief Defines sharing mode with which an I/O object (endpoint)
184   should be opened.
185 */
186 typedef enum _AdbOpenSharingMode {
187   /// Shares read and write.
188   AdbOpenSharingModeReadWrite,
189 
190   /// Shares only read.
191   AdbOpenSharingModeRead,
192 
193   /// Shares only write.
194   AdbOpenSharingModeWrite,
195 
196   /// Opens exclusive.
197   AdbOpenSharingModeExclusive,
198 } AdbOpenSharingMode;
199 
200 /** \brief Provides information about an interface.
201 */
202 typedef struct _AdbInterfaceInfo {
203   /// Inteface's class id (see SP_DEVICE_INTERFACE_DATA for details)
204   GUID          class_id;
205 
206   /// Interface flags (see SP_DEVICE_INTERFACE_DATA for details)
207   unsigned long flags;
208 
209   /// Device name for the interface (see SP_DEVICE_INTERFACE_DETAIL_DATA
210   /// for details)
211   wchar_t       device_name[1];
212 } AdbInterfaceInfo;
213 
214 /** \brief Creates USB interface enumerator
215 
216   This routine enumerates all USB interfaces that match provided class ID.
217   This routine uses SetupDiGetClassDevs SDK routine to enumerate devices that
218   match class ID and then SetupDiEnumDeviceInterfaces SDK routine is called
219   to enumerate interfaces on the devices.
220   @param[in] class_id Device class ID, assigned by the driver.
221   @param[in] exclude_not_present If true enumation will include only those
222          devices that are currently present.
223   @param[in] exclude_removed If true interfaces with SPINT_REMOVED flag set
224          will be not included in the enumeration.
225   @param[in] active_only If true only active interfaces (with flag
226            SPINT_ACTIVE set) will be included in the enumeration.
227   @return Handle to the enumerator object or NULL on failure. If NULL is
228           returned GetLastError() provides extended error information.
229 */
230 ADBWIN_API ADBAPIHANDLE __cdecl AdbEnumInterfaces(GUID class_id,
231                                           bool exclude_not_present,
232                                           bool exclude_removed,
233                                           bool active_only);
234 
235 /** \brief Gets next interface information
236 
237   @param[in] adb_handle Handle to interface enumerator object obtained via
238          AdbEnumInterfaces call.
239   @param[out] info Upon successful completion will receive interface
240          information. Can be NULL. If it is NULL, upon return from this
241          routine size parameter will contain memory size required for the
242          next entry.
243   @param[in,out] size On the way in provides size of the memory buffer
244          addressed by info parameter. On the way out (only if buffer was not
245          big enough) will provide memory size required for the next entry.
246   @return true on success, false on error. If false is returned
247           GetLastError() provides extended error information.
248           ERROR_INSUFFICIENT_BUFFER indicates that buffer provided in info
249           parameter was not big enough and size parameter contains memory size
250           required for the next entry. ERROR_NO_MORE_ITEMS indicates that
251           enumeration is over and there are no more entries to return.
252 */
253 ADBWIN_API bool __cdecl AdbNextInterface(ADBAPIHANDLE adb_handle,
254                                  AdbInterfaceInfo* info,
255                                  unsigned long* size);
256 
257 /** \brief Resets enumerator so next call to AdbNextInterface will start
258   from the beginning.
259 
260   @param[in] adb_handle Handle to interface enumerator object obtained via
261          AdbEnumInterfaces call.
262   @return true on success, false on error. If false is returned GetLastError()
263           provides extended error information.
264 */
265 ADBWIN_API bool __cdecl AdbResetInterfaceEnum(ADBAPIHANDLE adb_handle);
266 
267 /** \brief Creates USB interface object
268 
269   This routine creates an object that represents a USB interface.
270   @param[in] interface_name Name of the interface.
271   @return Handle to the interface object or NULL on failure. If NULL is
272           returned GetLastError() provides extended error information.
273 */
274 ADBWIN_API ADBAPIHANDLE __cdecl AdbCreateInterfaceByName(const wchar_t* interface_name);
275 
276 /** \brief Creates USB interface object based on vendor, product and
277   interface IDs.
278 
279   This routine creates and object that represents a USB interface on our
280   device. It uses AdbCreateInterfaceByName to actually do the create.
281   @param[in] class_id Device class ID, assigned by the driver.
282   @param[in] vendor_id Device vendor ID
283   @param[in] product_id Device product ID
284   @param[in] interface_id Device interface ID. This parameter is optional.
285          Value 0xFF indicates that interface should be addressed by vendor
286          and product IDs only.
287   @return Handle to the interface object or NULL on failure. If NULL is
288           returned GetLastError() provides extended error information.
289 */
290 ADBWIN_API ADBAPIHANDLE __cdecl AdbCreateInterface(GUID class_id,
291                                            unsigned short vendor_id,
292                                            unsigned short product_id,
293                                            unsigned char interface_id);
294 
295 /** \brief Gets interface name.
296 
297   @param[in] adb_interface A handle to interface object created with
298          AdbCreateInterface call.
299   @param[out] buffer Buffer for the name. Can be NULL in which case
300          buffer_char_size will contain number of characters required for
301          the name.
302   @param[in,out] buffer_char_size On the way in supplies size (in characters)
303          of the buffer. On the way out, if method failed and GetLastError
304          reports ERROR_INSUFFICIENT_BUFFER, will contain number of characters
305          required for the name.
306   @param[in] ansi If true the name will be returned as single character
307          string. Otherwise name will be returned as wide character string.
308   @return true on success, false on failure. If false is returned
309           GetLastError() provides extended error information.
310 */
311 ADBWIN_API bool __cdecl AdbGetInterfaceName(ADBAPIHANDLE adb_interface,
312                                     void* buffer,
313                                     unsigned long* buffer_char_size,
314                                     bool ansi);
315 
316 /** \brief Gets serial number for interface's device.
317 
318   @param[in] adb_interface A handle to interface object created with
319          AdbCreateInterface call.
320   @param[out] buffer Buffer for the serail number string. Can be NULL in which
321          case buffer_char_size will contain number of characters required for
322          the string.
323   @param[in,out] buffer_char_size On the way in supplies size (in characters)
324          of the buffer. On the way out, if method failed and GetLastError
325          reports ERROR_INSUFFICIENT_BUFFER, will contain number of characters
326          required for the name.
327   @param[in] ansi If true the name will be returned as single character
328          string. Otherwise name will be returned as wide character string.
329   @return true on success, false on failure. If false is returned
330           GetLastError() provides extended error information.
331 */
332 ADBWIN_API bool __cdecl AdbGetSerialNumber(ADBAPIHANDLE adb_interface,
333                                    void* buffer,
334                                    unsigned long* buffer_char_size,
335                                    bool ansi);
336 
337 /** \brief Gets device descriptor for the USB device associated with
338   the given interface.
339 
340   @param[in] adb_interface A handle to interface object created with
341          AdbCreateInterface call.
342   @param[out] desc Upon successful completion will have usb device
343          descriptor.
344   @return true on success, false on failure. If false is returned
345           GetLastError() provides extended error information.
346 */
347 ADBWIN_API bool __cdecl AdbGetUsbDeviceDescriptor(ADBAPIHANDLE adb_interface,
348                                           USB_DEVICE_DESCRIPTOR* desc);
349 
350 /** \brief Gets descriptor for the selected USB device configuration.
351 
352   @param[in] adb_interface A handle to interface object created with
353          AdbCreateInterface call.
354   @param[out] desc Upon successful completion will have usb device
355          configuration descriptor.
356   @return true on success, false on failure. If false is returned
357           GetLastError() provides extended error information.
358 */
359 ADBWIN_API bool __cdecl AdbGetUsbConfigurationDescriptor(
360                     ADBAPIHANDLE adb_interface,
361                     USB_CONFIGURATION_DESCRIPTOR* desc);
362 
363 /** \brief Gets descriptor for the given interface.
364 
365   @param[in] adb_interface A handle to interface object created with
366          AdbCreateInterface call.
367   @param[out] desc Upon successful completion will have usb device
368          configuration descriptor.
369   @return true on success, false on failure. If false is returned
370           GetLastError() provides extended error information.
371 */
372 ADBWIN_API bool __cdecl AdbGetUsbInterfaceDescriptor(ADBAPIHANDLE adb_interface,
373                                              USB_INTERFACE_DESCRIPTOR* desc);
374 
375 /** \brief Gets information about an endpoint on the given interface.
376 
377   @param[in] adb_interface A handle to interface object created with
378          AdbCreateInterface call.
379   @param[in] endpoint_index Zero-based endpoint index. There are two
380          shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
381          and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide information
382          about bulk write and bulk read endpoints respectively.
383   @param[out] info Upon successful completion will have endpoint information.
384   @return true on success, false on failure. If false is returned
385           GetLastError() provides extended error information.
386 */
387 ADBWIN_API bool __cdecl AdbGetEndpointInformation(ADBAPIHANDLE adb_interface,
388                                           unsigned char endpoint_index,
389                                           AdbEndpointInformation* info);
390 
391 /** \brief Gets information about default bulk read endpoint on the given
392   interface.
393 
394   @param[in] adb_interface A handle to interface object created with
395          AdbCreateInterface call.
396   @param[out] info Upon successful completion will have endpoint information.
397   @return true on success, false on failure. If false is returned
398           GetLastError() provides extended error information.
399 */
400 ADBWIN_API bool __cdecl AdbGetDefaultBulkReadEndpointInformation(
401                     ADBAPIHANDLE adb_interface,
402                     AdbEndpointInformation* info);
403 
404 /** \brief Gets information about default bulk write endpoint on the given
405   interface.
406 
407   @param[in] adb_interface A handle to interface object created with
408          AdbCreateInterface call.
409   @param[out] info Upon successful completion will have endpoint information.
410   @return true on success, false on failure. If false is returned
411           GetLastError() provides extended error information.
412 */
413 ADBWIN_API bool __cdecl AdbGetDefaultBulkWriteEndpointInformation(
414                     ADBAPIHANDLE adb_interface,
415                     AdbEndpointInformation* info);
416 
417 /** \brief Opens an endpoint on the given interface.
418 
419   Endpoints are always opened for overlapped I/O.
420   @param[in] adb_interface A handle to interface object created with
421          AdbCreateInterface call.
422   @param[in] endpoint_index Zero-based endpoint index. There are two
423          shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
424          and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide information
425          about bulk write and bulk read endpoints respectively.
426   @param[in] access_type Desired access type. In the current implementation
427          this parameter has no effect on the way endpoint is opened. It's
428          always read / write access.
429   @param[in] sharing_mode Desired share mode. In the current implementation
430          this parameter has no effect on the way endpoint is opened. It's
431          always shared for read / write.
432   @return Handle to the opened endpoint object or NULL on failure. If NULL is
433           returned GetLastError() provides extended error information.
434 */
435 ADBWIN_API ADBAPIHANDLE __cdecl AdbOpenEndpoint(ADBAPIHANDLE adb_interface,
436                                         unsigned char endpoint_index,
437                                         AdbOpenAccessType access_type,
438                                         AdbOpenSharingMode sharing_mode);
439 
440 /** \brief Opens default bulk read endpoint on the given interface.
441 
442   Endpoints are always opened for overlapped I/O.
443   @param[in] adb_interface A handle to interface object created with
444          AdbCreateInterface call.
445   @param[in] access_type Desired access type. In the current implementation
446          this parameter has no effect on the way endpoint is opened. It's
447          always read / write access.
448   @param[in] sharing_mode Desired share mode. In the current implementation
449          this parameter has no effect on the way endpoint is opened. It's
450          always shared for read / write.
451   @return Handle to the opened endpoint object or NULL on failure. If NULL is
452           returned GetLastError() provides extended error information.
453 */
454 ADBWIN_API ADBAPIHANDLE __cdecl AdbOpenDefaultBulkReadEndpoint(
455                             ADBAPIHANDLE adb_interface,
456                             AdbOpenAccessType access_type,
457                             AdbOpenSharingMode sharing_mode);
458 
459 /** \brief Opens default bulk write endpoint on the given interface.
460 
461   Endpoints are always opened for overlapped I/O.
462   @param[in] adb_interface A handle to interface object created with
463          AdbCreateInterface call.
464   @param[in] access_type Desired access type. In the current implementation
465          this parameter has no effect on the way endpoint is opened. It's
466          always read / write access.
467   @param[in] sharing_mode Desired share mode. In the current implementation
468          this parameter has no effect on the way endpoint is opened. It's
469          always shared for read / write.
470   @return Handle to the opened endpoint object or NULL on failure. If NULL is
471           returned GetLastError() provides extended error information.
472 */
473 ADBWIN_API ADBAPIHANDLE __cdecl AdbOpenDefaultBulkWriteEndpoint(
474                             ADBAPIHANDLE adb_interface,
475                             AdbOpenAccessType access_type,
476                             AdbOpenSharingMode sharing_mode);
477 
478 /** \brief Gets handle to interface object for the given endpoint
479 
480   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
481          of the AdbOpenXxxEndpoint calls.
482   @return Handle to the interface for this endpoint or NULL on failure. If NULL
483           is returned GetLastError() provides extended error information.
484 */
485 ADBWIN_API ADBAPIHANDLE __cdecl AdbGetEndpointInterface(ADBAPIHANDLE adb_endpoint);
486 
487 /** \brief Gets information about the given endpoint.
488 
489   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
490          of the AdbOpenXxxEndpoint calls.
491   @param[out] info Upon successful completion will have endpoint information.
492   @return true on success, false on failure. If false is returned
493           GetLastError() provides extended error information.
494 */
495 ADBWIN_API bool __cdecl AdbQueryInformationEndpoint(ADBAPIHANDLE adb_endpoint,
496                                             AdbEndpointInformation* info);
497 
498 /** \brief Asynchronously reads from the given endpoint.
499 
500   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
501          of the AdbOpenXxxEndpoint calls.
502   @param[out] buffer Pointer to the buffer that receives the data.
503   @param[in] bytes_to_read Number of bytes to be read.
504   @param[out] bytes_read Number of bytes read. Can be NULL.
505   @param[in] event_handle Event handle that should be signaled when async I/O
506          completes. Can be NULL. If it's not NULL this handle will be used to
507          initialize OVERLAPPED structure for this I/O.
508   @param[in] time_out A timeout (in milliseconds) required for this I/O to
509          complete. Zero value for this parameter means that there is no
510          timeout for this I/O.
511   @return A handle to IO completion object or NULL on failure. If NULL is
512           returned GetLastError() provides extended error information.
513 */
514 ADBWIN_API ADBAPIHANDLE __cdecl AdbReadEndpointAsync(ADBAPIHANDLE adb_endpoint,
515                                              void* buffer,
516                                              unsigned long bytes_to_read,
517                                              unsigned long* bytes_read,
518                                              unsigned long time_out,
519                                              HANDLE event_handle);
520 
521 /** \brief Asynchronously writes to the given endpoint.
522 
523   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
524          of the AdbOpenXxxEndpoint calls.
525   @param[in] buffer Pointer to the buffer containing the data to be written.
526   @param[in] bytes_to_write Number of bytes to be written.
527   @param[out] bytes_written Number of bytes written. Can be NULL.
528   @param[in] event_handle Event handle that should be signaled when async I/O
529          completes. Can be NULL. If it's not NULL this handle will be used to
530          initialize OVERLAPPED structure for this I/O.
531   @param[in] time_out A timeout (in milliseconds) required for this I/O to
532          complete. Zero value for this parameter means that there is no
533          timeout for this I/O.
534   @return A handle to IO completion object or NULL on failure. If NULL is
535           returned GetLastError() provides extended error information.
536 */
537 ADBWIN_API ADBAPIHANDLE __cdecl AdbWriteEndpointAsync(ADBAPIHANDLE adb_endpoint,
538                                               void* buffer,
539                                               unsigned long bytes_to_write,
540                                               unsigned long* bytes_written,
541                                               unsigned long time_out,
542                                               HANDLE event_handle);
543 
544 /** \brief Synchronously reads from the given endpoint.
545 
546   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
547          of the AdbOpenXxxEndpoint calls.
548   @param[out] buffer Pointer to the buffer that receives the data.
549   @param[in] bytes_to_read Number of bytes to be read.
550   @param[out] bytes_read Number of bytes read. Can be NULL.
551   @param[in] time_out A timeout (in milliseconds) required for this I/O to
552          complete. Zero value for this parameter means that there is no
553          timeout for this I/O.
554   @return true on success and false on failure. If false is
555           returned GetLastError() provides extended error information.
556 */
557 ADBWIN_API bool __cdecl AdbReadEndpointSync(ADBAPIHANDLE adb_endpoint,
558                                     void* buffer,
559                                     unsigned long bytes_to_read,
560                                     unsigned long* bytes_read,
561                                     unsigned long time_out);
562 
563 /** \brief Synchronously writes to the given endpoint.
564 
565   @param[in] adb_endpoint A handle to opened endpoint object, obtained via one
566          of the AdbOpenXxxEndpoint calls.
567   @param[in] buffer Pointer to the buffer containing the data to be written.
568   @param[in] bytes_to_write Number of bytes to be written.
569   @param[out] bytes_written Number of bytes written. Can be NULL.
570   @param[in] time_out A timeout (in milliseconds) required for this I/O to
571          complete. Zero value for this parameter means that there is no
572          timeout for this I/O.
573   @return true on success and false on failure. If false is
574           returned GetLastError() provides extended error information.
575 */
576 ADBWIN_API bool __cdecl AdbWriteEndpointSync(ADBAPIHANDLE adb_endpoint,
577                                      void* buffer,
578                                      unsigned long bytes_to_write,
579                                      unsigned long* bytes_written,
580                                      unsigned long time_out);
581 
582 /** \brief Gets overlapped I/O result for async I/O performed on the
583   given endpoint.
584 
585   @param[in] adb_io_completion A handle to an I/O completion object returned
586          from AdbRead/WriteAsync routines.
587   @param[out] ovl_data Buffer for the copy of this object's OVERLAPPED
588          structure. Can be NULL.
589   @param[out] bytes_transferred Pointer to a variable that receives the
590          number of bytes that were actually transferred by a read or write
591          operation. See SDK doc on GetOvelappedResult for more information.
592          Unlike regular GetOvelappedResult call this parameter can be NULL.
593   @param[in] wait If this parameter is true, the method does not return
594          until the operation has been completed. If this parameter is false
595          and the operation is still pending, the method returns false and
596          the GetLastError function returns ERROR_IO_INCOMPLETE.
597   @return true if I/O has been completed or false on failure or if request
598          is not yet completed. If false is returned GetLastError() provides
599          extended error information. If GetLastError returns
600          ERROR_IO_INCOMPLETE it means that I/O is not yet completed.
601 */
602 ADBWIN_API bool __cdecl AdbGetOvelappedIoResult(ADBAPIHANDLE adb_io_completion,
603                                         LPOVERLAPPED overlapped,
604                                         unsigned long* bytes_transferred,
605                                         bool wait);
606 
607 /** \brief Checks if overlapped I/O has been completed.
608 
609   @param[in] adb_io_completion A handle to an I/O completion object returned
610          from AdbRead/WriteAsync routines.
611   @return true if I/O has been completed or false if it's still
612           incomplete. Regardless of the returned value, caller should
613           check GetLastError to validate that handle was OK.
614 */
615 ADBWIN_API bool __cdecl AdbHasOvelappedIoComplated(ADBAPIHANDLE adb_io_completion);
616 
617 /** \brief Closes handle previously opened with one of the API calls
618 
619   @param[in] adb_handle ADB handle previously opened with one of the API calls
620   @return true on success or false on failure. If false is returned
621           GetLastError() provides extended error information.
622 */
623 ADBWIN_API bool __cdecl AdbCloseHandle(ADBAPIHANDLE adb_handle);
624 
625 #endif  // ANDROID_USB_API_ADBWINAPI_H__
626