• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_HEARTBETA_UTILS_STRUCT_H
17 #define LNN_HEARTBETA_UTILS_STRUCT_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #include "data_level_inner.h"
23 #include "softbus_common.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define HB_INVALID_TYPE_ID         (-1)
30 #define HB_SHORT_UUID_LEN          2
31 #define USERID_CHECKSUM_LEN        4
32 #define USERID_LEN                 4
33 #define HB_ADV_POWER_LEN           1
34 #define HB_SHORT_UDID_HASH_LEN     8
35 #define HB_SHORT_UDID_HASH_HEX_LEN 16
36 #define HB_SHORT_ACCOUNT_HASH_LEN  2
37 #define HB_FSM_NAME_LEN            32
38 #define HB_SLE_SHORT_UDID_HASH_LEN 6
39 
40 #define HB_TIME_FACTOR_TWO_HUNDRED_MS         (200LL)
41 #define HB_TIME_FACTOR                        (1000LL)
42 #define HB_START_DELAY_LEN                    (10 * HB_TIME_FACTOR)
43 #define HB_CLOUD_SYNC_DELAY_LEN               (13 * HB_TIME_FACTOR)
44 #define HB_SEND_ONCE_LEN                      (10 * HB_TIME_FACTOR)
45 #define HB_SEND_RELAY_LEN                     (1 * HB_TIME_FACTOR)
46 #define HB_CHECK_DELAY_LEN                    HB_SEND_ONCE_LEN
47 #define HB_CHECK_OFFLINE_TOLERANCE_LEN        HB_SEND_ONCE_LEN
48 #define HB_NOTIFY_DEV_LOST_DELAY_LEN          (2 * HB_TIME_FACTOR + 2 * HB_SEND_ONCE_LEN)
49 #define HB_NOTIFY_MASTER_NODE_DELAY_LEN       (2 * HB_TIME_FACTOR + HB_SEND_ONCE_LEN)
50 #define HB_REPEAD_RECV_THRESHOLD              (1 * HB_TIME_FACTOR)
51 #define HB_REPEAD_JOIN_LNN_THRESHOLD          (2 * HB_TIME_FACTOR)
52 #define HB_REPEAD_RECV_THRESHOLD_MULTI_DEVICE (3 * HB_TIME_FACTOR)
53 #define HB_OFFLINE_TIME                       (5 * 60 * HB_TIME_FACTOR + 2 * HB_SEND_ONCE_LEN)
54 #define HB_SCREEN_ON_COAP_TIME                (3 * HB_TIME_FACTOR)
55 #define HB_RESTART_LEN                        (3 * HB_TIME_FACTOR)
56 #define HB_PERIOD_DUMP_LOCAL_INFO_LEN         (5 * 60 * HB_TIME_FACTOR)
57 #define HB_SEND_RELAY_LEN_ONCE                (3 * HB_TIME_FACTOR)
58 #define HB_SEND_DIRECT_LEN_ONCE               (5 * HB_TIME_FACTOR)
59 #define HB_OFFLINE_PERIOD                     2
60 #define HB_SEND_SLE_HB_MODE                   (1 * HB_TIME_FACTOR + 4 * HB_TIME_FACTOR_TWO_HUNDRED_MS)
61 #define HB_SLE_OFFLINE_TIME                   (9 * HB_TIME_FACTOR + 3 * HB_TIME_FACTOR_TWO_HUNDRED_MS)
62 
63 #define HB_SEND_EACH_SEPARATELY_LEN (2 * HB_TIME_FACTOR) // Split and send a single heartbeat
64 #define HB_SEND_SEPARATELY_CNT      (HB_SEND_ONCE_LEN / HB_SEND_EACH_SEPARATELY_LEN)
65 
66 #define HB_MAX_TYPE_COUNT         7
67 #define HB_MULTI_DEVICE_THRESHOLD 8
68 
69 // heartbeat type
70 typedef uint32_t LnnHeartbeatType;
71 #define HEARTBEAT_TYPE_MIN       (0x1L)
72 #define HEARTBEAT_TYPE_UDP       HEARTBEAT_TYPE_MIN
73 #define HEARTBEAT_TYPE_BLE_V0    (0x1L << 1)
74 #define HEARTBEAT_TYPE_BLE_V1    (0x1L << 2)
75 #define HEARTBEAT_TYPE_TCP_FLUSH (0x1L << 3)
76 #define HEARTBEAT_TYPE_BLE_V3    (0x1L << 4)
77 #define HEARTBEAT_TYPE_BLE_V4    (0x1L << 5) // for heartbeat to lowpower
78 #define HEARTBEAT_TYPE_SLE       (0x1L << 6) // for heartbeat to lowpower
79 #define HEARTBEAT_TYPE_MAX       (0x1L << 7)
80 #define HEARTBEAT_TYPE_INVALID   0xFFFF
81 
82 #define NORMAL_STRATEGY               1
83 #define HIGH_PERFORMANCE_STRATEGY     2
84 #define ONCE_STRATEGY                 3
85 #define SUSPEND_STRATEGY              4
86 #define LOW_CONTINUOUS_ADVERTISE      7
87 #define ADJUST_INTERVAL_STRATEGY      8
88 #define REQUEST_DISABLE_BLE_DISCOVERY 100
89 #define REQUEST_ENABLE_BLE_DISCOVERY  101
90 #define SAME_ACCOUNT_REQUEST_DISABLE_BLE_DISCOVERY 102
91 #define SAME_ACCOUNT_REQUEST_ENABLE_BLE_DISCOVERY  103
92 
93 #define MIN_DISABLE_BLE_DISCOVERY_TIME 1000
94 #define MAX_DISABLE_BLE_DISCOVERY_TIME 15000
95 
96 #define BT_ADDR_LEN         6
97 #define BT_MAC_HASH_LEN     8
98 #define BT_MAC_HASH_STR_LEN 17
99 
100 #define CHECK_TRUSTED_RELATION_TIME 5000
101 
102 #define HB_ADV_RANDOM_TIME_50  50
103 #define HB_ADV_RANDOM_TIME_100 100
104 #define HB_ADV_RANDOM_TIME_200 200
105 #define HB_ADV_RANDOM_TIME_300 300
106 #define HB_ADV_RANDOM_TIME_500 500
107 #define HB_ADV_RANDOM_TIME_600 600
108 #define HB_ADV_RANDOM_TIME_1000 1000
109 
110 #define HB_USER_SWITCH_CALLER_ID "HEARTBEAT_USER_SWITCH_CALLER_ID"
111 
112 typedef struct {
113     bool isScreenOn;
114     bool isLocked;
115     bool isPlugged;
116     bool isOffline;
117     uint8_t netcap;
118 } SleDeviceInfo;
119 
120 typedef enum {
121     STRATEGY_HB_SEND_SINGLE = 0,
122     STRATEGY_HB_SEND_FIXED_PERIOD,
123     STRATEGY_HB_SEND_ADJUSTABLE_PERIOD,
124     STRATEGY_HB_RECV_SINGLE = 3,
125     STRATEGY_HB_RECV_REMOVE_REPEAT,
126     STRATEGY_HB_SEND_DIRECT,
127 } LnnHeartbeatStrategyType;
128 
129 typedef enum {
130     UPDATE_HB_INFO_MIN = 0,
131     UPDATE_HB_ACCOUNT_INFO,
132     UPDATE_HB_NETWORK_INFO,
133     UPDATE_SCREEN_STATE_INFO,
134     UPDATE_BT_STATE_OPEN_INFO,
135     UPDATE_BT_STATE_CLOSE_INFO,
136     UPDATE_BR_TURN_ON_INFO,
137     UPDATE_HB_MAX_INFO,
138 } LnnHeartbeatUpdateInfoType;
139 
140 typedef struct {
141     uint8_t capabiltiy;
142     uint8_t shortUuid[HB_SHORT_UUID_LEN];
143     uint8_t userIdCheckSum[USERID_CHECKSUM_LEN];
144     uint8_t advUserId[USERID_LEN];
145     uint8_t hbVersion;
146     bool isScreenOn;
147     int16_t stateVersion;
148     uint16_t staticLength;
149     uint16_t staticLevel;
150     uint16_t switchLength;
151     uint32_t switchLevel;
152     int32_t preferChannel;
153     int8_t advPower;
154 } HbRespData;
155 
156 typedef enum {
157     BIT_SUPPORT_DIRECT_TRIGGER = 0,
158     BIT_SUPPORT_SCREEN_STATUS = 1,
159 } HeartbeatCapability;
160 
161 #define STATE_VERSION_INVALID (-1)
162 #define ENABLE_COC_CAP        (1 << 0)
163 #define P2P_GO                (1 << 1)
164 #define P2P_GC                (1 << 2)
165 #define ENABLE_WIFI_CAP       (1 << 3)
166 #define DISABLE_BR_CAP        (1 << 4)
167 #define BLE_TRIGGER_HML       (1 << 5)
168 #define ENABLE_SLE_CAP        (1 << 6)
169 
170 typedef struct {
171     int32_t (*onDataLevelChanged)(const char *networkId, const DataLevelInfo *dataLevelInfo);
172 } IDataLevelChangeCallback;
173 
174 typedef struct {
175     void (*onRangeResult)(const RangeResultInnerInfo *info);
176     void (*onRangeStateChange)(const RangeState state);
177 } IBleRangeInnerCallback;
178 
179 typedef bool (*VisitHbTypeCb)(LnnHeartbeatType *typeSet, LnnHeartbeatType eachType, void *data);
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 #endif /*LNN_HEARTBETA_UTILS_STRUCT_H */