blob: e331f76ae839828a9a65190bf47c5d49c824f869 [file] [log] [blame]
adamdunkelse0cc0582003-04-08 19:41:23 +00001/*
2 * Copyright (c) 2002, 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
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
adamdunkels06f897e2004-06-06 05:59:20 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkelse0cc0582003-04-08 19:41:23 +000015 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the Contiki VNC client.
31 *
adamdunkels0c388812004-09-12 07:32:05 +000032 * $Id: vnc-viewer.h,v 1.8 2004/09/12 07:33:26 adamdunkels Exp $
adamdunkelse0cc0582003-04-08 19:41:23 +000033 *
34 */
35
36#ifndef __VNC_VIEWER_H__
37#define __VNC_VIEWER_H__
38
adamdunkelsf2f8cb22004-07-04 11:35:07 +000039#include "ek.h"
adamdunkels2e415422003-04-10 09:04:49 +000040
adamdunkelse0cc0582003-04-08 19:41:23 +000041struct vnc_viewer_state;
42
adamdunkels0e9d8ed2003-11-27 15:52:03 +000043typedef unsigned long u32_t;
44
adamdunkelse0cc0582003-04-08 19:41:23 +000045void vnc_viewer_init(void);
adamdunkels0c388812004-09-12 07:32:05 +000046void vnc_viewer_appcall(void *nullptr);
adamdunkelse0cc0582003-04-08 19:41:23 +000047
48void vnc_viewer_connect(u16_t *server, u8_t display);
49void vnc_viewer_close(void);
50
51/* Callback: redraws the VNC viewer bitmap area. */
52void vnc_viewer_refresh(void);
53
54#define VNC_POINTER_EVENT RFB_POINTER_EVENT
55#define VNC_KEY_EVENT RFB_KEY_EVENT
56#define VNC_UPDATERQ_EVENT 7
57
adamdunkels8539c152003-04-17 18:55:38 +000058#define VNC_VIEWER_POST_POINTER_EVENT(x, y, button) \
59 vnc_viewer_post_event(VNC_POINTER_EVENT, button, x, y, 0)
60
61#define VNC_VIEWER_POST_KEY_EVENT(key) \
62 vnc_viewer_post_event(VNC_KEY_EVENT, key, 0, 0, 0)
63
64#define VNC_VIEWER_POST_UPDATERQ_EVENT(x1,y1,x2,y2) \
65 vnc_viewer_post_event(VNC_UPDATERQ_EVENT, x1, y1, x2, y2)
66
adamdunkelse0cc0582003-04-08 19:41:23 +000067void vnc_viewer_post_event(u8_t event,
68 u16_t data1, u16_t data2,
69 u16_t data3, u16_t data4);
70
71/* UIP_APPCALL: the name of the application function. This function
72 must return void and take no arguments (i.e., C type "void
73 appfunc(void)"). */
74#ifndef UIP_APPCALL
75#define UIP_APPCALL vnc_viewer_app
76#endif
77
78struct vnc_key_event {
79 u8_t down;
80 u16_t key;
81};
82
83struct vnc_pointer_event {
84 u8_t buttonmask;
85 u16_t x, y;
86};
87
88struct vnc_updaterq_event {
89 u16_t x, y;
90 u16_t w, h;
91};
92
93struct vnc_event {
94 u8_t type;
95 union {
96 struct vnc_key_event key;
97 struct vnc_pointer_event ptr;
98 struct vnc_updaterq_event urq;
99 } ev;
100};
101
102enum vnc_sendmsg {
103 VNC_SEND_NONE,
104
105 VNC_SEND_VERSION,
106 VNC_SEND_AUTH,
107 VNC_SEND_CINIT,
108 VNC_SEND_PFMT,
109 VNC_SEND_ENCODINGS,
110
111 VNC_SEND_UPDATERQ,
112 VNC_SEND_UPDATERQ_INC,
113 VNC_SEND_EVENTS,
114};
115
116enum vnc_waitmsg {
117 VNC_WAIT_NONE,
118
119 VNC_WAIT_VERSION,
120 VNC_WAIT_AUTH,
121 VNC_WAIT_AUTH_RESPONSE,
122 VNC_WAIT_SINIT,
123
124 VNC_WAIT_UPDATE,
125 VNC_WAIT_UPDATE_RECT,
126
127};
128
129
130enum vnc_rectstate {
131 VNC_RECTSTATE_NONE,
132 VNC_RECTSTATE_RAW,
133 VNC_RECTSTATE_RRE,
134};
135
136struct vnc_viewer_state {
137 u8_t close;
138 u16_t w, h;
139
140 u8_t sendmsg;
141
142 u8_t waitmsg;
143
144 u16_t rectsleft;
145
146 u8_t rectstate;
147 u32_t rectstateleft;
148 u16_t rectstatex, rectstatey;
149 u16_t rectstateh, rectstatew;
150 u16_t rectstatex0, rectstatey0;
151 u16_t rectstatex2, rectstatey2;
152
153
154 u16_t eventptr_acked;
155 u16_t eventptr_unacked;
156 u16_t eventptr_next;
157#define VNC_EVENTQUEUE_SIZE 32
158 struct vnc_event event_queue[VNC_EVENTQUEUE_SIZE];
159
160
161 u16_t bufferleft;
162 u16_t buffersize;
163#define VNC_BUFFERSIZE 64
164 u8_t buffer[VNC_BUFFERSIZE];
165};
166
167extern struct vnc_viewer_state vnc_viewer_state;
168
169/* Definitions of the RFB (Remote Frame Buffer) protocol
170 structures and constants. */
171
172#include "uipopt.h"
173
174
175/* Generic rectangle - x, y coordinates, width and height. */
176struct rfb_rect {
177 u16_t x;
178 u16_t y;
179 u16_t w;
180 u16_t h;
181};
182
183/* Pixel format definition. */
184struct rfb_pixel_format {
185 u8_t bps; /* Bits per pixel: 8, 16 or 32. */
186 u8_t depth; /* Color depth: 8-32 */
187 u8_t endian; /* 1 - big endian (motorola), 0 - little endian
188 (x86) */
189 u8_t truecolor; /* 1 - true color is used, 0 - true color is not used. */
190
191 /* The following fields are only used if true color is used. */
192 u16_t red_max, green_max, blue_max;
193 u8_t red_shift, green_shift, blue_shift;
194 u8_t pad1;
195 u16_t pad2;
196};
197
198
199/* RFB authentication constants. */
200
201#define RFB_AUTH_FAILED 0
202#define RFB_AUTH_NONE 1
203#define RFB_AUTH_VNC 2
204
205#define RFB_VNC_AUTH_OK 0
206#define RFB_VNC_AUTH_FAILED 1
207#define RFB_VNC_AUTH_TOOMANY 2
208
209/* RFB message types. */
210
211/* From server to client: */
212#define RFB_FB_UPDATE 0
213#define RFB_SET_COLORMAP_ENTRIES 1
214#define RFB_BELL 2
215#define RFB_SERVER_CUT_TEXT 3
216
217/* From client to server. */
218#define RFB_SET_PIXEL_FORMAT 0
219#define RFB_FIX_COLORMAP_ENTRIES 1
220#define RFB_SET_ENCODINGS 2
221#define RFB_FB_UPDATE_REQ 3
222#define RFB_KEY_EVENT 4
223#define RFB_POINTER_EVENT 5
224#define RFB_CLIENT_CUT_TEXT 6
225
226/* Encoding types. */
227#define RFB_ENC_RAW 0
228#define RFB_ENC_COPYRECT 1
229#define RFB_ENC_RRE 2
230#define RFB_ENC_CORRE 3
231#define RFB_ENC_HEXTILE 4
232
233/* Message definitions. */
234
235/* Server to client messages. */
236
237struct rfb_server_init {
238 u16_t width;
239 u16_t height;
240 struct rfb_pixel_format format;
241 u8_t namelength[4];
242 /* Followed by name. */
243};
244
245struct rfb_fb_update {
246 u8_t type;
247 u8_t pad;
248 u16_t rects; /* Number of rectanges (struct rfb_fb_update_rect_hdr +
249 data) that follows. */
250};
251
252struct rfb_fb_update_rect_hdr {
253 struct rfb_rect rect;
254 u8_t encoding[4];
255};
256
257struct rfb_copy_rect {
258 u16_t srcx;
259 u16_t srcy;
260};
261
262struct rfb_rre_hdr {
263 u16_t subrects[2]; /* Number of subrectangles (struct
264 rfb_rre_subrect) to follow. */
265 u8_t bgpixel;
266};
267
268struct rfb_rre_subrect {
269 u8_t pixel;
270 struct rfb_rect rect;
271};
272
273struct rfb_corre_rect {
274 u8_t x;
275 u8_t y;
276 u8_t w;
277 u8_t h;
278};
279
280/* Client to server messages. */
281
282struct rfb_set_pixel_format {
283 u8_t type;
284 u8_t pad;
285 u16_t pad2;
286 struct rfb_pixel_format format;
287};
288
289struct rfb_fix_colormap_entries {
290 u8_t type;
291 u8_t pad;
292 u16_t firstcolor;
293 u16_t colors;
294};
295
296struct rfb_set_encodings {
297 u8_t type;
298 u8_t pad;
299 u16_t encodings;
300};
301
302struct rfb_fb_update_request {
303 u8_t type;
304 u8_t incremental;
305 u16_t x;
306 u16_t y;
307 u16_t w;
308 u16_t h;
309};
310
311struct rfb_key_event {
312 u8_t type;
313 u8_t down;
314 u16_t pad;
315 u8_t key[4];
316};
317
318#define RFB_BUTTON_MASK1 1
319#define RFB_BUTTON_MASK2 2
320#define RFB_BUTTON_MASK3 4
321struct rfb_pointer_event {
322 u8_t type;
323 u8_t buttonmask;
324 u16_t x;
325 u16_t y;
326};
327
oliverschmidte9a32572004-08-22 12:35:12 +0000328#endif /* __VNC_VIEWER_H__ */