58 #include "contiki-net.h"
59 #include "ctk/vnc-server.h"
60 #include "ctk/vnc-out.h"
65 #define RFB_SERVER_VERSION_STRING rfb_server_version_string
68 static u8_t rfb_server_version_string[12] = {82,70,66,32,48,48,51,46,48,48,51,10};
71 static u8_t uvnc_name[4] = {117,86,78,67};
75 #define PRINTF(x) printf x
80 vnc_server_draw_rect(u8_t *ptr, u16_t x, u16_t y, u16_t w, u16_t h, u8_t c)
82 register struct rfb_fb_update_rect_hdr *recthdr;
83 struct rfb_rre_hdr *rrehdr;
85 recthdr = (
struct rfb_fb_update_rect_hdr *)ptr;
86 rrehdr = (
struct rfb_rre_hdr *)(ptr +
sizeof(
struct rfb_fb_update_rect_hdr));
92 recthdr->encoding[0] =
93 recthdr->encoding[1] =
94 recthdr->encoding[2] = 0;
95 recthdr->encoding[3] = RFB_ENC_RRE;
98 rrehdr->subrects[1] = 0;
101 return sizeof(
struct rfb_fb_update_rect_hdr) + sizeof(struct rfb_rre_hdr);
105 vnc_server_init(
void)
111 vnc_send_blank(
struct vnc_server_state *vs)
115 vnc_out_send_blank(vs);
124 vnc_send_screen(
struct vnc_server_state *vs)
128 vnc_out_send_screen(vs);
137 vnc_send_update(
struct vnc_server_state *vs)
141 vnc_out_send_update(vs);
150 vnc_server_send_data(
struct vnc_server_state *vs)
152 register struct rfb_server_init *initmsg;
156 uip_send(RFB_SERVER_VERSION_STRING,
sizeof(RFB_SERVER_VERSION_STRING));
170 initmsg->format.bps = 8;
171 initmsg->format.depth = 8;
172 initmsg->format.endian = 1;
173 initmsg->format.truecolor = 1;
175 initmsg->format.green_max =
uip_htons(7);
177 initmsg->format.red_shift = 0;
178 initmsg->format.green_shift = 3;
179 initmsg->format.blue_shift = 6;
180 initmsg->namelength[0] = 0;
181 initmsg->namelength[1] = 0;
182 initmsg->namelength[2] = 0;
183 initmsg->namelength[3] = 4;
184 memcpy(&((
char *)
uip_appdata)[
sizeof(
struct rfb_server_init)], uvnc_name, 4);
192 switch(vs->sendmsg) {
194 PRINTF((
"Sending none\n"));
199 PRINTF((
"Sending blank\n"));
204 PRINTF((
"Sending screen\n"));
209 PRINTF((
"Sending update\n"));
222 vnc_key_event(
struct vnc_server_state *vs)
226 vnc_out_key_event(vs);
235 vnc_pointer_event(
struct vnc_server_state *vs)
239 vnc_out_pointer_event(vs);
252 struct rfb_fb_update_request *req;
259 if(vs->readlen > 0) {
260 appdata += vs->readlen;
261 if(len > vs->readlen) {
270 if(vs->readlen != 0) {
280 PRINTF((
"Read in version\n"));
282 vs->state = VNC_AUTH;
288 PRINTF((
"Read in auth \n"));
291 vs->state = VNC_INIT;
296 PRINTF((
"Read in init \n"));
298 vs->state = VNC_RUNNING;
303 case RFB_SET_PIXEL_FORMAT:
304 PRINTF((
"Set pixel format\n"));
305 vs->readlen =
sizeof(
struct rfb_set_pixel_format);
311 case RFB_FIX_COLORMAP_ENTRIES:
312 PRINTF((
"Fix colormap entries\n"));
315 case RFB_SET_ENCODINGS:
316 PRINTF((
"Set encodings\n"));
317 vs->readlen =
sizeof(
struct rfb_set_encoding);
318 vs->readlen +=
uip_htons(((
struct rfb_set_encoding *)appdata)->encodings) * 4;
323 case RFB_FB_UPDATE_REQ:
324 PRINTF((
"Update request\n"));
325 vs->update_requested = 1;
326 vs->readlen =
sizeof(
struct rfb_fb_update_request);
328 req = (
struct rfb_fb_update_request *)appdata;
329 if(req->incremental == 0) {
331 vnc_out_update_area(vs, 0, 0, vs->w, vs->h);
336 vs->readlen =
sizeof(
struct rfb_key_event);
340 case RFB_POINTER_EVENT:
341 vs->readlen =
sizeof(
struct rfb_pointer_event);
342 vnc_pointer_event(vs);
345 case RFB_CLIENT_CUT_TEXT:
346 PRINTF((
"Client cut text\n"));
348 if(((
struct rfb_client_cut_text *)appdata)->len[0] != 0 ||
349 ((
struct rfb_client_cut_text *)appdata)->len[1] != 0) {
353 vs->readlen =
sizeof(
struct rfb_client_cut_text) +
354 (((struct rfb_client_cut_text *)appdata)->len[2] << 8) +
355 ((
struct rfb_client_cut_text *)appdata)->len[3];
360 PRINTF((
"Unknown message %d\n", *appdata));
369 if(vs->readlen > 0) {
370 if(len > vs->readlen) {
372 appdata += vs->readlen;
399 vs->sendmsg = SEND_NONE;
400 vs->update_requested = 1;
416 vs->state = VNC_VERSION2;
420 vs->state = VNC_AUTH2;
424 vs->state = VNC_INIT2;
441 vnc_server_appcall(
struct vnc_server_state *vs)
448 vs->state = VNC_VERSION;
449 vnc_server_send_data(vs);
458 PRINTF((
"Newdata\n"));
460 if(vnc_read_data(vs) == 0) {
467 PRINTF((
"Rexmit\n"));
474 vnc_server_send_data(vs);
478 if(vs->counter >= 40) {