Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master

Signed-off-by: Zhangzi <zhangjiaxiang7@huawei.com>
This commit is contained in:
Zhangzi 2024-01-02 08:51:18 +00:00 committed by Gitee
commit 8fedb47620
339 changed files with 7443 additions and 3868 deletions

View File

@ -13,5 +13,119 @@
* limitations under the License.
*/
[Arch]
./BUILD.gn zhangchunxin@huawei.com zhangshaojie3@huawei.com
./bundle.json zhangchunxin@huawei.com zhangshaojie3@huawei.com
./dsoftbus.gni zhangchunxin@huawei.com zhangshaojie3@huawei.com
[Conn]
./adapter/common/net/bluetooth/ songzhengteng@huawei.com wuchunbo1@huawei.com
./core/adapter/br/ songzhengteng@huawei.com wuchunbo1@huawei.com
./core/connection/ songzhengteng@huawei.com wuchunbo1@huawei.com
./tests/adapter/bluetooth/ songzhengteng@huawei.com wuchunbo1@huawei.com
./tests/adapter/fuzztest/softbussocketrecv_fuzzer/ songzhengteng@huawei.com wuchunbo1@huawei.com
./tests/adapter/unittest/softbus_wifi_api_test.cpp songzhengteng@huawei.com wuchunbo1@huawei.com
./tests/adapter/unittest/softbus_socket_test.cpp songzhengteng@huawei.com wuchunbo1@huawei.com
./tests/core/connection/ songzhengteng@huawei.com wuchunbo1@huawei.com
[Disc]
./adapter/common/range/ liufeihu@huawei.com xudaqing@huawei.com
./core/discovery/ liufeihu@huawei.com xudaqing@huawei.com
./sdk/discovery/ liufeihu@huawei.com xudaqing@huawei.com
./tests/adapter/fuzztest/softbusadapterrange_fuzzer/ liufeihu@huawei.com xudaqing@huawei.com
./tests/adapter/unittest/softbus_adapter_range_test.cpp liufeihu@huawei.com xudaqing@huawei.com
./tests/core/discovery/ liufeihu@huawei.com xudaqing@huawei.com
./tests/sdk/discovery/ liufeihu@huawei.com xudaqing@huawei.com
[DiscInterface]
./interfaces/kits/discovery/ liufeihu@huawei.com xudaqing@huawei.com
[Lnn]
./adapter/common/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./adapter/common/net/hdi/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./adapter/common/net/wifi/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./adapter/common/perf/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./core/adapter/authentication/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./core/adapter/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./core/authentication/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./core/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./sdk/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/adapter/unittest/softbus_adapter_wlan_extend_test.cpp zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/core/adapter/unittest/bus_center_adapter_test.cpp zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/core/adapter/unittest/lnn_settingdata_event_monitor_test.cpp zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/core/authentication/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/core/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
./tests/sdk/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
[LnnInterface]
./interfaces/kits/bus_center/ zhangshaojie3@huawei.com fengyonghui@huawei.com
[Trans]
./core/adapter/transmission/ zhangchunxin@huawei.com zhangfengxi@huawei.com
./core/transmission/ zhangchunxin@huawei.com zhangfengxi@huawei.com
./sdk/transmission/ zhangchunxin@huawei.com zhangfengxi@huawei.com
./tests/core/transmission/ zhangchunxin@huawei.com zhangfengxi@huawei.com
./tests/sdk/transmission/ zhangchunxin@huawei.com zhangfengxi@huawei.com
[TransInterface]
./interfaces/inner_kits/transport/ zhangchunxin@huawei.com wuchengwen4@huawei.com
./interfaces/kits/transport/ zhangchunxin@huawei.com wuchengwen4@huawei.com
[Comm]
./adapter/common/dfx/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./adapter/common/include/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./adapter/common/json/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./adapter/common/kernel/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./adapter/common/log/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./tests/adapter/fuzztest/softbusadapterhisysevent_fuzzer/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./tests/adapter/unittest/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./tests/core/common/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./tests/sdk/common/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
./tests/utils/ zhangchunxin@huawei.com zhusiyuan2@huawei.com
[CommInterface]
./interfaces/kits/common/ zhangchunxin@huawei.com zhangshaojie3@huawei.com
[Framework]
./core/frame/ zhangshaojie3@huawei.com jiazhenyu1@huawei.com
./sdk/frame/ zhangshaojie3@huawei.com jiazhenyu1@huawei.com
./sdk/BUILD.gn zhangshaojie3@huawei.com jiazhenyu1@huawei.com
./sdk/libsoftbus_client_map zhangshaojie3@huawei.com jiazhenyu1@huawei.com
./tests/core/frame/ zhangshaojie3@huawei.com jiazhenyu1@huawei.com
./tests/sdk/frame/ zhangshaojie3@huawei.com jiazhenyu1@huawei.com
[Permission]
./core/common/security/permission/ zhangchunxin@huawei.com liubao6@huawei.com
./tests/core/common/security/permission/ zhangchunxin@huawei.com liubao6@huawei.com
[Crypto]
./adapter/common/mbedtls/ zhangshaojie3@huawei.com liubao6@huawei.com
./adapter/common/openssl/ zhangshaojie3@huawei.com liubao6@huawei.com
./components/mbedtls/ zhangshaojie3@huawei.com liubao6@huawei.com
./core/adapter/huks/ zhangshaojie3@huawei.com liubao6@huawei.com
./tests/adapter/fuzztest/softbusdecryptdata_fuzzer/ zhangshaojie3@huawei.com liubao6@huawei.com
./tests/adapter/unittest/dsoftbus_aes_crypto_test.cpp zhangshaojie3@huawei.com liubao6@huawei.com
./tests/adapter/unittest/dsoftbus_crypto_test.cpp zhangshaojie3@huawei.com liubao6@huawei.com
./tests/core/adapter/unittest/dsoftbus_rsa_crypto_test.cpp zhangshaojie3@huawei.com liubao6@huawei.com
[Config]
./adapter/default_config/ zhangchunxin@huawei.com zhangshaojie3@huawei.com
./config.py zhangchunxin@huawei.com zhangshaojie3@huawei.com
./Kconfig zhangchunxin@huawei.com zhangshaojie3@huawei.com
[2nd-Party]
./components/nstackx/ zhangchunxin@huawei.com xuxiaoqing16@huawei.com
[Misc]
./figures/ zhangchunxin@huawei.com zhangshaojie3@huawei.com
./.clang-format zhangchunxin@huawei.com zhangshaojie3@huawei.com
./.gitignore zhangchunxin@huawei.com zhangshaojie3@huawei.com
./CODEOWNERS zhangchunxin@huawei.com zhangshaojie3@huawei.com
./hisysevent.yaml zhangchunxin@huawei.com zhangshaojie3@huawei.com
./OAT.xml zhangchunxin@huawei.com zhangshaojie3@huawei.com
./README.md zhangchunxin@huawei.com zhangshaojie3@huawei.com
./README_zh.md zhangchunxin@huawei.com zhangshaojie3@huawei.com
[InterfaceCode]
# any change to core/common/include/softbus_server_ipc_interface_code.h needs to be reviewed by @leonchan5
core/common/include/softbus_server_ipc_interface_code.h @leonchan5
./core/common/include/softbus_server_ipc_interface_code.h @leonchan5 zhangchunxin@huawei.com zhangshaojie3@huawei.com

View File

@ -75,7 +75,6 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/kernel/liteos_m/softbus_adapter_timer.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_socket.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_thread.c",
"$softbus_adapter_common/log/softbus_adapter_log.c",
"$softbus_adapter_common/range/softbus_adapter_range.c",
"$softbus_adapter_config/spec_config/softbus_config_adapter.c",
]
@ -92,7 +91,6 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/kernel/posix/softbus_adapter_file.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_socket.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_thread.c",
"$softbus_adapter_common/log/softbus_adapter_log.c",
"$softbus_adapter_common/perf/softbus_adapter_perf.c",
"$softbus_adapter_common/range/softbus_adapter_range.c",
"$softbus_adapter_config/spec_config/softbus_config_adapter.c",
@ -140,7 +138,6 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/kernel/posix/softbus_adapter_socket.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_thread.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_timer.c",
"$softbus_adapter_common/log/softbus_adapter_log.c",
"$softbus_adapter_common/perf/softbus_adapter_perf.c",
"$softbus_adapter_common/range/softbus_adapter_range.c",
"$softbus_adapter_config/spec_config/softbus_config_adapter.c",
@ -207,7 +204,6 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/kernel/posix/softbus_adapter_socket.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_thread.c",
"$softbus_adapter_common/kernel/posix/softbus_adapter_timer.c",
"$softbus_adapter_common/log/softbus_adapter_log.c",
"$softbus_adapter_common/perf/softbus_adapter_perf.c",
]
public_deps = [

View File

@ -17,7 +17,6 @@
#include "bus_center_event.h"
#include "lnn_log.h"
#include "softbus_adapter_log.h"
#include "softbus_errcode.h"
#include "hdf_io_service_if.h"

View File

@ -17,9 +17,9 @@
#include <cstdlib>
#include "hiview.h"
#include "comm_log.h"
#include "parameter.h"
#include "securec.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#define PROP_USER_TYPE "ro.logsystem.usertype"

View File

@ -25,7 +25,6 @@
#include <stdlib.h>
#include <string.h>
#include "softbus_adapter_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOFTBUS_ADAPTER_LOG_H
#define SOFTBUS_ADAPTER_LOG_H
#include <stdio.h>
#include <stdbool.h>
#ifndef SOFTBUS_DEBUG
#if defined(__LITEOS_M__)
#define SOFTBUS_PRINTF
#include "log.h"
#else
#include "hilog/log.h"
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#ifndef SOFTBUS_DEBUG
#if defined(__LITEOS_M__)
#define LOG_DBG(fmt, ...) HILOG_DEBUG(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
#define LOG_INFO(fmt, ...) HILOG_INFO(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
#define LOG_WARN(fmt, ...) HILOG_WARN(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
#define LOG_ERR(fmt, ...) HILOG_ERROR(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
#else
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD0015C0
#define LOG_TAG "dsoftbus"
#define LOG_DBG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt"\n", ##__VA_ARGS__);
#define LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, fmt"\n", ##__VA_ARGS__);
#define LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, fmt"\n", ##__VA_ARGS__);
#define LOG_ERR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt"\n", ##__VA_ARGS__);
#endif
#else
enum {
SOFTBUS_LOG_LEVEL_DEBUG = 0,
SOFTBUS_LOG_LEVEL_INFO,
SOFTBUS_LOG_LEVEL_WARNING,
SOFTBUS_LOG_LEVEL_ERROR
};
#define SOFTBUS_LOG_LEVEL SOFTBUS_LOG_LEVEL_INFO
#define LOG_DBG(fmt, ...) do { \
if (SOFTBUS_LOG_LEVEL_DEBUG >= SOFTBUS_LOG_LEVEL) { \
printf("DEBUG:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
#define LOG_INFO(fmt, ...) do { \
if (SOFTBUS_LOG_LEVEL_INFO >= SOFTBUS_LOG_LEVEL) { \
printf("INFO:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
#define LOG_WARN(fmt, ...) do { \
if (SOFTBUS_LOG_LEVEL_WARNING >= SOFTBUS_LOG_LEVEL) { \
printf("WARN:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
#define LOG_ERR(fmt, ...) do { \
if (SOFTBUS_LOG_LEVEL_ERROR >= SOFTBUS_LOG_LEVEL) { \
printf("ERROR:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
#endif
#if defined(__LITEOS_M__)
#define SOFTBUS_HILOG_ID HILOG_MODULE_SOFTBUS
#else
#define SOFTBUS_HILOG_ID LOG_CORE
#endif
typedef enum {
SOFTBUS_LOG_DBG,
SOFTBUS_LOG_INFO,
SOFTBUS_LOG_WARN,
SOFTBUS_LOG_ERROR,
SOFTBUS_LOG_LEVEL_MAX,
} SoftBusLogLevel;
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@ -21,6 +21,7 @@
#include "softbus_adapter_mem.h"
#define JSON_LOGE(fmt, ...) COMM_LOGE(COMM_ADAPTER, "[%s] " fmt, __FUNCTION__, ##__VA_ARGS__)
#define JSON_LOGD(fmt, ...) COMM_LOGD(COMM_ADAPTER, "[%s] " fmt, __FUNCTION__, ##__VA_ARGS__)
JsonObj *JSON_CreateObject(void)
{
@ -256,7 +257,7 @@ bool JSON_GetStringFromOject(const JsonObj *obj, const char *key, char *value, u
}
nlohmann::json item = (*json)[key];
if (!item.is_string()) {
JSON_LOGE("cannot find or invalid [%s]", key);
JSON_LOGD("cannot find or invalid [%s]", key);
return false;
}
std::string valueString = item.get<std::string>();

View File

@ -97,7 +97,7 @@ int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr)
int32_t SoftBusMutexLock(SoftBusMutex *mutex)
{
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
COMM_LOGE(COMM_ADAPTER, "mutex is null");
COMM_LOGD(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}
@ -130,7 +130,7 @@ int32_t SoftBusMutexUnlock(SoftBusMutex *mutex)
int32_t SoftBusMutexDestroy(SoftBusMutex *mutex)
{
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
COMM_LOGE(COMM_ADAPTER, "mutex is null");
COMM_LOGD(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "softbus_adapter_log.h"
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level)
{
#ifdef SOFTBUS_PRINTF
(void)level;
printf("%s\n", buf);
return;
#else
switch (level) {
case SOFTBUS_LOG_DBG:
HILOG_DEBUG(SOFTBUS_HILOG_ID, "%{public}s", buf);
break;
case SOFTBUS_LOG_INFO:
HILOG_INFO(SOFTBUS_HILOG_ID, "%{public}s", buf);
break;
case SOFTBUS_LOG_WARN:
HILOG_WARN(SOFTBUS_HILOG_ID, "%{public}s", buf);
break;
case SOFTBUS_LOG_ERROR:
HILOG_ERROR(SOFTBUS_HILOG_ID, "%{public}s", buf);
break;
default:
break;
}
#endif
}

View File

@ -25,13 +25,12 @@
#define SOFTBUS_BLE_GATT_H
#include "softbus_broadcast_adapter_interface.h"
#include "softbus_broadcast_adapter_type.h"
#ifdef __cplusplus
extern "C"{
#endif
void softbus_ble_adapter_init(void);
void SoftbusBleAdapterInit(void);
#ifdef __cplusplus
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file softbus_ble_utils.h
* @brief ble utils
*
* @since 4.1
* @version 1.0
*/
#ifndef SOFTBUS_BLE_UTILS_H
#define SOFTBUS_BLE_UTILS_H
#include "softbus_broadcast_adapter_interface.h"
#include "c_header/ohos_bt_gatt.h"
#include "c_header/ohos_bt_def.h"
#ifdef __cplusplus
extern "C"{
#endif
int32_t BtStatusToSoftBus(BtStatus btStatus);
void SoftbusAdvParamToBt(const SoftbusBroadcastParam *src, BleAdvParams *dst);
void BtScanResultToSoftbus(const BtScanResultData *src, SoftBusBcScanResult *dst);
void SoftbusFilterToBt(BleScanNativeFilter *nativeFilter, const SoftBusBcScanFilter *filter, uint8_t filterSize);
void FreeBtFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize);
void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize);
int GetBtScanMode(uint16_t scanInterval, uint16_t scanWindow);
uint8_t *AssembleAdvData(const SoftbusBroadcastData *data, uint16_t *dataLen);
uint8_t *AssembleRspData(const SoftbusBroadcastPayload *data, uint16_t *dataLen);
int32_t ParseScanResult(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst);
void DumpSoftbusAdapterData(const char *description, uint8_t *data, uint16_t len);
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BLE_UTILS_H */

View File

@ -14,7 +14,804 @@
*/
#include "softbus_ble_gatt.h"
#include "softbus_adapter_thread.h"
#include "softbus_adapter_mem.h"
#include "softbus_broadcast_type.h"
#include "softbus_error_code.h"
#include "softbus_ble_utils.h"
#include "disc_log.h"
#include <stdatomic.h>
#include <string.h>
void softbus_ble_adapter_init(void)
#define GATT_ADV_MAX_NUM 16
#define GATT_SCAN_MAX_NUM 2
#define LP_BT_UUID "43d4a49f-604d-45b5-9302-4ddbbfd538fd"
#define LP_DELIVERY_MODE_REPLY 0xF0
#define LP_ADV_DURATION_MS 0
#define SCAN_CHANNEL_0 0
#define SCAN_CHANNEL_1 1
static atomic_bool g_init = false;
static atomic_bool g_bcCbReg = false;
static SoftBusMutex g_advLock = {0};
static SoftBusMutex g_scannerLock = {0};
typedef struct {
int32_t advId;
bool isUsed;
bool isAdvertising;
SoftbusBroadcastCallback *advCallback;
} AdvChannel;
typedef struct {
int32_t scannerId;
bool isUsed;
bool isScanning;
SoftbusScanCallback *scanCallback;
} ScanChannel;
static AdvChannel g_advChannel[GATT_ADV_MAX_NUM];
static ScanChannel g_scanChannel[GATT_SCAN_MAX_NUM];
static int32_t Init(void)
{
if (g_init) {
DISC_LOGI(DISC_BLE_ADAPTER, "already inited");
return SOFTBUS_OK;
}
g_init = true;
if (SoftBusMutexInit(&g_advLock, NULL) != SOFTBUS_OK) {
g_init = false;
DISC_LOGE(DISC_BLE_ADAPTER, "g_advLock init failed");
return SOFTBUS_ERR;
}
if (SoftBusMutexInit(&g_scannerLock, NULL) != SOFTBUS_OK) {
SoftBusMutexDestroy(&g_advLock);
g_init = false;
DISC_LOGE(DISC_BLE_ADAPTER, "g_scannerLock init failed");
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE_ADAPTER, "init success");
return SOFTBUS_OK;
}
static int32_t DeInit(void)
{
if (!g_init) {
DISC_LOGI(DISC_BLE_ADAPTER, "already deinited");
return SOFTBUS_OK;
}
g_init = false;
SoftBusMutexDestroy(&g_advLock);
SoftBusMutexDestroy(&g_scannerLock);
DISC_LOGI(DISC_BLE_ADAPTER, "deinit success");
return SOFTBUS_OK;
}
static void WrapperAdvEnableCallback(int advId, int status)
{
int32_t ret = BtStatusToSoftBus((BtStatus)status);
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
continue;
}
AdvChannel *advChannel = &g_advChannel[channelId];
if (advChannel->advId != advId || !advChannel->isUsed) {
SoftBusMutexUnlock(&g_advLock);
continue;
}
advChannel->isAdvertising = (ret == SOFTBUS_BC_STATUS_SUCCESS);
if (!advChannel->isAdvertising) {
advChannel->advId = -1;
}
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
SoftBusMutexUnlock(&g_advLock);
if (advChannel->advCallback != NULL && advChannel->advCallback->OnStartBroadcastingCallback != NULL) {
advChannel->advCallback->OnStartBroadcastingCallback(channelId, ret);
}
break;
}
}
static void WrapperAdvDisableCallback(int advId, int status)
{
int32_t ret = BtStatusToSoftBus((BtStatus)status);
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
continue;
}
AdvChannel *advChannel = &g_advChannel[channelId];
if (advChannel->advId != advId || !advChannel->isUsed) {
SoftBusMutexUnlock(&g_advLock);
continue;
}
advChannel->isAdvertising = false;
advChannel->advId = -1;
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
SoftBusMutexUnlock(&g_advLock);
if (advChannel->advCallback != NULL && advChannel->advCallback->OnStopBroadcastingCallback != NULL) {
advChannel->advCallback->OnStopBroadcastingCallback(channelId, ret);
}
break;
}
}
static void WrapperAdvSetDataCallback(int advId, int status)
{
int32_t ret = BtStatusToSoftBus((BtStatus)status);
for (uint32_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
continue;
}
AdvChannel *advChannel = &g_advChannel[channelId];
if (advChannel->advId != advId || !advChannel->isUsed) {
SoftBusMutexUnlock(&g_advLock);
continue;
}
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
SoftBusMutexUnlock(&g_advLock);
if (advChannel->advCallback != NULL && advChannel->advCallback->OnSetBroadcastingCallback != NULL) {
advChannel->advCallback->OnSetBroadcastingCallback(channelId, ret);
}
break;
}
}
static void WrapperAdvUpdateDataCallback(int advId, int status)
{
int32_t ret = BtStatusToSoftBus((BtStatus)status);
for (uint32_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
continue;
}
AdvChannel *advChannel = &g_advChannel[channelId];
if (advChannel->advId != advId || !advChannel->isUsed) {
SoftBusMutexUnlock(&g_advLock);
continue;
}
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
SoftBusMutexUnlock(&g_advLock);
if (advChannel->advCallback != NULL && advChannel->advCallback->OnUpdateBroadcastingCallback != NULL) {
advChannel->advCallback->OnUpdateBroadcastingCallback(channelId, ret);
}
break;
}
}
static BtGattCallbacks g_softbusGattCb = {
.advEnableCb = WrapperAdvEnableCallback,
.advDisableCb = WrapperAdvDisableCallback,
.advDataCb = WrapperAdvSetDataCallback,
.advUpdateCb = WrapperAdvUpdateDataCallback,
};
static int32_t RegisterAdvCallback(int32_t *advId, const SoftbusBroadcastCallback *cb)
{
if (advId == NULL || cb == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv param is null");
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed");
return SOFTBUS_LOCK_ERR;
}
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
if (g_advChannel[channelId].isUsed) {
continue;
}
if (!g_bcCbReg) {
if (BleGattRegisterCallbacks(&g_softbusGattCb) != OHOS_BT_STATUS_SUCCESS) {
DISC_LOGE(DISC_BLE_ADAPTER, "register failed, advId: %u", channelId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
g_bcCbReg = true;
}
g_advChannel[channelId].advId = -1;
g_advChannel[channelId].isUsed = true;
g_advChannel[channelId].isAdvertising = false;
g_advChannel[channelId].advCallback = (SoftbusBroadcastCallback *)cb;
*advId = channelId;
DISC_LOGI(DISC_BLE_ADAPTER, "register success, advId: %u", channelId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;
}
DISC_LOGE(DISC_BLE_ADAPTER, "no available adv channel");
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
static int32_t UnRegisterAdvCallback(int32_t advId)
{
if (advId < 0 || advId >= GATT_ADV_MAX_NUM) {
DISC_LOGE(DISC_BLE_ADAPTER, "invalid advId: %d", advId);
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, advId: %d", advId);
return SOFTBUS_LOCK_ERR;
}
if (!g_advChannel[advId].isUsed) {
DISC_LOGI(DISC_BLE_ADAPTER, "already unregistered, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;
}
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
g_advChannel[advId].advId = -1;
g_advChannel[advId].isUsed = false;
g_advChannel[advId].isAdvertising = false;
g_advChannel[advId].advCallback = NULL;
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;
}
static void WrapperScanResultCallback(uint8_t channelId, BtScanResultData *data)
{
if (data == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "scan result data is null, scannerId: %u", channelId);
return;
}
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
return;
}
ScanChannel *scanChannel = &g_scanChannel[channelId];
if (!scanChannel->isUsed || !scanChannel->isScanning) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
channelId, scanChannel->scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return;
}
SoftBusBcScanResult scanResult = {};
BtScanResultToSoftbus(data, &scanResult);
if (ParseScanResult(data->advData, data->advLen, &scanResult) != SOFTBUS_OK) {
SoftBusFree(scanResult.data.bcData.payload);
SoftBusFree(scanResult.data.rspData.payload);
SoftBusMutexUnlock(&g_scannerLock);
return;
}
SoftBusMutexUnlock(&g_scannerLock);
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnReportScanDataCallback != NULL) {
scanChannel->scanCallback->OnReportScanDataCallback(channelId, &scanResult);
}
SoftBusFree(scanResult.data.bcData.payload);
SoftBusFree(scanResult.data.rspData.payload);
}
static void WrapperScanStateChangeCallback(uint8_t channelId, int32_t resultCode, bool isStartScan)
{
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
return;
}
ScanChannel *scanChannel = &g_scanChannel[channelId];
if (!scanChannel->isUsed) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
channelId, scanChannel->scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return;
}
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, resultCode: %d, isStartScan: %d",
channelId, scanChannel->scannerId, resultCode, isStartScan);
SoftBusMutexUnlock(&g_scannerLock);
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnScanStateChanged != NULL) {
scanChannel->scanCallback->OnScanStateChanged(resultCode, isStartScan);
}
}
static void WrapperLpDeviceInfoCallback(uint8_t channelId, BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
{
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
return;
}
ScanChannel *scanChannel = &g_scanChannel[channelId];
if (!scanChannel->isUsed) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
channelId, scanChannel->scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return;
}
SoftBusMutexUnlock(&g_scannerLock);
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnLpDeviceInfoCallback != NULL) {
SoftbusBroadcastUuid bcUuid;
bcUuid.uuid = (uint8_t *)uuid->uuid;
bcUuid.uuidLen = (uint8_t)uuid->uuidLen;
scanChannel->scanCallback->OnLpDeviceInfoCallback(&bcUuid, type, data, dataSize);
}
}
static void WrapperScanResultCallback0(BtScanResultData *data)
{
WrapperScanResultCallback(SCAN_CHANNEL_0, data);
}
static void WrapperScanResultCallback1(BtScanResultData *data)
{
WrapperScanResultCallback(SCAN_CHANNEL_1, data);
}
static void WrapperScanStateChangeCallback0(int32_t resultCode, bool isStartScan)
{
WrapperScanStateChangeCallback(SCAN_CHANNEL_0, resultCode, isStartScan);
}
static void WrapperScanStateChangeCallback1(int32_t resultCode, bool isStartScan)
{
WrapperScanStateChangeCallback(SCAN_CHANNEL_1, resultCode, isStartScan);
}
static void WrapperLpDeviceInfoCallback0(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
{
WrapperLpDeviceInfoCallback(SCAN_CHANNEL_0, uuid, type, data, dataSize);
}
static void WrapperLpDeviceInfoCallback1(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
{
WrapperLpDeviceInfoCallback(SCAN_CHANNEL_1, uuid, type, data, dataSize);
}
static BleScanCallbacks g_softbusBleScanCb[GATT_SCAN_MAX_NUM] = {
{
.scanResultCb = WrapperScanResultCallback0,
.scanStateChangeCb = WrapperScanStateChangeCallback0,
.lpDeviceInfoCb = WrapperLpDeviceInfoCallback0,
},
{
.scanResultCb = WrapperScanResultCallback1,
.scanStateChangeCb = WrapperScanStateChangeCallback1,
.lpDeviceInfoCb = WrapperLpDeviceInfoCallback1,
}
};
static BleScanCallbacks *GetAdapterScanCallback(uint8_t channelId)
{
return &g_softbusBleScanCb[channelId];
}
static int32_t RegisterScanCallback(int32_t *scannerId, const SoftbusScanCallback *cb)
{
if (scannerId == NULL || cb == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "scan param is null");
return SOFTBUS_ERR;
}
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed");
return SOFTBUS_LOCK_ERR;
}
for (uint8_t channelId = 0; channelId < GATT_SCAN_MAX_NUM; channelId++) {
if (g_scanChannel[channelId].isUsed) {
continue;
}
if (BleRegisterScanCallbacks(GetAdapterScanCallback(channelId),
&g_scanChannel[channelId].scannerId) != OHOS_BT_STATUS_SUCCESS) {
DISC_LOGE(DISC_BLE_ADAPTER, "register callback failed, scannerId: %u", channelId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
g_scanChannel[channelId].isUsed = true;
g_scanChannel[channelId].isScanning = false;
g_scanChannel[channelId].scanCallback = (SoftbusScanCallback *)cb;
*scannerId = channelId;
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %u, bt-scannerId: %d", channelId, g_scanChannel[channelId].scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_OK;
}
DISC_LOGE(DISC_BLE_ADAPTER, "no available scan channel");
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
static int32_t UnRegisterScanCallback(int32_t scannerId)
{
if (scannerId < 0 || scannerId >= GATT_SCAN_MAX_NUM) {
DISC_LOGE(DISC_BLE_ADAPTER, "scannerId is invalid: %d", scannerId);
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", scannerId);
return SOFTBUS_LOCK_ERR;
}
if (!g_scanChannel[scannerId].isUsed) {
DISC_LOGI(DISC_BLE_ADAPTER, "already unregistered, scannerId: %d, bt-scannerId: %d",
scannerId, g_scanChannel[scannerId].scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_OK;
}
int32_t ret = BleDeregisterScanCallbacks(g_scanChannel[scannerId].scannerId);
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, result: %d",
scannerId, g_scanChannel[scannerId].scannerId, ret);
g_scanChannel[scannerId].scannerId = -1;
g_scanChannel[scannerId].isUsed = false;
g_scanChannel[scannerId].isScanning = false;
g_scanChannel[scannerId].scanCallback = NULL;
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_OK;
}
static bool CheckAdvChannelInUsed(int32_t advId)
{
if (advId < 0 || advId >= GATT_ADV_MAX_NUM) {
DISC_LOGE(DISC_BLE_ADAPTER, "invalid advId: %d", advId);
return false;
}
if (!g_advChannel[advId].isUsed) {
DISC_LOGE(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
return false;
}
return true;
}
static int32_t StartBleAdv(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
{
BleAdvParams advParam = {};
SoftbusAdvParamToBt(param, &advParam);
StartAdvRawData advRawData = {};
advRawData.advData = (unsigned char *)AssembleAdvData(data, (uint16_t *)&advRawData.advDataLen);
if (advRawData.advData == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advId: %d, bt-advId: %d",
advId, g_advChannel[advId].advId);
return SOFTBUS_ERR;
}
advRawData.rspDataLen = 0;
advRawData.rspData = NULL;
if (data->rspData.payloadLen > 0 && data->rspData.payload != NULL) {
advRawData.rspData = (unsigned char *)AssembleRspData(&data->rspData, (uint16_t *)&advRawData.rspDataLen);
if (advRawData.rspData == NULL) {
SoftBusFree(advRawData.advData);
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advId: %d, bt-advId: %d",
advId, g_advChannel[advId].advId);
return SOFTBUS_ERR;
}
}
DumpSoftbusAdapterData("mgr pkg:", advRawData.advData, advRawData.advDataLen);
int32_t ret = BleStartAdvEx(&g_advChannel[advId].advId, advRawData, advParam);
SoftBusFree(advRawData.advData);
SoftBusFree(advRawData.rspData);
return (ret == OHOS_BT_STATUS_SUCCESS) ? SOFTBUS_OK : SOFTBUS_ERR;
}
static int32_t StartAdv(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
{
if (param == NULL || data == NULL || data->bcData.payloadLen == 0 || data->bcData.payload == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "invalid adv param, advId: %d", advId);
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, advId: %d", advId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckAdvChannelInUsed(advId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
if (g_advChannel[advId].isAdvertising) {
DISC_LOGE(DISC_BLE_ADAPTER, "already started, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
int32_t ret = StartBleAdv(advId, param, data);
g_advChannel[advId].isAdvertising = (ret == SOFTBUS_OK);
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
SoftBusMutexUnlock(&g_advLock);
if (ret != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t StopAdv(int32_t advId)
{
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckAdvChannelInUsed(advId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
if (!g_advChannel[advId].isAdvertising) {
DISC_LOGI(DISC_BLE_ADAPTER, "already stopped, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;
}
int32_t ret = BleStopAdv(g_advChannel[advId].advId);
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
g_advChannel[advId].isAdvertising = false;
SoftBusMutexUnlock(&g_advLock);
if (ret != OHOS_BT_STATUS_SUCCESS) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t SetAdvData(int32_t advId, const SoftbusBroadcastData *data)
{
if (data == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "data is null, advId: %d", advId);
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckAdvChannelInUsed(advId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
if (!g_advChannel[advId].isAdvertising) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not advertising, advId: %d, bt-advId: %d",
advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
StartAdvRawData advRawData = {};
advRawData.advData = (unsigned char *)AssembleAdvData(data, (uint16_t *)&advRawData.advDataLen);
if (advRawData.advData == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advId: %d, bt-advId: %d",
advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
advRawData.rspDataLen = 0;
advRawData.rspData = NULL;
if (data->rspData.payloadLen > 0 && data->rspData.payload != NULL) {
advRawData.rspData = (unsigned char *)AssembleRspData(&data->rspData, (uint16_t *)&advRawData.rspDataLen);
if (advRawData.rspData == NULL) {
SoftBusFree(advRawData.advData);
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advId: %d, bt-advId: %d",
advId, g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
}
int32_t ret = BtStatusToSoftBus(BleSetAdvData(g_advChannel[advId].advId, advRawData));
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
SoftBusFree(advRawData.advData);
SoftBusFree(advRawData.rspData);
SoftBusMutexUnlock(&g_advLock);
return ret;
}
static int32_t UpdateAdvData(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
{
if (StopAdv(advId) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "update adv data failed, advId: %d", advId);
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE_ADAPTER, "update adv data, advId: %d", advId);
return StartAdv(advId, param, data);
}
static bool CheckScanChannelInUsed(int32_t scannerId)
{
if (scannerId < 0 || scannerId >= GATT_SCAN_MAX_NUM) {
DISC_LOGE(DISC_BLE_ADAPTER, "invalid scannerId: %d", scannerId);
return false;
}
if (!g_scanChannel[scannerId].isUsed) {
DISC_LOGE(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d", scannerId, g_scanChannel[scannerId].scannerId);
return false;
}
return true;
}
static int32_t StartScan(int32_t scannerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
int32_t filterSize)
{
if (param == NULL || scanFilter == NULL || filterSize <= 0) {
DISC_LOGE(DISC_BLE_ADAPTER, "invalid param, scannerId: %d", scannerId);
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckScanChannelInUsed(scannerId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %d", scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
if (g_scanChannel[scannerId].isScanning) {
DISC_LOGE(DISC_BLE_ADAPTER, "already scanning, scannerId: %d, bt-scannerId: %d",
scannerId, g_scanChannel[scannerId].scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
BleScanNativeFilter *nativeFilter =
(BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * filterSize);
if (nativeFilter == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "malloc native filter failed, scannerId: %d, bt-scannerId: %d",
scannerId, g_scanChannel[scannerId].scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_MALLOC_ERR;
}
SoftbusFilterToBt(nativeFilter, scanFilter, filterSize);
DumpBleScanFilter(nativeFilter, filterSize);
BleScanConfigs scanConfig = {};
scanConfig.scanMode = GetBtScanMode(param->scanInterval, param->scanWindow);
scanConfig.phy = (int)param->scanPhy;
int32_t ret = BleStartScanEx(g_scanChannel[scannerId].scannerId, &scanConfig, nativeFilter, (uint32_t)filterSize);
g_scanChannel[scannerId].isScanning = (ret == OHOS_BT_STATUS_SUCCESS);
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, ret: %d",
scannerId, g_scanChannel[scannerId].scannerId, ret);
FreeBtFilter(nativeFilter, filterSize);
SoftBusMutexUnlock(&g_scannerLock);
if (ret != OHOS_BT_STATUS_SUCCESS) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t StopScan(int32_t scannerId)
{
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckScanChannelInUsed(scannerId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used: %d", scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
if (!g_scanChannel[scannerId].isScanning) {
DISC_LOGI(DISC_BLE_ADAPTER, "already stopped, scannerId: %d, bt-scannerId: %d",
scannerId, g_scanChannel[scannerId].scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_OK;
}
int32_t ret = BleStopScan(g_scanChannel[scannerId].scannerId);
DISC_LOGI(DISC_BLE_ADAPTER, "stop scan, scannerId: %d, bt-scannerId: %d, ret: %d",
scannerId, g_scanChannel[scannerId].scannerId, ret);
g_scanChannel[scannerId].isScanning = false;
SoftBusMutexUnlock(&g_scannerLock);
if (ret != OHOS_BT_STATUS_SUCCESS) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static bool IsLpAvailable(void)
{
DISC_LOGI(DISC_BLE_ADAPTER, "is lp available");
return IsLpDeviceAvailable();
}
static bool SetLpParam(const SoftBusLpBroadcastParam *bcParam, const SoftBusLpScanParam *scanParam)
{
BleScanConfigs scanConfig = {};
scanConfig.scanMode = GetBtScanMode(scanParam->scanParam.scanInterval, scanParam->scanParam.scanWindow);
BtLpDeviceParam lpParam = {};
lpParam.scanConfig = &scanConfig;
lpParam.rawData.advData = (unsigned char *)AssembleAdvData(&bcParam->advData,
(uint16_t *)&lpParam.rawData.advDataLen);
if (lpParam.rawData.advData == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advHandle: %d", bcParam->advHandle);
return SOFTBUS_ERR;
}
if (bcParam->advData.rspData.payloadLen > 0 && bcParam->advData.rspData.payload != NULL) {
lpParam.rawData.rspData = (unsigned char *)AssembleRspData(&bcParam->advData.rspData,
(uint16_t *)&lpParam.rawData.rspDataLen);
if (lpParam.rawData.rspData == NULL) {
SoftBusFree(lpParam.rawData.advData);
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advHandle: %d", bcParam->advHandle);
return SOFTBUS_ERR;
}
}
lpParam.filter = (BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * scanParam->filterSize);
if (lpParam.filter == NULL) {
SoftBusFree(lpParam.rawData.advData);
SoftBusFree(lpParam.rawData.rspData);
DISC_LOGE(DISC_BLE_ADAPTER, "malloc native filter failed, advHandle: %d", bcParam->advHandle);
return SOFTBUS_MALLOC_ERR;
}
SoftbusFilterToBt(lpParam.filter, scanParam->filter, scanParam->filterSize);
lpParam.filterSize = (unsigned int)scanParam->filterSize;
SoftbusAdvParamToBt(&bcParam->advParam, &lpParam.advParam);
BtUuid btUuid = {};
btUuid.uuid = LP_BT_UUID;
btUuid.uuidLen = (unsigned char)strlen(LP_BT_UUID);
lpParam.uuid = btUuid;
lpParam.activeDeviceInfo = NULL;
lpParam.activeDeviceSize = 0;
lpParam.deliveryMode = LP_DELIVERY_MODE_REPLY;
lpParam.advHandle = bcParam->advHandle;
lpParam.duration = LP_ADV_DURATION_MS;
int32_t ret = SetLpDeviceParam(&lpParam);
FreeBtFilter(lpParam.filter, scanParam->filterSize);
SoftBusFree(lpParam.rawData.advData);
SoftBusFree(lpParam.rawData.rspData);
DISC_LOGI(DISC_BLE_ADAPTER, "advHandle: %d, ret: %d", bcParam->advHandle, ret);
return (ret == OHOS_BT_STATUS_SUCCESS) ? true : false;
}
static int32_t GetBroadcastHandle(int32_t advId, int32_t *bcHandle)
{
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckAdvChannelInUsed(advId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used: %d", advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
int32_t ret = GetAdvHandle(g_advChannel[advId].advId, bcHandle);
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
SoftBusMutexUnlock(&g_advLock);
return ret;
}
static int32_t EnableSyncDataToLp(void)
{
DISC_LOGI(DISC_BLE_ADAPTER, "enable sync data to lp");
return EnableSyncDataToLpDevice();
}
static int32_t DisableSyncDataToLp(void)
{
DISC_LOGI(DISC_BLE_ADAPTER, "disable sync data to lp");
return DisableSyncDataToLpDevice();
}
static int32_t SetScanReportChannelToLp(int32_t scannerId, bool enable)
{
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
return SOFTBUS_LOCK_ERR;
}
if (!CheckScanChannelInUsed(scannerId)) {
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used: %d", scannerId);
SoftBusMutexUnlock(&g_scannerLock);
return SOFTBUS_ERR;
}
int32_t ret = SetScanReportChannelToLpDevice(g_scanChannel[scannerId].scannerId, enable);
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, ret: %d",
scannerId, g_scanChannel[scannerId].scannerId, ret);
SoftBusMutexUnlock(&g_scannerLock);
return ret;
}
static int32_t SetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window,
int32_t interval, int32_t bcHandle)
{
DISC_LOGI(DISC_BLE_ADAPTER, "advHandle: %d", bcHandle);
return SetLpDeviceAdvParam(duration, maxExtAdvEvents, window, interval, bcHandle);
}
void SoftbusBleAdapterInit(void)
{
DISC_LOGI(DISC_BLE_ADAPTER, "SoftbusBleAdapterInit");
static SoftbusBroadcastMediumInterface interface = {
.Init = Init,
.DeInit = DeInit,
.RegisterBroadcaster = RegisterAdvCallback,
.UnRegisterBroadcaster = UnRegisterAdvCallback,
.RegisterScanListener = RegisterScanCallback,
.UnRegisterScanListener = UnRegisterScanCallback,
.StartBroadcasting = StartAdv,
.StopBroadcasting = StopAdv,
.SetBroadcastingData = SetAdvData,
.UpdateBroadcasting = UpdateAdvData,
.StartScan = StartScan,
.StopScan = StopScan,
.IsLpDeviceAvailable = IsLpAvailable,
.SetAdvFilterParam = SetLpParam,
.GetBroadcastHandle = GetBroadcastHandle,
.EnableSyncDataToLpDevice = EnableSyncDataToLp,
.DisableSyncDataToLpDevice = DisableSyncDataToLp,
.SetScanReportChannelToLpDevice = SetScanReportChannelToLp,
.SetLpDeviceParam = SetLpAdvParam,
};
if (RegisterBroadcastMediumFunction(BROADCAST_MEDIUM_TYPE_BLE, &interface) != 0) {
DISC_LOGE(DISC_BLE_ADAPTER, "Register gatt interface failed.");
}
}

View File

@ -0,0 +1,475 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "softbus_ble_utils.h"
#include "softbus_adapter_mem.h"
#include "softbus_broadcast_type.h"
#include "softbus_error_code.h"
#include "softbus_utils.h"
#include "softbus_broadcast_utils.h"
#include "disc_log.h"
#include <securec.h>
#define UUID_LEN 2
#define UUID_MASK_LEN 2
#define ID_LEN 2
int32_t BtStatusToSoftBus(BtStatus btStatus)
{
switch (btStatus) {
case OHOS_BT_STATUS_SUCCESS:
return SOFTBUS_BC_STATUS_SUCCESS;
case OHOS_BT_STATUS_FAIL:
return SOFTBUS_BC_STATUS_FAIL;
case OHOS_BT_STATUS_NOT_READY:
return SOFTBUS_BC_STATUS_NOT_READY;
case OHOS_BT_STATUS_NOMEM:
return SOFTBUS_BC_STATUS_NOMEM;
case OHOS_BT_STATUS_BUSY:
return SOFTBUS_BC_STATUS_BUSY;
case OHOS_BT_STATUS_DONE:
return SOFTBUS_BC_STATUS_DONE;
case OHOS_BT_STATUS_UNSUPPORTED:
return SOFTBUS_BC_STATUS_UNSUPPORTED;
case OHOS_BT_STATUS_PARM_INVALID:
return SOFTBUS_BC_STATUS_PARM_INVALID;
case OHOS_BT_STATUS_UNHANDLED:
return SOFTBUS_BC_STATUS_UNHANDLED;
case OHOS_BT_STATUS_AUTH_FAILURE:
return SOFTBUS_BC_STATUS_AUTH_FAILURE;
case OHOS_BT_STATUS_RMT_DEV_DOWN:
return SOFTBUS_BC_STATUS_RMT_DEV_DOWN;
case OHOS_BT_STATUS_AUTH_REJECTED:
return SOFTBUS_BC_STATUS_AUTH_REJECTED;
default:
return SOFTBUS_BC_STATUS_FAIL;
}
}
static uint16_t SoftbusAdvDataTypeToBt(uint16_t advType)
{
switch (advType) {
case BC_DATA_TYPE_SERVICE:
return SERVICE_BC_TYPE;
case BC_DATA_TYPE_MANUFACTURER:
return MANUFACTURE_BC_TYPE;
default:
return 0x00;
}
}
static uint16_t BtAdvTypeToSoftbus(uint16_t advType)
{
switch (advType) {
case SERVICE_BC_TYPE:
return BC_DATA_TYPE_SERVICE;
case MANUFACTURE_BC_TYPE:
return BC_DATA_TYPE_MANUFACTURER;
default:
return 0x00;
}
}
static BleAdvFilter SoftbusAdvFilterToBt(uint8_t advFilter)
{
switch (advFilter) {
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY:
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY:
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY;
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST:
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST;
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST:
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST;
default:
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
}
}
static BleAdvType SoftbusAdvTypeToBt(uint8_t advType)
{
switch (advType) {
case SOFTBUS_BC_ADV_IND:
return OHOS_BLE_ADV_IND;
case SOFTBUS_BC_ADV_DIRECT_IND_HIGH:
return OHOS_BLE_ADV_DIRECT_IND_HIGH;
case SOFTBUS_BC_ADV_SCAN_IND:
return OHOS_BLE_ADV_SCAN_IND;
case SOFTBUS_BC_ADV_NONCONN_IND:
return OHOS_BLE_ADV_NONCONN_IND;
case SOFTBUS_BC_ADV_DIRECT_IND_LOW:
return OHOS_BLE_ADV_DIRECT_IND_LOW;
default:
return OHOS_BLE_ADV_IND;
}
}
void SoftbusAdvParamToBt(const SoftbusBroadcastParam *src, BleAdvParams *dst)
{
if (memcpy_s(dst->peerAddr.addr, SOFTBUS_ADDR_MAC_LEN, src->peerAddr.addr, SOFTBUS_ADDR_MAC_LEN) != EOK) {
DISC_LOGW(DISC_BLE_ADAPTER, "copy peer addr failed");
}
dst->minInterval = src->minInterval;
dst->maxInterval = src->maxInterval;
dst->advType = SoftbusAdvTypeToBt(src->advType);
dst->ownAddrType = (unsigned char)src->ownAddrType;
dst->peerAddrType = (unsigned char)src->peerAddrType;
dst->channelMap = src->channelMap;
dst->advFilterPolicy = SoftbusAdvFilterToBt(src->advFilterPolicy);
dst->txPower = src->txPower;
dst->duration = src->duration;
}
static uint8_t BtScanEventTypeToSoftbus(unsigned char eventType)
{
switch (eventType) {
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE:
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE;
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED:
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
case OHOS_BLE_EVT_CONNECTABLE:
return SOFTBUS_BC_EVT_CONNECTABLE;
case OHOS_BLE_EVT_CONNECTABLE_DIRECTED:
return SOFTBUS_BC_EVT_CONNECTABLE_DIRECTED;
case OHOS_BLE_EVT_SCANNABLE:
return SOFTBUS_BC_EVT_SCANNABLE;
case OHOS_BLE_EVT_SCANNABLE_DIRECTED:
return SOFTBUS_BC_EVT_SCANNABLE_DIRECTED;
case OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE:
return SOFTBUS_BC_EVT_LEGACY_NON_CONNECTABLE;
case OHOS_BLE_EVT_LEGACY_SCANNABLE:
return SOFTBUS_BC_EVT_LEGACY_SCANNABLE;
case OHOS_BLE_EVT_LEGACY_CONNECTABLE:
return SOFTBUS_BC_EVT_LEGACY_CONNECTABLE;
case OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED:
return SOFTBUS_BC_EVT_LEGACY_CONNECTABLE_DIRECTED;
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN:
return SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN;
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV:
return SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV;
default:
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE;
}
}
static uint8_t BtScanDataStatusToSoftbus(unsigned char dataStatus)
{
switch (dataStatus) {
case OHOS_BLE_DATA_COMPLETE:
return SOFTBUS_BC_DATA_COMPLETE;
case OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME:
return SOFTBUS_BC_DATA_INCOMPLETE_MORE_TO_COME;
case OHOS_BLE_DATA_INCOMPLETE_TRUNCATED:
return SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED;
default:
return SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED;
}
}
static uint8_t BtScanAddrTypeToSoftbus(unsigned char addrType)
{
switch (addrType) {
case OHOS_BLE_PUBLIC_DEVICE_ADDRESS:
return SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS;
case OHOS_BLE_RANDOM_DEVICE_ADDRESS:
return SOFTBUS_BC_RANDOM_DEVICE_ADDRESS;
case OHOS_BLE_PUBLIC_IDENTITY_ADDRESS:
return SOFTBUS_BC_PUBLIC_IDENTITY_ADDRESS;
case OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS:
return SOFTBUS_BC_RANDOM_STATIC_IDENTITY_ADDRESS;
case OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS:
return SOFTBUS_BC_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
case OHOS_BLE_NO_ADDRESS:
return SOFTBUS_BC_NO_ADDRESS;
default:
return SOFTBUS_BC_NO_ADDRESS;
}
}
static uint8_t BtScanPhyTypeToSoftbus(unsigned char phyType)
{
switch (phyType) {
case OHOS_BLE_SCAN_PHY_NO_PACKET:
return SOFTBUS_BC_SCAN_PHY_NO_PACKET;
case OHOS_BLE_SCAN_PHY_1M:
return SOFTBUS_BC_SCAN_PHY_1M;
case OHOS_BLE_SCAN_PHY_2M:
return SOFTBUS_BC_SCAN_PHY_2M;
case OHOS_BLE_SCAN_PHY_CODED:
return SOFTBUS_BC_SCAN_PHY_CODED;
default:
return SOFTBUS_BC_SCAN_PHY_NO_PACKET;
}
}
void BtScanResultToSoftbus(const BtScanResultData *src, SoftBusBcScanResult *dst)
{
dst->eventType = BtScanEventTypeToSoftbus(src->eventType);
dst->dataStatus = BtScanDataStatusToSoftbus(src->dataStatus);
dst->addrType = BtScanAddrTypeToSoftbus(src->addrType);
if (memcpy_s(dst->addr.addr, SOFTBUS_ADDR_MAC_LEN, src->addr.addr, SOFTBUS_ADDR_MAC_LEN) != EOK) {
DISC_LOGW(DISC_BLE_ADAPTER, "copy addr failed");
}
dst->primaryPhy = BtScanPhyTypeToSoftbus(src->primaryPhy);
dst->secondaryPhy = BtScanPhyTypeToSoftbus(src->secondaryPhy);
dst->advSid = (uint8_t)src->advSid;
dst->txPower = (int8_t)src->txPower;
dst->rssi = (int8_t)src->rssi;
}
void SoftbusFilterToBt(BleScanNativeFilter *nativeFilter, const SoftBusBcScanFilter *filter, uint8_t filterSize)
{
while (filterSize-- > 0) {
(nativeFilter + filterSize)->address = (char *)(filter + filterSize)->address;
(nativeFilter + filterSize)->deviceName = (char *)(filter + filterSize)->deviceName;
(nativeFilter + filterSize)->manufactureData = (unsigned char *)(filter + filterSize)->manufactureData;
(nativeFilter + filterSize)->manufactureDataLength =
(unsigned int)(filter + filterSize)->manufactureDataLength;
(nativeFilter + filterSize)->manufactureDataMask = (unsigned char *)(filter + filterSize)->manufactureDataMask;
(nativeFilter + filterSize)->manufactureId = (unsigned short)(filter + filterSize)->manufactureId;
if ((filter + filterSize)->serviceData == NULL || (filter + filterSize)->serviceDataMask == NULL) {
continue;
}
// serviceData = uuid + serviceData, serviceDataMask = 0xFFFF + serviceDataMask
uint16_t serviceUuid = (filter + filterSize)->serviceUuid;
uint16_t serviceDataLen = (filter + filterSize)->serviceDataLength + 2;
uint8_t *serviceData = (uint8_t *)SoftBusCalloc(serviceDataLen);
if (serviceData == NULL) {
DISC_LOGW(DISC_BLE_ADAPTER, "malloc service data failed");
continue;
}
serviceData[0] = serviceUuid & BC_BYTE_MASK;
serviceData[1] = (serviceUuid >> BC_SHIFT_BIT) & BC_BYTE_MASK;
if (memcpy_s(serviceData + UUID_LEN, serviceDataLen - UUID_LEN, (filter + filterSize)->serviceData,
serviceDataLen - UUID_LEN) != EOK) {
DISC_LOGW(DISC_BLE_ADAPTER, "copy service data failed");
}
uint8_t *serviceDataMask = (uint8_t *)SoftBusCalloc(serviceDataLen);
if (serviceDataMask == NULL) {
SoftBusFree(serviceData);
DISC_LOGW(DISC_BLE_ADAPTER, "malloc service data mask failed");
continue;
}
serviceDataMask[0] = BC_BYTE_MASK;
serviceDataMask[1] = BC_BYTE_MASK;
if (memcpy_s(serviceDataMask + UUID_MASK_LEN, serviceDataLen - UUID_MASK_LEN,
(filter + filterSize)->serviceDataMask, serviceDataLen - UUID_MASK_LEN) != EOK) {
DISC_LOGW(DISC_BLE_ADAPTER, "copy service data mask failed");
}
(nativeFilter + filterSize)->serviceData = (unsigned char *)serviceData;
(nativeFilter + filterSize)->serviceDataLength = (unsigned int)serviceDataLen;
(nativeFilter + filterSize)->serviceDataMask = (unsigned char *)serviceDataMask;
}
}
void FreeBtFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize)
{
while (filterSize-- > 0) {
SoftBusFree((nativeFilter + filterSize)->serviceData);
SoftBusFree((nativeFilter + filterSize)->serviceDataMask);
}
SoftBusFree(nativeFilter);
}
void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize)
{
while (filterSize-- > 0) {
uint32_t len = (nativeFilter + filterSize)->serviceDataLength;
if (len == 0) {
continue;
}
uint32_t hexLen = HEXIFY_LEN(len);
char *serviceData = (char *)SoftBusCalloc(sizeof(char) * hexLen);
if (serviceData == NULL) {
continue;
}
char *serviceDataMask = (char *)SoftBusCalloc(sizeof(char) * hexLen);
if (serviceDataMask == NULL) {
SoftBusFree(serviceData);
continue;
}
(void)ConvertBytesToHexString(serviceData, hexLen, (nativeFilter + filterSize)->serviceData, len);
(void)ConvertBytesToHexString(serviceDataMask, hexLen, (nativeFilter + filterSize)->serviceDataMask, len);
DISC_LOGI(DISC_BLE_ADAPTER, "BLE Scan Filter size:%d [serviceData:%s, serviceDataMask:%s]",
filterSize, serviceData, serviceDataMask);
SoftBusFree(serviceData);
SoftBusFree(serviceDataMask);
}
}
int GetBtScanMode(uint16_t scanInterval, uint16_t scanWindow)
{
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P2 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P2) {
return OHOS_BLE_SCAN_MODE_OP_P2_60_3000;
}
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P10 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P10) {
return OHOS_BLE_SCAN_MODE_OP_P10_60_600;
}
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P25 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P25) {
return OHOS_BLE_SCAN_MODE_OP_P25_60_240;
}
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P100 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P100) {
return OHOS_BLE_SCAN_MODE_OP_P100_1000_1000;
}
return OHOS_BLE_SCAN_MODE_LOW_POWER;
}
uint8_t *AssembleAdvData(const SoftbusBroadcastData *data, uint16_t *dataLen)
{
uint16_t payloadLen = (data->bcData.payloadLen > BC_DATA_MAX_LEN) ? BC_DATA_MAX_LEN : data->bcData.payloadLen;
uint16_t len = data->isSupportFlag ? payloadLen + BC_HEAD_LEN : payloadLen + BC_HEAD_LEN - BC_FLAG_LEN;
uint8_t *advData = (uint8_t *)SoftBusCalloc(len);
if (advData == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "malloc adv data failed");
return NULL;
}
int8_t offset = -BC_FLAG_LEN;
if (data->isSupportFlag) {
advData[IDX_BC_FLAG_BYTE_LEN] = BC_FLAG_BYTE_LEN;
advData[IDX_BC_FLAG_AD_TYPE] = BC_FLAG_AD_TYPE;
advData[IDX_BC_FLAG_AD_DATA] = data->flag;
offset += BC_FLAG_LEN;
}
advData[IDX_PACKET_LEN + offset] = payloadLen + BC_HEAD_LEN - BC_FLAG_LEN - 1;
advData[IDX_BC_TYPE + offset] = SoftbusAdvDataTypeToBt(data->bcData.type);
uint16_t payloadId = data->bcData.id;
advData[IDX_BC_UUID + offset] = (uint8_t)(payloadId & BC_BYTE_MASK);
advData[IDX_BC_UUID + offset + 1] = (uint8_t)((payloadId >> BC_SHIFT_BIT) & BC_BYTE_MASK);
if (memcpy_s(&advData[BC_HEAD_LEN + offset], payloadLen, data->bcData.payload, payloadLen) != EOK) {
DISC_LOGE(DISC_BLE_ADAPTER, "copy adv payload failed");
SoftBusFree(advData);
return NULL;
}
*dataLen = len;
return advData;
}
uint8_t *AssembleRspData(const SoftbusBroadcastPayload *data, uint16_t *dataLen)
{
uint16_t payloadLen = (data->payloadLen > RSP_DATA_MAX_LEN) ? RSP_DATA_MAX_LEN : data->payloadLen;
uint16_t len = payloadLen + RSP_HEAD_LEN;
uint8_t *rspData = (uint8_t *)SoftBusCalloc(len);
if (rspData == NULL) {
DISC_LOGE(DISC_BLE_ADAPTER, "malloc rsp data failed");
return NULL;
}
rspData[IDX_RSP_PACKET_LEN] = payloadLen + RSP_HEAD_LEN - 1;
rspData[IDX_RSP_TYPE] = SoftbusAdvDataTypeToBt(data->type);
uint16_t payloadId = data->id;
rspData[IDX_RSP_UUID] = (uint8_t)(payloadId & BC_BYTE_MASK);
rspData[IDX_RSP_UUID + 1] = (uint8_t)((payloadId >> BC_SHIFT_BIT) & BC_BYTE_MASK);
if (memcpy_s(&rspData[RSP_HEAD_LEN], payloadLen, data->payload, payloadLen) != EOK) {
DISC_LOGE(DISC_BLE_ADAPTER, "copy rsp payload failed");
SoftBusFree(rspData);
return NULL;
}
*dataLen = len;
return rspData;
}
static int32_t ParseFlag(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst, uint8_t index)
{
if (index + 1 >= advLen) {
DISC_LOGE(DISC_BLE_ADAPTER, "parse flag failed");
return SOFTBUS_ERR;
}
dst->data.flag = advData[index + 1];
dst->data.isSupportFlag = true;
return SOFTBUS_OK;
}
static int32_t ParseLocalName(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst, uint8_t index,
uint8_t len)
{
if (index + 1 >= advLen) {
DISC_LOGE(DISC_BLE_ADAPTER, "parse local name failed");
return SOFTBUS_ERR;
}
if (memcpy_s(dst->localName, sizeof(dst->localName), &advData[index + 1], len - 1) != EOK) {
DISC_LOGE(DISC_BLE_ADAPTER, "copy local name failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t ParseScanResult(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst)
{
uint8_t index = 0;
bool isRsp = false;
while (index < advLen) {
uint8_t len = advData[index];
if (len == 0) {
index++;
continue;
}
if (index + len >= advLen || index + 1 >= advLen) {
break;
}
uint8_t type = advData[++index];
if (type == BC_FLAG_AD_TYPE) {
DISC_CHECK_AND_RETURN_RET_LOGE(ParseFlag(advData, advLen, dst, index) == SOFTBUS_OK, SOFTBUS_ERR,
DISC_BLE_ADAPTER, "parse flag failed");
} else if (type == SHORTENED_LOCAL_NAME_BC_TYPE || type == LOCAL_NAME_BC_TYPE) {
DISC_CHECK_AND_RETURN_RET_LOGE(ParseLocalName(advData, advLen, dst, index, len) == SOFTBUS_OK, SOFTBUS_ERR,
DISC_BLE_ADAPTER, "parse local name failed");
} else {
if (type != SERVICE_BC_TYPE && type != MANUFACTURE_BC_TYPE) {
index += len;
DISC_LOGW(DISC_BLE_ADAPTER, "unsupported type: %hhu", type);
continue;
}
SoftbusBroadcastPayload *data = isRsp ? &dst->data.rspData : &dst->data.bcData;
data->payloadLen = len - ID_LEN - 1;
if (data->payloadLen < 0 || index + ID_LEN >= advLen) {
DISC_LOGE(DISC_BLE_ADAPTER, "parse payload failed");
return SOFTBUS_ERR;
}
isRsp = !isRsp;
data->type = BtAdvTypeToSoftbus(type);
data->id = ((uint16_t)advData[index + ID_LEN] << BC_SHIFT_BIT) | (uint16_t)advData[index + ID_LEN - 1];
if (data->payloadLen == 0) {
index += len;
DISC_LOGW(DISC_BLE_ADAPTER, "parse no payload, isRsp: %d", isRsp);
continue;
}
data->payload = (uint8_t *)SoftBusCalloc(data->payloadLen);
DISC_CHECK_AND_RETURN_RET_LOGE(data->payload != NULL, SOFTBUS_ERR, DISC_BLE_ADAPTER,
"malloc payload failed");
(void)memcpy_s(data->payload, data->payloadLen, &advData[index + ID_LEN + 1], data->payloadLen);
}
index += len;
}
return SOFTBUS_OK;
}
void DumpSoftbusAdapterData(const char *description, uint8_t *data, uint16_t len)
{
DISC_CHECK_AND_RETURN_LOGE(description != NULL, DISC_BLE_ADAPTER, "data is null!");
DISC_CHECK_AND_RETURN_LOGE(len != 0, DISC_BLE_ADAPTER, "len is 0!");
DISC_CHECK_AND_RETURN_LOGE(data != NULL, DISC_BLE_ADAPTER, "data is null!");
int32_t hexLen = HEXIFY_LEN(len);
char *softbusData = (char *)SoftBusCalloc(sizeof(char) * hexLen);
DISC_CHECK_AND_RETURN_LOGE(softbusData != NULL, DISC_BLE_ADAPTER, "malloc failed!");
(void)ConvertBytesToHexString(softbusData, hexLen, data, len);
DISC_LOGI(DISC_BLE_ADAPTER, "%s softbusData:%s", description, softbusData);
SoftBusFree(softbusData);
}

View File

@ -77,7 +77,7 @@ typedef struct {
int32_t (*SetBroadcastingData)(int32_t advId, const SoftbusBroadcastData *data);
int32_t (*UpdateBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data);
int32_t (*StartScan)(int32_t scannerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
uint8_t filterSize);
int32_t filterSize);
int32_t (*StopScan)(int32_t scannerId);
bool (*IsLpDeviceAvailable)(void);
bool (*SetAdvFilterParam)(const SoftBusLpBroadcastParam *bcParam, const SoftBusLpScanParam *scanParam);

View File

@ -246,7 +246,7 @@ int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_
* @since 4.1
* @version 1.0
*/
int32_t GetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t *filterNum);
int32_t GetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *filterNum);
/**
* @brief Check whether available resources are available by using the bcid

View File

@ -87,6 +87,7 @@ typedef enum {
SRV_TYPE_SHARE, // The service type is share discovery.
SRV_TYPE_APPROACH, // The service type is approach discovery.
SRV_TYPE_SH, // The service type is sensorhub.
SRV_TYPE_FAST_OFFLINE, // The service type is fast offline.
SRV_TYPE_BUTT,
} BaseServiceType;
@ -396,8 +397,7 @@ typedef struct {
*/
typedef struct {
BcScanParams scanParam;
BcScanFilter *filter;
uint8_t filterSize;
int32_t listenerId;
} LpScanParam;
#ifdef __cplusplus

View File

@ -33,8 +33,8 @@ extern "C"{
#define MEDIUM_NUM_MAX 2
// max broadcasting and scan limit
#define BC_NUM_MAX 9
#define SCAN_NUM_MAX 9
#define BC_NUM_MAX 16
#define SCAN_NUM_MAX 16
#define BC_DATA_MAX_LEN 24
#define RSP_DATA_MAX_LEN 27

View File

@ -102,7 +102,7 @@ static void WrapperAclStateChangedCallback(const BdAddr *bdAddr, GapAclState sta
return;
}
COMM_LOGI(COMM_ADAPTER, "WrapperAclStateChangedCallback, addr:%02X:%02X:***%02X, state=%d, reason=%u",
COMM_LOGD(COMM_ADAPTER, "WrapperAclStateChangedCallback, addr:%02X:%02X:***%02X, state=%d, reason=%u",
bdAddr->addr[MAC_FIRST_INDEX], bdAddr->addr[MAC_ONE_INDEX], bdAddr->addr[MAC_FIVE_INDEX], state, reason);
int listenerId;
int aclState = ConvertAclState(state);
@ -248,7 +248,6 @@ int SoftBusSetBtName(const char *name)
return SOFTBUS_ERR;
}
void SoftBusBtInit(void)
{
if (SoftBusGetBtState() == BLE_ENABLE) {

View File

@ -18,6 +18,9 @@ adapter_ble_inc = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
"$dsoftbus_root_path/adapter/common/net/bluetooth/common",
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/interface",
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/include",
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/include",
]
adapter_ble_src = [
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c",
@ -25,7 +28,20 @@ adapter_ble_src = [
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/adapter_bt_utils.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/softbus_adapter_bt_common.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/src/softbus_ble_utils.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/manager/src/softbus_broadcast_mgr.c",
]
if (dsoftbus_feature_ex_kits) {
import(
"$dsoftbus_root_path/dsoftbus_enhance/adapter/common/net/bluetooth/broadcast/adapter/ble/adapter_ble_enhance.gni")
adapter_ble_inc += adapter_ble_enhance_inc
adapter_ble_src += adapter_ble_enhance_src
} else {
adapter_ble_src += [ "$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/src/softbus_ble_gatt.c" ]
}
adapter_net_br_src = [ "$dsoftbus_root_path/adapter/common/net/bluetooth/common/softbus_adapter_bt_common.c" ]
adapter_ble_external_deps = [ "bluetooth:btframework" ]
if (defined(ohos_lite)) {

View File

@ -15,7 +15,6 @@
#include "softbus_adapter_perf.h"
bool SoftBusIsRamTest(void)
{
return false;

View File

@ -110,6 +110,7 @@
"test": [
"//foundation/communication/dsoftbus/tests/adapter:fuzztest",
"//foundation/communication/dsoftbus/tests/adapter:unittest",
"//foundation/communication/dsoftbus/tests/core/adapter:fuzztest",
"//foundation/communication/dsoftbus/tests/core/adapter:unittest",
"//foundation/communication/dsoftbus/tests/core/authentication:fuzztest",
"//foundation/communication/dsoftbus/tests/core/authentication:unittest",

View File

@ -28,7 +28,6 @@
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include <coap3/utlist.h>
#include <coap3/coap_session_internal.h>
#include "nstackx_device.h"
#include "nstackx_error.h"

View File

@ -189,7 +189,7 @@ static int32_t CoapSendRequestEx(CoapCtxType *ctx, uint8_t coapType, const char
DFINDER_LOGD("MYCOAP", "send coap pdu mid: %d", coap_pdu_get_mid(pdu));
DFINDER_MGT_REQ_LOG(&coapRequest);
tid = coap_send(session, pdu);
if (tid == COAP_INVALID_TID) {
if (tid == COAP_INVALID_MID) {
DFINDER_LOGE(TAG, "coap send failed");
goto SESSION_RELEASE;
}
@ -983,7 +983,7 @@ int32_t CoapInitResources(coap_context_t *ctx)
DFINDER_LOGE(TAG, "coap resource init discover failed");
return NSTACKX_ENOMEM;
}
coap_register_handler(r, COAP_REQUEST_POST, HndPostServiceDiscover);
coap_register_request_handler(r, COAP_REQUEST_POST, HndPostServiceDiscover);
coap_resource_set_get_observable(r, NSTACKX_TRUE);
coap_add_resource(ctx, r);
@ -994,7 +994,7 @@ int32_t CoapInitResources(coap_context_t *ctx)
(void)coap_delete_resource(ctx, r);
return NSTACKX_ENOMEM;
}
coap_register_handler(msg, COAP_REQUEST_POST, HndPostServiceMsg);
coap_register_request_handler(msg, COAP_REQUEST_POST, HndPostServiceMsg);
coap_add_resource(ctx, msg);
return NSTACKX_EOK;
}

View File

@ -361,7 +361,7 @@ static void ParseBusinessType(const cJSON *data, DeviceInfo *dev)
item = cJSON_GetObjectItemCaseSensitive(data, JSON_BUSINESS_TYPE);
if (item == NULL) {
dev->businessType = NSTACKX_BUSINESS_TYPE_NULL;
DFINDER_LOGW(TAG, "Cannot get businessType json");
DFINDER_LOGD(TAG, "Cannot get businessType json");
return;
}
if (!cJSON_IsNumber(item) || (item->valuedouble < 0)) {
@ -377,7 +377,7 @@ static void ParseBusinessDataJsonData(const cJSON *data, DeviceInfo *dev, uint8_
cJSON *item = NULL;
item = cJSON_GetObjectItemCaseSensitive(data, JSON_BUSINESS_DATA);
if (item == NULL) {
DFINDER_LOGE(TAG, "Cannot get businessData json");
DFINDER_LOGD(TAG, "Cannot get businessData json");
return;
}
if (!cJSON_IsString(item)) {

View File

@ -124,8 +124,7 @@ static int32_t UpdateDeviceDbInDeviceList(const CoapCtxType *coapCtx, const Devi
}
// for non-automatic reply businessType, report each unicast received, even if the content is same
if (!receiveBcast && (CheckBusinessTypeReplyUnicast(deviceInfo->businessType) != NSTACKX_EOK)) {
DeviceInfoNotify(deviceInfo);
return NSTACKX_EOK;
return updated ? DeviceInfoNotify(deviceInfo) : NSTACKX_EOK;
}
if (updated || forceUpdate) {
DFINDER_LOGD(TAG, "updated is: %hhu, forceUpdate is: %hhu", updated, forceUpdate);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -15,15 +15,12 @@
#include "wrapper_br_interface.h"
#include "message_handler.h"
#include "c_header/ohos_bt_def.h"
#include "c_header/ohos_bt_gap.h"
#include "c_header/ohos_bt_spp.h"
#include "c_header/ohos_bt_socket.h"
#include "securec.h"
#include "conn_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "securec.h"
#include "softbus_errcode.h"
#include "string.h"
@ -106,6 +103,7 @@ static int32_t Accept(int32_t serverFd)
CONN_LOGI(CONN_BR, "[Accept remote device to connect, and serverFd = %d]", serverFd);
int32_t ret = SppServerAccept(serverFd);
if (ret == BT_SPP_INVALID_ID) {
CONN_LOGE(CONN_BR, "Accept spp server failed");
return SOFTBUS_ERR;
}
return ret;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +14,6 @@
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <securec.h>
@ -25,9 +24,7 @@
#include "lnn_log.h"
#include "lnn_settingdata_event_monitor.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_log.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_utils.h"
@ -109,7 +106,7 @@ int32_t GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len)
switch (key) {
case COMM_DEVICE_KEY_DEVNAME:
LNN_LOGI(LNN_STATE, "set default devicename in netledger init");
if (strncpy_s(value, len, DEFAULT_DEVICE_NAME, strlen(DEFAULT_DEVICE_NAME)) != EOK) {
if (strcpy_s(value, len, DEFAULT_DEVICE_NAME) != EOK) {
return SOFTBUS_ERR;
}
break;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -14,7 +14,6 @@
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <securec.h>

View File

@ -23,7 +23,6 @@
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_mem.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"

View File

@ -22,7 +22,7 @@
#include "securec.h"
#include "softbus_errcode.h"
#define ACCOUNT_STRTOLL_BASE 10
static const int32_t ACCOUNT_STRTOLL_BASE = 10;
#define DEFAULT_ACCOUNT_NAME "ohosAnonymousName"
int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len)

View File

@ -19,12 +19,15 @@
int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len)
{
(void)id;
(void)idLen;
(void)len;
return SOFTBUS_OK;
}
int64_t GetCurrentAccount(void)
{
return 0;
return SOFTBUS_OK;
}
int32_t GetActiveOsAccountIds(void)

View File

@ -38,10 +38,10 @@ namespace OHOS {
namespace BusCenter {
static const std::string SETTINGS_DATA_BASE_URI =
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
static const std::string SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
static const std::string SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD";
static const std::string SETTINGS_DATA_FIELD_VALUE = "VALUE";
static const std::string PREDICATES_STRING = "settings.general.device_name";
static constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
static constexpr const char *SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD";
static constexpr const char *SETTINGS_DATA_FIELD_VALUE = "VALUE";
static constexpr const char *PREDICATES_STRING = "settings.general.device_name";
std::shared_ptr<DataShare::DataShareHelper> g_dataShareHelper;
static const uint32_t SOFTBUS_SA_ID = 4700;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "lnn_ohos_account.h"
#include "lnn_settingdata_event_monitor.h"
#include "softbus_errcode.h"

View File

@ -91,7 +91,6 @@ int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, co
int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len);
int32_t AuthSessionHandleDeviceNotTrusted(const char *udid);
int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId);
AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq);
AuthFsm *GetAuthFsmByConnId(uint64_t connId, bool isServer);
void AuthSessionFsmExit(void);

View File

@ -50,6 +50,7 @@ typedef enum {
AUTH_LINK_TYPE_BR,
AUTH_LINK_TYPE_BLE,
AUTH_LINK_TYPE_P2P,
AUTH_LINK_TYPE_ENHANCED_P2P,
AUTH_LINK_TYPE_MAX,
} AuthLinkType;
@ -69,6 +70,8 @@ typedef struct {
char ip[IP_LEN];
int32_t port;
int64_t authId; /* for open p2p auth conn */
ListenerModule moduleId; /* for open enhance p2p auth conn */
char udid[UDID_BUF_LEN];
} ipInfo;
} info;
char peerUid[MAX_ACCOUNT_HASH_LEN];
@ -128,6 +131,9 @@ bool IsAuthHasTrustedRelation(void);
int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port);
void AuthStopListening(AuthLinkType type);
int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip, int32_t port, ListenerModule *moduleId);
void AuthStopListeningForWifiDirect(AuthLinkType type, ListenerModule moduleId);
typedef struct {
int32_t module;
int32_t flag;
@ -177,7 +183,7 @@ int32_t AuthGetGroupType(const char *udid, const char *uuid);
int32_t AuthInit(void);
void AuthDeinit(void);
int32_t AuthRestoreAuthManager(const char *udidHash,
const AuthConnInfo *connInfo, int32_t requestId, NodeInfo *nodeInfo, int64_t *authId);
const AuthConnInfo *connInfo, uint32_t requestId, NodeInfo *nodeInfo, int64_t *authId);
#ifdef __cplusplus
#if __cplusplus

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -131,9 +131,11 @@ static int32_t CustomFunc(const SoftBusMessage *msg, void *param)
CHECK_NULL_PTR_RETURN_VALUE(param, SOFTBUS_ERR);
EventRemoveInfo *info = (EventRemoveInfo *)param;
if (msg->what != (int32_t)info->event) {
AUTH_LOGE(AUTH_CONN, "msg->what and event inequality");
return SOFTBUS_ERR;
}
if (info->cmpFunc == NULL) {
AUTH_LOGE(AUTH_CONN, "cmpFunc is null");
return SOFTBUS_ERR;
}
return info->cmpFunc(msg->obj, info->param);
@ -185,13 +187,16 @@ bool GetConfigSupportAsServer(void)
uint8_t *DupMemBuffer(const uint8_t *buf, uint32_t size)
{
if (buf == NULL || size == 0) {
AUTH_LOGE(AUTH_CONN, "param err");
return NULL;
}
uint8_t *dup = (uint8_t *)SoftBusMalloc(size);
if (dup == NULL) {
AUTH_LOGE(AUTH_CONN, "malloc err");
return NULL;
}
if (memcpy_s(dup, size, buf, size) != EOK) {
AUTH_LOGE(AUTH_CONN, "memcpy err");
SoftBusFree(dup);
return NULL;
}
@ -278,6 +283,12 @@ bool CompareConnInfo(const AuthConnInfo *info1, const AuthConnInfo *info2, bool
return true;
}
break;
case AUTH_LINK_TYPE_ENHANCED_P2P:
if (info2->type == AUTH_LINK_TYPE_ENHANCED_P2P && info1->info.ipInfo.port == info2->info.ipInfo.port &&
strcmp(info1->info.ipInfo.ip, info2->info.ipInfo.ip) == 0) {
return true;
}
break;
default:
AUTH_LOGE(AUTH_CONN, "unexpected connType=%d", info1->type);
return false;
@ -321,6 +332,18 @@ int32_t ConvertToConnectOption(const AuthConnInfo *connInfo, ConnectOption *opti
option->socketOption.protocol = LNN_PROTOCOL_IP;
option->socketOption.keepAlive = 1;
break;
case AUTH_LINK_TYPE_ENHANCED_P2P:
option->type = CONNECT_TCP;
if (strcpy_s(option->socketOption.addr, sizeof(option->socketOption.addr), connInfo->info.ipInfo.ip) !=
EOK) {
AUTH_LOGE(AUTH_CONN, "copy ip fail");
return SOFTBUS_MEM_ERR;
}
option->socketOption.port = connInfo->info.ipInfo.port;
option->socketOption.moduleId = connInfo->info.ipInfo.moduleId;
option->socketOption.protocol = LNN_PROTOCOL_IP;
option->socketOption.keepAlive = 1;
break;
default:
AUTH_LOGE(AUTH_CONN, "unexpected connType=%d", connInfo->type);
return SOFTBUS_ERR;
@ -328,6 +351,14 @@ int32_t ConvertToConnectOption(const AuthConnInfo *connInfo, ConnectOption *opti
return SOFTBUS_OK;
}
static bool IsEnhanceP2pModuleId(ListenerModule moduleId)
{
if (moduleId >= AUTH_ENHANCED_P2P_START && moduleId <= AUTH_ENHANCED_P2P_END) {
return true;
}
return false;
}
int32_t ConvertToAuthConnInfo(const ConnectionInfo *info, AuthConnInfo *connInfo)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
@ -338,7 +369,11 @@ int32_t ConvertToAuthConnInfo(const ConnectionInfo *info, AuthConnInfo *connInfo
AUTH_LOGW(AUTH_CONN, "only support LNN_PROTOCOL_IP");
return SOFTBUS_ERR;
}
connInfo->type = AUTH_LINK_TYPE_P2P;
if (IsEnhanceP2pModuleId(info->socketInfo.moduleId)) {
connInfo->type = AUTH_LINK_TYPE_ENHANCED_P2P;
} else {
connInfo->type = AUTH_LINK_TYPE_P2P;
}
connInfo->info.ipInfo.port = info->socketInfo.port;
if (strcpy_s(connInfo->info.ipInfo.ip, IP_LEN, info->socketInfo.addr) != EOK) {
AUTH_LOGE(AUTH_CONN, "copy ip fail");
@ -406,5 +441,6 @@ int32_t GetPeerUdidByNetworkId(const char *networkId, char *udid)
}
return SOFTBUS_OK;
}
AUTH_LOGE(AUTH_CONN, "info or deviceUdid is null");
return SOFTBUS_ERR;
}

View File

@ -23,12 +23,11 @@
#include "lnn_async_callback_utils.h"
#include "lnn_event.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
#include "softbus_base_listener.h"
#include "softbus_conn_interface.h"
#include "softbus_def.h"
#include "softbus_adapter_errcode.h"
#define AUTH_CONN_DATA_HEAD_SIZE 24
#define AUTH_CONN_CONNECT_TIMEOUT_MS 10000
@ -52,6 +51,8 @@ typedef struct {
static ListNode g_connRequestList = { &g_connRequestList, &g_connRequestList };
static AuthConnListener g_listener = { 0 };
static bool g_enahnceP2pModuleIdStatics[AUTH_ENHANCED_P2P_NUM];
void __attribute__((weak)) RouteBuildClientAuthManager(int32_t cfd)
{
(void)cfd;
@ -61,6 +62,32 @@ void __attribute__((weak)) RouteClearAuthChannelId(int32_t cfd)
(void)cfd;
}
static bool IsEnhanceP2pModuleId(ListenerModule moduleId)
{
if (moduleId >= AUTH_ENHANCED_P2P_START && moduleId <= AUTH_ENHANCED_P2P_END) {
return true;
}
return false;
}
static ListenerModule AllocateWfiDirectListenerModuleId(void)
{
for (int32_t i = 0; i < AUTH_ENHANCED_P2P_NUM; i++) {
if (!g_enahnceP2pModuleIdStatics[i]) {
g_enahnceP2pModuleIdStatics[i] = true;
return (ListenerModule)(AUTH_ENHANCED_P2P_START + i);
}
}
return (ListenerModule)SOFTBUS_ERR;
}
static void FreeWifiDirectListenerModuleId(ListenerModule moduleId)
{
if (IsEnhanceP2pModuleId(moduleId)) {
g_enahnceP2pModuleIdStatics[moduleId - AUTH_ENHANCED_P2P_START] = false;
}
}
uint64_t GenConnId(int32_t connType, int32_t id)
{
uint64_t connId = (uint64_t)connType;
@ -86,6 +113,8 @@ const char *GetConnTypeStr(uint64_t connId)
return "ble";
case AUTH_LINK_TYPE_P2P:
return "p2p";
case AUTH_LINK_TYPE_ENHANCED_P2P:
return "enhanced_p2p";
default:
break;
}
@ -104,6 +133,7 @@ int32_t GetFd(uint64_t connId)
void UpdateFd(uint64_t *connId, int32_t id)
{
CHECK_NULL_PTR_RETURN_VOID(connId);
*connId &= MASK_UINT64_H32;
*connId |= (((uint64_t)id) & MASK_UINT64_L32);
}
@ -348,7 +378,7 @@ static void OnWiFiDataReceived(ListenerModule module, int32_t fd, const AuthData
CHECK_NULL_PTR_RETURN_VOID(head);
CHECK_NULL_PTR_RETURN_VOID(data);
if (module != AUTH && module != AUTH_P2P) {
if (module != AUTH && module != AUTH_P2P && !IsEnhanceP2pModuleId(module)) {
return;
}
bool fromServer = false;
@ -615,6 +645,7 @@ int32_t ConnectAuthDevice(uint32_t requestId, const AuthConnInfo *connInfo, Conn
}
__attribute__((fallthrough));
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
ret = ConnectCommDevice(connInfo, requestId, sideType);
break;
default:
@ -662,6 +693,7 @@ void DisconnectAuthDevice(uint64_t *connId)
ConnDisconnectDevice(GetConnId(*connId));
__attribute__((fallthrough));
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
break;
default:
AUTH_LOGI(AUTH_CONN, "unknown connType");
@ -681,6 +713,7 @@ int32_t PostAuthData(uint64_t connId, bool toServer, const AuthDataHead *head, c
case AUTH_LINK_TYPE_BLE:
case AUTH_LINK_TYPE_BR:
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
return PostCommData(GetConnId(connId), toServer, head, data);
default:
AUTH_LOGI(AUTH_CONN, "unknown connType");
@ -744,22 +777,6 @@ int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port)
}
return StartSocketListening(AUTH, &info);
}
case AUTH_LINK_TYPE_P2P: {
LocalListenerInfo local = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = port,
.moduleId = AUTH_P2P,
.protocol = LNN_PROTOCOL_IP,
},
};
if (strcpy_s(local.socketOption.addr, sizeof(local.socketOption.addr), ip) != EOK) {
AUTH_LOGE(AUTH_CONN, "strcpy_s ip fail");
return SOFTBUS_MEM_ERR;
}
return ConnStartLocalListening(&local);
}
default:
AUTH_LOGE(AUTH_CONN, "unsupport linkType=%d", type);
break;
@ -774,21 +791,56 @@ void AuthStopListening(AuthLinkType type)
case AUTH_LINK_TYPE_WIFI:
StopSocketListening();
break;
case AUTH_LINK_TYPE_P2P: {
LocalListenerInfo local = {
.type = CONNECT_TCP,
.socketOption = {
.moduleId = AUTH_P2P,
.protocol = LNN_PROTOCOL_IP,
},
};
if (ConnStopLocalListening(&local) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "ConnStopLocalListening fail");
}
break;
}
default:
AUTH_LOGE(AUTH_CONN, "unsupport linkType=%d", type);
break;
}
}
int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip, int32_t port, ListenerModule *moduleId)
{
AUTH_CHECK_AND_RETURN_RET_LOGE(ip != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "ip is null");
AUTH_CHECK_AND_RETURN_RET_LOGE(moduleId != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "moduleId is null");
LocalListenerInfo local;
local.type = CONNECT_TCP;
local.socketOption.port = port;
local.socketOption.protocol = LNN_PROTOCOL_IP;
int32_t ret = strcpy_s(local.socketOption.addr, sizeof(local.socketOption.addr), ip);
AUTH_CHECK_AND_RETURN_RET_LOGE(ret == EOK, SOFTBUS_STRCPY_ERR, AUTH_CONN, "copy ip failed");
if (type == AUTH_LINK_TYPE_P2P) {
local.socketOption.moduleId = AUTH_P2P;
} else if (type == AUTH_LINK_TYPE_ENHANCED_P2P) {
local.socketOption.moduleId = AllocateWfiDirectListenerModuleId();
AUTH_CHECK_AND_RETURN_RET_LOGE(local.socketOption.moduleId > 0, SOFTBUS_ERR, AUTH_CONN,
"alloc listener module id failed");
} else {
AUTH_LOGE(AUTH_CONN, "type=%d invalid", type);
return SOFTBUS_INVALID_PARAM;
}
int32_t realPort = ConnStartLocalListening(&local);
AUTH_CHECK_AND_RETURN_RET_LOGE(realPort > 0, SOFTBUS_ERR, AUTH_CONN, "start local listening failed");
AUTH_LOGI(AUTH_CONN, "moduleId=%u port=%d", local.socketOption.moduleId, realPort);
*moduleId = local.socketOption.moduleId;
return realPort;
}
void AuthStopListeningForWifiDirect(AuthLinkType type, ListenerModule moduleId)
{
AUTH_CHECK_AND_RETURN_LOGE(type == AUTH_LINK_TYPE_P2P || type == AUTH_LINK_TYPE_ENHANCED_P2P, AUTH_CONN,
"type=%d invalid", type);
LocalListenerInfo local = {
.type = CONNECT_TCP,
.socketOption = {
.moduleId = moduleId,
.protocol = LNN_PROTOCOL_IP,
},
};
FreeWifiDirectListenerModuleId(moduleId);
if (ConnStopLocalListening(&local) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "ConnStopLocalListening fail");
}
}

View File

@ -25,10 +25,9 @@
#include "lnn_secure_storage.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_thread.h"
#include "softbus_json_utils.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_json_utils.h"
#include "softbus_utils.h"
#define UDID_SHORT_HASH 8
@ -402,6 +401,10 @@ void AuthRemoveDeviceKey(const char *udidHash, int32_t keyType)
void AuthRemoveDeviceKeyByUdid(const char *udidOrHash)
{
if (udidOrHash == NULL) {
AUTH_LOGE(AUTH_KEY, "param err");
return;
}
char *anonyUdid = NULL;
Anonymize(udidOrHash, &anonyUdid);
AUTH_LOGE(AUTH_KEY, "remove device key, udid=%s", anonyUdid);
@ -418,7 +421,7 @@ void AuthRemoveDeviceKeyByUdid(const char *udidOrHash)
}
while (LnnMapHasNext(it)) {
it = LnnMapNext(it);
if (it ==NULL || it->node->value == NULL) {
if (it == NULL || it->node == NULL) {
break;
}
AuthDeviceCommonKey *deviceKey = (AuthDeviceCommonKey *)it->node->value;
@ -464,6 +467,7 @@ int32_t AuthFindDeviceKey(const char *udidHash, int32_t keyType, AuthDeviceKeyIn
return SOFTBUS_ERR;
}
if (KeyLock() != SOFTBUS_OK) {
AUTH_LOGE(AUTH_KEY, "keyLock fail");
return SOFTBUS_ERR;
}
AuthDeviceCommonKey *data = (AuthDeviceCommonKey *)LnnMapGet(&g_deviceKeyMap, (const char *)keyStr);
@ -500,7 +504,7 @@ static bool AuthParseDeviceKey(const char *deviceKey)
}
int32_t arraySize = cJSON_GetArraySize(json);
if (arraySize <= 0) {
AUTH_LOGE(AUTH_KEY, "no valid deviceKey");
AUTH_LOGE(AUTH_KEY, "invalid deviceKey log");
cJSON_Delete(json);
return false;
}
@ -521,7 +525,7 @@ static bool AuthParseDeviceKey(const char *deviceKey)
void AuthUpdateKeyIndex(const char *udidHash, int32_t keyType, int64_t index, bool isServer)
{
if (udidHash == NULL) {
AUTH_LOGW(AUTH_KEY, "update fail");
AUTH_LOGE(AUTH_KEY, "udidiHash log update fail");
return;
}
char keyStr[MAP_KEY_LEN] = {0};
@ -534,6 +538,10 @@ void AuthUpdateKeyIndex(const char *udidHash, int32_t keyType, int64_t index, bo
return;
}
AuthDeviceCommonKey *data = (AuthDeviceCommonKey *)LnnMapGet(&g_deviceKeyMap, (const char *)keyStr);
if (data == NULL) {
AUTH_LOGE(AUTH_KEY, "data is nullptr");
return;
}
data->keyInfo.keyIndex = index;
data->keyInfo.isServerSide = isServer;
KeyUnlock();
@ -566,7 +574,7 @@ void AuthLoadDeviceKey(void)
AUTH_LOGD(AUTH_KEY, "load deviceKey finish");
}
void AUthClearDeviceKey(void)
void AuthClearDeviceKey(void)
{
/*need aging mechanism*/
LnnMapDelete(&g_deviceKeyMap);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -22,9 +22,8 @@
#include "auth_hichain_adapter.h"
#include "auth_log.h"
#include "auth_session_fsm.h"
#include "device_auth.h"
#include "bus_center_manager.h"
#include "device_auth_defines.h"
#include "device_auth.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_json_utils.h"
@ -184,6 +183,7 @@ static void OnGroupCreated(const char *groupInfo)
return;
}
GroupInfo info;
(void)memset_s(&info, sizeof(GroupInfo), 0, sizeof(GroupInfo));
if (ParseGroupInfo(groupInfo, &info) != SOFTBUS_OK) {
return;
}
@ -212,6 +212,7 @@ static void OnGroupDeleted(const char *groupInfo)
return;
}
GroupInfo info;
(void)memset_s(&info, sizeof(GroupInfo), 0, sizeof(GroupInfo));
if (ParseGroupInfo(groupInfo, &info) != SOFTBUS_OK) {
return;
}
@ -259,7 +260,7 @@ int32_t RegTrustDataChangeListener(const TrustDataChangeListener *listener)
void UnregTrustDataChangeListener(void)
{
int32_t ret = UnregChangeListener(AUTH_APPID);
if (ret != 0) {
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_HICHAIN, "hichain unRegDataChangeListener err=%d", ret);
}
(void)memset_s(&g_dataChangeListener, sizeof(TrustDataChangeListener), 0, sizeof(TrustDataChangeListener));
@ -289,6 +290,7 @@ int32_t HichainStartAuth(int64_t authSeq, const char *udid, const char *uid)
int32_t HichainProcessData(int64_t authSeq, const uint8_t *data, uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_HICHAIN, "data is null");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = ProcessAuthData(authSeq, data, len, &g_hichainCallback);

View File

@ -15,9 +15,7 @@
#include "auth_hichain_adapter.h"
#include <stdlib.h>
#include <string.h>
#include <securec.h>
#include "auth_common.h"
#include "auth_hichain.h"
@ -81,6 +79,8 @@ int32_t RegChangeListener(const char *appId, DataChangeListener *listener)
int32_t UnregChangeListener(const char *appId)
{
AUTH_CHECK_AND_RETURN_RET_LOGE(appId != NULL, SOFTBUS_INVALID_PARAM, AUTH_HICHAIN,
"appId is null");
const DeviceGroupManager *gmInstance = GetGmInstance();
AUTH_CHECK_AND_RETURN_RET_LOGE(gmInstance != NULL, SOFTBUS_ERR, AUTH_HICHAIN,
"hichain GetGmInstance failed");
@ -286,6 +286,7 @@ uint32_t HichainGetJoinedGroups(int32_t groupType)
void CancelRequest(int64_t authReqId, const char *appId)
{
AUTH_CHECK_AND_RETURN_LOGE(appId != NULL, AUTH_HICHAIN, "appId is null");
if (g_hichain == NULL) {
g_hichain = InitHichain();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -124,6 +124,10 @@ static void NotifyTransDisconnected(int64_t authId)
int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback,
bool isMeta)
{
if (info == NULL || callback == NULL) {
AUTH_LOGE(AUTH_CONN, "info or callback is null");
return SOFTBUS_INVALID_PARAM;
}
if (isMeta) {
return AuthMetaOpenConn(info, requestId, callback);
}
@ -185,10 +189,10 @@ int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool
}
int32_t AuthRestoreAuthManager(const char *udidHash,
const AuthConnInfo *connInfo, int32_t requestId, NodeInfo *nodeInfo, int64_t *authId)
const AuthConnInfo *connInfo, uint32_t requestId, NodeInfo *nodeInfo, int64_t *authId)
{
if (udidHash == NULL || connInfo == NULL || nodeInfo == NULL || authId == NULL) {
AUTH_LOGW(AUTH_CONN, "restore manager fail because para error");
AUTH_LOGE(AUTH_CONN, "restore manager fail because para error");
return SOFTBUS_ERR;
}
// get device key
@ -367,7 +371,7 @@ TrustedReturnType AuthHasTrustedRelation(void)
return TRUSTED_RELATION_IGNORE;
}
SoftBusFree(udidArray);
AUTH_LOGD(AUTH_CONN, "auth get trusted relation num=%d", num);
AUTH_LOGD(AUTH_CONN, "auth get trusted relation num=%u", num);
return (num != 0) ? TRUSTED_RELATION_YES : TRUSTED_RELATION_NO;
}

View File

@ -28,14 +28,14 @@
#include "auth_session_message.h"
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_app_bind_interface.h"
#include "lnn_decision_db.h"
#include "lnn_feature_capability.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_net_builder.h"
#include "softbus_adapter_hitrace.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "lnn_feature_capability.h"
#include "lnn_net_builder.h"
#define MAX_AUTH_VALID_PERIOD (30 * 60 * 1000L) /* 30 mins */
#define SCHEDULE_UPDATE_SESSION_KEY_PERIOD ((5 * 60 + 30) * 60 * 1000L) /* 5 hour 30 mins */
@ -56,7 +56,7 @@ static bool g_regDataChangeListener = false;
/* Auth Manager */
AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
{
AuthManager *auth = (AuthManager *)SoftBusMalloc(sizeof(AuthManager));
AuthManager *auth = (AuthManager *)SoftBusCalloc(sizeof(AuthManager));
if (auth == NULL) {
AUTH_LOGW(AUTH_FSM, "malloc AuthManager fail");
return NULL;
@ -79,8 +79,7 @@ AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
} else {
ListTailInsert(&g_authClientList, &auth->node);
}
AUTH_LOGI(AUTH_FSM, "create auth manager, side=%s, authId=%" PRId64,
GetAuthSideStr(auth->isServer), auth->authId);
AUTH_LOGI(AUTH_FSM, "create auth manager, side=%s, authId=%" PRId64, GetAuthSideStr(auth->isServer), auth->authId);
return auth;
}
@ -103,7 +102,7 @@ static AuthManager *DupAuthManager(const AuthManager *auth)
void DelAuthManager(AuthManager *auth, bool removeAuthFromList)
{
CHECK_NULL_PTR_RETURN_VOID(auth);
AUTH_CHECK_AND_RETURN_LOGE(auth != NULL, AUTH_FSM, "auth is null");
if (removeAuthFromList) {
char *anonyUdid = NULL;
Anonymize(auth->udid, &anonyUdid);
@ -203,6 +202,8 @@ static AuthManager *FindAuthManagerByAuthId(int64_t authId)
return item;
}
}
AUTH_LOGE(AUTH_FSM, "auth manager[%" PRId64 "] not found", authId);
return NULL;
}
@ -272,14 +273,16 @@ static int32_t UpdateAuthManagerByAuthId(
static ConnectionAddrType ConvertAuthLinkTypeToConnect(AuthLinkType type)
{
if (type == AUTH_LINK_TYPE_WIFI) {
return CONNECTION_ADDR_WLAN;
} else if (type == AUTH_LINK_TYPE_BLE) {
return CONNECTION_ADDR_BLE;
} else if (type == AUTH_LINK_TYPE_BR) {
return CONNECTION_ADDR_BR;
switch (type) {
case AUTH_LINK_TYPE_WIFI:
return CONNECTION_ADDR_WLAN;
case AUTH_LINK_TYPE_BLE:
return CONNECTION_ADDR_BLE;
case AUTH_LINK_TYPE_BR:
return CONNECTION_ADDR_BR;
default:
return CONNECTION_ADDR_MAX;
}
return CONNECTION_ADDR_MAX;
}
void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index)
@ -289,8 +292,8 @@ void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index)
}
AuthManager *auth = FindAuthManagerByAuthId(authId);
if (auth == NULL) {
AUTH_LOGE(AUTH_CONN, "auth manager already removed, authId=%" PRId64, authId);
ReleaseAuthLock();
AUTH_LOGI(AUTH_CONN, "auth manager already removed, authId=%" PRId64, authId);
return;
}
RemoveSessionkeyByIndex(&auth->sessionKeyList, index);
@ -472,8 +475,7 @@ static int64_t GetAuthIdByConnInfo(const AuthConnInfo *connInfo, bool isServer)
}
AuthManager *auth = FindAuthManagerByConnInfo(connInfo, isServer);
if (auth == NULL) {
AUTH_LOGE(AUTH_CONN, "auth manager not found, connType=%d, side=%s", connInfo->type,
GetAuthSideStr(isServer));
AUTH_LOGE(AUTH_CONN, "auth manager not found, connType=%d, side=%s", connInfo->type, GetAuthSideStr(isServer));
ReleaseAuthLock();
return AUTH_INVALID_ID;
}
@ -501,7 +503,8 @@ static int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo)
/* Get lastest authId */
int64_t authId = AUTH_INVALID_ID;
uint64_t maxVerifyTime = 0;
for (uint32_t i = 0; i < sizeof(auth) / sizeof(auth[0]); i++) {
uint32_t authMgrNum = sizeof(auth) / sizeof(auth[0]);
for (uint32_t i = 0; i < authMgrNum; i++) {
if (auth[i] == NULL) {
continue;
}
@ -518,10 +521,10 @@ static int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo)
int32_t AuthManagerSetSessionKey(int64_t authSeq, const AuthSessionInfo *info,
const SessionKey *sessionKey, bool isConnect)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(sessionKey, SOFTBUS_INVALID_PARAM);
AUTH_LOGI(AUTH_FSM, "SetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u",
authSeq, GetAuthSideStr(info->isServer), info->requestId);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(sessionKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "sessionKey is NULL");
AUTH_LOGI(AUTH_FSM, "SetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
GetAuthSideStr(info->isServer), info->requestId);
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -575,13 +578,12 @@ int32_t AuthManagerSetSessionKey(int64_t authSeq, const AuthSessionInfo *info,
return SOFTBUS_OK;
}
int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(sessionKey, SOFTBUS_INVALID_PARAM);
AUTH_LOGI(AUTH_FSM, "GetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u",
authSeq, GetAuthSideStr(info->isServer), info->requestId);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(sessionKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "sessionKey is NULL");
AUTH_LOGI(AUTH_FSM, "GetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
GetAuthSideStr(info->isServer), info->requestId);
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -605,9 +607,10 @@ static void NotifyDeviceVerifyPassed(int64_t authId, const NodeInfo *nodeInfo)
{
AuthManager *auth = GetAuthManagerByAuthId(authId);
if (auth == NULL) {
AUTH_LOGE(AUTH_FSM, "get auth manager failed");
return;
}
if (auth->connInfo.type == AUTH_LINK_TYPE_P2P) {
if (auth->connInfo.type == AUTH_LINK_TYPE_P2P || auth->connInfo.type == AUTH_LINK_TYPE_ENHANCED_P2P) {
/* P2P auth no need notify to LNN. */
DelAuthManager(auth, false);
return;
@ -724,8 +727,7 @@ static int32_t StartVerifyDevice(uint32_t requestId, const AuthConnInfo *connInf
return SOFTBUS_AUTH_INNER_ERR;
}
if (waitNum > 1) {
AUTH_LOGI(AUTH_CONN, "wait last verify request complete, waitNum=%u, requestId=%u",
waitNum, requestId);
AUTH_LOGI(AUTH_CONN, "wait last verify request complete, waitNum=%u, requestId=%u", waitNum, requestId);
SoftbusHitraceStop();
return SOFTBUS_OK;
}
@ -782,7 +784,8 @@ static void ReportAuthRequestPassed(uint32_t requestId, int64_t authId, const No
do {
if (CheckAuthConnCallback(&request.connCb)) {
NotifyDeviceVerifyPassed(authId, nodeInfo);
if (request.connInfo.type == AUTH_LINK_TYPE_WIFI || request.connInfo.type == AUTH_LINK_TYPE_P2P) {
if (request.connInfo.type == AUTH_LINK_TYPE_WIFI || request.connInfo.type == AUTH_LINK_TYPE_P2P ||
request.connInfo.type == AUTH_LINK_TYPE_ENHANCED_P2P) {
PerformAuthConnCallback(request.requestId, SOFTBUS_OK, authId);
DelAuthRequest(request.requestId);
continue;
@ -829,6 +832,7 @@ static int32_t ComplementConnectionInfoIfNeed(AuthManager *auth, const char *udi
return SOFTBUS_OK;
}
if (udid == NULL || strlen(udid) == 0) {
AUTH_LOGE(AUTH_FSM, "invalid udid");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SoftBusGenerateStrHash((unsigned char *)udid, strlen(udid),
@ -839,9 +843,9 @@ static int32_t ComplementConnectionInfoIfNeed(AuthManager *auth, const char *udi
void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
{
int64_t authId;
CHECK_NULL_PTR_RETURN_VOID(info);
AUTH_LOGI(AUTH_FSM, "SetAuthPassed: authSeq=%" PRId64 ", side=%s, requestId=%u",
authSeq, GetAuthSideStr(info->isServer), info->requestId);
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "info is null");
AUTH_LOGI(AUTH_FSM, "SetAuthPassed: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
GetAuthSideStr(info->isServer), info->requestId);
if (!RequireAuthLock()) {
return;
@ -849,16 +853,16 @@ void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
AuthManager *auth = FindAuthManagerByConnInfo(&info->connInfo, info->isServer);
if (auth == NULL) {
PrintAuthConnInfo(&info->connInfo);
AUTH_LOGE(AUTH_FSM, "auth manager not found, connType=%d, side=%s",
info->connInfo.type, GetAuthSideStr(info->isServer));
ReleaseAuthLock();
AUTH_LOGE(AUTH_FSM, "auth manager not found, connType=%d, side=%s", info->connInfo.type,
GetAuthSideStr(info->isServer));
return;
}
int32_t ret = ComplementConnectionInfoIfNeed(auth, info->nodeInfo.deviceInfo.deviceUdid);
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "complement auth connection info failed, authSeq=%" PRId64 ", error=%d", authSeq, ret);
ReleaseAuthLock();
AUTH_LOGE(AUTH_FSM, "complement auth connection info failed, authSeq=%" PRId64 ", error=%d", authSeq, ret);
return;
}
@ -881,8 +885,9 @@ void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason)
{
AUTH_LOGE(AUTH_FSM, "SetAuthFailed: authSeq=%" PRId64 ", requestId=%u, reason=%d",
authSeq, info->requestId, reason);
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "auth session info is null");
AUTH_LOGE(
AUTH_FSM, "SetAuthFailed: authSeq=%" PRId64 ", requestId=%u, reason=%d", authSeq, info->requestId, reason);
AuthManager *auth = GetAuthManagerByConnInfo(&info->connInfo, info->isServer);
if (auth != NULL && auth->hasAuthPassed) {
AUTH_LOGE(AUTH_FSM, "update session key fail, authId=%" PRId64, auth->authId);
@ -903,7 +908,7 @@ void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int3
static void HandleBleDisconnectDelay(const void *para)
{
CHECK_NULL_PTR_RETURN_VOID(para);
AUTH_CHECK_AND_RETURN_LOGE(para != NULL, AUTH_FSM, "para is null");
uint64_t connId = *((uint64_t *)para);
DisconnectAuthDevice(&connId);
}
@ -915,6 +920,7 @@ static void BleDisconnectDelay(uint64_t connId, uint64_t delayMs)
void AuthManagerSetAuthFinished(int64_t authSeq, const AuthSessionInfo *info)
{
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "auth session info is null");
AUTH_LOGI(AUTH_FSM, "SetAuthFinished: authSeq=%" PRId64 ", requestId=%u", authSeq, info->requestId);
if (info->isServer) {
AUTH_LOGI(AUTH_FSM, "SERVER: wait client close connection");
@ -969,7 +975,7 @@ static void HandleBleConnectResult(uint32_t requestId, int64_t authId, uint64_t
AUTH_LOGI(AUTH_CONN, "get request info failed, requestId=%u", requestId);
return;
}
AuthManager inAuth = {.connId = connId };
AuthManager inAuth = { .connId = connId };
if (UpdateAuthManagerByAuthId(authId, SetAuthConnId, &inAuth) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "set auth connId fail, requestId=%u", requestId);
return;
@ -1076,8 +1082,8 @@ static void FlushDeviceProcess(const AuthConnInfo *connInfo, bool isServer)
AuthManager *auth = FindAuthManagerByConnInfo(connInfo, isServer);
if (auth == NULL) {
PrintAuthConnInfo(connInfo);
AUTH_LOGI(AUTH_FSM, "auth manager not found");
ReleaseAuthLock();
AUTH_LOGE(AUTH_FSM, "auth manager not found");
return;
}
if (PostVerifyDeviceMessage(auth, FLAG_REPLY) == SOFTBUS_OK) {
@ -1130,7 +1136,6 @@ static void HandleCloseAckData(
}
}
static void HandleConnectionData(
uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, const AuthDataHead *head, const uint8_t *data)
{
@ -1196,7 +1201,7 @@ static void OnDataReceived(
static void HandleDisconnectedEvent(const void *para)
{
CHECK_NULL_PTR_RETURN_VOID(para);
AUTH_CHECK_AND_RETURN_LOGE(para != NULL, AUTH_FSM, "para is null");
uint64_t connId = *((uint64_t *)para);
uint32_t num = 0;
uint64_t dupConnId = connId;
@ -1210,7 +1215,8 @@ static void HandleDisconnectedEvent(const void *para)
if (g_transCallback.OnDisconnected != NULL) {
g_transCallback.OnDisconnected(authIds[i]);
}
if (GetConnType(connId) == AUTH_LINK_TYPE_WIFI || GetConnType(connId) == AUTH_LINK_TYPE_P2P) {
if (GetConnType(connId) == AUTH_LINK_TYPE_WIFI || GetConnType(connId) == AUTH_LINK_TYPE_P2P ||
GetConnType(connId) == AUTH_LINK_TYPE_ENHANCED_P2P) {
NotifyDeviceDisconnect(authIds[i]);
DisconnectAuthDevice(&dupConnId);
AuthManager inAuth = { .connId = dupConnId };
@ -1267,13 +1273,13 @@ void AuthHandleLeaveLNN(int64_t authId)
}
AuthManager *auth = FindAuthManagerByAuthId(authId);
if (auth == NULL) {
AUTH_LOGI(AUTH_FSM, "auth manager not found, authId=%" PRId64, authId);
ReleaseAuthLock();
AUTH_LOGE(AUTH_FSM, "auth manager not found, authId=%" PRId64, authId);
return;
}
if (!auth->hasAuthPassed) {
AUTH_LOGI(AUTH_FSM, "auth pass = false, don't need to leave");
ReleaseAuthLock();
AUTH_LOGI(AUTH_FSM, "auth pass = false, don't need to leave");
return;
}
if (auth->connInfo.type == AUTH_LINK_TYPE_WIFI) {
@ -1324,7 +1330,7 @@ static int32_t TryGetBrConnInfo(const char *uuid, AuthConnInfo *connInfo)
return SOFTBUS_AUTH_GET_BR_CONN_INFO_FAIL;
}
if (((local & (1 << BIT_BR)) == 0) || ((remote & (1 << BIT_BR)) == 0)) {
AUTH_LOGI(AUTH_CONN, "can't support BR");
AUTH_LOGW(AUTH_CONN, "can't support BR");
return SOFTBUS_AUTH_GET_BR_CONN_INFO_FAIL;
}
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_BT_MAC, connInfo->info.brInfo.brMac, BT_MAC_LEN) != SOFTBUS_OK ||
@ -1342,8 +1348,10 @@ int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo)
AUTH_LOGE(AUTH_CONN, "invalid uuid or connInfo");
return SOFTBUS_INVALID_PARAM;
}
AuthLinkType linkList[] = { AUTH_LINK_TYPE_WIFI, AUTH_LINK_TYPE_BR, AUTH_LINK_TYPE_BLE };
for (uint32_t i = 0; i < sizeof(linkList) / sizeof(linkList[0]); i++) {
AuthLinkType linkList[] = { AUTH_LINK_TYPE_ENHANCED_P2P, AUTH_LINK_TYPE_WIFI, AUTH_LINK_TYPE_BR,
AUTH_LINK_TYPE_BLE };
uint32_t linkTypeNum = sizeof(linkList) / sizeof(linkList[0]);
for (uint32_t i = 0; i < linkTypeNum; i++) {
if (GetAuthConnInfoByUuid(uuid, linkList[i], connInfo) != SOFTBUS_OK) {
continue;
}
@ -1373,7 +1381,6 @@ bool AuthDeviceCheckConnInfo(const char *uuid, AuthLinkType type, bool checkConn
return checkConnection ? CheckActiveAuthConnection(&connInfo) : true;
}
int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback)
{
if (info == NULL || !CheckAuthConnCallback(callback)) {
@ -1398,6 +1405,14 @@ int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const A
return StartReconnectDevice(authId, info, requestId, callback);
}
return StartVerifyDevice(requestId, info, NULL, callback, true);
case AUTH_LINK_TYPE_ENHANCED_P2P:
authId = GetActiveAuthIdByConnInfo(info);
if (authId != AUTH_INVALID_ID) {
AUTH_LOGI(AUTH_CONN, "reuse enhanced p2p authId=%" PRId64, authId);
callback->onConnOpened(requestId, authId);
break;
}
return StartVerifyDevice(requestId, info, NULL, callback, true);
default:
AUTH_LOGE(AUTH_CONN, "unknown connType: %d", info->type);
return SOFTBUS_INVALID_PARAM;
@ -1415,6 +1430,7 @@ void AuthDeviceCloseConn(int64_t authId)
switch (auth->connInfo.type) {
case AUTH_LINK_TYPE_WIFI:
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
/* Do nothing. */
break;
case AUTH_LINK_TYPE_BR:
@ -1443,6 +1459,7 @@ int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo)
head.module = dataInfo->module;
head.seq = dataInfo->seq;
head.flag = dataInfo->flag;
head.len = 0;
uint8_t *encData = NULL;
if (EncryptInner(&auth->sessionKeyList, dataInfo->data, dataInfo->len, &encData, &head.len) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_KEY, "encrypt trans data fail");
@ -1463,6 +1480,7 @@ int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo)
int32_t RegGroupChangeListener(const GroupChangeListener *listener)
{
if (listener == NULL) {
AUTH_LOGE(AUTH_CONN, "listener is null");
return SOFTBUS_INVALID_PARAM;
}
g_groupChangeListener.onGroupCreated = listener->onGroupCreated;
@ -1600,7 +1618,6 @@ uint32_t AuthGetDecryptSize(uint32_t inLen)
return inLen - OVERHEAD_LEN;
}
int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen)
{
if (inData == NULL || inLen == 0 || outData == NULL || outLen == NULL || *outLen < AuthGetEncryptSize(inLen)) {
@ -1620,7 +1637,6 @@ int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen,
return SOFTBUS_OK;
}
int32_t AuthDeviceDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen)
{
if (inData == NULL || inLen == 0 || outData == NULL || outLen == NULL || *outLen < AuthGetDecryptSize(inLen)) {

View File

@ -15,8 +15,6 @@
#include "auth_request.h"
#include <securec.h>
#include "auth_common.h"
#include "auth_log.h"
#include "softbus_adapter_mem.h"
@ -35,7 +33,7 @@ static AuthRequest *FindAuthRequestByRequestId(uint64_t requestId)
return NULL;
}
static uint32_t GetAuthRequestWaitNum(AuthRequest *request)
static uint32_t GetAuthRequestWaitNum(const AuthRequest *request)
{
uint32_t num = 0;
AuthRequest *item = NULL;
@ -67,7 +65,7 @@ static uint32_t GetAuthRequestWaitNum(AuthRequest *request)
uint32_t AddAuthRequest(const AuthRequest *request)
{
CHECK_NULL_PTR_RETURN_VALUE(request, 0);
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, 0, AUTH_CONN, "request is NULL");
AuthRequest *newRequest = SoftBusCalloc(sizeof(AuthRequest));
if (newRequest == NULL) {
AUTH_LOGE(AUTH_CONN, "malloc AuthRequest fail");
@ -86,7 +84,7 @@ uint32_t AddAuthRequest(const AuthRequest *request)
int32_t GetAuthRequest(uint32_t requestId, AuthRequest *request)
{
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -102,9 +100,10 @@ int32_t GetAuthRequest(uint32_t requestId, AuthRequest *request)
int32_t GetAuthRequestNoLock(uint32_t requestId, AuthRequest *request)
{
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
AuthRequest *item = FindAuthRequestByRequestId(requestId);
if (item == NULL) {
AUTH_LOGE(AUTH_CONN, "find auth request failed");
return SOFTBUS_NOT_FIND;
}
*request = *item;
@ -113,8 +112,8 @@ int32_t GetAuthRequestNoLock(uint32_t requestId, AuthRequest *request)
int32_t FindAuthRequestByConnInfo(const AuthConnInfo *connInfo, AuthRequest *request)
{
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "connInfo is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -134,7 +133,7 @@ int32_t FindAuthRequestByConnInfo(const AuthConnInfo *connInfo, AuthRequest *req
int32_t FindAndDelAuthRequestByConnInfo(uint32_t requestId, const AuthConnInfo *connInfo)
{
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "connInfo is NULL");
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -195,9 +194,11 @@ void ClearAuthRequest(void)
bool CheckVerifyCallback(const AuthVerifyCallback *verifyCb)
{
if (verifyCb == NULL) {
AUTH_LOGE(AUTH_CONN, "verifyCb is null");
return false;
}
if (verifyCb->onVerifyPassed == NULL || verifyCb->onVerifyFailed == NULL) {
AUTH_LOGE(AUTH_CONN, "onVerifyPassed or onVerifyFailed is null");
return false;
}
return true;
@ -206,9 +207,11 @@ bool CheckVerifyCallback(const AuthVerifyCallback *verifyCb)
bool CheckAuthConnCallback(const AuthConnCallback *connCb)
{
if (connCb == NULL) {
AUTH_LOGE(AUTH_CONN, "connCb is null");
return false;
}
if (connCb->onConnOpened == NULL || connCb->onConnOpenFailed == NULL) {
AUTH_LOGE(AUTH_CONN, "onConnOpened or onConnOpenFailed is null");
return false;
}
return true;
@ -218,9 +221,11 @@ void PerformVerifyCallback(uint32_t requestId, int32_t result, int64_t authId, c
{
AuthRequest request;
if (GetAuthRequest(requestId, &request) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "get auth request failed");
return;
}
if (!CheckVerifyCallback(&request.verifyCb)) {
AUTH_LOGE(AUTH_CONN, "check verifyCb failed");
return;
}
if (result == SOFTBUS_OK) {
@ -234,9 +239,11 @@ void PerformAuthConnCallback(uint32_t requestId, int32_t result, int64_t authId)
{
AuthRequest request;
if (GetAuthRequest(requestId, &request) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "get auth request failed");
return;
}
if (!CheckAuthConnCallback(&request.connCb)) {
AUTH_LOGE(AUTH_CONN, "check connCb failed");
return;
}
if (result == SOFTBUS_OK) {

View File

@ -30,7 +30,6 @@
#include "softbus_adapter_hitrace.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_log_old.h"
#define AUTH_TIMEOUT_MS (10 * 1000)
#define TO_AUTH_FSM(ptr) CONTAINER_OF(ptr, AuthFsm, fsm)
@ -157,6 +156,49 @@ static bool IsNeedExchangeNetworkId(uint32_t feature, AuthCapability capaBit)
return ((feature & (1 << (uint32_t)capaBit)) != 0);
}
static void AddUdidInfo(uint32_t requestId, bool isServer, AuthConnInfo *connInfo)
{
if (isServer || connInfo->type != AUTH_LINK_TYPE_ENHANCED_P2P) {
AUTH_LOGD(AUTH_FSM, "is not server or enhancedP2p");
return;
}
AuthRequest request;
(void)memset_s(&request, sizeof(request), 0, sizeof(request));
if (GetAuthRequestNoLock(requestId, &request) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get auth request fail");
return;
}
if (strcpy_s(connInfo->info.ipInfo.udid, UDID_BUF_LEN,
request.connInfo.info.ipInfo.udid) != EOK) {
AUTH_LOGE(AUTH_FSM, "strcpy udid fail");
return;
}
}
static int32_t ProcAuthFsm(uint32_t requestId, bool isServer, AuthFsm *authFsm)
{
AuthRequest request;
NodeInfo nodeInfo;
(void)memset_s(&request, sizeof(request), 0, sizeof(request));
(void)memset_s(&nodeInfo, sizeof(nodeInfo), 0, sizeof(nodeInfo));
AddUdidInfo(requestId, isServer, &authFsm->info.connInfo);
if (authFsm->info.connInfo.type == AUTH_LINK_TYPE_BLE) {
if (GetAuthRequestNoLock(requestId, &request) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get auth request fail");
return SOFTBUS_ERR;
}
char udidHash[SHORT_UDID_HASH_HEX_LEN + 1] = {0};
int32_t ret = ConvertBytesToHexString(udidHash, SHORT_UDID_HASH_HEX_LEN + 1,
(const unsigned char *)request.connInfo.info.bleInfo.deviceIdHash, SHORT_UDID_HASH_LEN);
if (ret == SOFTBUS_OK && LnnRetrieveDeviceInfo((const char *)udidHash, &nodeInfo) == SOFTBUS_OK &&
IsNeedExchangeNetworkId(nodeInfo.authCapacity, BIT_SUPPORT_EXCHANGE_NETWORKID)) {
AUTH_LOGI(AUTH_FSM, "LnnRetrieveDeviceInfo success");
authFsm->info.idType = EXCHANGE_NETWORKID;
}
}
return SOFTBUS_OK;
}
static AuthFsm *CreateAuthFsm(int64_t authSeq, uint32_t requestId, uint64_t connId,
const AuthConnInfo *connInfo, bool isServer)
{
@ -172,30 +214,11 @@ static AuthFsm *CreateAuthFsm(int64_t authSeq, uint32_t requestId, uint64_t conn
authFsm->info.connId = connId;
authFsm->info.connInfo = *connInfo;
authFsm->info.version = SOFTBUS_NEW_V2;
NodeInfo nodeInfo;
AuthRequest request;
if (memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo)) != EOK ||
memset_s(&request, sizeof(NodeInfo), 0, sizeof(NodeInfo)) != EOK) {
AUTH_LOGE(AUTH_FSM, "memset fail.");
SoftBusFree(authFsm);
return NULL;
}
authFsm->info.idType = EXCHANHE_UDID;
if (!isServer) {
if (authFsm->info.connInfo.type == AUTH_LINK_TYPE_BLE) {
if (GetAuthRequestNoLock(requestId, &request) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get auth request fail");
SoftBusFree(authFsm);
return NULL;
}
char udidHash[SHORT_UDID_HASH_HEX_LEN + 1] = {0};
int32_t ret = ConvertBytesToHexString(udidHash, SHORT_UDID_HASH_HEX_LEN + 1,
(const unsigned char *)request.connInfo.info.bleInfo.deviceIdHash, SHORT_UDID_HASH_LEN);
if (ret == SOFTBUS_OK && LnnRetrieveDeviceInfo((const char *)udidHash, &nodeInfo) == SOFTBUS_OK &&
IsNeedExchangeNetworkId(nodeInfo.authCapacity, BIT_SUPPORT_EXCHANGE_NETWORKID)) {
AUTH_LOGI(AUTH_FSM, "LnnRetrieveDeviceInfo success");
authFsm->info.idType = EXCHANGE_NETWORKID;
}
if (ProcAuthFsm(requestId, isServer, authFsm) != SOFTBUS_OK) {
SoftBusFree(authFsm);
return NULL;
}
}
if (sprintf_s(authFsm->fsmName, sizeof(authFsm->fsmName), "AuthFsm-%u", authFsm->id) == -1) {
@ -447,7 +470,12 @@ static int32_t RecoveryDeviceKey(AuthFsm *authFsm)
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
return SOFTBUS_ERR;
}
if (AuthFindDeviceKey(udidShortHash, authFsm->info.connInfo.type, &key) != SOFTBUS_OK) {
AuthLinkType linkType = authFsm->info.connInfo.type;
if (authFsm->info.connInfo.type == AUTH_LINK_TYPE_ENHANCED_P2P) {
// enhanced p2p reuse ble authKey
linkType = AUTH_LINK_TYPE_BLE;
}
if (AuthFindDeviceKey(udidShortHash, linkType, &key) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "find key fail, fastAuth error");
return SOFTBUS_ERR;
}
@ -480,6 +508,7 @@ static void AuditReportSetPeerDevInfo(LnnAuditExtra *lnnAuditExtra, AuthSessionI
break;
case AUTH_LINK_TYPE_WIFI:
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
if (strcpy_s((char *)lnnAuditExtra->peerIp, IP_STR_MAX_LEN, info->connInfo.info.ipInfo.ip) != EOK) {
AUTH_LOGE(AUTH_FSM, "IP COPY ERROR");
}
@ -545,7 +574,7 @@ static int32_t ClientSetExchangeIdType(AuthFsm *authFsm)
{
AuthSessionInfo *info = &authFsm->info;
if (info->idType == EXCHANGE_FAIL) {
AUTH_LOGI(AUTH_FSM, "fsm switch to reauth due to not find networkId");
AUTH_LOGE(AUTH_FSM, "fsm switch to reauth due to not find networkId");
info->idType = EXCHANHE_UDID;
LnnFsmTransactState(&authFsm->fsm, g_states + STATE_SYNC_DEVICE_ID);
return SOFTBUS_ERR;
@ -553,7 +582,7 @@ static int32_t ClientSetExchangeIdType(AuthFsm *authFsm)
return SOFTBUS_OK;
}
static void HandleMsgRecvDeviceId(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgRecvDeviceId(AuthFsm *authFsm, const MessagePara *para)
{
int32_t ret;
AuthSessionInfo *info = &authFsm->info;
@ -567,6 +596,11 @@ static void HandleMsgRecvDeviceId(AuthFsm *authFsm, MessagePara *para)
break;
}
if (info->isServer) {
if (info->connInfo.type == AUTH_LINK_TYPE_BLE && strlen(info->udid) != 0 &&
authFsm->info.connInfo.info.bleInfo.deviceIdHash[0] == '\0') {
(void)SoftBusGenerateStrHash((unsigned char *)info->udid, strlen(info->nodeInfo.deviceInfo.deviceUdid),
(unsigned char *)authFsm->info.connInfo.info.bleInfo.deviceIdHash);
}
if (PostDeviceIdMessage(authFsm->authSeq, info) != SOFTBUS_OK) {
ret = SOFTBUS_AUTH_SYNC_DEVID_FAIL;
break;
@ -633,7 +667,7 @@ static bool SyncDevIdStateProcess(FsmStateMachine *fsm, int32_t msgType, void *p
return true;
}
static void HandleMsgRecvAuthData(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgRecvAuthData(AuthFsm *authFsm, const MessagePara *para)
{
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
@ -655,7 +689,7 @@ static void HandleMsgRecvAuthData(AuthFsm *authFsm, MessagePara *para)
}
}
static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
static int32_t TrySyncDeviceInfo(int64_t authSeq, const AuthSessionInfo *info)
{
switch (info->connInfo.type) {
case AUTH_LINK_TYPE_WIFI:
@ -667,6 +701,7 @@ static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
case AUTH_LINK_TYPE_BR:
case AUTH_LINK_TYPE_BLE:
case AUTH_LINK_TYPE_P2P:
case AUTH_LINK_TYPE_ENHANCED_P2P:
return PostDeviceInfoMessage(authSeq, info);
default:
break;
@ -674,7 +709,7 @@ static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
return SOFTBUS_ERR;
}
static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgSaveSessionKey(AuthFsm *authFsm, const MessagePara *para)
{
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
@ -706,14 +741,14 @@ static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
LnnFsmTransactState(&authFsm->fsm, g_states + STATE_SYNC_DEVICE_INFO);
}
static void HandleMsgAuthError(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgAuthError(AuthFsm *authFsm, const MessagePara *para)
{
int32_t result = *((int32_t *)(para->data));
AUTH_LOGE(AUTH_FSM, "auth fsm[%" PRId64"] handle hichain error, reason=%d", authFsm->authSeq, result);
CompleteAuthSession(authFsm, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
}
static void HandleMsgRecvDevInfoEarly(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgRecvDevInfoEarly(AuthFsm *authFsm, const MessagePara *para)
{
AUTH_LOGI(AUTH_FSM, "auth fsm[%" PRId64 "] recv device info early, save it", authFsm->authSeq);
AuthSessionInfo *info = &authFsm->info;
@ -789,7 +824,7 @@ static bool DeviceAuthStateProcess(FsmStateMachine *fsm, int32_t msgType, void *
return true;
}
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, MessagePara *para)
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, const MessagePara *para)
{
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
AuthSessionInfo *info = &authFsm->info;
@ -895,7 +930,7 @@ static bool SyncDevInfoStateProcess(FsmStateMachine *fsm, int32_t msgType, void
return true;
}
AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq)
static AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq)
{
AuthFsm *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_authFsmList, AuthFsm, node) {
@ -1008,7 +1043,7 @@ static void SetAuthStartTime(AuthFsm *authFsm)
int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId,
uint64_t connId, const AuthConnInfo *connInfo, bool isServer, bool isFastAuth)
{
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "connInfo is NULL");
if (!RequireAuthLock()) {
return SOFTBUS_LOCK_ERR;
}
@ -1033,6 +1068,7 @@ int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId,
int32_t AuthSessionProcessDevIdData(int64_t authSeq, const uint8_t *data, uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsm(FSM_MSG_RECV_DEVICE_ID, authSeq, data, len);
@ -1053,6 +1089,7 @@ int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t l
int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsm(FSM_MSG_RECV_AUTH_DATA, authSeq, data, len);
@ -1061,6 +1098,7 @@ int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_
int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size)
{
if (udid == NULL) {
AUTH_LOGE(AUTH_FSM, "udid is null");
return SOFTBUS_INVALID_PARAM;
}
AuthSessionInfo info = {0};
@ -1077,6 +1115,7 @@ int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size)
int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len)
{
if (key == NULL) {
AUTH_LOGE(AUTH_FSM, "key is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsm(FSM_MSG_SAVE_SESSION_KEY, authSeq, key, len);
@ -1095,6 +1134,7 @@ int32_t AuthSessionHandleAuthError(int64_t authSeq, int32_t reason)
int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsm(FSM_MSG_RECV_DEVICE_INFO, authSeq, data, len);
@ -1103,6 +1143,7 @@ int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint
int32_t AuthSessionProcessCloseAck(int64_t authSeq, const uint8_t *data, uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsm(FSM_MSG_RECV_CLOSE_ACK, authSeq, data, len);
@ -1112,6 +1153,7 @@ int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, co
uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsmByConnId(FSM_MSG_RECV_DEVICE_INFO, connId, isServer, data, len);
@ -1121,6 +1163,7 @@ int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const
uint32_t len)
{
if (data == NULL) {
AUTH_LOGE(AUTH_FSM, "data is null");
return SOFTBUS_INVALID_PARAM;
}
return PostMessageToAuthFsmByConnId(FSM_MSG_RECV_CLOSE_ACK, connId, isServer, data, len);
@ -1129,6 +1172,7 @@ int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const
int32_t AuthSessionHandleDeviceNotTrusted(const char *udid)
{
if (udid == NULL || udid[0] == '\0') {
AUTH_LOGE(AUTH_FSM, "invalid udid");
return SOFTBUS_INVALID_PARAM;
}
if (!RequireAuthLock()) {

View File

@ -55,19 +55,20 @@ static void RemoveOldKey(SessionKeyList *list)
void InitSessionKeyList(SessionKeyList *list)
{
CHECK_NULL_PTR_RETURN_VOID(list);
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
ListInit(list);
}
int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList)
{
CHECK_NULL_PTR_RETURN_VALUE(srcList, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(dstList, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(srcList != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "srcList is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(dstList != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "dstList is NULL");
SessionKeyItem *item = NULL;
SessionKeyItem *newItem = NULL;
LIST_FOR_EACH_ENTRY(item, srcList, SessionKeyItem, node) {
newItem = (SessionKeyItem *)DupMemBuffer((uint8_t *)item, sizeof(SessionKeyItem));
if (newItem == NULL) {
AUTH_LOGE(AUTH_FSM, "malloc newItem fail");
DestroySessionKeyList(dstList);
return SOFTBUS_MALLOC_ERR;
}
@ -78,7 +79,7 @@ int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList
void DestroySessionKeyList(SessionKeyList *list)
{
CHECK_NULL_PTR_RETURN_VOID(list);
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
SessionKeyItem *item = NULL;
SessionKeyItem *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, list, SessionKeyItem, node) {
@ -90,14 +91,14 @@ void DestroySessionKeyList(SessionKeyList *list)
bool HasSessionKey(const SessionKeyList *list)
{
CHECK_NULL_PTR_RETURN_VALUE(list, false);
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, false, AUTH_FSM, "list is NULL");
return !IsListEmpty(list);
}
int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key)
{
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
AUTH_LOGD(AUTH_FSM, "keyLen=%d", key->len);
SessionKeyItem *item = (SessionKeyItem *)SoftBusMalloc(sizeof(SessionKeyItem));
if (item == NULL) {
@ -118,9 +119,9 @@ int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key
int32_t GetLatestSessionKey(const SessionKeyList *list, int32_t *index, SessionKey *key)
{
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(index, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(index != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "index is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
if (IsListEmpty((const ListNode *)list)) {
AUTH_LOGE(AUTH_FSM, "session key list is empty");
return SOFTBUS_ERR;
@ -142,8 +143,8 @@ int32_t GetLatestSessionKey(const SessionKeyList *list, int32_t *index, SessionK
int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, SessionKey *key)
{
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
SessionKeyItem *item = NULL;
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
if (item->index != index) {
@ -163,7 +164,7 @@ int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, SessionK
void RemoveSessionkeyByIndex(SessionKeyList *list, int32_t index)
{
CHECK_NULL_PTR_RETURN_VOID(list);
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
bool isFind = false;
SessionKeyItem *item = NULL;
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
@ -192,7 +193,6 @@ int32_t EncryptData(const SessionKeyList *list, const uint8_t *inData, uint32_t
SessionKey sessionKey;
if (GetLatestSessionKey(list, &index, &sessionKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get key fail");
AUTH_LOGD(AUTH_FSM, "keyLen=%d", sessionKey.len);
return SOFTBUS_ENCRYPT_ERR;
}
/* pack key index */
@ -295,7 +295,7 @@ int32_t DecryptInner(const SessionKeyList *list, const uint8_t *inData, uint32_t
/* For Debug */
void DumpSessionkeyList(const SessionKeyList *list)
{
CHECK_NULL_PTR_RETURN_VOID(list);
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
uint32_t keyNum = 0;
SessionKeyItem *item = NULL;
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
@ -308,7 +308,7 @@ void DumpSessionkeyList(const SessionKeyList *list)
static void HandleUpdateSessionKeyEvent(const void *obj)
{
CHECK_NULL_PTR_RETURN_VOID(obj);
AUTH_CHECK_AND_RETURN_LOGE(obj != NULL, AUTH_FSM, "obj is NULL");
int64_t authId = *(int64_t *)(obj);
AUTH_LOGI(AUTH_FSM, "update session key begin, authId=%" PRId64, authId);
AuthManager *auth = GetAuthManagerByAuthId(authId);
@ -324,8 +324,8 @@ static void HandleUpdateSessionKeyEvent(const void *obj)
static int32_t RemoveUpdateSessionKeyFunc(const void *obj, void *para)
{
CHECK_NULL_PTR_RETURN_VALUE(obj, SOFTBUS_ERR);
CHECK_NULL_PTR_RETURN_VALUE(para, SOFTBUS_ERR);
AUTH_CHECK_AND_RETURN_RET_LOGE(obj != NULL, SOFTBUS_ERR, AUTH_FSM, "obj is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(para != NULL, SOFTBUS_ERR, AUTH_FSM, "para is NULL");
int64_t authId = *(int64_t *)(obj);
if (authId == *(int64_t *)(para)) {
AUTH_LOGI(AUTH_FSM, "remove update session key event, authId=%" PRId64, authId);

View File

@ -209,8 +209,7 @@ static void OptInt(const JsonObj *json, const char * const key, int *target, int
*target = defaultValue;
}
static void OptInt64(const JsonObj *json, const char * const key,
int64_t *target, int64_t defaultValue)
static void OptInt64(const JsonObj *json, const char * const key, int64_t *target, int64_t defaultValue)
{
if (JSON_GetInt64FromOject(json, key, target)) {
return;
@ -258,21 +257,30 @@ static int32_t PackFastAuthValue(JsonObj *obj, AuthDeviceKeyInfo *deviceCommKey)
return SOFTBUS_OK;
}
static bool GenerateUdidShortHash(const char *udid, char *udidHashBuf, uint32_t bufLen)
{
uint8_t hash[SHA_256_HASH_LEN] = {0};
int ret = SoftBusGenerateStrHash((uint8_t *)udid, strlen(udid), hash);
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
return false;
}
if (ConvertBytesToUpperCaseHexString(udidHashBuf, bufLen, hash, UDID_SHORT_HASH_LEN_TEMP) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
return false;
}
return true;
}
static bool GetUdidOrShortHash(const AuthSessionInfo *info, char *udidBuf, uint32_t bufLen)
{
if (!info->isServer && info->connInfo.type == AUTH_LINK_TYPE_ENHANCED_P2P) {
AUTH_LOGD(AUTH_FSM, "client(enhance p2p), use conninfo udid");
return GenerateUdidShortHash(info->connInfo.info.ipInfo.udid, udidBuf, bufLen);
}
if (strlen(info->udid) != 0) {
AUTH_LOGI(AUTH_FSM, "use info->udid build fastAuthInfo");
uint8_t hash[SHA_256_HASH_LEN] = {0};
int ret = SoftBusGenerateStrHash((uint8_t *)info->udid, strlen(info->udid), hash);
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
return false;
}
if (ConvertBytesToUpperCaseHexString(udidBuf, bufLen, hash, UDID_SHORT_HASH_LEN_TEMP) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
return false;
}
return true;
return GenerateUdidShortHash(info->udid, udidBuf, bufLen);
}
if (info->connInfo.type == AUTH_LINK_TYPE_BLE) {
AUTH_LOGI(AUTH_FSM, "use bleInfo deviceIdHash build fastAuthInfo");
@ -281,13 +289,59 @@ static bool GetUdidOrShortHash(const AuthSessionInfo *info, char *udidBuf, uint3
AUTH_LOGE(AUTH_FSM, "GetAuthRequest fail");
return false;
}
return (memcpy_s(udidBuf, bufLen, request.connInfo.info.bleInfo.deviceIdHash,
UDID_SHORT_HASH_HEX_STR) == EOK);
return (memcpy_s(udidBuf, bufLen, request.connInfo.info.bleInfo.deviceIdHash, UDID_SHORT_HASH_HEX_STR) == EOK);
}
AUTH_LOGD(AUTH_FSM, "udid len=%d, connInfo type=%d", strlen(info->udid), info->connInfo.type);
return false;
}
static int32_t GetEnhancedP2pAuthKey(const char *udidHash, AuthSessionInfo *info, AuthDeviceKeyInfo *deviceKey)
{
/* first, reuse ble authKey */
if (AuthFindDeviceKey(udidHash, AUTH_LINK_TYPE_BLE, deviceKey) == SOFTBUS_OK) {
AUTH_LOGD(AUTH_FSM, "get ble authKey succ");
return SOFTBUS_OK;
}
/* second, reuse wifi authKey */
int64_t authId = AuthGetLatestIdByUuid(info->uuid, AUTH_LINK_TYPE_WIFI, false);
if (authId == AUTH_INVALID_ID) {
AUTH_LOGE(AUTH_FSM, "get wifi authKey fail");
return SOFTBUS_ERR;
}
AuthManager *auth = GetAuthManagerByAuthId(authId);
int32_t index;
SessionKey sessionKey;
(void)memset_s(&sessionKey, sizeof(SessionKey), 0, sizeof(SessionKey));
if (GetLatestSessionKey(&auth->sessionKeyList, &index, &sessionKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get key fail");
DelAuthManager(auth, false);
return SOFTBUS_ERR;
}
DelAuthManager(auth, false);
if (memcpy_s(deviceKey->deviceKey, SESSION_KEY_LENGTH,
sessionKey.value, sizeof(sessionKey.value)) != EOK) {
AUTH_LOGE(AUTH_FSM, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
deviceKey->keyLen = sessionKey.len;
/* wifi authKey not enable, associated with recoveryDeviceKey */
return SOFTBUS_ERR;
}
static int32_t GetFastAuthKey(const char *udidHash, AuthSessionInfo *info, AuthDeviceKeyInfo *deviceKey)
{
if (info->connInfo.type == AUTH_LINK_TYPE_ENHANCED_P2P) {
AUTH_LOGI(AUTH_FSM, "get enhanced p2p fastAuth key");
return GetEnhancedP2pAuthKey(udidHash, info, deviceKey);
}
if (AuthFindDeviceKey(udidHash, info->connInfo.type, deviceKey) != SOFTBUS_OK) {
AUTH_LOGW(AUTH_FSM, "can't find common key, unsupport fastAuth");
info->isSupportFastAuth = false;
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static void PackFastAuth(JsonObj *obj, AuthSessionInfo *info, const NodeInfo *localNodeInfo)
{
AUTH_LOGD(AUTH_FSM, "pack fastAuth, isServer=%d", info->isServer);
@ -312,26 +366,26 @@ static void PackFastAuth(JsonObj *obj, AuthSessionInfo *info, const NodeInfo *lo
return;
}
AUTH_LOGD(AUTH_FSM, "udidHashHexStr=%s", udidHashHexStr);
if (!IsPotentialTrustedDevice(ID_TYPE_DEVID, (const char *)udidHashHexStr, false, true)) {
if (info->connInfo.type != AUTH_LINK_TYPE_ENHANCED_P2P &&
!IsPotentialTrustedDevice(ID_TYPE_DEVID, (const char *)udidHashHexStr, false, false)) {
AUTH_LOGI(AUTH_FSM, "not potential trusted realtion, bypass fastAuthProc");
info->isSupportFastAuth = false;
return;
}
AuthDeviceKeyInfo deviceCommKey = {0};
if (AuthFindDeviceKey(udidHashHexStr, info->connInfo.type, &deviceCommKey) != SOFTBUS_OK) {
AUTH_LOGW(AUTH_FSM, "can't find common key, unsupport fastAuth");
if (GetFastAuthKey(udidHashHexStr, info, &deviceCommKey) != SOFTBUS_OK) {
info->isSupportFastAuth = false;
return;
}
if (PackFastAuthValue(obj, &deviceCommKey) != SOFTBUS_OK) {
(void)memset_s(&deviceCommKey, sizeof(AuthDeviceKeyInfo), 0, sizeof(AuthDeviceKeyInfo));
info->isSupportFastAuth = false;
return;
}
(void)memset_s(&deviceCommKey, sizeof(AuthDeviceKeyInfo), 0, sizeof(AuthDeviceKeyInfo));
}
static void ParseFastAuthValue(AuthSessionInfo *info, const char *encryptedFastAuth,
AuthDeviceKeyInfo *deviceKey)
static void ParseFastAuthValue(AuthSessionInfo *info, const char *encryptedFastAuth, AuthDeviceKeyInfo *deviceKey)
{
uint8_t fastAuthBytes[ENCRYPTED_FAST_AUTH_MAX_LEN] = {0};
if (ConvertHexStringToBytes(fastAuthBytes, ENCRYPTED_FAST_AUTH_MAX_LEN,
@ -387,14 +441,14 @@ static void UnpackFastAuth(JsonObj *obj, AuthSessionInfo *info)
AUTH_LOGE(AUTH_FSM, "udid hash bytes to hexString fail");
return;
}
if (!IsPotentialTrustedDevice(ID_TYPE_DEVID, (const char *)udidShortHash, false, true)) {
if (info->connInfo.type != AUTH_LINK_TYPE_ENHANCED_P2P &&
!IsPotentialTrustedDevice(ID_TYPE_DEVID, (const char *)udidShortHash, false, false)) {
AUTH_LOGI(AUTH_FSM, "not potential trusted realtion, fastAuth not support");
return;
}
AuthDeviceKeyInfo deviceKey = {0};
/* find comm key use udid or udidShortHash */
if (AuthFindDeviceKey(udidShortHash, info->connInfo.type, &deviceKey) != SOFTBUS_OK) {
AUTH_LOGW(AUTH_FSM, "can't find common key, fastAuth not support");
if (GetFastAuthKey(udidShortHash, info, &deviceKey) != SOFTBUS_OK) {
AUTH_LOGW(AUTH_FSM, "can't find device key, fastAuth not support");
return;
}
ParseFastAuthValue(info, encryptedFastAuth, &deviceKey);
@ -415,6 +469,7 @@ static void PackCompressInfo(JsonObj *obj, const NodeInfo *info)
static void PackWifiSinglePassInfo(JsonObj *obj, const AuthSessionInfo *info)
{
if (info->connInfo.type != AUTH_LINK_TYPE_WIFI) {
AUTH_LOGE(AUTH_FSM, "link type is not wifi");
return;
}
uint8_t hash[SHA_256_HASH_LEN] = {0};
@ -487,8 +542,7 @@ static char *PackDeviceIdJson(const AuthSessionInfo *info)
AUTH_LOGI(AUTH_FSM, "exchangeIdType=%d, udid=%s", info->idType, anonyUdid);
AnonymizeFree(anonyUdid);
}
if (!JSON_AddStringToObject(obj, DATA_TAG, uuid) ||
!JSON_AddInt32ToObject(obj, DATA_BUF_SIZE_TAG, PACKET_SIZE) ||
if (!JSON_AddStringToObject(obj, DATA_TAG, uuid) || !JSON_AddInt32ToObject(obj, DATA_BUF_SIZE_TAG, PACKET_SIZE) ||
!JSON_AddInt32ToObject(obj, SOFTBUS_VERSION_TAG, info->version) ||
!JSON_AddInt32ToObject(obj, EXCHANGE_ID_TYPE, info->idType)) {
AUTH_LOGE(AUTH_FSM, "add msg body fail");
@ -519,7 +573,7 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
SoftBusSockAddrIn addr = {0};
SocketAddr socketAddr;
int32_t rc = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&addr);
if (rc != 0) {
if (rc != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "fd=%d, GetPerrName rc=%d", socketFd, rc);
return true;
}
@ -531,11 +585,11 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
uint8_t hash[SHA_256_HASH_LEN] = {0};
rc = SoftBusGenerateStrHash((const unsigned char *)socketAddr.addr, strlen(socketAddr.addr), hash);
if (rc != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "generate hash failed rc=%d", rc);
return true;
}
char socketIpHash[SHA_256_HEX_HASH_LEN] = {0};
if (ConvertBytesToUpperCaseHexString(socketIpHash, SHA_256_HEX_HASH_LEN,
hash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
char socketIpHash[SHA_256_HEX_HASH_LEN] = { 0 };
if (ConvertBytesToUpperCaseHexString(socketIpHash, SHA_256_HEX_HASH_LEN, hash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
return true;
}
if (strcmp(devIpHash, socketIpHash) == 0) {
@ -548,7 +602,7 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
static int32_t UnPackBtDeviceIdV1(AuthSessionInfo *info, const uint8_t *data, uint32_t len)
{
if (!info->isServer) {
AUTH_LOGE(AUTH_FSM, "invalid bt deviceId msg");
AUTH_LOGE(AUTH_FSM, "is not server");
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s(info->udid, UDID_BUF_LEN, data, len) != EOK) { // data:StandardCharsets.UTF_8
@ -696,9 +750,8 @@ static int32_t UnpackDeviceIdJson(const char *msg, uint32_t len, AuthSessionInfo
return SOFTBUS_ERR;
}
if (info->connInfo.type != AUTH_LINK_TYPE_WIFI) {
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = {0};
OptString(obj, SUPPORT_INFO_COMPRESS, compressParse,
PARSE_UNCOMPRESS_STRING_BUFF_LEN, FALSE_STRING_TAG);
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = { 0 };
OptString(obj, SUPPORT_INFO_COMPRESS, compressParse, PARSE_UNCOMPRESS_STRING_BUFF_LEN, FALSE_STRING_TAG);
SetCompressFlag(compressParse, &info->isSupportCompress);
}
UnpackFastAuth(obj, info);
@ -1051,7 +1104,7 @@ static void UnpackCommon(const JsonObj *json, NodeInfo *info, SoftBusVersion ver
OptInt64(json, ACCOUNT_ID, &info->accountId, 0);
OptInt(json, NODE_WEIGHT, &info->masterWeight, DEFAULT_NODE_WEIGHT);
//IS_SUPPORT_TCP_HEARTBEAT
// IS_SUPPORT_TCP_HEARTBEAT
OptInt64(json, NEW_CONN_CAP, (int64_t *)&info->netCapacity, -1);
if (info->netCapacity == (uint32_t)-1) {
(void)JSON_GetInt64FromOject(json, CONN_CAP, (int64_t *)&info->netCapacity);
@ -1105,7 +1158,7 @@ static void AddDiscoveryType(JsonObj *json, const char *remoteUuid)
}
char networkId[NETWORK_ID_BUF_LEN] = {0};
if (LnnGetNetworkIdByUuid(remoteUuid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
AUTH_LOGI(AUTH_FSM, "networkId not found by uuid, maybe first online");
AUTH_LOGE(AUTH_FSM, "networkId not found by uuid, maybe first online");
return;
}
uint32_t discoveryType = 0;
@ -1182,8 +1235,7 @@ static int32_t UnpackBt(const JsonObj *json, NodeInfo *info, SoftBusVersion vers
static int32_t PackWiFi(JsonObj *json, const NodeInfo *info, SoftBusVersion version, bool isMetaAuth)
{
AUTH_LOGD(AUTH_FSM, "devIp %d", strlen(info->connectInfo.deviceIp));
if (!JSON_AddInt32ToObject(json, CODE, CODE_VERIFY_IP) ||
!JSON_AddInt32ToObject(json, BUS_MAX_VERSION, BUS_V2) ||
if (!JSON_AddInt32ToObject(json, CODE, CODE_VERIFY_IP) || !JSON_AddInt32ToObject(json, BUS_MAX_VERSION, BUS_V2) ||
!JSON_AddInt32ToObject(json, BUS_MIN_VERSION, BUS_V1) ||
!JSON_AddInt32ToObject(json, AUTH_PORT, LnnGetAuthPort(info)) ||
!JSON_AddInt32ToObject(json, SESSION_PORT, LnnGetSessionPort(info)) ||
@ -1285,7 +1337,7 @@ static int32_t PackDeviceInfoBtV1(JsonObj *json, const NodeInfo *info, bool isMe
static int32_t UnpackDeviceInfoBtV1(const JsonObj *json, NodeInfo *info)
{
char deviceType[DEVICE_TYPE_BUF_LEN] = {0};
char deviceType[DEVICE_TYPE_BUF_LEN] = { 0 };
if (!JSON_GetStringFromOject(json, DEVICE_NAME, info->deviceInfo.deviceName, DEVICE_NAME_BUF_LEN) ||
!JSON_GetStringFromOject(json, DEVICE_TYPE, deviceType, DEVICE_TYPE_BUF_LEN) ||
!JSON_GetStringFromOject(json, DEVICE_UDID, info->deviceInfo.deviceUdid, UDID_BUF_LEN) ||
@ -1314,6 +1366,7 @@ static int32_t UnpackDeviceInfoBtV1(const JsonObj *json, NodeInfo *info)
}
if (strcpy_s(info->networkId, NETWORK_ID_BUF_LEN, info->uuid) != EOK) {
AUTH_LOGE(AUTH_FSM, "strcpy networkId fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
@ -1365,8 +1418,7 @@ static void UpdatePeerDeviceName(NodeInfo *peerNodeInfo)
if (strlen(peerNodeInfo->deviceInfo.unifiedName) != 0 &&
strcmp(peerNodeInfo->deviceInfo.unifiedName, peerNodeInfo->deviceInfo.unifiedDefaultName) != 0) {
ret = strcpy_s(deviceName, DEVICE_NAME_BUF_LEN, peerNodeInfo->deviceInfo.unifiedName);
} else if (strlen(peerNodeInfo->deviceInfo.nickName) == 0 ||
localInfo->accountId == peerNodeInfo->accountId) {
} else if (strlen(peerNodeInfo->deviceInfo.nickName) == 0 || localInfo->accountId == peerNodeInfo->accountId) {
ret = strcpy_s(deviceName, DEVICE_NAME_BUF_LEN, peerNodeInfo->deviceInfo.unifiedDefaultName);
} else {
LnnGetDeviceDisplayName(peerNodeInfo->deviceInfo.nickName,
@ -1385,8 +1437,8 @@ static void UpdatePeerDeviceName(NodeInfo *peerNodeInfo)
int32_t UnpackDeviceInfoMessage(const DevInfoData *devInfo, NodeInfo *nodeInfo, bool isMetaAuth)
{
CHECK_NULL_PTR_RETURN_VALUE(devInfo, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(nodeInfo, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(devInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "devInfo is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(nodeInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "nodeInfo is NULL");
AUTH_LOGI(AUTH_FSM, "connType=%d", devInfo->linkType);
JsonObj *json = JSON_Parse(devInfo->msg, devInfo->len);
if (json == NULL) {
@ -1489,7 +1541,7 @@ static int32_t PostDeviceIdNew(int64_t authSeq, const AuthSessionInfo *info)
int32_t PostDeviceIdMessage(int64_t authSeq, const AuthSessionInfo *info)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
if (info->version == SOFTBUS_OLD_V1) {
return PostDeviceIdV1(authSeq, info);
} else {
@ -1499,11 +1551,9 @@ int32_t PostDeviceIdMessage(int64_t authSeq, const AuthSessionInfo *info)
int32_t ProcessDeviceIdMessage(AuthSessionInfo *info, const uint8_t *data, uint32_t len)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) &&
(len == DEVICE_ID_STR_LEN) &&
(info->isServer)) {
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) && (len == DEVICE_ID_STR_LEN) && (info->isServer)) {
info->version = SOFTBUS_OLD_V1;
return UnPackBtDeviceIdV1(info, data, len);
}
@ -1520,13 +1570,15 @@ static void GetSessionKeyList(int64_t authSeq, const AuthSessionInfo *info, Sess
}
if (AddSessionKey(list, TO_INT32(authSeq), &sessionKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "add session key fail");
(void)memset_s(&sessionKey, sizeof(SessionKey), 0, sizeof(SessionKey));
return;
}
(void)memset_s(&sessionKey, sizeof(SessionKey), 0, sizeof(SessionKey));
}
int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
char *msg = PackDeviceInfoMessage(info->connInfo.type, info->version, false, info->uuid);
if (msg == NULL) {
AUTH_LOGE(AUTH_FSM, "pack device info fail");
@ -1543,7 +1595,7 @@ int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
compressFlag = FLAG_COMPRESS_DEVICE_INFO;
AUTH_LOGI(AUTH_FSM, "deviceInfo compress finish");
}
AUTH_LOGI(AUTH_FSM, "after compress, datalen=%d", compressLen);
AUTH_LOGI(AUTH_FSM, "after compress, datalen=%u", compressLen);
}
uint8_t *inputData = NULL;
uint32_t inputLen;
@ -1593,8 +1645,8 @@ int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const uint8_t *data, uint32_t len)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
uint8_t *msg = NULL;
uint32_t msgSize = 0;
SessionKeyList sessionKeyList;
@ -1606,7 +1658,7 @@ int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const u
uint8_t *decompressData = NULL;
uint32_t decompressLen = 0;
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) && info->isSupportCompress) {
AUTH_LOGI(AUTH_FSM, "before decompress, msgSize=%d", msgSize);
AUTH_LOGI(AUTH_FSM, "before decompress, msgSize=%u", msgSize);
if (DataDecompress((uint8_t *)msg, msgSize, &decompressData, &decompressLen) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "data decompress fail");
SoftBusFree(msg);
@ -1637,7 +1689,7 @@ int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const u
int32_t PostCloseAckMessage(int64_t authSeq, const AuthSessionInfo *info)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
const char *msg = "";
AuthDataHead head = {
.dataType = DATA_TYPE_CLOSE_ACK,
@ -1655,8 +1707,8 @@ int32_t PostCloseAckMessage(int64_t authSeq, const AuthSessionInfo *info)
int32_t PostHichainAuthMessage(int64_t authSeq, const AuthSessionInfo *info, const uint8_t *data, uint32_t len)
{
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
AuthDataHead head = {
.dataType = DATA_TYPE_AUTH,
.module = MODULE_AUTH_SDK,
@ -1678,8 +1730,7 @@ static char *PackVerifyDeviceMessage(const char *uuid)
AUTH_LOGE(AUTH_FSM, "create json fail");
return NULL;
}
if (!JSON_AddInt32ToObject(obj, CODE, CODE_VERIFY_DEVICE) ||
!JSON_AddStringToObject(obj, DEVICE_ID, uuid)) {
if (!JSON_AddInt32ToObject(obj, CODE, CODE_VERIFY_DEVICE) || !JSON_AddStringToObject(obj, DEVICE_ID, uuid)) {
AUTH_LOGE(AUTH_FSM, "add uuid fail");
JSON_Delete(obj);
return NULL;
@ -1730,7 +1781,7 @@ bool IsFlushDevicePacket(const AuthConnInfo *connInfo, const AuthDataHead *head,
int32_t PostVerifyDeviceMessage(const AuthManager *auth, int32_t flagRelay)
{
CHECK_NULL_PTR_RETURN_VALUE(auth, SOFTBUS_INVALID_PARAM);
AUTH_CHECK_AND_RETURN_RET_LOGE(auth != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "auth is NULL");
char *msg = PackVerifyDeviceMessage(auth->uuid);
if (msg == NULL) {
AUTH_LOGE(AUTH_FSM, "pack verify device msg fail");

View File

@ -248,6 +248,14 @@ static int32_t ProcessSocketInEvent(ListenerModule module, int32_t fd)
return SOFTBUS_OK;
}
static bool IsEnhanceP2pModuleId(ListenerModule moduleId)
{
if (moduleId >= AUTH_ENHANCED_P2P_START && moduleId <= AUTH_ENHANCED_P2P_END) {
return true;
}
return false;
}
static int32_t OnConnectEvent(ListenerModule module,
int32_t cfd, const ConnectOption *clientAddr)
{
@ -265,7 +273,7 @@ static int32_t OnConnectEvent(ListenerModule module,
ConnShutdownSocket(cfd);
return SOFTBUS_ERR;
}
if (module != AUTH && module != AUTH_P2P) {
if (module != AUTH && module != AUTH_P2P && !IsEnhanceP2pModuleId(module)) {
AUTH_LOGI(AUTH_CONN, "newip auth process");
if (RouteBuildServerAuthManager(cfd, clientAddr) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "build auth manager fail.");

View File

@ -35,7 +35,7 @@ int32_t LnnIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId,
int32_t LnnIpcGetNodeKeyInfoLen(int32_t key);
int32_t LnnIpcStartTimeSync(
const char *pkgName, int32_t callingPid, const char *targetNetworkId, int32_t accuracy, int32_t period);
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId);
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid);
int32_t LnnIpcPublishLNN(const char *pkgName, const PublishInfo *info);
int32_t LnnIpcStopPublishLNN(const char *pkgName, int32_t publishId);
int32_t LnnIpcRefreshLNN(const char *pkgName, int32_t callingPid, const SubscribeInfo *info);

View File

@ -97,9 +97,9 @@ int32_t LnnIpcStartTimeSync(const char *pkgName, int32_t callingPid, const char
return LnnStartTimeSync(pkgName, callingPid, targetNetworkId, (TimeSyncAccuracy)accuracy, (TimeSyncPeriod)period);
}
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid)
{
return LnnStopTimeSync(pkgName, targetNetworkId);
return LnnStopTimeSync(pkgName, targetNetworkId, callingPid);
}
int32_t LnnIpcPublishLNN(const char *pkgName, const PublishInfo *info)

View File

@ -310,9 +310,9 @@ int32_t LnnIpcStartTimeSync(const char *pkgName, int32_t callingPid, const char
return LnnStartTimeSync(pkgName, callingPid, targetNetworkId, (TimeSyncAccuracy)accuracy, (TimeSyncPeriod)period);
}
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid)
{
return LnnStopTimeSync(pkgName, targetNetworkId);
return LnnStopTimeSync(pkgName, targetNetworkId, callingPid);
}
int32_t LnnIpcPublishLNN(const char *pkgName, const PublishInfo *info)

View File

@ -223,9 +223,9 @@ int32_t LnnIpcStartTimeSync(const char *pkgName, int32_t callingPid, const char
return LnnStartTimeSync(pkgName, callingPid, targetNetworkId, (TimeSyncAccuracy)accuracy, (TimeSyncPeriod)period);
}
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid)
{
return LnnStopTimeSync(pkgName, targetNetworkId);
return LnnStopTimeSync(pkgName, targetNetworkId, callingPid);
}
int32_t LnnIpcPublishLNN(const char *pkgName, const PublishInfo *info)

View File

@ -151,6 +151,7 @@ typedef struct {
bool p2pOnly;
ProtocolType acceptableProtocols;
int32_t pid;
bool isWithQos;
//OldInfo
char peerBleMac[MAX_MAC_LEN];
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'

View File

@ -28,7 +28,8 @@ extern "C" {
typedef enum {
HIGH_BAND_WIDTH = 0,
MIDDLE_BAND_WIDTH,
MIDDLE_HIGH_BAND_WIDTH,
MIDDLE_LOW_BAND_WIDTH,
LOW_BAND_WIDTH,
BW_TYPE_BUTT,
} BandWidthType;

View File

@ -17,28 +17,18 @@
#define LNN_TRANS_LANE_H
#include "lnn_lane_assign.h"
#include "lnn_lane_link.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
MSG_TYPE_LANE_TRIGGER_LINK = 0,
MSG_TYPE_LANE_LINK_SUCCESS,
MSG_TYPE_LANE_LINK_FAIL,
MSG_TYPE_LANE_LINK_EXCEPTION,
MSG_TYPE_DELAY_DESTROY_LINK,
MSG_TYPE_LANE_DETECT_TIMEOUT,
MSG_TYPE_RELIABILITY_TIME,
} LaneMsgType;
LaneInterface *TransLaneGetInstance(void);
int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt);
int32_t LnnLanePostMsgToHandler(int32_t msgType, uint64_t param1, uint64_t param2,
void *obj, uint64_t delayMillis);
int32_t GetTransOptionByLaneId(uint32_t laneId, TransOption *reqInfo);
int32_t PostDetectTimeoutMessage(uint32_t detectId, uint64_t delayMillis);
int32_t PostReliabilityTimeMessage(void);
void RemoveDetectTimeoutMessage(uint32_t detectId);
int32_t PostDelayDestroyMessage(uint32_t laneId, LaneResource *resourseItem, uint64_t delayMillis);
#ifdef __cplusplus
}

View File

@ -179,10 +179,12 @@ int32_t AddLaneResourceItem(const LaneResource *inputResource)
return SOFTBUS_MALLOC_ERR;
}
if (CreateResourceItem(inputResource, resourceItem) != SOFTBUS_OK) {
SoftBusFree(resourceItem);
LNN_LOGE(LNN_LANE, "create resourceItem fail");
return SOFTBUS_ERR;
}
if (LaneLock() != SOFTBUS_OK) {
SoftBusFree(resourceItem);
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
@ -198,6 +200,25 @@ int32_t AddLaneResourceItem(const LaneResource *inputResource)
return SOFTBUS_OK;
}
static int32_t StartDelayDestroyLink(uint32_t laneId, LaneResource *item)
{
LaneResource *resourceItem = (LaneResource *)SoftBusMalloc(sizeof(LaneResource));
if (resourceItem == NULL) {
LNN_LOGE(LNN_LANE, "resourceItem malloc fail");
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(resourceItem, sizeof(LaneResource), item, sizeof(LaneResource)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy LaneResource error");
SoftBusFree(resourceItem);
return SOFTBUS_MEM_ERR;
}
if (PostDelayDestroyMessage(laneId, resourceItem, DELAY_DESTROY_LANE_TIME) != SOFTBUS_OK) {
SoftBusFree(resourceItem);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t DelLaneResourceItemWithDelay(LaneResource *resourceItem, uint32_t laneId, bool *isDelayDestroy)
{
if (resourceItem == NULL || isDelayDestroy == NULL) {
@ -210,9 +231,9 @@ int32_t DelLaneResourceItemWithDelay(LaneResource *resourceItem, uint32_t laneId
}
LaneResource* item = LaneResourceIsExist(resourceItem);
if (item != NULL) {
LNN_LOGI(LNN_LANE, "link=%d ref=%d", item->type, item->laneRef);
if (item->type == LANE_HML && item->laneRef == 1) {
if (LnnLanePostMsgToHandler(MSG_TYPE_DELAY_DESTROY_LINK, laneId, *isDelayDestroy, item,
DELAY_DESTROY_LANE_TIME) == SOFTBUS_OK) {
if (StartDelayDestroyLink(laneId, item) == SOFTBUS_OK) {
*isDelayDestroy = true;
LaneUnlock();
return SOFTBUS_OK;
@ -324,10 +345,12 @@ int32_t AddLinkInfoItem(const LaneLinkInfo *inputLinkInfo)
return SOFTBUS_MALLOC_ERR;
}
if (CreateLinkInfoItem(inputLinkInfo, linkInfoItem) != SOFTBUS_OK) {
SoftBusFree(linkInfoItem);
LNN_LOGE(LNN_LANE, "create linkInfoItem fail");
return SOFTBUS_ERR;
}
if (LaneLock() != SOFTBUS_OK) {
SoftBusFree(linkInfoItem);
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
@ -703,6 +726,22 @@ static int32_t LaneLinkOfBleReuse(uint32_t reqId, const LinkRequest *reqInfo, co
return LaneLinkOfBleReuseCommon(reqId, reqInfo, callback, BLE_GATT);
}
static int32_t LaneLinkSetBleMac(const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
{
NodeInfo node;
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(reqInfo->peerNetworkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "can not find node");
return SOFTBUS_ERR;
}
if (node.bleMacRefreshSwitch == 0 && strlen(node.connectInfo.bleMacAddr) > 0) {
if (strcpy_s(linkInfo->linkInfo.ble.bleMac, BT_MAC_LEN, node.connectInfo.bleMacAddr) == EOK) {
return SOFTBUS_OK;
}
}
return SOFTBUS_ERR;
}
static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
{
LaneLinkInfo linkInfo;
@ -712,8 +751,10 @@ static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const L
return SOFTBUS_MEM_ERR;
}
if (strlen(linkInfo.linkInfo.ble.bleMac) == 0) {
LNN_LOGE(LNN_LANE, "get peerBleMac error");
return SOFTBUS_ERR;
if (LaneLinkSetBleMac(reqInfo, &linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get peerBleMac error");
return SOFTBUS_ERR;
}
}
char peerUdid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_DEV_UDID, peerUdid, UDID_BUF_LEN) != SOFTBUS_OK) {

View File

@ -62,6 +62,7 @@ typedef struct {
bool networkDelegate;
bool p2pOnly;
uint32_t bandWidth;
bool isWithQos;
} P2pRequestInfo;
typedef struct {
@ -362,11 +363,12 @@ static int32_t GetP2pLinkReqParamByChannelRequetId(
return SOFTBUS_ERR;
}
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
if (item->p2pInfo.p2pOnly) {
wifiDirectInfo->connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P;
} else {
if (item->p2pInfo.isWithQos) {
wifiDirectInfo->connectType = ((item->laneRequestInfo.laneType == LANE_HML) ?
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P);
} else {
wifiDirectInfo->connectType = item->p2pInfo.p2pOnly ? WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P :
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
}
item->p2pInfo.p2pRequestId = p2pRequestId;
item->proxyChannelInfo.channelId = channelId;
@ -407,11 +409,12 @@ static int32_t GetP2pLinkReqParamByAuthId(uint32_t authRequestId, int32_t p2pReq
}
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
if (item->p2pInfo.p2pOnly) {
wifiDirectInfo->connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P;
} else {
if (item->p2pInfo.isWithQos) {
wifiDirectInfo->connectType = ((item->laneRequestInfo.laneType == LANE_HML) ?
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P);
} else {
wifiDirectInfo->connectType = item->p2pInfo.p2pOnly ? WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P :
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
}
item->p2pInfo.p2pRequestId = p2pRequestId;
LinkUnlock();
@ -617,6 +620,25 @@ static void OnAuthConnOpenFailed(uint32_t authRequestId, int32_t reason)
NotifyLinkFail(ASYNC_RESULT_AUTH, authRequestId, reason);
}
static int32_t updataP2pLinkReq(P2pLinkReqList *p2pReqInfo, uint32_t laneLinkReqId)
{
TransOption reqInfo = {0};
if (GetTransOptionByLaneId(laneLinkReqId, &reqInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get TransReqInfo fail, laneId=%d", laneLinkReqId);
return SOFTBUS_ERR;
}
if (reqInfo.isWithQos) {
p2pReqInfo->p2pInfo.bandWidth = reqInfo.qosRequire.minBW;
p2pReqInfo->p2pInfo.isWithQos = true;
} else {
p2pReqInfo->p2pInfo.bandWidth = 0;
p2pReqInfo->p2pInfo.isWithQos = false;
}
LNN_LOGI(LNN_LANE, "wifidirect conn, bandWidth=%d isWithQos=%d laneId=%d",
p2pReqInfo->p2pInfo.bandWidth, p2pReqInfo->p2pInfo.isWithQos, laneLinkReqId);
return SOFTBUS_OK;
}
static int32_t AddConnRequestItem(uint32_t authRequestId, int32_t p2pRequestId, uint32_t laneLinkReqId,
const LinkRequest *request, int32_t channelRequestId, const LaneLinkCb *callback)
{
@ -634,11 +656,9 @@ static int32_t AddConnRequestItem(uint32_t authRequestId, int32_t p2pRequestId,
SoftBusFree(item);
return SOFTBUS_MEM_ERR;
}
QosInfo qosOpt = {0};
if (GetQosInfoByLaneId(laneLinkReqId, &qosOpt) != SOFTBUS_OK) {
item->p2pInfo.bandWidth = 0;
} else {
item->p2pInfo.bandWidth = qosOpt.minBW;
if (updataP2pLinkReq(item, laneLinkReqId) != SOFTBUS_OK) {
SoftBusFree(item);
return SOFTBUS_ERR;
}
item->laneRequestInfo.laneLinkReqId = laneLinkReqId;
item->laneRequestInfo.pid = request->pid;

View File

@ -25,7 +25,6 @@
#include "lnn_lane_link.h"
#include "softbus_bus_center.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_wifi_api_adapter.h"
#include "wifi_direct_manager.h"

View File

@ -208,6 +208,7 @@ static int32_t WlanDetectReliability(uint32_t lnnReqId, const LaneLinkInfo *lane
}
infoItem->linkInfo.wlanDetect.wlanFd = fd;
if (SoftBusMutexLock(&g_laneDetectList.lock) != SOFTBUS_OK) {
ConnShutdownSocket(fd);
SoftBusFree(infoItem);
return SOFTBUS_LOCK_ERR;
}
@ -215,6 +216,7 @@ static int32_t WlanDetectReliability(uint32_t lnnReqId, const LaneLinkInfo *lane
ListTailInsert(&g_laneDetectList.list, &infoItem->node);
SoftBusMutexUnlock(&g_laneDetectList.lock);
if (AddLaneTriggerAndTimeOut(fd, infoItem->laneDetectId) != SOFTBUS_OK) {
ConnShutdownSocket(fd);
DelLaneDetectInfo(infoItem->laneDetectId);
LNN_LOGI(LNN_LANE, "wlan add trigger and timrout msg fail, lnnReqId=%u", infoItem->laneDetectId);
return SOFTBUS_ERR;

View File

@ -239,24 +239,38 @@ static void SwapListNode(LaneLinkType *left, LaneLinkType *right)
*right = tmp;
}
static int32_t AdjustLanePriority(LaneLinkType *resList, int32_t *resListScore, uint32_t resNum)
static int32_t AdjustLanePriority(const char *networkId, const LaneSelectParam *request,
LaneLinkType *resList, uint32_t resNum)
{
int32_t resListScore[LANE_LINK_TYPE_BUTT];
(void)memset_s(resListScore, sizeof(resListScore), INVALID_LINK, sizeof(resListScore));
if (GetListScore(networkId, request->expectedBw, resList, resListScore, resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get linklist score fail");
return SOFTBUS_ERR;
}
if ((resListScore[LANE_WLAN_2P4G] == INVALID_LINK && resListScore[LANE_WLAN_5G] == INVALID_LINK) ||
resListScore[LANE_P2P] == INVALID_LINK) {
LNN_LOGI(LNN_LANE, "resList no change");
(resListScore[LANE_P2P] == INVALID_LINK && resListScore[LANE_HML] == INVALID_LINK)) {
LNN_LOGI(LNN_LANE, "linklist does not require any changes");
return SOFTBUS_OK;
}
uint32_t idxWlan = LANE_LINK_TYPE_BUTT;
uint32_t idxP2p = LANE_LINK_TYPE_BUTT;
for (uint32_t i = 0; i < resNum; ++i) {
if (resList[i] == LANE_P2P) {
idxP2p = i;
} else if (resList[i] == LANE_WLAN_2P4G || resList[i] == LANE_WLAN_5G) {
idxWlan = (idxWlan == LANE_LINK_TYPE_BUTT) ? i : idxWlan;
if (resList[i] == LANE_WLAN_2P4G || resList[i] == LANE_WLAN_5G) {
idxWlan = i;
break;
}
}
if (resListScore[resList[idxWlan]] < UNACCEPT_SCORE && idxWlan < idxP2p) {
SwapListNode(&resList[idxWlan], &resList[idxP2p]);
if (resListScore[resList[idxWlan]] >= UNACCEPT_SCORE) {
return SOFTBUS_OK;
}
for (uint32_t j = idxWlan; j < resNum; ++j) {
if (resList[j] == LANE_HML || resList[j] == LANE_P2P) {
SwapListNode(&resList[idxWlan], &resList[j]);
idxWlan = j;
}
}
for (uint32_t k = 0; k < resNum; ++k) {
LNN_LOGD(LNN_LANE, "adjusted linklist , priority link=%d, score=%d", resList[k], resListScore[resList[k]]);
}
return SOFTBUS_OK;
}
@ -282,20 +296,10 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
*listNum = 0;
return SOFTBUS_ERR;
}
int32_t resListScore[LANE_LINK_TYPE_BUTT];
(void)memset_s(resListScore, sizeof(resListScore), INVALID_LINK, sizeof(resListScore));
if (GetListScore(networkId, request->expectedBw, resList, resListScore, resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get resListScore fail");
return SOFTBUS_ERR;
}
if (AdjustLanePriority(resList, resListScore, resNum) != SOFTBUS_OK) {
if (AdjustLanePriority(networkId, request, resList, resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "AdjustLanePriority fail");
return SOFTBUS_ERR;
}
for (uint32_t i = 0; i < resNum; ++i) {
LNN_LOGD(LNN_LANE, "adjusted list is LaneLinkType=%d, score=%d", resList[i], resListScore[resList[i]]);
}
recommendList->linkTypeNum = resNum;
for (uint32_t i = 0; i < resNum; i++) {
@ -305,27 +309,6 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
return SOFTBUS_OK;
}
static int32_t LanePrioritization(LanePreferredLinkList *recommendList, const uint16_t *laneScore)
{
(void)recommendList;
(void)laneScore;
return SOFTBUS_OK;
}
static bool GetLaneScore(const char *networkId, LaneLinkType linkType, uint16_t *score)
{
if (!IsLinkTypeValid(linkType)) {
return false;
}
LinkAttribute *linkAttr = GetLinkAttrByLinkType(linkType);
if ((linkAttr == NULL) || (!linkAttr->available)) {
return false;
}
uint32_t expectedBw = 0;
score[linkType] = linkAttr->GetLinkScore(networkId, expectedBw);
return true;
}
int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *request,
LanePreferredLinkList *recommendList)
{
@ -351,19 +334,16 @@ int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *req
}
}
recommendList->linkTypeNum = 0;
uint16_t laneScore[LANE_LINK_TYPE_BUTT] = {0};
for (uint32_t i = 0; i < laneLinkList.linkTypeNum; i++) {
if (!GetLaneScore(networkId, laneLinkList.linkType[i], laneScore)) {
LNN_LOGE(LNN_LANE, "link=%d get lane score fail", laneLinkList.linkType[i]);
continue;
}
recommendList->linkType[recommendList->linkTypeNum] = laneLinkList.linkType[i];
LNN_LOGI(LNN_LANE, "expect linklist the %u priority link=%d",
recommendList->linkTypeNum, laneLinkList.linkType[i]);
recommendList->linkTypeNum++;
}
if (LanePrioritization(recommendList, laneScore) != SOFTBUS_OK) {
if (AdjustLanePriority(networkId, request, recommendList->linkType,
recommendList->linkTypeNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "AdjustLanePriority fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;

View File

@ -41,13 +41,16 @@
#define LNN_LINK_DEFAULT_SCORE 60 /* Indicates that scoring is not supported */
#define LNN_ONLINETIME_OUT 10000 /*BLE connection reuse time*/
#define LOW_BW (500 * 1024)
#define LOW_BW (384 * 1024)
#define MID_BW (30 * 1024 * 1024)
#define HIGH_BW (160 * 1024 * 1024)
#define COC_DIRECT_LATENCY 1200
#define BR_LATENCY 2500
#define WLAN_LATENCY 800
#define P2P_LATENCY 1600
#define BLE_LATENCY 1500
#define HML_LATENCY 1500
#define BR_REUSE_LATENCY 1000
int32_t GetWlanLinkedFrequency(void)
@ -393,20 +396,24 @@ static int32_t g_laneLatency[LANE_LINK_TYPE_BUTT] = {
[LANE_WLAN_2P4G] = WLAN_LATENCY,
[LANE_WLAN_5G] = WLAN_LATENCY,
[LANE_COC_DIRECT] = COC_DIRECT_LATENCY,
[LANE_BLE] = BLE_LATENCY,
};
static uint32_t g_laneBandWidth[BW_TYPE_BUTT][LANE_LINK_TYPE_BUTT + 1] = {
[HIGH_BAND_WIDTH] = {LANE_P2P, LANE_LINK_TYPE_BUTT},
[MIDDLE_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_LINK_TYPE_BUTT},
[LOW_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_COC_DIRECT, LANE_LINK_TYPE_BUTT},
[MIDDLE_HIGH_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_LINK_TYPE_BUTT},
[MIDDLE_LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_LINK_TYPE_BUTT},
[LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_COC_DIRECT, LANE_LINK_TYPE_BUTT},
};
static uint32_t g_retryLaneList[BW_TYPE_BUTT][LANE_LINK_TYPE_BUTT + 1] = {
[HIGH_BAND_WIDTH] = {LANE_P2P, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_LINK_TYPE_BUTT},
[MIDDLE_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_P2P,
LANE_BR, LANE_LINK_TYPE_BUTT},
[LOW_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_P2P, LANE_COC_DIRECT,
LANE_BR, LANE_LINK_TYPE_BUTT},
[MIDDLE_HIGH_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_P2P, LANE_BR,
LANE_LINK_TYPE_BUTT},
[MIDDLE_LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_P2P, LANE_BR,
LANE_LINK_TYPE_BUTT},
[LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_P2P, LANE_COC_DIRECT,
LANE_BR, LANE_BLE, LANE_LINK_TYPE_BUTT},
};
static bool IsLinkTypeValid(LaneLinkType type)
@ -449,25 +456,31 @@ static bool IsLaneFillMinLatency(uint32_t minLaneLatency, LaneLinkType linkType)
return false;
}
static int32_t GetBwType(uint32_t bandWidth)
{
int32_t bandWidthType;
if (bandWidth >= HIGH_BW) {
bandWidthType = HIGH_BAND_WIDTH;
} else if (bandWidth > MID_BW) {
bandWidthType = MIDDLE_HIGH_BAND_WIDTH;
} else if (bandWidth > LOW_BW) {
bandWidthType = MIDDLE_LOW_BAND_WIDTH;
} else {
bandWidthType = LOW_BAND_WIDTH;
}
return bandWidthType;
}
static void DecideOptimalLinks(const char *networkId, const LaneSelectParam *request,
LaneLinkType *linkList, uint32_t *linksNum)
{
uint32_t minBandWidth = request->qosRequire.minBW;
uint32_t minLaneLatency = request->qosRequire.minLaneLatency;
if (minBandWidth == 0) {
minBandWidth = LOW_BW;
}
if (minLaneLatency == 0) {
minLaneLatency = BR_LATENCY;
}
int32_t bandWidthType;
if (minBandWidth >= HIGH_BW) {
bandWidthType = HIGH_BAND_WIDTH;
} else if (minBandWidth >= LOW_BW) {
bandWidthType = MIDDLE_BAND_WIDTH;
} else {
bandWidthType = LOW_BAND_WIDTH;
LNN_LOGI(LNN_LANE, "minLaneLatency is zero, cancel decide optimal link");
return;
}
int32_t bandWidthType = GetBwType(minBandWidth);
LNN_LOGI(LNN_LANE, "decide optimal link, band width type=%ld, latency=%d", bandWidthType, minLaneLatency);
for (uint32_t i = 0; i < (LANE_LINK_TYPE_BUTT + 1); i++) {
if (g_laneBandWidth[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
@ -493,21 +506,31 @@ static bool isLaneExist(LaneLinkType *linkList, LaneLinkType laneType)
return false;
}
static void GetAllLinksWithBw(const char *networkId, int32_t bandWidthType, const LaneSelectParam *request,
LaneLinkType *linkList, uint32_t *linksNum)
{
for (uint32_t i = 0; i < (LANE_LINK_TYPE_BUTT + 1); i++) {
if (g_retryLaneList[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
break;
}
if (IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
linkList[(*linksNum)++] = g_retryLaneList[bandWidthType][i];
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", g_retryLaneList[bandWidthType][i]);
}
}
}
static void DecideRetryLinks(const char *networkId, const LaneSelectParam *request,
LaneLinkType *linkList, uint32_t *linksNum)
{
uint32_t minBandWidth = request->qosRequire.minBW;
uint32_t maxLaneLatency = request->qosRequire.maxLaneLatency;
int32_t bandWidthType = GetBwType(minBandWidth);
if (maxLaneLatency == 0) {
maxLaneLatency = (BR_LATENCY + BR_LATENCY + BR_LATENCY + BR_LATENCY);
}
int32_t bandWidthType;
if (minBandWidth >= HIGH_BW) {
bandWidthType = HIGH_BAND_WIDTH;
} else if (minBandWidth >= LOW_BW) {
bandWidthType = MIDDLE_BAND_WIDTH;
} else {
bandWidthType = LOW_BAND_WIDTH;
LNN_LOGI(LNN_LANE, "maxLaneLatency is zero, get all retry link");
GetAllLinksWithBw(networkId, bandWidthType, request, linkList, linksNum);
return;
}
int32_t retryTime;
if (*linksNum == 0) {
@ -521,14 +544,40 @@ static void DecideRetryLinks(const char *networkId, const LaneSelectParam *reque
if (g_retryLaneList[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
break;
}
if (IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i]) &&
retryTime - g_laneLatency[g_retryLaneList[bandWidthType][i]] >= 0) {
if (retryTime - g_laneLatency[g_retryLaneList[bandWidthType][i]] >= 0 &&
IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
retryTime -= g_laneLatency[g_retryLaneList[bandWidthType][i]];
linkList[(*linksNum)++] = g_retryLaneList[bandWidthType][i];
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", g_retryLaneList[bandWidthType][i]);
}
}
if (bandWidthType == LOW_BAND_WIDTH &&
IsValidLane(networkId, LANE_BR, request->transType) && !isLaneExist(linkList, LANE_BR)) {
linkList[(*linksNum)++] = LANE_BR;
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", LANE_BR);
}
}
static bool IsSupportBrReuse(const char *peerNetWorkId)
{
ConnectOption connOpt;
(void)memset_s(&connOpt, sizeof(ConnectOption), 0, sizeof(ConnectOption));
connOpt.type = CONNECT_BR;
if (LnnGetRemoteStrInfo(peerNetWorkId, STRING_KEY_BT_MAC, connOpt.brOption.brMac, BT_MAC_LEN) != SOFTBUS_OK ||
connOpt.brOption.brMac[0] == '\0') {
return false;
}
return CheckActiveConnection(&connOpt);
}
static void UpdataLaneLatency(const char *peerNetWorkId)
{
if (IsSupportBrReuse(peerNetWorkId)) {
g_laneLatency[LANE_BR] = BR_REUSE_LATENCY;
} else {
g_laneLatency[LANE_BR] = BR_LATENCY;
}
}
int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *request, LanePreferredLinkList *recommendList)
@ -539,6 +588,7 @@ int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *reques
LaneLinkType linkList[LANE_LINK_TYPE_BUTT];
(void)memset_s(linkList, sizeof(linkList), -1, sizeof(linkList));
uint32_t linksNum = 0;
UpdataLaneLatency(networkId);
DecideOptimalLinks(networkId, request, linkList, &linksNum);
DecideRetryLinks(networkId, request, linkList, &linksNum);
for (uint32_t i = 0; i < linksNum; i++) {

View File

@ -23,7 +23,6 @@
#include "lnn_lane_common.h"
#include "lnn_lane_def.h"
#include "lnn_lane_interface.h"
#include "lnn_lane_link.h"
#include "lnn_lane_model.h"
#include "lnn_lane_select.h"
#include "lnn_log.h"
@ -39,6 +38,16 @@
#define DETECT_LANE_TIMELINESS 2000
typedef enum {
MSG_TYPE_LANE_TRIGGER_LINK = 0,
MSG_TYPE_LANE_LINK_SUCCESS,
MSG_TYPE_LANE_LINK_FAIL,
MSG_TYPE_LANE_LINK_EXCEPTION,
MSG_TYPE_DELAY_DESTROY_LINK,
MSG_TYPE_LANE_DETECT_TIMEOUT,
MSG_TYPE_RELIABILITY_TIME,
} LaneMsgType;
typedef struct {
ListNode node;
uint32_t laneId;
@ -275,6 +284,7 @@ static int32_t StartTriggerLink(uint32_t laneId, TransOption *transRequest, cons
if (newItem == NULL) {
return SOFTBUS_ERR;
}
newItem->info.isWithQos = true;
if (Lock() != SOFTBUS_OK) {
SoftBusFree(newItem);
return SOFTBUS_ERR;
@ -363,6 +373,7 @@ static int32_t Alloc(uint32_t laneId, const LaneRequestOption *request, const IL
SoftBusFree(recommendLinkList);
return SOFTBUS_ERR;
}
newItem->info.isWithQos = false;
if (Lock() != SOFTBUS_OK) {
SoftBusFree(newItem);
SoftBusFree(recommendLinkList);
@ -404,7 +415,9 @@ static int32_t FreeLaneLink(uint32_t laneId, LaneResource *laneResourceInfo, boo
Unlock();
DelLinkInfoItem(laneId);
if (isDelayDestroy) {
LNN_LOGI(LNN_LANE, "laneId=%u, delayDestroy finished", laneId);
DelLaneResourceItem(laneResourceInfo);
SoftBusFree(laneResourceInfo);
}
DestroyLink(item->info.networkId, laneId, item->type, item->info.pid);
UnbindLaneId(laneId, item);
@ -413,6 +426,11 @@ static int32_t FreeLaneLink(uint32_t laneId, LaneResource *laneResourceInfo, boo
return SOFTBUS_OK;
}
}
DelLinkInfoItem(laneId);
if (isDelayDestroy) {
DelLaneResourceItem(laneResourceInfo);
SoftBusFree(laneResourceInfo);
}
Unlock();
FreeLaneId(laneId);
return SOFTBUS_OK;
@ -686,6 +704,7 @@ static void HandleDelayDestroyLink(SoftBusMessage *msg)
uint32_t laneId = (uint32_t)msg->arg1;
bool isDelayDestroy = (bool)msg->arg2;
LaneResource *resourceItem = (LaneResource*)msg->obj;
LNN_LOGI(LNN_LANE, "handle delay destory message, laneId=%u", laneId);
FreeLaneLink(laneId, resourceItem, isDelayDestroy);
}
@ -816,9 +835,9 @@ LaneInterface *TransLaneGetInstance(void)
return &g_transLaneObject;
}
int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt)
int32_t GetTransOptionByLaneId(uint32_t laneId, TransOption *reqInfo)
{
if (qosOpt == NULL || laneId == INVALID_LANE_ID) {
if (reqInfo == NULL || laneId == INVALID_LANE_ID) {
return SOFTBUS_INVALID_PARAM;
}
if (Lock() != SOFTBUS_OK) {
@ -827,7 +846,11 @@ int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt)
TransReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_requestList->list, TransReqInfo, node) {
if (item->laneId == laneId) {
*qosOpt = item->info.qosRequire;
if (memcpy_s(reqInfo, sizeof(TransOption), &item->info, sizeof(TransOption)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy TransReqInfo fail");
Unlock();
return SOFTBUS_ERR;
}
Unlock();
return SOFTBUS_OK;
}
@ -866,3 +889,9 @@ int32_t PostReliabilityTimeMessage(void)
{
return LnnLanePostMsgToHandler(MSG_TYPE_RELIABILITY_TIME, 0, 0, NULL, DETECT_LANE_TIMELINESS);
}
int32_t PostDelayDestroyMessage(uint32_t laneId, LaneResource *resourseItem, uint64_t delayMillis)
{
LNN_LOGI(LNN_LANE, "post dely destory message, laneId=%u", laneId);
return LnnLanePostMsgToHandler(MSG_TYPE_DELAY_DESTROY_LINK, laneId, true, resourseItem, delayMillis);
}

View File

@ -25,7 +25,7 @@ extern "C" {
int32_t LnnStartTimeSync(const char *pkgName, int32_t callingPid, const char *targetNetworkId,
TimeSyncAccuracy accuracy, TimeSyncPeriod period);
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId);
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid);
int32_t LnnInitTimeSync(void);
void LnnDeinitTimeSync(void);

View File

@ -69,6 +69,7 @@ typedef struct {
} StartTimeSyncReqMsgPara;
typedef struct {
int32_t pid;
char pkgName[PKG_NAME_SIZE_MAX];
char targetNetworkId[NETWORK_ID_BUF_LEN];
} StopTimeSyncReqMsgPara;
@ -167,13 +168,13 @@ static int32_t TryUpdateStartTimeSyncReq(TimeSyncReqInfo *info, const StartTimeS
return SOFTBUS_OK;
}
static void RemoveStartTimeSyncReq(const TimeSyncReqInfo *info, const char *pkgName)
static void RemoveStartTimeSyncReq(const TimeSyncReqInfo *info, const char *pkgName, int32_t pid)
{
StartTimeSyncReq *item = NULL;
StartTimeSyncReq *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &info->startReqList, StartTimeSyncReq, node) {
if (strcmp(pkgName, item->pkgName) != 0) {
if (strcmp(pkgName, item->pkgName) != 0 || item->pid != pid) {
continue;
}
ListDelete(&item->node);
@ -227,7 +228,7 @@ static int32_t ProcessStartTimeSyncRequest(const StartTimeSyncReqMsgPara *para)
if (LnnStartTimeSyncImpl(existInfo->targetNetworkId, existInfo->curAccuracy,
existInfo->curPeriod, &g_timeSyncImplCb) != SOFTBUS_OK) {
LNN_LOGE(LNN_CLOCK, "start time sync fail");
RemoveStartTimeSyncReq(existInfo, para->pkgName);
RemoveStartTimeSyncReq(existInfo, para->pkgName, para->pid);
break;
}
}
@ -293,7 +294,7 @@ static int32_t ProcessStopTimeSyncRequest(const StopTimeSyncReqMsgPara *para)
SoftBusFree((void *)para);
return SOFTBUS_ERR;
}
RemoveStartTimeSyncReq(info, para->pkgName);
RemoveStartTimeSyncReq(info, para->pkgName, para->pid);
TryUpdateTimeSyncReq(info);
SoftBusFree((void *)para);
return SOFTBUS_OK;
@ -335,7 +336,7 @@ static void RemoveAllStartTimeSyncReq(TimeSyncReqInfo *info)
StartTimeSyncReq *startTimeSyncNextItem = NULL;
LIST_FOR_EACH_ENTRY_SAFE(startTimeSyncItem, startTimeSyncNextItem, &info->startReqList, StartTimeSyncReq, node) {
RemoveStartTimeSyncReq(info, startTimeSyncItem->pkgName);
RemoveStartTimeSyncReq(info, startTimeSyncItem->pkgName, startTimeSyncItem->pid);
}
(void)LnnStopTimeSyncImpl(info->targetNetworkId);
ListDelete(&info->node);
@ -530,7 +531,7 @@ int32_t LnnStartTimeSync(const char *pkgName, int32_t callingPid, const char *ta
return SOFTBUS_OK;
}
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId)
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid)
{
StopTimeSyncReqMsgPara *para = NULL;
@ -547,6 +548,7 @@ int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId)
LNN_LOGE(LNN_CLOCK, "malloc stop time sync request msg para fail");
return SOFTBUS_MALLOC_ERR;
}
para->pid = callingPid;
if (strncpy_s(para->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK ||
strncpy_s(para->targetNetworkId, NETWORK_ID_BUF_LEN, targetNetworkId, strlen(targetNetworkId)) != EOK) {
LNN_LOGE(LNN_CLOCK, "copy time sync request info fail");

View File

@ -29,10 +29,11 @@ int32_t LnnStartTimeSync(const char *pkgName, int32_t callingPid, const char *ta
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId)
int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId, int32_t callingPid)
{
(void)pkgName;
(void)targetNetworkId;
(void)callingPid;
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -16,7 +16,6 @@
#include "lnn_device_info_recovery.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
int32_t LnnLoadLocalDeviceInfo(void)
{

View File

@ -47,7 +47,7 @@ static bool g_isApCoexistSupported = false;
static bool g_isWifiEnable = false;
static bool g_isApEnable = false;
static uint32_t ConvertMsgToCapability(uint32_t *capability, const uint8_t *msg, int32_t len)
static uint32_t ConvertMsgToCapability(uint32_t *capability, const uint8_t *msg, uint32_t len)
{
if (capability == NULL || msg == NULL || len < BITS) {
return SOFTBUS_ERR;
@ -112,7 +112,7 @@ static void OnReceiveCapaSyncInfoMsg(LnnSyncInfoType type, const char *networkId
return;
}
uint32_t capability = 0;
if (ConvertMsgToCapability(&capability, (const uint8_t *)msg, len) != SOFTBUS_OK) {
if (ConvertMsgToCapability(&capability, msg, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert msg to capability fail");
return;
}
@ -202,8 +202,8 @@ static void SendNetCapabilityToRemote(uint32_t netCapability, uint32_t type)
static void WifiStateProcess(uint32_t netCapability, bool isSend)
{
LNN_LOGI(LNN_BUILDER, "wifi state change netCapability=%d, isSend=%d", netCapability, isSend);
if (LnnSetLocalNumInfo(NUM_KEY_NET_CAP, netCapability) != SOFTBUS_OK) {
LNN_LOGI(LNN_BUILDER, "wifi state change netCapability=%u, isSend=%d", netCapability, isSend);
if (LnnSetLocalNumInfo(NUM_KEY_NET_CAP, (int32_t)netCapability) != SOFTBUS_OK) {
return;
}
if (!isSend) {
@ -335,7 +335,7 @@ static void BtStateChangeEventHandler(const LnnEventBasicInfo *info)
LNN_LOGI(LNN_BUILDER, "bt state change netCapability=%d, isSend=%d",
netCapability, isSend);
if (LnnSetLocalNumInfo(NUM_KEY_NET_CAP, netCapability) != SOFTBUS_OK) {
if (LnnSetLocalNumInfo(NUM_KEY_NET_CAP, (int32_t)netCapability) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set cap to local ledger fail");
return;
}

View File

@ -256,7 +256,7 @@ static VisitNextChoice NotifyBtStatusChanged(const LnnNetIfMgr *netifManager, vo
static void BtNetworkInfoUpdate(SoftBusBtState btState)
{
if (btState == SOFTBUS_BLE_TURN_ON) {
LnnSetLocalNum64Info(NUM_KEY_BLE_START_TIME, SoftBusGetSysTimeMs());
LnnSetLocalNum64Info(NUM_KEY_BLE_START_TIME, (int64_t)SoftBusGetSysTimeMs());
}
if (btState == SOFTBUS_BLE_TURN_OFF) {
LnnSetLocalNum64Info(NUM_KEY_BLE_START_TIME, 0);

View File

@ -531,6 +531,10 @@ static void NightModeChangeEventHandler(const LnnEventBasicInfo *info)
if (g_nightOnCache == NULL) {
LNN_LOGD(LNN_BUILDER, "init g_nightOnCache");
g_nightOnCache = (ListNode *)SoftBusMalloc(sizeof(ListNode));
if (g_nightOnCache == NULL) {
LNN_LOGE(LNN_BUILDER, "malloc g_nightOnCache fail");
return;
}
ListInit(g_nightOnCache);
}
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;

View File

@ -20,6 +20,7 @@
#include "anonymizer.h"
#include "auth_device_common_key.h"
#include "bus_center_event.h"
#include "bus_center_manager.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_decision_db.h"
@ -92,6 +93,7 @@ static void LnnRestoreLocalDeviceInfo()
if (LnnUpdateLocalNetworkId(info.networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set networkId fail");
}
LnnNotifyNetworkIdChangeEvent(info.networkId);
}
AuthLoadDeviceKey();
if (LnnLoadRemoteDeviceInfo() != SOFTBUS_OK) {
@ -237,7 +239,7 @@ int32_t LnnSetNodeDataChangeFlag(const char *networkId, uint16_t dataChangeFlag)
isLocalNetworkId = true;
}
if (isLocalNetworkId) {
return LnnSetLocalNum16Info(NUM_KEY_DATA_CHANGE_FLAG, dataChangeFlag);
return LnnSetLocalNum16Info(NUM_KEY_DATA_CHANGE_FLAG, (int16_t)dataChangeFlag);
}
LNN_LOGE(LNN_LEDGER, "remote networkId");
return SOFTBUS_ERR;

View File

@ -49,7 +49,7 @@ int32_t EncryptStorageData(uint8_t *dbKey, uint32_t len)
LNN_LOGE(LNN_LEDGER, "calloc encrypt dbKey fail");
return SOFTBUS_MEM_ERR;
}
LNN_LOGI(LNN_LEDGER, "Encrypt, data len=%d", len);
LNN_LOGI(LNN_LEDGER, "Encrypt, data len=%u", len);
plainData.size = len;
plainData.data = dbKey;
if (LnnEncryptDataByHuks(&g_keyAlias, &plainData, &encryptData) != SOFTBUS_OK) {
@ -79,7 +79,7 @@ int32_t DecryptStorageData(uint8_t *dbKey, uint32_t len)
LNN_LOGE(LNN_LEDGER, "calloc decrypt dbKey fail");
return SOFTBUS_MEM_ERR;
}
LNN_LOGI(LNN_LEDGER, "Decrypt, data len=%d", len);
LNN_LOGI(LNN_LEDGER, "Decrypt, data len=%u", len);
encryptData.size = len;
encryptData.data = dbKey;
int32_t ret;
@ -363,7 +363,7 @@ static int32_t GetTrustedDevInfoRecord(DbContext *ctx, const char *accountHexHas
*num = 0;
return SOFTBUS_ERR;
}
*num = GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash);
*((int32_t *)num) = GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash);
if (*num == 0) {
LNN_LOGW(LNN_LEDGER, "get none trusted dev info");
*udidArray = NULL;
@ -375,7 +375,7 @@ static int32_t GetTrustedDevInfoRecord(DbContext *ctx, const char *accountHexHas
return SOFTBUS_MALLOC_ERR;
}
if (QueryRecordByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash,
(uint8_t **)udidArray, *num) != SOFTBUS_OK) {
(uint8_t **)udidArray, *((int32_t *)num)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "query udidArray failed");
SoftBusFree(*udidArray);
*udidArray = NULL;

View File

@ -847,7 +847,7 @@ static int32_t DlGetNetCap(const char *networkId, void *buf, uint32_t len)
return SOFTBUS_INVALID_PARAM;
}
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
*((int32_t *)buf) = info->netCapacity;
*((int32_t *)buf) = (int32_t)info->netCapacity;
return SOFTBUS_OK;
}
@ -869,7 +869,7 @@ static int32_t DlGetNetType(const char *networkId, void *buf, uint32_t len)
return SOFTBUS_INVALID_PARAM;
}
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
*((int32_t *)buf) = info->discoveryType;
*((int32_t *)buf) = (int32_t)info->discoveryType;
return SOFTBUS_OK;
}
@ -1071,7 +1071,7 @@ static int32_t DlGetNodeDataChangeFlag(const char *networkId, void *buf, uint32_
LNN_LOGE(LNN_LEDGER, "node is offline");
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
*((int16_t *)buf) = LnnGetDataChangeFlag(info);
*((int16_t *)buf) = (int16_t)LnnGetDataChangeFlag(info);
return SOFTBUS_OK;
}

View File

@ -527,7 +527,7 @@ static int32_t LlGetNetCap(void *buf, uint32_t len)
if (buf == NULL || len != LNN_COMMON_LEN) {
return SOFTBUS_INVALID_PARAM;
}
*((int32_t *)buf) = info->netCapacity;
*((int32_t *)buf) = (int32_t)info->netCapacity;
return SOFTBUS_OK;
}
@ -547,7 +547,7 @@ static int32_t LlGetNetType(void *buf, uint32_t len)
if (buf == NULL || len != LNN_COMMON_LEN) {
return SOFTBUS_INVALID_PARAM;
}
*((int32_t *)buf) = info->discoveryType;
*((int32_t *)buf) = (int32_t)info->discoveryType;
return SOFTBUS_OK;
}
@ -674,7 +674,7 @@ static int32_t L1GetNodeDataChangeFlag(void *buf, uint32_t len)
if (buf == NULL || len != DATA_CHANGE_FLAG_BUF_LEN) {
return SOFTBUS_INVALID_PARAM;
}
*((int16_t *)buf) = LnnGetDataChangeFlag(&g_localNetLedger.localInfo);
*((int16_t *)buf) = (int16_t)LnnGetDataChangeFlag(&g_localNetLedger.localInfo);
return SOFTBUS_OK;
}

View File

@ -50,6 +50,7 @@ typedef enum {
LNN_EVENT_NETWORK_STATE_CHANGED,
LNN_EVENT_SINGLE_NETWORK_OFFLINE,
LNN_EVENT_NODE_HB_REPEAT_CYCLE,
LNN_EVENT_NETWORKID_CHANGED,
LNN_EVENT_TYPE_MAX,
} LnnEventType;
@ -204,6 +205,11 @@ typedef struct {
const char *udid;
} LnnSingleNetworkOffLineEvent;
typedef struct {
LnnEventBasicInfo basic;
char networkId[NETWORK_ID_BUF_LEN];
} LnnNetworkIdChangedEvent;
typedef void (*LnnEventHandler)(const LnnEventBasicInfo *info);
int32_t LnnInitBusCenterEvent(void);
@ -244,6 +250,8 @@ void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool i
void LnnNotifyNetworkStateChanged(SoftBusNetworkState state);
void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basicInfo);
void LnnNotifyNetworkIdChangeEvent(const char *networkId);
void LnnNotifyHBRepeat(void);
#ifdef __cplusplus

View File

@ -119,6 +119,7 @@ static void HandleNetworkUpdateMessage(SoftBusMessage *msg)
return;
}
LnnSetLocalStrInfo(STRING_KEY_NETWORKID, networkId);
LnnNotifyNetworkIdChangeEvent(networkId);
LNN_LOGD(LNN_EVENT, "offline exceted 5min, process networkId update event");
}
@ -628,6 +629,21 @@ void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basi
NotifyEvent((const LnnEventBasicInfo *)&event);
}
void LnnNotifyNetworkIdChangeEvent(const char *networkId)
{
if (networkId == NULL) {
LNN_LOGW(LNN_EVENT, "networkId is null");
return;
}
LnnNetworkIdChangedEvent eventInfo;
(void)memset_s(&eventInfo, sizeof(eventInfo), 0, sizeof(eventInfo));
eventInfo.basic.event = LNN_EVENT_NETWORKID_CHANGED;
if (strcpy_s(eventInfo.networkId, NETWORK_ID_BUF_LEN, networkId) != EOK) {
return;
}
NotifyEvent((LnnEventBasicInfo *)&eventInfo);
}
int32_t LnnInitBusCenterEvent(void)
{
int32_t i;

View File

@ -24,7 +24,6 @@ common_utils_src = [
"bitmap/softbus_bitmap.c",
"network/softbus_network_utils.c",
"json_utils/softbus_json_utils.c",
"log/softbus_log_old.c",
"message_handler/message_handler.c",
"queue/softbus_queue.c",
"security/sequence_verification/softbus_sequence_verification.c",

View File

@ -62,7 +62,6 @@ static void AnonymizeUdid(const char *udid, char **anonymizedUdid)
}
if (memset_s(*anonymizedUdid, ANONYMIZED_UDID_LEN + 1, 0, ANONYMIZED_UDID_LEN + 1) != EOK) {
COMM_LOGE(COMM_DFX, "memset_s *anonymizedStr fail");
free(*anonymizedUdid);
return;
}
// Reserve 5 chars at head, concat with two wildcards, and 5 chars at tail
@ -74,7 +73,6 @@ static void AnonymizeUdid(const char *udid, char **anonymizedUdid)
(ANONYMIZED_UDID_LEN - RESERVED_LEN - strlen(WILDCARDS) + 1), (udid + strlen(udid) - RESERVED_LEN),
RESERVED_LEN) != EOK) {
COMM_LOGE(COMM_DFX, "strncpy_s *anonymizedUdid fail");
free(*anonymizedUdid);
}
}
@ -88,12 +86,10 @@ static void AnonymizeMac(const char *mac, char **anonymizedMac)
}
if (memset_s(*anonymizedMac, anonymizedMacLen + 1, 0, anonymizedMacLen + 1) != EOK) {
COMM_LOGE(COMM_DFX, "memset_s *anonymizedStr fail");
free(*anonymizedMac);
return;
}
if (strcpy_s(*anonymizedMac, anonymizedMacLen + 1, mac) != EOK) {
COMM_LOGE(COMM_DFX, "strcpy_s *anonymizedMac fail");
free(*anonymizedMac);
return;
}
// Anonymize the forth and fifth parts of the mac address
@ -113,12 +109,10 @@ static void AnonymizeIp(const char *ip, char **anonymizedIp)
}
if (memset_s(*anonymizedIp, anonymizedIpLen + 1, 0, anonymizedIpLen + 1) != EOK) {
COMM_LOGE(COMM_DFX, "memset_s *anonymizedIp fail");
free(*anonymizedIp);
return;
}
if (strcpy_s(*anonymizedIp, anonymizedIpLen + 1, ip) != EOK) {
COMM_LOGE(COMM_DFX, "strcpy_s *anonymizedIp fail");
free(*anonymizedIp);
return;
}
// Anonymize the last part of ip address
@ -160,7 +154,6 @@ static void AnonymizeString(char **anonymizedStr, size_t length, const char *fmt
va_end(args);
if (ret < 0) {
COMM_LOGE(COMM_DFX, "vsprintf_s *anonymizedStr fail");
free(*anonymizedStr);
}
}

View File

@ -47,10 +47,10 @@ CONN_ASSIGNER(Int32, CostTime, costTime)
CONN_ASSIGNER(Int32, Rssi, rssi)
CONN_ASSIGNER(Int32, Load, load)
CONN_ASSIGNER(Int32, Frequency, frequency)
CONN_ASSIGNER(String, PeerIp, peerIp)
CONN_ASSIGNER(String, PeerBrMac, peerBrMac)
CONN_ASSIGNER(String, PeerBleMac, peerBleMac)
CONN_ASSIGNER(String, PeerWifiMac, peerWifiMac)
CONN_ASSIGNER(AnonymizeString, PeerIp, peerIp)
CONN_ASSIGNER(AnonymizeString, PeerBrMac, peerBrMac)
CONN_ASSIGNER(AnonymizeString, PeerBleMac, peerBleMac)
CONN_ASSIGNER(AnonymizeString, PeerWifiMac, peerWifiMac)
CONN_ASSIGNER(String, PeerPort, peerPort)
CONN_ASSIGNER(String, CallerPkg, callerPkg)
CONN_ASSIGNER(String, CalleePkg, calleePkg)

View File

@ -43,16 +43,16 @@ DISC_ASSIGNER(String, ScanCycle, scanCycle)
DISC_ASSIGNER(Int32, DiscType, discType)
DISC_ASSIGNER(Int32, DiscMode, discMode)
DISC_ASSIGNER(Int32, CostTime, costTime)
DISC_ASSIGNER(String, LocalNetworkId, localNetworkId)
DISC_ASSIGNER(String, LocalUdid, localUdid)
DISC_ASSIGNER(AnonymizeString, LocalNetworkId, localNetworkId)
DISC_ASSIGNER(AnonymizeString, LocalUdid, localUdid)
DISC_ASSIGNER(String, LocalDeviceType, localDeviceType)
DISC_ASSIGNER(String, PeerIp, peerIp)
DISC_ASSIGNER(String, PeerBrMac, peerBrMac)
DISC_ASSIGNER(String, PeerBleMac, peerBleMac)
DISC_ASSIGNER(String, PeerWifiMac, peerWifiMac)
DISC_ASSIGNER(AnonymizeString, PeerIp, peerIp)
DISC_ASSIGNER(AnonymizeString, PeerBrMac, peerBrMac)
DISC_ASSIGNER(AnonymizeString, PeerBleMac, peerBleMac)
DISC_ASSIGNER(AnonymizeString, PeerWifiMac, peerWifiMac)
DISC_ASSIGNER(String, PeerPort, peerPort)
DISC_ASSIGNER(String, PeerUdid, peerUdid)
DISC_ASSIGNER(String, PeerNetworkId, peerNetworkId)
DISC_ASSIGNER(AnonymizeString, PeerUdid, peerUdid)
DISC_ASSIGNER(AnonymizeString, PeerNetworkId, peerNetworkId)
DISC_ASSIGNER(String, PeerDeviceType, peerDeviceType)
DISC_ASSIGNER(String, CallerPkg, callerPkg)

View File

@ -43,13 +43,13 @@ LNN_ASSIGNER(Int32, LnnType, lnnType)
LNN_ASSIGNER(Int32, OnlineNum, onlineNum)
LNN_ASSIGNER(Int32, PeerDeviceAbility, peerDeviceAbility)
LNN_ASSIGNER(String, PeerDeviceInfo, peerDeviceInfo)
LNN_ASSIGNER(String, PeerIp, peerIp)
LNN_ASSIGNER(String, PeerBrMac, peerBrMac)
LNN_ASSIGNER(String, PeerBleMac, peerBleMac)
LNN_ASSIGNER(String, PeerWifiMac, peerWifiMac)
LNN_ASSIGNER(AnonymizeString, PeerIp, peerIp)
LNN_ASSIGNER(AnonymizeString, PeerBrMac, peerBrMac)
LNN_ASSIGNER(AnonymizeString, PeerBleMac, peerBleMac)
LNN_ASSIGNER(AnonymizeString, PeerWifiMac, peerWifiMac)
LNN_ASSIGNER(String, PeerPort, peerPort)
LNN_ASSIGNER(String, PeerUdid, peerUdid)
LNN_ASSIGNER(String, PeerNetworkId, peerNetworkId)
LNN_ASSIGNER(AnonymizeString, PeerUdid, peerUdid)
LNN_ASSIGNER(AnonymizeString, PeerNetworkId, peerNetworkId)
LNN_ASSIGNER(String, PeerDeviceType, peerDeviceType)
LNN_ASSIGNER(String, CallerPkg, callerPkg)
LNN_ASSIGNER(String, CalleePkg, calleePkg)

View File

@ -22,13 +22,15 @@
#include "comm_log.h"
#include "form/softbus_event_form.h"
#include "hisysevent_c.h"
#include "anonymizer.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INVALID_INT_VALUE 0
#define PARAM_STRING_VALUE_MAX_LEN 256
#define INVALID_INT_VALUE 0
#define PARAM_STRING_VALUE_MAX_LEN 256
#define PARAM_LONG_STRING_VALUE_MAX_LEN (256 * 1024)
typedef struct {
char name[MAX_LENGTH_OF_PARAM_NAME];
@ -73,7 +75,7 @@ static inline bool AssignerInt32(int32_t value, HiSysEventParam **param)
/* Used by ASSIGNER macros */
static inline bool AssignerString(const char *value, HiSysEventParam **param)
{
if (value == NULL || strlen(value) == 0) {
if (value == NULL || value[0] == '\0' || strnlen(value, PARAM_STRING_VALUE_MAX_LEN) == PARAM_STRING_VALUE_MAX_LEN) {
(*param)->v.s = NULL;
return false;
}
@ -81,6 +83,35 @@ static inline bool AssignerString(const char *value, HiSysEventParam **param)
CopyString((*param)->v.s, value, PARAM_STRING_VALUE_MAX_LEN);
}
/* Used by ASSIGNER macros */
static inline bool AssignerLongString(const char *value, HiSysEventParam **param)
{
if (value == NULL || value[0] == '\0' || strnlen(value,
PARAM_LONG_STRING_VALUE_MAX_LEN) == PARAM_LONG_STRING_VALUE_MAX_LEN) {
(*param)->v.s = NULL;
return false;
}
return InitString(&(*param)->v.s, PARAM_LONG_STRING_VALUE_MAX_LEN) &&
CopyString((*param)->v.s, value, PARAM_LONG_STRING_VALUE_MAX_LEN);
}
/* Used by ASSIGNER macros */
static inline bool AssignerAnonymizeString(const char *value, HiSysEventParam **param)
{
if (value == NULL || value[0] == '\0' || strnlen(value, PARAM_STRING_VALUE_MAX_LEN) == PARAM_STRING_VALUE_MAX_LEN) {
(*param)->v.s = NULL;
return false;
}
if (!InitString(&(*param)->v.s, PARAM_STRING_VALUE_MAX_LEN)) {
return false;
}
char *anonyStr = NULL;
Anonymize(value, &anonyStr);
bool status = CopyString((*param)->v.s, anonyStr, PARAM_STRING_VALUE_MAX_LEN);
AnonymizeFree(anonyStr);
return status;
}
/* Used by ASSIGNER macros */
static inline bool AssignerErrcode(int32_t value, HiSysEventParam **param)
{

View File

@ -45,7 +45,7 @@ STATS_ASSIGNER(Int32, DeviceOfflineTimes, deviceOfflineTimes)
STATS_ASSIGNER(Int32, LaneScoreOverTimes, laneScoreOverTimes)
STATS_ASSIGNER(Int32, ActivationRate, activationRate)
STATS_ASSIGNER(Int32, DetectionTimes, detectionTimes)
STATS_ASSIGNER(String, SuccessRateDetail, successRateDetail)
STATS_ASSIGNER(LongString, SuccessRateDetail, successRateDetail)
#define STATS_ASSIGNER_SIZE 12 // Size of g_statsAssigners
static HiSysEventParamAssigner g_statsAssigners[] = {

View File

@ -52,7 +52,7 @@ TRANS_ASSIGNER(Int32, CostTime, costTime)
TRANS_ASSIGNER(Int32, ChannelScore, channelScore)
TRANS_ASSIGNER(Int32, PeerChannelId, peerChannelId)
TRANS_ASSIGNER(Int32, BtFlow, btFlow)
TRANS_ASSIGNER(String, PeerNetworkId, peerNetworkId)
TRANS_ASSIGNER(AnonymizeString, PeerNetworkId, peerNetworkId)
TRANS_ASSIGNER(String, CallerPkg, callerPkg)
TRANS_ASSIGNER(String, CalleePkg, calleePkg)

View File

@ -89,7 +89,6 @@ if (defined(ohos_lite)) {
include_dirs += trans_common_inc
sources = [
"$dsoftbus_root_path/core/bus_center/utils/src/lnn_map.c",
"$dsoftbus_root_path/core/common/log/softbus_log_old.c",
"$dsoftbus_root_path/core/common/message_handler/message_handler.c",
"$dsoftbus_root_path/core/common/softbus_property/softbus_feature_config.c",
"$dsoftbus_root_path/core/common/utils/softbus_utils.c",

View File

@ -18,10 +18,10 @@
#include <string.h>
#include <securec.h>
#include "comm_log.h"
#include "common_list.h"
#include "softbus_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_log_old.h"
#include "softbus_hidumper_buscenter.h"
#include "softbus_hidumper_conn.h"
#include "softbus_hidumper_disc.h"
@ -33,7 +33,7 @@ static LIST_HEAD(g_hidumperhander_list);
void SoftBusDumpShowHelp(int fd)
{
if (fd < 0) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "fd is invalid.");
COMM_LOGE(COMM_DFX, "fd is invalid.");
return;
}
@ -62,7 +62,7 @@ void SoftBusDumpShowHelp(int fd)
void SoftBusDumpErrInfo(int fd, const char *argv)
{
if (fd < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "param is invalid.");
COMM_LOGE(COMM_DFX, "param is invalid.");
return;
}
SOFTBUS_DPRINTF(fd, "the command %s is invalid, please input again!\n", argv);
@ -71,7 +71,7 @@ void SoftBusDumpErrInfo(int fd, const char *argv)
void SoftBusDumpSubModuleHelp(int fd, char *moduleName, ListNode *varList)
{
if (fd < 0 || moduleName == NULL || varList == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "param is invalid.");
COMM_LOGE(COMM_DFX, "param is invalid.");
return;
}
SOFTBUS_DPRINTF(fd, "Usage: hidumper -s 4700 -a \" %s [Option] \n", moduleName);
@ -90,11 +90,11 @@ static SoftBusDumpVarNode *SoftBusCreateDumpVarNode(const char *varName, SoftBus
{
SoftBusDumpVarNode *varNode = (SoftBusDumpVarNode *)SoftBusCalloc(sizeof(SoftBusDumpVarNode));
if (varNode == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusCreateDumpVarNode malloc fail.");
COMM_LOGE(COMM_DFX, "SoftBusCreateDumpVarNode malloc fail.");
return NULL;
}
if (strcpy_s(varNode->varName, SOFTBUS_DUMP_VAR_NAME_LEN, varName) != EOK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusCreateDumpVarNode set varName %s fail.", varName);
COMM_LOGE(COMM_DFX, "SoftBusCreateDumpVarNode set varName %s fail.", varName);
SoftBusFree(varNode);
return NULL;
}
@ -107,13 +107,13 @@ static SoftBusDumpVarNode *SoftBusCreateDumpVarNode(const char *varName, SoftBus
int32_t SoftBusAddDumpVarToList(const char *dumpVar, SoftBusVarDumpCb cb, ListNode *varList)
{
if (dumpVar == NULL || strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL || varList == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegDiscDumpCb invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegDiscDumpCb invalid param");
return SOFTBUS_ERR;
}
SoftBusDumpVarNode *varNode = SoftBusCreateDumpVarNode(dumpVar, cb);
if (varNode == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegDiscDumpCb node create fail");
COMM_LOGE(COMM_DFX, "SoftBusRegDiscDumpCb node create fail");
return SOFTBUS_ERR;
}
varNode->dumpCallback = cb;
@ -140,17 +140,17 @@ static HandlerNode *CreateHiDumperHandlerNode(char *moduleName, char *helpInfo,
{
HandlerNode *handlerNode = (HandlerNode *)SoftBusCalloc(sizeof(HandlerNode));
if (handlerNode == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "CreateHiDumperHandlerNode malloc fail.");
COMM_LOGE(COMM_DFX, "CreateHiDumperHandlerNode malloc fail.");
return NULL;
}
if (strcpy_s(handlerNode->moduleName, SOFTBUS_MODULE_NAME_LEN, moduleName) != EOK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "CreateHiDumperHandlerNode get moduleName fail.");
COMM_LOGE(COMM_DFX, "CreateHiDumperHandlerNode get moduleName fail.");
SoftBusFree(handlerNode);
return NULL;
}
if (strcpy_s(handlerNode->helpInfo, SOFTBUS_MODULE_HELP_LEN, helpInfo) != EOK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "CreateHiDumperHandlerNode get helpInfo fail");
COMM_LOGE(COMM_DFX, "CreateHiDumperHandlerNode get helpInfo fail");
SoftBusFree(handlerNode);
return NULL;
}
@ -174,13 +174,13 @@ int32_t SoftBusRegHiDumperHandler(char *moduleName, char *helpInfo, DumpHandlerF
{
if (moduleName == NULL || strlen(moduleName) >= SOFTBUS_MODULE_NAME_LEN || helpInfo == NULL ||
strlen(helpInfo) >= SOFTBUS_MODULE_HELP_LEN || handler == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegHiDumperHandler invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegHiDumperHandler invalid param");
return SOFTBUS_ERR;
}
HandlerNode *handlerNode = CreateHiDumperHandlerNode(moduleName, helpInfo, handler);
if (handlerNode == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegHiDumperHandler node create fail");
COMM_LOGE(COMM_DFX, "SoftBusRegHiDumperHandler node create fail");
return SOFTBUS_ERR;
}
ListTailInsert(&g_hidumperhander_list, &handlerNode->node);
@ -190,7 +190,7 @@ int32_t SoftBusRegHiDumperHandler(char *moduleName, char *helpInfo, DumpHandlerF
int32_t SoftBusDumpDispatch(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusDumpProcess: param invalid ");
COMM_LOGE(COMM_DFX, "SoftBusDumpProcess: param invalid ");
return SOFTBUS_ERR;
}
@ -226,27 +226,27 @@ int32_t SoftBusDumpDispatch(int fd, int32_t argc, const char **argv)
int32_t SoftBusHiDumperModuleInit(void)
{
if (SoftBusDiscHiDumperInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init Disc HiDumper fail!");
COMM_LOGE(COMM_INIT, "init Disc HiDumper fail!");
return SOFTBUS_ERR;
}
if (SoftBusConnHiDumperInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init Conn HiDumper fail!");
COMM_LOGE(COMM_INIT, "init Conn HiDumper fail!");
return SOFTBUS_ERR;
}
if (SoftBusNStackHiDumperInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init NStack HiDumper fail!");
COMM_LOGE(COMM_INIT, "init NStack HiDumper fail!");
return SOFTBUS_ERR;
}
if (SoftBusHiDumperBusCenterInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init BusCenter HiDumper fail!");
COMM_LOGE(COMM_INIT, "init BusCenter HiDumper fail!");
return SOFTBUS_ERR;
}
if (SoftBusTransDumpHandlerInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init Trans HiDumper fail!");
COMM_LOGE(COMM_INIT, "init Trans HiDumper fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;

View File

@ -17,12 +17,12 @@
#include <stdio.h>
#include <string.h>
#include "comm_log.h"
#include "softbus_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_hidumper.h"
#include "softbus_hidumper_util.h"
#include "softbus_log_old.h"
#define SOFTBUS_CONTROL_ALARM_ORDER "control"
#define SOFTBUS_MANAGEMENT_ALARM_ORDER "management"
@ -119,7 +119,7 @@ int32_t SoftBusAlarmHiDumperInit(void)
int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_ALARM_MODULE_NAME, SOFTBUS_ALARM_MODULE_HELP,
&SoftBusAlarmDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "SoftBusRegAlarmDumpCb registe fail");
COMM_LOGE(COMM_DFX, "SoftBusRegAlarmDumpCb registe fail");
}
return ret;
}

View File

@ -16,7 +16,7 @@
#include <stdio.h>
#include <string.h>
#include "softbus_log_old.h"
#include "comm_log.h"
#include "softbus_def.h"
#include "softbus_error_code.h"
#include "softbus_hidumper.h"
@ -30,7 +30,7 @@ static LIST_HEAD(g_busCenter_var_list);
int32_t SoftBusRegBusCenterVarDump(char *dumpVar, SoftBusVarDumpCb cb)
{
if (dumpVar == NULL || strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegBusCenterVarDump invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegBusCenterVarDump invalid param");
return SOFTBUS_ERR;
}
return SoftBusAddDumpVarToList(dumpVar, cb, &g_busCenter_var_list);
@ -77,7 +77,7 @@ int32_t SoftBusHiDumperBusCenterInit(void)
int32_t ret = SoftBusRegHiDumperHandler(
SOFTBUS_BUSCENTER_MODULE_NAME, SOFTBUS_CONN_MODULE_HELP, &SoftBusBusCenterDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusBusCenterDumpHander regist fail");
COMM_LOGE(COMM_INIT, "SoftBusBusCenterDumpHander regist fail");
}
return ret;
}

View File

@ -14,10 +14,10 @@
*/
#include <stdio.h>
#include <string.h>
#include "comm_log.h"
#include "softbus_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_log_old.h"
#include "softbus_hidumper.h"
#include "softbus_hidumper_conn.h"
@ -29,7 +29,7 @@ static LIST_HEAD(g_conn_var_list);
int32_t SoftBusRegConnVarDump(const char *dumpVar, SoftBusVarDumpCb cb)
{
if (dumpVar == NULL || strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegConnVarDump invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegConnVarDump invalid param");
return SOFTBUS_ERR;
}
return SoftBusAddDumpVarToList(dumpVar, cb, &g_conn_var_list);
@ -75,7 +75,7 @@ int32_t SoftBusConnHiDumperInit(void)
int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_CONN_MODULE_NAME, SOFTBUS_CONN_MODULE_HELP,
&SoftBusConnDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusConnDumpHander regist fail");
COMM_LOGE(COMM_INIT, "SoftBusConnDumpHander regist fail");
}
return ret;
}

View File

@ -15,10 +15,10 @@
#include <stdio.h>
#include <string.h>
#include "comm_log.h"
#include "softbus_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_log_old.h"
#include "softbus_hidumper_disc.h"
#define SOFTBUS_DISC_MODULE_NAME "disc"
@ -29,7 +29,7 @@ static LIST_HEAD(g_disc_var_list);
int32_t SoftBusRegDiscVarDump(char *dumpVar, SoftBusVarDumpCb cb)
{
if (dumpVar == NULL || strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegDiscDumpCb invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegDiscDumpCb invalid param");
return SOFTBUS_ERR;
}
return SoftBusAddDumpVarToList(dumpVar, cb, &g_disc_var_list);
@ -38,7 +38,7 @@ int32_t SoftBusRegDiscVarDump(char *dumpVar, SoftBusVarDumpCb cb)
static int32_t SoftBusDiscDumpHander(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusDiscDumpHander invalid param");
COMM_LOGE(COMM_DFX, "SoftBusDiscDumpHander invalid param");
return SOFTBUS_ERR;
}
@ -77,7 +77,7 @@ int32_t SoftBusDiscHiDumperInit(void)
int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_DISC_MODULE_NAME, SOFTBUS_DISC_MODULE_HELP,
&SoftBusDiscDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegDiscDumpCb registe fail");
COMM_LOGE(COMM_INIT, "SoftBusRegDiscDumpCb registe fail");
}
return ret;
}

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#include <string.h>
#include "comm_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_hidumper_alarm.h"
#include "softbus_hidumper_stats.h"
#include "softbus_hidumper_util.h"
@ -24,7 +24,7 @@
int32_t SoftBusDumpProcess(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusDumpProcess: param invalid ");
COMM_LOGE(COMM_DFX, "SoftBusDumpProcess: param invalid ");
return SOFTBUS_ERR;
}
return SoftBusDumpDispatch(fd, argc, argv);
@ -33,17 +33,17 @@ int32_t SoftBusDumpProcess(int fd, int32_t argc, const char **argv)
int32_t SoftBusHiDumperInit(void)
{
if (SoftBusAlarmHiDumperInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init Alarm HiDumper fail!");
COMM_LOGE(COMM_INIT, "init Alarm HiDumper fail!");
return SOFTBUS_ERR;
}
if (SoftBusHidumperUtilInit() != SOFTBUS_OK || SoftBusHiDumperModuleInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusHiDumperInit fail!");
COMM_LOGE(COMM_INIT, "SoftBusHiDumperInit fail!");
return SOFTBUS_ERR;
}
if (SoftBusStatsHiDumperInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "init Stats HiDumper fail!");
COMM_LOGE(COMM_INIT, "init Stats HiDumper fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;

View File

@ -14,8 +14,8 @@
*/
#include <stdio.h>
#include <string.h>
#include "comm_log.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_hidumper.h"
#include "fillpinc.h"
#include "nstackx.h"
@ -38,8 +38,7 @@ void SoftBufNstackDumpFunc(void *softObj, const char *data, uint32_t len)
int fd = *(int *)softObj;
size_t dataLen = strnlen(data, SOFTBUF_NSTACK_DUMP_BUF_LEN);
if (dataLen == 0 || dataLen == SOFTBUF_NSTACK_DUMP_BUF_LEN || dataLen != len) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR,
"SoftBufNstackDumpFunc len error, data strlen %d, len %d.", dataLen, len);
COMM_LOGE(COMM_DFX, "SoftBufNstackDumpFunc len error, data strlen %d, len %d.", dataLen, len);
return;
}
SOFTBUS_DPRINTF(fd, "%s", data);
@ -48,12 +47,12 @@ void SoftBufNstackDumpFunc(void *softObj, const char *data, uint32_t len)
static int32_t SoftBusNStackDstreamDumpHander(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackDstreamDumpHander invalid input");
COMM_LOGE(COMM_DFX, "SoftBusNStackDstreamDumpHander invalid input");
return SOFTBUS_ERR;
}
#ifdef FILLP_ENHANCED
if (FtDfxHiDumper((uint32_t)argc, argv, &fd, SoftBufNstackDumpFunc) != 0) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "call FtDfxHiDumper failed!");
COMM_LOGE(COMM_DFX, "call FtDfxHiDumper failed!");
return SOFTBUS_ERR;
}
#endif
@ -62,12 +61,12 @@ static int32_t SoftBusNStackDstreamDumpHander(int fd, int32_t argc, const char *
static int32_t SoftBusNStackDfileDumpHander(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackDfileDumpHander invalid input");
COMM_LOGE(COMM_DFX, "SoftBusNStackDfileDumpHander invalid input");
return SOFTBUS_ERR;
}
#ifdef FILLP_ENHANCED
if (NSTACKX_DFileDump((uint32_t)argc, argv, &fd, SoftBufNstackDumpFunc) != 0) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "call NSTACKX_DFileDump failed!");
COMM_LOGE(COMM_DFX, "call NSTACKX_DFileDump failed!");
return SOFTBUS_ERR;
}
#endif
@ -76,12 +75,12 @@ static int32_t SoftBusNStackDfileDumpHander(int fd, int32_t argc, const char **a
static int32_t SoftBusNStackDumpDfinderHander(int fd, int32_t argc, const char **argv)
{
if (fd < 0 || argc < 0 || argv == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "NSTACKX_DFinderDump invalid input!");
COMM_LOGE(COMM_DFX, "NSTACKX_DFinderDump invalid input!");
return SOFTBUS_ERR;
}
#ifdef FILLP_ENHANCED
if (NSTACKX_DFinderDump(argv, (uint32_t)argc, &fd, SoftBufNstackDumpFunc) != 0) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "call NSTACKX_DFinderDump failed!");
COMM_LOGE(COMM_DFX, "call NSTACKX_DFinderDump failed!");
return SOFTBUS_ERR;
}
#endif
@ -102,28 +101,28 @@ int32_t SoftBusNStackHiDumperInit(void)
int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_DSTREAM_MODULE_NAME, SOFTBUS_DSTREAM_MODULE_HELP,
&SoftBusNStackDstreamDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackHiDumperInit regist dstream handler fail");
COMM_LOGE(COMM_INIT, "SoftBusNStackHiDumperInit regist dstream handler fail");
return ret;
}
ret = SoftBusRegHiDumperHandler(SOFTBUS_DFILE_MODULE_NAME, SOFTBUS_DFILE_MODULE_HELP,
&SoftBusNStackDfileDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackHiDumperInit regist dstream handler fail");
COMM_LOGE(COMM_INIT, "SoftBusNStackHiDumperInit regist dstream handler fail");
return ret;
}
ret = SoftBusRegHiDumperHandler(SOFTBUS_DFINDLER_MODULE_NAME, SOFTBUS_DFINDLER_MODULE_HELP,
&SoftBusNStackDumpDfinderHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackHiDumperInit regist dstream handler fail");
COMM_LOGE(COMM_INIT, "SoftBusNStackHiDumperInit regist dstream handler fail");
return ret;
}
ret = SoftBusRegHiDumperHandler(SOFTBUS_DMSG_MODULE_NAME, SOFTBUS_DMSG_MODULE_HELP,
&SoftBusNStackDmsgDumpHander);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusNStackHiDumperInit regist dstream handler fail");
COMM_LOGE(COMM_INIT, "SoftBusNStackHiDumperInit regist dstream handler fail");
return ret;
}
return ret;

View File

@ -17,10 +17,10 @@
#include <stdio.h>
#include <string.h>
#include "comm_log.h"
#include "securec.h"
#include "softbus_adapter_mem.h"
#include "softbus_error_code.h"
#include "softbus_log_old.h"
#include "softbus_utils.h"
#define MAX_ID_LEN (10)
@ -48,7 +48,7 @@ static LIST_HEAD(g_trans_var_list);
int32_t SoftBusRegTransVarDump(const char *dumpVar, SoftBusVarDumpCb cb)
{
if (dumpVar == NULL || strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegTransVarDump invalid param");
COMM_LOGE(COMM_DFX, "SoftBusRegTransVarDump invalid param");
return SOFTBUS_ERR;
}
return SoftBusAddDumpVarToList(dumpVar, cb, &g_trans_var_list);
@ -58,7 +58,7 @@ void SoftBusTransDumpRegisterSession(int fd, const char* pkgName, const char* se
int uid, int pid)
{
if (fd < 0 || pkgName == NULL || sessionName == NULL || uid < 0 || pid < 0) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "param is invalid");
COMM_LOGE(COMM_DFX, "param is invalid");
return;
}
@ -67,7 +67,7 @@ void SoftBusTransDumpRegisterSession(int fd, const char* pkgName, const char* se
char uidStr[MAX_ID_LEN] = {0};
char pidStr[MAX_ID_LEN] = {0};
if (sprintf_s(uidArr, MAX_ID_LEN, "%d", uid) < 0 || sprintf_s(pidArr, MAX_ID_LEN, "%d", pid) < 0) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "set uidArr or pidArr failed");
COMM_LOGE(COMM_DFX, "set uidArr or pidArr failed");
return;
}
@ -82,7 +82,7 @@ void SoftBusTransDumpRegisterSession(int fd, const char* pkgName, const char* se
void SoftBusTransDumpRunningSession(int fd, TransDumpLaneLinkType type, AppInfo* appInfo)
{
if (fd < 0 || type < DUMPER_LANE_BR || type >= DUMPER_LANE_LINK_TYPE_BUTT || appInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "param is invalid");
COMM_LOGE(COMM_DFX, "param is invalid");
return;
}
@ -105,7 +105,7 @@ void SoftBusTransDumpRunningSession(int fd, TransDumpLaneLinkType type, AppInfo*
static int SoftBusTransDumpHandler(int fd, int argc, const char **argv)
{
if (fd < 0 || argv == NULL || argc < 0) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "param is invalid ");
COMM_LOGE(COMM_DFX, "param is invalid ");
return SOFTBUS_ERR;
}
if (argc == 0 || ((argc == 1) && (strcmp(argv[0], "-h") == 0)) || (argc == 1 && strcmp(argv[0], "-l") == 0)) {
@ -138,7 +138,7 @@ int32_t SoftBusTransDumpHandlerInit(void)
int32_t ret = SoftBusRegHiDumperHandler((char*)MODULE_NAME_TRAN, (char*)SOFTBUS_TRANS_MODULE_HELP,
&SoftBusTransDumpHandler);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "SoftBusTransDumpHander regist fail");
COMM_LOGE(COMM_INIT, "SoftBusTransDumpHander regist fail");
}
return ret;
}

View File

@ -44,11 +44,11 @@ void SoftBusTransDumpRunningSession(int fd, TransDumpLaneLinkType type, AppInfo*
return;
}
int32_t SoftBusTransDumpHanderInit()
int32_t SoftBusTransDumpHanderInit(void)
{
return SOFTBUS_OK;
}
void SoftBusHiDumperTransDeInit()
void SoftBusHiDumperTransDeInit(void)
{
}

View File

@ -29,7 +29,6 @@
#include "softbus_def.h"
#include "softbus_error_code.h"
#include "softbus_event.h"
#include "softbus_log_old.h"
#include "stats_event.h"
#include "hisysevent_manager_c.h"
@ -206,11 +205,11 @@ static void GetLocalTime(char* time, uint64_t timestamp)
(void)strftime(time, SOFTBUS_ALARM_TIME_LEN, "%Y-%m-%d %H:%M:%S", tmInfo);
}
static void ConnStatsLinkType(int32_t linkType, bool success)
static void ConnStatsLinkType(int32_t linkTypePara, bool success)
{
int32_t linkType = linkTypePara;
if (linkType < CONNECT_TCP || linkType >= CONNECT_TYPE_MAX) {
COMM_LOGE(COMM_DFX, "linkType:%d is unexpected.", linkType);
return;
linkType = SOFTBUS_ZERO;
}
g_connStatsInfo.linkTypeTotal[linkType]++;
if (success) {
@ -254,11 +253,11 @@ static void OnCompleteConn(int32_t reason, int32_t total)
g_isConnQueryEnd = true;
}
static void LnnStatsAuthLinkType(int32_t authLinkType, bool success)
static void LnnStatsAuthLinkType(int32_t authLinkTypePara, bool success)
{
int32_t authLinkType = authLinkTypePara;
if (authLinkType < AUTH_LINK_TYPE_WIFI || authLinkType >= AUTH_LINK_TYPE_MAX) {
COMM_LOGE(COMM_DFX, "authLinkType:%d is unexpected.", authLinkType);
return;
authLinkType = SOFTBUS_ZERO;
}
g_lnnStatsInfo.authLinkTypeTotal[authLinkType]++;
if (success) {
@ -324,23 +323,11 @@ static void OnCompleteLnn(int32_t reason, int32_t total)
g_isLnnQueryEnd = true;
}
static void TransStatsSuccessDetail(int32_t scene, int32_t stage, int32_t stageRes, const char *socketName,
int32_t linkType)
static void TransStatsSuccessDetail(bool success, const char *socketName, int32_t linkTypePara)
{
if (stageRes == EVENT_STAGE_RESULT_OK &&
(scene != EVENT_SCENE_OPEN_CHANNEL || stage != EVENT_STAGE_OPEN_CHANNEL_END)) {
return;
}
if (stageRes == EVENT_STAGE_RESULT_FAILED && scene != EVENT_SCENE_OPEN_CHANNEL) {
return;
}
if (socketName == NULL || strlen(socketName) == 0) {
COMM_LOGE(COMM_DFX, "socketName is NULL or length is 0");
return;
}
int linkType = linkTypePara;
if (linkType < CONNECT_TCP || linkType >= CONNECT_TYPE_MAX) {
COMM_LOGE(COMM_DFX, "linkType:%d is unexpected.", linkType);
return;
linkType = SOFTBUS_ZERO;
}
char keyStr[SESSION_NAME_SIZE_MAX + 3] = {0};
@ -359,27 +346,28 @@ static void TransStatsSuccessDetail(int32_t scene, int32_t stage, int32_t stageR
TransStatsSuccessRateDetail newResult;
newResult.successTotal = 0;
newResult.total = 1;
if (stageRes == EVENT_STAGE_RESULT_OK) {
if (success) {
newResult.successTotal = 1;
}
if (LnnMapSet(&g_transStatsInfo.sessionNameLinkTypeMap, keyStr, (const void *)&newResult,
sizeof(TransStatsSuccessRateDetail)) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "insert socketName:%s fail", socketName);
COMM_LOGE(COMM_DFX, "insert keyStr:%s fail", keyStr);
}
TransMapUnlock();
return;
}
data->total++;
if (stageRes == EVENT_STAGE_RESULT_OK) {
if (success) {
data->successTotal++;
}
TransMapUnlock();
}
static void TransStats(int32_t scene, int32_t stage, int32_t stageRes)
static void TransStats(int32_t scene, int32_t stage, int32_t stageRes, const char *socketName, int32_t linkType)
{
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
&& stageRes == EVENT_STAGE_RESULT_OK) {
TransStatsSuccessDetail(true, socketName, linkType);
g_transStatsInfo.openSessionSuccessTotal++;
g_transStatsInfo.currentParaSessionNum++;
return;
@ -387,6 +375,7 @@ static void TransStats(int32_t scene, int32_t stage, int32_t stageRes)
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
&& stageRes == EVENT_STAGE_RESULT_FAILED) {
TransStatsSuccessDetail(false, socketName, linkType);
g_transStatsInfo.openSessionFailTotal++;
return;
}
@ -428,10 +417,9 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
continue;
}
TransStats(scene, stage, stageRes);
char* socketName = GetStringValueByRecord(&srcRecord[i], SOCKET_KEY_NAME);
int32_t linkType = GetInt32ValueByRecord(&srcRecord[i], LINK_TYPE_NAME);
TransStatsSuccessDetail(scene, stage, stageRes, socketName, linkType);
TransStats(scene, stage, stageRes, socketName, linkType);
cJSON_free(socketName);
if (scene == EVENT_SCENE_CLOSE_CHANNEL_ACTIVE && stage == EVENT_STAGE_CLOSE_CHANNEL &&
stageRes == EVENT_STAGE_RESULT_OK && g_transStatsInfo.currentParaSessionNum > 0) {
@ -442,7 +430,7 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
maxParaSessionNum : g_transStatsInfo.currentParaSessionNum;
int32_t timeConsuming = GetInt32ValueByRecord(&srcRecord[i], TIME_CONSUMING_NAME);
if (timeConsuming != SOFTBUS_ERR) {
if (timeConsuming != SOFTBUS_ERR && stageRes == EVENT_STAGE_RESULT_OK) {
g_transStatsInfo.delayTimeTotal += timeConsuming;
g_transStatsInfo.delayNum++;
}
@ -594,7 +582,7 @@ void FillConnSuccessRateDetail(cJSON *connObj)
COMM_LOGE(COMM_DFX, "%s json is add to root fail", MODULE_NAME_CONN);
return;
}
for (int i = CONNECT_TCP; i < CONNECT_TYPE_MAX; i++) {
for (int i = SOFTBUS_ZERO; i < CONNECT_TYPE_MAX; i++) {
float rate = 0;
if (g_connStatsInfo.linkTypeTotal[i] > 0) {
rate = 1.0 * g_connStatsInfo.linkTypeSuccessTotal[i] / g_connStatsInfo.linkTypeTotal[i] * RATE_HUNDRED;
@ -616,7 +604,7 @@ void FillAuthSuccessRateDetail(cJSON *authObj)
COMM_LOGE(COMM_DFX, "%s json is add to root fail", MODULE_NAME_AUTH);
return;
}
for (int i = AUTH_LINK_TYPE_WIFI; i < AUTH_LINK_TYPE_MAX; i++) {
for (int i = SOFTBUS_ZERO; i < AUTH_LINK_TYPE_MAX; i++) {
float rate = 0;
if (g_lnnStatsInfo.authLinkTypeTotal[i] > 0) {
rate =
@ -678,11 +666,11 @@ static void SoftBusProcessStatsQueryData(SoftBusStatsResult* result)
result->laneScoreOverTimes = g_transStatsInfo.laneScoreOverTimes;
result->detectionTimes = g_transStatsInfo.detectionTimes;
if (memset_s(&g_connStatsInfo, sizeof(g_connStatsInfo), 0, sizeof(g_connStatsInfo)) != SOFTBUS_OK) {
if (memset_s(&g_connStatsInfo, sizeof(g_connStatsInfo), 0, sizeof(g_connStatsInfo)) != EOK) {
COMM_LOGE(COMM_DFX, "memset g_connStatsInfo fail!");
return;
}
if (memset_s(&g_lnnStatsInfo, sizeof(g_lnnStatsInfo), 0, sizeof(g_lnnStatsInfo)) != SOFTBUS_OK) {
if (memset_s(&g_lnnStatsInfo, sizeof(g_lnnStatsInfo), 0, sizeof(g_lnnStatsInfo)) != EOK) {
COMM_LOGE(COMM_DFX, "memset g_lnnStatsInfo fail!");
return;
}
@ -691,7 +679,7 @@ static void SoftBusProcessStatsQueryData(SoftBusStatsResult* result)
}
LnnMapDelete(&g_transStatsInfo.sessionNameLinkTypeMap);
TransMapUnlock();
if (memset_s(&g_transStatsInfo, sizeof(g_transStatsInfo), 0, sizeof(g_transStatsInfo)) != SOFTBUS_OK) {
if (memset_s(&g_transStatsInfo, sizeof(g_transStatsInfo), 0, sizeof(g_transStatsInfo)) != EOK) {
COMM_LOGE(COMM_DFX, "memset g_transStatsInfo fail!");
return;
}
@ -767,8 +755,9 @@ int32_t SoftBusQueryAlarmInfo(int time, int type, SoftBusAlarmEvtResult* result)
}
g_alarmEvtResult.recordSize = 0;
if (memset_s(g_alarmEvtResult.records, sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT, 0,
sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT) != SOFTBUS_OK) {
sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT) != EOK) {
COMM_LOGE(COMM_DFX, "memset g_alarmEvtResult records fail!");
(void)SoftBusMutexUnlock(&g_alarmQueryLock);
return SOFTBUS_ERR;
}
SoftBusEventQueryInfo(time, &g_queryAlarmParam[type]);
@ -825,10 +814,10 @@ static int32_t InitDumperUtilMutexLock(void)
static void UpdateSysEventQueryParam(HiSysEventQueryParam* param, char* eventName)
{
HiSysEventQueryRule* queryRule = &param->queryRules[SOFTBUS_ZERO];
if (strcpy_s(queryRule->domain, MAX_LENGTH_OF_EVENT_DOMAIN, SOFTBUS_EVENT_DOMAIN) != SOFTBUS_OK) {
if (strcpy_s(queryRule->domain, MAX_LENGTH_OF_EVENT_DOMAIN, SOFTBUS_EVENT_DOMAIN) != EOK) {
COMM_LOGE(COMM_DFX, "UpdateSysEventQueryParam copy domain fail");
}
if (strcpy_s(queryRule->eventList[SOFTBUS_ZERO], MAX_LENGTH_OF_EVENT_NAME, eventName) != SOFTBUS_OK) {
if (strcpy_s(queryRule->eventList[SOFTBUS_ZERO], MAX_LENGTH_OF_EVENT_NAME, eventName) != EOK) {
COMM_LOGE(COMM_DFX, "UpdateSysEventQueryParam copy domain fail");
}
queryRule->eventListSize = SOFTBUS_ONE;
@ -836,7 +825,7 @@ static void UpdateSysEventQueryParam(HiSysEventQueryParam* param, char* eventNam
param->eventSize = SOFTBUS_ONE;
}
static void InitSoftBusQueryEventParam()
static void InitSoftBusQueryEventParam(void)
{
HiSysEventQueryParam* connParam = &g_queryStatsParam[SOFTBUS_CONNECTION_STATS_TYPE];
UpdateSysEventQueryParam(connParam, CONN_EVENT_NAME);
@ -963,7 +952,7 @@ static int32_t CreateAndQueryMsgDelay(SoftBusLooper* looper, HandleMessageFunc c
static void QueryStatisticInfoPeriod(SoftBusMessage* msg)
{
QueryStatisticInfo(msg);
CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_DEFAULT), QueryStatisticInfoPeriod, DAY_TIME);
CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_HANDLE_FILE), QueryStatisticInfoPeriod, DAY_TIME);
}
int32_t SoftBusHidumperUtilInit(void)
@ -983,7 +972,7 @@ int32_t SoftBusHidumperUtilInit(void)
}
InitSoftBusQueryEventParam();
g_isDumperInit = true;
if (CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_DEFAULT), QueryStatisticInfoPeriod, DAY_TIME) != SOFTBUS_OK) {
if (CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_HANDLE_FILE), QueryStatisticInfoPeriod, DAY_TIME) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "CreateAndQueryMsgDelay fail");
}
return SOFTBUS_OK;
@ -1002,6 +991,7 @@ void SoftBusHidumperUtilDeInit(void)
LnnMapDelete(&g_transStatsInfo.sessionNameLinkTypeMap);
TransMapUnlock();
SoftBusMutexDestroy(&g_transMapLock);
g_isTransMapInit = false;
SoftBusMutexDestroy(&g_statsQueryLock);
SoftBusMutexDestroy(&g_alarmQueryLock);
SoftBusMutexDestroy(&g_connOnQueryLock);

View File

@ -15,7 +15,6 @@
#include "softbus_hidumper_util.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
int32_t SoftBusQueryStatsInfo(int time, SoftBusStatsResult* result)
{

View File

@ -24,7 +24,7 @@
#include "softbus_hisysevt_common.h"
#include "softbus_utils.h"
#define MODULE_NAME_MAX_LEN 33
#define MODULE_NAME_MAX_LEN 65
#define FIRST_DISC_DURATION_PARAM_NUM 10
#define SOFT_BUS_VERSION_KEY "SOFT_BUS_VERSION"

View File

@ -14,10 +14,10 @@
*/
#include <securec.h>
#include "comm_log.h"
#include "fillpinc.h"
#include "nstackx.h"
#include "nstackx_dfile.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -98,13 +98,13 @@ static int32_t CopyEventParamVal(SoftBusEvtParamType type, void *dst, const void
break;
case SOFTBUS_EVT_PARAMTYPE_STRING:
if (strcpy_s(dst, SOFTBUS_HISYSEVT_PARAM_LEN, src) != EOK) {
LOG_ERR("softbus param string max %d, nstack param string %s",
COMM_LOGE(COMM_DFX, "softbus param string max %d, nstack param string %s",
SOFTBUS_HISYSEVT_PARAM_LEN, (char *)src);
return SOFTBUS_ERR;
}
break;
default:
LOG_ERR("unknow param type");
COMM_LOGE(COMM_DFX, "unknow param type");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -113,13 +113,13 @@ static int32_t CopyEventParamVal(SoftBusEvtParamType type, void *dst, const void
static int32_t NstackEventParaToSoftBusEventPara(SoftBusEvtParam *dst, const NstackDfxEvtParam *src)
{
if (src->type >= SOFTBUS_EVT_PARAMTYPE_BUTT) {
LOG_ERR("softbus paramType max %d, nstack paramType %d",
COMM_LOGE(COMM_DFX, "softbus paramType max %d, nstack paramType %d",
SOFTBUS_EVT_PARAMTYPE_BUTT, src->type);
return SOFTBUS_ERR;
}
dst->paramType = (SoftBusEvtParamType)src->type;
if (strcpy_s(dst->paramName, SOFTBUS_HISYSEVT_NAME_LEN, src->paramName) != EOK) {
LOG_ERR("softbus paramName max size %d, nstack paramName name %s",
COMM_LOGE(COMM_DFX, "softbus paramName max size %d, nstack paramName name %s",
SOFTBUS_HISYSEVT_NAME_LEN, src->paramName);
return SOFTBUS_ERR;
}
@ -132,16 +132,16 @@ static int32_t NstackEventParaToSoftBusEventPara(SoftBusEvtParam *dst, const Nst
static int32_t NstackDfxEvtToSoftBusReportMsg(SoftBusEvtReportMsg *msg, const NstackDfxEvent *info)
{
if (strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, info->eventName) != EOK) {
LOG_ERR("eventName mismatch, nstack event name %s", info->eventName);
COMM_LOGE(COMM_DFX, "eventName mismatch, nstack event name %s", info->eventName);
return SOFTBUS_ERR;
}
if (info->type >= SOFTBUS_EVT_TYPE_BUTT) {
LOG_ERR("eventType mismatch, nstack event type %d", info->type);
COMM_LOGE(COMM_DFX, "eventType mismatch, nstack event type %d", info->type);
return SOFTBUS_ERR;
}
msg->evtType = (SoftBusEvtType)(info->type);
if (info->paramNum != 0 && info->paramArray == NULL) {
LOG_ERR("param mismatch, nstack paramNum %u paramArray is NULL", info->paramNum);
COMM_LOGE(COMM_DFX, "param mismatch, nstack paramNum %u paramArray is NULL", info->paramNum);
return SOFTBUS_ERR;
}
msg->paramNum = info->paramNum;
@ -150,7 +150,7 @@ static int32_t NstackDfxEvtToSoftBusReportMsg(SoftBusEvtReportMsg *msg, const Ns
}
msg->paramArray = (SoftBusEvtParam *)SoftBusCalloc(msg->paramNum * sizeof(SoftBusEvtParam));
if (msg->paramArray == NULL) {
LOG_ERR("SoftBusCalloc paramArray failed! paramNum %u", info->paramNum);
COMM_LOGE(COMM_DFX, "SoftBusCalloc paramArray failed! paramNum %u", info->paramNum);
return SOFTBUS_ERR;
}
for (uint8_t i = 0; i < info->paramNum; i++) {
@ -165,7 +165,7 @@ static void NstackHiEventCb(void *softObj, const NstackDfxEvent *info)
{
(void)softObj;
if (info == NULL) {
LOG_ERR("info is NULL");
COMM_LOGE(COMM_DFX, "info is NULL");
return;
}
SoftBusEvtReportMsg msg;
@ -174,7 +174,7 @@ static void NstackHiEventCb(void *softObj, const NstackDfxEvent *info)
if (msg.paramArray != NULL) {
SoftBusFree(msg.paramArray);
}
LOG_ERR("change NstackDfxEvent to SoftBusEvtReportMsg failed!");
COMM_LOGE(COMM_DFX, "change NstackDfxEvent to SoftBusEvtReportMsg failed!");
return;
}
(void)SoftbusWriteHisEvt(&msg);
@ -186,12 +186,12 @@ static void NstackHiEventCb(void *softObj, const NstackDfxEvent *info)
void DstreamHiEventCb(void *softObj, const FillpDfxEvent *info)
{
if (softObj == NULL || info == NULL) {
LOG_ERR("param is NULL");
COMM_LOGE(COMM_DFX, "param is NULL");
return;
}
NstackDfxEvent nstackInfo;
if (memcpy_s(&nstackInfo, sizeof(NstackDfxEvent), info, sizeof(FillpDfxEvent)) != EOK) {
LOG_ERR("change FillpDfxEvent to NstackDfxEvent failed!");
COMM_LOGE(COMM_DFX, "change FillpDfxEvent to NstackDfxEvent failed!");
return;
}
NstackHiEventCb(softObj, &nstackInfo);
@ -201,7 +201,7 @@ static void DFileHiEventCb(void *softObj, const DFileEvent *info)
{
NstackDfxEvent nstackInfo;
if (memcpy_s(&nstackInfo, sizeof(NstackDfxEvent), info, sizeof(DFileEvent)) != EOK) {
LOG_ERR("change DFileEvent to NstackDfxEvent failed!");
COMM_LOGE(COMM_DFX, "change DFileEvent to NstackDfxEvent failed!");
return;
}
NstackHiEventCb(softObj, &nstackInfo);
@ -212,7 +212,7 @@ static void DFinderHiEventCb(void *softObj, const DFinderEvent *info)
NstackDfxEvent nstackInfo;
if (memcpy_s(nstackInfo.eventName, sizeof(nstackInfo.eventName),
info->eventName, sizeof(info->eventName)) != EOK) {
LOG_ERR("change DFinderEvent to NstackDfxEvent failed!");
COMM_LOGE(COMM_DFX, "change DFinderEvent to NstackDfxEvent failed!");
return;
}
@ -227,7 +227,7 @@ void NstackInitHiEvent(void)
{
NSTACKX_DFileSetEventFunc(NULL, DFileHiEventCb);
if (NSTACKX_DFinderSetEventFunc(NULL, DFinderHiEventCb) != 0) {
LOG_ERR("NSTACKX_DFinderSetEventFunc failed!");
COMM_LOGE(COMM_DFX, "NSTACKX_DFinderSetEventFunc failed!");
}
}
#endif /* FILLP_ENHANCED */

View File

@ -40,11 +40,11 @@ static const SoftBusLogLabel AUTH_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{ AUTH_TEST, DOMAIN_ID_TEST, "AuthTest" },
};
#define AUTH_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_ERROR, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_WARN, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_INFO, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_DEBUG, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_FATAL, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_ERROR, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_WARN, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_INFO, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_DEBUG, AUTH_LABELS[label], ##__VA_ARGS__)
#define AUTH_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, AUTH_LOGW, label, fmt, ##__VA_ARGS__)

View File

@ -48,11 +48,11 @@ static const SoftBusLogLabel COMM_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{ COMM_TEST, DOMAIN_ID_TEST, "CommTest" },
};
#define COMM_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_ERROR, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_WARN, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_INFO, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_DEBUG, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_FATAL, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_ERROR, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_WARN, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_INFO, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_DEBUG, COMM_LABELS[label], ##__VA_ARGS__)
#define COMM_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, COMM_LOGW, label, fmt, ##__VA_ARGS__)

View File

@ -48,11 +48,11 @@ static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{CONN_TEST, DOMAIN_ID_TEST, "ConnTest"},
};
#define CONN_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_ERROR, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_WARN, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_INFO, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_DEBUG, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_FATAL, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGE(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_ERROR, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGW(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_WARN, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_INFO, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_LOG_DEBUG, CONN_LABELS[label], ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGW, label, fmt, ##__VA_ARGS__)

Some files were not shown because too many files have changed in this diff Show More