1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * Network Transport Layer
4  *
5  * Copyright 2011 Vic Lee
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef FREERDP_LIB_CORE_TRANSPORT_H
21 #define FREERDP_LIB_CORE_TRANSPORT_H
22 
23 typedef enum
24 {
25 	TRANSPORT_LAYER_TCP,
26 	TRANSPORT_LAYER_TLS,
27 	TRANSPORT_LAYER_TSG,
28 	TRANSPORT_LAYER_TSG_TLS,
29 	TRANSPORT_LAYER_CLOSED
30 } TRANSPORT_LAYER;
31 
32 typedef struct rdp_transport rdpTransport;
33 
34 #include "tcp.h"
35 #include "nla.h"
36 
37 #include "gateway/tsg.h"
38 #include "gateway/rdg.h"
39 
40 #include <winpr/sspi.h>
41 #include <winpr/wlog.h>
42 #include <winpr/synch.h>
43 #include <winpr/thread.h>
44 #include <winpr/stream.h>
45 #include <winpr/collections.h>
46 
47 #include <freerdp/api.h>
48 #include <freerdp/crypto/tls.h>
49 
50 #include <time.h>
51 #include <freerdp/types.h>
52 #include <freerdp/settings.h>
53 
54 typedef int (*TransportRecv)(rdpTransport* transport, wStream* stream, void* extra);
55 
56 struct rdp_transport
57 {
58 	TRANSPORT_LAYER layer;
59 	BIO* frontBio;
60 	rdpRdg* rdg;
61 	rdpTsg* tsg;
62 	rdpTls* tls;
63 	rdpContext* context;
64 	rdpNla* nla;
65 	rdpSettings* settings;
66 	void* ReceiveExtra;
67 	wStream* ReceiveBuffer;
68 	TransportRecv ReceiveCallback;
69 	wStreamPool* ReceivePool;
70 	HANDLE connectedEvent;
71 	BOOL NlaMode;
72 	BOOL blocking;
73 	BOOL GatewayEnabled;
74 	CRITICAL_SECTION ReadLock;
75 	CRITICAL_SECTION WriteLock;
76 	ULONG written;
77 	HANDLE rereadEvent;
78 	BOOL haveMoreBytesToRead;
79 	wLog* log;
80 };
81 
82 FREERDP_LOCAL wStream* transport_send_stream_init(rdpTransport* transport, int size);
83 FREERDP_LOCAL BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port,
84                                      DWORD timeout);
85 FREERDP_LOCAL BOOL transport_attach(rdpTransport* transport, int sockfd);
86 FREERDP_LOCAL BOOL transport_disconnect(rdpTransport* transport);
87 FREERDP_LOCAL BOOL transport_connect_rdp(rdpTransport* transport);
88 FREERDP_LOCAL BOOL transport_connect_tls(rdpTransport* transport);
89 FREERDP_LOCAL BOOL transport_connect_nla(rdpTransport* transport);
90 FREERDP_LOCAL BOOL transport_accept_rdp(rdpTransport* transport);
91 FREERDP_LOCAL BOOL transport_accept_tls(rdpTransport* transport);
92 FREERDP_LOCAL BOOL transport_accept_nla(rdpTransport* transport);
93 
94 FREERDP_LOCAL int transport_read_pdu(rdpTransport* transport, wStream* s);
95 FREERDP_LOCAL int transport_write(rdpTransport* transport, wStream* s);
96 
97 FREERDP_LOCAL void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount);
98 FREERDP_LOCAL int transport_check_fds(rdpTransport* transport);
99 
100 FREERDP_LOCAL DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events,
101                                                 DWORD nCount);
102 
103 FREERDP_LOCAL BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking);
104 FREERDP_LOCAL void transport_set_gateway_enabled(rdpTransport* transport, BOOL GatewayEnabled);
105 FREERDP_LOCAL void transport_set_nla_mode(rdpTransport* transport, BOOL NlaMode);
106 FREERDP_LOCAL BOOL transport_is_write_blocked(rdpTransport* transport);
107 FREERDP_LOCAL int transport_drain_output_buffer(rdpTransport* transport);
108 
109 FREERDP_LOCAL wStream* transport_receive_pool_take(rdpTransport* transport);
110 FREERDP_LOCAL int transport_receive_pool_return(rdpTransport* transport, wStream* pdu);
111 
112 FREERDP_LOCAL rdpTransport* transport_new(rdpContext* context);
113 FREERDP_LOCAL void transport_free(rdpTransport* transport);
114 
115 #endif /* FREERDP_LIB_CORE_TRANSPORT_H */
116