/[rdesktop]/jpeg/rdesktop/trunk/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 /jpeg/rdesktop/trunk/iso.c

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

sourceforge.net/branches/RDESKTOP/rdesktop/iso.c revision 3 by matty, Wed May 10 07:36:34 2000 UTC sourceforge.net/trunk/rdesktop/iso.c revision 64 by astrand, Thu Jul 18 16:38:31 2002 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);
30                  return NULL;  
31            out_uint8(s, 3);        /* version */
32            out_uint8(s, 0);        /* reserved */
33            out_uint16_be(s, 11);   /* length */
34    
35            out_uint8(s, 6);        /* hdrlen */
36            out_uint8(s, code);
37            out_uint16(s, 0);       /* dst_ref */
38            out_uint16(s, 0);       /* src_ref */
39            out_uint8(s, 0);        /* class */
40    
41            s_mark_end(s);
42            tcp_send(s);
43    }
44    
45          iso_send_msg(conn, ISO_PDU_CR);  /* Receive a message on the ISO layer, return code */
46    static STREAM
47    iso_recv_msg(uint8 * code)
48    {
49            STREAM s;
50            uint16 length;
51            uint8 version;
52    
53            s = tcp_recv(4);
54            if (s == NULL)
55                    return NULL;
56    
57          if (!iso_recv_msg(conn, &code) || (code != ISO_PDU_CC))          in_uint8(s, version);
58            if (version != 3)
59          {          {
60                  fprintf(stderr, "ISO error, expected CC\n");                  error("TPKT v%d\n", version);
                 tcp_disconnect(conn);  
61                  return NULL;                  return NULL;
62          }          }
63    
64          return conn;          in_uint8s(s, 1);        /* pad */
65  }          in_uint16_be(s, length);
66    
67  /* Disconnect from the ISO layer */          s = tcp_recv(length - 4);
68  void iso_disconnect(HCONN conn)          if (s == NULL)
69  {                  return NULL;
         iso_send_msg(conn, ISO_PDU_DR);  
         tcp_disconnect(conn);  
 }  
70    
71  /* Send self-contained ISO message identified by code */          in_uint8s(s, 1);        /* hdrlen */
72  BOOL iso_send_msg(HCONN conn, uint8 code)          in_uint8(s, *code);
 {  
         TPKT tpkt;  
         TPDU tpdu;  
73    
74          iso_make_tpkt(&tpkt, 11);          if (*code == ISO_PDU_DT)
75          iso_io_tpkt(&conn->out, &tpkt);          {
76          iso_make_tpdu(&tpdu, code);                  in_uint8s(s, 1);        /* eot */
77          iso_io_tpdu(&conn->out, &tpdu);                  return s;
78          MARK_END(conn->out);          }
79          return tcp_send(conn);  
80            in_uint8s(s, 5);        /* dst_ref, src_ref, class */
81            return s;
82  }  }
83    
84  /* Receive a message on the ISO layer, return code */  /* Initialise ISO transport data packet */
85  BOOL iso_recv_msg(HCONN conn, uint8 *code)  STREAM
86    iso_init(int length)
87  {  {
88          TPDU tpdu;          STREAM s;
89          TPKT tpkt;  
90          BOOL res;          s = tcp_init(length + 7);
91            s_push_layer(s, iso_hdr, 7);
         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;  
92    
93          *code = tpdu.code;          return s;
         return res;  
94  }  }
95    
96  /* Initialise ISO transport data packet */  /* Send an ISO data PDU */
97  void iso_init(struct connection *conn)  void
98    iso_send(STREAM s)
99  {  {
100          PUSH_LAYER(conn->out, iso_offset, 7);          uint16 length;
101    
102            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  /* Receive ISO transport data packet */  /* Receive ISO transport data packet */
117  BOOL iso_recv(HCONN conn)  STREAM
118    iso_recv()
119  {  {
120            STREAM s;
121          uint8 code;          uint8 code;
122    
123          if (!iso_recv_msg(conn, &code) || (code != ISO_PDU_DT))          s = iso_recv_msg(&code);
124            if (s == NULL)
125                    return NULL;
126    
127            if (code != ISO_PDU_DT)
128          {          {
129                  fprintf(stderr, "ISO error, expected DT\n");                  error("expected DT, got 0x%x\n", code);
130                  return False;                  return NULL;
131          }          }
132    
133          return True;          return s;
134  }  }
135    
136  /* Receive ISO transport data packet */  /* Establish a connection up to the ISO layer */
137  BOOL iso_send(HCONN conn)  BOOL
138    iso_connect(char *server)
139  {  {
140          TPKT tpkt;          uint8 code;
         TPDU tpdu;  
141    
142          POP_LAYER(conn->out, iso_offset);          if (!tcp_connect(server))
143          iso_make_tpkt(&tpkt, conn->out.end);                  return False;
         iso_io_tpkt(&conn->out, &tpkt);  
         iso_make_tpdu(&tpdu, ISO_PDU_DT);  
         iso_io_tpdu(&conn->out, &tpdu);  
         return tcp_send(conn);  
 }  
144    
145  /* Initialise a TPKT structure */          iso_send_msg(ISO_PDU_CR);
 void iso_make_tpkt(TPKT *tpkt, int length)  
 {  
         tpkt->version = 3;  
         tpkt->reserved = 0;  
         tpkt->length = length;  
 }  
146    
147  /* Marshall/demarshall a TPKT structure */          if (iso_recv_msg(&code) == NULL)
 BOOL iso_io_tpkt(STREAM s, TPKT *tpkt)  
 {  
         if (!prs_io_uint8(s, &tpkt->version))  
148                  return False;                  return False;
149    
150          if (tpkt->version != 3)          if (code != ISO_PDU_CC)
151          {          {
152                  fprintf(stderr, "Wrong TPKT version %d\n", tpkt->version);                  error("expected CC, got 0x%x\n", code);
153                    tcp_disconnect();
154                  return False;                  return False;
155          }          }
156    
         if (!prs_io_uint8 (s, &tpkt->reserved))  
                 return False;  
   
         if (!msb_io_uint16(s, &tpkt->length))  
                 return False;  
   
157          return True;          return True;
158  }  }
159    
160  /* Initialise a TPDU structure */  /* Disconnect from the ISO layer */
161  void iso_make_tpdu(TPDU *tpdu, uint8 code)  void
162  {  iso_disconnect()
         tpdu->hlen = (code == ISO_PDU_DT) ? 2 : 6;  
         tpdu->code = code;  
         tpdu->dst_ref = tpdu->src_ref = 0;  
         tpdu->class = 0;  
         tpdu->eot = 0x80;  
 }  
   
 /* Marshall/demarshall a TPDU structure */  
 BOOL iso_io_tpdu(STREAM s, TPDU *tpdu)  
163  {  {
164          BOOL res = True;          iso_send_msg(ISO_PDU_DR);
165            tcp_disconnect();
         res = res ? prs_io_uint8 (s, &tpdu->hlen) : False;  
         res = res ? prs_io_uint8 (s, &tpdu->code) : False;  
   
         if (tpdu->code == ISO_PDU_DT)  
         {  
                 res = res ? prs_io_uint8(s, &tpdu->eot) : False;  
         }  
         else  
         {  
                 res = res ? msb_io_uint16(s, &tpdu->dst_ref) : False;  
                 res = res ? msb_io_uint16(s, &tpdu->src_ref) : False;  
                 res = res ? prs_io_uint8 (s, &tpdu->class  ) : False;  
         }  
   
         return res;  
166  }  }

Legend:
Removed from v.3  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26