1 /* 2 * Copyright (c) 2025 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 /** 17 * @addtogroup SoftBus 18 * @{ 19 * 20 * @brief Provides data level of distributed database transport by DSoftBus ble heratbeat. 21 * 22 * This module implements unified distributed communication management of nearby devices and provides link-independent 23 * device discovery and transmission interfaces to support service publishing and data transmission. 24 * @since 1.0 25 * @version 1.0 26 */ 27 /** @} */ 28 29 #ifndef BLE_RANGE_H 30 #define BLE_RANGE_H 31 32 #include <stdint.h> 33 #include "softbus_common.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 typedef enum { 40 BLE_ADV_HB, 41 SLE_CONN_HADM, 42 } RangeMedium; 43 44 typedef struct { 45 RangeMedium medium; 46 float distance; 47 char networkId[NETWORK_ID_BUF_LEN]; 48 uint32_t length; 49 uint8_t *addition; 50 } RangeResult; 51 52 typedef struct { 53 RangeMedium medium; 54 int32_t state; 55 int32_t reason; 56 char networkId[NETWORK_ID_BUF_LEN]; 57 } RangeState; 58 59 typedef struct { 60 /** 61 * @brief Called when the devices receive ble range result. 62 * 63 * @param info Indicates the ble range result. 64 * 65 * @since 1.0 66 * @version 1.0 67 */ 68 void (*onRangeResult)(const RangeResult *result); 69 void (*onRangeStateChange)(const RangeState state); 70 } IRangeCallback; 71 72 /** 73 * @brief Registers a callback for ble range result. 74 * 75 * @param pkgName Indicates the package name of the caller. 76 * @param callback Indicates the function callback to be registered. For details, see {@link IRangeCallback}. 77 * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise. 78 * 79 * @since 1.0 80 * @version 1.0 81 */ 82 int32_t RegisterRangeCallbackForMsdp(const char *pkgName, IRangeCallback *callback); 83 84 /** 85 * @brief Unregisters a callback for ble range result. 86 * 87 * @param pkgName Indicates the package name of the caller. 88 * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise. 89 * 90 * @since 1.0 91 * @version 1.0 92 */ 93 int32_t UnregisterRangeCallbackForMsdp(const char *pkgName); 94 95 /** 96 * @brief Defines heartbeat mode parameter, see{@link HbMode}. 97 * 98 * @since 1.0 99 * @version 1.0 100 */ 101 typedef struct { 102 int32_t duration; /** Heartbeat for range duration, unit is seconds */ 103 bool connFlag; /** Heartbeat could connect or not */ 104 bool replyFlag; /** Heartbeat need reply or not, set this parameter to true if need reply */ 105 } HbMode; 106 107 typedef struct { 108 RangeMedium medium; 109 union { 110 struct HbConfig { 111 HbMode mode; // BLE_ADV_HB 112 } heartbeat; 113 struct SleConfig { 114 char networkId[NETWORK_ID_BUF_LEN]; // SLE_CONN_HADM 115 } sle; 116 } configInfo; 117 } RangeConfig; 118 119 /** 120 * @brief Modify heartbeat parameters and trigger a temporary heartbeat. 121 * 122 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 123 * @param callerId The id of the caller, whitch cannot be <b>NULL</b>, and maxium length is {@link CALLER_ID_MAX_LEN}. 124 * 125 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 126 * 127 * @since 1.0 128 * @version 1.0 129 */ 130 int32_t TriggerRangeForMsdp(const char *pkgName, const RangeConfig *config); 131 132 int32_t StopRangeForMsdp(const char *pkgName, const RangeConfig *config); 133 134 #ifdef __cplusplus 135 } 136 #endif 137 #endif