/[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

revision 10 by matty, Tue Aug 15 10:23:24 2000 UTC revision 733 by jsorg71, Mon Jul 5 19:09:07 2004 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
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-2002
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 21  Line 21 
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23  /* Send a self-contained ISO PDU */  /* Send a self-contained ISO PDU */
24  static void iso_send_msg(uint8 code)  static void
25    iso_send_msg(uint8 code)
26  {  {
27          STREAM s;          STREAM s;
28    
29          s = tcp_init(11);          s = tcp_init(11);
30    
31          out_uint8(s, 3); /* version */          out_uint8(s, 3);        /* version */
32          out_uint8(s, 0); /* reserved */          out_uint8(s, 0);        /* reserved */
33          out_uint16_be(s, 11); /* length */          out_uint16_be(s, 11);   /* length */
34    
35          out_uint8(s, 6);  /* hdrlen */          out_uint8(s, 6);        /* hdrlen */
36          out_uint8(s, code);          out_uint8(s, code);
37          out_uint16(s, 0); /* dst_ref */          out_uint16(s, 0);       /* dst_ref */
38          out_uint16(s, 0); /* src_ref */          out_uint16(s, 0);       /* src_ref */
39          out_uint8(s, 0);  /* class */          out_uint8(s, 0);        /* class */
40    
41            s_mark_end(s);
42            tcp_send(s);
43    }
44    
45    static void
46    iso_send_connection_request(char *username)
47    {
48            STREAM s;
49            int length = 30 + strlen(username);
50    
51            s = tcp_init(length);
52    
53            out_uint8(s, 3);        /* version */
54            out_uint8(s, 0);        /* reserved */
55            out_uint16_be(s, length);       /* length */
56    
57            out_uint8(s, length - 5);       /* hdrlen */
58            out_uint8(s, ISO_PDU_CR);
59            out_uint16(s, 0);       /* dst_ref */
60            out_uint16(s, 0);       /* src_ref */
61            out_uint8(s, 0);        /* class */
62    
63            out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
64            out_uint8p(s, username, strlen(username));
65    
66            out_uint8(s, 0x0d);     /* Unknown */
67            out_uint8(s, 0x0a);     /* Unknown */
68    
69          s_mark_end(s);          s_mark_end(s);
70          tcp_send(s);          tcp_send(s);
71  }  }
72    
73  /* Receive a message on the ISO layer, return code */  /* Receive a message on the ISO layer, return code */
74  static STREAM iso_recv_msg(uint8 *code)  static STREAM
75    iso_recv_msg(uint8 * code, uint8 * rdpver)
76  {  {
77          STREAM s;          STREAM s;
78          uint16 length;          uint16 length;
79          uint8 version;          uint8 version;
80    
81          s = tcp_recv(4);          s = tcp_recv(NULL, 4);
82          if (s == NULL)          if (s == NULL)
83                  return False;                  return NULL;
   
84          in_uint8(s, version);          in_uint8(s, version);
85          if (version != 3)          if (rdpver != NULL)
86                    *rdpver = version;
87            if (version == 3)
88          {          {
89                  ERROR("TPKT v%d\n", version);                  in_uint8s(s, 1);        /* pad */
90                  return False;                  in_uint16_be(s, length);
91          }          }
92            else
93          in_uint8s(s, 1); /* pad */          {
94          in_uint16_be(s, length);                  in_uint8(s, length);
95                    if (length & 0x80)
96          s = tcp_recv(length - 4);                  {
97                            length &= ~0x80;
98                            next_be(s, length);
99                    }
100            }
101            s = tcp_recv(s, length - 4);
102          if (s == NULL)          if (s == NULL)
103                  return False;                  return NULL;
104            if (version != 3)
105          in_uint8s(s, 1); /* hdrlen */                  return s;
106            in_uint8s(s, 1);        /* hdrlen */
107          in_uint8(s, *code);          in_uint8(s, *code);
   
108          if (*code == ISO_PDU_DT)          if (*code == ISO_PDU_DT)
109          {          {
110                  in_uint8s(s, 1); /* eot */                  in_uint8s(s, 1);        /* eot */
111                  return s;                  return s;
112          }          }
113            in_uint8s(s, 5);        /* dst_ref, src_ref, class */
         in_uint8s(s, 5); /* dst_ref, src_ref, class */  
114          return s;          return s;
115  }  }
116    
117  /* Initialise ISO transport data packet */  /* Initialise ISO transport data packet */
118  STREAM iso_init(int length)  STREAM
119    iso_init(int length)
120  {  {
121          STREAM s;          STREAM s;
122    
# Line 91  STREAM iso_init(int length) Line 127  STREAM iso_init(int length)
127  }  }
128    
129  /* Send an ISO data PDU */  /* Send an ISO data PDU */
130  void iso_send(STREAM s)  void
131    iso_send(STREAM s)
132  {  {
133          uint16 length;          uint16 length;
134    
135          s_pop_layer(s, iso_hdr);          s_pop_layer(s, iso_hdr);
136          length = s->end - s->p;          length = s->end - s->p;
137    
138          out_uint8(s, 3); /* version */          out_uint8(s, 3);        /* version */
139          out_uint8(s, 0); /* reserved */          out_uint8(s, 0);        /* reserved */
140          out_uint16_be(s, length);          out_uint16_be(s, length);
141    
142          out_uint8(s, 2);  /* hdrlen */          out_uint8(s, 2);        /* hdrlen */
143          out_uint8(s, ISO_PDU_DT); /* code */          out_uint8(s, ISO_PDU_DT);       /* code */
144          out_uint8(s, 0x80); /* eot */          out_uint8(s, 0x80);     /* eot */
145    
146          tcp_send(s);          tcp_send(s);
147  }  }
148    
149  /* Receive ISO transport data packet */  /* Receive ISO transport data packet */
150  STREAM iso_recv()  STREAM
151    iso_recv(uint8 * rdpver)
152  {  {
153          STREAM s;          STREAM s;
154          uint8 code;          uint8 code = 0;
155    
156          s = iso_recv_msg(&code);          s = iso_recv_msg(&code, rdpver);
157          if ((s == NULL) || (code != ISO_PDU_DT))          if (s == NULL)
158                    return NULL;
159            if (rdpver != NULL)
160                    if (*rdpver != 3)
161                            return s;
162            if (code != ISO_PDU_DT)
163          {          {
164                  ERROR("expected DT, got %d\n", code);                  error("expected DT, got 0x%x\n", code);
165                  return False;                  return NULL;
166          }          }
   
167          return s;          return s;
168  }  }
169    
170  /* Establish a connection up to the ISO layer */  /* Establish a connection up to the ISO layer */
171  BOOL iso_connect(char *server)  BOOL
172    iso_connect(char *server, char *username)
173  {  {
174          uint8 code;          uint8 code = 0;
175    
176          if (!tcp_connect(server))          if (!tcp_connect(server))
177                  return False;                  return False;
178    
179          iso_send_msg(ISO_PDU_CR);          iso_send_connection_request(username);
180    
181            if (iso_recv_msg(&code, NULL) == NULL)
182                    return False;
183    
184          if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))          if (code != ISO_PDU_CC)
185          {          {
186                  ERROR("expected CC, got %d\n", code);                  error("expected CC, got 0x%x\n", code);
187                  tcp_disconnect();                  tcp_disconnect();
188                  return False;                  return False;
189          }          }
# Line 146  BOOL iso_connect(char *server) Line 192  BOOL iso_connect(char *server)
192  }  }
193    
194  /* Disconnect from the ISO layer */  /* Disconnect from the ISO layer */
195  void iso_disconnect()  void
196    iso_disconnect(void)
197  {  {
198          iso_send_msg(ISO_PDU_DR);          iso_send_msg(ISO_PDU_DR);
199          tcp_disconnect();          tcp_disconnect();

Legend:
Removed from v.10  
changed lines
  Added in v.733

  ViewVC Help
Powered by ViewVC 1.1.26