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 |
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
|
|
23 |
uint16 mcs_userid; |
uint16 mcs_userid; |
24 |
|
extern BOOL use_rdp5; |
25 |
|
|
26 |
/* Parse an ASN.1 BER header */ |
/* Parse an ASN.1 BER header */ |
27 |
static BOOL ber_parse_header(STREAM s, int tagval, int *length) |
static BOOL |
28 |
|
ber_parse_header(STREAM s, int tagval, int *length) |
29 |
{ |
{ |
30 |
int tag, len; |
int tag, len; |
31 |
|
|
35 |
} |
} |
36 |
else |
else |
37 |
{ |
{ |
38 |
in_uint8(s, tag) |
in_uint8(s, tag)} |
|
} |
|
39 |
|
|
40 |
if (tag != tagval) |
if (tag != tagval) |
41 |
{ |
{ |
42 |
ERROR("expected tag %d, got %d\n", tagval, tag); |
error("expected tag %d, got %d\n", tagval, tag); |
43 |
return False; |
return False; |
44 |
} |
} |
45 |
|
|
52 |
while (len--) |
while (len--) |
53 |
next_be(s, *length); |
next_be(s, *length); |
54 |
} |
} |
55 |
else *length = len; |
else |
56 |
|
*length = len; |
57 |
|
|
58 |
return s_check(s); |
return s_check(s); |
59 |
} |
} |
60 |
|
|
61 |
/* Output an ASN.1 BER header */ |
/* Output an ASN.1 BER header */ |
62 |
static void ber_out_header(STREAM s, int tagval, int length) |
static void |
63 |
|
ber_out_header(STREAM s, int tagval, int length) |
64 |
{ |
{ |
65 |
if (tagval > 0xff) |
if (tagval > 0xff) |
66 |
{ |
{ |
76 |
out_uint8(s, 0x82); |
out_uint8(s, 0x82); |
77 |
out_uint16_be(s, length); |
out_uint16_be(s, length); |
78 |
} |
} |
79 |
else out_uint8(s, length); |
else |
80 |
|
out_uint8(s, length); |
81 |
} |
} |
82 |
|
|
83 |
/* Output an ASN.1 BER integer */ |
/* Output an ASN.1 BER integer */ |
84 |
static void ber_out_integer(STREAM s, int value) |
static void |
85 |
|
ber_out_integer(STREAM s, int value) |
86 |
{ |
{ |
87 |
ber_out_header(s, BER_TAG_INTEGER, 2); |
ber_out_header(s, BER_TAG_INTEGER, 2); |
88 |
out_uint16_be(s, value); |
out_uint16_be(s, value); |
89 |
} |
} |
90 |
|
|
91 |
/* Output a DOMAIN_PARAMS structure (ASN.1 BER) */ |
/* Output a DOMAIN_PARAMS structure (ASN.1 BER) */ |
92 |
static void mcs_out_domain_params(STREAM s, int max_channels, int max_users, |
static void |
93 |
int max_tokens, int max_pdusize) |
mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize) |
94 |
{ |
{ |
95 |
ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32); |
ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32); |
96 |
ber_out_integer(s, max_channels); |
ber_out_integer(s, max_channels); |
97 |
ber_out_integer(s, max_users); |
ber_out_integer(s, max_users); |
98 |
ber_out_integer(s, max_tokens); |
ber_out_integer(s, max_tokens); |
99 |
ber_out_integer(s, 1); /* num_priorities */ |
ber_out_integer(s, 1); /* num_priorities */ |
100 |
ber_out_integer(s, 0); /* min_throughput */ |
ber_out_integer(s, 0); /* min_throughput */ |
101 |
ber_out_integer(s, 1); /* max_height */ |
ber_out_integer(s, 1); /* max_height */ |
102 |
ber_out_integer(s, max_pdusize); |
ber_out_integer(s, max_pdusize); |
103 |
ber_out_integer(s, 2); /* ver_protocol */ |
ber_out_integer(s, 2); /* ver_protocol */ |
104 |
} |
} |
105 |
|
|
106 |
/* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */ |
/* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */ |
107 |
static BOOL mcs_parse_domain_params(STREAM s) |
static BOOL |
108 |
|
mcs_parse_domain_params(STREAM s) |
109 |
{ |
{ |
110 |
int length; |
int length; |
111 |
|
|
116 |
} |
} |
117 |
|
|
118 |
/* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */ |
/* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */ |
119 |
static void mcs_send_connect_initial(STREAM mcs_data) |
static void |
120 |
|
mcs_send_connect_initial(STREAM mcs_data) |
121 |
{ |
{ |
122 |
int datalen = mcs_data->end - mcs_data->data; |
int datalen = mcs_data->end - mcs_data->data; |
123 |
int length = 7 + 3*34 + 4 + datalen; |
int length = 9 + 3 * 34 + 4 + datalen; |
124 |
STREAM s; |
STREAM s; |
125 |
|
|
126 |
s = iso_init(length + 5); |
s = iso_init(length + 5); |
127 |
|
|
128 |
ber_out_header(s, MCS_CONNECT_INITIAL, length); |
ber_out_header(s, MCS_CONNECT_INITIAL, length); |
129 |
ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* calling domain */ |
ber_out_header(s, BER_TAG_OCTET_STRING, 1); /* calling domain */ |
130 |
ber_out_header(s, BER_TAG_OCTET_STRING, 0); /* called domain */ |
out_uint8(s, 1); |
131 |
|
ber_out_header(s, BER_TAG_OCTET_STRING, 1); /* called domain */ |
132 |
|
out_uint8(s, 1); |
133 |
|
|
134 |
ber_out_header(s, BER_TAG_BOOLEAN, 1); |
ber_out_header(s, BER_TAG_BOOLEAN, 1); |
135 |
out_uint8(s, 0xff); /* upward flag */ |
out_uint8(s, 0xff); /* upward flag */ |
136 |
|
|
137 |
mcs_out_domain_params(s, 2, 2, 0, 0xffff); /* target params */ |
mcs_out_domain_params(s, 34, 2, 0, 0xffff); /* target params */ |
138 |
mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */ |
mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */ |
139 |
mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */ |
mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */ |
140 |
|
|
141 |
ber_out_header(s, BER_TAG_OCTET_STRING, datalen); |
ber_out_header(s, BER_TAG_OCTET_STRING, datalen); |
142 |
out_uint8p(s, mcs_data->data, datalen); |
out_uint8p(s, mcs_data->data, datalen); |
146 |
} |
} |
147 |
|
|
148 |
/* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */ |
/* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */ |
149 |
static BOOL mcs_recv_connect_response(STREAM mcs_data) |
static BOOL |
150 |
|
mcs_recv_connect_response(STREAM mcs_data) |
151 |
{ |
{ |
152 |
uint8 result; |
uint8 result; |
153 |
int length; |
int length; |
163 |
in_uint8(s, result); |
in_uint8(s, result); |
164 |
if (result != 0) |
if (result != 0) |
165 |
{ |
{ |
166 |
ERROR("MCS connect: %d\n", result); |
error("MCS connect: %d\n", result); |
167 |
return False; |
return False; |
168 |
} |
} |
169 |
|
|
170 |
ber_parse_header(s, BER_TAG_INTEGER, &length); |
ber_parse_header(s, BER_TAG_INTEGER, &length); |
171 |
in_uint8s(s, length); /* connect id */ |
in_uint8s(s, length); /* connect id */ |
172 |
mcs_parse_domain_params(s); |
mcs_parse_domain_params(s); |
173 |
|
|
174 |
ber_parse_header(s, BER_TAG_OCTET_STRING, &length); |
ber_parse_header(s, BER_TAG_OCTET_STRING, &length); |
|
if (length > mcs_data->size) |
|
|
{ |
|
|
WARN("MCS data length %d\n", length); |
|
|
length = mcs_data->size; |
|
|
} |
|
|
|
|
|
in_uint8a(s, mcs_data->data, length); |
|
|
mcs_data->p = mcs_data->data; |
|
|
mcs_data->end = mcs_data->data + length; |
|
175 |
|
|
176 |
|
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); |
return s_check_end(s); |
190 |
} |
} |
191 |
|
|
192 |
/* Send an EDrq message (ASN.1 PER) */ |
/* Send an EDrq message (ASN.1 PER) */ |
193 |
static void mcs_send_edrq() |
static void |
194 |
|
mcs_send_edrq(void) |
195 |
{ |
{ |
196 |
STREAM s; |
STREAM s; |
197 |
|
|
198 |
s = iso_init(5); |
s = iso_init(5); |
199 |
|
|
200 |
out_uint8(s, (MCS_EDRQ << 2)); |
out_uint8(s, (MCS_EDRQ << 2)); |
201 |
out_uint16_be(s, 1); /* height */ |
out_uint16_be(s, 1); /* height */ |
202 |
out_uint16_be(s, 1); /* interval */ |
out_uint16_be(s, 1); /* interval */ |
203 |
|
|
204 |
s_mark_end(s); |
s_mark_end(s); |
205 |
iso_send(s); |
iso_send(s); |
206 |
} |
} |
207 |
|
|
208 |
/* Send an AUrq message (ASN.1 PER) */ |
/* Send an AUrq message (ASN.1 PER) */ |
209 |
static void mcs_send_aurq() |
static void |
210 |
|
mcs_send_aurq(void) |
211 |
{ |
{ |
212 |
STREAM s; |
STREAM s; |
213 |
|
|
220 |
} |
} |
221 |
|
|
222 |
/* Expect a AUcf message (ASN.1 PER) */ |
/* Expect a AUcf message (ASN.1 PER) */ |
223 |
static BOOL mcs_recv_aucf(uint16 *mcs_userid) |
static BOOL |
224 |
|
mcs_recv_aucf(uint16 * mcs_userid) |
225 |
{ |
{ |
226 |
uint8 opcode, result; |
uint8 opcode, result; |
227 |
STREAM s; |
STREAM s; |
233 |
in_uint8(s, opcode); |
in_uint8(s, opcode); |
234 |
if ((opcode >> 2) != MCS_AUCF) |
if ((opcode >> 2) != MCS_AUCF) |
235 |
{ |
{ |
236 |
ERROR("expected AUcf, got %d\n", opcode); |
error("expected AUcf, got %d\n", opcode); |
237 |
return False; |
return False; |
238 |
} |
} |
239 |
|
|
240 |
in_uint8(s, result); |
in_uint8(s, result); |
241 |
if (result != 0) |
if (result != 0) |
242 |
{ |
{ |
243 |
ERROR("AUrq: %d\n", result); |
error("AUrq: %d\n", result); |
244 |
return False; |
return False; |
245 |
} |
} |
246 |
|
|
251 |
} |
} |
252 |
|
|
253 |
/* Send a CJrq message (ASN.1 PER) */ |
/* Send a CJrq message (ASN.1 PER) */ |
254 |
static void mcs_send_cjrq(uint16 chanid) |
static void |
255 |
|
mcs_send_cjrq(uint16 chanid) |
256 |
{ |
{ |
257 |
STREAM s; |
STREAM s; |
258 |
|
|
267 |
} |
} |
268 |
|
|
269 |
/* Expect a CJcf message (ASN.1 PER) */ |
/* Expect a CJcf message (ASN.1 PER) */ |
270 |
static BOOL mcs_recv_cjcf() |
static BOOL |
271 |
|
mcs_recv_cjcf(void) |
272 |
{ |
{ |
273 |
uint8 opcode, result; |
uint8 opcode, result; |
274 |
STREAM s; |
STREAM s; |
280 |
in_uint8(s, opcode); |
in_uint8(s, opcode); |
281 |
if ((opcode >> 2) != MCS_CJCF) |
if ((opcode >> 2) != MCS_CJCF) |
282 |
{ |
{ |
283 |
ERROR("expected CJcf, got %d\n", opcode); |
error("expected CJcf, got %d\n", opcode); |
284 |
return False; |
return False; |
285 |
} |
} |
286 |
|
|
287 |
in_uint8(s, result); |
in_uint8(s, result); |
288 |
if (result != 0) |
if (result != 0) |
289 |
{ |
{ |
290 |
ERROR("CJrq: %d\n", result); |
error("CJrq: %d\n", result); |
291 |
return False; |
return False; |
292 |
} |
} |
293 |
|
|
294 |
in_uint8s(s, 4); /* mcs_userid, req_chanid */ |
in_uint8s(s, 4); /* mcs_userid, req_chanid */ |
295 |
if (opcode & 2) |
if (opcode & 2) |
296 |
in_uint8s(s, 2); /* join_chanid */ |
in_uint8s(s, 2); /* join_chanid */ |
297 |
|
|
298 |
return s_check_end(s); |
return s_check_end(s); |
299 |
} |
} |
300 |
|
|
301 |
/* Initialise an MCS transport data packet */ |
/* Initialise an MCS transport data packet */ |
302 |
STREAM mcs_init(int length) |
STREAM |
303 |
|
mcs_init(int length) |
304 |
{ |
{ |
305 |
STREAM s; |
STREAM s; |
306 |
|
|
311 |
} |
} |
312 |
|
|
313 |
/* Send an MCS transport data packet */ |
/* Send an MCS transport data packet */ |
314 |
void mcs_send(STREAM s) |
void |
315 |
|
mcs_send(STREAM s) |
316 |
{ |
{ |
317 |
uint16 length; |
uint16 length; |
318 |
|
|
323 |
out_uint8(s, (MCS_SDRQ << 2)); |
out_uint8(s, (MCS_SDRQ << 2)); |
324 |
out_uint16_be(s, mcs_userid); |
out_uint16_be(s, mcs_userid); |
325 |
out_uint16_be(s, MCS_GLOBAL_CHANNEL); |
out_uint16_be(s, MCS_GLOBAL_CHANNEL); |
326 |
out_uint8(s, 0x70); /* flags */ |
out_uint8(s, 0x70); /* flags */ |
327 |
out_uint16_be(s, length); |
out_uint16_be(s, length); |
328 |
|
|
329 |
iso_send(s); |
iso_send(s); |
330 |
} |
} |
331 |
|
|
332 |
/* Receive an MCS transport data packet */ |
/* Receive an MCS transport data packet */ |
333 |
STREAM mcs_recv() |
STREAM |
334 |
|
mcs_recv(uint16 * channel) |
335 |
{ |
{ |
336 |
uint8 opcode, appid, length; |
uint8 opcode, appid, length; |
337 |
STREAM s; |
STREAM s; |
346 |
{ |
{ |
347 |
if (appid != MCS_DPUM) |
if (appid != MCS_DPUM) |
348 |
{ |
{ |
349 |
ERROR("expected data, got %d\n", opcode); |
error("expected data, got %d\n", opcode); |
350 |
} |
} |
351 |
return NULL; |
return NULL; |
352 |
} |
} |
353 |
|
|
354 |
in_uint8s(s, 5); /* userid, chanid, flags */ |
in_uint8s(s, 2); /* userid */ |
355 |
|
in_uint16_be(s, *channel); |
356 |
|
in_uint8s(s, 1); /* flags */ |
357 |
in_uint8(s, length); |
in_uint8(s, length); |
358 |
if (length & 0x80) |
if (length & 0x80) |
359 |
in_uint8s(s, 1); /* second byte of length */ |
in_uint8s(s, 1); /* second byte of length */ |
360 |
|
|
361 |
return s; |
return s; |
362 |
} |
} |
363 |
|
|
364 |
/* Establish a connection up to the MCS layer */ |
/* Establish a connection up to the MCS layer */ |
365 |
BOOL mcs_connect(char *server, STREAM mcs_data) |
BOOL |
366 |
|
mcs_connect(char *server, STREAM mcs_data, char *username) |
367 |
{ |
{ |
368 |
if (!iso_connect(server)) |
if (!iso_connect(server, username)) |
369 |
return False; |
return False; |
370 |
|
|
371 |
mcs_send_connect_initial(mcs_data); |
mcs_send_connect_initial(mcs_data); |
386 |
if (!mcs_recv_cjcf()) |
if (!mcs_recv_cjcf()) |
387 |
goto error; |
goto error; |
388 |
|
|
389 |
|
if (use_rdp5) |
390 |
|
{ |
391 |
|
/* Note: If we send this cjrq after telling the server we support RDP4 only, |
392 |
|
the server won't respond with a cjcf and we will hang. */ |
393 |
|
mcs_send_cjrq(MCS_GLOBAL_CHANNEL + 1); /* hack - clipboard */ |
394 |
|
if (!mcs_recv_cjcf()) |
395 |
|
goto error; |
396 |
|
} |
397 |
|
|
398 |
return True; |
return True; |
399 |
|
|
400 |
error: |
error: |
401 |
iso_disconnect(); |
iso_disconnect(); |
402 |
return False; |
return False; |
403 |
} |
} |
404 |
|
|
405 |
/* Disconnect from the MCS layer */ |
/* Disconnect from the MCS layer */ |
406 |
void mcs_disconnect() |
void |
407 |
|
mcs_disconnect(void) |
408 |
{ |
{ |
409 |
iso_disconnect(); |
iso_disconnect(); |
410 |
} |
} |