vnc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * QEMU VNC display driver
  3. *
  4. * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
  5. * Copyright (C) 2006 Fabrice Bellard
  6. * Copyright (C) 2009 Red Hat, Inc
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef QEMU_VNC_H
  27. #define QEMU_VNC_H
  28. #include "qemu/queue.h"
  29. #include "qemu/thread.h"
  30. #include "ui/clipboard.h"
  31. #include "ui/console.h"
  32. #include "audio/audio.h"
  33. #include "qemu/bitmap.h"
  34. #include "crypto/tlssession.h"
  35. #include "qemu/buffer.h"
  36. #include "io/channel-socket.h"
  37. #include "io/channel-tls.h"
  38. #include "io/net-listener.h"
  39. #include "authz/base.h"
  40. #include <zlib.h>
  41. #include "keymaps.h"
  42. #include "vnc-palette.h"
  43. #include "vnc-enc-zrle.h"
  44. #include "ui/kbd-state.h"
  45. // #define _VNC_DEBUG 1
  46. #ifdef _VNC_DEBUG
  47. #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
  48. #else
  49. #define VNC_DEBUG(fmt, ...) do { } while (0)
  50. #endif
  51. /*****************************************************************************
  52. *
  53. * Core data structures
  54. *
  55. *****************************************************************************/
  56. typedef struct VncState VncState;
  57. typedef struct VncJob VncJob;
  58. typedef struct VncRect VncRect;
  59. typedef struct VncRectEntry VncRectEntry;
  60. typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
  61. typedef void VncWritePixels(VncState *vs, void *data, int size);
  62. typedef void VncSendHextileTile(VncState *vs,
  63. int x, int y, int w, int h,
  64. void *last_bg,
  65. void *last_fg,
  66. int *has_bg, int *has_fg);
  67. /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
  68. * by one bit in the dirty bitmap, should be a power of 2 */
  69. #define VNC_DIRTY_PIXELS_PER_BIT 16
  70. /* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */
  71. #define VNC_MAX_WIDTH ROUND_UP(5120, VNC_DIRTY_PIXELS_PER_BIT)
  72. #define VNC_MAX_HEIGHT 2160
  73. /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
  74. #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
  75. /* VNC_DIRTY_BPL (BPL = bits per line) might be greater than
  76. * VNC_DIRTY_BITS due to alignment */
  77. #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)
  78. #define VNC_STAT_RECT 64
  79. #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
  80. #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
  81. #define VNC_AUTH_CHALLENGE_SIZE 16
  82. typedef struct VncDisplay VncDisplay;
  83. #include "vnc-auth-vencrypt.h"
  84. #ifdef CONFIG_VNC_SASL
  85. #include "vnc-auth-sasl.h"
  86. #endif
  87. #include "vnc-ws.h"
  88. struct VncRectStat
  89. {
  90. /* time of last 10 updates, to find update frequency */
  91. struct timeval times[10];
  92. int idx;
  93. double freq; /* Update frequency (in Hz) */
  94. bool updated; /* Already updated during this refresh */
  95. };
  96. typedef struct VncRectStat VncRectStat;
  97. struct VncSurface
  98. {
  99. struct timeval last_freq_check;
  100. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT],
  101. VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT);
  102. VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
  103. pixman_image_t *fb;
  104. pixman_format_code_t format;
  105. };
  106. typedef enum VncShareMode {
  107. VNC_SHARE_MODE_CONNECTING = 1,
  108. VNC_SHARE_MODE_SHARED,
  109. VNC_SHARE_MODE_EXCLUSIVE,
  110. VNC_SHARE_MODE_DISCONNECTED,
  111. } VncShareMode;
  112. typedef enum VncSharePolicy {
  113. VNC_SHARE_POLICY_IGNORE = 1,
  114. VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
  115. VNC_SHARE_POLICY_FORCE_SHARED,
  116. } VncSharePolicy;
  117. struct VncDisplay
  118. {
  119. QTAILQ_HEAD(, VncState) clients;
  120. int num_connecting;
  121. int num_shared;
  122. int num_exclusive;
  123. int connections_limit;
  124. VncSharePolicy share_policy;
  125. QIONetListener *listener;
  126. QIONetListener *wslistener;
  127. DisplaySurface *ds;
  128. DisplayChangeListener dcl;
  129. kbd_layout_t *kbd_layout;
  130. int lock_key_sync;
  131. QEMUPutLEDEntry *led;
  132. int ledstate;
  133. QKbdState *kbd;
  134. QemuMutex mutex;
  135. int cursor_msize;
  136. uint8_t *cursor_mask;
  137. struct VncSurface guest; /* guest visible surface (aka ds->surface) */
  138. pixman_image_t *server; /* vnc server surface */
  139. int true_width; /* server surface width before rounding up */
  140. const char *id;
  141. QTAILQ_ENTRY(VncDisplay) next;
  142. char *password;
  143. time_t expires;
  144. int auth;
  145. int subauth; /* Used by VeNCrypt */
  146. int ws_auth; /* Used by websockets */
  147. int ws_subauth; /* Used by websockets */
  148. bool lossy;
  149. bool non_adaptive;
  150. bool power_control;
  151. QCryptoTLSCreds *tlscreds;
  152. QAuthZ *tlsauthz;
  153. char *tlsauthzid;
  154. #ifdef CONFIG_VNC_SASL
  155. VncDisplaySASL sasl;
  156. #endif
  157. AudioState *audio_state;
  158. };
  159. typedef struct VncTight {
  160. int type;
  161. uint8_t quality;
  162. uint8_t compression;
  163. uint8_t pixel24;
  164. Buffer tight;
  165. Buffer tmp;
  166. Buffer zlib;
  167. Buffer gradient;
  168. #ifdef CONFIG_VNC_JPEG
  169. Buffer jpeg;
  170. #endif
  171. #ifdef CONFIG_PNG
  172. Buffer png;
  173. #endif
  174. int levels[4];
  175. z_stream stream[4];
  176. } VncTight;
  177. typedef struct VncHextile {
  178. VncSendHextileTile *send_tile;
  179. } VncHextile;
  180. typedef struct VncZlib {
  181. Buffer zlib;
  182. Buffer tmp;
  183. z_stream stream;
  184. int level;
  185. } VncZlib;
  186. typedef struct VncZrle {
  187. int type;
  188. Buffer fb;
  189. Buffer zrle;
  190. Buffer tmp;
  191. Buffer zlib;
  192. z_stream stream;
  193. VncPalette palette;
  194. } VncZrle;
  195. typedef struct VncZywrle {
  196. int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
  197. } VncZywrle;
  198. struct VncRect
  199. {
  200. int x;
  201. int y;
  202. int w;
  203. int h;
  204. };
  205. struct VncRectEntry
  206. {
  207. struct VncRect rect;
  208. QLIST_ENTRY(VncRectEntry) next;
  209. };
  210. struct VncJob
  211. {
  212. VncState *vs;
  213. QLIST_HEAD(, VncRectEntry) rectangles;
  214. QTAILQ_ENTRY(VncJob) next;
  215. };
  216. typedef enum {
  217. VNC_STATE_UPDATE_NONE,
  218. VNC_STATE_UPDATE_INCREMENTAL,
  219. VNC_STATE_UPDATE_FORCE,
  220. } VncStateUpdate;
  221. #define VNC_MAGIC ((uint64_t)0x05b3f069b3d204bb)
  222. struct VncState
  223. {
  224. uint64_t magic;
  225. QIOChannelSocket *sioc; /* The underlying socket */
  226. QIOChannel *ioc; /* The channel currently used for I/O */
  227. guint ioc_tag;
  228. gboolean disconnecting;
  229. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
  230. uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
  231. * vnc-jobs-async.c */
  232. VncDisplay *vd;
  233. VncStateUpdate update; /* Most recent pending request from client */
  234. VncStateUpdate job_update; /* Currently processed by job thread */
  235. int has_dirty;
  236. uint32_t features;
  237. int absolute;
  238. int last_x;
  239. int last_y;
  240. uint32_t last_bmask;
  241. size_t client_width; /* limited to u16 by RFB proto */
  242. size_t client_height; /* limited to u16 by RFB proto */
  243. VncShareMode share_mode;
  244. uint32_t vnc_encoding;
  245. int major;
  246. int minor;
  247. int auth;
  248. int subauth; /* Used by VeNCrypt */
  249. char challenge[VNC_AUTH_CHALLENGE_SIZE];
  250. QCryptoTLSSession *tls; /* Borrowed pointer from channel, don't free */
  251. #ifdef CONFIG_VNC_SASL
  252. VncStateSASL sasl;
  253. #endif
  254. bool encode_ws;
  255. bool websocket;
  256. #ifdef CONFIG_VNC
  257. VncClientInfo *info;
  258. #endif
  259. /* Job thread bottom half has put data for a forced update
  260. * into the output buffer. This offset points to the end of
  261. * the update data in the output buffer. This lets us determine
  262. * when a force update is fully sent to the client, allowing
  263. * us to process further forced updates. */
  264. size_t force_update_offset;
  265. /* We allow multiple incremental updates or audio capture
  266. * samples to be queued in output buffer, provided the
  267. * buffer size doesn't exceed this threshold. The value
  268. * is calculating dynamically based on framebuffer size
  269. * and audio sample settings in vnc_update_throttle_offset() */
  270. size_t throttle_output_offset;
  271. Buffer output;
  272. Buffer input;
  273. /* current output mode information */
  274. VncWritePixels *write_pixels;
  275. PixelFormat client_pf;
  276. pixman_format_code_t client_format;
  277. bool client_be;
  278. CaptureVoiceOut *audio_cap;
  279. struct audsettings as;
  280. VncReadEvent *read_handler;
  281. size_t read_handler_expect;
  282. bool abort;
  283. QemuMutex output_mutex;
  284. QEMUBH *bh;
  285. Buffer jobs_buffer;
  286. /* Encoding specific, if you add something here, don't forget to
  287. * update vnc_async_encoding_start()
  288. */
  289. VncTight *tight;
  290. VncZlib zlib;
  291. VncHextile hextile;
  292. VncZrle *zrle;
  293. VncZywrle zywrle;
  294. Notifier mouse_mode_notifier;
  295. QemuClipboardPeer cbpeer;
  296. QemuClipboardInfo *cbinfo;
  297. uint32_t cbpending;
  298. QTAILQ_ENTRY(VncState) next;
  299. };
  300. /*****************************************************************************
  301. *
  302. * Authentication modes
  303. *
  304. *****************************************************************************/
  305. enum {
  306. VNC_AUTH_INVALID = 0,
  307. VNC_AUTH_NONE = 1,
  308. VNC_AUTH_VNC = 2,
  309. VNC_AUTH_RA2 = 5,
  310. VNC_AUTH_RA2NE = 6,
  311. VNC_AUTH_TIGHT = 16,
  312. VNC_AUTH_ULTRA = 17,
  313. VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */
  314. VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
  315. VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */
  316. };
  317. enum {
  318. VNC_AUTH_VENCRYPT_PLAIN = 256,
  319. VNC_AUTH_VENCRYPT_TLSNONE = 257,
  320. VNC_AUTH_VENCRYPT_TLSVNC = 258,
  321. VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
  322. VNC_AUTH_VENCRYPT_X509NONE = 260,
  323. VNC_AUTH_VENCRYPT_X509VNC = 261,
  324. VNC_AUTH_VENCRYPT_X509PLAIN = 262,
  325. VNC_AUTH_VENCRYPT_X509SASL = 263,
  326. VNC_AUTH_VENCRYPT_TLSSASL = 264,
  327. };
  328. /*****************************************************************************
  329. *
  330. * Encoding types
  331. *
  332. *****************************************************************************/
  333. #define VNC_ENCODING_RAW 0x00000000
  334. #define VNC_ENCODING_COPYRECT 0x00000001
  335. #define VNC_ENCODING_RRE 0x00000002
  336. #define VNC_ENCODING_CORRE 0x00000004
  337. #define VNC_ENCODING_HEXTILE 0x00000005
  338. #define VNC_ENCODING_ZLIB 0x00000006
  339. #define VNC_ENCODING_TIGHT 0x00000007
  340. #define VNC_ENCODING_ZLIBHEX 0x00000008
  341. #define VNC_ENCODING_TRLE 0x0000000f
  342. #define VNC_ENCODING_ZRLE 0x00000010
  343. #define VNC_ENCODING_ZYWRLE 0x00000011
  344. #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */
  345. #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */
  346. #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */
  347. #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */
  348. #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */
  349. #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */
  350. #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */
  351. #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */
  352. #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */
  353. #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */
  354. #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */
  355. #define VNC_ENCODING_LED_STATE 0XFFFFFEFB /* -261 */
  356. #define VNC_ENCODING_DESKTOP_RESIZE_EXT 0XFFFFFECC /* -308 */
  357. #define VNC_ENCODING_XVP 0XFFFFFECB /* -309 */
  358. #define VNC_ENCODING_ALPHA_CURSOR 0XFFFFFEC6 /* -314 */
  359. #define VNC_ENCODING_WMVi 0x574D5669
  360. #define VNC_ENCODING_CLIPBOARD_EXT 0xc0a1e5ce
  361. /*****************************************************************************
  362. *
  363. * Other tight constants
  364. *
  365. *****************************************************************************/
  366. /*
  367. * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
  368. */
  369. #define VNC_TIGHT_CCB_RESET_MASK (0x0f)
  370. #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4)
  371. #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4)
  372. #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4)
  373. #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4)
  374. #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4)
  375. #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4)
  376. #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
  377. /*****************************************************************************
  378. *
  379. * Features
  380. *
  381. *****************************************************************************/
  382. enum VncFeatures {
  383. VNC_FEATURE_RESIZE,
  384. VNC_FEATURE_RESIZE_EXT,
  385. VNC_FEATURE_HEXTILE,
  386. VNC_FEATURE_POINTER_TYPE_CHANGE,
  387. VNC_FEATURE_WMVI,
  388. VNC_FEATURE_TIGHT,
  389. VNC_FEATURE_ZLIB,
  390. VNC_FEATURE_RICH_CURSOR,
  391. VNC_FEATURE_ALPHA_CURSOR,
  392. VNC_FEATURE_TIGHT_PNG,
  393. VNC_FEATURE_ZRLE,
  394. VNC_FEATURE_ZYWRLE,
  395. VNC_FEATURE_LED_STATE,
  396. VNC_FEATURE_XVP,
  397. VNC_FEATURE_CLIPBOARD_EXT,
  398. VNC_FEATURE_AUDIO,
  399. };
  400. /* Client -> Server message IDs */
  401. #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0
  402. #define VNC_MSG_CLIENT_SET_ENCODINGS 2
  403. #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
  404. #define VNC_MSG_CLIENT_KEY_EVENT 4
  405. #define VNC_MSG_CLIENT_POINTER_EVENT 5
  406. #define VNC_MSG_CLIENT_CUT_TEXT 6
  407. #define VNC_MSG_CLIENT_VMWARE_0 127
  408. #define VNC_MSG_CLIENT_CALL_CONTROL 249
  409. #define VNC_MSG_CLIENT_XVP 250
  410. #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251
  411. #define VNC_MSG_CLIENT_TIGHT 252
  412. #define VNC_MSG_CLIENT_GII 253
  413. #define VNC_MSG_CLIENT_VMWARE_1 254
  414. #define VNC_MSG_CLIENT_QEMU 255
  415. /* Server -> Client message IDs */
  416. #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0
  417. #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1
  418. #define VNC_MSG_SERVER_BELL 2
  419. #define VNC_MSG_SERVER_CUT_TEXT 3
  420. #define VNC_MSG_SERVER_VMWARE_0 127
  421. #define VNC_MSG_SERVER_CALL_CONTROL 249
  422. #define VNC_MSG_SERVER_XVP 250
  423. #define VNC_MSG_SERVER_TIGHT 252
  424. #define VNC_MSG_SERVER_GII 253
  425. #define VNC_MSG_SERVER_VMWARE_1 254
  426. #define VNC_MSG_SERVER_QEMU 255
  427. /* QEMU client -> server message IDs */
  428. #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0
  429. #define VNC_MSG_CLIENT_QEMU_AUDIO 1
  430. /* QEMU server -> client message IDs */
  431. #define VNC_MSG_SERVER_QEMU_AUDIO 1
  432. /* QEMU client -> server audio message IDs */
  433. #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0
  434. #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1
  435. #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2
  436. /* QEMU server -> client audio message IDs */
  437. #define VNC_MSG_SERVER_QEMU_AUDIO_END 0
  438. #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1
  439. #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2
  440. /* XVP server -> client status code */
  441. #define VNC_XVP_CODE_FAIL 0
  442. #define VNC_XVP_CODE_INIT 1
  443. /* XVP client -> server action request */
  444. #define VNC_XVP_ACTION_SHUTDOWN 2
  445. #define VNC_XVP_ACTION_REBOOT 3
  446. #define VNC_XVP_ACTION_RESET 4
  447. /* extended clipboard flags */
  448. #define VNC_CLIPBOARD_TEXT (1 << 0)
  449. #define VNC_CLIPBOARD_RTF (1 << 1)
  450. #define VNC_CLIPBOARD_HTML (1 << 2)
  451. #define VNC_CLIPBOARD_DIB (1 << 3)
  452. #define VNC_CLIPBOARD_FILES (1 << 4)
  453. #define VNC_CLIPBOARD_CAPS (1 << 24)
  454. #define VNC_CLIPBOARD_REQUEST (1 << 25)
  455. #define VNC_CLIPBOARD_PEEK (1 << 26)
  456. #define VNC_CLIPBOARD_NOTIFY (1 << 27)
  457. #define VNC_CLIPBOARD_PROVIDE (1 << 28)
  458. /*****************************************************************************
  459. *
  460. * Internal APIs
  461. *
  462. *****************************************************************************/
  463. /* Event loop functions */
  464. gboolean vnc_client_io(QIOChannel *ioc,
  465. GIOCondition condition,
  466. void *opaque);
  467. size_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
  468. size_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
  469. /* Protocol I/O functions */
  470. void vnc_write(VncState *vs, const void *data, size_t len);
  471. void vnc_write_u32(VncState *vs, uint32_t value);
  472. void vnc_write_s32(VncState *vs, int32_t value);
  473. void vnc_write_u16(VncState *vs, uint16_t value);
  474. void vnc_write_u8(VncState *vs, uint8_t value);
  475. void vnc_flush(VncState *vs);
  476. void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
  477. void vnc_disconnect_finish(VncState *vs);
  478. void vnc_start_protocol(VncState *vs);
  479. /* Buffer I/O functions */
  480. uint32_t read_u32(uint8_t *data, size_t offset);
  481. /* Protocol stage functions */
  482. void vnc_client_error(VncState *vs);
  483. size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err);
  484. void start_client_init(VncState *vs);
  485. void start_auth_vnc(VncState *vs);
  486. /* Misc helpers */
  487. static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
  488. return (vs->features & (1 << feature));
  489. }
  490. static inline void vnc_set_feature(VncState *vs, enum VncFeatures feature)
  491. {
  492. vs->features |= (1 << feature);
  493. }
  494. /* Framebuffer */
  495. void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
  496. int32_t encoding);
  497. /* server fb is in PIXMAN_x8r8g8b8 */
  498. #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
  499. #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
  500. #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8)
  501. void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
  502. int vnc_server_fb_stride(VncDisplay *vd);
  503. void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
  504. double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
  505. void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
  506. /* Encodings */
  507. int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  508. int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  509. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  510. int y, int w, int h);
  511. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
  512. void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
  513. void vnc_zlib_zfree(void *x, void *addr);
  514. int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  515. void vnc_zlib_clear(VncState *vs);
  516. int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  517. int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
  518. int w, int h);
  519. void vnc_tight_clear(VncState *vs);
  520. int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  521. int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  522. void vnc_zrle_clear(VncState *vs);
  523. /* vnc-clipboard.c */
  524. void vnc_server_cut_text_caps(VncState *vs);
  525. void vnc_client_cut_text(VncState *vs, size_t len, uint8_t *text);
  526. void vnc_client_cut_text_ext(VncState *vs, int32_t len, uint32_t flags, uint8_t *data);
  527. #endif /* QEMU_VNC_H */