libfreerdp-core: start moving internal MCS variables out of rdpSettings*

This commit is contained in:
Marc-André Moreau 2014-02-15 16:32:38 -05:00
parent 4bbd78a80b
commit db7a9d2e77
10 changed files with 154 additions and 131 deletions

View File

@ -400,7 +400,7 @@ static void WTSProcessChannelData(rdpPeerChannel* channel, int channelId, BYTE*
}
}
static int WTSReceiveChannelData(freerdp_peer* client, int channelId, BYTE* data, int size, int flags, int total_size)
static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, BYTE* data, int size, int flags, int totalSize)
{
int i;
BOOL result = FALSE;
@ -418,7 +418,7 @@ static int WTSReceiveChannelData(freerdp_peer* client, int channelId, BYTE* data
if (channel != NULL)
{
WTSProcessChannelData(channel, channelId, data, size, flags, total_size);
WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
result = TRUE;
}
}

View File

@ -51,20 +51,21 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
wStream* s;
UINT32 flags;
int chunkSize;
rdpChannel* channel = NULL;
rdpMcs* mcs = rdp->mcs;
rdpMcsChannel* channel = NULL;
for (i = 0; i < rdp->settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
if (rdp->settings->ChannelDefArray[i].ChannelId == channelId)
if (mcs->channels[i].ChannelId == channelId)
{
channel = &rdp->settings->ChannelDefArray[i];
channel = &mcs->channels[i];
break;
}
}
if (!channel)
{
fprintf(stderr, "freerdp_channel_send: unknown channel_id %d\n", channelId);
fprintf(stderr, "freerdp_channel_send: unknown channelId %d\n", channelId);
return FALSE;
}
@ -118,16 +119,8 @@ BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channelId)
Stream_Read_UINT32(s, flags);
chunkLength = Stream_GetRemainingLength(s);
if (instance->ReceiveChannelData)
{
IFCALL(instance->ReceiveChannelData, instance,
channelId, Stream_Pointer(s), chunkLength, flags, length);
}
else
{
freerdp_channels_data(instance,
channelId, Stream_Pointer(s), chunkLength, flags, length);
}
IFCALL(instance->ReceiveChannelData, instance,
channelId, Stream_Pointer(s), chunkLength, flags, length);
return TRUE;
}

View File

@ -22,7 +22,7 @@
#include "client.h"
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size);
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size);
BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channel_id);
BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channel_id);

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include "rdp.h"
#include "client.h"
static void* g_pInterface;
@ -50,43 +52,18 @@ CHANNEL_OPEN_DATA* freerdp_channels_find_channel_open_data_by_name(rdpChannels*
return NULL;
}
/* returns rdpChannel for the channel id passed in */
rdpChannel* freerdp_channels_find_channel_by_id(rdpChannels* channels, rdpSettings* settings, int channel_id, int* pindex)
{
int index;
int count;
rdpChannel* channel;
count = settings->ChannelCount;
for (index = 0; index < count; index++)
{
channel = &settings->ChannelDefArray[index];
if (channel->ChannelId == channel_id)
{
if (pindex != 0)
*pindex = index;
return channel;
}
}
return NULL;
}
/* returns rdpChannel for the channel name passed in */
rdpChannel* freerdp_channels_find_channel_by_name(rdpChannels* channels,
rdpSettings* settings, const char* channelName)
rdpMcsChannel* freerdp_channels_find_channel_by_name(rdpRdp* rdp, const char* name)
{
int index;
rdpChannel* channel;
rdpMcsChannel* channel;
rdpMcs* mcs = rdp->mcs;
for (index = 0; index < settings->ChannelCount; index++)
for (index = 0; index < mcs->channelCount; index++)
{
channel = &settings->ChannelDefArray[index];
channel = &mcs->channels[index];
if (strcmp(channelName, channel->Name) == 0)
if (strcmp(name, channel->Name) == 0)
{
return channel;
}
@ -245,18 +222,29 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance)
int freerdp_channels_data(freerdp* instance, UINT16 channelId, BYTE* data, int dataSize, int flags, int totalSize)
{
int index;
rdpChannel* channel;
rdpMcs* mcs;
rdpChannels* channels;
rdpMcsChannel* channel = NULL;
CHANNEL_OPEN_DATA* pChannelOpenData;
mcs = instance->context->rdp->mcs;
channels = instance->context->channels;
if (!channels)
if (!channels || !mcs)
{
return 1;
}
channel = freerdp_channels_find_channel_by_id(channels, instance->settings, channelId, &index);
for (index = 0; index < mcs->channelCount; index++)
{
channel = &mcs->channels[index];
if (mcs->channels[index].ChannelId == channelId)
{
channel = &mcs->channels[index];
break;
}
}
if (!channel)
{
@ -337,10 +325,10 @@ FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, wMessage* eve
*/
static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instance)
{
int rc = TRUE;
int status = TRUE;
wMessage message;
wMessage* event;
rdpChannel* channel;
rdpMcsChannel* channel;
CHANNEL_OPEN_EVENT* item;
CHANNEL_OPEN_DATA* pChannelOpenData;
@ -348,7 +336,7 @@ static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instanc
{
if (message.id == WMQ_QUIT)
{
rc = FALSE;
status = FALSE;
break;
}
@ -361,8 +349,7 @@ static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instanc
pChannelOpenData = item->pChannelOpenData;
channel = freerdp_channels_find_channel_by_name(channels,
instance->settings, pChannelOpenData->name);
channel = freerdp_channels_find_channel_by_name(instance->context->rdp, pChannelOpenData->name);
if (channel)
instance->SendChannelData(instance, channel->ChannelId, item->Data, item->DataLength);
@ -386,7 +373,7 @@ static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instanc
}
}
return rc;
return status;
}
/**

View File

@ -23,6 +23,7 @@
#include "info.h"
#include "input.h"
#include "rdp.h"
#include "connection.h"
#include "transport.h"
@ -348,9 +349,9 @@ BOOL rdp_client_reconnect(rdpRdp* rdp)
transport_free(rdp->transport);
/* Reset virtual channel status */
for (i = 0; i < rdp->settings->ChannelCount; i++)
for (i = 0; i < rdp->mcs->channelCount; i++)
{
rdp->settings->ChannelDefArray[i].joined = FALSE;
rdp->mcs->channels[i].joined = FALSE;
}
rdp->transport = transport_new(rdp->settings);
@ -560,55 +561,56 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
UINT32 i;
UINT16 channelId;
BOOL allJoined = TRUE;
rdpMcs* mcs = rdp->mcs;
if (!mcs_recv_channel_join_confirm(rdp->mcs, s, &channelId))
if (!mcs_recv_channel_join_confirm(mcs, s, &channelId))
return FALSE;
if (!rdp->mcs->userChannelJoined)
if (!mcs->userChannelJoined)
{
if (channelId != rdp->mcs->userId)
if (channelId != mcs->userId)
return FALSE;
rdp->mcs->userChannelJoined = TRUE;
mcs->userChannelJoined = TRUE;
if (!mcs_send_channel_join_request(rdp->mcs, MCS_GLOBAL_CHANNEL_ID))
if (!mcs_send_channel_join_request(mcs, MCS_GLOBAL_CHANNEL_ID))
return FALSE;
}
else if (!rdp->mcs->globalChannelJoined)
else if (!mcs->globalChannelJoined)
{
if (channelId != MCS_GLOBAL_CHANNEL_ID)
return FALSE;
rdp->mcs->globalChannelJoined = TRUE;
mcs->globalChannelJoined = TRUE;
if (rdp->mcs->messageChannelId != 0)
if (mcs->messageChannelId != 0)
{
if (!mcs_send_channel_join_request(rdp->mcs, rdp->mcs->messageChannelId))
if (!mcs_send_channel_join_request(mcs, mcs->messageChannelId))
return FALSE;
allJoined = FALSE;
}
else
{
if (rdp->settings->ChannelCount > 0)
if (mcs->channelCount > 0)
{
if (!mcs_send_channel_join_request(rdp->mcs, rdp->settings->ChannelDefArray[0].ChannelId))
if (!mcs_send_channel_join_request(mcs, mcs->channels[0].ChannelId))
return FALSE;
allJoined = FALSE;
}
}
}
else if ((rdp->mcs->messageChannelId != 0) && !rdp->mcs->messageChannelJoined)
else if ((mcs->messageChannelId != 0) && !mcs->messageChannelJoined)
{
if (channelId != rdp->mcs->messageChannelId)
if (channelId != mcs->messageChannelId)
return FALSE;
rdp->mcs->messageChannelJoined = TRUE;
mcs->messageChannelJoined = TRUE;
if (rdp->settings->ChannelCount > 0)
if (mcs->channelCount > 0)
{
if (!mcs_send_channel_join_request(rdp->mcs, rdp->settings->ChannelDefArray[0].ChannelId))
if (!mcs_send_channel_join_request(mcs, mcs->channels[0].ChannelId))
return FALSE;
allJoined = FALSE;
@ -616,28 +618,29 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
}
else
{
for (i = 0; i < rdp->settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
if (rdp->settings->ChannelDefArray[i].joined)
if (mcs->channels[i].joined)
continue;
if (rdp->settings->ChannelDefArray[i].ChannelId != channelId)
if (mcs->channels[i].ChannelId != channelId)
return FALSE;
rdp->settings->ChannelDefArray[i].joined = TRUE;
mcs->channels[i].joined = TRUE;
break;
}
if (i + 1 < rdp->settings->ChannelCount)
if (i + 1 < mcs->channelCount)
{
if (!mcs_send_channel_join_request(rdp->mcs, rdp->settings->ChannelDefArray[i + 1].ChannelId))
if (!mcs_send_channel_join_request(mcs, mcs->channels[i + 1].ChannelId))
return FALSE;
allJoined = FALSE;
}
}
if (rdp->mcs->userChannelJoined && rdp->mcs->globalChannelJoined && allJoined)
if (mcs->userChannelJoined && mcs->globalChannelJoined && allJoined)
{
if (!rdp_client_establish_keys(rdp))
return FALSE;
@ -923,20 +926,21 @@ BOOL rdp_server_accept_nego(rdpRdp* rdp, wStream* s)
BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, wStream* s)
{
UINT32 i;
rdpMcs* mcs = rdp->mcs;
if (!mcs_recv_connect_initial(rdp->mcs, s))
if (!mcs_recv_connect_initial(mcs, s))
return FALSE;
fprintf(stderr, "Accepted client: %s\n", rdp->settings->ClientHostname);
fprintf(stderr, "Accepted channels:");
for (i = 0; i < rdp->settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
fprintf(stderr, " %s", rdp->settings->ChannelDefArray[i].Name);
fprintf(stderr, " %s", mcs->channels[i].Name);
}
fprintf(stderr, "\n");
if (!mcs_send_connect_response(rdp->mcs))
if (!mcs_send_connect_response(mcs))
return FALSE;
rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_CONNECT);
@ -972,28 +976,29 @@ BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, wStream* s)
UINT32 i;
UINT16 channelId;
BOOL allJoined = TRUE;
rdpMcs* mcs = rdp->mcs;
if (!mcs_recv_channel_join_request(rdp->mcs, s, &channelId))
if (!mcs_recv_channel_join_request(mcs, s, &channelId))
return FALSE;
if (!mcs_send_channel_join_confirm(rdp->mcs, channelId))
if (!mcs_send_channel_join_confirm(mcs, channelId))
return FALSE;
if (channelId == rdp->mcs->userId)
rdp->mcs->userChannelJoined = TRUE;
if (channelId == mcs->userId)
mcs->userChannelJoined = TRUE;
else if (channelId == MCS_GLOBAL_CHANNEL_ID)
rdp->mcs->globalChannelJoined = TRUE;
mcs->globalChannelJoined = TRUE;
for (i = 0; i < rdp->settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
if (rdp->settings->ChannelDefArray[i].ChannelId == channelId)
rdp->settings->ChannelDefArray[i].joined = TRUE;
if (mcs->channels[i].ChannelId == channelId)
mcs->channels[i].joined = TRUE;
if (!rdp->settings->ChannelDefArray[i].joined)
if (!mcs->channels[i].joined)
allJoined = FALSE;
}
if ((rdp->mcs->userChannelJoined) && (rdp->mcs->globalChannelJoined) && allJoined)
if ((mcs->userChannelJoined) && (mcs->globalChannelJoined) && allJoined)
{
rdp_server_transition_to_state(rdp, CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT);
}

View File

@ -1191,26 +1191,25 @@ void gcc_write_server_security_data(wStream* s, rdpMcs* mcs)
BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
{
UINT32 i;
rdpSettings* settings = mcs->settings;
if (blockLength < 4)
return FALSE;
Stream_Read_UINT32(s, settings->ChannelCount); /* channelCount */
Stream_Read_UINT32(s, mcs->channelCount); /* channelCount */
if (blockLength < 4 + settings->ChannelCount * 12)
if (blockLength < 4 + mcs->channelCount * 12)
return FALSE;
if (settings->ChannelCount > 16)
if (mcs->channelCount > 16)
return FALSE;
/* channelDefArray */
for (i = 0; i < settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
/* CHANNEL_DEF */
Stream_Read(s, settings->ChannelDefArray[i].Name, 8); /* name (8 bytes) */
Stream_Read_UINT32(s, settings->ChannelDefArray[i].options); /* options (4 bytes) */
settings->ChannelDefArray[i].ChannelId = MCS_GLOBAL_CHANNEL_ID + 1 + i;
Stream_Read(s, mcs->channels[i].Name, 8); /* name (8 bytes) */
Stream_Read_UINT32(s, mcs->channels[i].options); /* options (4 bytes) */
mcs->channels[i].ChannelId = MCS_GLOBAL_CHANNEL_ID + 1 + i;
}
return TRUE;
@ -1227,21 +1226,20 @@ void gcc_write_client_network_data(wStream* s, rdpMcs* mcs)
{
UINT32 i;
UINT16 length;
rdpSettings* settings = mcs->settings;
if (settings->ChannelCount > 0)
if (mcs->channelCount > 0)
{
length = settings->ChannelCount * 12 + 8;
length = mcs->channelCount * 12 + 8;
gcc_write_user_data_header(s, CS_NET, length);
Stream_Write_UINT32(s, settings->ChannelCount); /* channelCount */
Stream_Write_UINT32(s, mcs->channelCount); /* channelCount */
/* channelDefArray */
for (i = 0; i < settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
/* CHANNEL_DEF */
Stream_Write(s, settings->ChannelDefArray[i].Name, 8); /* name (8 bytes) */
Stream_Write_UINT32(s, settings->ChannelDefArray[i].options); /* options (4 bytes) */
Stream_Write(s, mcs->channels[i].Name, 8); /* name (8 bytes) */
Stream_Write_UINT32(s, mcs->channels[i].options); /* options (4 bytes) */
}
}
}
@ -1249,10 +1247,10 @@ void gcc_write_client_network_data(wStream* s, rdpMcs* mcs)
BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs)
{
int i;
UINT16 MCSChannelId;
UINT16 channelCount, channelsToTreat;
UINT16 channelId;
rdpSettings* settings = mcs->settings;
UINT16 MCSChannelId;
UINT16 channelCount;
UINT16 parsedChannelCount;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
@ -1260,25 +1258,26 @@ BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs)
Stream_Read_UINT16(s, MCSChannelId); /* MCSChannelId */
Stream_Read_UINT16(s, channelCount); /* channelCount */
channelsToTreat = channelCount;
parsedChannelCount = channelCount;
if (channelCount != settings->ChannelCount)
if (channelCount != mcs->channelCount)
{
fprintf(stderr, "requested %d channels, got %d instead\n",
settings->ChannelCount, channelCount);
mcs->channelCount, channelCount);
/* we ensure that the response is not bigger than the request */
if (channelCount > settings->ChannelCount)
channelsToTreat = settings->ChannelCount;
if (channelCount > mcs->channelCount)
parsedChannelCount = mcs->channelCount;
}
if (Stream_GetRemainingLength(s) < (size_t) channelCount * 2)
return FALSE;
for (i = 0; i < channelsToTreat; i++)
for (i = 0; i < parsedChannelCount; i++)
{
Stream_Read_UINT16(s, channelId); /* channelId */
settings->ChannelDefArray[i].ChannelId = channelId;
mcs->channels[i].ChannelId = channelId;
}
if (channelCount % 2 == 1)
@ -1290,19 +1289,18 @@ BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs)
void gcc_write_server_network_data(wStream* s, rdpMcs* mcs)
{
UINT32 i;
rdpSettings* settings = mcs->settings;
gcc_write_user_data_header(s, SC_NET, 8 + settings->ChannelCount * 2 + (settings->ChannelCount % 2 == 1 ? 2 : 0));
gcc_write_user_data_header(s, SC_NET, 8 + mcs->channelCount * 2 + (mcs->channelCount % 2 == 1 ? 2 : 0));
Stream_Write_UINT16(s, MCS_GLOBAL_CHANNEL_ID); /* MCSChannelId */
Stream_Write_UINT16(s, settings->ChannelCount); /* channelCount */
Stream_Write_UINT16(s, mcs->channelCount); /* channelCount */
for (i = 0; i < settings->ChannelCount; i++)
for (i = 0; i < mcs->channelCount; i++)
{
Stream_Write_UINT16(s, settings->ChannelDefArray[i].ChannelId);
Stream_Write_UINT16(s, mcs->channels[i].ChannelId);
}
if (settings->ChannelCount % 2 == 1)
if (mcs->channelCount % 2 == 1)
Stream_Write_UINT16(s, 0);
}

View File

@ -28,6 +28,7 @@
#include "mcs.h"
#include "tpdu.h"
#include "tpkt.h"
#include "client.h"
/**
* T.125 MCS is defined in:
@ -183,6 +184,25 @@ static const char* const mcs_result_enumerated[] =
};
*/
int mcs_initialize_client_channels(rdpMcs* mcs, rdpSettings* settings)
{
int index;
mcs->channelCount = settings->ChannelCount;
if (mcs->channelCount > mcs->channelMaxCount)
mcs->channelCount = mcs->channelMaxCount;
ZeroMemory(mcs->channels, sizeof(rdpMcsChannel) * mcs->channelMaxCount);
for (index = 0; index < mcs->channelCount; index++)
{
CopyMemory(mcs->channels[index].Name, settings->ChannelDefArray[index].Name, 8);
mcs->channels[index].options = settings->ChannelDefArray[index].options;
}
return 0;
}
/**
* Read a DomainMCSPDU header.
* @param s stream
@ -579,6 +599,8 @@ BOOL mcs_send_connect_initial(rdpMcs* mcs)
wStream* gcc_CCrq;
wStream* client_data;
mcs_initialize_client_channels(mcs, mcs->settings);
client_data = Stream_New(NULL, 512);
gcc_write_client_data_blocks(client_data, mcs);
@ -1047,6 +1069,10 @@ rdpMcs* mcs_new(rdpTransport* transport)
mcs_init_domain_parameters(&mcs->minimumParameters, 1, 1, 1, 0x420);
mcs_init_domain_parameters(&mcs->maximumParameters, 0xFFFF, 0xFC17, 0xFFFF, 0xFFFF);
mcs_init_domain_parameters(&mcs->domainParameters, 0, 0, 0, 0xFFFF);
mcs->channelCount = 0;
mcs->channelMaxCount = CHANNEL_MAX_COUNT;
mcs->channels = (rdpMcsChannel*) calloc(mcs->channelMaxCount, sizeof(rdpMcsChannel));
}
return mcs;

View File

@ -123,6 +123,16 @@ typedef struct
UINT32 protocolVersion;
} DomainParameters;
struct rdp_mcs_channel
{
char Name[8];
UINT32 options;
int ChannelId;
BOOL joined;
void* handle;
};
typedef struct rdp_mcs_channel rdpMcsChannel;
struct rdp_mcs
{
rdpTransport* transport;
@ -139,6 +149,10 @@ struct rdp_mcs
BOOL userChannelJoined;
BOOL globalChannelJoined;
BOOL messageChannelJoined;
UINT32 channelCount;
UINT32 channelMaxCount;
rdpMcsChannel* channels;
};
#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8

View File

@ -1161,7 +1161,7 @@ static int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
return status;
}
int rdp_send_channel_data(rdpRdp* rdp, int channelId, BYTE* data, int size)
int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
{
return freerdp_channel_send(rdp, channelId, data, size);
}

View File

@ -198,9 +198,9 @@ wStream* rdp_data_pdu_init(rdpRdp* rdp);
BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id);
int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id);
BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
int rdp_send_channel_data(rdpRdp* rdp, int channel_id, BYTE* data, int size);
int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size);
wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags);