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 /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
121 mcs_recv_connect_initial()
132 ber_parse_header(s, MCS_CONNECT_INITIAL, &length);
133 printf("parsing MCS_CONNECT_INITIAL (len=%u)\n", length);
134 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* calling domain */
136 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* called domain */
139 ber_parse_header(s, BER_TAG_BOOLEAN, &length);
142 mcs_parse_domain_params(s);
143 mcs_parse_domain_params(s);
144 mcs_parse_domain_params(s);
146 ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
147 in_uint8p(s, buf, length);
149 printf("Data from MCS connect: '%*s'\n", length, buf);
151 return s_check_end(s);
155 mcs_send_connect_response()
159 s = iso_init(2048); // FIXME
161 ber_out_header(s, MCS_CONNECT_RESPONSE, 2048);
162 ber_out_header(s, BER_TAG_RESULT, 1);
163 out_uint8(s, 1); // success
170 /* Send an EDrq message (ASN.1 PER) */
178 out_uint8(s, (MCS_EDRQ << 2));
179 out_uint16_be(s, 1); /* height */
180 out_uint16_be(s, 1); /* interval */
186 /* Send an AUrq message (ASN.1 PER) */
194 out_uint8(s, (MCS_AURQ << 2));
200 /* Expect a AUcf message (ASN.1 PER) */
202 mcs_recv_aucf(uint16 * mcs_userid)
204 uint8 opcode, result;
212 if ((opcode >> 2) != MCS_AUCF)
214 error("expected AUcf, got %d\n", opcode);
221 error("AUrq: %d\n", result);
226 in_uint16_be(s, *mcs_userid);
228 return s_check_end(s);
231 /* Send a CJrq message (ASN.1 PER) */
233 mcs_send_cjrq(uint16 chanid)
237 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
241 out_uint8(s, (MCS_CJRQ << 2));
242 out_uint16_be(s, g_mcs_userid);
243 out_uint16_be(s, chanid);
249 /* Expect a CJcf message (ASN.1 PER) */
253 uint8 opcode, result;
261 if ((opcode >> 2) != MCS_CJCF)
263 error("expected CJcf, got %d\n", opcode);
270 error("CJrq: %d\n", result);
274 in_uint8s(s, 4); /* mcs_userid, req_chanid */
276 in_uint8s(s, 2); /* join_chanid */
278 return s_check_end(s);
281 /* Initialise an MCS transport data packet */
287 s = iso_init(length + 8);
288 s_push_layer(s, mcs_hdr, 8);
293 /* Send an MCS transport data packet to a specific channel */
295 mcs_send_to_channel(STREAM s, uint16 channel)
299 s_pop_layer(s, mcs_hdr);
300 length = s->end - s->p - 8;
303 out_uint8(s, (MCS_SDRQ << 2));
304 out_uint16_be(s, g_mcs_userid);
305 out_uint16_be(s, channel);
306 out_uint8(s, 0x70); /* flags */
307 out_uint16_be(s, length);
312 /* Send an MCS transport data packet to the global channel */
316 mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
319 /* Receive an MCS transport data packet */
321 mcs_recv(uint16 * channel)
323 uint8 opcode, appid, length;
332 if (appid != MCS_SDIN)
334 if (appid != MCS_DPUM)
336 error("expected data, got %d\n", opcode);
341 in_uint8s(s, 2); /* userid */
342 in_uint16_be(s, *channel);
343 in_uint8s(s, 1); /* flags */
346 in_uint8s(s, 1); /* second byte of length */
351 /* Disconnect from the MCS layer */