--- sourceforge.net/trunk/rdesktop/mcs.c 2000/07/25 12:34:29 9 +++ sourceforge.net/trunk/rdesktop/mcs.c 2000/08/15 10:23:24 10 @@ -18,567 +18,358 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "includes.h" +#include "rdesktop.h" -/* Establish a connection up to the MCS layer */ -HCONN mcs_connect(char *server) -{ - HCONN conn; - MCS_CONNECT_RESPONSE mcr; - MCS_AUCF aucf; +uint16 mcs_userid; - if ((conn = iso_connect(server)) == NULL) - return NULL; +/* Parse an ASN.1 BER header */ +static BOOL ber_parse_header(STREAM s, int tagval, int *length) +{ + int tag, len; - mcs_send_connect_initial(conn); - if (!iso_recv(conn) || !mcs_io_connect_response(&conn->in, &mcr)) + if (tagval > 0xff) { - ERROR("MCS error, expected Connect-Response\n"); - iso_disconnect(conn); - return NULL; + in_uint16_be(s, tag); } - - if (mcr.result != 0) - { - ERROR("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)) + else { - ERROR("MCS error, expected AUcf\n"); - mcs_disconnect(conn); - return NULL; + in_uint8(s, tag) } - if (aucf.result != 0) + if (tag != tagval) { - ERROR("AUrq failed, result %d\n", mcr.result); - mcs_disconnect(conn); - return NULL; + ERROR("expected tag %d, got %d\n", tagval, tag); + return False; } - conn->mcs_userid = aucf.userid; + in_uint8(s, len); - if (!mcs_join_channel(conn, aucf.userid + 1001) - || !mcs_join_channel(conn, MCS_GLOBAL_CHANNEL)) + if (len & 0x80) { - mcs_disconnect(conn); - return NULL; + len &= ~0x80; + *length = 0; + while (len--) + next_be(s, *length); } + else *length = len; - return conn; + return s_check(s); } -BOOL mcs_join_channel(HCONN conn, uint16 chanid) +/* Output an ASN.1 BER header */ +static void ber_out_header(STREAM s, int tagval, int length) { - MCS_CJCF cjcf; - - mcs_send_cjrq(conn, chanid); - if (!iso_recv(conn) || !mcs_io_cjcf(&conn->in, &cjcf)) + if (tagval > 0xff) { - ERROR("MCS error, expected CJcf\n"); - return False; + out_uint16_be(s, tagval); } - - if (cjcf.result != 0) + else { - ERROR("CJrq failed, result %d\n", cjcf.result); - return False; + out_uint8(s, tagval); } - return True; + if (length >= 0x80) + { + out_uint8(s, 0x82); + out_uint16_be(s, length); + } + else out_uint8(s, length); } -/* Disconnect from the MCS layer */ -void mcs_disconnect(HCONN conn) +/* Output an ASN.1 BER integer */ +static void ber_out_integer(STREAM s, int value) { - /* Not complete */ - iso_disconnect(conn); + ber_out_header(s, BER_TAG_INTEGER, 2); + out_uint16_be(s, value); } -/* Send a Connect-Initial message */ -void mcs_send_connect_initial(HCONN conn) +/* Output a DOMAIN_PARAMS structure (ASN.1 BER) */ +static void mcs_out_domain_params(STREAM s, int max_channels, int max_users, + int max_tokens, int max_pdusize) { - MCS_CONNECT_INITIAL mci; - - iso_init(conn); - mcs_make_connect_initial(&mci); - mcs_io_connect_initial(&conn->out, &mci); - MARK_END(conn->out); - iso_send(conn); + ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32); + ber_out_integer(s, max_channels); + ber_out_integer(s, max_users); + ber_out_integer(s, max_tokens); + ber_out_integer(s, 1); /* num_priorities */ + ber_out_integer(s, 0); /* min_throughput */ + ber_out_integer(s, 1); /* max_height */ + ber_out_integer(s, max_pdusize); + ber_out_integer(s, 2); /* ver_protocol */ } -/* Send a EDrq message */ -void mcs_send_edrq(HCONN conn) +/* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */ +static BOOL mcs_parse_domain_params(STREAM s) { - 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); + ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length); + in_uint8s(s, length); + + return s_check(s); } -/* Send a AUrq message */ -void mcs_send_aurq(HCONN conn) +/* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */ +static void mcs_send_connect_initial(STREAM mcs_data) { - MCS_AURQ aurq; + int datalen = mcs_data->end - mcs_data->data; + int length = 7 + 3*34 + 4 + datalen; + STREAM s; - iso_init(conn); - mcs_io_aurq(&conn->out, &aurq); - MARK_END(conn->out); - iso_send(conn); -} + s = iso_init(length + 5); -/* Send a CJrq message */ -void mcs_send_cjrq(HCONN conn, uint16 chanid) -{ - MCS_CJRQ cjrq; + ber_out_header(s, MCS_CONNECT_INITIAL, length); + ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* calling domain */ + ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* called domain */ - iso_init(conn); - cjrq.userid = conn->mcs_userid; - cjrq.chanid = chanid; - mcs_io_cjrq(&conn->out, &cjrq); - MARK_END(conn->out); - iso_send(conn); -} + ber_out_header(s, BER_TAG_BOOLEAN, 1); + out_uint8(s, 0xff); /* upward flag */ -/* Initialise MCS transport data packet */ -void mcs_init_data(HCONN conn) -{ - iso_init(conn); - PUSH_LAYER(conn->out, mcs_offset, 8); -} + mcs_out_domain_params(s, 2, 2, 0, 0xffff); /* target params */ + mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */ + mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */ -/* Transmit MCS transport data packet */ -void mcs_send_data(HCONN conn, uint16 chanid, BOOL request) -{ - MCS_DATA dt; + ber_out_header(s, BER_TAG_OCTET_STRING, datalen); + out_uint8p(s, mcs_data->data, datalen); - POP_LAYER(conn->out, mcs_offset); - dt.userid = conn->mcs_userid; - 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); + s_mark_end(s); + iso_send(s); } -/* Receive a message on the MCS layer */ -BOOL mcs_recv(HCONN conn, BOOL request) +/* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */ +static BOOL mcs_recv_connect_response(STREAM mcs_data) { - MCS_DATA data; + uint8 result; + int length; + STREAM s; - if (!iso_recv(conn) || !mcs_io_data(&conn->in, &data, request)) + s = iso_recv(); + if (s == NULL) return False; - conn->in.rdp_offset = conn->in.offset; - return True; -} - -/* 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, - /* encryption disabled */ 0x00,0x00,0x00,0x00 }; - -char precanned_connect_userdata_e[] = { -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,0x57,0x00, -0x49,0x00,0x4e,0x00,0x39,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00,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,0x01,0x00,0x00,0x00 -}; - -char domain_data[] = {0x01}; - -/* Initialise a MCS_CONNECT_INITIAL structure */ -void mcs_make_connect_initial(MCS_CONNECT_INITIAL *mci) -{ - mci->calling_domain.length = 1; - mci->calling_domain.data = domain_data; - - mci->called_domain.length = 1; - mci->called_domain.data = domain_data; - - 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 - { - byte_tag = tagval; - res = prs_io_uint8(s, &byte_tag); - tag = byte_tag; - } + ber_parse_header(s, MCS_CONNECT_RESPONSE, &length); - if (!res || (tag != tagval)) + ber_parse_header(s, BER_TAG_RESULT, &length); + in_uint8(s, result); + if (result != 0) { - ERROR("Invalid ASN.1 tag\n"); + ERROR("MCS connect: %d\n", result); return False; } - /* Read/write length */ - if (s->marshall) + ber_parse_header(s, BER_TAG_INTEGER, &length); + in_uint8s(s, length); /* connect id */ + mcs_parse_domain_params(s); + + ber_parse_header(s, BER_TAG_OCTET_STRING, &length); + if (length > mcs_data->size) { - 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); - } + WARN("MCS data length %d\n", length); + length = mcs_data->size; } - else - { - if (!prs_io_uint8(s, &byte_len)) - return False; - if (byte_len & 0x80) - { - 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; - } + in_uint8a(s, mcs_data->data, length); + mcs_data->p = mcs_data->data; + mcs_data->end = mcs_data->data + length; - return res; + return s_check_end(s); } -/* Marshall/demarshall an octet string (ASN.1 BER) */ -BOOL ber_io_octet_string(STREAM s, OCTET_STRING *os) +/* Send an EDrq message (ASN.1 PER) */ +static void mcs_send_edrq() { - if (!ber_io_header(s, False, 4, &os->length)) - return False; + STREAM s; - if (os->length > s->end - s->offset) - return False; + s = iso_init(5); - if (s->marshall) - { - memcpy(s->data + s->offset, os->data, os->length); - } - else - { - os->data = malloc(os->length); - memcpy(os->data, s->data + s->offset, os->length); - } + out_uint8(s, (MCS_EDRQ << 2)); + out_uint16_be(s, 1); /* height */ + out_uint16_be(s, 1); /* interval */ - s->offset += os->length; - return True; + s_mark_end(s); + iso_send(s); } -/* Marshall/demarshall an integer (ASN.1 BER) */ -BOOL ber_io_integer(STREAM s, uint16 *word_int) +/* Send an AUrq message (ASN.1 PER) */ +static void mcs_send_aurq() { - int length = 2; - uint8 byte_int; - BOOL res; - - if (!ber_io_header(s, False, 2, &length)) - return False; + STREAM s; - if (s->marshall) - { - res = msb_io_uint16(s, word_int); - } - else - { - *word_int = 0; - while (length--) - { - if (!prs_io_uint8(s, &byte_int)) - return False; + s = iso_init(1); - *word_int <<= 8; - *word_int += byte_int; - } - } + out_uint8(s, (MCS_AURQ << 2)); - return res; + s_mark_end(s); + iso_send(s); } -/* Marshall/demarshall a simple uint8 type (ASN.1 BER) */ -BOOL ber_io_uint8(STREAM s, uint8 *i, int tagval) +/* Expect a AUcf message (ASN.1 PER) */ +static BOOL mcs_recv_aucf(uint16 *mcs_userid) { - int length = 1; + uint8 opcode, result; + STREAM s; - if (!ber_io_header(s, False, tagval, &length)) + s = iso_recv(); + if (s == NULL) return False; - if (length != 1) + in_uint8(s, opcode); + if ((opcode >> 2) != MCS_AUCF) { - ERROR("Wrong length for simple type\n"); + ERROR("expected AUcf, got %d\n", opcode); return False; } - return prs_io_uint8(s, i); -} - -/* Marshall/demarshall a DOMAIN_PARAMS structure (ASN.1 BER) */ -BOOL mcs_io_domain_params(STREAM s, DOMAIN_PARAMS *dp) -{ - int length = 32; - BOOL res; + in_uint8(s, result); + if (result != 0) + { + ERROR("AUrq: %d\n", result); + return False; + } - res = ber_io_header(s, False, 0x30, &length); - res = res ? ber_io_integer(s, &dp->max_channels ) : False; - 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; + if (opcode & 2) + in_uint16_be(s, *mcs_userid); - return res; + return s_check_end(s); } -/* Marshall/demarshall a MCS_CONNECT_INITIAL structure (ASN.1 BER) */ -BOOL mcs_io_connect_initial(STREAM s, MCS_CONNECT_INITIAL *mci) +/* Send a CJrq message (ASN.1 PER) */ +static void mcs_send_cjrq(uint16 chanid) { - BOOL res; + STREAM s; - res = ber_io_header(s, True, 0x7f65, &mci->length); - 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; + s = iso_init(5); - return res; + out_uint8(s, (MCS_CJRQ << 2)); + out_uint16_be(s, mcs_userid); + out_uint16_be(s, chanid); + + s_mark_end(s); + iso_send(s); } -/* Marshall/demarshall a MCS_CONNECT_RESPONSE structure (ASN.1 BER) */ -BOOL mcs_io_connect_response(STREAM s, MCS_CONNECT_RESPONSE *mcr) +/* Expect a CJcf message (ASN.1 PER) */ +static BOOL mcs_recv_cjcf() { - BOOL res; - - 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; + uint8 opcode, result; + STREAM s; - return res; -} + s = iso_recv(); + if (s == NULL) + return False; -/* Marshall/demarshall an EDrq structure (ASN.1 PER) */ -BOOL mcs_io_edrq(STREAM s, MCS_EDRQ *edrq) -{ - uint8 opcode = (1) << 2; - uint8 pkt_opcode = opcode; - BOOL res; + in_uint8(s, opcode); + if ((opcode >> 2) != MCS_CJCF) + { + ERROR("expected CJcf, got %d\n", opcode); + return False; + } - res = prs_io_uint8(s, &pkt_opcode); - if (pkt_opcode != opcode) + in_uint8(s, result); + if (result != 0) { - ERROR("Expected EDrq, received %x\n", pkt_opcode); + ERROR("CJrq: %d\n", result); return False; } - res = res ? msb_io_uint16(s, &edrq->height ) : False; - res = res ? msb_io_uint16(s, &edrq->interval) : False; + in_uint8s(s, 4); /* mcs_userid, req_chanid */ + if (opcode & 2) + in_uint8s(s, 2); /* join_chanid */ - return res; + return s_check_end(s); } -/* Marshall/demarshall an AUrq structure (ASN.1 PER) */ -BOOL mcs_io_aurq(STREAM s, MCS_AURQ *aurq) +/* Initialise an MCS transport data packet */ +STREAM mcs_init(int length) { - uint8 opcode = (10) << 2; - uint8 pkt_opcode = opcode; - BOOL res; + STREAM s; - res = prs_io_uint8(s, &pkt_opcode); - if (pkt_opcode != opcode) - { - ERROR("Expected AUrq, received %x\n", pkt_opcode); - return False; - } + s = iso_init(length + 8); + s_push_layer(s, mcs_hdr, 8); - return res; + return s; } -/* Marshall/demarshall an AUcf structure (ASN.1 PER) */ -BOOL mcs_io_aucf(STREAM s, MCS_AUCF *aucf) +/* Send an MCS transport data packet */ +void mcs_send(STREAM s) { - uint8 opcode = (11) << 2; - uint8 pkt_opcode = opcode | 2; - BOOL res; + uint16 length; - res = prs_io_uint8(s, &pkt_opcode); - if ((pkt_opcode & 0xfc) != opcode) - { - ERROR("Expected AUcf, received %x\n", pkt_opcode); - return False; - } + s_pop_layer(s, mcs_hdr); + length = s->end - s->p - 8; + length |= 0x8000; - res = res ? prs_io_uint8 (s, &aucf->result) : False; - if (pkt_opcode & 2) - res = res ? msb_io_uint16(s, &aucf->userid) : False; + out_uint8(s, (MCS_SDRQ << 2)); + out_uint16_be(s, mcs_userid); + out_uint16_be(s, MCS_GLOBAL_CHANNEL); + out_uint8(s, 0x70); /* flags */ + out_uint16_be(s, length); - return res; + iso_send(s); } -/* Marshall/demarshall an CJrq structure (ASN.1 PER) */ -BOOL mcs_io_cjrq(STREAM s, MCS_CJRQ *cjrq) +/* Receive an MCS transport data packet */ +STREAM mcs_recv() { - uint8 opcode = (14) << 2; - uint8 pkt_opcode = opcode; - BOOL res; + uint8 opcode, appid, length; + STREAM s; + + s = iso_recv(); + if (s == NULL) + return NULL; - res = prs_io_uint8(s, &pkt_opcode); - if (pkt_opcode != opcode) + in_uint8(s, opcode); + appid = opcode >> 2; + if (appid != MCS_SDIN) { - ERROR("Expected CJrq, received %x\n", pkt_opcode); - return False; + if (appid != MCS_DPUM) + { + ERROR("expected data, got %d\n", opcode); + } + return NULL; } - res = res ? msb_io_uint16(s, &cjrq->userid) : False; - res = res ? msb_io_uint16(s, &cjrq->chanid) : False; + in_uint8s(s, 5); /* userid, chanid, flags */ + in_uint8(s, length); + if (length & 0x80) + in_uint8s(s, 1); /* second byte of length */ - return res; + return s; } -/* Marshall/demarshall an CJcf structure (ASN.1 PER) */ -BOOL mcs_io_cjcf(STREAM s, MCS_CJCF *cjcf) +/* Establish a connection up to the MCS layer */ +BOOL mcs_connect(char *server, STREAM mcs_data) { - uint8 opcode = (15) << 2; - uint8 pkt_opcode = opcode | 2; - BOOL res; - - res = prs_io_uint8(s, &pkt_opcode); - if ((pkt_opcode & 0xfc) != opcode) - { - ERROR("Expected CJcf, received %x\n", pkt_opcode); + if (!iso_connect(server)) return False; - } - res = res ? prs_io_uint8 (s, &cjcf->result) : False; - res = res ? msb_io_uint16(s, &cjcf->userid) : False; - res = res ? msb_io_uint16(s, &cjcf->req_chanid) : False; - if (pkt_opcode & 2) - res = res ? msb_io_uint16(s, &cjcf->join_chanid) : False; + mcs_send_connect_initial(mcs_data); + if (!mcs_recv_connect_response(mcs_data)) + goto error; - return res; -} + mcs_send_edrq(); -/* Marshall/demarshall an SDrq or SDin packet (ASN.1 PER) */ -BOOL mcs_io_data(STREAM s, MCS_DATA *dt, BOOL request) -{ - uint8 opcode = (request ? 25 : 26) << 2; - uint8 pkt_opcode = opcode; - uint8 byte1, byte2; - BOOL res; + mcs_send_aurq(); + if (!mcs_recv_aucf(&mcs_userid)) + goto error; - res = prs_io_uint8(s, &pkt_opcode); - if (pkt_opcode != opcode) - { - ERROR("Expected MCS data, received %x\n", pkt_opcode); - return False; - } + mcs_send_cjrq(mcs_userid + 1001); + if (!mcs_recv_cjcf()) + goto error; - res = res ? msb_io_uint16(s, &dt->userid) : False; - res = res ? msb_io_uint16(s, &dt->chanid) : False; - res = res ? prs_io_uint8 (s, &dt->flags ) : False; + mcs_send_cjrq(MCS_GLOBAL_CHANNEL); + if (!mcs_recv_cjcf()) + goto error; - if (s->marshall) - { - dt->length |= 0x8000; - res = res ? msb_io_uint16(s, &dt->length) : False; - } - else - { - res = res ? prs_io_uint8(s, &byte1) : False; - if (byte1 & 0x80) - { - res = res ? prs_io_uint8(s, &byte2) : False; - dt->length = ((byte1 & ~0x80) << 8) + byte2; - } - else dt->length = byte1; - } + return True; - return res; + error: + iso_disconnect(); + return False; } +/* Disconnect from the MCS layer */ +void mcs_disconnect() +{ + iso_disconnect(); +}