/[rdesktop]/sourceforge.net/trunk/rdesktop/iso.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/iso.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by matty, Tue Jul 25 12:34:29 2000 UTC revision 30 by matty, Fri Sep 14 13:51:38 2001 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - ISO layer     Protocol services - ISO layer
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     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     it under the terms of the GNU General Public License as published by
# Line 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include "includes.h"  #include "rdesktop.h"
22    
23  /* Establish a connection up to the ISO layer */  /* Send a self-contained ISO PDU */
24  HCONN iso_connect(char *server)  static void
25    iso_send_msg(uint8 code)
26  {  {
27          HCONN conn;          STREAM s;
         uint8 code;  
28    
29          if ((conn = tcp_connect(server)) == NULL)          s = tcp_init(11);
                 return NULL;  
30    
31          iso_send_msg(conn, ISO_PDU_CR);          out_uint8(s, 3);        /* version */
32            out_uint8(s, 0);        /* reserved */
33            out_uint16_be(s, 11);   /* length */
34    
35          if (!iso_recv_msg(conn, &code) || (code != ISO_PDU_CC))          out_uint8(s, 6);        /* hdrlen */
36          {          out_uint8(s, code);
37                  ERROR("ISO error, expected CC\n");          out_uint16(s, 0);       /* dst_ref */
38                  tcp_disconnect(conn);          out_uint16(s, 0);       /* src_ref */
39                  return NULL;          out_uint8(s, 0);        /* class */
         }  
40    
41          return conn;          s_mark_end(s);
42  }          tcp_send(s);
   
 /* Disconnect from the ISO layer */  
 void iso_disconnect(HCONN conn)  
 {  
         iso_send_msg(conn, ISO_PDU_DR);  
         tcp_disconnect(conn);  
43  }  }
44    
45  /* Send self-contained ISO message identified by code */  /* Receive a message on the ISO layer, return code */
46  BOOL iso_send_msg(HCONN conn, uint8 code)  static STREAM
47    iso_recv_msg(uint8 *code)
48  {  {
49          TPKT tpkt;          STREAM s;
50          TPDU tpdu;          uint16 length;
51            uint8 version;
52    
53          iso_make_tpkt(&tpkt, 11);          s = tcp_recv(4);
54          iso_io_tpkt(&conn->out, &tpkt);          if (s == NULL)
55          iso_make_tpdu(&tpdu, code);                  return False;
         iso_io_tpdu(&conn->out, &tpdu);  
         MARK_END(conn->out);  
         return tcp_send(conn);  
 }  
56    
57  /* Receive a message on the ISO layer, return code */          in_uint8(s, version);
58  BOOL iso_recv_msg(HCONN conn, uint8 *code)          if (version != 3)
59  {          {
60          TPDU tpdu;                  error("TPKT v%d\n", version);
61          TPKT tpkt;                  return False;
62          BOOL res;          }
   
         res = tcp_recv(conn, 4);  
         res = res ? iso_io_tpkt(&conn->in, &tpkt) : False;  
         res = res ? tcp_recv(conn, tpkt.length - 4) : False;  
         res = res ? iso_io_tpdu(&conn->in, &tpdu) : False;  
63    
64          *code = tpdu.code;          in_uint8s(s, 1);        /* pad */
65          return res;          in_uint16_be(s, length);
 }  
66    
67  /* Initialise ISO transport data packet */          s = tcp_recv(length - 4);
68  void iso_init(struct connection *conn)          if (s == NULL)
69  {                  return False;
         PUSH_LAYER(conn->out, iso_offset, 7);  
 }  
70    
71  /* Receive ISO transport data packet */          in_uint8s(s, 1);        /* hdrlen */
72  BOOL iso_recv(HCONN conn)          in_uint8(s, *code);
 {  
         uint8 code;  
73    
74          if (!iso_recv_msg(conn, &code) || (code != ISO_PDU_DT))          if (*code == ISO_PDU_DT)
75          {          {
76                  ERROR("ISO error, expected DT\n");                  in_uint8s(s, 1);        /* eot */
77                  return False;                  return s;
78          }          }
79    
80          return True;          in_uint8s(s, 5);        /* dst_ref, src_ref, class */
81            return s;
82  }  }
83    
84  /* Receive ISO transport data packet */  /* Initialise ISO transport data packet */
85  BOOL iso_send(HCONN conn)  STREAM
86    iso_init(int length)
87  {  {
88          TPKT tpkt;          STREAM s;
89          TPDU tpdu;  
90            s = tcp_init(length + 7);
91            s_push_layer(s, iso_hdr, 7);
92    
93          POP_LAYER(conn->out, iso_offset);          return s;
         iso_make_tpkt(&tpkt, conn->out.end);  
         iso_io_tpkt(&conn->out, &tpkt);  
         iso_make_tpdu(&tpdu, ISO_PDU_DT);  
         iso_io_tpdu(&conn->out, &tpdu);  
         return tcp_send(conn);  
94  }  }
95    
96  /* Initialise a TPKT structure */  /* Send an ISO data PDU */
97  void iso_make_tpkt(TPKT *tpkt, int length)  void
98    iso_send(STREAM s)
99  {  {
100          tpkt->version = 3;          uint16 length;
101          tpkt->reserved = 0;  
102          tpkt->length = length;          s_pop_layer(s, iso_hdr);
103            length = s->end - s->p;
104    
105            out_uint8(s, 3);        /* version */
106            out_uint8(s, 0);        /* reserved */
107            out_uint16_be(s, length);
108    
109            out_uint8(s, 2);        /* hdrlen */
110            out_uint8(s, ISO_PDU_DT);       /* code */
111            out_uint8(s, 0x80);     /* eot */
112    
113            tcp_send(s);
114  }  }
115    
116  /* Marshall/demarshall a TPKT structure */  /* Receive ISO transport data packet */
117  BOOL iso_io_tpkt(STREAM s, TPKT *tpkt)  STREAM
118    iso_recv()
119  {  {
120          if (!prs_io_uint8(s, &tpkt->version))          STREAM s;
121                  return False;          uint8 code;
122    
123          if (tpkt->version != 3)          s = iso_recv_msg(&code);
124            if ((s == NULL) || (code != ISO_PDU_DT))
125          {          {
126                  ERROR("Wrong TPKT version %d\n", tpkt->version);                  error("expected DT, got %d\n", code);
127                  return False;                  return False;
128          }          }
129    
130          if (!prs_io_uint8 (s, &tpkt->reserved))          return s;
                 return False;  
   
         if (!msb_io_uint16(s, &tpkt->length))  
                 return False;  
   
         return True;  
131  }  }
132    
133  /* Initialise a TPDU structure */  /* Establish a connection up to the ISO layer */
134  void iso_make_tpdu(TPDU *tpdu, uint8 code)  BOOL
135    iso_connect(char *server)
136  {  {
137          tpdu->hlen = (code == ISO_PDU_DT) ? 2 : 6;          uint8 code;
         tpdu->code = code;  
         tpdu->dst_ref = tpdu->src_ref = 0;  
         tpdu->class = 0;  
         tpdu->eot = 0x80;  
 }  
138    
139  /* Marshall/demarshall a TPDU structure */          if (!tcp_connect(server))
140  BOOL iso_io_tpdu(STREAM s, TPDU *tpdu)                  return False;
 {  
         BOOL res = True;  
141    
142          res = res ? prs_io_uint8 (s, &tpdu->hlen) : False;          iso_send_msg(ISO_PDU_CR);
         res = res ? prs_io_uint8 (s, &tpdu->code) : False;  
143    
144          if (tpdu->code == ISO_PDU_DT)          if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))
         {  
                 res = res ? prs_io_uint8(s, &tpdu->eot) : False;  
         }  
         else  
145          {          {
146                  res = res ? msb_io_uint16(s, &tpdu->dst_ref) : False;                  error("expected CC, got %d\n", code);
147                  res = res ? msb_io_uint16(s, &tpdu->src_ref) : False;                  tcp_disconnect();
148                  res = res ? prs_io_uint8 (s, &tpdu->class  ) : False;                  return False;
149          }          }
150    
151          return res;          return True;
152    }
153    
154    /* Disconnect from the ISO layer */
155    void
156    iso_disconnect()
157    {
158            iso_send_msg(ISO_PDU_DR);
159            tcp_disconnect();
160  }  }

Legend:
Removed from v.9  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26