remove uirdesktop

ulab-original
jsorg71 18 years ago
parent c569c09a5c
commit b1d5617ed4

@ -1,181 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Protocol services - Virtual channels
Copyright (C) Erik Forsberg <forsberg@cendio.se> 2003
Copyright (C) Matthew Chapman 2003-2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "rdesktop.h"
#define MAX_CHANNELS 6
#define CHANNEL_CHUNK_LENGTH 1600
#define CHANNEL_FLAG_FIRST 0x01
#define CHANNEL_FLAG_LAST 0x02
#define CHANNEL_FLAG_SHOW_PROTOCOL 0x10
extern BOOL g_use_rdp5;
extern BOOL g_encryption;
VCHANNEL g_channels[MAX_CHANNELS];
unsigned int g_num_channels;
/* FIXME: We should use the information in TAG_SRV_CHANNELS to map RDP5
channels to MCS channels.
The format of TAG_SRV_CHANNELS seems to be
global_channel_no (uint16le)
number_of_other_channels (uint16le)
..followed by uint16les for the other channels.
*/
VCHANNEL *
channel_register(char *name, uint32 flags, void (*callback) (STREAM))
{
VCHANNEL *channel;
if (!g_use_rdp5)
return NULL;
if (g_num_channels >= MAX_CHANNELS)
{
error("Channel table full, increase MAX_CHANNELS\n");
return NULL;
}
channel = &g_channels[g_num_channels];
channel->mcs_id = MCS_GLOBAL_CHANNEL + 1 + g_num_channels;
strncpy(channel->name, name, 8);
channel->flags = flags;
channel->process = callback;
g_num_channels++;
return channel;
}
STREAM
channel_init(VCHANNEL * channel, uint32 length)
{
STREAM s;
s = sec_init(g_encryption ? SEC_ENCRYPT : 0, length + 8);
s_push_layer(s, channel_hdr, 8);
return s;
}
void
channel_send(STREAM s, VCHANNEL * channel)
{
uint32 length, flags;
uint32 thislength, remaining;
uint8 *data;
/* first fragment sent in-place */
s_pop_layer(s, channel_hdr);
length = s->end - s->p - 8;
DEBUG_CHANNEL(("channel_send, length = %d\n", length));
thislength = MIN(length, CHANNEL_CHUNK_LENGTH);
/* Note: In the original clipboard implementation, this number was
1592, not 1600. However, I don't remember the reason and 1600 seems
to work so.. This applies only to *this* length, not the length of
continuation or ending packets. */
remaining = length - thislength;
flags = (remaining == 0) ? CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST : CHANNEL_FLAG_FIRST;
if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
out_uint32_le(s, length);
out_uint32_le(s, flags);
data = s->end = s->p + thislength;
DEBUG_CHANNEL(("Sending %d bytes with FLAG_FIRST\n", thislength));
sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
/* subsequent segments copied (otherwise would have to generate headers backwards) */
while (remaining > 0)
{
thislength = MIN(remaining, CHANNEL_CHUNK_LENGTH);
remaining -= thislength;
flags = (remaining == 0) ? CHANNEL_FLAG_LAST : 0;
if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
DEBUG_CHANNEL(("Sending %d bytes with flags %d\n", thislength, flags));
s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8);
out_uint32_le(s, length);
out_uint32_le(s, flags);
out_uint8p(s, data, thislength);
s_mark_end(s);
sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
data += thislength;
}
}
void
channel_process(STREAM s, uint16 mcs_channel)
{
uint32 length, flags;
uint32 thislength;
VCHANNEL *channel = NULL;
unsigned int i;
STREAM in;
for (i = 0; i < g_num_channels; i++)
{
channel = &g_channels[i];
if (channel->mcs_id == mcs_channel)
break;
}
if (i >= g_num_channels)
return;
in_uint32_le(s, length);
in_uint32_le(s, flags);
if ((flags & CHANNEL_FLAG_FIRST) && (flags & CHANNEL_FLAG_LAST))
{
/* single fragment - pass straight up */
channel->process(s);
}
else
{
/* add fragment to defragmentation buffer */
in = &channel->in;
if (flags & CHANNEL_FLAG_FIRST)
{
if (length > in->size)
{
in->data = (uint8 *) xrealloc(in->data, length);
in->size = length;
}
in->p = in->data;
}
thislength = MIN(s->end - s->p, in->data + in->size - in->p);
memcpy(in->p, s->p, thislength);
in->p += thislength;
if (flags & CHANNEL_FLAG_LAST)
{
in->end = in->p;
in->p = in->data;
channel->process(in);
}
}
}

@ -1,436 +0,0 @@
/*
rdesktop: A Remote Desktop Protocol client.
Miscellaneous protocol constants
Copyright (C) Matthew Chapman 1999-2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* TCP port for Remote Desktop Protocol */
#define TCP_PORT_RDP 3389
#define DEFAULT_CODEPAGE "UTF-8"
#define WINDOWS_CODEPAGE "UTF-16LE"
/* ISO PDU codes */
enum ISO_PDU_CODE
{
ISO_PDU_CR = 0xE0, /* Connection Request */
ISO_PDU_CC = 0xD0, /* Connection Confirm */
ISO_PDU_DR = 0x80, /* Disconnect Request */
ISO_PDU_DT = 0xF0, /* Data */
ISO_PDU_ER = 0x70 /* Error */
};
/* MCS PDU codes */
enum MCS_PDU_TYPE
{
MCS_EDRQ = 1, /* Erect Domain Request */
MCS_DPUM = 8, /* Disconnect Provider Ultimatum */
MCS_AURQ = 10, /* Attach User Request */
MCS_AUCF = 11, /* Attach User Confirm */
MCS_CJRQ = 14, /* Channel Join Request */
MCS_CJCF = 15, /* Channel Join Confirm */
MCS_SDRQ = 25, /* Send Data Request */
MCS_SDIN = 26 /* Send Data Indication */
};
#define MCS_CONNECT_INITIAL 0x7f65
#define MCS_CONNECT_RESPONSE 0x7f66
#define BER_TAG_BOOLEAN 1
#define BER_TAG_INTEGER 2
#define BER_TAG_OCTET_STRING 4
#define BER_TAG_RESULT 10
#define MCS_TAG_DOMAIN_PARAMS 0x30
#define MCS_GLOBAL_CHANNEL 1003
#define MCS_USERCHANNEL_BASE 1001
/* RDP secure transport constants */
#define SEC_RANDOM_SIZE 32
#define SEC_MODULUS_SIZE 64
#define SEC_MAX_MODULUS_SIZE 256
#define SEC_PADDING_SIZE 8
#define SEC_EXPONENT_SIZE 4
#define SEC_CLIENT_RANDOM 0x0001
#define SEC_ENCRYPT 0x0008
#define SEC_LOGON_INFO 0x0040
#define SEC_LICENCE_NEG 0x0080
#define SEC_REDIRECT_ENCRYPT 0x0C00
#define SEC_TAG_SRV_INFO 0x0c01
#define SEC_TAG_SRV_CRYPT 0x0c02
#define SEC_TAG_SRV_CHANNELS 0x0c03
#define SEC_TAG_CLI_INFO 0xc001
#define SEC_TAG_CLI_CRYPT 0xc002
#define SEC_TAG_CLI_CHANNELS 0xc003
#define SEC_TAG_CLI_4 0xc004
#define SEC_TAG_PUBKEY 0x0006
#define SEC_TAG_KEYSIG 0x0008
#define SEC_RSA_MAGIC 0x31415352 /* RSA1 */
/* RDP licensing constants */
#define LICENCE_TOKEN_SIZE 10
#define LICENCE_HWID_SIZE 20
#define LICENCE_SIGNATURE_SIZE 16
#define LICENCE_TAG_DEMAND 0x01
#define LICENCE_TAG_AUTHREQ 0x02
#define LICENCE_TAG_ISSUE 0x03
#define LICENCE_TAG_REISSUE 0x04
#define LICENCE_TAG_PRESENT 0x12
#define LICENCE_TAG_REQUEST 0x13
#define LICENCE_TAG_AUTHRESP 0x15
#define LICENCE_TAG_RESULT 0xff
#define LICENCE_TAG_USER 0x000f
#define LICENCE_TAG_HOST 0x0010
/* RDP PDU codes */
enum RDP_PDU_TYPE
{
RDP_PDU_DEMAND_ACTIVE = 1,
RDP_PDU_CONFIRM_ACTIVE = 3,
RDP_PDU_REDIRECT = 4, /* MS Server 2003 Session Redirect */
RDP_PDU_DEACTIVATE = 6,
RDP_PDU_DATA = 7
};
enum RDP_DATA_PDU_TYPE
{
RDP_DATA_PDU_UPDATE = 2,
RDP_DATA_PDU_CONTROL = 20,
RDP_DATA_PDU_POINTER = 27,
RDP_DATA_PDU_INPUT = 28,
RDP_DATA_PDU_SYNCHRONISE = 31,
RDP_DATA_PDU_BELL = 34,
RDP_DATA_PDU_CLIENT_WINDOW_STATUS = 35,
RDP_DATA_PDU_LOGON = 38,
RDP_DATA_PDU_FONT2 = 39,
RDP_DATA_PDU_KEYBOARD_INDICATORS = 41,
RDP_DATA_PDU_DISCONNECT = 47
};
enum RDP_CONTROL_PDU_TYPE
{
RDP_CTL_REQUEST_CONTROL = 1,
RDP_CTL_GRANT_CONTROL = 2,
RDP_CTL_DETACH = 3,
RDP_CTL_COOPERATE = 4
};
enum RDP_UPDATE_PDU_TYPE
{
RDP_UPDATE_ORDERS = 0,
RDP_UPDATE_BITMAP = 1,
RDP_UPDATE_PALETTE = 2,
RDP_UPDATE_SYNCHRONIZE = 3
};
enum RDP_POINTER_PDU_TYPE
{
RDP_POINTER_SYSTEM = 1,
RDP_POINTER_MOVE = 3,
RDP_POINTER_COLOR = 6,
RDP_POINTER_CACHED = 7
};
enum RDP_SYSTEM_POINTER_TYPE
{
RDP_NULL_POINTER = 0,
RDP_DEFAULT_POINTER = 0x7F00
};
enum RDP_INPUT_DEVICE
{
RDP_INPUT_SYNCHRONIZE = 0,
RDP_INPUT_CODEPOINT = 1,
RDP_INPUT_VIRTKEY = 2,
RDP_INPUT_SCANCODE = 4,
RDP_INPUT_MOUSE = 0x8001
};
/* Device flags */
#define KBD_FLAG_RIGHT 0x0001
#define KBD_FLAG_EXT 0x0100
#define KBD_FLAG_QUIET 0x1000
#define KBD_FLAG_DOWN 0x4000
#define KBD_FLAG_UP 0x8000
/* These are for synchronization; not for keystrokes */
#define KBD_FLAG_SCROLL 0x0001
#define KBD_FLAG_NUMLOCK 0x0002
#define KBD_FLAG_CAPITAL 0x0004
/* See T.128 */
#define RDP_KEYPRESS 0
#define RDP_KEYRELEASE (KBD_FLAG_DOWN | KBD_FLAG_UP)
#define MOUSE_FLAG_MOVE 0x0800
#define MOUSE_FLAG_BUTTON1 0x1000
#define MOUSE_FLAG_BUTTON2 0x2000
#define MOUSE_FLAG_BUTTON3 0x4000
#define MOUSE_FLAG_BUTTON4 0x0280
#define MOUSE_FLAG_BUTTON5 0x0380
#define MOUSE_FLAG_DOWN 0x8000
/* Raster operation masks */
#define ROP2_S(rop3) ((uint8) (rop3 & 0xf))
#define ROP2_P(rop3) ((uint8) ((rop3 & 0x3) | ((rop3 & 0x30) >> 2)))
#define ROP_MINUS_1(rop) ((uint8) (rop - 1))
#define ROP2_COPY 0xc
#define ROP2_XOR 0x6
#define ROP2_AND 0x8
#define ROP2_NXOR 0x9
#define ROP2_OR 0xe
#define MIX_TRANSPARENT 0
#define MIX_OPAQUE 1
#define TEXT2_VERTICAL 0x04
#define TEXT2_IMPLICIT_X 0x20
#define ALTERNATE 1
#define WINDING 2
/* RDP bitmap cache (version 2) constants */
#define BMPCACHE2_C0_CELLS 0x78
#define BMPCACHE2_C1_CELLS 0x78
#define BMPCACHE2_C2_CELLS 0x150
#define BMPCACHE2_NUM_PSTCELLS 0x9f6
#define PDU_FLAG_FIRST 0x01
#define PDU_FLAG_LAST 0x02
/* RDP capabilities */
#define RDP_CAPSET_GENERAL 1 /* Maps to generalCapabilitySet in T.128 page 138 */
#define RDP_CAPLEN_GENERAL 0x18
#define OS_MAJOR_TYPE_UNIX 4
#define OS_MINOR_TYPE_XSERVER 7
#define RDP_CAPSET_BITMAP 2
#define RDP_CAPLEN_BITMAP 0x1C
#define RDP_CAPSET_ORDER 3
#define RDP_CAPLEN_ORDER 0x58
#define ORDER_CAP_NEGOTIATE 2
#define ORDER_CAP_NOSUPPORT 4
#define RDP_CAPSET_BMPCACHE 4
#define RDP_CAPLEN_BMPCACHE 0x28
#define RDP_CAPSET_CONTROL 5
#define RDP_CAPLEN_CONTROL 0x0C
#define RDP_CAPSET_ACTIVATE 7
#define RDP_CAPLEN_ACTIVATE 0x0C
#define RDP_CAPSET_POINTER 8
#define RDP_CAPLEN_POINTER 0x08
#define RDP_CAPSET_SHARE 9
#define RDP_CAPLEN_SHARE 0x08
#define RDP_CAPSET_COLCACHE 10
#define RDP_CAPLEN_COLCACHE 0x08
#define RDP_CAPSET_BMPCACHE2 19
#define RDP_CAPLEN_BMPCACHE2 0x28
#define BMPCACHE2_FLAG_PERSIST ((uint32)1<<31)
#define RDP_SOURCE "MSTSC"
/* Logon flags */
#define RDP_LOGON_AUTO 0x0008
#define RDP_LOGON_NORMAL 0x0033
#define RDP_LOGON_COMPRESSION 0x0080 /* mppc compression with 8kB histroy buffer */
#define RDP_LOGON_BLOB 0x0100
#define RDP_LOGON_COMPRESSION2 0x0200 /* rdp5 mppc compression with 64kB history buffer */
#define RDP_LOGON_LEAVE_AUDIO 0x2000
#define RDP5_DISABLE_NOTHING 0x00
#define RDP5_NO_WALLPAPER 0x01
#define RDP5_NO_FULLWINDOWDRAG 0x02
#define RDP5_NO_MENUANIMATIONS 0x04
#define RDP5_NO_THEMING 0x08
#define RDP5_NO_CURSOR_SHADOW 0x20
#define RDP5_NO_CURSORSETTINGS 0x40 /* disables cursor blinking */
/* compression types */
#define RDP_MPPC_BIG 0x01
#define RDP_MPPC_COMPRESSED 0x20
#define RDP_MPPC_RESET 0x40
#define RDP_MPPC_FLUSH 0x80
#define RDP_MPPC_DICT_SIZE 65536
#define RDP5_COMPRESSED 0x80
/* Keymap flags */
#define MapRightShiftMask (1<<0)
#define MapLeftShiftMask (1<<1)
#define MapShiftMask (MapRightShiftMask | MapLeftShiftMask)
#define MapRightAltMask (1<<2)
#define MapLeftAltMask (1<<3)
#define MapAltGrMask MapRightAltMask
#define MapRightCtrlMask (1<<4)
#define MapLeftCtrlMask (1<<5)
#define MapCtrlMask (MapRightCtrlMask | MapLeftCtrlMask)
#define MapRightWinMask (1<<6)
#define MapLeftWinMask (1<<7)
#define MapWinMask (MapRightWinMask | MapLeftWinMask)
#define MapNumLockMask (1<<8)
#define MapCapsLockMask (1<<9)
#define MapLocalStateMask (1<<10)
#define MapInhibitMask (1<<11)
#define MASK_ADD_BITS(var, mask) (var |= mask)
#define MASK_REMOVE_BITS(var, mask) (var &= ~mask)
#define MASK_HAS_BITS(var, mask) ((var & mask)>0)
#define MASK_CHANGE_BIT(var, mask, active) (var = ((var & ~mask) | (active ? mask : 0)))
/* Clipboard constants, "borrowed" from GCC system headers in
the w32 cross compiler */
#ifndef CF_TEXT
#define CF_TEXT 1
#define CF_BITMAP 2
#define CF_METAFILEPICT 3
#define CF_SYLK 4
#define CF_DIF 5
#define CF_TIFF 6
#define CF_OEMTEXT 7
#define CF_DIB 8
#define CF_PALETTE 9
#define CF_PENDATA 10
#define CF_RIFF 11
#define CF_WAVE 12
#define CF_UNICODETEXT 13
#define CF_ENHMETAFILE 14
#define CF_HDROP 15
#define CF_LOCALE 16
#define CF_MAX 17
#define CF_OWNERDISPLAY 128
#define CF_DSPTEXT 129
#define CF_DSPBITMAP 130
#define CF_DSPMETAFILEPICT 131
#define CF_DSPENHMETAFILE 142
#define CF_PRIVATEFIRST 512
#define CF_PRIVATELAST 767
#define CF_GDIOBJFIRST 768
#define CF_GDIOBJLAST 1023
#endif
/* Sound format constants */
#define WAVE_FORMAT_PCM 1
#define WAVE_FORMAT_ADPCM 2
#define WAVE_FORMAT_ALAW 6
#define WAVE_FORMAT_MULAW 7
/* Virtual channel options */
#define CHANNEL_OPTION_INITIALIZED 0x80000000
#define CHANNEL_OPTION_ENCRYPT_RDP 0x40000000
#define CHANNEL_OPTION_COMPRESS_RDP 0x00800000
#define CHANNEL_OPTION_SHOW_PROTOCOL 0x00200000
/* NT status codes for RDPDR */
#undef STATUS_SUCCESS
#define STATUS_SUCCESS 0x00000000
#undef STATUS_NOT_IMPLEMENTED
#define STATUS_NOT_IMPLEMENTED 0x00000001
#undef STATUS_PENDING
#define STATUS_PENDING 0x00000103
#ifndef STATUS_NO_MORE_FILES
#define STATUS_NO_MORE_FILES 0x80000006
#define STATUS_DEVICE_PAPER_EMPTY 0x8000000e
#define STATUS_DEVICE_POWERED_OFF 0x8000000f
#define STATUS_DEVICE_OFF_LINE 0x80000010
#define STATUS_DEVICE_BUSY 0x80000011
#endif
#ifndef STATUS_INVALID_HANDLE
#define STATUS_INVALID_HANDLE 0xc0000008
#define STATUS_INVALID_PARAMETER 0xc000000d
#define STATUS_NO_SUCH_FILE 0xc000000f
#define STATUS_INVALID_DEVICE_REQUEST 0xc0000010
#define STATUS_ACCESS_DENIED 0xc0000022
#define STATUS_OBJECT_NAME_COLLISION 0xc0000035
#define STATUS_DISK_FULL 0xc000007f
#define STATUS_FILE_IS_A_DIRECTORY 0xc00000ba
#define STATUS_NOT_SUPPORTED 0xc00000bb
#define STATUS_TIMEOUT 0xc0000102
#define STATUS_NOTIFY_ENUM_DIR 0xc000010c
#define STATUS_CANCELLED 0xc0000120
#endif
/* RDPDR constants */
#define RDPDR_MAX_DEVICES 0x10
#define DEVICE_TYPE_SERIAL 0x01
#define DEVICE_TYPE_PARALLEL 0x02
#define DEVICE_TYPE_PRINTER 0x04
#define DEVICE_TYPE_DISK 0x08
#define DEVICE_TYPE_SCARD 0x20
#define FILE_DIRECTORY_FILE 0x00000001
#define FILE_NON_DIRECTORY_FILE 0x00000040
#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
#define FILE_DELETE_ON_CLOSE 0x00001000
#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
/* RDP5 disconnect PDU */
#define exDiscReasonNoInfo 0x0000
#define exDiscReasonAPIInitiatedDisconnect 0x0001
#define exDiscReasonAPIInitiatedLogoff 0x0002
#define exDiscReasonServerIdleTimeout 0x0003
#define exDiscReasonServerLogonTimeout 0x0004
#define exDiscReasonReplacedByOtherConnection 0x0005
#define exDiscReasonOutOfMemory 0x0006
#define exDiscReasonServerDeniedConnection 0x0007
#define exDiscReasonServerDeniedConnectionFips 0x0008
#define exDiscReasonLicenseInternal 0x0100
#define exDiscReasonLicenseNoLicenseServer 0x0101
#define exDiscReasonLicenseNoLicense 0x0102
#define exDiscReasonLicenseErrClientMsg 0x0103
#define exDiscReasonLicenseHwidDoesntMatchLicense 0x0104
#define exDiscReasonLicenseErrClientLicense 0x0105
#define exDiscReasonLicenseCantFinishProtocol 0x0106
#define exDiscReasonLicenseClientEndedProtocol 0x0107
#define exDiscReasonLicenseErrClientEncryption 0x0108
#define exDiscReasonLicenseCantUpgradeLicense 0x0109
#define exDiscReasonLicenseNoRemoteConnections 0x010a
/* SeamlessRDP constants */
#define SEAMLESSRDP_NOTYETMAPPED -1
#define SEAMLESSRDP_NORMAL 0
#define SEAMLESSRDP_MINIMIZED 1
#define SEAMLESSRDP_MAXIMIZED 2
#define SEAMLESSRDP_POSITION_TIMER 200000
#define SEAMLESSRDP_CREATE_MODAL 0x0001
#define SEAMLESSRDP_HELLO_RECONNECT 0x0001
#define SEAMLESSRDP_HELLO_HIDDEN 0x0002

@ -1,894 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
directfb calls
Copyright (C) Jay Sorg 2006
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//#define USE_FLIPPING
#define USE_ORDERS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <directfb.h>
#include <pthread.h>
#include "uimain.h"
#include "bsops.h"
extern char g_username[];
extern char g_hostname[];
extern char g_servername[];
extern char g_password[];
extern char g_shell[];
extern char g_directory[];
extern char g_domain[];
extern int g_width;
extern int g_height;
extern int g_tcp_sck;
extern int g_server_depth;
extern int g_tcp_port_rdp; /* in tcp.c */
extern int g_bytes_in;
extern int pal_entries[];
extern char * g_bs;
static DFBRegion g_reg;
static pthread_mutex_t g_mutex1 = PTHREAD_MUTEX_INITIALIZER;
/* direct frame buffer stuff */
static IDirectFB * g_dfb = 0;
static IDirectFBSurface * g_primary = 0;
static IDirectFBEventBuffer * g_event = 0;
static DFBRectangle g_rect = {0, 0, 0, 0};
struct cursor
{
unsigned char andmask[32 * 32];
unsigned char xormask[32 * 32];
int x;
int y;
int w;
int h;
};
static struct cursor g_mcursor; /* current mouse */
static int g_mouse_x = 0;
static int g_mouse_y = 0;
static IDirectFBSurface * g_s = 0;
static int g_wfpx = 0; /* wait for pixel stuff */
static int g_wfpy = 0;
static int g_wfpv = 0;
static int g_show_wfp = 0;
static int g_no_draw = 0; /* this means don't draw the screen but draw on
backingstore */
/* for transparent colour */
static int g_use_trans = 0;
static int g_trans_colour = 0;
//static IDirectFBDataBuffer * g_buffer = 0;
//static IDirectFBImageProvider * g_provider = 0;
void (* master_callback)(int msg, int param1, int param2) = 0;
/*****************************************************************************/
void
mi_error(char * msg)
{
printf(msg);
}
/*****************************************************************************/
void
mi_warning(char * msg)
{
printf(msg);
}
/*****************************************************************************/
int
mi_read_keyboard_state(void)
{
return 0;
}
/*****************************************************************************/
/* returns non zero if ok */
int
mi_create_window(void)
{
if (!g_no_draw)
{
g_primary->SetColor(g_primary, 0, 0, 0, 0xff);
g_primary->FillRectangle(g_primary, 0, 0, g_width, g_height);
}
return 1;
}
/*****************************************************************************/
void
mi_update_screen(void)
{
int r;
int g;
int b;
if (g_no_draw)
{
return;
}
if (g_rect.w > 0 && g_rect.h > 0)
{
#ifdef USE_ORDERS_NOT
DFBRegion reg;
reg.x1 = 0;
reg.y1 = 0;
reg.x2 = g_width;
reg.y2 = g_height;
g_primary->SetClip(g_primary, &reg);
#endif
#ifdef USE_FLIPPING
g_primary->Blit(g_primary, g_primary, 0, 0, 0);
g_primary->Blit(g_primary, g_s, &g_rect, g_rect.x, g_rect.y);
g_primary->Flip(g_primary, 0, 0);
#else
g_primary->Blit(g_primary, g_s, &g_rect, g_rect.x, g_rect.y);
if (g_use_trans)
{
r = (g_trans_colour >> 16) & 0xff;
g = (g_trans_colour >> 8) & 0xff;
b = g_trans_colour & 0xff;
g_primary->SetDrawingFlags(g_primary, DSDRAW_DST_COLORKEY);
g_primary->SetDstColorKey(g_primary, r, g, b);
g_primary->SetColor(g_primary, r, g, b, 0);
g_primary->FillRectangle(g_primary, g_rect.x, g_rect.y, g_rect.w, g_rect.h);
g_primary->SetDrawingFlags(g_primary, DSDRAW_NOFX);
}
#endif
#ifdef USE_ORDERS_NOT
g_primary->SetClip(g_primary, &g_reg);
#endif
}
g_rect.x = 0;
g_rect.y = 0;
g_rect.w = 0;
g_rect.h = 0;
}
/*****************************************************************************/
void process_event(DFBEvent * event)
{
DFBInputEvent * input_event;
int mouse_x;
int mouse_y;
mouse_x = g_mouse_x + g_mcursor.x;
mouse_y = g_mouse_y + g_mcursor.y;
if (event->clazz == DFEC_INPUT)
{
input_event = (DFBInputEvent *) event;
if (input_event->type == DIET_AXISMOTION)
{
if (input_event->flags & DIEF_AXISABS)
{
if (input_event->axis == DIAI_X)
{
mouse_x = input_event->axisabs;
}
else if (input_event->axis == DIAI_Y)
{
mouse_y = input_event->axisabs;
}
}
if (input_event->flags & DIEF_AXISREL)
{
if (input_event->axis == DIAI_X)
{
mouse_x += input_event->axisrel;
}
else if (input_event->axis == DIAI_Y)
{
mouse_y += input_event->axisrel;
}
}
mouse_x = UI_MAX(mouse_x, 0);
mouse_x = UI_MIN(mouse_x, g_width - 1);
mouse_y = UI_MAX(mouse_y, 0);
mouse_y = UI_MIN(mouse_y, g_height - 1);
ui_mouse_move(mouse_x, mouse_y);
}
else if (input_event->type == DIET_BUTTONPRESS)
{
if (input_event->button == DIBI_LEFT)
{
ui_mouse_button(1, mouse_x, mouse_y, 1);
//rdp_send_input(0, RDP_INPUT_MOUSE,
// MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
// mouse_x, mouse_y);
}
else if (input_event->button == DIBI_RIGHT)
{
//mi_update_screen();
ui_mouse_button(2, mouse_x, mouse_y, 1);
// invalidate(0, 0, g_width, g_height);
//rdp_send_input(0, RDP_INPUT_MOUSE,
// MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
// mouse_x, mouse_y);
}
else if (input_event->button == DIBI_MIDDLE)
{
ui_mouse_button(3, mouse_x, mouse_y, 1);
}
}
else if (input_event->type == DIET_BUTTONRELEASE)
{
if (input_event->button == DIBI_LEFT)
{
ui_mouse_button(1, mouse_x, mouse_y, 0);
//rdp_send_input(0, RDP_INPUT_MOUSE,
// MOUSE_FLAG_BUTTON1,
// mouse_x, mouse_y);
}
else if (input_event->button == DIBI_RIGHT)
{
ui_mouse_button(2, mouse_x, mouse_y, 0);
//rdp_send_input(0, RDP_INPUT_MOUSE,
// MOUSE_FLAG_BUTTON2,
// mouse_x, mouse_y);
}
else if (input_event->button == DIBI_MIDDLE)
{
ui_mouse_button(3, mouse_x, mouse_y, 0);
}
}
else if (input_event->type == DIET_KEYPRESS)
{
//printf("hi1 %d\n", input_event->key_id);
return;
}
else if (input_event->type == DIET_KEYRELEASE)
{
//printf("hi2 %d\n", input_event->key_id);
return;
}
}
g_mouse_x = mouse_x - g_mcursor.x;
g_mouse_y = mouse_y - g_mcursor.y;
// printf("%d %d\n", g_mouse_x, g_mouse_y);
g_primary->SetColor(g_primary, 0, 0, 0, 0xff);
g_primary->FillRectangle(g_primary, g_mouse_x, g_mouse_y, 5, 5);
// draw_mouse();
}
/*****************************************************************************/
int
mi_main_loop(void)
{
fd_set rfds;
int rv;
int fd;
DFBEvent event[10];
struct timeval tv;
fd = g_tcp_sck;
FD_ZERO(&rfds);
FD_SET(g_tcp_sck, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 0;
rv = select(fd + 1, &rfds, 0, 0, &tv);
while (rv > -1)
{
if (g_event->HasEvent(g_event) == DFB_OK)
{
if (g_event->GetEvent(g_event, &event[0]) == 0)
{
process_event(&event[0]);
}
}
if (rv > 0)
{
if (FD_ISSET(g_tcp_sck, &rfds))
{
if (!ui_read_wire())
{
return 0;
}
}
}
else
{
//usleep(1000000 / 60);
usleep(0);
}
FD_ZERO(&rfds);
FD_SET(g_tcp_sck, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 0;
rv = select(fd + 1, &rfds, 0, 0, &tv);
}
return 0;
}
/*****************************************************************************/
void
mi_add_to(int x, int y, int cx, int cy)
{
int right;
int bottom;
if (g_rect.h == 0 && g_rect.w == 0)
{
g_rect.x = x;
g_rect.y = y;
g_rect.w = cx;
g_rect.h = cy;
}
else
{
right = g_rect.x + g_rect.w;
bottom = g_rect.y + g_rect.h;
if (x + cx > right)
{
right = x + cx;
}
if (y + cy > bottom)
{
bottom = y + cy;
}
if (x < g_rect.x)
{
g_rect.x = x;
}
if (y < g_rect.y)
{
g_rect.y = y;
}
g_rect.w = right - g_rect.x;
g_rect.h = bottom - g_rect.y;
}
}
/*****************************************************************************/
void
mi_invalidate(int x, int y, int cx, int cy)
{
mi_add_to(x, y, cx, cy);
mi_update_screen();
}
/*****************************************************************************/
void *
update_thread(void * arg)
{
struct timeval ltime;
struct timeval ntime;
int nsecs;
gettimeofday(&ltime, 0);
while (g_bs != 0)
{
gettimeofday(&ntime, 0);
nsecs = (ntime.tv_sec - ltime.tv_sec) * 1000000 + (ntime.tv_usec - ltime.tv_usec);
nsecs = (1000000 / 12) - nsecs;
if (nsecs < 0)
{
nsecs = 0;
}
usleep(nsecs);
gettimeofday(&ltime, 0);
pthread_mutex_lock(&g_mutex1);
mi_update_screen();
pthread_mutex_unlock(&g_mutex1);
}
return 0;
}
/*****************************************************************************/
/* return boolean */
int
mi_create_bs(void)
{
//pthread_t thread;
DFBSurfaceDescription dsc;
g_bs = malloc(g_width * g_height * 4);
dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT |
DSDESC_PREALLOCATED | DSDESC_PIXELFORMAT;
dsc.caps = DSCAPS_SYSTEMONLY;
dsc.width = g_width;
dsc.height = g_height;
dsc.pixelformat = DSPF_AiRGB;
dsc.preallocated[0].data = g_bs;
dsc.preallocated[0].pitch = g_width * 4;
if (g_dfb->CreateSurface(g_dfb, &dsc, &g_s) == 0)
{
//pthread_create(&thread, 0, update_thread, 0);
//pthread_detach(thread);
}
else
{
g_s = 0;
free(g_bs);
g_bs = 0;
return 0;
}
return 1;
}
/*****************************************************************************/
void
mi_begin_update(void)
{
pthread_mutex_lock(&g_mutex1);
}
/*****************************************************************************/
void
mi_end_update(void)
{
pthread_mutex_unlock(&g_mutex1);
if (g_show_wfp)
{
printf("pixel at %d %d is %d\n", g_wfpx, g_wfpy, bs_get_pixel(g_wfpx, g_wfpy));
}
if (g_no_draw)
{
if (g_wfpv == bs_get_pixel(g_wfpx, g_wfpy))
{
g_no_draw = 0;
mi_invalidate(0, 0, g_width, g_height);
}
}
}
/*****************************************************************************/
void
mi_fill_rect(int x, int y, int cx, int cy, int colour)
{
if (g_no_draw)
{
return;
}
#ifdef USE_ORDERS
int red;
int green;
int blue;
mi_update_screen();
red = (colour & 0xff0000) >> 16;
green = (colour & 0xff00) >> 8;
blue = colour & 0xff;
if (g_use_trans && g_trans_colour == colour)
{
g_primary->SetColor(g_primary, red, green, blue, 0);
}
else
{
g_primary->SetColor(g_primary, red, green, blue, 0xff);
}
g_primary->FillRectangle(g_primary, x, y, cx, cy);
#else
mi_add_to(x, y, cx, cy);
#endif
}
/*****************************************************************************/
void
mi_line(int x1, int y1, int x2, int y2, int colour)
{
if (g_no_draw)
{
return;
}
#ifdef USE_ORDERS_TOO_SLOW
int red;
int green;
int blue;
mi_update_screen();
red = (colour >> 16) & 0xff;
green = (colour >> 8) & 0xff;
blue = colour & 0xff;
if (g_use_trans && g_trans_colour == colour)
{
g_primary->SetColor(g_primary, red, green, blue, 0);
}
else
{
g_primary->SetColor(g_primary, red, green, blue, 0xff);
}
g_primary->DrawLine(g_primary, x1, y1, x2, y2);
#else
int x;
int y;
int cx;
int cy;
x = UI_MIN(x1, x2);
y = UI_MIN(y1, y2);
cx = (UI_MAX(x1, x2) + 1) - x;
cy = (UI_MAX(y1, y2) + 1) - y;
mi_add_to(x, y, cx, cy);
#endif
}
/*****************************************************************************/
void
mi_screen_copy(int x, int y, int cx, int cy, int srcx, int srcy)
{
if (g_no_draw)
{
return;
}
#ifdef USE_ORDERS
DFBRectangle rect;
DFBSurfaceDescription dsc;
IDirectFBSurface * surface;
mi_update_screen();
//if (srcy < y)
{
dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT;
dsc.caps = DSCAPS_VIDEOONLY;
dsc.width = cx;
dsc.height = cy;
if (g_dfb->CreateSurface(g_dfb, &dsc, &surface) == 0)
{
rect.x = srcx;
rect.y = srcy;
rect.w = cx;
rect.h = cy;
surface->Blit(surface, g_primary, &rect, 0, 0);
g_primary->Blit(g_primary, surface, 0, x, y);
surface->Release(surface);
}
}
//else
//{
// rect.x = srcx;
// rect.y = srcy;
// rect.w = cx;
// rect.h = cy;
// g_primary->Blit(g_primary, g_primary, &rect, x, y);
//}
#else
mi_add_to(x, y, cx, cy);
#endif
}
/*****************************************************************************/
void
mi_set_clip(int x, int y, int cx, int cy)
{
#ifdef USE_ORDERS
g_reg.x1 = x;
g_reg.y1 = y;
g_reg.x2 = (x + cx) - 1;
g_reg.y2 = (y + cy) - 1;
g_primary->SetClip(g_primary, &g_reg);
#endif
}
/*****************************************************************************/
void
mi_reset_clip(void)
{
#ifdef USE_ORDERS
// this dosen't work, directb bug?
// g_primary->SetClip(g_primary, 0);
g_reg.x1 = 0;
g_reg.y1 = 0;
g_reg.x2 = g_width;
g_reg.y2 = g_height;
g_primary->SetClip(g_primary, &g_reg);
#endif
}
/*****************************************************************************/
void *
mi_create_cursor(unsigned int x, unsigned int y,
int width, int height,
unsigned char * andmask, unsigned char * xormask)
{
return (void *) 1;
}
/*****************************************************************************/
void
mi_destroy_cursor(void * cursor)
{
}
/*****************************************************************************/
void
mi_set_cursor(void * cursor)
{
}
/*****************************************************************************/
void
mi_set_null_cursor(void)
{
}
/*****************************************************************************/
void
mi_logon(void)
{
if (master_callback != 0)
{
master_callback(1, 0, 0);
}
}
/*****************************************************************************/
static void
out_params(void)
{
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
fprintf(stderr, "Version 1.4.1. Copyright (C) 1999-2006 Matt Chapman.\n");
fprintf(stderr, "direct framebuffer uiport by Jay Sorg\n");
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
fprintf(stderr, "Usage: dfbrdesktop [options] server\n");
fprintf(stderr, " -u: user name\n");
fprintf(stderr, " -n: client hostname\n");
fprintf(stderr, " -s: shell\n");
fprintf(stderr, " -p: password\n");
fprintf(stderr, " -d: domain\n");
fprintf(stderr, " -c: working directory\n");
fprintf(stderr, " -a: colour depth\n");
fprintf(stderr, " -wfp x y pixel: skip screen updates till x, y pixel is \
this colour\n");
fprintf(stderr, " -trans pixel: transparent colour\n");
fprintf(stderr, "\n");
}
/*****************************************************************************/
static int
parse_parameters(int in_argc, char ** in_argv)
{
int i;
if (in_argc <= 1)
{
out_params();
return 0;
}
for (i = 1; i < in_argc; i++)
{
strcpy(g_servername, in_argv[i]);
if (strcmp(in_argv[i], "-h") == 0)
{
out_params();
return 0;
}
else if (strcmp(in_argv[i], "-u") == 0)
{
strcpy(g_username, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-n") == 0)
{
strcpy(g_hostname, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-s") == 0)
{
strcpy(g_shell, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-p") == 0)
{
strcpy(g_password, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-d") == 0)
{
strcpy(g_domain, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-c") == 0)
{
strcpy(g_directory, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-a") == 0)
{
g_server_depth = atoi(in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-wfp") == 0)
{
g_wfpx = atoi(in_argv[i + 1]);
g_wfpy = atoi(in_argv[i + 2]);
g_wfpv = atoi(in_argv[i + 3]);
if (g_wfpv == 0)
{
g_show_wfp = 1;
}
else
{
g_no_draw = 1;
}
}
else if (strcmp(in_argv[i], "-trans") == 0)
{
g_use_trans = 1;
g_trans_colour = atoi(in_argv[i + 1]);
}
}
return 1;
}
/*****************************************************************************/
int
main(int argc, char ** argv)
{
int rv;
DFBSurfaceDescription dsc;
DFBResult err;
strcpy(g_hostname, "test");
g_server_depth = 24;
if (!parse_parameters(argc, argv))
{
return 0;
}
err = DirectFBInit(&argc, &argv);
if (err == 0)
{
err = DirectFBCreate(&g_dfb);
}
if (err == 0)
{
err = g_dfb->SetCooperativeLevel(g_dfb, DFSCL_FULLSCREEN);
}
if (err == 0)
{
dsc.flags = DSDESC_CAPS;
#ifdef USE_FLIPPING
dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE | DSCAPS_FLIPPING;
#else
dsc.caps = DSCAPS_PRIMARY;
#endif
err = g_dfb->CreateSurface(g_dfb, &dsc, &g_primary);
}
if (err == 0)
{
g_dfb->CreateInputEventBuffer(g_dfb, DICAPS_AXES | DICAPS_BUTTONS |
DICAPS_KEYS, 0, &g_event);
}
if (err == 0)
{
err = g_primary->GetSize(g_primary, &g_width, &g_height);
}
if (err != 0)
{
printf("error in main\n");
return 1;
}
rv = ui_main();
g_s->Release(g_s);
g_primary->Release(g_primary);
g_dfb->Release(g_dfb);
return rv;
}
/*****************************************************************************/
/* returns non zero ok */
int
librdesktop_init(long obj1, long obj2, long obj3, int in_argc, char ** in_argv)
{
strcpy(g_hostname, "test");
g_dfb = (IDirectFB *) obj1;
g_primary = (IDirectFBSurface *) obj2;
g_primary->GetSize(g_primary, &g_width, &g_height);
g_server_depth = 24;
if (!parse_parameters(in_argc, in_argv))
{
return 0;
}
return 1;
}
/*****************************************************************************/
/* returns non zero ok */
int
librdesktop_connect(void)
{
return ui_lib_main();
}
/*****************************************************************************/
/* returns non zero ok */
int
librdesktop_check_wire(void)
{
fd_set rfds;
int rv;
int fd;
struct timeval tv;
fd = g_tcp_sck;
FD_ZERO(&rfds);
FD_SET(g_tcp_sck, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 0;
rv = select(fd + 1, &rfds, 0, 0, &tv);
if (rv > -1)
{
if (rv > 0)
{
if (FD_ISSET(g_tcp_sck, &rfds))
{
if (!ui_read_wire())
{
return 0;
}
}
}
}
return 1;
}
/*****************************************************************************/
int
librdesktop_mouse_move(int x, int y)
{
ui_mouse_move(x, y);
return 0;
}
/*****************************************************************************/
int
librdesktop_mouse_button(int button, int x, int y, int down)
{
ui_mouse_button(button, x, y, down);
return 0;
}
/*****************************************************************************/
int
librdesktop_key_down(int key, int ext)
{
ui_key_down(key, ext);
return 0;
}
/*****************************************************************************/
int
librdesktop_key_up(int key, int ext)
{
ui_key_up(key, ext);
return 0;
}
/*****************************************************************************/
int
librdesktop_quit(void)
{
return 1;
}
/*****************************************************************************/
int
librdesktop_set_callback(void (* callback)(int, int, int))
{
master_callback = callback;
return 0;
}

File diff suppressed because it is too large Load Diff

@ -1,231 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Protocol services - ISO layer
Copyright (C) Matthew Chapman 1999-2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "rdesktop.h"
/* Send a self-contained ISO PDU */
static void
iso_send_msg(uint8 code)
{
STREAM s;
s = tcp_init(11);
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* reserved */
out_uint16_be(s, 11); /* length */
out_uint8(s, 6); /* hdrlen */
out_uint8(s, code);
out_uint16(s, 0); /* dst_ref */
out_uint16(s, 0); /* src_ref */
out_uint8(s, 0); /* class */
s_mark_end(s);
tcp_send(s);
}
static void
iso_send_connection_request(char *username)
{
STREAM s;
int length = 30 + strlen(username);
s = tcp_init(length);
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* reserved */
out_uint16_be(s, length); /* length */
out_uint8(s, length - 5); /* hdrlen */
out_uint8(s, ISO_PDU_CR);
out_uint16(s, 0); /* dst_ref */
out_uint16(s, 0); /* src_ref */
out_uint8(s, 0); /* class */
out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
out_uint8p(s, username, strlen(username));
out_uint8(s, 0x0d); /* Unknown */
out_uint8(s, 0x0a); /* Unknown */
s_mark_end(s);
tcp_send(s);
}
/* Receive a message on the ISO layer, return code */
static STREAM
iso_recv_msg(uint8 * code, uint8 * rdpver)
{
STREAM s;
uint16 length;
uint8 version;
s = tcp_recv(NULL, 4);
if (s == NULL)
return NULL;
in_uint8(s, version);
if (rdpver != NULL)
*rdpver = version;
if (version == 3)
{
in_uint8s(s, 1); /* pad */
in_uint16_be(s, length);
}
else
{
in_uint8(s, length);
if (length & 0x80)
{
length &= ~0x80;
next_be(s, length);
}
}
s = tcp_recv(s, length - 4);
if (s == NULL)
return NULL;
if (version != 3)
return s;
in_uint8s(s, 1); /* hdrlen */
in_uint8(s, *code);
if (*code == ISO_PDU_DT)
{
in_uint8s(s, 1); /* eot */
return s;
}
in_uint8s(s, 5); /* dst_ref, src_ref, class */
return s;
}
/* Initialise ISO transport data packet */
STREAM
iso_init(int length)
{
STREAM s;
s = tcp_init(length + 7);
s_push_layer(s, iso_hdr, 7);
return s;
}
/* Send an ISO data PDU */
void
iso_send(STREAM s)
{
uint16 length;
s_pop_layer(s, iso_hdr);
length = s->end - s->p;
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* reserved */
out_uint16_be(s, length);
out_uint8(s, 2); /* hdrlen */
out_uint8(s, ISO_PDU_DT); /* code */
out_uint8(s, 0x80); /* eot */
tcp_send(s);
}
/* Receive ISO transport data packet */
STREAM
iso_recv(uint8 * rdpver)
{
STREAM s;
uint8 code = 0;
s = iso_recv_msg(&code, rdpver);
if (s == NULL)
return NULL;
if (rdpver != NULL)
if (*rdpver != 3)
return s;
if (code != ISO_PDU_DT)
{
error("expected DT, got 0x%x\n", code);
return NULL;
}
return s;
}
/* Establish a connection up to the ISO layer */
BOOL
iso_connect(char *server, char *username)
{
uint8 code = 0;
if (!tcp_connect(server))
return False;
iso_send_connection_request(username);
if (iso_recv_msg(&code, NULL) == NULL)
return False;
if (code != ISO_PDU_CC)
{
error("expected CC, got 0x%x\n", code);
tcp_disconnect();
return False;
}
return True;
}
/* Establish a reconnection up to the ISO layer */
BOOL
iso_reconnect(char *server)
{
uint8 code = 0;
if (!tcp_connect(server))
return False;
iso_send_msg(ISO_PDU_CR);
if (iso_recv_msg(&code, NULL) == NULL)
return False;
if (code != ISO_PDU_CC)
{
error("expected CC, got 0x%x\n", code);
tcp_disconnect();
return False;
}
return True;
}
/* Disconnect from the ISO layer */
void
iso_disconnect(void)
{
iso_send_msg(ISO_PDU_DR);
tcp_disconnect();
}
/* reset the state to support reconnecting */
void
iso_reset_state(void)
{
tcp_reset_state();
}
Loading…
Cancel
Save