2
* FreeRDP: A Remote Desktop Protocol Implementation
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.
29
* TPDUs are defined in:
31
* http://www.itu.int/rec/T-REC-X.224-199511-I/
32
* X.224: Information technology - Open Systems Interconnection - Protocol for providing the connection-mode transport service
34
* RDP uses only TPDUs of class 0, the "simple class" defined in section 8 of X.224
37
* ____________________ byte
40
* |____________________|
43
* |____________________|
46
* |_______DST-REF______|
49
* |____________________|
52
* |_______SRC-REF______|
55
* |____________________|
58
* |____________________|
65
* @param code variable pointer to receive TPDU code
66
* @return TPDU length indicator (LI)
69
BOOL tpdu_read_header(wStream* s, BYTE* code, BYTE *li)
71
if(Stream_GetRemainingLength(s) < 3)
74
Stream_Read_UINT8(s, *li); /* LI */
75
Stream_Read_UINT8(s, *code); /* Code */
77
if (*code == X224_TPDU_DATA)
84
/* DST-REF (2 bytes) */
85
/* SRC-REF (2 bytes) */
86
/* Class 0 (1 byte) */
87
return Stream_SafeSeek(s, 5);
95
* @param length length
96
* @param code TPDU code
99
void tpdu_write_header(wStream* s, UINT16 length, BYTE code)
101
Stream_Write_UINT8(s, length); /* LI */
102
Stream_Write_UINT8(s, code); /* code */
104
if (code == X224_TPDU_DATA)
106
Stream_Write_UINT8(s, 0x80); /* EOT */
110
Stream_Write_UINT16(s, 0); /* DST-REF */
111
Stream_Write_UINT16(s, 0); /* SRC-REF */
112
Stream_Write_UINT8(s, 0); /* Class 0 */
117
* Read Connection Request TPDU
119
* @return length indicator (LI)
122
BOOL tpdu_read_connection_request(wStream* s, BYTE *li)
126
if(!tpdu_read_header(s, &code, li))
129
if (code != X224_TPDU_CONNECTION_REQUEST)
131
fprintf(stderr, "Error: expected X224_TPDU_CONNECTION_REQUEST\n");
139
* Write Connection Request TPDU.
141
* @param length TPDU length
144
void tpdu_write_connection_request(wStream* s, UINT16 length)
146
tpdu_write_header(s, length, X224_TPDU_CONNECTION_REQUEST);
150
* Read Connection Confirm TPDU.
152
* @return length indicator (LI)
155
BOOL tpdu_read_connection_confirm(wStream* s, BYTE *li)
159
if(!tpdu_read_header(s, &code, li))
162
if (code != X224_TPDU_CONNECTION_CONFIRM)
164
fprintf(stderr, "Error: expected X224_TPDU_CONNECTION_CONFIRM\n");
168
return (Stream_GetRemainingLength(s) >= *li);
172
* Write Connection Confirm TPDU.
174
* @param length TPDU length
177
void tpdu_write_connection_confirm(wStream* s, UINT16 length)
179
tpdu_write_header(s, length, X224_TPDU_CONNECTION_CONFIRM);
183
* Write Disconnect Request TPDU.
185
* @param length TPDU length
188
void tpdu_write_disconnect_request(wStream* s, UINT16 length)
190
tpdu_write_header(s, length, X224_TPDU_DISCONNECT_REQUEST);
198
void tpdu_write_data(wStream* s)
200
tpdu_write_header(s, 2, X224_TPDU_DATA);
208
BOOL tpdu_read_data(wStream* s, UINT16 *LI)
213
if(!tpdu_read_header(s, &code, &li))
216
if (code != X224_TPDU_DATA)