FreeRDP
heartbeat.c
1 
20 #include <freerdp/config.h>
21 
22 #include "heartbeat.h"
23 
24 state_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_DBG(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 
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 
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 
92 void heartbeat_free(rdpHeartbeat* heartbeat)
93 {
94  free(heartbeat);
95 }