Merge pull request #474 from adamdunkels/push/cleanup-vnc

Remove the VNC client and server
This commit is contained in:
Nicolas Tsiftes 2013-11-29 05:07:53 -08:00
commit 65392ce59e
18 changed files with 0 additions and 5833 deletions

View File

@ -71,7 +71,6 @@ include $(CONTIKI)/core/net/Makefile.uip
include $(CONTIKI)/core/net/rpl/Makefile.rpl
CTK = ctk.c
CTKVNC = $(CTK) ctk-vncserver.c libconio.c vnc-server.c vnc-out.c ctk-vncfont.c
ifndef CONTIKI_NO_NET
CONTIKIFILES = $(SYSTEM) $(LIBS) $(NET) $(THREADS) $(DHCP) $(DEV)

View File

@ -1,2 +0,0 @@
vnc_src = vnc.c vnc-viewer.c vnc-draw.c
vnc_dsc = vnc-dsc.c

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2002, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki VNC client.
*
*
*/
#ifndef VNC_DRAW_H_
#define VNC_DRAW_H_
#include "net/uip_arch.h"
/* Pointer to the bitmap area in memory. */
extern uint8_t vnc_draw_bitmap[];
/* Initialize the vnc-draw module. */
void vnc_draw_init(void);
/* Draw one line of pixels starting at point (x, y). The pixel data is
given by the "data" argument and the length of data is given by the
"datalen" argument. The data format is one pixel per byte in bgr233
format (bbgggrrr). */
void vnc_draw_pixelline(uint16_t x, uint16_t y,
uint8_t *data, uint16_t datalen);
/* The following functions should return the x and y coordinates and
the width and height of the viewport. */
uint16_t vnc_draw_viewport_x(void);
uint16_t vnc_draw_viewport_y(void);
uint16_t vnc_draw_viewport_w(void);
uint16_t vnc_draw_viewport_h(void);
#endif /* VNC_DRAW_H_ */

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki desktop environment
*
*
*/
#include "sys/dsc.h"
/*-----------------------------------------------------------------------------------*/
#if CTK_CONF_ICON_BITMAPS
static unsigned char vncicon_bitmap[3*3*8] = {
0x00, 0x7e, 0x40, 0x73, 0x46, 0x4c, 0x18, 0x13,
0x00, 0x00, 0xff, 0x81, 0x34, 0xc9, 0x00, 0xb6,
0x00, 0x7e, 0x02, 0xce, 0x72, 0x32, 0x18, 0x48,
0x30, 0x27, 0x24, 0x20, 0x37, 0x24, 0x20, 0x33,
0x00, 0x7b, 0x42, 0x00, 0x7b, 0x42, 0x00, 0x3b,
0x0c, 0x24, 0x24, 0x04, 0xa4, 0x24, 0x04, 0x4c,
0x12, 0x19, 0x4c, 0x46, 0x63, 0x40, 0x7c, 0x00,
0x22, 0x91, 0x00, 0xc4, 0x81, 0xff, 0x00, 0x00,
0x08, 0x18, 0x32, 0x62, 0xc6, 0x02, 0x3e, 0x00
};
#endif /* CTK_CONF_ICON_BITMAPS */
#if CTK_CONF_ICON_TEXTMAPS
static char vncicon_textmap[9] = {
'V', 'N', 'C',
'c', 'l', 'i',
'e', 'n', 't'
};
#endif /* CTK_CONF_ICON_TEXTMAPS */
#if CTK_CONF_ICONS
static struct ctk_icon vnc_icon =
{CTK_ICON("VNC viewer", vncicon_bitmap, vncicon_textmap)};
#endif /* CTK_CONF_ICONS */
/*-----------------------------------------------------------------------------------*/
DSC(vnc_dsc,
"Remote control your PC using Contiki",
"vnc.prg",
vnc_process,
&vnc_icon);
/*-----------------------------------------------------------------------------------*/

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki desktop environment
*
*
*/
#ifndef VNC_DSC_H_
#define VNC_DSC_H_
#include "sys/dsc.h"
DSC_HEADER(vnc_dsc);
#endif /* VNC_DSC_H_ */

View File

@ -1,754 +0,0 @@
/*
* Copyright (c) 2001, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
*
*/
/* A micro implementation of a VNC client. VNC is a protocol for
remote network displays. See http://www.uk.research.att.com/vnc/
for information about VNC.
*/
#include "vnc-draw.h"
#include "net/uip.h"
#include "vnc-viewer.h"
#include <string.h> /* XXX for memcpy */
#include <stdio.h> /* XXX for printf */
/* RFB server initial handshaking string. */
#define RFB_SERVER_VERSION_STRING rfb_server_version_string
/* "RFB 003.003" */
static uint8_t rfb_server_version_string[12] =
{82,70,66,32,48,48,51,46,48,48,51,10};
#if 0
#define PRINTF(x)
#else
#define PRINTF(x) printf x
#endif
#ifndef NULL
#define NULL (void *)0
#endif
static struct vnc_viewer_state vnc_viewer_state;
#define vs (&vnc_viewer_state)
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_init(void)
{
}
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_close(void)
{
vs->close = 1;
}
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_connect(uint16_t *server, uint8_t display)
{
struct uip_conn *conn;
vnc_draw_init();
memset(vs, 0, sizeof(struct vnc_viewer_state));
conn = uip_connect((uip_ipaddr_t *)server, uip_htons(5900 + display));
if(conn == NULL) {
return;
}
tcp_markconn(conn, NULL);
vs->close = 0;
}
/*-----------------------------------------------------------------------------------*/
static void
senddata(void)
{
register uint8_t *dataptr;
uint16_t dataleft;
dataptr = (uint8_t *)uip_appdata;
switch(vs->sendmsg) {
case VNC_SEND_VERSION:
PRINTF(("Sending VERSION_STRING\n"));
uip_send(RFB_SERVER_VERSION_STRING, sizeof(RFB_SERVER_VERSION_STRING));
break;
case VNC_SEND_AUTH:
/* Send 16 bytes of encrypted challange response. */
/* XXX: not implemented. */
PRINTF(("Sending AUTH\n"));
uip_send(uip_appdata, 16);
break;
case VNC_SEND_CINIT:
PRINTF(("Sending CINIT\n"));
/* Send one byte of client init. */
*(uint8_t *)dataptr = 1;
uip_send(uip_appdata, 1);
break;
case VNC_SEND_PFMT:
PRINTF(("Sending PFMT\n"));
((struct rfb_set_pixel_format *)dataptr)->type = RFB_SET_PIXEL_FORMAT;
/* Set to BGR233 pixel format. */
((struct rfb_set_pixel_format *)dataptr)->format.bps = 8;
((struct rfb_set_pixel_format *)dataptr)->format.depth = 8;
((struct rfb_set_pixel_format *)dataptr)->format.endian = 1;
((struct rfb_set_pixel_format *)dataptr)->format.truecolor = 1;
((struct rfb_set_pixel_format *)dataptr)->format.red_max = uip_htons(7);
((struct rfb_set_pixel_format *)dataptr)->format.green_max = uip_htons(7);
((struct rfb_set_pixel_format *)dataptr)->format.blue_max = uip_htons(3);
((struct rfb_set_pixel_format *)dataptr)->format.red_shift = 0;
((struct rfb_set_pixel_format *)dataptr)->format.green_shift = 3;
((struct rfb_set_pixel_format *)dataptr)->format.blue_shift = 6;
uip_send(uip_appdata, sizeof(struct rfb_set_pixel_format));
break;
case VNC_SEND_ENCODINGS:
PRINTF(("Sending ENCODINGS\n"));
((struct rfb_set_encodings *)dataptr)->type = RFB_SET_ENCODINGS;
((struct rfb_set_encodings *)dataptr)->encodings = uip_htons(1);
dataptr += sizeof(struct rfb_set_encodings);
dataptr[0] = dataptr[1] = dataptr[2] = 0;
dataptr[3] = RFB_ENC_RAW;
/* ((uint8_t *)dataptr + sizeof(struct rfb_set_encodings))[4] =
((uint8_t *)dataptr + sizeof(struct rfb_set_encodings))[5] =
((uint8_t *)dataptr + sizeof(struct rfb_set_encodings))[6] = 0;
((uint8_t *)dataptr + sizeof(struct rfb_set_encodings))[7] = RFB_ENC_RRE;*/
uip_send(uip_appdata, sizeof(struct rfb_set_encodings) + 4);
break;
case VNC_SEND_UPDATERQ:
((struct rfb_fb_update_request *)dataptr)->type = RFB_FB_UPDATE_REQ;
((struct rfb_fb_update_request *)dataptr)->incremental = 0;
((struct rfb_fb_update_request *)dataptr)->x = uip_htons(vnc_draw_viewport_x());
((struct rfb_fb_update_request *)dataptr)->y = uip_htons(vnc_draw_viewport_y());
((struct rfb_fb_update_request *)dataptr)->w = uip_htons(vnc_draw_viewport_w());
((struct rfb_fb_update_request *)dataptr)->h = uip_htons(vnc_draw_viewport_h());
uip_send(uip_appdata, sizeof(struct rfb_fb_update_request));
break;
case VNC_SEND_UPDATERQ_INC:
((struct rfb_fb_update_request *)dataptr)->type = RFB_FB_UPDATE_REQ;
((struct rfb_fb_update_request *)dataptr)->incremental = 1;
((struct rfb_fb_update_request *)dataptr)->x = uip_htons(vnc_draw_viewport_x());
((struct rfb_fb_update_request *)dataptr)->y = uip_htons(vnc_draw_viewport_y());
((struct rfb_fb_update_request *)dataptr)->w = uip_htons(vnc_draw_viewport_w());
((struct rfb_fb_update_request *)dataptr)->h = uip_htons(vnc_draw_viewport_h());
uip_send(uip_appdata, sizeof(struct rfb_fb_update_request));
break;
case VNC_SEND_EVENTS:
dataleft = uip_mss();
vs->eventptr_unacked = vs->eventptr_acked;
while(vs->eventptr_unacked != vs->eventptr_next &&
dataleft > sizeof(struct rfb_key_event)) {
switch(vs->event_queue[vs->eventptr_unacked].type) {
case VNC_POINTER_EVENT:
((struct rfb_pointer_event *)dataptr)->type = RFB_POINTER_EVENT;
((struct rfb_pointer_event *)dataptr)->buttonmask =
vs->event_queue[vs->eventptr_unacked].ev.ptr.buttonmask;
((struct rfb_pointer_event *)dataptr)->x =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.ptr.x);
((struct rfb_pointer_event *)dataptr)->y =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.ptr.y);
/* uip_send(uip_appdata, sizeof(struct rfb_pointer_event));*/
dataptr += sizeof(struct rfb_pointer_event);
dataleft -= sizeof(struct rfb_pointer_event);
break;
case VNC_KEY_EVENT:
PRINTF(("Send key event.\n"));
((struct rfb_key_event *)dataptr)->type = RFB_KEY_EVENT;
((struct rfb_key_event *)dataptr)->down =
vs->event_queue[vs->eventptr_unacked].ev.key.down;
((struct rfb_key_event *)dataptr)->key[0] =
((struct rfb_key_event *)dataptr)->key[1];
((struct rfb_key_event *)dataptr)->key[2] =
vs->event_queue[vs->eventptr_unacked].ev.key.key >> 8;
((struct rfb_key_event *)dataptr)->key[3] =
vs->event_queue[vs->eventptr_unacked].ev.key.key & 0xff;
/* uip_send(uip_appdata, sizeof(struct rfb_key_event));*/
dataptr += sizeof(struct rfb_key_event);
dataleft -= sizeof(struct rfb_key_event);
break;
case VNC_UPDATERQ_EVENT:
((struct rfb_fb_update_request *)dataptr)->type = RFB_FB_UPDATE_REQ;
((struct rfb_fb_update_request *)dataptr)->incremental = 0;
((struct rfb_fb_update_request *)dataptr)->x =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.urq.x);
((struct rfb_fb_update_request *)dataptr)->y =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.urq.y);
((struct rfb_fb_update_request *)dataptr)->w =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.urq.w);
((struct rfb_fb_update_request *)dataptr)->h =
uip_htons(vs->event_queue[vs->eventptr_unacked].ev.urq.h);
/* uip_send(uip_appdata, sizeof(struct rfb_fb_update_request)); */
dataptr += sizeof(struct rfb_fb_update_request);
dataleft -= sizeof(struct rfb_fb_update_request);
break;
}
vs->eventptr_unacked = (vs->eventptr_unacked + 1) % VNC_EVENTQUEUE_SIZE;
}
uip_send(uip_appdata, uip_mss() - dataleft);
break;
}
}
/*-----------------------------------------------------------------------------------*/
static void
buffer_data(uint8_t *data, uint16_t datalen)
{
PRINTF(("Buffering %d bytes of data\n", datalen));
if(vs->buffersize + datalen > VNC_BUFFERSIZE) {
PRINTF(("Out of buffer space!\n"));
vs->buffersize = 0;
return;
}
memcpy(&(vs->buffer[vs->buffersize]), data, datalen);
vs->buffersize += datalen;
vs->bufferleft -= datalen;
}
/*-----------------------------------------------------------------------------------*/
static void
clearbuffer(void)
{
PRINTF(("Clearing buffer\n"));
vs->buffersize = 0;
}
/*-----------------------------------------------------------------------------------*/
/* Returns: the amount of bytes actually read. */
static uint16_t
recv_rectstate(uint8_t *dataptr, uint16_t datalen)
{
uint16_t pixels;
uint16_t pixelsleft;
switch(vs->rectstate) {
case VNC_RECTSTATE_RAW:
if(vs->rectstateleft > datalen) {
pixels = datalen;
vs->rectstateleft -= datalen;
} else {
pixels = vs->rectstateleft;
datalen = datalen - vs->rectstateleft;
vs->rectstateleft = 0;
vs->rectstate = VNC_RECTSTATE_NONE;
vs->sendmsg = VNC_SEND_NONE;
vs->waitmsg = VNC_WAIT_NONE;
vnc_viewer_refresh();
}
pixelsleft = pixels;
while(pixelsleft > 0) {
if(pixelsleft >= vs->rectstatex2 - vs->rectstatex) {
vnc_draw_pixelline(vs->rectstatex, vs->rectstatey,
dataptr,
vs->rectstatex2 - vs->rectstatex);
dataptr += vs->rectstatex2 - vs->rectstatex;
pixelsleft -= vs->rectstatex2 - vs->rectstatex;
vs->rectstatex = vs->rectstatex0;
++vs->rectstatey;
vnc_viewer_refresh();
} else {
vnc_draw_pixelline(vs->rectstatex, vs->rectstatey,
dataptr,
pixelsleft);
vs->rectstatex += pixelsleft;
pixelsleft = 0;
}
}
break;
case VNC_RECTSTATE_RRE:
break;
}
return pixels;
}
/*-----------------------------------------------------------------------------------*/
/* Returns: the amount of bytes that needs to be buffered before the
rect can be drawn. */
static unsigned short
recv_update_rect(CC_REGISTER_ARG struct rfb_fb_update_rect_hdr *rhdr,
uint16_t dataleft)
{
struct rfb_rre_hdr *rrehdr;
if((rhdr->encoding[0] |
rhdr->encoding[1] |
rhdr->encoding[2]) == 0) {
switch(rhdr->encoding[3]) {
case RFB_ENC_RAW:
vs->rectstateleft = (uint32_t)uip_htons(rhdr->rect.w) * (uint32_t)uip_htons(rhdr->rect.h);
vs->rectstate = VNC_RECTSTATE_RAW;
vs->rectstatex0 = vs->rectstatex = uip_htons(rhdr->rect.x);
vs->rectstatey0 = vs->rectstatey = uip_htons(rhdr->rect.y);
vs->rectstatew = uip_htons(rhdr->rect.w);
vs->rectstateh = uip_htons(rhdr->rect.h);
vs->rectstatex2 = vs->rectstatex0 + vs->rectstatew;
vs->rectstatey2 = vs->rectstatey0 + vs->rectstateh;
break;
case RFB_ENC_RRE:
rrehdr = (struct rfb_rre_hdr *)((uint8_t *)rhdr +
sizeof(struct rfb_fb_update_rect_hdr));
PRINTF(("Received RRE subrects %d (%d)\n",
(uip_htons(rrehdr->subrects[1]) << 16) +
uip_htons(rrehdr->subrects[0]),
rrehdr->bgpixel));
vs->rectstateleft = ((uint32_t)(uip_htons(rrehdr->subrects[1]) << 16) +
(uint32_t)uip_htons(rrehdr->subrects[0]));
vs->rectstate = VNC_RECTSTATE_RRE;
break;
default:
PRINTF(("Bad encoding %02x%02x%02x%02x\n", rhdr->encoding[0],
rhdr->encoding[1],rhdr->encoding[2],rhdr->encoding[3]));
break;
}
}
return 0;
PRINTF(("recv_update_rect: returning%d\n", vs->rectstateleft));
return sizeof(struct rfb_fb_update_rect_hdr) + vs->rectstateleft;
}
/*-----------------------------------------------------------------------------------*/
/* identify_data():
*
* This function looks at the state of the connection (i.e., if it is
* handshaking or in steady-state) as well as on the contents of the
* incoming message and returns the number of bytes of data that is to
* be expected.
*/
static uint16_t
identify_data(CC_REGISTER_ARG uint8_t *data, uint16_t datalen)
{
switch(vs->waitmsg) {
case VNC_WAIT_VERSION:
/* Expecting version string (12 bytes). */
return 12;
break;
case VNC_WAIT_AUTH:
return 4;
break;
case VNC_WAIT_AUTH_RESPONSE:
return 1;
break;
case VNC_WAIT_SINIT:
/* XXX: We should check that the entire message header is
received, otherwise we should buffer it. */
return sizeof(struct rfb_server_init) +
((struct rfb_server_init *)uip_appdata)->namelength[3] +
((struct rfb_server_init *)uip_appdata)->namelength[2];
case VNC_WAIT_UPDATE:
case VNC_WAIT_NONE:
switch(*data) {
case RFB_FB_UPDATE:
PRINTF(("RFB FB UPDATE received\n"));
return sizeof(struct rfb_fb_update);
case RFB_BELL:
return 1;
case RFB_SERVER_CUT_TEXT:
PRINTF(("Cut text received, unhandled\n"));
return 8 + (data[6] << 8) + data[7];
case RFB_SET_COLORMAP_ENTRIES:
uip_abort();
PRINTF(("Set colormap entries received, unhandled\n"));
return 0;
default:
uip_abort();
PRINTF(("Weird message type received (%d)\n", *(uint8_t *)uip_appdata));
return 0;
}
break;
case VNC_WAIT_UPDATE_RECT:
return sizeof(struct rfb_fb_update_rect_hdr);
default:
PRINTF(("identify: bad waitmsg %d\n", vs->waitmsg));
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
/* handle_data():
*
* Handles the data.
*/
static unsigned short
handle_data(CC_REGISTER_ARG uint8_t *data, uint16_t datalen)
{
switch(vs->waitmsg) {
case VNC_WAIT_VERSION:
/* Make sure we get the right version string from the server. */
/* XXX: not implemented. */
PRINTF(("Got version, waiting for auth, sending version\n"));
vs->waitmsg = VNC_WAIT_AUTH;
vs->sendmsg = VNC_SEND_VERSION;
break;
case VNC_WAIT_AUTH:
switch(data[3]) {
case RFB_AUTH_FAILED:
PRINTF(("Connection failed.\n"));
uip_abort();
return 0;
case RFB_AUTH_NONE:
vs->sendmsg = VNC_SEND_CINIT;
vs->waitmsg = VNC_WAIT_SINIT;
PRINTF(("No authentication needed.\n"));
break;
case RFB_AUTH_VNC:
vs->sendmsg = VNC_SEND_AUTH;
vs->waitmsg = VNC_WAIT_AUTH_RESPONSE;
PRINTF(("VNC authentication needed.\n"));
break;
}
break;
case VNC_WAIT_SINIT:
/* PRINTF(("Server init: w %d h %d, bps %d, d %d, name '%s'\n",
uip_htons(((struct rfb_server_init *)data)->width),
uip_htons(((struct rfb_server_init *)data)->height),
((struct rfb_server_init *)data)->format.bps,
((struct rfb_server_init *)data)->format.depth,
((uint8_t *)data + sizeof(struct rfb_server_init))));*/
vs->w = uip_htons(((struct rfb_server_init *)data)->width);
vs->h = uip_htons(((struct rfb_server_init *)data)->height);
vs->sendmsg = VNC_SEND_PFMT;
vs->waitmsg = VNC_WAIT_NONE;
break;
case VNC_WAIT_UPDATE:
case VNC_WAIT_NONE:
switch(*data) {
case RFB_FB_UPDATE:
vs->waitmsg = VNC_WAIT_UPDATE_RECT;
vs->rectsleft = uip_htons(((struct rfb_fb_update *)data)->rects);
PRINTF(("Handling RFB FB UPDATE for %d rects\n", vs->rectsleft));
break;
case RFB_BELL:
PRINTF(("BELL\n"));
break;
case RFB_SERVER_CUT_TEXT:
PRINTF(("Cut text received, unhandled\n"));
break;
case RFB_SET_COLORMAP_ENTRIES:
PRINTF(("Set colormap entries received, unhandled\n"));
break;
default:
PRINTF(("Weird message type received (%d)\n", *(uint8_t *)data));
break;
}
break;
case VNC_WAIT_UPDATE_RECT:
PRINTF(("Handling data in WAIT_UPDATE_RECT, %d rects left (%d bytes)\n", vs->rectsleft, datalen));
--vs->rectsleft;
if(vs->rectsleft > 0) {
vs->waitmsg = VNC_WAIT_UPDATE_RECT;
} else {
vs->waitmsg = VNC_WAIT_NONE;
vs->sendmsg = VNC_SEND_NONE;
vs->rectstate = VNC_RECTSTATE_NONE;
}
return recv_update_rect((struct rfb_fb_update_rect_hdr *)data, datalen);
break;
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
/* newdata():
*
* Called whenever new data arrives.
*
* First, checks if data needs to be buffered before a previously
* identified request can be fulfilled. If so, the incoming data is
* buffered and the data handler is called. If no data needs to be
* buffered, the code proceeds to identify the incoming request. If
* the incoming request can be processed immediately (i.e., all data
* is contained in this message) the data handler is invoked. If data
* has to be buffered to fulfill the request, this is noted and taken
* care of the next time this function is invoked (i.e., for the next
* incoming data chunk).
*/
static uint8_t
newdata(void)
{
uint16_t datalen;
uint16_t readlen;
uint8_t *dataptr;
datalen = uip_datalen();
dataptr = (uint8_t *)uip_appdata;
PRINTF(("newdata: %d bytes\n", datalen));
/* If we are in a "rectstate", meaning that the incoming data is
part of a rectangle that is being incrementaly drawn on the
screen, we handle that first. */
if(vs->rectstate != VNC_RECTSTATE_NONE) {
readlen = recv_rectstate(dataptr, datalen);
PRINTF(("newdata: vs->rectstate %d, datalen %d, readlen %d\n",
vs->rectstate, datalen, readlen));
datalen -= readlen;
dataptr += readlen;
}
/* Next, check if we are supposed to buffer data from the incoming
segment. */
while(vs->bufferleft > 0 && datalen > 0) {
if(datalen >= vs->bufferleft) {
/* There is more data in the incoming chunk than we need to
buffer, so we buffer as much as we can and handle the
buffered data, and repeat the (identify->buffer->handle)
sequence for the data that is left in the incoming chunk. */
datalen -= vs->bufferleft;
dataptr += vs->bufferleft;
buffer_data((uint8_t *)uip_appdata, vs->bufferleft);
handle_data(vs->buffer, vs->buffersize);
clearbuffer();
} else { /* datalen < vs->bufferleft */
/* We need to buffer more data than was received with this
chunk, so we buffer the avaliable data and return. */
buffer_data(dataptr, datalen);
return 0;
}
}
/* Finally, if there is data left in the segment, we handle it. */
while(datalen > 0) {
if(vs->rectstate != VNC_RECTSTATE_NONE) {
readlen = recv_rectstate(dataptr, datalen);
PRINTF(("newdata (2): vs->rectstate %d, datalen %d, readlen %d\n",
vs->rectstate, datalen, readlen));
datalen -= readlen;
dataptr += readlen;
} else {
/* We get here if there is data to be identified in the incoming
chunk. */
readlen = identify_data(dataptr, datalen);
if(readlen == 0) {
PRINTF(("Identify returned 0\n"));
return 0;
}
PRINTF(("Reading %d bytes more\n", readlen));
/* The data has been identified and the amount of data that
needs to be read to be able to process the data is in the
"readlen" variable. If the incoming chunk contains enough
data, we handle it directly, otherwise we buffer the incoming
data and set the state so that we know that there is more
data to be buffered. */
if(readlen > datalen) {
clearbuffer(); /* Should not be needed, but just in case... */
vs->bufferleft = readlen;
buffer_data(dataptr, datalen);
return 0;
}
if(readlen <= datalen) {
PRINTF(("Before handle_data %d\n", readlen));
readlen += handle_data(dataptr, readlen);
PRINTF(("After handle_data %d\n", readlen));
datalen -= readlen;
dataptr += readlen;
}
}
if(datalen > 0) {
PRINTF(("newdata: there is more data left after first iteration... %d\n", datalen));
}
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
/* Called when there is nothing else to do - checks for any pending
events (mouse movements or keypresses). If no events are found, it
makes sure that we send out an incremental update request. */
static void
check_events(void)
{
if(vs->sendmsg == VNC_SEND_NONE &&
vs->eventptr_next != vs->eventptr_acked &&
vs->eventptr_acked == vs->eventptr_unacked) {
vs->sendmsg = VNC_SEND_EVENTS;
}
}
/*-----------------------------------------------------------------------------------*/
static void
request_update(void)
{
if(vs->sendmsg == VNC_SEND_NONE) {
vs->sendmsg = VNC_SEND_UPDATERQ_INC;
vs->waitmsg = VNC_WAIT_UPDATE;
PRINTF(("request_update: requesting\n"));
} else {
PRINTF(("request_update: not requesting\n"));
}
}
/*-----------------------------------------------------------------------------------*/
static void
acked(void)
{
switch(vs->sendmsg) {
case VNC_SEND_PFMT:
vs->sendmsg = VNC_SEND_ENCODINGS;
break;
case VNC_SEND_ENCODINGS:
vs->sendmsg = VNC_SEND_UPDATERQ;
vs->waitmsg = VNC_WAIT_UPDATE;
clearbuffer();
break;
case VNC_SEND_EVENTS:
vs->eventptr_acked = vs->eventptr_unacked;
vs->sendmsg = VNC_SEND_NONE;
check_events();
break;
default:
vs->sendmsg = VNC_SEND_NONE;
break;
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_appcall(void * nullptr)
{
if(vs->close == 1) {
uip_close();
return;
}
if(uip_connected()) {
vs->sendmsg = VNC_SEND_NONE;
vs->waitmsg = VNC_WAIT_VERSION;
return;
}
if(uip_acked()) {
acked();
}
if(uip_newdata()) {
newdata();
}
if(vs->sendmsg == VNC_SEND_NONE &&
vs->waitmsg == VNC_WAIT_NONE &&
vs->rectstate == VNC_RECTSTATE_NONE) {
check_events();
request_update();
}
PRINTF(("vs->sendmsg %d, vs->waitmsg %d, vs->rectstate %d\n",
vs->sendmsg, vs->waitmsg, vs->rectstate));
if(uip_rexmit() ||
uip_newdata() ||
uip_acked()) {
senddata();
} else if(uip_poll()) {
check_events();
senddata();
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_post_event(uint8_t type,
uint16_t data1, uint16_t data2,
uint16_t data3, uint16_t data4)
{
register struct vnc_event *ev;
struct vnc_event *ev0;
ev0 = &(vs->event_queue[(vs->eventptr_next - 1) % VNC_EVENTQUEUE_SIZE]);
ev = &(vs->event_queue[vs->eventptr_next]);
switch(type) {
case VNC_POINTER_EVENT:
if(0 && vs->eventptr_next != vs->eventptr_acked &&
ev0->type == VNC_POINTER_EVENT &&
data1 == ev0->ev.ptr.buttonmask) {
ev0->ev.ptr.x = data2;
ev0->ev.ptr.y = data3;
return;
} else {
ev->type = type;
ev->ev.ptr.buttonmask = data1;
ev->ev.ptr.x = data2;
ev->ev.ptr.y = data3;
}
break;
case VNC_KEY_EVENT:
PRINTF(("Key event posted\n"));
ev->type = type;
ev->ev.key.down = data1;
ev->ev.key.key = data2;
break;
case VNC_UPDATERQ_EVENT:
PRINTF(("Update request event posted\n"));
ev->type = type;
ev->ev.urq.x = data1;
ev->ev.urq.y = data2;
ev->ev.urq.w = data3;
ev->ev.urq.h = data4;
break;
}
vs->eventptr_next = (vs->eventptr_next + 1) % VNC_EVENTQUEUE_SIZE;
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,326 +0,0 @@
/*
* Copyright (c) 2002, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki VNC client.
*
*
*/
#ifndef VNC_VIEWER_H_
#define VNC_VIEWER_H_
struct vnc_viewer_state;
/*typedef unsigned long uint32_t;*/
void vnc_viewer_init(void);
void vnc_viewer_appcall(void *nullptr);
void vnc_viewer_connect(uint16_t *server, uint8_t display);
void vnc_viewer_close(void);
/* Callback: redraws the VNC viewer bitmap area. */
void vnc_viewer_refresh(void);
#define VNC_POINTER_EVENT RFB_POINTER_EVENT
#define VNC_KEY_EVENT RFB_KEY_EVENT
#define VNC_UPDATERQ_EVENT 7
#define VNC_VIEWER_POST_POINTER_EVENT(x, y, button) \
vnc_viewer_post_event(VNC_POINTER_EVENT, button, x, y, 0)
#define VNC_VIEWER_POST_KEY_EVENT(key) \
vnc_viewer_post_event(VNC_KEY_EVENT, key, 0, 0, 0)
#define VNC_VIEWER_POST_UPDATERQ_EVENT(x1,y1,x2,y2) \
vnc_viewer_post_event(VNC_UPDATERQ_EVENT, x1, y1, x2, y2)
void vnc_viewer_post_event(uint8_t event,
uint16_t data1, uint16_t data2,
uint16_t data3, uint16_t data4);
/* UIP_APPCALL: the name of the application function. This function
must return void and take no arguments (i.e., C type "void
appfunc(void)"). */
#ifndef UIP_APPCALL
#define UIP_APPCALL vnc_viewer_app
#endif
struct vnc_key_event {
uint8_t down;
uint16_t key;
};
struct vnc_pointer_event {
uint8_t buttonmask;
uint16_t x, y;
};
struct vnc_updaterq_event {
uint16_t x, y;
uint16_t w, h;
};
struct vnc_event {
uint8_t type;
union {
struct vnc_key_event key;
struct vnc_pointer_event ptr;
struct vnc_updaterq_event urq;
} ev;
};
enum vnc_sendmsg {
VNC_SEND_NONE,
VNC_SEND_VERSION,
VNC_SEND_AUTH,
VNC_SEND_CINIT,
VNC_SEND_PFMT,
VNC_SEND_ENCODINGS,
VNC_SEND_UPDATERQ,
VNC_SEND_UPDATERQ_INC,
VNC_SEND_EVENTS,
};
enum vnc_waitmsg {
VNC_WAIT_NONE,
VNC_WAIT_VERSION,
VNC_WAIT_AUTH,
VNC_WAIT_AUTH_RESPONSE,
VNC_WAIT_SINIT,
VNC_WAIT_UPDATE,
VNC_WAIT_UPDATE_RECT,
};
enum vnc_rectstate {
VNC_RECTSTATE_NONE,
VNC_RECTSTATE_RAW,
VNC_RECTSTATE_RRE,
};
struct vnc_viewer_state {
uint8_t close;
uint16_t w, h;
uint8_t sendmsg;
uint8_t waitmsg;
uint16_t rectsleft;
uint8_t rectstate;
uint32_t rectstateleft;
uint16_t rectstatex, rectstatey;
uint16_t rectstateh, rectstatew;
uint16_t rectstatex0, rectstatey0;
uint16_t rectstatex2, rectstatey2;
uint16_t eventptr_acked;
uint16_t eventptr_unacked;
uint16_t eventptr_next;
#define VNC_EVENTQUEUE_SIZE 32
struct vnc_event event_queue[VNC_EVENTQUEUE_SIZE];
uint16_t bufferleft;
uint16_t buffersize;
#define VNC_BUFFERSIZE 64
uint8_t buffer[VNC_BUFFERSIZE];
};
extern static struct vnc_viewer_state vnc_viewer_state;
/* Definitions of the RFB (Remote Frame Buffer) protocol
structures and constants. */
#include "net/uipopt.h"
/* Generic rectangle - x, y coordinates, width and height. */
struct rfb_rect {
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
};
/* Pixel format definition. */
struct rfb_pixel_format {
uint8_t bps; /* Bits per pixel: 8, 16 or 32. */
uint8_t depth; /* Color depth: 8-32 */
uint8_t endian; /* 1 - big endian (motorola), 0 - little endian
(x86) */
uint8_t truecolor; /* 1 - true color is used, 0 - true color is not used. */
/* The following fields are only used if true color is used. */
uint16_t red_max, green_max, blue_max;
uint8_t red_shift, green_shift, blue_shift;
uint8_t pad1;
uint16_t pad2;
};
/* RFB authentication constants. */
#define RFB_AUTH_FAILED 0
#define RFB_AUTH_NONE 1
#define RFB_AUTH_VNC 2
#define RFB_VNC_AUTH_OK 0
#define RFB_VNC_AUTH_FAILED 1
#define RFB_VNC_AUTH_TOOMANY 2
/* RFB message types. */
/* From server to client: */
#define RFB_FB_UPDATE 0
#define RFB_SET_COLORMAP_ENTRIES 1
#define RFB_BELL 2
#define RFB_SERVER_CUT_TEXT 3
/* From client to server. */
#define RFB_SET_PIXEL_FORMAT 0
#define RFB_FIX_COLORMAP_ENTRIES 1
#define RFB_SET_ENCODINGS 2
#define RFB_FB_UPDATE_REQ 3
#define RFB_KEY_EVENT 4
#define RFB_POINTER_EVENT 5
#define RFB_CLIENT_CUT_TEXT 6
/* Encoding types. */
#define RFB_ENC_RAW 0
#define RFB_ENC_COPYRECT 1
#define RFB_ENC_RRE 2
#define RFB_ENC_CORRE 3
#define RFB_ENC_HEXTILE 4
/* Message definitions. */
/* Server to client messages. */
struct rfb_server_init {
uint16_t width;
uint16_t height;
struct rfb_pixel_format format;
uint8_t namelength[4];
/* Followed by name. */
};
struct rfb_fb_update {
uint8_t type;
uint8_t pad;
uint16_t rects; /* Number of rectanges (struct rfb_fb_update_rect_hdr +
data) that follows. */
};
struct rfb_fb_update_rect_hdr {
struct rfb_rect rect;
uint8_t encoding[4];
};
struct rfb_copy_rect {
uint16_t srcx;
uint16_t srcy;
};
struct rfb_rre_hdr {
uint16_t subrects[2]; /* Number of subrectangles (struct
rfb_rre_subrect) to follow. */
uint8_t bgpixel;
};
struct rfb_rre_subrect {
uint8_t pixel;
struct rfb_rect rect;
};
struct rfb_corre_rect {
uint8_t x;
uint8_t y;
uint8_t w;
uint8_t h;
};
/* Client to server messages. */
struct rfb_set_pixel_format {
uint8_t type;
uint8_t pad;
uint16_t pad2;
struct rfb_pixel_format format;
};
struct rfb_fix_colormap_entries {
uint8_t type;
uint8_t pad;
uint16_t firstcolor;
uint16_t colors;
};
struct rfb_set_encodings {
uint8_t type;
uint8_t pad;
uint16_t encodings;
};
struct rfb_fb_update_request {
uint8_t type;
uint8_t incremental;
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
};
struct rfb_key_event {
uint8_t type;
uint8_t down;
uint16_t pad;
uint8_t key[4];
};
#define RFB_BUTTON_MASK1 1
#define RFB_BUTTON_MASK2 2
#define RFB_BUTTON_MASK3 4
struct rfb_pointer_event {
uint8_t type;
uint8_t buttonmask;
uint16_t x;
uint16_t y;
};
#endif /* VNC_VIEWER_H_ */

View File

@ -1,234 +0,0 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki VNC client
*
*
*/
#include <string.h>
#include "contiki.h"
/*#include "petsciiconv.h"*/
#include "net/uiplib.h"
#include "net/uip.h"
#include "ctk/ctk.h"
#include "ctk/ctk-mouse.h"
#include "net/resolv.h"
/*#include "telnet.h"*/
#include "vnc.h"
#include "vnc-draw.h"
#include "vnc-viewer.h"
#include "contiki-conf.h"
#include "sys/loader.h"
#if 1
#define PRINTF(x)
#else
#include <stdio.h>
#define PRINTF(x) printf x
#endif
#ifdef VNC_CONF_VIEWPORT_WIDTH
#define VNC_VIEWPORT_WIDTH VNC_CONF_VIEWPORT_WIDTH
#else
#define VNC_VIEWPORT_WIDTH 10
#endif
#ifdef VNC_CONF_VIEWPORT_HEIGHT
#define VNC_VIEWPORT_HEIGHT VNC_CONF_VIEWPORT_HEIGHT
#else
#define VNC_VIEWPORT_HEIGHT 10
#endif
#define HEIGHT (4 + VNC_VIEWPORT_HEIGHT/8)
/* Main window */
static struct ctk_window mainwindow;
static char host[20];
static struct ctk_textentry hosttextentry =
{CTK_TEXTENTRY(0, 0, 18, 1, host, 18)};
static char portentry[4];
static struct ctk_textentry porttextentry =
{CTK_TEXTENTRY(21, 0, 3, 1, portentry, 3)};
static struct ctk_button connectbutton =
{CTK_BUTTON(27, 0, 7, "Connect")};
/*static struct ctk_button disconnectbutton =
{CTK_BUTTON(25, 3, 10, "Disconnect")};*/
static struct ctk_separator sep1 =
{CTK_SEPARATOR(0, 1, 36)};
static struct ctk_bitmap vncbitmap =
{CTK_BITMAP(2, 2,
VNC_VIEWPORT_WIDTH / 8,
VNC_VIEWPORT_HEIGHT / 8,
vnc_draw_bitmap,
VNC_VIEWPORT_WIDTH,
VNC_VIEWPORT_HEIGHT)};
static struct ctk_button leftbutton =
{CTK_BUTTON(6, HEIGHT - 1, 4, "Left")};
static struct ctk_button upbutton =
{CTK_BUTTON(13, HEIGHT - 1, 2, "Up")};
static struct ctk_button downbutton =
{CTK_BUTTON(18, HEIGHT - 1, 4, "Down")};
static struct ctk_button rightbutton =
{CTK_BUTTON(25, HEIGHT - 1, 5, "Right")};
PROCESS(vnc_process, "VNC viewer");
/*-----------------------------------------------------------------------------------*/
static void
show(char *text)
{
}
/*-----------------------------------------------------------------------------------*/
static void
connect(void)
{
uip_ipaddr_t addr, *addrptr;
uint16_t port;
char *cptr;
/* Find the first space character in host and put a zero there
to end the string. */
for(cptr = host; *cptr != ' ' && *cptr != 0; ++cptr);
*cptr = 0;
addrptr = &addr;
if(uiplib_ipaddrconv(host, &addr) == 0) {
if(resolv_lookup(host, &addrptr) == RESOLV_STATUS_UNCACHED) {
resolv_query(host);
show("Resolving host...");
return;
}
}
port = 0;
for(cptr = portentry; *cptr != ' ' && *cptr != 0; ++cptr) {
if(*cptr < '0' || *cptr > '9') {
show("Port number error");
return;
}
port = 10 * port + *cptr - '0';
}
vnc_viewer_connect(addrptr, port);
show("Connecting...");
}
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(vnc_process, ev, data)
{
unsigned short x, y;
unsigned char xc, yc;
PROCESS_BEGIN();
ctk_window_new(&mainwindow, 36, HEIGHT, "VNC client");
ctk_window_move(&mainwindow, 0, 0);
CTK_WIDGET_ADD(&mainwindow, &hosttextentry);
CTK_WIDGET_FOCUS(&mainwindow, &hosttextentry);
CTK_WIDGET_ADD(&mainwindow, &porttextentry);
CTK_WIDGET_ADD(&mainwindow, &connectbutton);
CTK_WIDGET_ADD(&mainwindow, &sep1);
CTK_WIDGET_ADD(&mainwindow, &vncbitmap);
CTK_WIDGET_ADD(&mainwindow, &leftbutton);
CTK_WIDGET_ADD(&mainwindow, &upbutton);
CTK_WIDGET_ADD(&mainwindow, &downbutton);
CTK_WIDGET_ADD(&mainwindow, &rightbutton);
vnc_draw_init();
ctk_window_open(&mainwindow);
while(1) {
PROCESS_WAIT_EVENT();
if(ev == ctk_signal_button_activate) {
if(data == (process_data_t)&connectbutton) {
connect();
}
} else if(ev == ctk_signal_window_close) {
process_exit(&vnc_process);
LOADER_UNLOAD();
} else if(ev == resolv_event_found) {
if(strcmp(data, host) == 0) {
if(resolv_lookup(host, NULL) == RESOLV_STATUS_CACHED) {
connect();
} else {
show("Host not found");
}
}
} else if(ev == ctk_signal_pointer_move) {
/* Check if pointer is within the VNC viewer area */
x = ctk_mouse_x();
y = ctk_mouse_y();
xc = ctk_mouse_xtoc(x);
yc = ctk_mouse_ytoc(y);
if(xc >= 2 && yc >= 2 &&
xc < 2 + VNC_VIEWPORT_WIDTH / 8 &&
yc < 2 + VNC_VIEWPORT_HEIGHT / 8) {
VNC_VIEWER_POST_POINTER_EVENT(x, y, 0);
}
} else if(ev == tcpip_event) {
vnc_viewer_appcall(data);
}
}
PROCESS_END();
}
/*-----------------------------------------------------------------------------------*/
void
vnc_viewer_refresh(void)
{
CTK_WIDGET_REDRAW(&vncbitmap);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki VNC client.
*
*
*/
#ifndef VNC_H_
#define VNC_H_
void vnc_init(char *arg);
#endif /* VNC_H_ */

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2002, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the "ctk" console GUI toolkit for cc65
*
*
*/
#ifndef CTK_VNCARCH_H_
#define CTK_VNCARCH_H_
#define CTK_ARCH_KEY_T unsigned char
unsigned char ctk_arch_keyavail(void);
CTK_ARCH_KEY_T ctk_arch_getkey(void);
#define CH_ENTER 0x0d
#define CH_DEL 0x08
#define CH_ESC 0x1b
#define CH_HOME 0x50
#define CH_TAB 0x09
#define CH_CURS_LEFT 0x51
#define CH_CURS_UP 0x52
#define CH_CURS_RIGHT 0x53
#define CH_CURS_DOWN 0x54
#define CH_F1 0xbe
#define CH_F2 0xbf
#define CH_F3 0xc0
#define CH_F4 0xc1
#define CH_F5 0xc2
#define CH_F6 0xc3
#define CH_F7 0xc4
#endif /* CTK_VNCARCH_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki VNC server
*
*
*/
#ifndef CTK_VNCFONT_H_
#define CTK_VNCFONT_H_
#define CTK_VNCFONT_WIDTH 6
#define CTK_VNCFONT_HEIGHT 8
extern unsigned char ctk_vncfont[CTK_VNCFONT_WIDTH *
CTK_VNCFONT_HEIGHT *
128];
#endif /* CTK_VNCFONT_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2002, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the "ctk" console GUI toolkit for cc65
*
*
*/
#ifndef CTK_VNCSERVER_H_
#define CTK_VNCSERVER_H_
#include "contiki.h"
void ctk_vncserver_init(char *arg);
PROCESS_NAME(ctk_vncserver_process);
#endif /* CTK_VNCSERVER_H_ */

View File

@ -1,977 +0,0 @@
/*
* Copyright (c) 2001, Adam Dunkels
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
*
*/
#include "contiki-net.h"
#include "ctk/vnc-server.h"
#include "ctk/vnc-out.h"
#include "ctk/ctk-vncfont.h"
#include "ctk/ctk-mouse.h"
#include "lib/libconio.h"
#ifdef WITH_AVR
#include <avr/pgmspace.h>
#else
#define memcpy_P memcpy
#endif /* WITH_AVR */
#define CHARS_WIDTH LIBCONIO_CONF_SCREEN_WIDTH
#define CHARS_HEIGHT LIBCONIO_CONF_SCREEN_HEIGHT
#define SCREEN_X 10
#define SCREEN_Y 8
#define SCREEN_WIDTH (CHARS_WIDTH * CTK_VNCFONT_WIDTH + 2 * SCREEN_X) /*420*/
#define SCREEN_HEIGHT (CHARS_HEIGHT * CTK_VNCFONT_HEIGHT + 2 * SCREEN_Y) /*300*/
#define BORDER_COLOR 0x00
#define SCREEN_COLOR 0x00 /*0xc0*/
#ifndef CH_HOME
#define CH_HOME 0x50
#endif
#ifndef CH_TAB
#define CH_TAB 0x09
#endif
#define BGR(b,g,r) (((b) << 6) | (g) << 3 | (r))
static const uint8_t menucolor[] = {
BGR(3,7,7), /* Background. */
BGR(2,6,6), /* Anti-alias font color. */
BGR(0,0,0), /* Font color. */
};
static const uint8_t activemenucolor[] = {
BGR(0,0,0), /* Background. */
BGR(2,5,5), /* Anti-alias font color. */
BGR(3,7,7), /* Font color. */
};
#define W BGR(3,7,7)
#define B BGR(0,0,0)
#define G0 BGR(0,2,2)
#define G1 BGR(1,2,2)
#define G2 BGR(1,3,3)
#define G3 BGR(2,4,4)
#define G4 BGR(2,5,5)
#define G5 BGR(2,6,6)
#define BG BGR(3,4,4)
static const unsigned char backgroundcolor[] = {BG};
static const unsigned char wincol[] =
{BGR(2,5,5),BGR(2,2,2),BGR(0,1,1),G2,G3,G4};
/* {BGR(2,5,5),BGR(2,2,2),BGR(0,1,1),BGR(1,0,0),BGR(2,0,0),BGR(2,1,1)}; */
static const unsigned char wincol_f[] =
{BGR(3,7,7),BGR(1,2,2),BGR(0,1,1),G4,G5,W};
/* {BGR(3,7,7),BGR(1,2,2),BGR(0,1,1),BGR(2,0,0),BGR(3,2,2),BGR(3,4,4)}; */
static const unsigned char wincol_d[] =
{BGR(3,7,7),BGR(1,5,5),BGR(0,0,0),BGR(2,0,0),BGR(3,2,2),BGR(3,4,4)};
static const unsigned char sepcol[] =
{BGR(2,5,5),BGR(2,6,6),BGR(3,6,6)};
static const unsigned char sepcol_f[] =
{BGR(3,7,7),BGR(3,5,5),BGR(2,5,5)};
static const unsigned char sepcol_d[] =
{BGR(3,7,7),BGR(1,5,7),BGR(0,0,0)};
static const unsigned char labcol[] =
{BGR(2,5,5),BGR(1,3,3),BGR(0,1,1)};
static const unsigned char labcol_f[] =
{BGR(3,7,7),BGR(3,6,6),BGR(0,0,0)};
static const unsigned char labcol_d[] =
{BGR(3,7,7),BGR(3,6,6),BGR(0,0,0)};
static const unsigned char butcol[] =
{BGR(2,4,4),BGR(1,3,3),BGR(0,1,1),BGR(2,4,4),BGR(2,4,4),BGR(2,4,4),
BGR(2,5,5),BGR(2,5,5)};
static const unsigned char butcol_w[] =
{BGR(2,4,4),BGR(1,3,3),BGR(0,1,1),BGR(2,4,4),BGR(2,4,4),BGR(2,4,4),
BGR(2,5,5),BGR(2,5,5)};
static const unsigned char butcol_f[] =
{G5,G4,B,BGR(3,5,5),BGR(3,6,6),BGR(3,7,7),
BGR(3,6,6),BGR(2,5,5)};
static const unsigned char butcol_fw[] =
{BGR(3,7,7),BGR(3,6,6),BGR(0,0,0),BGR(1,3,3),BGR(2,7,7),BGR(3,7,7),
BGR(3,6,6),BGR(3,7,7)};
static const unsigned char butcol_d[] =
{BGR(2,3,3),BGR(2,5,5),BGR(3,6,6),BGR(1,3,4),BGR(1,5,6),BGR(2,6,7),
BGR(3,7,7),BGR(2,5,5)};
static const unsigned char butcol_dw[] =
{BGR(0,0,0),BGR(2,5,5),BGR(3,7,7),BGR(1,3,4),BGR(1,5,6),BGR(2,6,7),
BGR(3,7,7),BGR(2,5,5)};
static const unsigned char hlcol[] =
{BGR(2,5,5),BGR(1,3,3),BGR(1,0,0)};
static const unsigned char hlcol_w[] =
{BGR(2,5,5),BGR(1,3,3),BGR(1,0,0)};
static const unsigned char hlcol_f[] =
{BGR(3,7,7),BGR(3,5,5),BGR(3,0,0)};
static const unsigned char hlcol_fw[] =
{BGR(3,7,7),BGR(3,6,7),BGR(3,7,7)};
static const unsigned char hlcol_d[] =
{BGR(3,7,7),BGR(3,5,5),BGR(2,0,0)};
static const unsigned char hlcol_dw[] =
{BGR(3,7,7),BGR(1,5,5),BGR(0,0,0)};
static const unsigned char iconcol[] =
{BG,G4,W,B,G1};
static const unsigned char iconcol_w[] =
{BGR(0,1,1),BGR(1,3,3),BGR(3,7,7), B,W};
static const uint8_t * const colortheme[] =
{
backgroundcolor,
/* Window colors */
wincol, wincol, wincol_f, wincol_f, wincol_d, wincol_d,
/* Separator colors. */
sepcol, sepcol, sepcol_f, sepcol_f, sepcol_d, sepcol_d,
/* Label colors. */
labcol, labcol, labcol_f, labcol_f, labcol_d, labcol_d,
/* Button colors. */
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
/* Hyperlink colors. */
hlcol, hlcol_w, hlcol_f, hlcol_fw, hlcol_d, hlcol_dw,
/* Textentry colors. */
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
/* Icon colors */
iconcol, iconcol_w, iconcol, iconcol_w, iconcol, iconcol_w,
/* Menu colors. */
menucolor, activemenucolor, activemenucolor
};
static int mouse_x, mouse_y, mouse_button;
#ifdef CTK_VNCSERVER_CONF_SCREEN
static uint8_t *screen = CTK_VNCSERVER_CONF_SCREEN;
#else
static uint8_t screen[CHARS_WIDTH * CHARS_HEIGHT];
#endif
#ifdef CTK_VNCSERVER_CONF_COLORSCREEN
staitc uint8_t *colorscreen = CTK_VNCSERVER_CONF_COLORSCREEN;
#else
static uint8_t colorscreen[CHARS_WIDTH * CHARS_HEIGHT];
#endif
#define PRINTF(x)
/*-----------------------------------------------------------------------------------*/
#define MAX_ICONS CTK_VNCSERVER_CONF_MAX_ICONS
struct ctk_icon *icons[MAX_ICONS];
unsigned char
vnc_out_add_icon(struct ctk_icon *icon)
{
uint8_t i;
signed int empty;
empty = -1;
for(i = 0; i < MAX_ICONS; ++i) {
if(icon == icons[i]) {
return i;
}
if(icons[i] == NULL && empty < 0){
empty = i;
}
}
if(empty == -1) {
empty = 0;
}
icons[empty] = icon;
return empty;
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_init(void)
{
uint16_t i;
for(i = 0; i < CHARS_WIDTH * CHARS_HEIGHT; ++i) {
screen[i] = 0x20;
}
}
void
vnc_out_update_screen(uint8_t xpos, uint8_t ypos, uint8_t c, uint8_t color)
{
screen[xpos + ypos * CHARS_WIDTH] = c;
colorscreen[xpos + ypos * CHARS_WIDTH] = color;
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_update_area(struct vnc_server_state *vs,
uint8_t x, uint8_t y, uint8_t w, uint8_t h)
{
uint8_t x2, y2, ax2, ay2;
register struct vnc_server_update *a, *b;
PRINTF(("update_area_connection: should update (%d:%d) (%d:%d)\n",
x, y, w, h));
/* First check if we already have a full update queued. If so, there
is no need to put this update on the list. If there is a full
update, it is always the first one on the list, so there is no
need to go step the list in search for it. */
if(vs->updates_pending != NULL &&
vs->updates_pending->type == VNC_SERVER_UPDATE_FULL) {
PRINTF(("Update_area_connecion: full update already queued...\n"));
return;
}
again:
/* Check that we don't update the same area twice by going through
the list and search for an update with the same coordinates. */
for(a = vs->updates_pending; a != NULL; a = a->next) {
if(a->x == x && a->y == y &&
a->w == w && a->h == h) {
PRINTF(("Update_area_connecion: found equal area\n"));
return;
}
}
/* Next we check if this update covers an existing update. If so, we
remove the old update, expand this update so that it covers both
areas to be updated and run through the process again. */
b = NULL;
for(a = vs->updates_pending; a != NULL; a = a->next) {
x2 = x + w;
y2 = y + h;
ax2 = a->x + a->w;
ay2 = a->y + a->h;
/* Test the corners of both updates to see if they are inside the
other area. */
#define INSIDE(x,y,x1,y1,x2,y2) ((x1) <= (x) && \
(x2) >= (x) && \
(y1) <= (y) && \
(y2) >= (y))
if(INSIDE(x, y, a->x, a->y, ax2, ay2) ||
INSIDE(x, y2, a->x, a->y, ax2, ay2) ||
INSIDE(x2, y2, a->x, a->y, ax2, ay2) ||
INSIDE(x2, y, a->x, a->y, ax2, ay2) ||
INSIDE(a->x, a->y, x, y, x2, y2) ||
INSIDE(a->x, ay2, x, y, x2, y2) ||
INSIDE(ax2, ay2, x, y, x2, y2) ||
INSIDE(ax2, a->y, x, y, x2, y2)) {
/* Remove the old update from the list. */
vnc_server_update_remove(vs, a);
/* Put it on the free list. */
vnc_server_update_free(vs, a);
PRINTF(("update_area_connection: inside (%d:%d, %d:%d)\n",
a->x, a->y, ax2, ay2));
/* Find the area that covers both updates. */
#define MIN(a,b) ((a) < (b)? (a): (b))
#define MAX(a,b) ((a) > (b)? (a): (b))
x = MIN(a->x, x);
y = MIN(a->y, y);
ax2 = MAX(ax2, x2);
ay2 = MAX(ay2, y2);
w = ax2 - x;
h = ay2 - y;
/* This should really be done by a recursive call to this
function: update_area_connection(vs, x, y, w, h); but because
some compilers might not be able to optimize away the
recursive call, we do it using a goto instead. */
PRINTF(("Update_area_connecion: trying larger area (%d:%d) (%d:%d)\n", x, y, w, h));
goto again;
}
if(b != NULL) {
b = b->next;
}
}
/* Allocate an update object by pulling it off the free list. If
there are no free objects, we go for a full update instead. */
/* a = vs->updates_free;*/
a = vnc_server_update_alloc(vs);
if(a == NULL) {
PRINTF(("Update_area_connecion: no free updates, doing full\n"));
/* Put all pending updates, except for one, on the free list. Use
the remaining update as a full update. */
while(vs->updates_pending != NULL) {
a = vs->updates_pending;
vnc_server_update_remove(vs, a);
vnc_server_update_free(vs, a);
}
a = vnc_server_update_alloc(vs);
a->type = VNC_SERVER_UPDATE_FULL;
vnc_server_update_add(vs, a);
} else {
PRINTF(("Update_area_connecion: allocated update for (%d:%d) (%d:%d)\n", x, y, w, h));
/* Else, we put the update object at the end of the pending
list. */
a->type = VNC_SERVER_UPDATE_PARTS;
a->x = x;
a->y = y;
a->w = w;
a->h = h;
vnc_server_update_add(vs, a);
}
}
/*-----------------------------------------------------------------------------------*/
static void
init_send_screen(CC_REGISTER_ARG struct vnc_server_state *vs)
{
vs->sendmsg = SEND_SCREEN;
vs->x = vs->y = 0;
vs->x1 = vs->y1 = 0;
vs->x2 = vs->y2 = 0;
vs->w = CHARS_WIDTH;
vs->h = CHARS_HEIGHT;
}
/*-----------------------------------------------------------------------------------*/
static void
check_updates(CC_REGISTER_ARG struct vnc_server_state *vs)
{
if(vs->state == VNC_RUNNING &&
vs->sendmsg == SEND_NONE &&
vs->updates_current == NULL) {
if(vs->updates_pending != NULL &&
vs->update_requested != 0) {
vs->update_requested = 0;
/* vs->updates_current = vs->updates_pending;
vs->updates_pending = vs->updates_pending->next;
vs->updates_current->next = NULL;*/
vs->updates_current = vnc_server_update_dequeue(vs);
if(vs->updates_current->type == VNC_SERVER_UPDATE_PARTS) {
vs->x = vs->x1 = vs->x2 = vs->updates_current->x;
vs->y = vs->y1 = vs->y2 = vs->updates_current->y;
vs->w = vs->updates_current->w;
vs->h = vs->updates_current->h;
vs->sendmsg = SEND_UPDATE;
PRINTF(("New update from (%d:%d) (%d:%d) to (%d:%d)\n",
vs->x, vs->y, vs->x1, vs->y1, vs->x + vs->w,
vs->y + vs->h));
} else if(vs->updates_current->type == VNC_SERVER_UPDATE_FULL) {
init_send_screen(vs);
PRINTF(("New full update\n"));
}
}
}
}
/*-----------------------------------------------------------------------------------*/
static uint8_t tmp[CTK_VNCFONT_WIDTH * CTK_VNCFONT_HEIGHT];
static void
makechar(CC_REGISTER_ARG char *ptr, uint8_t x, uint8_t y)
{
uint8_t i, *tmpptr;
register uint8_t *colorscheme;
unsigned char *bitmap;
uint8_t b, b2;
uint8_t xmove, ymove;
unsigned char c, color;
color = colorscreen[x + y * CHARS_WIDTH];
c = screen[x + y * CHARS_WIDTH];
colorscheme = (uint8_t *)colortheme[color];
/* First check if the character is a special icon character. These
are to be interpreted in a special manner: the first character of
the icon (the top left corner) has the highest bit set, but not
bit 6. All other characters have bit 6 set, and also count the
number of positions away from the top left corner. Only the top
left corner contains enough information to identify the icon, all
other chars only contain the number of steps to reach the
identifying icon. */
if((c & 0x80) != 0) {
xmove = c & 0x0f;
ymove = (c & 0x30) >> 4;
c = colorscreen[x + y * CHARS_WIDTH];
if(icons[c % MAX_ICONS] == NULL) {
c = 0;
}
bitmap = icons[c % MAX_ICONS]->bitmap;
if(bitmap != NULL) {
bitmap = bitmap + ymove * 8*3;
colorscheme = (uint8_t *)colortheme[VNC_OUT_ICONCOLOR + (c >> 6)];
switch(xmove) {
case 0:
for(i = 0; i < CTK_VNCFONT_HEIGHT; ++i) {
b = bitmap[i];
*ptr++ = colorscheme[((b >> 7) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 6) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 5) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 4) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 3) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 2) & 0x01) << 2];
}
break;
case 1:
for(i = 0; i < CTK_VNCFONT_HEIGHT; ++i) {
b = bitmap[i];
b2 = bitmap[i + 8];
*ptr++ = colorscheme[((b >> 1) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 0) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 7) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 6) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 5) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 4) & 0x01) << 2];
}
break;
case 2:
for(i = 0; i < CTK_VNCFONT_HEIGHT; ++i) {
b = bitmap[i + 8];
b2 = bitmap[i + 16];
*ptr++ = colorscheme[((b >> 3) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 2) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 1) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 0) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 7) & 0x01) << 2];
*ptr++ = colorscheme[((b2 >> 6) & 0x01) << 2];
}
break;
case 3:
for(i = 0; i < CTK_VNCFONT_HEIGHT; ++i) {
b = bitmap[i + 16];
*ptr++ = colorscheme[((b >> 5) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 4) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 3) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 2) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 1) & 0x01) << 2];
*ptr++ = colorscheme[((b >> 0) & 0x01) << 2];
}
break;
}
}
} else {
memcpy_P(tmp, &ctk_vncfont[c * (CTK_VNCFONT_WIDTH * CTK_VNCFONT_HEIGHT)],
CTK_VNCFONT_WIDTH * CTK_VNCFONT_HEIGHT);
tmpptr = tmp;
for(i = 0; i < CTK_VNCFONT_HEIGHT * CTK_VNCFONT_WIDTH; ++i) {
*ptr++ = colorscheme[*tmpptr++];
}
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_new(CC_REGISTER_ARG struct vnc_server_state *vs)
{
uint8_t i;
vs->width = SCREEN_WIDTH;
vs->height = SCREEN_HEIGHT;
vs->x = vs->y = vs->x1 = vs->y1 = vs->x2 = vs->y2 = 0;
vs->w = CHARS_WIDTH;
vs->h = CHARS_HEIGHT;
/* Initialize the linked list of updates. */
for(i = 0; i < VNC_SERVER_MAX_UPDATES - 1; ++i) {
vs->updates_pool[i].next = &vs->updates_pool[i + 1];
}
vs->updates_pool[VNC_SERVER_MAX_UPDATES].next = NULL;
vs->updates_free = &vs->updates_pool[0];
vs->updates_pending = vs->updates_current = NULL;
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_send_blank(CC_REGISTER_ARG struct vnc_server_state *vs)
{
register struct rfb_fb_update *umsg;
uint8_t *ptr;
uint16_t len;
uint8_t msglen;
vs->x = vs->y = 0;
vs->x2 = vs->y2 = 0;
umsg = (struct rfb_fb_update *)uip_appdata;
umsg->type = RFB_FB_UPDATE;
umsg->rects = UIP_HTONS(2);
ptr = (uint8_t *)umsg + sizeof(struct rfb_fb_update);
len = sizeof(struct rfb_fb_update);
msglen = vnc_server_draw_rect(ptr, 0, 0,
UIP_HTONS(SCREEN_WIDTH),
UIP_HTONS(SCREEN_HEIGHT),
BORDER_COLOR);
ptr += msglen;
len += msglen;
msglen = vnc_server_draw_rect(ptr,
UIP_HTONS(SCREEN_X), UIP_HTONS(SCREEN_Y),
UIP_HTONS(SCREEN_WIDTH - SCREEN_X * 2),
UIP_HTONS(SCREEN_HEIGHT - SCREEN_Y * 2),
SCREEN_COLOR);
uip_send(uip_appdata, len + msglen);
vs->sendmsg = SENT_BLANK;
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_send_screen(struct vnc_server_state *vs)
{
vnc_out_send_update(vs);
}
/*-----------------------------------------------------------------------------------*/
static short tmpbuf[30];
void
vnc_out_send_update(CC_REGISTER_ARG struct vnc_server_state *vs)
{
uint8_t x, y, x0;
uint8_t msglen;
uint16_t len, n;
uint8_t *ptr;
struct rfb_fb_update *umsg;
register struct rfb_fb_update_rect_hdr *recthdr;
struct rfb_rre_hdr *rrehdr;
uint8_t c, color, lastcolor;
uint8_t numblanks;
/* First, check if we need to feed the update function with a new
pending update. */
check_updates(vs);
/* PRINTF(("Sending Update from (%d:%d) (%d:%d) to (%d:%d)\n",
vs->x, vs->y, vs->x1, vs->y1, vs->x + vs->w,
vs->y + vs->h));*/
umsg = (struct rfb_fb_update *)uip_appdata;
umsg->type = RFB_FB_UPDATE;
x0 = vs->x1;
n = 0;
msglen = 0;
ptr = (uint8_t *)umsg + sizeof(struct rfb_fb_update);
len = sizeof(struct rfb_fb_update);
/* Loop over all characters that are covered by this update. */
for(y = vs->y1; y < vs->y + vs->h; ++y) {
for(x = x0; x < vs->x + vs->w; ++x) {
/* First check if there are any blank space characters, and if
so, find out how many of them there are in a row. Instead of
sending the individual space characters as raw bitmaps, we
can send the entire string of blanks as a single color
rectangle instead. */
c = screen[x + y * CHARS_WIDTH];
numblanks = 0;
lastcolor = color = colorscreen[x + y * CHARS_WIDTH];
/* If the character is a blank, we continue reading characters
until we find one that has a different color, or one that is
not a blank. We must keep within the update rectangle, so we
make sure that the "x" variable does not increase beyond the
edge. The "numblanks" variable is used to keep track of how
many blank characters we have found. */
while(lastcolor == color &&
c == 0x20 &&
x < vs->x + vs->w) {
++numblanks;
++x;
lastcolor = color;
color = colorscreen[x + y * CHARS_WIDTH];
c = screen[x + y * CHARS_WIDTH];
}
if(numblanks > 0) {
/* PRINTF(("Found %d blanks (%d:%d -> %d:%d)\n",
numblanks, x - numblanks, y, x, y));*/
/* There were one or more blank characters, so we send out a
single color rectangle with the right width. But first we
make sure that there is enough space in the current TCP
segment to put the rectangle. If there isn't we have to
backtrack the "x" variable to where we found the first
blank character so that the next TCP segment will be able
to update this area instead. */
msglen = sizeof(struct rfb_fb_update_rect_hdr) +
/*sizeof(struct rfb_rre_hdr)*/5;
if(msglen >= uip_mss() - len) {
/* PRINTF(("Not enouch space for blanks (%d, left %d)\n",
msglen, uip_mss() - len));*/
/* There is not enough space in the segment, so we remember
where we were ... */
vs->x2 = x - numblanks;
vs->y2 = y;
/* ... and we break out of the loop. */
goto loopend;
}
/* We construct a rectangle with the right width and color. */
/* recthdr = (struct rfb_fb_update_rect_hdr *)ptr;*/
recthdr = (struct rfb_fb_update_rect_hdr *)tmpbuf;
rrehdr = (struct rfb_rre_hdr *)((char *)recthdr +
sizeof(struct rfb_fb_update_rect_hdr));
/* PRINTF(("Blankign (%d:%d) to (%d:%d)\n",
(x - numblanks) * CTK_VNCFONT_WIDTH,
y * CTK_VNCFONT_HEIGHT,
CTK_VNCFONT_WIDTH * numblanks,
CTK_VNCFONT_HEIGHT));*/
recthdr->rect.x = uip_htons(SCREEN_X + (x - numblanks) *
CTK_VNCFONT_WIDTH);
recthdr->rect.y = uip_htons(SCREEN_Y + y * CTK_VNCFONT_HEIGHT);
recthdr->rect.w = uip_htons(CTK_VNCFONT_WIDTH * numblanks);
recthdr->rect.h = UIP_HTONS(CTK_VNCFONT_HEIGHT);
recthdr->encoding[0] =
recthdr->encoding[1] =
recthdr->encoding[2] = 0;
recthdr->encoding[3] = RFB_ENC_RRE;
rrehdr->subrects[0] =
rrehdr->subrects[1] = 0;
rrehdr->bgpixel = colortheme[lastcolor][0];
--x;
} else {
/* So there were no blank characters. */
/* PRINTF(("An char at (%d:%d)\n", x, y));*/
/* First we must make sure that there is enough space in the
outgoing TCP segment. */
msglen = sizeof(struct rfb_fb_update_rect_hdr) +
CTK_VNCFONT_HEIGHT * CTK_VNCFONT_WIDTH;
if(msglen >= uip_mss() - len) {
/* PRINTF(("Not enouch space for char (%d, left %d)\n",
msglen, uip_mss() - len));*/
/* There is not enough space in the segment, so we remember
where we were ... */
vs->x2 = x;
vs->y2 = y;
/* ... and we break out of the loop. */
goto loopend;
}
/* PRINTF(("ptr %p\n",ptr);*/
/* recthdr = (struct rfb_fb_update_rect_hdr *)ptr;*/
recthdr = (struct rfb_fb_update_rect_hdr *)tmpbuf;
recthdr->rect.x = uip_htons(SCREEN_X + x * CTK_VNCFONT_WIDTH);
recthdr->rect.y = uip_htons(SCREEN_Y + y * CTK_VNCFONT_HEIGHT);
recthdr->rect.w = UIP_HTONS(CTK_VNCFONT_WIDTH);
recthdr->rect.h = UIP_HTONS(CTK_VNCFONT_HEIGHT);
recthdr->encoding[0] =
recthdr->encoding[1] =
recthdr->encoding[2] = 0;
recthdr->encoding[3] = RFB_ENC_RAW;
makechar((uint8_t *)recthdr +
sizeof(struct rfb_fb_update_rect_hdr),
x, y);
}
memcpy(ptr, tmpbuf, msglen);
PRINTF(("Msglen %d (%d:%d)\n", msglen, x, y));
len += msglen;
ptr += msglen;
++n;
}
x0 = vs->x;
}
loopend:
umsg->rects = uip_htons(n);
if(y == vs->y + vs->h && x == vs->x + vs->w) {
vs->x2 = vs->y2 = 0;
}
if(n > 0) {
/* printf("Sending %d rects, %d bytes (%p, %p, %p)\n", n, len,
uip_appdata, umsg, ptr);*/
uip_send(uip_appdata, len);
}
}
/*-----------------------------------------------------------------------------------*/
#define NUMKEYS 20
static char keys[NUMKEYS];
static int firstkey, lastkey;
char
vnc_out_keyavail(void)
{
return firstkey != lastkey;
}
char
vnc_out_getkey(void)
{
char key;
key = keys[firstkey];
if(firstkey != lastkey) {
++firstkey;
if(firstkey >= NUMKEYS) {
firstkey = 0;
}
}
return key;
}
void
vnc_out_key_event(struct vnc_server_state *vs)
{
register struct rfb_key_event *ev;
ev = (struct rfb_key_event *)uip_appdata;
if(ev->down != 0) {
if(vs->sendmsg == SEND_NONE) {
vs->sendmsg = SEND_UPDATE;
}
if(ev->key[2] == 0 ||
(ev->key[2] == 0xff &&
(ev->key[3] == CH_HOME ||
ev->key[3] == CH_TAB ||
ev->key[3] == CH_ESC ||
ev->key[3] == CH_DEL ||
ev->key[3] == CH_ENTER ||
ev->key[3] == CH_CURS_LEFT ||
ev->key[3] == CH_CURS_UP ||
ev->key[3] == CH_CURS_RIGHT ||
ev->key[3] == CH_CURS_DOWN))) {
keys[lastkey] = ev->key[3];
++lastkey;
if(lastkey >= NUMKEYS) {
lastkey = 0;
}
}
}
check_updates(vs);
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_pointer_event(struct vnc_server_state *vs)
{
struct rfb_pointer_event *ev;
uint16_t evx, evy;
ev = (struct rfb_pointer_event *)uip_appdata;
evx = uip_htons(ev->x);
evy = uip_htons(ev->y);
if(evx > SCREEN_X && evx < SCREEN_WIDTH - 2 * SCREEN_X &&
evy > SCREEN_Y && evy < SCREEN_HEIGHT - 2 * SCREEN_Y) {
mouse_button = ev->buttonmask & RFB_BUTTON_MASK1;
mouse_x = evx - SCREEN_X;
mouse_y = evy - SCREEN_Y;
check_updates(vs);
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_acked(CC_REGISTER_ARG struct vnc_server_state *vs)
{
if(vs->state != VNC_RUNNING) {
return;
}
if(vs->sendmsg == SENT_BLANK) {
init_send_screen(vs);
} else if(vs->sendmsg == SEND_BLANK) {
/* Do nothing until sendmsg == SENT_BLANK. */
} else if(vs->sendmsg == SEND_SCREEN) {
/* When the screen has been fully drawn, ->x2 and ->y2 are both
set to 0 to indicate this.*/
if(vs->x2 == 0 && vs->y2 == 0) {
vs->sendmsg = SEND_NONE;
/* If there was an updaterequest for the entire screen, we can
clear that flag now. */
if(vs->updates_current != NULL) {
vnc_server_update_free(vs, vs->updates_current);
vs->updates_current = NULL;
}
check_updates(vs);
} else {
vs->x1 = vs->x2;
vs->y1 = vs->y2;
}
} else if(vs->sendmsg == SEND_UPDATE) {
if(vs->x2 == 0 && vs->y2 == 0) {
/* So, we have updated the area that we needed. We now check if
there have been any recent full screen update requests. If
so, we need to go to the SEND_SCREEN state. Else, we see if
there were more areas that needed to be updated and if so,
we'll continue with those. */
vs->sendmsg = SEND_NONE;
if(vs->updates_current != NULL) {
vnc_server_update_free(vs, vs->updates_current);
vs->updates_current = NULL;
}
check_updates(vs);
#if 0
if(vs->updaterequest == VNC_SERVER_UPDATE_FULL) {
check_updates(vs);
} else {
vs->updatesptr2 = (vs->updatesptr2 + 1) %
VNC_SERVER_MAX_UPDATES;
/* If there are no more updates to do, we'll go back to the
SEND_NONE state. */
if(vs->updatesptr2 == vs->updatesptr) {
vs->updatetype = VNC_SERVER_UPDATE_NONE;
} else {
/* Otherwise, we continue to update the next area. */
vs->updaterequest = VNC_SERVER_UPDATE_PARTS;
check_updates(vs);
}
}
#endif /* 0 */
} else {
vs->x1 = vs->x2;
vs->y1 = vs->y2;
}
} else {
vs->sendmsg = SEND_NONE;
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_out_poll(struct vnc_server_state *vs)
{
/* PRINTF(("vs->state %d, sendmsg %d, updatetype %d, updatereq %d\n",
vs->state, vs->sendmsg, vs->updatetype, vs->updaterequest);*/
if(vs->state == VNC_RUNNING &&
vs->sendmsg == SEND_NONE) {
check_updates(vs);
vnc_server_send_data(vs);
}
}
/*-----------------------------------------------------------------------------------*/
#if CTK_CONF_MOUSE_SUPPORT
void
ctk_mouse_init(void)
{
}
/*-----------------------------------------------------------------------------------*/
unsigned short
ctk_mouse_x(void)
{
return mouse_x;
}
/*-----------------------------------------------------------------------------------*/
unsigned short
ctk_mouse_y(void)
{
return mouse_y;
}
/*-----------------------------------------------------------------------------------*/
unsigned char
ctk_mouse_button(void)
{
return mouse_button;
}
/*-----------------------------------------------------------------------------------*/
void
ctk_mouse_hide(void)
{
}
/*-----------------------------------------------------------------------------------*/
void
ctk_mouse_show(void)
{
}
/*-----------------------------------------------------------------------------------*/
#endif /* CTK_CONF_MOUSE_SUPPORT */

View File

@ -1,91 +0,0 @@
/*
* Copyright (c) 2001, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
*
*/
#ifndef VNC_OUT_H_
#define VNC_OUT_H_
void vnc_out_init(void);
void vnc_out_new(struct vnc_server_state *vs);
void vnc_out_send_blank(struct vnc_server_state *vs);
void vnc_out_send_screen(struct vnc_server_state *vs);
void vnc_out_send_update(struct vnc_server_state *vs);
void vnc_out_key_event(struct vnc_server_state *vs);
void vnc_out_pointer_event(struct vnc_server_state *vs);
void vnc_out_acked(struct vnc_server_state *vs);
void vnc_out_poll(struct vnc_server_state *vs);
void vnc_out_update_screen(uint8_t x, uint8_t y, uint8_t c, uint8_t color);
char vnc_out_getkey(void);
char vnc_out_keyavail(void);
void vnc_out_update_area(struct vnc_server_state *vs,
uint8_t x, uint8_t y, uint8_t w, uint8_t h);
#include "ctk/ctk.h"
unsigned char vnc_out_add_icon(struct ctk_icon *icon);
#if 1
#define VNC_OUT_BACKGROUNDCOLOR 0
#define VNC_OUT_WINDOWCOLOR 1
#define VNC_OUT_SEPARATORCOLOR 7 /*(VNC_OUT_WINDOWCOLOR + 6)*/
#define VNC_OUT_LABELCOLOR 13 /*(VNC_OUT_SEPARATORCOLOR + 6)*/
#define VNC_OUT_BUTTONCOLOR 19 /*(VNC_OUT_LABELCOLOR + 6)*/
#define VNC_OUT_HYPERLINKCOLOR 25 /*(VNC_OUT_BUTTONCOLOR + 6)*/
#define VNC_OUT_TEXTENTRYCOLOR 31 /*(VNC_OUT_HYPERLINKCOLOR + 6)*/
#define VNC_OUT_ICONCOLOR 37 /*(VNC_OUT_TEXTENTRYCOLOR + 6)*/
#define VNC_OUT_MENUCOLOR 43 /*(VNC_OUT_ICONCOLOR + 6)*/
#define VNC_OUT_OPENMENUCOLOR 44/*(VNC_OUT_MENUCOLOR + 1)*/
#define VNC_OUT_ACTIVEMENUCOLOR 45 /*(VNC_OUT_OPENMENUCOLOR + 1) */
#else
#define VNC_OUT_BACKGROUNDCOLOR 0
#define VNC_OUT_WINDOWCOLOR 1
#define VNC_OUT_SEPARATORCOLOR (VNC_OUT_WINDOWCOLOR + 6)
#define VNC_OUT_LABELCOLOR (VNC_OUT_SEPARATORCOLOR + 6)
#define VNC_OUT_BUTTONCOLOR (VNC_OUT_LABELCOLOR + 6)
#define VNC_OUT_HYPERLINKCOLOR (VNC_OUT_BUTTONCOLOR + 6)
#define VNC_OUT_TEXTENTRYCOLOR (VNC_OUT_HYPERLINKCOLOR + 6)
#define VNC_OUT_ICONCOLOR (VNC_OUT_TEXTENTRYCOLOR + 6)
#define VNC_OUT_MENUCOLOR (VNC_OUT_ICONCOLOR + 6)
#define VNC_OUT_OPENMENUCOLOR (VNC_OUT_MENUCOLOR + 1)
#define VNC_OUT_ACTIVEMENUCOLOR (VNC_OUT_OPENMENUCOLOR + 1)
#endif
#endif /* VNC_OUT_H_ */

View File

@ -1,486 +0,0 @@
/*
* Copyright (c) 2001, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
*
*/
/* A micro implementation of a VNC server. VNC is a protocol for
remote network displays. See http://www.uk.research.att.com/vnc/
for information about VNC.
Initialization states:
VNC_VERSION (send version string)
VNC_AUTH (send auth message)
VNC_INIT (send init message)
Steady state:
VNC_RUNNING (send RFB updates, parse incoming messages)
What kind of message should be sent:
SEND_NONE (No message)
SEND_BLANK (Blank screen initially)
SEND_SCREEN (Send entire screen, initially)
SEND_UPDATE (Send incremental update)
*/
#include "contiki-net.h"
#include "ctk/vnc-server.h"
#include "ctk/vnc-out.h"
#include <string.h>
/* RFB server initial handshaking string. */
#define RFB_SERVER_VERSION_STRING rfb_server_version_string
/* "RFB 003.003" */
static uint8_t rfb_server_version_string[12] = {82,70,66,32,48,48,51,46,48,48,51,10};
/* uVNC */
static uint8_t uvnc_name[4] = {117,86,78,67};
#if 1
#define PRINTF(x)
#else
#define PRINTF(x) printf x
#endif
/*-----------------------------------------------------------------------------------*/
uint8_t
vnc_server_draw_rect(uint8_t *ptr, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t c)
{
register struct rfb_fb_update_rect_hdr *recthdr;
struct rfb_rre_hdr *rrehdr;
recthdr = (struct rfb_fb_update_rect_hdr *)ptr;
rrehdr = (struct rfb_rre_hdr *)(ptr + sizeof(struct rfb_fb_update_rect_hdr));
recthdr->rect.x = x;
recthdr->rect.y = y;
recthdr->rect.w = w;
recthdr->rect.h = h;
recthdr->encoding[0] =
recthdr->encoding[1] =
recthdr->encoding[2] = 0;
recthdr->encoding[3] = RFB_ENC_RRE;
rrehdr->subrects[0] =
rrehdr->subrects[1] = 0;
rrehdr->bgpixel = c;
return sizeof(struct rfb_fb_update_rect_hdr) + sizeof(struct rfb_rre_hdr);
}
/*-----------------------------------------------------------------------------------*/
void
vnc_server_init(void)
{
vnc_out_init();
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_send_blank(struct vnc_server_state *vs)
{
switch(vs->type) {
case 0:
vnc_out_send_blank(vs);
break;
/* case 1:
vnc_stats_send_blank(vs);
break; */
}
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_send_screen(struct vnc_server_state *vs)
{
switch(vs->type) {
case 0:
vnc_out_send_screen(vs);
break;
/* case 1:
vnc_stats_send_screen(vs);
break;*/
}
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_send_update(struct vnc_server_state *vs)
{
switch(vs->type) {
case 0:
vnc_out_send_update(vs);
break;
/* case 1:
vnc_stats_send_update(vs);
break;*/
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_server_send_data(struct vnc_server_state *vs)
{
register struct rfb_server_init *initmsg;
switch(vs->state) {
case VNC_VERSION:
uip_send(RFB_SERVER_VERSION_STRING, sizeof(RFB_SERVER_VERSION_STRING));
break;
case VNC_AUTH:
((char *)uip_appdata)[0] = 0;
((char *)uip_appdata)[1] = 0;
((char *)uip_appdata)[2] = 0;
((char *)uip_appdata)[3] = RFB_AUTH_NONE;
uip_send(uip_appdata, 4);
break;
case VNC_INIT:
initmsg = (struct rfb_server_init *)uip_appdata;
initmsg->width = uip_htons(vs->width);
initmsg->height = uip_htons(vs->height);
/* BGR233 pixel format. */
initmsg->format.bps = 8;
initmsg->format.depth = 8;
initmsg->format.endian = 1;
initmsg->format.truecolor = 1;
initmsg->format.red_max = uip_htons(7);
initmsg->format.green_max = uip_htons(7);
initmsg->format.blue_max = uip_htons(3);
initmsg->format.red_shift = 0;
initmsg->format.green_shift = 3;
initmsg->format.blue_shift = 6;
initmsg->namelength[0] = 0;
initmsg->namelength[1] = 0;
initmsg->namelength[2] = 0;
initmsg->namelength[3] = 4;
memcpy(&((char *)uip_appdata)[sizeof(struct rfb_server_init)], uvnc_name, 4);
/* ((char *)uip_appdata)[sizeof(struct rfb_server_init)+0] = 'u';
((char *)uip_appdata)[sizeof(struct rfb_server_init)+1] = 'V';
((char *)uip_appdata)[sizeof(struct rfb_server_init)+2] = 'N';
((char *)uip_appdata)[sizeof(struct rfb_server_init)+3] = 'C';*/
uip_send(uip_appdata, sizeof(struct rfb_server_init) + 4);
break;
case VNC_RUNNING:
switch(vs->sendmsg) {
case SEND_NONE:
PRINTF(("Sending none\n"));
break;
case SEND_BLANK:
case SENT_BLANK:
PRINTF(("Sending blank\n"));
vnc_send_blank(vs);
break;
case SEND_SCREEN:
PRINTF(("Sending screen\n"));
vnc_send_screen(vs);
break;
case SEND_UPDATE:
PRINTF(("Sending update\n"));
vnc_send_update(vs);
break;
}
break;
default:
break;
}
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_key_event(struct vnc_server_state *vs)
{
switch(vs->type) {
case 0:
vnc_out_key_event(vs);
break;
/* case 1:
vnc_stats_key_event(vs);
break;*/
}
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_pointer_event(struct vnc_server_state *vs)
{
switch(vs->type) {
case 0:
vnc_out_pointer_event(vs);
break;
/* case 1:
vnc_stats_pointer_event(vs);
break;*/
}
}
/*-----------------------------------------------------------------------------------*/
static uint8_t
vnc_read_data(CC_REGISTER_ARG struct vnc_server_state *vs)
{
uint8_t *appdata;
uint16_t len;
struct rfb_fb_update_request *req;
/* uint8_t niter;*/
len = uip_datalen();
appdata = (uint8_t *)uip_appdata;
/* First, check if there is data left to discard since last read. */
if(vs->readlen > 0) {
appdata += vs->readlen;
if(len > vs->readlen) {
len -= vs->readlen;
vs->readlen = 0;
} else {
vs->readlen -= len;
len = 0;
}
}
if(vs->readlen != 0) {
return 1;
}
/* All data read and ignored, parse next message. */
/* for(niter = 32; niter > 0 && len > 0; --niter) {*/
while(len > 0) {
switch(vs->state) {
case VNC_VERSION:
case VNC_VERSION2:
PRINTF(("Read in version\n"));
/* Receive and ignore client version string (12 bytes). */
vs->state = VNC_AUTH;
vs->readlen = 12;
break;
case VNC_AUTH:
case VNC_AUTH2:
PRINTF(("Read in auth \n"));
/* Read and discard initialization from client (1 byte). */
vs->readlen = 1;
vs->state = VNC_INIT;
break;
case VNC_INIT:
case VNC_INIT2:
PRINTF(("Read in init \n"));
vs->readlen = 0;
vs->state = VNC_RUNNING;
case VNC_RUNNING:
/* Handle all client events. */
switch(*appdata) {
case RFB_SET_PIXEL_FORMAT:
PRINTF(("Set pixel format\n"));
vs->readlen = sizeof(struct rfb_set_pixel_format);
/* Check if client runs with BGR233 format. If not, abort the
connection. */
/* XXX: not implemented yet. */
break;
case RFB_FIX_COLORMAP_ENTRIES:
PRINTF(("Fix colormap entries\n"));
return 0;
case RFB_SET_ENCODINGS:
PRINTF(("Set encodings\n"));
vs->readlen = sizeof(struct rfb_set_encoding);
vs->readlen += uip_htons(((struct rfb_set_encoding *)appdata)->encodings) * 4;
/* Make sure that client supports the encodings we use. */
/* XXX: not implemented yet. */
break;
case RFB_FB_UPDATE_REQ:
PRINTF(("Update request\n"));
vs->update_requested = 1;
vs->readlen = sizeof(struct rfb_fb_update_request);
/* blank the screen initially */
req = (struct rfb_fb_update_request *)appdata;
if(req->incremental == 0) {
/* vs->sendmsg = SEND_BLANK;*/
vnc_out_update_area(vs, 0, 0, vs->w, vs->h);
}
break;
case RFB_KEY_EVENT:
vs->readlen = sizeof(struct rfb_key_event);
vnc_key_event(vs);
break;
case RFB_POINTER_EVENT:
vs->readlen = sizeof(struct rfb_pointer_event);
vnc_pointer_event(vs);
break;
case RFB_CLIENT_CUT_TEXT:
PRINTF(("Client cut text\n"));
if(((struct rfb_client_cut_text *)appdata)->len[0] != 0 ||
((struct rfb_client_cut_text *)appdata)->len[1] != 0) {
return 0;
}
vs->readlen = sizeof(struct rfb_client_cut_text) +
(((struct rfb_client_cut_text *)appdata)->len[2] << 8) +
((struct rfb_client_cut_text *)appdata)->len[3];
/* return 0;*/
break;
default:
PRINTF(("Unknown message %d\n", *appdata));
return 0;
}
break;
default:
return 0;
}
if(vs->readlen > 0) {
if(len > vs->readlen) {
len -= vs->readlen;
appdata += vs->readlen;
vs->readlen = 0;
} else {
vs->readlen -= len;
len = 0;
}
} else {
/* Lost data. */
break;
}
}
/* if(vs->readlen > 0) {
printf("More data %d\n", vs->readlen);
}*/
/* uip_appdata = appdata;*/
return 1;
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_new(CC_REGISTER_ARG struct vnc_server_state *vs)
{
vs->counter = 0;
vs->readlen = 0;
vs->sendmsg = SEND_NONE;
vs->update_requested = 1;
switch(vs->type) {
case 0:
vnc_out_new(vs);
break;
/* case 1:
vnc_stats_new(vs);
break;*/
}
}
/*-----------------------------------------------------------------------------------*/
static void
vnc_acked(CC_REGISTER_ARG struct vnc_server_state *vs)
{
switch(vs->state) {
case VNC_VERSION:
vs->state = VNC_VERSION2;
break;
case VNC_AUTH:
vs->state = VNC_AUTH2;
break;
case VNC_INIT:
vs->state = VNC_INIT2;
break;
case VNC_RUNNING:
switch(vs->type) {
case 0:
vnc_out_acked(vs);
break;
/* case 1:
vnc_stats_acked(vs);
break;*/
}
break;
}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_server_appcall(struct vnc_server_state *vs)
{
vs->type = uip_htons(uip_conn->lport) - 5900;
if(uip_connected()) {
vnc_new(vs);
vs->state = VNC_VERSION;
vnc_server_send_data(vs);
return;
}
if(uip_acked()) {
PRINTF(("Acked\n"));
vnc_acked(vs);
}
if(uip_newdata()) {
PRINTF(("Newdata\n"));
vs->counter = 0;
if(vnc_read_data(vs) == 0) {
uip_abort();
return;
}
}
if(uip_rexmit()) {
PRINTF(("Rexmit\n"));
}
if(uip_newdata() ||
uip_rexmit() ||
uip_acked()) {
vnc_server_send_data(vs);
} else if(uip_poll()) {
++vs->counter;
/* Abort connection after about 20 seconds of inactivity. */
if(vs->counter >= 40) {
uip_abort();
return;
}
vnc_out_poll(vs);
}
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,295 +0,0 @@
/*
* Copyright (c) 2001, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the uIP TCP/IP stack.
*
*
*/
#ifndef VNC_SERVER_H_
#define VNC_SERVER_H_
/*struct vnc_server_updatearea {
uint8_t active;
uint8_t x, y;
uint8_t w, h;
};*/
struct vnc_server_update {
struct vnc_server_update *next;
#define VNC_SERVER_UPDATE_NONE 0
#define VNC_SERVER_UPDATE_PARTS 1
#define VNC_SERVER_UPDATE_FULL 2
uint8_t type;
uint8_t x, y;
uint8_t w, h;
};
struct vnc_server_state {
uint16_t counter;
uint8_t type;
uint8_t state;
uint16_t height, width;
uint8_t update_requested;
/* Variables used when sending screen updates. */
uint8_t x, y, x1, y1, x2, y2;
uint8_t w, h;
uint16_t readlen;
uint8_t sendmsg;
uint8_t button;
struct vnc_server_update *updates_current;
struct vnc_server_update *updates_pending;
struct vnc_server_update *updates_free;
#define VNC_SERVER_MAX_UPDATES 8
struct vnc_server_update updates_pool[VNC_SERVER_MAX_UPDATES];
};
struct vnc_server_update *
vnc_server_update_alloc(struct vnc_server_state *vs);
void vnc_server_update_free(struct vnc_server_state *vs,
struct vnc_server_update *a);
void vnc_server_update_remove(struct vnc_server_state *vs,
struct vnc_server_update *a);
void vnc_server_update_add(struct vnc_server_state *vs,
struct vnc_server_update *a);
struct vnc_server_update *
vnc_server_update_dequeue(struct vnc_server_state *vs);
void vnc_server_init(void);
void vnc_server_appcall(struct vnc_server_state *state);
extern struct vnc_server_state *vs;
enum {
VNC_DEALLOCATED,
VNC_VERSION,
VNC_VERSION2,
VNC_AUTH,
VNC_AUTH2,
VNC_INIT,
VNC_INIT2,
VNC_RUNNING
};
/* Sendmsg */
enum {
SEND_NONE,
SEND_BLANK,
SENT_BLANK,
SEND_SCREEN,
SEND_UPDATE
};
/* Definitions of the RFB (Remote Frame Buffer) protocol
structures and constants. */
#include "contiki-net.h"
void vnc_server_send_data(struct vnc_server_state *vs);
uint8_t vnc_server_draw_rect(uint8_t *ptr, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t c);
/* Generic rectangle - x, y coordinates, width and height. */
struct rfb_rect {
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
};
/* Pixel format definition. */
struct rfb_pixel_format {
uint8_t bps; /* Bits per pixel: 8, 16 or 32. */
uint8_t depth; /* Color depth: 8-32 */
uint8_t endian; /* 1 - big endian (motorola), 0 - little endian
(x86) */
uint8_t truecolor; /* 1 - true color is used, 0 - true color is not used. */
/* The following fields are only used if true color is used. */
uint16_t red_max, green_max, blue_max;
uint8_t red_shift, green_shift, blue_shift;
uint8_t pad1;
uint16_t pad2;
};
/* RFB authentication constants. */
#define RFB_AUTH_FAILED 0
#define RFB_AUTH_NONE 1
#define RFB_AUTH_VNC 2
#define RFB_VNC_AUTH_OK 0
#define RFB_VNC_AUTH_FAILED 1
#define RFB_VNC_AUTH_TOOMANY 2
/* RFB message types. */
/* From server to client: */
#define RFB_FB_UPDATE 0
#define RFB_SET_COLORMAP_ENTRIES 1
#define RFB_BELL 2
#define RFB_SERVER_CUT_TEXT 3
/* From client to server. */
#define RFB_SET_PIXEL_FORMAT 0
#define RFB_FIX_COLORMAP_ENTRIES 1
#define RFB_SET_ENCODINGS 2
#define RFB_FB_UPDATE_REQ 3
#define RFB_KEY_EVENT 4
#define RFB_POINTER_EVENT 5
#define RFB_CLIENT_CUT_TEXT 6
/* Encoding types. */
#define RFB_ENC_RAW 0
#define RFB_ENC_COPYRECT 1
#define RFB_ENC_RRE 2
#define RFB_ENC_CORRE 3
#define RFB_ENC_HEXTILE 4
/* Message definitions. */
/* Server to client messages. */
struct rfb_server_init {
uint16_t width;
uint16_t height;
struct rfb_pixel_format format;
uint8_t namelength[4];
/* Followed by name. */
};
struct rfb_fb_update {
uint8_t type;
uint8_t pad;
uint16_t rects; /* Number of rectanges (struct rfb_fb_update_rect_hdr +
data) that follows. */
};
struct rfb_fb_update_rect_hdr {
struct rfb_rect rect;
uint8_t encoding[4];
};
struct rfb_copy_rect {
uint16_t srcx;
uint16_t srcy;
};
struct rfb_rre_hdr {
uint16_t subrects[2]; /* Number of subrectangles (struct
rfb_rre_subrect) to follow. */
uint8_t bgpixel;
};
struct rfb_rre_subrect {
uint8_t pixel;
struct rfb_rect rect;
};
struct rfb_corre_rect {
uint8_t x;
uint8_t y;
uint8_t w;
uint8_t h;
};
/* Client to server messages. */
struct rfb_set_pixel_format {
uint8_t type;
uint8_t pad;
uint16_t pad2;
struct rfb_pixel_format format;
};
struct rfb_fix_colormap_entries {
uint8_t type;
uint8_t pad;
uint16_t firstcolor;
uint16_t colors;
};
struct rfb_set_encoding {
uint8_t type;
uint8_t pad;
uint16_t encodings;
};
struct rfb_fb_update_request {
uint8_t type;
uint8_t incremental;
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
};
struct rfb_key_event {
uint8_t type;
uint8_t down;
uint16_t pad;
uint8_t key[4];
};
#define RFB_BUTTON_MASK1 1
#define RFB_BUTTON_MASK2 2
#define RFB_BUTTON_MASK3 4
struct rfb_pointer_event {
uint8_t type;
uint8_t buttonmask;
uint16_t x;
uint16_t y;
};
struct rfb_client_cut_text {
uint8_t type;
uint8_t pad[3];
uint8_t len[4];
};
#endif /* VNC_SERVER_H_ */