diff --git a/graphics/vnc/server/Kconfig b/graphics/vnc/server/Kconfig index 35b2953d8a..63ca69094c 100644 --- a/graphics/vnc/server/Kconfig +++ b/graphics/vnc/server/Kconfig @@ -49,4 +49,8 @@ config VNCSERVER_KBDENCODE Use a special encoding of keyboard characters as defined in include/nuttx/input/kbd_coded.h. +config VNCSERVER_IOBUFFER_SIZE + int "I/O buffer size + default 80 + endif # VNCSERVER diff --git a/graphics/vnc/server/vnc_negotiate.c b/graphics/vnc/server/vnc_negotiate.c index 8f11218549..b8118634dd 100644 --- a/graphics/vnc/server/vnc_negotiate.c +++ b/graphics/vnc/server/vnc_negotiate.c @@ -47,6 +47,16 @@ #include "vnc_server.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if defined(CONFIG_VNCSERVER_PROTO3p3) +static const char g_vncproto[] = RFB_PROTOCOL_VERSION_3p3; +#elif defined(CONFIG_VNCSERVER_PROTO3p8) +static const char g_vncproto[] = RFB_PROTOCOL_VERSION_3p8; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -93,13 +103,60 @@ static void nvc_xyz(FAR struct vnc_session_s *session) #ifdef CONFIG_VNCSERVER_PROTO3p3 int vnc_negotiate(FAR struct vnc_session_s *session) { + ssize_t nrecvd; + size_t len; + int errcode; + + /* Inform the client of the VNC protocol */ + + len = strlen(g_vncproto); + nrecvd = psock_send(&session->connect, g_vncproto, len, 0); + if (nrecvd < 0) + { + goto errout_with_errno; + } + + nrecvd = psock_recv(&session->connect, session->iobuf, len, 0); + if (nrecvd <= 0) + { + goto errout_with_errno; + } + + /* Tell the client that we won't use any stinkin' security */ + return OK; + +errout_with_errno: + errcode = get_errno(); + +errout_with_errcode: + DEBUGASSERT(errcode > 0); + return -errcode; } #endif #ifdef CONFIG_VNCSERVER_PROTO3p8 int vnc_negotiate(FAR struct vnc_session_s *session) { + ssize_t nbytes; + + /* Inform the client of the VNC protocol */ + + len = strlen(g_vncproto); + nrecvd = psock_send(&session->connect, g_vncproto, len, 0); + if (nrecvd < 0) + { + goto errout_with_errno; + } + + nrecvd = psock_recv(&session->connect, session->iobuf, len, 0); + if (nrecvd <= 0) + { + goto errout_with_errno; + } + + /* Offer the client a choice of security -- where None is the only option. */ + return OK; } #endif diff --git a/graphics/vnc/server/vnc_server.h b/graphics/vnc/server/vnc_server.h index 79012d5d6b..f17d941be9 100644 --- a/graphics/vnc/server/vnc_server.h +++ b/graphics/vnc/server/vnc_server.h @@ -75,12 +75,26 @@ # define CONFIG_VNCSERVER_STACKSIZE 2048 #endif +#ifndef CONFIG_VNCSERVER_IOBUFFER_SIZE +# define CONFIG_VNCSERVER_IOBUFFER_SIZE 80 +#endif + /* RFB Port Number */ #define RFB_PORT_BASE 5900 #define RFB_MAX_DISPLAYS CONFIG_VNCSERVER_NDISPLAYS #define RFB_DISPLAY_PORT(d) (RFB_PORT_BASE + (d)) +/* Miscellaneous */ + +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -115,6 +129,10 @@ struct vnc_session_s uint8_t bpp; /* Bits per pixel */ struct nxgl_size_s screen; /* Size of the screen in pixels x rows */ FAR uint8_t *fb; /* Allocated local frame buffer */ + + /* I/O buffer for misc network send/receive */ + + uint8_t iobuf[CONFIG_VNCSERVER_IOBUFFER_SIZE]; }; /****************************************************************************