/[rdesktop]/sourceforge.net/trunk/rdesktop/mcs.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/mcs.c

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

revision 7 by matty, Fri Jul 7 09:40:03 2000 UTC revision 409 by forsberg, Fri Jun 6 10:46:00 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - Multipoint Communications Service     Protocol services - Multipoint Communications Service
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 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include "includes.h"  #include "rdesktop.h"
22    
23  /* Establish a connection up to the MCS layer */  uint16 g_mcs_userid;
24  HCONN mcs_connect(char *server)  extern BOOL use_rdp5;
 {  
         HCONN conn;  
         MCS_CONNECT_RESPONSE mcr;  
         MCS_AUCF aucf;  
25    
26          if ((conn = iso_connect(server)) == NULL)  /* Parse an ASN.1 BER header */
27                  return NULL;  static BOOL
28    ber_parse_header(STREAM s, int tagval, int *length)
29    {
30            int tag, len;
31    
32          mcs_send_connect_initial(conn);          if (tagval > 0xff)
         if (!iso_recv(conn) || !mcs_io_connect_response(&conn->in, &mcr))  
33          {          {
34                  fprintf(stderr, "MCS error, expected Connect-Response\n");                  in_uint16_be(s, tag);
                 iso_disconnect(conn);  
                 return NULL;  
35          }          }
36            else
         if (mcr.result != 0)  
         {  
                 fprintf(stderr, "MCS-Connect-Initial failed, result %d\n",  
                         mcr.result);  
                 iso_disconnect(conn);  
                 return NULL;  
         }  
   
         mcs_send_edrq(conn);  
   
         mcs_send_aurq(conn);  
         if (!iso_recv(conn) || !mcs_io_aucf(&conn->in, &aucf))  
37          {          {
38                  fprintf(stderr, "MCS error, expected AUcf\n");          in_uint8(s, tag)}
                 mcs_disconnect(conn);  
                 return NULL;  
         }  
39    
40          if (aucf.result != 0)          if (tag != tagval)
41          {          {
42                  fprintf(stderr, "AUrq failed, result %d\n", mcr.result);                  error("expected tag %d, got %d\n", tagval, tag);
43                  mcs_disconnect(conn);                  return False;
                 return NULL;  
44          }          }
45    
46          conn->mcs_userid = aucf.userid;          in_uint8(s, len);
47    
48          if (!mcs_join_channel(conn, aucf.userid + 1001)          if (len & 0x80)
             || !mcs_join_channel(conn, MCS_GLOBAL_CHANNEL))  
49          {          {
50                  mcs_disconnect(conn);                  len &= ~0x80;
51                  return NULL;                  *length = 0;
52                    while (len--)
53                            next_be(s, *length);
54          }          }
55            else
56                    *length = len;
57    
58          return conn;          return s_check(s);
59  }  }
60    
61  BOOL mcs_join_channel(HCONN conn, uint16 chanid)  /* Output an ASN.1 BER header */
62    static void
63    ber_out_header(STREAM s, int tagval, int length)
64  {  {
65          MCS_CJCF cjcf;          if (tagval > 0xff)
   
         mcs_send_cjrq(conn, chanid);  
         if (!iso_recv(conn) || !mcs_io_cjcf(&conn->in, &cjcf))  
66          {          {
67                  fprintf(stderr, "MCS error, expected CJcf\n");                  out_uint16_be(s, tagval);
                 return False;  
68          }          }
69            else
         if (cjcf.result != 0)  
70          {          {
71                  fprintf(stderr, "CJrq failed, result %d\n", cjcf.result);                  out_uint8(s, tagval);
                 return False;  
72          }          }
73    
74          return True;          if (length >= 0x80)
75            {
76                    out_uint8(s, 0x82);
77                    out_uint16_be(s, length);
78            }
79            else
80                    out_uint8(s, length);
81  }  }
82    
83  /* Disconnect from the MCS layer */  /* Output an ASN.1 BER integer */
84  void mcs_disconnect(HCONN conn)  static void
85    ber_out_integer(STREAM s, int value)
86  {  {
87          /* Not complete */          ber_out_header(s, BER_TAG_INTEGER, 2);
88          iso_disconnect(conn);          out_uint16_be(s, value);
89  }  }
90    
91  /* Send a Connect-Initial message */  /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
92  void mcs_send_connect_initial(HCONN conn)  static void
93    mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize)
94  {  {
95          MCS_CONNECT_INITIAL mci;          ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);
96            ber_out_integer(s, max_channels);
97          iso_init(conn);          ber_out_integer(s, max_users);
98          mcs_make_connect_initial(&mci);          ber_out_integer(s, max_tokens);
99          mcs_io_connect_initial(&conn->out, &mci);          ber_out_integer(s, 1);  /* num_priorities */
100          MARK_END(conn->out);          ber_out_integer(s, 0);  /* min_throughput */
101          iso_send(conn);          ber_out_integer(s, 1);  /* max_height */
102            ber_out_integer(s, max_pdusize);
103            ber_out_integer(s, 2);  /* ver_protocol */
104  }  }
105    
106  /* Send a EDrq message */  /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
107  void mcs_send_edrq(HCONN conn)  static BOOL
108    mcs_parse_domain_params(STREAM s)
109  {  {
110          MCS_EDRQ edrq;          int length;
111    
112            ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length);
113            in_uint8s(s, length);
114    
115          iso_init(conn);          return s_check(s);
         edrq.height = edrq.interval = 1;  
         mcs_io_edrq(&conn->out, &edrq);  
         MARK_END(conn->out);  
         iso_send(conn);  
116  }  }
117    
118  /* Send a AUrq message */  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
119  void mcs_send_aurq(HCONN conn)  static void
120    mcs_send_connect_initial(STREAM mcs_data)
121  {  {
122          MCS_AURQ aurq;          int datalen = mcs_data->end - mcs_data->data;
123            int length = 9 + 3 * 34 + 4 + datalen;
124            STREAM s;
125    
126          iso_init(conn);          s = iso_init(length + 5);
         mcs_io_aurq(&conn->out, &aurq);  
         MARK_END(conn->out);  
         iso_send(conn);  
 }  
127    
128  /* Send a CJrq message */          ber_out_header(s, MCS_CONNECT_INITIAL, length);
129  void mcs_send_cjrq(HCONN conn, uint16 chanid)          ber_out_header(s, BER_TAG_OCTET_STRING, 1);     /* calling domain */
130  {          out_uint8(s, 1);
131          MCS_CJRQ cjrq;          ber_out_header(s, BER_TAG_OCTET_STRING, 1);     /* called domain */
132            out_uint8(s, 1);
133    
134          iso_init(conn);          ber_out_header(s, BER_TAG_BOOLEAN, 1);
135          cjrq.userid = conn->mcs_userid;          out_uint8(s, 0xff);     /* upward flag */
         cjrq.chanid = chanid;  
         mcs_io_cjrq(&conn->out, &cjrq);  
         MARK_END(conn->out);  
         iso_send(conn);  
 }  
136    
137  /* Initialise MCS transport data packet */          mcs_out_domain_params(s, 34, 2, 0, 0xffff);     /* target params */
138  void mcs_init_data(HCONN conn)          mcs_out_domain_params(s, 1, 1, 1, 0x420);       /* min params */
139  {          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);       /* max params */
         iso_init(conn);  
         PUSH_LAYER(conn->out, mcs_offset, 8);  
 }  
140    
141  /* Transmit MCS transport data packet */          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);
142  void mcs_send_data(HCONN conn, uint16 chanid, BOOL request)          out_uint8p(s, mcs_data->data, datalen);
 {  
         MCS_DATA dt;  
143    
144          POP_LAYER(conn->out, mcs_offset);          s_mark_end(s);
145          dt.userid = conn->mcs_userid;          iso_send(s);
         dt.chanid = chanid;  
         dt.flags = 0x70;  
         dt.length = conn->out.end - conn->out.offset - 8;  
         mcs_io_data(&conn->out, &dt, request);  
         iso_send(conn);  
146  }  }
147    
148  /* Receive a message on the MCS layer */  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
149  BOOL mcs_recv(HCONN conn, BOOL request)  static BOOL
150    mcs_recv_connect_response(STREAM mcs_data)
151  {  {
152          MCS_DATA data;          uint8 result;
153            int length;
154            STREAM s;
155    
156          if (!iso_recv(conn) || !mcs_io_data(&conn->in, &data, request))          s = iso_recv();
157            if (s == NULL)
158                  return False;                  return False;
159    
160  #ifdef MCS_DEBUG          ber_parse_header(s, MCS_CONNECT_RESPONSE, &length);
         fprintf(stderr, "MCS packet\n");  
         dump_data(conn->in.data+conn->in.offset, conn->in.end-conn->in.offset);  
 #endif  
161    
162          conn->in.rdp_offset = conn->in.offset;          ber_parse_header(s, BER_TAG_RESULT, &length);
163          return True;          in_uint8(s, result);
164  }          if (result != 0)
   
 /* Initialise a DOMAIN_PARAMS structure */  
 void mcs_make_domain_params(DOMAIN_PARAMS *dp, uint16 max_channels,  
               uint16 max_users, uint16 max_tokens, uint16 max_pdusize)  
 {  
         dp->max_channels   = max_channels;  
         dp->max_users      = max_users;  
         dp->max_tokens     = max_tokens;  
         dp->num_priorities = 1;  
         dp->min_throughput = 0;  
         dp->max_height     = 1;  
         dp->max_pdusize    = max_pdusize;  
         dp->ver_protocol   = 2;  
 }  
   
 /* RDP-specific 'user data'. Let's just get this right for now - to be  
    decoded later. */  
 char precanned_connect_userdata[] = {  
    0x00,0x05,0x00,0x14,0x7c,0x00,0x01,0x80,0x9e,0x00,0x08,0x00,0x10,0x00,  
    0x01,0xc0,0x00,0x44,0x75,0x63,0x61,0x80,0x90,0x01,0xc0,0x88,0x00,0x01,  
    0x00,0x08,0x00,0x80,0x02,0xe0,0x01,0x01,0xca,0x03,0xaa,0x09,0x04,0x00,  
    0x00,0xa3,0x01,0x00,0x00,0x52,0x00,0x45,0x00,0x53,0x00,0x31,0x00,0x2d,  
    0x00,0x4e,0x00,0x45,0x00,0x57,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x0c,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x01,0xca,0x00,0x00,0x02,0xc0,0x08,0x00,0x00,0x00,0x00,0x00 };  
   
 /* Initialise a MCS_CONNECT_INITIAL structure */  
 void mcs_make_connect_initial(MCS_CONNECT_INITIAL *mci)  
 {  
         mci->calling_domain.length = 0;  
         mci->calling_domain.data = NULL;  
   
         mci->called_domain.length = 0;  
         mci->called_domain.data = NULL;  
   
         mci->upward_flag = 0xff;  
   
         mcs_make_domain_params(&mci->target_params,  2, 2, 0, 0xffff);  
         mcs_make_domain_params(&mci->minimum_params, 1, 1, 1, 0x420);  
         mcs_make_domain_params(&mci->maximum_params, 0xffff, 0xfc17, 0xffff,  
                                0xffff);  
   
         mci->user_data.length = sizeof(precanned_connect_userdata);  
         mci->user_data.data = precanned_connect_userdata;  
   
         mci->length = 2*2 + 3 + 3*34 + 4 + mci->user_data.length;  
 }  
   
 /* Marshall/demarshall an ASN.1 BER header */  
 BOOL ber_io_header(STREAM s, BOOL islong, int tagval, int *length)  
 {  
         uint16 word_tag;  
         uint8 byte_tag;  
         uint16 word_len;  
         uint8 byte_len;  
         uint8 byte_int;  
         int tag;  
         BOOL res;  
   
         /* Read/write tag */  
         if (islong)  
         {  
                 word_tag = tagval;  
                 res = msb_io_uint16(s, &word_tag);  
                 tag = word_tag;  
         }  
         else  
165          {          {
166                  byte_tag = tagval;                  error("MCS connect: %d\n", result);
                 res = prs_io_uint8(s, &byte_tag);  
                 tag = byte_tag;  
         }  
   
         if (!res || (tag != tagval))  
         {  
                 fprintf(stderr, "Invalid ASN.1 tag\n");  
167                  return False;                  return False;
168          }          }
169    
170          /* Read/write length */          ber_parse_header(s, BER_TAG_INTEGER, &length);
171          if (s->marshall)          in_uint8s(s, length);   /* connect id */
172          {          mcs_parse_domain_params(s);
                 if (*length >= 0x80)  
                 {  
                         byte_len = 0x82;  
                         word_len = (uint16)*length;  
                         res = prs_io_uint8(s, &byte_len);  
                         res = res ? msb_io_uint16(s, &word_len) : False;  
                 }  
                 else  
                 {  
                         byte_len = (uint8)*length;  
                         res = prs_io_uint8(s, &byte_len);  
                 }  
         }  
         else  
         {  
                 if (!prs_io_uint8(s, &byte_len))  
                         return False;  
173    
174                  if (byte_len & 0x80)          ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
                 {  
                         byte_len &= ~0x80;  
                         *length = 0;  
                         while (byte_len--)  
                         {  
                                 if (!prs_io_uint8(s, &byte_int))  
                                         return False;  
   
                                 *length <<= 8;  
                                 *length += byte_int;  
                         }  
                 }  
                 else *length = byte_len;  
         }  
175    
176          return res;          sec_process_mcs_data(s);
177            /*
178               if (length > mcs_data->size)
179               {
180               error("MCS data length %d, expected %d\n", length,
181               mcs_data->size);
182               length = mcs_data->size;
183               }
184    
185               in_uint8a(s, mcs_data->data, length);
186               mcs_data->p = mcs_data->data;
187               mcs_data->end = mcs_data->data + length;
188             */
189            return s_check_end(s);
190  }  }
191    
192  /* Marshall/demarshall an octet string (ASN.1 BER) */  /* Send an EDrq message (ASN.1 PER) */
193  BOOL ber_io_octet_string(STREAM s, OCTET_STRING *os)  static void
194    mcs_send_edrq(void)
195  {  {
196          if (!ber_io_header(s, False, 4, &os->length))          STREAM s;
                 return False;  
197    
198          if (os->length > s->end - s->offset)          s = iso_init(5);
                 return False;  
199    
200          if (s->marshall)          out_uint8(s, (MCS_EDRQ << 2));
201          {          out_uint16_be(s, 1);    /* height */
202                  memcpy(s->data + s->offset, os->data, os->length);          out_uint16_be(s, 1);    /* interval */
         }  
         else  
         {  
                 os->data = malloc(os->length);  
                 memcpy(os->data, s->data + s->offset, os->length);  
         }  
203    
204          s->offset += os->length;          s_mark_end(s);
205          return True;          iso_send(s);
206  }  }
207    
208  /* Marshall/demarshall an integer (ASN.1 BER) */  /* Send an AUrq message (ASN.1 PER) */
209  BOOL ber_io_integer(STREAM s, uint16 *word_int)  static void
210    mcs_send_aurq(void)
211  {  {
212          int length = 2;          STREAM s;
         uint8 byte_int;  
         BOOL res;  
213    
214          if (!ber_io_header(s, False, 2, &length))          s = iso_init(1);
                 return False;  
215    
216          if (s->marshall)          out_uint8(s, (MCS_AURQ << 2));
         {  
                 res = msb_io_uint16(s, word_int);  
         }  
         else  
         {  
                 *word_int = 0;  
                 while (length--)  
                 {  
                         if (!prs_io_uint8(s, &byte_int))  
                                 return False;  
217    
218                          *word_int <<= 8;          s_mark_end(s);
219                          *word_int += byte_int;          iso_send(s);
                 }  
         }  
   
         return res;  
220  }  }
221    
222  /* Marshall/demarshall a simple uint8 type (ASN.1 BER) */  /* Expect a AUcf message (ASN.1 PER) */
223  BOOL ber_io_uint8(STREAM s, uint8 *i, int tagval)  static BOOL
224    mcs_recv_aucf(uint16 * mcs_userid)
225  {  {
226          int length = 1;          uint8 opcode, result;
227            STREAM s;
228    
229          if (!ber_io_header(s, False, tagval, &length))          s = iso_recv();
230            if (s == NULL)
231                  return False;                  return False;
232    
233          if (length != 1)          in_uint8(s, opcode);
234            if ((opcode >> 2) != MCS_AUCF)
235          {          {
236                  fprintf(stderr, "Wrong length for simple type\n");                  error("expected AUcf, got %d\n", opcode);
237                  return False;                  return False;
238          }          }
239    
240          return prs_io_uint8(s, i);          in_uint8(s, result);
241  }          if (result != 0)
242            {
243  /* Marshall/demarshall a DOMAIN_PARAMS structure (ASN.1 BER) */                  error("AUrq: %d\n", result);
244  BOOL mcs_io_domain_params(STREAM s, DOMAIN_PARAMS *dp)                  return False;
245  {          }
         int length = 32;  
         BOOL res;  
246    
247          res = ber_io_header(s, False, 0x30, &length);          if (opcode & 2)
248          res = res ? ber_io_integer(s, &dp->max_channels  ) : False;                  in_uint16_be(s, *mcs_userid);
         res = res ? ber_io_integer(s, &dp->max_users     ) : False;  
         res = res ? ber_io_integer(s, &dp->max_tokens    ) : False;  
         res = res ? ber_io_integer(s, &dp->num_priorities) : False;  
         res = res ? ber_io_integer(s, &dp->min_throughput) : False;  
         res = res ? ber_io_integer(s, &dp->max_height    ) : False;  
         res = res ? ber_io_integer(s, &dp->max_pdusize   ) : False;  
         res = res ? ber_io_integer(s, &dp->ver_protocol  ) : False;  
249    
250          return res;          return s_check_end(s);
251  }  }
252    
253  /* Marshall/demarshall a MCS_CONNECT_INITIAL structure (ASN.1 BER) */  /* Send a CJrq message (ASN.1 PER) */
254  BOOL mcs_io_connect_initial(STREAM s, MCS_CONNECT_INITIAL *mci)  static void
255    mcs_send_cjrq(uint16 chanid)
256  {  {
257          BOOL res;          STREAM s;
258    
259          res = ber_io_header(s, True, 0x7f65, &mci->length);          DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
         res = res ? ber_io_octet_string (s, &mci->calling_domain) : False;  
         res = res ? ber_io_octet_string (s, &mci->called_domain ) : False;  
         res = res ? ber_io_uint8        (s, &mci->upward_flag, 1) : False;  
         res = res ? mcs_io_domain_params(s, &mci->target_params ) : False;  
         res = res ? mcs_io_domain_params(s, &mci->minimum_params) : False;  
         res = res ? mcs_io_domain_params(s, &mci->maximum_params) : False;  
         res = res ? ber_io_octet_string (s, &mci->user_data     ) : False;  
260    
261          return res;          s = iso_init(5);
 }  
   
 /* Marshall/demarshall a MCS_CONNECT_RESPONSE structure (ASN.1 BER) */  
 BOOL mcs_io_connect_response(STREAM s, MCS_CONNECT_RESPONSE *mcr)  
 {  
         BOOL res;  
262    
263          res = ber_io_header(s, True, 0x7f66, &mcr->length);          out_uint8(s, (MCS_CJRQ << 2));
264          res = res ? ber_io_uint8        (s, &mcr->result, 10   ) : False;          out_uint16_be(s, g_mcs_userid);
265          res = res ? ber_io_integer      (s, &mcr->connect_id   ) : False;          out_uint16_be(s, chanid);
         res = res ? mcs_io_domain_params(s, &mcr->domain_params) : False;  
         res = res ? ber_io_octet_string (s, &mcr->user_data    ) : False;  
266    
267          return res;          s_mark_end(s);
268            iso_send(s);
269  }  }
270    
271  /* Marshall/demarshall an EDrq structure (ASN.1 PER) */  /* Expect a CJcf message (ASN.1 PER) */
272  BOOL mcs_io_edrq(STREAM s, MCS_EDRQ *edrq)  static BOOL
273    mcs_recv_cjcf(void)
274  {  {
275          uint8 opcode = (1) << 2;          uint8 opcode, result;
276          uint8 pkt_opcode = opcode;          STREAM s;
         BOOL res;  
277    
278          res = prs_io_uint8(s, &pkt_opcode);          s = iso_recv();
279          if (pkt_opcode != opcode)          if (s == NULL)
280                    return False;
281    
282            in_uint8(s, opcode);
283            if ((opcode >> 2) != MCS_CJCF)
284          {          {
285                  fprintf(stderr, "Expected EDrq, received %x\n", pkt_opcode);                  error("expected CJcf, got %d\n", opcode);
286                  return False;                  return False;
287          }          }
288    
289          res = res ? msb_io_uint16(s, &edrq->height  ) : False;          in_uint8(s, result);
290          res = res ? msb_io_uint16(s, &edrq->interval) : False;          if (result != 0)
291            {
292                    error("CJrq: %d\n", result);
293                    return False;
294            }
295    
296          return res;          in_uint8s(s, 4);        /* mcs_userid, req_chanid */
297            if (opcode & 2)
298                    in_uint8s(s, 2);        /* join_chanid */
299    
300            return s_check_end(s);
301  }  }
302    
303  /* Marshall/demarshall an AUrq structure (ASN.1 PER) */  /* Initialise an MCS transport data packet */
304  BOOL mcs_io_aurq(STREAM s, MCS_AURQ *aurq)  STREAM
305    mcs_init(int length)
306  {  {
307          uint8 opcode = (10) << 2;          STREAM s;
         uint8 pkt_opcode = opcode;  
         BOOL res;  
308    
309          res = prs_io_uint8(s, &pkt_opcode);          s = iso_init(length + 8);
310          if (pkt_opcode != opcode)          s_push_layer(s, mcs_hdr, 8);
         {  
                 fprintf(stderr, "Expected AUrq, received %x\n", pkt_opcode);  
                 return False;  
         }  
311    
312          return res;          return s;
313  }  }
314    
315  /* Marshall/demarshall an AUcf structure (ASN.1 PER) */  /* Send an MCS transport data packet to a specific channel */
316  BOOL mcs_io_aucf(STREAM s, MCS_AUCF *aucf)  void
317    mcs_send_to_channel(STREAM s, uint16 channel)
318  {  {
319          uint8 opcode = (11) << 2;          uint16 length;
         uint8 pkt_opcode = opcode | 2;  
         BOOL res;  
320    
321          res = prs_io_uint8(s, &pkt_opcode);          s_pop_layer(s, mcs_hdr);
322          if ((pkt_opcode & 0xfc) != opcode)          length = s->end - s->p - 8;
323          {          length |= 0x8000;
                 fprintf(stderr, "Expected AUcf, received %x\n", pkt_opcode);  
                 return False;  
         }  
324    
325          res = res ? prs_io_uint8 (s, &aucf->result) : False;          out_uint8(s, (MCS_SDRQ << 2));
326          if (pkt_opcode & 2)          out_uint16_be(s, g_mcs_userid);
327                  res = res ? msb_io_uint16(s, &aucf->userid) : False;          out_uint16_be(s, channel);
328            out_uint8(s, 0x70);     /* flags */
329            out_uint16_be(s, length);
330    
331          return res;          iso_send(s);
332  }  }
333    
334  /* Marshall/demarshall an CJrq structure (ASN.1 PER) */  /* Send an MCS transport data packet to the global channel */
335  BOOL mcs_io_cjrq(STREAM s, MCS_CJRQ *cjrq)  void
336    mcs_send(STREAM s)
337  {  {
338          uint8 opcode = (14) << 2;          mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
339          uint8 pkt_opcode = opcode;  }
340          BOOL res;  
341    /* Receive an MCS transport data packet */
342    STREAM
343    mcs_recv(uint16 * channel)
344    {
345            uint8 opcode, appid, length;
346            STREAM s;
347    
348          res = prs_io_uint8(s, &pkt_opcode);          s = iso_recv();
349          if (pkt_opcode != opcode)          if (s == NULL)
350                    return NULL;
351    
352            in_uint8(s, opcode);
353            appid = opcode >> 2;
354            if (appid != MCS_SDIN)
355          {          {
356                  fprintf(stderr, "Expected CJrq, received %x\n", pkt_opcode);                  if (appid != MCS_DPUM)
357                  return False;                  {
358                            error("expected data, got %d\n", opcode);
359                    }
360                    return NULL;
361          }          }
362    
363          res = res ? msb_io_uint16(s, &cjrq->userid) : False;          in_uint8s(s, 2);        /* userid */
364          res = res ? msb_io_uint16(s, &cjrq->chanid) : False;          in_uint16_be(s, *channel);
365            in_uint8s(s, 1);        /* flags */
366            in_uint8(s, length);
367            if (length & 0x80)
368                    in_uint8s(s, 1);        /* second byte of length */
369    
370          return res;          return s;
371  }  }
372    
373  /* Marshall/demarshall an CJcf structure (ASN.1 PER) */  /* Establish a connection up to the MCS layer */
374  BOOL mcs_io_cjcf(STREAM s, MCS_CJCF *cjcf)  BOOL
375    mcs_connect(char *server, STREAM mcs_data, char *username)
376  {  {
377          uint8 opcode = (15) << 2;          uint16 num_channels, i;
378          uint8 pkt_opcode = opcode | 2;          rdp5_channel *channel;
379          BOOL res;          if (!iso_connect(server, username))
   
         res = prs_io_uint8(s, &pkt_opcode);  
         if ((pkt_opcode & 0xfc) != opcode)  
         {  
                 fprintf(stderr, "Expected CJcf, received %x\n", pkt_opcode);  
380                  return False;                  return False;
         }  
381    
382          res = res ? prs_io_uint8 (s, &cjcf->result) : False;          mcs_send_connect_initial(mcs_data);
383          res = res ? msb_io_uint16(s, &cjcf->userid) : False;          if (!mcs_recv_connect_response(mcs_data))
384          res = res ? msb_io_uint16(s, &cjcf->req_chanid) : False;                  goto error;
         if (pkt_opcode & 2)  
                 res = res ? msb_io_uint16(s, &cjcf->join_chanid) : False;  
385    
386          return res;          mcs_send_edrq();
 }  
387    
388  /* Marshall/demarshall an SDrq or SDin packet (ASN.1 PER) */          mcs_send_aurq();
389  BOOL mcs_io_data(STREAM s, MCS_DATA *dt, BOOL request)          if (!mcs_recv_aucf(&g_mcs_userid))
390  {                  goto error;
         uint8 opcode = (request ? 25 : 26) << 2;  
         uint8 pkt_opcode = opcode;  
         uint8 byte1, byte2;  
         BOOL res;  
391    
392          res = prs_io_uint8(s, &pkt_opcode);          mcs_send_cjrq(g_mcs_userid + MCS_USERCHANNEL_BASE);
         if (pkt_opcode != opcode)  
         {  
                 fprintf(stderr, "Expected MCS data, received %x\n", pkt_opcode);  
                 return False;  
         }  
393    
394          dt->length |= 0x8000;          if (!mcs_recv_cjcf())
395                    goto error;
396    
397          res = res ? msb_io_uint16(s, &dt->userid) : False;          mcs_send_cjrq(MCS_GLOBAL_CHANNEL);
398          res = res ? msb_io_uint16(s, &dt->chanid) : False;          if (!mcs_recv_cjcf())
399          res = res ? prs_io_uint8 (s, &dt->flags ) : False;                  goto error;
400    
401          if (s->marshall)          if (use_rdp5)
402          {          {
403                  res = res ? msb_io_uint16(s, &dt->length) : False;                  num_channels = get_num_channels();
404          }                  for (i = 0; i < num_channels; i++)
         else  
         {  
                 res = res ? prs_io_uint8(s, &byte1) : False;  
                 if (byte1 & 0x80)  
405                  {                  {
406                          res = res ? prs_io_uint8(s, &byte2) : False;                          channel = find_channel_by_num(i);
407                          dt->length = ((byte1 & ~0x80) << 8) + byte2;                          mcs_send_cjrq(channel->channelno);
408                            if (!mcs_recv_cjcf())
409                                    goto error;
410                  }                  }
                 else dt->length = byte1;  
411          }          }
412    
413          return res;          return True;
414    
415          error:
416            iso_disconnect();
417            return False;
418  }  }
419    
420    /* Disconnect from the MCS layer */
421    void
422    mcs_disconnect(void)
423    {
424            iso_disconnect();
425    }

Legend:
Removed from v.7  
changed lines
  Added in v.409

  ViewVC Help
Powered by ViewVC 1.1.26