2011-08-05 11:43:48 +04:00
|
|
|
/**
|
2012-10-09 05:00:07 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Device Redirection Virtual Channel
|
2011-08-05 11:43:48 +04:00
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2012-10-09 05:00:07 +04:00
|
|
|
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-03 14:38:47 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-08-05 11:43:48 +04: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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-08-05 11:43:48 +04:00
|
|
|
#include "config.h"
|
2012-08-15 01:09:01 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-05 11:43:48 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2013-10-17 23:42:51 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2012-10-09 05:00:07 +04:00
|
|
|
#include "rdpdr_main.h"
|
2011-08-05 11:43:48 +04:00
|
|
|
#include "rdpdr_capabilities.h"
|
|
|
|
|
|
|
|
/* Output device redirection capability set header */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_capset_header(wStream* s, UINT16 capabilityType, UINT16 capabilityLength, UINT32 version)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, capabilityType);
|
|
|
|
Stream_Write_UINT16(s, capabilityLength);
|
|
|
|
Stream_Write_UINT32(s, version);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Output device direction general capability set */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_general_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_capset_header(s, CAP_GENERAL_TYPE, 44, GENERAL_CAPABILITY_VERSION_02);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, 0); /* osType, ignored on receipt */
|
|
|
|
Stream_Write_UINT32(s, 0); /* osVersion, unused and must be set to zero */
|
|
|
|
Stream_Write_UINT16(s, 1); /* protocolMajorVersion, must be set to 1 */
|
|
|
|
Stream_Write_UINT16(s, RDPDR_MINOR_RDP_VERSION_5_2); /* protocolMinorVersion */
|
|
|
|
Stream_Write_UINT32(s, 0x0000FFFF); /* ioCode1 */
|
|
|
|
Stream_Write_UINT32(s, 0); /* ioCode2, must be set to zero, reserved for future use */
|
|
|
|
Stream_Write_UINT32(s, RDPDR_DEVICE_REMOVE_PDUS | RDPDR_CLIENT_DISPLAY_NAME_PDU | RDPDR_USER_LOGGEDON_PDU); /* extendedPDU */
|
|
|
|
Stream_Write_UINT32(s, ENABLE_ASYNCIO); /* extraFlags1 */
|
|
|
|
Stream_Write_UINT32(s, 0); /* extraFlags2, must be set to zero, reserved for future use */
|
|
|
|
Stream_Write_UINT32(s, 0); /* SpecialTypeDeviceCap, number of special devices to be redirected before logon */
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process device direction general capability set */
|
2016-01-27 21:26:52 +03:00
|
|
|
static UINT rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 capabilityLength;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityLength);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek(s, capabilityLength - 4);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Output printer direction capability set */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_printer_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_capset_header(s, CAP_PRINTER_TYPE, 8, PRINT_CAPABILITY_VERSION_01);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process printer direction capability set */
|
2016-01-27 21:26:52 +03:00
|
|
|
static UINT rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 capabilityLength;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityLength);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek(s, capabilityLength - 4);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Output port redirection capability set */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_port_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_capset_header(s, CAP_PORT_TYPE, 8, PORT_CAPABILITY_VERSION_01);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process port redirection capability set */
|
2016-01-27 21:26:52 +03:00
|
|
|
static UINT rdpdr_process_port_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 capabilityLength;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityLength);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek(s, capabilityLength - 4);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Output drive redirection capability set */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_drive_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_capset_header(s, CAP_DRIVE_TYPE, 8, DRIVE_CAPABILITY_VERSION_02);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process drive redirection capability set */
|
2016-01-27 21:26:52 +03:00
|
|
|
static UINT rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 capabilityLength;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityLength);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek(s, capabilityLength - 4);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Output smart card redirection capability set */
|
2013-08-19 02:09:12 +04:00
|
|
|
static void rdpdr_write_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_capset_header(s, CAP_SMARTCARD_TYPE, 8, SMARTCARD_CAPABILITY_VERSION_01);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process smartcard redirection capability set */
|
2016-01-27 21:26:52 +03:00
|
|
|
static UINT rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 capabilityLength;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityLength);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, capabilityLength - 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek(s, capabilityLength - 4);
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
2016-01-24 17:21:06 +03:00
|
|
|
UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2016-01-27 21:26:52 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 i;
|
|
|
|
UINT16 numCapabilities;
|
|
|
|
UINT16 capabilityType;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-24 17:21:06 +03:00
|
|
|
if (!rdpdr || !s)
|
2016-01-27 21:26:52 +03:00
|
|
|
return CHANNEL_RC_NULL_DATA;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
2016-01-24 17:21:06 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, numCapabilities);
|
|
|
|
Stream_Seek(s, 2); /* pad (2 bytes) */
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, sizeof(UINT16) * numCapabilities))
|
|
|
|
return CHANNEL_RC_NO_BUFFER;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
for (i = 0; i < numCapabilities; i++)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, capabilityType);
|
2011-08-05 11:43:48 +04:00
|
|
|
|
|
|
|
switch (capabilityType)
|
|
|
|
{
|
2016-01-27 21:26:52 +03:00
|
|
|
case CAP_GENERAL_TYPE:
|
|
|
|
status = rdpdr_process_general_capset(rdpdr, s);
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
case CAP_PRINTER_TYPE:
|
|
|
|
rdpdr_process_printer_capset(rdpdr, s);
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
case CAP_PORT_TYPE:
|
|
|
|
rdpdr_process_port_capset(rdpdr, s);
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
case CAP_DRIVE_TYPE:
|
|
|
|
rdpdr_process_drive_capset(rdpdr, s);
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
case CAP_SMARTCARD_TYPE:
|
|
|
|
rdpdr_process_smartcard_capset(rdpdr, s);
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2016-01-27 21:26:52 +03:00
|
|
|
default:
|
|
|
|
break;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
2016-01-27 21:26:52 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
return status;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
2016-01-24 17:21:06 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpdr_send_capability_response(rdpdrPlugin* rdpdr)
|
2011-08-05 11:43:48 +04:00
|
|
|
{
|
2013-08-19 02:09:12 +04:00
|
|
|
wStream* s;
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
s = Stream_New(NULL, 256);
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, RDPDR_CTYP_CORE);
|
|
|
|
Stream_Write_UINT16(s, PAKID_CORE_CLIENT_CAPABILITY);
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, 5); /* numCapabilities */
|
|
|
|
Stream_Write_UINT16(s, 0); /* pad */
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_write_general_capset(rdpdr, s);
|
|
|
|
rdpdr_write_printer_capset(rdpdr, s);
|
|
|
|
rdpdr_write_port_capset(rdpdr, s);
|
|
|
|
rdpdr_write_drive_capset(rdpdr, s);
|
|
|
|
rdpdr_write_smartcard_capset(rdpdr, s);
|
2011-08-05 11:43:48 +04:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return rdpdr_send(rdpdr, s);
|
2011-08-05 11:43:48 +04:00
|
|
|
}
|