/[rdesktop]/sourceforge.net/trunk/rdesktop/rdp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by matty, Tue Aug 15 10:23:24 2000 UTC revision 176 by n-ki, Tue Sep 17 09:55:03 2002 UTC
# Line 1  Line 1 
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-2000     Copyright (C) Matthew Chapman 1999-2001
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
# Line 22  Line 22 
22    
23  extern uint16 mcs_userid;  extern uint16 mcs_userid;
24  extern char username[16];  extern char username[16];
25    extern BOOL bitmap_compression;
26  extern BOOL orders;  extern BOOL orders;
27    extern BOOL encryption;
28    extern BOOL desktop_save;
29    
30  unsigned char *next_packet;  uint8 *next_packet;
31  uint32 rdp_shareid;  uint32 rdp_shareid;
32    
33  /* Initialise an RDP packet */  /* Initialise an RDP packet */
34  static STREAM rdp_init(int maxlen)  static STREAM
35    rdp_init(int maxlen)
36  {  {
37          STREAM s;          STREAM s;
38    
39          s = sec_init(SEC_ENCRYPT, maxlen + 6);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 6);
40          s_push_layer(s, rdp_hdr, 6);          s_push_layer(s, rdp_hdr, 6);
41    
42          return s;          return s;
43  }  }
44    
45  /* Send an RDP packet */  /* Send an RDP packet */
46  static void rdp_send(STREAM s, uint8 pdu_type)  static void
47    rdp_send(STREAM s, uint8 pdu_type)
48  {  {
49          uint16 length;          uint16 length;
50    
# Line 47  static void rdp_send(STREAM s, uint8 pdu Line 52  static void rdp_send(STREAM s, uint8 pdu
52          length = s->end - s->p;          length = s->end - s->p;
53    
54          out_uint16_le(s, length);          out_uint16_le(s, length);
55          out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */          out_uint16_le(s, (pdu_type | 0x10));    /* Version 1 */
56          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
57    
58          sec_send(s, SEC_ENCRYPT);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
59  }  }
60    
61  /* Receive an RDP packet */  /* Receive an RDP packet */
62  static STREAM rdp_recv(uint8 *type)  static STREAM
63    rdp_recv(uint8 * type)
64  {  {
65          static STREAM rdp_s;          static STREAM rdp_s;
66          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 74  static STREAM rdp_recv(uint8 *type) Line 80  static STREAM rdp_recv(uint8 *type)
80    
81          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
82          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
83          in_uint8s(rdp_s, 2); /* userid */          in_uint8s(rdp_s, 2);    /* userid */
   
         next_packet += length;  
84          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
85    
86  #if RDP_DEBUG  #if WITH_DEBUG
87          DEBUG("RDP packet (type %x):\n", *type);          DEBUG(("RDP packet (type %x):\n", *type));
88          hexdump(rdp_s->p, length);          hexdump(next_packet, length);
89  #endif  #endif /*  */
90    
91            next_packet += length;
92          return rdp_s;          return rdp_s;
93  }  }
94    
95  /* Initialise an RDP data packet */  /* Initialise an RDP data packet */
96  static STREAM rdp_init_data(int maxlen)  static STREAM
97    rdp_init_data(int maxlen)
98  {  {
99          STREAM s;          STREAM s;
100    
101          s = sec_init(SEC_ENCRYPT, maxlen + 18);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18);
102          s_push_layer(s, rdp_hdr, 18);          s_push_layer(s, rdp_hdr, 18);
103    
104          return s;          return s;
105  }  }
106    
107  /* Send an RDP data packet */  /* Send an RDP data packet */
108  static void rdp_send_data(STREAM s, uint8 data_pdu_type)  static void
109    rdp_send_data(STREAM s, uint8 data_pdu_type)
110  {  {
111          uint16 length;          uint16 length;
112    
# Line 111  static void rdp_send_data(STREAM s, uint Line 118  static void rdp_send_data(STREAM s, uint
118          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
119    
120          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
121          out_uint8(s, 0);  /* pad */          out_uint8(s, 0);        /* pad */
122          out_uint8(s, 1);  /* streamid */          out_uint8(s, 1);        /* streamid */
123          out_uint16(s, (length - 14));          out_uint16_le(s, (length - 14));
124          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
125          out_uint8(s, 0);  /* compress_type */          out_uint8(s, 0);        /* compress_type */
126          out_uint16(s, 0); /* compress_len */          out_uint16(s, 0);       /* compress_len */
127    
128          sec_send(s, SEC_ENCRYPT);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
129  }  }
130    
131  /* Output a string in Unicode */  /* Output a string in Unicode */
132  void rdp_out_unistr(STREAM s, char *string, int len)  void
133    rdp_out_unistr(STREAM s, char *string, int len)
134  {  {
135          int i = 0, j = 0;          int i = 0, j = 0;
136    
# Line 138  void rdp_out_unistr(STREAM s, char *stri Line 146  void rdp_out_unistr(STREAM s, char *stri
146  }  }
147    
148  /* Parse a logon info packet */  /* Parse a logon info packet */
149  static void rdp_send_logon_info(uint32 flags, char *domain, char *user,  static void
150                                  char *password, char *program, char *directory)  rdp_send_logon_info(uint32 flags, char *domain, char *user,
151  {                      char *password, char *program, char *directory)
152          int len_domain    = 2 * strlen(domain);  {
153          int len_user      = 2 * strlen(user);          int len_domain = 2 * strlen(domain);
154          int len_password  = 2 * strlen(password);          int len_user = 2 * strlen(user);
155          int len_program   = 2 * strlen(program);          int len_password = 2 * strlen(password);
156            int len_program = 2 * strlen(program);
157          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
158          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO;
159          STREAM s;          STREAM s;
160    
161          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
162                                          + len_program + len_directory + 10);                       + len_program + len_directory + 10);
163    
164          out_uint32(s, 0);          out_uint32(s, 0);
165          out_uint32_le(s, flags);          out_uint32_le(s, flags);
# Line 159  static void rdp_send_logon_info(uint32 f Line 168  static void rdp_send_logon_info(uint32 f
168          out_uint16_le(s, len_password);          out_uint16_le(s, len_password);
169          out_uint16_le(s, len_program);          out_uint16_le(s, len_program);
170          out_uint16_le(s, len_directory);          out_uint16_le(s, len_directory);
171          rdp_out_unistr(s, domain,    len_domain);          rdp_out_unistr(s, domain, len_domain);
172          rdp_out_unistr(s, user,      len_user);          rdp_out_unistr(s, user, len_user);
173          rdp_out_unistr(s, password,  len_password);          rdp_out_unistr(s, password, len_password);
174          rdp_out_unistr(s, program,   len_program);          rdp_out_unistr(s, program, len_program);
175          rdp_out_unistr(s, directory, len_directory);          rdp_out_unistr(s, directory, len_directory);
176    
177          s_mark_end(s);          s_mark_end(s);
# Line 170  static void rdp_send_logon_info(uint32 f Line 179  static void rdp_send_logon_info(uint32 f
179  }  }
180    
181  /* Send a control PDU */  /* Send a control PDU */
182  static void rdp_send_control(uint16 action)  static void
183    rdp_send_control(uint16 action)
184  {  {
185          STREAM s;          STREAM s;
186    
187          s = rdp_init_data(8);          s = rdp_init_data(8);
188    
189          out_uint16_le(s, action);          out_uint16_le(s, action);
190          out_uint16(s, 0); /* userid */          out_uint16(s, 0);       /* userid */
191          out_uint32(s, 0); /* control id */          out_uint32(s, 0);       /* control id */
192    
193          s_mark_end(s);          s_mark_end(s);
194          rdp_send_data(s, RDP_DATA_PDU_CONTROL);          rdp_send_data(s, RDP_DATA_PDU_CONTROL);
195  }  }
196    
197  /* Send a synchronisation PDU */  /* Send a synchronisation PDU */
198  static void rdp_send_synchronise()  static void
199    rdp_send_synchronise()
200  {  {
201          STREAM s;          STREAM s;
202    
203          s = rdp_init_data(4);          s = rdp_init_data(4);
204    
205          out_uint16_le(s, 1); /* type */          out_uint16_le(s, 1);    /* type */
206          out_uint16_le(s, 1002);          out_uint16_le(s, 1002);
207    
208          s_mark_end(s);          s_mark_end(s);
# Line 199  static void rdp_send_synchronise() Line 210  static void rdp_send_synchronise()
210  }  }
211    
212  /* Send a single input event */  /* Send a single input event */
213  void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  void
214                      uint16 param1, uint16 param2)  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
215  {  {
216          STREAM s;          STREAM s;
217    
218          s = rdp_init_data(16);          s = rdp_init_data(16);
219    
220          out_uint16_le(s, 1); /* number of events */          out_uint16_le(s, 1);    /* number of events */
221          out_uint16(s, 0);    /* pad */          out_uint16(s, 0);       /* pad */
222    
223          out_uint32_le(s, time);          out_uint32_le(s, time);
224          out_uint16_le(s, message_type);          out_uint16_le(s, message_type);
# Line 220  void rdp_send_input(uint32 time, uint16 Line 231  void rdp_send_input(uint32 time, uint16
231  }  }
232    
233  /* Send an (empty) font information PDU */  /* Send an (empty) font information PDU */
234  static void rdp_send_fonts(uint16 seq)  static void
235    rdp_send_fonts(uint16 seq)
236  {  {
237          STREAM s;          STREAM s;
238    
# Line 236  static void rdp_send_fonts(uint16 seq) Line 248  static void rdp_send_fonts(uint16 seq)
248  }  }
249    
250  /* Output general capability set */  /* Output general capability set */
251  static void rdp_out_general_caps(STREAM s)  static void
252    rdp_out_general_caps(STREAM s)
253  {  {
254          out_uint16_le(s, RDP_CAPSET_GENERAL);          out_uint16_le(s, RDP_CAPSET_GENERAL);
255          out_uint16_le(s, RDP_CAPLEN_GENERAL);          out_uint16_le(s, RDP_CAPLEN_GENERAL);
256    
257          out_uint16_le(s, 1);    /* OS major type */          out_uint16_le(s, 1);    /* OS major type */
258          out_uint16_le(s, 3);    /* OS minor type */          out_uint16_le(s, 3);    /* OS minor type */
259          out_uint16_le(s, 0x200); /* Protocol version */          out_uint16_le(s, 0x200);        /* Protocol version */
260          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
261          out_uint16(s, 0);       /* Compression types */          out_uint16(s, 0);       /* Compression types */
262          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
# Line 254  static void rdp_out_general_caps(STREAM Line 267  static void rdp_out_general_caps(STREAM
267  }  }
268    
269  /* Output bitmap capability set */  /* Output bitmap capability set */
270  static void rdp_out_bitmap_caps(STREAM s)  static void
271    rdp_out_bitmap_caps(STREAM s)
272  {  {
273          out_uint16_le(s, RDP_CAPSET_BITMAP);          out_uint16_le(s, RDP_CAPSET_BITMAP);
274          out_uint16_le(s, RDP_CAPLEN_BITMAP);          out_uint16_le(s, RDP_CAPLEN_BITMAP);
275    
276          out_uint16_le(s, 8);    /* Preferred BPP */          out_uint16_le(s, 8);    /* Preferred BPP */
277          out_uint16(s, 1);       /* Receive 1 BPP */          out_uint16_le(s, 1);    /* Receive 1 BPP */
278          out_uint16(s, 1);       /* Receive 4 BPP */          out_uint16_le(s, 1);    /* Receive 4 BPP */
279          out_uint16_le(s, 1);    /* Receive 8 BPP */          out_uint16_le(s, 1);    /* Receive 8 BPP */
280          out_uint16_le(s, 800);  /* Desktop width */          out_uint16_le(s, 800);  /* Desktop width */
281          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
282          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
283          out_uint16(s, 0);       /* Allow resize */          out_uint16(s, 0);       /* Allow resize */
284          out_uint16_le(s, 1);    /* Support compression */          out_uint16_le(s, bitmap_compression ? 1 : 0);   /* Support compression */
285          out_uint16(s, 0);       /* Unknown */          out_uint16(s, 0);       /* Unknown */
286          out_uint16_le(s, 1);    /* Unknown */          out_uint16_le(s, 1);    /* Unknown */
287          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
288  }  }
289    
290  /* Output order capability set */  /* Output order capability set */
291  static void rdp_out_order_caps(STREAM s)  static void
292    rdp_out_order_caps(STREAM s)
293  {  {
294          uint8 order_caps[32];          uint8 order_caps[32];
295    
         memset(order_caps, orders, 32);  
296    
297            memset(order_caps, 0, 32);
298            order_caps[0] = 1;      /* dest blt */
299            order_caps[1] = 1;      /* pat blt */
300            order_caps[2] = 1;      /* screen blt */
301            order_caps[3] = 1;      /* required for memblt? */
302            order_caps[8] = 1;      /* line */
303            order_caps[9] = 1;      /* line */
304            order_caps[10] = 1;     /* rect */
305            order_caps[11] = (desktop_save == False ? 0 : 1);       /* desksave */
306            order_caps[13] = 1;     /* memblt */
307            order_caps[14] = 1;     /* triblt */
308            order_caps[22] = 1;     /* polyline */
309            order_caps[27] = 1;     /* text2 */
310          out_uint16_le(s, RDP_CAPSET_ORDER);          out_uint16_le(s, RDP_CAPSET_ORDER);
311          out_uint16_le(s, RDP_CAPLEN_ORDER);          out_uint16_le(s, RDP_CAPLEN_ORDER);
312    
# Line 289  static void rdp_out_order_caps(STREAM s) Line 316  static void rdp_out_order_caps(STREAM s)
316          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
317          out_uint16_le(s, 1);    /* Max order level */          out_uint16_le(s, 1);    /* Max order level */
318          out_uint16_le(s, 0x147);        /* Number of fonts */          out_uint16_le(s, 0x147);        /* Number of fonts */
319          out_uint16_le(s, 0x2a);         /* Capability flags */          out_uint16_le(s, 0x2a); /* Capability flags */
320          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
321          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
322          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
323          out_uint32(s, 0x38400); /* Desktop cache size */          out_uint32_le(s, desktop_save == False ? 0 : 0x38400);  /* Desktop cache size */
324          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
325          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32_le(s, 0x4e4);        /* Unknown */
326  }  }
327    
328  /* Output bitmap cache capability set */  /* Output bitmap cache capability set */
329  static void rdp_out_bmpcache_caps(STREAM s)  static void
330    rdp_out_bmpcache_caps(STREAM s)
331  {  {
332          out_uint16_le(s, RDP_CAPSET_BMPCACHE);          out_uint16_le(s, RDP_CAPSET_BMPCACHE);
333          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
334    
335          out_uint8s(s, 24); /* unused */          out_uint8s(s, 24);      /* unused */
336          out_uint16_le(s, 0x258); /* entries */          out_uint16_le(s, 0x258);        /* entries */
337          out_uint16_le(s, 0x100); /* max cell size */          out_uint16_le(s, 0x100);        /* max cell size */
338          out_uint16_le(s, 0x12c); /* entries */          out_uint16_le(s, 0x12c);        /* entries */
339          out_uint16_le(s, 0x400); /* max cell size */          out_uint16_le(s, 0x400);        /* max cell size */
340          out_uint16_le(s, 0x106); /* entries */          out_uint16_le(s, 0x106);        /* entries */
341          out_uint16_le(s, 0x1000); /* max cell size */          out_uint16_le(s, 0x1000);       /* max cell size */
342  }  }
343    
344  /* Output control capability set */  /* Output control capability set */
345  static void rdp_out_control_caps(STREAM s)  static void
346    rdp_out_control_caps(STREAM s)
347  {  {
348          out_uint16_le(s, RDP_CAPSET_CONTROL);          out_uint16_le(s, RDP_CAPSET_CONTROL);
349          out_uint16_le(s, RDP_CAPLEN_CONTROL);          out_uint16_le(s, RDP_CAPLEN_CONTROL);
# Line 326  static void rdp_out_control_caps(STREAM Line 355  static void rdp_out_control_caps(STREAM
355  }  }
356    
357  /* Output activation capability set */  /* Output activation capability set */
358  static void rdp_out_activate_caps(STREAM s)  static void
359    rdp_out_activate_caps(STREAM s)
360  {  {
361          out_uint16_le(s, RDP_CAPSET_ACTIVATE);          out_uint16_le(s, RDP_CAPSET_ACTIVATE);
362          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);
# Line 338  static void rdp_out_activate_caps(STREAM Line 368  static void rdp_out_activate_caps(STREAM
368  }  }
369    
370  /* Output pointer capability set */  /* Output pointer capability set */
371  static void rdp_out_pointer_caps(STREAM s)  static void
372    rdp_out_pointer_caps(STREAM s)
373  {  {
374          out_uint16_le(s, RDP_CAPSET_POINTER);          out_uint16_le(s, RDP_CAPSET_POINTER);
375          out_uint16_le(s, RDP_CAPLEN_POINTER);          out_uint16_le(s, RDP_CAPLEN_POINTER);
# Line 348  static void rdp_out_pointer_caps(STREAM Line 379  static void rdp_out_pointer_caps(STREAM
379  }  }
380    
381  /* Output share capability set */  /* Output share capability set */
382  static void rdp_out_share_caps(STREAM s)  static void
383    rdp_out_share_caps(STREAM s)
384  {  {
385          out_uint16_le(s, RDP_CAPSET_SHARE);          out_uint16_le(s, RDP_CAPSET_SHARE);
386          out_uint16_le(s, RDP_CAPLEN_SHARE);          out_uint16_le(s, RDP_CAPLEN_SHARE);
# Line 358  static void rdp_out_share_caps(STREAM s) Line 390  static void rdp_out_share_caps(STREAM s)
390  }  }
391    
392  /* Output colour cache capability set */  /* Output colour cache capability set */
393  static void rdp_out_colcache_caps(STREAM s)  static void
394    rdp_out_colcache_caps(STREAM s)
395  {  {
396          out_uint16_le(s, RDP_CAPSET_COLCACHE);          out_uint16_le(s, RDP_CAPSET_COLCACHE);
397          out_uint16_le(s, RDP_CAPLEN_COLCACHE);          out_uint16_le(s, RDP_CAPLEN_COLCACHE);
# Line 368  static void rdp_out_colcache_caps(STREAM Line 401  static void rdp_out_colcache_caps(STREAM
401  }  }
402    
403  static uint8 canned_caps[] = {  static uint8 canned_caps[] = {
404  0x01,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x04,          0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
405  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
406  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
407  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
409  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x08,0x00,0x01,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
410  0x00,0x00,0x00,0x0E,0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x34,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00,
411  0x00,0x04,0x00,0xFE,0x00,0x04,0x00,0xFE,0x00,0x08,0x00,0xFE,0x00,0x08,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
412  0x00,0x10,0x00,0xFE,0x00,0x20,0x00,0xFE,0x00,0x40,0x00,0xFE,0x00,0x80,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00,
413  0x00,0x00,0x01,0x40,0x00,0x00,0x08,0x00,0x01,0x00,0x01,0x02,0x00,0x00,0x00          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
414            0x0C, 0x00, 0x08, 0x00, 0x01,
415            0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
416            0x10, 0x00, 0x34, 0x00, 0xFE,
417            0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
418            0xFE, 0x00, 0x08, 0x00, 0xFE,
419            0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
420            0xFE, 0x00, 0x80, 0x00, 0xFE,
421            0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
422            0x02, 0x00, 0x00, 0x00
423  };  };
424    
425  /* Output unknown capability set */  /* Output unknown capability set */
426  static void rdp_out_unknown_caps(STREAM s)  static void
427    rdp_out_unknown_caps(STREAM s)
428  {  {
429          out_uint16_le(s, RDP_CAPSET_UNKNOWN);          out_uint16_le(s, RDP_CAPSET_UNKNOWN);
430          out_uint16_le(s, 0x58);          out_uint16_le(s, 0x58);
431            
432          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN-4);          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
433  }  }
434    
435  /* Send a confirm active PDU */  /* Send a confirm active PDU */
436  static void rdp_send_confirm_active()  static void
437    rdp_send_confirm_active()
438  {  {
439          STREAM s;          STREAM s;
440          uint16 caplen = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER          uint16 caplen =
441                  + RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
442                  + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
443                  + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
444                    RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ;
445    
446          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
447    
448          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
449          out_uint16_le(s, 0x3ea); /* userid */          out_uint16_le(s, 0x3ea);        /* userid */
450          out_uint16_le(s, sizeof(RDP_SOURCE));          out_uint16_le(s, sizeof(RDP_SOURCE));
451          out_uint16_le(s, caplen);          out_uint16_le(s, caplen);
452    
453          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));
454          out_uint16_le(s, 0xd); /* num_caps */          out_uint16_le(s, 0xd);  /* num_caps */
455          out_uint8s(s, 2);     /* pad */          out_uint8s(s, 2);       /* pad */
456    
457          rdp_out_general_caps(s);          rdp_out_general_caps(s);
458          rdp_out_bitmap_caps(s);          rdp_out_bitmap_caps(s);
# Line 425  static void rdp_send_confirm_active() Line 470  static void rdp_send_confirm_active()
470  }  }
471    
472  /* Respond to a demand active PDU */  /* Respond to a demand active PDU */
473  static void process_demand_active(STREAM s)  static void
474    process_demand_active(STREAM s)
475  {  {
476          uint8 type;          uint8 type;
477    
478          in_uint32_le(s, rdp_shareid);          in_uint32_le(s, rdp_shareid);
479    
480          DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);          DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid));
481    
482          rdp_send_confirm_active();          rdp_send_confirm_active();
483          rdp_send_synchronise();          rdp_send_synchronise();
484          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
485          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
486          rdp_recv(&type); // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        /* RDP_PDU_SYNCHRONIZE */
487          rdp_recv(&type); // RDP_CTL_COOPERATE          rdp_recv(&type);        /* RDP_CTL_COOPERATE */
488          rdp_recv(&type); // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        /* RDP_CTL_GRANT_CONTROL */
489          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
490          rdp_send_fonts(1);          rdp_send_fonts(1);
491          rdp_send_fonts(2);          rdp_send_fonts(2);
492          rdp_recv(&type); // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        /* RDP_PDU_UNKNOWN 0x28 */
493          reset_order_state();          reset_order_state();
494  }  }
495    
496  /* Process a pointer PDU */  /* Process a pointer PDU */
497  static void process_pointer_pdu(STREAM s)  static void
498    process_pointer_pdu(STREAM s)
499  {  {
500          uint16 message_type;          uint16 message_type;
501          uint16 x, y;          uint16 x, y, width, height, cache_idx, masklen, datalen;
502            uint8 *mask, *data;
503            HCURSOR cursor;
504    
505          in_uint16_le(s, message_type);          in_uint16_le(s, message_type);
506          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
507    
508          switch (message_type)          switch (message_type)
509          {          {
# Line 465  static void process_pointer_pdu(STREAM s Line 514  static void process_pointer_pdu(STREAM s
514                                  ui_move_pointer(x, y);                                  ui_move_pointer(x, y);
515                          break;                          break;
516    
517                    case RDP_POINTER_COLOR:
518                            in_uint16_le(s, cache_idx);
519                            in_uint16_le(s, x);
520                            in_uint16_le(s, y);
521                            in_uint16_le(s, width);
522                            in_uint16_le(s, height);
523                            in_uint16_le(s, masklen);
524                            in_uint16_le(s, datalen);
525                            in_uint8p(s, data, datalen);
526                            in_uint8p(s, mask, masklen);
527                            cursor = ui_create_cursor(x, y, width, height, mask, data);
528                            ui_set_cursor(cursor);
529                            cache_put_cursor(cache_idx, cursor);
530                            break;
531    
532                    case RDP_POINTER_CACHED:
533                            in_uint16_le(s, cache_idx);
534                            ui_set_cursor(cache_get_cursor(cache_idx));
535                            break;
536    
537                  default:                  default:
538                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG(("Pointer message 0x%x\n", message_type));
539          }          }
540  }  }
541    
542  /* Process bitmap updates */  /* Process bitmap updates */
543  static void process_bitmap_updates(STREAM s)  static void
544    process_bitmap_updates(STREAM s)
545  {  {
546          uint16 num_updates;          uint16 num_updates;
547          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
548          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, compress, bufsize, size;
549          uint8 *data, *rawdata;          uint8 *data, *bmpdata;
550          int i;          int i;
551    
552          in_uint16_le(s, num_updates);          in_uint16_le(s, num_updates);
# Line 496  static void process_bitmap_updates(STREA Line 566  static void process_bitmap_updates(STREA
566                  cx = right - left + 1;                  cx = right - left + 1;
567                  cy = bottom - top + 1;                  cy = bottom - top + 1;
568    
569                  DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",                  DEBUG(("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",
570                          left, top, right, bottom, width, height, compress);                         left, top, right, bottom, width, height, compress));
571    
572                  if (!compress)                  if (!compress)
573                  {                  {
574                          in_uint8p(s, data, bufsize);                          int y;
575                          ui_paint_bitmap(left, top, cx, cy, width, height, data);                          bmpdata = xmalloc(width * height);
576                          return;                          for (y = 0; y < height; y++)
577                            {
578                                    in_uint8a(s, &bmpdata[(height - y - 1) * width], width);
579                            }
580                            ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
581                            xfree(bmpdata);
582                            continue;
583                  }                  }
584    
585                  in_uint8s(s, 2); /* pad */                  in_uint8s(s, 2);        /* pad */
586                  in_uint16_le(s, size);                  in_uint16_le(s, size);
587                  in_uint8s(s, 4); /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
588                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
589    
590                  rawdata = xmalloc(width * height);                  bmpdata = xmalloc(width * height);
591                  if (bitmap_decompress(rawdata, width, height, data, size))                  if (bitmap_decompress(bmpdata, width, height, data, size))
592                  {                  {
593                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
                                         rawdata);  
594                  }                  }
595    
596                  xfree(rawdata);                  xfree(bmpdata);
597          }          }
598  }  }
599    
600  /* Process a palette update */  /* Process a palette update */
601  static void process_palette(STREAM s)  static void
602    process_palette(STREAM s)
603  {  {
604          HCOLOURMAP hmap;          HCOLOURMAP hmap;
605          COLOURMAP map;          COLOURMAP map;
606            uint8 *colours;
607    
608          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
609          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
610          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
611          in_uint8p(s, (uint8 *)map.colours, (map.ncolours * 3));          in_uint8p(s, colours, (map.ncolours * 3));
612            map.colours = (COLOURENTRY *) colours;
613    
614          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
615          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
616  }  }
617    
618  /* Process an update PDU */  /* Process an update PDU */
619  static void process_update_pdu(STREAM s)  static void
620    process_update_pdu(STREAM s)
621  {  {
622          uint16 update_type;          uint16 update_type;
623    
# Line 562  static void process_update_pdu(STREAM s) Line 641  static void process_update_pdu(STREAM s)
641                          break;                          break;
642    
643                  default:                  default:
644                          NOTIMP("update %d\n", update_type);                          unimpl("update %d\n", update_type);
645          }          }
646    
647  }  }
648    
649  /* Process data PDU */  /* Process data PDU */
650  static void process_data_pdu(STREAM s)  static void
651    process_data_pdu(STREAM s)
652  {  {
653          uint8 data_pdu_type;          uint8 data_pdu_type;
654    
655          in_uint8s(s, 8); /* shareid, pad, streamid, length */          in_uint8s(s, 8);        /* shareid, pad, streamid, length */
656          in_uint8(s, data_pdu_type);          in_uint8(s, data_pdu_type);
657          in_uint8s(s, 3); /* compress_type, compress_len */          in_uint8s(s, 3);        /* compress_type, compress_len */
658    
659          switch (data_pdu_type)          switch (data_pdu_type)
660          {          {
# Line 595  static void process_data_pdu(STREAM s) Line 675  static void process_data_pdu(STREAM s)
675                          break;                          break;
676    
677                  default:                  default:
678                          NOTIMP("data PDU %d\n", data_pdu_type);                          unimpl("data PDU %d\n", data_pdu_type);
679          }          }
680  }  }
681    
682  /* Process incoming packets */  /* Process incoming packets */
683  void rdp_main_loop()  void
684    rdp_main_loop()
685  {  {
686          uint8 type;          uint8 type;
687          STREAM s;          STREAM s;
# Line 621  void rdp_main_loop() Line 702  void rdp_main_loop()
702                                  break;                                  break;
703    
704                          default:                          default:
705                                  NOTIMP("PDU %d\n", type);                                  unimpl("PDU %d\n", type);
706                  }                  }
707          }          }
708  }  }
709    
710  /* Establish a connection up to the RDP layer */  /* Establish a connection up to the RDP layer */
711  BOOL rdp_connect(char *server)  BOOL
712    rdp_connect(char *server, uint32 flags, char *domain, char *password,
713                char *command, char *directory)
714  {  {
715          if (!sec_connect(server))          if (!sec_connect(server))
716                  return False;                  return False;
717    
718          rdp_send_logon_info(0x33, "", username, "", "", "");          rdp_send_logon_info(flags, domain, username, password, command, directory);
719          return True;          return True;
720  }  }
721    
722  /* Disconnect from the RDP layer */  /* Disconnect from the RDP layer */
723  void rdp_disconnect()  void
724    rdp_disconnect()
725  {  {
726          sec_disconnect();          sec_disconnect();
727  }  }
   

Legend:
Removed from v.10  
changed lines
  Added in v.176

  ViewVC Help
Powered by ViewVC 1.1.26