FreeRDP
Loading...
Searching...
No Matches
gcc.c
1
24#include <freerdp/config.h>
25
26#include "settings.h"
27
28#include <winpr/crt.h>
29#include <winpr/crypto.h>
30#include <winpr/assert.h>
31#include <winpr/cast.h>
32
33#include <freerdp/log.h>
34#include <freerdp/utils/string.h>
35#include <freerdp/crypto/certificate.h>
36
37#include "utils.h"
38#include "gcc.h"
39#include "nego.h"
40
41#include "../crypto/certificate.h"
42
43typedef enum
44{
45 HIGH_COLOR_4BPP = 0x04,
46 HIGH_COLOR_8BPP = 0x08,
47 HIGH_COLOR_15BPP = 0x0F,
48 HIGH_COLOR_16BPP = 0x10,
49 HIGH_COLOR_24BPP = 0x18,
50} HIGH_COLOR_DEPTH;
51
52static const char* HighColorToString(HIGH_COLOR_DEPTH color)
53{
54 switch (color)
55 {
56 case HIGH_COLOR_4BPP:
57 return "HIGH_COLOR_4BPP";
58 case HIGH_COLOR_8BPP:
59 return "HIGH_COLOR_8BPP";
60 case HIGH_COLOR_15BPP:
61 return "HIGH_COLOR_15BPP";
62 case HIGH_COLOR_16BPP:
63 return "HIGH_COLOR_16BPP";
64 case HIGH_COLOR_24BPP:
65 return "HIGH_COLOR_24BPP";
66 default:
67 return "HIGH_COLOR_UNKNOWN";
68 }
69}
70
71static HIGH_COLOR_DEPTH ColorDepthToHighColor(UINT32 bpp)
72{
73 switch (bpp)
74 {
75 case 4:
76 return HIGH_COLOR_4BPP;
77 case 8:
78 return HIGH_COLOR_8BPP;
79 case 15:
80 return HIGH_COLOR_15BPP;
81 case 16:
82 return HIGH_COLOR_16BPP;
83 default:
84 return HIGH_COLOR_24BPP;
85 }
86}
87
88static char* gcc_block_type_string(UINT16 type, char* buffer, size_t size);
89static BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs);
90static BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs);
91static BOOL gcc_read_client_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length);
92static BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length);
93static BOOL gcc_read_user_data_header(wLog* log, wStream* s, UINT16* type, UINT16* length);
94static BOOL gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length);
95
96static BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs);
97static BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs);
98static BOOL gcc_write_server_core_data(wStream* s, rdpMcs* mcs);
99static BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs);
100static BOOL gcc_write_client_security_data(wStream* s, const rdpMcs* mcs);
101static BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs);
102static BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs);
103static BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs);
104static BOOL gcc_write_client_network_data(wStream* s, const rdpMcs* mcs);
105static BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs);
106static BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs);
107static BOOL gcc_write_client_cluster_data(wStream* s, const rdpMcs* mcs);
108static BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs);
109static BOOL gcc_write_client_monitor_data(wStream* s, const rdpMcs* mcs);
110static BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs);
111static BOOL gcc_write_client_monitor_extended_data(wStream* s, const rdpMcs* mcs);
112static BOOL gcc_read_client_message_channel_data(wStream* s, rdpMcs* mcs);
113static BOOL gcc_write_client_message_channel_data(wStream* s, const rdpMcs* mcs);
114static BOOL gcc_read_server_message_channel_data(wStream* s, rdpMcs* mcs);
115static BOOL gcc_write_server_message_channel_data(wStream* s, const rdpMcs* mcs);
116static BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpMcs* mcs);
117static BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMcs* mcs);
118static BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpMcs* mcs);
119static BOOL gcc_write_server_multitransport_channel_data(wStream* s, const rdpMcs* mcs);
120
121static rdpSettings* mcs_get_settings(rdpMcs* mcs)
122{
123 WINPR_ASSERT(mcs);
124 WINPR_ASSERT(mcs->context);
125
126 return mcs->context->settings;
127}
128
129static const rdpSettings* mcs_get_const_settings(const rdpMcs* mcs)
130{
131 WINPR_ASSERT(mcs);
132 WINPR_ASSERT(mcs->context);
133
134 return mcs->context->settings;
135}
136
137static char* rdp_early_server_caps_string(UINT32 flags, char* buffer, size_t size)
138{
139 char msg[32] = { 0 };
140 const UINT32 mask = RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1 | RNS_UD_SC_DYNAMIC_DST_SUPPORTED |
141 RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2 | RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED;
142 const UINT32 unknown = flags & (~mask);
143
144 if (flags & RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1)
145 winpr_str_append("RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1", buffer, size, "|");
146 if (flags & RNS_UD_SC_DYNAMIC_DST_SUPPORTED)
147 winpr_str_append("RNS_UD_SC_DYNAMIC_DST_SUPPORTED", buffer, size, "|");
148 if (flags & RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2)
149 winpr_str_append("RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2", buffer, size, "|");
150 if (flags & RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED)
151 winpr_str_append("RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED", buffer, size, "|");
152
153 if (unknown != 0)
154 {
155 (void)_snprintf(msg, sizeof(msg), "RNS_UD_SC_UNKNOWN[0x%08" PRIx32 "]", unknown);
156 winpr_str_append(msg, buffer, size, "|");
157 }
158 (void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
159 winpr_str_append(msg, buffer, size, "|");
160 return buffer;
161}
162
163static const char* rdp_early_client_caps_string(UINT32 flags, char* buffer, size_t size)
164{
165 char msg[32] = { 0 };
166 const UINT32 mask = RNS_UD_CS_SUPPORT_ERRINFO_PDU | RNS_UD_CS_WANT_32BPP_SESSION |
167 RNS_UD_CS_SUPPORT_STATUSINFO_PDU | RNS_UD_CS_STRONG_ASYMMETRIC_KEYS |
168 RNS_UD_CS_RELATIVE_MOUSE_INPUT | RNS_UD_CS_VALID_CONNECTION_TYPE |
169 RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU |
170 RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT |
171 RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL | RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE |
172 RNS_UD_CS_SUPPORT_HEARTBEAT_PDU | RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN;
173 const UINT32 unknown = flags & (~mask);
174
175 if (flags & RNS_UD_CS_SUPPORT_ERRINFO_PDU)
176 winpr_str_append("RNS_UD_CS_SUPPORT_ERRINFO_PDU", buffer, size, "|");
177 if (flags & RNS_UD_CS_WANT_32BPP_SESSION)
178 winpr_str_append("RNS_UD_CS_WANT_32BPP_SESSION", buffer, size, "|");
179 if (flags & RNS_UD_CS_SUPPORT_STATUSINFO_PDU)
180 winpr_str_append("RNS_UD_CS_SUPPORT_STATUSINFO_PDU", buffer, size, "|");
181 if (flags & RNS_UD_CS_STRONG_ASYMMETRIC_KEYS)
182 winpr_str_append("RNS_UD_CS_STRONG_ASYMMETRIC_KEYS", buffer, size, "|");
183 if (flags & RNS_UD_CS_RELATIVE_MOUSE_INPUT)
184 winpr_str_append("RNS_UD_CS_RELATIVE_MOUSE_INPUT", buffer, size, "|");
185 if (flags & RNS_UD_CS_VALID_CONNECTION_TYPE)
186 winpr_str_append("RNS_UD_CS_VALID_CONNECTION_TYPE", buffer, size, "|");
187 if (flags & RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU)
188 winpr_str_append("RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU", buffer, size, "|");
189 if (flags & RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT)
190 winpr_str_append("RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT", buffer, size, "|");
191 if (flags & RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
192 winpr_str_append("RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL", buffer, size, "|");
193 if (flags & RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE)
194 winpr_str_append("RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE", buffer, size, "|");
195 if (flags & RNS_UD_CS_SUPPORT_HEARTBEAT_PDU)
196 winpr_str_append("RNS_UD_CS_SUPPORT_HEARTBEAT_PDU", buffer, size, "|");
197 if (flags & RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN)
198 winpr_str_append("RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN", buffer, size, "|");
199
200 if (unknown != 0)
201 {
202 (void)_snprintf(msg, sizeof(msg), "RNS_UD_CS_UNKNOWN[0x%08" PRIx32 "]", unknown);
203 winpr_str_append(msg, buffer, size, "|");
204 }
205 (void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
206 winpr_str_append(msg, buffer, size, "|");
207 return buffer;
208}
209
210static DWORD rdp_version_common(wLog* log, DWORD serverVersion, DWORD clientVersion)
211{
212 DWORD version = MIN(serverVersion, clientVersion);
213
214 switch (version)
215 {
216 case RDP_VERSION_4:
217 case RDP_VERSION_5_PLUS:
218 case RDP_VERSION_10_0:
219 case RDP_VERSION_10_1:
220 case RDP_VERSION_10_2:
221 case RDP_VERSION_10_3:
222 case RDP_VERSION_10_4:
223 case RDP_VERSION_10_5:
224 case RDP_VERSION_10_6:
225 case RDP_VERSION_10_7:
226 case RDP_VERSION_10_8:
227 case RDP_VERSION_10_9:
228 case RDP_VERSION_10_10:
229 case RDP_VERSION_10_11:
230 case RDP_VERSION_10_12:
231 return version;
232
233 default:
234 WLog_Print(log, WLOG_ERROR,
235 "Invalid client [%" PRIu32 "] and server [%" PRIu32 "] versions",
236 serverVersion, clientVersion);
237 return version;
238 }
239}
240
335/*
336 * OID = 0.0.20.124.0.1
337 * { itu-t(0) recommendation(0) t(20) t124(124) version(0) 1 }
338 * v.1 of ITU-T Recommendation T.124 (Feb 1998): "Generic Conference Control"
339 */
340static const BYTE t124_02_98_oid[6] = { 0, 0, 20, 124, 0, 1 };
341
342static const BYTE h221_cs_key[4] = { 'D', 'u', 'c', 'a' };
343static const BYTE h221_sc_key[4] = { 'M', 'c', 'D', 'n' };
344
355BOOL gcc_read_conference_create_request(wStream* s, rdpMcs* mcs)
356{
357 UINT16 length = 0;
358 BYTE choice = 0;
359 BYTE number = 0;
360 BYTE selection = 0;
361
362 WINPR_ASSERT(s);
363 WINPR_ASSERT(mcs);
364 /* ConnectData */
365 if (!per_read_choice(s, &choice))
366 return FALSE;
367
368 if (!per_read_object_identifier(s, t124_02_98_oid))
369 return FALSE;
370
371 /* ConnectData::connectPDU (OCTET_STRING) */
372 if (!per_read_length(s, &length))
373 return FALSE;
374
375 /* ConnectGCCPDU */
376 if (!per_read_choice(s, &choice))
377 return FALSE;
378
379 if (!per_read_selection(s, &selection))
380 return FALSE;
381
382 /* ConferenceCreateRequest::conferenceName */
383 if (!per_read_numeric_string(s, 1)) /* ConferenceName::numeric */
384 return FALSE;
385
386 if (!per_read_padding(s, 1)) /* padding */
387 return FALSE;
388
389 /* UserData (SET OF SEQUENCE) */
390 if (!per_read_number_of_sets(s, &number) || number != 1) /* one set of UserData */
391 return FALSE;
392
393 if (!per_read_choice(s, &choice) ||
394 choice != 0xC0) /* UserData::value present + select h221NonStandard (1) */
395 return FALSE;
396
397 /* h221NonStandard */
398 if (!per_read_octet_string(s, h221_cs_key, 4,
399 4)) /* h221NonStandard, client-to-server H.221 key, "Duca" */
400 return FALSE;
401
402 /* userData::value (OCTET_STRING) */
403 if (!per_read_length(s, &length))
404 return FALSE;
405
406 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, length))
407 return FALSE;
408
409 if (!gcc_read_client_data_blocks(s, mcs, length))
410 return FALSE;
411
412 return TRUE;
413}
414
425BOOL gcc_write_conference_create_request(wStream* s, wStream* userData)
426{
427 WINPR_ASSERT(s);
428 WINPR_ASSERT(userData);
429 /* ConnectData */
430 if (!per_write_choice(s, 0)) /* From Key select object (0) of type OBJECT_IDENTIFIER */
431 return FALSE;
432 if (!per_write_object_identifier(s, t124_02_98_oid)) /* ITU-T T.124 (02/98) OBJECT_IDENTIFIER */
433 return FALSE;
434 /* ConnectData::connectPDU (OCTET_STRING) */
435 const size_t pos = Stream_GetPosition(userData);
436 WINPR_ASSERT(pos <= UINT16_MAX - 14);
437 if (!per_write_length(s, (UINT16)pos + 14)) /* connectPDU length */
438 return FALSE;
439 /* ConnectGCCPDU */
440 if (!per_write_choice(s, 0)) /* From ConnectGCCPDU select conferenceCreateRequest (0) of type
441 ConferenceCreateRequest */
442 return FALSE;
443 if (!per_write_selection(s, 0x08)) /* select optional userData from ConferenceCreateRequest */
444 return FALSE;
445 /* ConferenceCreateRequest::conferenceName */
446 if (!per_write_numeric_string(s, (BYTE*)"1", 1, 1)) /* ConferenceName::numeric */
447 return FALSE;
448 if (!per_write_padding(s, 1)) /* padding */
449 return FALSE;
450 /* UserData (SET OF SEQUENCE) */
451 if (!per_write_number_of_sets(s, 1)) /* one set of UserData */
452 return FALSE;
453 if (!per_write_choice(s, 0xC0)) /* UserData::value present + select h221NonStandard (1) */
454 return FALSE;
455 /* h221NonStandard */
456 if (!per_write_octet_string(s, h221_cs_key, 4,
457 4)) /* h221NonStandard, client-to-server H.221 key, "Duca" */
458 return FALSE;
459 /* userData::value (OCTET_STRING) */
460 const size_t upos = Stream_GetPosition(userData);
461 WINPR_ASSERT(upos <= UINT16_MAX);
462 return per_write_octet_string(s, Stream_Buffer(userData), (UINT16)upos,
463 0); /* array of client data blocks */
464}
465
466BOOL gcc_read_conference_create_response(wStream* s, rdpMcs* mcs)
467{
468 UINT16 length = 0;
469 UINT32 tag = 0;
470 UINT16 nodeID = 0;
471 BYTE result = 0;
472 BYTE choice = 0;
473 BYTE number = 0;
474 WINPR_ASSERT(s);
475 WINPR_ASSERT(mcs);
476 /* ConnectData */
477 if (!per_read_choice(s, &choice) || !per_read_object_identifier(s, t124_02_98_oid))
478 return FALSE;
479
480 /* ConnectData::connectPDU (OCTET_STRING) */
481 if (!per_read_length(s, &length))
482 return FALSE;
483
484 /* ConnectGCCPDU */
485 if (!per_read_choice(s, &choice))
486 return FALSE;
487
488 /* ConferenceCreateResponse::nodeID (UserID) */
489 if (!per_read_integer16(s, &nodeID, 1001))
490 return FALSE;
491
492 /* ConferenceCreateResponse::tag (INTEGER) */
493 if (!per_read_integer(s, &tag))
494 return FALSE;
495
496 /* ConferenceCreateResponse::result (ENUMERATED) */
497 if (!per_read_enumerated(s, &result, MCS_Result_enum_length))
498 return FALSE;
499
500 /* number of UserData sets */
501 if (!per_read_number_of_sets(s, &number))
502 return FALSE;
503
504 /* UserData::value present + select h221NonStandard (1) */
505 if (!per_read_choice(s, &choice))
506 return FALSE;
507
508 /* h221NonStandard */
509 if (!per_read_octet_string(s, h221_sc_key, 4,
510 4)) /* h221NonStandard, server-to-client H.221 key, "McDn" */
511 return FALSE;
512
513 /* userData (OCTET_STRING) */
514 if (!per_read_length(s, &length))
515 return FALSE;
516
517 if (!gcc_read_server_data_blocks(s, mcs, length))
518 {
519 WLog_Print(mcs->log, WLOG_ERROR,
520 "gcc_read_conference_create_response: gcc_read_server_data_blocks failed");
521 return FALSE;
522 }
523
524 return TRUE;
525}
526
527BOOL gcc_write_conference_create_response(wStream* s, wStream* userData)
528{
529 WINPR_ASSERT(s);
530 WINPR_ASSERT(userData);
531 /* ConnectData */
532 if (!per_write_choice(s, 0))
533 return FALSE;
534 if (!per_write_object_identifier(s, t124_02_98_oid))
535 return FALSE;
536 /* ConnectData::connectPDU (OCTET_STRING) */
537 /* This length MUST be ignored by the client according to [MS-RDPBCGR] */
538 if (!per_write_length(s, 0x2A))
539 return FALSE;
540 /* ConnectGCCPDU */
541 if (!per_write_choice(s, 0x14))
542 return FALSE;
543 /* ConferenceCreateResponse::nodeID (UserID) */
544 if (!per_write_integer16(s, 0x79F3, 1001))
545 return FALSE;
546 /* ConferenceCreateResponse::tag (INTEGER) */
547 if (!per_write_integer(s, 1))
548 return FALSE;
549 /* ConferenceCreateResponse::result (ENUMERATED) */
550 if (!per_write_enumerated(s, 0, MCS_Result_enum_length))
551 return FALSE;
552 /* number of UserData sets */
553 if (!per_write_number_of_sets(s, 1))
554 return FALSE;
555 /* UserData::value present + select h221NonStandard (1) */
556 if (!per_write_choice(s, 0xC0))
557 return FALSE;
558 /* h221NonStandard */
559 if (!per_write_octet_string(s, h221_sc_key, 4,
560 4)) /* h221NonStandard, server-to-client H.221 key, "McDn" */
561 return FALSE;
562 /* userData (OCTET_STRING) */
563 const size_t pos = Stream_GetPosition(userData);
564 WINPR_ASSERT(pos <= UINT16_MAX);
565 return per_write_octet_string(s, Stream_Buffer(userData), (UINT16)pos,
566 0); /* array of server data blocks */
567}
568
569static BOOL gcc_read_client_unused1_data(wStream* s)
570{
571 return Stream_SafeSeek(s, 2);
572}
573
574BOOL gcc_read_client_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
575{
576 WINPR_ASSERT(s);
577 WINPR_ASSERT(mcs);
578
579 BOOL gotMultitransport = FALSE;
580
581 while (length > 0)
582 {
583 wStream sbuffer = { 0 };
584 UINT16 type = 0;
585 UINT16 blockLength = 0;
586
587 if (!gcc_read_user_data_header(mcs->log, s, &type, &blockLength))
588 return FALSE;
589
590 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, (size_t)(blockLength - 4)))
591 return FALSE;
592
593 wStream* sub = Stream_StaticConstInit(&sbuffer, Stream_Pointer(s), blockLength - 4);
594 WINPR_ASSERT(sub);
595
596 Stream_Seek(s, blockLength - 4);
597
598 {
599 char buffer[64] = { 0 };
600 WLog_Print(mcs->log, WLOG_TRACE, "Processing block %s",
601 gcc_block_type_string(type, buffer, sizeof(buffer)));
602 }
603 switch (type)
604 {
605 case CS_CORE:
606 if (!gcc_read_client_core_data(sub, mcs))
607 return FALSE;
608
609 break;
610
611 case CS_SECURITY:
612 if (!gcc_read_client_security_data(sub, mcs))
613 return FALSE;
614
615 break;
616
617 case CS_NET:
618 if (!gcc_read_client_network_data(sub, mcs))
619 return FALSE;
620
621 break;
622
623 case CS_CLUSTER:
624 if (!gcc_read_client_cluster_data(sub, mcs))
625 return FALSE;
626
627 break;
628
629 case CS_MONITOR:
630 if (!gcc_read_client_monitor_data(sub, mcs))
631 return FALSE;
632
633 break;
634
635 case CS_MCS_MSGCHANNEL:
636 if (!gcc_read_client_message_channel_data(sub, mcs))
637 return FALSE;
638
639 break;
640
641 case CS_MONITOR_EX:
642 if (!gcc_read_client_monitor_extended_data(sub, mcs))
643 return FALSE;
644
645 break;
646
647 case CS_UNUSED1:
648 if (!gcc_read_client_unused1_data(sub))
649 return FALSE;
650
651 break;
652
653 case 0xC009:
654 case CS_MULTITRANSPORT:
655 gotMultitransport = TRUE;
656 if (!gcc_read_client_multitransport_channel_data(sub, mcs))
657 return FALSE;
658
659 break;
660
661 default:
662 WLog_Print(mcs->log, WLOG_ERROR, "Unknown GCC client data block: 0x%04" PRIX16 "",
663 type);
664 winpr_HexLogDump(mcs->log, WLOG_TRACE, Stream_Pointer(sub),
665 Stream_GetRemainingLength(sub));
666 break;
667 }
668
669 const size_t rem = Stream_GetRemainingLength(sub);
670 if (rem > 0)
671 {
672 char buffer[128] = { 0 };
673 const size_t total = Stream_Length(sub);
674 WLog_Print(mcs->log, WLOG_ERROR,
675 "Error parsing GCC client data block %s: Actual Offset: %" PRIuz
676 " Expected Offset: %" PRIuz,
677 gcc_block_type_string(type, buffer, sizeof(buffer)), total - rem, total);
678 }
679
680 if (blockLength > length)
681 {
682 char buffer[128] = { 0 };
683 WLog_Print(mcs->log, WLOG_ERROR,
684 "Error parsing GCC client data block %s: got blockLength 0x%04" PRIx16
685 ", but only 0x%04" PRIx16 "remaining",
686 gcc_block_type_string(type, buffer, sizeof(buffer)), blockLength, length);
687 length = 0;
688 }
689 else
690 length -= blockLength;
691 }
692
693 if (!gotMultitransport)
694 {
695 rdpSettings* settings = mcs_get_settings(mcs);
696 if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMultitransport, FALSE))
697 return FALSE;
698 if (!freerdp_settings_set_uint32(settings, FreeRDP_MultitransportFlags, 0))
699 return FALSE;
700 }
701 return TRUE;
702}
703
704BOOL gcc_write_client_data_blocks(wStream* s, const rdpMcs* mcs)
705{
706 const rdpSettings* settings = mcs_get_const_settings(mcs);
707
708 WINPR_ASSERT(s);
709 WINPR_ASSERT(settings);
710
711 if (!gcc_write_client_core_data(s, mcs) || !gcc_write_client_cluster_data(s, mcs) ||
712 !gcc_write_client_security_data(s, mcs) || !gcc_write_client_network_data(s, mcs))
713 return FALSE;
714
715 /* extended client data supported */
716
717 if (settings->NegotiationFlags & EXTENDED_CLIENT_DATA_SUPPORTED)
718 {
719 if (settings->UseMultimon && !settings->SpanMonitors)
720 {
721 if (!gcc_write_client_monitor_data(s, mcs) ||
722 !gcc_write_client_monitor_extended_data(s, mcs))
723 return FALSE;
724 }
725
726 if (!gcc_write_client_message_channel_data(s, mcs) ||
727 !gcc_write_client_multitransport_channel_data(s, mcs))
728 return FALSE;
729 }
730 else
731 {
732 if (settings->UseMultimon && !settings->SpanMonitors)
733 {
734 WLog_Print(mcs->log, WLOG_ERROR,
735 "WARNING: true multi monitor support was not advertised by server!");
736
737 if (settings->ForceMultimon)
738 {
739 WLog_Print(mcs->log, WLOG_ERROR,
740 "Sending multi monitor information anyway (may break connectivity!)");
741 if (!gcc_write_client_monitor_data(s, mcs) ||
742 !gcc_write_client_monitor_extended_data(s, mcs))
743 return FALSE;
744 }
745 else
746 {
747 WLog_Print(mcs->log, WLOG_ERROR,
748 "Use /multimon:force to force sending multi monitor information");
749 }
750 }
751 }
752 return TRUE;
753}
754
755char* gcc_block_type_string(UINT16 type, char* buffer, size_t size)
756{
757 switch (type)
758 {
759 case CS_CORE:
760 (void)_snprintf(buffer, size, "CS_CORE [0x%04" PRIx16 "]", type);
761 break;
762 case CS_SECURITY:
763 (void)_snprintf(buffer, size, "CS_SECURITY [0x%04" PRIx16 "]", type);
764 break;
765 case CS_NET:
766 (void)_snprintf(buffer, size, "CS_NET [0x%04" PRIx16 "]", type);
767 break;
768 case CS_CLUSTER:
769 (void)_snprintf(buffer, size, "CS_CLUSTER [0x%04" PRIx16 "]", type);
770 break;
771 case CS_MONITOR:
772 (void)_snprintf(buffer, size, "CS_MONITOR [0x%04" PRIx16 "]", type);
773 break;
774 case CS_MCS_MSGCHANNEL:
775 (void)_snprintf(buffer, size, "CS_MONITOR [0x%04" PRIx16 "]", type);
776 break;
777 case CS_MONITOR_EX:
778 (void)_snprintf(buffer, size, "CS_MONITOR_EX [0x%04" PRIx16 "]", type);
779 break;
780 case CS_UNUSED1:
781 (void)_snprintf(buffer, size, "CS_UNUSED1 [0x%04" PRIx16 "]", type);
782 break;
783 case CS_MULTITRANSPORT:
784 (void)_snprintf(buffer, size, "CS_MONITOR_EX [0x%04" PRIx16 "]", type);
785 break;
786 case SC_CORE:
787 (void)_snprintf(buffer, size, "SC_CORE [0x%04" PRIx16 "]", type);
788 break;
789 case SC_SECURITY:
790 (void)_snprintf(buffer, size, "SC_SECURITY [0x%04" PRIx16 "]", type);
791 break;
792 case SC_NET:
793 (void)_snprintf(buffer, size, "SC_NET [0x%04" PRIx16 "]", type);
794 break;
795 case SC_MCS_MSGCHANNEL:
796 (void)_snprintf(buffer, size, "SC_MCS_MSGCHANNEL [0x%04" PRIx16 "]", type);
797 break;
798 case SC_MULTITRANSPORT:
799 (void)_snprintf(buffer, size, "SC_MULTITRANSPORT [0x%04" PRIx16 "]", type);
800 break;
801 default:
802 (void)_snprintf(buffer, size, "UNKNOWN [0x%04" PRIx16 "]", type);
803 break;
804 }
805 return buffer;
806}
807
808BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
809{
810 UINT16 type = 0;
811 UINT16 offset = 0;
812 UINT16 blockLength = 0;
813 BYTE* holdp = NULL;
814
815 WINPR_ASSERT(s);
816 WINPR_ASSERT(mcs);
817
818 while (offset < length)
819 {
820 char buffer[64] = { 0 };
821 size_t rest = 0;
822 wStream subbuffer;
823 wStream* sub = NULL;
824
825 if (!gcc_read_user_data_header(mcs->log, s, &type, &blockLength))
826 {
827 WLog_Print(mcs->log, WLOG_ERROR,
828 "gcc_read_server_data_blocks: gcc_read_user_data_header failed");
829 return FALSE;
830 }
831 holdp = Stream_Pointer(s);
832 sub = Stream_StaticInit(&subbuffer, holdp, blockLength - 4);
833 if (!Stream_SafeSeek(s, blockLength - 4))
834 {
835 WLog_Print(mcs->log, WLOG_ERROR, "gcc_read_server_data_blocks: stream too short");
836 return FALSE;
837 }
838 offset += blockLength;
839
840 switch (type)
841 {
842 case SC_CORE:
843 if (!gcc_read_server_core_data(sub, mcs))
844 {
845 WLog_Print(mcs->log, WLOG_ERROR,
846 "gcc_read_server_data_blocks: gcc_read_server_core_data failed");
847 return FALSE;
848 }
849
850 break;
851
852 case SC_SECURITY:
853 if (!gcc_read_server_security_data(sub, mcs))
854 return FALSE;
855 break;
856
857 case SC_NET:
858 if (!gcc_read_server_network_data(sub, mcs))
859 {
860 WLog_Print(mcs->log, WLOG_ERROR,
861 "gcc_read_server_data_blocks: gcc_read_server_network_data failed");
862 return FALSE;
863 }
864
865 break;
866
867 case SC_MCS_MSGCHANNEL:
868 if (!gcc_read_server_message_channel_data(sub, mcs))
869 {
870 WLog_Print(
871 mcs->log, WLOG_ERROR,
872 "gcc_read_server_data_blocks: gcc_read_server_message_channel_data failed");
873 return FALSE;
874 }
875
876 break;
877
878 case SC_MULTITRANSPORT:
879 if (!gcc_read_server_multitransport_channel_data(sub, mcs))
880 {
881 WLog_Print(mcs->log, WLOG_ERROR,
882 "gcc_read_server_data_blocks: "
883 "gcc_read_server_multitransport_channel_data failed");
884 return FALSE;
885 }
886
887 break;
888
889 default:
890 WLog_Print(mcs->log, WLOG_ERROR, "gcc_read_server_data_blocks: ignoring type=%s",
891 gcc_block_type_string(type, buffer, sizeof(buffer)));
892 winpr_HexLogDump(mcs->log, WLOG_TRACE, Stream_Pointer(sub),
893 Stream_GetRemainingLength(sub));
894 break;
895 }
896
897 rest = Stream_GetRemainingLength(sub);
898 if (rest > 0)
899 {
900 WLog_Print(mcs->log, WLOG_WARN,
901 "gcc_read_server_data_blocks: ignoring %" PRIuz " bytes with type=%s", rest,
902 gcc_block_type_string(type, buffer, sizeof(buffer)));
903 }
904 }
905
906 return TRUE;
907}
908
909BOOL gcc_write_server_data_blocks(wStream* s, rdpMcs* mcs)
910{
911 WINPR_ASSERT(s);
912 WINPR_ASSERT(mcs);
913
914 if (!gcc_write_server_core_data(s, mcs) || /* serverCoreData */
915 !gcc_write_server_network_data(s, mcs) || /* serverNetworkData */
916 !gcc_write_server_security_data(s, mcs) || /* serverSecurityData */
917 !gcc_write_server_message_channel_data(s, mcs)) /* serverMessageChannelData */
918 return FALSE;
919
920 const rdpSettings* settings = mcs_get_const_settings(mcs);
921 WINPR_ASSERT(settings);
922
923 if (settings->SupportMultitransport && (settings->MultitransportFlags != 0))
924 /* serverMultitransportChannelData */
925 return gcc_write_server_multitransport_channel_data(s, mcs);
926
927 return TRUE;
928}
929
930BOOL gcc_read_user_data_header(wLog* log, wStream* s, UINT16* type, UINT16* length)
931{
932 WINPR_ASSERT(s);
933 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
934 return FALSE;
935
936 Stream_Read_UINT16(s, *type); /* type */
937 Stream_Read_UINT16(s, *length); /* length */
938
939 if ((*length < 4) || (!Stream_CheckAndLogRequiredLengthWLog(log, s, (size_t)(*length - 4))))
940 return FALSE;
941
942 return TRUE;
943}
944
956BOOL gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length)
957{
958
959 WINPR_ASSERT(s);
960 if (!Stream_EnsureRemainingCapacity(s, 4 + length))
961 return FALSE;
962 Stream_Write_UINT16(s, type); /* type */
963 Stream_Write_UINT16(s, length); /* length */
964 return TRUE;
965}
966
967static UINT32 filterAndLogEarlyServerCapabilityFlags(wLog* log, UINT32 flags)
968{
969 const UINT32 mask =
970 (RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1 | RNS_UD_SC_DYNAMIC_DST_SUPPORTED |
971 RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2 | RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED);
972 const UINT32 filtered = flags & mask;
973 const UINT32 unknown = flags & (~mask);
974 if (unknown != 0)
975 {
976 char buffer[256] = { 0 };
977 WLog_Print(log, WLOG_WARN,
978 "TS_UD_SC_CORE::EarlyCapabilityFlags [0x%08" PRIx32 " & 0x%08" PRIx32
979 " --> 0x%08" PRIx32 "] filtering %s, feature not implemented",
980 flags, ~mask, unknown,
981 rdp_early_server_caps_string(unknown, buffer, sizeof(buffer)));
982 }
983 return filtered;
984}
985
986static UINT32 earlyServerCapsFromSettings(wLog* log, const rdpSettings* settings)
987{
988 UINT32 EarlyCapabilityFlags = 0;
989
990 if (settings->SupportEdgeActionV1)
991 EarlyCapabilityFlags |= RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1;
992 if (settings->SupportDynamicTimeZone)
993 EarlyCapabilityFlags |= RNS_UD_SC_DYNAMIC_DST_SUPPORTED;
994 if (settings->SupportEdgeActionV2)
995 EarlyCapabilityFlags |= RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2;
996 if (settings->SupportSkipChannelJoin)
997 EarlyCapabilityFlags |= RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED;
998
999 return filterAndLogEarlyServerCapabilityFlags(log, EarlyCapabilityFlags);
1000}
1001
1002static UINT16 filterAndLogEarlyClientCapabilityFlags(wLog* log, UINT32 flags)
1003{
1004 const UINT32 mask =
1005 (RNS_UD_CS_SUPPORT_ERRINFO_PDU | RNS_UD_CS_WANT_32BPP_SESSION |
1006 RNS_UD_CS_SUPPORT_STATUSINFO_PDU | RNS_UD_CS_STRONG_ASYMMETRIC_KEYS |
1007 RNS_UD_CS_RELATIVE_MOUSE_INPUT | RNS_UD_CS_VALID_CONNECTION_TYPE |
1008 RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU | RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT |
1009 RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL | RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE |
1010 RNS_UD_CS_SUPPORT_HEARTBEAT_PDU | RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN);
1011 const UINT32 filtered = flags & mask;
1012 const UINT32 unknown = flags & ~mask;
1013 if (unknown != 0)
1014 {
1015 char buffer[256] = { 0 };
1016 WLog_Print(log, WLOG_WARN,
1017 "(TS_UD_CS_CORE)::EarlyCapabilityFlags [0x%08" PRIx32 " & 0x%08" PRIx32
1018 " --> 0x%08" PRIx32 "] filtering %s, feature not implemented",
1019 flags, ~mask, unknown,
1020 rdp_early_client_caps_string(unknown, buffer, sizeof(buffer)));
1021 }
1022
1023 WINPR_ASSERT(filtered <= UINT16_MAX);
1024 return (UINT16)filtered;
1025}
1026
1027static UINT16 earlyClientCapsFromSettings(wLog* log, const rdpSettings* settings)
1028{
1029 UINT32 earlyCapabilityFlags = 0;
1030
1031 WINPR_ASSERT(settings);
1032 if (settings->SupportErrorInfoPdu)
1033 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_ERRINFO_PDU;
1034
1035 if (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) == 32)
1036 earlyCapabilityFlags |= RNS_UD_CS_WANT_32BPP_SESSION;
1037
1038 if (settings->SupportStatusInfoPdu)
1039 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_STATUSINFO_PDU;
1040
1041 if (settings->ConnectionType)
1042 earlyCapabilityFlags |= RNS_UD_CS_VALID_CONNECTION_TYPE;
1043
1044 if (settings->SupportMonitorLayoutPdu)
1045 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU;
1046
1047 if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect))
1048 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT;
1049
1050 if (settings->SupportGraphicsPipeline)
1051 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL;
1052
1053 if (settings->SupportDynamicTimeZone)
1054 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE;
1055
1056 if (settings->SupportHeartbeatPdu)
1057 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_HEARTBEAT_PDU;
1058
1059 if (settings->SupportAsymetricKeys)
1060 earlyCapabilityFlags |= RNS_UD_CS_STRONG_ASYMMETRIC_KEYS;
1061
1062 if (settings->HasRelativeMouseEvent)
1063 earlyCapabilityFlags |= RNS_UD_CS_RELATIVE_MOUSE_INPUT;
1064
1065 if (settings->SupportSkipChannelJoin)
1066 earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN;
1067
1068 return filterAndLogEarlyClientCapabilityFlags(log, earlyCapabilityFlags);
1069}
1070
1071static BOOL updateEarlyClientCaps(wLog* log, rdpSettings* settings, UINT32 earlyCapabilityFlags,
1072 UINT32 connectionType)
1073{
1074 WINPR_ASSERT(settings);
1075
1076 if (settings->SupportErrorInfoPdu)
1077 settings->SupportErrorInfoPdu =
1078 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_ERRINFO_PDU) ? TRUE : FALSE;
1079
1080 /* RNS_UD_CS_WANT_32BPP_SESSION is already handled in gcc_read_client_core_data:
1081 *
1082 * it is evaluated in combination with highColorDepth and the server side
1083 * settings to determine the session color depth to use.
1084 */
1085
1086 if (settings->SupportStatusInfoPdu)
1087 settings->SupportStatusInfoPdu =
1088 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_STATUSINFO_PDU) ? TRUE : FALSE;
1089
1090 if (settings->SupportAsymetricKeys)
1091 settings->SupportAsymetricKeys =
1092 (earlyCapabilityFlags & RNS_UD_CS_STRONG_ASYMMETRIC_KEYS) ? TRUE : FALSE;
1093
1094 if (settings->HasRelativeMouseEvent)
1095 {
1096 /* [MS-RDPBCGR] 2.2.7.1.5 Pointer Capability Set (TS_POINTER_CAPABILITYSET)
1097 * the flag must be ignored if the RDP version is < 0x00080011 */
1098 if (settings->RdpVersion >= RDP_VERSION_10_12)
1099 {
1100 settings->HasRelativeMouseEvent =
1101 (earlyCapabilityFlags & RNS_UD_CS_RELATIVE_MOUSE_INPUT) ? TRUE : FALSE;
1102 }
1103 else
1104 settings->HasRelativeMouseEvent = FALSE;
1105 }
1106
1107 if (settings->NetworkAutoDetect)
1108 settings->NetworkAutoDetect =
1109 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT) ? TRUE : FALSE;
1110
1111 if (settings->SupportSkipChannelJoin)
1112 settings->SupportSkipChannelJoin =
1113 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN) ? TRUE : FALSE;
1114
1115 if (settings->SupportMonitorLayoutPdu)
1116 settings->SupportMonitorLayoutPdu =
1117 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU) ? TRUE : FALSE;
1118
1119 if (settings->SupportHeartbeatPdu)
1120 settings->SupportHeartbeatPdu =
1121 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_HEARTBEAT_PDU) ? TRUE : FALSE;
1122
1123 if (settings->SupportGraphicsPipeline)
1124 settings->SupportGraphicsPipeline =
1125 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL) ? TRUE : FALSE;
1126
1127 if (settings->SupportDynamicTimeZone)
1128 settings->SupportDynamicTimeZone =
1129 (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE) ? TRUE : FALSE;
1130
1131 if ((earlyCapabilityFlags & RNS_UD_CS_VALID_CONNECTION_TYPE) == 0)
1132 connectionType = 0;
1133 settings->ConnectionType = connectionType;
1134
1135 filterAndLogEarlyClientCapabilityFlags(log, earlyCapabilityFlags);
1136 return TRUE;
1137}
1138
1139static BOOL updateEarlyServerCaps(wLog* log, rdpSettings* settings, UINT32 earlyCapabilityFlags,
1140 WINPR_ATTR_UNUSED UINT32 connectionType)
1141{
1142 WINPR_ASSERT(settings);
1143
1144 settings->SupportEdgeActionV1 =
1145 settings->SupportEdgeActionV1 &&
1146 (earlyCapabilityFlags & RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1)
1147 ? TRUE
1148 : FALSE;
1149 settings->SupportDynamicTimeZone =
1150 settings->SupportDynamicTimeZone && (earlyCapabilityFlags & RNS_UD_SC_DYNAMIC_DST_SUPPORTED)
1151 ? TRUE
1152 : FALSE;
1153 settings->SupportEdgeActionV2 =
1154 settings->SupportEdgeActionV2 &&
1155 (earlyCapabilityFlags & RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2)
1156 ? TRUE
1157 : FALSE;
1158 settings->SupportSkipChannelJoin =
1159 settings->SupportSkipChannelJoin &&
1160 (earlyCapabilityFlags & RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED)
1161 ? TRUE
1162 : FALSE;
1163
1164 filterAndLogEarlyServerCapabilityFlags(log, earlyCapabilityFlags);
1165 return TRUE;
1166}
1167
1177BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs)
1178{
1179 char buffer[2048] = { 0 };
1180 char strbuffer[130] = { 0 };
1181 UINT32 version = 0;
1182 BYTE connectionType = 0;
1183 UINT32 clientColorDepth = 0;
1184 UINT16 colorDepth = 0;
1185 UINT16 postBeta2ColorDepth = 0;
1186 UINT16 highColorDepth = 0;
1187 UINT32 serverSelectedProtocol = 0;
1188 rdpSettings* settings = mcs_get_settings(mcs);
1189
1190 WINPR_ASSERT(s);
1191 WINPR_ASSERT(settings);
1192
1193 /* Length of all required fields, until imeFileName */
1194 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 128))
1195 return FALSE;
1196
1197 Stream_Read_UINT32(s, version); /* version (4 bytes) */
1198 settings->RdpVersion = rdp_version_common(mcs->log, version, settings->RdpVersion);
1199 Stream_Read_UINT16(s, settings->DesktopWidth); /* DesktopWidth (2 bytes) */
1200 Stream_Read_UINT16(s, settings->DesktopHeight); /* DesktopHeight (2 bytes) */
1201 Stream_Read_UINT16(s, colorDepth); /* ColorDepth (2 bytes) */
1202 Stream_Seek_UINT16(s); /* SASSequence (Secure Access Sequence) (2 bytes) */
1203 Stream_Read_UINT32(s, settings->KeyboardLayout); /* KeyboardLayout (4 bytes) */
1204 Stream_Read_UINT32(s, settings->ClientBuild); /* ClientBuild (4 bytes) */
1205
1206 /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
1207 if (Stream_Read_UTF16_String_As_UTF8_Buffer(s, 32 / sizeof(WCHAR), strbuffer,
1208 ARRAYSIZE(strbuffer)) < 0)
1209 {
1210 WLog_Print(mcs->log, WLOG_ERROR, "failed to convert client host name");
1211 return FALSE;
1212 }
1213
1214 if (!freerdp_settings_set_string(settings, FreeRDP_ClientHostname, strbuffer))
1215 return FALSE;
1216
1217 Stream_Read_UINT32(s, settings->KeyboardType); /* KeyboardType (4 bytes) */
1218 Stream_Read_UINT32(s, settings->KeyboardSubType); /* KeyboardSubType (4 bytes) */
1219 Stream_Read_UINT32(s, settings->KeyboardFunctionKey); /* KeyboardFunctionKey (4 bytes) */
1220 Stream_Seek(s, 64); /* imeFileName (64 bytes) */
1221
1229 do
1230 {
1231 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1232 break;
1233
1234 Stream_Read_UINT16(s, postBeta2ColorDepth); /* postBeta2ColorDepth (2 bytes) */
1235
1236 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1237 break;
1238
1239 const UINT16 clientProductId = Stream_Get_UINT16(s); /* clientProductID (2 bytes) */
1240
1241 /* [MS-RDPBCGR] 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE)::clientProductId (optional)
1242 * should be initialized to 1
1243 */
1244 if (clientProductId != 1)
1245 {
1246 WLog_Print(mcs->log, WLOG_WARN,
1247 "[MS-RDPBCGR] 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE)::clientProductId "
1248 "(optional) expected 1, got %" PRIu32,
1249 clientProductId);
1250 }
1251
1252 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1253 break;
1254
1255 const UINT32 serialNumber = Stream_Get_UINT32(s); /* serialNumber (4 bytes) */
1256
1257 /* [MS-RDPBCGR] 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE)::serialNumber (optional)
1258 * should be initialized to 0
1259 */
1260 if (serialNumber != 0)
1261 {
1262 WLog_Print(mcs->log, WLOG_WARN,
1263 "[MS-RDPBCGR] 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE)::serialNumber "
1264 "(optional) expected 0, got %" PRIu32,
1265 serialNumber);
1266 }
1267
1268 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1269 break;
1270
1271 Stream_Read_UINT16(s, highColorDepth); /* highColorDepth (2 bytes) */
1272
1273 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1274 break;
1275
1276 Stream_Read_UINT16(s, settings->SupportedColorDepths); /* supportedColorDepths (2 bytes) */
1277
1278 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1279 break;
1280
1281 Stream_Read_UINT16(s, settings->EarlyCapabilityFlags); /* earlyCapabilityFlags (2 bytes) */
1282
1283 /* clientDigProductId (64 bytes): Contains a value that uniquely identifies the client */
1284 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 64))
1285 break;
1286
1287 if (Stream_Read_UTF16_String_As_UTF8_Buffer(s, 64 / sizeof(WCHAR), strbuffer,
1288 ARRAYSIZE(strbuffer)) < 0)
1289 {
1290 WLog_Print(mcs->log, WLOG_ERROR, "failed to convert the client product identifier");
1291 return FALSE;
1292 }
1293
1294 if (!freerdp_settings_set_string(settings, FreeRDP_ClientProductId, strbuffer))
1295 return FALSE;
1296
1297 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 1))
1298 break;
1299
1300 Stream_Read_UINT8(s, connectionType); /* connectionType (1 byte) */
1301
1302 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 1))
1303 break;
1304
1305 Stream_Seek_UINT8(s); /* pad1octet (1 byte) */
1306
1307 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1308 break;
1309
1310 Stream_Read_UINT32(s, serverSelectedProtocol); /* serverSelectedProtocol (4 bytes) */
1311
1312 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1313 break;
1314
1315 Stream_Read_UINT32(s, settings->DesktopPhysicalWidth); /* desktopPhysicalWidth (4 bytes) */
1316
1317 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1318 break;
1319
1320 Stream_Read_UINT32(s,
1321 settings->DesktopPhysicalHeight); /* desktopPhysicalHeight (4 bytes) */
1322
1323 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
1324 break;
1325
1326 Stream_Read_UINT16(s, settings->DesktopOrientation); /* desktopOrientation (2 bytes) */
1327
1328 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1329 break;
1330
1331 Stream_Read_UINT32(s, settings->DesktopScaleFactor); /* desktopScaleFactor (4 bytes) */
1332
1333 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1334 break;
1335
1336 Stream_Read_UINT32(s, settings->DeviceScaleFactor); /* deviceScaleFactor (4 bytes) */
1337
1338 if (freerdp_settings_get_bool(settings, FreeRDP_TransportDumpReplay))
1339 settings->SelectedProtocol = serverSelectedProtocol;
1340 else if (settings->SelectedProtocol != serverSelectedProtocol)
1341 return FALSE;
1342 } while (0);
1343
1344 if (highColorDepth > 0)
1345 {
1346 if (settings->EarlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION)
1347 clientColorDepth = 32;
1348 else
1349 clientColorDepth = highColorDepth;
1350 }
1351 else if (postBeta2ColorDepth > 0)
1352 {
1353 switch (postBeta2ColorDepth)
1354 {
1355 case RNS_UD_COLOR_4BPP:
1356 clientColorDepth = 4;
1357 break;
1358
1359 case RNS_UD_COLOR_8BPP:
1360 clientColorDepth = 8;
1361 break;
1362
1363 case RNS_UD_COLOR_16BPP_555:
1364 clientColorDepth = 15;
1365 break;
1366
1367 case RNS_UD_COLOR_16BPP_565:
1368 clientColorDepth = 16;
1369 break;
1370
1371 case RNS_UD_COLOR_24BPP:
1372 clientColorDepth = 24;
1373 break;
1374
1375 default:
1376 return FALSE;
1377 }
1378 }
1379 else
1380 {
1381 switch (colorDepth)
1382 {
1383 case RNS_UD_COLOR_4BPP:
1384 clientColorDepth = 4;
1385 break;
1386
1387 case RNS_UD_COLOR_8BPP:
1388 clientColorDepth = 8;
1389 break;
1390
1391 default:
1392 return FALSE;
1393 }
1394 }
1395
1396 /*
1397 * If we are in server mode, accept client's color depth only if
1398 * it is smaller than ours. This is what Windows server does.
1399 */
1400 if ((clientColorDepth < freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth)) ||
1401 !settings->ServerMode)
1402 {
1403 if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, clientColorDepth))
1404 return FALSE;
1405 }
1406
1407 WLog_Print(
1408 mcs->log, WLOG_DEBUG, "Received EarlyCapabilityFlags=%s",
1409 rdp_early_client_caps_string(settings->EarlyCapabilityFlags, buffer, sizeof(buffer)));
1410
1411 return updateEarlyClientCaps(mcs->log, settings, settings->EarlyCapabilityFlags,
1412 connectionType);
1413}
1414
1424BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs)
1425{
1426 char buffer[2048] = { 0 };
1427 char dbuffer[2048] = { 0 };
1428 BYTE connectionType = 0;
1429 HIGH_COLOR_DEPTH highColorDepth = HIGH_COLOR_4BPP;
1430
1431 UINT16 earlyCapabilityFlags = 0;
1432 const rdpSettings* settings = mcs_get_const_settings(mcs);
1433
1434 WINPR_ASSERT(s);
1435 WINPR_ASSERT(settings);
1436
1437 const UINT16 SupportedColorDepths =
1438 freerdp_settings_get_uint16(settings, FreeRDP_SupportedColorDepths);
1439 const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
1440
1441 if (!gcc_write_user_data_header(s, CS_CORE, 234))
1442 return FALSE;
1443
1444 Stream_Write_UINT32(s, settings->RdpVersion); /* Version */
1445 Stream_Write_UINT16(
1446 s, WINPR_ASSERTING_INT_CAST(uint16_t, settings->DesktopWidth)); /* DesktopWidth */
1447 Stream_Write_UINT16(
1448 s, WINPR_ASSERTING_INT_CAST(uint16_t, settings->DesktopHeight)); /* DesktopHeight */
1449 Stream_Write_UINT16(s,
1450 RNS_UD_COLOR_8BPP); /* ColorDepth, ignored because of postBeta2ColorDepth */
1451 Stream_Write_UINT16(s, RNS_UD_SAS_DEL); /* SASSequence (Secure Access Sequence) */
1452 Stream_Write_UINT32(s, settings->KeyboardLayout); /* KeyboardLayout */
1453 Stream_Write_UINT32(s, settings->ClientBuild); /* ClientBuild */
1454
1455 if (!Stream_EnsureRemainingCapacity(s, 32 + 12 + 64 + 8))
1456 return FALSE;
1457
1458 /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
1459 size_t clientNameLength = 0;
1460 WCHAR* clientName = ConvertUtf8ToWCharAlloc(settings->ClientHostname, &clientNameLength);
1461 if (clientNameLength >= 16)
1462 {
1463 clientNameLength = 16;
1464 clientName[clientNameLength - 1] = 0;
1465 }
1466
1467 Stream_Write(s, clientName, (clientNameLength * 2));
1468 Stream_Zero(s, 32 - (clientNameLength * 2));
1469 free(clientName);
1470 Stream_Write_UINT32(s, settings->KeyboardType); /* KeyboardType */
1471 Stream_Write_UINT32(s, settings->KeyboardSubType); /* KeyboardSubType */
1472 Stream_Write_UINT32(s, settings->KeyboardFunctionKey); /* KeyboardFunctionKey */
1473 Stream_Zero(s, 64); /* imeFileName */
1474 Stream_Write_UINT16(s, RNS_UD_COLOR_8BPP); /* postBeta2ColorDepth */
1475 Stream_Write_UINT16(s, 1); /* clientProductID */
1476 Stream_Write_UINT32(s, 0); /* serialNumber (should be initialized to 0) */
1477 highColorDepth = ColorDepthToHighColor(ColorDepth);
1478 earlyCapabilityFlags = earlyClientCapsFromSettings(mcs->log, settings);
1479
1480 WINPR_ASSERT(settings->ConnectionType <= UINT8_MAX);
1481 connectionType = (UINT8)settings->ConnectionType;
1482
1483 if (!Stream_EnsureRemainingCapacity(s, 6))
1484 return FALSE;
1485
1486 WLog_Print(
1487 mcs->log, WLOG_DEBUG,
1488 "Sending highColorDepth=%s, supportedColorDepths=%s, earlyCapabilityFlags=%s",
1489 HighColorToString(highColorDepth),
1490 freerdp_supported_color_depths_string(SupportedColorDepths, dbuffer, sizeof(dbuffer)),
1491 rdp_early_client_caps_string(earlyCapabilityFlags, buffer, sizeof(buffer)));
1492 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, highColorDepth)); /* highColorDepth */
1493 Stream_Write_UINT16(s, SupportedColorDepths); /* supportedColorDepths */
1494 Stream_Write_UINT16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */
1495
1496 if (!Stream_EnsureRemainingCapacity(s, 64 + 24))
1497 return FALSE;
1498
1499 /* clientDigProductId (64 bytes, assume WCHAR, not \0 terminated */
1500 const char* str = freerdp_settings_get_string(settings, FreeRDP_ClientProductId);
1501 if (str)
1502 {
1503 if (Stream_Write_UTF16_String_From_UTF8(s, 32, str, strnlen(str, 32), TRUE) < 0)
1504 return FALSE;
1505 }
1506 else
1507 Stream_Zero(s, 32 * sizeof(WCHAR));
1508
1509 Stream_Write_UINT8(s, connectionType); /* connectionType */
1510 Stream_Write_UINT8(s, 0); /* pad1octet */
1511 Stream_Write_UINT32(s, settings->SelectedProtocol); /* serverSelectedProtocol */
1512 Stream_Write_UINT32(s, settings->DesktopPhysicalWidth); /* desktopPhysicalWidth */
1513 Stream_Write_UINT32(s, settings->DesktopPhysicalHeight); /* desktopPhysicalHeight */
1514 Stream_Write_UINT16(s, settings->DesktopOrientation); /* desktopOrientation */
1515 Stream_Write_UINT32(s, settings->DesktopScaleFactor); /* desktopScaleFactor */
1516 Stream_Write_UINT32(s, settings->DeviceScaleFactor); /* deviceScaleFactor */
1517 return TRUE;
1518}
1519
1520BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs)
1521{
1522 UINT32 serverVersion = 0;
1523 rdpSettings* settings = mcs_get_settings(mcs);
1524
1525 WINPR_ASSERT(s);
1526 WINPR_ASSERT(settings);
1527
1528 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1529 return FALSE;
1530
1531 Stream_Read_UINT32(s, serverVersion); /* version */
1532 settings->RdpVersion = rdp_version_common(mcs->log, serverVersion, settings->RdpVersion);
1533
1534 if (Stream_GetRemainingLength(s) >= 4)
1535 {
1536 Stream_Read_UINT32(s, settings->RequestedProtocols); /* clientRequestedProtocols */
1537 }
1538
1539 if (Stream_GetRemainingLength(s) >= 4)
1540 {
1541 char buffer[2048] = { 0 };
1542
1543 Stream_Read_UINT32(s, settings->EarlyCapabilityFlags); /* earlyCapabilityFlags */
1544 WLog_Print(
1545 mcs->log, WLOG_DEBUG, "Received EarlyCapabilityFlags=%s",
1546 rdp_early_client_caps_string(settings->EarlyCapabilityFlags, buffer, sizeof(buffer)));
1547 }
1548
1549 return updateEarlyServerCaps(mcs->log, settings, settings->EarlyCapabilityFlags,
1550 settings->ConnectionType);
1551}
1552
1553/* TODO: This function modifies rdpMcs
1554 * TODO: Split this out of this function
1555 */
1556BOOL gcc_write_server_core_data(wStream* s, rdpMcs* mcs)
1557{
1558 const rdpSettings* settings = mcs_get_const_settings(mcs);
1559
1560 WINPR_ASSERT(s);
1561 WINPR_ASSERT(settings);
1562
1563 if (!gcc_write_user_data_header(s, SC_CORE, 16))
1564 return FALSE;
1565
1566 const UINT32 EarlyCapabilityFlags = earlyServerCapsFromSettings(mcs->log, settings);
1567 Stream_Write_UINT32(s, settings->RdpVersion); /* version (4 bytes) */
1568 Stream_Write_UINT32(s, settings->RequestedProtocols); /* clientRequestedProtocols (4 bytes) */
1569 Stream_Write_UINT32(s, EarlyCapabilityFlags); /* earlyCapabilityFlags (4 bytes) */
1570 return TRUE;
1571}
1572
1582BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs)
1583{
1584 rdpSettings* settings = mcs_get_settings(mcs);
1585
1586 WINPR_ASSERT(s);
1587 WINPR_ASSERT(settings);
1588
1589 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 8))
1590 return FALSE;
1591
1592 if (settings->UseRdpSecurityLayer)
1593 {
1594 Stream_Read_UINT32(s, settings->EncryptionMethods); /* encryptionMethods */
1595
1596 if (settings->EncryptionMethods == ENCRYPTION_METHOD_NONE)
1597 Stream_Read_UINT32(s, settings->EncryptionMethods); /* extEncryptionMethods */
1598 else
1599 Stream_Seek(s, 4);
1600 }
1601 else
1602 {
1603 Stream_Seek(s, 8);
1604 }
1605
1606 return TRUE;
1607}
1608
1618BOOL gcc_write_client_security_data(wStream* s, const rdpMcs* mcs)
1619{
1620 const rdpSettings* settings = mcs_get_const_settings(mcs);
1621
1622 WINPR_ASSERT(s);
1623 WINPR_ASSERT(settings);
1624
1625 if (!gcc_write_user_data_header(s, CS_SECURITY, 12))
1626 return FALSE;
1627
1628 if (settings->UseRdpSecurityLayer)
1629 {
1630 Stream_Write_UINT32(s, settings->EncryptionMethods); /* encryptionMethods */
1631 Stream_Write_UINT32(s, 0); /* extEncryptionMethods */
1632 }
1633 else
1634 {
1635 /* French locale, disable encryption */
1636 Stream_Write_UINT32(s, 0); /* encryptionMethods */
1637 Stream_Write_UINT32(s, settings->EncryptionMethods); /* extEncryptionMethods */
1638 }
1639 return TRUE;
1640}
1641
1642BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs)
1643{
1644 BOOL validCryptoConfig = FALSE;
1645 UINT32 EncryptionMethod = 0;
1646 UINT32 EncryptionLevel = 0;
1647 rdpSettings* settings = mcs_get_settings(mcs);
1648
1649 WINPR_ASSERT(s);
1650 WINPR_ASSERT(settings);
1651
1652 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 8))
1653 return FALSE;
1654
1655 Stream_Read_UINT32(s, EncryptionMethod); /* encryptionMethod */
1656 Stream_Read_UINT32(s, EncryptionLevel); /* encryptionLevel */
1657
1658 /* Only accept valid/known encryption methods */
1659 switch (EncryptionMethod)
1660 {
1661 case ENCRYPTION_METHOD_NONE:
1662 WLog_Print(mcs->log, WLOG_DEBUG, "Server rdp encryption method: NONE");
1663 break;
1664
1665 case ENCRYPTION_METHOD_40BIT:
1666 WLog_Print(mcs->log, WLOG_DEBUG, "Server rdp encryption method: 40BIT");
1667 break;
1668
1669 case ENCRYPTION_METHOD_56BIT:
1670 WLog_Print(mcs->log, WLOG_DEBUG, "Server rdp encryption method: 56BIT");
1671 break;
1672
1673 case ENCRYPTION_METHOD_128BIT:
1674 WLog_Print(mcs->log, WLOG_DEBUG, "Server rdp encryption method: 128BIT");
1675 break;
1676
1677 case ENCRYPTION_METHOD_FIPS:
1678 WLog_Print(mcs->log, WLOG_DEBUG, "Server rdp encryption method: FIPS");
1679 break;
1680
1681 default:
1682 WLog_Print(mcs->log, WLOG_ERROR, "Received unknown encryption method %08" PRIX32 "",
1683 EncryptionMethod);
1684 return FALSE;
1685 }
1686
1687 if (settings->UseRdpSecurityLayer && !(settings->EncryptionMethods & EncryptionMethod))
1688 {
1689 WLog_Print(mcs->log, WLOG_WARN,
1690 "Server uses non-advertised encryption method 0x%08" PRIX32 "",
1691 EncryptionMethod);
1692 /* FIXME: Should we return FALSE; in this case ?? */
1693 }
1694
1695 settings->EncryptionMethods = EncryptionMethod;
1696 settings->EncryptionLevel = EncryptionLevel;
1697 /* Verify encryption level/method combinations according to MS-RDPBCGR Section 5.3.2 */
1698 switch (settings->EncryptionLevel)
1699 {
1700 case ENCRYPTION_LEVEL_NONE:
1701 if (settings->EncryptionMethods == ENCRYPTION_METHOD_NONE)
1702 {
1703 validCryptoConfig = TRUE;
1704 }
1705
1706 break;
1707
1708 case ENCRYPTION_LEVEL_FIPS:
1709 if (settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
1710 {
1711 validCryptoConfig = TRUE;
1712 }
1713
1714 break;
1715
1716 case ENCRYPTION_LEVEL_LOW:
1717 case ENCRYPTION_LEVEL_HIGH:
1718 case ENCRYPTION_LEVEL_CLIENT_COMPATIBLE:
1719 if (settings->EncryptionMethods == ENCRYPTION_METHOD_40BIT ||
1720 settings->EncryptionMethods == ENCRYPTION_METHOD_56BIT ||
1721 settings->EncryptionMethods == ENCRYPTION_METHOD_128BIT ||
1722 settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
1723 {
1724 validCryptoConfig = TRUE;
1725 }
1726
1727 break;
1728
1729 default:
1730 WLog_Print(mcs->log, WLOG_ERROR, "Received unknown encryption level 0x%08" PRIX32 "",
1731 settings->EncryptionLevel);
1732 }
1733
1734 if (!validCryptoConfig)
1735 {
1736 WLog_Print(mcs->log, WLOG_ERROR,
1737 "Received invalid cryptographic configuration (level=0x%08" PRIX32
1738 " method=0x%08" PRIX32 ")",
1739 settings->EncryptionLevel, settings->EncryptionMethods);
1740 return FALSE;
1741 }
1742
1743 if (settings->EncryptionLevel == ENCRYPTION_LEVEL_NONE)
1744 {
1745 /* serverRandomLen and serverCertLen must not be present */
1746 settings->UseRdpSecurityLayer = FALSE;
1747 return TRUE;
1748 }
1749
1750 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 8))
1751 return FALSE;
1752
1753 Stream_Read_UINT32(s, settings->ServerRandomLength); /* serverRandomLen */
1754 Stream_Read_UINT32(s, settings->ServerCertificateLength); /* serverCertLen */
1755
1756 if ((settings->ServerRandomLength == 0) || (settings->ServerCertificateLength == 0))
1757 {
1758 WLog_Print(mcs->log, WLOG_ERROR,
1759 "Invalid ServerRandom (length=%" PRIu32 ") or ServerCertificate (length=%" PRIu32
1760 ")",
1761 settings->ServerRandomLength, settings->ServerCertificateLength);
1762 return FALSE;
1763 }
1764
1765 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, settings->ServerRandomLength))
1766 return FALSE;
1767
1768 /* serverRandom */
1769 if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerRandom, NULL,
1770 settings->ServerRandomLength))
1771 goto fail;
1772
1773 Stream_Read(s, settings->ServerRandom, settings->ServerRandomLength);
1774
1775 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, settings->ServerCertificateLength))
1776 goto fail;
1777
1778 /* serverCertificate */
1779 if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerCertificate, NULL,
1780 settings->ServerCertificateLength))
1781 goto fail;
1782
1783 Stream_Read(s, settings->ServerCertificate, settings->ServerCertificateLength);
1784
1785 {
1786 const BYTE* data = settings->ServerCertificate;
1787 const uint32_t length = settings->ServerCertificateLength;
1788
1789 if (!freerdp_certificate_read_server_cert(settings->RdpServerCertificate, data, length))
1790 goto fail;
1791 }
1792 return TRUE;
1793fail:
1794 (void)freerdp_settings_set_pointer_len(settings, FreeRDP_ServerRandom, NULL, 0);
1795 (void)freerdp_settings_set_pointer_len(settings, FreeRDP_ServerCertificate, NULL, 0);
1796 return FALSE;
1797}
1798
1799static BOOL gcc_update_server_random(rdpSettings* settings)
1800{
1801 const size_t length = 32;
1802 WINPR_ASSERT(settings);
1803 if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerRandom, NULL, length))
1804 return FALSE;
1805 BYTE* data = freerdp_settings_get_pointer_writable(settings, FreeRDP_ServerRandom);
1806 if (!data)
1807 return FALSE;
1808 winpr_RAND(data, length);
1809 return TRUE;
1810}
1811
1812/* TODO: This function does manipulate data in rdpMcs
1813 * TODO: Split this out of this function
1814 */
1815BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs)
1816{
1817 if (!gcc_update_server_random(mcs_get_settings(mcs)))
1818 return FALSE;
1819
1820 const rdpSettings* settings = mcs_get_const_settings(mcs);
1821
1822 WINPR_ASSERT(s);
1823 WINPR_ASSERT(settings);
1824
1825 const size_t posHeader = Stream_GetPosition(s);
1826 if (!gcc_write_user_data_header(s, SC_SECURITY, 12))
1827 return FALSE;
1828
1829 Stream_Write_UINT32(s, settings->EncryptionMethods); /* encryptionMethod */
1830 Stream_Write_UINT32(s, settings->EncryptionLevel); /* encryptionLevel */
1831
1832 if (settings->EncryptionMethods == ENCRYPTION_METHOD_NONE)
1833 return TRUE;
1834
1835 if (!Stream_EnsureRemainingCapacity(s, sizeof(UINT32) + settings->ServerRandomLength))
1836 return FALSE;
1837 Stream_Write_UINT32(s, settings->ServerRandomLength); /* serverRandomLen */
1838 const size_t posCertLen = Stream_GetPosition(s);
1839 Stream_Seek_UINT32(s); /* serverCertLen */
1840 Stream_Write(s, settings->ServerRandom, settings->ServerRandomLength);
1841
1842 const SSIZE_T len = freerdp_certificate_write_server_cert(
1843 settings->RdpServerCertificate, CERT_TEMPORARILY_ISSUED | CERT_CHAIN_VERSION_1, s);
1844 if (len < 0)
1845 return FALSE;
1846 const size_t end = Stream_GetPosition(s);
1847
1848 WINPR_ASSERT(end >= posHeader);
1849 const size_t diff = end - posHeader;
1850 WINPR_ASSERT(diff <= UINT16_MAX);
1851 Stream_SetPosition(s, posHeader);
1852 if (!gcc_write_user_data_header(s, SC_SECURITY, (UINT16)diff))
1853 return FALSE;
1854 Stream_SetPosition(s, posCertLen);
1855 WINPR_ASSERT(len <= UINT32_MAX);
1856 Stream_Write_UINT32(s, (UINT32)len);
1857 Stream_SetPosition(s, end);
1858 return TRUE;
1859}
1860
1871BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs)
1872{
1873 WINPR_ASSERT(s);
1874 WINPR_ASSERT(mcs);
1875
1876 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1877 return FALSE;
1878
1879 Stream_Read_UINT32(s, mcs->channelCount); /* channelCount */
1880
1881 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(mcs->log, s, mcs->channelCount, 12ull))
1882 return FALSE;
1883
1884 if (mcs->channelCount > CHANNEL_MAX_COUNT)
1885 {
1886 WLog_Print(mcs->log, WLOG_ERROR, "rdpMcs::channelCount %" PRIu32 " > maximum %d",
1887 mcs->channelCount, CHANNEL_MAX_COUNT);
1888 return FALSE;
1889 }
1890
1891 /* channelDefArray */
1892 for (UINT32 i = 0; i < mcs->channelCount; i++)
1893 {
1900 rdpMcsChannel* channel = &mcs->channels[i];
1901 Stream_Read(s, channel->Name, CHANNEL_NAME_LEN + 1); /* name (8 bytes) */
1902
1903 if (!memchr(channel->Name, 0, CHANNEL_NAME_LEN + 1))
1904 {
1905 WLog_Print(
1906 mcs->log, WLOG_ERROR,
1907 "protocol violation: received a static channel name with missing null-termination");
1908 return FALSE;
1909 }
1910
1911 Stream_Read_UINT32(s, channel->options); /* options (4 bytes) */
1912 channel->ChannelId = mcs->baseChannelId++;
1913 }
1914
1915 return TRUE;
1916}
1917
1927BOOL gcc_write_client_network_data(wStream* s, const rdpMcs* mcs)
1928{
1929 WINPR_ASSERT(s);
1930 WINPR_ASSERT(mcs);
1931 if (mcs->channelCount > 0)
1932 {
1933 const size_t length = mcs->channelCount * 12 + 8;
1934 WINPR_ASSERT(length <= UINT16_MAX);
1935 if (!gcc_write_user_data_header(s, CS_NET, (UINT16)length))
1936 return FALSE;
1937 Stream_Write_UINT32(s, mcs->channelCount); /* channelCount */
1938
1939 /* channelDefArray */
1940 for (UINT32 i = 0; i < mcs->channelCount; i++)
1941 {
1942 /* CHANNEL_DEF */
1943 rdpMcsChannel* channel = &mcs->channels[i];
1944 Stream_Write(s, channel->Name, CHANNEL_NAME_LEN + 1); /* name (8 bytes) */
1945 Stream_Write_UINT32(s, channel->options); /* options (4 bytes) */
1946 }
1947 }
1948 return TRUE;
1949}
1950
1951BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs)
1952{
1953 UINT16 channelId = 0;
1954 UINT32 parsedChannelCount = 0;
1955 WINPR_ASSERT(s);
1956 WINPR_ASSERT(mcs);
1957 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
1958 return FALSE;
1959
1960 mcs->IOChannelId = Stream_Get_UINT16(s); /* MCSChannelId */
1961 const uint16_t channelCount = Stream_Get_UINT16(s); /* channelCount */
1962 parsedChannelCount = channelCount;
1963
1964 if (channelCount != mcs->channelCount)
1965 {
1966 WLog_Print(mcs->log, WLOG_ERROR, "requested %" PRIu32 " channels, got %" PRIu16 " instead",
1967 mcs->channelCount, channelCount);
1968
1969 /* we ensure that the response is not bigger than the request */
1970
1971 mcs->channelCount = channelCount;
1972 }
1973
1974 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(mcs->log, s, channelCount, 2ull))
1975 return FALSE;
1976
1977 if (mcs->channelMaxCount < parsedChannelCount)
1978 {
1979 WLog_Print(mcs->log, WLOG_ERROR,
1980 "requested %" PRIu32 " channels > channelMaxCount %" PRIu16, mcs->channelCount,
1981 mcs->channelMaxCount);
1982 return FALSE;
1983 }
1984
1985 for (UINT32 i = 0; i < parsedChannelCount; i++)
1986 {
1987 rdpMcsChannel* channel = &mcs->channels[i];
1988 Stream_Read_UINT16(s, channelId); /* channelId */
1989 channel->ChannelId = channelId;
1990 }
1991
1992 if (channelCount % 2 == 1)
1993 return Stream_SafeSeek(s, 2); /* padding */
1994
1995 return TRUE;
1996}
1997
1998BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs)
1999{
2000 WINPR_ASSERT(s);
2001 WINPR_ASSERT(mcs);
2002 const size_t payloadLen = 8 + mcs->channelCount * 2 + (mcs->channelCount % 2 == 1 ? 2 : 0);
2003
2004 WINPR_ASSERT(payloadLen <= UINT16_MAX);
2005 if (!gcc_write_user_data_header(s, SC_NET, (UINT16)payloadLen))
2006 return FALSE;
2007
2008 Stream_Write_UINT16(s, MCS_GLOBAL_CHANNEL_ID); /* MCSChannelId */
2009 Stream_Write_UINT16(s,
2010 WINPR_ASSERTING_INT_CAST(uint16_t, mcs->channelCount)); /* channelCount */
2011
2012 for (UINT32 i = 0; i < mcs->channelCount; i++)
2013 {
2014 const rdpMcsChannel* channel = &mcs->channels[i];
2015 Stream_Write_UINT16(s, channel->ChannelId);
2016 }
2017
2018 if (mcs->channelCount % 2 == 1)
2019 Stream_Write_UINT16(s, 0);
2020
2021 return TRUE;
2022}
2023
2033BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs)
2034{
2035 char buffer[128] = { 0 };
2036 UINT32 redirectedSessionId = 0;
2037 rdpSettings* settings = mcs_get_settings(mcs);
2038
2039 WINPR_ASSERT(s);
2040 WINPR_ASSERT(settings);
2041
2042 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 8))
2043 return FALSE;
2044
2045 Stream_Read_UINT32(s, settings->ClusterInfoFlags); /* flags */
2046 Stream_Read_UINT32(s, redirectedSessionId); /* redirectedSessionId */
2047
2048 WLog_Print(mcs->log, WLOG_TRACE, "read ClusterInfoFlags=%s, RedirectedSessionId=0x%08" PRIx32,
2049 rdp_cluster_info_flags_to_string(settings->ClusterInfoFlags, buffer, sizeof(buffer)),
2050 redirectedSessionId);
2051 if (settings->ClusterInfoFlags & REDIRECTED_SESSIONID_FIELD_VALID)
2052 settings->RedirectedSessionId = redirectedSessionId;
2053
2054 settings->ConsoleSession =
2055 (settings->ClusterInfoFlags & REDIRECTED_SESSIONID_FIELD_VALID) ? TRUE : FALSE;
2056 settings->RedirectSmartCards =
2057 (settings->ClusterInfoFlags & REDIRECTED_SMARTCARD) ? TRUE : FALSE;
2058
2059 if (Stream_GetRemainingLength(s) > 0)
2060 {
2061 /* The old Microsoft Mac RDP client can send a pad here */
2062 Stream_Seek(s, Stream_GetRemainingLength(s));
2063 }
2064
2065 return TRUE;
2066}
2067
2077BOOL gcc_write_client_cluster_data(wStream* s, const rdpMcs* mcs)
2078{
2079 char buffer[128] = { 0 };
2080 UINT32 flags = 0;
2081 const rdpSettings* settings = mcs_get_const_settings(mcs);
2082
2083 WINPR_ASSERT(s);
2084 WINPR_ASSERT(settings);
2085
2086 if (!gcc_write_user_data_header(s, CS_CLUSTER, 12))
2087 return FALSE;
2088 flags = settings->ClusterInfoFlags;
2089
2090 if (settings->ConsoleSession || settings->RedirectedSessionId)
2091 flags |= REDIRECTED_SESSIONID_FIELD_VALID;
2092
2093 if (settings->RedirectSmartCards && settings->SmartcardLogon)
2094 flags |= REDIRECTED_SMARTCARD;
2095
2096 if (flags & REDIRECTION_SUPPORTED)
2097 {
2098 /* REDIRECTION_VERSION6 requires multitransport enabled.
2099 * if we run without that use REDIRECTION_VERSION5 */
2100 if (freerdp_settings_get_bool(settings, FreeRDP_SupportMultitransport))
2101 flags |= (REDIRECTION_VERSION6 << 2);
2102 else
2103 flags |= (REDIRECTION_VERSION5 << 2);
2104 }
2105
2106 WLog_Print(mcs->log, WLOG_TRACE, "write ClusterInfoFlags=%s, RedirectedSessionId=0x%08" PRIx32,
2107 rdp_cluster_info_flags_to_string(flags, buffer, sizeof(buffer)),
2108 settings->RedirectedSessionId);
2109 Stream_Write_UINT32(s, flags); /* flags */
2110 Stream_Write_UINT32(s, settings->RedirectedSessionId); /* redirectedSessionID */
2111 return TRUE;
2112}
2113
2123BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs)
2124{
2125 UINT32 monitorCount = 0;
2126 rdpSettings* settings = mcs_get_settings(mcs);
2127
2128 WINPR_ASSERT(s);
2129 WINPR_ASSERT(settings);
2130
2131 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 8))
2132 return FALSE;
2133
2134 Stream_Read_UINT32(s, settings->MonitorFlags); /* flags */
2135 Stream_Read_UINT32(s, monitorCount); /* monitorCount */
2136
2137 /* 2.2.1.3.6 Client Monitor Data -
2138 * monitorCount (4 bytes): A 32-bit, unsigned integer. The number of display
2139 * monitor definitions in the monitorDefArray field (the maximum allowed is 16).
2140 */
2141 if (monitorCount > 16)
2142 {
2143 WLog_Print(mcs->log, WLOG_ERROR, "announced monitors(%" PRIu32 ") exceed the 16 limit",
2144 monitorCount);
2145 return FALSE;
2146 }
2147
2148 if (monitorCount > settings->MonitorDefArraySize)
2149 {
2150 WLog_Print(mcs->log, WLOG_ERROR,
2151 "too many announced monitors(%" PRIu32 "), clamping to %" PRIu32 "",
2152 monitorCount, settings->MonitorDefArraySize);
2153 monitorCount = settings->MonitorDefArraySize;
2154 }
2155
2156 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(mcs->log, s, monitorCount, 20))
2157 return FALSE;
2158
2159 settings->MonitorCount = monitorCount;
2160
2161 for (UINT32 index = 0; index < monitorCount; index++)
2162 {
2163 rdpMonitor* current = &settings->MonitorDefArray[index];
2164
2165 const INT32 left = Stream_Get_INT32(s); /* left */
2166 const INT32 top = Stream_Get_INT32(s); /* top */
2167 const INT32 right = Stream_Get_INT32(s); /* right */
2168 const INT32 bottom = Stream_Get_INT32(s); /* bottom */
2169 const UINT32 flags = Stream_Get_UINT32(s); /* flags */
2170
2171 if ((left > right) || (top > bottom))
2172 {
2173 WLog_Print(mcs->log, WLOG_ERROR, "rdpMonitor::rect %dx%d-%dx%d invalid", left, top,
2174 right, bottom);
2175 return FALSE;
2176 }
2177
2178 const INT64 w = 1ll * right - left;
2179 const INT64 h = 1ll * bottom - top;
2180 if ((w >= INT32_MAX) || (h >= INT32_MAX) || (w < 0) || (h < 0))
2181 {
2182 WLog_Print(mcs->log, WLOG_ERROR,
2183 "rdpMonitor::width/height %" PRId64 "/%" PRId64 " invalid", w, h);
2184 return FALSE;
2185 }
2186
2187 current->x = left;
2188 current->y = top;
2189 current->width = WINPR_ASSERTING_INT_CAST(int32_t, w + 1);
2190 current->height = WINPR_ASSERTING_INT_CAST(int32_t, h + 1);
2191 current->is_primary = (flags & MONITOR_PRIMARY) ? TRUE : FALSE;
2192 }
2193
2194 return TRUE;
2195}
2196
2206BOOL gcc_write_client_monitor_data(wStream* s, const rdpMcs* mcs)
2207{
2208 INT32 baseX = 0;
2209 INT32 baseY = 0;
2210 const rdpSettings* settings = mcs_get_const_settings(mcs);
2211
2212 WINPR_ASSERT(s);
2213 WINPR_ASSERT(settings);
2214
2215 WLog_Print(mcs->log, WLOG_DEBUG, "MonitorCount=%" PRIu32, settings->MonitorCount);
2216 if (settings->MonitorCount > 1)
2217 {
2218 const size_t len = (20 * settings->MonitorCount) + 12;
2219 WINPR_ASSERT(len <= UINT16_MAX);
2220 const UINT16 length = (UINT16)len;
2221 if (!gcc_write_user_data_header(s, CS_MONITOR, length))
2222 return FALSE;
2223 Stream_Write_UINT32(s, settings->MonitorFlags); /* flags */
2224 Stream_Write_UINT32(s, settings->MonitorCount); /* monitorCount */
2225
2226 /* first pass to get the primary monitor coordinates (it is supposed to be
2227 * in (0,0) */
2228 for (UINT32 i = 0; i < settings->MonitorCount; i++)
2229 {
2230 const rdpMonitor* current = &settings->MonitorDefArray[i];
2231 if (current->is_primary)
2232 {
2233 baseX = current->x;
2234 baseY = current->y;
2235 break;
2236 }
2237 }
2238
2239 for (UINT32 i = 0; i < settings->MonitorCount; i++)
2240 {
2241 const rdpMonitor* current = &settings->MonitorDefArray[i];
2242 const INT32 left = current->x - baseX;
2243 const INT32 top = current->y - baseY;
2244 const INT32 right = left + current->width - 1;
2245 const INT32 bottom = top + current->height - 1;
2246 const UINT32 flags = current->is_primary ? MONITOR_PRIMARY : 0;
2247 WLog_Print(mcs->log, WLOG_DEBUG,
2248 "Monitor[%" PRIu32 "]: top=%" PRId32 ", left=%" PRId32 ", bottom=%" PRId32
2249 ", right=%" PRId32 ", flags=%" PRIu32,
2250 i, top, left, bottom, right, flags);
2251 Stream_Write_INT32(s, left); /* left */
2252 Stream_Write_INT32(s, top); /* top */
2253 Stream_Write_INT32(s, right); /* right */
2254 Stream_Write_INT32(s, bottom); /* bottom */
2255 Stream_Write_UINT32(s, flags); /* flags */
2256 }
2257 }
2258 WLog_Print(mcs->log, WLOG_DEBUG, "FINISHED");
2259 return TRUE;
2260}
2261
2262BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs)
2263{
2264 UINT32 monitorCount = 0;
2265 UINT32 monitorAttributeSize = 0;
2266 rdpSettings* settings = mcs_get_settings(mcs);
2267
2268 WINPR_ASSERT(s);
2269 WINPR_ASSERT(settings);
2270
2271 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 12))
2272 return FALSE;
2273
2274 Stream_Read_UINT32(s, settings->MonitorAttributeFlags); /* flags */
2275 Stream_Read_UINT32(s, monitorAttributeSize); /* monitorAttributeSize */
2276 Stream_Read_UINT32(s, monitorCount); /* monitorCount */
2277
2278 if (monitorAttributeSize != 20)
2279 {
2280 WLog_Print(mcs->log, WLOG_ERROR,
2281 "TS_UD_CS_MONITOR_EX::monitorAttributeSize %" PRIu32 " != 20",
2282 monitorAttributeSize);
2283 return FALSE;
2284 }
2285
2286 if (!Stream_CheckAndLogRequiredCapacityOfSizeWLog(mcs->log, s, monitorCount,
2287 monitorAttributeSize))
2288 return FALSE;
2289
2290 if (settings->MonitorCount != monitorCount)
2291 {
2292 WLog_Print(mcs->log, WLOG_ERROR,
2293 "(TS_UD_CS_MONITOR_EX)::monitorCount %" PRIu32 " != expected %" PRIu32,
2294 monitorCount, settings->MonitorCount);
2295 return FALSE;
2296 }
2297
2298 settings->HasMonitorAttributes = TRUE;
2299
2300 for (UINT32 index = 0; index < monitorCount; index++)
2301 {
2302 rdpMonitor* current = &settings->MonitorDefArray[index];
2303 Stream_Read_UINT32(s, current->attributes.physicalWidth); /* physicalWidth */
2304 Stream_Read_UINT32(s, current->attributes.physicalHeight); /* physicalHeight */
2305 Stream_Read_UINT32(s, current->attributes.orientation); /* orientation */
2306 Stream_Read_UINT32(s, current->attributes.desktopScaleFactor); /* desktopScaleFactor */
2307 Stream_Read_UINT32(s, current->attributes.deviceScaleFactor); /* deviceScaleFactor */
2308 }
2309
2310 return TRUE;
2311}
2312
2313BOOL gcc_write_client_monitor_extended_data(wStream* s, const rdpMcs* mcs)
2314{
2315 const rdpSettings* settings = mcs_get_const_settings(mcs);
2316
2317 WINPR_ASSERT(s);
2318 WINPR_ASSERT(settings);
2319
2320 if (settings->HasMonitorAttributes)
2321 {
2322 const size_t length = (20 * settings->MonitorCount) + 16;
2323 WINPR_ASSERT(length <= UINT16_MAX);
2324 if (!gcc_write_user_data_header(s, CS_MONITOR_EX, (UINT16)length))
2325 return FALSE;
2326 Stream_Write_UINT32(s, settings->MonitorAttributeFlags); /* flags */
2327 Stream_Write_UINT32(s, 20); /* monitorAttributeSize */
2328 Stream_Write_UINT32(s, settings->MonitorCount); /* monitorCount */
2329
2330 for (UINT32 i = 0; i < settings->MonitorCount; i++)
2331 {
2332 const rdpMonitor* current = &settings->MonitorDefArray[i];
2333 Stream_Write_UINT32(s, current->attributes.physicalWidth); /* physicalWidth */
2334 Stream_Write_UINT32(s, current->attributes.physicalHeight); /* physicalHeight */
2335 Stream_Write_UINT32(s, current->attributes.orientation); /* orientation */
2336 Stream_Write_UINT32(s, current->attributes.desktopScaleFactor); /* desktopScaleFactor */
2337 Stream_Write_UINT32(s, current->attributes.deviceScaleFactor); /* deviceScaleFactor */
2338 }
2339 }
2340 return TRUE;
2341}
2342
2352BOOL gcc_read_client_message_channel_data(wStream* s, rdpMcs* mcs)
2353{
2354 WINPR_ASSERT(s);
2355 WINPR_ASSERT(mcs);
2356
2357 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
2358 return FALSE;
2359
2360 Stream_Read_UINT32(s, mcs->flags);
2361 mcs->messageChannelId = mcs->baseChannelId++;
2362 return TRUE;
2363}
2364
2374BOOL gcc_write_client_message_channel_data(wStream* s, const rdpMcs* mcs)
2375{
2376 const rdpSettings* settings = mcs_get_const_settings(mcs);
2377
2378 WINPR_ASSERT(s);
2379 WINPR_ASSERT(mcs);
2380 WINPR_ASSERT(settings);
2381 if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect) ||
2382 settings->SupportHeartbeatPdu || settings->SupportMultitransport)
2383 {
2384 if (!gcc_write_user_data_header(s, CS_MCS_MSGCHANNEL, 8))
2385 return FALSE;
2386 Stream_Write_UINT32(s, mcs->flags); /* flags */
2387 }
2388 return TRUE;
2389}
2390
2391BOOL gcc_read_server_message_channel_data(wStream* s, rdpMcs* mcs)
2392{
2393 UINT16 MCSChannelId = 0;
2394 WINPR_ASSERT(s);
2395 WINPR_ASSERT(mcs);
2396 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 2))
2397 return FALSE;
2398
2399 Stream_Read_UINT16(s, MCSChannelId); /* MCSChannelId */
2400 /* Save the MCS message channel id */
2401 mcs->messageChannelId = MCSChannelId;
2402 return TRUE;
2403}
2404
2405BOOL gcc_write_server_message_channel_data(wStream* s, const rdpMcs* mcs)
2406{
2407 WINPR_ASSERT(s);
2408 WINPR_ASSERT(mcs);
2409 if (mcs->messageChannelId == 0)
2410 return TRUE;
2411
2412 if (!gcc_write_user_data_header(s, SC_MCS_MSGCHANNEL, 6))
2413 return FALSE;
2414
2415 Stream_Write_UINT16(s, mcs->messageChannelId); /* mcsChannelId (2 bytes) */
2416 return TRUE;
2417}
2418
2428BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpMcs* mcs)
2429{
2430 rdpSettings* settings = mcs_get_settings(mcs);
2431
2432 WINPR_ASSERT(s);
2433 WINPR_ASSERT(settings);
2434
2435 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
2436 return FALSE;
2437
2438 UINT32 remoteFlags = 0;
2439 Stream_Read_UINT32(s, remoteFlags);
2440 settings->MultitransportFlags &= remoteFlags; /* merge local and remote flags */
2441 return TRUE;
2442}
2443
2454BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMcs* mcs)
2455{
2456 const rdpSettings* settings = mcs_get_const_settings(mcs);
2457
2458 WINPR_ASSERT(s);
2459 WINPR_ASSERT(settings);
2460 if (!gcc_write_user_data_header(s, CS_MULTITRANSPORT, 8))
2461 return FALSE;
2462 Stream_Write_UINT32(s, settings->MultitransportFlags); /* flags */
2463 return TRUE;
2464}
2465
2466BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpMcs* mcs)
2467{
2468 rdpSettings* settings = mcs_get_settings(mcs);
2469 UINT32 remoteFlags = 0;
2470
2471 WINPR_ASSERT(s);
2472 WINPR_ASSERT(settings);
2473 if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 4))
2474 return FALSE;
2475
2476 Stream_Read_UINT32(s, remoteFlags);
2477 settings->MultitransportFlags &= remoteFlags; /* merge with client setting */
2478 return TRUE;
2479}
2480
2481BOOL gcc_write_server_multitransport_channel_data(wStream* s, const rdpMcs* mcs)
2482{
2483 const rdpSettings* settings = mcs_get_const_settings(mcs);
2484
2485 WINPR_ASSERT(s);
2486 WINPR_ASSERT(settings);
2487
2488 if (!gcc_write_user_data_header(s, SC_MULTITRANSPORT, 8))
2489 return FALSE;
2490
2491 Stream_Write_UINT32(s, settings->MultitransportFlags); /* flags (4 bytes) */
2492 return TRUE;
2493}
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API const char * freerdp_supported_color_depths_string(UINT16 mask, char *buffer, size_t size)
returns a string representation of RNS_UD_XXBPP_SUPPORT values
FREERDP_API BOOL freerdp_settings_set_pointer_len(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id, const void *data, size_t len)
Set a pointer to value data.
FREERDP_API UINT16 freerdp_settings_get_uint16(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt16 id)
Returns a UINT16 settings value.
FREERDP_API void * freerdp_settings_get_pointer_writable(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a mutable pointer settings value.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.