Merge branch 'auto-detect' of github.com:vworkspace/FreeRDP

Conflicts:
	include/freerdp/settings.h
	libfreerdp/core/gcc.c
	libfreerdp/core/gcc.h
	libfreerdp/core/mcs.h
	libfreerdp/core/rdp.c
This commit is contained in:
Marc-André Moreau 2014-01-25 17:08:43 -05:00
commit 6bd4362e6d
13 changed files with 779 additions and 36 deletions

View File

@ -524,6 +524,7 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL;
#define FreeRDP_SupportMonitorLayoutPdu 141
#define FreeRDP_SupportGraphicsPipeline 142
#define FreeRDP_SupportDynamicTimeZone 143
#define FreeRDP_SupportHeartbeatPdu 144
#define FreeRDP_DisableEncryption 192
#define FreeRDP_EncryptionMethods 193
#define FreeRDP_ExtEncryptionMethods 194
@ -547,6 +548,7 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL;
#define FreeRDP_DesktopPosX 390
#define FreeRDP_DesktopPosY 391
#define FreeRDP_MultitransportFlags 512
#define FreeRDP_SupportMultitransport 513
#define FreeRDP_AlternateShell 640
#define FreeRDP_ShellWorkingDirectory 641
#define FreeRDP_AutoLogonEnabled 704
@ -819,7 +821,8 @@ struct rdp_settings
ALIGN64 BOOL SupportMonitorLayoutPdu; /* 141 */
ALIGN64 BOOL SupportGraphicsPipeline; /* 142 */
ALIGN64 BOOL SupportDynamicTimeZone; /* 143 */
UINT64 padding0192[192 - 143]; /* 143 */
ALIGN64 BOOL SupportHeartbeatPdu; /* 144 */
UINT64 padding0192[192 - 145]; /* 145 */
/* Client/Server Security Data */
ALIGN64 BOOL DisableEncryption; /* 192 */
@ -864,7 +867,8 @@ struct rdp_settings
/* Client Multitransport Channel Data */
ALIGN64 UINT32 MultitransportFlags; /* 512 */
UINT64 padding0576[576 - 513]; /* 513 */
ALIGN64 BOOL SupportMultitransport; /* 513 */
UINT64 padding0576[576 - 514]; /* 514 */
UINT64 padding0640[640 - 576]; /* 576 */
/*
@ -1326,7 +1330,7 @@ struct rdp_settings
/* Extensions */
ALIGN64 int num_extensions; /* */
ALIGN64 struct rdp_ext_set extensions[16]; /* */
ALIGN64 BYTE* SettingsModified; /* byte array marking fields that have been modified from their default value */
};
typedef struct rdp_settings rdpSettings;

View File

@ -83,6 +83,12 @@ set(${MODULE_PREFIX}_SRCS
connection.h
redirection.c
redirection.h
autodetect.c
autodetect.h
heartbeat.c
heartbeat.h
multitransport.c
multitransport.h
timezone.c
timezone.h
rdp.c

View File

@ -0,0 +1,283 @@
/**
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define WITH_DEBUG_AUTODETECT
#include "autodetect.h"
typedef struct
{
UINT8 headerLength;
UINT8 headerTypeId;
UINT16 sequenceNumber;
UINT16 requestType;
} AUTODETECT_REQ_PDU;
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);
if (s == NULL) return FALSE;
DEBUG_AUTODETECT("sending RTT Measure Response PDU");
Stream_Write_UINT8(s, 0x06); /* 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, 0x0000); /* responseType (1 byte) */
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
}
static BOOL autodetect_send_bandwidth_measure_results(rdpRdp* rdp, UINT16 responseType, UINT16 sequenceNumber)
{
UINT32 timeDelta;
wStream* s;
/* Compute the total time */
timeDelta = GetTickCount() - rdp->autodetect->bandwidthMeasureStartTime;
/* Send the result PDU to the server */
s = rdp_message_channel_pdu_init(rdp);
if (s == NULL) return FALSE;
DEBUG_AUTODETECT("sending Bandwidth Measure Results PDU -> timeDelta=%u, byteCount=%u", timeDelta, rdp->autodetect->bandwidthMeasureByteCount);
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, responseType); /* responseType (1 byte) */
Stream_Write_UINT32(s, timeDelta); /* timeDelta (4 bytes) */
Stream_Write_UINT32(s, rdp->autodetect->bandwidthMeasureByteCount); /* byteCount (4 bytes) */
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
}
static BOOL autodetect_send_netchar_sync(rdpRdp* rdp, UINT16 sequenceNumber)
{
wStream* s;
/* Send the response PDU to the server */
s = rdp_message_channel_pdu_init(rdp);
if (s == NULL) return FALSE;
DEBUG_AUTODETECT("sending Network Characteristics Sync PDU -> bandwidth=%u, rtt=%u", rdp->autodetect->netCharBandwidth, rdp->autodetect->netCharAverageRTT);
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, 0x0018); /* responseType (1 byte) */
Stream_Write_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
Stream_Write_UINT32(s, rdp->autodetect->netCharAverageRTT); /* rtt (4 bytes) */
return rdp_send_message_channel_pdu(rdp, s, SEC_AUTODETECT_RSP);
}
static BOOL autodetect_recv_rtt_measure_request(rdpRdp* rdp, wStream* s, AUTODETECT_REQ_PDU* autodetectReqPdu)
{
if (autodetectReqPdu->headerLength != 0x06)
return FALSE;
DEBUG_AUTODETECT("received RTT Measure Request PDU");
/* Send a response to the server */
return autodetect_send_rtt_measure_response(rdp, autodetectReqPdu->sequenceNumber);
}
static BOOL autodetect_recv_bandwidth_measure_start(rdpRdp* rdp, wStream* s, AUTODETECT_REQ_PDU* autodetectReqPdu)
{
if (autodetectReqPdu->headerLength != 0x06)
return FALSE;
DEBUG_AUTODETECT("received Bandwidth Measure Start PDU");
/* Initialize bandwidth measurement parameters */
rdp->autodetect->bandwidthMeasureStartTime = GetTickCount();
rdp->autodetect->bandwidthMeasureByteCount = 0;
return TRUE;
}
static BOOL autodetect_recv_bandwidth_measure_payload(rdpRdp* rdp, wStream* s, AUTODETECT_REQ_PDU* autodetectReqPdu)
{
UINT16 payloadLength;
if (autodetectReqPdu->headerLength != 0x08)
return FALSE;
if (Stream_GetRemainingLength(s) < 2)
return FALSE;
Stream_Read_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
DEBUG_AUTODETECT("received Bandwidth Measure Payload PDU -> payloadLength=%u", payloadLength);
/* Add the payload length to the bandwidth measurement parameters */
rdp->autodetect->bandwidthMeasureByteCount += payloadLength;
return TRUE;
}
static BOOL autodetect_recv_bandwidth_measure_stop(rdpRdp* rdp, wStream* s, AUTODETECT_REQ_PDU* autodetectReqPdu)
{
UINT16 payloadLength;
UINT16 responseType;
if (autodetectReqPdu->requestType == 0x002B)
{
if (autodetectReqPdu->headerLength != 0x08)
return FALSE;
if (Stream_GetRemainingLength(s) < 2)
return FALSE;
Stream_Read_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
}
else
{
if (autodetectReqPdu->headerLength != 0x06)
return FALSE;
payloadLength = 0;
}
DEBUG_AUTODETECT("received Bandwidth Measure Stop PDU -> payloadLength=%u", payloadLength);
/* Add the payload length to the bandwidth measurement parameters */
rdp->autodetect->bandwidthMeasureByteCount += payloadLength;
/* Send a response the server */
responseType = autodetectReqPdu->requestType == 0x002B ? 0x0003 : 0x000B;
return autodetect_send_bandwidth_measure_results(rdp, responseType, autodetectReqPdu->sequenceNumber);
}
static BOOL autodetect_recv_netchar_result(rdpRdp* rdp, wStream* s, AUTODETECT_REQ_PDU* autodetectReqPdu)
{
switch (autodetectReqPdu->requestType)
{
case 0x0840:
/* baseRTT and averageRTT fields are present (bandwidth field is not) */
if ((autodetectReqPdu->headerLength != 0x0E) || (Stream_GetRemainingLength(s) < 8))
return FALSE;
Stream_Read_UINT32(s, rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
break;
case 0x0880:
/* bandwidth and averageRTT fields are present (baseRTT field is not) */
if ((autodetectReqPdu->headerLength != 0x0E) || (Stream_GetRemainingLength(s) < 8))
return FALSE;
Stream_Read_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
break;
case 0x08C0:
/* baseRTT, bandwidth, and averageRTT fields are present */
if ((autodetectReqPdu->headerLength != 0x12) || (Stream_GetRemainingLength(s) < 12))
return FALSE;
Stream_Read_UINT32(s, rdp->autodetect->netCharBaseRTT); /* baseRTT (4 bytes) */
Stream_Read_UINT32(s, rdp->autodetect->netCharBandwidth); /* bandwidth (4 bytes) */
Stream_Read_UINT32(s, rdp->autodetect->netCharAverageRTT); /* averageRTT (4 bytes) */
break;
}
DEBUG_AUTODETECT("received Network Characteristics Result PDU -> baseRTT=%u, bandwidth=%u, averageRTT=%u", rdp->autodetect->netCharBaseRTT, rdp->autodetect->netCharBandwidth, rdp->autodetect->netCharAverageRTT);
return TRUE;
}
int rdp_recv_autodetect_packet(rdpRdp* rdp, wStream* s)
{
AUTODETECT_REQ_PDU autodetectReqPdu;
BOOL success = FALSE;
if (Stream_GetRemainingLength(s) < 6)
return -1;
Stream_Read_UINT8(s, autodetectReqPdu.headerLength); /* headerLength (1 byte) */
Stream_Read_UINT8(s, autodetectReqPdu.headerTypeId); /* headerTypeId (1 byte) */
Stream_Read_UINT16(s, autodetectReqPdu.sequenceNumber); /* sequenceNumber (2 bytes) */
Stream_Read_UINT16(s, autodetectReqPdu.requestType); /* requestType (2 bytes) */
if (autodetectReqPdu.headerTypeId != TYPE_ID_AUTODETECT_REQUEST)
return -1;
switch (autodetectReqPdu.requestType)
{
case 0x0001:
case 0x1001:
/* RTT Measure Request (RDP_RTT_REQUEST) - MS-RDPBCGR 2.2.14.1.1 */
success = autodetect_recv_rtt_measure_request(rdp, s, &autodetectReqPdu);
break;
case 0x0014:
case 0x0114:
case 0x1014:
/* Bandwidth Measure Start (RDP_BW_START) - MS-RDPBCGR 2.2.14.1.2 */
success = autodetect_recv_bandwidth_measure_start(rdp, s, &autodetectReqPdu);
break;
case 0x0002:
/* Bandwidth Measure Payload (RDP_BW_PAYLOAD) - MS-RDPBCGR 2.2.14.1.3 */
success = autodetect_recv_bandwidth_measure_payload(rdp, s, &autodetectReqPdu);
break;
case 0x002B:
case 0x0429:
case 0x0629:
/* Bandwidth Measure Stop (RDP_BW_STOP) - MS-RDPBCGR 2.2.14.1.4 */
success = autodetect_recv_bandwidth_measure_stop(rdp, s, &autodetectReqPdu);
break;
case 0x0840:
case 0x0880:
case 0x08C0:
/* Network Characteristics Result (RDP_NETCHAR_RESULT) - MS-RDPBCGR 2.2.14.1.5 */
success = autodetect_recv_netchar_result(rdp, s, &autodetectReqPdu);
break;
default:
break;
}
return success ? 0 : -1;
}
rdpAutoDetect* autodetect_new(void)
{
rdpAutoDetect* autodetect = (rdpAutoDetect*)malloc(sizeof(rdpAutoDetect));
if (autodetect)
{
memset(autodetect, 0, sizeof(rdpAutoDetect));
}
return autodetect;
}
void autodetect_free(rdpAutoDetect* autodetect)
{
free(autodetect);
}

View File

@ -0,0 +1,58 @@
/**
* 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.
*/
#ifndef __AUTODETECT_H
#define __AUTODETECT_H
typedef struct rdp_autodetect rdpAutoDetect;
#include "rdp.h"
#include <freerdp/freerdp.h>
#include <winpr/stream.h>
#include <winpr/sysinfo.h>
#define TYPE_ID_AUTODETECT_REQUEST 0x00
#define TYPE_ID_AUTODETECT_RESPONSE 0x01
struct rdp_autodetect
{
/* Bandwidth measurement */
UINT32 bandwidthMeasureStartTime;
UINT32 bandwidthMeasureByteCount;
/* Network characteristics (as reported by server) */
UINT32 netCharBandwidth;
UINT32 netCharBaseRTT;
UINT32 netCharAverageRTT;
};
int rdp_recv_autodetect_packet(rdpRdp* rdp, wStream* s);
rdpAutoDetect* autodetect_new(void);
void autodetect_free(rdpAutoDetect* autodetect);
#ifdef WITH_DEBUG_AUTODETECT
#define DEBUG_AUTODETECT(fmt, ...) DEBUG_CLASS(AUTODETECT, fmt, ## __VA_ARGS__)
#else
#define DEBUG_AUTODETECT(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
#endif
#endif /* __AUTODETECT_H */

View File

@ -405,10 +405,12 @@ void gcc_write_client_data_blocks(wStream* s, rdpSettings* settings)
if (settings->NegotiationFlags & EXTENDED_CLIENT_DATA_SUPPORTED)
{
if (!settings->SpanMonitors)
if (settings->SpanMonitors)
{
gcc_write_client_monitor_data(s, settings);
}
gcc_write_client_message_channel_data(s, settings);
gcc_write_client_multitransport_channel_data(s, settings);
}
else
{
@ -472,6 +474,22 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpSettings* settings, int length)
}
break;
case SC_MCS_MSGCHANNEL:
if (!gcc_read_server_message_channel_data(s, settings))
{
fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_server_message_channel_data failed\n");
return FALSE;
}
break;
case SC_MULTITRANSPORT:
if (!gcc_read_server_multitransport_channel_data(s, settings))
{
fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_server_multitransport_channel_data failed\n");
return FALSE;
}
break;
default:
fprintf(stderr, "gcc_read_server_data_blocks: ignoring type=%hu\n", type);
break;
@ -803,6 +821,9 @@ void gcc_write_client_core_data(wStream* s, rdpSettings* settings)
if (settings->NetworkAutoDetect)
earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT;
if (settings->SupportHeartbeatPdu)
earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_HEARTBEAT_PDU;
if (settings->SupportGraphicsPipeline)
earlyCapabilityFlags |= RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL;
@ -977,24 +998,6 @@ BOOL gcc_read_server_security_data(wStream* s, rdpSettings* settings)
return TRUE;
}
void gcc_write_server_message_channel_data(wStream* s, rdpSettings* settings)
{
UINT16 mcsChannelId = 0;
gcc_write_user_data_header(s, SC_MCS_MSGCHANNEL, 6);
Stream_Write_UINT16(s, mcsChannelId); /* mcsChannelId (2 bytes) */
}
void gcc_write_server_multitransport_channel_data(wStream* s, rdpSettings* settings)
{
UINT32 flags = 0;
gcc_write_user_data_header(s, SC_MULTITRANSPORT, 8);
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
}
static const BYTE initial_signature[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@ -1449,6 +1452,13 @@ void gcc_write_client_monitor_extended_data(wStream* s, rdpSettings* settings)
}
/**
* Read a client message channel data block (TS_UD_CS_MCS_MSGCHANNEL).\n
* @msdn{jj217627}
* @param s stream
* @param settings rdp settings
*/
BOOL gcc_read_client_message_channel_data(wStream* s, rdpSettings* settings, UINT16 blockLength)
{
UINT32 flags;
@ -1461,11 +1471,58 @@ BOOL gcc_read_client_message_channel_data(wStream* s, rdpSettings* settings, UIN
return TRUE;
}
/**
* Write a client message channel data block (TS_UD_CS_MCS_MSGCHANNEL).\n
* @msdn{jj217627}
* @param s stream
* @param settings rdp settings
*/
void gcc_write_client_message_channel_data(wStream* s, rdpSettings* settings)
{
if (settings->NetworkAutoDetect ||
settings->SupportHeartbeatPdu ||
settings->SupportMultitransport)
{
gcc_write_user_data_header(s, CS_MCS_MSGCHANNEL, 8);
Stream_Write_UINT32(s, 0); /* flags */
}
}
BOOL gcc_read_server_message_channel_data(wStream* s, rdpSettings* settings)
{
freerdp* instance;
UINT16 MCSChannelId;
if (Stream_GetRemainingLength(s) < 2)
return FALSE;
Stream_Read_UINT16(s, MCSChannelId); /* MCSChannelId */
/* Save the MCS message channel id */
instance = (freerdp*) settings->instance;
instance->context->rdp->mcs->message_channel_id = MCSChannelId;
return TRUE;
}
void gcc_write_server_message_channel_data(wStream* s, rdpSettings* settings)
{
UINT16 mcsChannelId = 0;
gcc_write_user_data_header(s, SC_MCS_MSGCHANNEL, 6);
Stream_Write_UINT16(s, mcsChannelId); /* mcsChannelId (2 bytes) */
}
/**
* Read a client multitransport channel data block (TS_UD_CS_MULTITRANSPORT).\n
* @msdn{jj217498}
* @param s stream
* @param settings rdp settings
*/
BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpSettings* settings, UINT16 blockLength)
{
UINT32 flags;
@ -1478,7 +1535,40 @@ BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpSettings* settin
return TRUE;
}
/**
* Write a client multitransport channel data block (TS_UD_CS_MULTITRANSPORT).\n
* @msdn{jj217498}
* @param s stream
* @param settings rdp settings
*/
void gcc_write_client_multitransport_channel_data(wStream* s, rdpSettings* settings)
{
if (settings->MultitransportFlags != 0)
{
gcc_write_user_data_header(s, CS_MULTITRANSPORT, 8);
Stream_Write_UINT32(s, settings->MultitransportFlags); /* flags */
}
}
BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpSettings* settings)
{
UINT32 flags;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
Stream_Read_UINT32(s, flags); /* flags */
return TRUE;
}
void gcc_write_server_multitransport_channel_data(wStream* s, rdpSettings* settings)
{
UINT32 flags = 0;
gcc_write_user_data_header(s, SC_MULTITRANSPORT, 8);
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
}

View File

@ -59,9 +59,11 @@ BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpSettings* settings, UI
void gcc_write_client_monitor_extended_data(wStream* s, rdpSettings* settings);
BOOL gcc_read_client_message_channel_data(wStream* s, rdpSettings* settings, UINT16 blockLength);
void gcc_write_client_message_channel_data(wStream* s, rdpSettings* settings);
BOOL gcc_read_server_message_channel_data(wStream* s, rdpSettings* settings);
void gcc_write_server_message_channel_data(wStream* s, rdpSettings* settings);
BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpSettings* settings, UINT16 blockLength);
void gcc_write_client_multitransport_channel_data(wStream* s, rdpSettings* settings);
BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpSettings* settings);
void gcc_write_server_multitransport_channel_data(wStream* s, rdpSettings* settings);
#endif /* FREERDP_CORE_GCC_H */

View File

@ -0,0 +1,62 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Heartbeat 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define WITH_DEBUG_HEARTBEAT
#include "heartbeat.h"
int rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s)
{
BYTE reserved;
BYTE period;
BYTE count1;
BYTE count2;
if (Stream_GetRemainingLength(s) < 4)
return -1;
Stream_Read_UINT8(s, reserved); /* reserved (1 byte) */
Stream_Read_UINT8(s, period); /* period (1 byte) */
Stream_Read_UINT8(s, count1); /* count1 (1 byte) */
Stream_Read_UINT8(s, count2); /* count2 (1 byte) */
DEBUG_HEARTBEAT("received Heartbeat PDU -> period=%u, count1=%u, count2=%u", period, count1, count2);
return 0;
}
rdpHeartbeat* heartbeat_new(void)
{
rdpHeartbeat* heartbeat = (rdpHeartbeat*)malloc(sizeof(rdpHeartbeat));
if (heartbeat)
{
ZeroMemory(heartbeat, sizeof(rdpHeartbeat));
}
return heartbeat;
}
void heartbeat_free(rdpHeartbeat* heartbeat)
{
free(heartbeat);
}

View File

@ -0,0 +1,47 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Heartbeat 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.
*/
#ifndef __HEARTBEAT_H
#define __HEARTBEAT_H
typedef struct rdp_heartbeat rdpHeartbeat;
#include "rdp.h"
#include <freerdp/freerdp.h>
#include <winpr/stream.h>
struct rdp_heartbeat
{
UINT32 placeholder;
};
int rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s);
rdpHeartbeat* heartbeat_new(void);
void heartbeat_free(rdpHeartbeat* heartbeat);
#ifdef WITH_DEBUG_HEARTBEAT
#define DEBUG_HEARTBEAT(fmt, ...) DEBUG_CLASS(HEARTBEAT, fmt, ## __VA_ARGS__)
#else
#define DEBUG_HEARTBEAT(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
#endif
#endif /* __HEARTBEAT_H */

View File

@ -125,8 +125,11 @@ typedef struct
struct rdp_mcs
{
UINT16 user_id;
rdpTransport* transport;
UINT16 user_id;
UINT16 message_channel_id;
DomainParameters domainParameters;
DomainParameters targetParameters;
DomainParameters minimumParameters;
@ -134,6 +137,7 @@ struct rdp_mcs
BOOL user_channel_joined;
BOOL global_channel_joined;
BOOL message_channel_joined;
};
#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8

View File

@ -0,0 +1,58 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* MULTITRANSPORT 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "multitransport.h"
int rdp_recv_multitransport_packet(rdpRdp* rdp, wStream* s)
{
UINT32 requestId;
UINT16 requestedProtocol;
UINT16 reserved;
BYTE securityCookie[16];
if (Stream_GetRemainingLength(s) < 24)
return -1;
Stream_Read_UINT32(s, requestId); /* requestId (4 bytes) */
Stream_Read_UINT16(s, requestedProtocol); /* requestedProtocol (2 bytes) */
Stream_Read_UINT16(s, reserved); /* reserved (2 bytes) */
Stream_Read(s, securityCookie, 16); /* securityCookie (16 bytes) */
return 0;
}
rdpMultitransport* multitransport_new(void)
{
rdpMultitransport* multitransport = (rdpMultitransport*)malloc(sizeof(rdpMultitransport));
if (multitransport)
{
memset(multitransport, 0, sizeof(rdpMultitransport));
}
return multitransport;
}
void multitransport_free(rdpMultitransport* multitransport)
{
free(multitransport);
}

View File

@ -0,0 +1,41 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Multitransport 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.
*/
#ifndef __MULTITRANSPORT_H
#define __MULTITRANSPORT_H
typedef struct rdp_multitransport rdpMultitransport;
#include "rdp.h"
#include <freerdp/freerdp.h>
#include <winpr/stream.h>
struct rdp_multitransport
{
UINT32 placeholder;
};
int rdp_recv_multitransport_packet(rdpRdp* rdp, wStream* s);
rdpMultitransport* multitransport_new(void);
void multitransport_free(rdpMultitransport* multitransport);
#endif /* __MULTITRANSPORT_H */

View File

@ -248,6 +248,15 @@ BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo)
return TRUE;
}
wStream* rdp_message_channel_pdu_init(rdpRdp* rdp)
{
wStream* s;
s = transport_send_stream_init(rdp->transport, 2048);
Stream_Seek(s, RDP_PACKET_HEADER_MAX_LENGTH);
rdp_security_stream_init(rdp, s);
return s;
}
/**
* Read an RDP packet header.\n
* @param rdp rdp module
@ -365,13 +374,12 @@ void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId)
Stream_Write_UINT16_BE(s, length); /* userData (OCTET_STRING) */
}
static UINT32 rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length)
static UINT32 rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 sec_flags)
{
BYTE* data;
UINT32 sec_flags;
UINT32 pad = 0;
sec_flags = rdp->sec_flags;
sec_flags |= rdp->sec_flags;
if (sec_flags != 0)
{
@ -468,7 +476,7 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id)
Stream_Seek(s, sec_bytes);
Stream_SetPosition(s, secm);
length += rdp_security_stream_out(rdp, s, length);
length += rdp_security_stream_out(rdp, s, length, 0);
Stream_SetPosition(s, length);
Stream_SealLength(s);
@ -497,7 +505,7 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
rdp_write_share_control_header(s, length - sec_bytes, type, channel_id);
Stream_SetPosition(s, sec_hold);
length += rdp_security_stream_out(rdp, s, length);
length += rdp_security_stream_out(rdp, s, length, 0);
Stream_SetPosition(s, length);
Stream_SealLength(s);
@ -527,7 +535,34 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
rdp_write_share_data_header(s, length - sec_bytes, type, rdp->settings->ShareId);
Stream_SetPosition(s, sec_hold);
length += rdp_security_stream_out(rdp, s, length);
length += rdp_security_stream_out(rdp, s, length, 0);
Stream_SetPosition(s, length);
Stream_SealLength(s);
if (transport_write(rdp->transport, s) < 0)
return FALSE;
return TRUE;
}
BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags)
{
UINT16 length;
UINT32 sec_bytes;
int sec_hold;
length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
rdp_write_header(rdp, s, length, rdp->mcs->message_channel_id);
sec_bytes = rdp_get_sec_bytes(rdp);
sec_hold = Stream_GetPosition(s);
Stream_Seek(s, sec_bytes);
Stream_SetPosition(s, sec_hold);
length += rdp_security_stream_out(rdp, s, length, sec_flags);
Stream_SetPosition(s, length);
Stream_SealLength(s);
@ -714,7 +749,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
#ifdef WITH_DEBUG_RDP
printf("recv %s Data PDU (0x%02X), length: %d\n",
type < ARRAYSIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
type < ARRAYSIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
#endif
switch (type)
@ -799,6 +834,34 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
return 0;
}
int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 securityFlags;
if (!rdp_read_security_header(s, &securityFlags))
return -1;
if (securityFlags & SEC_AUTODETECT_REQ)
{
/* Server Auto-Detect Request PDU */
return rdp_recv_autodetect_packet(rdp, s);
}
if (securityFlags & SEC_HEARTBEAT)
{
/* Heartbeat PDU */
return rdp_recv_heartbeat_packet(rdp, s);
}
if (securityFlags & SEC_TRANSPORT_REQ)
{
/* Initiate Multitransport Request PDU */
return rdp_recv_multitransport_packet(rdp, s);
}
return -1;
}
int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 type;
@ -947,12 +1010,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
}
}
if (channelId != MCS_GLOBAL_CHANNEL_ID)
{
if (!freerdp_channel_process(rdp->instance, s, channelId))
return -1;
}
else
if (channelId == MCS_GLOBAL_CHANNEL_ID)
{
while (Stream_GetRemainingLength(s) > 3)
{
@ -992,6 +1050,15 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
Stream_SetPosition(s, nextPosition);
}
}
else if (channelId == rdp->mcs->message_channel_id)
{
return rdp_recv_message_channel_pdu(rdp, s);
}
else
{
if (!freerdp_channel_process(rdp->instance, s, channelId))
return -1;
}
return 0;
}
@ -1147,6 +1214,9 @@ rdpRdp* rdp_new(rdpContext* context)
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
rdp->redirection = redirection_new();
rdp->autodetect = autodetect_new();
rdp->heartbeat = heartbeat_new();
rdp->multitransport = multitransport_new();
rdp->mppc_dec = mppc_dec_new();
rdp->mppc_enc = mppc_enc_new(PROTO_RDP_50);
}
@ -1219,6 +1289,9 @@ void rdp_free(rdpRdp* rdp)
nego_free(rdp->nego);
mcs_free(rdp->mcs);
redirection_free(rdp->redirection);
autodetect_free(rdp->autodetect);
heartbeat_free(rdp->heartbeat);
multitransport_free(rdp->multitransport);
mppc_dec_free(rdp->mppc_dec);
mppc_enc_free(rdp->mppc_enc);
free(rdp);

View File

@ -34,6 +34,9 @@
#include "license.h"
#include "errinfo.h"
#include "extension.h"
#include "autodetect.h"
#include "heartbeat.h"
#include "multitransport.h"
#include "security.h"
#include "transport.h"
#include "connection.h"
@ -51,6 +54,8 @@
/* Security Header Flags */
#define SEC_EXCHANGE_PKT 0x0001
#define SEC_TRANSPORT_REQ 0x0002
#define SEC_TRANSPORT_RSP 0x0004
#define SEC_ENCRYPT 0x0008
#define SEC_RESET_SEQNO 0x0010
#define SEC_IGNORE_SEQNO 0x0020
@ -60,6 +65,9 @@
#define SEC_LICENSE_ENCRYPT_SC 0x0200
#define SEC_REDIRECTION_PKT 0x0400
#define SEC_SECURE_CHECKSUM 0x0800
#define SEC_AUTODETECT_REQ 0x1000
#define SEC_AUTODETECT_RSP 0x2000
#define SEC_HEARTBEAT 0x4000
#define SEC_FLAGSHI_VALID 0x8000
#define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
@ -131,6 +139,9 @@ struct rdp_rdp
rdpSettings* settings;
rdpTransport* transport;
rdpExtension* extension;
rdpAutoDetect* autodetect;
rdpHeartbeat* heartbeat;
rdpMultitransport* multitransport;
struct rdp_mppc_dec* mppc_dec;
struct rdp_mppc_enc* mppc_enc;
struct crypto_rc4_struct* rc4_decrypt_key;
@ -191,6 +202,10 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id);
int rdp_send_channel_data(rdpRdp* rdp, int channel_id, BYTE* data, int size);
wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags);
int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s);
int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s);
void rdp_set_blocking_mode(rdpRdp* rdp, BOOL blocking);