1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - RDP layer |
Protocol services - RDP layer |
4 |
Copyright (C) Matthew Chapman 1999-2001 |
Copyright (C) Matthew Chapman 1999-2002 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
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 |
it under the terms of the GNU General Public License as published by |
30 |
uint8 *next_packet; |
uint8 *next_packet; |
31 |
uint32 rdp_shareid; |
uint32 rdp_shareid; |
32 |
|
|
33 |
|
#if WITH_DEBUG |
34 |
|
static uint32 packetno; |
35 |
|
#endif |
36 |
|
|
37 |
/* Initialise an RDP packet */ |
/* Initialise an RDP packet */ |
38 |
static STREAM |
static STREAM |
39 |
rdp_init(int maxlen) |
rdp_init(int maxlen) |
83 |
} |
} |
84 |
|
|
85 |
in_uint16_le(rdp_s, length); |
in_uint16_le(rdp_s, length); |
86 |
|
/* 32k packets are really 8, keepalive fix */ |
87 |
|
if (length == 0x8000) |
88 |
|
{ |
89 |
|
next_packet += 8; |
90 |
|
*type = 0; |
91 |
|
return rdp_s; |
92 |
|
} |
93 |
in_uint16_le(rdp_s, pdu_type); |
in_uint16_le(rdp_s, pdu_type); |
94 |
in_uint8s(rdp_s, 2); /* userid */ |
in_uint8s(rdp_s, 2); /* userid */ |
95 |
*type = pdu_type & 0xf; |
*type = pdu_type & 0xf; |
96 |
|
|
97 |
#if WITH_DEBUG |
#if WITH_DEBUG |
98 |
DEBUG(("RDP packet (type %x):\n", *type)); |
DEBUG(("RDP packet #%d, (type %x):\n", ++packetno, *type)); |
99 |
hexdump(next_packet, length); |
hexdump(next_packet, length); |
100 |
#endif /* */ |
#endif /* */ |
101 |
|
|
207 |
|
|
208 |
/* Send a synchronisation PDU */ |
/* Send a synchronisation PDU */ |
209 |
static void |
static void |
210 |
rdp_send_synchronise() |
rdp_send_synchronise(void) |
211 |
{ |
{ |
212 |
STREAM s; |
STREAM s; |
213 |
|
|
445 |
|
|
446 |
/* Send a confirm active PDU */ |
/* Send a confirm active PDU */ |
447 |
static void |
static void |
448 |
rdp_send_confirm_active() |
rdp_send_confirm_active(void) |
449 |
{ |
{ |
450 |
STREAM s; |
STREAM s; |
451 |
uint16 caplen = |
uint16 caplen = |
556 |
{ |
{ |
557 |
uint16 num_updates; |
uint16 num_updates; |
558 |
uint16 left, top, right, bottom, width, height; |
uint16 left, top, right, bottom, width, height; |
559 |
uint16 cx, cy, bpp, compress, bufsize, size; |
uint16 cx, cy, bpp, Bpp, compress, bufsize, size; |
560 |
uint8 *data, *bmpdata; |
uint8 *data, *bmpdata; |
561 |
int i; |
int i; |
562 |
|
|
571 |
in_uint16_le(s, width); |
in_uint16_le(s, width); |
572 |
in_uint16_le(s, height); |
in_uint16_le(s, height); |
573 |
in_uint16_le(s, bpp); |
in_uint16_le(s, bpp); |
574 |
|
Bpp = (bpp + 7) / 8; |
575 |
in_uint16_le(s, compress); |
in_uint16_le(s, compress); |
576 |
in_uint16_le(s, bufsize); |
in_uint16_le(s, bufsize); |
577 |
|
|
584 |
if (!compress) |
if (!compress) |
585 |
{ |
{ |
586 |
int y; |
int y; |
587 |
bmpdata = xmalloc(width * height); |
bmpdata = xmalloc(width * height * Bpp); |
588 |
for (y = 0; y < height; y++) |
for (y = 0; y < height; y++) |
589 |
{ |
{ |
590 |
in_uint8a(s, &bmpdata[(height - y - 1) * width], width); |
in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)], |
591 |
|
width * Bpp); |
592 |
} |
} |
593 |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
594 |
xfree(bmpdata); |
xfree(bmpdata); |
599 |
in_uint16_le(s, size); |
in_uint16_le(s, size); |
600 |
in_uint8s(s, 4); /* line_size, final_size */ |
in_uint8s(s, 4); /* line_size, final_size */ |
601 |
in_uint8p(s, data, size); |
in_uint8p(s, data, size); |
602 |
|
bmpdata = xmalloc(width * height * Bpp); |
603 |
bmpdata = xmalloc(width * height); |
if (bitmap_decompress(bmpdata, width, height, data, size, Bpp)) |
|
if (bitmap_decompress(bmpdata, width, height, data, size)) |
|
604 |
{ |
{ |
605 |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
606 |
} |
} |
|
|
|
607 |
xfree(bmpdata); |
xfree(bmpdata); |
608 |
} |
} |
609 |
} |
} |
612 |
static void |
static void |
613 |
process_palette(STREAM s) |
process_palette(STREAM s) |
614 |
{ |
{ |
615 |
HCOLOURMAP hmap; |
COLOURENTRY *entry; |
616 |
COLOURMAP map; |
COLOURMAP map; |
617 |
uint8 *colours; |
HCOLOURMAP hmap; |
618 |
|
int i; |
619 |
|
|
620 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
621 |
in_uint16_le(s, map.ncolours); |
in_uint16_le(s, map.ncolours); |
622 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
623 |
in_uint8p(s, colours, (map.ncolours * 3)); |
|
624 |
map.colours = (COLOURENTRY *) colours; |
map.colours = xmalloc(3 * map.ncolours); |
625 |
|
|
626 |
|
for (i = 0; i < map.ncolours; i++) |
627 |
|
{ |
628 |
|
entry = &map.colours[i]; |
629 |
|
in_uint8(s, entry->red); |
630 |
|
in_uint8(s, entry->green); |
631 |
|
in_uint8(s, entry->blue); |
632 |
|
} |
633 |
|
|
634 |
hmap = ui_create_colourmap(&map); |
hmap = ui_create_colourmap(&map); |
635 |
ui_set_colourmap(hmap); |
ui_set_colourmap(hmap); |
636 |
|
|
637 |
|
xfree(map.colours); |
638 |
} |
} |
639 |
|
|
640 |
/* Process an update PDU */ |
/* Process an update PDU */ |
703 |
|
|
704 |
/* Process incoming packets */ |
/* Process incoming packets */ |
705 |
void |
void |
706 |
rdp_main_loop() |
rdp_main_loop(void) |
707 |
{ |
{ |
708 |
uint8 type; |
uint8 type; |
709 |
STREAM s; |
STREAM s; |
723 |
process_data_pdu(s); |
process_data_pdu(s); |
724 |
break; |
break; |
725 |
|
|
726 |
|
case 0: |
727 |
|
break; |
728 |
|
|
729 |
default: |
default: |
730 |
unimpl("PDU %d\n", type); |
unimpl("PDU %d\n", type); |
731 |
} |
} |
746 |
|
|
747 |
/* Disconnect from the RDP layer */ |
/* Disconnect from the RDP layer */ |
748 |
void |
void |
749 |
rdp_disconnect() |
rdp_disconnect(void) |
750 |
{ |
{ |
751 |
sec_disconnect(); |
sec_disconnect(); |
752 |
} |
} |