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(80); // FIXME
161 ber_out_header(s, MCS_CONNECT_RESPONSE, 80);
162 ber_out_header(s, BER_TAG_RESULT, 1);
165 ber_out_header(s, BER_TAG_INTEGER, 1);
166 out_uint8(s, 1); // connect id
168 mcs_out_domain_params(s, 34, 2, 0, 0xffff); // dumdidum?
170 ber_out_header(s, BER_TAG_OCTET_STRING, 28);
172 out_uint8s(s, 21); // ick
175 // server info -- we claim to support RDP4
176 out_uint16_le(s, SEC_TAG_SRV_INFO);
177 out_uint16_le(s, 6); // length
180 // aiee, no crypto info yet! :-)
183 printf("LEN: %u\n", s->p - s->iso_hdr);
188 /* Send an EDrq message (ASN.1 PER) */
196 out_uint8(s, (MCS_EDRQ << 2));
197 out_uint16_be(s, 1); /* height */
198 out_uint16_be(s, 1); /* interval */
204 /* Send an AUrq message (ASN.1 PER) */
212 out_uint8(s, (MCS_AURQ << 2));
218 /* Send a AUcf message (ASN.1 PER) */
220 mcs_send_aucf(uint16 mcs_userid)
226 out_uint8(s, (MCS_AUCF << 2) | 2); // | 2 = send user ID
227 out_uint8(s, 0); // success
234 /* Send a CJrq message (ASN.1 PER) */
236 mcs_send_cjrq(uint16 chanid)
240 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
244 out_uint8(s, (MCS_CJRQ << 2));
245 out_uint16_be(s, g_mcs_userid);
246 out_uint16_be(s, chanid);
252 /* Expect a CJcf message (ASN.1 PER) */
254 mcs_send_cjcf(uint16 userid, uint16 chanid)
260 out_uint8(s, (MCS_CJCF << 2));
261 out_uint8(s, 0); // success
262 out_uint16_be(s, g_mcs_userid);
263 out_uint16_be(s, chanid);
269 /* Initialise an MCS transport data packet */
275 s = iso_init(length + 8);
276 s_push_layer(s, mcs_hdr, 8);
281 /* Send an MCS transport data packet to a specific channel */
283 mcs_send_to_channel(STREAM s, uint16 channel)
287 s_pop_layer(s, mcs_hdr);
288 length = s->end - s->p - 8;
291 out_uint8(s, (MCS_SDRQ << 2));
292 out_uint16_be(s, g_mcs_userid);
293 out_uint16_be(s, channel);
294 out_uint8(s, 0x70); /* flags */
295 out_uint16_be(s, length);
300 /* Send an MCS transport data packet to the global channel */
304 mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
307 /* Receive an MCS transport data packet */
309 mcs_recv(uint16 * channel)
311 uint8 opcode, appid, length, userid;
323 in_uint8s(s, 2); /* userid */
324 in_uint16_be(s, *channel);
325 in_uint8s(s, 1); /* flags */
328 in_uint8s(s, 1); /* second byte of length */
334 // Erect Domain (ignore)
335 printf("Received EDrq\n");
338 // Attach User Request, respond with AUcf (Attach User Confirm)
339 printf("Received AUrq, sending AUcf\n");
343 // Channel Join Request, respond with CJcf (Channel Join Confirm);
344 in_uint16_be(s, userid);
345 in_uint16_be(s, *channel);
346 printf("Received CJrq for channel %hu, sending CJcf\n", *channel);
347 mcs_send_cjcf(userid, *channel);
350 error("expected data, got %d\n", opcode);
356 /* Disconnect from the MCS layer */