2000-05-10 09:36:34 +02:00
|
|
|
/*
|
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
Protocol services - ISO layer
|
|
|
|
Copyright (C) Matthew Chapman 1999-2000
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
#include "rdesktop.h"
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Send a self-contained ISO PDU */
|
2001-01-06 04:47:04 +01:00
|
|
|
static void
|
|
|
|
iso_send_msg(uint8 code)
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
STREAM s;
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
s = tcp_init(11);
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
out_uint8(s, 3); /* version */
|
|
|
|
out_uint8(s, 0); /* reserved */
|
|
|
|
out_uint16_be(s, 11); /* length */
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
out_uint8(s, 6); /* hdrlen */
|
2000-08-15 12:23:24 +02:00
|
|
|
out_uint8(s, code);
|
2001-01-06 04:12:10 +01:00
|
|
|
out_uint16(s, 0); /* dst_ref */
|
|
|
|
out_uint16(s, 0); /* src_ref */
|
|
|
|
out_uint8(s, 0); /* class */
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
s_mark_end(s);
|
|
|
|
tcp_send(s);
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Receive a message on the ISO layer, return code */
|
2001-01-06 04:47:04 +01:00
|
|
|
static STREAM
|
|
|
|
iso_recv_msg(uint8 *code)
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
STREAM s;
|
|
|
|
uint16 length;
|
|
|
|
uint8 version;
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
s = tcp_recv(4);
|
|
|
|
if (s == NULL)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
in_uint8(s, version);
|
|
|
|
if (version != 3)
|
|
|
|
{
|
|
|
|
ERROR("TPKT v%d\n", version);
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
in_uint8s(s, 1); /* pad */
|
2000-08-15 12:23:24 +02:00
|
|
|
in_uint16_be(s, length);
|
|
|
|
|
|
|
|
s = tcp_recv(length - 4);
|
|
|
|
if (s == NULL)
|
|
|
|
return False;
|
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
in_uint8s(s, 1); /* hdrlen */
|
2000-08-15 12:23:24 +02:00
|
|
|
in_uint8(s, *code);
|
|
|
|
|
|
|
|
if (*code == ISO_PDU_DT)
|
|
|
|
{
|
2001-01-06 04:12:10 +01:00
|
|
|
in_uint8s(s, 1); /* eot */
|
|
|
|
return s;
|
2000-08-15 12:23:24 +02:00
|
|
|
}
|
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
in_uint8s(s, 5); /* dst_ref, src_ref, class */
|
2000-08-15 12:23:24 +02:00
|
|
|
return s;
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Initialise ISO transport data packet */
|
2001-01-06 04:47:04 +01:00
|
|
|
STREAM
|
|
|
|
iso_init(int length)
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
STREAM s;
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
s = tcp_init(length + 7);
|
|
|
|
s_push_layer(s, iso_hdr, 7);
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
return s;
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Send an ISO data PDU */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
|
|
|
iso_send(STREAM s)
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
uint16 length;
|
|
|
|
|
|
|
|
s_pop_layer(s, iso_hdr);
|
|
|
|
length = s->end - s->p;
|
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
out_uint8(s, 3); /* version */
|
|
|
|
out_uint8(s, 0); /* reserved */
|
2000-08-15 12:23:24 +02:00
|
|
|
out_uint16_be(s, length);
|
|
|
|
|
2001-01-06 04:12:10 +01:00
|
|
|
out_uint8(s, 2); /* hdrlen */
|
|
|
|
out_uint8(s, ISO_PDU_DT); /* code */
|
|
|
|
out_uint8(s, 0x80); /* eot */
|
2000-08-15 12:23:24 +02:00
|
|
|
|
|
|
|
tcp_send(s);
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive ISO transport data packet */
|
2001-01-06 04:47:04 +01:00
|
|
|
STREAM
|
|
|
|
iso_recv()
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
STREAM s;
|
2000-05-10 09:36:34 +02:00
|
|
|
uint8 code;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
s = iso_recv_msg(&code);
|
|
|
|
if ((s == NULL) || (code != ISO_PDU_DT))
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
ERROR("expected DT, got %d\n", code);
|
2000-05-10 09:36:34 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
return s;
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Establish a connection up to the ISO layer */
|
2001-01-06 04:47:04 +01:00
|
|
|
BOOL
|
|
|
|
iso_connect(char *server)
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
uint8 code;
|
2000-05-10 09:36:34 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if (!tcp_connect(server))
|
2000-05-10 09:36:34 +02:00
|
|
|
return False;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
iso_send_msg(ISO_PDU_CR);
|
|
|
|
|
|
|
|
if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
ERROR("expected CC, got %d\n", code);
|
|
|
|
tcp_disconnect();
|
2000-05-10 09:36:34 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Disconnect from the ISO layer */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
|
|
|
iso_disconnect()
|
2000-05-10 09:36:34 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
iso_send_msg(ISO_PDU_DR);
|
|
|
|
tcp_disconnect();
|
2000-05-10 09:36:34 +02:00
|
|
|
}
|