2019-09-07 16:51:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Andri Yngvason
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-08-12 20:49:23 +00:00
|
|
|
|
|
|
|
#define RFB_VERSION_MESSAGE "RFB 003.008\n"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#define RFB_PACKED __attribute__((packed))
|
|
|
|
|
2019-08-12 22:11:41 +00:00
|
|
|
enum rfb_security_type {
|
2019-10-20 22:13:51 +00:00
|
|
|
RFB_SECURITY_TYPE_INVALID = 0,
|
|
|
|
RFB_SECURITY_TYPE_NONE = 1,
|
|
|
|
RFB_SECURITY_TYPE_VNC_AUTH = 2,
|
2020-01-25 15:35:14 +00:00
|
|
|
RFB_SECURITY_TYPE_TIGHT = 16,
|
|
|
|
RFB_SECURITY_TYPE_VENCRYPT = 19,
|
2019-08-12 20:49:23 +00:00
|
|
|
};
|
|
|
|
|
2019-08-12 22:11:41 +00:00
|
|
|
enum rfb_security_handshake_result {
|
2019-08-12 20:49:23 +00:00
|
|
|
RFB_SECURITY_HANDSHAKE_OK = 0,
|
|
|
|
RFB_SECURITY_HANDSHAKE_FAILED = 1,
|
|
|
|
};
|
|
|
|
|
2019-08-12 22:11:41 +00:00
|
|
|
enum rfb_client_to_server_msg_type {
|
2019-08-12 20:49:23 +00:00
|
|
|
RFB_CLIENT_TO_SERVER_SET_PIXEL_FORMAT = 0,
|
|
|
|
RFB_CLIENT_TO_SERVER_SET_ENCODINGS = 2,
|
|
|
|
RFB_CLIENT_TO_SERVER_FRAMEBUFFER_UPDATE_REQUEST = 3,
|
|
|
|
RFB_CLIENT_TO_SERVER_KEY_EVENT = 4,
|
|
|
|
RFB_CLIENT_TO_SERVER_POINTER_EVENT = 5,
|
|
|
|
RFB_CLIENT_TO_SERVER_CLIENT_CUT_TEXT = 6,
|
2020-11-29 17:05:58 +00:00
|
|
|
RFB_CLIENT_TO_SERVER_QEMU = 255,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rfb_client_to_server_qemu_msg_type {
|
|
|
|
RFB_CLIENT_TO_SERVER_QEMU_KEY_EVENT = 0,
|
2019-08-12 20:49:23 +00:00
|
|
|
};
|
|
|
|
|
2019-08-12 23:33:06 +00:00
|
|
|
enum rfb_encodings {
|
|
|
|
RFB_ENCODING_RAW = 0,
|
|
|
|
RFB_ENCODING_COPYRECT = 1,
|
|
|
|
RFB_ENCODING_RRE = 2,
|
|
|
|
RFB_ENCODING_HEXTILE = 5,
|
2019-12-30 09:59:51 +00:00
|
|
|
RFB_ENCODING_TIGHT = 7,
|
2019-08-12 23:33:06 +00:00
|
|
|
RFB_ENCODING_TRLE = 15,
|
|
|
|
RFB_ENCODING_ZRLE = 16,
|
2021-09-26 17:32:37 +00:00
|
|
|
RFB_ENCODING_OPEN_H264 = 50,
|
2019-08-12 23:33:06 +00:00
|
|
|
RFB_ENCODING_CURSOR = -239,
|
|
|
|
RFB_ENCODING_DESKTOPSIZE = -223,
|
2020-04-03 19:56:44 +00:00
|
|
|
RFB_ENCODING_JPEG_HIGHQ = -23,
|
|
|
|
RFB_ENCODING_JPEG_LOWQ = -32,
|
2020-11-29 17:05:58 +00:00
|
|
|
RFB_ENCODING_QEMU_EXT_KEY_EVENT = -258,
|
2019-08-12 23:33:06 +00:00
|
|
|
};
|
|
|
|
|
2019-08-25 16:40:59 +00:00
|
|
|
enum rfb_server_to_client_msg_type {
|
2019-10-20 22:13:51 +00:00
|
|
|
RFB_SERVER_TO_CLIENT_FRAMEBUFFER_UPDATE = 0,
|
|
|
|
RFB_SERVER_TO_CLIENT_SET_COLOUR_MAP_ENTRIES = 1,
|
|
|
|
RFB_SERVER_TO_CLIENT_BELL = 2,
|
|
|
|
RFB_SERVER_TO_CLIENT_SERVER_CUT_TEXT = 3,
|
2019-08-25 16:40:59 +00:00
|
|
|
};
|
|
|
|
|
2020-01-25 15:35:14 +00:00
|
|
|
enum rfb_vencrypt_subtype {
|
|
|
|
RFB_VENCRYPT_PLAIN = 256,
|
|
|
|
RFB_VENCRYPT_TLS_NONE,
|
|
|
|
RFB_VENCRYPT_TLS_VNC,
|
|
|
|
RFB_VENCRYPT_TLS_PLAIN,
|
|
|
|
RFB_VENCRYPT_X509_NONE,
|
|
|
|
RFB_VENCRYPT_X509_VNC,
|
|
|
|
RFB_VENCRYPT_X509_PLAIN,
|
|
|
|
};
|
|
|
|
|
2019-08-12 20:49:23 +00:00
|
|
|
struct rfb_security_types_msg {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t n;
|
|
|
|
uint8_t types[1];
|
2019-08-12 20:49:23 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_error_reason {
|
|
|
|
uint32_t length;
|
|
|
|
char message[0];
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_pixel_format {
|
|
|
|
uint8_t bits_per_pixel;
|
|
|
|
uint8_t depth;
|
|
|
|
uint8_t big_endian_flag;
|
|
|
|
uint8_t true_colour_flag;
|
|
|
|
uint16_t red_max;
|
|
|
|
uint16_t green_max;
|
|
|
|
uint16_t blue_max;
|
|
|
|
uint8_t red_shift;
|
|
|
|
uint8_t green_shift;
|
|
|
|
uint8_t blue_shift;
|
|
|
|
uint8_t padding[3];
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_server_init_msg {
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
struct rfb_pixel_format pixel_format;
|
|
|
|
uint32_t name_length;
|
|
|
|
char name_string[0];
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
2019-08-12 23:33:06 +00:00
|
|
|
struct rfb_client_set_encodings_msg {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t padding;
|
|
|
|
uint16_t n_encodings;
|
|
|
|
int32_t encodings[0];
|
2019-08-12 23:33:06 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_client_fb_update_req_msg {
|
|
|
|
uint8_t type;
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t incremental;
|
|
|
|
uint16_t x;
|
|
|
|
uint16_t y;
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
2019-08-12 23:33:06 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_client_key_event_msg {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t down_flag;
|
|
|
|
uint16_t padding;
|
|
|
|
uint32_t key;
|
2019-08-12 23:33:06 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
2020-11-29 17:05:58 +00:00
|
|
|
struct rfb_client_qemu_key_event_msg {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t subtype;
|
|
|
|
uint16_t down_flag;
|
|
|
|
uint32_t keysym;
|
|
|
|
uint32_t keycode;
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
2019-08-12 23:33:06 +00:00
|
|
|
struct rfb_client_pointer_event_msg {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t button_mask;
|
|
|
|
uint16_t x;
|
|
|
|
uint16_t y;
|
2019-08-12 23:33:06 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
2020-09-16 22:10:15 +00:00
|
|
|
struct rfb_cut_text_msg {
|
2019-08-12 23:39:37 +00:00
|
|
|
uint8_t type;
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t padding[3];
|
|
|
|
uint32_t length;
|
2020-09-16 22:10:15 +00:00
|
|
|
char text[0];
|
2019-08-12 23:39:37 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
2019-08-25 16:40:59 +00:00
|
|
|
struct rfb_server_fb_rect {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint16_t x;
|
|
|
|
uint16_t y;
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
int32_t encoding;
|
2019-08-25 16:40:59 +00:00
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_server_fb_update_msg {
|
2019-10-20 22:13:51 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t padding;
|
|
|
|
uint16_t n_rects;
|
2019-08-25 16:40:59 +00:00
|
|
|
} RFB_PACKED;
|
2020-01-25 15:35:14 +00:00
|
|
|
|
|
|
|
struct rfb_vencrypt_version_msg {
|
|
|
|
uint8_t major;
|
|
|
|
uint8_t minor;
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_vencrypt_subtypes_msg {
|
|
|
|
uint8_t n;
|
|
|
|
uint32_t types[1];
|
|
|
|
} RFB_PACKED;
|
|
|
|
|
|
|
|
struct rfb_vencrypt_plain_auth_msg {
|
|
|
|
uint32_t username_len;
|
|
|
|
uint32_t password_len;
|
|
|
|
char text[0];
|
|
|
|
} RFB_PACKED;
|