1 | /*
|
---|
2 | * Copyright (c) 2013 Martin Sucha
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef RFB_H__
|
---|
30 | #define RFB_H__
|
---|
31 |
|
---|
32 | #include <inet/tcp.h>
|
---|
33 | #include <io/pixelmap.h>
|
---|
34 | #include <fibril_synch.h>
|
---|
35 |
|
---|
36 | #define RFB_SECURITY_NONE 1
|
---|
37 | #define RFB_SECURITY_HANDSHAKE_OK 0
|
---|
38 |
|
---|
39 | #define RFB_CMSG_SET_PIXEL_FORMAT 0
|
---|
40 | #define RFB_CMSG_SET_ENCODINGS 2
|
---|
41 | #define RFB_CMSG_FRAMEBUFFER_UPDATE_REQUEST 3
|
---|
42 | #define RFB_CMSG_KEY_EVENT 4
|
---|
43 | #define RFB_CMSG_POINTER_EVENT 5
|
---|
44 | #define RFB_CMSG_CLIENT_CUT_TEXT 6
|
---|
45 |
|
---|
46 | #define RFB_SMSG_FRAMEBUFFER_UPDATE 0
|
---|
47 | #define RFB_SMSG_SET_COLOR_MAP_ENTRIES 1
|
---|
48 | #define RFB_SMSG_BELL 2
|
---|
49 | #define RFB_SMSG_SERVER_CUT_TEXT 3
|
---|
50 |
|
---|
51 | #define RFB_ENCODING_RAW 0
|
---|
52 | #define RFB_ENCODING_TRLE 15
|
---|
53 |
|
---|
54 | #define RFB_TILE_ENCODING_RAW 0
|
---|
55 | #define RFB_TILE_ENCODING_SOLID 1
|
---|
56 |
|
---|
57 | typedef struct {
|
---|
58 | uint8_t bpp;
|
---|
59 | uint8_t depth;
|
---|
60 | uint8_t big_endian;
|
---|
61 | uint8_t true_color;
|
---|
62 | uint16_t r_max;
|
---|
63 | uint16_t g_max;
|
---|
64 | uint16_t b_max;
|
---|
65 | uint8_t r_shift;
|
---|
66 | uint8_t g_shift;
|
---|
67 | uint8_t b_shift;
|
---|
68 | uint8_t pad[3];
|
---|
69 | } __attribute__((packed)) rfb_pixel_format_t;
|
---|
70 |
|
---|
71 | typedef struct {
|
---|
72 | uint16_t width;
|
---|
73 | uint16_t height;
|
---|
74 | rfb_pixel_format_t pixel_format;
|
---|
75 | uint32_t name_length;
|
---|
76 | char name[0];
|
---|
77 | } __attribute__((packed)) rfb_server_init_t;
|
---|
78 |
|
---|
79 | typedef struct {
|
---|
80 | uint8_t message_type;
|
---|
81 | uint8_t pad[3];
|
---|
82 | rfb_pixel_format_t pixel_format;
|
---|
83 | } __attribute__((packed)) rfb_set_pixel_format_t;
|
---|
84 |
|
---|
85 | typedef struct {
|
---|
86 | uint8_t message_type;
|
---|
87 | uint8_t pad;
|
---|
88 | uint16_t count;
|
---|
89 | } __attribute__((packed)) rfb_set_encodings_t;
|
---|
90 |
|
---|
91 | typedef struct {
|
---|
92 | uint8_t message_type;
|
---|
93 | uint8_t incremental;
|
---|
94 | uint16_t x;
|
---|
95 | uint16_t y;
|
---|
96 | uint16_t width;
|
---|
97 | uint16_t height;
|
---|
98 | } __attribute__((packed)) rfb_framebuffer_update_request_t;
|
---|
99 |
|
---|
100 | typedef struct {
|
---|
101 | uint8_t message_type;
|
---|
102 | uint8_t down_flag;
|
---|
103 | uint8_t pad[2];
|
---|
104 | uint32_t key;
|
---|
105 | } __attribute__((packed)) rfb_key_event_t;
|
---|
106 |
|
---|
107 | typedef struct {
|
---|
108 | uint8_t message_type;
|
---|
109 | uint8_t button_mask;
|
---|
110 | uint16_t x;
|
---|
111 | uint16_t y;
|
---|
112 | } __attribute__((packed)) rfb_pointer_event_t;
|
---|
113 |
|
---|
114 | typedef struct {
|
---|
115 | uint8_t message_type;
|
---|
116 | uint8_t pad;
|
---|
117 | uint32_t length;
|
---|
118 | char text[0];
|
---|
119 | } __attribute__((packed)) rfb_client_cut_text_t;
|
---|
120 |
|
---|
121 | typedef struct {
|
---|
122 | uint16_t x;
|
---|
123 | uint16_t y;
|
---|
124 | uint16_t width;
|
---|
125 | uint16_t height;
|
---|
126 | int32_t enctype;
|
---|
127 | uint8_t data[0];
|
---|
128 | } __attribute__((packed)) rfb_rectangle_t;
|
---|
129 |
|
---|
130 | typedef struct {
|
---|
131 | uint8_t message_type;
|
---|
132 | uint8_t pad;
|
---|
133 | uint16_t rect_count;
|
---|
134 | } __attribute__((packed)) rfb_framebuffer_update_t;
|
---|
135 |
|
---|
136 | typedef struct {
|
---|
137 | uint8_t message_type;
|
---|
138 | uint8_t pad;
|
---|
139 | uint16_t first_color;
|
---|
140 | uint16_t color_count;
|
---|
141 | } __attribute__((packed)) rfb_set_color_map_entries_t;
|
---|
142 |
|
---|
143 | typedef struct {
|
---|
144 | uint16_t red;
|
---|
145 | uint16_t green;
|
---|
146 | uint16_t blue;
|
---|
147 | } __attribute__((packed)) rfb_color_map_entry_t;
|
---|
148 |
|
---|
149 | typedef struct {
|
---|
150 | uint16_t width;
|
---|
151 | uint16_t height;
|
---|
152 | rfb_pixel_format_t pixel_format;
|
---|
153 | const char *name;
|
---|
154 | tcp_t *tcp;
|
---|
155 | tcp_listener_t *lst;
|
---|
156 | pixelmap_t framebuffer;
|
---|
157 | rfb_rectangle_t damage_rect;
|
---|
158 | bool damage_valid;
|
---|
159 | fibril_mutex_t lock;
|
---|
160 | pixel_t *palette;
|
---|
161 | size_t palette_used;
|
---|
162 | bool supports_trle;
|
---|
163 | } rfb_t;
|
---|
164 |
|
---|
165 | extern errno_t rfb_init(rfb_t *, uint16_t, uint16_t, const char *);
|
---|
166 | extern errno_t rfb_set_size(rfb_t *, uint16_t, uint16_t);
|
---|
167 | extern errno_t rfb_listen(rfb_t *, uint16_t);
|
---|
168 |
|
---|
169 | #endif
|
---|