1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - ISO layer
4 Copyright (C) Matthew Chapman 1999-2002
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
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* Send a self-contained ISO PDU */
25 iso_send_msg(uint8 code, uint8 class)
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_be(s, 0x1234); /* src_ref */
39 out_uint8(s, class); /* 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)
82 s = tcp_recv(NULL, 4);
99 in_uint8s(s, 1); /* pad */
100 in_uint16_be(s, length);
104 error("TPKT v%d\n", version);
108 s = tcp_recv(s, length - 4);
112 if ((version & 3) == 0)
114 rdp5_process(s, version & 0x80);
118 in_uint8s(s, 1); /* hdrlen */
121 if (*code == ISO_PDU_DT)
123 in_uint8s(s, 1); /* eot */
127 in_uint8s(s, 5); /* dst_ref, src_ref, class */
131 /* Initialise ISO transport data packet */
137 s = tcp_init(length + 7);
138 s_push_layer(s, iso_hdr, 7);
143 /* Send an ISO data PDU */
149 s_pop_layer(s, iso_hdr);
150 length = s->end - s->p;
152 out_uint8(s, 3); /* version */
153 out_uint8(s, 0); /* reserved */
154 out_uint16_be(s, length);
156 out_uint8(s, 2); /* hdrlen */
157 out_uint8(s, ISO_PDU_DT); /* code */
158 out_uint8(s, 0x80); /* eot */
163 /* Receive ISO transport data packet */
170 s = iso_recv_msg(&code);
174 if (code != ISO_PDU_DT)
176 error("expected DT, got 0x%x\n", code);
184 iso_recv_connect(int server_sock)
189 tcp_recv_connect(server_sock);
191 s = iso_recv_msg(&code);
195 if (code != ISO_PDU_CR)
197 error("expected CR, got 0x%x\n", code);
201 DEBUG(("Got ISO connection request\n"));
203 iso_send_msg(ISO_PDU_CC, 0);
207 /* Disconnect from the ISO layer */
211 iso_send_msg(ISO_PDU_DR, 0);