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