libfreerdp-core: add fastpath receiving layer.

This commit is contained in:
Vic Lee 2011-08-09 23:28:02 +08:00
parent e5419bed9f
commit 236c41dac1
5 changed files with 258 additions and 10 deletions

View File

@ -41,15 +41,15 @@
* @return length
*/
uint16 fastpath_read_header(STREAM* s, uint8* encryptionFlags)
uint16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s)
{
uint8 header;
uint16 length;
uint8 t;
stream_read_uint8(s, header);
if (encryptionFlags != NULL)
*encryptionFlags = (header & 0xC0) >> 6;
if (fastpath != NULL)
fastpath->encryptionFlags = (header & 0xC0) >> 6;
stream_read_uint8(s, length); /* length1 */
/* If most significant bit is not set, length2 is not presented. */
@ -63,3 +63,192 @@ uint16 fastpath_read_header(STREAM* s, uint8* encryptionFlags)
return length;
}
static int fastpath_recv_update_surfcmd_surface_bits(rdpFastPath* fastpath, STREAM* s)
{
uint32 bitmapDataLength;
stream_seek(s, 16);
stream_read_uint32(s, bitmapDataLength);
stream_seek(s, bitmapDataLength);
/*printf("surface_bits %d\n", bitmapDataLength);*/
return 20 + bitmapDataLength;
}
static int fastpath_recv_update_surfcmd_frame_marker(rdpFastPath* fastpath, STREAM* s)
{
uint16 frameAction;
uint32 frameId;
STREAM* ack;
stream_read_uint16(s, frameAction);
stream_read_uint32(s, frameId);
/*printf("frameAction %d frameId %d\n", frameAction, frameId);*/
return 6;
}
static void fastpath_recv_update_surfcmds(rdpFastPath* fastpath, uint16 size, STREAM* s)
{
uint16 cmdType;
while (size > 2)
{
stream_read_uint16(s, cmdType);
size -= 2;
switch (cmdType)
{
case CMDTYPE_SET_SURFACE_BITS:
case CMDTYPE_STREAM_SURFACE_BITS:
size -= fastpath_recv_update_surfcmd_surface_bits(fastpath, s);
break;
case CMDTYPE_FRAME_MARKER:
size -= fastpath_recv_update_surfcmd_frame_marker(fastpath, s);
break;
default:
DEBUG_WARN("unknown cmdType 0x%X", cmdType);
return;
}
}
}
static void fastpath_recv_update(rdpFastPath* fastpath, uint8 updateCode, uint16 size, STREAM* s)
{
switch (updateCode)
{
case FASTPATH_UPDATETYPE_ORDERS:
printf("FASTPATH_UPDATETYPE_ORDERS\n");
break;
case FASTPATH_UPDATETYPE_BITMAP:
printf("FASTPATH_UPDATETYPE_BITMAP\n");
break;
case FASTPATH_UPDATETYPE_PALETTE:
printf("FASTPATH_UPDATETYPE_PALETTE\n");
break;
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
break;
case FASTPATH_UPDATETYPE_SURFCMDS:
fastpath_recv_update_surfcmds(fastpath, size, s);
break;
case FASTPATH_UPDATETYPE_PTR_NULL:
printf("FASTPATH_UPDATETYPE_PTR_NULL\n");
break;
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
printf("FASTPATH_UPDATETYPE_PTR_DEFAULT\n");
break;
case FASTPATH_UPDATETYPE_PTR_POSITION:
printf("FASTPATH_UPDATETYPE_PTR_POSITION\n");
break;
case FASTPATH_UPDATETYPE_COLOR:
printf("FASTPATH_UPDATETYPE_COLOR\n");
break;
case FASTPATH_UPDATETYPE_CACHED:
printf("FASTPATH_UPDATETYPE_CACHED\n");
break;
case FASTPATH_UPDATETYPE_POINTER:
printf("FASTPATH_UPDATETYPE_POINTER\n");
break;
default:
DEBUG_WARN("unknown updateCode 0x%X", updateCode);
break;
}
}
static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
{
uint8 updateHeader;
uint8 updateCode;
uint8 fragmentation;
uint8 compression;
uint8 compressionFlags;
uint16 size;
STREAM* update_stream;
int next_pos;
stream_read_uint8(s, updateHeader);
updateCode = updateHeader & 0x0F;
fragmentation = (updateHeader >> 4) & 0x03;
compression = (updateHeader >> 6) & 0x03;
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;
if (compressionFlags != 0)
{
printf("FastPath compression is not yet implemented!\n");
stream_seek(s, size);
return;
}
update_stream = NULL;
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
{
update_stream = s;
}
else
{
if (fragmentation == FASTPATH_FRAGMENT_FIRST)
stream_set_pos(fastpath->updateData, 0);
stream_check_size(fastpath->updateData, size);
stream_copy(fastpath->updateData, s, size);
if (fragmentation == FASTPATH_FRAGMENT_LAST)
{
update_stream = fastpath->updateData;
size = stream_get_length(update_stream);
stream_set_pos(update_stream, 0);
}
}
if (update_stream)
fastpath_recv_update(fastpath, updateCode, size, update_stream);
stream_set_pos(s, next_pos);
}
void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s)
{
while (stream_get_left(s) > 3)
{
fastpath_recv_update_data(fastpath, s);
}
}
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);
}

View File

@ -20,8 +20,11 @@
#ifndef __FASTPATH_H
#define __FASTPATH_H
#include "rdp.h"
#include <freerdp/utils/stream.h>
typedef struct rdp_fastpath rdpFastPath;
enum FASTPATH_OUTPUT_ACTION_TYPE
{
FASTPATH_OUTPUT_ACTION_FASTPATH = 0x0,
@ -34,6 +37,52 @@ enum FASTPATH_OUTPUT_ENCRYPTION_FLAGS
FASTPATH_OUTPUT_ENCRYPTED = 0x2
};
uint16 fastpath_read_header(STREAM* s, uint8* encryptionFlags);
enum FASTPATH_UPDATETYPE
{
FASTPATH_UPDATETYPE_ORDERS = 0x0,
FASTPATH_UPDATETYPE_BITMAP = 0x1,
FASTPATH_UPDATETYPE_PALETTE = 0x2,
FASTPATH_UPDATETYPE_SYNCHRONIZE = 0x3,
FASTPATH_UPDATETYPE_SURFCMDS = 0x4,
FASTPATH_UPDATETYPE_PTR_NULL = 0x5,
FASTPATH_UPDATETYPE_PTR_DEFAULT = 0x6,
FASTPATH_UPDATETYPE_PTR_POSITION = 0x8,
FASTPATH_UPDATETYPE_COLOR = 0x9,
FASTPATH_UPDATETYPE_CACHED = 0xA,
FASTPATH_UPDATETYPE_POINTER = 0xB
};
enum FASTPATH_FRAGMENT
{
FASTPATH_FRAGMENT_SINGLE = 0x0,
FASTPATH_FRAGMENT_LAST = 0x1,
FASTPATH_FRAGMENT_FIRST = 0x2,
FASTPATH_FRAGMENT_NEXT = 0x3
};
enum SURFCMD_CMDTYPE
{
CMDTYPE_SET_SURFACE_BITS = 0x0001,
CMDTYPE_FRAME_MARKER = 0x0004,
CMDTYPE_STREAM_SURFACE_BITS = 0x0006
};
enum FASTPATH_OUTPUT_COMPRESSION
{
FASTPATH_OUTPUT_COMPRESSION_USED = 0x2
};
struct rdp_fastpath
{
rdpRdp* rdp;
uint8 encryptionFlags;
STREAM* updateData;
};
uint16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s);
void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s);
rdpFastPath* fastpath_new(rdpRdp* rdp);
void fastpath_free(rdpFastPath* fastpath);
#endif

View File

@ -435,9 +435,18 @@ static void rdp_process_tpkt_pdu(rdpRdp* rdp, STREAM* s)
static void rdp_process_fastpath_pdu(rdpRdp* rdp, STREAM* s)
{
uint32 length = fastpath_read_header(s, NULL);
uint16 length;
printf("FastPath PDU: length=%d\n", length);
length = fastpath_read_header(rdp->fastpath, s);
/* TODO: fipsInformation */
if ((rdp->fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED))
{
stream_seek(s, 8); /* dataSignature */
}
fastpath_recv_updates(rdp->fastpath, s);
}
static void rdp_process_pdu(rdpRdp* rdp, STREAM* s)
@ -514,6 +523,7 @@ rdpRdp* rdp_new(freerdp* instance)
rdp->license = license_new(rdp);
rdp->input = input_new(rdp);
rdp->update = update_new(rdp);
rdp->fastpath = fastpath_new(rdp);
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
rdp->vchan = vchan_new(instance);
@ -536,6 +546,7 @@ void rdp_free(rdpRdp* rdp)
license_free(rdp->license);
input_free(rdp->input);
update_free(rdp->update);
fastpath_free(rdp->fastpath);
mcs_free(rdp->mcs);
vchan_free(rdp->vchan);
xfree(rdp);

View File

@ -120,6 +120,7 @@ struct rdp_rdp
struct rdp_nego* nego;
struct rdp_input* input;
struct rdp_update* update;
struct rdp_fastpath* fastpath;
struct rdp_license* license;
struct rdp_settings* settings;
struct rdp_registry* registry;

View File

@ -216,7 +216,6 @@ int transport_check_fds(rdpTransport* transport)
{
int pos;
int status;
uint8 header;
uint16 length;
STREAM* received;
@ -231,11 +230,10 @@ int transport_check_fds(rdpTransport* transport)
return 0;
stream_set_pos(transport->recv_buffer, 0);
stream_peek_uint8(transport->recv_buffer, header);
if (header == 0x03) /* TPKT */
if (tpkt_verify_header(transport->recv_buffer)) /* TPKT */
length = tpkt_read_header(transport->recv_buffer);
else /* Fast Path */
length = fastpath_read_header(transport->recv_buffer, NULL);
length = fastpath_read_header(NULL, transport->recv_buffer);
if (length == 0)
{