2014-01-24 07:23:47 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Auto-Detect PDUs
|
|
|
|
*
|
|
|
|
* Copyright 2014 Dell Software <Mike.McDonald@software.dell.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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2016-02-24 22:39:49 +03:00
|
|
|
#include <winpr/crypto.h>
|
2021-06-16 15:50:14 +03:00
|
|
|
#include <winpr/assert.h>
|
2016-02-24 22:39:49 +03:00
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
#include "autodetect.h"
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RDP_RTT_REQUEST_TYPE_CONTINUOUS 0x0001
|
2014-11-11 05:14:44 +03:00
|
|
|
#define RDP_RTT_REQUEST_TYPE_CONNECTTIME 0x1001
|
|
|
|
|
|
|
|
#define RDP_RTT_RESPONSE_TYPE 0x0000
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RDP_BW_START_REQUEST_TYPE_CONTINUOUS 0x0014
|
|
|
|
#define RDP_BW_START_REQUEST_TYPE_TUNNEL 0x0114
|
2014-11-11 05:14:44 +03:00
|
|
|
#define RDP_BW_START_REQUEST_TYPE_CONNECTTIME 0x1014
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RDP_BW_PAYLOAD_REQUEST_TYPE 0x0002
|
|
|
|
#define RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME 0x002B
|
|
|
|
#define RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS 0x0429
|
|
|
|
#define RDP_BW_STOP_REQUEST_TYPE_TUNNEL 0x0629
|
2014-11-11 05:14:44 +03:00
|
|
|
|
|
|
|
#define RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME 0x0003
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS 0x000B
|
2014-11-11 05:14:44 +03:00
|
|
|
|
|
|
|
#define RDP_NETCHAR_SYNC_RESPONSE_TYPE 0x0018
|
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
#define RDP_NETCHAR_RESULTS_0x0840 0x0840U
|
|
|
|
#define RDP_NETCHAR_RESULTS_0x0880 0x0880U
|
|
|
|
#define RDP_NETCHAR_RESULTS_0x08C0 0x08C0U
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT8 headerLength;
|
|
|
|
UINT8 headerTypeId;
|
|
|
|
UINT16 sequenceNumber;
|
|
|
|
UINT16 requestType;
|
|
|
|
} AUTODETECT_REQ_PDU;
|
|
|
|
|
2014-10-28 11:06:04 +03:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT8 headerLength;
|
|
|
|
UINT8 headerTypeId;
|
|
|
|
UINT16 sequenceNumber;
|
|
|
|
UINT16 responseType;
|
|
|
|
} AUTODETECT_RSP_PDU;
|
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
static const char* autodetect_request_type_to_string(UINT32 requestType)
|
|
|
|
{
|
|
|
|
switch (requestType)
|
|
|
|
{
|
|
|
|
case RDP_RTT_RESPONSE_TYPE:
|
|
|
|
return "RDP_RTT_RESPONSE_TYPE";
|
|
|
|
case RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME:
|
|
|
|
return "RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME";
|
|
|
|
case RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS:
|
|
|
|
return "RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS";
|
|
|
|
case RDP_RTT_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
return "RDP_RTT_REQUEST_TYPE_CONTINUOUS";
|
|
|
|
case RDP_RTT_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
return "RDP_RTT_REQUEST_TYPE_CONNECTTIME";
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
return "RDP_BW_START_REQUEST_TYPE_CONTINUOUS";
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_TUNNEL:
|
|
|
|
return "RDP_BW_START_REQUEST_TYPE_TUNNEL";
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
return "RDP_BW_START_REQUEST_TYPE_CONNECTTIME";
|
|
|
|
case RDP_BW_PAYLOAD_REQUEST_TYPE:
|
|
|
|
return "RDP_BW_PAYLOAD_REQUEST_TYPE";
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
return "RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME";
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
return "RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS";
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_TUNNEL:
|
|
|
|
return "RDP_BW_STOP_REQUEST_TYPE_TUNNEL";
|
|
|
|
case RDP_NETCHAR_RESULTS_0x0840:
|
|
|
|
return "RDP_NETCHAR_RESULTS_0x0840";
|
|
|
|
case RDP_NETCHAR_RESULTS_0x0880:
|
|
|
|
return "RDP_NETCHAR_RESULTS_0x0880";
|
|
|
|
case RDP_NETCHAR_RESULTS_0x08C0:
|
|
|
|
return "RDP_NETCHAR_RESULTS_0x08C0";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_rtt_measure_request(rdpContext* context, UINT16 sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 requestType)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
s = rdp_message_channel_pdu_init(context->rdp);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending RTT Measure Request PDU");
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x06); /* headerLength (1 byte) */
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, requestType); /* requestType (2 bytes) */
|
2019-09-02 16:44:52 +03:00
|
|
|
context->rdp->autodetect->rttMeasureStartTime = GetTickCount64();
|
2014-10-28 18:29:40 +03:00
|
|
|
return rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_continuous_rtt_measure_request(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-11-04 08:41:04 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_rtt_measure_request(context, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_RTT_REQUEST_TYPE_CONTINUOUS);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL autodetect_send_connecttime_rtt_measure_request(rdpContext* context, UINT16 sequenceNumber)
|
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_rtt_measure_request(context, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_RTT_REQUEST_TYPE_CONNECTTIME);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
static BOOL autodetect_send_rtt_measure_response(rdpRdp* rdp, UINT16 sequenceNumber)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
/* Send the response PDU to the server */
|
|
|
|
s = rdp_message_channel_pdu_init(rdp);
|
2014-02-11 07:23:59 +04:00
|
|
|
|
2014-09-25 01:23:12 +04:00
|
|
|
if (!s)
|
2014-02-11 07:23:59 +04:00
|
|
|
return FALSE;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2022-03-07 15:46:49 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending RTT Measure Response PDU (seqNumber=0x%"PRIx16")", sequenceNumber);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x06); /* headerLength (1 byte) */
|
2014-01-24 07:23:47 +04:00
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_RESPONSE); /* headerTypeId (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, RDP_RTT_RESPONSE_TYPE); /* responseType (1 byte) */
|
2014-01-24 07:23:47 +04:00
|
|
|
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_bandwidth_measure_start(rdpContext* context, UINT16 sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 requestType)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
s = rdp_message_channel_pdu_init(context->rdp);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-03-07 15:46:49 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Start PDU(seqNumber=%"PRIu16")", sequenceNumber);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x06); /* headerLength (1 byte) */
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, requestType); /* requestType (2 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
return rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_continuous_bandwidth_measure_start(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-11-04 08:41:04 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_bandwidth_measure_start(context, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_BW_START_REQUEST_TYPE_CONTINUOUS);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL autodetect_send_connecttime_bandwidth_measure_start(rdpContext* context, UINT16 sequenceNumber)
|
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_bandwidth_measure_start(context, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_BW_START_REQUEST_TYPE_CONNECTTIME);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
BOOL autodetect_send_bandwidth_measure_payload(rdpContext* context, UINT16 payloadLength,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
wStream* s;
|
2018-10-02 14:18:13 +03:00
|
|
|
UCHAR* buffer = NULL;
|
2015-05-04 16:53:15 +03:00
|
|
|
BOOL bResult = FALSE;
|
2014-10-28 18:29:40 +03:00
|
|
|
s = rdp_message_channel_pdu_init(context->rdp);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Payload PDU -> payloadLength=%" PRIu16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
payloadLength);
|
2014-10-28 18:29:40 +03:00
|
|
|
/* 4-bytes aligned */
|
|
|
|
payloadLength &= ~3;
|
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 8 + payloadLength))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x08); /* headerLength (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
2014-11-11 05:14:44 +03:00
|
|
|
Stream_Write_UINT16(s, RDP_BW_PAYLOAD_REQUEST_TYPE); /* requestType (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
/* Random data (better measurement in case the line is compressed) */
|
2018-10-02 14:18:13 +03:00
|
|
|
buffer = (UCHAR*)malloc(payloadLength);
|
|
|
|
|
2015-05-02 19:06:18 +03:00
|
|
|
if (NULL == buffer)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
2015-05-04 16:53:15 +03:00
|
|
|
Stream_Release(s);
|
2015-05-02 19:06:18 +03:00
|
|
|
return FALSE;
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 22:39:49 +03:00
|
|
|
winpr_RAND(buffer, payloadLength);
|
2015-04-30 17:12:37 +03:00
|
|
|
Stream_Write(s, buffer, payloadLength);
|
2015-05-04 16:53:15 +03:00
|
|
|
bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
2015-05-04 20:14:00 +03:00
|
|
|
free(buffer);
|
2015-05-04 16:53:15 +03:00
|
|
|
return bResult;
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_bandwidth_measure_stop(rdpContext* context, UINT16 payloadLength,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber, UINT16 requestType)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
wStream* s;
|
2018-10-02 14:18:13 +03:00
|
|
|
UCHAR* buffer = NULL;
|
2015-05-04 16:53:15 +03:00
|
|
|
BOOL bResult = FALSE;
|
2014-10-28 18:29:40 +03:00
|
|
|
s = rdp_message_channel_pdu_init(context->rdp);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Stop PDU -> payloadLength=%" PRIu16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
payloadLength);
|
2014-10-28 18:29:40 +03:00
|
|
|
/* 4-bytes aligned */
|
|
|
|
payloadLength &= ~3;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME
|
|
|
|
? 0x08
|
|
|
|
: 0x06); /* headerLength (1 byte) */
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, requestType); /* requestType (2 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2014-11-11 05:14:44 +03:00
|
|
|
if (requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
2014-11-04 08:41:04 +03:00
|
|
|
Stream_Write_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2014-11-04 08:41:04 +03:00
|
|
|
if (payloadLength > 0)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, payloadLength))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-04-30 17:12:37 +03:00
|
|
|
|
2014-11-04 08:41:04 +03:00
|
|
|
/* Random data (better measurement in case the line is compressed) */
|
2015-04-30 17:12:37 +03:00
|
|
|
buffer = malloc(payloadLength);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-05-02 19:06:18 +03:00
|
|
|
if (NULL == buffer)
|
2014-11-04 08:41:04 +03:00
|
|
|
{
|
2015-05-04 16:53:15 +03:00
|
|
|
Stream_Release(s);
|
2015-05-02 19:06:18 +03:00
|
|
|
return FALSE;
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
2015-05-02 19:06:18 +03:00
|
|
|
|
2016-02-24 22:39:49 +03:00
|
|
|
winpr_RAND(buffer, payloadLength);
|
2015-04-30 17:12:37 +03:00
|
|
|
Stream_Write(s, buffer, payloadLength);
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 16:53:15 +03:00
|
|
|
bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
2015-05-04 20:14:00 +03:00
|
|
|
free(buffer);
|
2015-05-04 16:53:15 +03:00
|
|
|
return bResult;
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_continuous_bandwidth_measure_stop(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-11-04 08:41:04 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_bandwidth_measure_stop(context, 0, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
BOOL autodetect_send_connecttime_bandwidth_measure_stop(rdpContext* context, UINT16 payloadLength,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-11-04 08:41:04 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_bandwidth_measure_stop(context, payloadLength, sequenceNumber,
|
2019-11-06 17:24:51 +03:00
|
|
|
RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME);
|
2014-11-04 08:41:04 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_send_bandwidth_measure_results(rdpRdp* rdp, UINT16 responseType,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16 sequenceNumber)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2015-05-20 11:47:24 +03:00
|
|
|
BOOL success = TRUE;
|
2014-01-24 07:23:47 +04:00
|
|
|
wStream* s;
|
2019-09-02 16:44:52 +03:00
|
|
|
UINT64 timeDelta;
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Compute the total time */
|
2019-09-02 16:44:52 +03:00
|
|
|
timeDelta = GetTickCount64() - rdp->autodetect->bandwidthMeasureStartTime;
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Send the result PDU to the server */
|
|
|
|
s = rdp_message_channel_pdu_init(rdp);
|
2014-02-11 07:23:59 +04:00
|
|
|
|
2014-09-25 01:23:12 +04:00
|
|
|
if (!s)
|
2014-02-11 07:23:59 +04:00
|
|
|
return FALSE;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG,
|
2021-06-16 15:50:14 +03:00
|
|
|
"sending Bandwidth Measure Results PDU -> timeDelta=%" PRIu64 ", byteCount=%" PRIu32
|
2019-11-06 17:24:51 +03:00
|
|
|
"",
|
|
|
|
timeDelta, rdp->autodetect->bandwidthMeasureByteCount);
|
2021-06-10 10:54:35 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x0E); /* headerLength (1 byte) */
|
2014-01-24 07:23:47 +04:00
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_RESPONSE); /* headerTypeId (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, responseType); /* responseType (1 byte) */
|
2021-06-16 15:50:14 +03:00
|
|
|
Stream_Write_UINT32(s, (UINT32)MIN(timeDelta, UINT32_MAX)); /* timeDelta (4 bytes) */
|
2014-01-24 07:23:47 +04:00
|
|
|
Stream_Write_UINT32(s, rdp->autodetect->bandwidthMeasureByteCount); /* byteCount (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALLRET(rdp->autodetect->ClientBandwidthMeasureResult, success, rdp->context,
|
|
|
|
rdp->autodetect);
|
2015-05-20 11:47:24 +03:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:29:40 +03:00
|
|
|
static BOOL autodetect_send_netchar_result(rdpContext* context, UINT16 sequenceNumber)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
s = rdp_message_channel_pdu_init(context->rdp);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Network Characteristics Result PDU");
|
2014-10-28 18:29:40 +03:00
|
|
|
|
|
|
|
if (context->rdp->autodetect->netCharBandwidth > 0)
|
|
|
|
{
|
2021-02-04 11:54:48 +03:00
|
|
|
Stream_Write_UINT8(s, 0x12); /* headerLength (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, RDP_NETCHAR_RESULTS_0x08C0); /* requestType (2 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Write_UINT32(s, context->rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
context->rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
context->rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 11:54:48 +03:00
|
|
|
Stream_Write_UINT8(s, 0x0E); /* headerLength (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, RDP_NETCHAR_RESULTS_0x0840); /* requestType (2 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Write_UINT32(s, context->rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
context->rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL autodetect_send_netchar_sync(rdpRdp* rdp, UINT16 sequenceNumber)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
/* Send the response PDU to the server */
|
|
|
|
s = rdp_message_channel_pdu_init(rdp);
|
2014-02-11 07:23:59 +04:00
|
|
|
|
2014-09-25 01:23:12 +04:00
|
|
|
if (!s)
|
2014-02-11 07:23:59 +04:00
|
|
|
return FALSE;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"sending Network Characteristics Sync PDU -> bandwidth=%" PRIu32 ", rtt=%" PRIu32 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
rdp->autodetect->netCharBandwidth, rdp->autodetect->netCharAverageRTT);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x0E); /* headerLength (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_RESPONSE); /* headerTypeId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, RDP_NETCHAR_SYNC_RESPONSE_TYPE); /* responseType (1 byte) */
|
|
|
|
Stream_Write_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
|
2014-01-24 07:23:47 +04:00
|
|
|
Stream_Write_UINT32(s, rdp->autodetect->netCharAverageRTT); /* rtt (4 bytes) */
|
|
|
|
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_rtt_measure_request(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_REQ_PDU* autodetectReqPdu)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
if (autodetectReqPdu->headerLength != 0x06)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "received RTT Measure Request PDU");
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Send a response to the server */
|
|
|
|
return autodetect_send_rtt_measure_response(rdp, autodetectReqPdu->sequenceNumber);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_rtt_measure_response(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_RSP_PDU* autodetectRspPdu)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
BOOL success = TRUE;
|
|
|
|
|
|
|
|
if (autodetectRspPdu->headerLength != 0x06)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "received RTT Measure Response PDU");
|
2021-06-16 15:50:14 +03:00
|
|
|
rdp->autodetect->netCharAverageRTT =
|
|
|
|
(UINT32)MIN(GetTickCount64() - rdp->autodetect->rttMeasureStartTime, UINT32_MAX);
|
2014-10-28 18:29:40 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
if (rdp->autodetect->netCharBaseRTT == 0 ||
|
|
|
|
rdp->autodetect->netCharBaseRTT > rdp->autodetect->netCharAverageRTT)
|
|
|
|
rdp->autodetect->netCharBaseRTT = rdp->autodetect->netCharAverageRTT;
|
2014-10-28 18:29:40 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
IFCALLRET(rdp->autodetect->RTTMeasureResponse, success, rdp->context,
|
|
|
|
autodetectRspPdu->sequenceNumber);
|
2014-10-28 18:29:40 +03:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_bandwidth_measure_start(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_REQ_PDU* autodetectReqPdu)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
if (autodetectReqPdu->headerLength != 0x06)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "received Bandwidth Measure Start PDU - time=%" PRIu64 "",
|
|
|
|
GetTickCount64());
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Initialize bandwidth measurement parameters */
|
2019-09-02 16:44:52 +03:00
|
|
|
rdp->autodetect->bandwidthMeasureStartTime = GetTickCount64();
|
2014-01-24 07:23:47 +04:00
|
|
|
rdp->autodetect->bandwidthMeasureByteCount = 0;
|
|
|
|
|
2014-11-07 11:18:49 +03:00
|
|
|
/* Continuous Auto-Detection: mark the start of the measurement */
|
2014-11-11 05:14:44 +03:00
|
|
|
if (autodetectReqPdu->requestType == RDP_BW_START_REQUEST_TYPE_CONTINUOUS)
|
2014-11-07 11:18:49 +03:00
|
|
|
{
|
|
|
|
rdp->autodetect->bandwidthMeasureStarted = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_bandwidth_measure_payload(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_REQ_PDU* autodetectReqPdu)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
UINT16 payloadLength;
|
|
|
|
|
|
|
|
if (autodetectReqPdu->headerLength != 0x08)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 2))
|
2014-01-24 07:23:47 +04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
|
2020-03-02 15:54:10 +03:00
|
|
|
if (!Stream_SafeSeek(s, payloadLength))
|
|
|
|
return FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(AUTODETECT_TAG, "received Bandwidth Measure Payload PDU -> payloadLength=%" PRIu16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
payloadLength);
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Add the payload length to the bandwidth measurement parameters */
|
|
|
|
rdp->autodetect->bandwidthMeasureByteCount += payloadLength;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_bandwidth_measure_stop(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_REQ_PDU* autodetectReqPdu)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
UINT16 payloadLength;
|
|
|
|
UINT16 responseType;
|
|
|
|
|
2014-11-11 05:14:44 +03:00
|
|
|
if (autodetectReqPdu->requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
if (autodetectReqPdu->headerLength != 0x08)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 2))
|
2014-01-24 07:23:47 +04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (autodetectReqPdu->headerLength != 0x06)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
payloadLength = 0;
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:54:10 +03:00
|
|
|
if (!Stream_SafeSeek(s, payloadLength))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "received Bandwidth Measure Stop PDU -> payloadLength=%" PRIu16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
payloadLength);
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Add the payload length to the bandwidth measurement parameters */
|
|
|
|
rdp->autodetect->bandwidthMeasureByteCount += payloadLength;
|
|
|
|
|
2014-11-07 11:18:49 +03:00
|
|
|
/* Continuous Auto-Detection: mark the stop of the measurement */
|
2014-11-11 05:14:44 +03:00
|
|
|
if (autodetectReqPdu->requestType == RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS)
|
2014-11-07 11:18:49 +03:00
|
|
|
{
|
|
|
|
rdp->autodetect->bandwidthMeasureStarted = FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
/* Send a response the server */
|
2019-11-06 17:24:51 +03:00
|
|
|
responseType = autodetectReqPdu->requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME
|
|
|
|
? RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME
|
|
|
|
: RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS;
|
2018-10-02 14:18:13 +03:00
|
|
|
return autodetect_send_bandwidth_measure_results(rdp, responseType,
|
2019-11-06 17:24:51 +03:00
|
|
|
autodetectReqPdu->sequenceNumber);
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_bandwidth_measure_results(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_RSP_PDU* autodetectRspPdu)
|
2014-10-28 18:29:40 +03:00
|
|
|
{
|
|
|
|
BOOL success = TRUE;
|
|
|
|
|
|
|
|
if (autodetectRspPdu->headerLength != 0x0E)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG, "received Bandwidth Measure Results PDU");
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 8))
|
2020-03-31 10:19:17 +03:00
|
|
|
return -1;
|
2014-10-28 18:29:40 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureTimeDelta); /* timeDelta (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureByteCount); /* byteCount (4 bytes) */
|
|
|
|
|
|
|
|
if (rdp->autodetect->bandwidthMeasureTimeDelta > 0)
|
2021-06-16 15:50:14 +03:00
|
|
|
rdp->autodetect->netCharBandwidth =
|
|
|
|
(UINT32)MIN(rdp->autodetect->bandwidthMeasureByteCount * 8ULL /
|
|
|
|
rdp->autodetect->bandwidthMeasureTimeDelta,
|
|
|
|
UINT32_MAX);
|
2014-10-28 18:29:40 +03:00
|
|
|
else
|
|
|
|
rdp->autodetect->netCharBandwidth = 0;
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
IFCALLRET(rdp->autodetect->BandwidthMeasureResults, success, rdp->context,
|
|
|
|
autodetectRspPdu->sequenceNumber);
|
2014-10-28 18:29:40 +03:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL autodetect_recv_netchar_result(rdpRdp* rdp, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
AUTODETECT_REQ_PDU* autodetectReqPdu)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2014-10-28 18:29:40 +03:00
|
|
|
BOOL success = TRUE;
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
switch (autodetectReqPdu->requestType)
|
|
|
|
{
|
2021-02-04 11:54:48 +03:00
|
|
|
case RDP_NETCHAR_RESULTS_0x0840:
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
/* baseRTT and averageRTT fields are present (bandwidth field is not) */
|
2022-04-19 15:29:17 +03:00
|
|
|
if ((autodetectReqPdu->headerLength != 0x0E) ||
|
|
|
|
(!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 8)))
|
2018-10-02 14:18:13 +03:00
|
|
|
return FALSE;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
|
|
|
|
break;
|
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
case RDP_NETCHAR_RESULTS_0x0880:
|
2018-10-02 14:18:13 +03:00
|
|
|
|
|
|
|
/* bandwidth and averageRTT fields are present (baseRTT field is not) */
|
2022-04-19 15:29:17 +03:00
|
|
|
if ((autodetectReqPdu->headerLength != 0x0E) ||
|
|
|
|
(!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 8)))
|
2018-10-02 14:18:13 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
|
|
|
|
break;
|
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
case RDP_NETCHAR_RESULTS_0x08C0:
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
/* baseRTT, bandwidth, and averageRTT fields are present */
|
2022-04-19 15:29:17 +03:00
|
|
|
if ((autodetectReqPdu->headerLength != 0x12) ||
|
|
|
|
(!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 12)))
|
2018-10-02 14:18:13 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
|
|
|
|
break;
|
|
|
|
}
|
2014-10-28 18:29:40 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"received Network Characteristics Result PDU -> baseRTT=%" PRIu32
|
|
|
|
", bandwidth=%" PRIu32 ", averageRTT=%" PRIu32 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
rdp->autodetect->netCharBaseRTT, rdp->autodetect->netCharBandwidth,
|
|
|
|
rdp->autodetect->netCharAverageRTT);
|
|
|
|
IFCALLRET(rdp->autodetect->NetworkCharacteristicsResult, success, rdp->context,
|
|
|
|
autodetectReqPdu->sequenceNumber);
|
2014-10-28 18:29:40 +03:00
|
|
|
return success;
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:06:04 +03:00
|
|
|
int rdp_recv_autodetect_request_packet(rdpRdp* rdp, wStream* s)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
|
|
|
AUTODETECT_REQ_PDU autodetectReqPdu;
|
|
|
|
BOOL success = FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 6))
|
2014-01-24 07:23:47 +04:00
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, autodetectReqPdu.headerLength); /* headerLength (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, autodetectReqPdu.headerTypeId); /* headerTypeId (1 byte) */
|
2014-01-24 07:23:47 +04:00
|
|
|
Stream_Read_UINT16(s, autodetectReqPdu.sequenceNumber); /* sequenceNumber (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, autodetectReqPdu.requestType); /* requestType (2 bytes) */
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"rdp_recv_autodetect_request_packet: headerLength=%" PRIu8 ", headerTypeId=%" PRIu8
|
|
|
|
", sequenceNumber=%" PRIu16 ", requestType=%04" PRIx16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
autodetectReqPdu.headerLength, autodetectReqPdu.headerTypeId,
|
|
|
|
autodetectReqPdu.sequenceNumber, autodetectReqPdu.requestType);
|
2014-01-30 07:53:32 +04:00
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
if (!rdp->settings->NetworkAutoDetect)
|
|
|
|
{
|
2021-02-04 15:10:58 +03:00
|
|
|
WLog_WARN(AUTODETECT_TAG,
|
|
|
|
"Received a [MS-RDPBCGR] 2.2.14.1.1 RTT Measure Request (RDP_RTT_REQUEST) [%s] "
|
|
|
|
"message but support was not enabled",
|
|
|
|
autodetect_request_type_to_string(autodetectReqPdu.requestType));
|
2021-02-04 11:54:48 +03:00
|
|
|
}
|
|
|
|
|
2014-01-24 07:23:47 +04:00
|
|
|
if (autodetectReqPdu.headerTypeId != TYPE_ID_AUTODETECT_REQUEST)
|
2021-02-04 11:54:48 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(AUTODETECT_TAG,
|
|
|
|
"Received a [MS-RDPBCGR] 2.2.14.1.1 RTT Measure Request (RDP_RTT_REQUEST) [%s] "
|
|
|
|
"message with invalid headerTypeId=0x%04" PRIx16,
|
|
|
|
autodetect_request_type_to_string(autodetectReqPdu.requestType),
|
|
|
|
autodetectReqPdu.headerTypeId);
|
2014-01-24 07:23:47 +04:00
|
|
|
return -1;
|
2021-02-04 11:54:48 +03:00
|
|
|
}
|
2014-01-24 07:23:47 +04:00
|
|
|
|
|
|
|
switch (autodetectReqPdu.requestType)
|
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
case RDP_RTT_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
case RDP_RTT_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
/* RTT Measure Request (RDP_RTT_REQUEST) - MS-RDPBCGR 2.2.14.1.1 */
|
|
|
|
success = autodetect_recv_rtt_measure_request(rdp, s, &autodetectReqPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_TUNNEL:
|
|
|
|
case RDP_BW_START_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
/* Bandwidth Measure Start (RDP_BW_START) - MS-RDPBCGR 2.2.14.1.2 */
|
|
|
|
success = autodetect_recv_bandwidth_measure_start(rdp, s, &autodetectReqPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_BW_PAYLOAD_REQUEST_TYPE:
|
|
|
|
/* Bandwidth Measure Payload (RDP_BW_PAYLOAD) - MS-RDPBCGR 2.2.14.1.3 */
|
|
|
|
success = autodetect_recv_bandwidth_measure_payload(rdp, s, &autodetectReqPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME:
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_CONTINUOUS:
|
|
|
|
case RDP_BW_STOP_REQUEST_TYPE_TUNNEL:
|
|
|
|
/* Bandwidth Measure Stop (RDP_BW_STOP) - MS-RDPBCGR 2.2.14.1.4 */
|
|
|
|
success = autodetect_recv_bandwidth_measure_stop(rdp, s, &autodetectReqPdu);
|
|
|
|
break;
|
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
case RDP_NETCHAR_RESULTS_0x0840:
|
|
|
|
case RDP_NETCHAR_RESULTS_0x0880:
|
|
|
|
case RDP_NETCHAR_RESULTS_0x08C0:
|
2018-10-02 14:18:13 +03:00
|
|
|
/* Network Characteristics Result (RDP_NETCHAR_RESULT) - MS-RDPBCGR 2.2.14.1.5 */
|
|
|
|
success = autodetect_recv_netchar_result(rdp, s, &autodetectReqPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return success ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:06:04 +03:00
|
|
|
int rdp_recv_autodetect_response_packet(rdpRdp* rdp, wStream* s)
|
|
|
|
{
|
|
|
|
AUTODETECT_RSP_PDU autodetectRspPdu;
|
|
|
|
BOOL success = FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 6))
|
2014-10-28 11:06:04 +03:00
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, autodetectRspPdu.headerLength); /* headerLength (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, autodetectRspPdu.headerTypeId); /* headerTypeId (1 byte) */
|
2014-10-28 11:06:04 +03:00
|
|
|
Stream_Read_UINT16(s, autodetectRspPdu.sequenceNumber); /* sequenceNumber (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, autodetectRspPdu.responseType); /* responseType (2 bytes) */
|
2015-04-14 13:54:33 +03:00
|
|
|
WLog_VRB(AUTODETECT_TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"rdp_recv_autodetect_response_packet: headerLength=%" PRIu8 ", headerTypeId=%" PRIu8
|
|
|
|
", sequenceNumber=%" PRIu16 ", requestType=%04" PRIx16 "",
|
2018-10-02 14:18:13 +03:00
|
|
|
autodetectRspPdu.headerLength, autodetectRspPdu.headerTypeId,
|
|
|
|
autodetectRspPdu.sequenceNumber, autodetectRspPdu.responseType);
|
2014-10-28 11:06:04 +03:00
|
|
|
|
2021-02-04 11:54:48 +03:00
|
|
|
if (!rdp->settings->NetworkAutoDetect)
|
|
|
|
{
|
2021-02-04 15:10:58 +03:00
|
|
|
WLog_WARN(AUTODETECT_TAG,
|
|
|
|
"Received a [MS-RDPBCGR] 2.2.14.2.1 RTT Measure Response (RDP_RTT_RESPONSE) [%s] "
|
|
|
|
"message but support was not enabled",
|
|
|
|
autodetect_request_type_to_string(autodetectRspPdu.responseType));
|
2021-02-04 11:54:48 +03:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:06:04 +03:00
|
|
|
if (autodetectRspPdu.headerTypeId != TYPE_ID_AUTODETECT_RESPONSE)
|
2021-02-04 11:54:48 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(AUTODETECT_TAG,
|
|
|
|
"Received a [MS-RDPBCGR] 2.2.14.2.1 RTT Measure Response (RDP_RTT_RESPONSE) [%s] "
|
|
|
|
"message with invalid headerTypeId=0x%04" PRIx16,
|
|
|
|
autodetect_request_type_to_string(autodetectRspPdu.responseType),
|
|
|
|
autodetectRspPdu.headerTypeId);
|
2014-10-28 11:06:04 +03:00
|
|
|
return -1;
|
2021-02-04 11:54:48 +03:00
|
|
|
}
|
2014-10-28 11:06:04 +03:00
|
|
|
|
2014-10-28 18:29:40 +03:00
|
|
|
switch (autodetectRspPdu.responseType)
|
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
case RDP_RTT_RESPONSE_TYPE:
|
|
|
|
/* RTT Measure Response (RDP_RTT_RESPONSE) - MS-RDPBCGR 2.2.14.2.1 */
|
|
|
|
success = autodetect_recv_rtt_measure_response(rdp, s, &autodetectRspPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME:
|
|
|
|
case RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS:
|
|
|
|
/* Bandwidth Measure Results (RDP_BW_RESULTS) - MS-RDPBCGR 2.2.14.2.2 */
|
|
|
|
success = autodetect_recv_bandwidth_measure_results(rdp, s, &autodetectRspPdu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-10-28 18:29:40 +03:00
|
|
|
}
|
2014-10-28 11:06:04 +03:00
|
|
|
return success ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpAutoDetect* autodetect_new(rdpContext* context)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpAutoDetect* autoDetect = (rdpAutoDetect*)calloc(1, sizeof(rdpAutoDetect));
|
2014-02-11 07:23:59 +04:00
|
|
|
|
|
|
|
if (autoDetect)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
autoDetect->context = context;
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2014-02-11 07:23:59 +04:00
|
|
|
return autoDetect;
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
2014-02-11 07:23:59 +04:00
|
|
|
void autodetect_free(rdpAutoDetect* autoDetect)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2014-02-11 07:23:59 +04:00
|
|
|
free(autoDetect);
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
2014-10-28 18:29:40 +03:00
|
|
|
|
|
|
|
void autodetect_register_server_callbacks(rdpAutoDetect* autodetect)
|
|
|
|
{
|
2014-11-04 08:41:04 +03:00
|
|
|
autodetect->RTTMeasureRequest = autodetect_send_continuous_rtt_measure_request;
|
|
|
|
autodetect->BandwidthMeasureStart = autodetect_send_continuous_bandwidth_measure_start;
|
|
|
|
autodetect->BandwidthMeasureStop = autodetect_send_continuous_bandwidth_measure_stop;
|
2014-10-28 18:29:40 +03:00
|
|
|
autodetect->NetworkCharacteristicsResult = autodetect_send_netchar_result;
|
|
|
|
}
|