/[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 25 by matty, Sat Jan 6 03:47:04 2001 UTC
# 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          {          {
# 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,
93                          int max_tokens, int max_pdusize)
94  {  {
95          ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);          ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);
96          ber_out_integer(s, max_channels);          ber_out_integer(s, max_channels);
97          ber_out_integer(s, max_users);          ber_out_integer(s, max_users);
98          ber_out_integer(s, max_tokens);          ber_out_integer(s, max_tokens);
99          ber_out_integer(s, 1); /* num_priorities */          ber_out_integer(s, 1);  /* num_priorities */
100          ber_out_integer(s, 0); /* min_throughput */          ber_out_integer(s, 0);  /* min_throughput */
101          ber_out_integer(s, 1); /* max_height */          ber_out_integer(s, 1);  /* max_height */
102          ber_out_integer(s, max_pdusize);          ber_out_integer(s, max_pdusize);
103          ber_out_integer(s, 2); /* ver_protocol */          ber_out_integer(s, 2);  /* ver_protocol */
104  }  }
105    
106  /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */  /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
107  static BOOL mcs_parse_domain_params(STREAM s)  static BOOL
108    mcs_parse_domain_params(STREAM s)
109  {  {
110          int length;          int length;
111    
# Line 110  static BOOL mcs_parse_domain_params(STRE Line 116  static BOOL mcs_parse_domain_params(STRE
116  }  }
117    
118  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
119  static void mcs_send_connect_initial(STREAM mcs_data)  static void
120    mcs_send_connect_initial(STREAM mcs_data)
121  {  {
122          int datalen = mcs_data->end - mcs_data->data;          int datalen = mcs_data->end - mcs_data->data;
123          int length = 7 + 3*34 + 4 + datalen;          int length = 7 + 3 * 34 + 4 + datalen;
124          STREAM s;          STREAM s;
125    
126          s = iso_init(length + 5);          s = iso_init(length + 5);
127    
128          ber_out_header(s, MCS_CONNECT_INITIAL, length);          ber_out_header(s, MCS_CONNECT_INITIAL, length);
129          ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* calling domain */          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* calling domain */
130          ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* called domain */          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* called domain */
131    
132          ber_out_header(s, BER_TAG_BOOLEAN, 1);          ber_out_header(s, BER_TAG_BOOLEAN, 1);
133          out_uint8(s, 0xff); /* upward flag */          out_uint8(s, 0xff);     /* upward flag */
134    
135          mcs_out_domain_params(s, 2, 2, 0, 0xffff); /* target params */          mcs_out_domain_params(s, 2, 2, 0, 0xffff);      /* target params */
136          mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */          mcs_out_domain_params(s, 1, 1, 1, 0x420);       /* min params */
137          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);       /* max params */
138    
139          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);
140          out_uint8p(s, mcs_data->data, datalen);          out_uint8p(s, mcs_data->data, datalen);
# Line 137  static void mcs_send_connect_initial(STR Line 144  static void mcs_send_connect_initial(STR
144  }  }
145    
146  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
147  static BOOL mcs_recv_connect_response(STREAM mcs_data)  static BOOL
148    mcs_recv_connect_response(STREAM mcs_data)
149  {  {
150          uint8 result;          uint8 result;
151          int length;          int length;
# Line 158  static BOOL mcs_recv_connect_response(ST Line 166  static BOOL mcs_recv_connect_response(ST
166          }          }
167    
168          ber_parse_header(s, BER_TAG_INTEGER, &length);          ber_parse_header(s, BER_TAG_INTEGER, &length);
169          in_uint8s(s, length); /* connect id */          in_uint8s(s, length);   /* connect id */
170          mcs_parse_domain_params(s);          mcs_parse_domain_params(s);
171    
172          ber_parse_header(s, BER_TAG_OCTET_STRING, &length);          ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
# Line 176  static BOOL mcs_recv_connect_response(ST Line 184  static BOOL mcs_recv_connect_response(ST
184  }  }
185    
186  /* Send an EDrq message (ASN.1 PER) */  /* Send an EDrq message (ASN.1 PER) */
187  static void mcs_send_edrq()  static void
188    mcs_send_edrq()
189  {  {
190          STREAM s;          STREAM s;
191    
192          s = iso_init(5);          s = iso_init(5);
193    
194          out_uint8(s, (MCS_EDRQ << 2));          out_uint8(s, (MCS_EDRQ << 2));
195          out_uint16_be(s, 1); /* height */          out_uint16_be(s, 1);    /* height */
196          out_uint16_be(s, 1); /* interval */          out_uint16_be(s, 1);    /* interval */
197    
198          s_mark_end(s);          s_mark_end(s);
199          iso_send(s);          iso_send(s);
200  }  }
201    
202  /* Send an AUrq message (ASN.1 PER) */  /* Send an AUrq message (ASN.1 PER) */
203  static void mcs_send_aurq()  static void
204    mcs_send_aurq()
205  {  {
206          STREAM s;          STREAM s;
207    
# Line 204  static void mcs_send_aurq() Line 214  static void mcs_send_aurq()
214  }  }
215    
216  /* Expect a AUcf message (ASN.1 PER) */  /* Expect a AUcf message (ASN.1 PER) */
217  static BOOL mcs_recv_aucf(uint16 *mcs_userid)  static BOOL
218    mcs_recv_aucf(uint16 *mcs_userid)
219  {  {
220          uint8 opcode, result;          uint8 opcode, result;
221          STREAM s;          STREAM s;
# Line 234  static BOOL mcs_recv_aucf(uint16 *mcs_us Line 245  static BOOL mcs_recv_aucf(uint16 *mcs_us
245  }  }
246    
247  /* Send a CJrq message (ASN.1 PER) */  /* Send a CJrq message (ASN.1 PER) */
248  static void mcs_send_cjrq(uint16 chanid)  static void
249    mcs_send_cjrq(uint16 chanid)
250  {  {
251          STREAM s;          STREAM s;
252    
# Line 249  static void mcs_send_cjrq(uint16 chanid) Line 261  static void mcs_send_cjrq(uint16 chanid)
261  }  }
262    
263  /* Expect a CJcf message (ASN.1 PER) */  /* Expect a CJcf message (ASN.1 PER) */
264  static BOOL mcs_recv_cjcf()  static BOOL
265    mcs_recv_cjcf()
266  {  {
267          uint8 opcode, result;          uint8 opcode, result;
268          STREAM s;          STREAM s;
# Line 272  static BOOL mcs_recv_cjcf() Line 285  static BOOL mcs_recv_cjcf()
285                  return False;                  return False;
286          }          }
287    
288          in_uint8s(s, 4); /* mcs_userid, req_chanid */          in_uint8s(s, 4);        /* mcs_userid, req_chanid */
289          if (opcode & 2)          if (opcode & 2)
290                  in_uint8s(s, 2); /* join_chanid */                  in_uint8s(s, 2);        /* join_chanid */
291    
292          return s_check_end(s);          return s_check_end(s);
293  }  }
294    
295  /* Initialise an MCS transport data packet */  /* Initialise an MCS transport data packet */
296  STREAM mcs_init(int length)  STREAM
297    mcs_init(int length)
298  {  {
299          STREAM s;          STREAM s;
300    
# Line 291  STREAM mcs_init(int length) Line 305  STREAM mcs_init(int length)
305  }  }
306    
307  /* Send an MCS transport data packet */  /* Send an MCS transport data packet */
308  void mcs_send(STREAM s)  void
309    mcs_send(STREAM s)
310  {  {
311          uint16 length;          uint16 length;
312    
# Line 302  void mcs_send(STREAM s) Line 317  void mcs_send(STREAM s)
317          out_uint8(s, (MCS_SDRQ << 2));          out_uint8(s, (MCS_SDRQ << 2));
318          out_uint16_be(s, mcs_userid);          out_uint16_be(s, mcs_userid);
319          out_uint16_be(s, MCS_GLOBAL_CHANNEL);          out_uint16_be(s, MCS_GLOBAL_CHANNEL);
320          out_uint8(s, 0x70); /* flags */          out_uint8(s, 0x70);     /* flags */
321          out_uint16_be(s, length);          out_uint16_be(s, length);
322    
323          iso_send(s);          iso_send(s);
324  }  }
325    
326  /* Receive an MCS transport data packet */  /* Receive an MCS transport data packet */
327  STREAM mcs_recv()  STREAM
328    mcs_recv()
329  {  {
330          uint8 opcode, appid, length;          uint8 opcode, appid, length;
331          STREAM s;          STREAM s;
# Line 329  STREAM mcs_recv() Line 345  STREAM mcs_recv()
345                  return NULL;                  return NULL;
346          }          }
347    
348          in_uint8s(s, 5); /* userid, chanid, flags */          in_uint8s(s, 5);        /* userid, chanid, flags */
349          in_uint8(s, length);          in_uint8(s, length);
350          if (length & 0x80)          if (length & 0x80)
351                  in_uint8s(s, 1); /* second byte of length */                  in_uint8s(s, 1);        /* second byte of length */
352    
353          return s;          return s;
354  }  }
355    
356  /* Establish a connection up to the MCS layer */  /* Establish a connection up to the MCS layer */
357  BOOL mcs_connect(char *server, STREAM mcs_data)  BOOL
358    mcs_connect(char *server, STREAM mcs_data)
359  {  {
360          if (!iso_connect(server))          if (!iso_connect(server))
361                  return False;                  return False;
# Line 363  BOOL mcs_connect(char *server, STREAM mc Line 380  BOOL mcs_connect(char *server, STREAM mc
380    
381          return True;          return True;
382    
383   error:        error:
384          iso_disconnect();          iso_disconnect();
385          return False;          return False;
386  }  }
387    
388  /* Disconnect from the MCS layer */  /* Disconnect from the MCS layer */
389  void mcs_disconnect()  void
390    mcs_disconnect()
391  {  {
392          iso_disconnect();          iso_disconnect();
393  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26