2011-08-01 20:19:39 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Fast Path
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2011-08-01 20:19:39 +04:00
|
|
|
#include <freerdp/utils/stream.h>
|
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
#include "orders.h"
|
2012-01-25 19:00:16 +04:00
|
|
|
#include "per.h"
|
2011-08-16 11:04:57 +04:00
|
|
|
#include "update.h"
|
2011-08-23 17:01:19 +04:00
|
|
|
#include "surface.h"
|
2011-08-16 11:04:57 +04:00
|
|
|
|
2011-08-01 20:19:39 +04:00
|
|
|
#include "fastpath.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fast-Path packet format is defined in [MS-RDPBCGR] 2.2.9.1.2, which revises
|
|
|
|
* server output packets from the first byte with the goal of improving
|
|
|
|
* bandwidth.
|
|
|
|
*
|
|
|
|
* Slow-Path packet always starts with TPKT header, which has the first
|
|
|
|
* byte 0x03, while Fast-Path packet starts with 2 zero bits in the first
|
|
|
|
* two less significant bits of the first byte.
|
|
|
|
*/
|
|
|
|
|
2011-08-26 17:18:07 +04:00
|
|
|
#define FASTPATH_MAX_PACKET_SIZE 0x3FFF
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2011-08-01 20:19:39 +04:00
|
|
|
/**
|
|
|
|
* Read a Fast-Path packet header.\n
|
|
|
|
* @param s stream
|
|
|
|
* @param encryptionFlags
|
|
|
|
* @return length
|
|
|
|
*/
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
uint16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s)
|
2011-08-01 20:19:39 +04:00
|
|
|
{
|
|
|
|
uint8 header;
|
|
|
|
uint16 length;
|
|
|
|
uint8 t;
|
|
|
|
|
|
|
|
stream_read_uint8(s, header);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
if (fastpath != NULL)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2011-08-09 19:28:02 +04:00
|
|
|
fastpath->encryptionFlags = (header & 0xC0) >> 6;
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath->numberEvents = (header & 0x3C) >> 2;
|
|
|
|
}
|
2011-08-01 20:19:39 +04:00
|
|
|
|
|
|
|
stream_read_uint8(s, length); /* length1 */
|
|
|
|
/* If most significant bit is not set, length2 is not presented. */
|
|
|
|
if ((length & 0x80))
|
|
|
|
{
|
|
|
|
length &= 0x7F;
|
|
|
|
length <<= 8;
|
|
|
|
stream_read_uint8(s, t);
|
|
|
|
length += t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
INLINE void fastpath_read_update_header(STREAM* s, uint8* updateCode, uint8* fragmentation, uint8* compression)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
|
|
|
uint8 updateHeader;
|
|
|
|
|
|
|
|
stream_read_uint8(s, updateHeader);
|
|
|
|
*updateCode = updateHeader & 0x0F;
|
|
|
|
*fragmentation = (updateHeader >> 4) & 0x03;
|
|
|
|
*compression = (updateHeader >> 6) & 0x03;
|
|
|
|
}
|
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
INLINE void fastpath_write_update_header(STREAM* s, uint8 updateCode, uint8 fragmentation, uint8 compression)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
|
|
|
uint8 updateHeader = 0;
|
|
|
|
|
|
|
|
updateHeader |= updateCode & 0x0F;
|
2011-08-29 06:27:46 +04:00
|
|
|
updateHeader |= (fragmentation & 0x03) << 4;
|
|
|
|
updateHeader |= (compression & 0x03) << 6;
|
2011-08-28 21:36:56 +04:00
|
|
|
stream_write_uint8(s, updateHeader);
|
|
|
|
}
|
|
|
|
|
2011-09-15 01:14:50 +04:00
|
|
|
uint16 fastpath_read_header_rdp(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
uint8 header;
|
|
|
|
uint16 length;
|
|
|
|
|
|
|
|
stream_read_uint8(s, header);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2011-09-15 01:14:50 +04:00
|
|
|
if (fastpath != NULL)
|
|
|
|
{
|
|
|
|
fastpath->encryptionFlags = (header & 0xC0) >> 6;
|
|
|
|
fastpath->numberEvents = (header & 0x3C) >> 2;
|
|
|
|
}
|
|
|
|
|
2012-01-25 19:00:16 +04:00
|
|
|
per_read_length(s, &length);
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2012-01-25 19:00:16 +04:00
|
|
|
return length - stream_get_length(s);
|
2011-09-15 01:14:50 +04:00
|
|
|
}
|
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
static void fastpath_recv_orders(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
|
|
|
uint16 numberOrders;
|
|
|
|
|
|
|
|
stream_read_uint16(s, numberOrders); /* numberOrders (2 bytes) */
|
|
|
|
|
|
|
|
while (numberOrders > 0)
|
|
|
|
{
|
|
|
|
update_recv_order(update, s);
|
|
|
|
numberOrders--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fastpath_recv_update_common(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
uint16 updateType;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
|
|
|
rdpContext* context = update->context;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, updateType); /* updateType (2 bytes) */
|
|
|
|
|
|
|
|
switch (updateType)
|
|
|
|
{
|
|
|
|
case UPDATE_TYPE_BITMAP:
|
|
|
|
update_read_bitmap(update, s, &update->bitmap_update);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BitmapUpdate, context, &update->bitmap_update);
|
2011-08-16 11:04:57 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPDATE_TYPE_PALETTE:
|
|
|
|
update_read_palette(update, s, &update->palette_update);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->Palette, context, &update->palette_update);
|
2011-08-16 11:04:57 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 02:03:31 +04:00
|
|
|
static void fastpath_recv_update_synchronize(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
stream_seek_uint16(s); /* size (2 bytes), must be set to zero */
|
|
|
|
}
|
|
|
|
|
2011-08-28 23:12:33 +04:00
|
|
|
static void fastpath_recv_update(rdpFastPath* fastpath, uint8 updateCode, uint32 size, STREAM* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2011-09-19 22:50:40 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
2011-11-22 02:48:03 +04:00
|
|
|
rdpContext* context = fastpath->rdp->update->context;
|
|
|
|
rdpPointerUpdate* pointer = update->pointer;
|
2011-09-19 22:50:40 +04:00
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
switch (updateCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_UPDATETYPE_ORDERS:
|
2011-08-16 11:04:57 +04:00
|
|
|
fastpath_recv_orders(fastpath, s);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_BITMAP:
|
|
|
|
case FASTPATH_UPDATETYPE_PALETTE:
|
2011-08-16 11:04:57 +04:00
|
|
|
fastpath_recv_update_common(fastpath, s);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
|
2012-01-11 02:03:31 +04:00
|
|
|
fastpath_recv_update_synchronize(fastpath, s);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->Synchronize, context);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SURFCMDS:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_recv_surfcmds(update, size, s);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_NULL:
|
2011-11-22 02:48:03 +04:00
|
|
|
pointer->pointer_system.type = SYSPTR_NULL;
|
|
|
|
IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
|
2011-11-22 02:48:03 +04:00
|
|
|
update->pointer->pointer_system.type = SYSPTR_DEFAULT;
|
|
|
|
IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_POSITION:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_position(s, &pointer->pointer_position);
|
|
|
|
IFCALL(pointer->PointerPosition, context, &pointer->pointer_position);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_COLOR:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_color(s, &pointer->pointer_color);
|
|
|
|
IFCALL(pointer->PointerColor, context, &pointer->pointer_color);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_CACHED:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_cached(s, &pointer->pointer_cached);
|
|
|
|
IFCALL(pointer->PointerCached, context, &pointer->pointer_cached);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_POINTER:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_new(s, &pointer->pointer_new);
|
|
|
|
IFCALL(pointer->PointerNew, context, &pointer->pointer_new);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown updateCode 0x%X", updateCode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
2011-08-28 23:12:33 +04:00
|
|
|
uint16 size;
|
|
|
|
int next_pos;
|
|
|
|
uint32 totalSize;
|
2011-08-09 19:28:02 +04:00
|
|
|
uint8 updateCode;
|
|
|
|
uint8 fragmentation;
|
|
|
|
uint8 compression;
|
|
|
|
uint8 compressionFlags;
|
|
|
|
STREAM* update_stream;
|
2011-09-11 11:00:40 +04:00
|
|
|
STREAM* comp_stream;
|
2011-09-08 09:17:58 +04:00
|
|
|
rdpRdp *rdp;
|
|
|
|
uint32 roff;
|
|
|
|
uint32 rlen;
|
|
|
|
|
|
|
|
rdp = fastpath->rdp;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
fastpath_read_update_header(s, &updateCode, &fragmentation, &compression);
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
if (compression == FASTPATH_OUTPUT_COMPRESSION_USED)
|
|
|
|
stream_read_uint8(s, compressionFlags);
|
|
|
|
else
|
|
|
|
compressionFlags = 0;
|
|
|
|
|
|
|
|
stream_read_uint16(s, size);
|
|
|
|
next_pos = stream_get_pos(s) + size;
|
2011-09-11 11:00:40 +04:00
|
|
|
comp_stream = s;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-09-11 22:08:15 +04:00
|
|
|
if (compressionFlags & PACKET_COMPRESSED)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2011-09-11 11:00:40 +04:00
|
|
|
if (decompress_rdp(rdp, s->p, size, compressionFlags, &roff, &rlen))
|
2011-09-08 09:17:58 +04:00
|
|
|
{
|
2011-09-11 11:00:40 +04:00
|
|
|
comp_stream = stream_new(0);
|
|
|
|
comp_stream->data = rdp->mppc->history_buf + roff;
|
|
|
|
comp_stream->p = comp_stream->data;
|
|
|
|
comp_stream->size = rlen;
|
|
|
|
size = comp_stream->size;
|
2011-09-08 09:17:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("decompress_rdp() failed\n");
|
|
|
|
stream_seek(s, size);
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
update_stream = NULL;
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
|
|
|
|
{
|
2011-08-28 23:12:33 +04:00
|
|
|
totalSize = size;
|
2011-09-11 11:00:40 +04:00
|
|
|
update_stream = comp_stream;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_FIRST)
|
|
|
|
stream_set_pos(fastpath->updateData, 0);
|
|
|
|
|
|
|
|
stream_check_size(fastpath->updateData, size);
|
2011-09-11 11:00:40 +04:00
|
|
|
stream_copy(fastpath->updateData, comp_stream, size);
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_LAST)
|
|
|
|
{
|
|
|
|
update_stream = fastpath->updateData;
|
2011-08-28 23:12:33 +04:00
|
|
|
totalSize = stream_get_length(update_stream);
|
2011-08-09 19:28:02 +04:00
|
|
|
stream_set_pos(update_stream, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_stream)
|
2011-08-28 23:12:33 +04:00
|
|
|
fastpath_recv_update(fastpath, updateCode, totalSize, update_stream);
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
stream_set_pos(s, next_pos);
|
2011-09-11 11:00:40 +04:00
|
|
|
|
|
|
|
if (comp_stream != s)
|
|
|
|
xfree(comp_stream);
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
boolean fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2011-08-10 19:55:47 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BeginPaint, update->context);
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2012-01-11 02:03:31 +04:00
|
|
|
while (stream_get_left(s) >= 3)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
|
|
|
fastpath_recv_update_data(fastpath, s);
|
|
|
|
}
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->EndPaint, update->context);
|
2011-08-23 08:58:10 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 08:58:10 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
static boolean fastpath_read_input_event_header(STREAM* s, uint8* eventFlags, uint8* eventCode)
|
|
|
|
{
|
|
|
|
uint8 eventHeader;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 1)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint8(s, eventHeader); /* eventHeader (1 byte) */
|
|
|
|
|
|
|
|
*eventFlags = (eventHeader & 0x1F);
|
|
|
|
*eventCode = (eventHeader >> 5);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event_scancode(rdpFastPath* fastpath, STREAM* s, uint8 eventFlags)
|
|
|
|
{
|
|
|
|
uint16 flags;
|
|
|
|
uint16 code;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 1)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint8(s, code); /* keyCode (1 byte) */
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
|
|
|
|
flags |= KBD_FLAGS_RELEASE;
|
|
|
|
else
|
|
|
|
flags |= KBD_FLAGS_DOWN;
|
|
|
|
|
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
|
|
|
|
flags |= KBD_FLAGS_EXTENDED;
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->KeyboardEvent, fastpath->rdp->input, flags, code);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event_mouse(rdpFastPath* fastpath, STREAM* s, uint8 eventFlags)
|
|
|
|
{
|
|
|
|
uint16 pointerFlags;
|
|
|
|
uint16 xPos;
|
|
|
|
uint16 yPos;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_read_uint16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_uint16(s, yPos); /* yPos (2 bytes) */
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->MouseEvent, fastpath->rdp->input, pointerFlags, xPos, yPos);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event_mousex(rdpFastPath* fastpath, STREAM* s, uint8 eventFlags)
|
2011-08-23 08:58:10 +04:00
|
|
|
{
|
2011-08-23 11:51:51 +04:00
|
|
|
uint16 pointerFlags;
|
|
|
|
uint16 xPos;
|
|
|
|
uint16 yPos;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 6)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
stream_read_uint16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_uint16(s, yPos); /* yPos (2 bytes) */
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->ExtendedMouseEvent, fastpath->rdp->input, pointerFlags, xPos, yPos);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event_sync(rdpFastPath* fastpath, STREAM* s, uint8 eventFlags)
|
|
|
|
{
|
|
|
|
IFCALL(fastpath->rdp->input->SynchronizeEvent, fastpath->rdp->input, eventFlags);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event_unicode(rdpFastPath* fastpath, STREAM* s, uint8 eventFlags)
|
|
|
|
{
|
|
|
|
uint16 unicodeCode;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 2)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, unicodeCode); /* unicodeCode (2 bytes) */
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->UnicodeKeyboardEvent, fastpath->rdp->input, unicodeCode);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean fastpath_recv_input_event(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
uint8 eventFlags;
|
|
|
|
uint8 eventCode;
|
|
|
|
|
|
|
|
if (!fastpath_read_input_event_header(s, &eventFlags, &eventCode))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
switch (eventCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_INPUT_EVENT_SCANCODE:
|
|
|
|
if (!fastpath_recv_input_event_scancode(fastpath, s, eventFlags))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSE:
|
|
|
|
if (!fastpath_recv_input_event_mouse(fastpath, s, eventFlags))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSEX:
|
|
|
|
if (!fastpath_recv_input_event_mousex(fastpath, s, eventFlags))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_SYNC:
|
|
|
|
if (!fastpath_recv_input_event_sync(fastpath, s, eventFlags))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_UNICODE:
|
|
|
|
if (!fastpath_recv_input_event_unicode(fastpath, s, eventFlags))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unknown eventCode %d\n", eventCode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean fastpath_recv_inputs(rdpFastPath* fastpath, STREAM* s)
|
|
|
|
{
|
|
|
|
uint8 i;
|
|
|
|
|
|
|
|
if (fastpath->numberEvents == 0)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If numberEvents is not provided in fpInputHeader, it will be provided
|
2011-08-27 05:44:37 +04:00
|
|
|
* as one additional byte here.
|
2011-08-23 11:51:51 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 1)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
stream_read_uint8(s, fastpath->numberEvents); /* eventHeader (1 byte) */
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < fastpath->numberEvents; i++)
|
|
|
|
{
|
|
|
|
if (!fastpath_recv_input_event(fastpath, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 19:28:28 +04:00
|
|
|
STREAM* fastpath_input_pdu_init(rdpFastPath* fastpath, uint8 eventFlags, uint8 eventCode)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
s = transport_send_stream_init(fastpath->rdp->transport, 127);
|
|
|
|
stream_seek(s, 2); /* fpInputHeader and length1 */
|
|
|
|
/* length2 is not necessary since input PDU should not exceed 127 bytes */
|
2011-08-23 19:28:28 +04:00
|
|
|
stream_write_uint8(s, eventFlags | (eventCode << 5)); /* eventHeader (1 byte) */
|
2011-08-16 10:37:11 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-08-23 19:28:28 +04:00
|
|
|
boolean fastpath_send_input_pdu(rdpFastPath* fastpath, STREAM* s)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2011-08-23 19:28:28 +04:00
|
|
|
uint16 length;
|
2011-08-16 10:37:11 +04:00
|
|
|
|
|
|
|
length = stream_get_length(s);
|
|
|
|
if (length > 127)
|
|
|
|
{
|
|
|
|
printf("Maximum FastPath PDU length is 127\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
stream_set_pos(s, 0);
|
2011-08-23 19:28:28 +04:00
|
|
|
stream_write_uint8(s, (1 << 2));
|
2011-08-16 10:37:11 +04:00
|
|
|
stream_write_uint8(s, length);
|
|
|
|
|
|
|
|
stream_set_pos(s, length);
|
2011-08-23 11:51:51 +04:00
|
|
|
if (transport_write(fastpath->rdp->transport, s) < 0)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 19:28:28 +04:00
|
|
|
STREAM* fastpath_update_pdu_init(rdpFastPath* fastpath)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-08-23 19:28:28 +04:00
|
|
|
s = transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE);
|
|
|
|
stream_seek(s, 3); /* fpOutputHeader, length1 and length2 */
|
2011-12-03 10:42:13 +04:00
|
|
|
stream_seek(s, 3); /* updateHeader, size */
|
2011-08-23 11:51:51 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
boolean fastpath_send_update_pdu(rdpFastPath* fastpath, uint8 updateCode, STREAM* s)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2011-12-03 10:42:13 +04:00
|
|
|
uint8* bm;
|
2011-08-28 01:11:20 +04:00
|
|
|
int fragment;
|
2011-08-27 05:44:37 +04:00
|
|
|
uint16 length;
|
2011-12-03 10:42:13 +04:00
|
|
|
boolean result;
|
|
|
|
uint16 pduLength;
|
2011-08-28 01:11:20 +04:00
|
|
|
uint16 maxLength;
|
2011-08-27 05:44:37 +04:00
|
|
|
uint32 totalLength;
|
2011-08-28 21:36:56 +04:00
|
|
|
uint8 fragmentation;
|
2011-08-27 05:44:37 +04:00
|
|
|
STREAM* update;
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
result = true;
|
|
|
|
|
2011-08-28 01:11:20 +04:00
|
|
|
maxLength = FASTPATH_MAX_PACKET_SIZE - 6;
|
2011-12-03 10:42:13 +04:00
|
|
|
totalLength = stream_get_length(s) - 6;
|
2011-08-28 21:36:56 +04:00
|
|
|
stream_set_pos(s, 0);
|
2011-12-03 10:42:13 +04:00
|
|
|
update = stream_new(0);
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
for (fragment = 0; totalLength > 0; fragment++)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2011-08-28 21:36:56 +04:00
|
|
|
length = MIN(maxLength, totalLength);
|
2011-08-27 05:44:37 +04:00
|
|
|
totalLength -= length;
|
2011-12-03 10:42:13 +04:00
|
|
|
pduLength = length + 6;
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
if (totalLength == 0)
|
|
|
|
fragmentation = (fragment == 0) ? FASTPATH_FRAGMENT_SINGLE : FASTPATH_FRAGMENT_LAST;
|
2011-08-28 01:11:20 +04:00
|
|
|
else
|
2011-08-28 21:36:56 +04:00
|
|
|
fragmentation = (fragment == 0) ? FASTPATH_FRAGMENT_FIRST : FASTPATH_FRAGMENT_NEXT;
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
stream_get_mark(s, bm);
|
|
|
|
stream_write_uint8(s, 0); /* fpOutputHeader (1 byte) */
|
|
|
|
stream_write_uint8(s, 0x80 | (pduLength >> 8)); /* length1 */
|
|
|
|
stream_write_uint8(s, pduLength & 0xFF); /* length2 */
|
|
|
|
fastpath_write_update_header(s, updateCode, fragmentation, 0);
|
|
|
|
stream_write_uint16(s, length);
|
|
|
|
|
|
|
|
stream_attach(update, bm, pduLength);
|
|
|
|
stream_seek(update, pduLength);
|
|
|
|
if (transport_write(fastpath->rdp->transport, update) < 0)
|
|
|
|
{
|
|
|
|
stream_detach(update);
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stream_detach(update);
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
/* Reserve 6 bytes for the next fragment header, if any. */
|
|
|
|
stream_seek(s, length - 6);
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
stream_free(update);
|
|
|
|
|
|
|
|
return result;
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
rdpFastPath* fastpath_new(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
rdpFastPath* fastpath;
|
|
|
|
|
|
|
|
fastpath = xnew(rdpFastPath);
|
|
|
|
fastpath->rdp = rdp;
|
|
|
|
fastpath->updateData = stream_new(4096);
|
|
|
|
|
|
|
|
return fastpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fastpath_free(rdpFastPath* fastpath)
|
|
|
|
{
|
|
|
|
stream_free(fastpath->updateData);
|
|
|
|
xfree(fastpath);
|
|
|
|
}
|