• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LNN_HEARTBEAT_UTILS_H
17 #define LNN_HEARTBEAT_UTILS_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #include "softbus_common.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define HB_INVALID_TYPE_ID (-1)
29 #define HB_SHORT_UDID_HASH_LEN 8
30 #define HB_SHORT_UDID_HASH_HEX_LEN 16
31 #define HB_SHORT_ACCOUNT_HASH_LEN 2
32 #define HB_FSM_NAME_LEN 32
33 
34 #define HB_TIME_FACTOR (1000LL)
35 #define HB_SEND_ONCE_LEN (10 * HB_TIME_FACTOR)
36 #define HB_SEND_RELAY_LEN (4 * HB_TIME_FACTOR)
37 #define HB_CHECK_DELAY_LEN HB_SEND_ONCE_LEN
38 #define HB_CHECK_OFFLINE_TOLERANCE_LEN HB_SEND_ONCE_LEN
39 #define HB_NOTIFY_DEV_LOST_DELAY_LEN (2 * HB_TIME_FACTOR + 2 * HB_SEND_ONCE_LEN)
40 #define HB_REMOVE_REPEAD_RECV_LEN HB_SEND_ONCE_LEN
41 
42 #define HB_MAX_TYPE_COUNT 4
43 
44 // heartbeat type
45 #define HEARTBEAT_TYPE_MIN              (0x1L)
46 #define HEARTBEAT_TYPE_UDP              HEARTBEAT_TYPE_MIN
47 #define HEARTBEAT_TYPE_BLE_V0           (0x1L << 1)
48 #define HEARTBEAT_TYPE_BLE_V1           (0x1L << 2)
49 #define HEARTBEAT_TYPE_TCP_FLUSH        (0x1L << 3)
50 #define HEARTBEAT_TYPE_MAX              (0x1L << 4)
51 
52 typedef uint32_t LnnHeartbeatType;
53 
54 typedef enum {
55     STRATEGY_HB_SEND_SINGLE = 0,
56     STRATEGY_HB_SEND_FIXED_PERIOD,
57     STRATEGY_HB_SEND_ADJUSTABLE_PERIOD,
58     STRATEGY_HB_RECV_SINGLE = 3,
59     STRATEGY_HB_RECV_REMOVE_REPEAT,
60 } LnnHeartbeatStrategyType;
61 
62 typedef enum {
63     UPDATE_HB_INFO_MIN = 0,
64     UPDATE_HB_ACCOUNT_INFO,
65     UPDATE_HB_NETWORK_INFO,
66     UPDATE_HB_MAX_INFO,
67 } LnnHeartbeatUpdateInfoType;
68 
69 typedef bool (*VisitHbTypeCb)(LnnHeartbeatType *typeSet, LnnHeartbeatType eachType, void *data);
70 bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *data);
71 
72 LnnHeartbeatType LnnConvertConnAddrTypeToHbType(ConnectionAddrType addrType);
73 ConnectionAddrType LnnConvertHbTypeToConnAddrType(LnnHeartbeatType type);
74 int32_t LnnConvertHbTypeToId(LnnHeartbeatType type);
75 bool LnnHasActiveConnection(const char *networkId, ConnectionAddrType addrType);
76 bool LnnCheckSupportedHbType(LnnHeartbeatType *srcType, LnnHeartbeatType *dstType);
77 int32_t LnnGenerateHexStringHash(const unsigned char *str, char *hashStr, uint32_t len);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 #endif /* LNN_HEARTBEAT_UTILS_H */
83