2014-11-21 00:19:29 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Extended Input channel server-side implementation
|
|
|
|
*
|
|
|
|
* Copyright 2014 Thincast Technologies Gmbh.
|
|
|
|
* Copyright 2014 David FORT <contact@hardening-consulting.com>
|
2015-06-09 13:46:10 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2014-11-21 00:19:29 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
|
|
|
|
#include "rdpei_main.h"
|
|
|
|
#include "../rdpei_common.h"
|
|
|
|
#include <freerdp/channels/rdpei.h>
|
|
|
|
#include <freerdp/server/rdpei.h>
|
|
|
|
|
|
|
|
/** @brief */
|
|
|
|
enum RdpEiState {
|
|
|
|
STATE_INITIAL,
|
|
|
|
STATE_WAITING_CLIENT_READY,
|
|
|
|
STATE_WAITING_FRAME,
|
|
|
|
STATE_SUSPENDED,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _rdpei_server_private
|
|
|
|
{
|
|
|
|
HANDLE channelHandle;
|
|
|
|
HANDLE eventHandle;
|
|
|
|
|
|
|
|
UINT32 expectedBytes;
|
|
|
|
BOOL waitingHeaders;
|
|
|
|
wStream *inputStream;
|
|
|
|
wStream *outputStream;
|
|
|
|
|
|
|
|
UINT16 currentMsgType;
|
|
|
|
|
|
|
|
RDPINPUT_TOUCH_EVENT touchEvent;
|
|
|
|
|
|
|
|
enum RdpEiState automataState;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RdpeiServerContext* rdpei_server_context_new(HANDLE vcm)
|
|
|
|
{
|
|
|
|
RdpeiServerContext *ret = calloc(1, sizeof(*ret));
|
|
|
|
RdpeiServerPrivate *priv;
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->priv = priv = calloc(1, sizeof(*ret->priv));
|
|
|
|
if (!priv)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
priv->inputStream = Stream_New(NULL, 256);
|
|
|
|
if (!priv->inputStream)
|
|
|
|
goto out_free_priv;
|
|
|
|
|
|
|
|
priv->outputStream = Stream_New(NULL, 200);
|
|
|
|
if (!priv->inputStream)
|
|
|
|
goto out_free_input_stream;
|
|
|
|
|
|
|
|
ret->vcm = vcm;
|
|
|
|
rdpei_server_context_reset(ret);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
out_free_input_stream:
|
|
|
|
Stream_Free(priv->inputStream, TRUE);
|
|
|
|
out_free_priv:
|
|
|
|
free(ret->priv);
|
|
|
|
out_free:
|
|
|
|
free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpei_server_init(RdpeiServerContext *context)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
void *buffer = NULL;
|
|
|
|
DWORD bytesReturned;
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
priv->channelHandle = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, RDPEI_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC);
|
|
|
|
if (!priv->channelHandle)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!");
|
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!WTSVirtualChannelQuery(priv->channelHandle, WTSVirtualEventHandle, &buffer, &bytesReturned) || (bytesReturned != sizeof(HANDLE)))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelQuery failed or invalid invalid returned size(%d)!", bytesReturned);
|
2014-11-21 00:19:29 +03:00
|
|
|
if (buffer)
|
|
|
|
WTSFreeMemory(buffer);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
CopyMemory(&priv->eventHandle, buffer, sizeof(HANDLE));
|
|
|
|
WTSFreeMemory(buffer);
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
out_close:
|
|
|
|
WTSVirtualChannelClose(priv->channelHandle);
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void rdpei_server_context_reset(RdpeiServerContext *context)
|
|
|
|
{
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
|
2014-12-10 18:47:15 +03:00
|
|
|
priv->channelHandle = INVALID_HANDLE_VALUE;
|
2014-11-21 00:19:29 +03:00
|
|
|
priv->expectedBytes = RDPINPUT_HEADER_LENGTH;
|
|
|
|
priv->waitingHeaders = TRUE;
|
|
|
|
priv->automataState = STATE_INITIAL;
|
|
|
|
Stream_SetPosition(priv->inputStream, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdpei_server_context_free(RdpeiServerContext* context)
|
|
|
|
{
|
2014-12-10 18:47:15 +03:00
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
if (priv->channelHandle != INVALID_HANDLE_VALUE)
|
|
|
|
WTSVirtualChannelClose(priv->channelHandle);
|
|
|
|
Stream_Free(priv->inputStream, TRUE);
|
|
|
|
free(priv);
|
2014-11-21 00:19:29 +03:00
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE rdpei_server_get_event_handle(RdpeiServerContext *context)
|
|
|
|
{
|
|
|
|
return context->priv->eventHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT read_cs_ready_message(RdpeiServerContext *context, wStream *s)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 10)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, context->protocolFlags);
|
|
|
|
Stream_Read_UINT32(s, context->clientVersion);
|
|
|
|
Stream_Read_UINT16(s, context->maxTouchPoints);
|
|
|
|
|
|
|
|
switch (context->clientVersion)
|
|
|
|
{
|
|
|
|
case RDPINPUT_PROTOCOL_V10:
|
|
|
|
case RDPINPUT_PROTOCOL_V101:
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "unhandled RPDEI protocol version 0x%x", context->clientVersion);
|
2014-11-21 00:19:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
IFCALLRET(context->onClientReady, error, context);
|
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->onClientReady failed with error %lu", error);
|
|
|
|
|
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT read_touch_contact_data(RdpeiServerContext *context, wStream *s, RDPINPUT_CONTACT_DATA *contactData)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Read_UINT8(s, contactData->contactId);
|
|
|
|
if (!rdpei_read_2byte_unsigned(s, &contactData->fieldsPresent) ||
|
|
|
|
!rdpei_read_4byte_signed(s, &contactData->x) ||
|
|
|
|
!rdpei_read_4byte_signed(s, &contactData->y) ||
|
|
|
|
!rdpei_read_4byte_unsigned(s, &contactData->contactFlags))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
if (contactData->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT)
|
|
|
|
{
|
|
|
|
if (!rdpei_read_2byte_signed(s, &contactData->contactRectLeft) ||
|
|
|
|
!rdpei_read_2byte_signed(s, &contactData->contactRectTop) ||
|
|
|
|
!rdpei_read_2byte_signed(s, &contactData->contactRectRight) ||
|
|
|
|
!rdpei_read_2byte_signed(s, &contactData->contactRectBottom))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((contactData->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT) &&
|
|
|
|
!rdpei_read_4byte_unsigned(s, &contactData->orientation))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
if ((contactData->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT) &&
|
|
|
|
!rdpei_read_4byte_unsigned(s, &contactData->pressure))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT read_touch_frame(RdpeiServerContext *context, wStream *s, RDPINPUT_TOUCH_FRAME *frame)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
RDPINPUT_CONTACT_DATA *contact;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
if (!rdpei_read_2byte_unsigned(s, &frame->contactCount) || !rdpei_read_8byte_unsigned(s, &frame->frameOffset))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
frame->contacts = contact = calloc(frame->contactCount, sizeof(RDPINPUT_CONTACT_DATA));
|
|
|
|
if (!frame->contacts)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
for (i = 0; i < frame->contactCount; i++, contact++)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = read_touch_contact_data(context, s, contact)))
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "read_touch_contact_data failed with error %lu!", error);
|
2014-11-21 00:19:29 +03:00
|
|
|
frame->contactCount = i;
|
2015-06-09 13:46:10 +03:00
|
|
|
touch_frame_reset(frame);
|
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT read_touch_event(RdpeiServerContext *context, wStream *s)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
UINT32 frameCount;
|
2015-06-09 13:46:10 +03:00
|
|
|
int i;
|
2014-11-21 00:19:29 +03:00
|
|
|
RDPINPUT_TOUCH_EVENT *event = &context->priv->touchEvent;
|
|
|
|
RDPINPUT_TOUCH_FRAME *frame;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
if (!rdpei_read_4byte_unsigned(s, &event->encodeTime) || !rdpei_read_2byte_unsigned(s, &frameCount))
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpei_read_ failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
event->frameCount = frameCount;
|
|
|
|
event->frames = frame = calloc(event->frameCount, sizeof(RDPINPUT_TOUCH_FRAME));
|
|
|
|
if (!event->frames)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
for (i = 0; i < frameCount; i++, frame++)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = read_touch_frame(context, s, frame)))
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "read_touch_contact_data failed with error %lu!", error);
|
2014-11-21 00:19:29 +03:00
|
|
|
event->frameCount = i;
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
IFCALLRET(context->onTouchEvent, error, context, event);
|
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->onTouchEvent failed with error %lu", error);
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
out_cleanup:
|
|
|
|
touch_event_reset(event);
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT read_dismiss_hovering_contact(RdpeiServerContext *context, wStream *s) {
|
2014-11-21 00:19:29 +03:00
|
|
|
BYTE contactId;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2015-06-09 13:46:10 +03:00
|
|
|
|
2014-11-21 00:19:29 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2015-06-09 13:46:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Read_UINT8(s, contactId);
|
2015-06-09 13:46:10 +03:00
|
|
|
|
|
|
|
IFCALLRET(context->onTouchReleased, error, context, contactId);
|
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->onTouchReleased failed with error %lu", error);
|
|
|
|
|
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpei_server_handle_messages(RdpeiServerContext *context) {
|
2014-11-21 00:19:29 +03:00
|
|
|
DWORD bytesReturned;
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
wStream *s = priv->inputStream;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
if (!WTSVirtualChannelRead(priv->channelHandle, 0, (PCHAR)Stream_Pointer(s), priv->expectedBytes, &bytesReturned))
|
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_NO_DATA)
|
2015-06-09 13:46:10 +03:00
|
|
|
return ERROR_READ_FAULT;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_DBG(TAG, "channel connection closed");
|
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
priv->expectedBytes -= bytesReturned;
|
|
|
|
Stream_Seek(s, bytesReturned);
|
|
|
|
|
|
|
|
if (priv->expectedBytes)
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_SealLength(s);
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
|
|
|
|
if (priv->waitingHeaders)
|
|
|
|
{
|
|
|
|
UINT32 pduLen;
|
|
|
|
|
|
|
|
/* header case */
|
|
|
|
Stream_Read_UINT16(s, priv->currentMsgType);
|
|
|
|
Stream_Read_UINT16(s, pduLen);
|
|
|
|
|
|
|
|
if (pduLen < RDPINPUT_HEADER_LENGTH)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "invalid pduLength %d", pduLen);
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
priv->expectedBytes = pduLen - RDPINPUT_HEADER_LENGTH;
|
|
|
|
priv->waitingHeaders = FALSE;
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
if (priv->expectedBytes)
|
|
|
|
{
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!Stream_EnsureCapacity(s, priv->expectedBytes))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when here we have the header + the body */
|
|
|
|
switch (priv->currentMsgType)
|
|
|
|
{
|
|
|
|
case EVENTID_CS_READY:
|
|
|
|
if (priv->automataState != STATE_WAITING_CLIENT_READY)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "not expecting a CS_READY packet in this state(%d)", (int)priv->automataState);
|
|
|
|
return ERROR_INVALID_STATE;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = read_cs_ready_message(context, s)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "read_cs_ready_message failed with error %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENTID_TOUCH:
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = read_touch_event(context, s)))
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "read_touch_event failed with error %lu", error);
|
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVENTID_DISMISS_HOVERING_CONTACT:
|
2015-06-09 13:46:10 +03:00
|
|
|
if ((error = read_dismiss_hovering_contact(context, s)))
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "read_dismiss_hovering_contact failed with error %lu", error);
|
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "unexpected message type 0x%x", priv->currentMsgType);
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
priv->waitingHeaders = TRUE;
|
|
|
|
priv->expectedBytes = RDPINPUT_HEADER_LENGTH;
|
2015-06-09 13:46:10 +03:00
|
|
|
return error;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpei_server_send_sc_ready(RdpeiServerContext *context, UINT32 version)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
if (priv->automataState != STATE_INITIAL)
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "called from unexpected state %d", (int)priv->automataState);
|
|
|
|
return ERROR_INVALID_STATE;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_SetPosition(priv->outputStream, 0);
|
2015-03-26 19:09:47 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH + 4))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Write_UINT16(priv->outputStream, EVENTID_SC_READY);
|
|
|
|
Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH + 4);
|
|
|
|
Stream_Write_UINT32(priv->outputStream, version);
|
|
|
|
|
|
|
|
if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream),
|
|
|
|
Stream_GetPosition(priv->outputStream), &written))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->automataState = STATE_WAITING_CLIENT_READY;
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpei_server_suspend(RdpeiServerContext *context)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
switch (priv->automataState)
|
|
|
|
{
|
|
|
|
case STATE_SUSPENDED:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "already suspended");
|
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
case STATE_WAITING_FRAME:
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "called from unexpected state %d", (int)priv->automataState);
|
|
|
|
return ERROR_INVALID_STATE;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_SetPosition(priv->outputStream, 0);
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Write_UINT16(priv->outputStream, EVENTID_SUSPEND_TOUCH);
|
|
|
|
Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH);
|
|
|
|
|
|
|
|
if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream),
|
|
|
|
Stream_GetPosition(priv->outputStream), &written))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->automataState = STATE_SUSPENDED;
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpei_server_resume(RdpeiServerContext *context)
|
2014-11-21 00:19:29 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
RdpeiServerPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
switch (priv->automataState)
|
|
|
|
{
|
|
|
|
case STATE_WAITING_FRAME:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "not suspended");
|
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
case STATE_SUSPENDED:
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "called from unexpected state %d", (int)priv->automataState);
|
|
|
|
return ERROR_INVALID_STATE;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_SetPosition(priv->outputStream, 0);
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
2014-11-21 00:19:29 +03:00
|
|
|
|
|
|
|
Stream_Write_UINT16(priv->outputStream, EVENTID_RESUME_TOUCH);
|
|
|
|
Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH);
|
|
|
|
|
|
|
|
if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream),
|
|
|
|
Stream_GetPosition(priv->outputStream), &written))
|
|
|
|
{
|
2015-06-09 13:46:10 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->automataState = STATE_WAITING_FRAME;
|
2015-06-09 13:46:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-21 00:19:29 +03:00
|
|
|
}
|
|
|
|
|