1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - ISO layer
4 Copyright (C) Matthew Chapman 1999-2005
6 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
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* Send a self-contained ISO PDU */
25 iso_send_msg(RDPCLIENT
* This
, uint8 code
)
29 s
= tcp_init(This
, 11);
34 out_uint8(s
, 3); /* version */
35 out_uint8(s
, 0); /* reserved */
36 out_uint16_be(s
, 11); /* length */
38 out_uint8(s
, 6); /* hdrlen */
40 out_uint16(s
, 0); /* dst_ref */
41 out_uint16(s
, 0); /* src_ref */
42 out_uint8(s
, 0); /* class */
45 return tcp_send(This
, s
);
49 iso_send_connection_request(RDPCLIENT
* This
, char *cookie
)
52 int cookielen
= (int)strlen(cookie
);
53 int length
= 11 + cookielen
;
55 s
= tcp_init(This
, length
);
60 out_uint8(s
, 3); /* version */
61 out_uint8(s
, 0); /* reserved */
62 out_uint16_be(s
, length
); /* length */
64 out_uint8(s
, length
- 5); /* hdrlen */
65 out_uint8(s
, ISO_PDU_CR
);
66 out_uint16(s
, 0); /* dst_ref */
67 out_uint16(s
, 0); /* src_ref */
68 out_uint8(s
, 0); /* class */
70 out_uint8p(s
, cookie
, cookielen
);
73 return tcp_send(This
, s
);
76 /* Receive a message on the ISO layer, return code */
78 iso_recv_msg(RDPCLIENT
* This
, uint8
* code
, uint8
* rdpver
)
84 s
= tcp_recv(This
, NULL
, 4);
92 in_uint8s(s
, 1); /* pad */
93 in_uint16_be(s
, length
);
104 s
= tcp_recv(This
, s
, length
- 4);
109 in_uint8s(s
, 1); /* hdrlen */
111 if (*code
== ISO_PDU_DT
)
113 in_uint8s(s
, 1); /* eot */
116 in_uint8s(s
, 5); /* dst_ref, src_ref, class */
120 /* Initialise ISO transport data packet */
122 iso_init(RDPCLIENT
* This
, int length
)
126 s
= tcp_init(This
, length
+ 7);
131 s_push_layer(s
, iso_hdr
, 7);
136 /* Send an ISO data PDU */
138 iso_send(RDPCLIENT
* This
, STREAM s
)
142 s_pop_layer(s
, iso_hdr
);
143 length
= (uint16
)(s
->end
- s
->p
);
145 out_uint8(s
, 3); /* version */
146 out_uint8(s
, 0); /* reserved */
147 out_uint16_be(s
, length
);
149 out_uint8(s
, 2); /* hdrlen */
150 out_uint8(s
, ISO_PDU_DT
); /* code */
151 out_uint8(s
, 0x80); /* eot */
153 return tcp_send(This
, s
);
156 /* Receive ISO transport data packet */
158 iso_recv(RDPCLIENT
* This
, uint8
* rdpver
)
163 s
= iso_recv_msg(This
, &code
, rdpver
);
169 if (code
!= ISO_PDU_DT
)
171 error("expected DT, got 0x%x\n", code
);
177 /* Establish a connection up to the ISO layer */
179 iso_connect(RDPCLIENT
* This
, char *server
, char *cookie
)
183 if (!tcp_connect(This
, server
))
186 if (!iso_send_connection_request(This
, cookie
))
189 if (iso_recv_msg(This
, &code
, NULL
) == NULL
)
192 if (code
!= ISO_PDU_CC
)
194 error("expected CC, got 0x%x\n", code
);
195 tcp_disconnect(This
);
202 /* Establish a reconnection up to the ISO layer */
204 iso_reconnect(RDPCLIENT
* This
, char *server
, char *cookie
)
208 if (!tcp_connect(This
, server
))
211 if (!iso_send_connection_request(This
, cookie
)) // BUGBUG should we really pass the cookie here?
214 if (iso_recv_msg(This
, &code
, NULL
) == NULL
)
217 if (code
!= ISO_PDU_CC
)
219 error("expected CC, got 0x%x\n", code
);
220 tcp_disconnect(This
);
227 /* Disconnect from the ISO layer */
229 iso_disconnect(RDPCLIENT
* This
)
231 iso_send_msg(This
, ISO_PDU_DR
);
232 return tcp_disconnect(This
);
235 /* reset the state to support reconnecting */
237 iso_reset_state(RDPCLIENT
* This
)
239 tcp_reset_state(This
);