1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - ISO layer |
Protocol services - ISO layer |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
Copyright (C) Matthew Chapman 1999-2001 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
|
|
23 |
/* Send a self-contained ISO PDU */ |
/* Send a self-contained ISO PDU */ |
24 |
static void iso_send_msg(uint8 code) |
static void |
25 |
|
iso_send_msg(uint8 code) |
26 |
{ |
{ |
27 |
STREAM s; |
STREAM s; |
28 |
|
|
43 |
} |
} |
44 |
|
|
45 |
/* Receive a message on the ISO layer, return code */ |
/* Receive a message on the ISO layer, return code */ |
46 |
static STREAM iso_recv_msg(uint8 *code) |
static STREAM |
47 |
|
iso_recv_msg(uint8 * code) |
48 |
{ |
{ |
49 |
STREAM s; |
STREAM s; |
50 |
uint16 length; |
uint16 length; |
52 |
|
|
53 |
s = tcp_recv(4); |
s = tcp_recv(4); |
54 |
if (s == NULL) |
if (s == NULL) |
55 |
return False; |
return NULL; |
56 |
|
|
57 |
in_uint8(s, version); |
in_uint8(s, version); |
58 |
if (version != 3) |
if (version != 3) |
59 |
{ |
{ |
60 |
ERROR("TPKT v%d\n", version); |
error("TPKT v%d\n", version); |
61 |
return False; |
return NULL; |
62 |
} |
} |
63 |
|
|
64 |
in_uint8s(s, 1); /* pad */ |
in_uint8s(s, 1); /* pad */ |
66 |
|
|
67 |
s = tcp_recv(length - 4); |
s = tcp_recv(length - 4); |
68 |
if (s == NULL) |
if (s == NULL) |
69 |
return False; |
return NULL; |
70 |
|
|
71 |
in_uint8s(s, 1); /* hdrlen */ |
in_uint8s(s, 1); /* hdrlen */ |
72 |
in_uint8(s, *code); |
in_uint8(s, *code); |
82 |
} |
} |
83 |
|
|
84 |
/* Initialise ISO transport data packet */ |
/* Initialise ISO transport data packet */ |
85 |
STREAM iso_init(int length) |
STREAM |
86 |
|
iso_init(int length) |
87 |
{ |
{ |
88 |
STREAM s; |
STREAM s; |
89 |
|
|
94 |
} |
} |
95 |
|
|
96 |
/* Send an ISO data PDU */ |
/* Send an ISO data PDU */ |
97 |
void iso_send(STREAM s) |
void |
98 |
|
iso_send(STREAM s) |
99 |
{ |
{ |
100 |
uint16 length; |
uint16 length; |
101 |
|
|
114 |
} |
} |
115 |
|
|
116 |
/* Receive ISO transport data packet */ |
/* Receive ISO transport data packet */ |
117 |
STREAM iso_recv() |
STREAM |
118 |
|
iso_recv() |
119 |
{ |
{ |
120 |
STREAM s; |
STREAM s; |
121 |
uint8 code; |
uint8 code; |
122 |
|
|
123 |
s = iso_recv_msg(&code); |
s = iso_recv_msg(&code); |
124 |
if ((s == NULL) || (code != ISO_PDU_DT)) |
if (s == NULL) |
125 |
|
return NULL; |
126 |
|
|
127 |
|
if (code != ISO_PDU_DT) |
128 |
{ |
{ |
129 |
ERROR("expected DT, got %d\n", code); |
error("expected DT, got 0x%x\n", code); |
130 |
return False; |
return NULL; |
131 |
} |
} |
132 |
|
|
133 |
return s; |
return s; |
134 |
} |
} |
135 |
|
|
136 |
/* Establish a connection up to the ISO layer */ |
/* Establish a connection up to the ISO layer */ |
137 |
BOOL iso_connect(char *server) |
BOOL |
138 |
|
iso_connect(char *server) |
139 |
{ |
{ |
140 |
uint8 code; |
uint8 code; |
141 |
|
|
144 |
|
|
145 |
iso_send_msg(ISO_PDU_CR); |
iso_send_msg(ISO_PDU_CR); |
146 |
|
|
147 |
if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC)) |
if (iso_recv_msg(&code) == NULL) |
148 |
|
return False; |
149 |
|
|
150 |
|
if (code != ISO_PDU_CC) |
151 |
{ |
{ |
152 |
ERROR("expected CC, got %d\n", code); |
error("expected CC, got 0x%x\n", code); |
153 |
tcp_disconnect(); |
tcp_disconnect(); |
154 |
return False; |
return False; |
155 |
} |
} |
158 |
} |
} |
159 |
|
|
160 |
/* Disconnect from the ISO layer */ |
/* Disconnect from the ISO layer */ |
161 |
void iso_disconnect() |
void |
162 |
|
iso_disconnect() |
163 |
{ |
{ |
164 |
iso_send_msg(ISO_PDU_DR); |
iso_send_msg(ISO_PDU_DR); |
165 |
tcp_disconnect(); |
tcp_disconnect(); |