xref: /openbmc/qemu/ui/vnc.h (revision 2cc45228)
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"
363e305e4aSDaniel P. Berrange #include "crypto/tlssession.h"
3788c5f205SDaniel P. Berrange #include "qemu/buffer.h"
3804d2529dSDaniel P. Berrange #include "io/channel-socket.h"
39*2cc45228SDaniel P. Berrange #include "io/channel-tls.h"
403e230dd2SCorentin Chary #include <zlib.h>
413e230dd2SCorentin Chary #include <stdbool.h>
423e230dd2SCorentin Chary 
433e230dd2SCorentin Chary #include "keymaps.h"
44148954faSCorentin Chary #include "vnc-palette.h"
45148954faSCorentin Chary #include "vnc-enc-zrle.h"
46fb6ba0d5SWenchao Xia #include "qapi-types.h"
473e230dd2SCorentin Chary 
483e230dd2SCorentin Chary // #define _VNC_DEBUG 1
493e230dd2SCorentin Chary 
503e230dd2SCorentin Chary #ifdef _VNC_DEBUG
513e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
523e230dd2SCorentin Chary #else
533e230dd2SCorentin Chary #define VNC_DEBUG(fmt, ...) do { } while (0)
543e230dd2SCorentin Chary #endif
553e230dd2SCorentin Chary 
563e230dd2SCorentin Chary /*****************************************************************************
573e230dd2SCorentin Chary  *
583e230dd2SCorentin Chary  * Core data structures
593e230dd2SCorentin Chary  *
603e230dd2SCorentin Chary  *****************************************************************************/
613e230dd2SCorentin Chary 
623e230dd2SCorentin Chary typedef struct VncState VncState;
63bd023f95SCorentin Chary typedef struct VncJob VncJob;
64bd023f95SCorentin Chary typedef struct VncRect VncRect;
65bd023f95SCorentin Chary typedef struct VncRectEntry VncRectEntry;
663e230dd2SCorentin Chary 
673e230dd2SCorentin Chary typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
683e230dd2SCorentin Chary 
699f64916dSGerd Hoffmann typedef void VncWritePixels(VncState *vs, void *data, int size);
703e230dd2SCorentin Chary 
713e230dd2SCorentin Chary typedef void VncSendHextileTile(VncState *vs,
723e230dd2SCorentin Chary                                 int x, int y, int w, int h,
733e230dd2SCorentin Chary                                 void *last_bg,
743e230dd2SCorentin Chary                                 void *last_fg,
753e230dd2SCorentin Chary                                 int *has_bg, int *has_fg);
763e230dd2SCorentin Chary 
77b4c85ddcSPeter Lieven /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
78bea60dd7SPeter Lieven  * by one bit in the dirty bitmap, should be a power of 2 */
79b4c85ddcSPeter Lieven #define VNC_DIRTY_PIXELS_PER_BIT 16
80b4c85ddcSPeter Lieven 
81bea60dd7SPeter Lieven /* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */
82bea60dd7SPeter Lieven 
83bea60dd7SPeter Lieven #define VNC_MAX_WIDTH ROUND_UP(2560, VNC_DIRTY_PIXELS_PER_BIT)
84bea60dd7SPeter Lieven #define VNC_MAX_HEIGHT 2048
85bea60dd7SPeter Lieven 
8623bfe28fSStefan Weil /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
87b4c85ddcSPeter Lieven #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
883e230dd2SCorentin Chary 
8912b316d4SPeter Lieven /* VNC_DIRTY_BPL (BPL = bits per line) might be greater than
9012b316d4SPeter Lieven  * VNC_DIRTY_BITS due to alignment */
9112b316d4SPeter Lieven #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)
9212b316d4SPeter Lieven 
93999342a0SCorentin Chary #define VNC_STAT_RECT  64
94999342a0SCorentin Chary #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
95999342a0SCorentin Chary #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
96999342a0SCorentin Chary 
973e230dd2SCorentin Chary #define VNC_AUTH_CHALLENGE_SIZE 16
983e230dd2SCorentin Chary 
993e230dd2SCorentin Chary typedef struct VncDisplay VncDisplay;
1003e230dd2SCorentin Chary 
1013e230dd2SCorentin Chary #include "vnc-auth-vencrypt.h"
1023e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL
1033e230dd2SCorentin Chary #include "vnc-auth-sasl.h"
1043e230dd2SCorentin Chary #endif
1057536ee4bSTim Hardeck #include "vnc-ws.h"
1063e230dd2SCorentin Chary 
107999342a0SCorentin Chary struct VncRectStat
108999342a0SCorentin Chary {
109999342a0SCorentin Chary     /* time of last 10 updates, to find update frequency */
110999342a0SCorentin Chary     struct timeval times[10];
111999342a0SCorentin Chary     int idx;
112999342a0SCorentin Chary 
113999342a0SCorentin Chary     double freq;        /* Update frequency (in Hz) */
114999342a0SCorentin Chary     bool updated;       /* Already updated during this refresh */
115999342a0SCorentin Chary };
116999342a0SCorentin Chary 
117999342a0SCorentin Chary typedef struct VncRectStat VncRectStat;
118999342a0SCorentin Chary 
1193e230dd2SCorentin Chary struct VncSurface
1203e230dd2SCorentin Chary {
121999342a0SCorentin Chary     struct timeval last_freq_check;
122bea60dd7SPeter Lieven     DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT],
123bea60dd7SPeter Lieven                    VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT);
124999342a0SCorentin Chary     VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
1259f64916dSGerd Hoffmann     pixman_image_t *fb;
1269f64916dSGerd Hoffmann     pixman_format_code_t format;
1273e230dd2SCorentin Chary };
1283e230dd2SCorentin Chary 
1298cf36489SGerd Hoffmann typedef enum VncShareMode {
1308cf36489SGerd Hoffmann     VNC_SHARE_MODE_CONNECTING = 1,
1318cf36489SGerd Hoffmann     VNC_SHARE_MODE_SHARED,
1328cf36489SGerd Hoffmann     VNC_SHARE_MODE_EXCLUSIVE,
1338cf36489SGerd Hoffmann     VNC_SHARE_MODE_DISCONNECTED,
1348cf36489SGerd Hoffmann } VncShareMode;
1358cf36489SGerd Hoffmann 
1368cf36489SGerd Hoffmann typedef enum VncSharePolicy {
1378cf36489SGerd Hoffmann     VNC_SHARE_POLICY_IGNORE = 1,
1388cf36489SGerd Hoffmann     VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
1398cf36489SGerd Hoffmann     VNC_SHARE_POLICY_FORCE_SHARED,
1408cf36489SGerd Hoffmann } VncSharePolicy;
1418cf36489SGerd Hoffmann 
1423e230dd2SCorentin Chary struct VncDisplay
1433e230dd2SCorentin Chary {
1443e230dd2SCorentin Chary     QTAILQ_HEAD(, VncState) clients;
145e5f34cddSGerd Hoffmann     int num_connecting;
146e5f34cddSGerd Hoffmann     int num_shared;
1478cf36489SGerd Hoffmann     int num_exclusive;
148e5f34cddSGerd Hoffmann     int connections_limit;
1498cf36489SGerd Hoffmann     VncSharePolicy share_policy;
15004d2529dSDaniel P. Berrange     QIOChannelSocket *lsock;
15104d2529dSDaniel P. Berrange     guint lsock_tag;
15204d2529dSDaniel P. Berrange     QIOChannelSocket *lwebsock;
15304d2529dSDaniel P. Berrange     guint lwebsock_tag;
154bf7aa45eSGerd Hoffmann     bool ws_enabled;
155d39fa6d8SGerd Hoffmann     DisplaySurface *ds;
15621ef45d7SGerd Hoffmann     DisplayChangeListener dcl;
1573e230dd2SCorentin Chary     kbd_layout_t *kbd_layout;
1583e230dd2SCorentin Chary     int lock_key_sync;
159bd023f95SCorentin Chary     QemuMutex mutex;
1603e230dd2SCorentin Chary 
1613e230dd2SCorentin Chary     QEMUCursor *cursor;
1623e230dd2SCorentin Chary     int cursor_msize;
1633e230dd2SCorentin Chary     uint8_t *cursor_mask;
1643e230dd2SCorentin Chary 
1653e230dd2SCorentin Chary     struct VncSurface guest;   /* guest visible surface (aka ds->surface) */
1669f64916dSGerd Hoffmann     pixman_image_t *server;    /* vnc server surface */
1673e230dd2SCorentin Chary 
168d616ccc5SGerd Hoffmann     const char *id;
169d616ccc5SGerd Hoffmann     QTAILQ_ENTRY(VncDisplay) next;
170bf7aa45eSGerd Hoffmann     bool enabled;
171bf7aa45eSGerd Hoffmann     bool is_unix;
1723e230dd2SCorentin Chary     char *password;
1733c9405a0SGerd Hoffmann     time_t expires;
1743e230dd2SCorentin Chary     int auth;
175d169f04bSDaniel P. Berrange     int subauth; /* Used by VeNCrypt */
176f9148c8aSDaniel P. Berrange     int ws_auth; /* Used by websockets */
177f9148c8aSDaniel P. Berrange     bool ws_tls; /* Used by websockets */
1783e230dd2SCorentin Chary     bool lossy;
17980e0c8c3SCorentin Chary     bool non_adaptive;
1803e305e4aSDaniel P. Berrange     QCryptoTLSCreds *tlscreds;
1813e305e4aSDaniel P. Berrange     char *tlsaclname;
1823e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL
1833e230dd2SCorentin Chary     VncDisplaySASL sasl;
1843e230dd2SCorentin Chary #endif
1853e230dd2SCorentin Chary };
1863e230dd2SCorentin Chary 
187d1af0e05SCorentin Chary typedef struct VncTight {
188d1af0e05SCorentin Chary     int type;
189d1af0e05SCorentin Chary     uint8_t quality;
190d1af0e05SCorentin Chary     uint8_t compression;
191d1af0e05SCorentin Chary     uint8_t pixel24;
192d1af0e05SCorentin Chary     Buffer tight;
193d1af0e05SCorentin Chary     Buffer tmp;
194d1af0e05SCorentin Chary     Buffer zlib;
195d1af0e05SCorentin Chary     Buffer gradient;
196d1af0e05SCorentin Chary #ifdef CONFIG_VNC_JPEG
197d1af0e05SCorentin Chary     Buffer jpeg;
198d1af0e05SCorentin Chary #endif
199d1af0e05SCorentin Chary #ifdef CONFIG_VNC_PNG
200d1af0e05SCorentin Chary     Buffer png;
201d1af0e05SCorentin Chary #endif
202d1af0e05SCorentin Chary     int levels[4];
203d1af0e05SCorentin Chary     z_stream stream[4];
204d1af0e05SCorentin Chary } VncTight;
205d1af0e05SCorentin Chary 
206d1af0e05SCorentin Chary typedef struct VncHextile {
207d1af0e05SCorentin Chary     VncSendHextileTile *send_tile;
208d1af0e05SCorentin Chary } VncHextile;
209d1af0e05SCorentin Chary 
210d1af0e05SCorentin Chary typedef struct VncZlib {
211d1af0e05SCorentin Chary     Buffer zlib;
212d1af0e05SCorentin Chary     Buffer tmp;
213d1af0e05SCorentin Chary     z_stream stream;
214d1af0e05SCorentin Chary     int level;
215d1af0e05SCorentin Chary } VncZlib;
216d1af0e05SCorentin Chary 
217148954faSCorentin Chary typedef struct VncZrle {
218148954faSCorentin Chary     int type;
219148954faSCorentin Chary     Buffer fb;
220148954faSCorentin Chary     Buffer zrle;
221148954faSCorentin Chary     Buffer tmp;
222148954faSCorentin Chary     Buffer zlib;
223148954faSCorentin Chary     z_stream stream;
224148954faSCorentin Chary     VncPalette palette;
225148954faSCorentin Chary } VncZrle;
226148954faSCorentin Chary 
227148954faSCorentin Chary typedef struct VncZywrle {
228148954faSCorentin Chary     int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
229148954faSCorentin Chary } VncZywrle;
230148954faSCorentin Chary 
231bd023f95SCorentin Chary struct VncRect
232bd023f95SCorentin Chary {
233bd023f95SCorentin Chary     int x;
234bd023f95SCorentin Chary     int y;
235bd023f95SCorentin Chary     int w;
236bd023f95SCorentin Chary     int h;
237bd023f95SCorentin Chary };
238bd023f95SCorentin Chary 
239bd023f95SCorentin Chary struct VncRectEntry
240bd023f95SCorentin Chary {
241bd023f95SCorentin Chary     struct VncRect rect;
242bd023f95SCorentin Chary     QLIST_ENTRY(VncRectEntry) next;
243bd023f95SCorentin Chary };
244bd023f95SCorentin Chary 
245bd023f95SCorentin Chary struct VncJob
246bd023f95SCorentin Chary {
247bd023f95SCorentin Chary     VncState *vs;
248bd023f95SCorentin Chary 
249bd023f95SCorentin Chary     QLIST_HEAD(, VncRectEntry) rectangles;
250bd023f95SCorentin Chary     QTAILQ_ENTRY(VncJob) next;
251bd023f95SCorentin Chary };
252bd023f95SCorentin Chary 
2533e230dd2SCorentin Chary struct VncState
2543e230dd2SCorentin Chary {
25504d2529dSDaniel P. Berrange     QIOChannelSocket *sioc; /* The underlying socket */
25604d2529dSDaniel P. Berrange     QIOChannel *ioc; /* The channel currently used for I/O */
25704d2529dSDaniel P. Berrange     guint ioc_tag;
25804d2529dSDaniel P. Berrange     gboolean disconnecting;
2593e230dd2SCorentin Chary 
26023bfe28fSStefan Weil     DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
2617d964c9dSCorentin Chary     uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
2627d964c9dSCorentin Chary                            * vnc-jobs-async.c */
2633e230dd2SCorentin Chary 
2643e230dd2SCorentin Chary     VncDisplay *vd;
2653e230dd2SCorentin Chary     int need_update;
2663e230dd2SCorentin Chary     int force_update;
26763658280SGerd Hoffmann     int has_dirty;
2683e230dd2SCorentin Chary     uint32_t features;
2693e230dd2SCorentin Chary     int absolute;
2703e230dd2SCorentin Chary     int last_x;
2713e230dd2SCorentin Chary     int last_y;
27214768ebaSGerd Hoffmann     uint32_t last_bmask;
2733e230dd2SCorentin Chary     int client_width;
2743e230dd2SCorentin Chary     int client_height;
2758cf36489SGerd Hoffmann     VncShareMode share_mode;
2763e230dd2SCorentin Chary 
2773e230dd2SCorentin Chary     uint32_t vnc_encoding;
2783e230dd2SCorentin Chary 
2793e230dd2SCorentin Chary     int major;
2803e230dd2SCorentin Chary     int minor;
2813e230dd2SCorentin Chary 
2827e7e2ebcSDaniel P. Berrange     int auth;
283d169f04bSDaniel P. Berrange     int subauth; /* Used by VeNCrypt */
2843e230dd2SCorentin Chary     char challenge[VNC_AUTH_CHALLENGE_SIZE];
285*2cc45228SDaniel P. Berrange     QCryptoTLSSession *tls; /* Borrowed pointer from channel, don't free */
2863e230dd2SCorentin Chary #ifdef CONFIG_VNC_SASL
2873e230dd2SCorentin Chary     VncStateSASL sasl;
2883e230dd2SCorentin Chary #endif
2897536ee4bSTim Hardeck     bool encode_ws;
2907536ee4bSTim Hardeck     bool websocket;
2913e230dd2SCorentin Chary 
292fb6ba0d5SWenchao Xia     VncClientInfo *info;
2933e230dd2SCorentin Chary 
2943e230dd2SCorentin Chary     Buffer output;
2953e230dd2SCorentin Chary     Buffer input;
2967536ee4bSTim Hardeck     Buffer ws_input;
2977536ee4bSTim Hardeck     Buffer ws_output;
298a2bebfd6SDaniel P. Berrange     size_t ws_payload_remain;
299a2bebfd6SDaniel P. Berrange     WsMask ws_payload_mask;
3003e230dd2SCorentin Chary     /* current output mode information */
3013e230dd2SCorentin Chary     VncWritePixels *write_pixels;
3029f64916dSGerd Hoffmann     PixelFormat client_pf;
3039f64916dSGerd Hoffmann     pixman_format_code_t client_format;
3049f64916dSGerd Hoffmann     bool client_be;
3053e230dd2SCorentin Chary 
3063e230dd2SCorentin Chary     CaptureVoiceOut *audio_cap;
3073e230dd2SCorentin Chary     struct audsettings as;
3083e230dd2SCorentin Chary 
3093e230dd2SCorentin Chary     VncReadEvent *read_handler;
3103e230dd2SCorentin Chary     size_t read_handler_expect;
3113e230dd2SCorentin Chary     /* input */
3123e230dd2SCorentin Chary     uint8_t modifiers_state[256];
3133e230dd2SCorentin Chary     QEMUPutLEDEntry *led;
3143e230dd2SCorentin Chary 
315bd023f95SCorentin Chary     bool abort;
3166fd8e79aSTim Hardeck     bool initialized;
317bd023f95SCorentin Chary     QemuMutex output_mutex;
318175b2a6eSCorentin Chary     QEMUBH *bh;
319175b2a6eSCorentin Chary     Buffer jobs_buffer;
320bd023f95SCorentin Chary 
321bd023f95SCorentin Chary     /* Encoding specific, if you add something here, don't forget to
322bd023f95SCorentin Chary      *  update vnc_async_encoding_start()
323bd023f95SCorentin Chary      */
324d1af0e05SCorentin Chary     VncTight tight;
325d1af0e05SCorentin Chary     VncZlib zlib;
326d1af0e05SCorentin Chary     VncHextile hextile;
327148954faSCorentin Chary     VncZrle zrle;
328148954faSCorentin Chary     VncZywrle zywrle;
3293e230dd2SCorentin Chary 
3303e230dd2SCorentin Chary     Notifier mouse_mode_notifier;
3313e230dd2SCorentin Chary 
3323e230dd2SCorentin Chary     QTAILQ_ENTRY(VncState) next;
3333e230dd2SCorentin Chary };
3343e230dd2SCorentin Chary 
3353e230dd2SCorentin Chary 
3363e230dd2SCorentin Chary /*****************************************************************************
3373e230dd2SCorentin Chary  *
3383e230dd2SCorentin Chary  * Authentication modes
3393e230dd2SCorentin Chary  *
3403e230dd2SCorentin Chary  *****************************************************************************/
3413e230dd2SCorentin Chary 
3423e230dd2SCorentin Chary enum {
3433e230dd2SCorentin Chary     VNC_AUTH_INVALID = 0,
3443e230dd2SCorentin Chary     VNC_AUTH_NONE = 1,
3453e230dd2SCorentin Chary     VNC_AUTH_VNC = 2,
3463e230dd2SCorentin Chary     VNC_AUTH_RA2 = 5,
3473e230dd2SCorentin Chary     VNC_AUTH_RA2NE = 6,
3483e230dd2SCorentin Chary     VNC_AUTH_TIGHT = 16,
3493e230dd2SCorentin Chary     VNC_AUTH_ULTRA = 17,
3503e230dd2SCorentin Chary     VNC_AUTH_TLS = 18,      /* Supported in GTK-VNC & VINO */
3513e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
3523e230dd2SCorentin Chary     VNC_AUTH_SASL = 20,     /* Supported in GTK-VNC & VINO */
3533e230dd2SCorentin Chary };
3543e230dd2SCorentin Chary 
3553e230dd2SCorentin Chary enum {
3563e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_PLAIN = 256,
3573e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_TLSNONE = 257,
3583e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_TLSVNC = 258,
3593e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
3603e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_X509NONE = 260,
3613e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_X509VNC = 261,
3623e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_X509PLAIN = 262,
3633e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_X509SASL = 263,
3643e230dd2SCorentin Chary     VNC_AUTH_VENCRYPT_TLSSASL = 264,
3653e230dd2SCorentin Chary };
3663e230dd2SCorentin Chary 
3673e230dd2SCorentin Chary 
3683e230dd2SCorentin Chary /*****************************************************************************
3693e230dd2SCorentin Chary  *
3703e230dd2SCorentin Chary  * Encoding types
3713e230dd2SCorentin Chary  *
3723e230dd2SCorentin Chary  *****************************************************************************/
3733e230dd2SCorentin Chary 
3743e230dd2SCorentin Chary #define VNC_ENCODING_RAW                  0x00000000
3753e230dd2SCorentin Chary #define VNC_ENCODING_COPYRECT             0x00000001
3763e230dd2SCorentin Chary #define VNC_ENCODING_RRE                  0x00000002
3773e230dd2SCorentin Chary #define VNC_ENCODING_CORRE                0x00000004
3783e230dd2SCorentin Chary #define VNC_ENCODING_HEXTILE              0x00000005
3793e230dd2SCorentin Chary #define VNC_ENCODING_ZLIB                 0x00000006
3803e230dd2SCorentin Chary #define VNC_ENCODING_TIGHT                0x00000007
3813e230dd2SCorentin Chary #define VNC_ENCODING_ZLIBHEX              0x00000008
3823e230dd2SCorentin Chary #define VNC_ENCODING_TRLE                 0x0000000f
3833e230dd2SCorentin Chary #define VNC_ENCODING_ZRLE                 0x00000010
3843e230dd2SCorentin Chary #define VNC_ENCODING_ZYWRLE               0x00000011
3853e230dd2SCorentin Chary #define VNC_ENCODING_COMPRESSLEVEL0       0xFFFFFF00 /* -256 */
3863e230dd2SCorentin Chary #define VNC_ENCODING_QUALITYLEVEL0        0xFFFFFFE0 /* -32  */
3873e230dd2SCorentin Chary #define VNC_ENCODING_XCURSOR              0xFFFFFF10 /* -240 */
3883e230dd2SCorentin Chary #define VNC_ENCODING_RICH_CURSOR          0xFFFFFF11 /* -239 */
3893e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_POS          0xFFFFFF18 /* -232 */
3903e230dd2SCorentin Chary #define VNC_ENCODING_LASTRECT             0xFFFFFF20 /* -224 */
3913e230dd2SCorentin Chary #define VNC_ENCODING_DESKTOPRESIZE        0xFFFFFF21 /* -223 */
3923e230dd2SCorentin Chary #define VNC_ENCODING_POINTER_TYPE_CHANGE  0XFFFFFEFF /* -257 */
3933e230dd2SCorentin Chary #define VNC_ENCODING_EXT_KEY_EVENT        0XFFFFFEFE /* -258 */
3943e230dd2SCorentin Chary #define VNC_ENCODING_AUDIO                0XFFFFFEFD /* -259 */
395efe556adSCorentin Chary #define VNC_ENCODING_TIGHT_PNG            0xFFFFFEFC /* -260 */
396ab99e5c1SLei Li #define VNC_ENCODING_LED_STATE            0XFFFFFEFB /* -261 */
3973e230dd2SCorentin Chary #define VNC_ENCODING_WMVi                 0x574D5669
3983e230dd2SCorentin Chary 
3993e230dd2SCorentin Chary /*****************************************************************************
4003e230dd2SCorentin Chary  *
4013e230dd2SCorentin Chary  * Other tight constants
4023e230dd2SCorentin Chary  *
4033e230dd2SCorentin Chary  *****************************************************************************/
4043e230dd2SCorentin Chary 
4053e230dd2SCorentin Chary /*
4063e230dd2SCorentin Chary  * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
4073e230dd2SCorentin Chary  */
4083e230dd2SCorentin Chary 
4093e230dd2SCorentin Chary #define VNC_TIGHT_CCB_RESET_MASK   (0x0f)
4103e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_MASK    (0x0f << 4)
4113e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_FILL    (0x08 << 4)
4123e230dd2SCorentin Chary #define VNC_TIGHT_CCB_TYPE_JPEG    (0x09 << 4)
413efe556adSCorentin Chary #define VNC_TIGHT_CCB_TYPE_PNG     (0x0A << 4)
4143e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_MAX    (0x07 << 4)
4153e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_ZLIB   (0x03 << 4)
4163e230dd2SCorentin Chary #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
4173e230dd2SCorentin Chary 
4183e230dd2SCorentin Chary /*****************************************************************************
4193e230dd2SCorentin Chary  *
4203e230dd2SCorentin Chary  * Features
4213e230dd2SCorentin Chary  *
4223e230dd2SCorentin Chary  *****************************************************************************/
4233e230dd2SCorentin Chary 
4243e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE                   0
4253e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE                  1
4263e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE      2
4273e230dd2SCorentin Chary #define VNC_FEATURE_WMVI                     3
4283e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT                    4
4293e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB                     5
4303e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT                 6
4313e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR              7
432efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG                8
433148954faSCorentin Chary #define VNC_FEATURE_ZRLE                     9
434148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE                  10
435ab99e5c1SLei Li #define VNC_FEATURE_LED_STATE               11
4363e230dd2SCorentin Chary 
4373e230dd2SCorentin Chary #define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
4383e230dd2SCorentin Chary #define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
4393e230dd2SCorentin Chary #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
4403e230dd2SCorentin Chary #define VNC_FEATURE_WMVI_MASK                (1 << VNC_FEATURE_WMVI)
4413e230dd2SCorentin Chary #define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
4423e230dd2SCorentin Chary #define VNC_FEATURE_ZLIB_MASK                (1 << VNC_FEATURE_ZLIB)
4433e230dd2SCorentin Chary #define VNC_FEATURE_COPYRECT_MASK            (1 << VNC_FEATURE_COPYRECT)
4443e230dd2SCorentin Chary #define VNC_FEATURE_RICH_CURSOR_MASK         (1 << VNC_FEATURE_RICH_CURSOR)
445efe556adSCorentin Chary #define VNC_FEATURE_TIGHT_PNG_MASK           (1 << VNC_FEATURE_TIGHT_PNG)
446148954faSCorentin Chary #define VNC_FEATURE_ZRLE_MASK                (1 << VNC_FEATURE_ZRLE)
447148954faSCorentin Chary #define VNC_FEATURE_ZYWRLE_MASK              (1 << VNC_FEATURE_ZYWRLE)
448ab99e5c1SLei Li #define VNC_FEATURE_LED_STATE_MASK           (1 << VNC_FEATURE_LED_STATE)
4493e230dd2SCorentin Chary 
4503e230dd2SCorentin Chary 
4513e230dd2SCorentin Chary /* Client -> Server message IDs */
4523e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT           0
4533e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_ENCODINGS              2
4543e230dd2SCorentin Chary #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
4553e230dd2SCorentin Chary #define VNC_MSG_CLIENT_KEY_EVENT                  4
4563e230dd2SCorentin Chary #define VNC_MSG_CLIENT_POINTER_EVENT              5
4573e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CUT_TEXT                   6
4583e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_0                   127
4593e230dd2SCorentin Chary #define VNC_MSG_CLIENT_CALL_CONTROL               249
4603e230dd2SCorentin Chary #define VNC_MSG_CLIENT_XVP                        250
4613e230dd2SCorentin Chary #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE           251
4623e230dd2SCorentin Chary #define VNC_MSG_CLIENT_TIGHT                      252
4633e230dd2SCorentin Chary #define VNC_MSG_CLIENT_GII                        253
4643e230dd2SCorentin Chary #define VNC_MSG_CLIENT_VMWARE_1                   254
4653e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU                       255
4663e230dd2SCorentin Chary 
4673e230dd2SCorentin Chary /* Server -> Client message IDs */
4683e230dd2SCorentin Chary #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE         0
4693e230dd2SCorentin Chary #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES     1
4703e230dd2SCorentin Chary #define VNC_MSG_SERVER_BELL                       2
4713e230dd2SCorentin Chary #define VNC_MSG_SERVER_CUT_TEXT                   3
4723e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_0                   127
4733e230dd2SCorentin Chary #define VNC_MSG_SERVER_CALL_CONTROL               249
4743e230dd2SCorentin Chary #define VNC_MSG_SERVER_XVP                        250
4753e230dd2SCorentin Chary #define VNC_MSG_SERVER_TIGHT                      252
4763e230dd2SCorentin Chary #define VNC_MSG_SERVER_GII                        253
4773e230dd2SCorentin Chary #define VNC_MSG_SERVER_VMWARE_1                   254
4783e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU                       255
4793e230dd2SCorentin Chary 
4803e230dd2SCorentin Chary 
4813e230dd2SCorentin Chary 
4823e230dd2SCorentin Chary /* QEMU client -> server message IDs */
4833e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT         0
4843e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO                 1
4853e230dd2SCorentin Chary 
4863e230dd2SCorentin Chary /* QEMU server -> client message IDs */
4873e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO                 1
4883e230dd2SCorentin Chary 
4893e230dd2SCorentin Chary 
4903e230dd2SCorentin Chary 
4913e230dd2SCorentin Chary /* QEMU client -> server audio message IDs */
4923e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE          0
4933e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE         1
4943e230dd2SCorentin Chary #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT      2
4953e230dd2SCorentin Chary 
4963e230dd2SCorentin Chary /* QEMU server -> client audio message IDs */
4973e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_END             0
4983e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN           1
4993e230dd2SCorentin Chary #define VNC_MSG_SERVER_QEMU_AUDIO_DATA            2
5003e230dd2SCorentin Chary 
5013e230dd2SCorentin Chary 
5023e230dd2SCorentin Chary /*****************************************************************************
5033e230dd2SCorentin Chary  *
5043e230dd2SCorentin Chary  * Internal APIs
5053e230dd2SCorentin Chary  *
5063e230dd2SCorentin Chary  *****************************************************************************/
5073e230dd2SCorentin Chary 
5083e230dd2SCorentin Chary /* Event loop functions */
50904d2529dSDaniel P. Berrange gboolean vnc_client_io(QIOChannel *ioc,
51004d2529dSDaniel P. Berrange                        GIOCondition condition,
51104d2529dSDaniel P. Berrange                        void *opaque);
5123e230dd2SCorentin Chary 
513fdd1ab6aSDaniel P. Berrange ssize_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
514fdd1ab6aSDaniel P. Berrange ssize_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
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);
53304d2529dSDaniel P. Berrange ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp);
5343e230dd2SCorentin Chary 
5353e230dd2SCorentin Chary void start_client_init(VncState *vs);
5363e230dd2SCorentin Chary void start_auth_vnc(VncState *vs);
5373e230dd2SCorentin Chary 
5383e230dd2SCorentin Chary 
5393e230dd2SCorentin Chary /* Misc helpers */
5403e230dd2SCorentin Chary 
541efe556adSCorentin Chary static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
542efe556adSCorentin Chary     return (vs->features & (1 << feature));
543efe556adSCorentin Chary }
544efe556adSCorentin Chary 
5453e230dd2SCorentin Chary /* Framebuffer */
5463e230dd2SCorentin Chary void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
5473e230dd2SCorentin Chary                             int32_t encoding);
5483e230dd2SCorentin Chary 
5499f64916dSGerd Hoffmann /* server fb is in PIXMAN_x8r8g8b8 */
5509f64916dSGerd Hoffmann #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
5519f64916dSGerd Hoffmann #define VNC_SERVER_FB_BITS   (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
5529f64916dSGerd Hoffmann #define VNC_SERVER_FB_BYTES  ((VNC_SERVER_FB_BITS+7)/8)
5539f64916dSGerd Hoffmann 
5549f64916dSGerd Hoffmann void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
5559f64916dSGerd Hoffmann int vnc_server_fb_stride(VncDisplay *vd);
5569f64916dSGerd Hoffmann 
5573e230dd2SCorentin Chary void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
558999342a0SCorentin Chary double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
5597d964c9dSCorentin Chary void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
5603e230dd2SCorentin Chary 
5613e230dd2SCorentin Chary /* Encodings */
562bd023f95SCorentin Chary int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
563bd023f95SCorentin Chary 
5643e230dd2SCorentin Chary int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
5653e230dd2SCorentin Chary 
5663e230dd2SCorentin Chary int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
5673e230dd2SCorentin Chary                                          int y, int w, int h);
5683e230dd2SCorentin Chary void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
5693e230dd2SCorentin Chary 
5703e230dd2SCorentin Chary void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
5713e230dd2SCorentin Chary void vnc_zlib_zfree(void *x, void *addr);
5723e230dd2SCorentin Chary int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
5733e230dd2SCorentin Chary void vnc_zlib_clear(VncState *vs);
5743e230dd2SCorentin Chary 
5753e230dd2SCorentin Chary int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
576efe556adSCorentin Chary int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
577efe556adSCorentin Chary                                           int w, int h);
5783e230dd2SCorentin Chary void vnc_tight_clear(VncState *vs);
5793e230dd2SCorentin Chary 
580148954faSCorentin Chary int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
581148954faSCorentin Chary int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
582148954faSCorentin Chary void vnc_zrle_clear(VncState *vs);
583148954faSCorentin Chary 
5843e230dd2SCorentin Chary #endif /* __QEMU_VNC_H */
585