2011-07-19 10:07:15 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-19 10:07:15 +04:00
|
|
|
* Dynamic Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2010-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
|
|
|
|
|
2012-10-09 04:26:11 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-05-14 01:39:53 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
#include <freerdp/constants.h>
|
|
|
|
|
|
|
|
#include "dvcman.h"
|
|
|
|
#include "drdynvc_types.h"
|
|
|
|
#include "drdynvc_main.h"
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
static int drdynvc_write_variable_uint(wStream* s, UINT32 val)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int cb;
|
|
|
|
|
|
|
|
if (val <= 0xFF)
|
|
|
|
{
|
|
|
|
cb = 0;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT8(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else if (val <= 0xFFFF)
|
|
|
|
{
|
|
|
|
cb = 1;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT16(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-25 22:27:38 +04:00
|
|
|
cb = 2;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
int drdynvc_send(drdynvcPlugin* drdynvc, wStream* s)
|
|
|
|
{
|
|
|
|
UINT32 status = 0;
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
|
|
|
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelWrite(drdynvc->OpenHandle,
|
|
|
|
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
WLog_ERR(TAG, "drdynvc_send: VirtualChannelWrite failed %d", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
int drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UINT32 dataSize)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 pos = 0;
|
|
|
|
UINT32 cbChId;
|
|
|
|
UINT32 cbLen;
|
2014-06-17 21:34:23 +04:00
|
|
|
UINT32 chunkLength;
|
|
|
|
int status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
DEBUG_DVC("ChannelId=%d size=%d", ChannelId, dataSize);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-04-25 22:27:38 +04:00
|
|
|
if (drdynvc->channel_error != CHANNEL_RC_OK)
|
|
|
|
return 1;
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, CHANNEL_CHUNK_LENGTH);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (dataSize == 0)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x40 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2014-06-17 21:34:23 +04:00
|
|
|
else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, dataSize);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fragment the data */
|
2014-06-17 21:34:23 +04:00
|
|
|
cbLen = drdynvc_write_variable_uint(data_out, dataSize);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x20 | cbChId | (cbLen << 2));
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, chunkLength);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
while (status == CHANNEL_RC_OK && dataSize > 0)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, CHANNEL_CHUNK_LENGTH);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = dataSize;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (chunkLength > CHANNEL_CHUNK_LENGTH - pos)
|
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, chunkLength);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-06-17 21:34:23 +04:00
|
|
|
drdynvc->channel_error = status;
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed %d", status);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
static int drdynvc_send_capability_response(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-06-03 21:00:03 +04:00
|
|
|
int status;
|
2014-06-17 21:34:23 +04:00
|
|
|
wStream* s;
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
s = Stream_New(NULL, 4);
|
|
|
|
Stream_Write_UINT16(s, 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */
|
|
|
|
Stream_Write_UINT16(s, drdynvc->version);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, s);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed %d", status);
|
2014-06-03 21:00:03 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
|
|
|
{
|
|
|
|
int status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
DEBUG_DVC("Sp=%d cbChId=%d", Sp, cbChId);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 1); /* pad */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->version);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-10 23:57:22 +04:00
|
|
|
/* RDP8 servers offer version 3, though Microsoft forgot to document it
|
|
|
|
* in their early documents. It behaves the same as version 2.
|
|
|
|
*/
|
|
|
|
if ((drdynvc->version == 2) || (drdynvc->version == 3))
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge0);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge1);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge2);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge3);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
status = drdynvc_send_capability_response(drdynvc);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
drdynvc->channel_error = status;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
2012-04-25 22:27:38 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
static UINT32 drdynvc_read_variable_uint(wStream* s, int cbLen)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 val;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT8(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case 1:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT16(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int pos;
|
2013-05-14 00:07:42 +04:00
|
|
|
int status;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2014-06-03 17:49:00 +04:00
|
|
|
int channel_status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
if (drdynvc->state == DRDYNVC_STATE_CAPABILITIES)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For some reason the server does not always send the
|
|
|
|
* capabilities pdu as it should. When this happens,
|
|
|
|
* send a capabilities response.
|
|
|
|
*/
|
|
|
|
|
|
|
|
drdynvc->version = 3;
|
|
|
|
drdynvc_send_capability_response(drdynvc);
|
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s);
|
|
|
|
DEBUG_DVC("ChannelId=%d ChannelName=%s", ChannelId, Stream_Pointer(s));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-03 17:49:00 +04:00
|
|
|
channel_status = dvcman_create_channel(drdynvc->channel_mgr, ChannelId, (char*) Stream_Pointer(s));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, pos + 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x10 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 1);
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Copy(data_out, s, pos - 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-03 17:49:00 +04:00
|
|
|
if (channel_status == 0)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
DEBUG_DVC("channel created");
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(data_out, 0);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_DVC("no listener");
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(data_out, (UINT32)(-1));
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed %d", status);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 17:49:00 +04:00
|
|
|
if (channel_status == 0)
|
|
|
|
{
|
|
|
|
dvcman_open_channel(drdynvc->channel_mgr, ChannelId);
|
|
|
|
}
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-05-14 01:39:53 +04:00
|
|
|
int status;
|
2012-11-20 07:31:15 +04:00
|
|
|
UINT32 Length;
|
|
|
|
UINT32 ChannelId;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
|
|
|
Length = drdynvc_read_variable_uint(s, Sp);
|
2011-07-19 10:07:15 +04:00
|
|
|
DEBUG_DVC("ChannelId=%d Length=%d", ChannelId, Length);
|
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
status = dvcman_receive_channel_data_first(drdynvc->channel_mgr, ChannelId, Length);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
if (status)
|
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
return dvcman_receive_channel_data(drdynvc->channel_mgr, ChannelId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2011-07-19 10:07:15 +04:00
|
|
|
DEBUG_DVC("ChannelId=%d", ChannelId);
|
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
return dvcman_receive_channel_data(drdynvc->channel_mgr, ChannelId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-09-13 17:22:10 +04:00
|
|
|
int value;
|
|
|
|
int error;
|
2014-11-12 21:34:07 +03:00
|
|
|
UINT32 ChannelId;
|
|
|
|
wStream* data_out;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2011-07-19 10:07:15 +04:00
|
|
|
DEBUG_DVC("ChannelId=%d", ChannelId);
|
|
|
|
dvcman_close_channel(drdynvc->channel_mgr, ChannelId);
|
2013-09-13 17:22:10 +04:00
|
|
|
|
|
|
|
data_out = Stream_New(NULL, 4);
|
2013-09-17 00:48:08 +04:00
|
|
|
value = (CLOSE_REQUEST_PDU << 4) | (cbChId & 0x03);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2013-09-13 17:22:10 +04:00
|
|
|
Stream_Write_UINT8(data_out, value);
|
|
|
|
drdynvc_write_variable_uint(data_out, ChannelId);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
error = drdynvc_send(drdynvc, data_out);
|
2013-09-13 17:22:10 +04:00
|
|
|
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed %d", error);
|
2013-09-13 17:22:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
drdynvc->channel_error = error;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
static void drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int value;
|
|
|
|
int Cmd;
|
|
|
|
int Sp;
|
|
|
|
int cbChId;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, value);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
Cmd = (value & 0xf0) >> 4;
|
|
|
|
Sp = (value & 0x0c) >> 2;
|
|
|
|
cbChId = (value & 0x03) >> 0;
|
2011-09-19 18:53:00 +04:00
|
|
|
|
|
|
|
DEBUG_DVC("Cmd=0x%x", Cmd);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case CAPABILITY_REQUEST_PDU:
|
2011-09-19 18:53:00 +04:00
|
|
|
drdynvc_process_capability_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CREATE_REQUEST_PDU:
|
2011-09-19 18:53:00 +04:00
|
|
|
drdynvc_process_create_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_FIRST_PDU:
|
2011-09-19 18:53:00 +04:00
|
|
|
drdynvc_process_data_first(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_PDU:
|
2011-09-19 18:53:00 +04:00
|
|
|
drdynvc_process_data(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CLOSE_REQUEST_PDU:
|
2011-09-19 18:53:00 +04:00
|
|
|
drdynvc_process_close_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown drdynvc cmd 0x%x", Cmd);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
/****************************************************************************************/
|
|
|
|
|
|
|
|
static wListDictionary* g_InitHandles;
|
|
|
|
static wListDictionary* g_OpenHandles;
|
|
|
|
|
|
|
|
void drdynvc_add_init_handle_data(void* pInitHandle, void* pUserData)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-11-12 21:34:07 +03:00
|
|
|
if (!g_InitHandles)
|
|
|
|
g_InitHandles = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
ListDictionary_Add(g_InitHandles, pInitHandle, pUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* drdynvc_get_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_InitHandles, pInitHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drdynvc_remove_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
ListDictionary_Remove(g_InitHandles, pInitHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drdynvc_add_open_handle_data(DWORD openHandle, void* pUserData)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
|
|
|
|
if (!g_OpenHandles)
|
|
|
|
g_OpenHandles = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
ListDictionary_Add(g_OpenHandles, pOpenHandle, pUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* drdynvc_get_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_OpenHandles, pOpenHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drdynvc_remove_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
ListDictionary_Remove(g_OpenHandles, pOpenHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc,
|
|
|
|
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
wStream* data_in;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
if (drdynvc->data_in)
|
|
|
|
Stream_Free(drdynvc->data_in, TRUE);
|
|
|
|
|
|
|
|
drdynvc->data_in = Stream_New(NULL, totalLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
data_in = drdynvc->data_in;
|
|
|
|
Stream_EnsureRemainingCapacity(data_in, (int) dataLength);
|
|
|
|
Stream_Write(data_in, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
|
|
|
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_plugin_process_received: read error");
|
|
|
|
}
|
|
|
|
|
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
Stream_SealLength(data_in);
|
|
|
|
Stream_SetPosition(data_in, 0);
|
|
|
|
|
|
|
|
MessageQueue_Post(drdynvc->MsgPipe->In, NULL, 0, (void*) data_in, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID VCAPITYPE drdynvc_virtual_channel_open_event(DWORD openHandle, UINT event,
|
|
|
|
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc;
|
|
|
|
|
|
|
|
drdynvc = (drdynvcPlugin*) drdynvc_get_open_handle_data(openHandle);
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_open_event: error no match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
|
|
|
drdynvc_virtual_channel_event_data_received(drdynvc, pData, dataLength, totalLength, dataFlags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
|
|
|
Stream_Free((wStream*) pData, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* drdynvc_virtual_channel_client_thread(void* arg)
|
|
|
|
{
|
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*) arg;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (!MessageQueue_Wait(drdynvc->MsgPipe->In))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (MessageQueue_Peek(drdynvc->MsgPipe->In, &message, TRUE))
|
|
|
|
{
|
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.id == 0)
|
|
|
|
{
|
|
|
|
data = (wStream*) message.wParam;
|
|
|
|
drdynvc_order_recv(drdynvc, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc, LPVOID pData, UINT32 dataLength)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2012-11-20 07:31:15 +04:00
|
|
|
ADDIN_ARGV* args;
|
|
|
|
rdpSettings* settings;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelOpen(drdynvc->InitHandle,
|
|
|
|
&drdynvc->OpenHandle, drdynvc->channelDef.name, drdynvc_virtual_channel_open_event);
|
|
|
|
|
|
|
|
drdynvc_add_open_handle_data(drdynvc->OpenHandle, drdynvc);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_event_connected: open failed: status: %d", status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
drdynvc->MsgPipe = MessagePipe_New();
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
drdynvc->channel_mgr = dvcman_new(drdynvc);
|
2012-04-25 22:27:38 +04:00
|
|
|
drdynvc->channel_error = 0;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
settings = (rdpSettings*) drdynvc->channelEntryPoints.pExtendedData;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
for (index = 0; index < settings->DynamicChannelCount; index++)
|
|
|
|
{
|
|
|
|
args = settings->DynamicChannelArray[index];
|
2014-07-03 22:35:03 +04:00
|
|
|
dvcman_load_addin(drdynvc->channel_mgr, args, settings);
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
dvcman_init(drdynvc->channel_mgr);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
drdynvc->state = DRDYNVC_STATE_CAPABILITIES;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
drdynvc->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) drdynvc_virtual_channel_client_thread, (void*) drdynvc, 0, NULL);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
static void drdynvc_virtual_channel_event_terminated(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-11-12 21:34:07 +03:00
|
|
|
MessagePipe_PostQuit(drdynvc->MsgPipe, 0);
|
|
|
|
WaitForSingleObject(drdynvc->thread, INFINITE);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
MessagePipe_Free(drdynvc->MsgPipe);
|
|
|
|
CloseHandle(drdynvc->thread);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->channelEntryPoints.pVirtualChannelClose(drdynvc->OpenHandle);
|
|
|
|
|
|
|
|
if (drdynvc->data_in)
|
|
|
|
{
|
|
|
|
Stream_Free(drdynvc->data_in, TRUE);
|
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
}
|
2014-06-20 01:08:50 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (drdynvc->channel_mgr)
|
2014-06-20 01:08:50 +04:00
|
|
|
{
|
2011-07-19 10:07:15 +04:00
|
|
|
dvcman_free(drdynvc->channel_mgr);
|
2014-06-20 01:08:50 +04:00
|
|
|
drdynvc->channel_mgr = NULL;
|
|
|
|
}
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc_remove_open_handle_data(drdynvc->OpenHandle);
|
|
|
|
drdynvc_remove_init_handle_data(drdynvc->InitHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID VCAPITYPE drdynvc_virtual_channel_init_event(LPVOID pInitHandle, UINT event, LPVOID pData, UINT dataLength)
|
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc;
|
2014-06-12 20:03:08 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc = (drdynvcPlugin*) drdynvc_get_init_handle_data(pInitHandle);
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_init_event: error no match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
|
|
|
drdynvc_virtual_channel_event_connected(drdynvc, pData, dataLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
|
|
|
drdynvc_virtual_channel_event_terminated(drdynvc);
|
|
|
|
break;
|
|
|
|
}
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
/**
|
|
|
|
* Channel Client Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
int drdynvc_get_version(DrdynvcClientContext* context)
|
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*) context->handle;
|
|
|
|
return drdynvc->version;
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:48:17 +04:00
|
|
|
/* drdynvc is always built-in */
|
2012-10-09 04:26:11 +04:00
|
|
|
#define VirtualChannelEntry drdynvc_VirtualChannelEntry
|
|
|
|
|
2014-03-04 03:28:31 +04:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2012-10-09 04:26:11 +04:00
|
|
|
{
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvcPlugin* drdynvc;
|
2013-05-14 00:07:42 +04:00
|
|
|
DrdynvcClientContext* context;
|
2014-02-17 02:38:59 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc = (drdynvcPlugin*) calloc(1, sizeof(drdynvcPlugin));
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
if (!drdynvc)
|
2014-06-17 21:34:23 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->channelDef.options =
|
2012-10-09 04:26:11 +04:00
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP |
|
|
|
|
CHANNEL_OPTION_COMPRESS_RDP;
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
strcpy(drdynvc->channelDef.name, "drdynvc");
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->state = DRDYNVC_STATE_INITIAL;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP*) pEntryPoints;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP)) &&
|
2013-05-14 00:07:42 +04:00
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
|
|
|
{
|
2014-06-17 21:34:23 +04:00
|
|
|
context = (DrdynvcClientContext*) calloc(1, sizeof(DrdynvcClientContext));
|
|
|
|
|
|
|
|
if (!context)
|
2014-11-16 18:02:28 +03:00
|
|
|
{
|
|
|
|
free(drdynvc);
|
2014-06-17 21:34:23 +04:00
|
|
|
return -1;
|
2014-11-16 18:02:28 +03:00
|
|
|
}
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
context->handle = (void*) drdynvc;
|
|
|
|
context->custom = NULL;
|
|
|
|
|
|
|
|
drdynvc->context = context;
|
2013-05-14 01:39:53 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
context->GetVersion = drdynvc_get_version;
|
|
|
|
|
|
|
|
*(pEntryPointsEx->ppInterface) = (void*) context;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->log = WLog_Get("com.freerdp.channels.drdynvc.client");
|
|
|
|
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "VirtualChannelEntry");
|
|
|
|
|
|
|
|
CopyMemory(&(drdynvc->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
|
|
|
|
|
|
|
|
drdynvc->channelEntryPoints.pVirtualChannelInit(&drdynvc->InitHandle,
|
|
|
|
&drdynvc->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, drdynvc_virtual_channel_init_event);
|
|
|
|
|
|
|
|
drdynvc->channelEntryPoints.pInterface = *(drdynvc->channelEntryPoints.ppInterface);
|
|
|
|
drdynvc->channelEntryPoints.ppInterface = &(drdynvc->channelEntryPoints.pInterface);
|
|
|
|
|
|
|
|
drdynvc_add_init_handle_data(drdynvc->InitHandle, (void*) drdynvc);
|
2012-10-09 04:26:11 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2014-06-12 20:03:08 +04:00
|
|
|
|