FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
heartbeat.c
1
20#include <freerdp/config.h>
21
22#include "heartbeat.h"
23
24state_run_t rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s)
25{
26 BYTE period = 0;
27 BYTE count1 = 0;
28 BYTE count2 = 0;
29 BOOL rc = 0;
30
31 WINPR_ASSERT(rdp);
32 WINPR_ASSERT(rdp->context);
33 WINPR_ASSERT(s);
34
35 if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 4))
36 return STATE_RUN_FAILED;
37
38 Stream_Seek_UINT8(s); /* reserved (1 byte) */
39 Stream_Read_UINT8(s, period); /* period (1 byte) */
40 Stream_Read_UINT8(s, count1); /* count1 (1 byte) */
41 Stream_Read_UINT8(s, count2); /* count2 (1 byte) */
42
43 WLog_VRB(HEARTBEAT_TAG,
44 "received Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
45 period, count1, count2);
46
47 rc = IFCALLRESULT(TRUE, rdp->heartbeat->ServerHeartbeat, rdp->context->instance, period, count1,
48 count2);
49 if (!rc)
50 {
51 WLog_ERR(HEARTBEAT_TAG, "heartbeat->ServerHeartbeat callback failed!");
52 return STATE_RUN_FAILED;
53 }
54
55 return STATE_RUN_SUCCESS;
56}
57
58BOOL freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer* peer, BYTE period, BYTE count1, BYTE count2)
59{
60 rdpRdp* rdp = peer->context->rdp;
61 UINT16 sec_flags = 0;
62 wStream* s = rdp_message_channel_pdu_init(rdp, &sec_flags);
63
64 if (!s)
65 return FALSE;
66
67 Stream_Seek_UINT8(s); /* reserved (1 byte) */
68 Stream_Write_UINT8(s, period); /* period (1 byte) */
69 Stream_Write_UINT8(s, count1); /* count1 (1 byte) */
70 Stream_Write_UINT8(s, count2); /* count2 (1 byte) */
71
72 WLog_DBG(HEARTBEAT_TAG,
73 "sending Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
74 period, count1, count2);
75
76 if (!rdp_send_message_channel_pdu(rdp, s, sec_flags | SEC_HEARTBEAT))
77 return FALSE;
78
79 return TRUE;
80}
81
82rdpHeartbeat* heartbeat_new(void)
83{
84 rdpHeartbeat* heartbeat = (rdpHeartbeat*)calloc(1, sizeof(rdpHeartbeat));
85
86 if (heartbeat)
87 {
88 }
89
90 return heartbeat;
91}
92
93void heartbeat_free(rdpHeartbeat* heartbeat)
94{
95 free(heartbeat);
96}