ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

iso.c
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 8 -*-
00002    rdesktop: A Remote Desktop Protocol client.
00003    Protocol services - ISO layer
00004    Copyright (C) Matthew Chapman 1999-2005
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 along
00017    with this program; if not, write to the Free Software Foundation, Inc.,
00018    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019 */
00020 
00021 #include <precomp.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 static void
00046 iso_send_connection_request(char *username)
00047 {
00048     STREAM s;
00049     int length = 30 + strlen(username);
00050 
00051     s = tcp_init(length);
00052 
00053     out_uint8(s, 3);    /* version */
00054     out_uint8(s, 0);    /* reserved */
00055     out_uint16_be(s, length);   /* length */
00056 
00057     out_uint8(s, length - 5);   /* hdrlen */
00058     out_uint8(s, ISO_PDU_CR);
00059     out_uint16(s, 0);   /* dst_ref */
00060     out_uint16(s, 0);   /* src_ref */
00061     out_uint8(s, 0);    /* class */
00062 
00063     out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
00064     out_uint8p(s, username, strlen(username));
00065 
00066     out_uint8(s, 0x0d); /* Unknown */
00067     out_uint8(s, 0x0a); /* Unknown */
00068 
00069     s_mark_end(s);
00070     tcp_send(s);
00071 }
00072 
00073 /* Receive a message on the ISO layer, return code */
00074 static STREAM
00075 iso_recv_msg(uint8 * code, uint8 * rdpver)
00076 {
00077     STREAM s;
00078     uint16 length;
00079     uint8 version;
00080 
00081     s = tcp_recv(NULL, 4);
00082     if (s == NULL)
00083         return NULL;
00084     in_uint8(s, version);
00085     if (rdpver != NULL)
00086         *rdpver = version;
00087     if (version == 3)
00088     {
00089         in_uint8s(s, 1);    /* pad */
00090         in_uint16_be(s, length);
00091     }
00092     else
00093     {
00094         in_uint8(s, length);
00095         if (length & 0x80)
00096         {
00097             length &= ~0x80;
00098             next_be(s, length);
00099         }
00100     }
00101     s = tcp_recv(s, length - 4);
00102     if (s == NULL)
00103         return NULL;
00104     if (version != 3)
00105         return s;
00106     in_uint8s(s, 1);    /* hdrlen */
00107     in_uint8(s, *code);
00108     if (*code == ISO_PDU_DT)
00109     {
00110         in_uint8s(s, 1);    /* eot */
00111         return s;
00112     }
00113     in_uint8s(s, 5);    /* dst_ref, src_ref, class */
00114     return s;
00115 }
00116 
00117 /* Initialise ISO transport data packet */
00118 STREAM
00119 iso_init(int length)
00120 {
00121     STREAM s;
00122 
00123     s = tcp_init(length + 7);
00124     s_push_layer(s, iso_hdr, 7);
00125 
00126     return s;
00127 }
00128 
00129 /* Send an ISO data PDU */
00130 void
00131 iso_send(STREAM s)
00132 {
00133     uint16 length;
00134 
00135     s_pop_layer(s, iso_hdr);
00136     length = s->end - s->p;
00137 
00138     out_uint8(s, 3);    /* version */
00139     out_uint8(s, 0);    /* reserved */
00140     out_uint16_be(s, length);
00141 
00142     out_uint8(s, 2);    /* hdrlen */
00143     out_uint8(s, ISO_PDU_DT);   /* code */
00144     out_uint8(s, 0x80); /* eot */
00145 
00146     tcp_send(s);
00147 }
00148 
00149 /* Receive ISO transport data packet */
00150 STREAM
00151 iso_recv(uint8 * rdpver)
00152 {
00153     STREAM s;
00154     uint8 code = 0;
00155 
00156     s = iso_recv_msg(&code, rdpver);
00157     if (s == NULL)
00158         return NULL;
00159     if (rdpver != NULL)
00160         if (*rdpver != 3)
00161             return s;
00162     if (code != ISO_PDU_DT)
00163     {
00164         error("expected DT, got 0x%x\n", code);
00165         return NULL;
00166     }
00167     return s;
00168 }
00169 
00170 /* Establish a connection up to the ISO layer */
00171 BOOL
00172 iso_connect(char *server, char *username)
00173 {
00174     uint8 code = 0;
00175 
00176     if (!tcp_connect(server))
00177         return False;
00178 
00179     iso_send_connection_request(username);
00180 
00181     if (iso_recv_msg(&code, NULL) == NULL)
00182         return False;
00183 
00184     if (code != ISO_PDU_CC)
00185     {
00186         error("expected CC, got 0x%x\n", code);
00187         tcp_disconnect();
00188         return False;
00189     }
00190 
00191     return True;
00192 }
00193 
00194 /* Establish a reconnection up to the ISO layer */
00195 BOOL
00196 iso_reconnect(char *server)
00197 {
00198     uint8 code = 0;
00199 
00200     if (!tcp_connect(server))
00201         return False;
00202 
00203     iso_send_msg(ISO_PDU_CR);
00204 
00205     if (iso_recv_msg(&code, NULL) == NULL)
00206         return False;
00207 
00208     if (code != ISO_PDU_CC)
00209     {
00210         error("expected CC, got 0x%x\n", code);
00211         tcp_disconnect();
00212         return False;
00213     }
00214 
00215     return True;
00216 }
00217 
00218 /* Disconnect from the ISO layer */
00219 void
00220 iso_disconnect(void)
00221 {
00222     iso_send_msg(ISO_PDU_DR);
00223     tcp_disconnect();
00224 }
00225 
00226 /* reset the state to support reconnecting */
00227 void
00228 iso_reset_state(void)
00229 {
00230     tcp_reset_state();
00231 }

Generated on Sun May 27 2012 04:17:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.