2
* FreeRDP: A Remote Desktop Protocol Client
5
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
32
#include "extension.h"
34
#include "transport.h"
35
#include "connection.h"
36
#include "redirection.h"
37
#include "capabilities.h"
41
#include <freerdp/freerdp.h>
42
#include <freerdp/settings.h>
43
#include <freerdp/utils/debug.h>
44
#include <freerdp/utils/stream.h>
46
/* Security Header Flags */
47
#define SEC_EXCHANGE_PKT 0x0001
48
#define SEC_ENCRYPT 0x0008
49
#define SEC_RESET_SEQNO 0x0010
50
#define SEC_IGNORE_SEQNO 0x0020
51
#define SEC_INFO_PKT 0x0040
52
#define SEC_LICENSE_PKT 0x0080
53
#define SEC_LICENSE_ENCRYPT_CS 0x0200
54
#define SEC_LICENSE_ENCRYPT_SC 0x0200
55
#define SEC_REDIRECTION_PKT 0x0400
56
#define SEC_SECURE_CHECKSUM 0x0800
57
#define SEC_FLAGSHI_VALID 0x8000
59
#define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
60
#define SEC_PKT_SC_MASK (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
61
#define SEC_PKT_MASK (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
63
#define RDP_SECURITY_HEADER_LENGTH 4
64
#define RDP_SHARE_CONTROL_HEADER_LENGTH 6
65
#define RDP_SHARE_DATA_HEADER_LENGTH 12
66
#define RDP_PACKET_HEADER_LENGTH (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_LENGTH)
68
#define PDU_TYPE_DEMAND_ACTIVE 0x1
69
#define PDU_TYPE_CONFIRM_ACTIVE 0x3
70
#define PDU_TYPE_DEACTIVATE_ALL 0x6
71
#define PDU_TYPE_DATA 0x7
72
#define PDU_TYPE_SERVER_REDIRECTION 0xA
74
#define FINALIZE_SC_SYNCHRONIZE_PDU 0x01
75
#define FINALIZE_SC_CONTROL_COOPERATE_PDU 0x02
76
#define FINALIZE_SC_CONTROL_GRANTED_PDU 0x04
77
#define FINALIZE_SC_FONT_MAP_PDU 0x08
78
#define FINALIZE_SC_COMPLETE 0x0F
81
#define DATA_PDU_TYPE_UPDATE 0x02
82
#define DATA_PDU_TYPE_CONTROL 0x14
83
#define DATA_PDU_TYPE_POINTER 0x1B
84
#define DATA_PDU_TYPE_INPUT 0x1C
85
#define DATA_PDU_TYPE_SYNCHRONIZE 0x1F
86
#define DATA_PDU_TYPE_REFRESH_RECT 0x21
87
#define DATA_PDU_TYPE_PLAY_SOUND 0x22
88
#define DATA_PDU_TYPE_SUPPRESS_OUTPUT 0x23
89
#define DATA_PDU_TYPE_SHUTDOWN_REQUEST 0x24
90
#define DATA_PDU_TYPE_SHUTDOWN_DENIED 0x25
91
#define DATA_PDU_TYPE_SAVE_SESSION_INFO 0x26
92
#define DATA_PDU_TYPE_FONT_LIST 0x27
93
#define DATA_PDU_TYPE_FONT_MAP 0x28
94
#define DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS 0x29
95
#define DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST 0x2B
96
#define DATA_PDU_TYPE_BITMAP_CACHE_ERROR 0x2C
97
#define DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS 0x2D
98
#define DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR 0x2E
99
#define DATA_PDU_TYPE_SET_ERROR_INFO 0x2F
100
#define DATA_PDU_TYPE_DRAW_NINEGRID_ERROR 0x30
101
#define DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR 0x31
102
#define DATA_PDU_TYPE_ARC_STATUS 0x32
103
#define DATA_PDU_TYPE_STATUS_INFO 0x36
104
#define DATA_PDU_TYPE_MONITOR_LAYOUT 0x37
106
/* Compression Types */
107
#define PACKET_COMPRESSED 0x20
108
#define PACKET_AT_FRONT 0x40
109
#define PACKET_FLUSHED 0x80
110
#define PACKET_COMPR_TYPE_8K 0x00
111
#define PACKET_COMPR_TYPE_64K 0x01
112
#define PACKET_COMPR_TYPE_RDP6 0x02
113
#define PACKET_COMPR_TYPE_RDP61 0x03
114
#define CompressionTypeMask 0x0F
116
/* Stream Identifiers */
117
#define STREAM_UNDEFINED 0x00
118
#define STREAM_LOW 0x01
119
#define STREAM_MED 0x02
120
#define STREAM_HI 0x04
127
struct rdp_nego* nego;
128
struct rdp_input* input;
129
struct rdp_update* update;
130
struct rdp_fastpath* fastpath;
131
struct rdp_license* license;
132
struct rdp_redirection* redirection;
133
struct rdp_settings* settings;
134
struct rdp_transport* transport;
135
struct rdp_extension* extension;
136
struct rdp_mppc* mppc;
137
struct crypto_rc4_struct* rc4_decrypt_key;
138
int decrypt_use_count;
139
struct crypto_rc4_struct* rc4_encrypt_key;
140
int encrypt_use_count;
141
struct crypto_des3_struct* fips_encrypt;
142
struct crypto_des3_struct* fips_decrypt;
143
struct crypto_hmac_struct* fips_hmac;
147
uint8 decrypt_key[16];
148
uint8 encrypt_key[16];
149
uint8 decrypt_update_key[16];
150
uint8 encrypt_update_key[16];
152
uint8 fips_sign_key[20];
153
uint8 fips_encrypt_key[24];
154
uint8 fips_decrypt_key[24];
156
uint32 finalize_sc_pdus;
159
void rdp_read_security_header(STREAM* s, uint16* flags);
160
void rdp_write_security_header(STREAM* s, uint16 flags);
162
boolean rdp_read_share_control_header(STREAM* s, uint16* length, uint16* type, uint16* channel_id);
163
void rdp_write_share_control_header(STREAM* s, uint16 length, uint16 type, uint16 channel_id);
165
boolean rdp_read_share_data_header(STREAM* s, uint16* length, uint8* type, uint32* share_id,
166
uint8 *compressed_type, uint16 *compressed_len);
168
void rdp_write_share_data_header(STREAM* s, uint16 length, uint8 type, uint32 share_id);
170
STREAM* rdp_send_stream_init(rdpRdp* rdp);
172
boolean rdp_read_header(rdpRdp* rdp, STREAM* s, uint16* length, uint16* channel_id);
173
void rdp_write_header(rdpRdp* rdp, STREAM* s, uint16 length, uint16 channel_id);
175
STREAM* rdp_pdu_init(rdpRdp* rdp);
176
boolean rdp_send_pdu(rdpRdp* rdp, STREAM* s, uint16 type, uint16 channel_id);
178
STREAM* rdp_data_pdu_init(rdpRdp* rdp);
179
boolean rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, uint8 type, uint16 channel_id);
180
void rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s);
182
boolean rdp_send(rdpRdp* rdp, STREAM* s, uint16 channel_id);
183
void rdp_recv(rdpRdp* rdp);
185
int rdp_send_channel_data(rdpRdp* rdp, int channel_id, uint8* data, int size);
187
boolean rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s);
189
void rdp_set_blocking_mode(rdpRdp* rdp, boolean blocking);
190
int rdp_check_fds(rdpRdp* rdp);
192
rdpRdp* rdp_new(freerdp* instance);
193
void rdp_free(rdpRdp* rdp);
195
#ifdef WITH_DEBUG_RDP
196
#define DEBUG_RDP(fmt, ...) DEBUG_CLASS(RDP, fmt, ## __VA_ARGS__)
198
#define DEBUG_RDP(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
201
boolean rdp_decrypt(rdpRdp* rdp, STREAM* s, int length);