24 #include <freerdp/config.h>
26 #include <winpr/crt.h>
27 #include <winpr/assert.h>
28 #include <freerdp/log.h>
36 #include "connection.h"
38 #define TAG FREERDP_TAG("core")
169 static const BYTE callingDomainSelector[1] =
"\x01";
170 static const BYTE calledDomainSelector[1] =
"\x01";
194 const char* mcs_domain_pdu_string(DomainMCSPDU pdu)
198 case DomainMCSPDU_PlumbDomainIndication:
199 return "DomainMCSPDU_PlumbDomainIndication";
200 case DomainMCSPDU_ErectDomainRequest:
201 return "DomainMCSPDU_ErectDomainRequest";
202 case DomainMCSPDU_MergeChannelsRequest:
203 return "DomainMCSPDU_MergeChannelsRequest";
204 case DomainMCSPDU_MergeChannelsConfirm:
205 return "DomainMCSPDU_MergeChannelsConfirm";
206 case DomainMCSPDU_PurgeChannelsIndication:
207 return "DomainMCSPDU_PurgeChannelsIndication";
208 case DomainMCSPDU_MergeTokensRequest:
209 return "DomainMCSPDU_MergeTokensRequest";
210 case DomainMCSPDU_MergeTokensConfirm:
211 return "DomainMCSPDU_MergeTokensConfirm";
212 case DomainMCSPDU_PurgeTokensIndication:
213 return "DomainMCSPDU_PurgeTokensIndication";
214 case DomainMCSPDU_DisconnectProviderUltimatum:
215 return "DomainMCSPDU_DisconnectProviderUltimatum";
216 case DomainMCSPDU_RejectMCSPDUUltimatum:
217 return "DomainMCSPDU_RejectMCSPDUUltimatum";
218 case DomainMCSPDU_AttachUserRequest:
219 return "DomainMCSPDU_AttachUserRequest";
220 case DomainMCSPDU_AttachUserConfirm:
221 return "DomainMCSPDU_AttachUserConfirm";
222 case DomainMCSPDU_DetachUserRequest:
223 return "DomainMCSPDU_DetachUserRequest";
224 case DomainMCSPDU_DetachUserIndication:
225 return "DomainMCSPDU_DetachUserIndication";
226 case DomainMCSPDU_ChannelJoinRequest:
227 return "DomainMCSPDU_ChannelJoinRequest";
228 case DomainMCSPDU_ChannelJoinConfirm:
229 return "DomainMCSPDU_ChannelJoinConfirm";
230 case DomainMCSPDU_ChannelLeaveRequest:
231 return "DomainMCSPDU_ChannelLeaveRequest";
232 case DomainMCSPDU_ChannelConveneRequest:
233 return "DomainMCSPDU_ChannelConveneRequest";
234 case DomainMCSPDU_ChannelConveneConfirm:
235 return "DomainMCSPDU_ChannelConveneConfirm";
236 case DomainMCSPDU_ChannelDisbandRequest:
237 return "DomainMCSPDU_ChannelDisbandRequest";
238 case DomainMCSPDU_ChannelDisbandIndication:
239 return "DomainMCSPDU_ChannelDisbandIndication";
240 case DomainMCSPDU_ChannelAdmitRequest:
241 return "DomainMCSPDU_ChannelAdmitRequest";
242 case DomainMCSPDU_ChannelAdmitIndication:
243 return "DomainMCSPDU_ChannelAdmitIndication";
244 case DomainMCSPDU_ChannelExpelRequest:
245 return "DomainMCSPDU_ChannelExpelRequest";
246 case DomainMCSPDU_ChannelExpelIndication:
247 return "DomainMCSPDU_ChannelExpelIndication";
248 case DomainMCSPDU_SendDataRequest:
249 return "DomainMCSPDU_SendDataRequest";
250 case DomainMCSPDU_SendDataIndication:
251 return "DomainMCSPDU_SendDataIndication";
252 case DomainMCSPDU_UniformSendDataRequest:
253 return "DomainMCSPDU_UniformSendDataRequest";
254 case DomainMCSPDU_UniformSendDataIndication:
255 return "DomainMCSPDU_UniformSendDataIndication";
256 case DomainMCSPDU_TokenGrabRequest:
257 return "DomainMCSPDU_TokenGrabRequest";
258 case DomainMCSPDU_TokenGrabConfirm:
259 return "DomainMCSPDU_TokenGrabConfirm";
260 case DomainMCSPDU_TokenInhibitRequest:
261 return "DomainMCSPDU_TokenInhibitRequest";
262 case DomainMCSPDU_TokenInhibitConfirm:
263 return "DomainMCSPDU_TokenInhibitConfirm";
264 case DomainMCSPDU_TokenGiveRequest:
265 return "DomainMCSPDU_TokenGiveRequest";
266 case DomainMCSPDU_TokenGiveIndication:
267 return "DomainMCSPDU_TokenGiveIndication";
268 case DomainMCSPDU_TokenGiveResponse:
269 return "DomainMCSPDU_TokenGiveResponse";
270 case DomainMCSPDU_TokenGiveConfirm:
271 return "DomainMCSPDU_TokenGiveConfirm";
272 case DomainMCSPDU_TokenPleaseRequest:
273 return "DomainMCSPDU_TokenPleaseRequest";
274 case DomainMCSPDU_TokenPleaseConfirm:
275 return "DomainMCSPDU_TokenPleaseConfirm";
276 case DomainMCSPDU_TokenReleaseRequest:
277 return "DomainMCSPDU_TokenReleaseRequest";
278 case DomainMCSPDU_TokenReleaseConfirm:
279 return "DomainMCSPDU_TokenReleaseConfirm";
280 case DomainMCSPDU_TokenTestRequest:
281 return "DomainMCSPDU_TokenTestRequest";
282 case DomainMCSPDU_TokenTestConfirm:
283 return "DomainMCSPDU_TokenTestConfirm";
284 case DomainMCSPDU_enum_length:
285 return "DomainMCSPDU_enum_length";
287 return "DomainMCSPDU_UNKNOWN";
296 static BOOL mcs_write_connect_initial(
wStream* s, rdpMcs* mcs,
wStream* userData);
297 static BOOL mcs_write_connect_response(
wStream* s, rdpMcs* mcs,
wStream* userData);
298 static BOOL mcs_read_domain_mcspdu_header(
wStream* s, DomainMCSPDU domainMCSPDU, UINT16* length,
299 DomainMCSPDU* actual);
301 static int mcs_initialize_client_channels(rdpMcs* mcs,
const rdpSettings* settings)
303 if (!mcs || !settings)
308 if (mcs->channelCount > mcs->channelMaxCount)
309 mcs->channelCount = mcs->channelMaxCount;
311 ZeroMemory(mcs->channels,
sizeof(rdpMcsChannel) * mcs->channelMaxCount);
313 for (UINT32 index = 0; index < mcs->channelCount; index++)
316 freerdp_settings_get_pointer_array(settings, FreeRDP_ChannelDefArray, index);
317 rdpMcsChannel* cur = &mcs->channels[index];
318 WINPR_ASSERT(defchannel);
319 CopyMemory(cur->Name, defchannel->name, CHANNEL_NAME_LEN);
320 cur->options = defchannel->options;
335 BOOL mcs_read_domain_mcspdu_header(
wStream* s, DomainMCSPDU domainMCSPDU, UINT16* length,
336 DomainMCSPDU* actual)
342 *actual = DomainMCSPDU_invalid;
345 WINPR_ASSERT(domainMCSPDU);
346 WINPR_ASSERT(length);
348 if (!tpkt_read_header(s, length))
351 if (!tpdu_read_data(s, &li, *length))
354 if (!per_read_choice(s, &choice))
357 const DomainMCSPDU MCSPDU = (choice >> 2);
361 if (domainMCSPDU != MCSPDU)
363 WLog_ERR(TAG,
"Expected MCS %s, got %s", mcs_domain_pdu_string(domainMCSPDU),
364 mcs_domain_pdu_string(MCSPDU));
378 BOOL mcs_write_domain_mcspdu_header(
wStream* s, DomainMCSPDU domainMCSPDU, UINT16 length,
382 WINPR_ASSERT((options & ~0x03) == 0);
383 WINPR_ASSERT((domainMCSPDU & ~0x3F) == 0);
385 if (!tpkt_write_header(s, length))
387 if (!tpdu_write_data(s))
389 return per_write_choice(s, (BYTE)((domainMCSPDU << 2) | options));
401 static BOOL mcs_init_domain_parameters(
DomainParameters* domainParameters, UINT32 maxChannelIds,
402 UINT32 maxUserIds, UINT32 maxTokenIds, UINT32 maxMCSPDUsize)
404 if (!domainParameters)
407 domainParameters->maxChannelIds = maxChannelIds;
408 domainParameters->maxUserIds = maxUserIds;
409 domainParameters->maxTokenIds = maxTokenIds;
410 domainParameters->maxMCSPDUsize = maxMCSPDUsize;
411 domainParameters->numPriorities = 1;
412 domainParameters->minThroughput = 0;
413 domainParameters->maxHeight = 1;
414 domainParameters->protocolVersion = 2;
428 if (!s || !domainParameters)
431 return ber_read_sequence_tag(s, &length) &&
432 ber_read_integer(s, &(domainParameters->maxChannelIds)) &&
433 ber_read_integer(s, &(domainParameters->maxUserIds)) &&
434 ber_read_integer(s, &(domainParameters->maxTokenIds)) &&
435 ber_read_integer(s, &(domainParameters->numPriorities)) &&
436 ber_read_integer(s, &(domainParameters->minThroughput)) &&
437 ber_read_integer(s, &(domainParameters->maxHeight)) &&
438 ber_read_integer(s, &(domainParameters->maxMCSPDUsize)) &&
439 ber_read_integer(s, &(domainParameters->protocolVersion));
453 if (!s || !domainParameters)
456 tmps = Stream_New(NULL, Stream_Capacity(s));
460 WLog_ERR(TAG,
"Stream_New failed!");
464 ber_write_integer(tmps, domainParameters->maxChannelIds);
465 ber_write_integer(tmps, domainParameters->maxUserIds);
466 ber_write_integer(tmps, domainParameters->maxTokenIds);
467 ber_write_integer(tmps, domainParameters->numPriorities);
468 ber_write_integer(tmps, domainParameters->minThroughput);
469 ber_write_integer(tmps, domainParameters->maxHeight);
470 ber_write_integer(tmps, domainParameters->maxMCSPDUsize);
471 ber_write_integer(tmps, domainParameters->protocolVersion);
472 length = Stream_GetPosition(tmps);
473 ber_write_sequence_tag(s, length);
474 Stream_Write(s, Stream_Buffer(tmps), length);
475 Stream_Free(tmps, TRUE);
487 WLog_INFO(TAG,
"DomainParameters {");
489 if (domainParameters)
491 WLog_INFO(TAG,
"\tmaxChannelIds:%" PRIu32
"", domainParameters->maxChannelIds);
492 WLog_INFO(TAG,
"\tmaxUserIds:%" PRIu32
"", domainParameters->maxUserIds);
493 WLog_INFO(TAG,
"\tmaxTokenIds:%" PRIu32
"", domainParameters->maxTokenIds);
494 WLog_INFO(TAG,
"\tnumPriorities:%" PRIu32
"", domainParameters->numPriorities);
495 WLog_INFO(TAG,
"\tminThroughput:%" PRIu32
"", domainParameters->minThroughput);
496 WLog_INFO(TAG,
"\tmaxHeight:%" PRIu32
"", domainParameters->maxHeight);
497 WLog_INFO(TAG,
"\tmaxMCSPDUsize:%" PRIu32
"", domainParameters->maxMCSPDUsize);
498 WLog_INFO(TAG,
"\tprotocolVersion:%" PRIu32
"", domainParameters->protocolVersion);
501 WLog_INFO(TAG,
"\tdomainParameters=%p", domainParameters);
523 if (!targetParameters || !minimumParameters || !maximumParameters || !pOutParameters)
526 if (targetParameters->maxChannelIds >= 4)
528 pOutParameters->maxChannelIds = targetParameters->maxChannelIds;
530 else if (maximumParameters->maxChannelIds >= 4)
532 pOutParameters->maxChannelIds = 4;
536 WLog_ERR(TAG,
"invalid maxChannelIds [%" PRIu32
", %" PRIu32
"]",
537 targetParameters->maxChannelIds, maximumParameters->maxChannelIds);
543 if (targetParameters->maxUserIds >= 3)
545 pOutParameters->maxUserIds = targetParameters->maxUserIds;
547 else if (maximumParameters->maxUserIds >= 3)
549 pOutParameters->maxUserIds = 3;
553 WLog_ERR(TAG,
"invalid maxUserIds [%" PRIu32
", %" PRIu32
"]", targetParameters->maxUserIds,
554 maximumParameters->maxUserIds);
559 pOutParameters->maxTokenIds = targetParameters->maxTokenIds;
563 if (minimumParameters->numPriorities <= 1)
565 pOutParameters->numPriorities = 1;
569 WLog_ERR(TAG,
"invalid numPriorities [%" PRIu32
"]", maximumParameters->numPriorities);
574 pOutParameters->minThroughput = targetParameters->minThroughput;
578 if ((targetParameters->maxHeight == 1) || (minimumParameters->maxHeight <= 1))
580 pOutParameters->maxHeight = 1;
584 WLog_ERR(TAG,
"invalid maxHeight [%" PRIu32
", %" PRIu32
"]", targetParameters->maxHeight,
585 minimumParameters->maxHeight);
591 if (targetParameters->maxMCSPDUsize >= 1024)
593 if (targetParameters->maxMCSPDUsize <= 65528)
595 pOutParameters->maxMCSPDUsize = targetParameters->maxMCSPDUsize;
597 else if ((minimumParameters->maxMCSPDUsize >= 124) &&
598 (minimumParameters->maxMCSPDUsize <= 65528))
600 pOutParameters->maxMCSPDUsize = 65528;
604 WLog_ERR(TAG,
"invalid maxMCSPDUsize [%" PRIu32
", %" PRIu32
"]",
605 targetParameters->maxMCSPDUsize, minimumParameters->maxMCSPDUsize);
611 if (maximumParameters->maxMCSPDUsize >= 124)
613 pOutParameters->maxMCSPDUsize = maximumParameters->maxMCSPDUsize;
617 WLog_ERR(TAG,
"invalid maxMCSPDUsize [%" PRIu32
"]", maximumParameters->maxMCSPDUsize);
624 if ((targetParameters->protocolVersion == 2) ||
625 ((minimumParameters->protocolVersion <= 2) && (maximumParameters->protocolVersion >= 2)))
627 pOutParameters->protocolVersion = 2;
631 WLog_ERR(TAG,
"invalid protocolVersion [%" PRIu32
", %" PRIu32
", %" PRIu32
"]",
632 targetParameters->protocolVersion, minimumParameters->protocolVersion,
633 maximumParameters->protocolVersion);
647 BOOL mcs_recv_connect_initial(rdpMcs* mcs,
wStream* s)
651 BOOL upwardFlag = FALSE;
657 if (!tpkt_read_header(s, &tlength))
660 if (!tpdu_read_data(s, &li, tlength))
663 if (!ber_read_application_tag(s, MCS_TYPE_CONNECT_INITIAL, &length))
667 if (!ber_read_octet_string_tag(s, &length) ||
668 (!Stream_CheckAndLogRequiredLength(TAG, s, length)))
671 Stream_Seek(s, length);
674 if (!ber_read_octet_string_tag(s, &length) ||
675 (!Stream_CheckAndLogRequiredLength(TAG, s, length)))
678 Stream_Seek(s, length);
681 if (!ber_read_BOOL(s, &upwardFlag))
685 if (!mcs_read_domain_parameters(s, &mcs->targetParameters))
689 if (!mcs_read_domain_parameters(s, &mcs->minimumParameters))
693 if (!mcs_read_domain_parameters(s, &mcs->maximumParameters))
696 if (!ber_read_octet_string_tag(s, &length) ||
697 (!Stream_CheckAndLogRequiredLength(TAG, s, length)))
700 if (!gcc_read_conference_create_request(s, mcs))
703 if (!mcs_merge_domain_parameters(&mcs->targetParameters, &mcs->minimumParameters,
704 &mcs->maximumParameters, &mcs->domainParameters))
707 return tpkt_ensure_stream_consumed(s, tlength);
718 BOOL mcs_write_connect_initial(
wStream* s, rdpMcs* mcs,
wStream* userData)
724 if (!s || !mcs || !userData)
727 tmps = Stream_New(NULL, Stream_Capacity(s));
731 WLog_ERR(TAG,
"Stream_New failed!");
736 ber_write_octet_string(tmps, callingDomainSelector,
sizeof(callingDomainSelector));
738 ber_write_octet_string(tmps, calledDomainSelector,
sizeof(calledDomainSelector));
740 ber_write_BOOL(tmps, TRUE);
743 if (!mcs_write_domain_parameters(tmps, &mcs->targetParameters))
747 if (!mcs_write_domain_parameters(tmps, &mcs->minimumParameters))
751 if (!mcs_write_domain_parameters(tmps, &mcs->maximumParameters))
755 ber_write_octet_string(tmps, Stream_Buffer(userData), Stream_GetPosition(userData));
756 length = Stream_GetPosition(tmps);
758 ber_write_application_tag(s, MCS_TYPE_CONNECT_INITIAL, length);
759 Stream_Write(s, Stream_Buffer(tmps), length);
762 Stream_Free(tmps, TRUE);
776 BOOL mcs_write_connect_response(
wStream* s, rdpMcs* mcs,
wStream* userData)
782 if (!s || !mcs || !userData)
785 tmps = Stream_New(NULL, Stream_Capacity(s));
789 WLog_ERR(TAG,
"Stream_New failed!");
793 ber_write_enumerated(tmps, 0, MCS_Result_enum_length);
794 ber_write_integer(tmps, 0);
796 if (!mcs_write_domain_parameters(tmps, &(mcs->domainParameters)))
800 ber_write_octet_string(tmps, Stream_Buffer(userData), Stream_GetPosition(userData));
801 length = Stream_GetPosition(tmps);
802 ber_write_application_tag(s, MCS_TYPE_CONNECT_RESPONSE, length);
803 Stream_Write(s, Stream_Buffer(tmps), length);
806 Stream_Free(tmps, TRUE);
816 static BOOL mcs_send_connect_initial(rdpMcs* mcs)
825 rdpContext* context = NULL;
830 context = transport_get_context(mcs->transport);
831 WINPR_ASSERT(context);
833 mcs_initialize_client_channels(mcs, context->settings);
834 client_data = Stream_New(NULL, 512);
838 WLog_ERR(TAG,
"Stream_New failed!");
842 if (!gcc_write_client_data_blocks(client_data, mcs))
844 gcc_CCrq = Stream_New(NULL, 1024);
848 WLog_ERR(TAG,
"Stream_New failed!");
852 if (!gcc_write_conference_create_request(gcc_CCrq, client_data))
854 length = Stream_GetPosition(gcc_CCrq) + 7;
855 s = Stream_New(NULL, 1024 + length);
859 WLog_ERR(TAG,
"Stream_New failed!");
863 bm = Stream_GetPosition(s);
866 if (!mcs_write_connect_initial(s, mcs, gcc_CCrq))
868 WLog_ERR(TAG,
"mcs_write_connect_initial failed!");
872 em = Stream_GetPosition(s);
874 if (length > UINT16_MAX)
876 Stream_SetPosition(s, bm);
877 if (!tpkt_write_header(s, (UINT16)length))
879 if (!tpdu_write_data(s))
881 Stream_SetPosition(s, em);
882 Stream_SealLength(s);
883 status = transport_write(mcs->transport, s);
885 Stream_Free(s, TRUE);
886 Stream_Free(gcc_CCrq, TRUE);
887 Stream_Free(client_data, TRUE);
888 return (status < 0 ? FALSE : TRUE);
897 BOOL mcs_recv_connect_response(rdpMcs* mcs,
wStream* s)
903 UINT32 calledConnectId = 0;
908 if (!tpkt_read_header(s, &tlength))
911 if (!tpdu_read_data(s, &li, tlength))
914 if (!ber_read_application_tag(s, MCS_TYPE_CONNECT_RESPONSE, &length) ||
915 !ber_read_enumerated(s, &result, MCS_Result_enum_length) ||
916 !ber_read_integer(s, &calledConnectId) ||
917 !mcs_read_domain_parameters(s, &(mcs->domainParameters)) ||
918 !ber_read_octet_string_tag(s, &length))
923 if (!gcc_read_conference_create_response(s, mcs))
925 WLog_ERR(TAG,
"gcc_read_conference_create_response failed");
929 return tpkt_ensure_stream_consumed(s, tlength);
938 BOOL mcs_send_connect_response(rdpMcs* mcs)
951 server_data = Stream_New(NULL, 512);
955 WLog_ERR(TAG,
"Stream_New failed!");
959 if (!gcc_write_server_data_blocks(server_data, mcs))
962 gcc_CCrsp = Stream_New(NULL, 512 + Stream_Capacity(server_data));
966 WLog_ERR(TAG,
"Stream_New failed!");
970 if (!gcc_write_conference_create_response(gcc_CCrsp, server_data))
972 length = Stream_GetPosition(gcc_CCrsp) + 7;
973 s = Stream_New(NULL, length + 1024);
977 WLog_ERR(TAG,
"Stream_New failed!");
981 bm = Stream_GetPosition(s);
984 if (!mcs_write_connect_response(s, mcs, gcc_CCrsp))
987 em = Stream_GetPosition(s);
989 if (length > UINT16_MAX)
991 Stream_SetPosition(s, bm);
992 if (!tpkt_write_header(s, (UINT16)length))
994 if (!tpdu_write_data(s))
996 Stream_SetPosition(s, em);
997 Stream_SealLength(s);
998 status = transport_write(mcs->transport, s);
1000 Stream_Free(s, TRUE);
1001 Stream_Free(gcc_CCrsp, TRUE);
1002 Stream_Free(server_data, TRUE);
1003 return (status < 0) ? FALSE : TRUE;
1013 BOOL mcs_recv_erect_domain_request(rdpMcs* mcs,
wStream* s)
1016 UINT32 subHeight = 0;
1017 UINT32 subInterval = 0;
1022 if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_ErectDomainRequest, &length, NULL))
1025 if (!per_read_integer(s, &subHeight))
1028 if (!per_read_integer(s, &subInterval))
1031 return tpkt_ensure_stream_consumed(s, length);
1040 BOOL mcs_send_erect_domain_request(rdpMcs* mcs)
1049 s = Stream_New(NULL, length);
1053 WLog_ERR(TAG,
"Stream_New failed!");
1057 mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ErectDomainRequest, length, 0);
1058 per_write_integer(s, 0);
1059 per_write_integer(s, 0);
1060 Stream_SealLength(s);
1061 status = transport_write(mcs->transport, s);
1062 Stream_Free(s, TRUE);
1063 return (status < 0) ? FALSE : TRUE;
1073 BOOL mcs_recv_attach_user_request(rdpMcs* mcs,
wStream* s)
1080 if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_AttachUserRequest, &length, NULL))
1082 return tpkt_ensure_stream_consumed(s, length);
1091 BOOL mcs_send_attach_user_request(rdpMcs* mcs)
1100 s = Stream_New(NULL, length);
1104 WLog_ERR(TAG,
"Stream_New failed!");
1108 mcs_write_domain_mcspdu_header(s, DomainMCSPDU_AttachUserRequest, length, 0);
1109 Stream_SealLength(s);
1110 status = transport_write(mcs->transport, s);
1111 Stream_Free(s, TRUE);
1112 return (status < 0) ? FALSE : TRUE;
1121 BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs,
wStream* s)
1129 if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_AttachUserConfirm, &length, NULL))
1131 if (!per_read_enumerated(s, &result, MCS_Result_enum_length))
1133 if (!per_read_integer16(s, &(mcs->userId), MCS_BASE_CHANNEL_ID))
1135 return tpkt_ensure_stream_consumed(s, length);
1144 BOOL mcs_send_attach_user_confirm(rdpMcs* mcs)
1153 s = Stream_New(NULL, length);
1157 WLog_ERR(TAG,
"Stream_New failed!");
1161 mcs->userId = mcs->baseChannelId++;
1162 mcs_write_domain_mcspdu_header(s, DomainMCSPDU_AttachUserConfirm, length, 2);
1163 per_write_enumerated(s, 0, MCS_Result_enum_length);
1164 per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID);
1165 Stream_SealLength(s);
1166 status = transport_write(mcs->transport, s);
1167 Stream_Free(s, TRUE);
1168 return (status < 0) ? FALSE : TRUE;
1178 BOOL mcs_recv_channel_join_request(rdpMcs* mcs,
const rdpSettings* settings,
wStream* s,
1184 if (!mcs || !s || !channelId)
1187 if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinRequest, &length, NULL))
1190 if (!per_read_integer16(s, &userId, MCS_BASE_CHANNEL_ID))
1192 if (userId != mcs->userId)
1195 mcs->userId = userId;
1199 if (!per_read_integer16(s, channelId, 0))
1202 return tpkt_ensure_stream_consumed(s, length);
1215 BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId)
1223 s = Stream_New(NULL, length);
1227 WLog_ERR(TAG,
"Stream_New failed!");
1231 mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinRequest, length, 0);
1232 per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID);
1233 per_write_integer16(s, channelId, 0);
1234 Stream_SealLength(s);
1235 status = transport_write(mcs->transport, s);
1236 Stream_Free(s, TRUE);
1237 return (status < 0) ? FALSE : TRUE;
1246 BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs,
wStream* s, UINT16* channelId)
1250 UINT16 initiator = 0;
1251 UINT16 requested = 0;
1254 WINPR_ASSERT(channelId);
1256 if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinConfirm, &length, NULL))
1259 if (!per_read_enumerated(s, &result, MCS_Result_enum_length))
1261 if (!per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID))
1263 if (!per_read_integer16(s, &requested, 0))
1265 if (!per_read_integer16(s, channelId, 0))
1267 return tpkt_ensure_stream_consumed(s, length);
1276 BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channelId)
1285 s = Stream_New(NULL, length);
1289 WLog_ERR(TAG,
"Stream_New failed!");
1293 if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinConfirm, length, 2))
1295 if (!per_write_enumerated(s, 0, MCS_Result_enum_length))
1297 if (!per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID))
1299 if (!per_write_integer16(s, channelId, 0))
1301 if (!per_write_integer16(s, channelId, 0))
1303 Stream_SealLength(s);
1304 status = transport_write(mcs->transport, s);
1306 Stream_Free(s, TRUE);
1307 return (status < 0) ? FALSE : TRUE;
1315 BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs,
wStream* s,
int* reason)
1322 WINPR_ASSERT(reason);
1351 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
1354 Stream_Rewind_UINT8(s);
1355 Stream_Read_UINT8(s, b1);
1356 Stream_Read_UINT8(s, b2);
1357 *reason = ((b1 & 0x01) << 1) | (b2 >> 7);
1366 BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs)
1374 s = Stream_New(NULL, length);
1379 if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_DisconnectProviderUltimatum, length, 1))
1382 if (!per_write_enumerated(s, 0x80, 0))
1384 status = transport_write(mcs->transport, s);
1386 Stream_Free(s, TRUE);
1387 return (status < 0) ? FALSE : TRUE;
1390 BOOL mcs_client_begin(rdpMcs* mcs)
1392 rdpContext* context = NULL;
1394 if (!mcs || !mcs->transport)
1397 context = transport_get_context(mcs->transport);
1403 if (!mcs_send_connect_initial(mcs))
1405 freerdp_set_last_error_if_not(context, FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR);
1407 WLog_ERR(TAG,
"Error: unable to send MCS Connect Initial");
1420 rdpMcs* mcs_new(rdpTransport* transport)
1424 mcs = (rdpMcs*)calloc(1,
sizeof(rdpMcs));
1429 mcs->transport = transport;
1430 mcs_init_domain_parameters(&mcs->targetParameters, 34, 2, 0, 0xFFFF);
1431 mcs_init_domain_parameters(&mcs->minimumParameters, 1, 1, 1, 0x420);
1432 mcs_init_domain_parameters(&mcs->maximumParameters, 0xFFFF, 0xFC17, 0xFFFF, 0xFFFF);
1433 mcs_init_domain_parameters(&mcs->domainParameters, 0, 0, 0, 0xFFFF);
1434 mcs->channelCount = 0;
1435 mcs->channelMaxCount = CHANNEL_MAX_COUNT;
1436 mcs->baseChannelId = MCS_GLOBAL_CHANNEL_ID + 1;
1437 mcs->channels = (rdpMcsChannel*)calloc(mcs->channelMaxCount,
sizeof(rdpMcsChannel));
1453 void mcs_free(rdpMcs* mcs)
1457 free(mcs->channels);
1462 BOOL mcs_server_apply_to_settings(
const rdpMcs* mcs, rdpSettings* settings)
1467 WINPR_ASSERT(settings);
1472 for (UINT32 x = 0; x < mcs->channelCount; x++)
1474 const rdpMcsChannel* current = &mcs->channels[x];
1476 def.options = current->options;
1477 memcpy(def.name, current->Name,
sizeof(def.name));
1478 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_ChannelDefArray, x, &def))
1485 WLog_WARN(TAG,
"failed to apply settings");
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_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.