]> git.sesse.net Git - rdpsrv/blob - rdp5.c
Reduce small block size to 32x32, and parametrize (#defines instead of hardcoding)
[rdpsrv] / rdp5.c
1 /* -*- c-basic-offset: 8 -*-
2    rdesktop: A Remote Desktop Protocol client.
3    Protocol services - Multipoint Communications Service
4    Copyright (C) Matthew Chapman 1999-2002
5    Copyright (C) Erik Forsberg 2003
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "rdesktop.h"
23
24 extern uint8 *g_next_packet;
25 extern int listen_on_vnc;
26
27 extern uint8 sec_sign_key[16];
28 extern int rc4_key_len;
29
30 /* Initialise secure transport packet */
31 STREAM
32 rdp5_init(int maxlen, BOOL encryption)
33 {
34         int hdrlen;
35         STREAM s;
36
37         hdrlen = encryption ? 11 : 3;
38         s = tcp_init(maxlen + hdrlen);
39         s_push_layer(s, sec_hdr, hdrlen);
40
41         return s;
42 }
43
44 void
45 rdp5_send(STREAM s, BOOL encryption)
46 {
47         int datalen;
48
49         s_pop_layer(s, sec_hdr);
50
51         datalen = s->end - s->p;
52
53         out_uint8(s, encryption ? 0x80 : 0);    // protocol
54         out_uint8(s, 0x80 | (datalen >> 8));
55         out_uint8(s, datalen & 0xff);
56
57         if (encryption) {
58                 datalen -= 11;
59
60                 sec_sign(s->p, 8, sec_sign_key, rc4_key_len, s->p + 8, datalen);
61                 sec_encrypt(s->p + 8, datalen);
62         }
63
64         tcp_send(s);
65 }
66
67 void
68 rdp5_process(STREAM s, BOOL encryption)
69 {
70         uint16 length, count, x, y;
71         uint8 type;
72         uint8 *next;
73
74         if (encryption)
75         {
76                 in_uint8s(s, 8);        /* signature */
77                 sec_decrypt(s->p, s->end - s->p);
78         }
79
80 #if 1
81         printf("RDP5 data:\n");
82         hexdump(s->p, s->end - s->p);
83 #endif
84
85         while (s->p < s->end)
86         {
87                 in_uint8(s, type);
88
89                 switch (type)
90                 {
91                         case 16 ... 31:
92                                 // unknown, but looks like some sort of
93                                 // "count" of how many packets there are
94                                 printf("Unimplemented RDP5 opcode (count?) %d, skipping\n", type);
95                                 break;
96                         case 32: { // mouse
97                                 listen_on_vnc = 1;
98                                 uint16 device_flags, x, y;
99                                 static int mouse1_down = 0, mouse2_down = 0;
100
101                                 in_uint16_le(s, device_flags);
102                                 in_uint16_le(s, x);
103                                 in_uint16_le(s, y);
104                                 
105                                 printf("- Type: Mouse\n");
106                                 printf("- Device flags: %x\n", device_flags);
107                                 printf("- Position: (%u,%u)\n", x, y);
108
109                                 if (device_flags & MOUSE_FLAG_BUTTON1)
110                                         mouse1_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x01 : 0;
111                                 if (device_flags & MOUSE_FLAG_BUTTON2)
112                                         mouse2_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x02 : 0;
113
114                                 printf("button mask = %x\n", mouse1_down | mouse2_down);
115
116                         /*      buf[0] = 5; // message type
117                                 buf[1] = mouse1_down | mouse2_down; // button mask
118                                 buf[2] = param1 >> 8;
119                                 buf[3] = param1 & 0xff;
120                                 buf[4] = param2 >> 8;
121                                 buf[5] = param2 & 0xff;
122                                 write(vnc_sock, buf, 6); */
123
124                                 break;
125                         }
126                         default:
127                                 printf("Unimplemented RDP5 opcode %d\n", type);
128                                 return;
129                 }
130         }
131 }