Contiki 2.5
vnc-server.h
1 /*
2  * Copyright (c) 2001, Adam Dunkels.
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  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote
14  * products derived from this software without specific prior
15  * written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the uIP TCP/IP stack.
30  *
31  * $Id: vnc-server.h,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $
32  *
33  */
34 
35 #ifndef __VNC_SERVER_H__
36 #define __VNC_SERVER_H__
37 
38 
39 /*struct vnc_server_updatearea {
40  u8_t active;
41  u8_t x, y;
42  u8_t w, h;
43  };*/
44 
45 struct vnc_server_update {
46  struct vnc_server_update *next;
47 
48 #define VNC_SERVER_UPDATE_NONE 0
49 #define VNC_SERVER_UPDATE_PARTS 1
50 #define VNC_SERVER_UPDATE_FULL 2
51 
52  u8_t type;
53 
54  u8_t x, y;
55  u8_t w, h;
56 };
57 
58 struct vnc_server_state {
59  u16_t counter;
60  u8_t type;
61  u8_t state;
62  u16_t height, width;
63 
64  u8_t update_requested;
65 
66  /* Variables used when sending screen updates. */
67  u8_t x, y, x1, y1, x2, y2;
68  u8_t w, h;
69 
70 
71 
72  u16_t readlen;
73  u8_t sendmsg;
74  u8_t button;
75 
76 
77  struct vnc_server_update *updates_current;
78  struct vnc_server_update *updates_pending;
79  struct vnc_server_update *updates_free;
80 
81 #define VNC_SERVER_MAX_UPDATES 8
82  struct vnc_server_update updates_pool[VNC_SERVER_MAX_UPDATES];
83 
84 };
85 
86 struct vnc_server_update *
87  vnc_server_update_alloc(struct vnc_server_state *vs);
88 void vnc_server_update_free(struct vnc_server_state *vs,
89  struct vnc_server_update *a);
90 void vnc_server_update_remove(struct vnc_server_state *vs,
91  struct vnc_server_update *a);
92 
93 void vnc_server_update_add(struct vnc_server_state *vs,
94  struct vnc_server_update *a);
95 struct vnc_server_update *
96  vnc_server_update_dequeue(struct vnc_server_state *vs);
97 
98 
99 
100 
101 void vnc_server_init(void);
102 void vnc_server_appcall(struct vnc_server_state *state);
103 
104 
105 extern struct vnc_server_state *vs;
106 
107 enum {
108  VNC_DEALLOCATED,
109  VNC_VERSION,
110  VNC_VERSION2,
111  VNC_AUTH,
112  VNC_AUTH2,
113  VNC_INIT,
114  VNC_INIT2,
115  VNC_RUNNING
116 };
117 
118 /* Sendmsg */
119 enum {
120  SEND_NONE,
121  SEND_BLANK,
122  SENT_BLANK,
123  SEND_SCREEN,
124  SEND_UPDATE
125 };
126 
127 
128 /* Definitions of the RFB (Remote Frame Buffer) protocol
129  structures and constants. */
130 
131 #include "contiki-net.h"
132 
133 void vnc_server_send_data(struct vnc_server_state *vs);
134 u8_t vnc_server_draw_rect(u8_t *ptr, u16_t x, u16_t y, u16_t w, u16_t h, u8_t c);
135 
136 
137 /* Generic rectangle - x, y coordinates, width and height. */
138 struct rfb_rect {
139  u16_t x;
140  u16_t y;
141  u16_t w;
142  u16_t h;
143 };
144 
145 /* Pixel format definition. */
146 struct rfb_pixel_format {
147  u8_t bps; /* Bits per pixel: 8, 16 or 32. */
148  u8_t depth; /* Color depth: 8-32 */
149  u8_t endian; /* 1 - big endian (motorola), 0 - little endian
150  (x86) */
151  u8_t truecolor; /* 1 - true color is used, 0 - true color is not used. */
152 
153  /* The following fields are only used if true color is used. */
154  u16_t red_max, green_max, blue_max;
155  u8_t red_shift, green_shift, blue_shift;
156  u8_t pad1;
157  u16_t pad2;
158 };
159 
160 
161 /* RFB authentication constants. */
162 
163 #define RFB_AUTH_FAILED 0
164 #define RFB_AUTH_NONE 1
165 #define RFB_AUTH_VNC 2
166 
167 #define RFB_VNC_AUTH_OK 0
168 #define RFB_VNC_AUTH_FAILED 1
169 #define RFB_VNC_AUTH_TOOMANY 2
170 
171 /* RFB message types. */
172 
173 /* From server to client: */
174 #define RFB_FB_UPDATE 0
175 #define RFB_SET_COLORMAP_ENTRIES 1
176 #define RFB_BELL 2
177 #define RFB_SERVER_CUT_TEXT 3
178 
179 /* From client to server. */
180 #define RFB_SET_PIXEL_FORMAT 0
181 #define RFB_FIX_COLORMAP_ENTRIES 1
182 #define RFB_SET_ENCODINGS 2
183 #define RFB_FB_UPDATE_REQ 3
184 #define RFB_KEY_EVENT 4
185 #define RFB_POINTER_EVENT 5
186 #define RFB_CLIENT_CUT_TEXT 6
187 
188 /* Encoding types. */
189 #define RFB_ENC_RAW 0
190 #define RFB_ENC_COPYRECT 1
191 #define RFB_ENC_RRE 2
192 #define RFB_ENC_CORRE 3
193 #define RFB_ENC_HEXTILE 4
194 
195 /* Message definitions. */
196 
197 /* Server to client messages. */
198 
199 struct rfb_server_init {
200  u16_t width;
201  u16_t height;
202  struct rfb_pixel_format format;
203  u8_t namelength[4];
204  /* Followed by name. */
205 };
206 
207 struct rfb_fb_update {
208  u8_t type;
209  u8_t pad;
210  u16_t rects; /* Number of rectanges (struct rfb_fb_update_rect_hdr +
211  data) that follows. */
212 };
213 
214 struct rfb_fb_update_rect_hdr {
215  struct rfb_rect rect;
216  u8_t encoding[4];
217 };
218 
219 struct rfb_copy_rect {
220  u16_t srcx;
221  u16_t srcy;
222 };
223 
224 struct rfb_rre_hdr {
225  u16_t subrects[2]; /* Number of subrectangles (struct
226  rfb_rre_subrect) to follow. */
227  u8_t bgpixel;
228 };
229 
230 struct rfb_rre_subrect {
231  u8_t pixel;
232  struct rfb_rect rect;
233 };
234 
235 struct rfb_corre_rect {
236  u8_t x;
237  u8_t y;
238  u8_t w;
239  u8_t h;
240 };
241 
242 /* Client to server messages. */
243 
244 struct rfb_set_pixel_format {
245  u8_t type;
246  u8_t pad;
247  u16_t pad2;
248  struct rfb_pixel_format format;
249 };
250 
251 struct rfb_fix_colormap_entries {
252  u8_t type;
253  u8_t pad;
254  u16_t firstcolor;
255  u16_t colors;
256 };
257 
258 struct rfb_set_encoding {
259  u8_t type;
260  u8_t pad;
261  u16_t encodings;
262 };
263 
264 struct rfb_fb_update_request {
265  u8_t type;
266  u8_t incremental;
267  u16_t x;
268  u16_t y;
269  u16_t w;
270  u16_t h;
271 };
272 
273 struct rfb_key_event {
274  u8_t type;
275  u8_t down;
276  u16_t pad;
277  u8_t key[4];
278 };
279 
280 #define RFB_BUTTON_MASK1 1
281 #define RFB_BUTTON_MASK2 2
282 #define RFB_BUTTON_MASK3 4
283 struct rfb_pointer_event {
284  u8_t type;
285  u8_t buttonmask;
286  u16_t x;
287  u16_t y;
288 };
289 
290 struct rfb_client_cut_text {
291  u8_t type;
292  u8_t pad[3];
293  u8_t len[4];
294 };
295 
296 #endif /* __VNC_SERVER_H__ */