00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "rdesktop.h"
00022
00023
00024 static void
00025 iso_send_msg(uint8 code)
00026 {
00027 STREAM s;
00028
00029 s = tcp_init(11);
00030
00031 out_uint8(s, 3);
00032 out_uint8(s, 0);
00033 out_uint16_be(s, 11);
00034
00035 out_uint8(s, 6);
00036 out_uint8(s, code);
00037 out_uint16(s, 0);
00038 out_uint16(s, 0);
00039 out_uint8(s, 0);
00040
00041 s_mark_end(s);
00042 tcp_send(s);
00043 }
00044
00045
00046 static STREAM
00047 iso_recv_msg(uint8 * code)
00048 {
00049 STREAM s;
00050 uint16 length;
00051 uint8 version;
00052
00053 s = tcp_recv(4);
00054 if (s == NULL)
00055 {
00056 return NULL;
00057 }
00058
00059 in_uint8(s, version);
00060 if (version != 3)
00061 {
00062 error("TPKT v%d\n", version);
00063 return NULL;
00064 }
00065
00066 in_uint8s(s, 1);
00067 in_uint16_be(s, length);
00068
00069 s = tcp_recv(length - 4);
00070 if (s == NULL)
00071 return NULL;
00072
00073 in_uint8s(s, 1);
00074 in_uint8(s, *code);
00075
00076 if (*code == ISO_PDU_DT)
00077 {
00078 in_uint8s(s, 1);
00079 return s;
00080 }
00081
00082 in_uint8s(s, 5);
00083 return s;
00084 }
00085
00086
00087 STREAM
00088 iso_init(int length)
00089 {
00090 STREAM s;
00091
00092 s = tcp_init(length + 7);
00093 s_push_layer(s, iso_hdr, 7);
00094
00095 return s;
00096 }
00097
00098
00099 void
00100 iso_send(STREAM s)
00101 {
00102 uint16 length;
00103
00104 s_pop_layer(s, iso_hdr);
00105 length = s->end - s->p;
00106
00107 out_uint8(s, 3);
00108 out_uint8(s, 0);
00109 out_uint16_be(s, length);
00110
00111 out_uint8(s, 2);
00112 out_uint8(s, ISO_PDU_DT);
00113 out_uint8(s, 0x80);
00114
00115 tcp_send(s);
00116 }
00117
00118
00119 STREAM
00120 iso_recv(void)
00121 {
00122 STREAM s;
00123 uint8 code;
00124
00125 s = iso_recv_msg(&code);
00126 if (s == NULL)
00127 return NULL;
00128
00129 if (code != ISO_PDU_DT)
00130 {
00131 error("expected DT, got 0x%x\n", code);
00132 return NULL;
00133 }
00134
00135 return s;
00136 }
00137
00138
00139 BOOL
00140 iso_connect(char *server)
00141 {
00142 uint8 code;
00143
00144 if (!tcp_connect(server))
00145 return False;
00146
00147 iso_send_msg(ISO_PDU_CR);
00148
00149 if (iso_recv_msg(&code) == NULL)
00150 {
00151 return False;
00152 }
00153
00154 if (code != ISO_PDU_CC)
00155 {
00156 error("expected CC, got 0x%x\n", code);
00157 tcp_disconnect();
00158 return False;
00159 }
00160
00161 return True;
00162 }
00163
00164
00165 void
00166 iso_disconnect(void)
00167 {
00168 iso_send_msg(ISO_PDU_DR);
00169 tcp_disconnect();
00170 }