libfreerdp-core: started TPDU encoding/decoding
This commit is contained in:
parent
071516187e
commit
37f3cff525
@ -30,6 +30,8 @@ set(LIBFREERDP_CORE_SRCS
|
|||||||
# credssp.h
|
# credssp.h
|
||||||
# ntlmssp.c
|
# ntlmssp.c
|
||||||
# ntlmssp.h
|
# ntlmssp.h
|
||||||
|
tpdu.c
|
||||||
|
tpdu.h
|
||||||
tpkt.c
|
tpkt.c
|
||||||
tpkt.h
|
tpkt.h
|
||||||
)
|
)
|
||||||
|
116
libfreerdp-core/tpdu.c
Normal file
116
libfreerdp-core/tpdu.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* FreeRDP: A Remote Desktop Protocol Client
|
||||||
|
* X.224 Transport Protocol Data Units (TPDUs)
|
||||||
|
*
|
||||||
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tpdu.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TPDUs are defined in:
|
||||||
|
*
|
||||||
|
* http://www.itu.int/rec/T-REC-X.224-199511-I/
|
||||||
|
* X.224: Information technology - Open Systems Interconnection - Protocol for providing the connection-mode transport service
|
||||||
|
*
|
||||||
|
* RDP uses only TPDUs of class 0, the "simple class" defined in section 8 of X.224
|
||||||
|
*
|
||||||
|
* TPDU Header
|
||||||
|
* ____________________ byte
|
||||||
|
* | |
|
||||||
|
* | LI | 1
|
||||||
|
* |____________________|
|
||||||
|
* | |
|
||||||
|
* | Code | 2
|
||||||
|
* |____________________|
|
||||||
|
* | |
|
||||||
|
* | | 3
|
||||||
|
* |_______DST-REF______|
|
||||||
|
* | |
|
||||||
|
* | | 4
|
||||||
|
* |____________________|
|
||||||
|
* | |
|
||||||
|
* | | 5
|
||||||
|
* |_______SRC-REF______|
|
||||||
|
* | |
|
||||||
|
* | | 6
|
||||||
|
* |____________________|
|
||||||
|
* | |
|
||||||
|
* | Class | 7
|
||||||
|
* |____________________|
|
||||||
|
* | ... |
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8
|
||||||
|
tpdu_read_header(STREAM* s, uint16 length)
|
||||||
|
{
|
||||||
|
uint8 li;
|
||||||
|
uint8 code;
|
||||||
|
|
||||||
|
stream_read_uint8(s, li); /* LI */
|
||||||
|
stream_read_uint8(s, code); /* Code */
|
||||||
|
|
||||||
|
if (code == X224_TPDU_DATA)
|
||||||
|
{
|
||||||
|
/* EOT (1 byte) */
|
||||||
|
stream_seek(s, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* DST-REF (2 bytes) */
|
||||||
|
/* SRC-REF (2 bytes) */
|
||||||
|
/* Class 0 (1 byte) */
|
||||||
|
stream_seek(s, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tpdu_write_header(STREAM* s, uint16 length, uint8 code)
|
||||||
|
{
|
||||||
|
stream_write_uint8(s, length - 5); /* LI */
|
||||||
|
stream_write_uint8(s, code); /* code */
|
||||||
|
|
||||||
|
if (code == X224_TPDU_DATA)
|
||||||
|
{
|
||||||
|
stream_write_uint8(s, 0x80); /* EOT */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stream_write_uint16(s, 0); /* DST-REF */
|
||||||
|
stream_write_uint16(s, 0); /* SRC-REF */
|
||||||
|
stream_write_uint8(s, 0); /* Class 0 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tpdu_write_connection_request(STREAM* s, uint16 length)
|
||||||
|
{
|
||||||
|
tpdu_write_header(s, length - 5, X224_TPDU_CONNECTION_REQUEST);
|
||||||
|
/* TODO: RDP_NEG_DATA */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tpdu_write_disconnect_request(STREAM* s, uint16 length)
|
||||||
|
{
|
||||||
|
tpdu_write_header(s, length - 5, X224_TPDU_DISCONNECT_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tpdu_write_data(STREAM* s, uint16 length)
|
||||||
|
{
|
||||||
|
tpdu_write_header(s, length - 5, X224_TPDU_DATA);
|
||||||
|
}
|
45
libfreerdp-core/tpdu.h
Normal file
45
libfreerdp-core/tpdu.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* FreeRDP: A Remote Desktop Protocol Client
|
||||||
|
* X.224 Transport Protocol Data Units (TPDUs)
|
||||||
|
*
|
||||||
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TPDU_H
|
||||||
|
#define __TPDU_H
|
||||||
|
|
||||||
|
#include <freerdp/utils/stream.h>
|
||||||
|
|
||||||
|
enum X224_TPDU_TYPE
|
||||||
|
{
|
||||||
|
X224_TPDU_CONNECTION_REQUEST = 0xE0,
|
||||||
|
X224_TPDU_CONNECTION_CONFIRM = 0xD0,
|
||||||
|
X224_TPDU_DISCONNECT_REQUEST = 0x80,
|
||||||
|
X224_TPDU_DATA = 0xF0,
|
||||||
|
X224_TPDU_ERROR = 0x70
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8
|
||||||
|
tpdu_read_header(STREAM* s, uint16 length);
|
||||||
|
void
|
||||||
|
tpdu_write_header(STREAM* s, uint16 length, uint8 code);
|
||||||
|
void
|
||||||
|
tpdu_write_connection_request(STREAM* s, uint16 length);
|
||||||
|
void
|
||||||
|
tpdu_write_disconnect_request(STREAM* s, uint16 length);
|
||||||
|
void
|
||||||
|
tpdu_write_data(STREAM* s, uint16 length);
|
||||||
|
|
||||||
|
#endif /* __TPDU_H */
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* FreeRDP: A Remote Desktop Protocol Client
|
* FreeRDP: A Remote Desktop Protocol Client
|
||||||
* TPKT Headers
|
* Transport Packets (TPKTs)
|
||||||
*
|
*
|
||||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
*
|
*
|
||||||
@ -17,10 +17,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "tpdu.h"
|
||||||
|
|
||||||
#include "tpkt.h"
|
#include "tpkt.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TPKT headers are defined in:
|
* TPKTs are defined in:
|
||||||
*
|
*
|
||||||
* http://tools.ietf.org/html/rfc1006/
|
* http://tools.ietf.org/html/rfc1006/
|
||||||
* RFC 1006 - ISO Transport Service on top of the TCP
|
* RFC 1006 - ISO Transport Service on top of the TCP
|
||||||
@ -43,13 +45,15 @@
|
|||||||
* | Length (LSB) | 4
|
* | Length (LSB) | 4
|
||||||
* |____________________|
|
* |____________________|
|
||||||
* | |
|
* | |
|
||||||
* | TPDU | 5 - ?
|
* | X.224 TPDU | 5 - ?
|
||||||
* ....
|
* ....
|
||||||
|
*
|
||||||
|
* A TPKT header is of fixed length 4, and the following X.224 TPDU is at least three bytes long.
|
||||||
|
* Therefore, the minimum TPKT length is 7, and the maximum TPKT length is 65535. Because the TPKT
|
||||||
|
* length includes the TPKT header (4 bytes), the maximum X.224 TPDU length is 65531.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <freerdp/utils/stream.h>
|
uint16
|
||||||
|
|
||||||
int
|
|
||||||
tpkt_read_header(STREAM* s)
|
tpkt_read_header(STREAM* s)
|
||||||
{
|
{
|
||||||
uint8 version;
|
uint8 version;
|
||||||
@ -65,7 +69,7 @@ tpkt_read_header(STREAM* s)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* not a TPKT header */
|
/* not a TPKT header */
|
||||||
length = -1;
|
length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* FreeRDP: A Remote Desktop Protocol Client
|
* FreeRDP: A Remote Desktop Protocol Client
|
||||||
* TPKT Headers
|
* Transport Packets (TPKTs)
|
||||||
*
|
*
|
||||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
*
|
*
|
||||||
@ -22,9 +22,8 @@
|
|||||||
|
|
||||||
#include <freerdp/utils/stream.h>
|
#include <freerdp/utils/stream.h>
|
||||||
|
|
||||||
int
|
uint16
|
||||||
tpkt_read_header(STREAM* s);
|
tpkt_read_header(STREAM* s);
|
||||||
|
|
||||||
void
|
void
|
||||||
tpkt_write_header(STREAM* s, int length);
|
tpkt_write_header(STREAM* s, int length);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user