Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Hardening <rdp.effort@gmail.com> |
| 3 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | #include <linux/input.h> |
| 32 | |
Hardening | 04633b6 | 2014-01-10 11:33:06 +0100 | [diff] [blame] | 33 | #if HAVE_FREERDP_VERSION_H |
| 34 | #include <freerdp/version.h> |
| 35 | #else |
| 36 | /* assume it's a early 1.1 version */ |
| 37 | #define FREERDP_VERSION_MAJOR 1 |
| 38 | #define FREERDP_VERSION_MINOR 1 |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 39 | #define FREERDP_VERSION_REVISION 0 |
| 40 | #endif |
| 41 | |
| 42 | #define FREERDP_VERSION_NUMBER ((FREERDP_VERSION_MAJOR * 0x10000) + \ |
| 43 | (FREERDP_VERSION_MINOR * 0x100) + FREERDP_VERSION_REVISION) |
| 44 | |
| 45 | #if FREERDP_VERSION_NUMBER >= 0x10201 |
| 46 | #define HAVE_SKIP_COMPRESSION |
| 47 | #endif |
| 48 | |
| 49 | #if FREERDP_VERSION_NUMBER < 0x10202 |
| 50 | #define FREERDP_CB_RET_TYPE void |
| 51 | #define FREERDP_CB_RETURN(V) return |
| 52 | #else |
| 53 | #define HAVE_NSC_RESET |
| 54 | #define FREERDP_CB_RET_TYPE BOOL |
| 55 | #define FREERDP_CB_RETURN(V) return TRUE |
Hardening | 04633b6 | 2014-01-10 11:33:06 +0100 | [diff] [blame] | 56 | #endif |
| 57 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 58 | #include <freerdp/freerdp.h> |
| 59 | #include <freerdp/listener.h> |
| 60 | #include <freerdp/update.h> |
| 61 | #include <freerdp/input.h> |
| 62 | #include <freerdp/codec/color.h> |
| 63 | #include <freerdp/codec/rfx.h> |
| 64 | #include <freerdp/codec/nsc.h> |
Hardening | ea2aa13 | 2014-04-11 09:49:57 +0200 | [diff] [blame] | 65 | #include <freerdp/locale/keyboard.h> |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 66 | #include <winpr/input.h> |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 67 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame^] | 68 | #include "shared/helpers.h" |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 69 | #include "compositor.h" |
| 70 | #include "pixman-renderer.h" |
| 71 | |
| 72 | #define MAX_FREERDP_FDS 32 |
Hardening | b60e46f | 2013-06-03 22:55:47 +0200 | [diff] [blame] | 73 | #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10) |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 74 | #define RDP_MODE_FREQ 60 * 1000 |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 75 | |
| 76 | struct rdp_compositor_config { |
| 77 | int width; |
| 78 | int height; |
| 79 | char *bind_address; |
| 80 | int port; |
| 81 | char *rdp_key; |
| 82 | char *server_cert; |
| 83 | char *server_key; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 84 | int env_socket; |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 85 | int no_clients_resize; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct rdp_output; |
| 89 | |
| 90 | struct rdp_compositor { |
| 91 | struct weston_compositor base; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 92 | |
| 93 | freerdp_listener *listener; |
| 94 | struct wl_event_source *listener_events[MAX_FREERDP_FDS]; |
| 95 | struct rdp_output *output; |
| 96 | |
| 97 | char *server_cert; |
| 98 | char *server_key; |
| 99 | char *rdp_key; |
| 100 | int tls_enabled; |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 101 | int no_clients_resize; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | enum peer_item_flags { |
| 105 | RDP_PEER_ACTIVATED = (1 << 0), |
| 106 | RDP_PEER_OUTPUT_ENABLED = (1 << 1), |
| 107 | }; |
| 108 | |
| 109 | struct rdp_peers_item { |
| 110 | int flags; |
| 111 | freerdp_peer *peer; |
| 112 | struct weston_seat seat; |
| 113 | |
| 114 | struct wl_list link; |
| 115 | }; |
| 116 | |
| 117 | struct rdp_output { |
| 118 | struct weston_output base; |
| 119 | struct wl_event_source *finish_frame_timer; |
| 120 | pixman_image_t *shadow_surface; |
| 121 | |
| 122 | struct wl_list peers; |
| 123 | }; |
| 124 | |
| 125 | struct rdp_peer_context { |
| 126 | rdpContext _p; |
Hardening | b8f03aa | 2013-05-26 23:34:00 +0200 | [diff] [blame] | 127 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 128 | struct rdp_compositor *rdpCompositor; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 129 | struct wl_event_source *events[MAX_FREERDP_FDS]; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 130 | RFX_CONTEXT *rfx_context; |
| 131 | wStream *encode_stream; |
| 132 | RFX_RECT *rfx_rects; |
| 133 | NSC_CONTEXT *nsc_context; |
| 134 | |
| 135 | struct rdp_peers_item item; |
| 136 | }; |
| 137 | typedef struct rdp_peer_context RdpPeerContext; |
| 138 | |
| 139 | static void |
| 140 | rdp_compositor_config_init(struct rdp_compositor_config *config) { |
| 141 | config->width = 640; |
| 142 | config->height = 480; |
| 143 | config->bind_address = NULL; |
| 144 | config->port = 3389; |
| 145 | config->rdp_key = NULL; |
| 146 | config->server_cert = NULL; |
| 147 | config->server_key = NULL; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 148 | config->env_socket = 0; |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 149 | config->no_clients_resize = 0; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static void |
| 153 | rdp_peer_refresh_rfx(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer) |
| 154 | { |
| 155 | int width, height, nrects, i; |
| 156 | pixman_box32_t *region, *rects; |
| 157 | uint32_t *ptr; |
| 158 | RFX_RECT *rfxRect; |
| 159 | rdpUpdate *update = peer->update; |
| 160 | SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command; |
| 161 | RdpPeerContext *context = (RdpPeerContext *)peer->context; |
| 162 | |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 163 | Stream_Clear(context->encode_stream); |
| 164 | Stream_SetPosition(context->encode_stream, 0); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 165 | |
| 166 | width = (damage->extents.x2 - damage->extents.x1); |
| 167 | height = (damage->extents.y2 - damage->extents.y1); |
| 168 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 169 | #ifdef HAVE_SKIP_COMPRESSION |
| 170 | cmd->skipCompression = TRUE; |
| 171 | #else |
| 172 | memset(cmd, 0, sizeof(*cmd)); |
| 173 | #endif |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 174 | cmd->destLeft = damage->extents.x1; |
| 175 | cmd->destTop = damage->extents.y1; |
| 176 | cmd->destRight = damage->extents.x2; |
| 177 | cmd->destBottom = damage->extents.y2; |
| 178 | cmd->bpp = 32; |
| 179 | cmd->codecID = peer->settings->RemoteFxCodecId; |
| 180 | cmd->width = width; |
| 181 | cmd->height = height; |
| 182 | |
| 183 | ptr = pixman_image_get_data(image) + damage->extents.x1 + |
| 184 | damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t)); |
| 185 | |
| 186 | rects = pixman_region32_rectangles(damage, &nrects); |
| 187 | context->rfx_rects = realloc(context->rfx_rects, nrects * sizeof *rfxRect); |
| 188 | |
| 189 | for (i = 0; i < nrects; i++) { |
| 190 | region = &rects[i]; |
| 191 | rfxRect = &context->rfx_rects[i]; |
| 192 | |
| 193 | rfxRect->x = (region->x1 - damage->extents.x1); |
| 194 | rfxRect->y = (region->y1 - damage->extents.y1); |
| 195 | rfxRect->width = (region->x2 - region->x1); |
| 196 | rfxRect->height = (region->y2 - region->y1); |
| 197 | } |
| 198 | |
| 199 | rfx_compose_message(context->rfx_context, context->encode_stream, context->rfx_rects, nrects, |
| 200 | (BYTE *)ptr, width, height, |
| 201 | pixman_image_get_stride(image) |
| 202 | ); |
| 203 | |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 204 | cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream); |
| 205 | cmd->bitmapData = Stream_Buffer(context->encode_stream); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 206 | |
| 207 | update->SurfaceBits(update->context, cmd); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | static void |
| 212 | rdp_peer_refresh_nsc(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer) |
| 213 | { |
| 214 | int width, height; |
| 215 | uint32_t *ptr; |
| 216 | rdpUpdate *update = peer->update; |
| 217 | SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command; |
| 218 | RdpPeerContext *context = (RdpPeerContext *)peer->context; |
| 219 | |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 220 | Stream_Clear(context->encode_stream); |
| 221 | Stream_SetPosition(context->encode_stream, 0); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 222 | |
| 223 | width = (damage->extents.x2 - damage->extents.x1); |
| 224 | height = (damage->extents.y2 - damage->extents.y1); |
| 225 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 226 | #ifdef HAVE_SKIP_COMPRESSION |
| 227 | cmd->skipCompression = TRUE; |
| 228 | #else |
| 229 | memset(cmd, 0, sizeof(*cmd)); |
| 230 | #endif |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 231 | cmd->destLeft = damage->extents.x1; |
| 232 | cmd->destTop = damage->extents.y1; |
| 233 | cmd->destRight = damage->extents.x2; |
| 234 | cmd->destBottom = damage->extents.y2; |
| 235 | cmd->bpp = 32; |
| 236 | cmd->codecID = peer->settings->NSCodecId; |
| 237 | cmd->width = width; |
| 238 | cmd->height = height; |
| 239 | |
| 240 | ptr = pixman_image_get_data(image) + damage->extents.x1 + |
| 241 | damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t)); |
| 242 | |
| 243 | nsc_compose_message(context->nsc_context, context->encode_stream, (BYTE *)ptr, |
| 244 | cmd->width, cmd->height, |
| 245 | pixman_image_get_stride(image)); |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 246 | cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream); |
| 247 | cmd->bitmapData = Stream_Buffer(context->encode_stream); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 248 | update->SurfaceBits(update->context, cmd); |
| 249 | } |
| 250 | |
| 251 | static void |
Hardening | fe36a13 | 2013-05-22 23:40:20 +0200 | [diff] [blame] | 252 | pixman_image_flipped_subrect(const pixman_box32_t *rect, pixman_image_t *img, BYTE *dest) { |
| 253 | int stride = pixman_image_get_stride(img); |
| 254 | int h; |
| 255 | int toCopy = (rect->x2 - rect->x1) * 4; |
| 256 | int height = (rect->y2 - rect->y1); |
| 257 | const BYTE *src = (const BYTE *)pixman_image_get_data(img); |
| 258 | src += ((rect->y2-1) * stride) + (rect->x1 * 4); |
| 259 | |
| 260 | for (h = 0; h < height; h++, src -= stride, dest += toCopy) |
| 261 | memcpy(dest, src, toCopy); |
| 262 | } |
| 263 | |
| 264 | static void |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 265 | rdp_peer_refresh_raw(pixman_region32_t *region, pixman_image_t *image, freerdp_peer *peer) |
| 266 | { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 267 | rdpUpdate *update = peer->update; |
| 268 | SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command; |
Hardening | fe36a13 | 2013-05-22 23:40:20 +0200 | [diff] [blame] | 269 | SURFACE_FRAME_MARKER *marker = &update->surface_frame_marker; |
| 270 | pixman_box32_t *rect, subrect; |
| 271 | int nrects, i; |
| 272 | int heightIncrement, remainingHeight, top; |
| 273 | |
| 274 | rect = pixman_region32_rectangles(region, &nrects); |
| 275 | if (!nrects) |
| 276 | return; |
| 277 | |
| 278 | marker->frameId++; |
| 279 | marker->frameAction = SURFACECMD_FRAMEACTION_BEGIN; |
| 280 | update->SurfaceFrameMarker(peer->context, marker); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 281 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 282 | memset(cmd, 0, sizeof(*cmd)); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 283 | cmd->bpp = 32; |
| 284 | cmd->codecID = 0; |
Hardening | fe36a13 | 2013-05-22 23:40:20 +0200 | [diff] [blame] | 285 | |
| 286 | for (i = 0; i < nrects; i++, rect++) { |
| 287 | /*weston_log("rect(%d,%d, %d,%d)\n", rect->x1, rect->y1, rect->x2, rect->y2);*/ |
| 288 | cmd->destLeft = rect->x1; |
| 289 | cmd->destRight = rect->x2; |
| 290 | cmd->width = rect->x2 - rect->x1; |
| 291 | |
| 292 | heightIncrement = peer->settings->MultifragMaxRequestSize / (16 + cmd->width * 4); |
| 293 | remainingHeight = rect->y2 - rect->y1; |
| 294 | top = rect->y1; |
| 295 | |
| 296 | subrect.x1 = rect->x1; |
| 297 | subrect.x2 = rect->x2; |
| 298 | |
| 299 | while (remainingHeight) { |
| 300 | cmd->height = (remainingHeight > heightIncrement) ? heightIncrement : remainingHeight; |
| 301 | cmd->destTop = top; |
| 302 | cmd->destBottom = top + cmd->height; |
| 303 | cmd->bitmapDataLength = cmd->width * cmd->height * 4; |
| 304 | cmd->bitmapData = (BYTE *)realloc(cmd->bitmapData, cmd->bitmapDataLength); |
| 305 | |
| 306 | subrect.y1 = top; |
| 307 | subrect.y2 = top + cmd->height; |
| 308 | pixman_image_flipped_subrect(&subrect, image, cmd->bitmapData); |
| 309 | |
| 310 | /*weston_log("* sending (%d,%d, %d,%d)\n", subrect.x1, subrect.y1, subrect.x2, subrect.y2); */ |
| 311 | update->SurfaceBits(peer->context, cmd); |
| 312 | |
| 313 | remainingHeight -= cmd->height; |
| 314 | top += cmd->height; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | marker->frameAction = SURFACECMD_FRAMEACTION_END; |
| 319 | update->SurfaceFrameMarker(peer->context, marker); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static void |
| 323 | rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer) |
| 324 | { |
| 325 | RdpPeerContext *context = (RdpPeerContext *)peer->context; |
| 326 | struct rdp_output *output = context->rdpCompositor->output; |
| 327 | rdpSettings *settings = peer->settings; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 328 | |
Hardening | fe36a13 | 2013-05-22 23:40:20 +0200 | [diff] [blame] | 329 | if (settings->RemoteFxCodec) |
| 330 | rdp_peer_refresh_rfx(region, output->shadow_surface, peer); |
| 331 | else if (settings->NSCodec) |
| 332 | rdp_peer_refresh_nsc(region, output->shadow_surface, peer); |
| 333 | else |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 334 | rdp_peer_refresh_raw(region, output->shadow_surface, peer); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 337 | static void |
| 338 | rdp_output_start_repaint_loop(struct weston_output *output) |
| 339 | { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 340 | struct timespec ts; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 341 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 342 | weston_compositor_read_presentation_clock(output->compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 343 | weston_output_finish_frame(output, &ts, PRESENTATION_FEEDBACK_INVALID); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 344 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 345 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 346 | static int |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 347 | rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage) |
| 348 | { |
| 349 | struct rdp_output *output = container_of(output_base, struct rdp_output, base); |
| 350 | struct weston_compositor *ec = output->base.compositor; |
| 351 | struct rdp_peers_item *outputPeer; |
| 352 | |
| 353 | pixman_renderer_output_set_buffer(output_base, output->shadow_surface); |
| 354 | ec->renderer->repaint_output(&output->base, damage); |
| 355 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 356 | if (pixman_region32_not_empty(damage)) { |
| 357 | wl_list_for_each(outputPeer, &output->peers, link) { |
| 358 | if ((outputPeer->flags & RDP_PEER_ACTIVATED) && |
| 359 | (outputPeer->flags & RDP_PEER_OUTPUT_ENABLED)) |
| 360 | { |
| 361 | rdp_peer_refresh_region(damage, outputPeer->peer); |
| 362 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 367 | &ec->primary_plane.damage, damage); |
| 368 | |
| 369 | wl_event_source_timer_update(output->finish_frame_timer, 16); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 370 | return 0; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void |
| 374 | rdp_output_destroy(struct weston_output *output_base) |
| 375 | { |
| 376 | struct rdp_output *output = (struct rdp_output *)output_base; |
| 377 | |
| 378 | wl_event_source_remove(output->finish_frame_timer); |
| 379 | free(output); |
| 380 | } |
| 381 | |
| 382 | static int |
| 383 | finish_frame_handler(void *data) |
| 384 | { |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 385 | struct rdp_output *output = data; |
| 386 | struct timespec ts; |
| 387 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 388 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 389 | weston_output_finish_frame(&output->base, &ts, 0); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 390 | |
| 391 | return 1; |
| 392 | } |
| 393 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 394 | static struct weston_mode * |
| 395 | rdp_insert_new_mode(struct weston_output *output, int width, int height, int rate) { |
| 396 | struct weston_mode *ret; |
| 397 | ret = zalloc(sizeof *ret); |
| 398 | if (!ret) |
| 399 | return NULL; |
| 400 | ret->width = width; |
| 401 | ret->height = height; |
| 402 | ret->refresh = rate; |
| 403 | wl_list_insert(&output->mode_list, &ret->link); |
| 404 | return ret; |
| 405 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 406 | |
| 407 | static struct weston_mode * |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 408 | ensure_matching_mode(struct weston_output *output, struct weston_mode *target) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 409 | struct weston_mode *local; |
| 410 | |
| 411 | wl_list_for_each(local, &output->mode_list, link) { |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 412 | if ((local->width == target->width) && (local->height == target->height)) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 413 | return local; |
| 414 | } |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 415 | |
| 416 | return rdp_insert_new_mode(output, target->width, target->height, RDP_MODE_FREQ); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static int |
| 420 | rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) { |
| 421 | struct rdp_output *rdpOutput = container_of(output, struct rdp_output, base); |
| 422 | struct rdp_peers_item *rdpPeer; |
| 423 | rdpSettings *settings; |
| 424 | pixman_image_t *new_shadow_buffer; |
| 425 | struct weston_mode *local_mode; |
| 426 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 427 | local_mode = ensure_matching_mode(output, target_mode); |
| 428 | if (!local_mode) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 429 | weston_log("mode %dx%d not available\n", target_mode->width, target_mode->height); |
| 430 | return -ENOENT; |
| 431 | } |
| 432 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 433 | if (local_mode == output->current_mode) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 434 | return 0; |
| 435 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 436 | output->current_mode->flags &= ~WL_OUTPUT_MODE_CURRENT; |
| 437 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 438 | output->current_mode = local_mode; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 439 | output->current_mode->flags |= WL_OUTPUT_MODE_CURRENT; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 440 | |
| 441 | pixman_renderer_output_destroy(output); |
| 442 | pixman_renderer_output_create(output); |
| 443 | |
| 444 | new_shadow_buffer = pixman_image_create_bits(PIXMAN_x8r8g8b8, target_mode->width, |
| 445 | target_mode->height, 0, target_mode->width * 4); |
| 446 | pixman_image_composite32(PIXMAN_OP_SRC, rdpOutput->shadow_surface, 0, new_shadow_buffer, |
| 447 | 0, 0, 0, 0, 0, 0, target_mode->width, target_mode->height); |
| 448 | pixman_image_unref(rdpOutput->shadow_surface); |
| 449 | rdpOutput->shadow_surface = new_shadow_buffer; |
| 450 | |
| 451 | wl_list_for_each(rdpPeer, &rdpOutput->peers, link) { |
| 452 | settings = rdpPeer->peer->settings; |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 453 | if (settings->DesktopWidth == (UINT32)target_mode->width && |
| 454 | settings->DesktopHeight == (UINT32)target_mode->height) |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 455 | continue; |
| 456 | |
| 457 | if (!settings->DesktopResize) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 458 | /* too bad this peer does not support desktop resize */ |
| 459 | rdpPeer->peer->Close(rdpPeer->peer); |
| 460 | } else { |
| 461 | settings->DesktopWidth = target_mode->width; |
| 462 | settings->DesktopHeight = target_mode->height; |
| 463 | rdpPeer->peer->update->DesktopResize(rdpPeer->peer->context); |
| 464 | } |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 470 | rdp_compositor_create_output(struct rdp_compositor *c, int width, int height) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 471 | { |
| 472 | struct rdp_output *output; |
| 473 | struct wl_event_loop *loop; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 474 | struct weston_mode *currentMode; |
| 475 | struct weston_mode initMode; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 476 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 477 | output = zalloc(sizeof *output); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 478 | if (output == NULL) |
| 479 | return -1; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 480 | |
| 481 | wl_list_init(&output->peers); |
| 482 | wl_list_init(&output->base.mode_list); |
| 483 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 484 | initMode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 485 | initMode.width = width; |
| 486 | initMode.height = height; |
| 487 | initMode.refresh = RDP_MODE_FREQ; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 488 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 489 | currentMode = ensure_matching_mode(&output->base, &initMode); |
| 490 | if (!currentMode) |
| 491 | goto out_free_output; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 492 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 493 | output->base.current_mode = output->base.native_mode = currentMode; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 494 | weston_output_init(&output->base, &c->base, 0, 0, width, height, |
Kristian Høgsberg | 785e1f3 | 2013-05-22 21:53:09 -0400 | [diff] [blame] | 495 | WL_OUTPUT_TRANSFORM_NORMAL, 1); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 496 | |
| 497 | output->base.make = "weston"; |
| 498 | output->base.model = "rdp"; |
| 499 | output->shadow_surface = pixman_image_create_bits(PIXMAN_x8r8g8b8, |
| 500 | width, height, |
| 501 | NULL, |
| 502 | width * 4); |
| 503 | if (output->shadow_surface == NULL) { |
| 504 | weston_log("Failed to create surface for frame buffer.\n"); |
| 505 | goto out_output; |
| 506 | } |
| 507 | |
| 508 | if (pixman_renderer_output_create(&output->base) < 0) |
| 509 | goto out_shadow_surface; |
| 510 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 511 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 512 | output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 513 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 514 | output->base.start_repaint_loop = rdp_output_start_repaint_loop; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 515 | output->base.repaint = rdp_output_repaint; |
| 516 | output->base.destroy = rdp_output_destroy; |
| 517 | output->base.assign_planes = NULL; |
| 518 | output->base.set_backlight = NULL; |
| 519 | output->base.set_dpms = NULL; |
| 520 | output->base.switch_mode = rdp_switch_mode; |
| 521 | c->output = output; |
| 522 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 523 | weston_compositor_add_output(&c->base, &output->base); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 524 | return 0; |
| 525 | |
| 526 | out_shadow_surface: |
| 527 | pixman_image_unref(output->shadow_surface); |
| 528 | out_output: |
| 529 | weston_output_destroy(&output->base); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 530 | out_free_output: |
| 531 | free(output); |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | static void |
| 536 | rdp_restore(struct weston_compositor *ec) |
| 537 | { |
| 538 | } |
| 539 | |
| 540 | static void |
| 541 | rdp_destroy(struct weston_compositor *ec) |
| 542 | { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 543 | weston_compositor_shutdown(ec); |
| 544 | |
| 545 | free(ec); |
| 546 | } |
| 547 | |
| 548 | static |
| 549 | int rdp_listener_activity(int fd, uint32_t mask, void *data) { |
| 550 | freerdp_listener* instance = (freerdp_listener *)data; |
| 551 | |
| 552 | if (!(mask & WL_EVENT_READABLE)) |
| 553 | return 0; |
| 554 | if (!instance->CheckFileDescriptor(instance)) |
| 555 | { |
| 556 | weston_log("failed to check FreeRDP file descriptor\n"); |
| 557 | return -1; |
| 558 | } |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static |
| 563 | int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) { |
| 564 | int i, fd; |
| 565 | int rcount = 0; |
| 566 | void* rfds[MAX_FREERDP_FDS]; |
| 567 | struct wl_event_loop *loop; |
| 568 | |
| 569 | if (!instance->GetFileDescriptor(instance, rfds, &rcount)) { |
| 570 | weston_log("Failed to get FreeRDP file descriptor\n"); |
| 571 | return -1; |
| 572 | } |
| 573 | |
| 574 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 575 | for (i = 0; i < rcount; i++) { |
| 576 | fd = (int)(long)(rfds[i]); |
| 577 | c->listener_events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 578 | rdp_listener_activity, instance); |
| 579 | } |
| 580 | |
| 581 | for( ; i < MAX_FREERDP_FDS; i++) |
| 582 | c->listener_events[i] = 0; |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | static void |
| 588 | rdp_peer_context_new(freerdp_peer* client, RdpPeerContext* context) |
| 589 | { |
| 590 | context->item.peer = client; |
Hardening | 58bcc36 | 2013-08-17 00:30:31 +0200 | [diff] [blame] | 591 | context->item.flags = RDP_PEER_OUTPUT_ENABLED; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 592 | |
Hardening | 04633b6 | 2014-01-10 11:33:06 +0100 | [diff] [blame] | 593 | #if FREERDP_VERSION_MAJOR == 1 && FREERDP_VERSION_MINOR == 1 |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 594 | context->rfx_context = rfx_context_new(); |
Hardening | 04633b6 | 2014-01-10 11:33:06 +0100 | [diff] [blame] | 595 | #else |
| 596 | context->rfx_context = rfx_context_new(TRUE); |
| 597 | #endif |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 598 | context->rfx_context->mode = RLGR3; |
| 599 | context->rfx_context->width = client->settings->DesktopWidth; |
| 600 | context->rfx_context->height = client->settings->DesktopHeight; |
| 601 | rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); |
| 602 | |
| 603 | context->nsc_context = nsc_context_new(); |
Hardening | 827358e | 2013-05-22 23:40:18 +0200 | [diff] [blame] | 604 | nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 605 | |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 606 | context->encode_stream = Stream_New(NULL, 65536); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static void |
| 610 | rdp_peer_context_free(freerdp_peer* client, RdpPeerContext* context) |
| 611 | { |
| 612 | int i; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 613 | if (!context) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 614 | return; |
| 615 | |
| 616 | wl_list_remove(&context->item.link); |
| 617 | for(i = 0; i < MAX_FREERDP_FDS; i++) { |
Hardening | b8f03aa | 2013-05-26 23:34:00 +0200 | [diff] [blame] | 618 | if (context->events[i]) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 619 | wl_event_source_remove(context->events[i]); |
| 620 | } |
| 621 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 622 | if (context->item.flags & RDP_PEER_ACTIVATED) { |
Hardening | fb8546e | 2013-12-21 23:19:11 +0100 | [diff] [blame] | 623 | weston_seat_release_keyboard(&context->item.seat); |
| 624 | weston_seat_release_pointer(&context->item.seat); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 625 | weston_seat_release(&context->item.seat); |
Hardening | fb8546e | 2013-12-21 23:19:11 +0100 | [diff] [blame] | 626 | } |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 627 | |
Hardening | a1ce6cd | 2013-05-22 23:40:16 +0200 | [diff] [blame] | 628 | Stream_Free(context->encode_stream, TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 629 | nsc_context_free(context->nsc_context); |
| 630 | rfx_context_free(context->rfx_context); |
| 631 | free(context->rfx_rects); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | static int |
| 636 | rdp_client_activity(int fd, uint32_t mask, void *data) { |
| 637 | freerdp_peer* client = (freerdp_peer *)data; |
| 638 | |
| 639 | if (!client->CheckFileDescriptor(client)) { |
| 640 | weston_log("unable to checkDescriptor for %p\n", client); |
| 641 | goto out_clean; |
| 642 | } |
| 643 | return 0; |
| 644 | |
| 645 | out_clean: |
| 646 | freerdp_peer_context_free(client); |
| 647 | freerdp_peer_free(client); |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static BOOL |
| 652 | xf_peer_capabilities(freerdp_peer* client) |
| 653 | { |
| 654 | return TRUE; |
| 655 | } |
| 656 | |
| 657 | struct rdp_to_xkb_keyboard_layout { |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 658 | UINT32 rdpLayoutCode; |
Hardening | ea2aa13 | 2014-04-11 09:49:57 +0200 | [diff] [blame] | 659 | const char *xkbLayout; |
| 660 | const char *xkbVariant; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 661 | }; |
| 662 | |
Hardening | ea2aa13 | 2014-04-11 09:49:57 +0200 | [diff] [blame] | 663 | /* table reversed from |
| 664 | https://github.com/awakecoding/FreeRDP/blob/master/libfreerdp/locale/xkb_layout_ids.c#L811 */ |
| 665 | static |
| 666 | struct rdp_to_xkb_keyboard_layout rdp_keyboards[] = { |
| 667 | {KBD_ARABIC_101, "ara", 0}, |
| 668 | {KBD_BULGARIAN, 0, 0}, |
| 669 | {KBD_CHINESE_TRADITIONAL_US, 0}, |
| 670 | {KBD_CZECH, "cz", 0}, |
| 671 | {KBD_CZECH_PROGRAMMERS, "cz", "bksl"}, |
| 672 | {KBD_CZECH_QWERTY, "cz", "qwerty"}, |
| 673 | {KBD_DANISH, "dk", 0}, |
| 674 | {KBD_GERMAN, "de", 0}, |
| 675 | {KBD_GERMAN_NEO, "de", "neo"}, |
| 676 | {KBD_GERMAN_IBM, "de", "qwerty"}, |
| 677 | {KBD_GREEK, "gr", 0}, |
| 678 | {KBD_GREEK_220, "gr", "simple"}, |
| 679 | {KBD_GREEK_319, "gr", "extended"}, |
| 680 | {KBD_GREEK_POLYTONIC, "gr", "polytonic"}, |
| 681 | {KBD_US, "us", 0}, |
| 682 | {KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L, "ara", "buckwalter"}, |
| 683 | {KBD_SPANISH, "es", 0}, |
| 684 | {KBD_SPANISH_VARIATION, "es", "nodeadkeys"}, |
| 685 | {KBD_FINNISH, "fi", 0}, |
| 686 | {KBD_FRENCH, "fr", 0}, |
| 687 | {KBD_HEBREW, "il", 0}, |
| 688 | {KBD_HUNGARIAN, "hu", 0}, |
| 689 | {KBD_HUNGARIAN_101_KEY, "hu", "standard"}, |
| 690 | {KBD_ICELANDIC, "is", 0}, |
| 691 | {KBD_ITALIAN, "it", 0}, |
| 692 | {KBD_ITALIAN_142, "it", "nodeadkeys"}, |
| 693 | {KBD_JAPANESE, "jp", 0}, |
| 694 | {KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, "jp", "kana"}, |
| 695 | {KBD_KOREAN, "kr", 0}, |
| 696 | {KBD_KOREAN_INPUT_SYSTEM_IME_2000, "kr", "kr104"}, |
| 697 | {KBD_DUTCH, "nl", 0}, |
| 698 | {KBD_NORWEGIAN, "no", 0}, |
| 699 | {KBD_POLISH_PROGRAMMERS, "pl", 0}, |
| 700 | {KBD_POLISH_214, "pl", "qwertz"}, |
| 701 | // {KBD_PORTUGUESE_BRAZILIAN_ABN0416, 0}, |
| 702 | {KBD_ROMANIAN, "ro", 0}, |
| 703 | {KBD_RUSSIAN, "ru", 0}, |
| 704 | {KBD_RUSSIAN_TYPEWRITER, "ru", "typewriter"}, |
| 705 | {KBD_CROATIAN, "hr", 0}, |
| 706 | {KBD_SLOVAK, "sk", 0}, |
| 707 | {KBD_SLOVAK_QWERTY, "sk", "qwerty"}, |
| 708 | {KBD_ALBANIAN, 0, 0}, |
| 709 | {KBD_SWEDISH, "se", 0}, |
| 710 | {KBD_THAI_KEDMANEE, "th", 0}, |
| 711 | {KBD_THAI_KEDMANEE_NON_SHIFTLOCK, "th", "tis"}, |
| 712 | {KBD_TURKISH_Q, "tr", 0}, |
| 713 | {KBD_TURKISH_F, "tr", "f"}, |
| 714 | {KBD_URDU, "in", "urd-phonetic3"}, |
| 715 | {KBD_UKRAINIAN, "ua", 0}, |
| 716 | {KBD_BELARUSIAN, "by", 0}, |
| 717 | {KBD_SLOVENIAN, "si", 0}, |
| 718 | {KBD_ESTONIAN, "ee", 0}, |
| 719 | {KBD_LATVIAN, "lv", 0}, |
| 720 | {KBD_LITHUANIAN_IBM, "lt", "ibm"}, |
| 721 | {KBD_FARSI, "af", 0}, |
| 722 | {KBD_VIETNAMESE, "vn", 0}, |
| 723 | {KBD_ARMENIAN_EASTERN, "am", 0}, |
| 724 | {KBD_AZERI_LATIN, 0, 0}, |
| 725 | {KBD_FYRO_MACEDONIAN, "mk", 0}, |
| 726 | {KBD_GEORGIAN, "ge", 0}, |
| 727 | {KBD_FAEROESE, 0, 0}, |
| 728 | {KBD_DEVANAGARI_INSCRIPT, 0, 0}, |
| 729 | {KBD_MALTESE_47_KEY, 0, 0}, |
| 730 | {KBD_NORWEGIAN_WITH_SAMI, "no", "smi"}, |
| 731 | {KBD_KAZAKH, "kz", 0}, |
| 732 | {KBD_KYRGYZ_CYRILLIC, "kg", "phonetic"}, |
| 733 | {KBD_TATAR, "ru", "tt"}, |
| 734 | {KBD_BENGALI, "bd", 0}, |
| 735 | {KBD_BENGALI_INSCRIPT, "bd", "probhat"}, |
| 736 | {KBD_PUNJABI, 0, 0}, |
| 737 | {KBD_GUJARATI, "in", "guj"}, |
| 738 | {KBD_TAMIL, "in", "tam"}, |
| 739 | {KBD_TELUGU, "in", "tel"}, |
| 740 | {KBD_KANNADA, "in", "kan"}, |
| 741 | {KBD_MALAYALAM, "in", "mal"}, |
| 742 | {KBD_HINDI_TRADITIONAL, "in", 0}, |
| 743 | {KBD_MARATHI, 0, 0}, |
| 744 | {KBD_MONGOLIAN_CYRILLIC, "mn", 0}, |
| 745 | {KBD_UNITED_KINGDOM_EXTENDED, "gb", "intl"}, |
| 746 | {KBD_SYRIAC, "syc", 0}, |
| 747 | {KBD_SYRIAC_PHONETIC, "syc", "syc_phonetic"}, |
| 748 | {KBD_NEPALI, "np", 0}, |
| 749 | {KBD_PASHTO, "af", "ps"}, |
| 750 | {KBD_DIVEHI_PHONETIC, 0, 0}, |
| 751 | {KBD_LUXEMBOURGISH, 0, 0}, |
| 752 | {KBD_MAORI, "mao", 0}, |
| 753 | {KBD_CHINESE_SIMPLIFIED_US, 0, 0}, |
| 754 | {KBD_SWISS_GERMAN, "ch", "de_nodeadkeys"}, |
| 755 | {KBD_UNITED_KINGDOM, "gb", 0}, |
| 756 | {KBD_LATIN_AMERICAN, "latam", 0}, |
| 757 | {KBD_BELGIAN_FRENCH, "be", 0}, |
| 758 | {KBD_BELGIAN_PERIOD, "be", "oss_sundeadkeys"}, |
| 759 | {KBD_PORTUGUESE, "pt", 0}, |
| 760 | {KBD_SERBIAN_LATIN, "rs", 0}, |
| 761 | {KBD_AZERI_CYRILLIC, "az", "cyrillic"}, |
| 762 | {KBD_SWEDISH_WITH_SAMI, "se", "smi"}, |
| 763 | {KBD_UZBEK_CYRILLIC, "af", "uz"}, |
| 764 | {KBD_INUKTITUT_LATIN, "ca", "ike"}, |
| 765 | {KBD_CANADIAN_FRENCH_LEGACY, "ca", "fr-legacy"}, |
| 766 | {KBD_SERBIAN_CYRILLIC, "rs", 0}, |
| 767 | {KBD_CANADIAN_FRENCH, "ca", "fr-legacy"}, |
| 768 | {KBD_SWISS_FRENCH, "ch", "fr"}, |
| 769 | {KBD_BOSNIAN, "ba", 0}, |
| 770 | {KBD_IRISH, 0, 0}, |
| 771 | {KBD_BOSNIAN_CYRILLIC, "ba", "us"}, |
| 772 | {KBD_UNITED_STATES_DVORAK, "us", "dvorak"}, |
| 773 | {KBD_PORTUGUESE_BRAZILIAN_ABNT2, "br", "nativo"}, |
| 774 | {KBD_CANADIAN_MULTILINGUAL_STANDARD, "ca", "multix"}, |
| 775 | {KBD_GAELIC, "ie", "CloGaelach"}, |
| 776 | |
| 777 | {0x00000000, 0, 0}, |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 778 | }; |
| 779 | |
| 780 | /* taken from 2.2.7.1.6 Input Capability Set (TS_INPUT_CAPABILITYSET) */ |
| 781 | static char *rdp_keyboard_types[] = { |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 782 | "", /* 0: unused */ |
| 783 | "", /* 1: IBM PC/XT or compatible (83-key) keyboard */ |
| 784 | "", /* 2: Olivetti "ICO" (102-key) keyboard */ |
| 785 | "", /* 3: IBM PC/AT (84-key) or similar keyboard */ |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 786 | "pc102",/* 4: IBM enhanced (101- or 102-key) keyboard */ |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 787 | "", /* 5: Nokia 1050 and similar keyboards */ |
| 788 | "", /* 6: Nokia 9140 and similar keyboards */ |
| 789 | "" /* 7: Japanese keyboard */ |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | static BOOL |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 793 | xf_peer_activate(freerdp_peer* client) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 794 | { |
| 795 | RdpPeerContext *peerCtx; |
| 796 | struct rdp_compositor *c; |
| 797 | struct rdp_output *output; |
| 798 | rdpSettings *settings; |
Hardening | c39118b | 2013-05-22 23:40:19 +0200 | [diff] [blame] | 799 | rdpPointerUpdate *pointer; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 800 | struct rdp_peers_item *peersItem; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 801 | struct xkb_context *xkbContext; |
| 802 | struct xkb_rule_names xkbRuleNames; |
| 803 | struct xkb_keymap *keymap; |
| 804 | int i; |
Hardening | c39118b | 2013-05-22 23:40:19 +0200 | [diff] [blame] | 805 | pixman_box32_t box; |
| 806 | pixman_region32_t damage; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 807 | char seat_name[50]; |
Hardening | c39118b | 2013-05-22 23:40:19 +0200 | [diff] [blame] | 808 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 809 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 810 | peerCtx = (RdpPeerContext *)client->context; |
| 811 | c = peerCtx->rdpCompositor; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 812 | peersItem = &peerCtx->item; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 813 | output = c->output; |
| 814 | settings = client->settings; |
| 815 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 816 | if (!settings->SurfaceCommandsEnabled) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 817 | weston_log("client doesn't support required SurfaceCommands\n"); |
| 818 | return FALSE; |
| 819 | } |
| 820 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 821 | if (output->base.width != (int)settings->DesktopWidth || |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 822 | output->base.height != (int)settings->DesktopHeight) |
| 823 | { |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 824 | if (c->no_clients_resize) { |
| 825 | /* RDP peers don't dictate their resolution to weston */ |
| 826 | if (!settings->DesktopResize) { |
| 827 | /* peer does not support desktop resize */ |
| 828 | weston_log("%s: client doesn't support resizing, closing connection\n", __FUNCTION__); |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 829 | return FALSE; |
| 830 | } else { |
| 831 | settings->DesktopWidth = output->base.width; |
| 832 | settings->DesktopHeight = output->base.height; |
| 833 | client->update->DesktopResize(client->context); |
| 834 | } |
| 835 | } else { |
| 836 | /* ask weston to adjust size */ |
| 837 | struct weston_mode new_mode; |
| 838 | struct weston_mode *target_mode; |
| 839 | new_mode.width = (int)settings->DesktopWidth; |
| 840 | new_mode.height = (int)settings->DesktopHeight; |
| 841 | target_mode = ensure_matching_mode(&output->base, &new_mode); |
| 842 | if (!target_mode) { |
| 843 | weston_log("client mode not found\n"); |
| 844 | return FALSE; |
| 845 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 846 | weston_output_mode_set_native(&output->base, target_mode, 1); |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 847 | output->base.width = new_mode.width; |
| 848 | output->base.height = new_mode.height; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 849 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 852 | rfx_context_reset(peerCtx->rfx_context); |
| 853 | #ifdef HAVE_NSC_RESET |
| 854 | nsc_context_reset(peerCtx->nsc_context); |
| 855 | #endif |
| 856 | |
| 857 | if (peersItem->flags & RDP_PEER_ACTIVATED) |
| 858 | return TRUE; |
| 859 | |
| 860 | /* when here it's the first reactivation, we need to setup a little more */ |
| 861 | weston_log("kbd_layout:0x%x kbd_type:0x%x kbd_subType:0x%x kbd_functionKeys:0x%x\n", |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 862 | settings->KeyboardLayout, settings->KeyboardType, settings->KeyboardSubType, |
| 863 | settings->KeyboardFunctionKey); |
| 864 | |
| 865 | memset(&xkbRuleNames, 0, sizeof(xkbRuleNames)); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 866 | if (settings->KeyboardType <= 7) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 867 | xkbRuleNames.model = rdp_keyboard_types[settings->KeyboardType]; |
Hardening | ea2aa13 | 2014-04-11 09:49:57 +0200 | [diff] [blame] | 868 | for(i = 0; rdp_keyboards[i].rdpLayoutCode; i++) { |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 869 | if (rdp_keyboards[i].rdpLayoutCode == settings->KeyboardLayout) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 870 | xkbRuleNames.layout = rdp_keyboards[i].xkbLayout; |
Hardening | ea2aa13 | 2014-04-11 09:49:57 +0200 | [diff] [blame] | 871 | xkbRuleNames.variant = rdp_keyboards[i].xkbVariant; |
Hardening | 6d1d112 | 2014-04-11 10:24:22 +0200 | [diff] [blame] | 872 | weston_log("%s: matching layout=%s variant=%s\n", __FUNCTION__, |
| 873 | xkbRuleNames.layout, xkbRuleNames.variant); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 874 | break; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | keymap = NULL; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 879 | if (xkbRuleNames.layout) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 880 | xkbContext = xkb_context_new(0); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 881 | if (!xkbContext) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 882 | weston_log("unable to create a xkb_context\n"); |
| 883 | return FALSE; |
| 884 | } |
| 885 | |
| 886 | keymap = xkb_keymap_new_from_names(xkbContext, &xkbRuleNames, 0); |
| 887 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 888 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 889 | if (settings->ClientHostname) |
| 890 | snprintf(seat_name, sizeof(seat_name), "RDP %s", settings->ClientHostname); |
| 891 | else |
| 892 | snprintf(seat_name, sizeof(seat_name), "RDP peer @%s", settings->ClientAddress); |
| 893 | |
| 894 | weston_seat_init(&peersItem->seat, &c->base, seat_name); |
| 895 | weston_seat_init_keyboard(&peersItem->seat, keymap); |
| 896 | weston_seat_init_pointer(&peersItem->seat); |
| 897 | |
| 898 | peersItem->flags |= RDP_PEER_ACTIVATED; |
Hardening | c39118b | 2013-05-22 23:40:19 +0200 | [diff] [blame] | 899 | |
| 900 | /* disable pointer on the client side */ |
| 901 | pointer = client->update->pointer; |
| 902 | pointer->pointer_system.type = SYSPTR_NULL; |
| 903 | pointer->PointerSystem(client->context, &pointer->pointer_system); |
| 904 | |
| 905 | /* sends a full refresh */ |
| 906 | box.x1 = 0; |
| 907 | box.y1 = 0; |
| 908 | box.x2 = output->base.width; |
| 909 | box.y2 = output->base.height; |
| 910 | pixman_region32_init_with_extents(&damage, &box); |
| 911 | |
| 912 | rdp_peer_refresh_region(&damage, client); |
| 913 | |
| 914 | pixman_region32_fini(&damage); |
| 915 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 916 | return TRUE; |
| 917 | } |
| 918 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 919 | static BOOL xf_peer_post_connect(freerdp_peer *client) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 920 | { |
| 921 | return TRUE; |
| 922 | } |
| 923 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 924 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 925 | xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) { |
Hardening | b60e46f | 2013-06-03 22:55:47 +0200 | [diff] [blame] | 926 | wl_fixed_t wl_x, wl_y, axis; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 927 | RdpPeerContext *peerContext = (RdpPeerContext *)input->context; |
| 928 | struct rdp_output *output; |
| 929 | uint32_t button = 0; |
| 930 | |
| 931 | if (flags & PTR_FLAGS_MOVE) { |
| 932 | output = peerContext->rdpCompositor->output; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 933 | if (x < output->base.width && y < output->base.height) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 934 | wl_x = wl_fixed_from_int((int)x); |
| 935 | wl_y = wl_fixed_from_int((int)y); |
| 936 | notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(), |
| 937 | wl_x, wl_y); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | if (flags & PTR_FLAGS_BUTTON1) |
| 942 | button = BTN_LEFT; |
| 943 | else if (flags & PTR_FLAGS_BUTTON2) |
| 944 | button = BTN_RIGHT; |
| 945 | else if (flags & PTR_FLAGS_BUTTON3) |
| 946 | button = BTN_MIDDLE; |
| 947 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 948 | if (button) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 949 | notify_button(&peerContext->item.seat, weston_compositor_get_time(), button, |
| 950 | (flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED |
| 951 | ); |
| 952 | } |
Hardening | b60e46f | 2013-06-03 22:55:47 +0200 | [diff] [blame] | 953 | |
| 954 | if (flags & PTR_FLAGS_WHEEL) { |
| 955 | /* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c |
| 956 | * The RDP specs says the lower bits of flags contains the "the number of rotation |
| 957 | * units the mouse wheel was rotated". |
| 958 | * |
| 959 | * http://blogs.msdn.com/b/oldnewthing/archive/2013/01/23/10387366.aspx explains the 120 value |
| 960 | */ |
| 961 | axis = (DEFAULT_AXIS_STEP_DISTANCE * (flags & 0xff)) / 120; |
| 962 | if (flags & PTR_FLAGS_WHEEL_NEGATIVE) |
| 963 | axis = -axis; |
| 964 | |
| 965 | notify_axis(&peerContext->item.seat, weston_compositor_get_time(), |
| 966 | WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 967 | axis); |
| 968 | } |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 969 | |
| 970 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 971 | } |
| 972 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 973 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 974 | xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) { |
| 975 | wl_fixed_t wl_x, wl_y; |
| 976 | RdpPeerContext *peerContext = (RdpPeerContext *)input->context; |
| 977 | struct rdp_output *output; |
| 978 | |
| 979 | output = peerContext->rdpCompositor->output; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 980 | if (x < output->base.width && y < output->base.height) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 981 | wl_x = wl_fixed_from_int((int)x); |
| 982 | wl_y = wl_fixed_from_int((int)y); |
| 983 | notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(), |
| 984 | wl_x, wl_y); |
| 985 | } |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 986 | |
| 987 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 991 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 992 | xf_input_synchronize_event(rdpInput *input, UINT32 flags) |
| 993 | { |
| 994 | freerdp_peer *client = input->context->peer; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 995 | RdpPeerContext *peerCtx = (RdpPeerContext *)input->context; |
| 996 | struct rdp_output *output = peerCtx->rdpCompositor->output; |
| 997 | pixman_box32_t box; |
| 998 | pixman_region32_t damage; |
| 999 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1000 | /* sends a full refresh */ |
| 1001 | box.x1 = 0; |
| 1002 | box.y1 = 0; |
| 1003 | box.x2 = output->base.width; |
| 1004 | box.y2 = output->base.height; |
| 1005 | pixman_region32_init_with_extents(&damage, &box); |
| 1006 | |
| 1007 | rdp_peer_refresh_region(&damage, client); |
| 1008 | |
| 1009 | pixman_region32_fini(&damage); |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1010 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1013 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1014 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1015 | xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code) |
| 1016 | { |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1017 | uint32_t scan_code, vk_code, full_code; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1018 | enum wl_keyboard_key_state keyState; |
| 1019 | RdpPeerContext *peerContext = (RdpPeerContext *)input->context; |
| 1020 | int notify = 0; |
| 1021 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1022 | if (!(peerContext->item.flags & RDP_PEER_ACTIVATED)) |
| 1023 | FREERDP_CB_RETURN(TRUE); |
| 1024 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1025 | if (flags & KBD_FLAGS_DOWN) { |
| 1026 | keyState = WL_KEYBOARD_KEY_STATE_PRESSED; |
| 1027 | notify = 1; |
| 1028 | } else if (flags & KBD_FLAGS_RELEASE) { |
| 1029 | keyState = WL_KEYBOARD_KEY_STATE_RELEASED; |
| 1030 | notify = 1; |
| 1031 | } |
| 1032 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1033 | if (notify) { |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1034 | full_code = code; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1035 | if (flags & KBD_FLAGS_EXTENDED) |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1036 | full_code |= KBD_FLAGS_EXTENDED; |
| 1037 | |
| 1038 | vk_code = GetVirtualKeyCodeFromVirtualScanCode(full_code, 4); |
Hardening | 6d1d112 | 2014-04-11 10:24:22 +0200 | [diff] [blame] | 1039 | if(flags & KBD_FLAGS_EXTENDED) |
| 1040 | vk_code |= KBDEXT; |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1041 | |
Hardening | 6d1d112 | 2014-04-11 10:24:22 +0200 | [diff] [blame] | 1042 | scan_code = GetKeycodeFromVirtualKeyCode(vk_code, KEYCODE_TYPE_EVDEV); |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1043 | |
| 1044 | /*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0, |
| 1045 | vk_code, scan_code);*/ |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1046 | notify_key(&peerContext->item.seat, weston_compositor_get_time(), |
Hardening | 6d1d112 | 2014-04-11 10:24:22 +0200 | [diff] [blame] | 1047 | scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC); |
Hardening | 4a3c150 | 2013-04-06 23:39:26 +0200 | [diff] [blame] | 1048 | } |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1049 | |
| 1050 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1053 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1054 | xf_input_unicode_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code) |
| 1055 | { |
| 1056 | weston_log("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1057 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1061 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1062 | xf_suppress_output(rdpContext *context, BYTE allow, RECTANGLE_16 *area) { |
| 1063 | RdpPeerContext *peerContext = (RdpPeerContext *)context; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1064 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1065 | if (allow) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1066 | peerContext->item.flags |= RDP_PEER_OUTPUT_ENABLED; |
| 1067 | else |
| 1068 | peerContext->item.flags &= (~RDP_PEER_OUTPUT_ENABLED); |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1069 | |
| 1070 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static int |
| 1074 | rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c) |
| 1075 | { |
| 1076 | int rcount = 0; |
| 1077 | void *rfds[MAX_FREERDP_FDS]; |
| 1078 | int i, fd; |
| 1079 | struct wl_event_loop *loop; |
| 1080 | rdpSettings *settings; |
| 1081 | rdpInput *input; |
| 1082 | RdpPeerContext *peerCtx; |
| 1083 | |
Hardening | fe107f3 | 2013-07-08 00:51:34 +0200 | [diff] [blame] | 1084 | client->ContextSize = sizeof(RdpPeerContext); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1085 | client->ContextNew = (psPeerContextNew)rdp_peer_context_new; |
| 1086 | client->ContextFree = (psPeerContextFree)rdp_peer_context_free; |
| 1087 | freerdp_peer_context_new(client); |
| 1088 | |
| 1089 | peerCtx = (RdpPeerContext *) client->context; |
| 1090 | peerCtx->rdpCompositor = c; |
| 1091 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1092 | client->Initialize(client); |
| 1093 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1094 | settings = client->settings; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1095 | /* configure security settings */ |
| 1096 | if (c->rdp_key) |
| 1097 | settings->RdpKeyFile = strdup(c->rdp_key); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1098 | if (c->tls_enabled) { |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1099 | settings->CertificateFile = strdup( c->server_cert); |
| 1100 | settings->PrivateKeyFile = strdup(c->server_key); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1101 | } else { |
| 1102 | settings->TlsSecurity = FALSE; |
| 1103 | } |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1104 | settings->NlaSecurity = FALSE; |
| 1105 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1106 | settings->OsMajorType = OSMAJORTYPE_UNIX; |
| 1107 | settings->OsMinorType = OSMINORTYPE_PSEUDO_XSERVER; |
| 1108 | settings->ColorDepth = 32; |
| 1109 | settings->RefreshRect = TRUE; |
| 1110 | settings->RemoteFxCodec = TRUE; |
| 1111 | settings->NSCodec = TRUE; |
| 1112 | settings->FrameMarkerCommandEnabled = TRUE; |
| 1113 | settings->SurfaceFrameMarkerEnabled = TRUE; |
| 1114 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1115 | client->Capabilities = xf_peer_capabilities; |
| 1116 | client->PostConnect = xf_peer_post_connect; |
| 1117 | client->Activate = xf_peer_activate; |
| 1118 | |
| 1119 | client->update->SuppressOutput = xf_suppress_output; |
| 1120 | |
| 1121 | input = client->input; |
| 1122 | input->SynchronizeEvent = xf_input_synchronize_event; |
| 1123 | input->MouseEvent = xf_mouseEvent; |
| 1124 | input->ExtendedMouseEvent = xf_extendedMouseEvent; |
| 1125 | input->KeyboardEvent = xf_input_keyboard_event; |
| 1126 | input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event; |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 1127 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1128 | if (!client->GetFileDescriptor(client, rfds, &rcount)) { |
| 1129 | weston_log("unable to retrieve client fds\n"); |
| 1130 | return -1; |
| 1131 | } |
| 1132 | |
| 1133 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 1134 | for(i = 0; i < rcount; i++) { |
| 1135 | fd = (int)(long)(rfds[i]); |
| 1136 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1137 | peerCtx->events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 1138 | rdp_client_activity, client); |
| 1139 | } |
Hardening | b8f03aa | 2013-05-26 23:34:00 +0200 | [diff] [blame] | 1140 | for ( ; i < MAX_FREERDP_FDS; i++) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1141 | peerCtx->events[i] = 0; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1142 | |
| 1143 | wl_list_insert(&c->output->peers, &peerCtx->item.link); |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1148 | static FREERDP_CB_RET_TYPE |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1149 | rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client) |
| 1150 | { |
| 1151 | struct rdp_compositor *c = (struct rdp_compositor *)instance->param4; |
Hardening | 0c944b0 | 2015-05-11 22:19:02 +0100 | [diff] [blame] | 1152 | if (rdp_peer_init(client, c) < 0) { |
| 1153 | weston_log("error when treating incoming peer"); |
| 1154 | FREERDP_CB_RETURN(FALSE); |
| 1155 | } |
| 1156 | |
| 1157 | FREERDP_CB_RETURN(TRUE); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static struct weston_compositor * |
| 1161 | rdp_compositor_create(struct wl_display *display, |
| 1162 | struct rdp_compositor_config *config, |
Hardening | 6a4e8c6 | 2013-05-27 23:13:45 +0200 | [diff] [blame] | 1163 | int *argc, char *argv[], struct weston_config *wconfig) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1164 | { |
| 1165 | struct rdp_compositor *c; |
| 1166 | char *fd_str; |
| 1167 | int fd; |
| 1168 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1169 | c = zalloc(sizeof *c); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1170 | if (c == NULL) |
| 1171 | return NULL; |
| 1172 | |
Hardening | 6a4e8c6 | 2013-05-27 23:13:45 +0200 | [diff] [blame] | 1173 | if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1174 | goto err_free; |
| 1175 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1176 | c->base.destroy = rdp_destroy; |
| 1177 | c->base.restore = rdp_restore; |
| 1178 | c->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL; |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 1179 | c->no_clients_resize = config->no_clients_resize; |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1180 | |
| 1181 | /* activate TLS only if certificate/key are available */ |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1182 | if (config->server_cert && config->server_key) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1183 | weston_log("TLS support activated\n"); |
| 1184 | c->server_cert = strdup(config->server_cert); |
| 1185 | c->server_key = strdup(config->server_key); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1186 | if (!c->server_cert || !c->server_key) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1187 | goto err_free_strings; |
| 1188 | c->tls_enabled = 1; |
| 1189 | } |
| 1190 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1191 | if (weston_compositor_set_presentation_clock_software(&c->base) < 0) |
| 1192 | goto err_compositor; |
| 1193 | |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1194 | if (pixman_renderer_init(&c->base) < 0) |
| 1195 | goto err_compositor; |
| 1196 | |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1197 | if (rdp_compositor_create_output(c, config->width, config->height) < 0) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1198 | goto err_compositor; |
| 1199 | |
Jason Ekstrand | 9fc7151 | 2014-04-02 19:53:46 -0500 | [diff] [blame] | 1200 | c->base.capabilities |= WESTON_CAP_ARBITRARY_MODES; |
| 1201 | |
| 1202 | if(!config->env_socket) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1203 | c->listener = freerdp_listener_new(); |
| 1204 | c->listener->PeerAccepted = rdp_incoming_peer; |
| 1205 | c->listener->param4 = c; |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1206 | if (!c->listener->Open(c->listener, config->bind_address, config->port)) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1207 | weston_log("unable to bind rdp socket\n"); |
| 1208 | goto err_listener; |
| 1209 | } |
| 1210 | |
| 1211 | if (rdp_implant_listener(c, c->listener) < 0) |
| 1212 | goto err_compositor; |
| 1213 | } else { |
| 1214 | /* get the socket from RDP_FD var */ |
| 1215 | fd_str = getenv("RDP_FD"); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1216 | if (!fd_str) { |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1217 | weston_log("RDP_FD env variable not set"); |
| 1218 | goto err_output; |
| 1219 | } |
| 1220 | |
| 1221 | fd = strtoul(fd_str, NULL, 10); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1222 | if (rdp_peer_init(freerdp_peer_new(fd), c)) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1223 | goto err_output; |
| 1224 | } |
| 1225 | |
| 1226 | return &c->base; |
| 1227 | |
| 1228 | err_listener: |
| 1229 | freerdp_listener_free(c->listener); |
| 1230 | err_output: |
| 1231 | weston_output_destroy(&c->output->base); |
| 1232 | err_compositor: |
| 1233 | weston_compositor_shutdown(&c->base); |
| 1234 | err_free_strings: |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1235 | if (c->rdp_key) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1236 | free(c->rdp_key); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1237 | if (c->server_cert) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1238 | free(c->server_cert); |
Hardening | fb24eaa | 2014-03-20 22:34:30 +0100 | [diff] [blame] | 1239 | if (c->server_key) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1240 | free(c->server_key); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1241 | err_free: |
| 1242 | free(c); |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
| 1246 | WL_EXPORT struct weston_compositor * |
| 1247 | backend_init(struct wl_display *display, int *argc, char *argv[], |
Hardening | 6a4e8c6 | 2013-05-27 23:13:45 +0200 | [diff] [blame] | 1248 | struct weston_config *wconfig) |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1249 | { |
| 1250 | struct rdp_compositor_config config; |
| 1251 | rdp_compositor_config_init(&config); |
| 1252 | int major, minor, revision; |
| 1253 | |
| 1254 | freerdp_get_version(&major, &minor, &revision); |
| 1255 | weston_log("using FreeRDP version %d.%d.%d\n", major, minor, revision); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1256 | |
| 1257 | const struct weston_option rdp_options[] = { |
| 1258 | { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket }, |
| 1259 | { WESTON_OPTION_INTEGER, "width", 0, &config.width }, |
| 1260 | { WESTON_OPTION_INTEGER, "height", 0, &config.height }, |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1261 | { WESTON_OPTION_STRING, "address", 0, &config.bind_address }, |
| 1262 | { WESTON_OPTION_INTEGER, "port", 0, &config.port }, |
Hardening | f34cd2c | 2014-04-02 19:54:00 -0500 | [diff] [blame] | 1263 | { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize }, |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1264 | { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key }, |
| 1265 | { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert }, |
| 1266 | { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key } |
| 1267 | }; |
| 1268 | |
| 1269 | parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv); |
David FORT | ab3298a | 2015-05-19 09:57:37 +0200 | [diff] [blame] | 1270 | if (!config.rdp_key && (!config.server_cert || !config.server_key)) { |
| 1271 | weston_log("the RDP compositor requires keys and an optional certificate for RDP or TLS security (" |
| 1272 | "--rdp4-key or --rdp-tls-cert/--rdp-tls-key)\n"); |
| 1273 | return NULL; |
| 1274 | } |
| 1275 | |
Hardening | 6a4e8c6 | 2013-05-27 23:13:45 +0200 | [diff] [blame] | 1276 | return rdp_compositor_create(display, &config, argc, argv, wconfig); |
Hardening | a83409c | 2013-04-01 23:43:58 +0200 | [diff] [blame] | 1277 | } |