root / vnc.h @ 0497d2f4
History | View | Annotate | Download (9.4 kB)
1 | 19a490bf | aliguori | /*
|
---|---|---|---|
2 | 19a490bf | aliguori | * QEMU VNC display driver
|
3 | 19a490bf | aliguori | *
|
4 | 19a490bf | aliguori | * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
|
5 | 19a490bf | aliguori | * Copyright (C) 2006 Fabrice Bellard
|
6 | 19a490bf | aliguori | * Copyright (C) 2009 Red Hat, Inc
|
7 | 19a490bf | aliguori | *
|
8 | 19a490bf | aliguori | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | 19a490bf | aliguori | * of this software and associated documentation files (the "Software"), to deal
|
10 | 19a490bf | aliguori | * in the Software without restriction, including without limitation the rights
|
11 | 19a490bf | aliguori | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | 19a490bf | aliguori | * copies of the Software, and to permit persons to whom the Software is
|
13 | 19a490bf | aliguori | * furnished to do so, subject to the following conditions:
|
14 | 19a490bf | aliguori | *
|
15 | 19a490bf | aliguori | * The above copyright notice and this permission notice shall be included in
|
16 | 19a490bf | aliguori | * all copies or substantial portions of the Software.
|
17 | 19a490bf | aliguori | *
|
18 | 19a490bf | aliguori | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | 19a490bf | aliguori | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | 19a490bf | aliguori | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21 | 19a490bf | aliguori | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22 | 19a490bf | aliguori | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23 | 19a490bf | aliguori | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 19a490bf | aliguori | * THE SOFTWARE.
|
25 | 19a490bf | aliguori | */
|
26 | 19a490bf | aliguori | |
27 | 19a490bf | aliguori | #ifndef __QEMU_VNC_H
|
28 | 19a490bf | aliguori | #define __QEMU_VNC_H
|
29 | 19a490bf | aliguori | |
30 | 19a490bf | aliguori | #include "qemu-common.h" |
31 | 19a490bf | aliguori | #include "console.h" |
32 | 19a490bf | aliguori | #include "monitor.h" |
33 | 19a490bf | aliguori | #include "audio/audio.h" |
34 | 19a490bf | aliguori | #include <zlib.h> |
35 | 19a490bf | aliguori | |
36 | 19a490bf | aliguori | #include "keymaps.h" |
37 | 19a490bf | aliguori | |
38 | 5fb6c7a8 | aliguori | // #define _VNC_DEBUG 1
|
39 | 5fb6c7a8 | aliguori | |
40 | 5fb6c7a8 | aliguori | #ifdef _VNC_DEBUG
|
41 | 5fb6c7a8 | aliguori | #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
42 | 5fb6c7a8 | aliguori | #else
|
43 | 5fb6c7a8 | aliguori | #define VNC_DEBUG(fmt, ...) do { } while (0) |
44 | 5fb6c7a8 | aliguori | #endif
|
45 | 5fb6c7a8 | aliguori | |
46 | 19a490bf | aliguori | /*****************************************************************************
|
47 | 19a490bf | aliguori | *
|
48 | 19a490bf | aliguori | * Core data structures
|
49 | 19a490bf | aliguori | *
|
50 | 19a490bf | aliguori | *****************************************************************************/
|
51 | 19a490bf | aliguori | |
52 | 19a490bf | aliguori | typedef struct Buffer |
53 | 19a490bf | aliguori | { |
54 | 19a490bf | aliguori | size_t capacity; |
55 | 19a490bf | aliguori | size_t offset; |
56 | 19a490bf | aliguori | uint8_t *buffer; |
57 | 19a490bf | aliguori | } Buffer; |
58 | 19a490bf | aliguori | |
59 | 19a490bf | aliguori | typedef struct VncState VncState; |
60 | 19a490bf | aliguori | |
61 | 19a490bf | aliguori | typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len); |
62 | 19a490bf | aliguori | |
63 | 19a490bf | aliguori | typedef void VncWritePixels(VncState *vs, void *data, int size); |
64 | 19a490bf | aliguori | |
65 | 19a490bf | aliguori | typedef void VncSendHextileTile(VncState *vs, |
66 | 19a490bf | aliguori | int x, int y, int w, int h, |
67 | 19a490bf | aliguori | void *last_bg,
|
68 | 19a490bf | aliguori | void *last_fg,
|
69 | 19a490bf | aliguori | int *has_bg, int *has_fg); |
70 | 19a490bf | aliguori | |
71 | 19a490bf | aliguori | #define VNC_MAX_WIDTH 2048 |
72 | 19a490bf | aliguori | #define VNC_MAX_HEIGHT 2048 |
73 | 19a490bf | aliguori | #define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) |
74 | 19a490bf | aliguori | |
75 | 19a490bf | aliguori | #define VNC_AUTH_CHALLENGE_SIZE 16 |
76 | 19a490bf | aliguori | |
77 | 19a490bf | aliguori | typedef struct VncDisplay VncDisplay; |
78 | 19a490bf | aliguori | |
79 | 5fb6c7a8 | aliguori | #ifdef CONFIG_VNC_TLS
|
80 | 5fb6c7a8 | aliguori | #include "vnc-tls.h" |
81 | 5fb6c7a8 | aliguori | #include "vnc-auth-vencrypt.h" |
82 | 5fb6c7a8 | aliguori | #endif
|
83 | 2f9606b3 | aliguori | #ifdef CONFIG_VNC_SASL
|
84 | 2f9606b3 | aliguori | #include "vnc-auth-sasl.h" |
85 | 2f9606b3 | aliguori | #endif
|
86 | 2f9606b3 | aliguori | |
87 | 5fb6c7a8 | aliguori | |
88 | 19a490bf | aliguori | struct VncDisplay
|
89 | 19a490bf | aliguori | { |
90 | 19a490bf | aliguori | int lsock;
|
91 | 19a490bf | aliguori | DisplayState *ds; |
92 | 19a490bf | aliguori | VncState *clients; |
93 | 19a490bf | aliguori | kbd_layout_t *kbd_layout; |
94 | 19a490bf | aliguori | |
95 | 19a490bf | aliguori | char *display;
|
96 | 19a490bf | aliguori | char *password;
|
97 | 19a490bf | aliguori | int auth;
|
98 | 19a490bf | aliguori | #ifdef CONFIG_VNC_TLS
|
99 | 5fb6c7a8 | aliguori | int subauth; /* Used by VeNCrypt */ |
100 | 5fb6c7a8 | aliguori | VncDisplayTLS tls; |
101 | 19a490bf | aliguori | #endif
|
102 | 76655d6d | aliguori | #ifdef CONFIG_VNC_SASL
|
103 | 76655d6d | aliguori | VncDisplaySASL sasl; |
104 | 76655d6d | aliguori | #endif
|
105 | 19a490bf | aliguori | }; |
106 | 19a490bf | aliguori | |
107 | 19a490bf | aliguori | struct VncState
|
108 | 19a490bf | aliguori | { |
109 | 19a490bf | aliguori | QEMUTimer *timer; |
110 | 19a490bf | aliguori | int csock;
|
111 | 19a490bf | aliguori | DisplayState *ds; |
112 | 19a490bf | aliguori | VncDisplay *vd; |
113 | 19a490bf | aliguori | int need_update;
|
114 | 19a490bf | aliguori | uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; |
115 | 19a490bf | aliguori | char *old_data;
|
116 | 19a490bf | aliguori | uint32_t features; |
117 | 19a490bf | aliguori | int absolute;
|
118 | 19a490bf | aliguori | int last_x;
|
119 | 19a490bf | aliguori | int last_y;
|
120 | 19a490bf | aliguori | |
121 | 19a490bf | aliguori | uint32_t vnc_encoding; |
122 | 19a490bf | aliguori | uint8_t tight_quality; |
123 | 19a490bf | aliguori | uint8_t tight_compression; |
124 | 19a490bf | aliguori | |
125 | 19a490bf | aliguori | int major;
|
126 | 19a490bf | aliguori | int minor;
|
127 | 19a490bf | aliguori | |
128 | 19a490bf | aliguori | char challenge[VNC_AUTH_CHALLENGE_SIZE];
|
129 | 19a490bf | aliguori | #ifdef CONFIG_VNC_TLS
|
130 | 5fb6c7a8 | aliguori | VncStateTLS tls; |
131 | 19a490bf | aliguori | #endif
|
132 | 2f9606b3 | aliguori | #ifdef CONFIG_VNC_SASL
|
133 | 2f9606b3 | aliguori | VncStateSASL sasl; |
134 | 2f9606b3 | aliguori | #endif
|
135 | 19a490bf | aliguori | |
136 | 19a490bf | aliguori | Buffer output; |
137 | 19a490bf | aliguori | Buffer input; |
138 | 19a490bf | aliguori | /* current output mode information */
|
139 | 19a490bf | aliguori | VncWritePixels *write_pixels; |
140 | 19a490bf | aliguori | VncSendHextileTile *send_hextile_tile; |
141 | 19a490bf | aliguori | DisplaySurface clientds, serverds; |
142 | 19a490bf | aliguori | |
143 | 19a490bf | aliguori | CaptureVoiceOut *audio_cap; |
144 | 19a490bf | aliguori | struct audsettings as;
|
145 | 19a490bf | aliguori | |
146 | 19a490bf | aliguori | VncReadEvent *read_handler; |
147 | 19a490bf | aliguori | size_t read_handler_expect; |
148 | 19a490bf | aliguori | /* input */
|
149 | 19a490bf | aliguori | uint8_t modifiers_state[256];
|
150 | 19a490bf | aliguori | |
151 | 19a490bf | aliguori | Buffer zlib; |
152 | 19a490bf | aliguori | Buffer zlib_tmp; |
153 | 19a490bf | aliguori | z_stream zlib_stream[4];
|
154 | 19a490bf | aliguori | |
155 | 19a490bf | aliguori | VncState *next; |
156 | 19a490bf | aliguori | }; |
157 | 19a490bf | aliguori | |
158 | e06679fb | aliguori | |
159 | e06679fb | aliguori | /*****************************************************************************
|
160 | e06679fb | aliguori | *
|
161 | e06679fb | aliguori | * Authentication modes
|
162 | e06679fb | aliguori | *
|
163 | e06679fb | aliguori | *****************************************************************************/
|
164 | e06679fb | aliguori | |
165 | e06679fb | aliguori | enum {
|
166 | e06679fb | aliguori | VNC_AUTH_INVALID = 0,
|
167 | e06679fb | aliguori | VNC_AUTH_NONE = 1,
|
168 | e06679fb | aliguori | VNC_AUTH_VNC = 2,
|
169 | e06679fb | aliguori | VNC_AUTH_RA2 = 5,
|
170 | e06679fb | aliguori | VNC_AUTH_RA2NE = 6,
|
171 | e06679fb | aliguori | VNC_AUTH_TIGHT = 16,
|
172 | e06679fb | aliguori | VNC_AUTH_ULTRA = 17,
|
173 | 2f9606b3 | aliguori | VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */ |
174 | 2f9606b3 | aliguori | VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */ |
175 | 2f9606b3 | aliguori | VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ |
176 | e06679fb | aliguori | }; |
177 | e06679fb | aliguori | |
178 | e06679fb | aliguori | enum {
|
179 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_PLAIN = 256,
|
180 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_TLSNONE = 257,
|
181 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_TLSVNC = 258,
|
182 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
|
183 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_X509NONE = 260,
|
184 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_X509VNC = 261,
|
185 | e06679fb | aliguori | VNC_AUTH_VENCRYPT_X509PLAIN = 262,
|
186 | 2f9606b3 | aliguori | VNC_AUTH_VENCRYPT_X509SASL = 263,
|
187 | 2f9606b3 | aliguori | VNC_AUTH_VENCRYPT_TLSSASL = 264,
|
188 | e06679fb | aliguori | }; |
189 | e06679fb | aliguori | |
190 | e06679fb | aliguori | |
191 | e06679fb | aliguori | /*****************************************************************************
|
192 | e06679fb | aliguori | *
|
193 | e06679fb | aliguori | * Encoding types
|
194 | e06679fb | aliguori | *
|
195 | e06679fb | aliguori | *****************************************************************************/
|
196 | e06679fb | aliguori | |
197 | e06679fb | aliguori | #define VNC_ENCODING_RAW 0x00000000 |
198 | e06679fb | aliguori | #define VNC_ENCODING_COPYRECT 0x00000001 |
199 | e06679fb | aliguori | #define VNC_ENCODING_RRE 0x00000002 |
200 | e06679fb | aliguori | #define VNC_ENCODING_CORRE 0x00000004 |
201 | e06679fb | aliguori | #define VNC_ENCODING_HEXTILE 0x00000005 |
202 | e06679fb | aliguori | #define VNC_ENCODING_ZLIB 0x00000006 |
203 | e06679fb | aliguori | #define VNC_ENCODING_TIGHT 0x00000007 |
204 | e06679fb | aliguori | #define VNC_ENCODING_ZLIBHEX 0x00000008 |
205 | e06679fb | aliguori | #define VNC_ENCODING_TRLE 0x0000000f |
206 | e06679fb | aliguori | #define VNC_ENCODING_ZRLE 0x00000010 |
207 | e06679fb | aliguori | #define VNC_ENCODING_ZYWRLE 0x00000011 |
208 | e06679fb | aliguori | #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */ |
209 | e06679fb | aliguori | #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */ |
210 | e06679fb | aliguori | #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */ |
211 | e06679fb | aliguori | #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */ |
212 | e06679fb | aliguori | #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */ |
213 | e06679fb | aliguori | #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */ |
214 | e06679fb | aliguori | #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */ |
215 | e06679fb | aliguori | #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */ |
216 | e06679fb | aliguori | #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */ |
217 | e06679fb | aliguori | #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */ |
218 | e06679fb | aliguori | #define VNC_ENCODING_WMVi 0x574D5669 |
219 | e06679fb | aliguori | |
220 | e06679fb | aliguori | /*****************************************************************************
|
221 | e06679fb | aliguori | *
|
222 | e06679fb | aliguori | * Other tight constants
|
223 | e06679fb | aliguori | *
|
224 | e06679fb | aliguori | *****************************************************************************/
|
225 | e06679fb | aliguori | |
226 | e06679fb | aliguori | /*
|
227 | e06679fb | aliguori | * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
|
228 | e06679fb | aliguori | */
|
229 | e06679fb | aliguori | |
230 | e06679fb | aliguori | #define VNC_TIGHT_CCB_RESET_MASK (0x0f) |
231 | e06679fb | aliguori | #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4) |
232 | e06679fb | aliguori | #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4) |
233 | e06679fb | aliguori | #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4) |
234 | e06679fb | aliguori | #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4) |
235 | e06679fb | aliguori | #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4) |
236 | e06679fb | aliguori | #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4) |
237 | e06679fb | aliguori | |
238 | e06679fb | aliguori | /*****************************************************************************
|
239 | e06679fb | aliguori | *
|
240 | e06679fb | aliguori | * Features
|
241 | e06679fb | aliguori | *
|
242 | e06679fb | aliguori | *****************************************************************************/
|
243 | e06679fb | aliguori | |
244 | e06679fb | aliguori | #define VNC_FEATURE_RESIZE 0 |
245 | e06679fb | aliguori | #define VNC_FEATURE_HEXTILE 1 |
246 | e06679fb | aliguori | #define VNC_FEATURE_POINTER_TYPE_CHANGE 2 |
247 | e06679fb | aliguori | #define VNC_FEATURE_WMVI 3 |
248 | e06679fb | aliguori | #define VNC_FEATURE_TIGHT 4 |
249 | e06679fb | aliguori | #define VNC_FEATURE_ZLIB 5 |
250 | 753b4053 | aliguori | #define VNC_FEATURE_COPYRECT 6 |
251 | e06679fb | aliguori | |
252 | e06679fb | aliguori | #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE) |
253 | e06679fb | aliguori | #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE) |
254 | e06679fb | aliguori | #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE) |
255 | e06679fb | aliguori | #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI) |
256 | e06679fb | aliguori | #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT) |
257 | e06679fb | aliguori | #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB) |
258 | 753b4053 | aliguori | #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT) |
259 | e06679fb | aliguori | |
260 | 5fb6c7a8 | aliguori | |
261 | 5fb6c7a8 | aliguori | /*****************************************************************************
|
262 | 5fb6c7a8 | aliguori | *
|
263 | 5fb6c7a8 | aliguori | * Internal APIs
|
264 | 5fb6c7a8 | aliguori | *
|
265 | 5fb6c7a8 | aliguori | *****************************************************************************/
|
266 | 5fb6c7a8 | aliguori | |
267 | 5fb6c7a8 | aliguori | /* Event loop functions */
|
268 | 5fb6c7a8 | aliguori | void vnc_client_read(void *opaque); |
269 | 5fb6c7a8 | aliguori | void vnc_client_write(void *opaque); |
270 | 5fb6c7a8 | aliguori | |
271 | 2f9606b3 | aliguori | long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
|
272 | 2f9606b3 | aliguori | long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen); |
273 | 5fb6c7a8 | aliguori | |
274 | 5fb6c7a8 | aliguori | /* Protocol I/O functions */
|
275 | 5fb6c7a8 | aliguori | void vnc_write(VncState *vs, const void *data, size_t len); |
276 | 5fb6c7a8 | aliguori | void vnc_write_u32(VncState *vs, uint32_t value);
|
277 | 5fb6c7a8 | aliguori | void vnc_write_s32(VncState *vs, int32_t value);
|
278 | 5fb6c7a8 | aliguori | void vnc_write_u16(VncState *vs, uint16_t value);
|
279 | 5fb6c7a8 | aliguori | void vnc_write_u8(VncState *vs, uint8_t value);
|
280 | 5fb6c7a8 | aliguori | void vnc_flush(VncState *vs);
|
281 | 5fb6c7a8 | aliguori | void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
|
282 | 5fb6c7a8 | aliguori | |
283 | 5fb6c7a8 | aliguori | |
284 | 5fb6c7a8 | aliguori | /* Buffer I/O functions */
|
285 | 5fb6c7a8 | aliguori | uint8_t read_u8(uint8_t *data, size_t offset); |
286 | 5fb6c7a8 | aliguori | uint16_t read_u16(uint8_t *data, size_t offset); |
287 | 5fb6c7a8 | aliguori | int32_t read_s32(uint8_t *data, size_t offset); |
288 | 5fb6c7a8 | aliguori | uint32_t read_u32(uint8_t *data, size_t offset); |
289 | 5fb6c7a8 | aliguori | |
290 | 5fb6c7a8 | aliguori | /* Protocol stage functions */
|
291 | 5fb6c7a8 | aliguori | void vnc_client_error(VncState *vs);
|
292 | 2f9606b3 | aliguori | int vnc_client_io_error(VncState *vs, int ret, int last_errno); |
293 | 5fb6c7a8 | aliguori | |
294 | 5fb6c7a8 | aliguori | void start_client_init(VncState *vs);
|
295 | 5fb6c7a8 | aliguori | void start_auth_vnc(VncState *vs);
|
296 | 5fb6c7a8 | aliguori | |
297 | 2f9606b3 | aliguori | /* Buffer management */
|
298 | 2f9606b3 | aliguori | void buffer_reserve(Buffer *buffer, size_t len);
|
299 | 2f9606b3 | aliguori | int buffer_empty(Buffer *buffer);
|
300 | 2f9606b3 | aliguori | uint8_t *buffer_end(Buffer *buffer); |
301 | 2f9606b3 | aliguori | void buffer_reset(Buffer *buffer);
|
302 | 2f9606b3 | aliguori | void buffer_append(Buffer *buffer, const void *data, size_t len); |
303 | 2f9606b3 | aliguori | |
304 | 2f9606b3 | aliguori | |
305 | 2f9606b3 | aliguori | /* Misc helpers */
|
306 | 2f9606b3 | aliguori | |
307 | 2f9606b3 | aliguori | char *vnc_socket_local_addr(const char *format, int fd); |
308 | 2f9606b3 | aliguori | char *vnc_socket_remote_addr(const char *format, int fd); |
309 | 2f9606b3 | aliguori | |
310 | 19a490bf | aliguori | #endif /* __QEMU_VNC_H */ |