gem5  v20.1.0.0
vncserver.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2015 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
42 #ifndef __BASE_VNC_VNC_SERVER_HH__
43 #define __BASE_VNC_VNC_SERVER_HH__
44 
45 #include <iostream>
46 
47 #include "base/vnc/vncinput.hh"
48 #include "base/circlebuf.hh"
49 #include "base/pollevent.hh"
50 #include "base/socket.hh"
51 #include "params/VncServer.hh"
52 #include "sim/sim_object.hh"
53 
58 class VncServer : public VncInput
59 {
60  public:
61 
67  const static uint32_t AuthInvalid = 0;
68  const static uint32_t AuthNone = 1;
69 
71  const static uint32_t VncOK = 0;
72 
79  };
80 
87  };
88 
90  enum MouseEvents {
94  };
95 
96  const char* vncVersion() const
97  {
98  return "RFB 003.008\n";
99  }
100 
107  };
108 
109  struct ServerInitMsg {
110  uint16_t fbWidth;
111  uint16_t fbHeight;
113  uint32_t namelen;
114  char name[2]; // just to put M5 in here
115  } M5_ATTR_PACKED;
116 
118  uint8_t type;
119  uint8_t padding;
120  uint16_t num_rects;
121  } M5_ATTR_PACKED;
122 
124  uint16_t x;
125  uint16_t y;
126  uint16_t width;
127  uint16_t height;
128  int32_t encoding;
129  } M5_ATTR_PACKED;
130 
131  struct ServerCutText {
132  uint8_t type;
133  uint8_t padding[3];
134  uint32_t length;
135  } M5_ATTR_PACKED;
136 
139  protected:
141  class ListenEvent: public PollEvent
142  {
143  protected:
145 
146  public:
147  ListenEvent(VncServer *vs, int fd, int e);
148  void process(int revent);
149  };
150 
151  friend class ListenEvent;
153 
155  class DataEvent: public PollEvent
156  {
157  protected:
159 
160  public:
161  DataEvent(VncServer *vs, int fd, int e);
162  void process(int revent);
163  };
164 
165  friend class DataEvent;
167 
168  int number;
169  int dataFd; // data stream file describer
170 
172 
173  void listen(int port);
174  void accept();
175  void data();
176  void detach();
177 
178  public:
179  typedef VncServerParams Params;
180  VncServer(const Params *p);
181  ~VncServer();
182 
183  // RFB
184  protected:
185 
188 
192 
195 
198 
201 
202  protected:
210  void sendError(const char* error_msg);
211 
217  bool read(uint8_t *buf, size_t len);
218 
227  bool read1(uint8_t *buf, size_t len);
228 
229 
234  template <typename T> bool read(T* val);
235 
236 
242  bool write(const uint8_t *buf, size_t len);
243 
248  template <typename T> bool write(T* val);
249 
253  bool write(const char* str);
254 
258  void checkProtocolVersion();
259 
262  void checkSecurity();
263 
265  void sendServerInit();
266 
270  void sendError(std::string error_msg);
271 
275  void sendFrameBufferUpdate();
276 
278  void setPixelFormat();
279 
281  void setEncodings();
282 
284  void requestFbUpdate();
285 
287  void recvKeyboardInput();
288 
290  void recvPointerInput();
291 
296  void recvCutText();
297 
301  void sendFrameBufferResized();
302 
304 
305  public:
306  void setDirty() override;
307  void frameBufferResized() override;
308 };
309 
310 #endif
VncServer::ServerBell
@ ServerBell
Definition: vncserver.hh:77
VncServer::setEncodings
void setEncodings()
Receive encodings message from client and process it.
Definition: vncserver.cc:513
VncServer::ServerSetColorMapEntries
@ ServerSetColorMapEntries
Definition: vncserver.hh:76
VncServer::ServerInitMsg::name
char name[2]
Definition: vncserver.hh:114
VncServer::ServerFrameBufferUpdate
@ ServerFrameBufferUpdate
Definition: vncserver.hh:75
socket.hh
VncServer::sendError
void sendError(const char *error_msg)
vnc client Interface
Definition: vncserver.cc:368
VncServer::FrameBufferRect::x
uint16_t x
Definition: vncserver.hh:124
VncServer::write
bool write(const uint8_t *buf, size_t len)
Write a buffer to the client.
Definition: vncserver.cc:317
ListenSocket
Definition: socket.hh:32
VncServer::dataFd
int dataFd
Definition: vncserver.hh:169
VncServer::ServerInitMsg
Definition: vncserver.hh:109
VncServer::supportsResizeEnc
bool supportsResizeEnc
If the vnc client supports the desktop resize command.
Definition: vncserver.hh:200
VncServer::AuthNone
const static uint32_t AuthNone
Definition: vncserver.hh:68
PixelConverter
Configurable RGB pixel converter.
Definition: pixel.hh:87
VncServer::ServerCutText::padding
uint8_t padding[3]
Definition: vncserver.hh:133
VncServer::read1
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.
Definition: vncserver.cc:302
VncServer::~VncServer
~VncServer()
Definition: vncserver.cc:145
circlebuf.hh
VncServer::accept
void accept()
Definition: vncserver.cc:183
VncServer::ConnectionState
ConnectionState
Definition: vncserver.hh:101
VncServer::ServerInitMsg::fbHeight
uint16_t fbHeight
Definition: vncserver.hh:111
MipsISA::vs
Bitfield< 9, 5 > vs
Definition: pra_constants.hh:146
ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:159
vncinput.hh
VncServer::ServerCutText::type
uint8_t type
Definition: vncserver.hh:132
VncServer::FrameBufferUpdate::padding
uint8_t padding
Definition: vncserver.hh:119
VncInput::Params
VncInputParams Params
Definition: vncinput.hh:154
VncServer::setDirty
void setDirty() override
The frame buffer uses this call to notify the vnc server that the frame buffer has been updated and a...
Definition: vncserver.cc:713
VncServer::WaitForClientInit
@ WaitForClientInit
Definition: vncserver.hh:104
VncServer::VncOK
const static uint32_t VncOK
Error conditions.
Definition: vncserver.hh:71
VncServer::DataEvent::DataEvent
DataEvent(VncServer *vs, int fd, int e)
Poll event for the data socket.
Definition: vncserver.cc:101
VncServer::requestFbUpdate
void requestFbUpdate()
Receive message from client asking for updated frame buffer.
Definition: vncserver.cc:549
VncInput
Definition: vncinput.hh:85
VncServer::FrameBufferRect::y
uint16_t y
Definition: vncserver.hh:125
VncServer
Definition: vncserver.hh:58
VncServer::sendFrameBufferResized
void sendFrameBufferResized()
Tell the client that the frame buffer resized.
Definition: vncserver.cc:680
VncServer::dataEvent
DataEvent * dataEvent
Definition: vncserver.hh:166
VncServer::pixelConverter
static const PixelConverter pixelConverter
Definition: vncserver.hh:303
VncServer::FrameBufferRect::width
uint16_t width
Definition: vncserver.hh:126
VncServer::ListenEvent::process
void process(int revent)
Definition: vncserver.cc:93
VncServer::VncServer
VncServer(const Params *p)
VncServer.
Definition: vncserver.cc:118
VncServer::curState
ConnectionState curState
The rfb prototol state the connection is in.
Definition: vncserver.hh:187
VncServer::FrameBufferUpdate::type
uint8_t type
Definition: vncserver.hh:118
VncServer::DataEvent::vncserver
VncServer * vncserver
Definition: vncserver.hh:158
VncServer::FrameBufferRect::height
uint16_t height
Definition: vncserver.hh:127
VncServer::MouseMiddleButton
@ MouseMiddleButton
Definition: vncserver.hh:93
VncServer::sendServerInit
void sendServerInit()
Send client our idea about what the frame buffer looks like.
Definition: vncserver.cc:451
sim_object.hh
VncServer::sendUpdate
bool sendUpdate
An update needs to be sent to the client.
Definition: vncserver.hh:191
VncServer::WaitForSecurityResponse
@ WaitForSecurityResponse
Definition: vncserver.hh:103
VncServer::M5_ATTR_PACKED
struct VncServer::ServerInitMsg M5_ATTR_PACKED
VncServer::EncodingHextile
@ EncodingHextile
Definition: vncserver.hh:85
VncServer::InitializationPhase
@ InitializationPhase
Definition: vncserver.hh:105
VncServer::checkSecurity
void checkSecurity()
Check that the security exchange was successful.
Definition: vncserver.cc:429
pollevent.hh
VncServer::ServerMessages
ServerMessages
Server -> Client message IDs.
Definition: vncserver.hh:74
VncServer::ServerCutText::length
uint32_t length
Definition: vncserver.hh:134
VncServer::EncodingCopyRect
@ EncodingCopyRect
Definition: vncserver.hh:84
VncServer::recvKeyboardInput
void recvKeyboardInput()
Receive message from client providing new keyboard input.
Definition: vncserver.cc:569
VncServer::DataEvent
DataEvent to read data from vnc.
Definition: vncserver.hh:155
VncServer::sendFrameBufferUpdate
void sendFrameBufferUpdate()
Send a updated frame buffer to the client.
Definition: vncserver.cc:627
VncServer::WaitForProtocolVersion
@ WaitForProtocolVersion
Definition: vncserver.hh:102
VncServer::MouseEvents
MouseEvents
keyboard/mouse support
Definition: vncserver.hh:90
VncServer::FrameBufferUpdate
Definition: vncserver.hh:117
VncServer::checkProtocolVersion
void checkProtocolVersion()
Check the client's protocol verion for compatibility and send the security types we support.
Definition: vncserver.cc:377
VncServer::FrameBufferRect::encoding
int32_t encoding
Definition: vncserver.hh:128
VncServer::ServerCutText
Definition: vncserver.hh:131
VncServer::recvPointerInput
void recvPointerInput()
Recv message from client providing new mouse movement or button click.
Definition: vncserver.cc:585
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
VncServer::ListenEvent::vncserver
VncServer * vncserver
Definition: vncserver.hh:144
VncServer::EncodingTypes
EncodingTypes
Encoding types.
Definition: vncserver.hh:82
VncServer::AuthInvalid
const static uint32_t AuthInvalid
Authentication modes.
Definition: vncserver.hh:67
VncServer::FrameBufferUpdate::num_rects
uint16_t num_rects
Definition: vncserver.hh:120
VncServer::supportsRawEnc
bool supportsRawEnc
If the vnc client supports receiving raw data.
Definition: vncserver.hh:197
VncServer::EncodingDesktopSize
@ EncodingDesktopSize
Definition: vncserver.hh:86
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
VncServer::ServerInitMsg::px
PixelFormat px
Definition: vncserver.hh:112
VncServer::number
int number
Definition: vncserver.hh:168
VncServer::setPixelFormat
void setPixelFormat()
Receive pixel foramt message from client and process it.
Definition: vncserver.cc:481
VncServer::DataEvent::process
void process(int revent)
Definition: vncserver.cc:107
VncServer::FrameBufferRect
Definition: vncserver.hh:123
VncServer::recvCutText
void recvCutText()
Receive message from client that there is text in it's paste buffer.
Definition: vncserver.cc:603
VncServer::MouseRightButton
@ MouseRightButton
Definition: vncserver.hh:92
VncServer::ListenEvent
ListenEvent to accept a vnc client connection.
Definition: vncserver.hh:141
VncServer::ServerInitMsg::fbWidth
uint16_t fbWidth
Definition: vncserver.hh:110
VncServer::Params
VncServerParams Params
Definition: vncserver.hh:179
VncServer::vncVersion
const char * vncVersion() const
Definition: vncserver.hh:96
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
VncServer::frameBufferResized
void frameBufferResized() override
Definition: vncserver.cc:722
VncServer::listenEvent
ListenEvent * listenEvent
Definition: vncserver.hh:152
VncServer::ListenEvent::ListenEvent
ListenEvent(VncServer *vs, int fd, int e)
Poll event for the listen socket.
Definition: vncserver.cc:87
VncServer::ServerInitMsg::namelen
uint32_t namelen
Definition: vncserver.hh:113
VncServer::detach
void detach()
Definition: vncserver.cc:348
VncServer::pixelFormat
PixelFormat pixelFormat
The one and only pixel format we support.
Definition: vncserver.hh:194
VncServer::EncodingRaw
@ EncodingRaw
Definition: vncserver.hh:83
PollEvent
Definition: pollevent.hh:41
VncInput::PixelFormat
Definition: vncinput.hh:99
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
VncServer::MouseLeftButton
@ MouseLeftButton
Definition: vncserver.hh:91
VncServer::listener
ListenSocket listener
Definition: vncserver.hh:171
VncServer::NormalPhase
@ NormalPhase
Definition: vncserver.hh:106
VncServer::data
void data()
Definition: vncserver.cc:220
VncServer::listen
void listen(int port)
Definition: vncserver.cc:160
VncServer::read
bool read(uint8_t *buf, size_t len)
Read some data from the client.
Definition: vncserver.cc:281

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17