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);
93 ber_in_integer(STREAM s, int *value)
96 ber_parse_header(s, BER_TAG_INTEGER, &length);
97 in_uint16_be(s, *value);
100 /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
102 mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize)
104 ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 32);
105 ber_out_integer(s, max_channels);
106 ber_out_integer(s, max_users);
107 ber_out_integer(s, max_tokens);
108 ber_out_integer(s, 1); /* num_priorities */
109 ber_out_integer(s, 0); /* min_throughput */
110 ber_out_integer(s, 1); /* max_height */
111 ber_out_integer(s, max_pdusize);
112 ber_out_integer(s, 2); /* ver_protocol */
115 /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
117 mcs_parse_domain_params(STREAM s)
120 int max_channels, max_users, max_tokens, max_pdusize;
121 int num_priorities, min_throughput, max_height;
124 ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length);
125 printf("MCS_TAG_DOMAIN_PARAMS, len %u (expected 32)\n", length);
127 ber_in_integer(s, &max_channels);
128 ber_in_integer(s, &max_users);
129 ber_in_integer(s, &max_tokens);
130 ber_in_integer(s, &num_priorities);
131 ber_in_integer(s, &min_throughput);
132 ber_in_integer(s, &max_height);
133 ber_in_integer(s, &max_pdusize);
134 ber_in_integer(s, &ver_protocol);
136 printf("max_channels=%u\n", max_channels);
137 printf("max_users=%u\n", max_users);
138 printf("max_tokens=%u\n", max_tokens);
139 printf("num_priorities=%u\n", num_priorities);
140 printf("min_throughput=%u\n", min_throughput);
141 printf("max_pdusize=%u\n", max_pdusize);
142 printf("ver_protocol=%u\n", ver_protocol);
144 in_uint8s(s, length);
150 /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
152 mcs_recv_connect_initial()
163 ber_parse_header(s, MCS_CONNECT_INITIAL, &length);
164 printf("parsing MCS_CONNECT_INITIAL (len=%u)\n", length);
165 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* calling domain */
167 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* called domain */
170 ber_parse_header(s, BER_TAG_BOOLEAN, &length);
173 mcs_parse_domain_params(s);
174 mcs_parse_domain_params(s);
175 mcs_parse_domain_params(s);
177 ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
178 in_uint8p(s, buf, length);
180 printf("Data from MCS connect: '%*s'\n", length, buf);
182 return s_check_end(s);
186 mcs_send_connect_response()
193 ber_out_header(s, MCS_CONNECT_RESPONSE, 80);
194 ber_out_header(s, BER_TAG_RESULT, 1);
197 ber_out_header(s, BER_TAG_INTEGER, 1);
198 out_uint8(s, 1); // connect id
200 mcs_out_domain_params(s, 34, 2, 0, 0xffff); // dumdidum?
202 ber_out_header(s, BER_TAG_OCTET_STRING, 40);
204 out_uint8s(s, 21); // ick
207 // server info -- we claim to support RDP1
208 out_uint16_le(s, SEC_TAG_SRV_INFO);
209 out_uint16_le(s, 6); // length
213 out_uint16_le(s, SEC_TAG_SRV_CRYPT);
214 out_uint16_le(s, 12); // length
215 out_uint32_le(s, 1); // 40-bit
216 out_uint32_le(s, 0); // no encryption
219 printf("LEN: %u\n", s->p - s->iso_hdr);
224 /* Send an EDrq message (ASN.1 PER) */
232 out_uint8(s, (MCS_EDRQ << 2));
233 out_uint16_be(s, 1); /* height */
234 out_uint16_be(s, 1); /* interval */
240 /* Send an AUrq message (ASN.1 PER) */
248 out_uint8(s, (MCS_AURQ << 2));
254 /* Send a AUcf message (ASN.1 PER) */
256 mcs_send_aucf(uint16 mcs_userid)
262 out_uint8(s, (MCS_AUCF << 2) | 2); // | 2 = send user ID
263 out_uint8(s, 0); // success
270 /* Send a CJrq message (ASN.1 PER) */
272 mcs_send_cjrq(uint16 chanid)
276 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
280 out_uint8(s, (MCS_CJRQ << 2));
281 out_uint16_be(s, g_mcs_userid);
282 out_uint16_be(s, chanid);
288 /* Expect a CJcf message (ASN.1 PER) */
290 mcs_send_cjcf(uint16 userid, uint16 chanid)
296 out_uint8(s, (MCS_CJCF << 2));
297 out_uint8(s, 0); // success
298 out_uint16_be(s, g_mcs_userid);
299 out_uint16_be(s, chanid);
305 /* Initialise an MCS transport data packet */
311 s = iso_init(length + 8);
312 s_push_layer(s, mcs_hdr, 8);
317 /* Send an MCS transport data packet to a specific channel */
319 mcs_send_to_channel(STREAM s, uint16 channel)
323 s_pop_layer(s, mcs_hdr);
324 length = s->end - s->p - 8;
327 out_uint8(s, (MCS_SDIN << 2));
328 out_uint16_be(s, g_mcs_userid);
329 out_uint16_be(s, channel);
330 out_uint8(s, 0x70); /* flags */
331 out_uint16_be(s, length);
336 /* Send an MCS transport data packet to the global channel */
340 mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
343 /* Receive an MCS transport data packet */
345 mcs_recv(uint16 * channel)
347 uint8 opcode, appid, length, userid;
359 in_uint8s(s, 2); /* userid */
360 in_uint16_be(s, *channel);
361 in_uint8s(s, 1); /* flags */
364 in_uint8s(s, 1); /* second byte of length */
370 // Erect Domain (ignore)
371 printf("Received EDrq\n");
374 // Attach User Request, respond with AUcf (Attach User Confirm)
375 printf("Received AUrq, sending AUcf\n");
379 // Channel Join Request, respond with CJcf (Channel Join Confirm);
380 in_uint16_be(s, userid);
381 in_uint16_be(s, *channel);
382 printf("Received CJrq for channel %hu, sending CJcf\n", *channel);
383 mcs_send_cjcf(userid, *channel);
386 error("expected data, got %d\n", opcode);
392 /* Disconnect from the MCS layer */