Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

iso.cpp

Go to the documentation of this file.
00001 /*
00002    rdesktop: A Remote Desktop Protocol client.
00003    Protocol services - ISO layer
00004    Copyright (C) Matthew Chapman 1999-2002
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "rdesktop.h"
00022 
00023 /* Send a self-contained ISO PDU */
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);        /* version */
00032         out_uint8(s, 0);        /* reserved */
00033         out_uint16_be(s, 11);   /* length */
00034 
00035         out_uint8(s, 6);        /* hdrlen */
00036         out_uint8(s, code);
00037         out_uint16(s, 0);       /* dst_ref */
00038         out_uint16(s, 0);       /* src_ref */
00039         out_uint8(s, 0);        /* class */
00040 
00041         s_mark_end(s);
00042         tcp_send(s);
00043 }
00044 
00045 /* Receive a message on the ISO layer, return code */
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);        /* pad */
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);        /* hdrlen */
00074         in_uint8(s, *code);
00075 
00076         if (*code == ISO_PDU_DT)
00077         {
00078                 in_uint8s(s, 1);        /* eot */
00079                 return s;
00080         }
00081 
00082         in_uint8s(s, 5);        /* dst_ref, src_ref, class */
00083         return s;
00084 }
00085 
00086 /* Initialise ISO transport data packet */
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 /* Send an ISO data PDU */
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);        /* version */
00108         out_uint8(s, 0);        /* reserved */
00109         out_uint16_be(s, length);
00110 
00111         out_uint8(s, 2);        /* hdrlen */
00112         out_uint8(s, ISO_PDU_DT);       /* code */
00113         out_uint8(s, 0x80);     /* eot */
00114 
00115         tcp_send(s);
00116 }
00117 
00118 /* Receive ISO transport data packet */
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 /* Establish a connection up to the ISO layer */
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 /* Disconnect from the ISO layer */
00165 void
00166 iso_disconnect(void)
00167 {
00168         iso_send_msg(ISO_PDU_DR);
00169         tcp_disconnect();
00170 }

Generated on Sat Nov 5 16:17:41 2005 for OPIE by  doxygen 1.4.2