Go to the documentation of this file.
42 #include <sys/ioctl.h>
45 #if defined(__FreeBSD__)
49 #include <sys/termios.h>
56 #include <sys/types.h>
68 #include "debug/VNC.hh"
111 else if (revent & POLLNVAL)
142 DPRINTF(VNC,
"Vnc server created at port %d\n",
p->port);
163 warn_once(
"Sockets disabled, not accepting vnc client connections");
169 "can't bind address vnc server port %d in use PID %d\n",
174 ccprintf(cerr,
"%s: Listening for connections on port %d\n",
191 panic(
"%s: cannot accept a connection if not listening!",
name());
195 warn(
"%s: failed to accept VNC connection!",
name());
200 char message[] =
"vnc server already attached!\n";
215 inform(
"VNC client attached\n");
223 DPRINTF(VNC,
"Vnc client message recieved\n");
243 uint8_t message_type;
244 if (!
read(&message_type))
247 switch (message_type) {
267 warn(
"Unimplemented message type recv from client: %d\n",
274 panic(
"Unknown vnc server state\n");
284 panic(
"vnc not properly attached.\n");
289 }
while (ret == -1 && errno == EINTR);
293 DPRINTF(VNC,
"Read failed %d.\n", ret);
312 return read((uint8_t *)
val,
sizeof(T));
320 panic(
"Vnc client not properly attached.\n");
325 DPRINTF(VNC,
"Write failed.\n");
337 return write((uint8_t *)
val,
sizeof(T));
343 return write((uint8_t *)str, strlen(str));
363 inform(
"VNC client detached\n");
370 uint32_t
len = strlen(error_msg);
381 size_t len M5_VAR_USED;
382 char version_string[13];
385 version_string[12] = 0;
387 if (!
read((uint8_t *)version_string,
sizeof(version_string) - 1)) {
388 warn(
"Failed to read protocol version.");
392 uint32_t major, minor;
395 if (sscanf(version_string,
"RFB %03d.%03d\n", &major, &minor) != 2) {
396 warn(
" Malformed protocol version %s\n", version_string);
397 sendError(
"Malformed protocol version\n");
402 DPRINTF(VNC,
"Client request protocol version %d.%d\n", major, minor);
405 if (major != 3 || minor < 2) {
406 warn(
"Unsupported VNC client version... disconnecting\n");
415 if (!
write(&sec_type))
433 uint8_t security_type;
434 if (!
read(&security_type))
438 warn(
"Unknown VNC security type\n");
442 DPRINTF(VNC,
"Sending security auth OK\n");
445 if (!
write(&success))
455 DPRINTF(VNC,
"Sending server init message to client\n");
473 memcpy(msg.
name,
"M5", 2);
483 DPRINTF(VNC,
"Received pixel format from client message\n");
489 DPRINTF(VNC,
" -- bpp = %d; depth = %d; be = %d\n", pfm.px.bpp,
490 pfm.px.depth, pfm.px.bigendian);
491 DPRINTF(VNC,
" -- true color = %d red,green,blue max = %d,%d,%d\n",
492 pfm.px.truecolor,
betoh(pfm.px.redmax),
betoh(pfm.px.greenmax),
493 betoh(pfm.px.bluemax));
494 DPRINTF(VNC,
" -- red,green,blue shift = %d,%d,%d\n", pfm.px.redshift,
495 pfm.px.greenshift, pfm.px.blueshift);
507 warn(
"VNC client doesn't support true color raw encoding\n");
515 DPRINTF(VNC,
"Received supported encodings from client\n");
523 DPRINTF(VNC,
" -- %d encoding present\n", pem.num_encodings);
526 for (
int x = 0;
x < pem.num_encodings;
x++) {
543 warn(
"VNC clients must always support raw encoding\n");
551 DPRINTF(VNC,
"Received frame buffer update request from client\n");
558 fbr.y =
betoh(fbr.y);
559 fbr.width =
betoh(fbr.width);
560 fbr.height =
betoh(fbr.height);
562 DPRINTF(VNC,
" -- x = %d y = %d w = %d h = %d\n", fbr.x, fbr.y, fbr.width,
571 DPRINTF(VNC,
"Received keyboard input from client\n");
577 DPRINTF(VNC,
" -- received key code %d (%s)\n", kem.key, kem.down_flag ?
587 DPRINTF(VNC,
"Received pointer input from client\n");
594 pem.y =
betoh(pem.y);
595 DPRINTF(VNC,
" -- pointer at x = %d y = %d buttons = %#x\n", pem.x, pem.y,
605 DPRINTF(VNC,
"Received client copy buffer message\n");
612 size_t data_len =
betoh(cct.length);
613 DPRINTF(VNC,
"String length %d\n", data_len);
614 while (data_len > 0) {
615 size_t bytes_to_read = data_len > 1024 ? 1024 : data_len;
616 if (!
read((uint8_t *)&str, bytes_to_read))
618 str[bytes_to_read] = 0;
619 data_len -= bytes_to_read;
620 DPRINTF(VNC,
"Buffer: %s\n", str);
631 DPRINTF(VNC,
"NOT sending framebuffer update\n");
638 DPRINTF(VNC,
"Sending framebuffer update\n");
666 for (
int y = 0; y <
fb->
height(); ++y) {
668 uint8_t *raw_pixel(line_buffer.data());
674 if (!
write(line_buffer.data(), line_buffer.size()))
683 DPRINTF(VNC,
"Sending framebuffer resize\n");
735 VncServerParams::create()
void setEncodings()
Receive encodings message from client and process it.
@ ServerFrameBufferUpdate
unsigned mask
Bit mask (after shifting)
void sendError(const char *error_msg)
vnc client Interface
bool write(const uint8_t *buf, size_t len)
Write a buffer to the client.
virtual bool listen(int port, bool reuse=true)
bool supportsResizeEnc
If the vnc client supports the desktop resize command.
const static uint32_t AuthNone
Configurable RGB pixel converter.
bool read1(uint8_t *buf, size_t len)
Read len -1 bytes from the client into the buffer provided + 1 assert that we read enough bytes.
virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons)=0
called whenever the mouse moves or it's button state changes buttons is a simple mask with each butto...
virtual int accept(bool nodelay=false)
void setDirty() override
The frame buffer uses this call to notify the vnc server that the frame buffer has been updated and a...
const static uint32_t VncOK
Error conditions.
void schedule(PollEvent *event)
Channel ch_g
Green channel conversion helper.
const Pixel & pixel(unsigned x, unsigned y) const
Get a pixel from an (x, y) coordinate.
ByteOrder byte_order
Byte order when stored to memory.
DataEvent(VncServer *vs, int fd, int e)
Poll event for the data socket.
void requestFbUpdate()
Receive message from client asking for updated frame buffer.
void sendFrameBufferResized()
Tell the client that the frame buffer resized.
static const PixelConverter pixelConverter
VncServer(const Params *p)
VncServer.
ConnectionState curState
The rfb prototol state the connection is in.
void sendServerInit()
Send client our idea about what the frame buffer looks like.
unsigned length
Bytes per pixel when stored in memory (including padding)
bool sendUpdate
An update needs to be sent to the client.
@ WaitForSecurityResponse
unsigned depth
Number of bits used to represent one pixel value (excluding padding).
void checkSecurity()
Check that the security exchange was successful.
void recvKeyboardInput()
Receive message from client providing new keyboard input.
void sendFrameBufferUpdate()
Send a updated frame buffer to the client.
void checkProtocolVersion()
Check the client's protocol verion for compatibility and send the security types we support.
void recvPointerInput()
Recv message from client providing new mouse movement or button click.
Channel ch_b
Blue channel conversion helper.
EventQueue * eventQueue() const
virtual void keyPress(uint32_t key, bool down)=0
Called when the vnc server receives a key press event from the client.
const static uint32_t AuthInvalid
Authentication modes.
bool supportsRawEnc
If the vnc client supports receiving raw data.
virtual const std::string name() const
static bool allDisabled()
void setPixelFormat()
Receive pixel foramt message from client and process it.
unsigned offset
Offset in bits.
Channel ch_r
Red channel conversion helper.
void recvCutText()
Receive message from client that there is text in it's paste buffer.
void remove(PollEvent *event)
Overload hash function for BasicBlockRange type.
const char * vncVersion() const
void frameBufferResized() override
ListenEvent * listenEvent
void ccprintf(cp::Print &print)
ListenEvent(VncServer *vs, int fd, int e)
Poll event for the listen socket.
PixelFormat pixelFormat
The one and only pixel format we support.
ssize_t atomic_write(int fd, const void *s, size_t n)
unsigned width() const
Frame buffer width in pixels.
unsigned height() const
Frame buffer height in pixels.
Bitfield< 27, 25 > encoding
bool read(uint8_t *buf, size_t len)
Read some data from the client.
#define panic(...)
This implements a cprintf based panic() function.
uint32_t fromPixel(const Pixel &pixel) const
Convert a Pixel into a color word.
Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17