21 #ifndef FREERDP_LIB_CORE_RDP_H
22 #define FREERDP_LIB_CORE_RDP_H
24 #include <winpr/json.h>
25 #include <freerdp/config.h>
31 #include "../codec/bulk.h"
39 #include "autodetect.h"
40 #include "heartbeat.h"
41 #include "multitransport.h"
43 #include "transport.h"
44 #include "connection.h"
45 #include "redirection.h"
46 #include "capabilities.h"
49 #include <freerdp/freerdp.h>
50 #include <freerdp/settings.h>
51 #include <freerdp/log.h>
52 #include <freerdp/api.h>
54 #include <winpr/stream.h>
55 #include <winpr/crypto.h>
58 #define SEC_EXCHANGE_PKT 0x0001
59 #define SEC_TRANSPORT_REQ 0x0002
60 #define SEC_TRANSPORT_RSP 0x0004
61 #define SEC_ENCRYPT 0x0008
62 #define SEC_RESET_SEQNO 0x0010
63 #define SEC_IGNORE_SEQNO 0x0020
64 #define SEC_INFO_PKT 0x0040
65 #define SEC_LICENSE_PKT 0x0080
66 #define SEC_LICENSE_ENCRYPT_CS 0x0200
67 #define SEC_LICENSE_ENCRYPT_SC 0x0200
68 #define SEC_REDIRECTION_PKT 0x0400
69 #define SEC_SECURE_CHECKSUM 0x0800
70 #define SEC_AUTODETECT_REQ 0x1000
71 #define SEC_AUTODETECT_RSP 0x2000
72 #define SEC_HEARTBEAT 0x4000
73 #define SEC_FLAGSHI_VALID 0x8000
75 #define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
76 #define SEC_PKT_SC_MASK (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
77 #define SEC_PKT_MASK (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
79 #define RDP_SECURITY_HEADER_LENGTH 4
80 #define RDP_SHARE_CONTROL_HEADER_LENGTH 6
81 #define RDP_SHARE_DATA_HEADER_LENGTH 12
82 #define RDP_PACKET_HEADER_MAX_LENGTH (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_MAX_LENGTH)
84 #define PDU_TYPE_DEMAND_ACTIVE 0x1
85 #define PDU_TYPE_CONFIRM_ACTIVE 0x3
86 #define PDU_TYPE_DEACTIVATE_ALL 0x6
87 #define PDU_TYPE_DATA 0x7
88 #define PDU_TYPE_SERVER_REDIRECTION 0xA
90 #define PDU_TYPE_FLOW_TEST 0x41
91 #define PDU_TYPE_FLOW_RESPONSE 0x42
92 #define PDU_TYPE_FLOW_STOP 0x43
96 FINALIZE_SC_SYNCHRONIZE_PDU = 0x01,
97 FINALIZE_SC_CONTROL_COOPERATE_PDU = 0x02,
98 FINALIZE_SC_CONTROL_GRANTED_PDU = 0x04,
99 FINALIZE_SC_FONT_MAP_PDU = 0x08,
101 FINALIZE_CS_SYNCHRONIZE_PDU = 0x10,
102 FINALIZE_CS_CONTROL_COOPERATE_PDU = 0x20,
103 FINALIZE_CS_CONTROL_REQUEST_PDU = 0x40,
104 FINALIZE_CS_PERSISTENT_KEY_LIST_PDU = 0x80,
105 FINALIZE_CS_FONT_LIST_PDU = 0x100,
107 FINALIZE_DEACTIVATE_REACTIVATE = 0x200
108 } rdpFinalizePduType;
113 DATA_PDU_TYPE_UPDATE = 0x02,
114 DATA_PDU_TYPE_CONTROL = 0x14,
115 DATA_PDU_TYPE_POINTER = 0x1B,
116 DATA_PDU_TYPE_INPUT = 0x1C,
117 DATA_PDU_TYPE_SYNCHRONIZE = 0x1F,
118 DATA_PDU_TYPE_REFRESH_RECT = 0x21,
119 DATA_PDU_TYPE_PLAY_SOUND = 0x22,
120 DATA_PDU_TYPE_SUPPRESS_OUTPUT = 0x23,
121 DATA_PDU_TYPE_SHUTDOWN_REQUEST = 0x24,
122 DATA_PDU_TYPE_SHUTDOWN_DENIED = 0x25,
123 DATA_PDU_TYPE_SAVE_SESSION_INFO = 0x26,
124 DATA_PDU_TYPE_FONT_LIST = 0x27,
125 DATA_PDU_TYPE_FONT_MAP = 0x28,
126 DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS = 0x29,
127 DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST = 0x2B,
128 DATA_PDU_TYPE_BITMAP_CACHE_ERROR = 0x2C,
129 DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS = 0x2D,
130 DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR = 0x2E,
131 DATA_PDU_TYPE_SET_ERROR_INFO = 0x2F,
132 DATA_PDU_TYPE_DRAW_NINEGRID_ERROR = 0x30,
133 DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR = 0x31,
134 DATA_PDU_TYPE_ARC_STATUS = 0x32,
135 DATA_PDU_TYPE_STATUS_INFO = 0x36,
136 DATA_PDU_TYPE_MONITOR_LAYOUT = 0x37,
137 DATA_PDU_TYPE_FRAME_ACKNOWLEDGE = 0x38
141 #define STREAM_UNDEFINED 0x00
142 #define STREAM_LOW 0x01
143 #define STREAM_MED 0x02
144 #define STREAM_HI 0x04
148 CONNECTION_STATE state;
157 rdpFastPath* fastpath;
159 rdpRedirection* redirection;
160 rdpSettings* settings;
161 rdpSettings* originalSettings;
162 rdpSettings* remoteSettings;
163 rdpTransport* transport;
164 rdpAutoDetect* autodetect;
165 rdpHeartbeat* heartbeat;
166 rdpMultitransport* multitransport;
167 WINPR_RC4_CTX* rc4_decrypt_key;
168 UINT32 decrypt_use_count;
169 UINT32 decrypt_checksum_use_count;
170 WINPR_RC4_CTX* rc4_encrypt_key;
171 UINT32 encrypt_use_count;
172 UINT32 encrypt_checksum_use_count;
173 WINPR_CIPHER_CTX* fips_encrypt;
174 WINPR_CIPHER_CTX* fips_decrypt;
177 BOOL do_crypt_license;
178 BOOL do_secure_checksum;
180 BYTE decrypt_key[16];
181 BYTE encrypt_key[16];
182 BYTE decrypt_update_key[16];
183 BYTE encrypt_update_key[16];
185 BYTE fips_sign_key[20];
186 BYTE fips_encrypt_key[24];
187 BYTE fips_decrypt_key[24];
189 UINT32 finalize_sc_pdus;
203 BOOL monitor_layout_pdu;
204 BOOL was_deactivated;
205 UINT32 deactivated_width;
206 UINT32 deactivated_height;
209 char log_context[64];
210 WINPR_JSON* wellknown;
213 FREERDP_LOCAL BOOL rdp_read_security_header(rdpRdp* rdp,
wStream* s, UINT16* flags, UINT16* length);
214 FREERDP_LOCAL BOOL rdp_write_security_header(rdpRdp* rdp,
wStream* s, UINT16 flags);
216 FREERDP_LOCAL BOOL rdp_read_share_control_header(rdpRdp* rdp,
wStream* s, UINT16* tpktLength,
217 UINT16* remainingLength, UINT16* type,
220 FREERDP_LOCAL BOOL rdp_read_share_data_header(rdpRdp* rdp,
wStream* s, UINT16* length, BYTE* type,
221 UINT32* share_id, BYTE* compressed_type,
222 UINT16* compressed_len);
224 FREERDP_LOCAL
wStream* rdp_send_stream_init(rdpRdp* rdp);
225 FREERDP_LOCAL
wStream* rdp_send_stream_pdu_init(rdpRdp* rdp);
227 FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp,
wStream* s, UINT16* length, UINT16* channel_id);
228 FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp,
wStream* s,
size_t length, UINT16 channel_id);
230 FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp,
wStream* s, UINT16 type, UINT16 channel_id);
232 FREERDP_LOCAL
wStream* rdp_data_pdu_init(rdpRdp* rdp);
233 FREERDP_LOCAL BOOL rdp_send_data_pdu(rdpRdp* rdp,
wStream* s, BYTE type, UINT16 channel_id);
234 FREERDP_LOCAL state_run_t rdp_recv_data_pdu(rdpRdp* rdp,
wStream* s);
236 FREERDP_LOCAL BOOL rdp_send(rdpRdp* rdp,
wStream* s, UINT16 channelId);
238 FREERDP_LOCAL BOOL rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId,
const BYTE* data,
240 FREERDP_LOCAL BOOL rdp_channel_send_packet(rdpRdp* rdp, UINT16 channelId,
size_t totalSize,
241 UINT32 flags,
const BYTE* data,
size_t chunkSize);
243 FREERDP_LOCAL
wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
244 FREERDP_LOCAL BOOL rdp_send_message_channel_pdu(rdpRdp* rdp,
wStream* s, UINT16 sec_flags);
245 FREERDP_LOCAL state_run_t rdp_recv_message_channel_pdu(rdpRdp* rdp,
wStream* s,
246 UINT16 securityFlags);
248 FREERDP_LOCAL state_run_t rdp_recv_out_of_sequence_pdu(rdpRdp* rdp,
wStream* s, UINT16 pduType,
251 FREERDP_LOCAL state_run_t rdp_recv_callback(rdpTransport* transport,
wStream* s,
void* extra);
253 FREERDP_LOCAL
int rdp_check_fds(rdpRdp* rdp);
255 FREERDP_LOCAL
void rdp_free(rdpRdp* rdp);
257 WINPR_ATTR_MALLOC(rdp_free, 1)
258 FREERDP_LOCAL rdpRdp* rdp_new(rdpContext* context);
259 FREERDP_LOCAL BOOL rdp_reset(rdpRdp* rdp);
261 FREERDP_LOCAL BOOL rdp_io_callback_set_event(rdpRdp* rdp, BOOL reset);
263 FREERDP_LOCAL const rdpTransportIo* rdp_get_io_callbacks(rdpRdp* rdp);
264 FREERDP_LOCAL BOOL rdp_set_io_callbacks(rdpRdp* rdp, const rdpTransportIo* io_callbacks);
266 FREERDP_LOCAL BOOL rdp_set_io_callback_context(rdpRdp* rdp,
void* usercontext);
267 FREERDP_LOCAL
void* rdp_get_io_callback_context(rdpRdp* rdp);
269 #define RDP_TAG FREERDP_TAG("core.rdp")
270 #ifdef WITH_DEBUG_RDP
271 #define DEBUG_RDP(rdp, ...) WLog_Print(rdp->log, WLOG_DEBUG, __VA_ARGS__)
273 #define DEBUG_RDP(rdp, ...) \
279 const char* data_pdu_type_to_string(UINT8 type);
280 const char* pdu_type_to_str(UINT16 pduType,
char* buffer,
size_t length);
282 BOOL rdp_finalize_reset_flags(rdpRdp* rdp, BOOL clearAll);
283 BOOL rdp_finalize_set_flag(rdpRdp* rdp, UINT32 flag);
284 BOOL rdp_finalize_is_flag_set(rdpRdp* rdp, UINT32 flag);
285 const char* rdp_finalize_flags_to_str(UINT32 flags,
char* buffer,
size_t size);
287 BOOL rdp_decrypt(rdpRdp* rdp,
wStream* s, UINT16* pLength, UINT16 securityFlags);
289 BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo);
290 BOOL rdp_send_error_info(rdpRdp* rdp);
292 void rdp_free_rc4_encrypt_keys(rdpRdp* rdp);
293 BOOL rdp_reset_rc4_encrypt_keys(rdpRdp* rdp);
295 void rdp_free_rc4_decrypt_keys(rdpRdp* rdp);
296 BOOL rdp_reset_rc4_decrypt_keys(rdpRdp* rdp);
298 const char* rdp_security_flag_string(UINT32 securityFlags,
char* buffer,
size_t size);
300 BOOL rdp_set_backup_settings(rdpRdp* rdp);
301 BOOL rdp_reset_runtime_settings(rdpRdp* rdp);
303 void rdp_log_build_warnings(rdpRdp* rdp);