Cleaned up rdpei channel, updated to current spec.

This commit is contained in:
Armin Novak 2020-11-11 08:54:46 +01:00 committed by akallabeth
parent 95315816d9
commit d493cf6f07
8 changed files with 960 additions and 267 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,11 +34,6 @@
#define TAG CHANNELS_TAG("rdpei.client")
#define RDPINPUT_CONTACT_STATE_INITIAL 0x0000
#define RDPINPUT_CONTACT_STATE_ENGAGED 0x0001
#define RDPINPUT_CONTACT_STATE_HOVERING 0x0002
#define RDPINPUT_CONTACT_STATE_OUT_OF_RANGE 0x0003
/**
* Touch Contact State Transitions
*
@ -69,18 +64,23 @@
struct _RDPINPUT_CONTACT_POINT
{
int lastX;
int lastY;
BOOL dirty;
BOOL active;
UINT32 state;
UINT32 flags;
UINT32 contactId;
int externalId;
INT32 externalId;
RDPINPUT_CONTACT_DATA data;
};
typedef struct _RDPINPUT_CONTACT_POINT RDPINPUT_CONTACT_POINT;
struct _RDPINPUT_PEN_CONTACT_POINT
{
BOOL dirty;
BOOL active;
INT32 externalId;
RDPINPUT_PEN_CONTACT data;
};
typedef struct _RDPINPUT_PEN_CONTACT_POINT RDPINPUT_PEN_CONTACT_POINT;
#ifdef WITH_DEBUG_DVC
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
#else

View File

@ -27,7 +27,7 @@
#include "rdpei_common.h"
BOOL rdpei_read_2byte_unsigned(wStream* s, UINT32* value)
BOOL rdpei_read_2byte_unsigned(wStream* s, UINT16* value)
{
BYTE byte;
@ -53,10 +53,13 @@ BOOL rdpei_read_2byte_unsigned(wStream* s, UINT32* value)
return TRUE;
}
BOOL rdpei_write_2byte_unsigned(wStream* s, UINT32 value)
BOOL rdpei_write_2byte_unsigned(wStream* s, UINT16 value)
{
BYTE byte;
if (!Stream_EnsureRemainingCapacity(s, 2))
return FALSE;
if (value > 0x7FFF)
return FALSE;
@ -76,7 +79,7 @@ BOOL rdpei_write_2byte_unsigned(wStream* s, UINT32 value)
return TRUE;
}
BOOL rdpei_read_2byte_signed(wStream* s, INT32* value)
BOOL rdpei_read_2byte_signed(wStream* s, INT16* value)
{
BYTE byte;
BOOL negative;
@ -105,11 +108,14 @@ BOOL rdpei_read_2byte_signed(wStream* s, INT32* value)
return TRUE;
}
BOOL rdpei_write_2byte_signed(wStream* s, INT32 value)
BOOL rdpei_write_2byte_signed(wStream* s, INT16 value)
{
BYTE byte;
BOOL negative = FALSE;
if (!Stream_EnsureRemainingCapacity(s, 2))
return FALSE;
if (value < 0)
{
negative = TRUE;
@ -199,6 +205,9 @@ BOOL rdpei_write_4byte_unsigned(wStream* s, UINT32 value)
{
BYTE byte;
if (!Stream_EnsureRemainingCapacity(s, 4))
return FALSE;
if (value <= 0x3FUL)
{
Stream_Write_UINT8(s, value);
@ -300,6 +309,9 @@ BOOL rdpei_write_4byte_signed(wStream* s, INT32 value)
BYTE byte;
BOOL negative = FALSE;
if (!Stream_EnsureRemainingCapacity(s, 4))
return FALSE;
if (value < 0)
{
negative = TRUE;
@ -478,6 +490,9 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value)
{
BYTE byte;
if (!Stream_EnsureRemainingCapacity(s, 8))
return FALSE;
if (value <= 0x1FULL)
{
byte = value & 0x1F;
@ -591,7 +606,7 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value)
void touch_event_reset(RDPINPUT_TOUCH_EVENT* event)
{
int i;
UINT16 i;
for (i = 0; i < event->frameCount; i++)
touch_frame_reset(&event->frames[i]);
@ -607,3 +622,22 @@ void touch_frame_reset(RDPINPUT_TOUCH_FRAME* frame)
frame->contacts = NULL;
frame->contactCount = 0;
}
void pen_event_reset(RDPINPUT_PEN_EVENT* event)
{
UINT16 i;
for (i = 0; i < event->frameCount; i++)
pen_frame_reset(&event->frames[i]);
free(event->frames);
event->frames = NULL;
event->frameCount = 0;
}
void pen_frame_reset(RDPINPUT_PEN_FRAME* frame)
{
free(frame->contacts);
frame->contacts = NULL;
frame->contactCount = 0;
}

View File

@ -33,13 +33,14 @@ enum
EVENTID_TOUCH = 0x0003,
EVENTID_SUSPEND_TOUCH = 0x0004,
EVENTID_RESUME_TOUCH = 0x0005,
EVENTID_DISMISS_HOVERING_CONTACT = 0x0006
EVENTID_DISMISS_HOVERING_CONTACT = 0x0006,
EVENTID_PEN = 0x0008
};
BOOL rdpei_read_2byte_unsigned(wStream* s, UINT32* value);
BOOL rdpei_write_2byte_unsigned(wStream* s, UINT32 value);
BOOL rdpei_read_2byte_signed(wStream* s, INT32* value);
BOOL rdpei_write_2byte_signed(wStream* s, INT32 value);
BOOL rdpei_read_2byte_unsigned(wStream* s, UINT16* value);
BOOL rdpei_write_2byte_unsigned(wStream* s, UINT16 value);
BOOL rdpei_read_2byte_signed(wStream* s, INT16* value);
BOOL rdpei_write_2byte_signed(wStream* s, INT16 value);
BOOL rdpei_read_4byte_unsigned(wStream* s, UINT32* value);
BOOL rdpei_write_4byte_unsigned(wStream* s, UINT32 value);
BOOL rdpei_read_4byte_signed(wStream* s, INT32* value);
@ -50,4 +51,7 @@ BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value);
void touch_event_reset(RDPINPUT_TOUCH_EVENT* event);
void touch_frame_reset(RDPINPUT_TOUCH_FRAME* frame);
void pen_event_reset(RDPINPUT_PEN_EVENT* event);
void pen_frame_reset(RDPINPUT_PEN_FRAME* frame);
#endif /* FREERDP_CHANNEL_RDPEI_COMMON_H */

View File

@ -55,6 +55,7 @@ struct _rdpei_server_private
UINT16 currentMsgType;
RDPINPUT_TOUCH_EVENT touchEvent;
RDPINPUT_PEN_EVENT penEvent;
enum RdpEiState automataState;
};
@ -69,26 +70,22 @@ RdpeiServerContext* rdpei_server_context_new(HANDLE vcm)
ret->priv = priv = calloc(1, sizeof(*ret->priv));
if (!priv)
goto out_free;
goto fail;
priv->inputStream = Stream_New(NULL, 256);
if (!priv->inputStream)
goto out_free_priv;
goto fail;
priv->outputStream = Stream_New(NULL, 200);
if (!priv->inputStream)
goto out_free_input_stream;
goto fail;
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);
fail:
rdpei_server_context_free(ret);
return NULL;
}
@ -145,10 +142,17 @@ void rdpei_server_context_reset(RdpeiServerContext* context)
void rdpei_server_context_free(RdpeiServerContext* context)
{
RdpeiServerPrivate* priv = context->priv;
RdpeiServerPrivate* priv;
if (!context)
return;
priv = context->priv;
if (priv)
{
if (priv->channelHandle != INVALID_HANDLE_VALUE)
WTSVirtualChannelClose(priv->channelHandle);
Stream_Free(priv->inputStream, TRUE);
}
free(priv);
free(context);
}
@ -180,6 +184,8 @@ static UINT read_cs_ready_message(RdpeiServerContext* context, wStream* s)
{
case RDPINPUT_PROTOCOL_V10:
case RDPINPUT_PROTOCOL_V101:
case RDPINPUT_PROTOCOL_V200:
case RDPINPUT_PROTOCOL_V300:
break;
default:
WLog_ERR(TAG, "unhandled RPDEI protocol version 0x%" PRIx32 "", context->clientVersion);
@ -201,6 +207,7 @@ static UINT read_cs_ready_message(RdpeiServerContext* context, wStream* s)
static UINT read_touch_contact_data(RdpeiServerContext* context, wStream* s,
RDPINPUT_CONTACT_DATA* contactData)
{
WINPR_UNUSED(context);
if (Stream_GetRemainingLength(s) < 1)
{
WLog_ERR(TAG, "Not enough data!");
@ -246,6 +253,55 @@ static UINT read_touch_contact_data(RdpeiServerContext* context, wStream* s,
return CHANNEL_RC_OK;
}
static UINT read_pen_contact(RdpeiServerContext* context, wStream* s,
RDPINPUT_PEN_CONTACT* contactData)
{
WINPR_UNUSED(context);
if (Stream_GetRemainingLength(s) < 1)
{
WLog_ERR(TAG, "Not enough data!");
return ERROR_INVALID_DATA;
}
Stream_Read_UINT8(s, contactData->deviceId);
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))
{
WLog_ERR(TAG, "rdpei_read_ failed!");
return ERROR_INTERNAL_ERROR;
}
if (contactData->fieldsPresent & PEN_CONTACT_PENFLAGS_PRESENT)
{
if (!rdpei_read_4byte_unsigned(s, &contactData->penFlags))
return ERROR_INVALID_DATA;
}
if (contactData->fieldsPresent & PEN_CONTACT_PRESSURE_PRESENT)
{
if (!rdpei_read_4byte_unsigned(s, &contactData->pressure))
return ERROR_INVALID_DATA;
}
if (contactData->fieldsPresent & PEN_CONTACT_ROTATION_PRESENT)
{
if (!rdpei_read_2byte_unsigned(s, &contactData->rotation))
return ERROR_INVALID_DATA;
}
if (contactData->fieldsPresent & PEN_CONTACT_TILTX_PRESENT)
{
if (!rdpei_read_2byte_signed(s, &contactData->tiltX))
return ERROR_INVALID_DATA;
}
if (contactData->fieldsPresent & PEN_CONTACT_TILTY_PRESENT)
{
if (!rdpei_read_2byte_signed(s, &contactData->tiltY))
return ERROR_INVALID_DATA;
}
return CHANNEL_RC_OK;
}
/**
* Function description
*
@ -284,6 +340,39 @@ static UINT read_touch_frame(RdpeiServerContext* context, wStream* s, RDPINPUT_T
return CHANNEL_RC_OK;
}
static UINT read_pen_frame(RdpeiServerContext* context, wStream* s, RDPINPUT_PEN_FRAME* frame)
{
UINT32 i;
RDPINPUT_PEN_CONTACT* contact;
UINT error;
if (!rdpei_read_2byte_unsigned(s, &frame->contactCount) ||
!rdpei_read_8byte_unsigned(s, &frame->frameOffset))
{
WLog_ERR(TAG, "rdpei_read_ failed!");
return ERROR_INTERNAL_ERROR;
}
frame->contacts = contact = calloc(frame->contactCount, sizeof(RDPINPUT_CONTACT_DATA));
if (!frame->contacts)
{
WLog_ERR(TAG, "calloc failed!");
return CHANNEL_RC_NO_MEMORY;
}
for (i = 0; i < frame->contactCount; i++, contact++)
{
if ((error = read_pen_contact(context, s, contact)))
{
WLog_ERR(TAG, "read_touch_contact_data failed with error %" PRIu32 "!", error);
frame->contactCount = i;
pen_frame_reset(frame);
return error;
}
}
return CHANNEL_RC_OK;
}
/**
* Function description
*
@ -291,7 +380,7 @@ static UINT read_touch_frame(RdpeiServerContext* context, wStream* s, RDPINPUT_T
*/
static UINT read_touch_event(RdpeiServerContext* context, wStream* s)
{
UINT32 frameCount;
UINT16 frameCount;
UINT32 i;
RDPINPUT_TOUCH_EVENT* event = &context->priv->touchEvent;
RDPINPUT_TOUCH_FRAME* frame;
@ -331,6 +420,48 @@ out_cleanup:
return error;
}
static UINT read_pen_event(RdpeiServerContext* context, wStream* s)
{
UINT16 frameCount;
UINT32 i;
RDPINPUT_PEN_EVENT* event = &context->priv->penEvent;
RDPINPUT_PEN_FRAME* frame;
UINT error = CHANNEL_RC_OK;
if (!rdpei_read_4byte_unsigned(s, &event->encodeTime) ||
!rdpei_read_2byte_unsigned(s, &frameCount))
{
WLog_ERR(TAG, "rdpei_read_ failed!");
return ERROR_INTERNAL_ERROR;
}
event->frameCount = frameCount;
event->frames = frame = calloc(event->frameCount, sizeof(RDPINPUT_PEN_FRAME));
if (!event->frames)
{
WLog_ERR(TAG, "calloc failed!");
return CHANNEL_RC_NO_MEMORY;
}
for (i = 0; i < frameCount; i++, frame++)
{
if ((error = read_pen_frame(context, s, frame)))
{
WLog_ERR(TAG, "read_pen_frame failed with error %" PRIu32 "!", error);
event->frameCount = i;
goto out_cleanup;
}
}
IFCALLRET(context->onPenEvent, error, context, event);
if (error)
WLog_ERR(TAG, "context->onPenEvent failed with error %" PRIu32 "", error);
out_cleanup:
pen_event_reset(event);
return error;
}
/**
* Function description
*
@ -445,6 +576,13 @@ UINT rdpei_server_handle_messages(RdpeiServerContext* context)
return error;
}
break;
case EVENTID_PEN:
if ((error = read_pen_event(context, s)))
{
WLog_ERR(TAG, "read_pen_event failed with error %" PRIu32 "", error);
return error;
}
break;
default:
WLog_ERR(TAG, "unexpected message type 0x%" PRIx16 "", priv->currentMsgType);
}
@ -460,7 +598,7 @@ UINT rdpei_server_handle_messages(RdpeiServerContext* context)
*
* @return 0 on success, otherwise a Win32 error code
*/
UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version)
UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version, UINT32 features)
{
ULONG written;
RdpeiServerPrivate* priv = context->priv;
@ -482,6 +620,8 @@ UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version)
Stream_Write_UINT16(priv->outputStream, EVENTID_SC_READY);
Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH + 4);
Stream_Write_UINT32(priv->outputStream, version);
if (version >= RDPINPUT_PROTOCOL_V300)
Stream_Write_UINT32(priv->outputStream, features);
if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream),
Stream_GetPosition(priv->outputStream), &written))

View File

@ -32,36 +32,58 @@
enum
{
RDPINPUT_PROTOCOL_V10 = 0x00010000,
RDPINPUT_PROTOCOL_V101 = 0x00010001
RDPINPUT_PROTOCOL_V101 = 0x00010001,
RDPINPUT_PROTOCOL_V200 = 0x00020000,
RDPINPUT_PROTOCOL_V300 = 0x00030000
};
/* Client Ready Flags */
#define READY_FLAGS_SHOW_TOUCH_VISUALS 0x00000001
#define READY_FLAGS_DISABLE_TIMESTAMP_INJECTION 0x00000002
#define CS_READY_FLAGS_SHOW_TOUCH_VISUALS 0x00000001
#define CS_READY_FLAGS_DISABLE_TIMESTAMP_INJECTION 0x00000002
#define CS_READY_FLAGS_ENABLE_MULTIPEN_INJECTION 0x00000004
#define CONTACT_DATA_CONTACTRECT_PRESENT 0x0001
#define CONTACT_DATA_ORIENTATION_PRESENT 0x0002
#define CONTACT_DATA_PRESSURE_PRESENT 0x0004
#define CONTACT_FLAG_DOWN 0x0001
#define CONTACT_FLAG_UPDATE 0x0002
#define CONTACT_FLAG_UP 0x0004
#define CONTACT_FLAG_INRANGE 0x0008
#define CONTACT_FLAG_INCONTACT 0x0010
#define CONTACT_FLAG_CANCELED 0x0020
typedef enum
{
PEN_CONTACT_PENFLAGS_PRESENT = 0x0001,
PEN_CONTACT_PRESSURE_PRESENT = 0x0002,
PEN_CONTACT_ROTATION_PRESENT = 0x0004,
PEN_CONTACT_TILTX_PRESENT = 0x0008,
PEN_CONTACT_TILTY_PRESENT = 0x0010
} RDPINPUT_PEN_FIELDS_PRESENT;
typedef enum
{
CONTACT_FLAG_DOWN = 0x0001,
CONTACT_FLAG_UPDATE = 0x0002,
CONTACT_FLAG_UP = 0x0004,
CONTACT_FLAG_INRANGE = 0x0008,
CONTACT_FLAG_INCONTACT = 0x0010,
CONTACT_FLAG_CANCELED = 0x0020
} RDPINPUT_CONTACT_FLAGS;
typedef enum
{
PEN_FLAG_BARREL_PRESSED = 0x0001,
PEN_FLAG_ERASER_PRESSED = 0x0002,
PEN_FLAG_INVERTED = 0x0004
} RDPINPUT_PEN_FLAGS;
/** @brief a contact point */
struct _RDPINPUT_CONTACT_DATA
{
UINT32 contactId;
UINT32 fieldsPresent;
UINT16 fieldsPresent;
INT32 x;
INT32 y;
UINT32 contactFlags;
INT32 contactRectLeft;
INT32 contactRectTop;
INT32 contactRectRight;
INT32 contactRectBottom;
INT16 contactRectLeft;
INT16 contactRectTop;
INT16 contactRectRight;
INT16 contactRectBottom;
UINT32 orientation;
UINT32 pressure;
};
@ -70,7 +92,7 @@ typedef struct _RDPINPUT_CONTACT_DATA RDPINPUT_CONTACT_DATA;
/** @brief a frame containing contact points */
struct _RDPINPUT_TOUCH_FRAME
{
UINT32 contactCount;
UINT16 contactCount;
UINT64 frameOffset;
RDPINPUT_CONTACT_DATA* contacts;
};
@ -85,4 +107,35 @@ struct _RDPINPUT_TOUCH_EVENT
};
typedef struct _RDPINPUT_TOUCH_EVENT RDPINPUT_TOUCH_EVENT;
struct _RDPINPUT_PEN_CONTACT
{
UINT8 deviceId;
UINT16 fieldsPresent;
INT32 x;
INT32 y;
UINT32 contactFlags;
UINT32 penFlags;
UINT32 pressure;
UINT16 rotation;
INT16 tiltX;
INT16 tiltY;
};
typedef struct _RDPINPUT_PEN_CONTACT RDPINPUT_PEN_CONTACT;
struct _RDPINPUT_PEN_FRAME
{
UINT16 contactCount;
UINT64 frameOffset;
RDPINPUT_PEN_CONTACT* contacts;
};
typedef struct _RDPINPUT_PEN_FRAME RDPINPUT_PEN_FRAME;
/** @brief a touch event with some frames*/
struct _RDPINPUT_PEN_EVENT
{
UINT32 encodeTime;
UINT16 frameCount;
RDPINPUT_PEN_FRAME* frames;
};
typedef struct _RDPINPUT_PEN_EVENT RDPINPUT_PEN_EVENT;
#endif /* FREERDP_CHANNEL_RDPEI_H */

View File

@ -30,16 +30,23 @@
typedef struct _rdpei_client_context RdpeiClientContext;
typedef int (*pcRdpeiGetVersion)(RdpeiClientContext* context);
typedef UINT32 (*pcRdpeiGetVersion)(RdpeiClientContext* context);
typedef UINT32 (*pcRdpeiGetFeatures)(RdpeiClientContext* context);
typedef UINT (*pcRdpeiAddContact)(RdpeiClientContext* context,
const RDPINPUT_CONTACT_DATA* contact);
typedef UINT (*pcRdpeiTouchBegin)(RdpeiClientContext* context, int externalId, int x, int y,
int* contactId);
typedef UINT (*pcRdpeiTouchUpdate)(RdpeiClientContext* context, int externalId, int x, int y,
int* contactId);
typedef UINT (*pcRdpeiTouchEnd)(RdpeiClientContext* context, int externalId, int x, int y,
int* contactId);
typedef UINT (*pcRdpeiTouchBegin)(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
INT32* contactId);
typedef UINT (*pcRdpeiTouchUpdate)(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
INT32* contactId);
typedef UINT (*pcRdpeiTouchEnd)(RdpeiClientContext* context, INT32 externalId, INT32 x, INT32 y,
INT32* contactId);
typedef UINT (*pcRdpeiAddPen)(RdpeiClientContext* context, INT32 externalId,
const RDPINPUT_PEN_CONTACT* contact);
typedef UINT (*pcRdpeiPen)(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags,
INT32 x, INT32 y, ...);
typedef UINT (*pcRdpeiSuspendTouch)(RdpeiClientContext* context);
typedef UINT (*pcRdpeiResumeTouch)(RdpeiClientContext* context);
@ -50,6 +57,7 @@ struct _rdpei_client_context
void* custom;
pcRdpeiGetVersion GetVersion;
pcRdpeiGetFeatures GetFeatures;
pcRdpeiAddContact AddContact;
@ -57,6 +65,12 @@ struct _rdpei_client_context
pcRdpeiTouchUpdate TouchUpdate;
pcRdpeiTouchEnd TouchEnd;
pcRdpeiAddPen AddPen;
pcRdpeiPen PenBegin;
pcRdpeiPen PenUpdate;
pcRdpeiPen PenEnd;
pcRdpeiSuspendTouch SuspendTouch;
pcRdpeiResumeTouch ResumeTouch;
};

View File

@ -41,7 +41,8 @@ struct _rdpei_server_context
/** callbacks that can be set by the user */
UINT (*onClientReady)(RdpeiServerContext* context);
UINT (*onTouchEvent)(RdpeiServerContext* context, RDPINPUT_TOUCH_EVENT* touchEvent);
UINT (*onTouchEvent)(RdpeiServerContext* context, const RDPINPUT_TOUCH_EVENT* touchEvent);
UINT (*onPenEvent)(RdpeiServerContext* context, const RDPINPUT_PEN_EVENT* penEvent);
UINT (*onTouchReleased)(RdpeiServerContext* context, BYTE contactId);
void* user_data; /* user data, useful for callbacks */
@ -59,7 +60,8 @@ extern "C"
FREERDP_API UINT rdpei_server_init(RdpeiServerContext* context);
FREERDP_API UINT rdpei_server_handle_messages(RdpeiServerContext* context);
FREERDP_API UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version);
FREERDP_API UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version,
UINT32 features);
FREERDP_API UINT rdpei_server_suspend(RdpeiServerContext* context);
FREERDP_API UINT rdpei_server_resume(RdpeiServerContext* context);