1 /** 2 * FreeRDP: A Remote Desktop Protocol Implementation 3 * Fast Path 4 * 5 * Copyright 2011 Vic Lee 6 * 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 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 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. 18 */ 19 20 #ifndef FREERDP_LIB_CORE_FASTPATH_H 21 #define FREERDP_LIB_CORE_FASTPATH_H 22 23 /* 24 * Fast-Path has 15 bits available for length information which would lead to a 25 * maximal pdu size of 0x8000. However in practice only 14 bits are used 26 * this isn't documented anywhere but it looks like most implementations will 27 * fail if fast-path packages > 0x3FFF arrive. 28 */ 29 #define FASTPATH_MAX_PACKET_SIZE 0x3FFF 30 31 /* 32 * The following size guarantees that no fast-path PDU fragmentation occurs. 33 * It was calculated by subtracting 128 from FASTPATH_MAX_PACKET_SIZE. 34 * 128 was chosen because it includes all required and optional headers as well as 35 * possible paddings and some extra bytes for safety. 36 */ 37 #define FASTPATH_FRAGMENT_SAFE_SIZE 0x3F80 38 39 typedef struct rdp_fastpath rdpFastPath; 40 41 #include "rdp.h" 42 43 #include <winpr/stream.h> 44 #include <freerdp/api.h> 45 46 enum FASTPATH_INPUT_ACTION_TYPE 47 { 48 FASTPATH_INPUT_ACTION_FASTPATH = 0x0, 49 FASTPATH_INPUT_ACTION_X224 = 0x3 50 }; 51 52 enum FASTPATH_OUTPUT_ACTION_TYPE 53 { 54 FASTPATH_OUTPUT_ACTION_FASTPATH = 0x0, 55 FASTPATH_OUTPUT_ACTION_X224 = 0x3 56 }; 57 58 enum FASTPATH_INPUT_ENCRYPTION_FLAGS 59 { 60 FASTPATH_INPUT_SECURE_CHECKSUM = 0x1, 61 FASTPATH_INPUT_ENCRYPTED = 0x2 62 }; 63 64 enum FASTPATH_OUTPUT_ENCRYPTION_FLAGS 65 { 66 FASTPATH_OUTPUT_SECURE_CHECKSUM = 0x1, 67 FASTPATH_OUTPUT_ENCRYPTED = 0x2 68 }; 69 70 enum FASTPATH_UPDATETYPE 71 { 72 FASTPATH_UPDATETYPE_ORDERS = 0x0, 73 FASTPATH_UPDATETYPE_BITMAP = 0x1, 74 FASTPATH_UPDATETYPE_PALETTE = 0x2, 75 FASTPATH_UPDATETYPE_SYNCHRONIZE = 0x3, 76 FASTPATH_UPDATETYPE_SURFCMDS = 0x4, 77 FASTPATH_UPDATETYPE_PTR_NULL = 0x5, 78 FASTPATH_UPDATETYPE_PTR_DEFAULT = 0x6, 79 FASTPATH_UPDATETYPE_PTR_POSITION = 0x8, 80 FASTPATH_UPDATETYPE_COLOR = 0x9, 81 FASTPATH_UPDATETYPE_CACHED = 0xA, 82 FASTPATH_UPDATETYPE_POINTER = 0xB, 83 FASTPATH_UPDATETYPE_LARGE_POINTER = 0xC 84 }; 85 86 enum FASTPATH_FRAGMENT 87 { 88 FASTPATH_FRAGMENT_SINGLE = 0x0, 89 FASTPATH_FRAGMENT_LAST = 0x1, 90 FASTPATH_FRAGMENT_FIRST = 0x2, 91 FASTPATH_FRAGMENT_NEXT = 0x3 92 }; 93 94 enum FASTPATH_OUTPUT_COMPRESSION 95 { 96 FASTPATH_OUTPUT_COMPRESSION_USED = 0x2 97 }; 98 99 /* FastPath Input Events */ 100 enum FASTPATH_INPUT_EVENT_CODE 101 { 102 FASTPATH_INPUT_EVENT_SCANCODE = 0x0, 103 FASTPATH_INPUT_EVENT_MOUSE = 0x1, 104 FASTPATH_INPUT_EVENT_MOUSEX = 0x2, 105 FASTPATH_INPUT_EVENT_SYNC = 0x3, 106 FASTPATH_INPUT_EVENT_UNICODE = 0x4 107 }; 108 109 /* FastPath Keyboard Event Flags */ 110 enum FASTPATH_INPUT_KBDFLAGS 111 { 112 FASTPATH_INPUT_KBDFLAGS_RELEASE = 0x01, 113 FASTPATH_INPUT_KBDFLAGS_EXTENDED = 0x02, 114 FASTPATH_INPUT_KBDFLAGS_PREFIX_E1 = 0x04 /* for pause sequence */ 115 }; 116 117 struct _FASTPATH_UPDATE_PDU_HEADER 118 { 119 BYTE fpOutputHeader; 120 BYTE length1; 121 BYTE length2; 122 BYTE fipsInformation[4]; 123 BYTE dataSignature[8]; 124 125 BYTE action; 126 BYTE secFlags; 127 UINT16 length; 128 }; 129 typedef struct _FASTPATH_UPDATE_PDU_HEADER FASTPATH_UPDATE_PDU_HEADER; 130 131 struct _FASTPATH_UPDATE_HEADER 132 { 133 BYTE updateHeader; 134 BYTE compressionFlags; 135 UINT16 size; 136 137 BYTE updateCode; 138 BYTE fragmentation; 139 BYTE compression; 140 }; 141 typedef struct _FASTPATH_UPDATE_HEADER FASTPATH_UPDATE_HEADER; 142 143 struct rdp_fastpath 144 { 145 rdpRdp* rdp; 146 wStream* fs; 147 BYTE encryptionFlags; 148 BYTE numberEvents; 149 wStream* updateData; 150 int fragmentation; 151 }; 152 153 FREERDP_LOCAL UINT16 fastpath_header_length(wStream* s); 154 FREERDP_LOCAL UINT16 fastpath_read_header(rdpFastPath* fastpath, wStream* s); 155 FREERDP_LOCAL BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16* length); 156 FREERDP_LOCAL int fastpath_recv_updates(rdpFastPath* fastpath, wStream* s); 157 FREERDP_LOCAL int fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s); 158 159 FREERDP_LOCAL wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath); 160 FREERDP_LOCAL wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, 161 BYTE eventCode); 162 FREERDP_LOCAL BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, 163 size_t iEventCount); 164 FREERDP_LOCAL BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s); 165 166 FREERDP_LOCAL wStream* fastpath_update_pdu_init(rdpFastPath* fastpath); 167 FREERDP_LOCAL wStream* fastpath_update_pdu_init_new(rdpFastPath* fastpath); 168 FREERDP_LOCAL BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s, 169 BOOL skipCompression); 170 171 FREERDP_LOCAL BOOL fastpath_send_surfcmd_frame_marker(rdpFastPath* fastpath, UINT16 frameAction, 172 UINT32 frameId); 173 174 FREERDP_LOCAL rdpFastPath* fastpath_new(rdpRdp* rdp); 175 FREERDP_LOCAL void fastpath_free(rdpFastPath* fastpath); 176 177 #endif /* FREERDP_LIB_CORE_FASTPATH_H */ 178