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>
|
|
|
|
|
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"
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
/**
|
|
|
|
* [MS-RPCH]: Remote Procedure Call over HTTP Protocol Specification:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/cc243950/
|
|
|
|
*/
|
|
|
|
|
2012-04-22 00:18:07 +04:00
|
|
|
/**
|
|
|
|
* Connection Establishment\n
|
|
|
|
*
|
|
|
|
* Client Outbound Proxy Inbound Proxy Server\n
|
|
|
|
* | | | |\n
|
|
|
|
* |-----------------IN Channel Request--------------->| |\n
|
|
|
|
* |---OUT Channel Request-->| |<-Legacy Server Response-|\n
|
|
|
|
* | |<--------------Legacy Server Response--------------|\n
|
|
|
|
* | | | |\n
|
|
|
|
* |---------CONN_A1-------->| | |\n
|
|
|
|
* |----------------------CONN_B1--------------------->| |\n
|
|
|
|
* | |----------------------CONN_A2--------------------->|\n
|
|
|
|
* | | | |\n
|
|
|
|
* |<--OUT Channel Response--| |---------CONN_B2-------->|\n
|
|
|
|
* |<--------CONN_A3---------| | |\n
|
|
|
|
* | |<---------------------CONN_C1----------------------|\n
|
|
|
|
* | | |<--------CONN_B3---------|\n
|
|
|
|
* |<--------CONN_C2---------| | |\n
|
|
|
|
* | | | |\n
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rts_connect(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2012-11-29 06:25:01 +04:00
|
|
|
RPC_PDU* pdu;
|
2012-11-16 22:31:16 +04:00
|
|
|
rpcconn_rts_hdr_t* rts;
|
2012-04-22 00:18:07 +04:00
|
|
|
HttpResponse* http_response;
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
/**
|
|
|
|
* Connection Opening
|
|
|
|
*
|
|
|
|
* When opening a virtual connection to the server, an implementation of this protocol MUST perform
|
|
|
|
* the following sequence of steps:
|
|
|
|
*
|
|
|
|
* 1. Send an IN channel request as specified in section 2.1.2.1.1, containing the connection timeout,
|
|
|
|
* ResourceType UUID, and Session UUID values, if any, supplied by the higher-layer protocol or application.
|
|
|
|
*
|
|
|
|
* 2. Send an OUT channel request as specified in section 2.1.2.1.2.
|
|
|
|
*
|
|
|
|
* 3. Send a CONN/A1 RTS PDU as specified in section 2.2.4.2
|
|
|
|
*
|
|
|
|
* 4. Send a CONN/B1 RTS PDU as specified in section 2.2.4.5
|
|
|
|
*
|
|
|
|
* 5. Wait for the connection establishment protocol sequence as specified in 3.2.1.5.3.1 to complete
|
|
|
|
*
|
|
|
|
* An implementation MAY execute steps 1 and 2 in parallel. An implementation SHOULD execute steps
|
|
|
|
* 3 and 4 in parallel. An implementation MUST execute step 3 after completion of step 1 and execute
|
|
|
|
* step 4 after completion of step 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_INITIAL;
|
|
|
|
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_INITIAL");
|
|
|
|
|
2012-11-29 10:33:19 +04:00
|
|
|
rpc->client->SynchronousSend = TRUE;
|
|
|
|
rpc->client->SynchronousReceive = TRUE;
|
|
|
|
|
2012-04-24 00:33:18 +04:00
|
|
|
if (!rpc_ntlm_http_out_connect(rpc))
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rpc_out_connect_http error!\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
if (rts_send_CONN_A1_pdu(rpc) != 0)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rpc_send_CONN_A1_pdu error!\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-04-24 00:33:18 +04:00
|
|
|
if (!rpc_ntlm_http_in_connect(rpc))
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rpc_in_connect_http error!\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
if (rts_send_CONN_B1_pdu(rpc) != 0)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rpc_send_CONN_B1_pdu error!\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT;
|
|
|
|
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive OUT Channel Response
|
|
|
|
*
|
|
|
|
* A client implementation MUST NOT accept the OUT channel HTTP response in any state other than
|
|
|
|
* Out Channel Wait. If received in any other state, this HTTP response is a protocol error. Therefore,
|
|
|
|
* the client MUST consider the virtual connection opening a failure and indicate this to higher layers
|
|
|
|
* in an implementation-specific way. The Microsoft Windows® implementation returns
|
|
|
|
* RPC_S_PROTOCOL_ERROR, as specified in [MS-ERREF], to higher-layer protocols.
|
|
|
|
*
|
|
|
|
* If this HTTP response is received in Out Channel Wait state, the client MUST process the fields of
|
|
|
|
* this response as defined in this section.
|
|
|
|
*
|
|
|
|
* First, the client MUST determine whether the response indicates a success or a failure. If the status
|
|
|
|
* code is set to 200, the client MUST interpret this as a success, and it MUST do the following:
|
|
|
|
*
|
|
|
|
* 1. Ignore the values of all other header fields.
|
|
|
|
*
|
|
|
|
* 2. Transition to Wait_A3W state.
|
|
|
|
*
|
|
|
|
* 3. Wait for network events.
|
|
|
|
*
|
|
|
|
* 4. Skip the rest of the processing in this section.
|
|
|
|
*
|
|
|
|
* If the status code is not set to 200, the client MUST interpret this as a failure and follow the same
|
|
|
|
* processing rules as specified in section 3.2.2.5.6.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-15 19:00:07 +04:00
|
|
|
http_response = http_response_recv(rpc->TlsOut);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
if (http_response->StatusCode != 200)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rts_connect error! Status Code: %d\n", http_response->StatusCode);
|
2012-04-22 00:18:07 +04:00
|
|
|
http_response_print(http_response);
|
2012-11-15 19:00:07 +04:00
|
|
|
http_response_free(http_response);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-12-13 07:34:41 +04:00
|
|
|
//http_response_print(http_response);
|
2012-04-22 00:18:07 +04:00
|
|
|
http_response_free(http_response);
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_WAIT_A3W;
|
|
|
|
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_WAIT_A3W");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive CONN_A3 RTS PDU
|
|
|
|
*
|
|
|
|
* A client implementation MUST NOT accept the CONN/A3 RTS PDU in any state other than
|
|
|
|
* Wait_A3W. If received in any other state, this PDU is a protocol error and the client
|
|
|
|
* MUST consider the virtual connection opening a failure and indicate this to higher
|
|
|
|
* layers in an implementation-specific way.
|
|
|
|
*
|
|
|
|
* Set the ConnectionTimeout in the Ping Originator of the Client's IN Channel to the
|
|
|
|
* ConnectionTimeout in the CONN/A3 PDU.
|
|
|
|
*
|
|
|
|
* If this RTS PDU is received in Wait_A3W state, the client MUST transition the state
|
|
|
|
* machine to Wait_C2 state and wait for network events.
|
|
|
|
*
|
|
|
|
*/
|
2012-11-16 22:31:16 +04:00
|
|
|
|
2012-12-12 02:24:52 +04:00
|
|
|
rpc_client_start(rpc);
|
|
|
|
|
2012-11-29 07:03:18 +04:00
|
|
|
pdu = rpc_recv_dequeue_pdu(rpc);
|
2012-11-16 02:58:40 +04:00
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
if (!pdu)
|
2012-11-16 02:58:40 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
|
2012-11-16 22:31:16 +04:00
|
|
|
|
|
|
|
if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_A3_SIGNATURE, rts))
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Unexpected RTS PDU: Expected CONN/A3\n");
|
2012-11-16 22:31:16 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
rts_recv_CONN_A3_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
|
2012-11-16 22:31:16 +04:00
|
|
|
|
2012-12-12 09:49:15 +04:00
|
|
|
rpc_client_receive_pool_return(rpc, pdu);
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_WAIT_C2;
|
|
|
|
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_WAIT_C2");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive CONN_C2 RTS PDU
|
|
|
|
*
|
|
|
|
* A client implementation MUST NOT accept the CONN/C2 RTS PDU in any state other than Wait_C2.
|
|
|
|
* If received in any other state, this PDU is a protocol error and the client MUST consider the virtual
|
|
|
|
* connection opening a failure and indicate this to higher layers in an implementation-specific way.
|
|
|
|
*
|
|
|
|
* If this RTS PDU is received in Wait_C2 state, the client implementation MUST do the following:
|
|
|
|
*
|
|
|
|
* 1. Transition the state machine to opened state.
|
|
|
|
*
|
|
|
|
* 2. Set the connection time-out protocol variable to the value of the ConnectionTimeout field from
|
|
|
|
* the CONN/C2 RTS PDU.
|
|
|
|
*
|
|
|
|
* 3. Set the PeerReceiveWindow value in the SendingChannel of the Client IN Channel to the
|
|
|
|
* ReceiveWindowSize value in the CONN/C2 PDU.
|
|
|
|
*
|
|
|
|
* 4. Indicate to higher-layer protocols that the virtual connection opening is a success.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-29 07:03:18 +04:00
|
|
|
pdu = rpc_recv_dequeue_pdu(rpc);
|
2012-11-16 02:58:40 +04:00
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
if (!pdu)
|
2012-11-16 02:58:40 +04:00
|
|
|
return FALSE;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
|
2012-11-16 22:31:16 +04:00
|
|
|
|
|
|
|
if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_C2_SIGNATURE, rts))
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Unexpected RTS PDU: Expected CONN/C2\n");
|
2012-11-16 22:31:16 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
rts_recv_CONN_C2_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
|
2012-11-16 22:31:16 +04:00
|
|
|
|
2012-12-12 09:49:15 +04:00
|
|
|
rpc_client_receive_pool_return(rpc, pdu);
|
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OPENED;
|
|
|
|
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_OPENED");
|
|
|
|
|
2012-12-12 02:24:52 +04:00
|
|
|
rpc->client->SynchronousSend = TRUE;
|
|
|
|
rpc->client->SynchronousReceive = TRUE;
|
2012-11-29 10:33:19 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-04-21 01:00:00 +04:00
|
|
|
#ifdef WITH_DEBUG_RTS
|
|
|
|
|
|
|
|
static const char* const RTS_CMD_STRINGS[] =
|
|
|
|
{
|
|
|
|
"ReceiveWindowSize",
|
|
|
|
"FlowControlAck",
|
|
|
|
"ConnectionTimeout",
|
|
|
|
"Cookie",
|
|
|
|
"ChannelLifetime",
|
|
|
|
"ClientKeepalive",
|
|
|
|
"Version",
|
|
|
|
"Empty",
|
|
|
|
"Padding",
|
|
|
|
"NegativeANCE",
|
|
|
|
"ANCE",
|
|
|
|
"ClientAddress",
|
|
|
|
"AssociationGroupId",
|
|
|
|
"Destination",
|
|
|
|
"PingTrafficSentNotify"
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-16 02:58:40 +04:00
|
|
|
void rts_pdu_header_init(rpcconn_rts_hdr_t* header)
|
2012-11-01 05:23:08 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-11-17 03:30:53 +04:00
|
|
|
int rts_receive_window_size_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length, 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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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) */
|
2012-04-21 01:00:00 +04:00
|
|
|
|
2012-11-16 20:25:10 +04:00
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 16;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4;
|
2012-04-19 22:09:27 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
int rts_padding_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-19 23:43:20 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ConformanceCount;
|
2012-04-19 23:43:20 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
int rts_client_address_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
2012-04-19 23:43:20 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 AddressType;
|
2012-04-19 23:43:20 +04:00
|
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 4 + 16 + 12;
|
2012-04-19 23:43:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
2012-11-16 20:25:10 +04:00
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
return 16;
|
2012-04-21 01:00:00 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 03:20:14 +04:00
|
|
|
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) */
|
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
|
|
|
}
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
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
|
|
|
{
|
|
|
|
RAND_pseudo_bytes(cookie, 16);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
DEBUG_RPC("Sending CONN_A1 RTS PDU");
|
|
|
|
|
2012-10-29 23:02:35 +04:00
|
|
|
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->Cookie));
|
|
|
|
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie));
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
VirtualConnectionCookie = (BYTE*) &(rpc->VirtualConnection->Cookie);
|
|
|
|
OUTChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie);
|
2012-04-22 00:18:07 +04:00
|
|
|
ReceiveWindowSize = rpc->VirtualConnection->DefaultOutChannel->ReceiveWindow;
|
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
|
|
|
|
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
|
|
|
rts_version_command_write(&buffer[20]); /* Version (8 bytes) */
|
|
|
|
rts_cookie_command_write(&buffer[28], VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
|
|
|
rts_cookie_command_write(&buffer[48], OUTChannelCookie); /* OUTChannelCookie (20 bytes) */
|
|
|
|
rts_receive_window_size_command_write(&buffer[68], ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
rpc_out_write(rpc, buffer, header.frag_length);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
return 0;
|
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);
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
DEBUG_RTS("ConnectionTimeout: %d", ConnectionTimeout);
|
2012-11-17 03:30:53 +04:00
|
|
|
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = ConnectionTimeout;
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CONN/B Sequence */
|
|
|
|
|
|
|
|
int rts_send_CONN_B1_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
DEBUG_RPC("Sending CONN_B1 RTS PDU");
|
|
|
|
|
2012-10-29 23:02:35 +04:00
|
|
|
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->DefaultInChannelCookie));
|
|
|
|
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->AssociationGroupId));
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
VirtualConnectionCookie = (BYTE*) &(rpc->VirtualConnection->Cookie);
|
|
|
|
INChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultInChannelCookie);
|
|
|
|
AssociationGroupId = (BYTE*) &(rpc->VirtualConnection->AssociationGroupId);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
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) */
|
|
|
|
rts_cookie_command_write(&buffer[28], VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
|
|
|
rts_cookie_command_write(&buffer[48], INChannelCookie); /* INChannelCookie (20 bytes) */
|
2012-11-17 03:30:53 +04: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) */
|
2012-11-16 01:52:49 +04:00
|
|
|
rts_association_group_id_command_write(&buffer[84], AssociationGroupId); /* AssociationGroupId (20 bytes) */
|
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
|
|
|
|
|
|
|
rpc_in_write(rpc, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
|
|
|
|
free(buffer);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
return 0;
|
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;
|
|
|
|
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;
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
DEBUG_RTS("ConnectionTimeout: %d", ConnectionTimeout);
|
|
|
|
DEBUG_RTS("ReceiveWindowSize: %d", ReceiveWindowSize);
|
2012-11-17 03:30:53 +04:00
|
|
|
|
|
|
|
/* TODO: verify if this is the correct protocol variable */
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = ConnectionTimeout;
|
|
|
|
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->PeerReceiveWindow = ReceiveWindowSize;
|
|
|
|
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->State = CLIENT_IN_CHANNEL_STATE_OPENED;
|
|
|
|
rpc->VirtualConnection->DefaultOutChannel->State = CLIENT_OUT_CHANNEL_STATE_OPENED;
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Out-of-Sequence PDUs */
|
|
|
|
|
|
|
|
int rts_send_keep_alive_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
DEBUG_RPC("Sending Keep-Alive RTS PDU");
|
|
|
|
|
2012-11-16 01:25:22 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
|
|
|
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
2012-11-16 20:25:10 +04:00
|
|
|
rts_client_keepalive_command_write(&buffer[20], rpc->CurrentKeepAliveInterval); /* ClientKeepAlive (8 bytes) */
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
rpc_in_write(rpc, buffer, length);
|
2012-11-16 01:25:22 +04:00
|
|
|
free(buffer);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
return length;
|
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
|
|
|
{
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
DEBUG_RPC("Sending FlowControlAck RTS PDU");
|
|
|
|
|
2012-04-22 05:43:30 +04:00
|
|
|
BytesReceived = rpc->VirtualConnection->DefaultOutChannel->BytesReceived;
|
2012-11-17 06:17:04 +04:00
|
|
|
AvailableWindow = rpc->VirtualConnection->DefaultOutChannel->AvailableWindowAdvertised;
|
2012-10-09 11:01:37 +04:00
|
|
|
ChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-17 06:17:04 +04:00
|
|
|
rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow =
|
|
|
|
rpc->VirtualConnection->DefaultOutChannel->AvailableWindowAdvertised;
|
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
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) */
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
/* FlowControlAck Command (28 bytes) */
|
|
|
|
rts_flow_control_ack_command_write(&buffer[28], BytesReceived, AvailableWindow, ChannelCookie);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
rpc_in_write(rpc, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
return 0;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-28 03:34:00 +04:00
|
|
|
int rts_recv_flow_control_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
|
|
|
{
|
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,
|
|
|
|
&BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4;
|
|
|
|
|
2013-01-09 21:05:34 +04:00
|
|
|
#if 0
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "BytesReceived: %d AvailableWindow: %d\n",
|
2012-12-13 20:01:13 +04:00
|
|
|
BytesReceived, AvailableWindow);
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie));
|
2013-01-09 21:05:34 +04:00
|
|
|
#endif
|
2012-12-13 20:01:13 +04:00
|
|
|
|
|
|
|
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow =
|
|
|
|
AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived);
|
|
|
|
|
2012-11-28 03:34:00 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
&BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4;
|
|
|
|
|
2013-01-09 21:05:34 +04:00
|
|
|
#if 0
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Destination: %d BytesReceived: %d AvailableWindow: %d\n",
|
2012-11-17 06:56:53 +04:00
|
|
|
Destination, BytesReceived, AvailableWindow);
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie));
|
2013-01-09 21:05:34 +04:00
|
|
|
#endif
|
2012-11-17 06:56:53 +04:00
|
|
|
|
2012-11-27 13:05:41 +04:00
|
|
|
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow =
|
|
|
|
AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived);
|
|
|
|
|
2012-11-17 06:56:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-17 00:51:12 +04:00
|
|
|
int rts_send_ping_pdu(rdpRpc* rpc)
|
2012-04-22 00:18:07 +04:00
|
|
|
{
|
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-11-01 05:23:08 +04:00
|
|
|
|
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;
|
2012-04-22 00:18:07 +04:00
|
|
|
|
|
|
|
DEBUG_RPC("Sending Ping RTS PDU");
|
|
|
|
|
2012-11-16 01:52:49 +04:00
|
|
|
buffer = (BYTE*) malloc(header.frag_length);
|
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-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
length = header.frag_length;
|
2012-11-16 01:52:49 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
rpc_in_write(rpc, buffer, length);
|
2012-11-16 01:52:49 +04:00
|
|
|
free(buffer);
|
2012-04-22 00:18:07 +04:00
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
return length;
|
2012-04-22 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2012-11-16 22:31:16 +04:00
|
|
|
int rts_command_length(rdpRpc* rpc, UINT32 CommandType, BYTE* buffer, UINT32 length)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
CommandLength = rts_padding_command_read(rpc, buffer, length);
|
|
|
|
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 */
|
|
|
|
CommandLength = rts_client_address_command_read(rpc, buffer, length);
|
|
|
|
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:
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Error: Unknown RTS Command Type: 0x%x\n", CommandType);
|
2012-11-16 22:31:16 +04:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CommandLength;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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;
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
rts = (rpcconn_rts_hdr_t*) buffer;
|
2012-11-17 06:17:04 +04:00
|
|
|
|
|
|
|
rts_extract_pdu_signature(rpc, &signature, rts);
|
2012-11-17 06:56:53 +04:00
|
|
|
SignatureId = rts_identify_pdu_signature(rpc, &signature, NULL);
|
|
|
|
|
|
|
|
if (SignatureId == RTS_PDU_FLOW_CONTROL_ACK)
|
|
|
|
{
|
2012-11-29 06:25:01 +04:00
|
|
|
return rts_recv_flow_control_ack_pdu(rpc, buffer, length);
|
2012-11-17 06:56:53 +04:00
|
|
|
}
|
|
|
|
else if (SignatureId == RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION)
|
|
|
|
{
|
2012-11-29 06:25:01 +04:00
|
|
|
return rts_recv_flow_control_ack_with_destination_pdu(rpc, buffer, length);
|
2012-11-17 06:56:53 +04:00
|
|
|
}
|
2012-12-13 19:49:52 +04:00
|
|
|
else if (SignatureId == RTS_PDU_PING)
|
|
|
|
{
|
|
|
|
rts_send_ping_pdu(rpc);
|
|
|
|
}
|
2012-12-12 08:34:51 +04:00
|
|
|
else
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Unimplemented signature id: 0x%08X\n", SignatureId);
|
2013-01-09 21:05:34 +04:00
|
|
|
rts_print_pdu_signature(rpc, &signature);
|
2012-12-12 08:34:51 +04:00
|
|
|
}
|
2012-11-17 06:17:04 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|