2011-08-23 17:01:19 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-23 17:01:19 +04:00
|
|
|
* Surface Commands
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-27 04:26:40 +04:00
|
|
|
#include <freerdp/utils/pcap.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-08-27 04:26:40 +04:00
|
|
|
|
2011-08-23 17:01:19 +04:00
|
|
|
#include "surface.h"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.surface")
|
|
|
|
|
2013-04-13 01:05:42 +04:00
|
|
|
static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT32* length)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
|
|
|
int pos;
|
2011-08-27 05:44:37 +04:00
|
|
|
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, cmd->destLeft);
|
|
|
|
Stream_Read_UINT16(s, cmd->destTop);
|
|
|
|
Stream_Read_UINT16(s, cmd->destRight);
|
|
|
|
Stream_Read_UINT16(s, cmd->destBottom);
|
|
|
|
Stream_Read_UINT8(s, cmd->bpp);
|
2014-05-29 12:12:02 +04:00
|
|
|
if ((cmd->bpp < 1) || (cmd->bpp > 32))
|
|
|
|
{
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "invalid bpp value %d", cmd->bpp);
|
2014-05-29 12:12:02 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 2); /* reserved1, reserved2 */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, cmd->codecID);
|
|
|
|
Stream_Read_UINT16(s, cmd->width);
|
|
|
|
Stream_Read_UINT16(s, cmd->height);
|
|
|
|
Stream_Read_UINT32(s, cmd->bitmapDataLength);
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < cmd->bitmapDataLength)
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s) + cmd->bitmapDataLength;
|
|
|
|
cmd->bitmapData = Stream_Pointer(s);
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, pos);
|
2013-01-14 02:37:50 +04:00
|
|
|
*length = 20 + cmd->bitmapDataLength;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2013-10-09 04:40:58 +04:00
|
|
|
WLog_Print(update->log, WLOG_DEBUG,
|
2014-09-12 16:36:29 +04:00
|
|
|
"SurfaceBits: destLeft: %d destTop: %d destRight: %d destBottom: %d "
|
|
|
|
"bpp: %d codecId: %d width: %d height: %d bitmapDataLength: %d",
|
|
|
|
cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom,
|
|
|
|
cmd->bpp, cmd->codecID, cmd->width, cmd->height, cmd->bitmapDataLength);
|
2013-04-13 01:05:42 +04:00
|
|
|
IFCALL(update->SurfaceBits, update->context, cmd);
|
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return 0;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int update_recv_surfcmd_frame_marker(rdpUpdate* update, wStream* s, UINT32 *length)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
2011-11-25 20:30:15 +04:00
|
|
|
SURFACE_FRAME_MARKER* marker = &update->surface_frame_marker;
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, marker->frameAction);
|
|
|
|
Stream_Read_UINT32(s, marker->frameId);
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2013-10-09 04:40:58 +04:00
|
|
|
WLog_Print(update->log, WLOG_DEBUG, "SurfaceFrameMarker: action: %s (%d) id: %d",
|
|
|
|
(!marker->frameAction) ? "Begin" : "End",
|
|
|
|
marker->frameAction, marker->frameId);
|
|
|
|
|
2011-11-25 20:30:15 +04:00
|
|
|
IFCALL(update->SurfaceFrameMarker, update->context, marker);
|
2011-11-25 14:48:51 +04:00
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
*length = 6;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
|
|
|
return 0;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* mark;
|
|
|
|
UINT16 cmdType;
|
2014-07-08 23:07:19 +04:00
|
|
|
UINT32 cmdLength = 0;
|
2011-08-27 04:26:40 +04:00
|
|
|
|
2011-08-27 05:44:37 +04:00
|
|
|
while (size > 2)
|
|
|
|
{
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(s, mark);
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, cmdType);
|
2011-08-23 17:01:19 +04:00
|
|
|
size -= 2;
|
|
|
|
|
|
|
|
switch (cmdType)
|
|
|
|
{
|
|
|
|
case CMDTYPE_SET_SURFACE_BITS:
|
|
|
|
case CMDTYPE_STREAM_SURFACE_BITS:
|
2013-01-17 03:01:10 +04:00
|
|
|
if (update_recv_surfcmd_surface_bits(update, s, &cmdLength) < 0)
|
2013-01-14 02:37:50 +04:00
|
|
|
return -1;
|
2011-08-23 17:01:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMDTYPE_FRAME_MARKER:
|
2013-01-17 03:01:10 +04:00
|
|
|
if (update_recv_surfcmd_frame_marker(update, s, &cmdLength) < 0)
|
2013-01-14 02:37:50 +04:00
|
|
|
return -1;
|
2011-08-23 17:01:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "unknown cmdType 0x%X", cmdType);
|
2013-01-09 02:18:10 +04:00
|
|
|
return -1;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
2011-08-28 01:11:20 +04:00
|
|
|
|
|
|
|
size -= cmdLength;
|
|
|
|
|
|
|
|
if (update->dump_rfx)
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
/* TODO: treat return values */
|
2011-08-28 01:11:20 +04:00
|
|
|
pcap_add_record(update->pcap_rfx, mark, cmdLength + 2);
|
|
|
|
pcap_flush(update->pcap_rfx);
|
|
|
|
}
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
2013-01-09 02:18:10 +04:00
|
|
|
|
|
|
|
return 0;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd)
|
2011-08-23 19:28:28 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH))
|
|
|
|
return FALSE;
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CMDTYPE_STREAM_SURFACE_BITS);
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, cmd->destLeft);
|
|
|
|
Stream_Write_UINT16(s, cmd->destTop);
|
|
|
|
Stream_Write_UINT16(s, cmd->destRight);
|
|
|
|
Stream_Write_UINT16(s, cmd->destBottom);
|
|
|
|
Stream_Write_UINT8(s, cmd->bpp);
|
|
|
|
Stream_Write_UINT16(s, 0); /* reserved1, reserved2 */
|
|
|
|
Stream_Write_UINT8(s, cmd->codecID);
|
|
|
|
Stream_Write_UINT16(s, cmd->width);
|
|
|
|
Stream_Write_UINT16(s, cmd->height);
|
|
|
|
Stream_Write_UINT32(s, cmd->bitmapDataLength);
|
2015-04-14 11:14:23 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2011-08-23 19:28:28 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId)
|
2011-08-23 19:28:28 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH))
|
|
|
|
return FALSE;
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CMDTYPE_FRAME_MARKER);
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, frameAction);
|
|
|
|
Stream_Write_UINT32(s, frameId);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-08-23 19:28:28 +04:00
|
|
|
}
|