1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - Multipoint Communications Service
4 Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
5 Copyright 2005-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 extern VCHANNEL g_channels
[];
25 extern unsigned int g_num_channels
;
28 /* Output a DOMAIN_PARAMS structure (ASN.1 BER) */
30 mcs_out_domain_params(STREAM s
, int max_channels
, int max_users
, int max_tokens
, int max_pdusize
)
32 ber_out_header(s
, MCS_TAG_DOMAIN_PARAMS
, 32);
33 ber_out_integer(s
, max_channels
);
34 ber_out_integer(s
, max_users
);
35 ber_out_integer(s
, max_tokens
);
36 ber_out_integer(s
, 1); /* num_priorities */
37 ber_out_integer(s
, 0); /* min_throughput */
38 ber_out_integer(s
, 1); /* max_height */
39 ber_out_integer(s
, max_pdusize
);
40 ber_out_integer(s
, 2); /* ver_protocol */
43 /* Parse a DOMAIN_PARAMS structure (ASN.1 BER) */
45 mcs_parse_domain_params(STREAM s
)
49 ber_parse_header(s
, MCS_TAG_DOMAIN_PARAMS
, &length
);
55 /* Send an MCS_CONNECT_INITIAL message (ASN.1 BER) */
57 mcs_send_connect_initial(STREAM mcs_data
)
59 int datalen
= mcs_data
->end
- mcs_data
->data
;
60 int length
= 9 + 3 * 34 + 4 + datalen
;
63 s
= iso_init(length
+ 5);
65 ber_out_header(s
, MCS_CONNECT_INITIAL
, length
);
66 ber_out_header(s
, BER_TAG_OCTET_STRING
, 1); /* calling domain */
68 ber_out_header(s
, BER_TAG_OCTET_STRING
, 1); /* called domain */
71 ber_out_header(s
, BER_TAG_BOOLEAN
, 1);
72 out_uint8(s
, 0xff); /* upward flag */
74 mcs_out_domain_params(s
, 34, 2, 0, 0xffff); /* target params */
75 mcs_out_domain_params(s
, 1, 1, 1, 0x420); /* min params */
76 mcs_out_domain_params(s
, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */
78 ber_out_header(s
, BER_TAG_OCTET_STRING
, datalen
);
79 out_uint8p(s
, mcs_data
->data
, datalen
);
85 /* Expect a MCS_CONNECT_RESPONSE message (ASN.1 BER) */
87 mcs_recv_connect_response(STREAM mcs_data
)
97 ber_parse_header(s
, MCS_CONNECT_RESPONSE
, &length
);
99 ber_parse_header(s
, BER_TAG_RESULT
, &length
);
103 error("MCS connect: %d\n", result
);
107 ber_parse_header(s
, BER_TAG_INTEGER
, &length
);
108 in_uint8s(s
, length
); /* connect id */
109 mcs_parse_domain_params(s
);
111 ber_parse_header(s
, BER_TAG_OCTET_STRING
, &length
);
113 sec_process_mcs_data(s
);
115 if (length > mcs_data->size)
117 error("MCS data length %d, expected %d\n", length,
119 length = mcs_data->size;
122 in_uint8a(s, mcs_data->data, length);
123 mcs_data->p = mcs_data->data;
124 mcs_data->end = mcs_data->data + length;
126 return s_check_end(s
);
129 /* Send an EDrq message (ASN.1 PER) */
137 out_uint8(s
, (MCS_EDRQ
<< 2));
138 out_uint16_be(s
, 1); /* height */
139 out_uint16_be(s
, 1); /* interval */
145 /* Send an AUrq message (ASN.1 PER) */
153 out_uint8(s
, (MCS_AURQ
<< 2));
159 /* Expect a AUcf message (ASN.1 PER) */
161 mcs_recv_aucf(uint16
* mcs_userid
)
163 uint8 opcode
, result
;
171 if ((opcode
>> 2) != MCS_AUCF
)
173 error("expected AUcf, got %d\n", opcode
);
180 error("AUrq: %d\n", result
);
185 in_uint16_be(s
, *mcs_userid
);
187 return s_check_end(s
);
190 /* Send a CJrq message (ASN.1 PER) */
192 mcs_send_cjrq(uint16 chanid
)
196 DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid
));
200 out_uint8(s
, (MCS_CJRQ
<< 2));
201 out_uint16_be(s
, g_mcs_userid
);
202 out_uint16_be(s
, chanid
);
208 /* Expect a CJcf message (ASN.1 PER) */
212 uint8 opcode
, result
;
220 if ((opcode
>> 2) != MCS_CJCF
)
222 error("expected CJcf, got %d\n", opcode
);
229 error("CJrq: %d\n", result
);
233 in_uint8s(s
, 4); /* mcs_userid, req_chanid */
235 in_uint8s(s
, 2); /* join_chanid */
237 return s_check_end(s
);
240 /* Initialise an MCS transport data packet */
246 s
= iso_init(length
+ 8);
247 s_push_layer(s
, mcs_hdr
, 8);
252 /* Send an MCS transport data packet to a specific channel */
254 mcs_send_to_channel(STREAM s
, uint16 channel
)
258 s_pop_layer(s
, mcs_hdr
);
259 length
= s
->end
- s
->p
- 8;
262 out_uint8(s
, (MCS_SDRQ
<< 2));
263 out_uint16_be(s
, g_mcs_userid
);
264 out_uint16_be(s
, channel
);
265 out_uint8(s
, 0x70); /* flags */
266 out_uint16_be(s
, length
);
271 /* Send an MCS transport data packet to the global channel */
275 mcs_send_to_channel(s
, MCS_GLOBAL_CHANNEL
);
278 /* Receive an MCS transport data packet */
280 mcs_recv(uint16
* channel
, uint8
* rdpver
)
282 uint8 opcode
, appid
, length
;
285 s
= iso_recv(rdpver
);
293 if (appid
!= MCS_SDIN
)
295 if (appid
!= MCS_DPUM
)
297 error("expected data, got %d\n", opcode
);
301 in_uint8s(s
, 2); /* userid */
302 in_uint16_be(s
, *channel
);
303 in_uint8s(s
, 1); /* flags */
306 in_uint8s(s
, 1); /* second byte of length */
311 mcs_connect_start(char *server
, char *username
, char *domain
, char *password
,
312 RD_BOOL reconnect
, uint32
* selected_protocol
)
314 return iso_connect(server
, username
, domain
, password
, reconnect
, selected_protocol
);
318 mcs_connect_finalize(STREAM mcs_data
)
322 mcs_send_connect_initial(mcs_data
);
323 if (!mcs_recv_connect_response(mcs_data
))
329 if (!mcs_recv_aucf(&g_mcs_userid
))
332 mcs_send_cjrq(g_mcs_userid
+ MCS_USERCHANNEL_BASE
);
334 if (!mcs_recv_cjcf())
337 mcs_send_cjrq(MCS_GLOBAL_CHANNEL
);
338 if (!mcs_recv_cjcf())
341 for (i
= 0; i
< g_num_channels
; i
++)
343 mcs_send_cjrq(g_channels
[i
].mcs_id
);
344 if (!mcs_recv_cjcf())
354 /* Disconnect from the MCS layer */
361 /* reset the state of the mcs layer */
363 mcs_reset_state(void)