vnc-ws.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * QEMU VNC display driver: Websockets support
  3. *
  4. * Copyright (C) 2010 Joel Martin
  5. * Copyright (C) 2012 Tim Hardeck
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this software; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __QEMU_UI_VNC_WS_H
  21. #define __QEMU_UI_VNC_WS_H
  22. #include <gnutls/gnutls.h>
  23. #define B64LEN(__x) (((__x + 2) / 3) * 12 / 3)
  24. #define SHA1_DIGEST_LEN 20
  25. #define WS_ACCEPT_LEN (B64LEN(SHA1_DIGEST_LEN) + 1)
  26. #define WS_CLIENT_KEY_LEN 24
  27. #define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
  28. #define WS_GUID_LEN strlen(WS_GUID)
  29. #define WS_HANDSHAKE "HTTP/1.1 101 Switching Protocols\r\n\
  30. Upgrade: websocket\r\n\
  31. Connection: Upgrade\r\n\
  32. Sec-WebSocket-Accept: %s\r\n\
  33. Sec-WebSocket-Protocol: binary\r\n\
  34. \r\n"
  35. #define WS_HANDSHAKE_DELIM "\r\n"
  36. #define WS_HANDSHAKE_END "\r\n\r\n"
  37. #define WS_SUPPORTED_VERSION "13"
  38. #define WS_HEAD_MIN_LEN sizeof(uint16_t)
  39. #define WS_HEAD_MAX_LEN (WS_HEAD_MIN_LEN + sizeof(uint64_t) + sizeof(uint32_t))
  40. typedef union WsMask {
  41. char c[4];
  42. uint32_t u;
  43. } WsMask;
  44. typedef struct QEMU_PACKED WsHeader {
  45. unsigned char b0;
  46. unsigned char b1;
  47. union {
  48. struct QEMU_PACKED {
  49. uint16_t l16;
  50. WsMask m16;
  51. } s16;
  52. struct QEMU_PACKED {
  53. uint64_t l64;
  54. WsMask m64;
  55. } s64;
  56. WsMask m;
  57. } u;
  58. } WsHeader;
  59. enum {
  60. WS_OPCODE_CONTINUATION = 0x0,
  61. WS_OPCODE_TEXT_FRAME = 0x1,
  62. WS_OPCODE_BINARY_FRAME = 0x2,
  63. WS_OPCODE_CLOSE = 0x8,
  64. WS_OPCODE_PING = 0x9,
  65. WS_OPCODE_PONG = 0xA
  66. };
  67. #ifdef CONFIG_VNC_TLS
  68. void vncws_tls_handshake_peek(void *opaque);
  69. #endif /* CONFIG_VNC_TLS */
  70. void vncws_handshake_read(void *opaque);
  71. long vnc_client_write_ws(VncState *vs);
  72. long vnc_client_read_ws(VncState *vs);
  73. void vncws_process_handshake(VncState *vs, uint8_t *line, size_t size);
  74. void vncws_encode_frame(Buffer *output, const void *payload,
  75. const size_t payload_size);
  76. int vncws_decode_frame(Buffer *input, uint8_t **payload,
  77. size_t *payload_size, size_t *frame_size);
  78. #endif /* __QEMU_UI_VNC_WS_H */