Merge pull request #3079 from akallabeth/drive_hotplug_fix
[platform/upstream/freerdp.git] / libfreerdp / core / rdp.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * RDP Core
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  * Copyright 2014 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #ifndef __RDP_H
22 #define __RDP_H
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "nla.h"
29 #include "mcs.h"
30 #include "tpkt.h"
31 #include "bulk.h"
32 #include "fastpath.h"
33 #include "tpdu.h"
34 #include "nego.h"
35 #include "input.h"
36 #include "update.h"
37 #include "license.h"
38 #include "errinfo.h"
39 #include "autodetect.h"
40 #include "heartbeat.h"
41 #include "multitransport.h"
42 #include "security.h"
43 #include "transport.h"
44 #include "connection.h"
45 #include "redirection.h"
46 #include "capabilities.h"
47 #include "channels.h"
48
49 #include <freerdp/freerdp.h>
50 #include <freerdp/settings.h>
51 #include <freerdp/log.h>
52
53 #include <winpr/stream.h>
54
55 /* Security Header Flags */
56 #define SEC_EXCHANGE_PKT                                        0x0001
57 #define SEC_TRANSPORT_REQ                                       0x0002
58 #define SEC_TRANSPORT_RSP                                       0x0004
59 #define SEC_ENCRYPT                                             0x0008
60 #define SEC_RESET_SEQNO                                         0x0010
61 #define SEC_IGNORE_SEQNO                                        0x0020
62 #define SEC_INFO_PKT                                            0x0040
63 #define SEC_LICENSE_PKT                                         0x0080
64 #define SEC_LICENSE_ENCRYPT_CS                                  0x0200
65 #define SEC_LICENSE_ENCRYPT_SC                                  0x0200
66 #define SEC_REDIRECTION_PKT                                     0x0400
67 #define SEC_SECURE_CHECKSUM                                     0x0800
68 #define SEC_AUTODETECT_REQ                                      0x1000
69 #define SEC_AUTODETECT_RSP                                      0x2000
70 #define SEC_HEARTBEAT                                           0x4000
71 #define SEC_FLAGSHI_VALID                                       0x8000
72
73 #define SEC_PKT_CS_MASK                                         (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
74 #define SEC_PKT_SC_MASK                                         (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
75 #define SEC_PKT_MASK                                            (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
76
77 #define RDP_SECURITY_HEADER_LENGTH                              4
78 #define RDP_SHARE_CONTROL_HEADER_LENGTH                         6
79 #define RDP_SHARE_DATA_HEADER_LENGTH                            12
80 #define RDP_PACKET_HEADER_MAX_LENGTH                            (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_MAX_LENGTH)
81
82 #define PDU_TYPE_DEMAND_ACTIVE                                  0x1
83 #define PDU_TYPE_CONFIRM_ACTIVE                                 0x3
84 #define PDU_TYPE_DEACTIVATE_ALL                                 0x6
85 #define PDU_TYPE_DATA                                           0x7
86 #define PDU_TYPE_SERVER_REDIRECTION                             0xA
87
88 #define PDU_TYPE_FLOW_TEST                                      0x41
89 #define PDU_TYPE_FLOW_RESPONSE                                  0x42
90 #define PDU_TYPE_FLOW_STOP                                      0x43
91
92 #define FINALIZE_SC_SYNCHRONIZE_PDU                             0x01
93 #define FINALIZE_SC_CONTROL_COOPERATE_PDU                       0x02
94 #define FINALIZE_SC_CONTROL_GRANTED_PDU                         0x04
95 #define FINALIZE_SC_FONT_MAP_PDU                                0x08
96 #define FINALIZE_SC_COMPLETE                                    0x0F
97
98 /* Data PDU Types */
99 #define DATA_PDU_TYPE_UPDATE                                    0x02
100 #define DATA_PDU_TYPE_CONTROL                                   0x14
101 #define DATA_PDU_TYPE_POINTER                                   0x1B
102 #define DATA_PDU_TYPE_INPUT                                     0x1C
103 #define DATA_PDU_TYPE_SYNCHRONIZE                               0x1F
104 #define DATA_PDU_TYPE_REFRESH_RECT                              0x21
105 #define DATA_PDU_TYPE_PLAY_SOUND                                0x22
106 #define DATA_PDU_TYPE_SUPPRESS_OUTPUT                           0x23
107 #define DATA_PDU_TYPE_SHUTDOWN_REQUEST                          0x24
108 #define DATA_PDU_TYPE_SHUTDOWN_DENIED                           0x25
109 #define DATA_PDU_TYPE_SAVE_SESSION_INFO                         0x26
110 #define DATA_PDU_TYPE_FONT_LIST                                 0x27
111 #define DATA_PDU_TYPE_FONT_MAP                                  0x28
112 #define DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS                   0x29
113 #define DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST              0x2B
114 #define DATA_PDU_TYPE_BITMAP_CACHE_ERROR                        0x2C
115 #define DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS                   0x2D
116 #define DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR                     0x2E
117 #define DATA_PDU_TYPE_SET_ERROR_INFO                            0x2F
118 #define DATA_PDU_TYPE_DRAW_NINEGRID_ERROR                       0x30
119 #define DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR                        0x31
120 #define DATA_PDU_TYPE_ARC_STATUS                                0x32
121 #define DATA_PDU_TYPE_STATUS_INFO                               0x36
122 #define DATA_PDU_TYPE_MONITOR_LAYOUT                            0x37
123 #define DATA_PDU_TYPE_FRAME_ACKNOWLEDGE                         0x38
124
125 /* Stream Identifiers */
126 #define STREAM_UNDEFINED                                        0x00
127 #define STREAM_LOW                                              0x01
128 #define STREAM_MED                                              0x02
129 #define STREAM_HI                                               0x04
130
131 struct rdp_rdp
132 {
133         int state;
134         freerdp* instance;
135         rdpContext* context;
136         rdpNla* nla;
137         rdpMcs* mcs;
138         rdpNego* nego;
139         rdpBulk* bulk;
140         rdpInput* input;
141         rdpUpdate* update;
142         rdpFastPath* fastpath;
143         rdpLicense* license;
144         rdpRedirection* redirection;
145         rdpSettings* settings;
146         rdpTransport* transport;
147         rdpAutoDetect* autodetect;
148         rdpHeartbeat* heartbeat;
149         rdpMultitransport* multitransport;
150         struct crypto_rc4_struct* rc4_decrypt_key;
151         int decrypt_use_count;
152         int decrypt_checksum_use_count;
153         struct crypto_rc4_struct* rc4_encrypt_key;
154         int encrypt_use_count;
155         int encrypt_checksum_use_count;
156         struct crypto_des3_struct* fips_encrypt;
157         struct crypto_des3_struct* fips_decrypt;
158         struct crypto_hmac_struct* fips_hmac;
159         UINT32 sec_flags;
160         BOOL do_crypt;
161         BOOL do_crypt_license;
162         BOOL do_secure_checksum;
163         BYTE sign_key[16];
164         BYTE decrypt_key[16];
165         BYTE encrypt_key[16];
166         BYTE decrypt_update_key[16];
167         BYTE encrypt_update_key[16];
168         int rc4_key_len;
169         BYTE fips_sign_key[20];
170         BYTE fips_encrypt_key[24];
171         BYTE fips_decrypt_key[24];
172         UINT32 errorInfo;
173         UINT32 finalize_sc_pdus;
174         BOOL resendFocus;
175         BOOL deactivation_reactivation;
176         BOOL AwaitCapabilities;
177         rdpSettings* settingsCopy;
178 };
179
180 BOOL rdp_read_security_header(wStream* s, UINT16* flags);
181 void rdp_write_security_header(wStream* s, UINT16 flags);
182
183 BOOL rdp_read_share_control_header(wStream* s, UINT16* length, UINT16* type, UINT16* channel_id);
184 void rdp_write_share_control_header(wStream* s, UINT16 length, UINT16 type, UINT16 channel_id);
185
186 BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type, UINT32* share_id, 
187                         BYTE *compressed_type, UINT16 *compressed_len);
188
189 void rdp_write_share_data_header(wStream* s, UINT16 length, BYTE type, UINT32 share_id);
190
191 int rdp_init_stream(rdpRdp* rdp, wStream* s);
192 wStream* rdp_send_stream_init(rdpRdp* rdp);
193
194 BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id);
195 void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id);
196
197 int rdp_init_stream_pdu(rdpRdp* rdp, wStream* s);
198 BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id);
199
200 wStream* rdp_data_pdu_init(rdpRdp* rdp);
201 int rdp_init_stream_data_pdu(rdpRdp* rdp, wStream* s);
202 BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id);
203 int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
204
205 BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
206
207 int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size);
208
209 wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
210 BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags);
211 int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 securityFlags);
212
213 int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s);
214
215 void rdp_read_flow_control_pdu(wStream* s, UINT16* type);
216
217 BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount, const rdpMonitor* monitorDefArray);
218
219 int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra);
220
221 int rdp_check_fds(rdpRdp* rdp);
222
223 rdpRdp* rdp_new(rdpContext* context);
224 void rdp_reset(rdpRdp* rdp);
225 void rdp_free(rdpRdp* rdp);
226
227 #define RDP_TAG FREERDP_TAG("core.rdp")
228 #ifdef WITH_DEBUG_RDP
229 #define DEBUG_RDP(fmt, ...) WLog_DBG(RDP_TAG, fmt, ## __VA_ARGS__)
230 #else
231 #define DEBUG_RDP(fmt, ...) do { } while (0)
232 #endif
233
234 BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags);
235
236 BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo);
237 BOOL rdp_send_error_info(rdpRdp* rdp);
238
239 #endif /* __RDP_H */