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" 311de7afc9SPaolo Bonzini #include "qemu/queue.h" 321de7afc9SPaolo Bonzini #include "qemu/thread.h" 3328ecbaeeSPaolo Bonzini #include "ui/console.h" 343e230dd2SCorentin Chary #include "audio/audio.h" 351de7afc9SPaolo Bonzini #include "qemu/bitmap.h" 36*3e305e4aSDaniel P. Berrange #include "crypto/tlssession.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" 43fb6ba0d5SWenchao Xia #include "qapi-types.h" 443e230dd2SCorentin Chary 453e230dd2SCorentin Chary // #define _VNC_DEBUG 1 463e230dd2SCorentin Chary 473e230dd2SCorentin Chary #ifdef _VNC_DEBUG 483e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) 493e230dd2SCorentin Chary #else 503e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { } while (0) 513e230dd2SCorentin Chary #endif 523e230dd2SCorentin Chary 533e230dd2SCorentin Chary /***************************************************************************** 543e230dd2SCorentin Chary * 553e230dd2SCorentin Chary * Core data structures 563e230dd2SCorentin Chary * 573e230dd2SCorentin Chary *****************************************************************************/ 583e230dd2SCorentin Chary 593e230dd2SCorentin Chary typedef struct Buffer 603e230dd2SCorentin Chary { 613e230dd2SCorentin Chary size_t capacity; 623e230dd2SCorentin Chary size_t offset; 633e230dd2SCorentin Chary uint8_t *buffer; 643e230dd2SCorentin Chary } Buffer; 653e230dd2SCorentin Chary 663e230dd2SCorentin Chary typedef struct VncState VncState; 67bd023f95SCorentin Chary typedef struct VncJob VncJob; 68bd023f95SCorentin Chary typedef struct VncRect VncRect; 69bd023f95SCorentin Chary typedef struct VncRectEntry VncRectEntry; 703e230dd2SCorentin Chary 713e230dd2SCorentin Chary typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len); 723e230dd2SCorentin Chary 739f64916dSGerd Hoffmann typedef void VncWritePixels(VncState *vs, void *data, int size); 743e230dd2SCorentin Chary 753e230dd2SCorentin Chary typedef void VncSendHextileTile(VncState *vs, 763e230dd2SCorentin Chary int x, int y, int w, int h, 773e230dd2SCorentin Chary void *last_bg, 783e230dd2SCorentin Chary void *last_fg, 793e230dd2SCorentin Chary int *has_bg, int *has_fg); 803e230dd2SCorentin Chary 81b4c85ddcSPeter Lieven /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented 82bea60dd7SPeter Lieven * by one bit in the dirty bitmap, should be a power of 2 */ 83b4c85ddcSPeter Lieven #define VNC_DIRTY_PIXELS_PER_BIT 16 84b4c85ddcSPeter Lieven 85bea60dd7SPeter Lieven /* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */ 86bea60dd7SPeter Lieven 87bea60dd7SPeter Lieven #define VNC_MAX_WIDTH ROUND_UP(2560, VNC_DIRTY_PIXELS_PER_BIT) 88bea60dd7SPeter Lieven #define VNC_MAX_HEIGHT 2048 89bea60dd7SPeter Lieven 9023bfe28fSStefan Weil /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */ 91b4c85ddcSPeter Lieven #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT) 923e230dd2SCorentin Chary 9312b316d4SPeter Lieven /* VNC_DIRTY_BPL (BPL = bits per line) might be greater than 9412b316d4SPeter Lieven * VNC_DIRTY_BITS due to alignment */ 9512b316d4SPeter Lieven #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE) 9612b316d4SPeter Lieven 97999342a0SCorentin Chary #define VNC_STAT_RECT 64 98999342a0SCorentin Chary #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) 99999342a0SCorentin Chary #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT) 100999342a0SCorentin Chary 1013e230dd2SCorentin Chary #define VNC_AUTH_CHALLENGE_SIZE 16 1023e230dd2SCorentin Chary 1033e230dd2SCorentin Chary typedef struct VncDisplay VncDisplay; 1043e230dd2SCorentin Chary 1053e230dd2SCorentin Chary #include "vnc-auth-vencrypt.h" 1063e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 1073e230dd2SCorentin Chary #include "vnc-auth-sasl.h" 1083e230dd2SCorentin Chary #endif 1097536ee4bSTim Hardeck #include "vnc-ws.h" 1103e230dd2SCorentin Chary 111999342a0SCorentin Chary struct VncRectStat 112999342a0SCorentin Chary { 113999342a0SCorentin Chary /* time of last 10 updates, to find update frequency */ 114999342a0SCorentin Chary struct timeval times[10]; 115999342a0SCorentin Chary int idx; 116999342a0SCorentin Chary 117999342a0SCorentin Chary double freq; /* Update frequency (in Hz) */ 118999342a0SCorentin Chary bool updated; /* Already updated during this refresh */ 119999342a0SCorentin Chary }; 120999342a0SCorentin Chary 121999342a0SCorentin Chary typedef struct VncRectStat VncRectStat; 122999342a0SCorentin Chary 1233e230dd2SCorentin Chary struct VncSurface 1243e230dd2SCorentin Chary { 125999342a0SCorentin Chary struct timeval last_freq_check; 126bea60dd7SPeter Lieven DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], 127bea60dd7SPeter Lieven VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT); 128999342a0SCorentin Chary VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS]; 1299f64916dSGerd Hoffmann pixman_image_t *fb; 1309f64916dSGerd Hoffmann pixman_format_code_t format; 1313e230dd2SCorentin Chary }; 1323e230dd2SCorentin Chary 1338cf36489SGerd Hoffmann typedef enum VncShareMode { 1348cf36489SGerd Hoffmann VNC_SHARE_MODE_CONNECTING = 1, 1358cf36489SGerd Hoffmann VNC_SHARE_MODE_SHARED, 1368cf36489SGerd Hoffmann VNC_SHARE_MODE_EXCLUSIVE, 1378cf36489SGerd Hoffmann VNC_SHARE_MODE_DISCONNECTED, 1388cf36489SGerd Hoffmann } VncShareMode; 1398cf36489SGerd Hoffmann 1408cf36489SGerd Hoffmann typedef enum VncSharePolicy { 1418cf36489SGerd Hoffmann VNC_SHARE_POLICY_IGNORE = 1, 1428cf36489SGerd Hoffmann VNC_SHARE_POLICY_ALLOW_EXCLUSIVE, 1438cf36489SGerd Hoffmann VNC_SHARE_POLICY_FORCE_SHARED, 1448cf36489SGerd Hoffmann } VncSharePolicy; 1458cf36489SGerd Hoffmann 1463e230dd2SCorentin Chary struct VncDisplay 1473e230dd2SCorentin Chary { 1483e230dd2SCorentin Chary QTAILQ_HEAD(, VncState) clients; 149e5f34cddSGerd Hoffmann int num_connecting; 150e5f34cddSGerd Hoffmann int num_shared; 1518cf36489SGerd Hoffmann int num_exclusive; 152e5f34cddSGerd Hoffmann int connections_limit; 1538cf36489SGerd Hoffmann VncSharePolicy share_policy; 1543e230dd2SCorentin Chary int lsock; 1557536ee4bSTim Hardeck int lwebsock; 156bf7aa45eSGerd Hoffmann bool ws_enabled; 157d39fa6d8SGerd Hoffmann DisplaySurface *ds; 15821ef45d7SGerd Hoffmann DisplayChangeListener dcl; 1593e230dd2SCorentin Chary kbd_layout_t *kbd_layout; 1603e230dd2SCorentin Chary int lock_key_sync; 161bd023f95SCorentin Chary QemuMutex mutex; 1623e230dd2SCorentin Chary 1633e230dd2SCorentin Chary QEMUCursor *cursor; 1643e230dd2SCorentin Chary int cursor_msize; 1653e230dd2SCorentin Chary uint8_t *cursor_mask; 1663e230dd2SCorentin Chary 1673e230dd2SCorentin Chary struct VncSurface guest; /* guest visible surface (aka ds->surface) */ 1689f64916dSGerd Hoffmann pixman_image_t *server; /* vnc server surface */ 1693e230dd2SCorentin Chary 170d616ccc5SGerd Hoffmann const char *id; 171d616ccc5SGerd Hoffmann QTAILQ_ENTRY(VncDisplay) next; 172bf7aa45eSGerd Hoffmann bool enabled; 173bf7aa45eSGerd Hoffmann bool is_unix; 1743e230dd2SCorentin Chary char *password; 1753c9405a0SGerd Hoffmann time_t expires; 1763e230dd2SCorentin Chary int auth; 177d169f04bSDaniel P. Berrange int subauth; /* Used by VeNCrypt */ 178f9148c8aSDaniel P. Berrange int ws_auth; /* Used by websockets */ 179f9148c8aSDaniel P. Berrange bool ws_tls; /* Used by websockets */ 1803e230dd2SCorentin Chary bool lossy; 18180e0c8c3SCorentin Chary bool non_adaptive; 182*3e305e4aSDaniel P. Berrange QCryptoTLSCreds *tlscreds; 183*3e305e4aSDaniel P. Berrange char *tlsaclname; 1843e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 1853e230dd2SCorentin Chary VncDisplaySASL sasl; 1863e230dd2SCorentin Chary #endif 1873e230dd2SCorentin Chary }; 1883e230dd2SCorentin Chary 189d1af0e05SCorentin Chary typedef struct VncTight { 190d1af0e05SCorentin Chary int type; 191d1af0e05SCorentin Chary uint8_t quality; 192d1af0e05SCorentin Chary uint8_t compression; 193d1af0e05SCorentin Chary uint8_t pixel24; 194d1af0e05SCorentin Chary Buffer tight; 195d1af0e05SCorentin Chary Buffer tmp; 196d1af0e05SCorentin Chary Buffer zlib; 197d1af0e05SCorentin Chary Buffer gradient; 198d1af0e05SCorentin Chary #ifdef CONFIG_VNC_JPEG 199d1af0e05SCorentin Chary Buffer jpeg; 200d1af0e05SCorentin Chary #endif 201d1af0e05SCorentin Chary #ifdef CONFIG_VNC_PNG 202d1af0e05SCorentin Chary Buffer png; 203d1af0e05SCorentin Chary #endif 204d1af0e05SCorentin Chary int levels[4]; 205d1af0e05SCorentin Chary z_stream stream[4]; 206d1af0e05SCorentin Chary } VncTight; 207d1af0e05SCorentin Chary 208d1af0e05SCorentin Chary typedef struct VncHextile { 209d1af0e05SCorentin Chary VncSendHextileTile *send_tile; 210d1af0e05SCorentin Chary } VncHextile; 211d1af0e05SCorentin Chary 212d1af0e05SCorentin Chary typedef struct VncZlib { 213d1af0e05SCorentin Chary Buffer zlib; 214d1af0e05SCorentin Chary Buffer tmp; 215d1af0e05SCorentin Chary z_stream stream; 216d1af0e05SCorentin Chary int level; 217d1af0e05SCorentin Chary } VncZlib; 218d1af0e05SCorentin Chary 219148954faSCorentin Chary typedef struct VncZrle { 220148954faSCorentin Chary int type; 221148954faSCorentin Chary Buffer fb; 222148954faSCorentin Chary Buffer zrle; 223148954faSCorentin Chary Buffer tmp; 224148954faSCorentin Chary Buffer zlib; 225148954faSCorentin Chary z_stream stream; 226148954faSCorentin Chary VncPalette palette; 227148954faSCorentin Chary } VncZrle; 228148954faSCorentin Chary 229148954faSCorentin Chary typedef struct VncZywrle { 230148954faSCorentin Chary int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT]; 231148954faSCorentin Chary } VncZywrle; 232148954faSCorentin Chary 233bd023f95SCorentin Chary struct VncRect 234bd023f95SCorentin Chary { 235bd023f95SCorentin Chary int x; 236bd023f95SCorentin Chary int y; 237bd023f95SCorentin Chary int w; 238bd023f95SCorentin Chary int h; 239bd023f95SCorentin Chary }; 240bd023f95SCorentin Chary 241bd023f95SCorentin Chary struct VncRectEntry 242bd023f95SCorentin Chary { 243bd023f95SCorentin Chary struct VncRect rect; 244bd023f95SCorentin Chary QLIST_ENTRY(VncRectEntry) next; 245bd023f95SCorentin Chary }; 246bd023f95SCorentin Chary 247bd023f95SCorentin Chary struct VncJob 248bd023f95SCorentin Chary { 249bd023f95SCorentin Chary VncState *vs; 250bd023f95SCorentin Chary 251bd023f95SCorentin Chary QLIST_HEAD(, VncRectEntry) rectangles; 252bd023f95SCorentin Chary QTAILQ_ENTRY(VncJob) next; 253bd023f95SCorentin Chary }; 254bd023f95SCorentin Chary 2553e230dd2SCorentin Chary struct VncState 2563e230dd2SCorentin Chary { 2573e230dd2SCorentin Chary int csock; 2583e230dd2SCorentin Chary 25923bfe28fSStefan Weil DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS); 2607d964c9dSCorentin Chary uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in 2617d964c9dSCorentin Chary * vnc-jobs-async.c */ 2623e230dd2SCorentin Chary 2633e230dd2SCorentin Chary VncDisplay *vd; 2643e230dd2SCorentin Chary int need_update; 2653e230dd2SCorentin Chary int force_update; 26663658280SGerd Hoffmann int has_dirty; 2673e230dd2SCorentin Chary uint32_t features; 2683e230dd2SCorentin Chary int absolute; 2693e230dd2SCorentin Chary int last_x; 2703e230dd2SCorentin Chary int last_y; 27114768ebaSGerd Hoffmann uint32_t last_bmask; 2723e230dd2SCorentin Chary int client_width; 2733e230dd2SCorentin Chary int client_height; 2748cf36489SGerd Hoffmann VncShareMode share_mode; 2753e230dd2SCorentin Chary 2763e230dd2SCorentin Chary uint32_t vnc_encoding; 2773e230dd2SCorentin Chary 2783e230dd2SCorentin Chary int major; 2793e230dd2SCorentin Chary int minor; 2803e230dd2SCorentin Chary 2817e7e2ebcSDaniel P. Berrange int auth; 282d169f04bSDaniel P. Berrange int subauth; /* Used by VeNCrypt */ 2833e230dd2SCorentin Chary char challenge[VNC_AUTH_CHALLENGE_SIZE]; 284*3e305e4aSDaniel P. Berrange QCryptoTLSSession *tls; 2853e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL 2863e230dd2SCorentin Chary VncStateSASL sasl; 2873e230dd2SCorentin Chary #endif 2887536ee4bSTim Hardeck bool encode_ws; 2897536ee4bSTim Hardeck bool websocket; 2903e230dd2SCorentin Chary 291fb6ba0d5SWenchao Xia VncClientInfo *info; 2923e230dd2SCorentin Chary 2933e230dd2SCorentin Chary Buffer output; 2943e230dd2SCorentin Chary Buffer input; 2957536ee4bSTim Hardeck Buffer ws_input; 2967536ee4bSTim Hardeck Buffer ws_output; 297a2bebfd6SDaniel P. Berrange size_t ws_payload_remain; 298a2bebfd6SDaniel P. Berrange WsMask ws_payload_mask; 2993e230dd2SCorentin Chary /* current output mode information */ 3003e230dd2SCorentin Chary VncWritePixels *write_pixels; 3019f64916dSGerd Hoffmann PixelFormat client_pf; 3029f64916dSGerd Hoffmann pixman_format_code_t client_format; 3039f64916dSGerd Hoffmann bool client_be; 3043e230dd2SCorentin Chary 3053e230dd2SCorentin Chary CaptureVoiceOut *audio_cap; 3063e230dd2SCorentin Chary struct audsettings as; 3073e230dd2SCorentin Chary 3083e230dd2SCorentin Chary VncReadEvent *read_handler; 3093e230dd2SCorentin Chary size_t read_handler_expect; 3103e230dd2SCorentin Chary /* input */ 3113e230dd2SCorentin Chary uint8_t modifiers_state[256]; 3123e230dd2SCorentin Chary QEMUPutLEDEntry *led; 3133e230dd2SCorentin Chary 314bd023f95SCorentin Chary bool abort; 3156fd8e79aSTim Hardeck bool initialized; 316bd023f95SCorentin Chary QemuMutex output_mutex; 317175b2a6eSCorentin Chary QEMUBH *bh; 318175b2a6eSCorentin Chary Buffer jobs_buffer; 319bd023f95SCorentin Chary 320bd023f95SCorentin Chary /* Encoding specific, if you add something here, don't forget to 321bd023f95SCorentin Chary * update vnc_async_encoding_start() 322bd023f95SCorentin Chary */ 323d1af0e05SCorentin Chary VncTight tight; 324d1af0e05SCorentin Chary VncZlib zlib; 325d1af0e05SCorentin Chary VncHextile hextile; 326148954faSCorentin Chary VncZrle zrle; 327148954faSCorentin Chary VncZywrle zywrle; 3283e230dd2SCorentin Chary 3293e230dd2SCorentin Chary Notifier mouse_mode_notifier; 3303e230dd2SCorentin Chary 3313e230dd2SCorentin Chary QTAILQ_ENTRY(VncState) next; 3323e230dd2SCorentin Chary }; 3333e230dd2SCorentin Chary 3343e230dd2SCorentin Chary 3353e230dd2SCorentin Chary /***************************************************************************** 3363e230dd2SCorentin Chary * 3373e230dd2SCorentin Chary * Authentication modes 3383e230dd2SCorentin Chary * 3393e230dd2SCorentin Chary *****************************************************************************/ 3403e230dd2SCorentin Chary 3413e230dd2SCorentin Chary enum { 3423e230dd2SCorentin Chary VNC_AUTH_INVALID = 0, 3433e230dd2SCorentin Chary VNC_AUTH_NONE = 1, 3443e230dd2SCorentin Chary VNC_AUTH_VNC = 2, 3453e230dd2SCorentin Chary VNC_AUTH_RA2 = 5, 3463e230dd2SCorentin Chary VNC_AUTH_RA2NE = 6, 3473e230dd2SCorentin Chary VNC_AUTH_TIGHT = 16, 3483e230dd2SCorentin Chary VNC_AUTH_ULTRA = 17, 3493e230dd2SCorentin Chary VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */ 3503e230dd2SCorentin Chary VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */ 3513e230dd2SCorentin Chary VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ 3523e230dd2SCorentin Chary }; 3533e230dd2SCorentin Chary 3543e230dd2SCorentin Chary enum { 3553e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_PLAIN = 256, 3563e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSNONE = 257, 3573e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSVNC = 258, 3583e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSPLAIN = 259, 3593e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509NONE = 260, 3603e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509VNC = 261, 3613e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509PLAIN = 262, 3623e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_X509SASL = 263, 3633e230dd2SCorentin Chary VNC_AUTH_VENCRYPT_TLSSASL = 264, 3643e230dd2SCorentin Chary }; 3653e230dd2SCorentin Chary 3663e230dd2SCorentin Chary 3673e230dd2SCorentin Chary /***************************************************************************** 3683e230dd2SCorentin Chary * 3693e230dd2SCorentin Chary * Encoding types 3703e230dd2SCorentin Chary * 3713e230dd2SCorentin Chary *****************************************************************************/ 3723e230dd2SCorentin Chary 3733e230dd2SCorentin Chary #define VNC_ENCODING_RAW 0x00000000 3743e230dd2SCorentin Chary #define VNC_ENCODING_COPYRECT 0x00000001 3753e230dd2SCorentin Chary #define VNC_ENCODING_RRE 0x00000002 3763e230dd2SCorentin Chary #define VNC_ENCODING_CORRE 0x00000004 3773e230dd2SCorentin Chary #define VNC_ENCODING_HEXTILE 0x00000005 3783e230dd2SCorentin Chary #define VNC_ENCODING_ZLIB 0x00000006 3793e230dd2SCorentin Chary #define VNC_ENCODING_TIGHT 0x00000007 3803e230dd2SCorentin Chary #define VNC_ENCODING_ZLIBHEX 0x00000008 3813e230dd2SCorentin Chary #define VNC_ENCODING_TRLE 0x0000000f 3823e230dd2SCorentin Chary #define VNC_ENCODING_ZRLE 0x00000010 3833e230dd2SCorentin Chary #define VNC_ENCODING_ZYWRLE 0x00000011 3843e230dd2SCorentin Chary #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */ 3853e230dd2SCorentin Chary #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */ 3863e230dd2SCorentin Chary #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */ 3873e230dd2SCorentin Chary #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */ 3883e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */ 3893e230dd2SCorentin Chary #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */ 3903e230dd2SCorentin Chary #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */ 3913e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */ 3923e230dd2SCorentin Chary #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */ 3933e230dd2SCorentin Chary #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */ 394efe556adSCorentin Chary #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */ 395ab99e5c1SLei Li #define VNC_ENCODING_LED_STATE 0XFFFFFEFB /* -261 */ 3963e230dd2SCorentin Chary #define VNC_ENCODING_WMVi 0x574D5669 3973e230dd2SCorentin Chary 3983e230dd2SCorentin Chary /***************************************************************************** 3993e230dd2SCorentin Chary * 4003e230dd2SCorentin Chary * Other tight constants 4013e230dd2SCorentin Chary * 4023e230dd2SCorentin Chary *****************************************************************************/ 4033e230dd2SCorentin Chary 4043e230dd2SCorentin Chary /* 4053e230dd2SCorentin Chary * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC. 4063e230dd2SCorentin Chary */ 4073e230dd2SCorentin Chary 4083e230dd2SCorentin Chary #define VNC_TIGHT_CCB_RESET_MASK (0x0f) 4093e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4) 4103e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4) 4113e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4) 412efe556adSCorentin Chary #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4) 4133e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4) 4143e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4) 4153e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4) 4163e230dd2SCorentin Chary 4173e230dd2SCorentin Chary /***************************************************************************** 4183e230dd2SCorentin Chary * 4193e230dd2SCorentin Chary * Features 4203e230dd2SCorentin Chary * 4213e230dd2SCorentin Chary *****************************************************************************/ 4223e230dd2SCorentin Chary 4233e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE 0 4243e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE 1 4253e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE 2 4263e230dd2SCorentin Chary #define VNC_FEATURE_WMVI 3 4273e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT 4 4283e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB 5 4293e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT 6 4303e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR 7 431efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG 8 432148954faSCorentin Chary #define VNC_FEATURE_ZRLE 9 433148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE 10 434ab99e5c1SLei Li #define VNC_FEATURE_LED_STATE 11 4353e230dd2SCorentin Chary 4363e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE) 4373e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE) 4383e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE) 4393e230dd2SCorentin Chary #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI) 4403e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT) 4413e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB) 4423e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT) 4433e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR) 444efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG) 445148954faSCorentin Chary #define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE) 446148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE) 447ab99e5c1SLei Li #define VNC_FEATURE_LED_STATE_MASK (1 << VNC_FEATURE_LED_STATE) 4483e230dd2SCorentin Chary 4493e230dd2SCorentin Chary 4503e230dd2SCorentin Chary /* Client -> Server message IDs */ 4513e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0 4523e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_ENCODINGS 2 4533e230dd2SCorentin Chary #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3 4543e230dd2SCorentin Chary #define VNC_MSG_CLIENT_KEY_EVENT 4 4553e230dd2SCorentin Chary #define VNC_MSG_CLIENT_POINTER_EVENT 5 4563e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CUT_TEXT 6 4573e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_0 127 4583e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CALL_CONTROL 249 4593e230dd2SCorentin Chary #define VNC_MSG_CLIENT_XVP 250 4603e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251 4613e230dd2SCorentin Chary #define VNC_MSG_CLIENT_TIGHT 252 4623e230dd2SCorentin Chary #define VNC_MSG_CLIENT_GII 253 4633e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_1 254 4643e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU 255 4653e230dd2SCorentin Chary 4663e230dd2SCorentin Chary /* Server -> Client message IDs */ 4673e230dd2SCorentin Chary #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0 4683e230dd2SCorentin Chary #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1 4693e230dd2SCorentin Chary #define VNC_MSG_SERVER_BELL 2 4703e230dd2SCorentin Chary #define VNC_MSG_SERVER_CUT_TEXT 3 4713e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_0 127 4723e230dd2SCorentin Chary #define VNC_MSG_SERVER_CALL_CONTROL 249 4733e230dd2SCorentin Chary #define VNC_MSG_SERVER_XVP 250 4743e230dd2SCorentin Chary #define VNC_MSG_SERVER_TIGHT 252 4753e230dd2SCorentin Chary #define VNC_MSG_SERVER_GII 253 4763e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_1 254 4773e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU 255 4783e230dd2SCorentin Chary 4793e230dd2SCorentin Chary 4803e230dd2SCorentin Chary 4813e230dd2SCorentin Chary /* QEMU client -> server message IDs */ 4823e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0 4833e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO 1 4843e230dd2SCorentin Chary 4853e230dd2SCorentin Chary /* QEMU server -> client message IDs */ 4863e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO 1 4873e230dd2SCorentin Chary 4883e230dd2SCorentin Chary 4893e230dd2SCorentin Chary 4903e230dd2SCorentin Chary /* QEMU client -> server audio message IDs */ 4913e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0 4923e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1 4933e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2 4943e230dd2SCorentin Chary 4953e230dd2SCorentin Chary /* QEMU server -> client audio message IDs */ 4963e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_END 0 4973e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1 4983e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2 4993e230dd2SCorentin Chary 5003e230dd2SCorentin Chary 5013e230dd2SCorentin Chary /***************************************************************************** 5023e230dd2SCorentin Chary * 5033e230dd2SCorentin Chary * Internal APIs 5043e230dd2SCorentin Chary * 5053e230dd2SCorentin Chary *****************************************************************************/ 5063e230dd2SCorentin Chary 5073e230dd2SCorentin Chary /* Event loop functions */ 5083e230dd2SCorentin Chary void vnc_client_read(void *opaque); 5093e230dd2SCorentin Chary void vnc_client_write(void *opaque); 5103e230dd2SCorentin Chary 511fdd1ab6aSDaniel P. Berrange ssize_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen); 512fdd1ab6aSDaniel P. Berrange ssize_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen); 513*3e305e4aSDaniel P. Berrange ssize_t vnc_tls_pull(char *buf, size_t len, void *opaque); 514*3e305e4aSDaniel P. Berrange ssize_t vnc_tls_push(const char *buf, size_t len, void *opaque); 5153e230dd2SCorentin Chary 5163e230dd2SCorentin Chary /* Protocol I/O functions */ 5173e230dd2SCorentin Chary void vnc_write(VncState *vs, const void *data, size_t len); 5183e230dd2SCorentin Chary void vnc_write_u32(VncState *vs, uint32_t value); 5193e230dd2SCorentin Chary void vnc_write_s32(VncState *vs, int32_t value); 5203e230dd2SCorentin Chary void vnc_write_u16(VncState *vs, uint16_t value); 5213e230dd2SCorentin Chary void vnc_write_u8(VncState *vs, uint8_t value); 5223e230dd2SCorentin Chary void vnc_flush(VncState *vs); 5233e230dd2SCorentin Chary void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting); 5247536ee4bSTim Hardeck void vnc_disconnect_finish(VncState *vs); 5257536ee4bSTim Hardeck void vnc_init_state(VncState *vs); 5263e230dd2SCorentin Chary 5273e230dd2SCorentin Chary 5283e230dd2SCorentin Chary /* Buffer I/O functions */ 5293e230dd2SCorentin Chary uint32_t read_u32(uint8_t *data, size_t offset); 5303e230dd2SCorentin Chary 5313e230dd2SCorentin Chary /* Protocol stage functions */ 5323e230dd2SCorentin Chary void vnc_client_error(VncState *vs); 533fdd1ab6aSDaniel P. Berrange ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, int last_errno); 5343e230dd2SCorentin Chary 5353e230dd2SCorentin Chary void start_client_init(VncState *vs); 5363e230dd2SCorentin Chary void start_auth_vnc(VncState *vs); 5373e230dd2SCorentin Chary 5383e230dd2SCorentin Chary /* Buffer management */ 5393e230dd2SCorentin Chary void buffer_reserve(Buffer *buffer, size_t len); 5403e230dd2SCorentin Chary void buffer_reset(Buffer *buffer); 5413e230dd2SCorentin Chary void buffer_free(Buffer *buffer); 5423e230dd2SCorentin Chary void buffer_append(Buffer *buffer, const void *data, size_t len); 54332ed2680STim Hardeck void buffer_advance(Buffer *buf, size_t len); 5447536ee4bSTim Hardeck uint8_t *buffer_end(Buffer *buffer); 5453e230dd2SCorentin Chary 5463e230dd2SCorentin Chary 5473e230dd2SCorentin Chary /* Misc helpers */ 5483e230dd2SCorentin Chary 5493e230dd2SCorentin Chary char *vnc_socket_local_addr(const char *format, int fd); 5503e230dd2SCorentin Chary char *vnc_socket_remote_addr(const char *format, int fd); 5513e230dd2SCorentin Chary 552efe556adSCorentin Chary static inline uint32_t vnc_has_feature(VncState *vs, int feature) { 553efe556adSCorentin Chary return (vs->features & (1 << feature)); 554efe556adSCorentin Chary } 555efe556adSCorentin Chary 5563e230dd2SCorentin Chary /* Framebuffer */ 5573e230dd2SCorentin Chary void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, 5583e230dd2SCorentin Chary int32_t encoding); 5593e230dd2SCorentin Chary 5609f64916dSGerd Hoffmann /* server fb is in PIXMAN_x8r8g8b8 */ 5619f64916dSGerd Hoffmann #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8) 5629f64916dSGerd Hoffmann #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT)) 5639f64916dSGerd Hoffmann #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8) 5649f64916dSGerd Hoffmann 5659f64916dSGerd Hoffmann void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y); 5669f64916dSGerd Hoffmann int vnc_server_fb_stride(VncDisplay *vd); 5679f64916dSGerd Hoffmann 5683e230dd2SCorentin Chary void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v); 569999342a0SCorentin Chary double vnc_update_freq(VncState *vs, int x, int y, int w, int h); 5707d964c9dSCorentin Chary void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h); 5713e230dd2SCorentin Chary 5723e230dd2SCorentin Chary /* Encodings */ 573bd023f95SCorentin Chary int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 574bd023f95SCorentin Chary 5753e230dd2SCorentin Chary int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 5763e230dd2SCorentin Chary 5773e230dd2SCorentin Chary int vnc_hextile_send_framebuffer_update(VncState *vs, int x, 5783e230dd2SCorentin Chary int y, int w, int h); 5793e230dd2SCorentin Chary void vnc_hextile_set_pixel_conversion(VncState *vs, int generic); 5803e230dd2SCorentin Chary 5813e230dd2SCorentin Chary void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size); 5823e230dd2SCorentin Chary void vnc_zlib_zfree(void *x, void *addr); 5833e230dd2SCorentin Chary int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 5843e230dd2SCorentin Chary void vnc_zlib_clear(VncState *vs); 5853e230dd2SCorentin Chary 5863e230dd2SCorentin Chary int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 587efe556adSCorentin Chary int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y, 588efe556adSCorentin Chary int w, int h); 5893e230dd2SCorentin Chary void vnc_tight_clear(VncState *vs); 5903e230dd2SCorentin Chary 591148954faSCorentin Chary int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 592148954faSCorentin Chary int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h); 593148954faSCorentin Chary void vnc_zrle_clear(VncState *vs); 594148954faSCorentin Chary 5953e230dd2SCorentin Chary #endif /* __QEMU_VNC_H */ 596