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)
115 // rdp5_process(s, version & 0x80);
116 printf("rdp5_process()\n");
120 in_uint8s(s, 1); /* hdrlen */
123 if (*code == ISO_PDU_DT)
125 in_uint8s(s, 1); /* eot */
129 in_uint8s(s, 5); /* dst_ref, src_ref, class */
133 /* Initialise ISO transport data packet */
139 s = tcp_init(length + 7);
140 s_push_layer(s, iso_hdr, 7);
145 /* Send an ISO data PDU */
151 s_pop_layer(s, iso_hdr);
152 length = s->end - s->p;
154 out_uint8(s, 3); /* version */
155 out_uint8(s, 0); /* reserved */
156 out_uint16_be(s, length);
158 out_uint8(s, 2); /* hdrlen */
159 out_uint8(s, ISO_PDU_DT); /* code */
160 out_uint8(s, 0x80); /* eot */
165 /* Receive ISO transport data packet */
172 s = iso_recv_msg(&code);
176 if (code != ISO_PDU_DT)
178 error("expected DT, got 0x%x\n", code);
186 iso_recv_connect(int server_sock)
191 tcp_recv_connect(server_sock);
193 s = iso_recv_msg(&code);
197 if (code != ISO_PDU_CR)
199 error("expected CR, got 0x%x\n", code);
203 DEBUG(("Got ISO connection request\n"));
205 iso_send_msg(ISO_PDU_CC, 0);
209 /* Disconnect from the ISO layer */
213 iso_send_msg(ISO_PDU_DR, 0);