2014-01-24 07:23:47 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-10-10 12:53:15 +03:00
|
|
|
#include <winpr/assert.h>
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2022-10-10 12:53:15 +03:00
|
|
|
#include <freerdp/log.h>
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2022-10-10 12:53:15 +03:00
|
|
|
#include "rdp.h"
|
2014-01-24 07:23:47 +04:00
|
|
|
#include "multitransport.h"
|
|
|
|
|
2022-10-10 12:53:15 +03:00
|
|
|
struct rdp_multitransport
|
|
|
|
{
|
|
|
|
rdpRdp* rdp;
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
MultiTransportRequestCb MtRequest;
|
|
|
|
MultiTransportResponseCb MtResponse;
|
|
|
|
|
|
|
|
/* server-side data */
|
|
|
|
UINT32 reliableReqId;
|
|
|
|
|
|
|
|
BYTE reliableCookie[RDPUDP_COOKIE_LEN];
|
|
|
|
BYTE reliableCookieHash[RDPUDP_COOKIE_HASHLEN];
|
2022-10-10 12:53:15 +03:00
|
|
|
};
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
enum
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
RDPTUNNEL_ACTION_CREATEREQUEST = 0x00,
|
|
|
|
RDPTUNNEL_ACTION_CREATERESPONSE = 0x01,
|
|
|
|
RDPTUNNEL_ACTION_DATA = 0x02
|
|
|
|
};
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
#define TAG FREERDP_TAG("core.multitransport")
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
state_run_t multitransport_recv_request(rdpMultitransport* multi, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(multi);
|
|
|
|
rdpSettings* settings = multi->rdp->settings;
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
if (settings->ServerMode)
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
WLog_ERR(TAG, "not expecting a multi-transport request in server mode");
|
|
|
|
return STATE_RUN_FAILED;
|
2022-10-10 12:53:15 +03:00
|
|
|
}
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
UINT32 requestId;
|
|
|
|
UINT16 requestedProto;
|
|
|
|
const BYTE* cookie;
|
2014-01-24 07:23:47 +04:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
Stream_Read_UINT32(s, requestId); /* requestId (4 bytes) */
|
|
|
|
Stream_Read_UINT16(s, requestedProto); /* requestedProtocol (2 bytes) */
|
|
|
|
Stream_Seek(s, 2); /* reserved (2 bytes) */
|
|
|
|
cookie = Stream_Pointer(s);
|
|
|
|
Stream_Seek(s, RDPUDP_COOKIE_LEN); /* securityCookie (16 bytes) */
|
|
|
|
|
|
|
|
WINPR_ASSERT(multi->MtRequest);
|
|
|
|
return multi->MtRequest(multi, requestId, requestedProto, cookie);
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
static BOOL multitransport_request_send(rdpMultitransport* multi, UINT32 reqId, UINT16 reqProto,
|
|
|
|
const BYTE* cookie)
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
WINPR_ASSERT(multi);
|
|
|
|
wStream* s = rdp_message_channel_pdu_init(multi->rdp);
|
2022-10-10 12:53:15 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 24))
|
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
Stream_Write_UINT32(s, reqId); /* requestId (4 bytes) */
|
|
|
|
Stream_Write_UINT16(s, reqProto); /* requestedProtocol (2 bytes) */
|
|
|
|
Stream_Zero(s, 2); /* reserved (2 bytes) */
|
|
|
|
Stream_Write(s, cookie, RDPUDP_COOKIE_LEN); /* securityCookie (16 bytes) */
|
|
|
|
|
|
|
|
return rdp_send_message_channel_pdu(multi->rdp, s, SEC_TRANSPORT_REQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
state_run_t multitransport_server_request(rdpMultitransport* multi, UINT16 reqProto)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(multi);
|
|
|
|
|
|
|
|
/* TODO: move this static variable to the listener */
|
|
|
|
static UINT32 reqId = 0;
|
|
|
|
|
|
|
|
if (reqProto == INITIATE_REQUEST_PROTOCOL_UDPFECR)
|
|
|
|
{
|
|
|
|
multi->reliableReqId = reqId++;
|
|
|
|
winpr_RAND(multi->reliableCookie, sizeof(multi->reliableCookie));
|
|
|
|
|
|
|
|
return multitransport_request_send(multi, multi->reliableReqId, reqProto,
|
|
|
|
multi->reliableCookie)
|
|
|
|
? STATE_RUN_SUCCESS
|
|
|
|
: STATE_RUN_FAILED;
|
|
|
|
}
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
WLog_ERR(TAG, "only reliable transport is supported");
|
|
|
|
return STATE_RUN_CONTINUE;
|
2022-10-10 12:53:15 +03:00
|
|
|
}
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
BOOL multitransport_client_send_response(rdpMultitransport* multi, UINT32 reqId, HRESULT hr)
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
WINPR_ASSERT(multi);
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
wStream* s = rdp_message_channel_pdu_init(multi->rdp);
|
2022-10-10 12:53:15 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 28))
|
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
Stream_Write_UINT32(s, reqId); /* requestId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, hr); /* HResult (4 bytes) */
|
|
|
|
return rdp_send_message_channel_pdu(multi->rdp, s, SEC_TRANSPORT_RSP);
|
2022-10-10 12:53:15 +03:00
|
|
|
}
|
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
state_run_t multitransport_recv_response(rdpMultitransport* multi, wStream* s)
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
WINPR_ASSERT(multi && multi->rdp);
|
|
|
|
WINPR_ASSERT(s);
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
rdpSettings* settings = multi->rdp->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
if (!settings->ServerMode)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "client is not expecting a multi-transport resp packet");
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
}
|
2022-10-10 12:53:15 +03:00
|
|
|
|
2022-11-24 15:24:26 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
|
|
|
|
UINT32 requestId;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, requestId); /* requestId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, hr); /* hrResponse (4 bytes) */
|
|
|
|
|
|
|
|
return IFCALLRESULT(STATE_RUN_SUCCESS, multi->MtResponse, multi, requestId, hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static state_run_t multitransport_no_udp(rdpMultitransport* multi, UINT32 reqId, UINT16 reqProto,
|
|
|
|
const BYTE* cookie)
|
|
|
|
{
|
|
|
|
return multitransport_client_send_response(multi, reqId, E_ABORT) ? STATE_RUN_SUCCESS
|
|
|
|
: STATE_RUN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static state_run_t multitransport_server_handle_response(rdpMultitransport* multi, UINT32 reqId,
|
|
|
|
UINT32 hrResponse)
|
|
|
|
{
|
|
|
|
rdpRdp* rdp = multi->rdp;
|
|
|
|
|
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE))
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
|
|
|
|
return STATE_RUN_CONTINUE;
|
2022-10-10 12:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
rdpMultitransport* multitransport_new(rdpRdp* rdp, UINT16 protocol)
|
2014-01-24 07:23:47 +04:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
rdpSettings* settings = rdp->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-10-10 12:53:15 +03:00
|
|
|
rdpMultitransport* multi = calloc(1, sizeof(rdpMultitransport));
|
2022-11-24 15:24:26 +03:00
|
|
|
if (!multi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (settings->ServerMode)
|
2022-10-10 12:53:15 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
multi->MtResponse = multitransport_server_handle_response;
|
2022-10-10 12:53:15 +03:00
|
|
|
}
|
2022-11-24 15:24:26 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
multi->MtRequest = multitransport_no_udp;
|
|
|
|
}
|
|
|
|
|
|
|
|
multi->rdp = rdp;
|
2022-10-10 12:53:15 +03:00
|
|
|
return multi;
|
2014-01-24 07:23:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void multitransport_free(rdpMultitransport* multitransport)
|
|
|
|
{
|
|
|
|
free(multitransport);
|
|
|
|
}
|