summaryrefslogtreecommitdiff
path: root/UsbDkHelper/UsbDkHelper.h
blob: a5b56666823bc3df5514572f1a7cc2c2e13d0836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**********************************************************************
* Copyright (c) 2013-2014  Red Hat, Inc.
*
* Developed by Daynix Computing LTD.
*
* Authors:
*     Dmitry Fleytman <dmitry@daynix.com>
*     Pavel Gurvich <pavel@daynix.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************/

#pragma once

// UsbDkHelper C-interface

#ifdef BUILD_DLL
#define DLL __declspec(dllexport)
#else
#ifdef _MSC_VER
#define DLL __declspec(dllimport)
#else
#define DLL
#endif
#endif

#include "UsbDkData.h"

typedef enum
{
    InstallFailure,
    InstallSuccessNeedReboot,
    InstallSuccess,
    InstallAborted
} InstallResult;

#ifdef __cplusplus
extern "C" {
#endif

    /* Install UsbDk Driver on the system
     * Requires usbdk.inf , usbdk.sys,  usbdkHelper.dll and
     * wdfcoinstaller01009.dll files to exist in current directory
     *
     *
     * @params
     *   None
     *
     * @return
     *  installation status
     *
     */
    DLL InstallResult    UsbDk_InstallDriver(void);

    /* Uninstall UsbDk Driver from the system
    *
    *
    * @params
    *   None
    *
    * @return
    *  TRUE if uninstall succeeds
    *
    */
    DLL BOOL             UsbDk_UninstallDriver(void);

    /* List USB devices attached to the system
    *
    * @params
    *    IN  - None
    *    OUT - DevicesArray  pointer to array where devices will be stored
               NumberDevices amount of returned devices
    *
    * @return
    *  TRUE if function succeeds
    * @note
    *  It is caller's responsibility to release device list by
    *  using UsbDk_ReleaseDevicesList
    *
    */
    DLL BOOL             UsbDk_GetDevicesList(PUSB_DK_DEVICE_INFO *DevicesArray, PULONG NumberDevices);

    /* Release deviceArray list returned by UsbDk_GetDevicesList
    *
    * @params
    *    IN  - DevicesArray  pointer to  device list to be released
    *    OUT - None
    *
    * @return
    *  None
    *
    */
    DLL void             UsbDk_ReleaseDevicesList(PUSB_DK_DEVICE_INFO DevicesArray);

    /* Retrieve USB device configuration descriptor
    *
    * @params
    *    IN  - Request      pointer to descriptor request
    *    OUT - Descriptor   pointer where configuration descriptor header will be stored
    *        - Length       length of full descriptor
    *
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_GetConfigurationDescriptor(PUSB_DK_CONFIG_DESCRIPTOR_REQUEST Request,
                                                          PUSB_CONFIGURATION_DESCRIPTOR *Descriptor,
                                                          PULONG Length);

    /* Release configuration descriptor returned by UsbDk_GetConfigurationDescriptor
    *
    * @params
    *    IN  - Descriptor - pointer to  descriptor to be released
    *    OUT - None
    *
    * @return
    *  None
    *
    */
    DLL void             UsbDk_ReleaseConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR Descriptor);

    /* Detach USB device from Windows and acquire it for exclusive access
    *
    * @params
    *    IN  - DeviceID   id of device to be acquired
    *    OUT - None
    *
    * @return
    *  Handle to acquired device
    *
    * @note
    *  Device returned to system automatically when handle is closed
    *
    */
    DLL HANDLE           UsbDk_StartRedirect(PUSB_DK_DEVICE_ID DeviceID);

    /* Return USB device to system
    *
    * @params
    *    IN  - DeviceHandle  handle of acquired device
    *    OUT - None
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_StopRedirect(HANDLE DeviceHandle);

    /* Write to USB device pipe
    *
    * @params
    *    IN  - DeviceHandle - handle of target USB device
    *        - Request      - write request
    *        - Overlapped   - asynchronous I/O definition
    *    OUT - None
    *
    * @return
    *  Status of transfer
    *
    */
    DLL TransferResult   UsbDk_WritePipe(HANDLE DeviceHandle, PUSB_DK_TRANSFER_REQUEST Request, LPOVERLAPPED Overlapped);

    /* Read from USB device pipe
    *
    * @params
    *    IN  - DeviceHandle - handle of target USB device
    *        - Request      - read request
    *        - Overlapped   - asynchronous I/O definition
    *    OUT - None
    *
    * @return
    *  Status of transfer
    *
    */
    DLL TransferResult   UsbDk_ReadPipe(HANDLE DeviceHandle, PUSB_DK_TRANSFER_REQUEST Request, LPOVERLAPPED Overlapped);

    /* Issue an USB abort pipe request
    *
    * @params
    *    IN  - DeviceHandle - handle of target USB device
    *        - PipeAddress  - address of pipe to be aborted
    *    OUT - None
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_AbortPipe(HANDLE DeviceHandle, ULONG64 PipeAddress);

    /* Issue an USB reset pipe request
    *
    * @params
    *    IN  - DeviceHandle - handle of target USB device
    *        - PipeAddress  - address of pipe to be reset
    *    OUT - None
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_ResetPipe(HANDLE DeviceHandle, ULONG64 PipeAddress);

    /* Set active alternative settings for USB device
    *
    * @params
    *    IN  - DeviceHandle  - handle of target USB device
    *        - InterfaceIdx  - interface index
    *        - AltSettingIdx - alternative settings index
    *    OUT - None
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_SetAltsetting(HANDLE DeviceHandle, ULONG64 InterfaceIdx, ULONG64 AltSettingIdx);

    /* Reset USB device
    *
    * @params
    *    IN  - DeviceHandle  - handle of target USB device
    *    OUT - None
    *
    * @return
    * TRUE if function succeeds
    *
    */
    DLL BOOL             UsbDk_ResetDevice(HANDLE DeviceHandle);

    /* Get system handle for asynchronous I/O cancellation requests
    *
    * @params
    *    IN  - DeviceHandle  - handle of target USB device
    *    OUT - None
    *
    * @return
    *  handle
    *
    */
    DLL HANDLE           UsbDk_GetRedirectorSystemHandle(HANDLE DeviceHandle);
#ifdef __cplusplus
}
#endif