/[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 10 by matty, Tue Aug 15 10:23:24 2000 UTC revision 207 by matthewc, Thu Sep 26 14:26:46 2002 UTC
# Line 1  Line 1 
1  /*  /*
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 23  Line 23 
23  uint16 mcs_userid;  uint16 mcs_userid;
24    
25  /* Parse an ASN.1 BER header */  /* Parse an ASN.1 BER header */
26  static BOOL ber_parse_header(STREAM s, int tagval, int *length)  static BOOL
27    ber_parse_header(STREAM s, int tagval, int *length)
28  {  {
29          int tag, len;          int tag, len;
30    
# Line 33  static BOOL ber_parse_header(STREAM s, i Line 34  static BOOL ber_parse_header(STREAM s, i
34          }          }
35          else          else
36          {          {
37                  in_uint8(s, tag)          in_uint8(s, tag)}
         }  
38    
39          if (tag != tagval)          if (tag != tagval)
40          {          {
41                  ERROR("expected tag %d, got %d\n", tagval, tag);                  error("expected tag %d, got %d\n", tagval, tag);
42                  return False;                  return False;
43          }          }
44    
# Line 51  static BOOL ber_parse_header(STREAM s, i Line 51  static BOOL ber_parse_header(STREAM s, i
51                  while (len--)                  while (len--)
52                          next_be(s, *length);                          next_be(s, *length);
53          }          }
54          else *length = len;          else
55                    *length = len;
56    
57          return s_check(s);          return s_check(s);
58  }  }
59    
60  /* Output an ASN.1 BER header */  /* Output an ASN.1 BER header */
61  static void ber_out_header(STREAM s, int tagval, int length)  static void
62    ber_out_header(STREAM s, int tagval, int length)
63  {  {
64          if (tagval > 0xff)          if (tagval > 0xff)
65          {          {
# Line 73  static void ber_out_header(STREAM s, int Line 75  static void ber_out_header(STREAM s, int
75                  out_uint8(s, 0x82);                  out_uint8(s, 0x82);
76                  out_uint16_be(s, length);                  out_uint16_be(s, length);
77          }          }
78          else out_uint8(s, length);          else
79                    out_uint8(s, length);
80  }  }
81    
82  /* Output an ASN.1 BER integer */  /* Output an ASN.1 BER integer */
83  static void ber_out_integer(STREAM s, int value)  static void
84    ber_out_integer(STREAM s, int value)
85  {  {
86          ber_out_header(s, BER_TAG_INTEGER, 2);          ber_out_header(s, BER_TAG_INTEGER, 2);
87          out_uint16_be(s, value);          out_uint16_be(s, value);
88  }  }
89    
90  /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */  /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
91  static void mcs_out_domain_params(STREAM s, int max_channels, int max_users,  static void
92                             int max_tokens, int max_pdusize)  mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize)
93  {  {
94          ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);          ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);
95          ber_out_integer(s, max_channels);          ber_out_integer(s, max_channels);
96          ber_out_integer(s, max_users);          ber_out_integer(s, max_users);
97          ber_out_integer(s, max_tokens);          ber_out_integer(s, max_tokens);
98          ber_out_integer(s, 1); /* num_priorities */          ber_out_integer(s, 1);  /* num_priorities */
99          ber_out_integer(s, 0); /* min_throughput */          ber_out_integer(s, 0);  /* min_throughput */
100          ber_out_integer(s, 1); /* max_height */          ber_out_integer(s, 1);  /* max_height */
101          ber_out_integer(s, max_pdusize);          ber_out_integer(s, max_pdusize);
102          ber_out_integer(s, 2); /* ver_protocol */          ber_out_integer(s, 2);  /* ver_protocol */
103  }  }
104    
105  /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */  /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
106  static BOOL mcs_parse_domain_params(STREAM s)  static BOOL
107    mcs_parse_domain_params(STREAM s)
108  {  {
109          int length;          int length;
110    
# Line 110  static BOOL mcs_parse_domain_params(STRE Line 115  static BOOL mcs_parse_domain_params(STRE
115  }  }
116    
117  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
118  static void mcs_send_connect_initial(STREAM mcs_data)  static void
119    mcs_send_connect_initial(STREAM mcs_data)
120  {  {
121          int datalen = mcs_data->end - mcs_data->data;          int datalen = mcs_data->end - mcs_data->data;
122          int length = 7 + 3*34 + 4 + datalen;          int length = 7 + 3 * 34 + 4 + datalen;
123          STREAM s;          STREAM s;
124    
125          s = iso_init(length + 5);          s = iso_init(length + 5);
126    
127          ber_out_header(s, MCS_CONNECT_INITIAL, length);          ber_out_header(s, MCS_CONNECT_INITIAL, length);
128          ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* calling domain */          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* calling domain */
129          ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* called domain */          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* called domain */
130    
131          ber_out_header(s, BER_TAG_BOOLEAN, 1);          ber_out_header(s, BER_TAG_BOOLEAN, 1);
132          out_uint8(s, 0xff); /* upward flag */          out_uint8(s, 0xff);     /* upward flag */
133    
134          mcs_out_domain_params(s, 2, 2, 0, 0xffff); /* target params */          mcs_out_domain_params(s, 2, 2, 0, 0xffff);      /* target params */
135          mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */          mcs_out_domain_params(s, 1, 1, 1, 0x420);       /* min params */
136          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);       /* max params */
137    
138          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);
139          out_uint8p(s, mcs_data->data, datalen);          out_uint8p(s, mcs_data->data, datalen);
# Line 137  static void mcs_send_connect_initial(STR Line 143  static void mcs_send_connect_initial(STR
143  }  }
144    
145  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
146  static BOOL mcs_recv_connect_response(STREAM mcs_data)  static BOOL
147    mcs_recv_connect_response(STREAM mcs_data)
148  {  {
149          uint8 result;          uint8 result;
150          int length;          int length;
# Line 153  static BOOL mcs_recv_connect_response(ST Line 160  static BOOL mcs_recv_connect_response(ST
160          in_uint8(s, result);          in_uint8(s, result);
161          if (result != 0)          if (result != 0)
162          {          {
163                  ERROR("MCS connect: %d\n", result);                  error("MCS connect: %d\n", result);
164                  return False;                  return False;
165          }          }
166    
167          ber_parse_header(s, BER_TAG_INTEGER, &length);          ber_parse_header(s, BER_TAG_INTEGER, &length);
168          in_uint8s(s, length); /* connect id */          in_uint8s(s, length);   /* connect id */
169          mcs_parse_domain_params(s);          mcs_parse_domain_params(s);
170    
171          ber_parse_header(s, BER_TAG_OCTET_STRING, &length);          ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
172          if (length > mcs_data->size)          if (length > mcs_data->size)
173          {          {
174                  WARN("MCS data length %d\n", length);                  error("MCS data length %d\n", length);
175                  length = mcs_data->size;                  length = mcs_data->size;
176          }          }
177    
# Line 176  static BOOL mcs_recv_connect_response(ST Line 183  static BOOL mcs_recv_connect_response(ST
183  }  }
184    
185  /* Send an EDrq message (ASN.1 PER) */  /* Send an EDrq message (ASN.1 PER) */
186  static void mcs_send_edrq()  static void
187    mcs_send_edrq(void)
188  {  {
189          STREAM s;          STREAM s;
190    
191          s = iso_init(5);          s = iso_init(5);
192    
193          out_uint8(s, (MCS_EDRQ << 2));          out_uint8(s, (MCS_EDRQ << 2));
194          out_uint16_be(s, 1); /* height */          out_uint16_be(s, 1);    /* height */
195          out_uint16_be(s, 1); /* interval */          out_uint16_be(s, 1);    /* interval */
196    
197          s_mark_end(s);          s_mark_end(s);
198          iso_send(s);          iso_send(s);
199  }  }
200    
201  /* Send an AUrq message (ASN.1 PER) */  /* Send an AUrq message (ASN.1 PER) */
202  static void mcs_send_aurq()  static void
203    mcs_send_aurq(void)
204  {  {
205          STREAM s;          STREAM s;
206    
# Line 204  static void mcs_send_aurq() Line 213  static void mcs_send_aurq()
213  }  }
214    
215  /* Expect a AUcf message (ASN.1 PER) */  /* Expect a AUcf message (ASN.1 PER) */
216  static BOOL mcs_recv_aucf(uint16 *mcs_userid)  static BOOL
217    mcs_recv_aucf(uint16 * mcs_userid)
218  {  {
219          uint8 opcode, result;          uint8 opcode, result;
220          STREAM s;          STREAM s;
# Line 216  static BOOL mcs_recv_aucf(uint16 *mcs_us Line 226  static BOOL mcs_recv_aucf(uint16 *mcs_us
226          in_uint8(s, opcode);          in_uint8(s, opcode);
227          if ((opcode >> 2) != MCS_AUCF)          if ((opcode >> 2) != MCS_AUCF)
228          {          {
229                  ERROR("expected AUcf, got %d\n", opcode);                  error("expected AUcf, got %d\n", opcode);
230                  return False;                  return False;
231          }          }
232    
233          in_uint8(s, result);          in_uint8(s, result);
234          if (result != 0)          if (result != 0)
235          {          {
236                  ERROR("AUrq: %d\n", result);                  error("AUrq: %d\n", result);
237                  return False;                  return False;
238          }          }
239    
# Line 234  static BOOL mcs_recv_aucf(uint16 *mcs_us Line 244  static BOOL mcs_recv_aucf(uint16 *mcs_us
244  }  }
245    
246  /* Send a CJrq message (ASN.1 PER) */  /* Send a CJrq message (ASN.1 PER) */
247  static void mcs_send_cjrq(uint16 chanid)  static void
248    mcs_send_cjrq(uint16 chanid)
249  {  {
250          STREAM s;          STREAM s;
251    
# Line 249  static void mcs_send_cjrq(uint16 chanid) Line 260  static void mcs_send_cjrq(uint16 chanid)
260  }  }
261    
262  /* Expect a CJcf message (ASN.1 PER) */  /* Expect a CJcf message (ASN.1 PER) */
263  static BOOL mcs_recv_cjcf()  static BOOL
264    mcs_recv_cjcf(void)
265  {  {
266          uint8 opcode, result;          uint8 opcode, result;
267          STREAM s;          STREAM s;
# Line 261  static BOOL mcs_recv_cjcf() Line 273  static BOOL mcs_recv_cjcf()
273          in_uint8(s, opcode);          in_uint8(s, opcode);
274          if ((opcode >> 2) != MCS_CJCF)          if ((opcode >> 2) != MCS_CJCF)
275          {          {
276                  ERROR("expected CJcf, got %d\n", opcode);                  error("expected CJcf, got %d\n", opcode);
277                  return False;                  return False;
278          }          }
279    
280          in_uint8(s, result);          in_uint8(s, result);
281          if (result != 0)          if (result != 0)
282          {          {
283                  ERROR("CJrq: %d\n", result);                  error("CJrq: %d\n", result);
284                  return False;                  return False;
285          }          }
286    
287          in_uint8s(s, 4); /* mcs_userid, req_chanid */          in_uint8s(s, 4);        /* mcs_userid, req_chanid */
288          if (opcode & 2)          if (opcode & 2)
289                  in_uint8s(s, 2); /* join_chanid */                  in_uint8s(s, 2);        /* join_chanid */
290    
291          return s_check_end(s);          return s_check_end(s);
292  }  }
293    
294  /* Initialise an MCS transport data packet */  /* Initialise an MCS transport data packet */
295  STREAM mcs_init(int length)  STREAM
296    mcs_init(int length)
297  {  {
298          STREAM s;          STREAM s;
299    
# Line 291  STREAM mcs_init(int length) Line 304  STREAM mcs_init(int length)
304  }  }
305    
306  /* Send an MCS transport data packet */  /* Send an MCS transport data packet */
307  void mcs_send(STREAM s)  void
308    mcs_send(STREAM s)
309  {  {
310          uint16 length;          uint16 length;
311    
# Line 302  void mcs_send(STREAM s) Line 316  void mcs_send(STREAM s)
316          out_uint8(s, (MCS_SDRQ << 2));          out_uint8(s, (MCS_SDRQ << 2));
317          out_uint16_be(s, mcs_userid);          out_uint16_be(s, mcs_userid);
318          out_uint16_be(s, MCS_GLOBAL_CHANNEL);          out_uint16_be(s, MCS_GLOBAL_CHANNEL);
319          out_uint8(s, 0x70); /* flags */          out_uint8(s, 0x70);     /* flags */
320          out_uint16_be(s, length);          out_uint16_be(s, length);
321    
322          iso_send(s);          iso_send(s);
323  }  }
324    
325  /* Receive an MCS transport data packet */  /* Receive an MCS transport data packet */
326  STREAM mcs_recv()  STREAM
327    mcs_recv(void)
328  {  {
329          uint8 opcode, appid, length;          uint8 opcode, appid, length;
330          STREAM s;          STREAM s;
# Line 324  STREAM mcs_recv() Line 339  STREAM mcs_recv()
339          {          {
340                  if (appid != MCS_DPUM)                  if (appid != MCS_DPUM)
341                  {                  {
342                          ERROR("expected data, got %d\n", opcode);                          error("expected data, got %d\n", opcode);
343                  }                  }
344                  return NULL;                  return NULL;
345          }          }
346    
347          in_uint8s(s, 5); /* userid, chanid, flags */          in_uint8s(s, 5);        /* userid, chanid, flags */
348          in_uint8(s, length);          in_uint8(s, length);
349          if (length & 0x80)          if (length & 0x80)
350                  in_uint8s(s, 1); /* second byte of length */                  in_uint8s(s, 1);        /* second byte of length */
351    
352          return s;          return s;
353  }  }
354    
355  /* Establish a connection up to the MCS layer */  /* Establish a connection up to the MCS layer */
356  BOOL mcs_connect(char *server, STREAM mcs_data)  BOOL
357    mcs_connect(char *server, STREAM mcs_data)
358  {  {
359          if (!iso_connect(server))          if (!iso_connect(server))
360                  return False;                  return False;
# Line 363  BOOL mcs_connect(char *server, STREAM mc Line 379  BOOL mcs_connect(char *server, STREAM mc
379    
380          return True;          return True;
381    
382   error:        error:
383          iso_disconnect();          iso_disconnect();
384          return False;          return False;
385  }  }
386    
387  /* Disconnect from the MCS layer */  /* Disconnect from the MCS layer */
388  void mcs_disconnect()  void
389    mcs_disconnect(void)
390  {  {
391          iso_disconnect();          iso_disconnect();
392  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26