adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 1 | /* |
| 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. |
adamdunkels | 06f897e | 2004-06-06 05:59:20 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 15 | * 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 | * |
adamdunkels | 0c38881 | 2004-09-12 07:32:05 +0000 | [diff] [blame] | 32 | * $Id: vnc-viewer.h,v 1.8 2004/09/12 07:33:26 adamdunkels Exp $ |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
| 36 | #ifndef __VNC_VIEWER_H__ |
| 37 | #define __VNC_VIEWER_H__ |
| 38 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 39 | #include "ek.h" |
adamdunkels | 2e41542 | 2003-04-10 09:04:49 +0000 | [diff] [blame] | 40 | |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 41 | struct vnc_viewer_state; |
| 42 | |
adamdunkels | 0e9d8ed | 2003-11-27 15:52:03 +0000 | [diff] [blame] | 43 | typedef unsigned long u32_t; |
| 44 | |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 45 | void vnc_viewer_init(void); |
adamdunkels | 0c38881 | 2004-09-12 07:32:05 +0000 | [diff] [blame] | 46 | void vnc_viewer_appcall(void *nullptr); |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 47 | |
| 48 | void vnc_viewer_connect(u16_t *server, u8_t display); |
| 49 | void vnc_viewer_close(void); |
| 50 | |
| 51 | /* Callback: redraws the VNC viewer bitmap area. */ |
| 52 | void 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 | |
adamdunkels | 8539c15 | 2003-04-17 18:55:38 +0000 | [diff] [blame] | 58 | #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 | |
adamdunkels | e0cc058 | 2003-04-08 19:41:23 +0000 | [diff] [blame] | 67 | void 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 | |
| 78 | struct vnc_key_event { |
| 79 | u8_t down; |
| 80 | u16_t key; |
| 81 | }; |
| 82 | |
| 83 | struct vnc_pointer_event { |
| 84 | u8_t buttonmask; |
| 85 | u16_t x, y; |
| 86 | }; |
| 87 | |
| 88 | struct vnc_updaterq_event { |
| 89 | u16_t x, y; |
| 90 | u16_t w, h; |
| 91 | }; |
| 92 | |
| 93 | struct 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 | |
| 102 | enum 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 | |
| 116 | enum 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 | |
| 130 | enum vnc_rectstate { |
| 131 | VNC_RECTSTATE_NONE, |
| 132 | VNC_RECTSTATE_RAW, |
| 133 | VNC_RECTSTATE_RRE, |
| 134 | }; |
| 135 | |
| 136 | struct 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 | |
| 167 | extern 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. */ |
| 176 | struct rfb_rect { |
| 177 | u16_t x; |
| 178 | u16_t y; |
| 179 | u16_t w; |
| 180 | u16_t h; |
| 181 | }; |
| 182 | |
| 183 | /* Pixel format definition. */ |
| 184 | struct 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 | |
| 237 | struct 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 | |
| 245 | struct 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 | |
| 252 | struct rfb_fb_update_rect_hdr { |
| 253 | struct rfb_rect rect; |
| 254 | u8_t encoding[4]; |
| 255 | }; |
| 256 | |
| 257 | struct rfb_copy_rect { |
| 258 | u16_t srcx; |
| 259 | u16_t srcy; |
| 260 | }; |
| 261 | |
| 262 | struct rfb_rre_hdr { |
| 263 | u16_t subrects[2]; /* Number of subrectangles (struct |
| 264 | rfb_rre_subrect) to follow. */ |
| 265 | u8_t bgpixel; |
| 266 | }; |
| 267 | |
| 268 | struct rfb_rre_subrect { |
| 269 | u8_t pixel; |
| 270 | struct rfb_rect rect; |
| 271 | }; |
| 272 | |
| 273 | struct 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 | |
| 282 | struct rfb_set_pixel_format { |
| 283 | u8_t type; |
| 284 | u8_t pad; |
| 285 | u16_t pad2; |
| 286 | struct rfb_pixel_format format; |
| 287 | }; |
| 288 | |
| 289 | struct rfb_fix_colormap_entries { |
| 290 | u8_t type; |
| 291 | u8_t pad; |
| 292 | u16_t firstcolor; |
| 293 | u16_t colors; |
| 294 | }; |
| 295 | |
| 296 | struct rfb_set_encodings { |
| 297 | u8_t type; |
| 298 | u8_t pad; |
| 299 | u16_t encodings; |
| 300 | }; |
| 301 | |
| 302 | struct 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 | |
| 311 | struct 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 |
| 321 | struct rfb_pointer_event { |
| 322 | u8_t type; |
| 323 | u8_t buttonmask; |
| 324 | u16_t x; |
| 325 | u16_t y; |
| 326 | }; |
| 327 | |
oliverschmidt | e9a3257 | 2004-08-22 12:35:12 +0000 | [diff] [blame] | 328 | #endif /* __VNC_VIEWER_H__ */ |