1 /**
2  * xrdp: A Remote Desktop Protocol server.
3  * Miscellaneous protocol constants
4  *
5  * Copyright (C) Matthew Chapman 1999-2008
6  * Copyright (C) Jay Sorg 2004-2014
7  * Copyright (C) Kevin Zhou 2012
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 #if !defined(XRDP_CONSTANTS_H)
23 #define XRDP_CONSTANTS_H
24 
25 /* TCP port for Remote Desktop Protocol */
26 #define TCP_PORT_RDP                   3389
27 
28 /******************************************************************************
29  *
30  * xrdp constants
31  *
32  * Constants defined in publically available Microsoft documents are not
33  * stored here, but are stored in the include files ms-*.h, where the name
34  * of the file is the name of the document defining the constant.
35  *
36  * So for example, NTSTATUS values found in [MS-ERREF] are found in
37  * ms-erref.h
38  ******************************************************************************/
39 
40 #define INFO_CLIENT_NAME_BYTES  32
41 /**
42  * Maximum length of a string including the mandatory null terminator
43  * [MS-RDPBCGR] TS_INFO_PACKET(2.2.1.11.1.1)
44  */
45 #define INFO_CLIENT_MAX_CB_LEN  512
46 
47 #define XRDP_MAX_BITMAP_CACHE_ID  3
48 #define XRDP_MAX_BITMAP_CACHE_IDX 2000
49 #define XRDP_BITMAP_CACHE_ENTRIES 2048
50 
51 #define XR_MIN_KEY_CODE 8
52 #define XR_MAX_KEY_CODE 256
53 
54 /*
55  * Constants come from ITU-T Recommendations
56  */
57 
58 #define ISO_PDU_CR                     0xE0 /* X.224 Connection Request */
59 #define ISO_PDU_CC                     0xD0 /* X.224 Connection Confirm */
60 #define ISO_PDU_DR                     0x80 /* Disconnect Request */
61 #define ISO_PDU_DT                     0xF0 /* Data */
62 #define ISO_PDU_ER                     0x70 /* Error */
63 
64 /* MCS PDU codes (T.125) */
65 #define MCS_EDRQ                       1  /* Erect Domain Request */
66 #define MCS_DPUM                       8  /* Disconnect Provider Ultimatum */
67 #define MCS_AURQ                       10 /* Attach User Request */
68 #define MCS_AUCF                       11 /* Attach User Confirm */
69 #define MCS_CJRQ                       14 /* Channel Join Request */
70 #define MCS_CJCF                       15 /* Channel Join Confirm */
71 #define MCS_SDRQ                       25 /* Send Data Request */
72 #define MCS_SDIN                       26 /* Send Data Indication */
73 
74 /******************************************************************************
75  *
76  * Constants come from other Microsoft products
77  *
78  *****************************************************************************/
79 
80 /* Sound format constants - see also RFC 2361 and MS-RDPAI  */
81 #define WAVE_FORMAT_PCM                0x0001
82 #define WAVE_FORMAT_ADPCM              0x0002
83 #define WAVE_FORMAT_ALAW               0x0006
84 #define WAVE_FORMAT_MULAW              0x0007
85 #define WAVE_FORMAT_MPEGLAYER3         0x0055
86 #define WAVE_FORMAT_OPUS               0x0069
87 #define WAVE_FORMAT_AAC                0xA106
88 
89 /* https://technet.microsoft.com/ja-jp/library/aa387685.aspx */
90 #define SEC_RSA_MAGIC                  0x31415352 /* RSA1 */
91 
92 /* NTSTATUS Values (MS-ERREF 2.3.1) */
93 /* used for RDPDR */
94 /*
95  * not yet sorted out
96  */
97 
98 #define MCS_CONNECT_INITIAL            0x7f65 /* MCS BER: big endian, class=application (0x4000), constructed (0x2000), tag number > 30 (0x1f00), tag number=101 (0x0065) */
99 #define MCS_CONNECT_RESPONSE           0x7f66 /* MCS BER: application 102 */
100 
101 #define BER_TAG_BOOLEAN                1
102 #define BER_TAG_INTEGER                2
103 #define BER_TAG_OCTET_STRING           4
104 #define BER_TAG_RESULT                 10
105 #define MCS_TAG_DOMAIN_PARAMS          0x30
106 
107 #define MCS_GLOBAL_CHANNEL             1003
108 #define MCS_USERCHANNEL_BASE           1001
109 
110 /* RDP secure transport constants */
111 /* not used anywhere */
112 #define SEC_RANDOM_SIZE                32
113 #define SEC_MODULUS_SIZE               64
114 #define SEC_PADDING_SIZE               8
115 #define SEC_EXPONENT_SIZE              4
116 
117 /* RDP licensing constants */
118 #define LICENCE_TOKEN_SIZE             10
119 #define LICENCE_HWID_SIZE              20
120 #define LICENCE_SIGNATURE_SIZE         16
121 
122 
123 /* See T.128 */
124 /* not used anywhere */
125 #define RDP_KEYPRESS                   0
126 #define RDP_KEYRELEASE                 (KBD_FLAG_DOWN | KBD_FLAG_UP)
127 
128 /* Raster operation masks */
129 #define ROP2_S(rop3)                   (rop3 & 0xf)
130 #define ROP2_P(rop3)                   ((rop3 & 0x3) | ((rop3 & 0x30) >> 2))
131 
132 #define ROP2_COPY                      0xc
133 #define ROP2_XOR                       0x6
134 #define ROP2_AND                       0x8
135 #define ROP2_NXOR                      0x9
136 #define ROP2_OR                        0xe
137 
138 #define MIX_TRANSPARENT                0
139 #define MIX_OPAQUE                     1
140 
141 #define TEXT2_VERTICAL                 0x04
142 #define TEXT2_IMPLICIT_X               0x20
143 
144 /* RDP bitmap cache (version 2) constants */
145 #define BMPCACHE2_C0_CELLS             0x78
146 #define BMPCACHE2_C1_CELLS             0x78
147 #define BMPCACHE2_C2_CELLS             0x150
148 #define BMPCACHE2_NUM_PSTCELLS         0x9f6
149 
150 #define PDU_FLAG_FIRST                 0x01
151 #define PDU_FLAG_LAST                  0x02
152 
153 #define RDP_SOURCE                     "MSTSC"
154 
155 /* Keymap flags */
156 #define MapRightShiftMask              (1 << 0)
157 #define MapLeftShiftMask               (1 << 1)
158 #define MapShiftMask                   (MapRightShiftMask | MapLeftShiftMask)
159 
160 #define MapRightAltMask                (1 << 2)
161 #define MapLeftAltMask                 (1 << 3)
162 #define MapAltGrMask                   MapRightAltMask
163 
164 #define MapRightCtrlMask               (1 << 4)
165 #define MapLeftCtrlMask                (1 << 5)
166 #define MapCtrlMask                    (MapRightCtrlMask | MapLeftCtrlMask)
167 
168 #define MapRightWinMask                (1 << 6)
169 #define MapLeftWinMask                 (1 << 7)
170 #define MapWinMask                     (MapRightWinMask | MapLeftWinMask)
171 
172 #define MapNumLockMask                 (1 << 8)
173 #define MapCapsLockMask                (1 << 9)
174 
175 #define MapLocalStateMask              (1 << 10)
176 
177 #define MapInhibitMask                 (1 << 11)
178 
179 #define MASK_ADD_BITS(var, mask)       (var |= mask)
180 #define MASK_REMOVE_BITS(var, mask)    (var &= ~mask)
181 #define MASK_HAS_BITS(var, mask)       ((var & mask)>0)
182 #define MASK_CHANGE_BIT(var, mask, active) \
183     (var = ((var & ~mask) | (active ? mask : 0)))
184 
185 /* Clipboard constants, "borrowed" from GCC system headers in
186    the w32 cross compiler */
187 
188 #define CF_TEXT                        1
189 #define CF_BITMAP                      2
190 #define CF_METAFILEPICT                3
191 #define CF_SYLK                        4
192 #define CF_DIF                         5
193 #define CF_TIFF                        6
194 #define CF_OEMTEXT                     7
195 #define CF_DIB                         8
196 #define CF_PALETTE                     9
197 #define CF_PENDATA                     10
198 #define CF_RIFF                        11
199 #define CF_WAVE                        12
200 #define CF_UNICODETEXT                 13
201 #define CF_ENHMETAFILE                 14
202 #define CF_HDROP                       15
203 #define CF_LOCALE                      16
204 #define CF_MAX                         17
205 #define CF_OWNERDISPLAY                128
206 #define CF_DSPTEXT                     129
207 #define CF_DSPBITMAP                   130
208 #define CF_DSPMETAFILEPICT             131
209 #define CF_DSPENHMETAFILE              142
210 #define CF_PRIVATEFIRST                512
211 #define CF_PRIVATELAST                 767
212 #define CF_GDIOBJFIRST                 768
213 #define CF_GDIOBJLAST                  1023
214 
215 /* RDPDR constants */
216 #define RDPDR_MAX_DEVICES              0x10
217 
218 /* drawable types */
219 #define WND_TYPE_BITMAP  0
220 #define WND_TYPE_WND     1
221 #define WND_TYPE_SCREEN  2
222 #define WND_TYPE_BUTTON  3
223 #define WND_TYPE_IMAGE   4
224 #define WND_TYPE_EDIT    5
225 #define WND_TYPE_LABEL   6
226 #define WND_TYPE_COMBO   7
227 #define WND_TYPE_SPECIAL 8
228 #define WND_TYPE_LISTBOX 9
229 #define WND_TYPE_OFFSCREEN 10
230 
231 /* button states */
232 #define BUTTON_STATE_UP   0
233 #define BUTTON_STATE_DOWN 1
234 
235 /* messages */
236 #define WM_PAINT       3
237 #define WM_KEYDOWN     15
238 #define WM_KEYUP       16
239 #define WM_MOUSEMOVE   100
240 #define WM_LBUTTONUP   101
241 #define WM_LBUTTONDOWN 102
242 #define WM_RBUTTONUP   103
243 #define WM_RBUTTONDOWN 104
244 #define WM_BUTTON3UP   105
245 #define WM_BUTTON3DOWN 106
246 #define WM_BUTTON4UP   107
247 #define WM_BUTTON4DOWN 108
248 #define WM_BUTTON5UP   109
249 #define WM_BUTTON5DOWN 110
250 #define WM_BUTTON6UP   111
251 #define WM_BUTTON6DOWN 112
252 #define WM_BUTTON7UP   113
253 #define WM_BUTTON7DOWN 114
254 #define WM_BUTTON8UP   115
255 #define WM_BUTTON8DOWN 116
256 #define WM_BUTTON9UP   117
257 #define WM_BUTTON9DOWN 118
258 #define WM_INVALIDATE  200
259 
260 #define CB_ITEMCHANGE  300
261 
262 #define FASTPATH_MAX_PACKET_SIZE    0x3fff
263 
264 #define XR_RDP_SCAN_LSHIFT 42
265 #define XR_RDP_SCAN_ALT    56
266 
267 #endif
268