libfreerdp-core: added connection module
This commit is contained in:
parent
54a697d0bc
commit
841800a451
@ -20,10 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tpkt.h"
|
||||
#include "nego.h"
|
||||
#include "mcs.h"
|
||||
#include "transport.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
@ -32,16 +29,23 @@ rdpMcs* mcs;
|
||||
rdpNego* nego;
|
||||
rdpSettings* settings;
|
||||
rdpTransport* transport;
|
||||
rdpConnection* connection;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
char* username;
|
||||
char* hostname;
|
||||
char* password;
|
||||
uint16 channelId;
|
||||
|
||||
settings = settings_new();
|
||||
transport = transport_new(settings);
|
||||
nego = nego_new(transport);
|
||||
connection = connection_new();
|
||||
connection->nego = nego;
|
||||
connection->settings = settings;
|
||||
connection->transport = transport;
|
||||
|
||||
if (argc < 4)
|
||||
{
|
||||
@ -69,24 +73,7 @@ int main(int argc, char* argv[])
|
||||
settings->password = password;
|
||||
settings->domain = NULL;
|
||||
|
||||
nego_init(nego);
|
||||
nego_set_target(nego, hostname, 3389);
|
||||
nego_set_protocols(nego, 1, 1, 1);
|
||||
nego_set_cookie(nego, username);
|
||||
nego_connect(nego);
|
||||
|
||||
transport_connect_nla(transport);
|
||||
|
||||
mcs = mcs_new(transport);
|
||||
|
||||
mcs_send_connect_initial(mcs);
|
||||
|
||||
mcs_recv_connect_response(mcs);
|
||||
|
||||
mcs_send_erect_domain_request(mcs);
|
||||
mcs_send_attach_user_request(mcs);
|
||||
|
||||
mcs_recv_attach_user_confirm(mcs);
|
||||
connection_client_connect(connection);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ set(LIBFREERDP_CORE_SRCS
|
||||
ntlmssp.c
|
||||
ntlmssp.h
|
||||
settings.c
|
||||
connection.c
|
||||
connection.h
|
||||
per.c
|
||||
per.h
|
||||
tcp.c
|
||||
|
105
libfreerdp-core/connection.c
Normal file
105
libfreerdp-core/connection.c
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Connection Sequence
|
||||
*
|
||||
* Copyright 2011 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.
|
||||
*/
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
/**
|
||||
* Connection Sequence
|
||||
* client server
|
||||
* | |
|
||||
* |-----------------------X.224 Connection Request PDU--------------------->|
|
||||
* |<----------------------X.224 Connection Confirm PDU----------------------|
|
||||
* |-------MCS Connect-Initial PDU with GCC Conference Create Request------->|
|
||||
* |<-----MCS Connect-Response PDU with GCC Conference Create Response-------|
|
||||
* |------------------------MCS Erect Domain Request PDU-------------------->|
|
||||
* |------------------------MCS Attach User Request PDU--------------------->|
|
||||
* |<-----------------------MCS Attach User Confirm PDU----------------------|
|
||||
* |------------------------MCS Channel Join Request PDU-------------------->|
|
||||
* |<-----------------------MCS Channel Join Confirm PDU---------------------|
|
||||
* |----------------------------Security Exchange PDU----------------------->|
|
||||
* |-------------------------------Client Info PDU-------------------------->|
|
||||
*
|
||||
*/
|
||||
|
||||
void connection_client_connect(rdpConnection* connection)
|
||||
{
|
||||
int i;
|
||||
uint16 channelId;
|
||||
|
||||
nego_init(connection->nego);
|
||||
nego_set_target(connection->nego, connection->settings->hostname, 3389);
|
||||
nego_set_cookie(connection->nego, connection->settings->username);
|
||||
nego_set_protocols(connection->nego, 1, 1, 1);
|
||||
nego_connect(connection->nego);
|
||||
|
||||
transport_connect_nla(connection->transport);
|
||||
|
||||
connection->mcs = mcs_new(connection->transport);
|
||||
|
||||
mcs_send_connect_initial(connection->mcs);
|
||||
mcs_recv_connect_response(connection->mcs);
|
||||
|
||||
mcs_send_erect_domain_request(connection->mcs);
|
||||
mcs_send_attach_user_request(connection->mcs);
|
||||
mcs_recv_attach_user_confirm(connection->mcs);
|
||||
|
||||
mcs_send_channel_join_request(connection->mcs, connection->mcs->user_id);
|
||||
mcs_recv_channel_join_confirm(connection->mcs);
|
||||
|
||||
for (i = 0; i < connection->settings->num_channels; i++)
|
||||
{
|
||||
channelId = connection->settings->channels[i].chan_id;
|
||||
mcs_send_channel_join_request(connection->mcs, channelId);
|
||||
mcs_recv_channel_join_confirm(connection->mcs);
|
||||
}
|
||||
|
||||
mcs_recv(connection->mcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate new connection module.
|
||||
* @return new connection module
|
||||
*/
|
||||
|
||||
rdpConnection* connection_new()
|
||||
{
|
||||
rdpConnection* connection;
|
||||
|
||||
connection = (rdpConnection*) xzalloc(sizeof(rdpConnection));
|
||||
|
||||
if (connection != NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free connection module.
|
||||
* @param connection connect module to be freed
|
||||
*/
|
||||
|
||||
void connection_free(rdpConnection* connection)
|
||||
{
|
||||
if (connection != NULL)
|
||||
{
|
||||
xfree(connection);
|
||||
}
|
||||
}
|
45
libfreerdp-core/connection.h
Normal file
45
libfreerdp-core/connection.h
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Connection Sequence
|
||||
*
|
||||
* Copyright 2011 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.
|
||||
*/
|
||||
|
||||
#ifndef __CONNECTION_H
|
||||
#define __CONNECTION_H
|
||||
|
||||
#include "tpkt.h"
|
||||
#include "nego.h"
|
||||
#include "mcs.h"
|
||||
#include "transport.h"
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
struct rdp_connection
|
||||
{
|
||||
struct rdp_mcs* mcs;
|
||||
struct rdp_nego* nego;
|
||||
struct rdp_settings* settings;
|
||||
struct rdp_transport* transport;
|
||||
};
|
||||
typedef struct rdp_connection rdpConnection;
|
||||
|
||||
void connection_client_connect(rdpConnection* connection);
|
||||
|
||||
rdpConnection* connection_new();
|
||||
void connection_free(rdpConnection* connection);
|
||||
|
||||
#endif /* __CONNECTION_H */
|
@ -372,7 +372,7 @@ void mcs_recv_attach_user_confirm(rdpMcs* mcs)
|
||||
void mcs_send_channel_join_request(rdpMcs* mcs, uint16 channel_id)
|
||||
{
|
||||
STREAM* s;
|
||||
int length = 8;
|
||||
int length = 12;
|
||||
s = stream_new(length);
|
||||
|
||||
tpkt_write_header(s, length);
|
||||
@ -409,6 +409,17 @@ void mcs_recv_channel_join_confirm(rdpMcs* mcs)
|
||||
per_read_integer16(s, &channelId, 0); /* channelId */
|
||||
}
|
||||
|
||||
void mcs_recv(rdpMcs* mcs)
|
||||
{
|
||||
STREAM* s;
|
||||
int length;
|
||||
uint8 result;
|
||||
uint8 choice;
|
||||
|
||||
s = stream_new(32);
|
||||
tls_read(mcs->transport->tls, s->data, s->size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate new MCS module.
|
||||
* @param transport transport
|
||||
|
@ -132,6 +132,8 @@ void mcs_recv_attach_user_confirm(rdpMcs* mcs);
|
||||
void mcs_send_channel_join_request(rdpMcs* mcs, uint16 channel_id);
|
||||
void mcs_recv_channel_join_confirm(rdpMcs* mcs);
|
||||
|
||||
void mcs_recv(rdpMcs* mcs);
|
||||
|
||||
rdpMcs* mcs_new(rdpTransport* transport);
|
||||
void mcs_free(rdpMcs* mcs);
|
||||
|
||||
|
@ -27,6 +27,23 @@
|
||||
|
||||
#include "nego.h"
|
||||
|
||||
char NEGO_STATE_STRINGS[6][25] =
|
||||
{
|
||||
"NEGO_STATE_INITIAL",
|
||||
"NEGO_STATE_NLA",
|
||||
"NEGO_STATE_TLS",
|
||||
"NEGO_STATE_RDP",
|
||||
"NEGO_STATE_FAIL",
|
||||
"NEGO_STATE_FINAL"
|
||||
};
|
||||
|
||||
char PROTOCOL_SECURITY_STRINGS[3][4] =
|
||||
{
|
||||
"RDP",
|
||||
"TLS",
|
||||
"NLA"
|
||||
};
|
||||
|
||||
/**
|
||||
* Negotiate protocol security and connect.
|
||||
* @param nego
|
||||
|
@ -37,16 +37,6 @@ enum _NEGO_STATE
|
||||
};
|
||||
typedef enum _NEGO_STATE NEGO_STATE;
|
||||
|
||||
char NEGO_STATE_STRINGS[6][25] =
|
||||
{
|
||||
"NEGO_STATE_INITIAL",
|
||||
"NEGO_STATE_NLA",
|
||||
"NEGO_STATE_TLS",
|
||||
"NEGO_STATE_RDP",
|
||||
"NEGO_STATE_FAIL",
|
||||
"NEGO_STATE_FINAL"
|
||||
};
|
||||
|
||||
/* RDP Negotiation Messages */
|
||||
enum RDP_NEG_MSG
|
||||
{
|
||||
@ -57,12 +47,8 @@ enum RDP_NEG_MSG
|
||||
TYPE_RDP_NEG_FAILURE = 0x3
|
||||
};
|
||||
|
||||
char PROTOCOL_SECURITY_STRINGS[3][4] =
|
||||
{
|
||||
"RDP",
|
||||
"TLS",
|
||||
"NLA"
|
||||
};
|
||||
extern char NEGO_STATE_STRINGS[6][25];
|
||||
extern char PROTOCOL_SECURITY_STRINGS[3][4];
|
||||
|
||||
struct rdp_nego
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user