/[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 28 by matty, Wed Jun 20 13:54:48 2001 UTC revision 318 by astrand, Mon Feb 10 12:58:51 2003 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-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
# Line 24  extern uint16 mcs_userid; Line 24  extern uint16 mcs_userid;
24  extern char username[16];  extern char username[16];
25  extern BOOL bitmap_compression;  extern BOOL bitmap_compression;
26  extern BOOL orders;  extern BOOL orders;
27  extern BOOL use_encryption;  extern BOOL encryption;
28  extern BOOL desktop_save;  extern BOOL desktop_save;
29    
30  uint8 *next_packet;  uint8 *next_packet;
# Line 36  rdp_init(int maxlen) Line 36  rdp_init(int maxlen)
36  {  {
37          STREAM s;          STREAM s;
38    
39          s = sec_init(use_encryption ? SEC_ENCRYPT : 0, 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;
# Line 55  rdp_send(STREAM s, uint8 pdu_type) Line 55  rdp_send(STREAM s, uint8 pdu_type)
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, use_encryption ? SEC_ENCRYPT : 0);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
59  }  }
60    
61  /* Receive an RDP packet */  /* Receive an RDP packet */
62  static STREAM  static STREAM
63  rdp_recv(uint8 *type)  rdp_recv(uint8 * type)
64  {  {
65          static STREAM rdp_s;          static STREAM rdp_s;
66          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 79  rdp_recv(uint8 *type) Line 79  rdp_recv(uint8 *type)
79          }          }
80    
81          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
82            /* 32k packets are really 8, keepalive fix */
83            if (length == 0x8000)
84            {
85                    next_packet += 8;
86                    *type = 0;
87                    return rdp_s;
88            }
89          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
90          in_uint8s(rdp_s, 2);    /* userid */          in_uint8s(rdp_s, 2);    /* userid */
91          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
92    
93  #if RDP_DEBUG  #if WITH_DEBUG
94          DEBUG("RDP packet (type %x):\n", *type);          DEBUG(("RDP packet (type %x):\n", *type));
95          hexdump(next_packet, length);          hexdump(next_packet, length);
96  #endif /*  */  #endif /*  */
97    
# Line 98  rdp_init_data(int maxlen) Line 105  rdp_init_data(int maxlen)
105  {  {
106          STREAM s;          STREAM s;
107    
108          s = sec_init(use_encryption ? SEC_ENCRYPT : 0, maxlen + 18);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18);
109          s_push_layer(s, rdp_hdr, 18);          s_push_layer(s, rdp_hdr, 18);
110    
111          return s;          return s;
# Line 120  rdp_send_data(STREAM s, uint8 data_pdu_t Line 127  rdp_send_data(STREAM s, uint8 data_pdu_t
127          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
128          out_uint8(s, 0);        /* pad */          out_uint8(s, 0);        /* pad */
129          out_uint8(s, 1);        /* streamid */          out_uint8(s, 1);        /* streamid */
130          out_uint16(s, (length - 14));          out_uint16_le(s, (length - 14));
131          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
132          out_uint8(s, 0);        /* compress_type */          out_uint8(s, 0);        /* compress_type */
133          out_uint16(s, 0);       /* compress_len */          out_uint16(s, 0);       /* compress_len */
134    
135          sec_send(s, use_encryption ? SEC_ENCRYPT : 0);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
136  }  }
137    
138  /* Output a string in Unicode */  /* Output a string in Unicode */
# Line 155  rdp_send_logon_info(uint32 flags, char * Line 162  rdp_send_logon_info(uint32 flags, char *
162          int len_password = 2 * strlen(password);          int len_password = 2 * strlen(password);
163          int len_program = 2 * strlen(program);          int len_program = 2 * strlen(program);
164          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
165          uint32 sec_flags = use_encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT)          uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO;
                                 : SEC_LOGON_INFO;  
166          STREAM s;          STREAM s;
167    
168          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
# Line 197  rdp_send_control(uint16 action) Line 203  rdp_send_control(uint16 action)
203    
204  /* Send a synchronisation PDU */  /* Send a synchronisation PDU */
205  static void  static void
206  rdp_send_synchronise()  rdp_send_synchronise(void)
207  {  {
208          STREAM s;          STREAM s;
209    
# Line 212  rdp_send_synchronise() Line 218  rdp_send_synchronise()
218    
219  /* Send a single input event */  /* Send a single input event */
220  void  void
221  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
                uint16 param1, uint16 param2)  
222  {  {
223          STREAM s;          STREAM s;
224    
# Line 276  rdp_out_bitmap_caps(STREAM s) Line 281  rdp_out_bitmap_caps(STREAM s)
281          out_uint16_le(s, RDP_CAPLEN_BITMAP);          out_uint16_le(s, RDP_CAPLEN_BITMAP);
282    
283          out_uint16_le(s, 8);    /* Preferred BPP */          out_uint16_le(s, 8);    /* Preferred BPP */
284          out_uint16(s, 1);       /* Receive 1 BPP */          out_uint16_le(s, 1);    /* Receive 1 BPP */
285          out_uint16(s, 1);       /* Receive 4 BPP */          out_uint16_le(s, 1);    /* Receive 4 BPP */
286          out_uint16_le(s, 1);    /* Receive 8 BPP */          out_uint16_le(s, 1);    /* Receive 8 BPP */
287          out_uint16_le(s, 800);  /* Desktop width */          out_uint16_le(s, 800);  /* Desktop width */
288          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
# Line 300  rdp_out_order_caps(STREAM s) Line 305  rdp_out_order_caps(STREAM s)
305          order_caps[0] = 1;      /* dest blt */          order_caps[0] = 1;      /* dest blt */
306          order_caps[1] = 1;      /* pat blt */          order_caps[1] = 1;      /* pat blt */
307          order_caps[2] = 1;      /* screen blt */          order_caps[2] = 1;      /* screen blt */
308            order_caps[3] = 1;      /* required for memblt? */
309          order_caps[8] = 1;      /* line */          order_caps[8] = 1;      /* line */
310          order_caps[9] = 1;      /* line */          order_caps[9] = 1;      /* line */
311          order_caps[10] = 1;     /* rect */          order_caps[10] = 1;     /* rect */
# Line 321  rdp_out_order_caps(STREAM s) Line 327  rdp_out_order_caps(STREAM s)
327          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
328          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
329          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
330          out_uint32(s, desktop_save == False ? 0 : 0x38400);     /* Desktop cache size */          out_uint32_le(s, desktop_save == False ? 0 : 0x38400);  /* Desktop cache size */
331          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
332          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32_le(s, 0x4e4);        /* Unknown */
333  }  }
334    
335  /* Output bitmap cache capability set */  /* Output bitmap cache capability set */
# Line 435  rdp_out_unknown_caps(STREAM s) Line 441  rdp_out_unknown_caps(STREAM s)
441    
442  /* Send a confirm active PDU */  /* Send a confirm active PDU */
443  static void  static void
444  rdp_send_confirm_active()  rdp_send_confirm_active(void)
445  {  {
446          STREAM s;          STREAM s;
447          uint16 caplen =          uint16 caplen =
448                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
449                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
450                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
451                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ;
                         + 4 /* w2k fix, why? */;  
452    
453          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
454    
# Line 479  process_demand_active(STREAM s) Line 484  process_demand_active(STREAM s)
484    
485          in_uint32_le(s, rdp_shareid);          in_uint32_le(s, rdp_shareid);
486    
487          DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);          DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid));
488    
489          rdp_send_confirm_active();          rdp_send_confirm_active();
490          rdp_send_synchronise();          rdp_send_synchronise();
# Line 526  process_pointer_pdu(STREAM s) Line 531  process_pointer_pdu(STREAM s)
531                          in_uint16_le(s, datalen);                          in_uint16_le(s, datalen);
532                          in_uint8p(s, data, datalen);                          in_uint8p(s, data, datalen);
533                          in_uint8p(s, mask, masklen);                          in_uint8p(s, mask, masklen);
534                          cursor = ui_create_cursor(x, y, width, height, mask,                          cursor = ui_create_cursor(x, y, width, height, mask, data);
                                                   data);  
535                          ui_set_cursor(cursor);                          ui_set_cursor(cursor);
536                          cache_put_cursor(cache_idx, cursor);                          cache_put_cursor(cache_idx, cursor);
537                          break;                          break;
# Line 538  process_pointer_pdu(STREAM s) Line 542  process_pointer_pdu(STREAM s)
542                          break;                          break;
543    
544                  default:                  default:
545                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG(("Pointer message 0x%x\n", message_type));
546          }          }
547  }  }
548    
# Line 548  process_bitmap_updates(STREAM s) Line 552  process_bitmap_updates(STREAM s)
552  {  {
553          uint16 num_updates;          uint16 num_updates;
554          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
555          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, Bpp, compress, bufsize, size;
556          uint8 *data, *bmpdata;          uint8 *data, *bmpdata;
557          int i;          int i;
558    
# Line 563  process_bitmap_updates(STREAM s) Line 567  process_bitmap_updates(STREAM s)
567                  in_uint16_le(s, width);                  in_uint16_le(s, width);
568                  in_uint16_le(s, height);                  in_uint16_le(s, height);
569                  in_uint16_le(s, bpp);                  in_uint16_le(s, bpp);
570                    Bpp = (bpp + 7) / 8;
571                  in_uint16_le(s, compress);                  in_uint16_le(s, compress);
572                  in_uint16_le(s, bufsize);                  in_uint16_le(s, bufsize);
573    
574                  cx = right - left + 1;                  cx = right - left + 1;
575                  cy = bottom - top + 1;                  cy = bottom - top + 1;
576    
577                  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",
578                        left, top, right, bottom, width, height, compress);                         left, top, right, bottom, width, height, compress));
579    
580                  if (!compress)                  if (!compress)
581                  {                  {
582                          int y;                          int y;
583                          bmpdata = xmalloc(width * height);                          bmpdata = xmalloc(width * height * Bpp);
584                          for (y = 0; y < height; y++)                          for (y = 0; y < height; y++)
585                          {                          {
586                                  in_uint8a(s,                                  in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)],
587                                            &bmpdata[(height - y - 1) * width],                                            width * Bpp);
                                           width);  
588                          }                          }
589                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
                                         bmpdata);  
590                          xfree(bmpdata);                          xfree(bmpdata);
591                          continue;                          continue;
592                  }                  }
# Line 592  process_bitmap_updates(STREAM s) Line 595  process_bitmap_updates(STREAM s)
595                  in_uint16_le(s, size);                  in_uint16_le(s, size);
596                  in_uint8s(s, 4);        /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
597                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
598                    bmpdata = xmalloc(width * height * Bpp);
599                  bmpdata = xmalloc(width * height);                  if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
                 if (bitmap_decompress(bmpdata, width, height, data, size))  
600                  {                  {
601                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
                                         bmpdata);  
602                  }                  }
   
603                  xfree(bmpdata);                  xfree(bmpdata);
604          }          }
605  }  }
# Line 608  process_bitmap_updates(STREAM s) Line 608  process_bitmap_updates(STREAM s)
608  static void  static void
609  process_palette(STREAM s)  process_palette(STREAM s)
610  {  {
611          HCOLOURMAP hmap;          COLOURENTRY *entry;
612          COLOURMAP map;          COLOURMAP map;
613            HCOLOURMAP hmap;
614            int i;
615    
616          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
617          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
618          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
619          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));  
620            map.colours = xmalloc(3 * map.ncolours);
621    
622            for (i = 0; i < map.ncolours; i++)
623            {
624                    entry = &map.colours[i];
625                    in_uint8(s, entry->red);
626                    in_uint8(s, entry->green);
627                    in_uint8(s, entry->blue);
628            }
629    
630          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
631          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
632    
633            xfree(map.colours);
634  }  }
635    
636  /* Process an update PDU */  /* Process an update PDU */
# Line 646  process_update_pdu(STREAM s) Line 659  process_update_pdu(STREAM s)
659                          break;                          break;
660    
661                  default:                  default:
662                          NOTIMP("update %d\n", update_type);                          unimpl("update %d\n", update_type);
663          }          }
664    
665  }  }
# Line 680  process_data_pdu(STREAM s) Line 693  process_data_pdu(STREAM s)
693                          break;                          break;
694    
695                  default:                  default:
696                          NOTIMP("data PDU %d\n", data_pdu_type);                          unimpl("data PDU %d\n", data_pdu_type);
697          }          }
698  }  }
699    
700  /* Process incoming packets */  /* Process incoming packets */
701  void  void
702  rdp_main_loop()  rdp_main_loop(void)
703  {  {
704          uint8 type;          uint8 type;
705          STREAM s;          STREAM s;
# Line 706  rdp_main_loop() Line 719  rdp_main_loop()
719                                  process_data_pdu(s);                                  process_data_pdu(s);
720                                  break;                                  break;
721    
722                            case 0:
723                                    break;
724    
725                          default:                          default:
726                                  NOTIMP("PDU %d\n", type);                                  unimpl("PDU %d\n", type);
727                  }                  }
728          }          }
729  }  }
# Line 720  rdp_connect(char *server, uint32 flags, Line 736  rdp_connect(char *server, uint32 flags,
736          if (!sec_connect(server))          if (!sec_connect(server))
737                  return False;                  return False;
738    
739          rdp_send_logon_info(flags, domain, username, password,          rdp_send_logon_info(flags, domain, username, password, command, directory);
                             command, directory);  
740          return True;          return True;
741  }  }
742    
743  /* Disconnect from the RDP layer */  /* Disconnect from the RDP layer */
744  void  void
745  rdp_disconnect()  rdp_disconnect(void)
746  {  {
747          sec_disconnect();          sec_disconnect();
748  }  }

Legend:
Removed from v.28  
changed lines
  Added in v.318

  ViewVC Help
Powered by ViewVC 1.1.26