13e230dd2SCorentin Chary /* 23e230dd2SCorentin Chary * QEMU VNC display driver 33e230dd2SCorentin Chary * 43e230dd2SCorentin Chary * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws> 53e230dd2SCorentin Chary * Copyright (C) 2006 Fabrice Bellard 63e230dd2SCorentin Chary * Copyright (C) 2009 Red Hat, Inc 73e230dd2SCorentin Chary * 83e230dd2SCorentin Chary * Permission is hereby granted, free of charge, to any person obtaining a copy 93e230dd2SCorentin Chary * of this software and associated documentation files (the "Software"), to deal 103e230dd2SCorentin Chary * in the Software without restriction, including without limitation the rights 113e230dd2SCorentin Chary * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 123e230dd2SCorentin Chary * copies of the Software, and to permit persons to whom the Software is 133e230dd2SCorentin Chary * furnished to do so, subject to the following conditions: 143e230dd2SCorentin Chary * 153e230dd2SCorentin Chary * The above copyright notice and this permission notice shall be included in 163e230dd2SCorentin Chary * all copies or substantial portions of the Software. 173e230dd2SCorentin Chary * 183e230dd2SCorentin Chary * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 193e230dd2SCorentin Chary * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 203e230dd2SCorentin Chary * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 213e230dd2SCorentin Chary * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 223e230dd2SCorentin Chary * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 233e230dd2SCorentin Chary * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 243e230dd2SCorentin Chary * THE SOFTWARE. 253e230dd2SCorentin Chary */ 263e230dd2SCorentin Chary 273e230dd2SCorentin Chary #ifndef __QEMU_VNC_H 283e230dd2SCorentin Chary #define __QEMU_VNC_H 293e230dd2SCorentin Chary 303e230dd2SCorentin Chary #include "qemu-common.h" 313e230dd2SCorentin Chary #include "qemu-queue.h" 32bd023f95SCorentin Chary #include "qemu-thread.h" 3328ecbaeeSPaolo Bonzini #include "ui/console.h" 34*83c9089eSPaolo Bonzini #include "monitor/monitor.h" 353e230dd2SCorentin Chary #include "audio/audio.h" 36bc2429b9SCorentin Chary #include "bitmap.h" 373e230dd2SCorentin Chary #include <zlib.h> 383e230dd2SCorentin Chary #include <stdbool.h> 393e230dd2SCorentin Chary 403e230dd2SCorentin Chary #include "keymaps.h" 41148954faSCorentin Chary #include "vnc-palette.h" 42148954faSCorentin Chary #include "vnc-enc-zrle.h" 433e230dd2SCorentin Chary 443e230dd2SCorentin Chary // #define _VNC_DEBUG 1 453e230dd2SCorentin Chary 463e230dd2SCorentin Chary #ifdef _VNC_DEBUG 473e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) 483e230dd2SCorentin Chary #else 493e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { } while (0) 503e230dd2SCorentin Chary #endif 513e230dd2SCorentin Chary 523e230dd2SCorentin Chary /***************************************************************************** 533e230dd2SCorentin Chary * 543e230dd2SCorentin Chary * Core data structures 553e230dd2SCorentin Chary * 563e230dd2SCorentin Chary *****************************************************************************/ 573e230dd2SCorentin Chary 583e230dd2SCorentin Chary typedef struct Buffer 593e230dd2SCorentin Chary { 603e230dd2SCorentin Chary size_t capacity; 613e230dd2SCorentin Chary size_t offset; 623e230dd2SCorentin Chary uint8_t *buffer; 633e230dd2SCorentin Chary } Buffer; 643e230dd2SCorentin Chary 653e230dd2SCorentin Chary typedef struct VncState VncState; 66bd023f95SCorentin Chary typedef struct VncJob VncJob; 67bd023f95SCorentin Chary typedef struct VncRect VncRect; 68bd023f95SCorentin Chary typedef struct VncRectEntry VncRectEntry; 693e230dd2SCorentin Chary 703e230dd2SCorentin Chary typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len); 713e230dd2SCorentin Chary 729f64916dSGerd Hoffmann typedef void VncWritePixels(VncState *vs, void *data, int size); 733e230dd2SCorentin Chary 743e230dd2SCorentin Chary typedef void VncSendHextileTile(VncState *vs, 753e230dd2SCorentin Chary int x, int y, int w, int h, 763e230dd2SCorentin Chary void *last_bg, 773e230dd2SCorentin Chary void *last_fg, 783e230dd2SCorentin Chary int *has_bg, int *has_fg); 793e230dd2SCorentin Chary 8023bfe28fSStefan Weil /* VNC_MAX_WIDTH must be a multiple of 16. */ 813e230dd2SCorentin Chary #define VNC_MAX_WIDTH 2560 823e230dd2SCorentin Chary #define VNC_MAX_HEIGHT 2048 8323bfe28fSStefan Weil 8423bfe28fSStefan Weil /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */ 8523bfe28fSStefan Weil #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / 16) 863e230dd2SCorentin Chary 87999342a0SCorentin Chary #define VNC_STAT_RECT 64 88999342a0SCorentin Chary #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) 89999342a0SCorentin Chary #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT) 90999342a0SCorentin Chary 913e230dd2SCorentin Chary #define VNC_AUTH_CHALLENGE_SIZE 16 923e230dd2SCorentin Chary 933e230dd2SCorentin Chary typedef struct VncDisplay VncDisplay; 943e230dd2SCorentin Chary 953e230dd2SCorentin Chary #ifdef CONFIG_VNC_TLS 963e230dd2SCorentin Chary #include "vnc-tls.h" 973e230dd2SCorentin Chary #include "vnc-auth-vencrypt.h" 983e230dd2SCorentin Chary #endif 993e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 1003e230dd2SCorentin Chary #include "vnc-auth-sasl.h" 1013e230dd2SCorentin Chary #endif 1023e230dd2SCorentin Chary 103999342a0SCorentin Chary struct VncRectStat 104999342a0SCorentin Chary { 105999342a0SCorentin Chary /* time of last 10 updates, to find update frequency */ 106999342a0SCorentin Chary struct timeval times[10]; 107999342a0SCorentin Chary int idx; 108999342a0SCorentin Chary 109999342a0SCorentin Chary double freq; /* Update frequency (in Hz) */ 110999342a0SCorentin Chary bool updated; /* Already updated during this refresh */ 111999342a0SCorentin Chary }; 112999342a0SCorentin Chary 113999342a0SCorentin Chary typedef struct VncRectStat VncRectStat; 114999342a0SCorentin Chary 1153e230dd2SCorentin Chary struct VncSurface 1163e230dd2SCorentin Chary { 117999342a0SCorentin Chary struct timeval last_freq_check; 11823bfe28fSStefan Weil DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_MAX_WIDTH / 16); 119999342a0SCorentin Chary VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS]; 1209f64916dSGerd Hoffmann pixman_image_t *fb; 1219f64916dSGerd Hoffmann pixman_format_code_t format; 1223e230dd2SCorentin Chary }; 1233e230dd2SCorentin Chary 1248cf36489SGerd Hoffmann typedef enum VncShareMode { 1258cf36489SGerd Hoffmann VNC_SHARE_MODE_CONNECTING = 1, 1268cf36489SGerd Hoffmann VNC_SHARE_MODE_SHARED, 1278cf36489SGerd Hoffmann VNC_SHARE_MODE_EXCLUSIVE, 1288cf36489SGerd Hoffmann VNC_SHARE_MODE_DISCONNECTED, 1298cf36489SGerd Hoffmann } VncShareMode; 1308cf36489SGerd Hoffmann 1318cf36489SGerd Hoffmann typedef enum VncSharePolicy { 1328cf36489SGerd Hoffmann VNC_SHARE_POLICY_IGNORE = 1, 1338cf36489SGerd Hoffmann VNC_SHARE_POLICY_ALLOW_EXCLUSIVE, 1348cf36489SGerd Hoffmann VNC_SHARE_POLICY_FORCE_SHARED, 1358cf36489SGerd Hoffmann } VncSharePolicy; 1368cf36489SGerd Hoffmann 1373e230dd2SCorentin Chary struct VncDisplay 1383e230dd2SCorentin Chary { 1393e230dd2SCorentin Chary QTAILQ_HEAD(, VncState) clients; 1408cf36489SGerd Hoffmann int num_exclusive; 1418cf36489SGerd Hoffmann VncSharePolicy share_policy; 1423e230dd2SCorentin Chary QEMUTimer *timer; 1433e230dd2SCorentin Chary int timer_interval; 1443e230dd2SCorentin Chary int lsock; 1453e230dd2SCorentin Chary DisplayState *ds; 1463e230dd2SCorentin Chary kbd_layout_t *kbd_layout; 1473e230dd2SCorentin Chary int lock_key_sync; 148bd023f95SCorentin Chary QemuMutex mutex; 1493e230dd2SCorentin Chary 1503e230dd2SCorentin Chary QEMUCursor *cursor; 1513e230dd2SCorentin Chary int cursor_msize; 1523e230dd2SCorentin Chary uint8_t *cursor_mask; 1533e230dd2SCorentin Chary 1543e230dd2SCorentin Chary struct VncSurface guest; /* guest visible surface (aka ds->surface) */ 1559f64916dSGerd Hoffmann pixman_image_t *server; /* vnc server surface */ 1563e230dd2SCorentin Chary 1573e230dd2SCorentin Chary char *display; 1583e230dd2SCorentin Chary char *password; 1593c9405a0SGerd Hoffmann time_t expires; 1603e230dd2SCorentin Chary int auth; 1613e230dd2SCorentin Chary bool lossy; 16280e0c8c3SCorentin Chary bool non_adaptive; 1633e230dd2SCorentin Chary #ifdef CONFIG_VNC_TLS 1643e230dd2SCorentin Chary int subauth; /* Used by VeNCrypt */ 1653e230dd2SCorentin Chary VncDisplayTLS tls; 1663e230dd2SCorentin Chary #endif 1673e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 1683e230dd2SCorentin Chary VncDisplaySASL sasl; 1693e230dd2SCorentin Chary #endif 1703e230dd2SCorentin Chary }; 1713e230dd2SCorentin Chary 172d1af0e05SCorentin Chary typedef struct VncTight { 173d1af0e05SCorentin Chary int type; 174d1af0e05SCorentin Chary uint8_t quality; 175d1af0e05SCorentin Chary uint8_t compression; 176d1af0e05SCorentin Chary uint8_t pixel24; 177d1af0e05SCorentin Chary Buffer tight; 178d1af0e05SCorentin Chary Buffer tmp; 179d1af0e05SCorentin Chary Buffer zlib; 180d1af0e05SCorentin Chary Buffer gradient; 181d1af0e05SCorentin Chary #ifdef CONFIG_VNC_JPEG 182d1af0e05SCorentin Chary Buffer jpeg; 183d1af0e05SCorentin Chary #endif 184d1af0e05SCorentin Chary #ifdef CONFIG_VNC_PNG 185d1af0e05SCorentin Chary Buffer png; 186d1af0e05SCorentin Chary #endif 187d1af0e05SCorentin Chary int levels[4]; 188d1af0e05SCorentin Chary z_stream stream[4]; 189d1af0e05SCorentin Chary } VncTight; 190d1af0e05SCorentin Chary 191d1af0e05SCorentin Chary typedef struct VncHextile { 192d1af0e05SCorentin Chary VncSendHextileTile *send_tile; 193d1af0e05SCorentin Chary } VncHextile; 194d1af0e05SCorentin Chary 195d1af0e05SCorentin Chary typedef struct VncZlib { 196d1af0e05SCorentin Chary Buffer zlib; 197d1af0e05SCorentin Chary Buffer tmp; 198d1af0e05SCorentin Chary z_stream stream; 199d1af0e05SCorentin Chary int level; 200d1af0e05SCorentin Chary } VncZlib; 201d1af0e05SCorentin Chary 202148954faSCorentin Chary typedef struct VncZrle { 203148954faSCorentin Chary int type; 204148954faSCorentin Chary Buffer fb; 205148954faSCorentin Chary Buffer zrle; 206148954faSCorentin Chary Buffer tmp; 207148954faSCorentin Chary Buffer zlib; 208148954faSCorentin Chary z_stream stream; 209148954faSCorentin Chary VncPalette palette; 210148954faSCorentin Chary } VncZrle; 211148954faSCorentin Chary 212148954faSCorentin Chary typedef struct VncZywrle { 213148954faSCorentin Chary int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT]; 214148954faSCorentin Chary } VncZywrle; 215148954faSCorentin Chary 216bd023f95SCorentin Chary struct VncRect 217bd023f95SCorentin Chary { 218bd023f95SCorentin Chary int x; 219bd023f95SCorentin Chary int y; 220bd023f95SCorentin Chary int w; 221bd023f95SCorentin Chary int h; 222bd023f95SCorentin Chary }; 223bd023f95SCorentin Chary 224bd023f95SCorentin Chary struct VncRectEntry 225bd023f95SCorentin Chary { 226bd023f95SCorentin Chary struct VncRect rect; 227bd023f95SCorentin Chary QLIST_ENTRY(VncRectEntry) next; 228bd023f95SCorentin Chary }; 229bd023f95SCorentin Chary 230bd023f95SCorentin Chary struct VncJob 231bd023f95SCorentin Chary { 232bd023f95SCorentin Chary VncState *vs; 233bd023f95SCorentin Chary 234bd023f95SCorentin Chary QLIST_HEAD(, VncRectEntry) rectangles; 235bd023f95SCorentin Chary QTAILQ_ENTRY(VncJob) next; 236bd023f95SCorentin Chary }; 237bd023f95SCorentin Chary 2383e230dd2SCorentin Chary struct VncState 2393e230dd2SCorentin Chary { 2403e230dd2SCorentin Chary int csock; 2413e230dd2SCorentin Chary 2423e230dd2SCorentin Chary DisplayState *ds; 24323bfe28fSStefan Weil DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS); 2447d964c9dSCorentin Chary uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in 2457d964c9dSCorentin Chary * vnc-jobs-async.c */ 2463e230dd2SCorentin Chary 2473e230dd2SCorentin Chary VncDisplay *vd; 2483e230dd2SCorentin Chary int need_update; 2493e230dd2SCorentin Chary int force_update; 2503e230dd2SCorentin Chary uint32_t features; 2513e230dd2SCorentin Chary int absolute; 2523e230dd2SCorentin Chary int last_x; 2533e230dd2SCorentin Chary int last_y; 2543e230dd2SCorentin Chary int client_width; 2553e230dd2SCorentin Chary int client_height; 2568cf36489SGerd Hoffmann VncShareMode share_mode; 2573e230dd2SCorentin Chary 2583e230dd2SCorentin Chary uint32_t vnc_encoding; 2593e230dd2SCorentin Chary 2603e230dd2SCorentin Chary int major; 2613e230dd2SCorentin Chary int minor; 2623e230dd2SCorentin Chary 2637e7e2ebcSDaniel P. Berrange int auth; 2643e230dd2SCorentin Chary char challenge[VNC_AUTH_CHALLENGE_SIZE]; 2653e230dd2SCorentin Chary #ifdef CONFIG_VNC_TLS 2667e7e2ebcSDaniel P. Berrange int subauth; /* Used by VeNCrypt */ 2673e230dd2SCorentin Chary VncStateTLS tls; 2683e230dd2SCorentin Chary #endif 2693e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 2703e230dd2SCorentin Chary VncStateSASL sasl; 2713e230dd2SCorentin Chary #endif 2723e230dd2SCorentin Chary 2733e230dd2SCorentin Chary QObject *info; 2743e230dd2SCorentin Chary 2753e230dd2SCorentin Chary Buffer output; 2763e230dd2SCorentin Chary Buffer input; 2773e230dd2SCorentin Chary /* current output mode information */ 2783e230dd2SCorentin Chary VncWritePixels *write_pixels; 2799f64916dSGerd Hoffmann PixelFormat client_pf; 2809f64916dSGerd Hoffmann pixman_format_code_t client_format; 2819f64916dSGerd Hoffmann bool client_be; 2823e230dd2SCorentin Chary 2833e230dd2SCorentin Chary CaptureVoiceOut *audio_cap; 2843e230dd2SCorentin Chary struct audsettings as; 2853e230dd2SCorentin Chary 2863e230dd2SCorentin Chary VncReadEvent *read_handler; 2873e230dd2SCorentin Chary size_t read_handler_expect; 2883e230dd2SCorentin Chary /* input */ 2893e230dd2SCorentin Chary uint8_t modifiers_state[256]; 2903e230dd2SCorentin Chary QEMUPutLEDEntry *led; 2913e230dd2SCorentin Chary 292bd023f95SCorentin Chary bool abort; 293bd023f95SCorentin Chary QemuMutex output_mutex; 294175b2a6eSCorentin Chary QEMUBH *bh; 295175b2a6eSCorentin Chary Buffer jobs_buffer; 296bd023f95SCorentin Chary 297bd023f95SCorentin Chary /* Encoding specific, if you add something here, don't forget to 298bd023f95SCorentin Chary * update vnc_async_encoding_start() 299bd023f95SCorentin Chary */ 300d1af0e05SCorentin Chary VncTight tight; 301d1af0e05SCorentin Chary VncZlib zlib; 302d1af0e05SCorentin Chary VncHextile hextile; 303148954faSCorentin Chary VncZrle zrle; 304148954faSCorentin Chary VncZywrle zywrle; 3053e230dd2SCorentin Chary 3063e230dd2SCorentin Chary Notifier mouse_mode_notifier; 3073e230dd2SCorentin Chary 3083e230dd2SCorentin Chary QTAILQ_ENTRY(VncState) next; 3093e230dd2SCorentin Chary }; 3103e230dd2SCorentin Chary 3113e230dd2SCorentin Chary 3123e230dd2SCorentin Chary /***************************************************************************** 3133e230dd2SCorentin Chary * 3143e230dd2SCorentin Chary * Authentication modes 3153e230dd2SCorentin Chary * 3163e230dd2SCorentin Chary *****************************************************************************/ 3173e230dd2SCorentin Chary 3183e230dd2SCorentin Chary enum { 3193e230dd2SCorentin Chary VNC_AUTH_INVALID = 0, 3203e230dd2SCorentin Chary VNC_AUTH_NONE = 1, 3213e230dd2SCorentin Chary VNC_AUTH_VNC = 2, 3223e230dd2SCorentin Chary VNC_AUTH_RA2 = 5, 3233e230dd2SCorentin Chary VNC_AUTH_RA2NE = 6, 3243e230dd2SCorentin Chary VNC_AUTH_TIGHT = 16, 3253e230dd2SCorentin Chary VNC_AUTH_ULTRA = 17, 3263e230dd2SCorentin Chary VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */ 3273e230dd2SCorentin Chary VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */ 3283e230dd2SCorentin Chary VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ 3293e230dd2SCorentin Chary }; 3303e230dd2SCorentin Chary 3313e230dd2SCorentin Chary enum { 3323e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_PLAIN = 256, 3333e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSNONE = 257, 3343e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSVNC = 258, 3353e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSPLAIN = 259, 3363e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509NONE = 260, 3373e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509VNC = 261, 3383e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509PLAIN = 262, 3393e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509SASL = 263, 3403e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSSASL = 264, 3413e230dd2SCorentin Chary }; 3423e230dd2SCorentin Chary 3433e230dd2SCorentin Chary 3443e230dd2SCorentin Chary /***************************************************************************** 3453e230dd2SCorentin Chary * 3463e230dd2SCorentin Chary * Encoding types 3473e230dd2SCorentin Chary * 3483e230dd2SCorentin Chary *****************************************************************************/ 3493e230dd2SCorentin Chary 3503e230dd2SCorentin Chary #define VNC_ENCODING_RAW 0x00000000 3513e230dd2SCorentin Chary #define VNC_ENCODING_COPYRECT 0x00000001 3523e230dd2SCorentin Chary #define VNC_ENCODING_RRE 0x00000002 3533e230dd2SCorentin Chary #define VNC_ENCODING_CORRE 0x00000004 3543e230dd2SCorentin Chary #define VNC_ENCODING_HEXTILE 0x00000005 3553e230dd2SCorentin Chary #define VNC_ENCODING_ZLIB 0x00000006 3563e230dd2SCorentin Chary #define VNC_ENCODING_TIGHT 0x00000007 3573e230dd2SCorentin Chary #define VNC_ENCODING_ZLIBHEX 0x00000008 3583e230dd2SCorentin Chary #define VNC_ENCODING_TRLE 0x0000000f 3593e230dd2SCorentin Chary #define VNC_ENCODING_ZRLE 0x00000010 3603e230dd2SCorentin Chary #define VNC_ENCODING_ZYWRLE 0x00000011 3613e230dd2SCorentin Chary #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */ 3623e230dd2SCorentin Chary #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */ 3633e230dd2SCorentin Chary #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */ 3643e230dd2SCorentin Chary #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */ 3653e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */ 3663e230dd2SCorentin Chary #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */ 3673e230dd2SCorentin Chary #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */ 3683e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */ 3693e230dd2SCorentin Chary #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */ 3703e230dd2SCorentin Chary #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */ 371efe556adSCorentin Chary #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */ 3723e230dd2SCorentin Chary #define VNC_ENCODING_WMVi 0x574D5669 3733e230dd2SCorentin Chary 3743e230dd2SCorentin Chary /***************************************************************************** 3753e230dd2SCorentin Chary * 3763e230dd2SCorentin Chary * Other tight constants 3773e230dd2SCorentin Chary * 3783e230dd2SCorentin Chary *****************************************************************************/ 3793e230dd2SCorentin Chary 3803e230dd2SCorentin Chary /* 3813e230dd2SCorentin Chary * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC. 3823e230dd2SCorentin Chary */ 3833e230dd2SCorentin Chary 3843e230dd2SCorentin Chary #define VNC_TIGHT_CCB_RESET_MASK (0x0f) 3853e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4) 3863e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4) 3873e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4) 388efe556adSCorentin Chary #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4) 3893e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4) 3903e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4) 3913e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4) 3923e230dd2SCorentin Chary 3933e230dd2SCorentin Chary /***************************************************************************** 3943e230dd2SCorentin Chary * 3953e230dd2SCorentin Chary * Features 3963e230dd2SCorentin Chary * 3973e230dd2SCorentin Chary *****************************************************************************/ 3983e230dd2SCorentin Chary 3993e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE 0 4003e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE 1 4013e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE 2 4023e230dd2SCorentin Chary #define VNC_FEATURE_WMVI 3 4033e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT 4 4043e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB 5 4053e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT 6 4063e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR 7 407efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG 8 408148954faSCorentin Chary #define VNC_FEATURE_ZRLE 9 409148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE 10 4103e230dd2SCorentin Chary 4113e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE) 4123e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE) 4133e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE) 4143e230dd2SCorentin Chary #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI) 4153e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT) 4163e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB) 4173e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT) 4183e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR) 419efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG) 420148954faSCorentin Chary #define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE) 421148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE) 4223e230dd2SCorentin Chary 4233e230dd2SCorentin Chary 4243e230dd2SCorentin Chary /* Client -> Server message IDs */ 4253e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0 4263e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_ENCODINGS 2 4273e230dd2SCorentin Chary #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3 4283e230dd2SCorentin Chary #define VNC_MSG_CLIENT_KEY_EVENT 4 4293e230dd2SCorentin Chary #define VNC_MSG_CLIENT_POINTER_EVENT 5 4303e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CUT_TEXT 6 4313e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_0 127 4323e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CALL_CONTROL 249 4333e230dd2SCorentin Chary #define VNC_MSG_CLIENT_XVP 250 4343e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251 4353e230dd2SCorentin Chary #define VNC_MSG_CLIENT_TIGHT 252 4363e230dd2SCorentin Chary #define VNC_MSG_CLIENT_GII 253 4373e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_1 254 4383e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU 255 4393e230dd2SCorentin Chary 4403e230dd2SCorentin Chary /* Server -> Client message IDs */ 4413e230dd2SCorentin Chary #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0 4423e230dd2SCorentin Chary #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1 4433e230dd2SCorentin Chary #define VNC_MSG_SERVER_BELL 2 4443e230dd2SCorentin Chary #define VNC_MSG_SERVER_CUT_TEXT 3 4453e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_0 127 4463e230dd2SCorentin Chary #define VNC_MSG_SERVER_CALL_CONTROL 249 4473e230dd2SCorentin Chary #define VNC_MSG_SERVER_XVP 250 4483e230dd2SCorentin Chary #define VNC_MSG_SERVER_TIGHT 252 4493e230dd2SCorentin Chary #define VNC_MSG_SERVER_GII 253 4503e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_1 254 4513e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU 255 4523e230dd2SCorentin Chary 4533e230dd2SCorentin Chary 4543e230dd2SCorentin Chary 4553e230dd2SCorentin Chary /* QEMU client -> server message IDs */ 4563e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0 4573e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO 1 4583e230dd2SCorentin Chary 4593e230dd2SCorentin Chary /* QEMU server -> client message IDs */ 4603e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO 1 4613e230dd2SCorentin Chary 4623e230dd2SCorentin Chary 4633e230dd2SCorentin Chary 4643e230dd2SCorentin Chary /* QEMU client -> server audio message IDs */ 4653e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0 4663e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1 4673e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2 4683e230dd2SCorentin Chary 4693e230dd2SCorentin Chary /* QEMU server -> client audio message IDs */ 4703e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_END 0 4713e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1 4723e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2 4733e230dd2SCorentin Chary 4743e230dd2SCorentin Chary 4753e230dd2SCorentin Chary /***************************************************************************** 4763e230dd2SCorentin Chary * 4773e230dd2SCorentin Chary * Internal APIs 4783e230dd2SCorentin Chary * 4793e230dd2SCorentin Chary *****************************************************************************/ 4803e230dd2SCorentin Chary 4813e230dd2SCorentin Chary /* Event loop functions */ 4823e230dd2SCorentin Chary void vnc_client_read(void *opaque); 4833e230dd2SCorentin Chary void vnc_client_write(void *opaque); 4843e230dd2SCorentin Chary 4853e230dd2SCorentin Chary long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen); 4863e230dd2SCorentin Chary long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen); 4873e230dd2SCorentin Chary 4883e230dd2SCorentin Chary /* Protocol I/O functions */ 4893e230dd2SCorentin Chary void vnc_write(VncState *vs, const void *data, size_t len); 4903e230dd2SCorentin Chary void vnc_write_u32(VncState *vs, uint32_t value); 4913e230dd2SCorentin Chary void vnc_write_s32(VncState *vs, int32_t value); 4923e230dd2SCorentin Chary void vnc_write_u16(VncState *vs, uint16_t value); 4933e230dd2SCorentin Chary void vnc_write_u8(VncState *vs, uint8_t value); 4943e230dd2SCorentin Chary void vnc_flush(VncState *vs); 4953e230dd2SCorentin Chary void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting); 4963e230dd2SCorentin Chary 4973e230dd2SCorentin Chary 4983e230dd2SCorentin Chary /* Buffer I/O functions */ 4993e230dd2SCorentin Chary uint32_t read_u32(uint8_t *data, size_t offset); 5003e230dd2SCorentin Chary 5013e230dd2SCorentin Chary /* Protocol stage functions */ 5023e230dd2SCorentin Chary void vnc_client_error(VncState *vs); 5033e230dd2SCorentin Chary int vnc_client_io_error(VncState *vs, int ret, int last_errno); 5043e230dd2SCorentin Chary 5053e230dd2SCorentin Chary void start_client_init(VncState *vs); 5063e230dd2SCorentin Chary void start_auth_vnc(VncState *vs); 5073e230dd2SCorentin Chary 5083e230dd2SCorentin Chary /* Buffer management */ 5093e230dd2SCorentin Chary void buffer_reserve(Buffer *buffer, size_t len); 5103e230dd2SCorentin Chary void buffer_reset(Buffer *buffer); 5113e230dd2SCorentin Chary void buffer_free(Buffer *buffer); 5123e230dd2SCorentin Chary void buffer_append(Buffer *buffer, const void *data, size_t len); 5133e230dd2SCorentin Chary 5143e230dd2SCorentin Chary 5153e230dd2SCorentin Chary /* Misc helpers */ 5163e230dd2SCorentin Chary 5173e230dd2SCorentin Chary char *vnc_socket_local_addr(const char *format, int fd); 5183e230dd2SCorentin Chary char *vnc_socket_remote_addr(const char *format, int fd); 5193e230dd2SCorentin Chary 520efe556adSCorentin Chary static inline uint32_t vnc_has_feature(VncState *vs, int feature) { 521efe556adSCorentin Chary return (vs->features & (1 << feature)); 522efe556adSCorentin Chary } 523efe556adSCorentin Chary 5243e230dd2SCorentin Chary /* Framebuffer */ 5253e230dd2SCorentin Chary void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, 5263e230dd2SCorentin Chary int32_t encoding); 5273e230dd2SCorentin Chary 5289f64916dSGerd Hoffmann /* server fb is in PIXMAN_x8r8g8b8 */ 5299f64916dSGerd Hoffmann #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8) 5309f64916dSGerd Hoffmann #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT)) 5319f64916dSGerd Hoffmann #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8) 5329f64916dSGerd Hoffmann 5339f64916dSGerd Hoffmann void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y); 5349f64916dSGerd Hoffmann int vnc_server_fb_stride(VncDisplay *vd); 5359f64916dSGerd Hoffmann 5363e230dd2SCorentin Chary void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v); 537999342a0SCorentin Chary double vnc_update_freq(VncState *vs, int x, int y, int w, int h); 5387d964c9dSCorentin Chary void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h); 5393e230dd2SCorentin Chary 5403e230dd2SCorentin Chary /* Encodings */ 541bd023f95SCorentin Chary int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 542bd023f95SCorentin Chary 5433e230dd2SCorentin Chary int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 5443e230dd2SCorentin Chary 5453e230dd2SCorentin Chary int vnc_hextile_send_framebuffer_update(VncState *vs, int x, 5463e230dd2SCorentin Chary int y, int w, int h); 5473e230dd2SCorentin Chary void vnc_hextile_set_pixel_conversion(VncState *vs, int generic); 5483e230dd2SCorentin Chary 5493e230dd2SCorentin Chary void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size); 5503e230dd2SCorentin Chary void vnc_zlib_zfree(void *x, void *addr); 5513e230dd2SCorentin Chary int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 5523e230dd2SCorentin Chary void vnc_zlib_clear(VncState *vs); 5533e230dd2SCorentin Chary 5543e230dd2SCorentin Chary int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 555efe556adSCorentin Chary int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y, 556efe556adSCorentin Chary int w, int h); 5573e230dd2SCorentin Chary void vnc_tight_clear(VncState *vs); 5583e230dd2SCorentin Chary 559148954faSCorentin Chary int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 560148954faSCorentin Chary int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 561148954faSCorentin Chary void vnc_zrle_clear(VncState *vs); 562148954faSCorentin Chary 5633e230dd2SCorentin Chary #endif /* __QEMU_VNC_H */ 564