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");
183 panic(
"%s: cannot accept a connection if not listening!",
name());
187 warn(
"%s: failed to accept VNC connection!",
name());
192 char message[] =
"vnc server already attached!\n";
207 inform(
"VNC client attached\n");
215 DPRINTF(VNC,
"Vnc client message recieved\n");
235 uint8_t message_type;
236 if (!
read(&message_type))
239 switch (message_type) {
259 warn(
"Unimplemented message type recv from client: %d\n",
266 panic(
"Unknown vnc server state\n");
276 panic(
"vnc not properly attached.\n");
281 }
while (ret == -1 && errno == EINTR);
285 DPRINTF(VNC,
"Read failed %d.\n", ret);
304 return read((uint8_t *)
val,
sizeof(T));
312 panic(
"Vnc client not properly attached.\n");
317 DPRINTF(VNC,
"Write failed.\n");
329 return write((uint8_t *)
val,
sizeof(T));
335 return write((uint8_t *)str, strlen(str));
355 inform(
"VNC client detached\n");
362 uint32_t
len = strlen(error_msg);
373 [[maybe_unused]]
size_t len;
374 char version_string[13];
377 version_string[12] = 0;
379 if (!
read((uint8_t *)version_string,
sizeof(version_string) - 1)) {
380 warn(
"Failed to read protocol version.");
384 uint32_t major_version, minor_version;
387 if (sscanf(version_string,
"RFB %03d.%03d\n", &major_version,
388 &minor_version) != 2) {
389 warn(
" Malformed protocol version %s\n", version_string);
390 sendError(
"Malformed protocol version\n");
395 DPRINTF(VNC,
"Client request protocol version %d.%d\n", major_version,
399 if (major_version != 3 || minor_version < 2) {
400 warn(
"Unsupported VNC client version... disconnecting\n");
407 if (minor_version < 7) {
409 if (!
write(&sec_type))
427 uint8_t security_type;
428 if (!
read(&security_type))
432 warn(
"Unknown VNC security type\n");
436 DPRINTF(VNC,
"Sending security auth OK\n");
439 if (!
write(&success))
449 DPRINTF(VNC,
"Sending server init message to client\n");
467 std::memcpy(msg.
name,
"M5", 2);
477 DPRINTF(VNC,
"Received pixel format from client message\n");
483 DPRINTF(VNC,
" -- bpp = %d; depth = %d; be = %d\n", pfm.px.bpp,
484 pfm.px.depth, pfm.px.bigendian);
485 DPRINTF(VNC,
" -- true color = %d red,green,blue max = %d,%d,%d\n",
486 pfm.px.truecolor,
betoh(pfm.px.redmax),
betoh(pfm.px.greenmax),
487 betoh(pfm.px.bluemax));
488 DPRINTF(VNC,
" -- red,green,blue shift = %d,%d,%d\n", pfm.px.redshift,
489 pfm.px.greenshift, pfm.px.blueshift);
501 warn(
"VNC client doesn't support true color raw encoding\n");
509 DPRINTF(VNC,
"Received supported encodings from client\n");
517 DPRINTF(VNC,
" -- %d encoding present\n", pem.num_encodings);
520 for (
int x = 0;
x < pem.num_encodings;
x++) {
537 warn(
"VNC clients must always support raw encoding\n");
545 DPRINTF(VNC,
"Received frame buffer update request from client\n");
552 fbr.y =
betoh(fbr.y);
553 fbr.width =
betoh(fbr.width);
554 fbr.height =
betoh(fbr.height);
556 DPRINTF(VNC,
" -- x = %d y = %d w = %d h = %d\n", fbr.x, fbr.y, fbr.width,
565 DPRINTF(VNC,
"Received keyboard input from client\n");
571 DPRINTF(VNC,
" -- received key code %d (%s)\n", kem.key, kem.down_flag ?
581 DPRINTF(VNC,
"Received pointer input from client\n");
588 pem.y =
betoh(pem.y);
589 DPRINTF(VNC,
" -- pointer at x = %d y = %d buttons = %#x\n", pem.x, pem.y,
599 DPRINTF(VNC,
"Received client copy buffer message\n");
606 size_t data_len =
betoh(cct.length);
607 DPRINTF(VNC,
"String length %d\n", data_len);
608 while (data_len > 0) {
609 size_t bytes_to_read = data_len > 1024 ? 1024 : data_len;
610 if (!
read((uint8_t *)&str, bytes_to_read))
612 str[bytes_to_read] = 0;
613 data_len -= bytes_to_read;
614 DPRINTF(VNC,
"Buffer: %s\n", str);
625 DPRINTF(VNC,
"NOT sending framebuffer update\n");
632 DPRINTF(VNC,
"Sending framebuffer update\n");
660 for (
int y = 0; y <
fb->
height(); ++y) {
662 uint8_t *raw_pixel(line_buffer.data());
668 if (!
write(line_buffer.data(), line_buffer.size()))
677 DPRINTF(VNC,
"Sending framebuffer resize\n");
ListenEvent(VncServer *vs, int fd, int e)
Poll event for the listen socket.
ConnectionState curState
The rfb prototol state the connection is in.
unsigned offset
Offset in bits.
const static uint32_t AuthNone
Channel ch_b
Blue channel conversion helper.
@ WaitForSecurityResponse
EventQueue * eventQueue() const
void sendFrameBufferUpdate()
Send a updated frame buffer to the client.
void setPixelFormat()
Receive pixel foramt message from client and process it.
virtual void keyPress(uint32_t key, bool down)=0
Called when the vnc server receives a key press event from the client.
void sendFrameBufferResized()
Tell the client that the frame buffer resized.
unsigned mask
Bit mask (after shifting)
uint32_t fromPixel(const Pixel &pixel) const
Convert a Pixel into a color word.
unsigned width() const
Frame buffer width in pixels.
void setEncodings()
Receive encodings message from client and process it.
Bitfield< 27, 25 > encoding
ListenEvent * listenEvent
void remove(PollEvent *event)
const char * vncVersion() const
unsigned height() const
Frame buffer height in pixels.
void recvCutText()
Receive message from client that there is text in it's paste buffer.
bool supportsRawEnc
If the vnc client supports receiving raw data.
unsigned length
Bytes per pixel when stored in memory (including padding)
const static uint32_t VncOK
Error conditions.
void recvKeyboardInput()
Receive message from client providing new keyboard input.
@ ServerFrameBufferUpdate
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 std::string name() const
ByteOrder byte_order
Byte order when stored to memory.
void recvPointerInput()
Recv message from client providing new mouse movement or button click.
DataEvent(VncServer *vs, int fd, int e)
Poll event for the data socket.
const Pixel & pixel(unsigned x, unsigned y) const
Get a pixel from an (x, y) coordinate.
bool sendUpdate
An update needs to be sent to the client.
void schedule(PollEvent *event)
static bool allDisabled()
ssize_t atomic_write(int fd, const void *s, size_t n)
const static uint32_t AuthInvalid
Authentication modes.
void checkProtocolVersion()
Check the client's protocol verion for compatibility and send the security types we support.
void requestFbUpdate()
Receive message from client asking for updated frame buffer.
void setDirty() override
The frame buffer uses this call to notify the vnc server that the frame buffer has been updated and a...
bool write(const uint8_t *buf, size_t len)
Write a buffer to the client.
Channel ch_r
Red channel conversion helper.
bool read(uint8_t *buf, size_t len)
Read some data from the client.
void sendServerInit()
Send client our idea about what the frame buffer looks like.
unsigned depth
Number of bits used to represent one pixel value (excluding padding).
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.
void sendError(const char *error_msg)
vnc client Interface
void frameBufferResized() override
bool supportsResizeEnc
If the vnc client supports the desktop resize command.
VncServer(const Params &p)
VncServer.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
static const PixelConverter pixelConverter
Channel ch_g
Green channel conversion helper.
PixelFormat pixelFormat
The one and only pixel format we support.
#define panic(...)
This implements a cprintf based panic() function.
void checkSecurity()
Check that the security exchange was successful.
Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17