From 0d936404a974ed40f2a64ecc39e62dd2f1b54132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Mon, 25 Jul 2011 13:52:48 -0400 Subject: [PATCH] libfreerdp-core: moved activation sequence to activation.c --- libfreerdp-core/CMakeLists.txt | 2 + libfreerdp-core/activation.c | 173 +++++++++++++++++++++++++++++++++ libfreerdp-core/activation.h | 52 ++++++++++ libfreerdp-core/connection.c | 152 ----------------------------- libfreerdp-core/connection.h | 24 +---- 5 files changed, 228 insertions(+), 175 deletions(-) create mode 100644 libfreerdp-core/activation.c create mode 100644 libfreerdp-core/activation.h diff --git a/libfreerdp-core/CMakeLists.txt b/libfreerdp-core/CMakeLists.txt index 5685c76dc..d41746509 100644 --- a/libfreerdp-core/CMakeLists.txt +++ b/libfreerdp-core/CMakeLists.txt @@ -20,6 +20,8 @@ add_definitions(-DEXT_PATH="/usr/lib/freerdp/extensions") set(LIBFREERDP_CORE_SRCS + activation.c + activation.h ber.c ber.h gcc.c diff --git a/libfreerdp-core/activation.c b/libfreerdp-core/activation.c new file mode 100644 index 000000000..319f0fe69 --- /dev/null +++ b/libfreerdp-core/activation.c @@ -0,0 +1,173 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Activation Sequence + * + * Copyright 2011 Marc-Andre Moreau + * + * 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 "activation.h" + +uint8 CTRLACTION_STRINGS[][32] = +{ + "", + "CTRLACTION_REQUEST_CONTROL", + "CTRLACTION_GRANTED_CONTROL", + "CTRLACTION_DETACH", + "CTRLACTION_COOPERATE" +}; + +boolean rdp_client_activate(rdpRdp* rdp) +{ + while (rdp->activated != True) + { + rdp_recv(rdp); + } + + printf("client is activated\n"); + + return True; +} + +void rdp_write_client_synchronize_pdu(STREAM* s, rdpSettings* settings) +{ + stream_write_uint16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */ + stream_write_uint16(s, settings->pdu_source); /* targetUser (2 bytes) */ +} + +void rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) +{ + rdp_send_client_control_pdu(rdp, CTRLACTION_COOPERATE); +} + +void rdp_send_client_synchronize_pdu(rdpRdp* rdp) +{ + STREAM* s; + + s = rdp_data_pdu_init(rdp); + + rdp_write_client_synchronize_pdu(s, rdp->settings); + + rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->user_id); +} + +void rdp_read_server_control_pdu(STREAM* s, uint16* action) +{ + stream_read_uint16(s, *action); /* action (2 bytes) */ + stream_seek_uint16(s); /* grantId (2 bytes) */ + stream_seek_uint32(s); /* controlId (4 bytes) */ +} + +void rdp_write_client_control_pdu(STREAM* s, uint16 action) +{ + stream_write_uint16(s, action); /* action (2 bytes) */ + stream_write_uint16(s, 0); /* grantId (2 bytes) */ + stream_write_uint32(s, 0); /* controlId (4 bytes) */ +} + +void rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) +{ + uint16 action; + + rdp_read_server_control_pdu(s, &action); + + if (action == CTRLACTION_COOPERATE) + { + rdp_send_client_control_pdu(rdp, CTRLACTION_REQUEST_CONTROL); + } + else if (action == CTRLACTION_GRANTED_CONTROL) + { + if (rdp->settings->rdp_version >= 5) + { + //rdp_send_client_persistent_key_list_pdu(rdp); + rdp_send_client_font_list_pdu(rdp, FONTLIST_FIRST | FONTLIST_LAST); + } + else + { + rdp_send_client_font_list_pdu(rdp, FONTLIST_FIRST); + rdp_send_client_font_list_pdu(rdp, FONTLIST_LAST); + } + } +} + +void rdp_send_client_control_pdu(rdpRdp* rdp, uint16 action) +{ + STREAM* s; + + s = rdp_data_pdu_init(rdp); + + rdp_write_client_control_pdu(s, action); + + rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->user_id); +} + +void rdp_write_persistent_list_entry(STREAM* s, uint32 key1, uint32 key2) +{ + stream_write_uint32(s, key1); /* key1 (4 bytes) */ + stream_write_uint32(s, key2); /* key2 (4 bytes) */ +} + +void rdp_write_client_persistent_key_list_pdu(STREAM* s, rdpSettings* settings) +{ + stream_write_uint16(s, 0); /* numEntriesCache0 (2 bytes) */ + stream_write_uint16(s, 0); /* numEntriesCache1 (2 bytes) */ + stream_write_uint16(s, 0); /* numEntriesCache2 (2 bytes) */ + stream_write_uint16(s, 0); /* numEntriesCache3 (2 bytes) */ + stream_write_uint16(s, 0); /* numEntriesCache4 (2 bytes) */ + stream_write_uint16(s, 0); /* totalEntriesCache0 (2 bytes) */ + stream_write_uint16(s, 0); /* totalEntriesCache1 (2 bytes) */ + stream_write_uint16(s, 0); /* totalEntriesCache2 (2 bytes) */ + stream_write_uint16(s, 0); /* totalEntriesCache3 (2 bytes) */ + stream_write_uint16(s, 0); /* totalEntriesCache4 (2 bytes) */ + stream_write_uint8(s, PERSIST_LAST_PDU); /* bBitMask (1 byte) */ + stream_write_uint8(s, 0); /* pad1 (1 byte) */ + stream_write_uint16(s, 0); /* pad3 (2 bytes) */ + + /* entries */ +} + +void rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp) +{ + STREAM* s; + + s = rdp_data_pdu_init(rdp); + + rdp_write_client_persistent_key_list_pdu(s, rdp->settings); + + rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->user_id); +} + +void rdp_write_client_font_list_pdu(STREAM* s, uint16 flags) +{ + stream_write_uint16(s, 0); /* numberFonts (2 bytes) */ + stream_write_uint16(s, 0); /* totalNumFonts (2 bytes) */ + stream_write_uint16(s, flags); /* listFlags (2 bytes) */ + stream_write_uint16(s, 50); /* entrySize (2 bytes) */ +} + +void rdp_send_client_font_list_pdu(rdpRdp* rdp, uint16 flags) +{ + STREAM* s; + + s = rdp_data_pdu_init(rdp); + + rdp_write_client_font_list_pdu(s, flags); + + rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->user_id); +} + +void rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) +{ + rdp->activated = True; +} diff --git a/libfreerdp-core/activation.h b/libfreerdp-core/activation.h new file mode 100644 index 000000000..4fc7fbf0b --- /dev/null +++ b/libfreerdp-core/activation.h @@ -0,0 +1,52 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Activation Sequence + * + * Copyright 2011 Marc-Andre Moreau + * + * 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 __ACTIVATION_H +#define __ACTIVATION_H + +#include "rdp.h" + +#include +#include + +#define SYNCMSGTYPE_SYNC 0x0001 + +#define CTRLACTION_REQUEST_CONTROL 0x0001 +#define CTRLACTION_GRANTED_CONTROL 0x0002 +#define CTRLACTION_DETACH 0x0003 +#define CTRLACTION_COOPERATE 0x0004 + +#define PERSIST_FIRST_PDU 0x01 +#define PERSIST_LAST_PDU 0x02 + +#define FONTLIST_FIRST 0x0001 +#define FONTLIST_LAST 0x0002 + +boolean rdp_client_activate(rdpRdp* rdp); + +void rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); +void rdp_send_client_synchronize_pdu(rdpRdp* rdp); +void rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); +void rdp_read_server_control_pdu(STREAM* s, uint16* action); +void rdp_send_client_control_pdu(rdpRdp* rdp, uint16 action); +void rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp); +void rdp_send_client_font_list_pdu(rdpRdp* rdp, uint16 flags); +void rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); + +#endif /* __ACTIVATION_H */ diff --git a/libfreerdp-core/connection.c b/libfreerdp-core/connection.c index 870c8818c..17c393069 100644 --- a/libfreerdp-core/connection.c +++ b/libfreerdp-core/connection.c @@ -49,15 +49,6 @@ * */ -uint8 CTRLACTION_STRINGS[][32] = -{ - "", - "CTRLACTION_REQUEST_CONTROL", - "CTRLACTION_GRANTED_CONTROL", - "CTRLACTION_DETACH", - "CTRLACTION_COOPERATE" -}; - /** * Establish RDP Connection.\n * @msdn{cc240452} @@ -112,146 +103,3 @@ boolean rdp_client_connect(rdpRdp* rdp) return True; } -boolean rdp_client_activate(rdpRdp* rdp) -{ - while (rdp->activated != True) - { - rdp_recv(rdp); - } - - printf("client is activated\n"); - - return True; -} - -void rdp_write_client_synchronize_pdu(STREAM* s, rdpSettings* settings) -{ - stream_write_uint16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */ - stream_write_uint16(s, settings->pdu_source); /* targetUser (2 bytes) */ -} - -void rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) -{ - rdp_send_client_control_pdu(rdp, CTRLACTION_COOPERATE); -} - -void rdp_send_client_synchronize_pdu(rdpRdp* rdp) -{ - STREAM* s; - - s = rdp_data_pdu_init(rdp); - - rdp_write_client_synchronize_pdu(s, rdp->settings); - - rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->user_id); -} - -void rdp_read_server_control_pdu(STREAM* s, uint16* action) -{ - stream_read_uint16(s, *action); /* action (2 bytes) */ - stream_seek_uint16(s); /* grantId (2 bytes) */ - stream_seek_uint32(s); /* controlId (4 bytes) */ -} - -void rdp_write_client_control_pdu(STREAM* s, uint16 action) -{ - stream_write_uint16(s, action); /* action (2 bytes) */ - stream_write_uint16(s, 0); /* grantId (2 bytes) */ - stream_write_uint32(s, 0); /* controlId (4 bytes) */ -} - -void rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) -{ - uint16 action; - - rdp_read_server_control_pdu(s, &action); - - if (action == CTRLACTION_COOPERATE) - { - rdp_send_client_control_pdu(rdp, CTRLACTION_REQUEST_CONTROL); - } - else if (action == CTRLACTION_GRANTED_CONTROL) - { - if (rdp->settings->rdp_version >= 5) - { - //rdp_send_client_persistent_key_list_pdu(rdp); - rdp_send_client_font_list_pdu(rdp, FONTLIST_FIRST | FONTLIST_LAST); - } - else - { - rdp_send_client_font_list_pdu(rdp, FONTLIST_FIRST); - rdp_send_client_font_list_pdu(rdp, FONTLIST_LAST); - } - } -} - -void rdp_send_client_control_pdu(rdpRdp* rdp, uint16 action) -{ - STREAM* s; - - s = rdp_data_pdu_init(rdp); - - rdp_write_client_control_pdu(s, action); - - rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->user_id); -} - -void rdp_write_persistent_list_entry(STREAM* s, uint32 key1, uint32 key2) -{ - stream_write_uint32(s, key1); /* key1 (4 bytes) */ - stream_write_uint32(s, key2); /* key2 (4 bytes) */ -} - -void rdp_write_client_persistent_key_list_pdu(STREAM* s, rdpSettings* settings) -{ - stream_write_uint16(s, 0); /* numEntriesCache0 (2 bytes) */ - stream_write_uint16(s, 0); /* numEntriesCache1 (2 bytes) */ - stream_write_uint16(s, 0); /* numEntriesCache2 (2 bytes) */ - stream_write_uint16(s, 0); /* numEntriesCache3 (2 bytes) */ - stream_write_uint16(s, 0); /* numEntriesCache4 (2 bytes) */ - stream_write_uint16(s, 0); /* totalEntriesCache0 (2 bytes) */ - stream_write_uint16(s, 0); /* totalEntriesCache1 (2 bytes) */ - stream_write_uint16(s, 0); /* totalEntriesCache2 (2 bytes) */ - stream_write_uint16(s, 0); /* totalEntriesCache3 (2 bytes) */ - stream_write_uint16(s, 0); /* totalEntriesCache4 (2 bytes) */ - stream_write_uint8(s, PERSIST_LAST_PDU); /* bBitMask (1 byte) */ - stream_write_uint8(s, 0); /* pad1 (1 byte) */ - stream_write_uint16(s, 0); /* pad3 (2 bytes) */ - - /* entries */ -} - -void rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp) -{ - STREAM* s; - - s = rdp_data_pdu_init(rdp); - - rdp_write_client_persistent_key_list_pdu(s, rdp->settings); - - rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->user_id); -} - -void rdp_write_client_font_list_pdu(STREAM* s, uint16 flags) -{ - stream_write_uint16(s, 0); /* numberFonts (2 bytes) */ - stream_write_uint16(s, 0); /* totalNumFonts (2 bytes) */ - stream_write_uint16(s, flags); /* listFlags (2 bytes) */ - stream_write_uint16(s, 50); /* entrySize (2 bytes) */ -} - -void rdp_send_client_font_list_pdu(rdpRdp* rdp, uint16 flags) -{ - STREAM* s; - - s = rdp_data_pdu_init(rdp); - - rdp_write_client_font_list_pdu(s, flags); - - rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->user_id); -} - -void rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings) -{ - rdp->activated = True; -} diff --git a/libfreerdp-core/connection.h b/libfreerdp-core/connection.h index 69f882518..6011bd0a3 100644 --- a/libfreerdp-core/connection.h +++ b/libfreerdp-core/connection.h @@ -26,33 +26,11 @@ #include "nego.h" #include "mcs.h" #include "transport.h" +#include "activation.h" #include #include -#define SYNCMSGTYPE_SYNC 0x0001 - -#define CTRLACTION_REQUEST_CONTROL 0x0001 -#define CTRLACTION_GRANTED_CONTROL 0x0002 -#define CTRLACTION_DETACH 0x0003 -#define CTRLACTION_COOPERATE 0x0004 - -#define PERSIST_FIRST_PDU 0x01 -#define PERSIST_LAST_PDU 0x02 - -#define FONTLIST_FIRST 0x0001 -#define FONTLIST_LAST 0x0002 - boolean rdp_client_connect(rdpRdp* rdp); -boolean rdp_client_activate(rdpRdp* rdp); - -void rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); -void rdp_send_client_synchronize_pdu(rdpRdp* rdp); -void rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); -void rdp_read_server_control_pdu(STREAM* s, uint16* action); -void rdp_send_client_control_pdu(rdpRdp* rdp, uint16 action); -void rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp); -void rdp_send_client_font_list_pdu(rdpRdp* rdp, uint16 flags); -void rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s, rdpSettings* settings); #endif /* __CONNECTION_H */