1 |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - RDP layer |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
5 |
|
6 |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2 of the License, or |
9 |
(at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
enum RDP_PDU_TYPE |
22 |
{ |
23 |
RDP_PDU_DEMAND_ACTIVE = 1, |
24 |
RDP_PDU_CONFIRM_ACTIVE = 3, |
25 |
RDP_PDU_DEACTIVATE = 6, |
26 |
RDP_PDU_DATA = 7 |
27 |
}; |
28 |
|
29 |
enum RDP_DATA_PDU_TYPE |
30 |
{ |
31 |
RDP_DATA_PDU_UPDATE = 2, |
32 |
RDP_DATA_PDU_CONTROL = 20, |
33 |
RDP_DATA_PDU_POINTER = 27, |
34 |
RDP_DATA_PDU_INPUT = 28, |
35 |
RDP_DATA_PDU_SYNCHRONIZE = 31, |
36 |
RDP_DATA_PDU_FONT2 = 39 |
37 |
}; |
38 |
|
39 |
typedef struct _RDP_HEADER |
40 |
{ |
41 |
uint16 length; |
42 |
uint16 pdu_type; |
43 |
uint16 userid; |
44 |
|
45 |
} RDP_HEADER; |
46 |
|
47 |
typedef struct _RDP_DATA_HEADER |
48 |
{ |
49 |
uint32 shareid; |
50 |
uint8 pad; |
51 |
uint8 streamid; |
52 |
uint16 length; |
53 |
uint8 data_pdu_type; |
54 |
uint8 compress_type; |
55 |
uint16 compress_len; |
56 |
|
57 |
} RDP_DATA_HEADER; |
58 |
|
59 |
#define RDP_CAPSET_GENERAL 1 |
60 |
#define RDP_CAPLEN_GENERAL 0x18 |
61 |
#define OS_MAJOR_TYPE_UNIX 4 |
62 |
#define OS_MINOR_TYPE_XSERVER 7 |
63 |
|
64 |
typedef struct _RDP_GENERAL_CAPS |
65 |
{ |
66 |
uint16 os_major_type; |
67 |
uint16 os_minor_type; |
68 |
uint16 ver_protocol; |
69 |
uint16 pad1; |
70 |
uint16 compress_types; |
71 |
uint16 pad2; |
72 |
uint16 cap_update; |
73 |
uint16 remote_unshare; |
74 |
uint16 compress_level; |
75 |
uint16 pad3; |
76 |
|
77 |
} RDP_GENERAL_CAPS; |
78 |
|
79 |
#define RDP_CAPSET_BITMAP 2 |
80 |
#define RDP_CAPLEN_BITMAP 0x1C |
81 |
|
82 |
typedef struct _RDP_BITMAP_CAPS |
83 |
{ |
84 |
uint16 preferred_bpp; |
85 |
uint16 receive1bpp; |
86 |
uint16 receive4bpp; |
87 |
uint16 receive8bpp; |
88 |
uint16 width; |
89 |
uint16 height; |
90 |
uint16 pad1; |
91 |
uint16 allow_resize; |
92 |
uint16 compression; |
93 |
uint16 unknown1; |
94 |
uint16 unknown2; |
95 |
uint16 pad2; |
96 |
|
97 |
} RDP_BITMAP_CAPS; |
98 |
|
99 |
#define RDP_CAPSET_ORDER 3 |
100 |
#define RDP_CAPLEN_ORDER 0x58 |
101 |
#define ORDER_CAP_NEGOTIATE 2 |
102 |
#define ORDER_CAP_NOSUPPORT 4 |
103 |
|
104 |
typedef struct _RDP_ORDER_CAPS |
105 |
{ |
106 |
uint8 terminal_desc[16]; |
107 |
uint32 pad1; |
108 |
uint16 xgranularity; // 1 |
109 |
uint16 ygranularity; // 20 |
110 |
uint16 pad2; |
111 |
uint16 max_order_level; |
112 |
uint16 num_fonts; // 0x2C |
113 |
uint16 cap_flags; // 0x22 |
114 |
uint8 support[32]; |
115 |
uint16 text_cap_flags; // 0x6A1 |
116 |
uint16 pad3; |
117 |
uint32 pad4; |
118 |
uint32 desk_save_size; |
119 |
uint32 unknown1; // 1 from server, 0 from client |
120 |
uint32 unknown2; // 0x4E4 from client |
121 |
|
122 |
} RDP_ORDER_CAPS; |
123 |
|
124 |
#define RDP_CAPSET_BMPCACHE 4 |
125 |
#define RDP_CAPLEN_BMPCACHE 0x28 |
126 |
|
127 |
typedef struct _RDP_BMPCACHE_INFO |
128 |
{ |
129 |
uint16 entries; |
130 |
uint16 max_cell_size; |
131 |
|
132 |
} RDP_BMPCACHE_INFO; |
133 |
|
134 |
typedef struct _RDP_BMPCACHE_CAPS |
135 |
{ |
136 |
uint32 unused[6]; |
137 |
RDP_BMPCACHE_INFO caches[3]; |
138 |
|
139 |
} RDP_BMPCACHE_CAPS; |
140 |
|
141 |
#define RDP_CAPSET_CONTROL 5 |
142 |
#define RDP_CAPLEN_CONTROL 0x0C |
143 |
|
144 |
typedef struct _RDP_CONTROL_CAPS |
145 |
{ |
146 |
uint16 control_caps; |
147 |
uint16 remote_detach; |
148 |
uint16 control_interest; |
149 |
uint16 detach_interest; |
150 |
|
151 |
} RDP_CONTROL_CAPS; |
152 |
|
153 |
#define RDP_CAPSET_ACTIVATE 7 |
154 |
#define RDP_CAPLEN_ACTIVATE 0x0C |
155 |
|
156 |
typedef struct _RDP_ACTIVATE_CAPS |
157 |
{ |
158 |
uint16 help_key; |
159 |
uint16 help_index_key; |
160 |
uint16 help_extended_key; |
161 |
uint16 window_activate; |
162 |
|
163 |
} RDP_ACTIVATE_CAPS; |
164 |
|
165 |
#define RDP_CAPSET_POINTER 8 |
166 |
#define RDP_CAPLEN_POINTER 0x08 |
167 |
|
168 |
typedef struct _RDP_POINTER_CAPS |
169 |
{ |
170 |
uint16 colour_pointer; |
171 |
uint16 cache_size; |
172 |
|
173 |
} RDP_POINTER_CAPS; |
174 |
|
175 |
#define RDP_CAPSET_SHARE 9 |
176 |
#define RDP_CAPLEN_SHARE 0x08 |
177 |
|
178 |
typedef struct _RDP_SHARE_CAPS |
179 |
{ |
180 |
uint16 userid; |
181 |
uint16 pad; |
182 |
|
183 |
} RDP_SHARE_CAPS; |
184 |
|
185 |
#define RDP_CAPSET_COLCACHE 10 |
186 |
#define RDP_CAPLEN_COLCACHE 0x08 |
187 |
|
188 |
typedef struct _RDP_COLCACHE_CAPS |
189 |
{ |
190 |
uint16 cache_size; |
191 |
uint16 pad; |
192 |
|
193 |
} RDP_COLCACHE_CAPS; |
194 |
|
195 |
#define RDP_CAPSET_UNKNOWN 13 |
196 |
#define RDP_CAPLEN_UNKNOWN 0x9C |
197 |
|
198 |
#define RDP_SOURCE "MSTSC" |
199 |
|
200 |
typedef struct _RDP_ACTIVE_PDU |
201 |
{ |
202 |
uint32 shareid; |
203 |
uint16 userid; // RDP_PDU_CONFIRM_ACTIVE only |
204 |
uint16 source_len; |
205 |
uint16 caps_len; |
206 |
uint8 source[48]; |
207 |
uint16 num_caps; |
208 |
uint16 pad; |
209 |
|
210 |
RDP_GENERAL_CAPS general_caps; |
211 |
RDP_BITMAP_CAPS bitmap_caps; |
212 |
RDP_ORDER_CAPS order_caps; |
213 |
RDP_BMPCACHE_CAPS bmpcache_caps; |
214 |
RDP_ACTIVATE_CAPS activate_caps; |
215 |
RDP_CONTROL_CAPS control_caps; |
216 |
RDP_POINTER_CAPS pointer_caps; |
217 |
RDP_SHARE_CAPS share_caps; |
218 |
RDP_COLCACHE_CAPS colcache_caps; |
219 |
|
220 |
} RDP_ACTIVE_PDU; |
221 |
|
222 |
typedef struct _RDP_SYNCHRONISE_PDU |
223 |
{ |
224 |
uint16 type; // 1 |
225 |
uint16 userid; |
226 |
|
227 |
} RDP_SYNCHRONISE_PDU; |
228 |
|
229 |
#define RDP_CTL_REQUEST_CONTROL 1 |
230 |
#define RDP_CTL_GRANT_CONTROL 2 |
231 |
#define RDP_CTL_DETACH 3 |
232 |
#define RDP_CTL_COOPERATE 4 |
233 |
|
234 |
typedef struct _RDP_CONTROL_PDU |
235 |
{ |
236 |
uint16 action; // see above |
237 |
uint16 userid; |
238 |
uint32 controlid; |
239 |
|
240 |
} RDP_CONTROL_PDU; |
241 |
|
242 |
#define RDP_INPUT_SYNCHRONIZE 0 |
243 |
#define RDP_INPUT_CODEPOINT 1 |
244 |
#define RDP_INPUT_VIRTKEY 2 |
245 |
#define RDP_INPUT_SCANCODE 4 |
246 |
#define RDP_INPUT_MOUSE 0x8001 |
247 |
|
248 |
#define KBD_FLAG_RIGHT 0x0001 |
249 |
#define KBD_FLAG_QUIET 0x1000 |
250 |
#define KBD_FLAG_DOWN 0x4000 |
251 |
#define KBD_FLAG_UP 0x8000 |
252 |
|
253 |
#define MOUSE_FLAG_MOVE 0x0800 |
254 |
#define MOUSE_FLAG_BUTTON1 0x1000 |
255 |
#define MOUSE_FLAG_BUTTON2 0x2000 |
256 |
#define MOUSE_FLAG_BUTTON3 0x4000 |
257 |
#define MOUSE_FLAG_DOWN 0x8000 |
258 |
|
259 |
#define RDP_MAX_EVENTS 50 |
260 |
|
261 |
typedef struct _RDP_INPUT_EVENT |
262 |
{ |
263 |
uint32 event_time; |
264 |
uint16 message_type; |
265 |
uint16 device_flags; |
266 |
uint16 param1; |
267 |
uint16 param2; |
268 |
|
269 |
} RDP_INPUT_EVENT; |
270 |
|
271 |
typedef struct _RDP_INPUT_PDU |
272 |
{ |
273 |
uint16 num_events; |
274 |
uint16 pad; |
275 |
RDP_INPUT_EVENT event[RDP_MAX_EVENTS]; |
276 |
|
277 |
} RDP_INPUT_PDU; |
278 |
|
279 |
#define RDP_FONT_INFO_SIZE 0x32 |
280 |
#define RDP_MAX_FONTS 100 |
281 |
|
282 |
typedef struct _RDP_FONT_INFO |
283 |
{ |
284 |
uint8 name[32]; |
285 |
uint16 flags; |
286 |
uint16 width; |
287 |
uint16 height; |
288 |
uint16 xaspect; |
289 |
uint16 yaspect; |
290 |
uint32 signature; |
291 |
uint16 codepage; |
292 |
uint16 ascent; |
293 |
|
294 |
} RDP_FONT_INFO; |
295 |
|
296 |
typedef struct _RDP_FONT_PDU |
297 |
{ |
298 |
uint16 num_fonts; |
299 |
uint16 unknown1; // 0x3e |
300 |
uint16 unknown2; // series number? |
301 |
uint16 entry_size; |
302 |
RDP_FONT_INFO font[RDP_MAX_FONTS]; |
303 |
|
304 |
} RDP_FONT_PDU; |
305 |
|
306 |
#define RDP_UPDATE_ORDERS 0 |
307 |
#define RDP_UPDATE_PALETTE 2 |
308 |
#define RDP_UPDATE_SYNCHRONIZE 3 |
309 |
|
310 |
typedef struct _DESTBLT_ORDER |
311 |
{ |
312 |
uint16 x; |
313 |
uint16 y; |
314 |
uint16 cx; |
315 |
uint16 cy; |
316 |
uint8 opcode; |
317 |
|
318 |
} DESTBLT_ORDER; |
319 |
|
320 |
typedef struct _PATBLT_ORDER |
321 |
{ |
322 |
uint16 x; |
323 |
uint16 y; |
324 |
uint16 cx; |
325 |
uint16 cy; |
326 |
uint8 opcode; |
327 |
uint8 bgcolour; |
328 |
uint8 fgcolour; |
329 |
BRUSH brush; |
330 |
|
331 |
} PATBLT_ORDER; |
332 |
|
333 |
typedef struct _SCREENBLT_ORDER |
334 |
{ |
335 |
uint16 x; |
336 |
uint16 y; |
337 |
uint16 cx; |
338 |
uint16 cy; |
339 |
uint8 opcode; |
340 |
uint16 srcx; |
341 |
uint16 srcy; |
342 |
|
343 |
} SCREENBLT_ORDER; |
344 |
|
345 |
typedef struct _LINE_ORDER |
346 |
{ |
347 |
uint16 mixmode; |
348 |
uint16 startx; |
349 |
uint16 starty; |
350 |
uint16 endx; |
351 |
uint16 endy; |
352 |
uint8 bgcolour; |
353 |
uint8 opcode; |
354 |
PEN pen; |
355 |
|
356 |
} LINE_ORDER; |
357 |
|
358 |
typedef struct _RECT_ORDER |
359 |
{ |
360 |
uint16 x; |
361 |
uint16 y; |
362 |
uint16 cx; |
363 |
uint16 cy; |
364 |
uint8 colour; |
365 |
|
366 |
} RECT_ORDER; |
367 |
|
368 |
typedef struct _DESKSAVE_ORDER |
369 |
{ |
370 |
uint32 offset; |
371 |
uint16 left; |
372 |
uint16 top; |
373 |
uint16 right; |
374 |
uint16 bottom; |
375 |
uint8 action; |
376 |
|
377 |
} DESKSAVE_ORDER; |
378 |
|
379 |
typedef struct _TRIBLT_ORDER |
380 |
{ |
381 |
uint8 colour_table; |
382 |
uint8 cache_id; |
383 |
uint16 x; |
384 |
uint16 y; |
385 |
uint16 cx; |
386 |
uint16 cy; |
387 |
uint8 opcode; |
388 |
uint16 srcx; |
389 |
uint16 srcy; |
390 |
uint8 bgcolour; |
391 |
uint8 fgcolour; |
392 |
BRUSH brush; |
393 |
uint16 cache_idx; |
394 |
uint16 unknown; |
395 |
|
396 |
} TRIBLT_ORDER; |
397 |
|
398 |
typedef struct _MEMBLT_ORDER |
399 |
{ |
400 |
uint8 colour_table; |
401 |
uint8 cache_id; |
402 |
uint16 x; |
403 |
uint16 y; |
404 |
uint16 cx; |
405 |
uint16 cy; |
406 |
uint8 opcode; |
407 |
uint16 srcx; |
408 |
uint16 srcy; |
409 |
uint16 cache_idx; |
410 |
|
411 |
} MEMBLT_ORDER; |
412 |
|
413 |
#define MAX_TEXT 256 |
414 |
|
415 |
#define MIX_TRANSPARENT 0 |
416 |
#define MIX_OPAQUE 1 |
417 |
|
418 |
#define TEXT2_IMPLICIT_X 0x20 |
419 |
|
420 |
typedef struct _TEXT2_ORDER |
421 |
{ |
422 |
uint8 font; |
423 |
uint8 flags; |
424 |
uint8 mixmode; |
425 |
uint8 unknown; |
426 |
uint8 fgcolour; |
427 |
uint8 bgcolour; |
428 |
uint16 clipleft; |
429 |
uint16 cliptop; |
430 |
uint16 clipright; |
431 |
uint16 clipbottom; |
432 |
uint16 boxleft; |
433 |
uint16 boxtop; |
434 |
uint16 boxright; |
435 |
uint16 boxbottom; |
436 |
uint16 x; |
437 |
uint16 y; |
438 |
uint8 length; |
439 |
uint8 text[MAX_TEXT]; |
440 |
|
441 |
} TEXT2_ORDER; |
442 |
|
443 |
typedef struct _RDP_ORDER_STATE |
444 |
{ |
445 |
uint8 order_type; |
446 |
BOUNDS bounds; |
447 |
|
448 |
DESTBLT_ORDER destblt; |
449 |
PATBLT_ORDER patblt; |
450 |
SCREENBLT_ORDER screenblt; |
451 |
LINE_ORDER line; |
452 |
RECT_ORDER rect; |
453 |
DESKSAVE_ORDER desksave; |
454 |
MEMBLT_ORDER memblt; |
455 |
TRIBLT_ORDER triblt; |
456 |
TEXT2_ORDER text2; |
457 |
|
458 |
} RDP_ORDER_STATE; |
459 |
|
460 |
typedef struct _RDP_UPDATE_PDU |
461 |
{ |
462 |
uint16 update_type; |
463 |
uint16 pad; |
464 |
|
465 |
} RDP_UPDATE_PDU; |
466 |
|
467 |
#define RDP_ORDER_STANDARD 0x01 |
468 |
#define RDP_ORDER_SECONDARY 0x02 |
469 |
#define RDP_ORDER_BOUNDS 0x04 |
470 |
#define RDP_ORDER_CHANGE 0x08 |
471 |
#define RDP_ORDER_DELTA 0x10 |
472 |
#define RDP_ORDER_LASTBOUNDS 0x20 |
473 |
#define RDP_ORDER_SMALL 0x40 |
474 |
#define RDP_ORDER_TINY 0x80 |
475 |
|
476 |
enum RDP_ORDER_TYPE |
477 |
{ |
478 |
RDP_ORDER_DESTBLT = 0, |
479 |
RDP_ORDER_PATBLT = 1, |
480 |
RDP_ORDER_SCREENBLT = 2, |
481 |
RDP_ORDER_LINE = 9, |
482 |
RDP_ORDER_RECT = 10, |
483 |
RDP_ORDER_DESKSAVE = 11, |
484 |
RDP_ORDER_MEMBLT = 13, |
485 |
RDP_ORDER_TRIBLT = 14, |
486 |
RDP_ORDER_TEXT2 = 27 |
487 |
}; |
488 |
|
489 |
enum RDP_SECONDARY_ORDER_TYPE |
490 |
{ |
491 |
RDP_ORDER_RAW_BMPCACHE = 0, |
492 |
RDP_ORDER_COLCACHE = 1, |
493 |
RDP_ORDER_BMPCACHE = 2, |
494 |
RDP_ORDER_FONTCACHE = 3 |
495 |
}; |
496 |
|
497 |
typedef struct _RDP_SECONDARY_ORDER |
498 |
{ |
499 |
uint16 length; |
500 |
uint16 flags; |
501 |
uint8 type; |
502 |
|
503 |
} RDP_SECONDARY_ORDER; |
504 |
|
505 |
typedef struct _RDP_RAW_BMPCACHE_ORDER |
506 |
{ |
507 |
uint8 cache_id; |
508 |
uint8 pad1; |
509 |
uint8 width; |
510 |
uint8 height; |
511 |
uint8 bpp; |
512 |
uint16 bufsize; |
513 |
uint16 cache_idx; |
514 |
uint8 *data; |
515 |
|
516 |
} RDP_RAW_BMPCACHE_ORDER; |
517 |
|
518 |
typedef struct _RDP_BMPCACHE_ORDER |
519 |
{ |
520 |
uint8 cache_id; |
521 |
uint8 pad1; |
522 |
uint8 width; |
523 |
uint8 height; |
524 |
uint8 bpp; |
525 |
uint16 bufsize; |
526 |
uint16 cache_idx; |
527 |
uint16 pad2; |
528 |
uint16 size; |
529 |
uint16 row_size; |
530 |
uint16 final_size; |
531 |
uint8 *data; |
532 |
|
533 |
} RDP_BMPCACHE_ORDER; |
534 |
|
535 |
#define MAX_GLYPH 32 |
536 |
|
537 |
typedef struct _RDP_FONT_GLYPH |
538 |
{ |
539 |
uint16 character; |
540 |
uint16 unknown; |
541 |
uint16 baseline; |
542 |
uint16 width; |
543 |
uint16 height; |
544 |
uint8 data[MAX_GLYPH]; |
545 |
|
546 |
} RDP_FONT_GLYPH; |
547 |
|
548 |
#define MAX_GLYPHS 256 |
549 |
|
550 |
typedef struct _RDP_FONTCACHE_ORDER |
551 |
{ |
552 |
uint8 font; |
553 |
uint8 nglyphs; |
554 |
RDP_FONT_GLYPH glyphs[MAX_GLYPHS]; |
555 |
|
556 |
} RDP_FONTCACHE_ORDER; |
557 |
|
558 |
typedef struct _RDP_COLCACHE_ORDER |
559 |
{ |
560 |
uint8 cache_id; |
561 |
COLOURMAP map; |
562 |
|
563 |
} RDP_COLCACHE_ORDER; |
564 |
|
565 |
#define RDP_POINTER_MOVE 3 |
566 |
|
567 |
typedef struct _RDP_POINTER_PDU |
568 |
{ |
569 |
uint16 message; |
570 |
uint16 pad; |
571 |
uint16 x; |
572 |
uint16 y; |
573 |
|
574 |
} RDP_POINTER_PDU; |
575 |
|