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(uint8 code
)
31 out_uint8(s
, 3); /* version */
32 out_uint8(s
, 0); /* reserved */
33 out_uint16_be(s
, 11); /* length */
35 out_uint8(s
, 6); /* hdrlen */
37 out_uint16(s
, 0); /* dst_ref */
38 out_uint16(s
, 0); /* src_ref */
39 out_uint8(s
, 0); /* class */
46 iso_send_connection_request(char *username
)
49 int length
= 30 + strlen(username
);
53 out_uint8(s
, 3); /* version */
54 out_uint8(s
, 0); /* reserved */
55 out_uint16_be(s
, length
); /* length */
57 out_uint8(s
, length
- 5); /* hdrlen */
58 out_uint8(s
, ISO_PDU_CR
);
59 out_uint16(s
, 0); /* dst_ref */
60 out_uint16(s
, 0); /* src_ref */
61 out_uint8(s
, 0); /* class */
63 out_uint8p(s
, "Cookie: mstshash=", strlen("Cookie: mstshash="));
64 out_uint8p(s
, username
, strlen(username
));
66 out_uint8(s
, 0x0d); /* Unknown */
67 out_uint8(s
, 0x0a); /* Unknown */
73 /* Receive a message on the ISO layer, return code */
75 iso_recv_msg(uint8
* code
, uint8
* rdpver
)
81 s
= tcp_recv(NULL
, 4);
89 in_uint8s(s
, 1); /* pad */
90 in_uint16_be(s
, length
);
101 s
= tcp_recv(s
, length
- 4);
106 in_uint8s(s
, 1); /* hdrlen */
108 if (*code
== ISO_PDU_DT
)
110 in_uint8s(s
, 1); /* eot */
113 in_uint8s(s
, 5); /* dst_ref, src_ref, class */
117 /* Initialise ISO transport data packet */
123 s
= tcp_init(length
+ 7);
124 s_push_layer(s
, iso_hdr
, 7);
129 /* Send an ISO data PDU */
135 s_pop_layer(s
, iso_hdr
);
136 length
= s
->end
- s
->p
;
138 out_uint8(s
, 3); /* version */
139 out_uint8(s
, 0); /* reserved */
140 out_uint16_be(s
, length
);
142 out_uint8(s
, 2); /* hdrlen */
143 out_uint8(s
, ISO_PDU_DT
); /* code */
144 out_uint8(s
, 0x80); /* eot */
149 /* Receive ISO transport data packet */
151 iso_recv(uint8
* rdpver
)
156 s
= iso_recv_msg(&code
, rdpver
);
162 if (code
!= ISO_PDU_DT
)
164 error("expected DT, got 0x%x\n", code
);
170 /* Establish a connection up to the ISO layer */
172 iso_connect(char *server
, char *username
)
176 if (!tcp_connect(server
))
179 iso_send_connection_request(username
);
181 if (iso_recv_msg(&code
, NULL
) == NULL
)
184 if (code
!= ISO_PDU_CC
)
186 error("expected CC, got 0x%x\n", code
);
194 /* Establish a reconnection up to the ISO layer */
196 iso_reconnect(char *server
)
200 if (!tcp_connect(server
))
203 iso_send_msg(ISO_PDU_CR
);
205 if (iso_recv_msg(&code
, NULL
) == NULL
)
208 if (code
!= ISO_PDU_CC
)
210 error("expected CC, got 0x%x\n", code
);
218 /* Disconnect from the ISO layer */
222 iso_send_msg(ISO_PDU_DR
);
226 /* reset the state to support reconnecting */
228 iso_reset_state(void)