1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * Heartbeat PDUs
4  *
5  * Copyright 2014 Dell Software <Mike.McDonald@software.dell.com>
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #define WITH_DEBUG_HEARTBEAT
25 
26 #include "heartbeat.h"
27 
rdp_recv_heartbeat_packet(rdpRdp * rdp,wStream * s)28 int rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s)
29 {
30 	BYTE reserved;
31 	BYTE period;
32 	BYTE count1;
33 	BYTE count2;
34 	BOOL rc;
35 
36 	if (Stream_GetRemainingLength(s) < 4)
37 		return -1;
38 
39 	Stream_Read_UINT8(s, reserved); /* reserved (1 byte) */
40 	Stream_Read_UINT8(s, period);   /* period (1 byte) */
41 	Stream_Read_UINT8(s, count1);   /* count1 (1 byte) */
42 	Stream_Read_UINT8(s, count2);   /* count2 (1 byte) */
43 
44 	WLog_DBG(HEARTBEAT_TAG,
45 	         "received Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
46 	         period, count1, count2);
47 
48 	rc = IFCALLRESULT(TRUE, rdp->heartbeat->ServerHeartbeat, rdp->instance, period, count1, count2);
49 	if (!rc)
50 	{
51 		WLog_ERR(HEARTBEAT_TAG, "heartbeat->ServerHeartbeat callback failed!");
52 		return -1;
53 	}
54 
55 	return 0;
56 }
57 
freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer * peer,BYTE period,BYTE count1,BYTE count2)58 BOOL freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer* peer, BYTE period, BYTE count1, BYTE count2)
59 {
60 	rdpRdp* rdp = peer->context->rdp;
61 	wStream* s = rdp_message_channel_pdu_init(rdp);
62 
63 	if (!s)
64 		return FALSE;
65 
66 	Stream_Seek_UINT8(s);          /* reserved (1 byte) */
67 	Stream_Write_UINT8(s, period); /* period (1 byte) */
68 	Stream_Write_UINT8(s, count1); /* count1 (1 byte) */
69 	Stream_Write_UINT8(s, count2); /* count2 (1 byte) */
70 
71 	WLog_DBG(HEARTBEAT_TAG,
72 	         "sending Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
73 	         period, count1, count2);
74 
75 	if (!rdp_send_message_channel_pdu(rdp, s, SEC_HEARTBEAT))
76 		return FALSE;
77 
78 	return TRUE;
79 }
80 
heartbeat_new(void)81 rdpHeartbeat* heartbeat_new(void)
82 {
83 	rdpHeartbeat* heartbeat = (rdpHeartbeat*)calloc(1, sizeof(rdpHeartbeat));
84 
85 	if (heartbeat)
86 	{
87 	}
88 
89 	return heartbeat;
90 }
91 
heartbeat_free(rdpHeartbeat * heartbeat)92 void heartbeat_free(rdpHeartbeat* heartbeat)
93 {
94 	free(heartbeat);
95 }
96