2012-03-26 10:45:01 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-03-26 20:20:38 +04:00
|
|
|
* Terminal Server Gateway (TSG)
|
2012-03-26 10:45:01 +04:00
|
|
|
*
|
2012-03-26 20:20:38 +04:00
|
|
|
* Copyright 2012 Fujitsu Technology Solutions GmbH
|
|
|
|
* Copyright 2012 Dmitrij Jasnov <dmitrij.jasnov@ts.fujitsu.com>
|
2012-11-01 04:38:48 +04:00
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2012-03-26 10:45:01 +04:00
|
|
|
*
|
|
|
|
* 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-03-26 20:20:38 +04:00
|
|
|
#ifndef FREERDP_CORE_TSG_H
|
|
|
|
#define FREERDP_CORE_TSG_H
|
2012-03-26 10:45:01 +04:00
|
|
|
|
|
|
|
typedef struct rdp_tsg rdpTsg;
|
|
|
|
|
2012-04-14 22:19:31 +04:00
|
|
|
#include "rpc.h"
|
2012-12-13 08:36:15 +04:00
|
|
|
|
|
|
|
#include "../transport.h"
|
2012-05-05 02:32:34 +04:00
|
|
|
|
|
|
|
#include <winpr/rpc.h>
|
2012-05-05 03:36:35 +04:00
|
|
|
#include <winpr/winpr.h>
|
2012-09-09 00:45:06 +04:00
|
|
|
#include <winpr/wtypes.h>
|
2014-05-30 22:53:10 +04:00
|
|
|
#include <winpr/synch.h>
|
2012-10-31 18:52:04 +04:00
|
|
|
#include <winpr/error.h>
|
2012-03-26 10:45:01 +04:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/settings.h>
|
2012-12-13 08:18:20 +04:00
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
#include <freerdp/utils/debug.h>
|
|
|
|
|
2012-11-15 07:34:45 +04:00
|
|
|
enum _TSG_STATE
|
|
|
|
{
|
|
|
|
TSG_STATE_INITIAL,
|
|
|
|
TSG_STATE_CONNECTED,
|
|
|
|
TSG_STATE_AUTHORIZED,
|
|
|
|
TSG_STATE_CHANNEL_CREATED,
|
|
|
|
TSG_STATE_PIPE_CREATED,
|
|
|
|
TSG_STATE_TUNNEL_CLOSE_PENDING,
|
|
|
|
TSG_STATE_CHANNEL_CLOSE_PENDING,
|
|
|
|
TSG_STATE_FINAL
|
|
|
|
};
|
|
|
|
typedef enum _TSG_STATE TSG_STATE;
|
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
struct rdp_tsg
|
|
|
|
{
|
2012-04-19 19:29:53 +04:00
|
|
|
rdpRpc* rpc;
|
2012-10-31 20:34:52 +04:00
|
|
|
UINT16 Port;
|
2012-11-29 06:25:01 +04:00
|
|
|
RPC_PDU* pdu;
|
2012-10-31 20:34:52 +04:00
|
|
|
LPWSTR Hostname;
|
2012-10-31 17:22:32 +04:00
|
|
|
LPWSTR MachineName;
|
2012-11-15 07:34:45 +04:00
|
|
|
TSG_STATE state;
|
2012-11-15 04:51:45 +04:00
|
|
|
BOOL PendingPdu;
|
2013-05-08 16:50:29 +04:00
|
|
|
UINT32 BytesRead;
|
|
|
|
UINT32 BytesAvailable;
|
2012-11-15 04:51:45 +04:00
|
|
|
UINT32 StubOffset;
|
|
|
|
UINT32 StubLength;
|
2012-03-26 20:20:38 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
rdpTransport* transport;
|
2012-11-09 21:52:34 +04:00
|
|
|
CONTEXT_HANDLE TunnelContext;
|
|
|
|
CONTEXT_HANDLE ChannelContext;
|
2012-03-26 10:45:01 +04:00
|
|
|
};
|
|
|
|
|
2012-10-31 11:43:21 +04:00
|
|
|
typedef WCHAR* RESOURCENAME;
|
2012-04-01 05:32:13 +04:00
|
|
|
|
2012-10-30 04:54:49 +04:00
|
|
|
#define TsProxyCreateTunnelOpnum 1
|
|
|
|
#define TsProxyAuthorizeTunnelOpnum 2
|
|
|
|
#define TsProxyMakeTunnelCallOpnum 3
|
|
|
|
#define TsProxyCreateChannelOpnum 4
|
2012-11-01 04:38:48 +04:00
|
|
|
#define TsProxyUnused5Opnum 5
|
|
|
|
#define TsProxyCloseChannelOpnum 6
|
|
|
|
#define TsProxyCloseTunnelOpnum 7
|
2012-10-30 04:54:49 +04:00
|
|
|
#define TsProxySetupReceivePipeOpnum 8
|
2012-11-01 04:38:48 +04:00
|
|
|
#define TsProxySendToServerOpnum 9
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2012-04-01 05:32:13 +04:00
|
|
|
#define MAX_RESOURCE_NAMES 50
|
|
|
|
|
|
|
|
typedef struct _tsendpointinfo
|
|
|
|
{
|
|
|
|
RESOURCENAME* resourceName;
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 numResourceNames;
|
2012-04-01 05:32:13 +04:00
|
|
|
RESOURCENAME* alternateResourceNames;
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT16 numAlternateResourceNames;
|
|
|
|
UINT32 Port;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSENDPOINTINFO, *PTSENDPOINTINFO;
|
|
|
|
|
2012-10-31 18:52:04 +04:00
|
|
|
#define TS_GATEWAY_TRANSPORT 0x5452
|
|
|
|
|
|
|
|
#define TSG_PACKET_TYPE_HEADER 0x00004844
|
|
|
|
#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643
|
|
|
|
#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143
|
|
|
|
#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152
|
|
|
|
#define TSG_PACKET_TYPE_RESPONSE 0x00005052
|
|
|
|
#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552
|
|
|
|
#define TSG_CAPABILITY_TYPE_NAP 0x00000001
|
|
|
|
#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350
|
|
|
|
#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752
|
|
|
|
#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750
|
|
|
|
#define TSG_PACKET_TYPE_AUTH 0x00004054
|
|
|
|
#define TSG_PACKET_TYPE_REAUTH 0x00005250
|
|
|
|
|
|
|
|
#define TSG_ASYNC_MESSAGE_CONSENT_MESSAGE 0x00000001
|
|
|
|
#define TSG_ASYNC_MESSAGE_SERVICE_MESSAGE 0x00000002
|
|
|
|
#define TSG_ASYNC_MESSAGE_REAUTH 0x00000003
|
2013-02-02 02:52:19 +04:00
|
|
|
|
2012-10-31 18:52:04 +04:00
|
|
|
#define TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST 0x00000001
|
|
|
|
#define TSG_TUNNEL_CANCEL_ASYNC_MSG_REQUEST 0x00000002
|
|
|
|
|
|
|
|
#define TSG_NAP_CAPABILITY_QUAR_SOH 0x00000001
|
|
|
|
#define TSG_NAP_CAPABILITY_IDLE_TIMEOUT 0x00000002
|
|
|
|
#define TSG_MESSAGING_CAP_CONSENT_SIGN 0x00000004
|
|
|
|
#define TSG_MESSAGING_CAP_SERVICE_MSG 0x00000008
|
|
|
|
#define TSG_MESSAGING_CAP_REAUTH 0x00000010
|
2013-10-18 00:51:04 +04:00
|
|
|
#define TSG_MESSAGING_MAX_MESSAGE_LENGTH 65536
|
2012-10-31 18:52:04 +04:00
|
|
|
|
|
|
|
/* Error Codes */
|
|
|
|
|
|
|
|
#define E_PROXY_INTERNALERROR 0x800759D8
|
|
|
|
#define E_PROXY_RAP_ACCESSDENIED 0x800759DA
|
|
|
|
#define E_PROXY_NAP_ACCESSDENIED 0x800759DB
|
|
|
|
#define E_PROXY_TS_CONNECTFAILED 0x800759DD
|
|
|
|
#define E_PROXY_ALREADYDISCONNECTED 0x800759DF
|
|
|
|
#define E_PROXY_QUARANTINE_ACCESSDENIED 0x800759ED
|
|
|
|
#define E_PROXY_NOCERTAVAILABLE 0x800759EE
|
|
|
|
#define E_PROXY_COOKIE_BADPACKET 0x800759F7
|
|
|
|
#define E_PROXY_COOKIE_AUTHENTICATION_ACCESS_DENIED 0x800759F8
|
|
|
|
#define E_PROXY_UNSUPPORTED_AUTHENTICATION_METHOD 0x800759F9
|
|
|
|
#define E_PROXY_CAPABILITYMISMATCH 0x800759E9
|
|
|
|
|
|
|
|
#define E_PROXY_NOTSUPPORTED 0x000059E8
|
|
|
|
#define E_PROXY_MAXCONNECTIONSREACHED 0x000059E6
|
|
|
|
#define E_PROXY_SESSIONTIMEOUT 0x000059F6
|
|
|
|
#define E_PROXY_REAUTH_AUTHN_FAILED 0X000059FA
|
|
|
|
#define E_PROXY_REAUTH_CAP_FAILED 0x000059FB
|
|
|
|
#define E_PROXY_REAUTH_RAP_FAILED 0x000059FC
|
|
|
|
#define E_PROXY_SDR_NOT_SUPPORTED_BY_TS 0x000059FD
|
|
|
|
#define E_PROXY_REAUTH_NAP_FAILED 0x00005A00
|
|
|
|
#define E_PROXY_CONNECTIONABORTED 0x000004D4
|
|
|
|
|
2012-04-01 05:32:13 +04:00
|
|
|
typedef struct _TSG_PACKET_HEADER
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT16 ComponentId;
|
|
|
|
UINT16 PacketId;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_HEADER, *PTSG_PACKET_HEADER;
|
|
|
|
|
|
|
|
typedef struct _TSG_CAPABILITY_NAP
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 capabilities;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_CAPABILITY_NAP, *PTSG_CAPABILITY_NAP;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
TSG_CAPABILITY_NAP tsgCapNap;
|
|
|
|
} TSG_CAPABILITIES_UNION, *PTSG_CAPABILITIES_UNION;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_CAPABILITIES
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 capabilityType;
|
2012-04-01 05:32:13 +04:00
|
|
|
TSG_CAPABILITIES_UNION tsgPacket;
|
|
|
|
} TSG_PACKET_CAPABILITIES, *PTSG_PACKET_CAPABILITIES;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_VERSIONCAPS
|
|
|
|
{
|
|
|
|
TSG_PACKET_HEADER tsgHeader;
|
|
|
|
PTSG_PACKET_CAPABILITIES tsgCaps;
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 numCapabilities;
|
|
|
|
UINT16 majorVersion;
|
|
|
|
UINT16 minorVersion;
|
|
|
|
UINT16 quarantineCapabilities;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_VERSIONCAPS, *PTSG_PACKET_VERSIONCAPS;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_QUARCONFIGREQUEST
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 flags;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_QUARCONFIGREQUEST, *PTSG_PACKET_QUARCONFIGREQUEST;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_QUARREQUEST
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 flags;
|
|
|
|
WCHAR* machineName;
|
|
|
|
UINT32 nameLength;
|
|
|
|
BYTE* data;
|
|
|
|
UINT32 dataLen;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_QUARREQUEST, *PTSG_PACKET_QUARREQUEST;
|
|
|
|
|
|
|
|
typedef struct _TSG_REDIRECTION_FLAGS
|
|
|
|
{
|
|
|
|
BOOL enableAllRedirections;
|
|
|
|
BOOL disableAllRedirections;
|
|
|
|
BOOL driveRedirectionDisabled;
|
|
|
|
BOOL printerRedirectionDisabled;
|
|
|
|
BOOL portRedirectionDisabled;
|
|
|
|
BOOL reserved;
|
|
|
|
BOOL clipboardRedirectionDisabled;
|
|
|
|
BOOL pnpRedirectionDisabled;
|
|
|
|
} TSG_REDIRECTION_FLAGS, *PTSG_REDIRECTION_FLAGS;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_RESPONSE
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 flags;
|
|
|
|
UINT32 reserved;
|
|
|
|
BYTE* responseData;
|
|
|
|
UINT32 responseDataLen;
|
2012-04-01 05:32:13 +04:00
|
|
|
TSG_REDIRECTION_FLAGS redirectionFlags;
|
|
|
|
} TSG_PACKET_RESPONSE, *PTSG_PACKET_RESPONSE;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_QUARENC_RESPONSE
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 flags;
|
|
|
|
UINT32 certChainLen;
|
|
|
|
WCHAR* certChainData;
|
2012-04-01 05:32:13 +04:00
|
|
|
GUID nonce;
|
|
|
|
PTSG_PACKET_VERSIONCAPS versionCaps;
|
|
|
|
} TSG_PACKET_QUARENC_RESPONSE, *PTSG_PACKET_QUARENC_RESPONSE;
|
|
|
|
|
|
|
|
typedef struct TSG_PACKET_STRING_MESSAGE
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
INT32 isDisplayMandatory;
|
|
|
|
INT32 isConsentMandatory;
|
|
|
|
UINT32 msgBytes;
|
|
|
|
WCHAR* msgBuffer;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_STRING_MESSAGE, *PTSG_PACKET_STRING_MESSAGE;
|
|
|
|
|
|
|
|
typedef struct TSG_PACKET_REAUTH_MESSAGE
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT64 tunnelContext;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_REAUTH_MESSAGE, *PTSG_PACKET_REAUTH_MESSAGE;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
PTSG_PACKET_STRING_MESSAGE consentMessage;
|
|
|
|
PTSG_PACKET_STRING_MESSAGE serviceMessage;
|
|
|
|
PTSG_PACKET_REAUTH_MESSAGE reauthMessage;
|
|
|
|
} TSG_PACKET_TYPE_MESSAGE_UNION, *PTSG_PACKET_TYPE_MESSAGE_UNION;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_MSG_RESPONSE
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 msgID;
|
|
|
|
UINT32 msgType;
|
|
|
|
INT32 isMsgPresent;
|
2012-04-01 05:32:13 +04:00
|
|
|
TSG_PACKET_TYPE_MESSAGE_UNION messagePacket;
|
|
|
|
} TSG_PACKET_MSG_RESPONSE, *PTSG_PACKET_MSG_RESPONSE;
|
|
|
|
|
|
|
|
typedef struct TSG_PACKET_CAPS_RESPONSE
|
|
|
|
{
|
|
|
|
TSG_PACKET_QUARENC_RESPONSE pktQuarEncResponse;
|
|
|
|
TSG_PACKET_MSG_RESPONSE pktConsentMessage;
|
|
|
|
} TSG_PACKET_CAPS_RESPONSE, *PTSG_PACKET_CAPS_RESPONSE;
|
|
|
|
|
|
|
|
typedef struct TSG_PACKET_MSG_REQUEST
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 maxMessagesPerBatch;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_MSG_REQUEST, *PTSG_PACKET_MSG_REQUEST;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET_AUTH
|
|
|
|
{
|
|
|
|
TSG_PACKET_VERSIONCAPS tsgVersionCaps;
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 cookieLen;
|
|
|
|
BYTE* cookie;
|
2012-04-01 05:32:13 +04:00
|
|
|
} TSG_PACKET_AUTH, *PTSG_PACKET_AUTH;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
|
|
|
|
PTSG_PACKET_AUTH packetAuth;
|
|
|
|
} TSG_INITIAL_PACKET_TYPE_UNION, *PTSG_INITIAL_PACKET_TYPE_UNION;
|
|
|
|
|
|
|
|
typedef struct TSG_PACKET_REAUTH
|
|
|
|
{
|
2012-10-31 18:52:04 +04:00
|
|
|
UINT64 tunnelContext;
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 packetId;
|
2012-04-01 05:32:13 +04:00
|
|
|
TSG_INITIAL_PACKET_TYPE_UNION tsgInitialPacket;
|
|
|
|
} TSG_PACKET_REAUTH, *PTSG_PACKET_REAUTH;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
PTSG_PACKET_HEADER packetHeader;
|
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
|
|
|
|
PTSG_PACKET_QUARCONFIGREQUEST packetQuarConfigRequest;
|
|
|
|
PTSG_PACKET_QUARREQUEST packetQuarRequest;
|
|
|
|
PTSG_PACKET_RESPONSE packetResponse;
|
|
|
|
PTSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse;
|
|
|
|
PTSG_PACKET_CAPS_RESPONSE packetCapsResponse;
|
|
|
|
PTSG_PACKET_MSG_REQUEST packetMsgRequest;
|
|
|
|
PTSG_PACKET_MSG_RESPONSE packetMsgResponse;
|
|
|
|
PTSG_PACKET_AUTH packetAuth;
|
|
|
|
PTSG_PACKET_REAUTH packetReauth;
|
|
|
|
} TSG_PACKET_TYPE_UNION;
|
|
|
|
|
|
|
|
typedef struct _TSG_PACKET
|
|
|
|
{
|
2012-10-31 11:43:21 +04:00
|
|
|
UINT32 packetId;
|
2012-04-01 05:32:13 +04:00
|
|
|
TSG_PACKET_TYPE_UNION tsgPacket;
|
|
|
|
} TSG_PACKET, *PTSG_PACKET;
|
|
|
|
|
2012-10-31 11:43:21 +04:00
|
|
|
DWORD TsProxySendToServer(handle_t IDL_handle, BYTE pRpcMessage[], UINT32 count, UINT32* lengths);
|
2012-04-01 05:32:13 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port);
|
2012-12-13 05:02:56 +04:00
|
|
|
BOOL tsg_disconnect(rdpTsg* tsg);
|
2012-03-26 20:20:38 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length);
|
|
|
|
int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length);
|
2012-03-26 20:20:38 +04:00
|
|
|
|
2012-12-07 01:49:50 +04:00
|
|
|
BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking);
|
|
|
|
|
2012-04-24 00:33:18 +04:00
|
|
|
rdpTsg* tsg_new(rdpTransport* transport);
|
2012-03-26 10:45:01 +04:00
|
|
|
void tsg_free(rdpTsg* tsg);
|
|
|
|
|
|
|
|
#ifdef WITH_DEBUG_TSG
|
|
|
|
#define DEBUG_TSG(fmt, ...) DEBUG_CLASS(TSG, fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DEBUG_TSG(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2012-03-26 20:20:38 +04:00
|
|
|
#endif /* FREERDP_CORE_TSG_H */
|