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

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

  ViewVC Help
Powered by ViewVC 1.1.26