2012-04-19 22:09:27 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Request To Send (RTS) PDUs
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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-11-16 01:25:22 +04:00
|
|
|
#include <winpr/crt.h>
|
2016-02-24 22:39:49 +03:00
|
|
|
#include <winpr/crypto.h>
|
2013-12-18 21:59:53 +04:00
|
|
|
#include <winpr/winhttp.h>
|
2012-11-16 01:25:22 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
|
2012-11-28 07:26:57 +04:00
|
|
|
#include "ncacn_http.h"
|
2012-11-29 07:03:18 +04:00
|
|
|
#include "rpc_client.h"
|
2012-11-28 07:26:57 +04:00
|
|
|
|
2012-04-19 22:09:27 +04:00
|
|
|
#include "rts.h"
|
|
|
|
|
2015-02-03 02:50:26 +03:00
|
|
|
#define TAG FREERDP_TAG("core.gateway.rts")
|
2014-09-12 16:36:29 +04:00
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
/**
|
|
|
|
* RTS PDU Header
|
|
|
|
*
|
|
|
|
* The RTS PDU Header has the same layout as the common header of the connection-oriented RPC
|
|
|
|
* PDU as specified in [C706] section 12.6.1, with a few additional requirements around the contents
|
|
|
|
* of the header fields. The additional requirements are as follows:
|
|
|
|
*
|
|
|
|
* All fields MUST use little-endian byte order.
|
|
|
|
*
|
|
|
|
* Fragmentation MUST NOT occur for an RTS PDU.
|
|
|
|
*
|
|
|
|
* PFC_FIRST_FRAG and PFC_LAST_FRAG MUST be present in all RTS PDUs, and all other PFC flags
|
|
|
|
* MUST NOT be present.
|
|
|
|
*
|
|
|
|
* The rpc_vers and rpc_vers_minor fields MUST contain version information as described in
|
|
|
|
* [MS-RPCE] section 1.7.
|
|
|
|
*
|
|
|
|
* PTYPE MUST be set to a value of 20 (0x14). This field differentiates RTS packets from other RPC packets.
|
|
|
|
*
|
|
|
|
* The packed_drep MUST indicate little-endian integer and floating-pointer byte order, IEEE float-point
|
|
|
|
* format representation, and ASCII character format as specified in [C706] section 12.6.
|
|
|
|
*
|
|
|
|
* The auth_length MUST be set to 0.
|
|
|
|
*
|
|
|
|
* The frag_length field MUST reflect the size of the header plus the size of all commands, including
|
|
|
|
* the variable portion of variable-sized commands.
|
|
|
|
*
|
|
|
|
* The call_id MUST be set to 0 by senders and MUST be 0 on receipt.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static void rts_pdu_header_init(rpcconn_rts_hdr_t* header)
|
2012-11-01 05:23:08 +04:00
|
|
|
{
|
2014-05-21 19:32:14 +04:00
|
|
|
ZeroMemory(header, sizeof(*header));
|
2012-11-16 02:58:40 +04:00
|
|
|
header->rpc_vers = 5;
|
|
|
|
header->rpc_vers_minor = 0;
|
|
|
|
header->ptype = PTYPE_RTS;
|
|
|
|
header->packed_drep[0] = 0x10;
|
|
|
|
header->packed_drep[1] = 0x00;
|
|
|
|
header->packed_drep[2] = 0x00;
|
|
|
|
header->packed_drep[3] = 0x00;
|
|
|
|
header->pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
|
|
|
|
header->auth_length = 0;
|
|
|
|
header->call_id = 0;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_receive_window_size_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length,
|
2017-02-20 20:31:58 +03:00
|
|
|
UINT32* ReceiveWindowSize)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-17 03:30:53 +04:00
|
|
|
if (ReceiveWindowSize)
|
|
|
|
*ReceiveWindowSize = *((UINT32*) &buffer[0]); /* ReceiveWindowSize (4 bytes) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_receive_window_size_command_write(BYTE* buffer, UINT32 ReceiveWindowSize)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_RECEIVE_WINDOW_SIZE; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = ReceiveWindowSize; /* ReceiveWindowSize (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_flow_control_ack_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length,
|
|
|
|
UINT32* BytesReceived, UINT32* AvailableWindow, BYTE* ChannelCookie)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
|
|
|
/* Ack (24 bytes) */
|
2012-11-17 06:56:53 +04:00
|
|
|
if (BytesReceived)
|
|
|
|
*BytesReceived = *((UINT32*) &buffer[0]); /* BytesReceived (4 bytes) */
|
|
|
|
|
|
|
|
if (AvailableWindow)
|
|
|
|
*AvailableWindow = *((UINT32*) &buffer[4]); /* AvailableWindow (4 bytes) */
|
|
|
|
|
|
|
|
if (ChannelCookie)
|
|
|
|
CopyMemory(ChannelCookie, &buffer[8], 16); /* ChannelCookie (16 bytes) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 24;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_flow_control_ack_command_write(BYTE* buffer, UINT32 BytesReceived,
|
|
|
|
UINT32 AvailableWindow,
|
|
|
|
BYTE* ChannelCookie)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_FLOW_CONTROL_ACK; /* CommandType (4 bytes) */
|
|
|
|
/* Ack (24 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = BytesReceived; /* BytesReceived (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[8]) = AvailableWindow; /* AvailableWindow (4 bytes) */
|
|
|
|
CopyMemory(&buffer[12], ChannelCookie, 16); /* ChannelCookie (16 bytes) */
|
|
|
|
}
|
2012-11-16 01:25:22 +04:00
|
|
|
|
|
|
|
return 28;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_connection_timeout_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length,
|
|
|
|
UINT32* ConnectionTimeout)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-17 00:51:12 +04:00
|
|
|
if (ConnectionTimeout)
|
|
|
|
*ConnectionTimeout = *((UINT32*) &buffer[0]); /* ConnectionTimeout (4 bytes) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_connection_timeout_command_write(BYTE* buffer, UINT32 ConnectionTimeout)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_CONNECTION_TIMEOUT; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = ConnectionTimeout; /* ConnectionTimeout (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_cookie_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* Cookie (16 bytes) */
|
|
|
|
return 16;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_cookie_command_write(BYTE* buffer, BYTE* Cookie)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_COOKIE; /* CommandType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], Cookie, 16); /* Cookie (16 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 20;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_channel_lifetime_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* ChannelLifetime (4 bytes) */
|
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_channel_lifetime_command_write(BYTE* buffer, UINT32 ChannelLifetime)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_CHANNEL_LIFETIME; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = ChannelLifetime; /* ChannelLifetime (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_client_keepalive_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* ClientKeepalive (4 bytes) */
|
|
|
|
return 4;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_client_keepalive_command_write(BYTE* buffer, UINT32 ClientKeepalive)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-17 03:30:53 +04:00
|
|
|
/**
|
|
|
|
* An unsigned integer that specifies the keep-alive interval, in milliseconds,
|
|
|
|
* that this connection is configured to use. This value MUST be 0 or in the inclusive
|
|
|
|
* range of 60,000 through 4,294,967,295. If it is 0, it MUST be interpreted as 300,000.
|
|
|
|
*/
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_CLIENT_KEEPALIVE; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = ClientKeepalive; /* ClientKeepalive (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_version_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* Version (4 bytes) */
|
|
|
|
return 4;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_version_command_write(BYTE* buffer)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_VERSION; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = 1; /* Version (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_empty_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
return 0;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_empty_command_write(BYTE* buffer)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_EMPTY; /* CommandType (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 13:08:27 +03:00
|
|
|
static SSIZE_T rts_padding_command_read(const BYTE* buffer, size_t length)
|
2012-04-19 23:43:20 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ConformanceCount;
|
2012-11-16 03:20:14 +04:00
|
|
|
ConformanceCount = *((UINT32*) &buffer[0]); /* ConformanceCount (4 bytes) */
|
|
|
|
/* Padding (variable) */
|
|
|
|
return ConformanceCount + 4;
|
2012-04-19 23:43:20 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_padding_command_write(BYTE* buffer, UINT32 ConformanceCount)
|
2012-04-19 22:09:27 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_PADDING; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = ConformanceCount; /* ConformanceCount (4 bytes) */
|
|
|
|
ZeroMemory(&buffer[8], ConformanceCount); /* Padding (variable) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8 + ConformanceCount;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_negative_ance_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
return 0;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
2012-04-19 23:43:20 +04:00
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_negative_ance_command_write(BYTE* buffer)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_NEGATIVE_ANCE; /* CommandType (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_ance_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
return 0;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_ance_command_write(BYTE* buffer)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_ANCE; /* CommandType (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 13:08:27 +03:00
|
|
|
static SSIZE_T rts_client_address_command_read(const BYTE* buffer, size_t length)
|
2012-04-19 23:43:20 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 AddressType;
|
2012-11-16 03:20:14 +04:00
|
|
|
AddressType = *((UINT32*) &buffer[0]); /* AddressType (4 bytes) */
|
2012-04-19 23:43:20 +04:00
|
|
|
|
|
|
|
if (AddressType == 0)
|
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* ClientAddress (4 bytes) */
|
|
|
|
/* padding (12 bytes) */
|
|
|
|
return 4 + 4 + 12;
|
2012-04-19 23:43:20 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* ClientAddress (16 bytes) */
|
|
|
|
/* padding (12 bytes) */
|
|
|
|
return 4 + 16 + 12;
|
2012-04-19 23:43:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_client_address_command_write(BYTE* buffer, UINT32 AddressType, BYTE* ClientAddress)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_CLIENT_ADDRESS; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = AddressType; /* AddressType (4 bytes) */
|
|
|
|
}
|
2012-04-21 01:00:00 +04:00
|
|
|
|
|
|
|
if (AddressType == 0)
|
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
CopyMemory(&buffer[8], ClientAddress, 4); /* ClientAddress (4 bytes) */
|
|
|
|
ZeroMemory(&buffer[12], 12); /* padding (12 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 24;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
CopyMemory(&buffer[8], ClientAddress, 16); /* ClientAddress (16 bytes) */
|
|
|
|
ZeroMemory(&buffer[24], 12); /* padding (12 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 36;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_association_group_id_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* AssociationGroupId (16 bytes) */
|
|
|
|
return 16;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_association_group_id_command_write(BYTE* buffer, BYTE* AssociationGroupId)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_ASSOCIATION_GROUP_ID; /* CommandType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], AssociationGroupId, 16); /* AssociationGroupId (16 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 20;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_destination_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length,
|
|
|
|
UINT32* Destination)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-17 06:56:53 +04:00
|
|
|
if (Destination)
|
|
|
|
*Destination = *((UINT32*) &buffer[0]); /* Destination (4 bytes) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_destination_command_write(BYTE* buffer, UINT32 Destination)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_DESTINATION; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = Destination; /* Destination (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_ping_traffic_sent_notify_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 03:20:14 +04:00
|
|
|
/* PingTrafficSent (4 bytes) */
|
|
|
|
return 4;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_ping_traffic_sent_notify_command_write(BYTE* buffer, UINT32 PingTrafficSent)
|
2012-04-21 01:00:00 +04:00
|
|
|
{
|
2012-11-16 20:25:10 +04:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
*((UINT32*) &buffer[0]) = RTS_CMD_PING_TRAFFIC_SENT_NOTIFY; /* CommandType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = PingTrafficSent; /* PingTrafficSent (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
return 8;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2012-10-29 23:02:35 +04:00
|
|
|
void rts_generate_cookie(BYTE* cookie)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2016-02-24 22:39:49 +03:00
|
|
|
winpr_RAND(cookie, 16);
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
/* CONN/A Sequence */
|
|
|
|
|
|
|
|
int rts_send_CONN_A1_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status;
|
2012-11-16 01:52:49 +04:00
|
|
|
BYTE* buffer;
|
2012-11-16 02:58:40 +04:00
|
|
|
rpcconn_rts_hdr_t header;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ReceiveWindowSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* OUTChannelCookie;
|
|
|
|
BYTE* VirtualConnectionCookie;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
RpcOutChannel* outChannel = connection->DefaultOutChannel;
|
2012-11-16 02:58:40 +04:00
|
|
|
rts_pdu_header_init(&header);
|
2012-04-22 00:18:07 +04:00
|
|
|
header.frag_length = 76;
|
2012-11-16 02:58:40 +04:00
|
|
|
header.Flags = RTS_FLAG_NONE;
|
|
|
|
header.NumberOfCommands = 4;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Sending CONN/A1 RTS PDU");
|
2018-01-15 14:43:37 +03:00
|
|
|
VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
|
2018-09-27 17:05:14 +03:00
|
|
|
OUTChannelCookie = (BYTE*) & (outChannel->common.Cookie);
|
2015-02-12 22:08:38 +03:00
|
|
|
ReceiveWindowSize = outChannel->ReceiveWindow;
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
2015-02-02 04:47:43 +03:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2012-11-16 01:52:49 +04:00
|
|
|
|
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_version_command_write(&buffer[20]); /* Version (8 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_cookie_command_write(&buffer[28],
|
|
|
|
VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
2012-11-16 01:52:49 +04:00
|
|
|
rts_cookie_command_write(&buffer[48], OUTChannelCookie); /* OUTChannelCookie (20 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_receive_window_size_command_write(&buffer[68],
|
|
|
|
ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&outChannel->common, buffer, header.frag_length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
int rts_recv_CONN_A3_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
|
|
|
{
|
|
|
|
UINT32 ConnectionTimeout;
|
|
|
|
rts_connection_timeout_command_read(rpc, &buffer[24], length - 24, &ConnectionTimeout);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "Receiving CONN/A3 RTS PDU: ConnectionTimeout: %"PRIu32"", ConnectionTimeout);
|
2012-11-17 03:30:53 +04:00
|
|
|
rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = ConnectionTimeout;
|
2015-02-03 22:44:31 +03:00
|
|
|
return 1;
|
2012-11-17 00:51:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CONN/B Sequence */
|
|
|
|
|
|
|
|
int rts_send_CONN_B1_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2015-02-02 04:47:43 +03:00
|
|
|
int status;
|
2012-11-16 01:52:49 +04:00
|
|
|
BYTE* buffer;
|
2012-12-13 07:03:40 +04:00
|
|
|
UINT32 length;
|
2012-11-16 02:58:40 +04:00
|
|
|
rpcconn_rts_hdr_t header;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* INChannelCookie;
|
|
|
|
BYTE* AssociationGroupId;
|
|
|
|
BYTE* VirtualConnectionCookie;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
RpcInChannel* inChannel = connection->DefaultInChannel;
|
2012-11-16 02:58:40 +04:00
|
|
|
rts_pdu_header_init(&header);
|
2012-04-22 00:18:07 +04:00
|
|
|
header.frag_length = 104;
|
2012-11-16 02:58:40 +04:00
|
|
|
header.Flags = RTS_FLAG_NONE;
|
|
|
|
header.NumberOfCommands = 6;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Sending CONN/B1 RTS PDU");
|
2018-01-15 14:43:37 +03:00
|
|
|
VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
|
2018-09-27 17:05:14 +03:00
|
|
|
INChannelCookie = (BYTE*) & (inChannel->common.Cookie);
|
2018-01-15 14:43:37 +03:00
|
|
|
AssociationGroupId = (BYTE*) & (connection->AssociationGroupId);
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
2015-02-02 04:47:43 +03:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_version_command_write(&buffer[20]); /* Version (8 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_cookie_command_write(&buffer[28],
|
|
|
|
VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
2012-11-16 01:52:49 +04:00
|
|
|
rts_cookie_command_write(&buffer[48], INChannelCookie); /* INChannelCookie (20 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_channel_lifetime_command_write(&buffer[68],
|
|
|
|
rpc->ChannelLifetime); /* ChannelLifetime (8 bytes) */
|
|
|
|
rts_client_keepalive_command_write(&buffer[76],
|
|
|
|
rpc->KeepAliveInterval); /* ClientKeepalive (8 bytes) */
|
|
|
|
rts_association_group_id_command_write(&buffer[84],
|
|
|
|
AssociationGroupId); /* AssociationGroupId (20 bytes) */
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&inChannel->common, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
/* CONN/C Sequence */
|
|
|
|
|
|
|
|
int rts_recv_CONN_C2_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
|
|
|
{
|
2012-11-17 03:30:53 +04:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 ReceiveWindowSize;
|
|
|
|
UINT32 ConnectionTimeout;
|
|
|
|
offset = 24;
|
|
|
|
offset += rts_version_command_read(rpc, &buffer[offset], length - offset) + 4;
|
2017-02-20 20:31:58 +03:00
|
|
|
offset += rts_receive_window_size_command_read(rpc, &buffer[offset], length - offset,
|
|
|
|
&ReceiveWindowSize) + 4;
|
|
|
|
offset += rts_connection_timeout_command_read(rpc, &buffer[offset], length - offset,
|
|
|
|
&ConnectionTimeout) + 4;
|
|
|
|
WLog_DBG(TAG,
|
|
|
|
"Receiving CONN/C2 RTS PDU: ConnectionTimeout: %"PRIu32" ReceiveWindowSize: %"PRIu32"",
|
|
|
|
ConnectionTimeout, ReceiveWindowSize);
|
2012-11-17 03:30:53 +04:00
|
|
|
rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = ConnectionTimeout;
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->PeerReceiveWindow = ReceiveWindowSize;
|
2015-02-03 22:44:31 +03:00
|
|
|
return 1;
|
2012-11-17 00:51:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Out-of-Sequence PDUs */
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_send_keep_alive_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status;
|
2012-11-16 01:25:22 +04:00
|
|
|
BYTE* buffer;
|
2012-12-13 07:03:40 +04:00
|
|
|
UINT32 length;
|
2012-11-16 02:58:40 +04:00
|
|
|
rpcconn_rts_hdr_t header;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
|
2012-11-16 02:58:40 +04:00
|
|
|
rts_pdu_header_init(&header);
|
2012-04-22 00:18:07 +04:00
|
|
|
header.frag_length = 28;
|
2012-11-16 02:58:40 +04:00
|
|
|
header.Flags = RTS_FLAG_OTHER_CMD;
|
|
|
|
header.NumberOfCommands = 1;
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_DBG(TAG, "Sending Keep-Alive RTS PDU");
|
2012-11-16 01:25:22 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
2015-02-02 04:47:43 +03:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2015-02-02 04:47:43 +03:00
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_client_keepalive_command_write(&buffer[20],
|
|
|
|
rpc->CurrentKeepAliveInterval); /* ClientKeepAlive (8 bytes) */
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&inChannel->common, buffer, length);
|
2012-11-16 01:25:22 +04:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status;
|
2012-11-16 01:52:49 +04:00
|
|
|
BYTE* buffer;
|
2012-12-13 07:03:40 +04:00
|
|
|
UINT32 length;
|
2012-11-16 02:58:40 +04:00
|
|
|
rpcconn_rts_hdr_t header;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 BytesReceived;
|
|
|
|
UINT32 AvailableWindow;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* ChannelCookie;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
RpcInChannel* inChannel = connection->DefaultInChannel;
|
|
|
|
RpcOutChannel* outChannel = connection->DefaultOutChannel;
|
2012-11-16 02:58:40 +04:00
|
|
|
rts_pdu_header_init(&header);
|
2012-04-22 00:18:07 +04:00
|
|
|
header.frag_length = 56;
|
2012-11-16 02:58:40 +04:00
|
|
|
header.Flags = RTS_FLAG_OTHER_CMD;
|
|
|
|
header.NumberOfCommands = 2;
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_DBG(TAG, "Sending FlowControlAck RTS PDU");
|
2015-02-12 22:08:38 +03:00
|
|
|
BytesReceived = outChannel->BytesReceived;
|
|
|
|
AvailableWindow = outChannel->AvailableWindowAdvertised;
|
2018-09-27 17:05:14 +03:00
|
|
|
ChannelCookie = (BYTE*) & (outChannel->common.Cookie);
|
2015-02-12 22:08:38 +03:00
|
|
|
outChannel->ReceiverAvailableWindow = outChannel->AvailableWindowAdvertised;
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_destination_command_write(&buffer[20], FDOutProxy); /* Destination Command (8 bytes) */
|
|
|
|
/* FlowControlAck Command (28 bytes) */
|
|
|
|
rts_flow_control_ack_command_write(&buffer[28], BytesReceived, AvailableWindow, ChannelCookie);
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&inChannel->common, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_recv_flow_control_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-11-28 03:34:00 +04:00
|
|
|
{
|
2012-12-13 20:01:13 +04:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 BytesReceived;
|
|
|
|
UINT32 AvailableWindow;
|
|
|
|
BYTE ChannelCookie[16];
|
|
|
|
offset = 24;
|
|
|
|
offset += rts_flow_control_ack_command_read(rpc, &buffer[offset], length - offset,
|
2017-02-20 20:31:58 +03:00
|
|
|
&BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4;
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Receiving FlowControlAck RTS PDU: BytesReceived: %"PRIu32" AvailableWindow: %"PRIu32"",
|
|
|
|
BytesReceived, AvailableWindow);
|
2012-12-13 20:01:13 +04:00
|
|
|
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow =
|
2017-02-20 20:31:58 +03:00
|
|
|
AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived);
|
2015-02-03 22:44:31 +03:00
|
|
|
return 1;
|
2012-11-28 03:34:00 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-11-17 06:56:53 +04:00
|
|
|
{
|
|
|
|
UINT32 offset;
|
|
|
|
UINT32 Destination;
|
|
|
|
UINT32 BytesReceived;
|
|
|
|
UINT32 AvailableWindow;
|
|
|
|
BYTE ChannelCookie[16];
|
|
|
|
/**
|
|
|
|
* When the sender receives a FlowControlAck RTS PDU, it MUST use the following formula to
|
|
|
|
* recalculate its Sender AvailableWindow variable:
|
|
|
|
*
|
|
|
|
* Sender AvailableWindow = Receiver AvailableWindow_from_ack - (BytesSent - BytesReceived_from_ack)
|
|
|
|
*
|
|
|
|
* Where:
|
|
|
|
*
|
|
|
|
* Receiver AvailableWindow_from_ack is the Available Window field in the Flow Control
|
|
|
|
* Acknowledgement Structure (section 2.2.3.4) in the PDU received.
|
|
|
|
*
|
|
|
|
* BytesReceived_from_ack is the Bytes Received field in the Flow Control Acknowledgement structure
|
|
|
|
* in the PDU received.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
offset = 24;
|
|
|
|
offset += rts_destination_command_read(rpc, &buffer[offset], length - offset, &Destination) + 4;
|
|
|
|
offset += rts_flow_control_ack_command_read(rpc, &buffer[offset], length - offset,
|
2017-02-20 20:31:58 +03:00
|
|
|
&BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4;
|
|
|
|
WLog_DBG(TAG,
|
|
|
|
"Receiving FlowControlAckWithDestination RTS PDU: BytesReceived: %"PRIu32" AvailableWindow: %"PRIu32"",
|
|
|
|
BytesReceived, AvailableWindow);
|
2012-11-27 13:05:41 +04:00
|
|
|
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow =
|
2017-02-20 20:31:58 +03:00
|
|
|
AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived);
|
2015-02-03 22:44:31 +03:00
|
|
|
return 1;
|
2012-11-17 06:56:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static int rts_send_ping_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status;
|
2012-11-16 01:52:49 +04:00
|
|
|
BYTE* buffer;
|
2012-12-13 07:03:40 +04:00
|
|
|
UINT32 length;
|
2012-11-16 02:58:40 +04:00
|
|
|
rpcconn_rts_hdr_t header;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
|
2012-11-16 02:58:40 +04:00
|
|
|
rts_pdu_header_init(&header);
|
2012-04-22 00:18:07 +04:00
|
|
|
header.frag_length = 20;
|
2012-11-16 02:58:40 +04:00
|
|
|
header.Flags = RTS_FLAG_PING;
|
|
|
|
header.NumberOfCommands = 0;
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_DBG(TAG, "Sending Ping RTS PDU");
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&inChannel->common, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 13:08:27 +03:00
|
|
|
SSIZE_T rts_command_length(UINT32 CommandType, const BYTE* buffer, size_t length)
|
2012-11-16 22:31:16 +04:00
|
|
|
{
|
|
|
|
int CommandLength = 0;
|
|
|
|
|
|
|
|
switch (CommandType)
|
|
|
|
{
|
|
|
|
case RTS_CMD_RECEIVE_WINDOW_SIZE:
|
|
|
|
CommandLength = RTS_CMD_RECEIVE_WINDOW_SIZE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_FLOW_CONTROL_ACK:
|
|
|
|
CommandLength = RTS_CMD_FLOW_CONTROL_ACK_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_CONNECTION_TIMEOUT:
|
|
|
|
CommandLength = RTS_CMD_CONNECTION_TIMEOUT_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_COOKIE:
|
|
|
|
CommandLength = RTS_CMD_COOKIE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_CHANNEL_LIFETIME:
|
|
|
|
CommandLength = RTS_CMD_CHANNEL_LIFETIME_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_CLIENT_KEEPALIVE:
|
|
|
|
CommandLength = RTS_CMD_CLIENT_KEEPALIVE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_VERSION:
|
|
|
|
CommandLength = RTS_CMD_VERSION_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_EMPTY:
|
|
|
|
CommandLength = RTS_CMD_EMPTY_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_PADDING: /* variable-size */
|
2018-09-28 13:08:27 +03:00
|
|
|
CommandLength = rts_padding_command_read(buffer, length);
|
2012-11-16 22:31:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_NEGATIVE_ANCE:
|
|
|
|
CommandLength = RTS_CMD_NEGATIVE_ANCE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_ANCE:
|
|
|
|
CommandLength = RTS_CMD_ANCE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_CLIENT_ADDRESS: /* variable-size */
|
2018-09-28 13:08:27 +03:00
|
|
|
CommandLength = rts_client_address_command_read(buffer, length);
|
2012-11-16 22:31:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_ASSOCIATION_GROUP_ID:
|
|
|
|
CommandLength = RTS_CMD_ASSOCIATION_GROUP_ID_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_DESTINATION:
|
|
|
|
CommandLength = RTS_CMD_DESTINATION_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTS_CMD_PING_TRAFFIC_SENT_NOTIFY:
|
|
|
|
CommandLength = RTS_CMD_PING_TRAFFIC_SENT_NOTIFY_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Error: Unknown RTS Command Type: 0x%"PRIx32"", CommandType);
|
2012-11-16 22:31:16 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CommandLength;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_send_OUT_R2_A7_pdu(rdpRpc* rpc)
|
2015-02-12 21:14:43 +03:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
rpcconn_rts_hdr_t header;
|
|
|
|
BYTE* SuccessorChannelCookie;
|
2015-02-19 21:41:00 +03:00
|
|
|
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcOutChannel* nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel;
|
2015-02-12 21:14:43 +03:00
|
|
|
rts_pdu_header_init(&header);
|
|
|
|
header.frag_length = 56;
|
|
|
|
header.Flags = RTS_FLAG_OUT_CHANNEL;
|
|
|
|
header.NumberOfCommands = 3;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Sending OUT_R2/A7 RTS PDU");
|
2018-09-27 17:05:14 +03:00
|
|
|
SuccessorChannelCookie = (BYTE*) & (nextOutChannel->common.Cookie);
|
2015-02-12 21:14:43 +03:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CopyMemory(buffer, ((BYTE*)&header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_destination_command_write(&buffer[20], FDServer); /* Destination (8 bytes)*/
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_cookie_command_write(&buffer[28],
|
|
|
|
SuccessorChannelCookie); /* SuccessorChannelCookie (20 bytes) */
|
2015-02-12 21:14:43 +03:00
|
|
|
rts_version_command_write(&buffer[48]); /* Version (8 bytes) */
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&inChannel->common, buffer, header.frag_length);
|
2015-02-12 21:14:43 +03:00
|
|
|
free(buffer);
|
|
|
|
return (status > 0) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_send_OUT_R2_C1_pdu(rdpRpc* rpc)
|
2015-02-12 21:14:43 +03:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
rpcconn_rts_hdr_t header;
|
2015-02-19 21:41:00 +03:00
|
|
|
RpcOutChannel* nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel;
|
2015-02-12 21:14:43 +03:00
|
|
|
rts_pdu_header_init(&header);
|
|
|
|
header.frag_length = 24;
|
|
|
|
header.Flags = RTS_FLAG_PING;
|
|
|
|
header.NumberOfCommands = 1;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Sending OUT_R2/C1 RTS PDU");
|
2015-02-12 21:14:43 +03:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_empty_command_write(&buffer[20]); /* Empty command (4 bytes) */
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&nextOutChannel->common, buffer, header.frag_length);
|
2015-02-12 21:14:43 +03:00
|
|
|
free(buffer);
|
|
|
|
return (status > 0) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2015-01-14 00:35:34 +03:00
|
|
|
int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
|
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status;
|
2015-01-14 00:35:34 +03:00
|
|
|
BYTE* buffer;
|
|
|
|
rpcconn_rts_hdr_t header;
|
|
|
|
UINT32 ReceiveWindowSize;
|
|
|
|
BYTE* VirtualConnectionCookie;
|
|
|
|
BYTE* PredecessorChannelCookie;
|
|
|
|
BYTE* SuccessorChannelCookie;
|
2015-02-12 22:08:38 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
RpcOutChannel* outChannel = connection->DefaultOutChannel;
|
|
|
|
RpcOutChannel* nextOutChannel = connection->NonDefaultOutChannel;
|
2015-01-14 00:35:34 +03:00
|
|
|
rts_pdu_header_init(&header);
|
|
|
|
header.frag_length = 96;
|
|
|
|
header.Flags = RTS_FLAG_RECYCLE_CHANNEL;
|
|
|
|
header.NumberOfCommands = 5;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Sending OUT_R1/A3 RTS PDU");
|
2018-01-15 14:43:37 +03:00
|
|
|
VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
|
2018-09-27 17:05:14 +03:00
|
|
|
PredecessorChannelCookie = (BYTE*) & (outChannel->common.Cookie);
|
|
|
|
SuccessorChannelCookie = (BYTE*) & (nextOutChannel->common.Cookie);
|
2015-02-12 22:08:38 +03:00
|
|
|
ReceiveWindowSize = outChannel->ReceiveWindow;
|
2015-01-14 00:35:34 +03:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_version_command_write(&buffer[20]); /* Version (8 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
rts_cookie_command_write(&buffer[28],
|
|
|
|
VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
|
|
|
rts_cookie_command_write(&buffer[48],
|
|
|
|
PredecessorChannelCookie); /* PredecessorChannelCookie (20 bytes) */
|
|
|
|
rts_cookie_command_write(&buffer[68],
|
|
|
|
SuccessorChannelCookie); /* SuccessorChannelCookie (20 bytes) */
|
|
|
|
rts_receive_window_size_command_write(&buffer[88],
|
|
|
|
ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
|
2018-09-27 17:05:14 +03:00
|
|
|
status = rpc_channel_write(&nextOutChannel->common, buffer, header.frag_length);
|
2015-01-14 00:35:34 +03:00
|
|
|
free(buffer);
|
2015-02-03 22:44:31 +03:00
|
|
|
return (status > 0) ? 1 : -1;
|
2015-01-14 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_recv_OUT_R1_A2_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2015-01-13 23:01:07 +03:00
|
|
|
{
|
2015-02-19 23:06:57 +03:00
|
|
|
int status;
|
2015-01-13 23:01:07 +03:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 Destination = 0;
|
2015-02-12 21:14:43 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_DBG(TAG, "Receiving OUT R1/A2 RTS PDU");
|
2015-01-13 23:01:07 +03:00
|
|
|
offset = 24;
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (length < offset)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rts_destination_command_read(rpc, &buffer[offset], length - offset, &Destination);
|
2015-02-19 23:06:57 +03:00
|
|
|
connection->NonDefaultOutChannel = rpc_out_channel_new(rpc);
|
2015-01-13 23:01:07 +03:00
|
|
|
|
2015-02-19 23:06:57 +03:00
|
|
|
if (!connection->NonDefaultOutChannel)
|
|
|
|
return -1;
|
2015-01-14 00:35:34 +03:00
|
|
|
|
2015-02-19 23:06:57 +03:00
|
|
|
status = rpc_out_channel_replacement_connect(connection->NonDefaultOutChannel, 5000);
|
2015-02-19 21:41:00 +03:00
|
|
|
|
2015-02-19 23:06:57 +03:00
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rpc_out_channel_replacement_connect failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
rpc_out_channel_transition_to_state(connection->DefaultOutChannel,
|
|
|
|
CLIENT_OUT_CHANNEL_STATE_OPENED_A6W);
|
2015-02-12 21:14:43 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_recv_OUT_R2_A6_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2015-02-12 21:14:43 +03:00
|
|
|
{
|
|
|
|
int status;
|
2015-02-19 23:06:57 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
WLog_DBG(TAG, "Receiving OUT R2/A6 RTS PDU");
|
2015-02-12 21:14:43 +03:00
|
|
|
status = rts_send_OUT_R2_C1_pdu(rpc);
|
2015-02-19 23:06:57 +03:00
|
|
|
|
2015-02-19 21:41:00 +03:00
|
|
|
if (status < 0)
|
|
|
|
{
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_ERR(TAG, "rts_send_OUT_R2_C1_pdu failure");
|
2015-02-19 21:41:00 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-12 21:14:43 +03:00
|
|
|
|
2015-02-19 21:41:00 +03:00
|
|
|
status = rts_send_OUT_R2_A7_pdu(rpc);
|
2015-02-19 23:06:57 +03:00
|
|
|
|
2015-02-12 21:14:43 +03:00
|
|
|
if (status < 0)
|
2015-02-19 21:41:00 +03:00
|
|
|
{
|
2015-02-19 23:06:57 +03:00
|
|
|
WLog_ERR(TAG, "rts_send_OUT_R2_A7_pdu failure");
|
2015-02-12 21:14:43 +03:00
|
|
|
return -1;
|
2015-02-19 21:41:00 +03:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
rpc_out_channel_transition_to_state(connection->NonDefaultOutChannel,
|
|
|
|
CLIENT_OUT_CHANNEL_STATE_OPENED_B3W);
|
|
|
|
rpc_out_channel_transition_to_state(connection->DefaultOutChannel,
|
|
|
|
CLIENT_OUT_CHANNEL_STATE_OPENED_B3W);
|
2015-02-12 21:14:43 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int rts_recv_OUT_R2_B3_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2015-02-12 21:14:43 +03:00
|
|
|
{
|
2015-02-19 23:06:57 +03:00
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
WLog_DBG(TAG, "Receiving OUT R2/B3 RTS PDU");
|
2017-02-20 20:31:58 +03:00
|
|
|
rpc_out_channel_transition_to_state(connection->DefaultOutChannel,
|
|
|
|
CLIENT_OUT_CHANNEL_STATE_RECYCLED);
|
2015-02-03 22:44:31 +03:00
|
|
|
return 1;
|
2015-01-13 23:01:07 +03:00
|
|
|
}
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
int rts_recv_out_of_sequence_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-11-17 06:17:04 +04:00
|
|
|
{
|
2015-02-03 22:44:31 +03:00
|
|
|
int status = -1;
|
2012-11-17 06:56:53 +04:00
|
|
|
UINT32 SignatureId;
|
2012-11-17 06:17:04 +04:00
|
|
|
rpcconn_rts_hdr_t* rts;
|
|
|
|
RtsPduSignature signature;
|
2018-09-28 13:08:27 +03:00
|
|
|
RpcVirtualConnection* connection;
|
|
|
|
|
|
|
|
if (!rpc || !buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
connection = rpc->VirtualConnection;
|
|
|
|
|
|
|
|
if (!connection)
|
|
|
|
return -1;
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
rts = (rpcconn_rts_hdr_t*) buffer;
|
2012-11-17 06:56:53 +04:00
|
|
|
|
2018-09-28 13:08:27 +03:00
|
|
|
if (!rts_extract_pdu_signature(&signature, rts))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
SignatureId = rts_identify_pdu_signature(&signature, NULL);
|
|
|
|
|
|
|
|
if (rts_match_pdu_signature(&RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE, rts))
|
2012-11-17 06:56:53 +04:00
|
|
|
{
|
2015-02-20 00:06:20 +03:00
|
|
|
status = rts_recv_flow_control_ack_pdu(rpc, buffer, length);
|
|
|
|
}
|
2018-09-28 13:08:27 +03:00
|
|
|
else if (rts_match_pdu_signature(&RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE, rts))
|
2015-02-20 00:06:20 +03:00
|
|
|
{
|
|
|
|
status = rts_recv_flow_control_ack_with_destination_pdu(rpc, buffer, length);
|
|
|
|
}
|
2018-09-28 13:08:27 +03:00
|
|
|
else if (rts_match_pdu_signature(&RTS_PDU_PING_SIGNATURE, rts))
|
2015-02-20 00:06:20 +03:00
|
|
|
{
|
|
|
|
status = rts_send_ping_pdu(rpc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED)
|
|
|
|
{
|
2018-09-28 13:08:27 +03:00
|
|
|
if (rts_match_pdu_signature(&RTS_PDU_OUT_R1_A2_SIGNATURE, rts))
|
2015-02-20 00:06:20 +03:00
|
|
|
{
|
|
|
|
status = rts_recv_OUT_R1_A2_pdu(rpc, buffer, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED_A6W)
|
|
|
|
{
|
2018-09-28 13:08:27 +03:00
|
|
|
if (rts_match_pdu_signature(&RTS_PDU_OUT_R2_A6_SIGNATURE, rts))
|
2015-02-20 00:06:20 +03:00
|
|
|
{
|
|
|
|
status = rts_recv_OUT_R2_A6_pdu(rpc, buffer, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED_B3W)
|
|
|
|
{
|
2018-09-28 13:08:27 +03:00
|
|
|
if (rts_match_pdu_signature(&RTS_PDU_OUT_R2_B3_SIGNATURE, rts))
|
2015-02-20 00:06:20 +03:00
|
|
|
{
|
|
|
|
status = rts_recv_OUT_R2_B3_pdu(rpc, buffer, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 21:41:00 +03:00
|
|
|
|
2015-02-20 00:06:20 +03:00
|
|
|
if (status < 0)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "error parsing RTS PDU with signature id: 0x%08"PRIX32"", SignatureId);
|
2018-09-28 13:08:27 +03:00
|
|
|
rts_print_pdu_signature(&signature);
|
2012-12-12 08:34:51 +04:00
|
|
|
}
|
2012-11-17 06:17:04 +04:00
|
|
|
|
2015-02-03 22:44:31 +03:00
|
|
|
return status;
|
2012-11-17 06:17:04 +04:00
|
|
|
}
|