FreeRDP
channels/rdpdr.h
1 
23 #ifndef FREERDP_CHANNEL_RDPDR_H
24 #define FREERDP_CHANNEL_RDPDR_H
25 
26 #include <winpr/nt.h>
27 #include <winpr/io.h>
28 #include <winpr/crt.h>
29 #include <winpr/file.h>
30 #include <winpr/synch.h>
31 #include <winpr/thread.h>
32 #include <winpr/stream.h>
33 #include <winpr/interlocked.h>
34 #include <winpr/collections.h>
35 
36 #include <freerdp/api.h>
37 #include <freerdp/types.h>
38 #include <freerdp/settings.h>
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
49 #define RDPDR_CHANNEL_NAME "rdpdr"
50 #define RDPDR_SVC_CHANNEL_NAME "rdpdr"
51 
52 #define RDPDR_DEVICE_IO_REQUEST_LENGTH 24
53 #define RDPDR_DEVICE_IO_RESPONSE_LENGTH 16
54 
55 #define RDPDR_DEVICE_IO_CONTROL_REQ_HDR_LENGTH 32
56 #define RDPDR_DEVICE_IO_CONTROL_RSP_HDR_LENGTH 4
57 
58 #define RDPDR_VERSION_MAJOR 0x0001
59 
60 #define RDPDR_VERSION_MINOR_RDP50 0x0002
61 #define RDPDR_VERSION_MINOR_RDP51 0x0005
62 #define RDPDR_VERSION_MINOR_RDP52 0x000A
63 #define RDPDR_VERSION_MINOR_RDP6X 0x000C
64 #define RDPDR_VERSION_MINOR_RDP10X 0x000D
65 
66 /* RDPDR_HEADER.Component */
67 enum RDPDR_CTYP
68 {
69  RDPDR_CTYP_CORE = 0x4472,
70  RDPDR_CTYP_PRN = 0x5052
71 };
72 
73 /* RDPDR_HEADER.PacketId */
74 enum RDPDR_PAKID
75 {
76  PAKID_CORE_SERVER_ANNOUNCE = 0x496E,
77  PAKID_CORE_CLIENTID_CONFIRM = 0x4343,
78  PAKID_CORE_CLIENT_NAME = 0x434E,
79  PAKID_CORE_DEVICELIST_ANNOUNCE = 0x4441,
80  PAKID_CORE_DEVICE_REPLY = 0x6472,
81  PAKID_CORE_DEVICE_IOREQUEST = 0x4952,
82  PAKID_CORE_DEVICE_IOCOMPLETION = 0x4943,
83  PAKID_CORE_SERVER_CAPABILITY = 0x5350,
84  PAKID_CORE_CLIENT_CAPABILITY = 0x4350,
85  PAKID_CORE_DEVICELIST_REMOVE = 0x444D,
86  PAKID_CORE_USER_LOGGEDON = 0x554C,
87  PAKID_PRN_CACHE_DATA = 0x5043,
88  PAKID_PRN_USING_XPS = 0x5543
89 };
90 
91 /* CAPABILITY_HEADER.CapabilityType */
92 enum RDPDR_CAP_TYPE
93 {
94  CAP_GENERAL_TYPE = 0x0001,
95  CAP_PRINTER_TYPE = 0x0002,
96  CAP_PORT_TYPE = 0x0003,
97  CAP_DRIVE_TYPE = 0x0004,
98  CAP_SMARTCARD_TYPE = 0x0005
99 };
100 
101 /* CAPABILITY_HEADER.Version */
102 enum RDPDR_CAP_VERSION
103 {
104  GENERAL_CAPABILITY_VERSION_01 = 0x00000001,
105  GENERAL_CAPABILITY_VERSION_02 = 0x00000002,
106  PRINT_CAPABILITY_VERSION_01 = 0x00000001,
107  PORT_CAPABILITY_VERSION_01 = 0x00000001,
108  DRIVE_CAPABILITY_VERSION_01 = 0x00000001,
109  DRIVE_CAPABILITY_VERSION_02 = 0x00000002,
110  SMARTCARD_CAPABILITY_VERSION_01 = 0x00000001
111 };
112 
113 /* DR_DEVICE_IOREQUEST.MajorFunction */
114 enum IRP_MJ
115 {
116  IRP_MJ_CREATE = 0x00000000,
117  IRP_MJ_CLOSE = 0x00000002,
118  IRP_MJ_READ = 0x00000003,
119  IRP_MJ_WRITE = 0x00000004,
120  IRP_MJ_DEVICE_CONTROL = 0x0000000E,
121  IRP_MJ_QUERY_VOLUME_INFORMATION = 0x0000000A,
122  IRP_MJ_SET_VOLUME_INFORMATION = 0x0000000B,
123  IRP_MJ_QUERY_INFORMATION = 0x00000005,
124  IRP_MJ_SET_INFORMATION = 0x00000006,
125  IRP_MJ_DIRECTORY_CONTROL = 0x0000000C,
126  IRP_MJ_LOCK_CONTROL = 0x00000011
127 };
128 
129 /* DR_DEVICE_IOREQUEST.MinorFunction */
130 enum IRP_MN
131 {
132  IRP_MN_QUERY_DIRECTORY = 0x00000001,
133  IRP_MN_NOTIFY_CHANGE_DIRECTORY = 0x00000002
134 };
135 
136 /* DR_CREATE_REQ.CreateDisposition */
137 
138 /* DR_CREATE_REQ.CreateOptions [MS-SMB2] */
139 
140 /* DR_CREATE_REQ.DesiredAccess [MS-SMB2] */
141 
142 /* DR_CREATE_RSP.Information */
143 /* DR_DRIVE_CREATE_RSP.DeviceCreateResponse */
144 
145 
146 /* DR_CORE_CLIENT_ANNOUNCE_RSP.VersionMinor */
147 #define RDPDR_MAJOR_RDP_VERSION 1
148 enum RDPDR_MINOR_RDP_VERSION
149 {
150  RDPDR_MINOR_RDP_VERSION_5_0 = 0x0002,
151  RDPDR_MINOR_RDP_VERSION_5_1 = 0x0005,
152  RDPDR_MINOR_RDP_VERSION_5_2 = 0x000A,
153  RDPDR_MINOR_RDP_VERSION_6_X = 0x000C,
154  RDPDR_MINOR_RDP_VERSION_13 = 0x000D
155 };
156 
157 /* DR_CORE_CLIENT_NAME_REQ.UnicodeFlag */
158 enum RDPDR_CLIENT_NAME_FLAG
159 {
160  RDPDR_CLIENT_NAME_UNICODE = 0x00000001,
161  RDPDR_CLIENT_NAME_ASCII = 0x00000000
162 };
163 
164 /* GENERAL_CAPS_SET.ioCode1 */
165 enum RDPDR_CAPS_IRP_MJ
166 {
167  RDPDR_IRP_MJ_CREATE = 0x00000001,
168  RDPDR_IRP_MJ_CLEANUP = 0x00000002,
169  RDPDR_IRP_MJ_CLOSE = 0x00000004,
170  RDPDR_IRP_MJ_READ = 0x00000008,
171  RDPDR_IRP_MJ_WRITE = 0x00000010,
172  RDPDR_IRP_MJ_FLUSH_BUFFERS = 0x00000020,
173  RDPDR_IRP_MJ_SHUTDOWN = 0x00000040,
174  RDPDR_IRP_MJ_DEVICE_CONTROL = 0x00000080,
175  RDPDR_IRP_MJ_QUERY_VOLUME_INFORMATION = 0x00000100,
176  RDPDR_IRP_MJ_SET_VOLUME_INFORMATION = 0x00000200,
177  RDPDR_IRP_MJ_QUERY_INFORMATION = 0x00000400,
178  RDPDR_IRP_MJ_SET_INFORMATION = 0x00000800,
179  RDPDR_IRP_MJ_DIRECTORY_CONTROL = 0x00001000,
180  RDPDR_IRP_MJ_LOCK_CONTROL = 0x00002000,
181  RDPDR_IRP_MJ_QUERY_SECURITY = 0x00004000,
182  RDPDR_IRP_MJ_SET_SECURITY = 0x00008000
183 };
184 
185 /* GENERAL_CAPS_SET.extendedPDU */
186 enum RDPDR_CAPS_PDU
187 {
188  RDPDR_DEVICE_REMOVE_PDUS = 0x00000001,
189  RDPDR_CLIENT_DISPLAY_NAME_PDU = 0x00000002,
190  RDPDR_USER_LOGGEDON_PDU = 0x00000004
191 };
192 
193 /* GENERAL_CAPS_SET.extraFlags1 */
194 enum RDPDR_CAPS_FLAG
195 {
196  ENABLE_ASYNCIO = 0x00000001
197 };
198 
199 /* DR_DRIVE_LOCK_REQ.Operation */
200 enum RDP_LOWIO_OP
201 {
202  RDP_LOWIO_OP_SHAREDLOCK = 0x00000002,
203  RDP_LOWIO_OP_EXCLUSIVELOCK = 0x00000003,
204  RDP_LOWIO_OP_UNLOCK = 0x00000004,
205  RDP_LOWIO_OP_UNLOCK_MULTIPLE = 0x00000005
206 };
207 
208 enum RDPDR_PRINTER_ANNOUNCE_FLAG
209 {
210  RDPDR_PRINTER_ANNOUNCE_FLAG_ASCII = 0x00000001,
211  RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER = 0x00000002,
212  RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER = 0x00000004,
213  RDPDR_PRINTER_ANNOUNCE_FLAG_TSPRINTER = 0x00000008,
214  RDPDR_PRINTER_ANNOUNCE_FLAG_XPSFORMAT = 0x00000010
215 };
216 
217 /* [MS-FSCC] FileAttributes */
218 
219 /* Included with winpr/file.h */
220 
221 /* [MS-FSCC] FSCTL Structures */
222 
223 #if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
224 #define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION 0x1400ec
225 #define FSCTL_PIPE_PEEK 0x11400c
226 #define FSCTL_PIPE_TRANSCEIVE 0x11c017
227 #define FSCTL_PIPE_WAIT 0x110018
228 #define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x9013c
229 #define FSCTL_QUERY_SPARING_INFO 0x90138
230 #endif
231 
232 #ifndef _WIN32
233 #define FSCTL_CREATE_OR_GET_OBJECT_ID 0x900c0
234 #define FSCTL_GET_REPARSE_POINT 0x900a8
235 #define FSCTL_GET_RETRIEVAL_POINTERS 0x90073
236 #define FSCTL_IS_PATHNAME_VALID 0x9002c
237 #define FSCTL_READ_FILE_USN_DATA 0x900eb
238 #define FSCTL_RECALL_FILE 0x90117
239 #define FSCTL_QUERY_FAT_BPB 0x90058
240 #define FSCTL_QUERY_ALLOCATED_RANGES 0x940cf
241 #define FSCTL_SET_COMPRESSION 0x9c040
242 #define FSCTL_SET_ENCRYPTION 0x900D7
243 #define FSCTL_SET_OBJECT_ID 0x90098
244 #define FSCTL_SET_OBJECT_ID_EXTENDED 0x900bc
245 #define FSCTL_SET_REPARSE_POINT 0x900a4
246 #define FSCTL_SET_SPARSE 0x900c4
247 #define FSCTL_SET_ZERO_DATA 0x980c8
248 #define FSCTL_SIS_COPYFILE 0x90100
249 #define FSCTL_WRITE_USN_CLOSE_RECORD 0x900ef
250 #endif
251 
252 #if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
253 #define FSCTL_SET_DEFECT_MANAGEMENT 0x98134
254 #define FSCTL_SET_ZERO_ON_DEALLOCATION 0x90194
255 #endif
256 
257 /* [MS-FSCC] FileFsAttributeInformation.FileSystemAttributes */
258 
259 #ifndef _WIN32
260 
261 #define FILE_SUPPORTS_USN_JOURNAL 0x02000000
262 #define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
263 #define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
264 #define FILE_SUPPORTS_HARD_LINKS 0x00400000
265 #define FILE_SUPPORTS_TRANSACTIONS 0x00200000
266 #define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
267 #define FILE_READ_ONLY_VOLUME 0x00080000
268 #define FILE_NAMED_STREAMS 0x00040000
269 #define FILE_SUPPORTS_ENCRYPTION 0x00020000
270 #define FILE_SUPPORTS_OBJECT_IDS 0x00010000
271 #define FILE_VOLUME_IS_COMPRESSED 0x00008000
272 #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
273 #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
274 #define FILE_SUPPORTS_SPARSE_FILES 0x00000040
275 #define FILE_VOLUME_QUOTAS 0x00000020
276 #define FILE_FILE_COMPRESSION 0x00000010
277 #define FILE_PERSISTENT_ACLS 0x00000008
278 #define FILE_UNICODE_ON_DISK 0x00000004
279 #define FILE_CASE_PRESERVED_NAMES 0x00000002
280 #define FILE_CASE_SENSITIVE_SEARCH 0x00000001
281 
282 #endif
283 
284 /* [MS-FSCC] FileFsDeviceInformation.DeviceType */
285 
286 #ifndef FILE_DEVICE_CD_ROM
287 #define FILE_DEVICE_CD_ROM 0x00000002
288 #endif
289 
290 #ifndef FILE_DEVICE_DISK
291 #define FILE_DEVICE_DISK 0x00000007
292 #endif
293 
294 /* [MS-FSCC] FileFsDeviceInformation.Characteristics */
295 enum FILE_FS_DEVICE_FLAG
296 {
297  FILE_REMOVABLE_MEDIA = 0x00000001,
298  FILE_READ_ONLY_DEVICE = 0x00000002,
299  FILE_FLOPPY_DISKETTE = 0x00000004,
300  FILE_WRITE_ONCE_MEDIA = 0x00000008,
301  FILE_REMOTE_DEVICE = 0x00000010,
302  FILE_DEVICE_IS_MOUNTED = 0x00000020,
303  FILE_VIRTUAL_VOLUME = 0x00000040,
304  FILE_DEVICE_SECURE_OPEN = 0x00000100
305 };
306 
307 #ifndef __MINGW32__
308 enum FILE_FS_INFORMATION_CLASS
309 {
310  FileFsVolumeInformation = 1,
311  FileFsLabelInformation,
312  FileFsSizeInformation,
313  FileFsDeviceInformation,
314  FileFsAttributeInformation,
315  FileFsControlInformation,
316  FileFsFullSizeInformation,
317  FileFsObjectIdInformation,
318  FileFsDriverPathInformation,
319  FileFsMaximumInformation
320 };
321 #endif
322 
323 typedef struct S_DEVICE DEVICE;
324 typedef struct S_IRP IRP;
325 typedef struct S_DEVMAN DEVMAN;
326 
327 typedef UINT (*pcCustomComponentRequest)(DEVICE* device, UINT16 component, UINT16 packetId,
328  wStream* s);
329 typedef UINT (*pcIRPRequest)(DEVICE* device, IRP* irp);
330 typedef UINT (*pcInitDevice)(DEVICE* device);
331 typedef UINT (*pcFreeDevice)(DEVICE* device);
332 
333 struct S_DEVICE
334 {
335  UINT32 id;
336 
337  UINT32 type;
338  const char* name;
339  wStream* data;
340 
341  pcCustomComponentRequest CustomComponentRequest;
342  pcIRPRequest IRPRequest;
343  pcInitDevice Init;
344  pcFreeDevice Free;
345 };
346 
347 typedef UINT (*pcIRPResponse)(IRP* irp);
348 
349 struct S_IRP
350 {
351  WINPR_SLIST_ENTRY ItemEntry;
352 
353  DEVICE* device;
354  DEVMAN* devman;
355  UINT32 FileId;
356  UINT32 CompletionId;
357  UINT32 MajorFunction;
358  UINT32 MinorFunction;
359  wStream* input;
360 
361  UINT32 IoStatus;
362  wStream* output;
363 
364  pcIRPResponse Complete;
365  pcIRPResponse Discard;
366 
367  HANDLE thread;
368  BOOL cancelled;
369 };
370 
371 struct S_DEVMAN
372 {
373  void* plugin;
374  UINT32 id_sequence;
375  wListDictionary* devices;
376 };
377 
378 typedef UINT (*pcRegisterDevice)(DEVMAN* devman, DEVICE* device);
379 
380 typedef struct
381 {
382  DEVMAN* devman;
383 
384  pcRegisterDevice RegisterDevice;
385  RDPDR_DEVICE* device;
386  rdpContext* rdpcontext;
389 
390 typedef UINT(VCAPITYPE* PDEVICE_SERVICE_ENTRY)(PDEVICE_SERVICE_ENTRY_POINTS);
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif /* FREERDP_CHANNEL_RDPDR_H */