2 * FreeRDP: A Remote Desktop Protocol Client
3 * X.224 Transport Protocol Data Units (TPDUs)
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 * TPDUs are defined in:
27 * http://www.itu.int/rec/T-REC-X.224-199511-I/
28 * X.224: Information technology - Open Systems Interconnection - Protocol for providing the connection-mode transport service
30 * RDP uses only TPDUs of class 0, the "simple class" defined in section 8 of X.224
33 * ____________________ byte
36 * |____________________|
39 * |____________________|
42 * |_______DST-REF______|
45 * |____________________|
48 * |_______SRC-REF______|
51 * |____________________|
54 * |____________________|
61 * @param code variable pointer to receive TPDU code
62 * @return TPDU length indicator (LI)
66 tpdu_read_header(STREAM* s, uint8* code)
70 stream_read_uint8(s, li); /* LI */
71 stream_read_uint8(s, *code); /* Code */
73 if (*code == X224_TPDU_DATA)
80 /* DST-REF (2 bytes) */
81 /* SRC-REF (2 bytes) */
82 /* Class 0 (1 byte) */
92 * @param length length
93 * @param code TPDU code
97 tpdu_write_header(STREAM* s, uint16 length, uint8 code)
99 stream_write_uint8(s, length); /* LI */
100 stream_write_uint8(s, code); /* code */
102 if (code == X224_TPDU_DATA)
104 stream_write_uint8(s, 0x80); /* EOT */
108 stream_write_uint16(s, 0); /* DST-REF */
109 stream_write_uint16(s, 0); /* SRC-REF */
110 stream_write_uint8(s, 0); /* Class 0 */
115 * Read Connection Request TPDU
117 * @return length indicator (LI)
120 uint8 tpdu_read_connection_request(STREAM* s)
125 li = tpdu_read_header(s, &code);
127 if (code != X224_TPDU_CONNECTION_REQUEST)
129 printf("Error: expected X224_TPDU_CONNECTION_REQUEST\n");
137 * Write Connection Request TPDU.
139 * @param length TPDU length
143 tpdu_write_connection_request(STREAM* s, uint16 length)
145 tpdu_write_header(s, length, X224_TPDU_CONNECTION_REQUEST);
149 * Read Connection Confirm TPDU.
151 * @return length indicator (LI)
155 tpdu_read_connection_confirm(STREAM* s)
160 li = tpdu_read_header(s, &code);
162 if (code != X224_TPDU_CONNECTION_CONFIRM)
164 printf("Error: expected X224_TPDU_CONNECTION_CONFIRM\n");
172 * Write Connection Confirm TPDU.
174 * @param length TPDU length
178 tpdu_write_connection_confirm(STREAM* s, uint16 length)
180 tpdu_write_header(s, length, X224_TPDU_CONNECTION_CONFIRM);
184 * Write Disconnect Request TPDU.
186 * @param length TPDU length
190 tpdu_write_disconnect_request(STREAM* s, uint16 length)
192 tpdu_write_header(s, length, X224_TPDU_DISCONNECT_REQUEST);
201 tpdu_write_data(STREAM* s)
203 tpdu_write_header(s, 2, X224_TPDU_DATA);
212 tpdu_read_data(STREAM* s)
217 li = tpdu_read_header(s, &code);
219 if (code != X224_TPDU_DATA)