22#ifndef FREERDP_LIB_CORE_GATEWAY_RPC_H
23#define FREERDP_LIB_CORE_GATEWAY_RPC_H
25#include <winpr/wtypes.h>
26#include <winpr/stream.h>
27#include <winpr/collections.h>
28#include <winpr/interlocked.h>
30#include <freerdp/log.h>
31#include <freerdp/utils/ringbuffer.h>
33#include "../../crypto/tls.h"
51#define RPC_COMMON_FIELDS_LENGTH sizeof(rpcconn_common_hdr_t)
58 UINT16 NumberOfCommands;
61#define RTS_PDU_HEADER_LENGTH 20
63#define RPC_PDU_FLAG_STUB 0x00000001
76#include "../transport.h"
79#include "../credssp_auth.h"
83#include <winpr/sspi.h>
84#include <winpr/interlocked.h>
86#include <freerdp/types.h>
87#include <freerdp/settings.h>
88#include <freerdp/crypto/crypto.h>
89#include <freerdp/api.h>
91#include <winpr/print.h>
100#define PTYPE_REQUEST 0x00
101#define PTYPE_PING 0x01
102#define PTYPE_RESPONSE 0x02
103#define PTYPE_FAULT 0x03
104#define PTYPE_WORKING 0x04
105#define PTYPE_NOCALL 0x05
106#define PTYPE_REJECT 0x06
107#define PTYPE_ACK 0x07
108#define PTYPE_CL_CANCEL 0x08
109#define PTYPE_FACK 0x09
110#define PTYPE_CANCEL_ACK 0x0A
111#define PTYPE_BIND 0x0B
112#define PTYPE_BIND_ACK 0x0C
113#define PTYPE_BIND_NAK 0x0D
114#define PTYPE_ALTER_CONTEXT 0x0E
115#define PTYPE_ALTER_CONTEXT_RESP 0x0F
116#define PTYPE_RPC_AUTH_3 0x10
117#define PTYPE_SHUTDOWN 0x11
118#define PTYPE_CO_CANCEL 0x12
119#define PTYPE_ORPHANED 0x13
120#define PTYPE_RTS 0x14
122#define PFC_FIRST_FRAG 0x01
123#define PFC_LAST_FRAG 0x02
124#define PFC_PENDING_CANCEL 0x04
125#define PFC_SUPPORT_HEADER_SIGN 0x04
126#define PFC_RESERVED_1 0x08
127#define PFC_CONC_MPX 0x10
128#define PFC_DID_NOT_EXECUTE 0x20
129#define PFC_MAYBE 0x40
130#define PFC_OBJECT_UUID 0x80
133#define RPC_CO_MUST_RECV_FRAG_SIZE 1432
134#define RPC_CL_MUST_RECV_FRAG_SIZE 1464
142#define RPC_PDU_HEADER_MAX_LENGTH 32
146typedef UINT16 p_context_id_t;
147typedef UINT16 p_reject_reason_t;
153 UINT16 time_hi_and_version;
154 BYTE clock_seq_hi_and_reserved;
159#define ndr_c_int_big_endian 0
160#define ndr_c_int_little_endian 1
161#define ndr_c_float_ieee 0
162#define ndr_c_float_vax 1
163#define ndr_c_float_cray 2
164#define ndr_c_float_ibm 3
165#define ndr_c_char_ascii 0
166#define ndr_c_char_ebcdic 1
178 UINT32 context_handle_attributes;
190 p_context_id_t p_cont_id;
210} p_cont_def_result_t;
214 reason_not_specified,
215 abstract_syntax_not_supported,
216 proposed_transfer_syntaxes_not_supported,
218} p_provider_reason_t;
222 p_cont_def_result_t result;
223 p_provider_reason_t reason;
256#define REASON_NOT_SPECIFIED 0
257#define TEMPORARY_CONGESTION 1
258#define LOCAL_LIMIT_EXCEEDED 2
259#define CALLED_PADDR_UNKNOWN 3
260#define PROTOCOL_VERSION_NOT_SUPPORTED 4
261#define DEFAULT_CONTEXT_NOT_SUPPORTED 5
262#define USER_DATA_NOT_READABLE 6
263#define NO_PSAP_AVAILABLE 7
265typedef UINT16 rpcrt_reason_code_t;
273 UINT32 reject_status;
279 rpcrt_reason_code_t reason_code;
285 rpcrt_reason_code_t reason_code;
300 BYTE auth_pad_length;
302 UINT32 auth_context_id;
316 UINT16 max_xmit_frag;
317 UINT16 max_recv_frag;
318 UINT32 assoc_group_id;
322 auth_verifier_co_t auth_verifier;
330 UINT16 max_xmit_frag;
331 UINT16 max_recv_frag;
332 UINT32 assoc_group_id;
339 auth_verifier_co_t auth_verifier;
347 UINT16 max_xmit_frag;
348 UINT16 max_recv_frag;
349 UINT32 assoc_group_id;
353 auth_verifier_co_t auth_verifier;
360 UINT16 max_xmit_frag;
361 UINT16 max_recv_frag;
362 UINT32 assoc_group_id;
370 auth_verifier_co_t auth_verifier;
377 UINT16 max_xmit_frag;
378 UINT16 max_recv_frag;
380 auth_verifier_co_t auth_verifier;
387 p_reject_reason_t provider_reject_reason;
396 auth_verifier_co_t auth_verifier;
408 const char* category;
411#define DEFINE_RPC_FAULT_CODE(_code, cat) \
416#define nca_s_comm_failure 0x1C010001
417#define nca_s_op_rng_error 0x1C010002
418#define nca_s_unk_if 0x1C010003
419#define nca_s_wrong_boot_time 0x1C010006
420#define nca_s_you_crashed 0x1C010009
421#define nca_s_proto_error 0x1C01000B
422#define nca_s_out_args_too_big 0x1C010013
423#define nca_s_server_too_busy 0x1C010014
424#define nca_s_fault_string_too_long 0x1C010015
425#define nca_s_unsupported_type 0x1C010017
426#define nca_s_fault_int_div_by_zero 0x1C000001
427#define nca_s_fault_addr_error 0x1C000002
428#define nca_s_fault_fp_div_zero 0x1C000003
429#define nca_s_fault_fp_underflow 0x1C000004
430#define nca_s_fault_fp_overflow 0x1C000005
431#define nca_s_fault_invalid_tag 0x1C000006
432#define nca_s_fault_invalid_bound 0x1C000007
433#define nca_s_rpc_version_mismatch 0x1C000008
434#define nca_s_unspec_reject 0x1C000009
435#define nca_s_bad_actid 0x1C00000A
436#define nca_s_who_are_you_failed 0x1C00000B
437#define nca_s_manager_not_entered 0x1C00000C
438#define nca_s_fault_cancel 0x1C00000D
439#define nca_s_fault_ill_inst 0x1C00000E
440#define nca_s_fault_fp_error 0x1C00000F
441#define nca_s_fault_int_overflow 0x1C000010
442#define nca_s_fault_unspec 0x1C000012
443#define nca_s_fault_remote_comm_failure 0x1C000013
444#define nca_s_fault_pipe_empty 0x1C000014
445#define nca_s_fault_pipe_closed 0x1C000015
446#define nca_s_fault_pipe_order 0x1C000016
447#define nca_s_fault_pipe_discipline 0x1C000017
448#define nca_s_fault_pipe_comm_error 0x1C000018
449#define nca_s_fault_pipe_memory 0x1C000019
450#define nca_s_fault_context_mismatch 0x1C00001A
451#define nca_s_fault_remote_no_memory 0x1C00001B
452#define nca_s_invalid_pres_context_id 0x1C00001C
453#define nca_s_unsupported_authn_level 0x1C00001D
454#define nca_s_invalid_checksum 0x1C00001F
455#define nca_s_invalid_crc 0x1C000020
456#define nca_s_fault_user_defined 0x1C000021
457#define nca_s_fault_tx_open_failed 0x1C000022
458#define nca_s_fault_codeset_conv_error 0x1C000023
459#define nca_s_fault_object_not_found 0x1C000024
460#define nca_s_fault_no_client_stub 0x1C000025
469 p_context_id_t p_cont_id;
480 auth_verifier_co_t auth_verifier;
487 auth_verifier_co_t auth_verifier;
496 p_context_id_t p_cont_id;
506 auth_verifier_co_t auth_verifier;
514 p_context_id_t p_cont_id;
523 auth_verifier_co_t auth_verifier;
560 RPC_CLIENT_STATE_INITIAL,
561 RPC_CLIENT_STATE_ESTABLISHED,
562 RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK,
563 RPC_CLIENT_STATE_WAIT_UNSECURE_BIND_ACK,
564 RPC_CLIENT_STATE_WAIT_SECURE_ALTER_CONTEXT_RESPONSE,
565 RPC_CLIENT_STATE_CONTEXT_NEGOTIATED,
566 RPC_CLIENT_STATE_WAIT_RESPONSE,
567 RPC_CLIENT_STATE_FINAL
572 RPC_CLIENT_CALL_STATE_INITIAL,
573 RPC_CLIENT_CALL_STATE_SEND_PDUS,
574 RPC_CLIENT_CALL_STATE_DISPATCHED,
575 RPC_CLIENT_CALL_STATE_RECEIVE_PDU,
576 RPC_CLIENT_CALL_STATE_COMPLETE,
577 RPC_CLIENT_CALL_STATE_FAULT,
578 RPC_CLIENT_CALL_STATE_FINAL
579} RPC_CLIENT_CALL_STATE;
585 RPC_CLIENT_CALL_STATE State;
596 wArrayList* ClientCallList;
607 rdpCredsspAuth* auth;
617 UINT32 ConnectionTimeout;
618 UINT32 LastPacketSentTimestamp;
619 UINT32 KeepAliveInterval;
626 CLIENT_IN_CHANNEL_STATE_INITIAL,
627 CLIENT_IN_CHANNEL_STATE_CONNECTED,
628 CLIENT_IN_CHANNEL_STATE_SECURITY,
629 CLIENT_IN_CHANNEL_STATE_NEGOTIATED,
630 CLIENT_IN_CHANNEL_STATE_OPENED,
631 CLIENT_IN_CHANNEL_STATE_OPENED_A4W,
632 CLIENT_IN_CHANNEL_STATE_FINAL
633} CLIENT_IN_CHANNEL_STATE;
641 CLIENT_IN_CHANNEL_STATE State;
646 UINT32 SenderAvailableWindow;
647 UINT32 PeerReceiveWindow;
658 CLIENT_OUT_CHANNEL_STATE_INITIAL,
659 CLIENT_OUT_CHANNEL_STATE_CONNECTED,
660 CLIENT_OUT_CHANNEL_STATE_SECURITY,
661 CLIENT_OUT_CHANNEL_STATE_NEGOTIATED,
662 CLIENT_OUT_CHANNEL_STATE_OPENED,
663 CLIENT_OUT_CHANNEL_STATE_OPENED_A6W,
664 CLIENT_OUT_CHANNEL_STATE_OPENED_A10W,
665 CLIENT_OUT_CHANNEL_STATE_OPENED_B3W,
666 CLIENT_OUT_CHANNEL_STATE_RECYCLED,
667 CLIENT_OUT_CHANNEL_STATE_FINAL
668} CLIENT_OUT_CHANNEL_STATE;
676 CLIENT_OUT_CHANNEL_STATE State;
678 UINT32 ReceiveWindow;
679 UINT32 ReceiveWindowSize;
680 UINT32 ReceiverAvailableWindow;
681 UINT32 BytesReceived;
682 UINT32 AvailableWindowAdvertised;
689 VIRTUAL_CONNECTION_STATE_INITIAL,
690 VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT,
691 VIRTUAL_CONNECTION_STATE_WAIT_A3W,
692 VIRTUAL_CONNECTION_STATE_WAIT_C2,
693 VIRTUAL_CONNECTION_STATE_OPENED,
694 VIRTUAL_CONNECTION_STATE_FINAL
695} VIRTUAL_CONNECTION_STATE;
700 GUID AssociationGroupId;
701 VIRTUAL_CONNECTION_STATE State;
710#define RPC_UUID_FORMAT_STRING \
711 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
712#define RPC_UUID_FORMAT_ARGUMENTS(_rpc_uuid) \
713 _rpc_uuid[0], _rpc_uuid[1], _rpc_uuid[2], _rpc_uuid[3], _rpc_uuid[4], _rpc_uuid[5], \
714 _rpc_uuid[6], _rpc_uuid[7], _rpc_uuid[8], _rpc_uuid[9], _rpc_uuid[10], _rpc_uuid[11], \
715 _rpc_uuid[12], _rpc_uuid[13], _rpc_uuid[14], _rpc_uuid[15]
720 UINT32 ReferenceCount;
726 RPC_CLIENT_STATE State;
730 rdpCredsspAuth* auth;
735 rdpTransport* transport;
741 UINT32 StubFragCount;
747 UINT16 max_xmit_frag;
748 UINT16 max_recv_frag;
750 UINT32 ReceiveWindow;
751 UINT32 ChannelLifetime;
752 UINT32 KeepAliveInterval;
753 UINT32 CurrentKeepAliveTime;
754 UINT32 CurrentKeepAliveInterval;
760FREERDP_LOCAL
const char* rpc_vc_state_str(VIRTUAL_CONNECTION_STATE state);
761FREERDP_LOCAL
void rpc_pdu_header_print(wLog* log,
const rpcconn_hdr_t* header);
764FREERDP_LOCAL
size_t rpc_offset_align(
size_t* offset,
size_t alignment);
765FREERDP_LOCAL
size_t rpc_offset_pad(
size_t* offset,
size_t pad);
767FREERDP_LOCAL BOOL rpc_get_stub_data_info(rdpRpc* rpc,
const rpcconn_hdr_t* header,
size_t* offset,
770#define rpc_channel_write(channel, data, length) \
771 rpc_channel_write_int((channel), (data), (length), __FILE__, __LINE__, __func__)
772FREERDP_LOCAL SSIZE_T rpc_channel_write_int(
RpcChannel* channel,
const BYTE* data,
size_t length,
773 const char* file,
size_t line,
const char* fkt);
775FREERDP_LOCAL SSIZE_T rpc_channel_read(
RpcChannel* channel,
wStream* s,
size_t length);
777FREERDP_LOCAL
void rpc_channel_free(
RpcChannel* channel);
779WINPR_ATTR_MALLOC(rpc_channel_free, 1)
780FREERDP_LOCAL
RpcOutChannel* rpc_out_channel_new(rdpRpc* rpc, const GUID* guid);
781FREERDP_LOCAL
int rpc_out_channel_replacement_connect(
RpcOutChannel* outChannel, uint32_t timeout);
783FREERDP_LOCAL BOOL rpc_in_channel_transition_to_state(
RpcInChannel* inChannel,
784 CLIENT_IN_CHANNEL_STATE state);
785FREERDP_LOCAL BOOL rpc_out_channel_transition_to_state(
RpcOutChannel* outChannel,
786 CLIENT_OUT_CHANNEL_STATE state);
788FREERDP_LOCAL BOOL rpc_virtual_connection_transition_to_state(rdpRpc* rpc,
790 VIRTUAL_CONNECTION_STATE state);
792FREERDP_LOCAL BOOL rpc_connect(rdpRpc* rpc, UINT32 timeout);
794FREERDP_LOCAL
void rpc_free(rdpRpc* rpc);
796WINPR_ATTR_MALLOC(rpc_free, 1)
797FREERDP_LOCAL rdpRpc* rpc_new(rdpTransport* transport);