Merge pull request #4755 from akallabeth/dyn_resize_fix

Fixed #4679, #4753 dynamic resizing
This commit is contained in:
Martin Fleisz 2018-07-30 12:28:38 +02:00 committed by GitHub
commit 143a2b149a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 312 additions and 237 deletions

View File

@ -1295,6 +1295,10 @@ static void xf_post_disconnect(freerdp* instance)
context = instance->context;
xfc = (xfContext*) context;
PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
xf_OnChannelConnectedEventHandler);
PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
xf_OnChannelDisconnectedEventHandler);
gdi_free(instance);
if (xfc->clipboard)
@ -1532,12 +1536,9 @@ static DWORD WINAPI xf_client_thread(LPVOID param)
goto disconnect;
}
handles[0] = timer;
if (!settings->AsyncInput)
{
inputEvent = xfc->x11event;
handles[1] = inputEvent;
}
else
{
@ -1551,6 +1552,12 @@ static DWORD WINAPI xf_client_thread(LPVOID param)
while (!freerdp_shall_disconnect(instance))
{
nCount = 0;
handles[nCount++] = timer;
if (!settings->AsyncInput)
handles[nCount++] = inputEvent;
/*
* win8 and server 2k12 seem to have some timing issue/race condition
* when a initial sync request is send to sync the keyboard indicators
@ -1562,11 +1569,9 @@ static DWORD WINAPI xf_client_thread(LPVOID param)
xf_keyboard_focus_in(xfc);
}
nCount = (settings->AsyncInput) ? 1 : 2;
if (!settings->AsyncTransport)
{
DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);
DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], ARRAYSIZE(handles) - nCount);
if (tmp == 0)
{
@ -1941,6 +1946,15 @@ static void xfreerdp_client_free(freerdp* instance, rdpContext* context)
if (!context)
return;
PubSub_UnsubscribeTerminate(context->pubSub,
xf_TerminateEventHandler);
#ifdef WITH_XRENDER
PubSub_UnsubscribeZoomingChange(context->pubSub,
xf_ZoomingChangeEventHandler);
PubSub_UnsubscribePanningChange(context->pubSub,
xf_PanningChangeEventHandler);
#endif
if (xfc->display)
{
XCloseDisplay(xfc->display);

View File

@ -39,7 +39,7 @@
struct _xfDispContext
{
xfContext *xfc;
xfContext* xfc;
BOOL haveXRandr;
int eventBase, errorBase;
int lastSentWidth, lastSentHeight;
@ -47,37 +47,83 @@ struct _xfDispContext
int targetWidth, targetHeight;
BOOL activated;
BOOL waitingResize;
UINT16 lastSentDesktopOrientation;
UINT32 lastSentDesktopScaleFactor;
UINT32 lastSentDeviceScaleFactor;
};
static BOOL xf_disp_settings_changed(xfDispContext* xfDisp)
{
rdpSettings* settings;
settings = xfDisp->xfc->context.settings;
static BOOL xf_disp_sendResize(xfDispContext *xfDisp, int width, int height)
if (xfDisp->lastSentWidth != xfDisp->targetWidth)
return TRUE;
if (xfDisp->lastSentHeight != xfDisp->targetHeight)
return TRUE;
if (xfDisp->lastSentDesktopOrientation != settings->DesktopOrientation)
return TRUE;
if (xfDisp->lastSentDesktopScaleFactor != settings->DesktopScaleFactor)
return TRUE;
if (xfDisp->lastSentDeviceScaleFactor != settings->DeviceScaleFactor)
return TRUE;
return FALSE;
}
static BOOL xf_update_last_sent(xfDispContext* xfDisp)
{
rdpSettings* settings = xfDisp->xfc->context.settings;
xfDisp->lastSentWidth = xfDisp->targetWidth;
xfDisp->lastSentHeight = xfDisp->targetHeight;
xfDisp->lastSentDesktopOrientation = settings->DesktopOrientation;
xfDisp->lastSentDesktopScaleFactor = settings->DesktopScaleFactor;
xfDisp->lastSentDeviceScaleFactor = settings->DeviceScaleFactor;
return TRUE;
}
static BOOL xf_disp_sendResize(xfDispContext* xfDisp)
{
DISPLAY_CONTROL_MONITOR_LAYOUT layout;
xfContext *xfc = xfDisp->xfc;
rdpSettings *settings = xfc->context.settings;
xfContext* xfc = xfDisp->xfc;
rdpSettings* settings = xfc->context.settings;
if (!xfDisp->activated)
return TRUE;
if (GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY)
return TRUE;
xfDisp->lastSentDate = GetTickCount64();
xfDisp->lastSentWidth = width;
xfDisp->lastSentHeight = height;
xfDisp->waitingResize = TRUE;
if (!xf_disp_settings_changed(xfDisp))
return TRUE;
xfDisp->waitingResize = TRUE;
layout.Flags = DISPLAY_CONTROL_MONITOR_PRIMARY;
layout.Top = layout.Left = 0;
layout.Width = width;
layout.Height = height;
layout.Orientation = ORIENTATION_LANDSCAPE;
layout.Width = xfDisp->targetWidth;
layout.Height = xfDisp->targetHeight;
layout.Orientation = settings->DesktopOrientation;
layout.DesktopScaleFactor = settings->DesktopScaleFactor;
layout.DeviceScaleFactor = settings->DeviceScaleFactor;
layout.PhysicalWidth = width;
layout.PhysicalHeight = height;
layout.PhysicalWidth = xfDisp->targetWidth;
layout.PhysicalHeight = xfDisp->targetHeight;
return xfc->disp->SendMonitorLayout(xfc->disp, 1, &layout) == CHANNEL_RC_OK;
if (xfc->disp->SendMonitorLayout(xfc->disp, 1, &layout) != CHANNEL_RC_OK)
return FALSE;
return xf_update_last_sent(xfDisp);
}
static BOOL xf_disp_set_window_resizable(xfDispContext *xfDisp)
static BOOL xf_disp_set_window_resizable(xfDispContext* xfDisp)
{
XSizeHints *size_hints;
XSizeHints* size_hints;
if (!(size_hints = XAllocSizeHints()))
return FALSE;
@ -86,8 +132,10 @@ static BOOL xf_disp_set_window_resizable(xfDispContext *xfDisp)
size_hints->win_gravity = NorthWestGravity;
size_hints->min_width = size_hints->min_height = 320;
size_hints->max_width = size_hints->max_height = 8192;
if (xfDisp->xfc->window)
XSetWMNormalHints(xfDisp->xfc->display, xfDisp->xfc->window->handle, size_hints);
XFree(size_hints);
return TRUE;
}
@ -95,10 +143,9 @@ static BOOL xf_disp_set_window_resizable(xfDispContext *xfDisp)
static void xf_disp_OnActivated(void* context, ActivatedEventArgs* e)
{
xfContext *xfc = (xfContext *)context;
xfDispContext *xfDisp = xfc->xfDisp;
rdpSettings *settings = xfc->context.settings;
xfContext* xfc = (xfContext*)context;
xfDispContext* xfDisp = xfc->xfDisp;
rdpSettings* settings = xfc->context.settings;
xfDisp->waitingResize = FALSE;
if (xfDisp->activated && !settings->Fullscreen)
@ -108,102 +155,78 @@ static void xf_disp_OnActivated(void* context, ActivatedEventArgs* e)
if (e->firstActivation)
return;
/* if a resize has been done recently don't do anything and let the timer
* perform the resize */
if (GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY)
return;
if ((xfDisp->lastSentWidth != xfDisp->targetWidth) || (xfDisp->lastSentHeight != xfDisp->targetHeight))
{
WLog_DBG(TAG, "performing delayed resize to %dx%d", xfDisp->targetWidth, xfDisp->targetHeight);
xf_disp_sendResize(xfDisp, xfDisp->targetWidth, xfDisp->targetHeight);
}
xf_disp_sendResize(xfDisp);
}
}
static void xf_disp_OnGraphicsReset(void* context, GraphicsResetEventArgs* e)
{
xfContext *xfc = (xfContext *)context;
xfDispContext *xfDisp = xfc->xfDisp;
rdpSettings *settings = xfc->context.settings;
xfContext* xfc = (xfContext*)context;
xfDispContext* xfDisp = xfc->xfDisp;
rdpSettings* settings = xfc->context.settings;
xfDisp->waitingResize = FALSE;
if (xfDisp->activated && !settings->Fullscreen)
{
xf_disp_set_window_resizable(xfDisp);
/* if a resize has been done recently don't do anything and let the timer
* perform the resize */
if (GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY)
return;
if ((xfDisp->lastSentWidth != xfDisp->targetWidth) || (xfDisp->lastSentHeight != xfDisp->targetHeight))
{
WLog_DBG(TAG, "performing delayed resize to %dx%d", xfDisp->targetWidth, xfDisp->targetHeight);
xf_disp_sendResize(xfDisp, xfDisp->targetWidth, xfDisp->targetHeight);
}
xf_disp_sendResize(xfDisp);
}
}
static void xf_disp_OnTimer(void* context, TimerEventArgs* e)
{
xfContext *xfc = (xfContext *)context;
xfDispContext *xfDisp = xfc->xfDisp;
rdpSettings *settings = xfc->context.settings;
xfContext* xfc = (xfContext*)context;
xfDispContext* xfDisp = xfc->xfDisp;
rdpSettings* settings = xfc->context.settings;
if (!xfDisp->activated || settings->Fullscreen)
return;
if (e->now - xfDisp->lastSentDate < RESIZE_MIN_DELAY)
return;
if ((xfDisp->lastSentWidth != xfDisp->targetWidth) || (xfDisp->lastSentHeight != xfDisp->targetHeight))
{
WLog_DBG(TAG, "timer performing delayed resize to %dx%d", xfDisp->targetWidth, xfDisp->targetHeight);
xf_disp_sendResize(xfDisp, xfDisp->targetWidth, xfDisp->targetHeight);
}
xf_disp_sendResize(xfDisp);
}
xfDispContext *xf_disp_new(xfContext* xfc)
xfDispContext* xf_disp_new(xfContext* xfc)
{
xfDispContext *ret = calloc(1, sizeof(xfDispContext));
xfDispContext* ret = calloc(1, sizeof(xfDispContext));
if (!ret)
return NULL;
ret->xfc = xfc;
#ifdef USABLE_XRANDR
if (XRRQueryExtension(xfc->display, &ret->eventBase, &ret->errorBase))
{
ret->haveXRandr = TRUE;
}
#endif
ret->lastSentWidth = ret->targetWidth = xfc->context.settings->DesktopWidth;
ret->lastSentHeight = ret->targetHeight = xfc->context.settings->DesktopHeight;
PubSub_SubscribeActivated(xfc->context.pubSub, xf_disp_OnActivated);
PubSub_SubscribeGraphicsReset(xfc->context.pubSub, xf_disp_OnGraphicsReset);
PubSub_SubscribeTimer(xfc->context.pubSub, xf_disp_OnTimer);
return ret;
}
void xf_disp_free(xfDispContext *disp)
void xf_disp_free(xfDispContext* disp)
{
PubSub_UnsubscribeActivated(disp->xfc->context.pubSub, xf_disp_OnActivated);
PubSub_UnsubscribeGraphicsReset(disp->xfc->context.pubSub, xf_disp_OnGraphicsReset);
PubSub_UnsubscribeTimer(disp->xfc->context.pubSub, xf_disp_OnTimer);
free(disp);
}
static UINT xf_disp_sendLayout(DispClientContext *disp, rdpMonitor *monitors, int nmonitors)
static UINT xf_disp_sendLayout(DispClientContext* disp, rdpMonitor* monitors, int nmonitors)
{
UINT ret = CHANNEL_RC_OK;
DISPLAY_CONTROL_MONITOR_LAYOUT *layouts;
DISPLAY_CONTROL_MONITOR_LAYOUT* layouts;
int i;
xfDispContext *xfDisp = (xfDispContext *)disp->custom;
rdpSettings *settings = xfDisp->xfc->context.settings;
xfDispContext* xfDisp = (xfDispContext*)disp->custom;
rdpSettings* settings = xfDisp->xfc->context.settings;
layouts = calloc(nmonitors, sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT));
if (!layouts)
return CHANNEL_RC_NO_MEMORY;
@ -218,89 +241,81 @@ static UINT xf_disp_sendLayout(DispClientContext *disp, rdpMonitor *monitors, in
layouts[i].PhysicalWidth = monitors[i].attributes.physicalWidth;
layouts[i].PhysicalHeight = monitors[i].attributes.physicalHeight;
switch(monitors[i].attributes.orientation)
switch (monitors[i].attributes.orientation)
{
case 90:
layouts[i].Orientation = ORIENTATION_PORTRAIT;
break;
case 180:
layouts[i].Orientation = ORIENTATION_LANDSCAPE_FLIPPED;
break;
case 270:
layouts[i].Orientation = ORIENTATION_PORTRAIT_FLIPPED;
break;
case 0:
default:
/* MS-RDPEDISP - 2.2.2.2.1:
* Orientation (4 bytes): A 32-bit unsigned integer that specifies the
* orientation of the monitor in degrees. Valid values are 0, 90, 180
* or 270
*
* So we default to ORIENTATION_LANDSCAPE
*/
layouts[i].Orientation = ORIENTATION_LANDSCAPE;
break;
case 90:
layouts[i].Orientation = ORIENTATION_PORTRAIT;
break;
case 180:
layouts[i].Orientation = ORIENTATION_LANDSCAPE_FLIPPED;
break;
case 270:
layouts[i].Orientation = ORIENTATION_PORTRAIT_FLIPPED;
break;
case 0:
default:
/* MS-RDPEDISP - 2.2.2.2.1:
* Orientation (4 bytes): A 32-bit unsigned integer that specifies the
* orientation of the monitor in degrees. Valid values are 0, 90, 180
* or 270
*
* So we default to ORIENTATION_LANDSCAPE
*/
layouts[i].Orientation = ORIENTATION_LANDSCAPE;
break;
}
layouts[i].DesktopScaleFactor = settings->DesktopScaleFactor;
layouts[i].DeviceScaleFactor = settings->DeviceScaleFactor;
}
ret = disp->SendMonitorLayout(disp, nmonitors, layouts);
free(layouts);
return ret;
}
BOOL xf_disp_handle_xevent(xfContext *xfc, XEvent *event)
BOOL xf_disp_handle_xevent(xfContext* xfc, XEvent* event)
{
xfDispContext *xfDisp = xfc->xfDisp;
rdpSettings *settings = xfc->context.settings;
xfDispContext* xfDisp = xfc->xfDisp;
rdpSettings* settings = xfc->context.settings;
UINT32 maxWidth, maxHeight;
if (!xfDisp->haveXRandr)
return TRUE;
#ifdef USABLE_XRANDR
if (event->type != xfDisp->eventBase + RRScreenChangeNotify)
return TRUE;
#endif
xf_detect_monitors(xfc, &maxWidth, &maxHeight);
return xf_disp_sendLayout(xfc->disp, settings->MonitorDefArray, settings->MonitorCount) == CHANNEL_RC_OK;
return xf_disp_sendLayout(xfc->disp, settings->MonitorDefArray,
settings->MonitorCount) == CHANNEL_RC_OK;
}
BOOL xf_disp_handle_configureNotify(xfContext *xfc, int width, int height)
BOOL xf_disp_handle_configureNotify(xfContext* xfc, int width, int height)
{
xfDispContext *xfDisp = xfc->xfDisp;
if (xfDisp->lastSentWidth == width && xfDisp->lastSentHeight == height)
return TRUE;
if (xfDisp->waitingResize || !xfDisp->activated ||
(GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY))
{
WLog_DBG(TAG, "delaying resize to %dx%d", width, height);
xfDisp->targetWidth = width;
xfDisp->targetHeight = height;
return TRUE;
}
WLog_DBG(TAG, "resizing on ConfigureNotify to %dx%d", width, height);
return xf_disp_sendResize(xfDisp, width, height);
xfDispContext* xfDisp = xfc->xfDisp;
xfDisp->targetWidth = width;
xfDisp->targetHeight = height;
return xf_disp_sendResize(xfDisp);
}
UINT xf_DisplayControlCaps(DispClientContext *disp, UINT32 maxNumMonitors, UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB)
UINT xf_DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors,
UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB)
{
/* we're called only if dynamic resolution update is activated */
xfDispContext *xfDisp = (xfDispContext *)disp->custom;
rdpSettings *settings = xfDisp->xfc->context.settings;
WLog_DBG(TAG, "DisplayControlCapsPdu: MaxNumMonitors: %"PRIu32" MaxMonitorAreaFactorA: %"PRIu32" MaxMonitorAreaFactorB: %"PRIu32"",
maxNumMonitors, maxMonitorAreaFactorA, maxMonitorAreaFactorB);
xfDispContext* xfDisp = (xfDispContext*)disp->custom;
rdpSettings* settings = xfDisp->xfc->context.settings;
WLog_DBG(TAG,
"DisplayControlCapsPdu: MaxNumMonitors: %"PRIu32" MaxMonitorAreaFactorA: %"PRIu32" MaxMonitorAreaFactorB: %"PRIu32"",
maxNumMonitors, maxMonitorAreaFactorA, maxMonitorAreaFactorB);
xfDisp->activated = TRUE;
if (settings->Fullscreen)
@ -310,9 +325,9 @@ UINT xf_DisplayControlCaps(DispClientContext *disp, UINT32 maxNumMonitors, UINT3
return xf_disp_set_window_resizable(xfDisp) ? CHANNEL_RC_OK : CHANNEL_RC_NO_MEMORY;
}
BOOL xf_disp_init(xfContext* xfc, DispClientContext *disp)
BOOL xf_disp_init(xfContext* xfc, DispClientContext* disp)
{
rdpSettings *settings = xfc->context.settings;
rdpSettings* settings = xfc->context.settings;
xfc->disp = disp;
disp->custom = (void*) xfc->xfDisp;
@ -320,11 +335,13 @@ BOOL xf_disp_init(xfContext* xfc, DispClientContext *disp)
{
disp->DisplayControlCaps = xf_DisplayControlCaps;
#ifdef USABLE_XRANDR
if (settings->Fullscreen)
{
/* ask X11 to notify us of screen changes */
XRRSelectInput(xfc->display, DefaultRootWindow(xfc->display), RRScreenChangeNotifyMask);
}
#endif
}

View File

@ -49,7 +49,7 @@
#define TAG FREERDP_TAG("core.channels")
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, const BYTE* data, int size)
{
DWORD i;
int left;

View File

@ -24,7 +24,7 @@
#include "client.h"
FREERDP_LOCAL BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId,
BYTE* data, int size);
const BYTE* data, int size);
FREERDP_LOCAL BOOL freerdp_channel_process(freerdp* instance, wStream* s,
UINT16 channelId);
FREERDP_LOCAL BOOL freerdp_channel_peer_process(freerdp_peer* client,

View File

@ -76,10 +76,9 @@ static rdpMcsChannel* freerdp_channels_find_channel_by_name(rdpRdp* rdp,
return NULL;
}
static void channel_queue_free(void* obj)
static void channel_queue_message_free(wMessage* msg)
{
CHANNEL_OPEN_EVENT* ev;
wMessage* msg = (wMessage*)obj;
if (!msg || (msg->id != 0))
return;
@ -102,6 +101,12 @@ static void channel_queue_free(void* obj)
}
}
static void channel_queue_free(void* obj)
{
wMessage* msg = (wMessage*)obj;
channel_queue_message_free(msg);
}
rdpChannels* freerdp_channels_new(freerdp* instance)
{
rdpChannels* channels;
@ -493,9 +498,9 @@ static int freerdp_channels_process_sync(rdpChannels* channels,
pChannelOpenData->OpenHandle, CHANNEL_EVENT_WRITE_COMPLETE, item->UserData, item->DataLength,
item->DataLength, 0);
}
free(item);
}
IFCALL(message.Free, &message);
}
return status;
@ -954,6 +959,7 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelWriteEx(LPVOID pInitHandle, DWORD op
CHANNEL_INIT_DATA* pChannelInitData = NULL;
CHANNEL_OPEN_DATA* pChannelOpenData = NULL;
CHANNEL_OPEN_EVENT* pChannelOpenEvent = NULL;
wMessage message;
if (!pInitHandle)
return CHANNEL_RC_BAD_INIT_HANDLE;
@ -990,10 +996,15 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelWriteEx(LPVOID pInitHandle, DWORD op
pChannelOpenEvent->DataLength = dataLength;
pChannelOpenEvent->UserData = pUserData;
pChannelOpenEvent->pChannelOpenData = pChannelOpenData;
message.context = channels;
message.id = 0;
message.wParam = pChannelOpenEvent;
message.lParam = NULL;
message.Free = channel_queue_message_free;
if (!MessageQueue_Post(channels->queue, (void*) channels, 0, (void*) pChannelOpenEvent, NULL))
if (!MessageQueue_Dispatch(channels->queue, &message))
{
free(pChannelOpenEvent);
channel_queue_message_free(&message);
return CHANNEL_RC_NO_MEMORY;
}
@ -1003,6 +1014,7 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelWriteEx(LPVOID pInitHandle, DWORD op
static UINT VCAPITYPE FreeRDP_VirtualChannelWrite(DWORD openHandle,
LPVOID pData, ULONG dataLength, LPVOID pUserData)
{
wMessage message;
CHANNEL_OPEN_DATA* pChannelOpenData;
CHANNEL_OPEN_EVENT* pChannelOpenEvent;
rdpChannels* channels = (rdpChannels*) freerdp_channel_get_open_handle_data(&g_ChannelHandles,
@ -1037,10 +1049,15 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelWrite(DWORD openHandle,
pChannelOpenEvent->DataLength = dataLength;
pChannelOpenEvent->UserData = pUserData;
pChannelOpenEvent->pChannelOpenData = pChannelOpenData;
message.context = channels;
message.id = 0;
message.wParam = pChannelOpenEvent;
message.lParam = NULL;
message.Free = channel_queue_message_free;
if (!MessageQueue_Post(channels->queue, (void*) channels, 0, (void*) pChannelOpenEvent, NULL))
if (!MessageQueue_Dispatch(channels->queue, &message))
{
free(pChannelOpenEvent);
channel_queue_message_free(&message);
return CHANNEL_RC_NO_MEMORY;
}

View File

@ -582,7 +582,6 @@ static int peer_recv_callback(rdpTransport* transport, wStream* s, void* extra)
case CONNECTION_STATE_CAPABILITIES_EXCHANGE:
if (!rdp->AwaitCapabilities)
{
if (client->Capabilities && !client->Capabilities(client))
return -1;
@ -675,7 +674,7 @@ static void freerdp_peer_disconnect(freerdp_peer* client)
transport_disconnect(transport);
}
static int freerdp_peer_send_channel_data(freerdp_peer* client, UINT16 channelId, BYTE* data,
static int freerdp_peer_send_channel_data(freerdp_peer* client, UINT16 channelId, const BYTE* data,
int size)
{
return rdp_send_channel_data(client->context->rdp, channelId, data, size);

View File

@ -36,40 +36,40 @@
const char* DATA_PDU_TYPE_STRINGS[80] =
{
"?", "?", /* 0x00 - 0x01 */
"Update", /* 0x02 */
"?", "?", "?", "?", "?", "?", "?", "?", /* 0x03 - 0x0A */
"?", "?", "?", "?", "?", "?", "?", "?", "?", /* 0x0B - 0x13 */
"Control", /* 0x14 */
"?", "?", "?", "?", "?", "?", /* 0x15 - 0x1A */
"Pointer", /* 0x1B */
"Input", /* 0x1C */
"?", "?", /* 0x1D - 0x1E */
"Synchronize", /* 0x1F */
"?", /* 0x20 */
"Refresh Rect", /* 0x21 */
"Play Sound", /* 0x22 */
"Suppress Output", /* 0x23 */
"Shutdown Request", /* 0x24 */
"Shutdown Denied", /* 0x25 */
"Save Session Info", /* 0x26 */
"Font List", /* 0x27 */
"Font Map", /* 0x28 */
"Set Keyboard Indicators", /* 0x29 */
"?", /* 0x2A */
"Bitmap Cache Persistent List", /* 0x2B */
"Bitmap Cache Error", /* 0x2C */
"Set Keyboard IME Status", /* 0x2D */
"Offscreen Cache Error", /* 0x2E */
"Set Error Info", /* 0x2F */
"Draw Nine Grid Error", /* 0x30 */
"Draw GDI+ Error", /* 0x31 */
"ARC Status", /* 0x32 */
"?", "?", "?", /* 0x33 - 0x35 */
"Status Info", /* 0x36 */
"Monitor Layout", /* 0x37 */
"FrameAcknowledge", "?", "?", /* 0x38 - 0x40 */
"?", "?", "?", "?", "?", "?" /* 0x41 - 0x46 */
"?", "?", /* 0x00 - 0x01 */
"Update", /* 0x02 */
"?", "?", "?", "?", "?", "?", "?", "?", /* 0x03 - 0x0A */
"?", "?", "?", "?", "?", "?", "?", "?", "?", /* 0x0B - 0x13 */
"Control", /* 0x14 */
"?", "?", "?", "?", "?", "?", /* 0x15 - 0x1A */
"Pointer", /* 0x1B */
"Input", /* 0x1C */
"?", "?", /* 0x1D - 0x1E */
"Synchronize", /* 0x1F */
"?", /* 0x20 */
"Refresh Rect", /* 0x21 */
"Play Sound", /* 0x22 */
"Suppress Output", /* 0x23 */
"Shutdown Request", /* 0x24 */
"Shutdown Denied", /* 0x25 */
"Save Session Info", /* 0x26 */
"Font List", /* 0x27 */
"Font Map", /* 0x28 */
"Set Keyboard Indicators", /* 0x29 */
"?", /* 0x2A */
"Bitmap Cache Persistent List", /* 0x2B */
"Bitmap Cache Error", /* 0x2C */
"Set Keyboard IME Status", /* 0x2D */
"Offscreen Cache Error", /* 0x2E */
"Set Error Info", /* 0x2F */
"Draw Nine Grid Error", /* 0x30 */
"Draw GDI+ Error", /* 0x31 */
"ARC Status", /* 0x32 */
"?", "?", "?", /* 0x33 - 0x35 */
"Status Info", /* 0x36 */
"Monitor Layout", /* 0x37 */
"FrameAcknowledge", "?", "?", /* 0x38 - 0x40 */
"?", "?", "?", "?", "?", "?" /* 0x41 - 0x46 */
};
/**
@ -84,6 +84,7 @@ BOOL rdp_read_security_header(wStream* s, UINT16* flags, UINT16* length)
/* Basic Security Header */
if ((Stream_GetRemainingLength(s) < 4) || (length && (*length < 4)))
return FALSE;
Stream_Read_UINT16(s, *flags); /* flags */
Stream_Seek(s, 2); /* flagsHi (unused) */
@ -142,7 +143,6 @@ BOOL rdp_read_share_control_header(wStream* s, UINT16* length, UINT16* type, UIN
void rdp_write_share_control_header(wStream* s, UINT16 length, UINT16 type, UINT16 channel_id)
{
length -= RDP_PACKET_HEADER_MAX_LENGTH;
/* Share Control Header */
Stream_Write_UINT16(s, length); /* totalLength */
Stream_Write_UINT16(s, type | 0x10); /* pduType */
@ -150,7 +150,7 @@ void rdp_write_share_control_header(wStream* s, UINT16 length, UINT16 type, UINT
}
BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type, UINT32* shareId,
BYTE* compressedType, UINT16* compressedLength)
BYTE* compressedType, UINT16* compressedLength)
{
if (Stream_GetRemainingLength(s) < 12)
return FALSE;
@ -163,7 +163,6 @@ BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type, UINT32*
Stream_Read_UINT8(s, *type); /* pduType2, Data PDU Type (1 byte) */
Stream_Read_UINT8(s, *compressedType); /* compressedType (1 byte) */
Stream_Read_UINT16(s, *compressedLength); /* compressedLength (2 bytes) */
return TRUE;
}
@ -172,7 +171,6 @@ void rdp_write_share_data_header(wStream* s, UINT16 length, BYTE type, UINT32 sh
length -= RDP_PACKET_HEADER_MAX_LENGTH;
length -= RDP_SHARE_CONTROL_HEADER_LENGTH;
length -= RDP_SHARE_DATA_HEADER_LENGTH;
/* Share Data Header */
Stream_Write_UINT32(s, share_id); /* shareId (4 bytes) */
Stream_Write_UINT8(s, 0); /* pad1 (1 byte) */
@ -240,8 +238,10 @@ wStream* rdp_data_pdu_init(rdpRdp* rdp)
{
wStream* s;
s = transport_send_stream_init(rdp->transport, 2048);
if (!s)
return NULL;
rdp_init_stream_data_pdu(rdp, s);
return s;
}
@ -254,9 +254,11 @@ BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo)
{
rdpContext* context = rdp->context;
rdp_print_errinfo(rdp->errorInfo);
if (context)
{
context->LastError = MAKE_FREERDP_ERROR(ERRINFO, errorInfo);
if (context->pubSub)
{
ErrorInfoEventArgs e;
@ -278,8 +280,10 @@ wStream* rdp_message_channel_pdu_init(rdpRdp* rdp)
{
wStream* s;
s = transport_send_stream_init(rdp->transport, 2048);
if (!s)
return NULL;
Stream_Seek(s, RDP_PACKET_HEADER_MAX_LENGTH);
rdp_security_stream_init(rdp, s, TRUE);
return s;
@ -302,8 +306,8 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
UINT16 initiator;
enum DomainMCSPDU MCSPDU;
enum DomainMCSPDU domainMCSPDU;
MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataRequest : DomainMCSPDU_SendDataIndication;
MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataRequest :
DomainMCSPDU_SendDataIndication;
if (!tpkt_read_header(s, length))
return FALSE;
@ -325,7 +329,7 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
if (!per_read_choice(s, &choice))
return FALSE;
domainMCSPDU = (enum DomainMCSPDU) (choice >> 2);
domainMCSPDU = (enum DomainMCSPDU)(choice >> 2);
if (domainMCSPDU != MCSPDU)
{
@ -362,7 +366,6 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
* when the user logs off like they should. Map DisconnectProviderUltimatum
* to a ERRINFO_LOGOFF_BY_USER when the errinfo code is ERRINFO_SUCCESS.
*/
if (reason == MCS_Reason_provider_initiated)
rdp_set_error_info(rdp, ERRINFO_RPC_INITIATED_DISCONNECT);
else if (reason == MCS_Reason_user_requested)
@ -373,11 +376,9 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
WLog_DBG(TAG, "DisconnectProviderUltimatum: reason: %d", reason);
freerdp_abort_connect(rdp->instance);
EventArgsInit(&e, "freerdp");
e.code = 0;
PubSub_OnTerminate(context->pubSub, context, &e);
return TRUE;
}
@ -413,13 +414,12 @@ void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId)
{
int body_length;
enum DomainMCSPDU MCSPDU;
MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataIndication : DomainMCSPDU_SendDataRequest;
MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataIndication :
DomainMCSPDU_SendDataRequest;
if ((rdp->sec_flags & SEC_ENCRYPT) && (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS))
{
int pad;
body_length = length - RDP_PACKET_HEADER_MAX_LENGTH - 16;
pad = 8 - (body_length % 8);
@ -441,11 +441,11 @@ void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId)
Stream_Write_UINT16_BE(s, length); /* userData (OCTET_STRING) */
}
static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 sec_flags, UINT32 *pad)
static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 sec_flags,
UINT32* pad)
{
BYTE* data;
BOOL status;
sec_flags |= rdp->sec_flags;
*pad = 0;
@ -458,22 +458,23 @@ static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
{
data = Stream_Pointer(s) + 12;
length = length - (data - Stream_Buffer(s));
Stream_Write_UINT16(s, 0x10); /* length */
Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
/* handle padding */
*pad = 8 - (length % 8);
if (*pad == 8)
*pad = 0;
if (*pad)
memset(data+length, 0, *pad);
memset(data + length, 0, *pad);
Stream_Write_UINT8(s, *pad);
if (!security_hmac_signature(data, length, Stream_Pointer(s), rdp))
return FALSE;
Stream_Seek(s, 8);
security_fips_encrypt(data, length + *pad, rdp);
}
@ -543,6 +544,7 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id)
if (!rdp_security_stream_out(rdp, s, length, 0, &pad))
return FALSE;
length += pad;
Stream_SetPosition(s, length);
Stream_SealLength(s);
@ -559,7 +561,6 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
UINT32 sec_bytes;
size_t sec_hold;
UINT32 pad;
length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
@ -588,7 +589,6 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
UINT32 sec_bytes;
size_t sec_hold;
UINT32 pad;
length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
@ -598,14 +598,16 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
rdp_write_share_control_header(s, length - sec_bytes, PDU_TYPE_DATA, channel_id);
rdp_write_share_data_header(s, length - sec_bytes, type, rdp->settings->ShareId);
Stream_SetPosition(s, sec_hold);
if (!rdp_security_stream_out(rdp, s, length, 0, &pad))
return FALSE;
length += pad;
Stream_SetPosition(s, length);
Stream_SealLength(s);
WLog_DBG(TAG, "%s: sending data (type=0x%x size=%"PRIuz" channelId=%"PRIu16")", __FUNCTION__,
type, Stream_Length(s), channel_id);
type, Stream_Length(s), channel_id);
if (transport_write(rdp->transport, s) < 0)
return FALSE;
@ -616,7 +618,6 @@ BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags)
{
UINT16 length;
UINT32 pad;
length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
rdp_write_header(rdp, s, length, rdp->mcs->messageChannelId);
@ -650,9 +651,7 @@ static BOOL rdp_recv_server_set_keyboard_indicators_pdu(rdpRdp* rdp, wStream* s)
Stream_Read_UINT16(s, unitId); /* unitId (2 bytes) */
Stream_Read_UINT16(s, ledFlags); /* ledFlags (2 bytes) */
IFCALL(context->update->SetKeyboardIndicators, context, ledFlags);
return TRUE;
}
@ -671,9 +670,7 @@ static BOOL rdp_recv_server_set_keyboard_ime_status_pdu(rdpRdp* rdp, wStream* s)
Stream_Read_UINT16(s, unitId); /* unitId (2 bytes) */
Stream_Read_UINT32(s, imeState); /* imeState (4 bytes) */
Stream_Read_UINT32(s, imeConvMode); /* imeConvMode (4 bytes) */
IFCALL(rdp->update->SetKeyboardImeStatus, rdp->context, unitId, imeState, imeConvMode);
return TRUE;
}
@ -696,9 +693,7 @@ static BOOL rdp_recv_server_auto_reconnect_status_pdu(rdpRdp* rdp, wStream* s)
return FALSE;
Stream_Read_UINT32(s, arcStatus); /* arcStatus (4 bytes) */
WLog_WARN(TAG, "AutoReconnectStatus: 0x%08"PRIX32"", arcStatus);
return TRUE;
}
@ -744,13 +739,12 @@ static BOOL rdp_recv_monitor_layout_pdu(rdpRdp* rdp, wStream* s)
}
IFCALLRET(rdp->update->RemoteMonitors, ret, rdp->context, monitorCount, monitorDefArray);
free(monitorDefArray);
return ret;
}
BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount, const rdpMonitor* monitorDefArray)
BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount,
const rdpMonitor* monitorDefArray)
{
UINT32 index;
const rdpMonitor* monitor;
@ -824,7 +818,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
}
WLog_DBG(TAG, "recv %s Data PDU (0x%02"PRIX8"), length: %"PRIu16"",
type < ARRAYSIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
type < ARRAYSIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
switch (type)
{
@ -834,6 +828,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_UPDATE - update_recv() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_CONTROL:
@ -842,6 +837,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_CONTROL - rdp_recv_server_control_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_POINTER:
@ -850,6 +846,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_POINTER - update_recv_pointer() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SYNCHRONIZE:
@ -858,6 +855,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_SYNCHRONIZE - rdp_recv_synchronize_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_PLAY_SOUND:
@ -866,6 +864,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_PLAY_SOUND - update_recv_play_sound() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SHUTDOWN_DENIED:
@ -874,6 +873,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_SHUTDOWN_DENIED - rdp_recv_server_shutdown_denied_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SAVE_SESSION_INFO:
@ -882,6 +882,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_SAVE_SESSION_INFO - rdp_recv_save_session_info() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_FONT_MAP:
@ -890,22 +891,27 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_FONT_MAP - rdp_recv_font_map_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS:
if (!rdp_recv_server_set_keyboard_indicators_pdu(rdp, cs))
{
WLog_ERR(TAG, "DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS - rdp_recv_server_set_keyboard_indicators_pdu() failed");
WLog_ERR(TAG,
"DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS - rdp_recv_server_set_keyboard_indicators_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS:
if (!rdp_recv_server_set_keyboard_ime_status_pdu(rdp, cs))
{
WLog_ERR(TAG, "DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS - rdp_recv_server_set_keyboard_ime_status_pdu() failed");
WLog_ERR(TAG,
"DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS - rdp_recv_server_set_keyboard_ime_status_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_SET_ERROR_INFO:
@ -914,6 +920,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_SET_ERROR_INFO - rdp_recv_set_error_info_data_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_ARC_STATUS:
@ -922,6 +929,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_ARC_STATUS - rdp_recv_server_auto_reconnect_status_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_STATUS_INFO:
@ -930,6 +938,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_STATUS_INFO - rdp_recv_server_status_info_pdu() failed");
goto out_fail;
}
break;
case DATA_PDU_TYPE_MONITOR_LAYOUT:
@ -938,6 +947,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "DATA_PDU_TYPE_MONITOR_LAYOUT - rdp_recv_monitor_layout_pdu() failed");
goto out_fail;
}
break;
default:
@ -948,11 +958,12 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
Stream_Release(cs);
return 0;
out_fail:
if (cs != s)
Stream_Release(cs);
return -1;
if (cs != s)
Stream_Release(cs);
return -1;
}
int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 securityFlags)
@ -1002,8 +1013,8 @@ int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s)
return rdp_recv_enhanced_security_redirection_packet(rdp, s);
}
else if (type == PDU_TYPE_FLOW_RESPONSE ||
type == PDU_TYPE_FLOW_STOP ||
type == PDU_TYPE_FLOW_TEST)
type == PDU_TYPE_FLOW_STOP ||
type == PDU_TYPE_FLOW_TEST)
{
return 0;
}
@ -1060,12 +1071,11 @@ BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, INT32 length, UINT16 securityFlags)
Stream_Read_UINT16(s, len); /* 0x10 */
Stream_Read_UINT8(s, version); /* 0x1 */
Stream_Read_UINT8(s, pad);
sig = Stream_Pointer(s);
Stream_Seek(s, 8); /* signature */
length -= 12;
padLength = length - pad;
if ((length <= 0) || (padLength <= 0))
return FALSE;
@ -1090,6 +1100,7 @@ BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, INT32 length, UINT16 securityFlags)
Stream_Read(s, wmac, sizeof(wmac));
length -= sizeof(wmac);
if (length <= 0)
return FALSE;
@ -1144,7 +1155,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
if (freerdp_shall_disconnect(rdp->instance))
return 0;
if (rdp->autodetect->bandwidthMeasureStarted)
{
rdp->autodetect->bandwidthMeasureByteCount += length;
@ -1174,7 +1185,6 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
* - no share control header, nor the 2 byte pad
*/
Stream_Rewind(s, 2);
return rdp_recv_enhanced_security_redirection_packet(rdp, s);
}
}
@ -1192,7 +1202,6 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
}
nextPosition += pduLength;
rdp->settings->PduSource = pduSource;
switch (pduType)
@ -1203,6 +1212,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "rdp_recv_data_pdu() failed");
return -1;
}
break;
case PDU_TYPE_DEACTIVATE_ALL:
@ -1211,12 +1221,13 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
WLog_ERR(TAG, "rdp_recv_tpkt_pdu: rdp_recv_deactivate_all() fail");
return -1;
}
break;
case PDU_TYPE_SERVER_REDIRECTION:
return rdp_recv_enhanced_security_redirection_packet(rdp, s);
break;
case PDU_TYPE_FLOW_RESPONSE:
case PDU_TYPE_FLOW_STOP:
case PDU_TYPE_FLOW_TEST:
@ -1255,7 +1266,6 @@ static int rdp_recv_fastpath_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 length;
rdpFastPath* fastpath;
fastpath = rdp->fastpath;
if (!fastpath_read_header_rdp(fastpath, s, &length))
@ -1277,7 +1287,8 @@ static int rdp_recv_fastpath_pdu(rdpRdp* rdp, wStream* s)
if (fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED)
{
UINT16 flags = (fastpath->encryptionFlags & FASTPATH_OUTPUT_SECURE_CHECKSUM) ? SEC_SECURE_CHECKSUM : 0;
UINT16 flags = (fastpath->encryptionFlags & FASTPATH_OUTPUT_SECURE_CHECKSUM) ? SEC_SECURE_CHECKSUM :
0;
if (!rdp_decrypt(rdp, s, length, flags))
{
@ -1302,7 +1313,7 @@ int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
int status = 0;
rdpRdp* rdp = (rdpRdp*) extra;
/*
/*
* At any point in the connection sequence between when all
* MCS channels have been joined and when the RDP connection
* enters the active state, an auto-detect PDU can be received
@ -1410,21 +1421,28 @@ int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
case CONNECTION_STATE_MCS_CHANNEL_JOIN:
if (!rdp_client_connect_mcs_channel_join_confirm(rdp, s))
{
WLog_ERR(TAG, "rdp_recv_callback: CONNECTION_STATE_MCS_CHANNEL_JOIN - rdp_client_connect_mcs_channel_join_confirm() fail");
WLog_ERR(TAG,
"rdp_recv_callback: CONNECTION_STATE_MCS_CHANNEL_JOIN - rdp_client_connect_mcs_channel_join_confirm() fail");
status = -1;
}
break;
case CONNECTION_STATE_LICENSING:
status = rdp_client_connect_license(rdp, s);
if (status < 0)
WLog_DBG(TAG, "CONNECTION_STATE_LICENSING - rdp_client_connect_license() - %i", status);
break;
case CONNECTION_STATE_CAPABILITIES_EXCHANGE:
status = rdp_client_connect_demand_active(rdp, s);
if (status < 0)
WLog_DBG(TAG, "CONNECTION_STATE_CAPABILITIES_EXCHANGE - rdp_client_connect_demand_active() - %i", status);
WLog_DBG(TAG, "CONNECTION_STATE_CAPABILITIES_EXCHANGE - rdp_client_connect_demand_active() - %i",
status);
break;
case CONNECTION_STATE_FINALIZATION:
@ -1433,24 +1451,25 @@ int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
if ((status >= 0) && (rdp->finalize_sc_pdus == FINALIZE_SC_COMPLETE))
{
ActivatedEventArgs activatedEvent;
rdpContext *context = rdp->context;
rdpContext* context = rdp->context;
rdp_client_transition_to_state(rdp, CONNECTION_STATE_ACTIVE);
EventArgsInit(&activatedEvent, "xfreerdp");
activatedEvent.firstActivation = !rdp->deactivation_reactivation;
PubSub_OnActivated(context->pubSub, context, &activatedEvent);
return 2;
}
if (status < 0)
WLog_DBG(TAG, "CONNECTION_STATE_FINALIZATION - rdp_recv_pdu() - %i", status);
break;
case CONNECTION_STATE_ACTIVE:
status = rdp_recv_pdu(rdp, s);
if (status < 0)
WLog_DBG(TAG, "CONNECTION_STATE_ACTIVE - rdp_recv_pdu() - %i", status);
break;
default:
@ -1462,7 +1481,7 @@ int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
return status;
}
int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, const BYTE* data, int size)
{
return freerdp_channel_send(rdp, channelId, data, size);
}
@ -1476,13 +1495,12 @@ BOOL rdp_send_error_info(rdpRdp* rdp)
return TRUE;
s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
Stream_Write_UINT32(s, rdp->errorInfo); /* error id (4 bytes) */
status = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_ERROR_INFO, 0);
return status;
}
@ -1494,7 +1512,6 @@ int rdp_check_fds(rdpRdp* rdp)
if (transport->tsg)
{
rdpTsg* tsg = transport->tsg;
status = tsg_check_event_handles(tsg);
if (status < 0)
@ -1513,6 +1530,7 @@ int rdp_check_fds(rdpRdp* rdp)
{
status = rdp_client_redirect(rdp); /* session redirection */
}
if (status < 0)
WLog_DBG(TAG, "transport_check_fds() - %i", status);
@ -1529,7 +1547,6 @@ rdpRdp* rdp_new(rdpContext* context)
rdpRdp* rdp;
DWORD flags;
BOOL newSettings = FALSE;
rdp = (rdpRdp*) calloc(1, sizeof(rdpRdp));
if (!rdp)
@ -1537,7 +1554,6 @@ rdpRdp* rdp_new(rdpContext* context)
rdp->context = context;
rdp->instance = context->instance;
flags = 0;
if (context->ServerMode)
@ -1546,12 +1562,15 @@ rdpRdp* rdp_new(rdpContext* context)
if (!context->settings)
{
context->settings = freerdp_settings_new(flags);
if (!context->settings)
goto out_free;
newSettings = TRUE;
}
rdp->settings = context->settings;
if (context->instance)
{
rdp->settings->instance = context->instance;
@ -1569,51 +1588,61 @@ rdpRdp* rdp_new(rdpContext* context)
goto out_free_settings;
rdp->license = license_new(rdp);
if (!rdp->license)
goto out_free_transport;
rdp->input = input_new(rdp);
if (!rdp->input)
goto out_free_license;
rdp->update = update_new(rdp);
if (!rdp->update)
goto out_free_input;
rdp->fastpath = fastpath_new(rdp);
if (!rdp->fastpath)
goto out_free_update;
rdp->nego = nego_new(rdp->transport);
if (!rdp->nego)
goto out_free_fastpath;
rdp->mcs = mcs_new(rdp->transport);
if (!rdp->mcs)
goto out_free_nego;
rdp->redirection = redirection_new();
if (!rdp->redirection)
goto out_free_mcs;
rdp->autodetect = autodetect_new();
if (!rdp->autodetect)
goto out_free_redirection;
rdp->heartbeat = heartbeat_new();
if (!rdp->heartbeat)
goto out_free_autodetect;
rdp->multitransport = multitransport_new();
if (!rdp->multitransport)
goto out_free_heartbeat;
rdp->bulk = bulk_new(context);
if (!rdp->bulk)
goto out_free_multitransport;
return rdp;
out_free_multitransport:
multitransport_free(rdp->multitransport);
out_free_heartbeat:
@ -1637,8 +1666,10 @@ out_free_license:
out_free_transport:
transport_free(rdp->transport);
out_free_settings:
if (newSettings)
freerdp_settings_free(rdp->settings);
out_free:
free(rdp);
return NULL;
@ -1648,10 +1679,8 @@ void rdp_reset(rdpRdp* rdp)
{
rdpContext* context;
rdpSettings* settings;
context = rdp->context;
settings = rdp->settings;
bulk_reset(rdp->bulk);
if (rdp->rc4_decrypt_key)
@ -1701,7 +1730,6 @@ void rdp_reset(rdpRdp* rdp)
nego_free(rdp->nego);
license_free(rdp->license);
transport_free(rdp->transport);
rdp->transport = transport_new(context);
rdp->license = license_new(rdp);
rdp->nego = nego_new(rdp->transport);

View File

@ -213,7 +213,7 @@ FREERDP_LOCAL int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
FREERDP_LOCAL BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
FREERDP_LOCAL int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId,
BYTE* data, int size);
const BYTE* data, int size);
FREERDP_LOCAL wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
FREERDP_LOCAL BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s,