2
* FreeRDP: A Remote Desktop Protocol Implementation
3
* RemoteFX USB Redirection
5
* Copyright 2012 Atrust corp.
6
* Copyright 2012 Alfred Liu <alfred.liu@atruscorp.com>
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
21
#ifndef __URBDRC_TYPES_H
22
#define __URBDRC_TYPES_H
28
#include <freerdp/dvc.h>
29
#include <freerdp/types.h>
30
#include <freerdp/utils/debug.h>
31
#include <freerdp/utils/msusb.h>
33
#include <uuid/uuid.h>
35
#include <semaphore.h>
37
#include <winpr/stream.h>
40
#define DEBUG_DVC(fmt, ...) DEBUG_CLASS(DVC, fmt, ## __VA_ARGS__)
42
#define DEBUG_DVC(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
45
#define CAPABILITIES_NEGOTIATOR 0x00000000
46
#define CLIENT_DEVICE_SINK 0x00000001
47
#define SERVER_CHANNEL_NOTIFICATION 0x00000002
48
#define CLIENT_CHANNEL_NOTIFICATION 0x00000003
49
#define BASE_USBDEVICE_NUM 0x00000005
51
#define RIMCALL_RELEASE 0x00000001
52
#define RIM_EXCHANGE_CAPABILITY_REQUEST 0x00000100
53
#define CHANNEL_CREATED 0x00000100
54
#define ADD_VIRTUAL_CHANNEL 0x00000100
55
#define ADD_DEVICE 0x00000101
57
#define INIT_CHANNEL_IN 1
58
#define INIT_CHANNEL_OUT 0
61
#define CLASS_RESERVE 0x00
62
#define CLASS_AUDIO 0x01
63
#define CLASS_COMMUNICATION_IF 0x02
64
#define CLASS_HID 0x03
65
#define CLASS_PHYSICAL 0x05
66
#define CLASS_IMAGE 0x06
67
#define CLASS_PRINTER 0x07
68
#define CLASS_MASS_STORAGE 0x08
69
#define CLASS_HUB 0x09
70
#define CLASS_COMMUNICATION_DATA_IF 0x0a
71
#define CLASS_SMART_CARD 0x0b
72
#define CLASS_CONTENT_SECURITY 0x0d
73
#define CLASS_VIDEO 0x0e
74
#define CLASS_PERSONAL_HEALTHCARE 0x0f
75
#define CLASS_DIAGNOSTIC 0xdc
76
#define CLASS_WIRELESS_CONTROLLER 0xe0
77
#define CLASS_ELSE_DEVICE 0xef
78
#define CLASS_DEPENDENCE 0xfe
79
#define CLASS_VENDOR_DEPENDENCE 0xff
82
#define USB_v1_0 0x100
83
#define USB_v1_1 0x110
84
#define USB_v2_0 0x200
85
#define USB_v3_0 0x300
87
#define STREAM_ID_NONE 0x0
88
#define STREAM_ID_PROXY 0x1
89
#define STREAM_ID_STUB 0x2
91
#define CANCEL_REQUEST 0x00000100
92
#define REGISTER_REQUEST_CALLBACK 0x00000101
93
#define IO_CONTROL 0x00000102
94
#define INTERNAL_IO_CONTROL 0x00000103
95
#define QUERY_DEVICE_TEXT 0x00000104
96
#define TRANSFER_IN_REQUEST 0x00000105
97
#define TRANSFER_OUT_REQUEST 0x00000106
98
#define RETRACT_DEVICE 0x00000107
101
#define IOCONTROL_COMPLETION 0x00000100
102
#define URB_COMPLETION 0x00000101
103
#define URB_COMPLETION_NO_DATA 0x00000102
105
/* The USB device is to be stopped from being redirected because the
106
* device is blocked by the server's policy. */
107
#define UsbRetractReason_BlockedByPolicy 0x00000001
109
enum device_text_type
111
DeviceTextDescription = 0,
112
DeviceTextLocationInformation = 1,
115
enum device_descriptor_table
118
B_DESCRIPTOR_TYPE = 1,
121
B_DEVICE_SUBCLASS = 5,
122
B_DEVICE_PROTOCOL = 6,
123
B_MAX_PACKET_SIZE0 = 7,
129
I_SERIAL_NUMBER = 16,
130
B_NUM_CONFIGURATIONS = 17
133
#define PIPE_CANCEL 0
136
#define IOCTL_INTERNAL_USB_SUBMIT_URB 0x00220003
137
#define IOCTL_INTERNAL_USB_RESET_PORT 0x00220007
138
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS 0x00220013
139
#define IOCTL_INTERNAL_USB_CYCLE_PORT 0x0022001F
140
#define IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION 0x00220027
144
#define URB_FUNCTION_SELECT_CONFIGURATION 0x0000
145
#define URB_FUNCTION_SELECT_INTERFACE 0x0001
146
#define URB_FUNCTION_ABORT_PIPE 0x0002
147
#define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL 0x0003
148
#define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL 0x0004
149
#define URB_FUNCTION_GET_FRAME_LENGTH 0x0005
150
#define URB_FUNCTION_SET_FRAME_LENGTH 0x0006
151
#define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER 0x0007
152
#define URB_FUNCTION_CONTROL_TRANSFER 0x0008
153
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER 0x0009
154
#define URB_FUNCTION_ISOCH_TRANSFER 0x000A
155
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 0x000B
156
#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE 0x000C
157
#define URB_FUNCTION_SET_FEATURE_TO_DEVICE 0x000D
158
#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE 0x000E
159
#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT 0x000F
160
#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE 0x0010
161
#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE 0x0011
162
#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT 0x0012
163
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE 0x0013
164
#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE 0x0014
165
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT 0x0015
166
#define URB_FUNCTION_RESERVED_0X0016 0x0016
167
#define URB_FUNCTION_VENDOR_DEVICE 0x0017
168
#define URB_FUNCTION_VENDOR_INTERFACE 0x0018
169
#define URB_FUNCTION_VENDOR_ENDPOINT 0x0019
170
#define URB_FUNCTION_CLASS_DEVICE 0x001A
171
#define URB_FUNCTION_CLASS_INTERFACE 0x001B
172
#define URB_FUNCTION_CLASS_ENDPOINT 0x001C
173
#define URB_FUNCTION_RESERVE_0X001D 0x001D
174
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL 0x001E
175
#define URB_FUNCTION_CLASS_OTHER 0x001F
176
#define URB_FUNCTION_VENDOR_OTHER 0x0020
177
#define URB_FUNCTION_GET_STATUS_FROM_OTHER 0x0021
178
#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER 0x0022
179
#define URB_FUNCTION_SET_FEATURE_TO_OTHER 0x0023
180
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT 0x0024
181
#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT 0x0025
182
#define URB_FUNCTION_GET_CONFIGURATION 0x0026
183
#define URB_FUNCTION_GET_INTERFACE 0x0027
184
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE 0x0028
185
#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE 0x0029
186
#define URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR 0x002A
187
#define URB_FUNCTION_RESERVE_0X002B 0x002B
188
#define URB_FUNCTION_RESERVE_0X002C 0x002C
189
#define URB_FUNCTION_RESERVE_0X002D 0x002D
190
#define URB_FUNCTION_RESERVE_0X002E 0x002E
191
#define URB_FUNCTION_RESERVE_0X002F 0x002F
192
// USB 2.0 calls start at 0x0030
193
#define URB_FUNCTION_SYNC_RESET_PIPE 0x0030
194
#define URB_FUNCTION_SYNC_CLEAR_STALL 0x0031
195
#define URB_FUNCTION_CONTROL_TRANSFER_EX 0x0032
197
#define USBD_STATUS_SUCCESS 0x0
198
#define USBD_STATUS_PENDING 0x40000000
199
#define USBD_STATUS_CANCELED 0xC0010000
201
#define USBD_STATUS_CRC 0xC0000001
202
#define USBD_STATUS_BTSTUFF 0xC0000002
203
#define USBD_STATUS_DATA_TOGGLE_MISMATCH 0xC0000003
204
#define USBD_STATUS_STALL_PID 0xC0000004
205
#define USBD_STATUS_DEV_NOT_RESPONDING 0xC0000005
206
#define USBD_STATUS_PID_CHECK_FAILURE 0xC0000006
207
#define USBD_STATUS_UNEXPECTED_PID 0xC0000007
208
#define USBD_STATUS_DATA_OVERRUN 0xC0000008
209
#define USBD_STATUS_DATA_UNDERRUN 0xC0000009
210
#define USBD_STATUS_RESERVED1 0xC000000A
211
#define USBD_STATUS_RESERVED2 0xC000000B
212
#define USBD_STATUS_BUFFER_OVERRUN 0xC000000C
213
#define USBD_STATUS_BUFFER_UNDERRUN 0xC000000D
216
#define USBD_STATUS_NO_DATA 0xC000000E
218
#define USBD_STATUS_NOT_ACCESSED 0xC000000F
219
#define USBD_STATUS_FIFO 0xC0000010
220
#define USBD_STATUS_XACT_ERROR 0xC0000011
221
#define USBD_STATUS_BABBLE_DETECTED 0xC0000012
222
#define USBD_STATUS_DATA_BUFFER_ERROR 0xC0000013
224
#define USBD_STATUS_NOT_SUPPORTED 0xC0000E00
225
#define USBD_STATUS_BUFFER_TOO_SMALL 0xC0003000
226
#define USBD_STATUS_TIMEOUT 0xC0006000
227
#define USBD_STATUS_DEVICE_GONE 0xC0007000
229
#define USBD_STATUS_NO_MEMORY 0x80000100
230
#define USBD_STATUS_INVALID_URB_FUNCTION 0x80000200
231
#define USBD_STATUS_INVALID_PARAMETER 0x80000300
232
#define USBD_STATUS_REQUEST_FAILED 0x80000500
233
#define USBD_STATUS_INVALID_PIPE_HANDLE 0x80000600
234
#define USBD_STATUS_ERROR_SHORT_TRANSFER 0x80000900
236
// Values for URB TransferFlags Field
240
Set if data moves device->host
242
#define USBD_TRANSFER_DIRECTION 0x00000001
244
This bit if not set indicates that a short packet, and hence,
245
a short transfer is an error condition
247
#define USBD_SHORT_TRANSFER_OK 0x00000002
249
Subit the iso transfer on the next frame
251
#define USBD_START_ISO_TRANSFER_ASAP 0x00000004
252
#define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
255
#define USBD_TRANSFER_DIRECTION_FLAG(flags) ((flags) & USBD_TRANSFER_DIRECTION)
257
#define USBD_TRANSFER_DIRECTION_OUT 0
258
#define USBD_TRANSFER_DIRECTION_IN 1
260
#define VALID_TRANSFER_FLAGS_MASK USBD_SHORT_TRANSFER_OK | \
261
USBD_TRANSFER_DIRECTION | \
262
USBD_START_ISO_TRANSFER_ASAP | \
263
USBD_DEFAULT_PIPE_TRANSFER)
265
#define ENDPOINT_HALT 0x00
266
#define DEVICE_REMOTE_WAKEUP 0x01
269
#define CONTROL_TRANSFER 0x00
270
#define ISOCHRONOUS_TRANSFER 0x01
271
#define BULK_TRANSFER 0x02
272
#define INTERRUPT_TRANSFER 0x03
274
#define ClearHubFeature (0x2000 | LIBUSB_REQUEST_CLEAR_FEATURE)
275
#define ClearPortFeature (0x2300 | LIBUSB_REQUEST_CLEAR_FEATURE)
276
#define GetHubDescriptor (0xa000 | LIBUSB_REQUEST_GET_DESCRIPTOR)
277
#define GetHubStatus (0xa000 | LIBUSB_REQUEST_GET_STATUS)
278
#define GetPortStatus (0xa300 | LIBUSB_REQUEST_GET_STATUS)
279
#define SetHubFeature (0x2000 | LIBUSB_REQUEST_SET_FEATURE)
280
#define SetPortFeature (0x2300 | LIBUSB_REQUEST_SET_FEATURE)
282
#define USBD_PF_CHANGE_MAX_PACKET 0x00000001
283
#define USBD_PF_SHORT_PACKET_OPT 0x00000002
284
#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
285
#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008
287
/* feature request */
288
#define URB_SET_FEATURE 0x00
289
#define URB_CLEAR_FEATURE 0x01
291
#define USBD_PF_CHANGE_MAX_PACKET 0x00000001
292
#define USBD_PF_SHORT_PACKET_OPT 0x00000002
293
#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
294
#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008
296
#define URB_CONTROL_TRANSFER_EXTERNAL 0x1
297
#define URB_CONTROL_TRANSFER_NONEXTERNAL 0x0
299
#define USBFS_URB_SHORT_NOT_OK 0x01
300
#define USBFS_URB_ISO_ASAP 0x02
301
#define USBFS_URB_BULK_CONTINUATION 0x04
302
#define USBFS_URB_QUEUE_BULK 0x10
304
#define URBDRC_DEVICE_INITIALIZED 0x01
305
#define URBDRC_DEVICE_NOT_FOUND 0x02
306
#define URBDRC_DEVICE_SIGNAL_END 0x04
307
#define URBDRC_DEVICE_CHANNEL_CLOSED 0x08
308
#define URBDRC_DEVICE_ALREADY_SEND 0x10
309
#define URBDRC_DEVICE_DETACH_KERNEL 0x20
311
#define UDEVMAN_FLAG_ADD_BY_VID_PID 0x01
312
#define UDEVMAN_FLAG_ADD_BY_ADDR 0x02
313
#define UDEVMAN_FLAG_ADD_BY_AUTO 0x04
314
#define UDEVMAN_FLAG_DEBUG 0x08
316
#define MAX_URB_REQUSET_NUM 0x80
319
#define LLOG(_level, _args) \
320
do { if (_level < LOG_LEVEL) { printf _args ; } } while (0)
321
#define LLOGLN(_level, _args) \
322
do { if (_level < LOG_LEVEL) { printf _args ; printf("\n"); } } while (0)
324
#define dummy_wait_obj(void) do{ sleep(5); } while(0)
325
#define dummy_wait_s_obj(_s) do{ sleep(_s); } while(0)
328
#define WAIT_COMPLETE_SLEEP 10000 /* for cpu high loading */
330
#define urbdrc_get_mstime(_t) do { \
331
struct timeval _tp; \
332
gettimeofday(&_tp, 0); \
333
_t = (_tp.tv_sec * 1000) + (_tp.tv_usec / 1000); \
336
extern int urbdrc_debug;
338
#endif /* __URBDRC_TYPES_H */