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