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_initial()
162 ber_parse_header(s, MCS_CONNECT_INITIAL, &length);
163 printf("parsing MCS_CONNECT_INITIAL (len=%u)\n", length);
164 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* calling domain */
166 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* called domain */
169 ber_parse_header(s, BER_TAG_BOOLEAN, &length);
172 mcs_parse_domain_params(s);
173 mcs_parse_domain_params(s);
174 mcs_parse_domain_params(s);
176 ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
177 in_uint8p(s, buf, length);
179 printf("Data from MCS connect: '%*s'\n", length, buf);
181 return s_check_end(s);
184 /* Send an EDrq message (ASN.1 PER) */
192 out_uint8(s, (MCS_EDRQ << 2));
193 out_uint16_be(s, 1); /* height */
194 out_uint16_be(s, 1); /* interval */
200 /* Send an AUrq message (ASN.1 PER) */
208 out_uint8(s, (MCS_AURQ << 2));
214 /* Expect a AUcf message (ASN.1 PER) */
216 mcs_recv_aucf(uint16 * mcs_userid)
218 uint8 opcode, result;
226 if ((opcode >> 2) != MCS_AUCF)
228 error("expected AUcf, got %d\n", opcode);
235 error("AUrq: %d\n", result);
240 in_uint16_be(s, *mcs_userid);
242 return s_check_end(s);
245 /* Send a CJrq message (ASN.1 PER) */
247 mcs_send_cjrq(uint16 chanid)
251 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
255 out_uint8(s, (MCS_CJRQ << 2));
256 out_uint16_be(s, g_mcs_userid);
257 out_uint16_be(s, chanid);
263 /* Expect a CJcf message (ASN.1 PER) */
267 uint8 opcode, result;
275 if ((opcode >> 2) != MCS_CJCF)
277 error("expected CJcf, got %d\n", opcode);
284 error("CJrq: %d\n", result);
288 in_uint8s(s, 4); /* mcs_userid, req_chanid */
290 in_uint8s(s, 2); /* join_chanid */
292 return s_check_end(s);
295 /* Initialise an MCS transport data packet */
301 s = iso_init(length + 8);
302 s_push_layer(s, mcs_hdr, 8);
307 /* Send an MCS transport data packet to a specific channel */
309 mcs_send_to_channel(STREAM s, uint16 channel)
313 s_pop_layer(s, mcs_hdr);
314 length = s->end - s->p - 8;
317 out_uint8(s, (MCS_SDRQ << 2));
318 out_uint16_be(s, g_mcs_userid);
319 out_uint16_be(s, channel);
320 out_uint8(s, 0x70); /* flags */
321 out_uint16_be(s, length);
326 /* Send an MCS transport data packet to the global channel */
330 mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
333 /* Receive an MCS transport data packet */
335 mcs_recv(uint16 * channel)
337 uint8 opcode, appid, length;
346 if (appid != MCS_SDIN)
348 if (appid != MCS_DPUM)
350 error("expected data, got %d\n", opcode);
355 in_uint8s(s, 2); /* userid */
356 in_uint16_be(s, *channel);
357 in_uint8s(s, 1); /* flags */
360 in_uint8s(s, 1); /* second byte of length */
365 /* Disconnect from the MCS layer */