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