1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * T.125 Multipoint Communication Service (MCS) Protocol
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  * Copyright 2015 Thincast Technologies GmbH
7  * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef FREERDP_LIB_CORE_MCS_H
23 #define FREERDP_LIB_CORE_MCS_H
24 
25 typedef struct rdp_mcs rdpMcs;
26 
27 #include "transport.h"
28 
29 #include <freerdp/crypto/ber.h>
30 #include <freerdp/api.h>
31 #include <freerdp/types.h>
32 
33 #include <winpr/stream.h>
34 
35 #define MCS_BASE_CHANNEL_ID 1001
36 #define MCS_GLOBAL_CHANNEL_ID 1003
37 
38 enum MCS_Result
39 {
40 	MCS_Result_successful = 0,
41 	MCS_Result_domain_merging = 1,
42 	MCS_Result_domain_not_hierarchical = 2,
43 	MCS_Result_no_such_channel = 3,
44 	MCS_Result_no_such_domain = 4,
45 	MCS_Result_no_such_user = 5,
46 	MCS_Result_not_admitted = 6,
47 	MCS_Result_other_user_id = 7,
48 	MCS_Result_parameters_unacceptable = 8,
49 	MCS_Result_token_not_available = 9,
50 	MCS_Result_token_not_possessed = 10,
51 	MCS_Result_too_many_channels = 11,
52 	MCS_Result_too_many_tokens = 12,
53 	MCS_Result_too_many_users = 13,
54 	MCS_Result_unspecified_failure = 14,
55 	MCS_Result_user_rejected = 15,
56 	MCS_Result_enum_length = 16
57 };
58 
59 enum DomainMCSPDU
60 {
61 	DomainMCSPDU_PlumbDomainIndication = 0,
62 	DomainMCSPDU_ErectDomainRequest = 1,
63 	DomainMCSPDU_MergeChannelsRequest = 2,
64 	DomainMCSPDU_MergeChannelsConfirm = 3,
65 	DomainMCSPDU_PurgeChannelsIndication = 4,
66 	DomainMCSPDU_MergeTokensRequest = 5,
67 	DomainMCSPDU_MergeTokensConfirm = 6,
68 	DomainMCSPDU_PurgeTokensIndication = 7,
69 	DomainMCSPDU_DisconnectProviderUltimatum = 8,
70 	DomainMCSPDU_RejectMCSPDUUltimatum = 9,
71 	DomainMCSPDU_AttachUserRequest = 10,
72 	DomainMCSPDU_AttachUserConfirm = 11,
73 	DomainMCSPDU_DetachUserRequest = 12,
74 	DomainMCSPDU_DetachUserIndication = 13,
75 	DomainMCSPDU_ChannelJoinRequest = 14,
76 	DomainMCSPDU_ChannelJoinConfirm = 15,
77 	DomainMCSPDU_ChannelLeaveRequest = 16,
78 	DomainMCSPDU_ChannelConveneRequest = 17,
79 	DomainMCSPDU_ChannelConveneConfirm = 18,
80 	DomainMCSPDU_ChannelDisbandRequest = 19,
81 	DomainMCSPDU_ChannelDisbandIndication = 20,
82 	DomainMCSPDU_ChannelAdmitRequest = 21,
83 	DomainMCSPDU_ChannelAdmitIndication = 22,
84 	DomainMCSPDU_ChannelExpelRequest = 23,
85 	DomainMCSPDU_ChannelExpelIndication = 24,
86 	DomainMCSPDU_SendDataRequest = 25,
87 	DomainMCSPDU_SendDataIndication = 26,
88 	DomainMCSPDU_UniformSendDataRequest = 27,
89 	DomainMCSPDU_UniformSendDataIndication = 28,
90 	DomainMCSPDU_TokenGrabRequest = 29,
91 	DomainMCSPDU_TokenGrabConfirm = 30,
92 	DomainMCSPDU_TokenInhibitRequest = 31,
93 	DomainMCSPDU_TokenInhibitConfirm = 32,
94 	DomainMCSPDU_TokenGiveRequest = 33,
95 	DomainMCSPDU_TokenGiveIndication = 34,
96 	DomainMCSPDU_TokenGiveResponse = 35,
97 	DomainMCSPDU_TokenGiveConfirm = 36,
98 	DomainMCSPDU_TokenPleaseRequest = 37,
99 	DomainMCSPDU_TokenPleaseConfirm = 38,
100 	DomainMCSPDU_TokenReleaseRequest = 39,
101 	DomainMCSPDU_TokenReleaseConfirm = 40,
102 	DomainMCSPDU_TokenTestRequest = 41,
103 	DomainMCSPDU_TokenTestConfirm = 42,
104 	DomainMCSPDU_enum_length = 43
105 };
106 
107 typedef struct
108 {
109 	UINT32 maxChannelIds;
110 	UINT32 maxUserIds;
111 	UINT32 maxTokenIds;
112 	UINT32 numPriorities;
113 	UINT32 minThroughput;
114 	UINT32 maxHeight;
115 	UINT32 maxMCSPDUsize;
116 	UINT32 protocolVersion;
117 } DomainParameters;
118 
119 struct rdp_mcs_channel
120 {
121 	char Name[8];
122 	UINT32 options;
123 	int ChannelId;
124 	BOOL joined;
125 	void* handle;
126 };
127 typedef struct rdp_mcs_channel rdpMcsChannel;
128 
129 struct rdp_mcs
130 {
131 	rdpTransport* transport;
132 	rdpSettings* settings;
133 
134 	UINT16 userId;
135 	UINT16 baseChannelId;
136 	UINT16 messageChannelId;
137 
138 	DomainParameters domainParameters;
139 	DomainParameters targetParameters;
140 	DomainParameters minimumParameters;
141 	DomainParameters maximumParameters;
142 
143 	BOOL userChannelJoined;
144 	BOOL globalChannelJoined;
145 	BOOL messageChannelJoined;
146 
147 	UINT32 channelCount;
148 	UINT32 channelMaxCount;
149 	rdpMcsChannel* channels;
150 };
151 
152 #define MCS_SEND_DATA_HEADER_MAX_LENGTH 8
153 
154 #define MCS_TYPE_CONNECT_INITIAL 0x65
155 #define MCS_TYPE_CONNECT_RESPONSE 0x66
156 
157 FREERDP_LOCAL BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s);
158 FREERDP_LOCAL BOOL mcs_send_connect_initial(rdpMcs* mcs);
159 FREERDP_LOCAL BOOL mcs_recv_connect_response(rdpMcs* mcs, wStream* s);
160 FREERDP_LOCAL BOOL mcs_send_connect_response(rdpMcs* mcs);
161 FREERDP_LOCAL BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, wStream* s);
162 FREERDP_LOCAL BOOL mcs_send_erect_domain_request(rdpMcs* mcs);
163 FREERDP_LOCAL BOOL mcs_recv_attach_user_request(rdpMcs* mcs, wStream* s);
164 FREERDP_LOCAL BOOL mcs_send_attach_user_request(rdpMcs* mcs);
165 FREERDP_LOCAL BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s);
166 FREERDP_LOCAL BOOL mcs_send_attach_user_confirm(rdpMcs* mcs);
167 FREERDP_LOCAL BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s, UINT16* channelId);
168 FREERDP_LOCAL BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId);
169 FREERDP_LOCAL BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId);
170 FREERDP_LOCAL BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channelId);
171 FREERDP_LOCAL BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs, wStream* s, int* reason);
172 FREERDP_LOCAL BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs);
173 
174 FREERDP_LOCAL void mcs_write_domain_mcspdu_header(wStream* s, enum DomainMCSPDU domainMCSPDU,
175                                                   UINT16 length, BYTE options);
176 
177 FREERDP_LOCAL BOOL mcs_client_begin(rdpMcs* mcs);
178 
179 FREERDP_LOCAL rdpMcs* mcs_new(rdpTransport* transport);
180 FREERDP_LOCAL void mcs_free(rdpMcs* mcs);
181 
182 #endif /* FREERDP_LIB_CORE_MCS_H */
183