1
/* -*- c-basic-offset: 8 -*-
2
rdesktop: A Remote Desktop Protocol client.
3
Protocol services - Multipoint Communications Service
4
Copyright (C) Matthew Chapman 1999-2002
6
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
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
extern VCHANNEL g_channels[];
25
extern unsigned int g_num_channels;
27
/* Parse an ASN.1 BER header */
29
ber_parse_header(STREAM s, int tagval, int *length)
43
error("expected tag %d, got %d\n", tagval, tag);
62
/* Output an ASN.1 BER header */
64
ber_out_header(STREAM s, int tagval, int length)
68
out_uint16_be(s, tagval);
78
out_uint16_be(s, length);
84
/* Output an ASN.1 BER integer */
86
ber_out_integer(STREAM s, int value)
88
ber_out_header(s, BER_TAG_INTEGER, 2);
89
out_uint16_be(s, value);
92
/* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
94
mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize)
96
ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);
97
ber_out_integer(s, max_channels);
98
ber_out_integer(s, max_users);
99
ber_out_integer(s, max_tokens);
100
ber_out_integer(s, 1); /* num_priorities */
101
ber_out_integer(s, 0); /* min_throughput */
102
ber_out_integer(s, 1); /* max_height */
103
ber_out_integer(s, max_pdusize);
104
ber_out_integer(s, 2); /* ver_protocol */
107
/* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
109
mcs_parse_domain_params(STREAM s)
113
ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length);
114
in_uint8s(s, length);
119
/* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
121
mcs_send_connect_initial(STREAM mcs_data)
123
int datalen = mcs_data->end - mcs_data->data;
124
int length = 9 + 3 * 34 + 4 + datalen;
127
s = iso_init(length + 5);
129
ber_out_header(s, MCS_CONNECT_INITIAL, length);
130
ber_out_header(s, BER_TAG_OCTET_STRING, 1); /* calling domain */
132
ber_out_header(s, BER_TAG_OCTET_STRING, 1); /* called domain */
135
ber_out_header(s, BER_TAG_BOOLEAN, 1);
136
out_uint8(s, 0xff); /* upward flag */
138
mcs_out_domain_params(s, 34, 2, 0, 0xffff); /* target params */
139
mcs_out_domain_params(s, 1, 1, 1, 0x420); /* min params */
140
mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */
142
ber_out_header(s, BER_TAG_OCTET_STRING, datalen);
143
out_uint8p(s, mcs_data->data, datalen);
149
/* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
151
mcs_recv_connect_response(STREAM mcs_data)
161
ber_parse_header(s, MCS_CONNECT_RESPONSE, &length);
163
ber_parse_header(s, BER_TAG_RESULT, &length);
167
error("MCS connect: %d\n", result);
171
ber_parse_header(s, BER_TAG_INTEGER, &length);
172
in_uint8s(s, length); /* connect id */
173
mcs_parse_domain_params(s);
175
ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
177
sec_process_mcs_data(s);
179
if (length > mcs_data->size)
181
error("MCS data length %d, expected %d\n", length,
183
length = mcs_data->size;
186
in_uint8a(s, mcs_data->data, length);
187
mcs_data->p = mcs_data->data;
188
mcs_data->end = mcs_data->data + length;
190
return s_check_end(s);
193
/* Send an EDrq message (ASN.1 PER) */
201
out_uint8(s, (MCS_EDRQ << 2));
202
out_uint16_be(s, 1); /* height */
203
out_uint16_be(s, 1); /* interval */
209
/* Send an AUrq message (ASN.1 PER) */
217
out_uint8(s, (MCS_AURQ << 2));
223
/* Expect a AUcf message (ASN.1 PER) */
225
mcs_recv_aucf(uint16 * mcs_userid)
227
uint8 opcode, result;
235
if ((opcode >> 2) != MCS_AUCF)
237
error("expected AUcf, got %d\n", opcode);
244
error("AUrq: %d\n", result);
249
in_uint16_be(s, *mcs_userid);
251
return s_check_end(s);
254
/* Send a CJrq message (ASN.1 PER) */
256
mcs_send_cjrq(uint16 chanid)
260
DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
264
out_uint8(s, (MCS_CJRQ << 2));
265
out_uint16_be(s, g_mcs_userid);
266
out_uint16_be(s, chanid);
272
/* Expect a CJcf message (ASN.1 PER) */
276
uint8 opcode, result;
284
if ((opcode >> 2) != MCS_CJCF)
286
error("expected CJcf, got %d\n", opcode);
293
error("CJrq: %d\n", result);
297
in_uint8s(s, 4); /* mcs_userid, req_chanid */
299
in_uint8s(s, 2); /* join_chanid */
301
return s_check_end(s);
304
/* Initialise an MCS transport data packet */
310
s = iso_init(length + 8);
311
s_push_layer(s, mcs_hdr, 8);
316
/* Send an MCS transport data packet to a specific channel */
318
mcs_send_to_channel(STREAM s, uint16 channel)
322
s_pop_layer(s, mcs_hdr);
323
length = s->end - s->p - 8;
326
out_uint8(s, (MCS_SDRQ << 2));
327
out_uint16_be(s, g_mcs_userid);
328
out_uint16_be(s, channel);
329
out_uint8(s, 0x70); /* flags */
330
out_uint16_be(s, length);
335
/* Send an MCS transport data packet to the global channel */
339
mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
342
/* Receive an MCS transport data packet */
344
mcs_recv(uint16 * channel)
346
uint8 opcode, appid, length;
355
if (appid != MCS_SDIN)
357
if (appid != MCS_DPUM)
359
error("expected data, got %d\n", opcode);
364
in_uint8s(s, 2); /* userid */
365
in_uint16_be(s, *channel);
366
in_uint8s(s, 1); /* flags */
369
in_uint8s(s, 1); /* second byte of length */
374
/* Establish a connection up to the MCS layer */
376
mcs_connect(char *server, STREAM mcs_data, char *username)
380
if (!iso_connect(server, username))
383
mcs_send_connect_initial(mcs_data);
384
if (!mcs_recv_connect_response(mcs_data))
390
if (!mcs_recv_aucf(&g_mcs_userid))
393
mcs_send_cjrq(g_mcs_userid + MCS_USERCHANNEL_BASE);
395
if (!mcs_recv_cjcf())
398
mcs_send_cjrq(MCS_GLOBAL_CHANNEL);
399
if (!mcs_recv_cjcf())
402
for (i = 0; i < g_num_channels; i++)
404
mcs_send_cjrq(g_channels[i].mcs_id);
405
if (!mcs_recv_cjcf())
415
/* Disconnect from the MCS layer */