1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - Multipoint Communications Service |
Protocol services - Multipoint Communications Service |
4 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2005 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
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 |
it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
|
|
23 |
uint16 mcs_userid; |
uint16 g_mcs_userid; |
24 |
extern BOOL use_rdp5; |
extern VCHANNEL g_channels[]; |
25 |
|
extern unsigned int g_num_channels; |
26 |
|
|
27 |
/* Parse an ASN.1 BER header */ |
/* Parse an ASN.1 BER header */ |
28 |
static BOOL |
static BOOL |
154 |
int length; |
int length; |
155 |
STREAM s; |
STREAM s; |
156 |
|
|
157 |
s = iso_recv(); |
s = iso_recv(NULL); |
158 |
if (s == NULL) |
if (s == NULL) |
159 |
return False; |
return False; |
160 |
|
|
178 |
/* |
/* |
179 |
if (length > mcs_data->size) |
if (length > mcs_data->size) |
180 |
{ |
{ |
181 |
error("MCS data length %d, expected %d\n", length, |
error("MCS data length %d, expected %d\n", length, |
182 |
mcs_data->size); |
mcs_data->size); |
183 |
length = mcs_data->size; |
length = mcs_data->size; |
184 |
} |
} |
227 |
uint8 opcode, result; |
uint8 opcode, result; |
228 |
STREAM s; |
STREAM s; |
229 |
|
|
230 |
s = iso_recv(); |
s = iso_recv(NULL); |
231 |
if (s == NULL) |
if (s == NULL) |
232 |
return False; |
return False; |
233 |
|
|
257 |
{ |
{ |
258 |
STREAM s; |
STREAM s; |
259 |
|
|
260 |
|
DEBUG_RDP5(("Sending CJRQ for channel #%d\n", chanid)); |
261 |
|
|
262 |
s = iso_init(5); |
s = iso_init(5); |
263 |
|
|
264 |
out_uint8(s, (MCS_CJRQ << 2)); |
out_uint8(s, (MCS_CJRQ << 2)); |
265 |
out_uint16_be(s, mcs_userid); |
out_uint16_be(s, g_mcs_userid); |
266 |
out_uint16_be(s, chanid); |
out_uint16_be(s, chanid); |
267 |
|
|
268 |
s_mark_end(s); |
s_mark_end(s); |
276 |
uint8 opcode, result; |
uint8 opcode, result; |
277 |
STREAM s; |
STREAM s; |
278 |
|
|
279 |
s = iso_recv(); |
s = iso_recv(NULL); |
280 |
if (s == NULL) |
if (s == NULL) |
281 |
return False; |
return False; |
282 |
|
|
313 |
return s; |
return s; |
314 |
} |
} |
315 |
|
|
316 |
/* Send an MCS transport data packet */ |
/* Send an MCS transport data packet to a specific channel */ |
317 |
void |
void |
318 |
mcs_send(STREAM s) |
mcs_send_to_channel(STREAM s, uint16 channel) |
319 |
{ |
{ |
320 |
uint16 length; |
uint16 length; |
321 |
|
|
324 |
length |= 0x8000; |
length |= 0x8000; |
325 |
|
|
326 |
out_uint8(s, (MCS_SDRQ << 2)); |
out_uint8(s, (MCS_SDRQ << 2)); |
327 |
out_uint16_be(s, mcs_userid); |
out_uint16_be(s, g_mcs_userid); |
328 |
out_uint16_be(s, MCS_GLOBAL_CHANNEL); |
out_uint16_be(s, channel); |
329 |
out_uint8(s, 0x70); /* flags */ |
out_uint8(s, 0x70); /* flags */ |
330 |
out_uint16_be(s, length); |
out_uint16_be(s, length); |
331 |
|
|
332 |
iso_send(s); |
iso_send(s); |
333 |
} |
} |
334 |
|
|
335 |
|
/* Send an MCS transport data packet to the global channel */ |
336 |
|
void |
337 |
|
mcs_send(STREAM s) |
338 |
|
{ |
339 |
|
mcs_send_to_channel(s, MCS_GLOBAL_CHANNEL); |
340 |
|
} |
341 |
|
|
342 |
/* Receive an MCS transport data packet */ |
/* Receive an MCS transport data packet */ |
343 |
STREAM |
STREAM |
344 |
mcs_recv(uint16 * channel) |
mcs_recv(uint16 * channel, uint8 * rdpver) |
345 |
{ |
{ |
346 |
uint8 opcode, appid, length; |
uint8 opcode, appid, length; |
347 |
STREAM s; |
STREAM s; |
348 |
|
|
349 |
s = iso_recv(); |
s = iso_recv(rdpver); |
350 |
if (s == NULL) |
if (s == NULL) |
351 |
return NULL; |
return NULL; |
352 |
|
if (rdpver != NULL) |
353 |
|
if (*rdpver != 3) |
354 |
|
return s; |
355 |
in_uint8(s, opcode); |
in_uint8(s, opcode); |
356 |
appid = opcode >> 2; |
appid = opcode >> 2; |
357 |
if (appid != MCS_SDIN) |
if (appid != MCS_SDIN) |
362 |
} |
} |
363 |
return NULL; |
return NULL; |
364 |
} |
} |
|
|
|
365 |
in_uint8s(s, 2); /* userid */ |
in_uint8s(s, 2); /* userid */ |
366 |
in_uint16_be(s, *channel); |
in_uint16_be(s, *channel); |
367 |
in_uint8s(s, 1); /* flags */ |
in_uint8s(s, 1); /* flags */ |
368 |
in_uint8(s, length); |
in_uint8(s, length); |
369 |
if (length & 0x80) |
if (length & 0x80) |
370 |
in_uint8s(s, 1); /* second byte of length */ |
in_uint8s(s, 1); /* second byte of length */ |
|
|
|
371 |
return s; |
return s; |
372 |
} |
} |
373 |
|
|
375 |
BOOL |
BOOL |
376 |
mcs_connect(char *server, STREAM mcs_data, char *username) |
mcs_connect(char *server, STREAM mcs_data, char *username) |
377 |
{ |
{ |
378 |
|
unsigned int i; |
379 |
|
|
380 |
if (!iso_connect(server, username)) |
if (!iso_connect(server, username)) |
381 |
return False; |
return False; |
382 |
|
|
387 |
mcs_send_edrq(); |
mcs_send_edrq(); |
388 |
|
|
389 |
mcs_send_aurq(); |
mcs_send_aurq(); |
390 |
if (!mcs_recv_aucf(&mcs_userid)) |
if (!mcs_recv_aucf(&g_mcs_userid)) |
391 |
goto error; |
goto error; |
392 |
|
|
393 |
mcs_send_cjrq(mcs_userid + 1001); |
mcs_send_cjrq(g_mcs_userid + MCS_USERCHANNEL_BASE); |
394 |
|
|
395 |
if (!mcs_recv_cjcf()) |
if (!mcs_recv_cjcf()) |
396 |
goto error; |
goto error; |
397 |
|
|
399 |
if (!mcs_recv_cjcf()) |
if (!mcs_recv_cjcf()) |
400 |
goto error; |
goto error; |
401 |
|
|
402 |
if (use_rdp5) |
for (i = 0; i < g_num_channels; i++) |
403 |
{ |
{ |
404 |
/* Note: If we send this cjrq after telling the server we support RDP4 only, |
mcs_send_cjrq(g_channels[i].mcs_id); |
|
the server won't respond with a cjcf and we will hang. */ |
|
|
mcs_send_cjrq(MCS_GLOBAL_CHANNEL + 1); /* hack - clipboard */ |
|
405 |
if (!mcs_recv_cjcf()) |
if (!mcs_recv_cjcf()) |
406 |
goto error; |
goto error; |
407 |
} |
} |
408 |
|
return True; |
409 |
|
|
410 |
|
error: |
411 |
|
iso_disconnect(); |
412 |
|
return False; |
413 |
|
} |
414 |
|
|
415 |
|
/* Establish a connection up to the MCS layer */ |
416 |
|
BOOL |
417 |
|
mcs_reconnect(char *server, STREAM mcs_data) |
418 |
|
{ |
419 |
|
unsigned int i; |
420 |
|
|
421 |
|
if (!iso_reconnect(server)) |
422 |
|
return False; |
423 |
|
|
424 |
|
mcs_send_connect_initial(mcs_data); |
425 |
|
if (!mcs_recv_connect_response(mcs_data)) |
426 |
|
goto error; |
427 |
|
|
428 |
|
mcs_send_edrq(); |
429 |
|
|
430 |
|
mcs_send_aurq(); |
431 |
|
if (!mcs_recv_aucf(&g_mcs_userid)) |
432 |
|
goto error; |
433 |
|
|
434 |
|
mcs_send_cjrq(g_mcs_userid + MCS_USERCHANNEL_BASE); |
435 |
|
|
436 |
|
if (!mcs_recv_cjcf()) |
437 |
|
goto error; |
438 |
|
|
439 |
|
mcs_send_cjrq(MCS_GLOBAL_CHANNEL); |
440 |
|
if (!mcs_recv_cjcf()) |
441 |
|
goto error; |
442 |
|
|
443 |
|
for (i = 0; i < g_num_channels; i++) |
444 |
|
{ |
445 |
|
mcs_send_cjrq(g_channels[i].mcs_id); |
446 |
|
if (!mcs_recv_cjcf()) |
447 |
|
goto error; |
448 |
|
} |
449 |
return True; |
return True; |
450 |
|
|
451 |
error: |
error: |
459 |
{ |
{ |
460 |
iso_disconnect(); |
iso_disconnect(); |
461 |
} |
} |
462 |
|
|
463 |
|
/* reset the state of the mcs layer */ |
464 |
|
void |
465 |
|
mcs_reset_state(void) |
466 |
|
{ |
467 |
|
g_mcs_userid = 0; |
468 |
|
iso_reset_state(); |
469 |
|
} |