/[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 4 by matty, Wed May 10 07:36:34 2000 UTC revision 64 by astrand, Thu Jul 18 16:38:31 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-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 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 mcs_userid;
 HCONN mcs_connect(char *server)  
 {  
         HCONN conn;  
         MCS_CONNECT_RESPONSE mcr;  
         MCS_AUCF aucf;  
24    
25          if ((conn = iso_connect(server)) == NULL)  /* Parse an ASN.1 BER header */
26                  return NULL;  static BOOL
27    ber_parse_header(STREAM s, int tagval, int *length)
28    {
29            int tag, len;
30    
31          mcs_send_connect_initial(conn);          if (tagval > 0xff)
         if (!iso_recv(conn) || !mcs_io_connect_response(&conn->in, &mcr))  
32          {          {
33                  fprintf(stderr, "MCS error, expected Connect-Response\n");                  in_uint16_be(s, tag);
                 iso_disconnect(conn);  
                 return NULL;  
34          }          }
35            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))  
36          {          {
37                  fprintf(stderr, "MCS error, expected AUcf\n");          in_uint8(s, tag)}
                 mcs_disconnect(conn);  
                 return NULL;  
         }  
38    
39          if (aucf.result != 0)          if (tag != tagval)
40          {          {
41                  fprintf(stderr, "AUrq failed, result %d\n", mcr.result);                  error("expected tag %d, got %d\n", tagval, tag);
42                  mcs_disconnect(conn);                  return False;
                 return NULL;  
43          }          }
44    
45          conn->mcs_userid = aucf.userid;          in_uint8(s, len);
46    
47          if (!mcs_join_channel(conn, aucf.userid + 1001)          if (len & 0x80)
             || !mcs_join_channel(conn, MCS_GLOBAL_CHANNEL))  
48          {          {
49                  mcs_disconnect(conn);                  len &= ~0x80;
50                  return NULL;                  *length = 0;
51                    while (len--)
52                            next_be(s, *length);
53          }          }
54            else
55                    *length = len;
56    
57          return conn;          return s_check(s);
58  }  }
59    
60  BOOL mcs_join_channel(HCONN conn, uint16 chanid)  /* Output an ASN.1 BER header */
61    static void
62    ber_out_header(STREAM s, int tagval, int length)
63  {  {
64          MCS_CJCF cjcf;          if (tagval > 0xff)
   
         mcs_send_cjrq(conn, chanid);  
         if (!iso_recv(conn) || !mcs_io_cjcf(&conn->in, &cjcf))  
65          {          {
66                  fprintf(stderr, "MCS error, expected CJcf\n");                  out_uint16_be(s, tagval);
                 return False;  
67          }          }
68            else
         if (cjcf.result != 0)  
69          {          {
70                  fprintf(stderr, "CJrq failed, result %d\n", cjcf.result);                  out_uint8(s, tagval);
                 return False;  
71          }          }
72    
73          return True;          if (length >= 0x80)
74            {
75                    out_uint8(s, 0x82);
76                    out_uint16_be(s, length);
77            }
78            else
79                    out_uint8(s, length);
80  }  }
81    
82  /* Disconnect from the MCS layer */  /* Output an ASN.1 BER integer */
83  void mcs_disconnect(HCONN conn)  static void
84    ber_out_integer(STREAM s, int value)
85  {  {
86          /* Not complete */          ber_out_header(s, BER_TAG_INTEGER, 2);
87          iso_disconnect(conn);          out_uint16_be(s, value);
88  }  }
89    
90  /* Send a Connect-Initial message */  /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
91  void mcs_send_connect_initial(HCONN conn)  static void
92    mcs_out_domain_params(STREAM s, int max_channels, int max_users,
93                          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;
   
         iso_init(conn);  
         edrq.height = edrq.interval = 1;  
         mcs_io_edrq(&conn->out, &edrq);  
         MARK_END(conn->out);  
         iso_send(conn);  
 }  
111    
112  /* Send a AUrq message */          ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length);
113  void mcs_send_aurq(HCONN conn)          in_uint8s(s, length);
 {  
         MCS_AURQ aurq;  
114    
115          iso_init(conn);          return s_check(s);
         mcs_io_aurq(&conn->out, &aurq);  
         MARK_END(conn->out);  
         iso_send(conn);  
116  }  }
117    
118  /* Send a CJrq message */  /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
119  void mcs_send_cjrq(HCONN conn, uint16 chanid)  static void
120    mcs_send_connect_initial(STREAM mcs_data)
121  {  {
122          MCS_CJRQ cjrq;          int datalen = mcs_data->end - mcs_data->data;
123            int length = 7 + 3 * 34 + 4 + datalen;
124            STREAM s;
125    
126          iso_init(conn);          s = iso_init(length + 5);
         cjrq.userid = conn->mcs_userid;  
         cjrq.chanid = chanid;  
         mcs_io_cjrq(&conn->out, &cjrq);  
         MARK_END(conn->out);  
         iso_send(conn);  
 }  
127    
128  /* Initialise MCS transport data packet */          ber_out_header(s, MCS_CONNECT_INITIAL, length);
129  void mcs_init_data(HCONN conn)          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* calling domain */
130  {          ber_out_header(s, BER_TAG_OCTET_STRING, 0);     /* called domain */
         iso_init(conn);  
         PUSH_LAYER(conn->out, mcs_offset, 8);  
 }  
131    
132  /* Transmit MCS transport data packet */          ber_out_header(s, BER_TAG_BOOLEAN, 1);
133  void mcs_send_data(HCONN conn, uint16 chanid, BOOL request)          out_uint8(s, 0xff);     /* upward flag */
 {  
         MCS_DATA dt;  
134    
135          POP_LAYER(conn->out, mcs_offset);          mcs_out_domain_params(s, 2, 2, 0, 0xffff);      /* target params */
136          dt.userid = conn->mcs_userid;          mcs_out_domain_params(s, 1, 1, 1, 0x420);       /* min params */
137          dt.chanid = chanid;          mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);       /* max params */
         dt.flags = 0x70;  
         dt.length = conn->out.end - conn->out.offset - 8;  
         mcs_io_data(&conn->out, &dt, request);  
         iso_send(conn);  
 }  
138    
139  /* Receive a message on the MCS layer */          ber_out_header(s, BER_TAG_OCTET_STRING, datalen);
140  BOOL mcs_recv(HCONN conn, BOOL request)          out_uint8p(s, mcs_data->data, datalen);
 {  
         MCS_DATA data;  
141    
142          return (iso_recv(conn)) && mcs_io_data(&conn->in, &data, request);          s_mark_end(s);
143            iso_send(s);
144  }  }
145    
146  /* Initialise a DOMAIN_PARAMS structure */  /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
147  void mcs_make_domain_params(DOMAIN_PARAMS *dp, uint16 max_channels,  static BOOL
148                uint16 max_users, uint16 max_tokens, uint16 max_pdusize)  mcs_recv_connect_response(STREAM mcs_data)
149  {  {
150          dp->max_channels   = max_channels;          uint8 result;
151          dp->max_users      = max_users;          int length;
152          dp->max_tokens     = max_tokens;          STREAM s;
         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);  
153    
154          mci->user_data.length = sizeof(precanned_connect_userdata);          s = iso_recv();
155          mci->user_data.data = precanned_connect_userdata;          if (s == NULL)
156                    return False;
         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;  
157    
158          /* Read/write tag */          ber_parse_header(s, MCS_CONNECT_RESPONSE, &length);
         if (islong) {  
                 word_tag = tagval;  
                 res = msb_io_uint16(s, &word_tag);  
                 tag = word_tag;  
         } else {  
                 byte_tag = tagval;  
                 res = prs_io_uint8(s, &byte_tag);  
                 tag = byte_tag;  
         }  
159    
160          if (!res || (tag != tagval)) {          ber_parse_header(s, BER_TAG_RESULT, &length);
161                  fprintf(stderr, "Invalid ASN.1 tag\n");          in_uint8(s, result);
162            if (result != 0)
163            {
164                    error("MCS connect: %d\n", result);
165                  return False;                  return False;
166          }          }
167    
168          /* Read/write length */          ber_parse_header(s, BER_TAG_INTEGER, &length);
169          if (s->marshall)          in_uint8s(s, length);   /* connect id */
170            mcs_parse_domain_params(s);
171    
172            ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
173            if (length > mcs_data->size)
174          {          {
175                  if (*length >= 0x80)                  error("MCS data length %d\n", length);
176                  {                  length = mcs_data->size;
                         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);  
                 }  
177          }          }
         else  
         {  
                 if (!prs_io_uint8(s, &byte_len))  
                         return False;  
178    
179                  if (byte_len & 0x80)          in_uint8a(s, mcs_data->data, length);
180                  {          mcs_data->p = mcs_data->data;
181                          byte_len &= ~0x80;          mcs_data->end = mcs_data->data + length;
                         *length = 0;  
                         while (byte_len--)  
                         {  
                                 if (!prs_io_uint8(s, &byte_int))  
                                         return False;  
   
                                 *length <<= 8;  
                                 *length += byte_int;  
                         }  
                 }  
                 else *length = byte_len;  
         }  
182    
183          return res;          return s_check_end(s);
184  }  }
185    
186  /* Marshall/demarshall an octet string (ASN.1 BER) */  /* Send an EDrq message (ASN.1 PER) */
187  BOOL ber_io_octet_string(STREAM s, OCTET_STRING *os)  static void
188    mcs_send_edrq()
189  {  {
190          if (!ber_io_header(s, False, 4, &os->length))          STREAM s;
                 return False;  
191    
192          if (os->length > s->end - s->offset)          s = iso_init(5);
                 return False;  
193    
194          if (s->marshall)          out_uint8(s, (MCS_EDRQ << 2));
195          {          out_uint16_be(s, 1);    /* height */
196                  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);  
         }  
197    
198          s->offset += os->length;          s_mark_end(s);
199          return True;          iso_send(s);
200  }  }
201    
202  /* Marshall/demarshall an integer (ASN.1 BER) */  /* Send an AUrq message (ASN.1 PER) */
203  BOOL ber_io_integer(STREAM s, uint16 *word_int)  static void
204    mcs_send_aurq()
205  {  {
206          int length = 2;          STREAM s;
         uint8 byte_int;  
         BOOL res;  
   
         if (!ber_io_header(s, False, 2, &length))  
                 return False;  
207    
208          if (s->marshall)          s = iso_init(1);
         {  
                 res = msb_io_uint16(s, word_int);  
         }  
         else  
         {  
                 *word_int = 0;  
                 while (length--)  
                 {  
                         if (!prs_io_uint8(s, &byte_int))  
                                 return False;  
209    
210                          *word_int <<= 8;          out_uint8(s, (MCS_AURQ << 2));
                         *word_int += byte_int;  
                 }  
         }  
211    
212          return res;          s_mark_end(s);
213            iso_send(s);
214  }  }
215    
216  /* Marshall/demarshall a simple uint8 type (ASN.1 BER) */  /* Expect a AUcf message (ASN.1 PER) */
217  BOOL ber_io_uint8(STREAM s, uint8 *i, int tagval)  static BOOL
218    mcs_recv_aucf(uint16 * mcs_userid)
219  {  {
220          int length = 1;          uint8 opcode, result;
221            STREAM s;
222    
223          if (!ber_io_header(s, False, tagval, &length))          s = iso_recv();
224            if (s == NULL)
225                  return False;                  return False;
226    
227          if (length != 1)          in_uint8(s, opcode);
228            if ((opcode >> 2) != MCS_AUCF)
229          {          {
230                  fprintf(stderr, "Wrong length for simple type\n");                  error("expected AUcf, got %d\n", opcode);
231                  return False;                  return False;
232          }          }
233    
234          return prs_io_uint8(s, i);          in_uint8(s, result);
235  }          if (result != 0)
236            {
237  /* Marshall/demarshall a DOMAIN_PARAMS structure (ASN.1 BER) */                  error("AUrq: %d\n", result);
238  BOOL mcs_io_domain_params(STREAM s, DOMAIN_PARAMS *dp)                  return False;
239  {          }
         int length = 32;  
         BOOL res;  
240    
241          res = ber_io_header(s, False, 0x30, &length);          if (opcode & 2)
242          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;  
243    
244          return res;          return s_check_end(s);
245  }  }
246    
247  /* Marshall/demarshall a MCS_CONNECT_INITIAL structure (ASN.1 BER) */  /* Send a CJrq message (ASN.1 PER) */
248  BOOL mcs_io_connect_initial(STREAM s, MCS_CONNECT_INITIAL *mci)  static void
249    mcs_send_cjrq(uint16 chanid)
250  {  {
251          BOOL res;          STREAM s;
252    
253          res = ber_io_header(s, True, 0x7f65, &mci->length);          s = iso_init(5);
         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;  
254    
255          return res;          out_uint8(s, (MCS_CJRQ << 2));
256            out_uint16_be(s, mcs_userid);
257            out_uint16_be(s, chanid);
258    
259            s_mark_end(s);
260            iso_send(s);
261  }  }
262    
263  /* Marshall/demarshall a MCS_CONNECT_RESPONSE structure (ASN.1 BER) */  /* Expect a CJcf message (ASN.1 PER) */
264  BOOL mcs_io_connect_response(STREAM s, MCS_CONNECT_RESPONSE *mcr)  static BOOL
265    mcs_recv_cjcf()
266  {  {
267          BOOL res;          uint8 opcode, result;
268            STREAM s;
         res = ber_io_header(s, True, 0x7f66, &mcr->length);  
         res = res ? ber_io_uint8        (s, &mcr->result, 10   ) : False;  
         res = res ? ber_io_integer      (s, &mcr->connect_id   ) : False;  
         res = res ? mcs_io_domain_params(s, &mcr->domain_params) : False;  
         res = res ? ber_io_octet_string (s, &mcr->user_data    ) : False;  
269    
270          return res;          s = iso_recv();
271  }          if (s == NULL)
272                    return False;
273    
274  /* Marshall/demarshall an EDrq structure (ASN.1 PER) */          in_uint8(s, opcode);
275  BOOL mcs_io_edrq(STREAM s, MCS_EDRQ *edrq)          if ((opcode >> 2) != MCS_CJCF)
276  {          {
277          uint8 opcode = (1) << 2;                  error("expected CJcf, got %d\n", opcode);
278          uint8 pkt_opcode = opcode;                  return False;
279          BOOL res;          }
280    
281          res = prs_io_uint8(s, &pkt_opcode);          in_uint8(s, result);
282          if (pkt_opcode != opcode)          if (result != 0)
283          {          {
284                  fprintf(stderr, "Expected EDrq, received %x\n", pkt_opcode);                  error("CJrq: %d\n", result);
285                  return False;                  return False;
286          }          }
287    
288          res = res ? msb_io_uint16(s, &edrq->height  ) : False;          in_uint8s(s, 4);        /* mcs_userid, req_chanid */
289          res = res ? msb_io_uint16(s, &edrq->interval) : False;          if (opcode & 2)
290                    in_uint8s(s, 2);        /* join_chanid */
291    
292          return res;          return s_check_end(s);
293  }  }
294    
295  /* Marshall/demarshall an AUrq structure (ASN.1 PER) */  /* Initialise an MCS transport data packet */
296  BOOL mcs_io_aurq(STREAM s, MCS_AURQ *aurq)  STREAM
297    mcs_init(int length)
298  {  {
299          uint8 opcode = (10) << 2;          STREAM s;
         uint8 pkt_opcode = opcode;  
         BOOL res;  
300    
301          res = prs_io_uint8(s, &pkt_opcode);          s = iso_init(length + 8);
302          if (pkt_opcode != opcode)          s_push_layer(s, mcs_hdr, 8);
         {  
                 fprintf(stderr, "Expected AUrq, received %x\n", pkt_opcode);  
                 return False;  
         }  
303    
304          return res;          return s;
305  }  }
306    
307  /* Marshall/demarshall an AUcf structure (ASN.1 PER) */  /* Send an MCS transport data packet */
308  BOOL mcs_io_aucf(STREAM s, MCS_AUCF *aucf)  void
309    mcs_send(STREAM s)
310  {  {
311          uint8 opcode = (11) << 2;          uint16 length;
         uint8 pkt_opcode = opcode | 2;  
         BOOL res;  
312    
313          res = prs_io_uint8(s, &pkt_opcode);          s_pop_layer(s, mcs_hdr);
314          if ((pkt_opcode & 0xfc) != opcode)          length = s->end - s->p - 8;
315          {          length |= 0x8000;
                 fprintf(stderr, "Expected AUcf, received %x\n", pkt_opcode);  
                 return False;  
         }  
316    
317          res = res ? prs_io_uint8 (s, &aucf->result) : False;          out_uint8(s, (MCS_SDRQ << 2));
318          if (pkt_opcode & 2)          out_uint16_be(s, mcs_userid);
319                  res = res ? msb_io_uint16(s, &aucf->userid) : False;          out_uint16_be(s, MCS_GLOBAL_CHANNEL);
320            out_uint8(s, 0x70);     /* flags */
321            out_uint16_be(s, length);
322    
323          return res;          iso_send(s);
324  }  }
325    
326  /* Marshall/demarshall an CJrq structure (ASN.1 PER) */  /* Receive an MCS transport data packet */
327  BOOL mcs_io_cjrq(STREAM s, MCS_CJRQ *cjrq)  STREAM
328    mcs_recv()
329  {  {
330          uint8 opcode = (14) << 2;          uint8 opcode, appid, length;
331          uint8 pkt_opcode = opcode;          STREAM s;
332          BOOL res;  
333            s = iso_recv();
334            if (s == NULL)
335                    return NULL;
336    
337          res = prs_io_uint8(s, &pkt_opcode);          in_uint8(s, opcode);
338          if (pkt_opcode != opcode)          appid = opcode >> 2;
339            if (appid != MCS_SDIN)
340          {          {
341                  fprintf(stderr, "Expected CJrq, received %x\n", pkt_opcode);                  if (appid != MCS_DPUM)
342                  return False;                  {
343                            error("expected data, got %d\n", opcode);
344                    }
345                    return NULL;
346          }          }
347    
348          res = res ? msb_io_uint16(s, &cjrq->userid) : False;          in_uint8s(s, 5);        /* userid, chanid, flags */
349          res = res ? msb_io_uint16(s, &cjrq->chanid) : False;          in_uint8(s, length);
350            if (length & 0x80)
351                    in_uint8s(s, 1);        /* second byte of length */
352    
353          return res;          return s;
354  }  }
355    
356  /* Marshall/demarshall an CJcf structure (ASN.1 PER) */  /* Establish a connection up to the MCS layer */
357  BOOL mcs_io_cjcf(STREAM s, MCS_CJCF *cjcf)  BOOL
358    mcs_connect(char *server, STREAM mcs_data)
359  {  {
360          uint8 opcode = (15) << 2;          if (!iso_connect(server))
         uint8 pkt_opcode = opcode | 2;  
         BOOL res;  
   
         res = prs_io_uint8(s, &pkt_opcode);  
         if ((pkt_opcode & 0xfc) != opcode)  
         {  
                 fprintf(stderr, "Expected CJcf, received %x\n", pkt_opcode);  
361                  return False;                  return False;
         }  
362    
363          res = res ? prs_io_uint8 (s, &cjcf->result) : False;          mcs_send_connect_initial(mcs_data);
364          res = res ? msb_io_uint16(s, &cjcf->userid) : False;          if (!mcs_recv_connect_response(mcs_data))
365          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;  
366    
367          return res;          mcs_send_edrq();
 }  
368    
369  /* Marshall/demarshall an SDrq or SDin packet (ASN.1 PER) */          mcs_send_aurq();
370  BOOL mcs_io_data(STREAM s, MCS_DATA *dt, BOOL request)          if (!mcs_recv_aucf(&mcs_userid))
371  {                  goto error;
         uint8 opcode = (request ? 25 : 26) << 2;  
         uint8 pkt_opcode = opcode;  
         BOOL res;  
372    
373          res = prs_io_uint8(s, &pkt_opcode);          mcs_send_cjrq(mcs_userid + 1001);
374          if (pkt_opcode != opcode)          if (!mcs_recv_cjcf())
375          {                  goto error;
                 fprintf(stderr, "Expected MCS data, received %x\n", pkt_opcode);  
                 return False;  
         }  
376    
377          dt->length |= 0x8000;          mcs_send_cjrq(MCS_GLOBAL_CHANNEL);
378            if (!mcs_recv_cjcf())
379                    goto error;
380    
381          res = res ? msb_io_uint16(s, &dt->userid) : False;          return True;
         res = res ? msb_io_uint16(s, &dt->chanid) : False;  
         res = res ? prs_io_uint8 (s, &dt->flags ) : False;  
         res = res ? msb_io_uint16(s, &dt->length) : False;  
382    
383          return res;        error:
384            iso_disconnect();
385            return False;
386    }
387    
388    /* Disconnect from the MCS layer */
389    void
390    mcs_disconnect()
391    {
392            iso_disconnect();
393  }  }

Legend:
Removed from v.4  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26