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_out_uint8(STREAM s, uint8 value)
95 ber_out_header(s, BER_TAG_INTEGER, 1);
100 ber_in_integer(STREAM s, int *value)
103 ber_parse_header(s, BER_TAG_INTEGER, &length);
104 in_uint16_be(s, *value);
107 /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
109 mcs_out_domain_params(STREAM s, int max_channels, int max_users, int max_tokens, int max_pdusize)
111 ber_out_header(s, MCS_TAG_DOMAIN_PARAMS, 26);
112 ber_out_uint8(s, 34); // max_channels
113 ber_out_uint8(s, 3); // max_users
114 ber_out_uint8(s, 0); // max_tokens
115 ber_out_uint8(s, 1); // num_priorities
116 ber_out_uint8(s, 0); // min_throughput
117 ber_out_uint8(s, 1); // max_height
118 ber_out_header(s, BER_TAG_INTEGER, 3); // pdu size
122 ber_out_uint8(s, 2); // ver_protocol
125 /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
127 mcs_parse_domain_params(STREAM s)
130 int max_channels, max_users, max_tokens, max_pdusize;
131 int num_priorities, min_throughput, max_height;
134 ber_parse_header(s, MCS_TAG_DOMAIN_PARAMS, &length);
135 printf("MCS_TAG_DOMAIN_PARAMS, len %u (expected 32)\n", length);
137 ber_in_integer(s, &max_channels);
138 ber_in_integer(s, &max_users);
139 ber_in_integer(s, &max_tokens);
140 ber_in_integer(s, &num_priorities);
141 ber_in_integer(s, &min_throughput);
142 ber_in_integer(s, &max_height);
143 ber_in_integer(s, &max_pdusize);
144 ber_in_integer(s, &ver_protocol);
146 printf("max_channels=%u\n", max_channels);
147 printf("max_users=%u\n", max_users);
148 printf("max_tokens=%u\n", max_tokens);
149 printf("num_priorities=%u\n", num_priorities);
150 printf("min_throughput=%u\n", min_throughput);
151 printf("max_pdusize=%u\n", max_pdusize);
152 printf("ver_protocol=%u\n", ver_protocol);
154 hexdump(s->p, length);
155 in_uint8s(s, length);
161 /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
163 mcs_recv_connect_initial()
174 ber_parse_header(s, MCS_CONNECT_INITIAL, &length);
175 printf("parsing MCS_CONNECT_INITIAL (len=%u)\n", length);
176 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* calling domain */
178 ber_parse_header(s, BER_TAG_OCTET_STRING, &length); /* called domain */
181 ber_parse_header(s, BER_TAG_BOOLEAN, &length);
184 mcs_parse_domain_params(s);
185 mcs_parse_domain_params(s);
186 mcs_parse_domain_params(s);
188 ber_parse_header(s, BER_TAG_OCTET_STRING, &length);
189 in_uint8p(s, buf, length);
191 printf("Data from MCS connect: '%*s'\n", length, buf);
193 return s_check_end(s);
197 mcs_send_connect_response()
203 printf("INITLEN: %u\n", s->p - s->iso_hdr);
205 ber_out_header(s, MCS_CONNECT_RESPONSE, 93);
206 ber_out_header(s, BER_TAG_RESULT, 1);
209 ber_out_header(s, BER_TAG_INTEGER, 1);
210 out_uint8(s, 0); // connect id
212 mcs_out_domain_params(s, 34, 2, 0, 0xffff); // dumdidum?
214 ber_out_header(s, BER_TAG_OCTET_STRING, 59);
216 // some unknown header of sorts
227 out_uint8(s, 0x0a); // length?
228 out_uint8(s, 0x01); // length?
239 out_uint8(s, 0x81); // one byte length
240 out_uint8(s, 0x04); // unknown
242 // server info -- we claim to support RDP5
243 out_uint16_le(s, SEC_TAG_SRV_INFO);
244 out_uint16_le(s, 8); // length
245 out_uint16_le(s, 4); // version
246 out_uint16_le(s, 8); // unknown
248 // channel info -- open a few channels
249 out_uint16_le(s, SEC_TAG_SRV_CHANNELS);
250 out_uint16_le(s, 16); // length
251 out_uint16_le(s, 1003);
253 out_uint16_le(s, 1004);
254 out_uint16_le(s, 1005);
255 out_uint16_le(s, 1006);
259 out_uint16_le(s, SEC_TAG_SRV_CRYPT);
260 out_uint16_le(s, 12); // length
261 out_uint32_le(s, 1); // 40-bit
262 out_uint32_le(s, 0); // no encryption
265 printf("LEN: %u\n", s->p - s->iso_hdr);
270 /* Send an EDrq message (ASN.1 PER) */
278 out_uint8(s, (MCS_EDRQ << 2));
279 out_uint16_be(s, 1); /* height */
280 out_uint16_be(s, 1); /* interval */
286 /* Send an AUrq message (ASN.1 PER) */
294 out_uint8(s, (MCS_AURQ << 2));
300 /* Send a AUcf message (ASN.1 PER) */
302 mcs_send_aucf(uint16 mcs_userid)
308 out_uint8(s, (MCS_AUCF << 2) | 2); // | 2 = send user ID
309 out_uint8(s, 0); // success
316 /* Send a CJrq message (ASN.1 PER) */
318 mcs_send_cjrq(uint16 chanid)
322 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid));
326 out_uint8(s, (MCS_CJRQ << 2));
327 out_uint16_be(s, g_mcs_userid);
328 out_uint16_be(s, chanid);
334 /* Expect a CJcf message (ASN.1 PER) */
336 mcs_send_cjcf(uint16 userid, uint16 chanid)
342 out_uint8(s, (MCS_CJCF << 2) | 2);
343 out_uint8(s, 0); // success
345 out_uint16_be(s, chanid);
346 out_uint16_be(s, chanid);
352 /* Initialise an MCS transport data packet */
358 s = iso_init(length + 8);
359 s_push_layer(s, mcs_hdr, 8);
364 /* Send an MCS transport data packet to a specific channel */
366 mcs_send_to_channel(STREAM s, uint16 channel)
370 s_pop_layer(s, mcs_hdr);
371 length = s->end - s->p - 8;
374 out_uint8(s, (MCS_SDIN << 2));
375 out_uint16_be(s, g_mcs_userid);
376 out_uint16_be(s, channel);
377 out_uint8(s, 0x70); /* flags */
378 out_uint16_be(s, length);
383 /* Send an MCS transport data packet to the global channel */
387 mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL);
390 /* Receive an MCS transport data packet */
392 mcs_recv(uint16 * channel)
394 uint8 opcode, appid, length, userid;
406 in_uint8s(s, 2); /* userid */
407 in_uint16_be(s, *channel);
408 in_uint8s(s, 1); /* flags */
411 in_uint8s(s, 1); /* second byte of length */
417 // Erect Domain (ignore)
418 printf("Received EDrq\n");
421 // Attach User Request, respond with AUcf (Attach User Confirm)
422 printf("Received AUrq, sending AUcf\n");
426 // Channel Join Request, respond with CJcf (Channel Join Confirm);
427 in_uint16_be(s, userid);
428 in_uint16_be(s, *channel);
429 printf("Received CJrq for channel %hu, sending CJcf\n", *channel);
430 mcs_send_cjcf(userid, *channel);
433 error("expected data, got %d\n", opcode);
439 /* Disconnect from the MCS layer */