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

Signed-off-by: ym <yuanmeng36@huawei.com>
This commit is contained in:
ym 2023-11-25 02:23:40 +00:00 committed by Gitee
commit a3f5a8d2a3
312 changed files with 12475 additions and 5769 deletions

View File

@ -95,23 +95,18 @@ if (defined(ohos_lite)) {
]
}
deps = [
"$hilog_lite_deps_path",
"//base/security/huks/interfaces/inner_api/huks_lite:huks_3.0_sdk",
]
deps = [ "$hilog_lite_deps_path" ]
if (dsoftbus_feature_encrypt == 0) {
sources += [
"$softbus_adapter_common/mbedtls/softbus_adapter_crypto.c",
"$softbus_adapter_common/mbedtls/softbus_aes_encrypt_virtual.c",
"$softbus_adapter_common/mbedtls/softbus_rsa_encrypt_virtual.c",
]
deps += [ "//third_party/mbedtls" ]
} else if (dsoftbus_feature_encrypt == 1) {
sources += [
"$softbus_adapter_common/openssl/softbus_adapter_crypto.c",
"$softbus_adapter_common/openssl/softbus_aes_encrypt.c",
"$softbus_adapter_common/openssl/softbus_rsa_encrypt.c",
]
deps += [ "//third_party/openssl/ohos_lite:openssl_shared" ]
}
@ -145,7 +140,6 @@ if (defined(ohos_lite)) {
]
deps = [
"$hilog_lite_deps_path",
"//base/security/huks/interfaces/inner_api/huks_lite:huks_3.0_sdk",
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//third_party/bounds_checking_function:libsec_shared",
]
@ -154,14 +148,12 @@ if (defined(ohos_lite)) {
sources += [
"$softbus_adapter_common/mbedtls/softbus_adapter_crypto.c",
"$softbus_adapter_common/mbedtls/softbus_aes_encrypt_virtual.c",
"$softbus_adapter_common/mbedtls/softbus_rsa_encrypt_virtual.c",
]
deps += [ "//third_party/mbedtls" ]
} else if (dsoftbus_feature_encrypt == 1) {
sources += [
"$softbus_adapter_common/openssl/softbus_adapter_crypto.c",
"$softbus_adapter_common/openssl/softbus_aes_encrypt.c",
"$softbus_adapter_common/openssl/softbus_rsa_encrypt.c",
]
deps += [ "//third_party/openssl/ohos_lite:openssl_shared" ]
}
@ -231,7 +223,7 @@ if (defined(ohos_lite)) {
]
}
external_deps = [ "huks:libhukssdk" ]
external_deps = []
if (enhanced_range && defined(global_parts_info.msdp_algorithm)) {
include_dirs += [ "//base/msdp/algorithm/ble_range/include" ]
sources += [ "$dsoftbus_root_path/dsoftbus_enhance/adapter/common/range/softbus_adapter_range.c" ]
@ -244,14 +236,12 @@ if (defined(ohos_lite)) {
sources += [
"$softbus_adapter_common/mbedtls/softbus_adapter_crypto.c",
"$softbus_adapter_common/mbedtls/softbus_aes_encrypt_virtual.c",
"$softbus_adapter_common/mbedtls/softbus_rsa_encrypt_virtual.c",
]
public_deps += [ "//third_party/mbedtls" ]
} else if (dsoftbus_feature_encrypt == 1) {
sources += [
"$softbus_adapter_common/openssl/softbus_adapter_crypto.c",
"$softbus_adapter_common/openssl/softbus_aes_encrypt.c",
"$softbus_adapter_common/openssl/softbus_rsa_encrypt.c",
]
public_deps += [ "//third_party/openssl:libcrypto_shared" ]
}

View File

@ -28,6 +28,7 @@ extern "C" {
#define AES_SESSION_KEY_LENGTH 16
#define AES_IV_LENGTH 16
#define AES_GCM_TAG_LEN 16
#define RANDOM_LENGTH 8
#define TAG_LEN 16
#define GCM_OVERHEAD_LEN TAG_LEN

View File

@ -754,9 +754,31 @@ int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data)
return ret;
}
static int OhosBleStartAdvEx(int *advId, const SoftBusBleAdvParams *param, const SoftBusBleAdvData *data)
{
int btAdvId = -1;
BleAdvParams dstParam;
StartAdvRawData advData;
ConvertAdvParam(param, &dstParam);
ConvertAdvData(data, &advData);
int ret = BleStartAdvEx(&btAdvId, advData, dstParam);
if (ret != OHOS_BT_STATUS_SUCCESS) {
CLOGE("BleStartAdvEx, bt-advId: %d, ret: %d", btAdvId, ret);
return SOFTBUS_ERR;
}
*advId = btAdvId;
return SOFTBUS_OK;
}
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param)
{
if (param == NULL) {
return SoftBusStartAdvEx(advId, param, OhosBleStartAdvEx);
}
int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
int (*startAdvEx)(int *, const SoftBusBleAdvParams *, const SoftBusBleAdvData *))
{
if (param == NULL || startAdvEx == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != 0) {
@ -782,19 +804,12 @@ int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param)
return SOFTBUS_ERR;
}
}
int btAdvId = -1;
BleAdvParams dstParam;
StartAdvRawData advData;
ConvertAdvParam(param, &dstParam);
ConvertAdvData(&g_advChannel[advId].advData, &advData);
int ret = BleStartAdvEx(&btAdvId, advData, dstParam);
g_advChannel[advId].advId = btAdvId;
CLOGI("BleStartAdvEx, inner-advId: %d, bt-advId: %d, "
"ret: %d", advId, btAdvId, ret);
if (ret != OHOS_BT_STATUS_SUCCESS) {
int ret = startAdvEx(&g_advChannel[advId].advId, param, &g_advChannel[advId].advData);
CLOGI("inner-advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
if (ret != SOFTBUS_OK) {
g_advChannel[advId].advCallback->AdvEnableCallback(advId, SOFTBUS_BT_STATUS_FAIL);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
return ret;
}
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;

View File

@ -0,0 +1,39 @@
/*
* 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_gatt.h
* @brief ble stack adapter
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BLE_GATT_H
#define SOFTBUS_BLE_GATT_H
#include "softbus_broadcast_adapter.h"
#ifdef __cplusplus
extern "C"{
#endif
void softbus_ble_adapter_init(void);
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BLE_GATT_H */

View File

@ -0,0 +1,20 @@
/*
* 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_gatt.h"
void softbus_ble_adapter_init(void)
{
}

View File

@ -0,0 +1,104 @@
/*
* 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_broadcast_adapter_interface.h
* @brief Different broadcast protocol stacks adapt layer interfaces
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BROADCAST_ADAPTER_INTERFACE_H
#define SOFTBUS_BROADCAST_ADAPTER_INTERFACE_H
#include "softbus_broadcast_adapter_type.h"
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Defines the broadcast callback function.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
void (*OnStartBroadcastingCallback)(int32_t advId, int32_t status);
void (*OnStopBroadcastingCallback)(int32_t advId, int32_t status);
void (*OnUpdateBroadcastingCallback)(int32_t advId, int32_t status);
void (*OnSetBroadcastingCallback)(int32_t advId, int32_t status);
} SoftbusBroadcastCallback;
/**
* @brief Defines the broadcast scan callback function.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
void (*OnStartScanCallback)(int32_t scanId, int32_t status);
void (*OnStopScanCallback)(int32_t scanId, int32_t status);
void (*OnReportScanDataCallback)(int32_t scanId, const SoftBusBleScanResult *reportData);
} SoftbusScanCallback;
/**
* @brief Defines Different broadcast protocol stacks adapt layer interfaces
*
* @since 1.0
* @version 1.0
*/
struct SoftbusBroadcastMediumInterface {
int32_t (*InitBroadcast)(void);
int32_t (*DeInitBroadcast)(void);
int32_t (*RegisterBroadcaster)(int32_t *advId, const SoftbusBroadcastCallback *cb);
int32_t (*UnRegisterBroadcaster)(int32_t advId);
int32_t (*RegisterScanListener)(int32_t *scanerId, const SoftbusScanCallback *cb);
int32_t (*UnRegisterScanListener)(int32_t scanerId);
int32_t (*StartBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *bcData,
const SoftbusBroadcastData *rspData);
int32_t (*UpdateBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *bcData,
const SoftbusBroadcastData *rspData);
int32_t (*StopBroadcasting)(int32_t advId);
int32_t (*StartScan)(int32_t scanerId, const SoftBusBcScanParams *param);
int32_t (*StopScan)(int32_t scanerId);
int32_t (*SetScanFilter)(int32_t scanerId, const SoftBusBcScanFilter *scanFilter, uint8_t filterSize);
int32_t (*GetScanFilter)(int32_t scanerId, const SoftBusBcScanFilter *scanFilter, uint8_t *filterSize);
int32_t (*QueryBroadcastStatus)(int32_t advId, int32_t *status);
};
/**
* @brief Defines interface functions for registering different media
*
* @since 1.0
* @version 1.0
*/
int32_t RegisterBroadcastMediumFunction(enum SoftbusMediumType type,
const struct SoftbusBroadcastMediumInterface *interface);
/**
* @brief Defines interface functions for unregistering different media
*
* @since 1.0
* @version 1.0
*/
int32_t UnRegisterBroadcastMediumFunction(enum SoftbusMediumType type);
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BROADCAST_ADAPTER_INTERFACE_H */

View File

@ -0,0 +1,158 @@
/*
* 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_broadcast_adapter_type.h
* @brief Declare functions and constants for the soft bus broadcast adaptation
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BROADCAST_ADAPTER_TYPE_H
#define SOFTBUS_BROADCAST_ADAPTER_TYPE_H
#include <stdint.h>
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Defines mac address length
*
* @since 1.0
* @version 1.0
*/
#define SOFTBUS_ADDR_MAC_LEN 6
/**
* @brief Defines different broadcast media protocol stacks
*
* @since 1.0
* @version 1.0
*/
enum SoftbusMediumType {
BROADCAST_MEDIUM_TYPE_BLE,
BROADCAST_MEDIUM_TYPE_SLE,
BROADCAST_MEDIUM_TYPE_BUTT,
};
/**
* @brief Defines the broadcast data information
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint16_t uuidLen;
uint16_t serviceLen;
uint8_t *uuid;
uint8_t *serviceData;
uint16_t companyId;
uint16_t manufacturerDataLen;
uint8_t *manufacturerData;
uint8_t flag;
uint8_t rsv[3]; // Reserved
} SoftbusBroadcastData;
/**
* @brief Defines mac address information
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint8_t addr[SOFTBUS_ADDR_MAC_LEN];
} SoftbusMacAddr;
/**
* @brief Defines the device information returned by <b>SoftbusBroadcastCallback</b>.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint8_t eventType;
uint8_t dataStatus;
uint8_t primaryPhy;
uint8_t secondaryPhy;
uint8_t advSid;
int8_t txPower;
int8_t rssi;
uint8_t addrType;
SoftbusMacAddr addr;
SoftbusBroadcastData data;
} SoftBusBleScanResult;
/**
* @brief Defines the broadcast parameters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
int32_t minInterval;
int32_t maxInterval;
uint8_t advType;
uint8_t advFilterPolicy;
uint8_t ownAddrType;
uint8_t peerAddrType;
SoftbusMacAddr peerAddr;
int32_t channelMap;
int32_t duration;
int8_t txPower;
} SoftbusBroadcastParam;
/**
* @brief Defines broadcast scan filters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
int8_t *address;
int8_t *deviceName;
uint32_t serviceUuidLength;
uint8_t *serviceUuid;
uint8_t *serviceUuidMask;
uint32_t serviceDataLength;
uint8_t *serviceData;
uint8_t *serviceDataMask;
uint32_t manufactureDataLength;
uint8_t *manufactureData;
uint8_t *manufactureDataMask;
uint16_t manufactureId;
} SoftBusBcScanFilter;
/**
* @brief Defines broadcast scan parameters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint16_t scanInterval;
uint16_t scanWindow;
uint8_t scanType;
uint8_t scanPhy;
uint8_t scanFilterPolicy;
} SoftBusBcScanParams;
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BROADCAST_ADAPTER_TYPE_H */

View File

@ -0,0 +1,256 @@
/*
* 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_broadcast_manager.h
* @brief
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BROADCAST_MANAGER_H
#define SOFTBUS_BROADCAST_MANAGER_H
#include "softbus_broadcast_type.h"
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Defines the broadcast callback function.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
void (*OnStartBroadcastingCallback)(int32_t bcId, int32_t status);
void (*OnStopBroadcastingCallback)(int32_t bcId, int32_t status);
void (*OnUpdateBroadcastingCallback)(int32_t bcId, int32_t status);
void (*OnSetBroadcastingCallback)(int32_t bcId, int32_t status);
} BroadcastCallback;
/**
* @brief Defines the broadcast scan callback function.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
void (*OnStartScanCallback)(int32_t listenerId, int32_t status);
void (*OnStopScanCallback)(int32_t listenerId, int32_t status);
void (*OnReportScanDataCallback)(int32_t listenerId, const BroadcastReportInfo *reportInfo);
} ScanCallback;
/**
* @brief init broadcast manager.
*
* @return Returns <b>0</b> If the broadcast management initialization fails;
* returns any other value if the request fails.
* @since 1.0
* @version 1.0
*/
int32_t InitBroadcastMgr(void);
/**
* @brief init broadcast manager.
*
* @return Returns <b>SOFTBUS_OK</b> If the broadcast management deinitialization fails;
* returns any other value if the request fails.
* @since 1.0
* @version 1.0
*/
int32_t DeInitBroadcastMgr(void);
/**
* @brief Register the service to the broadcast manager.
*
* @param type Indicates the service type {@link BaseServiceType}.
* @param bcId Indicates the service broadcast ID.
* @param cb Indicates the service broadcast callback {@link BroadcastCallback}.
*
* @return Returns <b>SOFTBUS_OK</b> if the service register is successful.
* returns any other value if the register fails.
*
* @since 1.0
* @version 1.0
*/
int32_t RegisterBroadcaster(enum BaseServiceType type, int32_t *bcId, const BroadcastCallback *cb);
/**
* @brief UnRegister the service to the broadcast manager.
*
* @param bcId Indicates the service broadcast ID.
*
* @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful.
* returns any other value if the unregister fails.
*
* @since 1.0
* @version 1.0
*/
int32_t UnRegisterBroadcaster(int32_t bcId);
/**
* @brief Register the service listener to the broadcast manager.
*
* @param type Indicates the service type {@link BaseServiceType}.
* @param listenerId Indicates the service listener ID.
* @param cb Indicates the service listener callback {@link ScanCallback}.
*
* @return Returns <b>SOFTBUS_OK</b> if the service register is successful.
* returns any other value if the register fails.
*
* @since 1.0
* @version 1.0
*/
int32_t RegisterScanListener(enum BaseServiceType type, int32_t *listenerId, const ScanCallback *cb);
/**
* @brief UnRegister the service listener to the broadcast manager.
*
* @param listenerId Indicates the service listener ID.
*
* @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful.
* returns any other value if the unregister fails.
*
* @since 1.0
* @version 1.0
*/
int32_t UnRegisterScanListener(int32_t listenerId);
/**
* @brief The service enable broadcast
*
* @param bcId Indicates the service broadcast ID.
* @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}.
* @param bcData Indicates the pointer to the service advertising data. For details, see {@link BroadcastData}.
* @param rspData Indicates the pointer to the service broadcast respond data. For details, see {@link BroadcastData}.
*
* @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully.
* returns any other value if the unregister fails.
*
* @since 1.0
* @version 1.0
*/
int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastData *bcData,
const BroadcastData *rspData);
/**
* @brief The service update broadcast data and parameters.
*
* @param bcId Indicates the service broadcast ID.
* @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}.
* @param bcData Indicates the pointer to the service advertising data. For details, see {@link BroadcastData}.
* @param rspData Indicates the pointer to the service broadcast respond data. For details, see {@link BroadcastData}.
*
* @return Returns <b>SOFTBUS_OK</b> if the service updates the broadcast successfully.
* returns any other value if the service fails to update the broadcast.
*
* @since 1.0
* @version 1.0
*/
int32_t UpdateBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastData *bcData,
const BroadcastData *rspData);
/**
* @brief The service stop broadcast
*
* @param bcId Indicates the service broadcast ID.
*
* @return Returns <b>SOFTBUS_OK</b> if the service stop the broadcast successfully.
* returns any other value if the service fails to stop the broadcast.
*
* @since 1.0
* @version 1.0
*/
int32_t StopBroadcasting(int32_t bcId);
/**
* @brief The service enable broadcast scanning
*
* @param listenerId Indicates the service listener ID.
* @param param Indicates the broadcast scan parameter {@link BcScanParams}
*
* @return Returns <b>SOFTBUS_OK</b> if the service start to scan the broadcast successfully.
* returns any other value if the service fails to scan the broadcast.
*
* @since 1.0
* @version 1.0
*/
int32_t StartScan(int32_t listenerId, const BcScanParams *param);
/**
* @brief The service stop broadcast scanning
*
* @param listenerId Indicates the service listener ID.
*
* @return Returns <b>SOFTBUS_OK</b> if the service stop to scan the broadcast successfully.
* returns any other value if the service fails to stop scanning the broadcast.
*
* @since 1.0
* @version 1.0
*/
int32_t StopScan(int32_t listenerId);
/**
* @brief Set the Scan Filter object
*
* @param listenerId Indicates the service listener ID.
* @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter}
* @param filterNum Indicates the number of the filter parameter
*
* @return Returns <b>SOFTBUS_OK</b> if the service set the Scan Filter successfully.
* returns any other value if the service fails to set the Scan Filter.
*
* @since 1.0
* @version 1.0
*/
int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t filterNum);
/**
* @brief Get the Scan Filter object
*
* @param listenerId Indicates the service listener ID.
* @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter}
* @param filterNum Indicates the number of the filter parameter
*
* @return Returns <b>SOFTBUS_OK</b> if the service get the Scan Filter successfully.
* returns any other value if the service fails to get the Scan Filter.
*
* @since 1.0
* @version 1.0
*/
int32_t GetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t *filterNum);
/**
* @brief Check whether available resources are available by using the bcid
*
* @param bcId Indicates the service broadcast ID, when the service register successfully
* @param status Indicates the status of available broadcast resources
*
* @return Returns <b>SOFTBUS_OK</b> if the service query status successfully.
* returns any other value if the service fails to query status.
*
* @since 1.0
* @version 1.0
*/
int32_t QueryBroadcastStatus(int32_t bcId, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BROADCAST_MANAGER_H */

View File

@ -0,0 +1,162 @@
/*
* 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_broadcast_type.h
* @brief Declare constants for the softbus broadcast.
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BROADCAST_TYPE_H
#define SOFTBUS_BROADCAST_TYPE_H
#include <stdint.h>
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Defines mac address length
*
* @since 1.0
* @version 1.0
*/
#define BC_ADDR_MAC_LEN 6
/**
* @brief Defines the broadcast service type.
*
* @since 1.0
* @version 1.0
*/
enum BaseServiceType {
SRV_TYPE_HB, // The service type is heart beat.
SRV_TYPE_CONN, // The service type is connection.
SRV_TYPE_TRANS_MSG, // The service type is transmission message.
SRV_TYPE_DIS, // The service type is distrubite discovery.
SRV_TYPE_SHARE, // The service type is share discovery.
SRV_TYPE_APPROACH, // The service type is approach discovery.
SRV_TYPE_BUTT,
};
/**
* @brief Defines the broadcast data information
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint16_t uuidLen;
uint16_t serviceLen;
uint8_t *uuid;
uint8_t *serviceData;
uint16_t companyId;
uint16_t manufacturerDataLen;
uint8_t *manufacturerData;
uint8_t flag;
uint8_t rsv[3]; // Reserved
} BroadcastData;
/**
* @brief Defines mac address information
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint8_t addr[BC_ADDR_MAC_LEN];
} BcMacAddr;
/**
* @brief Defines the device information returned by <b>SoftbusBroadcastCallback</b>.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint8_t eventType;
uint8_t dataStatus;
uint8_t primaryPhy;
uint8_t secondaryPhy;
uint8_t advSid;
int8_t txPower;
int8_t rssi;
uint8_t addrType;
BcMacAddr addr;
BroadcastData data;
} BroadcastReportInfo;
/**
* @brief Defines the broadcast parameters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
int32_t minInterval;
int32_t maxInterval;
uint8_t advType;
uint8_t advFilterPolicy;
uint8_t ownAddrType;
uint8_t peerAddrType;
BcMacAddr peerAddr;
int32_t channelMap;
int32_t duration;
int8_t txPower;
} BroadcastParam;
/**
* @brief Defines broadcast scan filters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
int8_t *address;
int8_t *deviceName;
uint32_t serviceUuidLength;
uint8_t *serviceUuid;
uint8_t *serviceUuidMask;
uint32_t serviceDataLength;
uint8_t *serviceData;
uint8_t *serviceDataMask;
uint32_t manufactureDataLength;
uint8_t *manufactureData;
uint8_t *manufactureDataMask;
uint16_t manufactureId;
} BcScanFilter;
/**
* @brief Defines broadcast scan parameters
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint16_t scanInterval;
uint16_t scanWindow;
uint8_t scanType;
uint8_t scanPhy;
uint8_t scanFilterPolicy;
} BcScanParams;
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BROADCAST_TYPE_H */

View File

@ -0,0 +1,240 @@
/*
* 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_broadcast_utils.h
* @brief Declare functions and constants for the softbus broadcast or scan data fill or parse common functions.
*
* @since 1.0
* @version 1.0
*/
#ifndef SOFTBUS_BROADCAST_UTILS_H
#define SOFTBUS_BROADCAST_UTILS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Defines the format of broadcast TLV data
*
* DATA_FORMAT_TL_1BYTE indicates BcTlvDataFormatThe TLV format is 4 bits for T and 4 bits for L
* DATA_FORMAT_TL_2BYTE indicates BcTlvDataFormatThe TLV format is 1 byte for T and 1 byte for L
*
* @since 1.0
* @version 1.0
*/
enum BcTlvDataFormat {
DATA_FORMAT_TL_1BYTE,
DATA_FORMAT_TL_2BYTE,
};
/**
* @brief Defines the broadcast TLV data
*
* @since 1.0
* @version 1.0
*/
typedef struct {
uint8_t type;
uint8_t len;
uint8_t *value;
} BcTlv;
/**
* @brief Get the advertising service data object.
*
* @param uuid Indicates the uuid of the service data.
* @param advPosPtr Indicates the position of the broadcast service data pointer in the scanned raw data.
* @param advLen Indicates the length of the broadcast service data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets service data successful.
* returns any other value if the service fails to get service data.
*
* @since 1.0
* @version 1.0
*/
int32_t GetServiceAdvData(uint16_t uuid, uint8_t **advPosPtr, uint32_t *advLen,
const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Get the respond service data object.
*
* @param uuid Indicates the uuid of the respond service data.
* @param advPosPtr Indicates the position of the respond service data pointer in the scanned raw data.
* @param advLen Indicates the length of the respond service data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets respond service data successful.
* returns any other value if the service fails to get respond service data.
*
* @since 1.0
* @version 1.0
*/
int32_t GetServiceRspData(uint16_t uuid, uint8_t **rspPosPtr, uint32_t *rspLen,
const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Get the advertising manufacturer data object.
*
* @param companyId Indicates the companyId of the manufacturer data.
* @param advPosPtr Indicates the position of the broadcast manufacturer data pointer in the scanned raw data.
* @param advLen Indicates the length of the broadcast manufacturer data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets manufacturer data successful.
* returns any other value if the service fails to get manufacturer data.
*
* @since 1.0
* @version 1.0
*/
int32_t GetManufacturerAdvData(uint16_t companyId, uint8_t **advPosPtr, uint32_t *advLen, const uint8_t *rawData,
uint32_t dataLen);
/**
* @brief Get the respond manufacturer data object.
*
* @param companyId Indicates the companyId of the respond manufacturer data.
* @param advPosPtr Indicates the position of the respond manufacturer data pointer in the scanned raw data.
* @param advLen Indicates the length of the respond manufacturer data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets respond manufacturer data successful.
* returns any other value if the service fails to get respond manufacturer data.
*
* @since 1.0
* @version 1.0
*/
int32_t GetManufacturerRspData(uint16_t companyId, uint8_t **rspPosPtr, uint32_t *rspLen, const uint8_t *rawData,
uint32_t dataLen);
/**
* @brief Get the local name data object by the scanned raw data.
*
* @param localName Indicates shortened local name or complete local name.
* @param len Indicates the length of local name.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets local name successful.
* returns any other value if the service fails to get local name.
*
* @since 1.0
* @version 1.0
*/
int32_t GetLocalNameData(uint8_t *localName, uint32_t *len, const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Get the broadcast flag object
*
* @param flag Indicates the flag value of the advertising data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets flag successful.
* returns any other value if the service fails to get flag.
*
* @since 1.0
* @version 1.0
*/
int32_t GetBcFlag(uint8_t *flag, const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Get the service Uuid object
*
* @param uuid Indicates the uuid of the advertising service data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets uuid successful.
* returns any other value if the service fails to get uuid.
*
* @since 1.0
* @version 1.0
*/
int32_t GetServiceUuid(uint16_t *uuid, const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Get the manufacturer companyId object
*
* @param companyId Indicates the companyId of the advertising manufacturer data.
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return Returns <b>SOFTBUS_OK</b> if the service gets companyId successful.
* returns any other value if the service fails to get companyId.
*
* @since 1.0
* @version 1.0
*/
int32_t GetManufacturerId(uint16_t *companyId, const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Check whether it is service data.
*
* @param rawData Indicates the scanned raw data by reporter.
* @param dataLen Indicates the length of the scanned raw data.
*
* @return true
* @return false
*
* @since 1.0
* @version 1.0
*/
bool IsServiceData(const uint8_t *rawData, uint32_t dataLen);
/**
* @brief Assemble TLV packet.
*
* @param bcData Indicates the pointers to the destination data to be assembled.
* @param dataLen Indicates the length of the destination data.
* @param tlv Indicates Assemble TLV data.
*
* @return Returns <b>SOFTBUS_OK</b> if the TLV packet assemble successful.
* returns any other value if the TLV packet fails to assemble.
*
* @since 1.0
* @version 1.0
*/
int32_t AssembleTlvPkg(enum BcTlvDataFormat, uint8_t *bcData, uint32_t dataLen, const BcTlv *tlv);
/**
* @brief Parse TLV packet by the source data.
*
* @param bcData Indicates the source data of the scanned raw data.
* @param dataLen Indicates the length of the source data
* @param tlv Indicates parsed TLV data.
*
* @return Returns <b>SOFTBUS_OK</b> if the TLV packet parse successful.
* returns any other value if the TLV packet fails to parse.
*
* @since 1.0
* @version 1.0
*/
int32_t ParseTlvPkg(enum BcTlvDataFormat, const uint8_t *bcData, uint32_t dataLen, BcTlv *tlv);
#ifdef __cplusplus
}
#endif
#endif /* SOFTBUS_BROADCAST_UTILS_H */

View File

@ -0,0 +1,22 @@
/*
* 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_broadcast_manager.h"
#include "softbus_broadcast_type.h"
int32_t InitBroadcastMgr(void)
{
return SOFTBUS_OK;
}

View File

@ -26,7 +26,7 @@
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#define STATE_LISTENER_MAX_NUM 9
#define STATE_LISTENER_MAX_NUM 18
#define BR_STATE_CB_TRANSPORT 1
typedef struct {

View File

@ -34,11 +34,28 @@ typedef struct {
int32_t (*getConnection)(const char *udid);
} SoftBusBleConflictListener;
typedef struct {
void (*conlictNotifyConnectResult)(int32_t requestId, uint32_t connectionId,
int32_t underlayerHandle, bool status);
void (*conlictNotifyDataReceive)(uint32_t connectionId, const uint8_t *data, uint32_t dataLen);
void (*conlictNotifyDisconnect)(uint32_t connectionId, int32_t status);
} LegacyConflictEventListener;
void SoftbusBleConflictRegisterListener(SoftBusBleConflictListener *listener);
void SoftbusBleConflictNotifyConnectResult(int32_t requestId, int32_t underlayerHandle, bool status);
void SoftbusBleConflictNotifyDateReceive(int32_t underlayerHandle, const uint8_t *data, uint32_t dataLen);
void SoftbusBleConflictNotifyDisconnect(const char *addr, const char *udid);
int32_t LegacyConflictReuseConnection(const char *address, const char *udid, uint32_t requestId,
uint32_t *connectionId);
bool LegacyConflictPostBytes(int32_t underlayerHandle, uint8_t *data, uint32_t dataLen);
void LegacyConflictDisconnect(int32_t handle, bool isForce);
void LegacyConflictCancelOccupy(const char *udid);
void LegacyConflictOccupy(const char *udid, int32_t timeout);
int32_t LegacyConflictGetConnection(const char *udid);
int32_t LegacyBleInitConflictModule(LegacyConflictEventListener *listener);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -193,6 +193,9 @@ int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data);
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param);
int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
int (*startAdvEx)(int *, const SoftBusBleAdvParams *, const SoftBusBleAdvData *));
int SoftBusStopAdv(int advId);
int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param);

View File

@ -20,7 +20,6 @@ adapter_ble_inc = [
"$dsoftbus_root_path/adapter/common/net/bluetooth/common",
]
adapter_ble_src = [
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_conflict_virtual.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_client.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c",

View File

@ -396,4 +396,14 @@ bool SoftBusIsWifiTripleMode(void)
char* SoftBusGetWifiInterfaceCoexistCap(void)
{
return NULL;
}
bool SoftBusIsWifiActive(void)
{
int wifiState = IsWifiActive();
LNN_LOGI(LNN_STATE, "wifi state %d", wifiState);
if (wifiState == WIFI_STA_ACTIVE) {
return true;
}
return false;
}

View File

@ -98,3 +98,8 @@ char* SoftBusGetWifiInterfaceCoexistCap(void)
{
return NULL;
}
bool SoftBusIsWifiActive(void)
{
return true;
}

View File

@ -150,6 +150,7 @@ int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo);
bool SoftBusHasWifiDirectCapability(void);
bool SoftBusIsWifiTripleMode(void);
char* SoftBusGetWifiInterfaceCoexistCap(void);
bool SoftBusIsWifiActive(void);
#ifdef __cplusplus
}

View File

@ -27,17 +27,17 @@
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#define AES_128_CFB_KEYLEN 16
#define AES_256_CFB_KEYLEN 32
#define AES_128_GCM_KEYLEN 16
#define AES_256_GCM_KEYLEN 32
#define AES_128_CFB_BITS_LEN 128
#define AES_256_CFB_BITS_LEN 256
#define AES_128_CFB_KEYLEN 16
#define AES_256_CFB_KEYLEN 32
#define AES_128_GCM_KEYLEN 16
#define AES_256_GCM_KEYLEN 32
#define AES_128_CFB_BITS_LEN 128
#define AES_256_CFB_BITS_LEN 256
#define OPENSSL_EVP_PADDING_FUNC_OPEN (1)
#define OPENSSL_EVP_PADDING_FUNC_CLOSE (0)
int32_t SoftBusGenerateHmacHash(const EncryptKey *randomKey, const uint8_t *rootKey, uint32_t rootKeyLen,
uint8_t *hash, uint32_t hashLen)
int32_t SoftBusGenerateHmacHash(
const EncryptKey *randomKey, const uint8_t *rootKey, uint32_t rootKeyLen, uint8_t *hash, uint32_t hashLen)
{
uint32_t outBufLen;
uint8_t tempOutputData[EVP_MAX_MD_SIZE];
@ -438,5 +438,51 @@ int32_t SoftbusAesGcmEncrypt(
int32_t SoftbusAesCfbEncrypt(
const AesInputData *inData, AesCipherKey *cipherKey, int32_t encMode, AesOutputData *outData)
{
return SOFTBUS_NOT_IMPLEMENT;
}
uint8_t random[RANDOM_LENGTH] = { 0 };
uint8_t result[SHA256_MAC_LEN] = { 0 };
if (inData == NULL || inData->data == NULL || cipherKey == NULL || outData == NULL ||
(cipherKey->ivLen < RANDOM_LENGTH) || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
uint32_t encryptDataLen = inData->len;
uint8_t *encryptData = (uint8_t *)SoftBusCalloc(encryptDataLen);
if (encryptData == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encrypt data calloc fail.");
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(random, sizeof(random), cipherKey->iv, sizeof(random)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "random memcpy_s failed!");
SoftBusFree(encryptData);
return SOFTBUS_MEM_ERR;
}
EncryptKey key = { cipherKey->key, cipherKey->keyLen };
(void)memset_s(cipherKey->key, cipherKey->keyLen, 0, cipherKey->keyLen);
if (SoftBusGenerateHmacHash(&key, random, sizeof(random), result, SHA256_MAC_LEN) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SslHmacSha256 failed.");
SoftBusFree(encryptData);
return SOFTBUS_ERR;
}
if (memcpy_s(cipherKey->key, cipherKey->keyLen, result, SHA256_MAC_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "fill cipherKey->key failed!");
SoftBusFree(encryptData);
return SOFTBUS_MEM_ERR;
}
if (encMode == ENCRYPT_MODE) {
if (OpensslAesCfbEncrypt(cipherKey, inData->data, inData->len, encryptData, &encryptDataLen) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesCfbEncrypt failed.");
SoftBusFree(encryptData);
return SOFTBUS_ENCRYPT_ERR;
}
} else {
if (OpensslAesCfbDecrypt(cipherKey, inData->data, inData->len, encryptData, &encryptDataLen) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesCfbEncrypt failed.");
SoftBusFree(encryptData);
return SOFTBUS_DECRYPT_ERR;
}
}
outData->data = encryptData;
outData->len = encryptDataLen;
return SOFTBUS_OK;
}

View File

@ -44,4 +44,6 @@ declare_args() {
dsoftbus_feature_ex_kits = false
dsoftbus_feature_proxy_file = false
dsoftbus_feature_wifi_notify = true
}

View File

@ -44,4 +44,6 @@ declare_args() {
dsoftbus_feature_ex_kits = false
dsoftbus_feature_proxy_file = true
dsoftbus_feature_wifi_notify = true
}

View File

@ -44,4 +44,6 @@ declare_args() {
dsoftbus_feature_ex_kits = false
dsoftbus_feature_proxy_file = true
dsoftbus_feature_wifi_notify = true
}

View File

@ -39,7 +39,8 @@
"dsoftbus_feature_lnn_wifiservice_dependence",
"dsoftbus_standard_feature_dfinder_support_multi_nif",
"dsoftbus_feature_protocol_newip",
"dsoftbus_feature_ex_kits"
"dsoftbus_feature_ex_kits",
"dsoftbus_feature_wifi_notify"
],
"rom": "3000KB",
"ram": "40MB",
@ -107,6 +108,7 @@
"test": [
"//foundation/communication/dsoftbus/tests/adapter:fuzztest",
"//foundation/communication/dsoftbus/tests/adapter:unittest",
"//foundation/communication/dsoftbus/tests/core/adapter:unittest",
"//foundation/communication/dsoftbus/tests/core/authentication:fuzztest",
"//foundation/communication/dsoftbus/tests/core/authentication:unittest",
"//foundation/communication/dsoftbus/tests/core/bus_center:unittest",

View File

@ -57,12 +57,13 @@ NSTACKX_EXPORT_VARIABLE extern NstakcxLogCallback g_nstackxLogCallBack;
NSTACKX_EXPORT int32_t SetLogCallback(NstakcxLogCallback logCb);
NSTACKX_EXPORT void SetDefaultLogCallback(void);
#define NSTACKX_LOG_COMMON(moduleName, logLevel, moduleDebugLevel, format, ...) \
do { \
if (logLevel <= moduleDebugLevel && g_nstackxLogCallBack != NULL) { \
g_nstackxLogCallBack(moduleName, logLevel, "%s:[%d] :" format "\n", \
__FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
#define FILE_NAME (__builtin_strrchr("/" __FILE__, '/') + 1)
#define NSTACKX_LOG_COMMON(moduleName, logLevel, moduleDebugLevel, format, ...) \
do { \
if (logLevel <= moduleDebugLevel && g_nstackxLogCallBack != NULL) { \
g_nstackxLogCallBack( \
moduleName, logLevel, "[%s:%d] %s# " format "\n", FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
} \
} while (0)
#define LOGF(moduleName, format, ...) \

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
@ -13,28 +13,27 @@
* limitations under the License.
*/
#ifndef TRANS_AUTH_MESSAGE_H
#define TRANS_AUTH_MESSAGE_H
#ifndef LNN_LINKFINDER_H
#define LNN_LINKFINDER_H
#include "softbus_app_info.h"
#include "softbus_json_utils.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif
#define ERR_MSG_MAX_LEN 128
int32_t TransAuthChannelMsgPack(cJSON *msg, const AppInfo *appInfo);
int32_t TransAuthChannelMsgUnpack(const char *msg, AppInfo *appInfo, int32_t len);
int32_t TransAuthChannelErrorPack(int32_t errcode, const char *errMsg, char *cJsonStr, int32_t maxLen);
int32_t LnnLinkFinderInit(void);
int32_t LnnUpdateLinkFinderInfo(void);
int32_t LnnRemoveLinkFinderInfo(const char *networkId);
int32_t LnnInsertLinkFinderInfo(const char *networkId);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* LNN_LINKFINDER_H */

View File

@ -13,23 +13,27 @@
* limitations under the License.
*/
#include "trans_log.h"
#include "lnn_link_finder.h"
#include "softbus_error_code.h"
#include "anonymizer.h"
#include "comm_log.h"
void PrintAnonymousPacket(TransLogLabelEnum label, const char *msg, const char *packet)
int32_t LnnLinkFinderInit(void)
{
if ((msg == NULL) || (packet == NULL)) {
COMM_LOGW(COMM_DFX, "msg or packet is null");
return;
}
#ifdef __LITEOS_M__
TRANS_LOGI(label, "%s%s", msg, "******");
#else
char *anonymousOut;
AnonymizePacket(packet, &anonymousOut);
TRANS_LOGI(label, "%s%s", msg, anonymousOut);
AnonymizeFree(anonymousOut);
#endif // __LITEOS_M__
}
return SOFTBUS_OK;
}
int32_t LnnUpdateLinkFinderInfo(void)
{
return SOFTBUS_OK;
}
int32_t LnnRemoveLinkFinderInfo(const char *networkId)
{
(void)networkId;
return SOFTBUS_OK;
}
int32_t LnnInsertLinkFinderInfo(const char *networkId)
{
(void)networkId;
return SOFTBUS_OK;
}

View File

View File

@ -1,4 +1,4 @@
# 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
@ -43,6 +43,21 @@ if (defined(ohos_lite)) {
bus_center_core_adapter_deps +=
[ "//base/startup/init/interfaces/innerkits:libbegetutil" ]
if (dsoftbus_feature_encrypt == 0) {
bus_center_core_adapter_src += [
"$dsoftbus_root_path/core/adapter/huks/src/softbus_rsa_encrypt_virtual.c",
]
bus_center_core_adapter_inc +=
[ "$dsoftbus_root_path/core/adapter/huks/include" ]
} else if (dsoftbus_feature_encrypt == 1) {
bus_center_core_adapter_src +=
[ "$dsoftbus_root_path/core/adapter/huks/src/softbus_rsa_encrypt.c" ]
bus_center_core_adapter_inc +=
[ "$dsoftbus_root_path/core/adapter/huks/include" ]
bus_center_core_adapter_deps += [ "//third_party/openssl:libcrypto_shared" ]
bus_center_core_adapter_external_deps += [ "huks:libhukssdk" ]
}
} else {
if (dsoftbus_get_devicename == false) {
bus_center_core_adapter_src += [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ]
@ -82,4 +97,18 @@ if (defined(ohos_lite)) {
"$dsoftbus_root_path/core/adapter/bus_center/src/lnn_ohos_account_adapter_virtual.cpp",
]
}
if (dsoftbus_feature_encrypt == 0) {
bus_center_core_adapter_src += [
"$dsoftbus_root_path/core/adapter/huks/src/softbus_rsa_encrypt_virtual.c",
]
bus_center_core_adapter_inc +=
[ "$dsoftbus_root_path/core/adapter/huks/include" ]
} else if (dsoftbus_feature_encrypt == 1) {
bus_center_core_adapter_src +=
[ "$dsoftbus_root_path/core/adapter/huks/src/softbus_rsa_encrypt.c" ]
bus_center_core_adapter_inc +=
[ "$dsoftbus_root_path/core/adapter/huks/include" ]
bus_center_core_adapter_deps += [ "//third_party/openssl:libcrypto_shared" ]
bus_center_core_adapter_external_deps += [ "huks:libhukssdk" ]
}
}

View File

@ -22,10 +22,10 @@
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <securec.h>
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
static const uint8_t SOFTBUS_RSA_KEY_ALIAS[] = "DsoftbusRsaKey";
static const struct HksBlob g_rsaKeyAlias = { sizeof(SOFTBUS_RSA_KEY_ALIAS), (uint8_t *)SOFTBUS_RSA_KEY_ALIAS };
@ -49,10 +49,10 @@ static struct HksParam g_decryptParams[] = {
static bool IsRsaKeyPairExist(struct HksBlob Alias)
{
if (HksKeyExist(&Alias, NULL) == HKS_SUCCESS) {
HILOG_INFO(SOFTBUS_HILOG_ID, "rsa keypair already exist.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "rsa keypair already exist.");
return true;
} else {
HILOG_ERROR(SOFTBUS_HILOG_ID, "rsa keypair do not exist.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "rsa keypair do not exist.");
return false;
}
}
@ -60,16 +60,16 @@ static bool IsRsaKeyPairExist(struct HksBlob Alias)
static int32_t ConstructKeyParamSet(struct HksParamSet **paramSet, const struct HksParam *params, uint32_t paramCount)
{
if (HksInitParamSet(paramSet) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksInitParamSet failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksInitParamSet failed.");
return SOFTBUS_ERR;
}
if (HksAddParams(*paramSet, params, paramCount) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksAddParams failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksAddParams failed.");
HksFreeParamSet(paramSet);
return SOFTBUS_ERR;
}
if (HksBuildParamSet(paramSet) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksBuildParamSet failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksBuildParamSet failed.");
HksFreeParamSet(paramSet);
return SOFTBUS_ERR;
}
@ -84,7 +84,7 @@ static int32_t GenerateRsaKeyPair(void)
return SOFTBUS_ERR;
}
if (HksGenerateKey(&g_rsaKeyAlias, paramSet, NULL) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksGenerateKey failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksGenerateKey failed.");
HksFreeParamSet(&paramSet);
return SOFTBUS_ERR;
}
@ -95,12 +95,12 @@ static int32_t GenerateRsaKeyPair(void)
int32_t SoftbusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
{
if (publicKey == NULL || publicKeyLen == 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "invalid param");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (!IsRsaKeyPairExist(g_rsaKeyAlias)) {
if (GenerateRsaKeyPair() != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Generate RsaKeyPair failed");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Generate RsaKeyPair failed");
return SOFTBUS_ERR;
}
}
@ -108,10 +108,10 @@ int32_t SoftbusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
uint8_t pubKey[HKS_RSA_KEY_SIZE_4096] = { 0 };
struct HksBlob publicKeyBlob = { HKS_RSA_KEY_SIZE_4096, pubKey };
if (HksExportPublicKey(&g_rsaKeyAlias, NULL, &publicKeyBlob) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksExportPubKey failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksExportPubKey failed.");
return SOFTBUS_ERR;
}
HILOG_DEBUG(SOFTBUS_HILOG_ID, "X509 public key size is: %u.", publicKeyBlob.size);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "X509 public key size is: %u.", publicKeyBlob.size);
if (memcpy_s(publicKey, publicKeyBlob.size, publicKeyBlob.data, publicKeyBlob.size) != EOK) {
return SOFTBUS_ERR;
}
@ -120,16 +120,16 @@ int32_t SoftbusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
static int32_t X509ToRsaPublicKey(struct HksBlob *x509Key, struct HksBlob *publicKey)
{
HILOG_DEBUG(SOFTBUS_HILOG_ID, "X509ToRsaPublicKey invoked.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "X509ToRsaPublicKey invoked.");
uint8_t *data = x509Key->data;
EVP_PKEY *pkey = d2i_PUBKEY(NULL, (const unsigned char **)&data, x509Key->size);
if (pkey == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "d2i_PUBKEY failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "d2i_PUBKEY failed.");
return SOFTBUS_ERR;
}
const RSA *rsa = EVP_PKEY_get0_RSA(pkey);
if (rsa == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_PKEY_get0_RSA failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "EVP_PKEY_get0_RSA failed.");
return SOFTBUS_ERR;
}
int32_t nSizeTemp = BN_num_bytes(RSA_get0_n(rsa));
@ -150,8 +150,8 @@ static int32_t X509ToRsaPublicKey(struct HksBlob *x509Key, struct HksBlob *publi
EVP_PKEY_free(pkey);
return SOFTBUS_ERR;
}
HILOG_INFO(SOFTBUS_HILOG_ID, "nSize is: %u.", nSize);
HILOG_INFO(SOFTBUS_HILOG_ID, "eSize is: %u.", eSize);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "nSize is: %u.", nSize);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "eSize is: %u.", eSize);
EVP_PKEY_free(pkey);
return SOFTBUS_OK;
}
@ -161,7 +161,7 @@ static RSA *InitRsa(struct HksBlob *key, const bool needPrivateExponent)
const struct HksKeyMaterialRsa *keyMaterial = (struct HksKeyMaterialRsa *)(key->data);
uint8_t *buff = (uint8_t *)SoftBusCalloc(HKS_KEY_BYTES(keyMaterial->keySize));
if (buff == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "buff calloc failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "buff calloc failed.");
return NULL;
}
@ -215,7 +215,7 @@ static const EVP_MD *GetOpensslDigestType(int digestType)
case DIGEST_SHA512:
return EVP_sha512();
default:
HILOG_ERROR(SOFTBUS_HILOG_ID, "GetOpensslDigestType failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "GetOpensslDigestType failed.");
return NULL;
}
}
@ -272,32 +272,32 @@ int32_t SoftbusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, const uin
uint8_t **encryptedData, uint32_t *encryptedDataLen)
{
if (srcData == NULL || srcDataLen == 0 || publicKey == NULL || encryptedData == NULL || encryptedDataLen == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "invalid param");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
uint32_t publicKeySize = SOFTBUS_RSA_PUB_KEY_LEN;
uint8_t huksPublicKey[publicKeySize];
if (memcpy_s(huksPublicKey, publicKeySize, publicKey, publicKeySize) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "huksPublicKey memcpy_s failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "huksPublicKey memcpy_s failed.");
return SOFTBUS_MEM_ERR;
}
struct HksBlob huksPublicKeyInfo = { publicKeySize, huksPublicKey };
uint8_t opensslPublicKey[HKS_RSA_KEY_SIZE_4096] = { 0 };
struct HksBlob opensslPublicKeyInfo = { HKS_RSA_KEY_SIZE_4096, opensslPublicKey };
if (X509ToRsaPublicKey(&huksPublicKeyInfo, &opensslPublicKeyInfo) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "X509ToRsaPublicKey failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "X509ToRsaPublicKey failed.");
return SOFTBUS_ERR;
}
HILOG_DEBUG(SOFTBUS_HILOG_ID, "opensslPublicKeyInfo.size is: %u.", opensslPublicKeyInfo.size);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "opensslPublicKeyInfo.size is: %u.", opensslPublicKeyInfo.size);
struct HksBlob finalPublicKeyInfo = { .size = opensslPublicKeyInfo.size,
.data = (uint8_t *)SoftBusCalloc(opensslPublicKeyInfo.size) };
if (finalPublicKeyInfo.data == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "malloc failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "malloc failed.");
return SOFTBUS_ERR;
}
if (memcpy_s(finalPublicKeyInfo.data, finalPublicKeyInfo.size, opensslPublicKeyInfo.data,
opensslPublicKeyInfo.size) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "memcpy_s failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "memcpy_s failed.");
SoftBusFree(finalPublicKeyInfo.data);
return SOFTBUS_ERR;
}
@ -305,13 +305,13 @@ int32_t SoftbusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, const uin
struct HksBlob cipherText = { .size = HKS_RSA_KEY_SIZE_4096,
.data = (uint8_t *)SoftBusCalloc(HKS_RSA_KEY_SIZE_4096) };
if (cipherText.data == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "malloc failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "malloc failed.");
SoftBusFree(finalPublicKeyInfo.data);
return SOFTBUS_ERR;
}
if (EncryptByPublicKey(&plainText, &cipherText, &finalPublicKeyInfo, RSA_PKCS1_OAEP_PADDING, DIGEST_SHA256) !=
SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_PKEY_encrypt failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "EVP_PKEY_encrypt failed.");
SoftBusFree(finalPublicKeyInfo.data);
SoftBusFree(cipherText.data);
return SOFTBUS_ERR;
@ -319,13 +319,13 @@ int32_t SoftbusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, const uin
*encryptedDataLen = cipherText.size;
*encryptedData = (uint8_t *)SoftBusCalloc(cipherText.size);
if (*encryptedData == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encrypted Data calloc fail");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "encrypted Data calloc fail");
SoftBusFree(finalPublicKeyInfo.data);
SoftBusFree(cipherText.data);
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(*encryptedData, cipherText.size, cipherText.data, cipherText.size) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encryptedData memcpy_s fail");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "encryptedData memcpy_s fail");
SoftBusFree(finalPublicKeyInfo.data);
SoftBusFree(cipherText.data);
return SOFTBUS_MEM_ERR;
@ -339,10 +339,10 @@ int32_t SoftbusRsaDecrypt(const uint8_t *srcData, uint32_t srcDataLen, uint8_t *
uint32_t *decryptedDataLen)
{
if (srcData == NULL || srcDataLen == 0 || decryptedData == NULL || decryptedDataLen == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "invalid srcData");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid srcData");
return SOFTBUS_INVALID_PARAM;
}
HILOG_DEBUG(SOFTBUS_HILOG_ID, "DecryptByPrivateKey invoked.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "DecryptByPrivateKey invoked.");
struct HksBlob encryptedBlob = { srcDataLen, (uint8_t *)srcData };
struct HksParamSet *paramSet = NULL;
if (ConstructKeyParamSet(&paramSet, g_decryptParams, sizeof(g_decryptParams) / sizeof(struct HksParam)) !=
@ -352,26 +352,26 @@ int32_t SoftbusRsaDecrypt(const uint8_t *srcData, uint32_t srcDataLen, uint8_t *
struct HksBlob decryptedBlob = { .size = HKS_RSA_KEY_SIZE_4096,
.data = (uint8_t *)(SoftBusCalloc(HKS_RSA_KEY_SIZE_4096)) };
if (decryptedBlob.data == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "decryptedBlob data calloc failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "decryptedBlob data calloc failed.");
return SOFTBUS_MEM_ERR;
}
if (HksDecrypt(&g_rsaKeyAlias, paramSet, &encryptedBlob, &decryptedBlob) != HKS_SUCCESS) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HksDecrypt failed.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "HksDecrypt failed.");
HksFreeParamSet(&paramSet);
SoftBusFree(decryptedBlob.data);
return SOFTBUS_ERR;
}
HILOG_DEBUG(SOFTBUS_HILOG_ID, "HksDecrypt success.");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "HksDecrypt success.");
*decryptedDataLen = decryptedBlob.size;
*decryptedData = (uint8_t *)SoftBusCalloc(decryptedBlob.size);
if (*decryptedData == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "decrypted Data calloc fail");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "decrypted Data calloc fail");
HksFreeParamSet(&paramSet);
SoftBusFree(decryptedBlob.data);
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(*decryptedData, decryptedBlob.size, decryptedBlob.data, decryptedBlob.size) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "decrypted Data memcpy_s fail");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "decrypted Data memcpy_s fail");
HksFreeParamSet(&paramSet);
SoftBusFree(decryptedBlob.data);
return SOFTBUS_MEM_ERR;

View File

@ -21,13 +21,14 @@ int32_t SoftbusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t SoftbusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, const uint8_t *publicKey, uint8_t **encryptedData,
uint32_t *encryptedDataLen)
int32_t SoftbusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, const uint8_t *publicKey,
uint8_t **encryptedData, uint32_t *encryptedDataLen)
{
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t SoftbusRsaDecrypt(const uint8_t *srcData, uint32_t srcDataLen, uint8_t **decryptedData, uint32_t *decryptedDataLen)
int32_t SoftbusRsaDecrypt(
const uint8_t *srcData, uint32_t srcDataLen, uint8_t **decryptedData, uint32_t *decryptedDataLen)
{
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -84,7 +84,10 @@ if (dsoftbus_feature_lnn_net) {
"$authentication_path/src/virtual/auth_meta_manager_virtual.c",
]
}
auth_server_deps = [ "$dsoftbus_dfx_path/log:softbus_dfx_log" ]
auth_server_deps = [
"$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
"$dsoftbus_dfx_path/log:softbus_dfx_log",
]
if (defined(ohos_lite)) {
if (ohos_kernel_type == "liteos_m") {

View File

@ -25,6 +25,7 @@
#include "auth_device_common_key.h"
#include "common_list.h"
#include "lnn_node_info.h"
#include "lnn_p2p_info.h"
#include "lnn_state_machine.h"
#include "softbus_hisysevt_bus_center.h"

View File

@ -21,6 +21,7 @@
#include "auth_log.h"
#include "auth_tcp_connection.h"
#include "lnn_async_callback_utils.h"
#include "lnn_event.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
@ -286,8 +287,12 @@ static void HandleConnConnectCmd(const void *para)
AUTH_LOGE(AUTH_CONN, "invalid connType=%d", info->connInfo.type);
return;
}
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
int32_t fd = SocketConnectDevice(info->connInfo.info.ipInfo.ip, info->connInfo.info.ipInfo.port, false);
if (fd < 0) {
lnnEventExtra.errcode = SOFTBUS_AUTH_CONN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
AUTH_LOGE(AUTH_CONN, "SocketConnectDevice fail");
RemoveConnConnectTimeout(info->requestId);
NotifyClientConnected(info->requestId, 0, SOFTBUS_AUTH_CONN_FAIL, NULL);
@ -307,8 +312,11 @@ static void HandleConnConnectResult(const void *para)
AUTH_LOGE(AUTH_CONN, "ConnRequest not found, fd=%d", fd);
return;
}
uint64_t connId = GenConnId(AUTH_LINK_TYPE_WIFI, fd);
RemoveConnConnectTimeout(item->requestId);
NotifyClientConnected(item->requestId, GenConnId(AUTH_LINK_TYPE_WIFI, fd), SOFTBUS_OK, &item->connInfo);
NotifyClientConnected(item->requestId, connId, SOFTBUS_OK, &item->connInfo);
LnnEventExtra lnnEventExtra = { .connectionId = connId, .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
DelConnRequest(item);
}
@ -483,7 +491,10 @@ static void OnCommConnectSucc(uint32_t requestId, uint32_t connectionId, const C
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
(void)ConvertToAuthConnInfo(info, &connInfo);
RemoveConnConnectTimeout(requestId);
NotifyClientConnected(requestId, GenConnId(connInfo.type, connectionId), SOFTBUS_OK, &connInfo);
uint64_t connId = GenConnId(connInfo.type, connectionId);
NotifyClientConnected(requestId, connId, SOFTBUS_OK, &connInfo);
LnnEventExtra lnnEventExtra = { .connectionId = (int32_t)connId, .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
}
static void OnCommConnectFail(uint32_t requestId, int32_t reason)
@ -491,6 +502,8 @@ static void OnCommConnectFail(uint32_t requestId, int32_t reason)
AUTH_LOGI(AUTH_CONN, "requestId=%u, reason=%d", requestId, reason);
RemoveConnConnectTimeout(requestId);
NotifyClientConnected(requestId, 0, SOFTBUS_CONN_FAIL, NULL);
LnnEventExtra lnnEventExtra = { .errcode = reason };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
}
static int32_t ConnectCommDevice(const AuthConnInfo *info, uint32_t requestId, ConnSideType sideType)
@ -509,8 +522,12 @@ static int32_t ConnectCommDevice(const AuthConnInfo *info, uint32_t requestId, C
.OnConnectSuccessed = OnCommConnectSucc,
.OnConnectFailed = OnCommConnectFail,
};
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
ret = ConnConnectDevice(&option, requestId, &result);
if (ret != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_AUTH_CONN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, lnnEventExtra);
AUTH_LOGE(AUTH_CONN, "ConnConnectDevice fail=%d", ret);
return SOFTBUS_CONN_FAIL;
}

View File

@ -25,6 +25,7 @@
#include "auth_manager.h"
#include "auth_request.h"
#include "auth_session_message.h"
#include "lnn_event.h"
#include "softbus_adapter_hitrace.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
@ -504,8 +505,12 @@ static void HandleMsgRecvDeviceId(AuthFsm *authFsm, MessagePara *para)
Anonymize(info->udid, &anonyUdid);
AUTH_LOGI(AUTH_FSM, "start auth send udid=%s", anonyUdid);
AnonymizeFree(anonyUdid);
LnnEventExtra lnnEventExtra = { .authId = authFsm->authSeq };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_DEVICE, lnnEventExtra);
if (HichainStartAuth(authFsm->authSeq, info->udid, info->connInfo.peerUid) != SOFTBUS_OK) {
ret = SOFTBUS_AUTH_HICHAIN_AUTH_FAIL;
lnnEventExtra.errcode = SOFTBUS_AUTH_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_DEVICE, lnnEventExtra);
break;
}
}
@ -544,8 +549,12 @@ static bool SyncDevIdStateProcess(FsmStateMachine *fsm, int32_t msgType, void *p
static void HandleMsgRecvAuthData(AuthFsm *authFsm, MessagePara *para)
{
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
int32_t ret = HichainProcessData(authFsm->authSeq, para->data, para->len);
if (ret != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_AUTH_EXCHANGE_CIPHER_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
AUTH_LOGE(AUTH_FSM, "process hichain data fail");
if (!authFsm->info.isAuthFinished) {
CompleteAuthSession(authFsm, SOFTBUS_AUTH_HICHAIN_PROCESS_FAIL);
@ -576,6 +585,8 @@ static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
{
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
SessionKey sessionKey = {.len = para->len};
if (memcpy_s(sessionKey.value, sizeof(sessionKey.value), para->data, para->len) != EOK) {
AUTH_LOGE(AUTH_FSM, "copy session key fail.");
@ -586,7 +597,9 @@ static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
AUTH_LOGE(AUTH_FSM, "auth fsm[%" PRId64 "] save session key fail", authFsm->authSeq);
}
(void)memset_s(&sessionKey, sizeof(sessionKey), 0, sizeof(sessionKey));
if (LnnGenerateLocalPtk(authFsm->info.udid) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "generate ptk fail");
}
if (TrySyncDeviceInfo(authFsm->authSeq, &authFsm->info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "auth fsm[%" PRId64"] sync device info fail", authFsm->authSeq);
CompleteAuthSession(authFsm, SOFTBUS_AUTH_SYNC_DEVINFO_FAIL);
@ -639,6 +652,8 @@ static void HandleMsgAuthFinish(AuthFsm *authFsm, MessagePara *para)
{
(void)para;
AuthSessionInfo *info = &authFsm->info;
LnnEventExtra lnnEventExtra = { .authId = (int32_t)authFsm->authSeq, .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_DEVICE, lnnEventExtra);
AUTH_LOGI(AUTH_FSM, "auth fsm[%" PRId64"] hichain finished, devInfo|closeAck=%d|%d",
authFsm->authSeq, info->isNodeInfoReceived, info->isCloseAckReceived);
info->isAuthFinished = true;
@ -685,14 +700,19 @@ static bool DeviceAuthStateProcess(FsmStateMachine *fsm, int32_t msgType, void *
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, MessagePara *para)
{
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
AuthSessionInfo *info = &authFsm->info;
if (ProcessDeviceInfoMessage(authFsm->authSeq, info, para->data, para->len) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_AUTH_EXCHANGE_DEVICE_INFO_END_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_DEVICE_INFO, lnnEventExtra);
AUTH_LOGE(AUTH_FSM, "process device info msg fail");
CompleteAuthSession(authFsm, SOFTBUS_AUTH_UNPACK_DEVINFO_FAIL);
return;
}
info->isNodeInfoReceived = true;
lnnEventExtra.peerDeviceAbility = info->nodeInfo.netCapacity;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_DEVICE_INFO, lnnEventExtra);
if (info->connInfo.type == AUTH_LINK_TYPE_WIFI) {
info->isCloseAckReceived = true; /* WiFi auth no need close ack, set true directly */
if (!info->isServer) {

View File

@ -30,6 +30,7 @@
#include "bus_center_manager.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_common_utils.h"
#include "lnn_event.h"
#include "lnn_extdata_config.h"
#include "lnn_local_net_ledger.h"
#include "lnn_feature_capability.h"
@ -45,6 +46,7 @@
#include "softbus_json_utils.h"
#include "lnn_compress.h"
#include "softbus_adapter_json.h"
#include "softbus_adapter_timer.h"
#include "softbus_socket.h"
/* DeviceId */
@ -133,6 +135,13 @@
#define UNIFIED_DISPLAY_DEVICE_NAME "UNIFIED_DISPLAY_DEVICE_NAME"
#define UNIFIED_DEFAULT_DEVICE_NAME "UNIFIED_DEFAULT_DEVICE_NAME"
#define UNIFIED_DEVICE_NAME "UNIFIED_DEVICE_NAME"
#define PTK "PTK"
#define STATIC_CAP "STATIC_CAP"
#define STATIC_CAP_LENGTH "STATIC_CAP_LEN"
#define BROADCAST_CIPHER_KEY "BROADCAST_CIPHER_KEY"
#define BROADCAST_CIPHER_IV "BROADCAST_CIPHER_IV"
#define IRK "IRK"
#define PUB_MAC "PUB_MAC"
#define FLAG_COMPRESS_DEVICE_INFO 1
#define FLAG_UNCOMPRESS_DEVICE_INFO 0
@ -739,6 +748,135 @@ static void PackCommP2pInfo(JsonObj *json, const NodeInfo *info)
(void)JSON_AddInt32ToObject(json, STA_FREQUENCY, LnnGetStaFrequency(info));
}
static void PackWifiDirectInfo(JsonObj *json, const NodeInfo *info, const char *remoteUdid)
{
if (json == NULL || remoteUdid == NULL) {
AUTH_LOGE(AUTH_FSM, "invalid param");
return;
}
unsigned char encodePtk[PTK_ENCODE_LEN] = {0};
char localPtk[PTK_DEFAULT_LEN] = {0};
if (LnnGetLocalPtkByUdid(remoteUdid, localPtk) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get ptk by udid fail");
return;
}
size_t keyLen = 0;
if (SoftBusBase64Encode(encodePtk, PTK_ENCODE_LEN, &keyLen, (unsigned char *)localPtk,
PTK_DEFAULT_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "encode ptk fail");
return;
}
if (!JSON_AddStringToObject(json, PTK, (char *)encodePtk)) {
AUTH_LOGE(AUTH_FSM, "add ptk string to json fail");
return;
}
if (!JSON_AddInt32ToObject(json, STATIC_CAP_LENGTH, info->staticCapLen)) {
AUTH_LOGE(AUTH_FSM, "add static cap len fail");
return;
}
char staticCap[STATIC_CAP_STR_LEN] = {0};
if (ConvertBytesToHexString((char *)staticCap, STATIC_CAP_STR_LEN,
info->staticCapability, info->staticCapLen) != SOFTBUS_OK) {
AUTH_LOGW(AUTH_FSM, "convert static cap fail");
return;
}
if (!JSON_AddStringToObject(json, STATIC_CAP, (char *)staticCap)) {
AUTH_LOGW(AUTH_FSM, "add static capability fail");
return;
}
return;
}
static int32_t PackCipherRpaInfo(JsonObj *json, const NodeInfo *info)
{
unsigned char cipherKey[SESSION_KEY_STR_LEN] = {0};
unsigned char cipherIv[BROADCAST_IV_STR_LEN] = {0};
unsigned char peerIrk[LFINDER_IRK_STR_LEN] = {0};
unsigned char pubMac[LFINDER_MAC_ADDR_STR_LEN] = {0};
if (ConvertBytesToHexString((char *)cipherKey, SESSION_KEY_STR_LEN,
info->cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher key to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)cipherIv, BROADCAST_IV_STR_LEN,
info->cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher iv to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)peerIrk, LFINDER_IRK_STR_LEN,
info->rpaInfo.peerIrk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert peerIrk to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)pubMac, LFINDER_MAC_ADDR_STR_LEN,
info->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert publicAddress to string fail.");
return SOFTBUS_ERR;
}
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_KEY, (const char *)cipherKey);
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_IV, (const char *)cipherIv);
(void)JSON_AddStringToObject(json, IRK, (const char *)peerIrk);
(void)JSON_AddStringToObject(json, PUB_MAC, (const char *)pubMac);
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, broadcastKey.udid, UDID_BUF_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get udid fail");
return SOFTBUS_ERR;
}
if (memcpy_s(&broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH, info->cipherInfo.key, SESSION_KEY_LENGTH) != EOK) {
AUTH_LOGE(AUTH_FSM, "memcpy key fail.");
return SOFTBUS_ERR;
}
if (memcpy_s(&broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN, info->cipherInfo.iv, BROADCAST_IV_LEN) != EOK) {
AUTH_LOGE(AUTH_FSM, "memcpy iv fail.");
return SOFTBUS_ERR;
}
if (LnnUpdateLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "update local broadcast key failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static void UnpackCipherRpaInfo(const JsonObj *json, NodeInfo *info)
{
char cipherKey[SESSION_KEY_STR_LEN] = {0};
char cipherIv[BROADCAST_IV_STR_LEN] = {0};
char peerIrk[LFINDER_IRK_STR_LEN] = {0};
char pubMac[LFINDER_MAC_ADDR_STR_LEN] = {0};
if (!JSON_GetStringFromOject(json, BROADCAST_CIPHER_KEY, cipherKey, SESSION_KEY_STR_LEN) ||
!JSON_GetStringFromOject(json, BROADCAST_CIPHER_IV, cipherIv, BROADCAST_IV_STR_LEN) ||
!JSON_GetStringFromOject(json, IRK, peerIrk, LFINDER_IRK_STR_LEN) ||
!JSON_GetStringFromOject(json, PUB_MAC, pubMac, LFINDER_MAC_ADDR_STR_LEN)) {
AUTH_LOGE(AUTH_FSM, "get json info fail.");
return;
}
if (ConvertHexStringToBytes((unsigned char *)info->cipherInfo.key,
SESSION_KEY_LENGTH, cipherKey, strlen(cipherKey)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher key to bytes fail.");
return;
}
if (ConvertHexStringToBytes((unsigned char *)info->cipherInfo.iv,
BROADCAST_IV_LEN, cipherIv, strlen(cipherIv)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher iv to bytes fail.");
return;
}
if (ConvertHexStringToBytes((unsigned char *)info->rpaInfo.peerIrk,
LFINDER_IRK_LEN, peerIrk, strlen(peerIrk)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert peerIrk to bytes fail.");
return;
}
if (ConvertHexStringToBytes((unsigned char *)info->rpaInfo.publicAddress,
LFINDER_MAC_ADDR_LEN, pubMac, strlen(pubMac)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert publicAddress to bytes fail.");
return;
}
}
static int32_t PackCommon(JsonObj *json, const NodeInfo *info, SoftBusVersion version, bool isMetaAuth)
{
if (version >= SOFTBUS_NEW_V1) {
@ -801,9 +939,47 @@ static int32_t PackCommon(JsonObj *json, const NodeInfo *info, SoftBusVersion ve
AUTH_LOGE(AUTH_FSM, "PackCipherKeySyncMsg fail");
}
PackCommP2pInfo(json, info);
if (PackCipherRpaInfo(json, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "pack CipherRpaInfo of device key fail.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static void UnpackWifiDirectInfo(const JsonObj *json, NodeInfo *info)
{
char staticCap[STATIC_CAP_STR_LEN] = {0};
if (!JSON_GetInt32FromOject(json, STATIC_CAP_LENGTH, &info->staticCapLen)) {
AUTH_LOGE(AUTH_FSM, "get static cap len fail");
return;
}
if (!JSON_GetStringFromOject(json, STATIC_CAP, staticCap, STATIC_CAP_STR_LEN)) {
AUTH_LOGE(AUTH_FSM, "get static cap fail");
return;
}
if (ConvertHexStringToBytes((unsigned char *)info->staticCapability, STATIC_CAP_LEN,
staticCap, strlen(staticCap)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert static cap fail");
return;
}
char encodePtk[PTK_ENCODE_LEN] = {0};
size_t len = 0;
if (!JSON_GetStringFromOject(json, PTK, encodePtk, PTK_ENCODE_LEN)) {
AUTH_LOGE(AUTH_FSM, "get encode ptk fail");
return;
}
if (SoftBusBase64Decode((unsigned char *)info->remotePtk, PTK_DEFAULT_LEN,
&len, (const unsigned char *)encodePtk, strlen((char *)encodePtk)) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "decode static cap fail");
return;
}
if (len != PTK_DEFAULT_LEN) {
AUTH_LOGE(AUTH_FSM, "decode data len error");
return;
}
}
static void UnpackCommon(const JsonObj *json, NodeInfo *info, SoftBusVersion version, bool isMetaAuth)
{
if (version >= SOFTBUS_NEW_V1) {
@ -873,6 +1049,8 @@ static void UnpackCommon(const JsonObj *json, NodeInfo *info, SoftBusVersion ver
OptInt(json, STA_FREQUENCY, &info->p2pInfo.staFrequency, -1);
OptString(json, P2P_MAC_ADDR, info->p2pInfo.p2pMac, MAC_LEN, "");
OptString(json, HML_MAC, info->wifiDirectAddr, MAC_LEN, "");
UnpackCipherRpaInfo(json, info);
}
static int32_t GetBtDiscTypeString(const NodeInfo *info, char *buf, uint32_t len)
@ -1138,6 +1316,16 @@ char *PackDeviceInfoMessage(int32_t linkType, SoftBusVersion version, bool isMet
JSON_Delete(json);
return NULL;
}
int64_t authId = AuthDeviceGetLatestIdByUuid(remoteUuid, (AuthLinkType)linkType);
if (authId == AUTH_INVALID_ID) {
AUTH_LOGW(AUTH_FSM, "get auth id fail");
}
AuthManager *manager = GetAuthManagerByAuthId(authId);
if (manager != NULL) {
PackWifiDirectInfo(json, info, manager->udid);
SoftBusFree(manager);
AUTH_LOGI(AUTH_FSM, "pack wifi direct info done");
}
char *msg = JSON_PrintUnformatted(json);
if (msg == NULL) {
@ -1193,6 +1381,7 @@ int32_t UnpackDeviceInfoMessage(const DevInfoData *devInfo, NodeInfo *nodeInfo,
} else {
ret = UnpackBt(json, nodeInfo, devInfo->version, isMetaAuth);
}
UnpackWifiDirectInfo(json, nodeInfo);
JSON_Delete(json);
int32_t stateVersion;
if (LnnGetLocalNumInfo(NUM_KEY_STATE_VERSION, &stateVersion) == SOFTBUS_OK) {
@ -1368,7 +1557,11 @@ int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
.flag = compressFlag,
.len = dataLen,
};
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_DEVICE_INFO, lnnEventExtra);
if (PostAuthData(info->connId, !info->isServer, &head, data) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_AUTH_EXCHANGE_DEVICE_INFO_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_DEVICE_INFO, lnnEventExtra);
AUTH_LOGE(AUTH_FSM, "post device info fail");
SoftBusFree(data);
return SOFTBUS_ERR;

View File

@ -182,3 +182,26 @@ if (meta_node_enhanced) {
bus_center_server_src += bus_center_meta_node_src
bus_center_server_inc += bus_center_meta_node_inc
}
native_source_path = rebase_path("$dsoftbus_root_path")
dep_linkfinder = "dsoftbus_enhance/core/bus_center/adapter"
lk_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
"$dep_linkfinder",
],
"value")
if (lk_enhanced) {
import("../../dsoftbus_enhance/core/bus_center/adapter/adapter.gni")
bus_center_server_src += lnn_link_finder_sources
bus_center_server_inc += lnn_link_finder_include_dirs
bus_center_server_deps += lnn_link_finder_deps
} else {
bus_center_server_src += [
"$dsoftbus_root_path/core/adapter/bus_center/src/lnn_link_finder_virtul.c",
]
bus_center_server_inc +=
[ "$dsoftbus_root_path/core/adapter/bus_center/include" ]
}

View File

@ -67,12 +67,19 @@ typedef enum {
NUM_KEY_ACCOUNT_LONG,
NUM_KEY_BLE_START_TIME,
NUM_KEY_STATE_VERSION,
NUM_KEY_STATIC_CAP_LEN,
NUM_KEY_END,
BOOL_KEY_BEGIN,
BOOL_KEY_TLV_NEGOTIATION = BOOL_KEY_BEGIN,
BOOL_KEY_END,
BYTE_KEY_BEGIN,
BYTE_KEY_ACCOUNT_HASH = BYTE_KEY_BEGIN,
BYTE_KEY_REMOTE_PTK,
BYTE_KEY_STATIC_CAPABILITY,
BYTE_KEY_IRK,
BYTE_KEY_PUB_MAC,
BYTE_KEY_BROADCAST_CIPHER_KEY,
BYTE_KEY_BROADCAST_CIPHER_IV,
BYTE_KEY_END,
} InfoKey;

View File

@ -46,8 +46,10 @@ if (dsoftbus_feature_lnn_net) {
"$core_lane_hub_path/lane_manager/src/lnn_lane_common.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_model.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_select.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_query.c",
"$core_lane_hub_path/lane_manager/src/lnn_select_rule.c",
"$core_lane_hub_path/lane_manager/src/lnn_trans_lane.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_reliablity.c",
]
if (enhanced) {

View File

@ -36,6 +36,7 @@ void RegisterLaneIdListener(const ILaneIdStateListener *listener);
void UnregisterLaneIdListener(const ILaneIdStateListener *listener);
int32_t InitLane(void);
void DeinitLane(void);
void FreeLaneId(uint32_t laneId);
#ifdef __cplusplus
}

View File

@ -28,6 +28,7 @@ typedef struct {
void (*Init)(const ILaneIdStateListener *listener);
void (*Deinit)(void);
int32_t (*AllocLane)(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t (*allocLaneByQos)(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t (*FreeLane)(uint32_t laneId);
} LaneInterface;

View File

@ -40,6 +40,7 @@ typedef enum {
LANE_BLE_REUSE,
LANE_COC,
LANE_COC_DIRECT,
LANE_HML,
LANE_LINK_TYPE_BUTT,
} LaneLinkType;
@ -79,15 +80,14 @@ typedef struct {
typedef struct {
BleProtocolType protoType;
char nodeIdHash[NODEID_SHORT_HASH_LEN];
char localUdidHash[UDID_SHORT_HASH_LEN];
char peerUdidHash[SHA_256_HASH_LEN];
char networkId[NETWORK_ID_BUF_LEN];
} BleDirectConnInfo;
typedef struct {
uint16_t protocol;
char localIp[IP_LEN];
char peerIp[IP_LEN];
uint16_t port;
} P2pConnInfo;
typedef struct {
@ -130,7 +130,6 @@ typedef enum {
typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
LaneTransType transType;
uint32_t expectedBw;
} LaneQueryInfo;
typedef struct {
@ -138,18 +137,26 @@ typedef struct {
LaneLinkType linkType[LANE_LINK_TYPE_BUTT];
} LanePreferredLinkList;
typedef struct {
uint32_t minBW;
uint32_t maxLaneLatency;
uint32_t minLaneLatency;
} QosInfo;
typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
char peerBleMac[MAX_MAC_LEN];
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'
int32_t psm;
QosInfo qosRequire;
LaneTransType transType;
uint32_t expectedBw;
int32_t pid;
LanePreferredLinkList expectedLink;
bool networkDelegate;
bool p2pOnly;
ProtocolType acceptableProtocols;
int32_t pid;
//OldInfo
char peerBleMac[MAX_MAC_LEN];
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'
int32_t psm;
uint32_t expectedBw;
LanePreferredLinkList expectedLink;
} TransOption;
typedef struct {
@ -159,7 +166,16 @@ typedef struct {
} requestInfo;
} LaneRequestOption;
QueryResult LnnQueryLaneResource(const LaneQueryInfo *queryInfo);
typedef struct {
int32_t (*lnnQueryLaneResource)(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
uint32_t (*applyLaneId)(LaneType type);
int32_t (*lnnRequestLane)(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t (*lnnFreeLane)(uint32_t laneId);
} LnnLaneManager;
LnnLaneManager* GetLaneManager(void);
int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
uint32_t ApplyLaneId(LaneType type);
int32_t LnnRequestLane(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t LnnFreeLane(uint32_t laneId);

View File

@ -28,14 +28,15 @@ extern "C" {
typedef struct {
char peerNetworkId[NETWORK_ID_BUF_LEN];
char peerBleMac[MAX_MAC_LEN];
int32_t psm;
int32_t pid;
bool networkDelegate;
bool p2pOnly;
LaneTransType transType;
LaneLinkType linkType;
ProtocolType acceptableProtocols;
int32_t pid;
//OldInfo
LaneTransType transType;
char peerBleMac[MAX_MAC_LEN];
int32_t psm;
} LinkRequest;
typedef struct {
@ -65,13 +66,11 @@ typedef struct {
// 'GATT' and 'CoC' protocols under BLE use the same definitions
typedef struct {
BleProtocolType protoType;
int32_t psm; // mark--
char nodeIdHash[NODEID_SHORT_HASH_LEN];
char localUdidHash[UDID_SHORT_HASH_LEN];
char peerUdidHash[SHA_256_HASH_LEN];
char networkId[NETWORK_ID_BUF_LEN];
} BleDirectInfo;
typedef struct {
ListNode node;
LaneLinkType type;
union {
WlanLinkInfo wlan;
@ -80,8 +79,27 @@ typedef struct {
BleLinkInfo ble;
BleDirectInfo bleDirect;
} linkInfo;
uint32_t laneId;
} LaneLinkInfo;
typedef struct {
ListNode node;
LaneLinkType type;
union {
WlanLinkInfo wlan;
P2pLinkInfo p2p;
BrLinkInfo br;
BleLinkInfo ble;
BleDirectInfo bleDirect;
} linkInfo;
bool isReliable;
bool isTimeValid;
uint32_t timeOut;
uint32_t laneScore;
uint32_t laneFload;
uint32_t laneRef;
} LaneResource;
typedef struct {
void (*OnLaneLinkSuccess)(uint32_t reqId, const LaneLinkInfo *linkInfo);
void (*OnLaneLinkFail)(uint32_t reqId, int32_t reason);
@ -99,6 +117,14 @@ void LaneAddP2pAddress(const char *networkId, const char *ipAddr, uint16_t port)
void LaneAddP2pAddressByIp(const char *ipAddr, uint16_t port);
void LaneUpdateP2pAddressByIp(const char *ipAddr, const char *networkId);
int32_t AddLaneResourceItem(const LaneResource *resourceItem);
int32_t DelLaneResourceItem(const LaneResource *resourceItem);
int32_t AddLinkInfoItem(const LaneLinkInfo *linkInfoItem);
int32_t DelLinkInfoItem(uint32_t laneId);
int32_t FindLaneLinkInfoByLaneId(uint32_t laneId, LaneLinkInfo *linkInfoitem);
int32_t ConvertToLaneResource(const LaneLinkInfo *linkInfo, LaneResource *laneResourceInfo);
int32_t DelLaneResourceItemWithDelayDestroy(LaneResource *resourceItem, uint32_t laneId, bool *isDelayDestroy);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,30 @@
/*
* 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.
*/
#ifndef LNN_LANE_QUERY_H
#define LNN_LANE_QUERY_H
#include "lnn_lane_interface.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t QueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,32 @@
/*
* 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.
*/
#ifndef LNN_LANE_RELIABLITY_H
#define LNN_LANE_RELIABLITY_H
#include "lnn_lane_link.h"
#ifdef __cplusplus
extern "C" {
#endif
bool LaneDetectReliablity(const LaneResource *resourceItem);
int32_t LaneDetectFload(const LaneResource *resourceItem);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -25,13 +25,19 @@ extern "C" {
typedef struct {
LaneTransType transType;
QosInfo qosRequire;
//OldInfo
uint32_t expectedBw;
LanePreferredLinkList list;
} LaneSelectParam;
int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
LanePreferredLinkList *recommendList, uint32_t *listNum);
int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *request,
LanePreferredLinkList *recommendList);
#ifdef __cplusplus
}
#endif

View File

@ -17,6 +17,7 @@
#define LNN_SELECT_RULE_H
#include "softbus_common.h"
#include "lnn_lane_select.h"
#include "lnn_lane_interface.h"
#ifdef __cplusplus
@ -25,6 +26,13 @@ extern "C" {
#define UNACCEPT_SCORE 20
typedef enum {
HIGH_BAND_WIDTH = 0,
MIDDLE_BAND_WIDTH,
LOW_BAND_WIDTH,
BW_TYPE_BUTT,
} BandWidthType;
typedef struct {
bool available;
bool (*IsEnable)(const char *networkId);
@ -35,6 +43,9 @@ int32_t GetWlanLinkedFrequency(void);
LinkAttribute *GetLinkAttrByLinkType(LaneLinkType linkType);
int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *request,
LanePreferredLinkList *recommendList);
#ifdef __cplusplus
}
#endif

View File

@ -22,7 +22,18 @@
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,
} 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);
#ifdef __cplusplus
}

View File

@ -18,14 +18,17 @@
#include <securec.h>
#include <string.h>
#include "anonymizer.h"
#include "common_list.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_lane_assign.h"
#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_query.h"
#include "lnn_lane_score.h"
#include "lnn_lane_select.h"
#include "lnn_log.h"
@ -268,6 +271,49 @@ uint32_t ApplyLaneId(LaneType type)
return AllocLaneId(type);
}
void FreeLaneId(uint32_t laneId)
{
return DestroyLaneId(laneId);
}
static int32_t LnnRequestLaneByQos(uint32_t laneId, const LaneRequestOption *request,
const ILaneListener *listener)
{
if (RequestInfoCheck(request, listener) == false) {
LNN_LOGE(LNN_LANE, "lane requestInfo by qos invalid");
return SOFTBUS_ERR;
}
if (g_laneObject[request->type] == NULL) {
LNN_LOGE(LNN_LANE, "laneType=%d is not supported", request->type);
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_LANE, "laneRequestByQos, laneId=%u, laneType=%d, transType=%d, "
"minBW=%u, maxLaneLatency=%u, minLaneLatency=%u",
laneId, request->type, request->requestInfo.trans.transType,
request->requestInfo.trans.qosRequire.minBW,
request->requestInfo.trans.qosRequire.maxLaneLatency,
request->requestInfo.trans.qosRequire.minLaneLatency);
int32_t result = g_laneObject[request->type]->allocLaneByQos(laneId, request, listener);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc lane by qos fail, laneId=%u, result=%d", laneId, result);
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_LANE, "request lane by qos success, laneId=%u", laneId);
return SOFTBUS_OK;
}
static LnnLaneManager g_LaneManager = {
.lnnQueryLaneResource = LnnQueryLaneResource,
.applyLaneId = ApplyLaneId,
.lnnRequestLane = LnnRequestLaneByQos,
.lnnFreeLane = LnnFreeLane,
};
LnnLaneManager* GetLaneManager(void)
{
return &g_LaneManager;
}
int32_t LnnRequestLane(uint32_t laneId, const LaneRequestOption *request,
const ILaneListener *listener)
{
@ -306,16 +352,24 @@ int32_t LnnFreeLane(uint32_t laneId)
LNN_LOGE(LNN_LANE, "freeLane fail, result:%d", result);
return SOFTBUS_ERR;
}
DestroyLaneId(laneId);
return SOFTBUS_OK;
}
QueryResult LnnQueryLaneResource(const LaneQueryInfo *queryInfo)
int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (queryInfo == NULL) {
return QUERY_RESULT_REQUEST_ILLEGAL;
if (queryInfo == NULL || qosInfo == NULL) {
LNN_LOGE(LNN_LANE, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
return QUERY_RESULT_OK;
if (!LnnGetOnlineStateById(queryInfo->networkId, CATEGORY_NETWORK_ID)) {
char *anonyNetworkId = NULL;
Anonymize(queryInfo->networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "device not online, cancel query peerNetworkId:%s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
return QueryLaneResource(queryInfo, qosInfo);
}
static void LaneInitChannelRatingDelay(void *para)

View File

@ -71,6 +71,20 @@ static int32_t P2pInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
profile->phyChannel = linkInfo->linkInfo.p2p.channel;
return SOFTBUS_OK;
}
static int32_t HmlInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
connInfo->type = LANE_HML;
if (memcpy_s(&connInfo->connInfo.p2p, sizeof(P2pConnInfo),
&linkInfo->linkInfo.p2p.connInfo, sizeof(P2pConnInfo)) != EOK) {
return SOFTBUS_ERR;
}
profile->linkType = LANE_HML;
profile->bw = linkInfo->linkInfo.p2p.bw;
profile->phyChannel = linkInfo->linkInfo.p2p.channel;
return SOFTBUS_OK;
}
static int32_t P2pReuseInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
connInfo->type = LANE_P2P_REUSE;
@ -107,16 +121,8 @@ static int32_t Wlan5GInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connIn
static int32_t BleDirectInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
if (memcpy_s(connInfo->connInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN,
linkInfo->linkInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(connInfo->connInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN,
linkInfo->linkInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(connInfo->connInfo.bleDirect.peerUdidHash, SHA_256_HASH_LEN,
linkInfo->linkInfo.bleDirect.peerUdidHash, SHA_256_HASH_LEN) != EOK) {
if (strcpy_s(connInfo->connInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN,
linkInfo->linkInfo.bleDirect.networkId) != EOK) {
return SOFTBUS_ERR;
}
connInfo->type = LANE_BLE_DIRECT;
@ -145,6 +151,7 @@ static LinkInfoProc g_funcList[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = BrInfoProc,
[LANE_BLE] = BleInfoProc,
[LANE_P2P] = P2pInfoProc,
[LANE_HML] = HmlInfoProc,
[LANE_WLAN_2P4G] = Wlan2P4GInfoProc,
[LANE_WLAN_5G] = Wlan5GInfoProc,
[LANE_P2P_REUSE] = P2pReuseInfoProc,
@ -229,4 +236,4 @@ void LnnDeinitLaneLooper(void)
DestroyLooper(looper);
SetLooper(LOOP_TYPE_LANE, NULL);
}
}
}

View File

@ -17,6 +17,7 @@
#include <securec.h>
#include "lnn_trans_lane.h"
#include "anonymizer.h"
#include "bus_center_info_key.h"
#include "bus_center_manager.h"
@ -30,6 +31,7 @@
#include "lnn_network_manager.h"
#include "lnn_node_info.h"
#include "lnn_physical_subnet_manager.h"
#include "lnn_lane_common.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_crypto.h"
#include "softbus_conn_ble_connection.h"
@ -41,11 +43,334 @@
#include "softbus_utils.h"
#include "softbus_def.h"
#define DELAY_DESTROY_LANE_TIME 5000
typedef int32_t (*LaneLinkByType)(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback);
static SoftBusMutex g_laneResourceMutex;
static ListNode g_laneResourceList;
static ListNode g_LinkInfoList;
static int32_t LaneLock(void)
{
return SoftBusMutexLock(&g_laneResourceMutex);
}
static void LaneUnlock(void)
{
(void)SoftBusMutexUnlock(&g_laneResourceMutex);
}
static bool FindLaneResource(const LaneResource *resourceItem, LaneResource *item)
{
switch (resourceItem->type) {
case LANE_BR:
if (strncmp(resourceItem->linkInfo.br.brMac, item->linkInfo.br.brMac, BT_MAC_LEN) != 0) {
return false;
}
break;
case LANE_BLE:
case LANE_COC:
if (strncmp(resourceItem->linkInfo.ble.bleMac, item->linkInfo.ble.bleMac, BT_MAC_LEN) != 0) {
return false;
}
break;
case LANE_P2P:
case LANE_HML:
if (strncmp(resourceItem->linkInfo.p2p.connInfo.peerIp,
item->linkInfo.p2p.connInfo.peerIp, IP_LEN) != 0) {
return false;
}
break;
case LANE_WLAN_5G:
case LANE_WLAN_2P4G:
case LANE_P2P_REUSE:
if (strncmp(resourceItem->linkInfo.wlan.connInfo.addr,
item->linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN) != 0) {
return false;
}
break;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (strcmp(resourceItem->linkInfo.bleDirect.networkId, item->linkInfo.bleDirect.networkId) != 0) {
return false;
}
break;
default:
return false;
}
return true;
}
static LaneResource* LaneResourceIsExist(const LaneResource *resourceItem)
{
LaneResource *item = NULL;
LaneResource *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_laneResourceList, LaneResource, node) {
if (resourceItem->type == item->type) {
if (FindLaneResource(resourceItem, item)) {
return item;
}
}
}
return NULL;
}
static int32_t CreateResourceItem(const LaneResource *inputResource, LaneResource *outputResource)
{
switch (inputResource->type) {
case LANE_BR:
if (memcpy_s(&(outputResource->linkInfo.br), sizeof(BrLinkInfo),
&(inputResource->linkInfo.br), sizeof(BrLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_BLE:
case LANE_COC:
if (memcpy_s(&(outputResource->linkInfo.ble), sizeof(BleLinkInfo),
&(inputResource->linkInfo.ble), sizeof(BleLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_P2P:
case LANE_HML:
if (memcpy_s(&(outputResource->linkInfo.p2p), sizeof(P2pLinkInfo),
&(inputResource->linkInfo.p2p), sizeof(P2pLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_WLAN_5G:
case LANE_WLAN_2P4G:
case LANE_P2P_REUSE:
if (memcpy_s(&(outputResource->linkInfo.wlan), sizeof(WlanLinkInfo),
&(inputResource->linkInfo.wlan), sizeof(WlanLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (memcpy_s(&(outputResource->linkInfo.bleDirect), sizeof(BleDirectInfo),
&(inputResource->linkInfo.bleDirect), sizeof(BleDirectInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
default:
return SOFTBUS_ERR;
}
outputResource->type = inputResource->type;
outputResource->isReliable = inputResource->isReliable;
outputResource->isTimeValid = inputResource->isTimeValid;
outputResource->timeOut = 0;
outputResource->laneScore = inputResource->laneScore;
outputResource->laneFload = inputResource->laneFload;
outputResource->laneRef = 1;
return SOFTBUS_OK;
}
int32_t AddLaneResourceItem(const LaneResource *inputResource)
{
if (inputResource == NULL) {
LNN_LOGE(LNN_LANE, "inputResource is nullptr");
return SOFTBUS_INVALID_PARAM;
}
LaneResource *resourceItem = (LaneResource *)SoftBusMalloc(sizeof(LaneResource));
if (resourceItem == NULL) {
LNN_LOGE(LNN_LANE, "resourceItem malloc fail");
return SOFTBUS_MALLOC_ERR;
}
if (CreateResourceItem(inputResource, resourceItem) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "create resourceItem fail");
return SOFTBUS_ERR;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
LaneResource* item = LaneResourceIsExist(resourceItem);
if (item != NULL) {
item->laneRef++;
SoftBusFree(resourceItem);
} else {
ListAdd(&g_laneResourceList, &resourceItem->node);
}
LaneUnlock();
return SOFTBUS_OK;
}
int32_t DelLaneResourceItemWithDelayDestroy(LaneResource *resourceItem, uint32_t laneId, bool *isDelayDestroy)
{
if (resourceItem == NULL || isDelayDestroy == NULL) {
LNN_LOGE(LNN_LANE, "resourceItem or isDelayDestroy is nullptr");
return SOFTBUS_INVALID_PARAM;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
LaneResource* item = LaneResourceIsExist(resourceItem);
if (item != NULL) {
if (item->type == LANE_HML && item->laneRef == 1) {
if (LnnLanePostMsgToHandler(MSG_TYPE_DELAY_DESTROY_LINK, laneId, *isDelayDestroy, item,
DELAY_DESTROY_LANE_TIME) == SOFTBUS_OK) {
*isDelayDestroy = true;
LaneUnlock();
return SOFTBUS_OK;
}
}
if ((--item->laneRef) == 0) {
ListDelete(&item->node);
SoftBusFree(item);
}
}
*isDelayDestroy = false;
LaneUnlock();
return SOFTBUS_OK;
}
int32_t DelLaneResourceItem(const LaneResource *resourceItem)
{
if (resourceItem == NULL) {
LNN_LOGE(LNN_LANE, "resourceItem is nullptr");
return SOFTBUS_INVALID_PARAM;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
LaneResource* item = LaneResourceIsExist(resourceItem);
if (item != NULL) {
if ((--item->laneRef) == 0) {
ListDelete(&item->node);
SoftBusFree(item);
}
}
LaneUnlock();
return SOFTBUS_OK;
}
static int32_t CreateLinkInfoItem(const LaneLinkInfo *inputLinkInfo, LaneLinkInfo *outputLinkInfo)
{
switch (inputLinkInfo->type) {
case LANE_BR:
if (memcpy_s(&(outputLinkInfo->linkInfo.br), sizeof(BrLinkInfo),
&(inputLinkInfo->linkInfo.br), sizeof(BrLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_BLE:
case LANE_COC:
if (memcpy_s(&(outputLinkInfo->linkInfo.ble), sizeof(BleLinkInfo),
&(inputLinkInfo->linkInfo.ble), sizeof(BleLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_P2P:
case LANE_HML:
if (memcpy_s(&(outputLinkInfo->linkInfo.p2p), sizeof(P2pLinkInfo),
&(inputLinkInfo->linkInfo.p2p), sizeof(P2pLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_WLAN_5G:
case LANE_WLAN_2P4G:
case LANE_P2P_REUSE:
if (memcpy_s(&(outputLinkInfo->linkInfo.wlan), sizeof(WlanLinkInfo),
&(inputLinkInfo->linkInfo.wlan), sizeof(WlanLinkInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (memcpy_s(&(outputLinkInfo->linkInfo.bleDirect), sizeof(BleDirectInfo),
&(inputLinkInfo->linkInfo.bleDirect), sizeof(BleDirectInfo)) != EOK) {
return SOFTBUS_ERR;
}
break;
default:
return SOFTBUS_ERR;
}
outputLinkInfo->type = inputLinkInfo->type;
outputLinkInfo->laneId = inputLinkInfo->laneId;
return SOFTBUS_OK;
}
int32_t AddLinkInfoItem(const LaneLinkInfo *inputLinkInfo)
{
if (inputLinkInfo == NULL) {
LNN_LOGE(LNN_LANE, "inputLinkInfo is nullptr");
return SOFTBUS_INVALID_PARAM;
}
LaneLinkInfo *linkInfoItem = (LaneLinkInfo *)SoftBusMalloc(sizeof(LaneLinkInfo));
if (linkInfoItem == NULL) {
LNN_LOGE(LNN_LANE, "linkInfoItem malloc fail");
return SOFTBUS_MALLOC_ERR;
}
if (CreateLinkInfoItem(inputLinkInfo, linkInfoItem) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "create linkInfoItem fail");
return SOFTBUS_ERR;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
ListAdd(&g_LinkInfoList, &linkInfoItem->node);
LaneUnlock();
return SOFTBUS_OK;
}
int32_t DelLinkInfoItem(uint32_t laneId)
{
if (laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "laneId is invalid");
return SOFTBUS_INVALID_PARAM;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
LaneLinkInfo *item = NULL;
LaneLinkInfo *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_LinkInfoList, LaneLinkInfo, node) {
if (item->laneId == laneId) {
ListDelete(&item->node);
SoftBusFree(item);
}
}
LaneUnlock();
return SOFTBUS_OK;
}
int32_t FindLaneLinkInfoByLaneId(uint32_t laneId, LaneLinkInfo *linkInfoitem)
{
if (laneId == INVALID_LANE_ID || linkInfoitem == NULL) {
LNN_LOGE(LNN_LANE, "laneId or linkInfoItem is invalid");
return SOFTBUS_INVALID_PARAM;
}
if (LaneLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane lock fail");
return SOFTBUS_LOCK_ERR;
}
LaneLinkInfo *item = NULL;
LaneLinkInfo *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_LinkInfoList, LaneLinkInfo, node) {
if (item->laneId == laneId) {
if (CreateLinkInfoItem(item, linkInfoitem) != SOFTBUS_OK) {
LaneUnlock();
LNN_LOGE(LNN_LANE, "create linkInfoItem fail");
return SOFTBUS_ERR;
}
LaneUnlock();
return SOFTBUS_OK;
}
}
LaneUnlock();
LNN_LOGE(LNN_LANE, "find laneLinkInfo by laneId fail");
return SOFTBUS_ERR;
}
static bool LinkTypeCheck(LaneLinkType type)
{
static const LaneLinkType supportList[] = { LANE_P2P, LANE_WLAN_2P4G, LANE_WLAN_5G, LANE_BR, LANE_BLE,
static const LaneLinkType supportList[] = { LANE_P2P, LANE_HML, LANE_WLAN_2P4G, LANE_WLAN_5G, LANE_BR, LANE_BLE,
LANE_BLE_DIRECT, LANE_P2P_REUSE, LANE_COC, LANE_COC_DIRECT };
uint32_t size = sizeof(supportList) / sizeof(LaneLinkType);
for (uint32_t i = 0; i < size; i++) {
@ -66,6 +391,61 @@ static int32_t IsLinkRequestValid(const LinkRequest *reqInfo)
return SOFTBUS_OK;
}
int32_t ConvertToLaneResource(const LaneLinkInfo *linkInfo, LaneResource *laneResourceInfo)
{
if (linkInfo == NULL || laneResourceInfo == NULL) {
LNN_LOGE(LNN_LANE, "linkInfo or laneResourceInfo is nullptr");
return SOFTBUS_INVALID_PARAM;
}
laneResourceInfo->type = linkInfo->type;
switch (linkInfo->type) {
case LANE_BR:
if (memcpy_s(&(laneResourceInfo->linkInfo.br), sizeof(BrLinkInfo),
&(linkInfo->linkInfo.br), sizeof(BrLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo br memcpy_s fail, linkInfo type=%d", linkInfo->type);
return SOFTBUS_ERR;
}
break;
case LANE_BLE:
case LANE_COC:
if (memcpy_s(&(laneResourceInfo->linkInfo.ble), sizeof(BleLinkInfo),
&(linkInfo->linkInfo.ble), sizeof(BleLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo ble memcpy_s fail, linkInfo type=%d", linkInfo->type);
return SOFTBUS_ERR;
}
break;
case LANE_P2P:
case LANE_HML:
if (memcpy_s(&(laneResourceInfo->linkInfo.p2p), sizeof(P2pConnInfo),
&(linkInfo->linkInfo.p2p), sizeof(P2pConnInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo p2p memcpy_s fail, linkInfo type=%d", linkInfo->type);
return SOFTBUS_ERR;
}
break;
case LANE_WLAN_5G:
case LANE_WLAN_2P4G:
case LANE_P2P_REUSE:
if (memcpy_s(&(laneResourceInfo->linkInfo.wlan), sizeof(WlanLinkInfo),
&(linkInfo->linkInfo.wlan), sizeof(WlanLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo wlan memcpy_s fail, linkInfo type=%d", linkInfo->type);
return SOFTBUS_ERR;
}
break;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (memcpy_s(&(laneResourceInfo->linkInfo.bleDirect), sizeof(BleDirectInfo),
&(linkInfo->linkInfo.bleDirect), sizeof(BleDirectInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo bleDirect memcpy_s fail, linkInfo type=%d", linkInfo->type);
return SOFTBUS_ERR;
}
break;
default:
LNN_LOGE(LNN_LANE, "curr linkInfo type=%d is not supported", linkInfo->type);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t LaneLinkOfBr(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
{
LaneLinkInfo linkInfo;
@ -141,7 +521,7 @@ void LaneAddP2pAddress(const char *networkId, const char *ipAddr, uint16_t port)
item->port = port;
item->cnt++;
} else {
P2pAddrNode *p2pAddrNode = (P2pAddrNode*)SoftBusMalloc(sizeof(P2pAddrNode));
P2pAddrNode *p2pAddrNode = (P2pAddrNode *)SoftBusMalloc(sizeof(P2pAddrNode));
if (p2pAddrNode == NULL) {
SoftBusMutexUnlock(&g_P2pAddrList.lock);
return;
@ -184,7 +564,7 @@ void LaneAddP2pAddressByIp(const char *ipAddr, uint16_t port)
item->port = port;
item->cnt++;
} else {
P2pAddrNode *p2pAddrNode = (P2pAddrNode*)SoftBusMalloc(sizeof(P2pAddrNode));
P2pAddrNode *p2pAddrNode = (P2pAddrNode *)SoftBusMalloc(sizeof(P2pAddrNode));
if (p2pAddrNode == NULL) {
SoftBusMutexUnlock(&g_P2pAddrList.lock);
return;
@ -308,52 +688,15 @@ static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const L
return SOFTBUS_OK;
}
static int32_t LaneLinkOfBleDirectCommon(const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
{
unsigned char peerUdid[UDID_BUF_LEN] = {0};
unsigned char peerNetwordIdHash[SHA_256_HASH_LEN] = {0};
unsigned char localUdidHash[SHA_256_HASH_LEN] = {0};
if (SoftBusGenerateStrHash((const unsigned char*)reqInfo->peerNetworkId, strlen(reqInfo->peerNetworkId),
peerNetwordIdHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
const NodeInfo* nodeInfo = LnnGetLocalNodeInfo();
if (SoftBusGenerateStrHash((const unsigned char*)nodeInfo->deviceInfo.deviceUdid,
strlen(nodeInfo->deviceInfo.deviceUdid), localUdidHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_DEV_UDID,
(char *)peerUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (SoftBusGenerateStrHash(peerUdid, strlen((char*)peerUdid),
(unsigned char *)linkInfo->linkInfo.bleDirect.peerUdidHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (memcpy_s(linkInfo->linkInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN, peerNetwordIdHash,
NODEID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(linkInfo->linkInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN, localUdidHash, UDID_SHORT_HASH_LEN) !=
EOK) {
return SOFTBUS_ERR;
}
linkInfo->type = LANE_BLE_DIRECT;
return SOFTBUS_OK;
}
static int32_t LaneLinkOfGattDirect(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
{
LaneLinkInfo linkInfo;
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
if (LaneLinkOfBleDirectCommon(reqInfo, &linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "ble direct common failed");
return SOFTBUS_ERR;
if (strcpy_s(linkInfo.linkInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN, reqInfo->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId fail");
return SOFTBUS_MEM_ERR;
}
linkInfo.type = LANE_BLE_DIRECT;
linkInfo.linkInfo.bleDirect.protoType = BLE_GATT;
callback->OnLaneLinkSuccess(reqId, &linkInfo);
return SOFTBUS_OK;
@ -379,7 +722,6 @@ static int32_t LaneLinkOfP2pReuse(uint32_t reqId, const LinkRequest *reqInfo, co
if (memcpy_s(linkInfo.linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN, ipAddr, MAX_SOCKET_ADDR_LEN) != EOK) {
return SOFTBUS_ERR;
}
callback->OnLaneLinkSuccess(reqId, &linkInfo);
return SOFTBUS_OK;
}
@ -481,16 +823,6 @@ static int32_t LaneLinkOfWlan(uint32_t reqId, const LinkRequest *reqInfo, const
LaneLinkInfo linkInfo;
int32_t port = 0;
int32_t ret = SOFTBUS_OK;
NodeInfo node;
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(reqInfo->peerNetworkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
LNN_LOGW(LNN_LANE, "can not get peer node");
return SOFTBUS_ERR;
}
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) && !LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
LNN_LOGE(LNN_LANE, "peer node is not wifi online");
return SOFTBUS_ERR;
}
ProtocolType acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
if (reqInfo->transType == LANE_T_MSG || reqInfo->transType == LANE_T_BYTE) {
acceptableProtocols |= LNN_PROTOCOL_NIP;
@ -542,7 +874,6 @@ static int32_t LaneLinkOfWlan(uint32_t reqId, const LinkRequest *reqInfo, const
if (!isConnected) {
LNN_LOGE(LNN_LANE, "wlan is disconnected");
}
FillWlanLinkInfo(&linkInfo, is5GBand, channel, (uint16_t)port, protocol);
callback->OnLaneLinkSuccess(reqId, &linkInfo);
return SOFTBUS_OK;
@ -581,11 +912,13 @@ static int32_t LaneLinkOfCocDirect(uint32_t reqId, const LinkRequest *reqInfo, c
{
LaneLinkInfo linkInfo;
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
if (LaneLinkOfBleDirectCommon(reqInfo, &linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "ble direct common failed");
return SOFTBUS_ERR;
if (strcpy_s(linkInfo.linkInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN, reqInfo->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId fail");
return SOFTBUS_MEM_ERR;
}
linkInfo.type = LANE_COC_DIRECT;
linkInfo.linkInfo.bleDirect.protoType = BLE_COC;
callback->OnLaneLinkSuccess(reqId, &linkInfo);
return SOFTBUS_OK;
}
@ -594,6 +927,7 @@ static LaneLinkByType g_linkTable[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = LaneLinkOfBr,
[LANE_BLE] = LaneLinkOfBle,
[LANE_P2P] = LaneLinkOfP2p,
[LANE_HML] = LaneLinkOfP2p,
[LANE_WLAN_2P4G] = LaneLinkOfWlan,
[LANE_WLAN_5G] = LaneLinkOfWlan,
[LANE_BLE_REUSE] = LaneLinkOfBleReuse,
@ -633,8 +967,8 @@ void DestroyLink(const char *networkId, uint32_t reqId, LaneLinkType type, int32
LNN_LOGE(LNN_LANE, "the networkId is nullptr");
return;
}
if (type == LANE_P2P) {
LNN_LOGI(LNN_LANE, "type=LANE_P2P");
if (type == LANE_P2P || type == LANE_HML) {
LNN_LOGI(LNN_LANE, "type=LANE_WD: %d", type);
LaneDeleteP2pAddress(networkId, false);
LnnDisconnectP2p(networkId, pid, reqId);
} else {
@ -645,6 +979,12 @@ void DestroyLink(const char *networkId, uint32_t reqId, LaneLinkType type, int32
int32_t InitLaneLink(void)
{
LaneInitP2pAddrList();
if (SoftBusMutexInit(&g_laneResourceMutex, NULL) != SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "g_laneResourceMutex init fail");
return SOFTBUS_ERR;
}
ListInit(&g_laneResourceList);
ListInit(&g_LinkInfoList);
return SOFTBUS_OK;
}

View File

@ -38,6 +38,9 @@
#include "softbus_proxychannel_pipeline.h"
#include "wifi_direct_manager.h"
#include "lnn_trans_lane.h"
#include "lnn_lane_interface.h"
typedef struct {
uint32_t requestId;
int64_t authId;
@ -47,6 +50,7 @@ typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
uint32_t laneLinkReqId;
int32_t pid;
LaneLinkType laneType;
LaneLinkCb cb;
} LaneLinkRequestInfo;
@ -55,6 +59,7 @@ typedef struct {
int32_t p2pModuleGenId;
bool networkDelegate;
bool p2pOnly;
uint32_t bandWidth;
} P2pRequestInfo;
typedef struct {
@ -161,7 +166,7 @@ static void DisconnectP2pWithoutAuthConn(int32_t pid, const char *mac, int32_t l
struct WifiDirectConnectInfo info;
(void)memset_s(&info, sizeof(info), 0, sizeof(info));
info.requestId = GetWifiDirectManager()->getRequestId();
info.connectType = WIFI_DIRECT_CONNECT_TYPE_WIFI_DIRECT;
info.connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
info.negoChannel = NULL;
info.pid = pid;
info.linkId = linkId;
@ -231,7 +236,7 @@ static void OnConnOpenFailedForDisconnect(uint32_t requestId, int32_t reason)
struct WifiDirectConnectInfo info;
(void)memset_s(&info, sizeof(info), 0, sizeof(info));
info.requestId = GetWifiDirectManager()->getRequestId();
info.connectType = WIFI_DIRECT_CONNECT_TYPE_WIFI_DIRECT;
info.connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
info.negoChannel = NULL;
if (GetP2pLinkDownParam(requestId, info.requestId, &info) != SOFTBUS_OK) {
return;
@ -256,7 +261,7 @@ static void OnConnOpenedForDisconnect(uint32_t requestId, int64_t authId)
struct DefaultNegotiateChannel channel;
DefaultNegotiateChannelConstructor(&channel, authId);
info.negoChannel = (struct WifiDirectNegotiateChannel*)&channel;
info.connectType = WIFI_DIRECT_CONNECT_TYPE_WIFI_DIRECT;
info.connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
if (GetP2pLinkDownParam(requestId, info.requestId, &info) != SOFTBUS_OK) {
goto FAIL;
}
@ -320,6 +325,7 @@ static int32_t GetP2pLinkReqParamByChannelRequetId(
LNN_LOGE(LNN_LANE, "get remote p2p mac fail");
return SOFTBUS_ERR;
}
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->pid = item->laneRequestInfo.pid;
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
item->p2pInfo.p2pRequestId = p2pRequestId;
@ -356,9 +362,14 @@ static int32_t GetP2pLinkReqParamByAuthId(uint32_t authRequestId, int32_t p2pReq
int32_t ret = strcpy_s(wifiDirectInfo->remoteNetworkId, sizeof(wifiDirectInfo->remoteNetworkId),
item->laneRequestInfo.networkId);
LNN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_ERR, LNN_LANE, "copy networkId failed");
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
wifiDirectInfo->connectType =
item->p2pInfo.p2pOnly ? WIFI_DIRECT_CONNECT_TYPE_P2P : WIFI_DIRECT_CONNECT_TYPE_WIFI_DIRECT;
if (item->p2pInfo.p2pOnly) {
wifiDirectInfo->connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P;
} else {
wifiDirectInfo->connectType = ((item->laneRequestInfo.laneType == LANE_HML) ?
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P);
}
item->p2pInfo.p2pRequestId = p2pRequestId;
LinkUnlock();
return SOFTBUS_OK;
@ -497,7 +508,11 @@ static void OnWifiDirectConnectSuccess(int32_t p2pRequestId, const struct WifiDi
}
LNN_LOGI(LNN_LANE, "requestId=%d p2pGenLinkId=%d", p2pRequestId, link->linkId);
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
linkInfo.type = LANE_P2P;
if (link->linkType == WIFI_DIRECT_LINK_TYPE_HML) {
linkInfo.type = LANE_HML;
} else {
linkInfo.type = LANE_P2P;
}
linkInfo.linkInfo.p2p.bw = LANE_BW_RANDOM;
P2pConnInfo *p2p = (P2pConnInfo *)&(linkInfo.linkInfo.p2p.connInfo);
if (strcpy_s(p2p->localIp, IP_LEN, link->localIp) != EOK) {
@ -572,6 +587,12 @@ 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;
}
item->laneRequestInfo.laneLinkReqId = laneLinkReqId;
item->laneRequestInfo.pid = request->pid;
item->auth.authId = INVAILD_AUTH_ID;
@ -581,6 +602,7 @@ static int32_t AddConnRequestItem(uint32_t authRequestId, int32_t p2pRequestId,
item->p2pInfo.p2pOnly = request->p2pOnly;
item->p2pInfo.p2pRequestId = p2pRequestId;
item->proxyChannelInfo.requestId = channelRequestId;
item->laneRequestInfo.laneType = request->linkType;
if (LinkLock() != 0) {
SoftBusFree(item);
LNN_LOGE(LNN_LANE, "lock fail, add conn request fail");
@ -662,7 +684,7 @@ static void OnProxyChannelOpened(int32_t channelRequestId, int32_t channelId)
LNN_LOGI(LNN_LANE, "channelRequestId=%d, channelId=%d", channelRequestId, channelId);
struct WifiDirectConnectInfo info;
info.requestId = GetWifiDirectManager()->getRequestId();
info.connectType = WIFI_DIRECT_CONNECT_TYPE_WIFI_DIRECT;
info.connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
struct FastConnectNegotiateChannel channel;
FastConnectNegotiateChannelConstructor(&channel, channelId);

View File

@ -0,0 +1,346 @@
/*
* 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 "lnn_lane_query.h"
#include <securec.h>
#include "bus_center_info_key.h"
#include "bus_center_manager.h"
#include "lnn_feature_capability.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#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"
#define QOS_MIN_BANDWIDTH (500 * 1024)
#define QOS_P2P_ONLY_BANDWIDTH (160 * 1024 * 1024)
typedef struct {
bool available;
int32_t (*QueryLink)(const char *networkId);
} LinkState;
static void GetFileLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BR;
}
}
static void GetStreamLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
}
static void GetMsgLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
}
}
static void GetBytesLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
}
}
static int32_t GetLaneResource(LaneTransType transType, LaneLinkType *optLink, uint32_t *linkNum,
bool isHighBand)
{
LaneLinkType defaultLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(defaultLink, sizeof(defaultLink), -1, sizeof(defaultLink));
uint32_t optLinkMaxNum = *linkNum;
uint32_t index = 0;
switch (transType) {
case LANE_T_MSG:
GetMsgLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_BYTE:
GetBytesLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_FILE:
GetFileLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_RAW_STREAM:
case LANE_T_COMMON_VIDEO:
case LANE_T_COMMON_VOICE:
GetStreamLaneLink(defaultLink, &index, isHighBand);
break;
default:
LNN_LOGE(LNN_LANE, "lane type=%d is not supported", transType);
return SOFTBUS_ERR;
}
*linkNum = 0;
if (memcpy_s(optLink, optLinkMaxNum * sizeof(LaneLinkType), defaultLink, sizeof(defaultLink)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy default linkList to optinal fail");
return SOFTBUS_MEM_ERR;
}
*linkNum = index;
return SOFTBUS_OK;
}
static bool GetNetCap(const char *networkId, int32_t *local, int32_t *remote)
{
int32_t ret = LnnGetLocalNumInfo(NUM_KEY_NET_CAP, local);
if (ret != SOFTBUS_OK || *local < 0) {
LNN_LOGE(LNN_LANE, "LnnGetLocalNumInfo err, ret = %d, local = %d", ret, *local);
return false;
}
ret = LnnGetRemoteNumInfo(networkId, NUM_KEY_NET_CAP, remote);
if (ret != SOFTBUS_OK || *remote < 0) {
LNN_LOGE(LNN_LANE, "LnnGetRemoteNumInfo err, ret = %d, remote = %d", ret, *remote);
return false;
}
return true;
}
static int32_t BrLinkState(const char *networkId)
{
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_BR))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%d", local);
return SOFTBUS_BLUETOOTH_OFF;
}
if (!(remote & (1 << BIT_BR))) {
LNN_LOGE(LNN_LANE, "remote bluetooth close, remote=%d", remote);
return SOFTBUS_BLUETOOTH_OFF;
}
LNN_LOGI(LNN_LANE, "br link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t BleLinkState(const char *networkId)
{
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_BLE))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%d", local);
return SOFTBUS_BLUETOOTH_OFF;
}
if (!(remote & (1 << BIT_BLE))) {
LNN_LOGE(LNN_LANE, "remote bluetooth close, remote=%d", remote);
return SOFTBUS_BLUETOOTH_OFF;
}
LNN_LOGI(LNN_LANE, "ble link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t WlanLinkState(const char *networkId)
{
int32_t local, remote;
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_WIFI))) {
LNN_LOGE(LNN_LANE, "local wifi close, local=%d", local);
return SOFTBUS_WIFI_DISCONNECT;
}
if (!(remote & (1 << BIT_WIFI))) {
LNN_LOGE(LNN_LANE, "remote wifi close, remote=%d", remote);
return SOFTBUS_WIFI_DISCONNECT;
}
LNN_LOGI(LNN_LANE, "wifi link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t P2pLinkState(const char *networkId)
{
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (((local & (1 << BIT_WIFI_P2P)) == 0) || ((remote & (1 << BIT_WIFI_P2P)) == 0)) {
LNN_LOGE(LNN_LANE, "p2p capa disable, local=%d, remote=%d", local, remote);
return SOFTBUS_P2P_NOT_SUPPORT;
}
int32_t ret = GetWifiDirectManager()->prejudgeAvailability(networkId, WIFI_DIRECT_LINK_TYPE_P2P);
if (ret == V1_ERROR_GC_CONNECTED_TO_ANOTHER_DEVICE) {
return SOFTBUS_P2P_ROLE_CONFLICT;
}
return ret;
}
static int32_t HmlLinkState(const char *networkId)
{
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
uint64_t feature = LnnGetFeatureCapabilty();
if (!IsFeatureSupport(feature, BIT_WIFI_DIRECT_TLV_NEGOTIATION)) {
LNN_LOGE(LNN_LANE, "local feature not supported");
return SOFTBUS_HML_NOT_SUPPORT;
}
bool result = false;
if (LnnGetRemoteBoolInfo(networkId, BOOL_KEY_TLV_NEGOTIATION, &result) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get remote feature failed");
return SOFTBUS_ERR;
}
if (!result) {
LNN_LOGE(LNN_LANE, "remote feature not supported");
return SOFTBUS_HML_NOT_SUPPORT;
}
int32_t ret = GetWifiDirectManager()->prejudgeAvailability(networkId, WIFI_DIRECT_LINK_TYPE_HML);
if (ret == ERROR_LOCAL_THREE_VAP_CONFLICT) {
return SOFTBUS_HML_THREE_VAP_CONFLIC;
}
return ret;
}
static LinkState g_linkState[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = {true, BrLinkState},
[LANE_BLE] = { true, BleLinkState},
[LANE_WLAN_2P4G] = { true, WlanLinkState},
[LANE_WLAN_5G] = { true, WlanLinkState},
[LANE_P2P] = { true, P2pLinkState},
[LANE_HML] = { true, HmlLinkState},
};
static int32_t IsValidLaneLink(const char *networkId, LaneLinkType linkType)
{
if ((linkType < 0) || (linkType >= LANE_LINK_TYPE_BUTT)) {
LNN_LOGE(LNN_LANE, "invalid linkType=%d", linkType);
return SOFTBUS_INVALID_PARAM;
}
if (!g_linkState[linkType].available) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%d", linkType);
return SOFTBUS_ERR;
}
if (g_linkState[linkType].QueryLink == NULL) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%d", linkType);
return SOFTBUS_ERR;
}
return g_linkState[linkType].QueryLink(networkId);
}
static bool isHighRequire(const QosInfo *qosInfo, bool *isHighBand)
{
if (qosInfo->minBW > QOS_MIN_BANDWIDTH) {
*isHighBand = true;
return true;
} else {
*isHighBand = false;
return true;
}
return false;
}
static int32_t QueryByRequireLink(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (qosInfo->minBW == QOS_P2P_ONLY_BANDWIDTH) {
return IsValidLaneLink(queryInfo->networkId, LANE_P2P);
}
bool isHighBand = false;
if (!isHighRequire(qosInfo, &isHighBand)) {
LNN_LOGE(LNN_LANE, "set param failed");
return SOFTBUS_ERR;
}
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
int32_t ret = SOFTBUS_ERR;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, isHighBand) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return ret;
}
for (uint32_t i = 0; i < linkNum; i++) {
ret = IsValidLaneLink(queryInfo->networkId, optLink[i]);
if (ret == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "high require get enable Link, linktype=%d", optLink[i]);
return ret;
}
}
return ret;
}
static int32_t QueryByDefaultLink(const LaneQueryInfo *queryInfo)
{
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, false) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return SOFTBUS_ERR;
}
int32_t ret = SOFTBUS_ERR;
for (uint32_t i = 0; i < linkNum; i++) {
ret = IsValidLaneLink(queryInfo->networkId, optLink[i]);
if (ret == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "default get enable Link, linktype=%d", optLink[i]);
return ret;
}
}
return ret;
}
int32_t QueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (queryInfo == NULL || qosInfo == NULL) {
LNN_LOGE(LNN_LANE, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_ERR;
if (qosInfo->minBW > 0) {
LNN_LOGI(LNN_LANE, "Query lane by prefer linklist, transType=%d, minBW=%d",
queryInfo->transType, qosInfo->minBW);
ret = QueryByRequireLink(queryInfo, qosInfo);
} else {
LNN_LOGI(LNN_LANE, "Query lane by default linklist, transType=%d", queryInfo->transType);
ret = QueryByDefaultLink(queryInfo);
}
return ret;
}

View File

@ -0,0 +1,30 @@
/*
* 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 "lnn_lane_reliablity.h"
#include "softbus_errcode.h"
bool LaneDetectReliablity(const LaneResource *resourceItem)
{
(void)resourceItem;
return true;
}
int32_t LaneDetectFload(const LaneResource *resourceItem)
{
(void)resourceItem;
return SOFTBUS_OK;
}

View File

@ -106,7 +106,7 @@ static bool IsValidLane(const char *networkId, LaneLinkType linkType, uint32_t e
return false;
}
LinkAttribute *linkAttr = GetLinkAttrByLinkType(linkType);
if ((linkAttr == NULL) || (linkAttr->available != true)) {
if ((linkAttr == NULL) || (!linkAttr->available)) {
return false;
}
if (linkAttr->IsEnable(networkId) != true) {
@ -133,6 +133,8 @@ static char *GetLinkTypeStrng(LaneLinkType preferredLink)
return "BLE";
case LANE_P2P:
return "P2P";
case LANE_HML:
return "HML";
case LANE_WLAN_2P4G:
return "WLAN 2.4G";
case LANE_WLAN_5G:
@ -269,4 +271,67 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
}
*listNum = resNum;
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)
{
LNN_LOGI(LNN_LANE, "SelectExpectLanesByQos enter");
if ((networkId == NULL) || (request == NULL) || (recommendList == NULL)) {
return SOFTBUS_INVALID_PARAM;
}
if (!LnnGetOnlineStateById(networkId, CATEGORY_NETWORK_ID)) {
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "device not online, cancel selectLane by qos, networkId=%s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
LanePreferredLinkList laneLinkList = {0};
if (request->qosRequire.minBW == 0 && request->qosRequire.maxLaneLatency == 0 &&
request->qosRequire.minLaneLatency == 0) {
LNN_LOGI(LNN_LANE, "select lane by default linkList");
SelectByDefaultLink(networkId, request, laneLinkList.linkType, &(laneLinkList.linkTypeNum));
} else {
LNN_LOGI(LNN_LANE, "select lane by qos require");
if (DecideAvailableLane(networkId, request, &laneLinkList) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
}
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)) {
continue;
}
recommendList->linkType[recommendList->linkTypeNum] = laneLinkList.linkType[i];
recommendList->linkTypeNum++;
DumpPreferredLink(laneLinkList.linkType[i], i);
}
if (LanePrioritization(recommendList, laneScore) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}

View File

@ -17,6 +17,7 @@
#include <securec.h>
#include "anonymizer.h"
#include "bus_center_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_feature_capability.h"
@ -39,6 +40,15 @@
#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 HIGH_BW (160 * 1024 * 1024)
#define COC_DIRECT_LATENCY 1000
#define BR_LATENCY 2500
#define WLAN_LATENCY 800
#define P2P_LATENCY 1600
#define HML_LATENCY 1000
int32_t GetWlanLinkedFrequency(void)
{
LnnWlanLinkedInfo info;
@ -88,6 +98,23 @@ static bool IsEnableWlan2P4G(const char *networkId)
LNN_LOGE(LNN_LANE, "band isn't 2.4G or unknown");
return false;
}
NodeInfo node;
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "get remote node info fail, networkId=%s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) && !LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "peer node networkId=%s, not have discType[%d, %d]",
anonyNetworkId, DISCOVERY_TYPE_WIFI, DISCOVERY_TYPE_LSA);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
@ -108,6 +135,23 @@ static bool IsEnableWlan5G(const char *networkId)
LNN_LOGE(LNN_LANE, "band isn't 5G or unknown");
return false;
}
NodeInfo node;
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "get remote node info fail, networkId=%s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) && !LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "peer node networkId=%s, not have discType[%d, %d]",
anonyNetworkId, DISCOVERY_TYPE_WIFI, DISCOVERY_TYPE_LSA);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
@ -149,6 +193,22 @@ static bool IsEnableP2p(const char *networkId)
return true;
}
static bool IsEnableHml(const char *networkId)
{
if (!IsEnableP2p(networkId)) {
return false;
}
uint64_t local, remote;
if (!GetFeatureCap(networkId, &local, &remote)) {
return false;
}
if (((local & (1 << BIT_WIFI_DIRECT_TLV_NEGOTIATION)) == 0) ||
((remote & (1 << BIT_WIFI_DIRECT_TLV_NEGOTIATION)) == 0)) {
return false;
}
return true;
}
static bool IsEnableP2pReuse(const char *networkId)
{
if (!IsEnableP2p(networkId)) {
@ -254,6 +314,14 @@ static int32_t GetP2pScore(const char *networkId, uint32_t expectedBw)
return LNN_LINK_DEFAULT_SCORE;
}
static int32_t GetHmlScore(const char *networkId, uint32_t expectedBw)
{
(void)networkId;
(void)expectedBw;
return LNN_LINK_DEFAULT_SCORE;
}
static int32_t GetLinkedChannelScore(void)
{
int32_t frequency = GetWlanLinkedFrequency();
@ -298,6 +366,7 @@ static LinkAttribute g_linkAttr[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = {true, IsEnableBr, GetBrScore },
[LANE_BLE] = { true, IsEnableBle, GetBleScore },
[LANE_P2P] = { true, IsEnableP2p, GetP2pScore },
[LANE_HML] = { true, IsEnableHml, GetHmlScore },
[LANE_WLAN_2P4G] = { true, IsEnableWlan2P4G, GetWlan2P4GScore},
[LANE_WLAN_5G] = { true, IsEnableWlan5G, GetWlan5GScore },
[LANE_ETH] = { false, NULL, NULL },
@ -315,3 +384,160 @@ LinkAttribute *GetLinkAttrByLinkType(LaneLinkType linkType)
}
return &g_linkAttr[linkType];
}
static uint32_t g_laneLatency[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = BR_LATENCY,
[LANE_P2P] = P2P_LATENCY,
[LANE_HML] = HML_LATENCY,
[LANE_WLAN_2P4G] = WLAN_LATENCY,
[LANE_WLAN_5G] = WLAN_LATENCY,
[LANE_COC_DIRECT] = COC_DIRECT_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},
};
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},
};
static bool IsLinkTypeValid(LaneLinkType type)
{
if ((type < 0) || (type >= LANE_LINK_TYPE_BUTT)) {
return false;
}
return true;
}
static bool IsValidLane(const char *networkId, LaneLinkType linkType, LaneTransType transType)
{
if (!IsLinkTypeValid(linkType)) {
return false;
}
LinkAttribute *linkAttr = GetLinkAttrByLinkType(linkType);
if ((linkAttr == NULL) || (!linkAttr->available)) {
return false;
}
if (linkAttr->IsEnable(networkId) != true) {
return false;
}
bool isStream = (transType == LANE_T_RAW_STREAM || transType == LANE_T_COMMON_VIDEO ||
transType == LANE_T_COMMON_VOICE);
bool isBt = (linkType == LANE_BR || linkType == LANE_BLE || linkType == LANE_BLE_DIRECT ||
linkType == LANE_BLE_REUSE || linkType == LANE_COC || linkType == LANE_COC_DIRECT);
if (isStream && isBt) {
return false;
}
return true;
}
static bool IsLaneFillMinLatency(uint32_t minLaneLatency, LaneLinkType linkType)
{
if (minLaneLatency >= g_laneLatency[linkType]) {
return true;
}
return false;
}
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, "decide optimal link, band width type=%ld", bandWidthType);
for (uint32_t i = 0; i < (LANE_LINK_TYPE_BUTT + 1); i++) {
if (g_laneBandWidth[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
break;
}
if (IsValidLane(networkId, g_laneBandWidth[bandWidthType][i], request->transType) &&
IsLaneFillMinLatency(minLaneLatency, g_laneBandWidth[bandWidthType][i])) {
linkList[(*linksNum)++] = g_laneBandWidth[bandWidthType][i];
LNN_LOGI(LNN_LANE, "decide optimal linkType=%d", g_laneBandWidth[bandWidthType][i]);
break;
}
}
}
static bool isLaneExist(LaneLinkType *linkList, LaneLinkType laneType)
{
for (int i = 0; i < LANE_LINK_TYPE_BUTT; i++) {
if (linkList[i] == laneType) {
return true;
}
}
return false;
}
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;
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, "decide retry link, band width type=%ld", bandWidthType);
int32_t retryTime;
if (linksNum == 0) {
retryTime = maxLaneLatency;
} else {
retryTime = maxLaneLatency - g_laneLatency[linkList[0]];
}
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]) &&
retryTime - g_laneLatency[g_retryLaneList[bandWidthType][i]] >= 0) {
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]);
}
}
}
int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *request, LanePreferredLinkList *recommendList)
{
if (request == NULL || recommendList == NULL) {
return SOFTBUS_INVALID_PARAM;
}
LaneLinkType linkList[LANE_LINK_TYPE_BUTT] = {0};
uint32_t linksNum = 0;
DecideOptimalLinks(networkId, request, linkList, &linksNum);
DecideRetryLinks(networkId, request, linkList, &linksNum);
for (uint32_t i = 0; i < linksNum; i++) {
recommendList->linkType[i] = linkList[i];
}
recommendList->linkTypeNum = linksNum;
return SOFTBUS_OK;
}

View File

@ -36,12 +36,7 @@
#include "softbus_protocol_def.h"
#include "wifi_direct_error_code.h"
typedef enum {
MSG_TYPE_LANE_TRIGGER_LINK = 0,
MSG_TYPE_LANE_LINK_SUCCESS,
MSG_TYPE_LANE_LINK_FAIL,
MSG_TYPE_LANE_LINK_EXCEPTION,
} LaneMsgType;
#define DELAY_DESTROY_LANE_TIME 5000
typedef struct {
ListNode node;
@ -62,15 +57,16 @@ typedef struct {
uint32_t laneId;
int32_t pid;
char networkId[NETWORK_ID_BUF_LEN];
char peerBleMac[MAX_MAC_LEN];
int32_t psm;
LaneTransType transType;
LanePreferredLinkList *linkList; /* Mem provided by laneSelect module */
uint32_t listNum;
uint32_t linkRetryIdx;
bool networkDelegate;
bool p2pOnly;
int32_t p2pErrCode;
// OldInfo
char peerBleMac[MAX_MAC_LEN];
int32_t psm;
LaneTransType transType;
} LaneLinkNodeInfo;
static ListNode g_multiLinkList;
@ -79,6 +75,7 @@ static TransLaneList *g_requestList = NULL;
static SoftBusHandler g_laneLoopHandler;
static ILaneIdStateListener *g_laneIdCallback = NULL;
static int32_t Lock(void)
{
return SoftBusMutexLock(&g_transLaneMutex);
@ -89,7 +86,8 @@ static void Unlock(void)
(void)SoftBusMutexUnlock(&g_transLaneMutex);
}
static int32_t PostMsgToHandler(int32_t msgType, uint64_t param1, uint64_t param2, void *obj)
int32_t LnnLanePostMsgToHandler(int32_t msgType, uint64_t param1, uint64_t param2,
void *obj, uint64_t delayMillis)
{
SoftBusMessage *msg = (SoftBusMessage *)SoftBusCalloc(sizeof(SoftBusMessage));
if (msg == NULL) {
@ -101,7 +99,11 @@ static int32_t PostMsgToHandler(int32_t msgType, uint64_t param1, uint64_t param
msg->arg2 = param2;
msg->handler = &g_laneLoopHandler;
msg->obj = obj;
g_laneLoopHandler.looper->PostMessage(g_laneLoopHandler.looper, msg);
if (delayMillis == 0) {
g_laneLoopHandler.looper->PostMessage(g_laneLoopHandler.looper, msg);
} else {
g_laneLoopHandler.looper->PostMessageDelay(g_laneLoopHandler.looper, msg, delayMillis);
}
return SOFTBUS_OK;
}
@ -116,19 +118,36 @@ static void LinkSuccess(uint32_t laneId, const LaneLinkInfo *linkInfo)
LNN_LOGE(LNN_LANE, "linkSuccess info malloc fail");
return;
}
LaneResource resourceItem;
(void)memset_s(&resourceItem, sizeof(LaneResource), 0, sizeof(LaneResource));
if (memcpy_s(linkParam, sizeof(LaneLinkInfo), linkInfo, sizeof(LaneLinkInfo)) != EOK) {
SoftBusFree(linkParam);
LNN_LOGE(LNN_LANE, "linkParam memcpy_s fail");
return;
}
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_SUCCESS, laneId, 0, linkParam) != SOFTBUS_OK) {
linkParam->laneId = laneId;
if (ConvertToLaneResource(linkParam, &resourceItem) != SOFTBUS_OK) {
SoftBusFree(linkParam);
LNN_LOGE(LNN_LANE, "convert to laneResource fail, laneId=%u", laneId);
return;
}
if (AddLinkInfoItem(linkParam) != SOFTBUS_OK || AddLaneResourceItem(&resourceItem) != SOFTBUS_OK) {
SoftBusFree(linkParam);
LNN_LOGE(LNN_LANE, "add linkInfo item fail, laneId=%u", laneId);
return;
}
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_SUCCESS, laneId, 0, linkParam, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post LaneLinkSuccess msg err, laneId=%u", laneId);
SoftBusFree(linkParam);
DelLaneResourceItem(&resourceItem);
DelLinkInfoItem(laneId);
return;
}
}
static void LinkFail(uint32_t laneId, int32_t reason)
{
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, reason, NULL) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, reason, NULL, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post lanelink fail msg err");
return;
}
@ -136,7 +155,7 @@ static void LinkFail(uint32_t laneId, int32_t reason)
static void LinkException(uint32_t laneId, int32_t reason)
{
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_EXCEPTION, laneId, reason, NULL) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_EXCEPTION, laneId, reason, NULL, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post laneStateException msg err");
return;
}
@ -161,27 +180,30 @@ static void DeleteLaneLinkNode(uint32_t laneId)
}
static int32_t TriggerLink(uint32_t laneId, TransOption *request,
LanePreferredLinkList *recommendLinkList, uint32_t listNum)
LanePreferredLinkList *recommendLinkList)
{
LNN_LOGI(LNN_LANE, "TriggerLink enter");
LaneLinkNodeInfo *linkNode = (LaneLinkNodeInfo *)SoftBusCalloc(sizeof(LaneLinkNodeInfo));
if (linkNode == NULL) {
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(linkNode->networkId, NETWORK_ID_BUF_LEN,
request->networkId, NETWORK_ID_BUF_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy fail for networkId");
SoftBusFree(linkNode);
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(linkNode->peerBleMac, MAX_MAC_LEN, request->peerBleMac, MAX_MAC_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy fail for peerBleMac");
SoftBusFree(linkNode);
return SOFTBUS_MEM_ERR;
}
linkNode->psm = request->psm;
linkNode->transType = request->transType;
linkNode->laneId = laneId;
linkNode->linkRetryIdx = 0;
linkNode->listNum = listNum;
linkNode->listNum = recommendLinkList->linkTypeNum;
linkNode->linkList = recommendLinkList;
linkNode->transType = request->transType;
linkNode->pid = request->pid;
linkNode->networkDelegate = request->networkDelegate;
linkNode->p2pOnly = request->p2pOnly;
@ -193,7 +215,8 @@ static int32_t TriggerLink(uint32_t laneId, TransOption *request,
}
ListTailInsert(&g_multiLinkList, &linkNode->node);
Unlock();
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, request->acceptableProtocols, NULL) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId,
request->acceptableProtocols, NULL, 0) != SOFTBUS_OK) {
DeleteLaneLinkNode(laneId);
return SOFTBUS_ERR;
}
@ -238,6 +261,67 @@ static void DeleteRequestNode(uint32_t laneId)
Unlock();
}
static int32_t StartTriggerLink(uint32_t laneId, TransOption *transRequest, const ILaneListener *listener,
LanePreferredLinkList *recommendLinkList)
{
LNN_LOGI(LNN_LANE, "StartTriggerLink enter");
TransReqInfo *newItem = CreateRequestNode(laneId, transRequest, listener);
if (newItem == NULL) {
return SOFTBUS_ERR;
}
if (Lock() != SOFTBUS_OK) {
SoftBusFree(newItem);
return SOFTBUS_ERR;
}
ListTailInsert(&g_requestList->list, &newItem->node);
g_requestList->cnt++;
Unlock();
if (TriggerLink(laneId, transRequest, recommendLinkList) != SOFTBUS_OK) {
DeleteRequestNode(laneId);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t AllocLane(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener)
{
if ((request == NULL) || (request->type != LANE_TYPE_TRANS)) {
LNN_LOGE(LNN_LANE, "AllocLane param invalid");
return SOFTBUS_INVALID_PARAM;
}
TransOption *transRequest = (TransOption *)&request->requestInfo.trans;
LaneSelectParam selectParam;
(void)memset_s(&selectParam, sizeof(LaneSelectParam), 0, sizeof(LaneSelectParam));
selectParam.transType = transRequest->transType;
selectParam.qosRequire = transRequest->qosRequire;
LanePreferredLinkList *recommendLinkList = (LanePreferredLinkList *)SoftBusMalloc(sizeof(LanePreferredLinkList));
if (recommendLinkList == NULL) {
LNN_LOGE(LNN_LANE, "recommendLinkList malloc fail");
return SOFTBUS_ERR;
}
recommendLinkList->linkTypeNum = 0;
if (SelectExpectLanesByQos((const char *)transRequest->networkId, &selectParam,
recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "selectExpectLanesByQos fail, laneId=%u", laneId);
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_LANE, "select lane link by qos success, laneId=%u, linkNum=%d",
laneId, recommendLinkList->linkTypeNum);
if (recommendLinkList->linkTypeNum == 0) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "no link resources available, allocLane fail, laneId=%u", laneId);
return SOFTBUS_ERR;
}
if (StartTriggerLink(laneId, transRequest, listener, recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "trigger link fail, laneId=%u", laneId);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t Alloc(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener)
{
if ((request == NULL) || (request->type != LANE_TYPE_TRANS)) {
@ -282,7 +366,7 @@ static int32_t Alloc(uint32_t laneId, const LaneRequestOption *request, const IL
ListTailInsert(&g_requestList->list, &newItem->node);
g_requestList->cnt++;
Unlock();
if (TriggerLink(laneId, transRequest, recommendLinkList, listNum) != SOFTBUS_OK) {
if (TriggerLink(laneId, transRequest, recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
DeleteRequestNode(laneId);
return SOFTBUS_ERR;
@ -301,7 +385,7 @@ static void UnbindLaneId(uint32_t laneId, const TransReqInfo *infoNode)
UnbindLaneIdFromProfile(laneId, profileId);
}
static int32_t Free(uint32_t laneId)
static int32_t FreeLaneLink(uint32_t laneId, LaneResource *laneResourceInfo, bool isDelayDestroy)
{
if (Lock() != SOFTBUS_OK) {
return SOFTBUS_ERR;
@ -313,16 +397,39 @@ static int32_t Free(uint32_t laneId)
ListDelete(&item->node);
g_requestList->cnt--;
Unlock();
DelLinkInfoItem(laneId);
if (isDelayDestroy) {
DelLaneResourceItem(laneResourceInfo);
}
DestroyLink(item->info.networkId, laneId, item->type, item->info.pid);
UnbindLaneId(laneId, item);
SoftBusFree(item);
FreeLaneId(laneId);
return SOFTBUS_OK;
}
}
Unlock();
FreeLaneId(laneId);
return SOFTBUS_OK;
}
static int32_t Free(uint32_t laneId)
{
LaneLinkInfo laneLinkInfo;
(void)memset_s(&laneLinkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
LaneResource laneResourceInfo;
(void)memset_s(&laneResourceInfo, sizeof(LaneResource), 0, sizeof(LaneResource));
FindLaneLinkInfoByLaneId(laneId, &laneLinkInfo);
ConvertToLaneResource(&laneLinkInfo, &laneResourceInfo);
bool isDelayDestroy = false;
DelLaneResourceItemWithDelayDestroy(&laneResourceInfo, laneId, &isDelayDestroy);
LNN_LOGI(LNN_LANE, "delayDestroy is %s", isDelayDestroy ? "true" : "false");
if (isDelayDestroy) {
return SOFTBUS_OK;
}
return FreeLaneLink(laneId, &laneResourceInfo, isDelayDestroy);
}
static int32_t GetLaneReqInfo(uint32_t laneId, TransReqInfo *reqInfo)
{
if (Lock() != SOFTBUS_OK) {
@ -351,7 +458,7 @@ static int32_t GetLaneReqInfo(uint32_t laneId, TransReqInfo *reqInfo)
static void UpdateP2pInfo(TransReqInfo *nodeInfo)
{
if (nodeInfo->type != LANE_P2P) {
if (nodeInfo->type != LANE_P2P && nodeInfo->type != LANE_HML) {
return;
}
if (LnnGetRemoteStrInfo(nodeInfo->info.networkId, STRING_KEY_P2P_MAC,
@ -482,13 +589,13 @@ static void LaneTriggerLink(SoftBusMessage *msg)
requestInfo.linkType = nodeInfo->linkList->linkType[nodeInfo->linkRetryIdx];
nodeInfo->linkRetryIdx++;
requestInfo.pid = nodeInfo->pid;
requestInfo.transType = nodeInfo->transType;
requestInfo.acceptableProtocols = acceptableProtocols;
if (memcpy_s(requestInfo.peerNetworkId, sizeof(requestInfo.peerNetworkId),
nodeInfo->networkId, sizeof(nodeInfo->networkId)) != EOK) {
Unlock();
return;
}
requestInfo.transType = nodeInfo->transType;
if (memcpy_s(requestInfo.peerBleMac, MAX_MAC_LEN, nodeInfo->peerBleMac, MAX_MAC_LEN) != EOK) {
Unlock();
return;
@ -499,7 +606,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
if (ret == SOFTBUS_OK) {
return;
}
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, acceptableProtocols, NULL) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, acceptableProtocols, NULL, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post laneLinkFail msg err");
}
}
@ -514,7 +621,7 @@ static void LaneLinkSuccess(SoftBusMessage *msg)
uint32_t laneId = (uint32_t)msg->arg1;
DeleteLaneLinkNode(laneId);
NotifyLaneAllocSuccess(laneId, info);
SoftBusFree(msg->obj);
SoftBusFree(info);
return;
}
@ -550,7 +657,7 @@ static void LaneLinkFail(SoftBusMessage *msg)
if (msg->arg2 == (uint64_t)SOFTBUS_ERR) {
acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
}
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, acceptableProtocols, NULL) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, acceptableProtocols, NULL, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post triggerLink msg fail");
return;
}
@ -563,6 +670,18 @@ static void LaneLinkException(SoftBusMessage *msg)
NotifyLaneStateChange(laneId, state);
}
static void HandleDelayDestroyLink(SoftBusMessage *msg)
{
if (msg->obj == NULL) {
LNN_LOGE(LNN_LANE, "invalid msg->obj");
return;
}
uint32_t laneId = msg->arg1;
bool isDelayDestroy = msg->arg2;
LaneResource *resourceItem = (LaneResource*)msg->obj;
FreeLaneLink(laneId, resourceItem, isDelayDestroy);
}
static void MsgHandler(SoftBusMessage *msg)
{
if (msg == NULL) {
@ -581,6 +700,9 @@ static void MsgHandler(SoftBusMessage *msg)
case MSG_TYPE_LANE_LINK_EXCEPTION:
LaneLinkException(msg);
break;
case MSG_TYPE_DELAY_DESTROY_LINK:
HandleDelayDestroyLink(msg);
break;
default:
LNN_LOGE(LNN_LANE, "msg type=%d cannot found", msg->what);
break;
@ -650,6 +772,7 @@ static LaneInterface g_transLaneObject = {
.Init = Init,
.Deinit = Deinit,
.AllocLane = Alloc,
.allocLaneByQos = AllocLane,
.FreeLane = Free,
};
@ -657,3 +780,23 @@ LaneInterface *TransLaneGetInstance(void)
{
return &g_transLaneObject;
}
int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt)
{
if (qosOpt == NULL || laneId == INVALID_LANE_ID) {
return SOFTBUS_INVALID_PARAM;
}
if (Lock() != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
TransReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_requestList->list, TransReqInfo, node) {
if (item->laneId == laneId) {
*qosOpt = item->info.qosRequire;
Unlock();
return SOFTBUS_OK;
}
}
Unlock();
return SOFTBUS_ERR;
}

View File

@ -20,11 +20,18 @@
#include "cJSON.h"
#include "softbus_common.h"
#include "lnn_node_info.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char udid[UDID_BUF_LEN];
uint64_t endTime;
BroadcastCipherInfo cipherInfo;
} BroadcastCipherKey;
int32_t LnnInitCipherKeyManager(void);
void LnnDeinitCipherKeyManager(void);
bool GetCipherKeyByNetworkId(const char *networkId, int32_t seq, uint32_t tableIndex, unsigned char *key,
@ -34,6 +41,10 @@ void LoadBleBroadcastKey(void);
bool IsCipherManagerFindKey(const char *udid);
bool PackCipherKeySyncMsg(void *json);
void ProcessCipherKeySyncInfo(const void *json, const char *networkId);
int32_t LnnLoadLocalBroadcastCipherKey(void);
int32_t LnnGetLocalBroadcastCipherKey(BroadcastCipherKey *broadcastKey);
int32_t LnnSaveLocalBroadcastCipherKey(const BroadcastCipherKey *broadcastKey);
int32_t LnnUpdateLocalBroadcastCipherKey(BroadcastCipherKey *broadcastCipherKey);
#ifdef __cplusplus
}

View File

@ -17,17 +17,38 @@
#define LNN_P2P_INFO_H
#include <stdint.h>
#include "common_list.h"
#include "lnn_node_info.h"
#include "softbus_json_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char udid[UDID_BUF_LEN];
uint64_t createTime;
uint64_t endTime;
char ptk[PTK_DEFAULT_LEN];
ListNode node;
} LocalPtkList;
int32_t LnnInitP2p(void);
void LnnDeinitP2p(void);
int32_t LnnInitLocalP2pInfo(NodeInfo *info);
int32_t LnnSyncP2pInfo(void);
int32_t LnnInitPtk(void);
void LnnDeinitPtk(void);
int32_t LnnGetLocalPtkByUdid(const char *udid, char *localPtk);
void LnnLoadPtkInfo(void);
int32_t LnnSyncPtk(char *networkId);
int32_t UpdateLocalPtkIfValid(char *udid);
int32_t LnnSetLocalPtkConn(char *udid);
int32_t LnnGenerateLocalPtk(char *udid);
#ifdef __cplusplus
}
#endif

View File

@ -41,6 +41,7 @@ typedef enum {
LNN_INFO_TYPE_NODE_ADDR_DETECTION,
LNN_INFO_TYPE_SYNC_CIPHERKEY,
LNN_INFO_TYPE_ROUTE_LSU,
LNN_INFO_TYPE_PTK,
LNN_INFO_TYPE_COUNT,
//LNN_INFO_TYPE_P2P_ROLE = 256,
} LnnSyncInfoType;

View File

@ -40,14 +40,18 @@ if (dsoftbus_feature_lnn_net) {
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_cipherkey_manager_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_device_info_recovery_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_ptk_info_virtual.c",
"$dsoftbus_root_path/core/bus_center/utils/src/lnn_secure_storage.c",
]
bus_center_builder_inc =
[ "$dsoftbus_root_path/core/connection/wifi_direct/adapter/single" ]
} else {
import(
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/cipherkey/cipherkey.gni")
import(
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/ptk/ptk.gni")
bus_center_builder_src += cipherkey_sources
bus_center_builder_src += cipherkey_sources + ptk_sources
bus_center_builder_src += [
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/fast_online/lnn_device_info_recovery.c",
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/fast_online/lnn_secure_storage.c",
@ -58,6 +62,7 @@ if (dsoftbus_feature_lnn_net) {
bus_center_builder_src = [
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_net_builder_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_cipherkey_manager_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_ptk_info_virtual.c",
"$dsoftbus_root_path/core/connection/wifi_direct/adapter/single/wifi_direct_p2p_adapter_virtual.c",
]
}

View File

@ -63,3 +63,26 @@ bool IsCipherManagerFindKey(const char *udid)
(void)udid;
return false;
}
int32_t LnnLoadLocalBroadcastCipherKey(void)
{
return SOFTBUS_OK;
}
int32_t LnnGetLocalBroadcastCipherKey(BroadcastCipherKey *broadcastKey)
{
(void)broadcastKey;
return SOFTBUS_OK;
}
int32_t LnnSaveLocalBroadcastCipherKey(const BroadcastCipherKey *broadcastKey)
{
(void)broadcastKey;
return SOFTBUS_OK;
}
int32_t LnnUpdateLocalBroadcastCipherKey(BroadcastCipherKey *broadcastKey)
{
(void)broadcastKey;
return SOFTBUS_OK;
}

View File

@ -24,6 +24,7 @@
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_ble_lpdevice.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_connection_addr_utils.h"
#include "lnn_decision_db.h"
#include "lnn_device_info.h"
@ -31,6 +32,7 @@
#include "lnn_distributed_net_ledger.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_heartbeat_utils.h"
#include "lnn_link_finder.h"
#include "lnn_log.h"
#include "lnn_net_builder.h"
#include "lnn_sync_item_info.h"
@ -392,6 +394,9 @@ static void CompleteJoinLNN(LnnConnectionFsm *connFsm, const char *networkId, in
ReportLnnResultEvt(connFsm, retCode);
if (retCode == SOFTBUS_OK && connInfo->nodeInfo != NULL) {
report = LnnAddOnlineNode(connInfo->nodeInfo);
if (LnnInsertLinkFinderInfo(networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "insert rpa info fail.");
}
if (LnnUpdateGroupType(connInfo->nodeInfo) != SOFTBUS_OK) {
LNN_LOGI(LNN_BUILDER, "update grouptype fail");
}
@ -548,6 +553,28 @@ static void TryCancelJoinProcedure(LnnConnectionFsm *connFsm)
}
}
static int32_t LnnRecoveryBroadcastKey()
{
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (LnnGetLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local info failed");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY, broadcastKey.cipherInfo.key,
SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set key failed");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, broadcastKey.cipherInfo.iv,
BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set iv failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t OnJoinLNN(LnnConnectionFsm *connFsm)
{
int32_t rc;
@ -579,7 +606,8 @@ static int32_t OnJoinLNN(LnnConnectionFsm *connFsm)
LNN_LOGI(LNN_BUILDER, "join udidHash = %s", udidHash);
if (ret == EOK) {
if (LnnRetrieveDeviceInfo(udidHash, &deviceInfo) == SOFTBUS_OK &&
AuthRestoreAuthManager(udidHash, &authConn, connInfo->requestId, &deviceInfo, &authId) == SOFTBUS_OK) {
AuthRestoreAuthManager(udidHash, &authConn, connInfo->requestId, &deviceInfo, &authId) == SOFTBUS_OK &&
LnnRecoveryBroadcastKey() == SOFTBUS_OK) {
LnnGetVerifyCallback()->onVerifyPassed(connInfo->requestId, authId, &deviceInfo);
return SOFTBUS_OK;
}
@ -626,11 +654,14 @@ int32_t OnJoinMetaNode(MetaJoinRequestNode *metaJoinNode, CustomData *customData
static int32_t LnnFillConnInfo(LnnConntionInfo *connInfo)
{
bool isAuthServer = false;
SoftBusVersion version;
NodeInfo *nodeInfo = connInfo->nodeInfo;
nodeInfo->discoveryType = 1 << (uint32_t)LnnConvAddrTypeToDiscType(connInfo->addr.type);
nodeInfo->authSeqNum = connInfo->authId;
nodeInfo->authChannelId[connInfo->addr.type] = (int32_t)connInfo->authId;
(void)AuthGetServerSide(connInfo->authId, &isAuthServer);
nodeInfo->authChannelId[connInfo->addr.type][isAuthServer ? AUTH_AS_SERVER_SIDE : AUTH_AS_CLIENT_SIDE] =
(int32_t)connInfo->authId;
nodeInfo->relation[connInfo->addr.type]++;
if (AuthGetVersion(connInfo->authId, &version) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fill version fail");

View File

@ -36,8 +36,10 @@
#include "lnn_devicename_info.h"
#include "lnn_discovery_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_event.h"
#include "lnn_fast_offline.h"
#include "lnn_heartbeat_utils.h"
#include "lnn_link_finder.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_network_id.h"
@ -1471,12 +1473,15 @@ static NodeInfo *DupNodeInfo(const NodeInfo *nodeInfo)
static int32_t FillNodeInfo(MetaJoinRequestNode *metaNode, NodeInfo *info)
{
if (metaNode == NULL || info ==NULL) {
if (metaNode == NULL || info == NULL) {
return SOFTBUS_ERR;
}
bool isAuthServer = false;
info->discoveryType = 1 << (uint32_t)LnnConvAddrTypeToDiscType(metaNode->addr.type);
info->authSeqNum = metaNode->authId;
info->authChannelId[metaNode->addr.type] = (int32_t)metaNode->authId;
(void)AuthGetServerSide(metaNode->authId, &isAuthServer);
info->authChannelId[metaNode->addr.type][isAuthServer ? AUTH_AS_SERVER_SIDE : AUTH_AS_CLIENT_SIDE] =
(int32_t)metaNode->authId;
info->relation[metaNode->addr.type]++;
if (AuthGetDeviceUuid(metaNode->authId, info->uuid, sizeof(info->uuid)) != SOFTBUS_OK ||
info->uuid[0] == '\0') {
@ -1794,6 +1799,20 @@ static const char *SelectUseUdid(const char *peerUdid, const char *lowerUdid)
}
}
static void LnnDeleteLinkFinderInfo(const char *peerUdid)
{
char networkId[NETWORK_ID_BUF_LEN] = {0};
if (LnnGetNetworkIdByUdid(peerUdid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get networkId fail.");
return;
}
if (LnnRemoveLinkFinderInfo(networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "remove a rpa info fail.");
return;
}
}
static void OnDeviceNotTrusted(const char *peerUdid)
{
if (peerUdid == NULL) {
@ -1818,6 +1837,7 @@ static void OnDeviceNotTrusted(const char *peerUdid)
if (useUdid == NULL) {
return;
}
LnnDeleteLinkFinderInfo(peerUdid);
NotTrustedDelayInfo *info = (NotTrustedDelayInfo *)SoftBusCalloc(sizeof(NotTrustedDelayInfo));
if (info == NULL) {
LNN_LOGE(LNN_BUILDER, "malloc NotTrustedDelayInfo fail");
@ -2105,6 +2125,29 @@ static JoinLnnMsgPara *CreateJoinLnnMsgPara(const ConnectionAddr *addr, const ch
return para;
}
static void BuildLnnEvent(LnnEventExtra *lnnEventExtra, const ConnectionAddr *addr)
{
if (lnnEventExtra == NULL || addr == NULL) {
LNN_LOGW(LNN_STATE, "lnnEventExtra or addr is null");
return;
}
switch (addr->type) {
case CONNECTION_ADDR_BR:
lnnEventExtra->peerBrMac = addr->info.br.brMac;
break;
case CONNECTION_ADDR_BLE:
lnnEventExtra->peerBleMac = addr->info.ble.bleMac;
break;
case CONNECTION_ADDR_WLAN:
case CONNECTION_ADDR_ETH:
lnnEventExtra->peerIp = addr->info.ip.ip;
break;
default:
LNN_LOGE(LNN_BUILDER, "unknow param type!");
break;
}
}
static ConnectionAddrKey *CreateConnectionAddrMsgParaKey(const ConnectionAddrKey *addrDataKey)
{
ConnectionAddrKey *para = NULL;
@ -2147,15 +2190,27 @@ static int32_t ConifgLocalLedger(void)
{
char uuid[UUID_BUF_LEN] = {0};
char networkId[NETWORK_ID_BUF_LEN] = {0};
unsigned char irk[LFINDER_IRK_LEN] = {0};
// set local uuid and networkId
// set local networkId and uuid
if (LnnGenLocalNetworkId(networkId, NETWORK_ID_BUF_LEN) != SOFTBUS_OK ||
LnnGenLocalUuid(uuid, UUID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local id fail");
return SOFTBUS_ERR;
}
// irk fail should not cause softbus init fail
if (LnnGenLocalIrk(irk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local irk fail");
}
LnnSetLocalStrInfo(STRING_KEY_UUID, uuid);
LnnSetLocalStrInfo(STRING_KEY_NETWORKID, networkId);
LnnSetLocalByteInfo(BYTE_KEY_IRK, irk, LFINDER_IRK_LEN);
// irk fail should not cause softbus init fail
if (LnnUpdateLinkFinderInfo() != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "sync rpa info to linkfinder fail.");
}
return SOFTBUS_OK;
}
@ -2375,6 +2430,10 @@ int32_t LnnInitNetBuilder(void)
LnnInitTopoManager();
InitNodeInfoSync();
NetBuilderConfigInit();
// link finder init fail will not cause softbus init fail
if (LnnLinkFinderInit() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "link finder init fail");
}
if (RegAuthVerifyListener(&g_verifyListener) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register auth verify listener fail");
return SOFTBUS_ERR;
@ -2465,7 +2524,12 @@ int32_t LnnServerJoin(ConnectionAddr *addr, const char *pkgName)
LNN_LOGE(LNN_BUILDER, "prepare join lnn message fail");
return SOFTBUS_MALLOC_ERR;
}
LnnEventExtra lnnEventExtra = { .callerPkg = pkgName };
BuildLnnEvent(&lnnEventExtra, addr);
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
if (PostMessageToHandler(MSG_TYPE_JOIN_LNN, para) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_JOIN_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "post join lnn message fail");
SoftBusFree(para);
return SOFTBUS_NETWORK_LOOPER_ERR;
@ -2519,7 +2583,11 @@ int32_t LnnServerLeave(const char *networkId, const char *pkgName)
LNN_LOGE(LNN_BUILDER, "prepare leave lnn message fail");
return SOFTBUS_MALLOC_ERR;
}
LnnEventExtra lnnEventExtra = { .callerPkg = pkgName };
LNN_EVENT(EVENT_SCENE_LEAVE_LNN, EVENT_STAGE_LEAVE_LNN_START, lnnEventExtra);
if (PostMessageToHandler(MSG_TYPE_LEAVE_LNN, para) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_LEAVE_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_LEAVE_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "post leave lnn message fail");
SoftBusFree(para);
return SOFTBUS_NETWORK_LOOPER_ERR;
@ -2553,17 +2621,26 @@ int32_t LnnNotifyDiscoveryDevice(const ConnectionAddr *addr, bool isNeedConnect)
{
JoinLnnMsgPara *para = NULL;
LnnEventExtra lnnEventExtra = {0};
BuildLnnEvent(&lnnEventExtra, addr);
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
LNN_LOGI(LNN_BUILDER, "notify discovery device enter! isNeedConnect = %d", isNeedConnect);
if (g_netBuilder.isInit == false) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_JOIN_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "no init");
return SOFTBUS_ERR;
}
para = CreateJoinLnnMsgPara(addr, DEFAULT_PKG_NAME, isNeedConnect);
if (para == NULL) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_JOIN_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "malloc discovery device message fail");
return SOFTBUS_MALLOC_ERR;
}
if (PostMessageToHandler(MSG_TYPE_DISCOVERY_DEVICE, para) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_JOIN_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "post notify discovery device message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
@ -2638,7 +2715,11 @@ void LnnSyncOfflineComplete(LnnSyncInfoType type, const char *networkId, const u
LNN_LOGE(LNN_BUILDER, "prepare notify sync offline message fail");
return;
}
LnnEventExtra lnnEventExtra = {0};
LNN_EVENT(EVENT_SCENE_LEAVE_LNN, EVENT_STAGE_LEAVE_LNN_START, lnnEventExtra);
if (PostMessageToHandler(MSG_TYPE_SYNC_OFFLINE_FINISH, para) != SOFTBUS_OK) {
lnnEventExtra.errcode = SOFTBUS_NETWORK_LEAVE_LNN_START_ERR;
LNN_EVENT(EVENT_SCENE_LEAVE_LNN, EVENT_STAGE_LEAVE_LNN_START, lnnEventExtra);
LNN_LOGE(LNN_BUILDER, "post sync offline finish message failed");
SoftBusFree(para);
}

View File

@ -15,18 +15,22 @@
#include "lnn_p2p_info.h"
#include <securec.h>
#include "auth_device_common_key.h"
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_secure_storage.h"
#include "lnn_sync_info_manager.h"
#include "wifi_direct_manager.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_json.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_json_utils.h"
#include "softbus_adapter_json.h"
#include "wifi_direct_manager.h"
#define JSON_KEY_P2P_ROLE "P2P_ROLE"
#define JSON_KEY_WIFI_CFG "WIFI_CFG"
@ -210,10 +214,14 @@ int32_t LnnInitLocalP2pInfo(NodeInfo *info)
int32_t LnnInitP2p(void)
{
if (LnnInitPtk() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init ptk fail");
}
return LnnRegSyncInfoHandler(LNN_INFO_TYPE_P2P_INFO, OnReceiveP2pSyncInfoMsg);
}
void LnnDeinitP2p(void)
{
LnnDeinitPtk();
(void)LnnUnregSyncInfoHandler(LNN_INFO_TYPE_P2P_INFO, OnReceiveP2pSyncInfoMsg);
}

View File

@ -0,0 +1,64 @@
/*
* 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 "lnn_p2p_info.h"
#include "softbus_errcode.h"
void LnnLoadPtkInfo(void)
{
return;
}
int32_t UpdateLocalPtkIfValid(char *udid)
{
(void)udid;
return SOFTBUS_ERR;
}
int32_t LnnGenerateLocalPtk(char *udid)
{
(void)udid;
return SOFTBUS_OK;
}
int32_t LnnSetLocalPtkConn(char *udid)
{
(void)udid;
return SOFTBUS_OK;
}
int32_t LnnGetLocalPtkByUdid(const char *udid, char *localPtk)
{
(void)udid;
(void)localPtk;
return SOFTBUS_OK;
}
int32_t LnnSyncPtk(char *networkId)
{
(void)networkId;
return SOFTBUS_OK;
}
int32_t LnnInitPtk(void)
{
return SOFTBUS_OK;
}
void LnnDeinitPtk(void)
{
return;
}

View File

@ -74,6 +74,7 @@ static int32_t GetAvailableBtMac(char *macStr, uint32_t len)
LNN_LOGE(LNN_BUILDER, "convert bt mac to str fail");
return ret;
}
LnnSetLocalByteInfo(BYTE_KEY_PUB_MAC, mac.addr, sizeof(mac.addr));
return SOFTBUS_OK;
}

View File

@ -20,7 +20,6 @@
#include "bus_center_info_key.h"
#include "softbus_bus_center.h"
#include "bus_center_adapter.h"
#ifdef __cplusplus
extern "C" {

View File

@ -38,6 +38,7 @@ typedef enum {
BIT_BLE_DIRECT_ONLINE,
BIT_BLE_DIRECT_CONNECT_CAPABILITY,
BIT_SUPPORT_NEGO_P2P_BY_CHANNEL_CAPABILITY,
BIT_BLE_TRIGGER_CONNECTION,
BIT_FEATURE_COUNT,
} FeatureCapability;

View File

@ -22,6 +22,7 @@
#include "lnn_connect_info.h"
#include "lnn_device_info.h"
#include "lnn_net_capability.h"
#include "softbus_def.h"
#ifdef __cplusplus
extern "C" {
@ -31,11 +32,32 @@ extern "C" {
#define OFFLINE_CODE_LEN 32
#define OFFLINE_CODE_BYTE_SIZE 4
#define EXTDATA_LEN 8
#define PTK_DEFAULT_LEN 32
#define STATIC_CAP_LEN 100
#define STATIC_CAP_STR_LEN 201
#define PTK_ENCODE_LEN 45
#define LNN_RELATION_MASK 0x03
#define WIFI_CFG_INFO_MAX_LEN 512
#define CHANNEL_LIST_STR_LEN 256
#define SESSION_KEY_STR_LEN 65
#define BROADCAST_IV_LEN 16
#define BROADCAST_IV_STR_LEN 33
#define LFINDER_UDID_HASH_LEN 32
#define LFINDER_IRK_LEN 16
#define LFINDER_IRK_STR_LEN 33
#define LFINDER_MAC_ADDR_LEN 6
#define LFINDER_MAC_ADDR_STR_LEN 13
typedef enum {
AUTH_AS_CLIENT_SIDE = 0,
AUTH_AS_SERVER_SIDE,
AUTH_SIDE_MAX,
} AuthSide;
typedef enum {
ROLE_UNKNOWN = 0,
ROLE_CONTROLLER,
@ -85,6 +107,18 @@ typedef enum {
BIT_SUPPORT_EXCHANGE_NETWORKID = 0,
} AuthCapability;
typedef struct {
int32_t keylen;
unsigned char key[SESSION_KEY_LENGTH];
unsigned char iv[BROADCAST_IV_LEN];
} BroadcastCipherInfo;
typedef struct {
uint8_t peerIrk[LFINDER_IRK_LEN];
unsigned char publicAddress[LFINDER_MAC_ADDR_LEN];
unsigned char peerUdidHash[LFINDER_UDID_HASH_LEN];
} RpaInfo;
typedef struct {
char softBusVersion[VERSION_MAX_LEN];
char versionType[VERSION_MAX_LEN]; // compatible nearby
@ -138,6 +172,9 @@ typedef struct {
BroadcastCipherInfo cipherInfo;
int32_t bleMacRefreshSwitch;
int32_t bleConnCloseDelayTime;
uint8_t staticCapability[STATIC_CAP_LEN];
int32_t staticCapLen;
char remotePtk[PTK_DEFAULT_LEN];
} NodeInfo;
const char *LnnGetDeviceUdid(const NodeInfo *info);
@ -180,6 +217,9 @@ int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac);
const char *LnnGetP2pGoMac(const NodeInfo *info);
uint64_t LnnGetSupportedProtocols(const NodeInfo *info);
int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols);
int32_t LnnSetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
int32_t LnnGetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
int32_t LnnSetPtk(NodeInfo *info, const char *remotePtk);
#ifdef __cplusplus
}

View File

@ -19,6 +19,7 @@
#include <string.h>
#include <securec.h>
#include "bus_center_adapter.h"
#include "lnn_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"

View File

@ -29,6 +29,7 @@
#include "lnn_log.h"
#include "lnn_meta_node_ledger.h"
#include "lnn_meta_node_interface.h"
#include "lnn_p2p_info.h"
#include "lnn_device_info_recovery.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
@ -37,6 +38,10 @@
int32_t LnnInitNetLedger(void)
{
if (LnnInitHuksInterface() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init huks interface fail");
return SOFTBUS_ERR;
}
if (LnnInitLocalLedger() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init local net ledger fail!");
return SOFTBUS_ERR;
@ -49,10 +54,6 @@ int32_t LnnInitNetLedger(void)
LNN_LOGE(LNN_LEDGER, "init meta node ledger fail");
return SOFTBUS_ERR;
}
if (LnnInitHuksInterface() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init huks interface fail");
return SOFTBUS_ERR;
}
if (LnnInitMetaNodeExtLedger() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init meta node ext ledger fail");
return SOFTBUS_ERR;
@ -98,6 +99,8 @@ static void LnnRestoreLocalDeviceInfo()
return;
}
LoadBleBroadcastKey();
LnnLoadPtkInfo();
LnnLoadLocalBroadcastCipherKey();
LNN_LOGI(LNN_LEDGER, "load remote deviceInfo devicekey success");
}

View File

@ -424,3 +424,50 @@ int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols)
info->supportedProtocols = protocols;
return SOFTBUS_OK;
}
int32_t LnnSetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len)
{
if (info == NULL || cap == NULL) {
LNN_LOGE(LNN_LEDGER, "param is null");
return SOFTBUS_INVALID_PARAM;
}
if (len <= 0 || len > STATIC_CAP_LEN) {
LNN_LOGE(LNN_LEDGER, "length error");
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s(info->staticCapability, STATIC_CAP_LEN, cap, len) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy static cap err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnGetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len)
{
if (info == NULL || cap == NULL) {
LNN_LOGE(LNN_LEDGER, "param err");
return SOFTBUS_INVALID_PARAM;
}
if (len < 0 || len > STATIC_CAP_LEN) {
LNN_LOGE(LNN_LEDGER, "param err");
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s(cap, len, info->staticCapability, info->staticCapLen) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy static cap err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnSetPtk(NodeInfo *info, const char *remotePtk)
{
if (info == NULL || remotePtk == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s(info->remotePtk, PTK_DEFAULT_LEN, remotePtk, PTK_DEFAULT_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy ptk err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}

View File

@ -87,6 +87,8 @@ int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort);
int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort);
int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort);
NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
bool LnnSetDlPtk(const char *networkId, const char *remotePtk);
#ifdef __cplusplus
}
#endif

View File

@ -21,6 +21,7 @@
#include <securec.h>
#include "lnn_event.h"
#include "anonymizer.h"
#include "lnn_connection_addr_utils.h"
#include "lnn_fast_offline.h"
@ -733,6 +734,52 @@ static int32_t DlGetNodeBleMac(const char *networkId, void *buf, uint32_t len)
return SOFTBUS_OK;
}
static int32_t DlGetRemotePtk(const char *networkId, void *buf, uint32_t len)
{
if (len != PTK_DEFAULT_LEN) {
LNN_LOGE(LNN_LEDGER, "length error");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->remotePtk, PTK_DEFAULT_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy remote ptk err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t DlGetStaticCapLen(const char *networkId, void *buf, uint32_t len)
{
NodeInfo *info = NULL;
if (len != LNN_COMMON_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (!LnnIsNodeOnline(info)) {
LNN_LOGE(LNN_LEDGER, "device is offline");
return SOFTBUS_ERR;
}
*((int32_t *)buf) = info->staticCapLen;
return SOFTBUS_OK;
}
static int32_t DlGetStaticCap(const char *networkId, void *buf, uint32_t len)
{
if (len > STATIC_CAP_LEN) {
LNN_LOGE(LNN_LEDGER, "length error");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->staticCapability, STATIC_CAP_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy static cap err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
void LnnUpdateNodeBleMac(const char *networkId, char *bleMac, uint32_t len)
{
if ((networkId == NULL) || (bleMac == NULL) || (len != MAC_LEN)) {
@ -1038,6 +1085,50 @@ static int32_t DlGetAccountHash(const char *networkId, void *buf, uint32_t len)
return SOFTBUS_OK;
}
static int32_t DlGetDeviceIrk(const char *networkId, void *buf, uint32_t len)
{
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->rpaInfo.peerIrk, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy peerIrk fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t DlGetDevicePubMac(const char *networkId, void *buf, uint32_t len)
{
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy publicAddress fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t DlGetDeviceCipherInfoKey(const char *networkId, void *buf, uint32_t len)
{
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->cipherInfo.key, SESSION_KEY_LENGTH) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipher key fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t DlGetDeviceCipherInfoIv(const char *networkId, void *buf, uint32_t len)
{
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (memcpy_s(buf, len, info->cipherInfo.iv, BROADCAST_IV_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipher iv fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static DistributedLedgerKey g_dlKeyTable[] = {
{STRING_KEY_HICE_VERSION, DlGetNodeSoftBusVersion},
{STRING_KEY_DEV_UDID, DlGetDeviceUdid},
@ -1067,8 +1158,15 @@ static DistributedLedgerKey g_dlKeyTable[] = {
{NUM_KEY_STATE_VERSION, DlGetStateVersion},
{NUM_KEY_DATA_CHANGE_FLAG, DlGetNodeDataChangeFlag},
{NUM_KEY_DEV_TYPE_ID, DlGetDeviceTypeId},
{NUM_KEY_STATIC_CAP_LEN, DlGetStaticCapLen},
{BOOL_KEY_TLV_NEGOTIATION, DlGetNodeTlvNegoFlag},
{BYTE_KEY_ACCOUNT_HASH, DlGetAccountHash},
{BYTE_KEY_REMOTE_PTK, DlGetRemotePtk},
{BYTE_KEY_STATIC_CAPABILITY, DlGetStaticCap},
{BYTE_KEY_IRK, DlGetDeviceIrk},
{BYTE_KEY_PUB_MAC, DlGetDevicePubMac},
{BYTE_KEY_BROADCAST_CIPHER_KEY, DlGetDeviceCipherInfoKey},
{BYTE_KEY_BROADCAST_CIPHER_IV, DlGetDeviceCipherInfoIv},
};
static char *CreateCnnCodeKey(const char *uuid, DiscoveryType type)
@ -1151,16 +1249,23 @@ short LnnGetCnnCode(const char *uuid, DiscoveryType type)
static void MergeLnnInfo(const NodeInfo *oldInfo, NodeInfo *info)
{
int32_t i;
int32_t i, j;
for (i = 0; i < CONNECTION_ADDR_MAX; ++i) {
info->relation[i] += oldInfo->relation[i];
info->relation[i] &= LNN_RELATION_MASK;
if (oldInfo->authChannelId[i] != 0) {
info->authChannelId[i] = oldInfo->authChannelId[i];
for (j = 0; j < AUTH_SIDE_MAX; ++j) {
if (oldInfo->authChannelId[i][j] != 0 && info->authChannelId[i][j] == 0) {
info->authChannelId[i][j] = oldInfo->authChannelId[i][j];
}
}
if (oldInfo->authChannelId[i][AUTH_AS_CLIENT_SIDE] != 0 ||
oldInfo->authChannelId[i][AUTH_AS_SERVER_SIDE] != 0 || info->authChannelId[i][AUTH_AS_CLIENT_SIDE] != 0 ||
info->authChannelId[i][AUTH_AS_SERVER_SIDE] != 0 ) {
LNN_LOGD(LNN_LEDGER, "Merge authChannelId %d|%d -> %d|%d, addrType = %d ",
oldInfo->authChannelId[i][AUTH_AS_CLIENT_SIDE], oldInfo->authChannelId[i][AUTH_AS_SERVER_SIDE],
info->authChannelId[i][AUTH_AS_CLIENT_SIDE], info->authChannelId[i][AUTH_AS_SERVER_SIDE], i);
}
LNN_LOGI(LNN_LEDGER,
"Update authChannelId: %d, addrType=%d.", info->authChannelId[i], i);
}
}
@ -1364,13 +1469,15 @@ static void NotifyMigrateUpgrade(NodeInfo *info)
static void FilterWifiInfo(NodeInfo *info)
{
(void)LnnClearDiscoveryType(info, DISCOVERY_TYPE_WIFI);
info->authChannelId[CONNECTION_ADDR_WLAN] = 0;
info->authChannelId[CONNECTION_ADDR_WLAN][AUTH_AS_CLIENT_SIDE] = 0;
info->authChannelId[CONNECTION_ADDR_WLAN][AUTH_AS_SERVER_SIDE] = 0;
}
static void FilterBrInfo(NodeInfo *info)
{
(void)LnnClearDiscoveryType(info, DISCOVERY_TYPE_BR);
info->authChannelId[CONNECTION_ADDR_BR] = 0;
info->authChannelId[CONNECTION_ADDR_BR][AUTH_AS_CLIENT_SIDE] = 0;
info->authChannelId[CONNECTION_ADDR_BR][AUTH_AS_SERVER_SIDE] = 0;
}
static void BleDirectlyOnlineProc(NodeInfo *info)
@ -1462,6 +1569,8 @@ ReportCategory LnnAddOnlineNode(NodeInfo *info)
udid = LnnGetDeviceUdid(info);
map = &g_distributedNetLedger.distributedInfo;
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_END, lnnEventExtra);
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
LNN_LOGE(LNN_LEDGER, "lock mutex fail!");
return REPORT_NONE;
@ -1588,15 +1697,45 @@ static void NotifyMigrateDegrade(const char *udid)
}
}
static ReportCategory ClearAuthChannelId(NodeInfo *info, ConnectionAddrType type, int32_t authId)
{
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_WIFI) && LnnConvAddrTypeToDiscType(type) == DISCOVERY_TYPE_WIFI) {
if (info->authChannelId[type][AUTH_AS_CLIENT_SIDE] == authId) {
info->authChannelId[type][AUTH_AS_CLIENT_SIDE] = 0;
}
if (info->authChannelId[type][AUTH_AS_SERVER_SIDE] == authId) {
info->authChannelId[type][AUTH_AS_SERVER_SIDE] = 0;
}
if (info->authChannelId[type][AUTH_AS_CLIENT_SIDE] != 0 ||
info->authChannelId[type][AUTH_AS_SERVER_SIDE] != 0) {
LNN_LOGI(LNN_LEDGER, "authChannelId(%d|%d) not clear, not need to report offline.",
info->authChannelId[type][AUTH_AS_CLIENT_SIDE], info->authChannelId[type][AUTH_AS_SERVER_SIDE]);
return REPORT_NONE;
}
}
info->authChannelId[type][AUTH_AS_CLIENT_SIDE] = 0;
info->authChannelId[type][AUTH_AS_SERVER_SIDE] = 0;
return REPORT_OFFLINE;
}
static void LnnCleanNodeInfo(NodeInfo *info)
{
LnnSetNodeConnStatus(info, STATUS_OFFLINE);
LnnClearAuthTypeValue(&info->AuthTypeValue, ONLINE_HICHAIN);
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
LNN_LOGI(LNN_LEDGER, "need to report offline");
}
ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int32_t authId)
{
NodeInfo *info = NULL;
DoubleHashMap *map = &g_distributedNetLedger.distributedInfo;
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
LNN_LOGE(LNN_LEDGER, "lock mutex fail!");
return REPORT_NONE;
}
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
LNN_EVENT(EVENT_SCENE_LEAVE_LNN, EVENT_STAGE_LEAVE_LNN_END, lnnEventExtra);
info = (NodeInfo *)LnnMapGet(&map->udidMap, udid);
if (info == NULL) {
LNN_LOGE(LNN_LEDGER, "PARA ERROR!");
@ -1609,20 +1748,16 @@ ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int3
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_BR) && LnnConvAddrTypeToDiscType(type) == DISCOVERY_TYPE_BR) {
RemoveCnnCode(&g_distributedNetLedger.cnnCode.connectionCode, info->uuid, DISCOVERY_TYPE_BR);
}
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_WIFI) && LnnConvAddrTypeToDiscType(type) == DISCOVERY_TYPE_WIFI &&
info->authChannelId[type] != authId) {
LNN_LOGI(LNN_LEDGER, "authChannelId != authId, not need to report offline.");
if (ClearAuthChannelId(info, type, authId) == REPORT_NONE) {
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return REPORT_NONE;
}
info->authChannelId[type] = 0;
if (LnnConvAddrTypeToDiscType(type) == DISCOVERY_TYPE_WIFI) {
LnnSetWiFiIp(info, LOCAL_IP);
}
LnnClearDiscoveryType(info, LnnConvAddrTypeToDiscType(type));
if (info->discoveryType != 0) {
LNN_LOGI(LNN_LEDGER, "discoveryType=%u after clear, not need to report offline.",
info->discoveryType);
LNN_LOGI(LNN_LEDGER, "discoveryType=%u after clear, not need to report offline.", info->discoveryType);
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
UpdateNetworkInfo(udid);
if (type == CONNECTION_ADDR_WLAN) {
@ -1635,10 +1770,7 @@ ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int3
LNN_LOGI(LNN_LEDGER, "the state is already offline, no need to report offline");
return REPORT_NONE;
}
LnnSetNodeConnStatus(info, STATUS_OFFLINE);
LnnClearAuthTypeValue(&info->AuthTypeValue, ONLINE_HICHAIN);
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
LNN_LOGI(LNN_LEDGER, "need to report offline");
LnnCleanNodeInfo(info);
return REPORT_OFFLINE;
}
@ -1843,6 +1975,33 @@ EXIT:
return false;
}
bool LnnSetDlPtk(const char *networkId, const char *remotePtk)
{
NodeInfo *node = NULL;
if (networkId == NULL || remotePtk == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return false;
}
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
LNN_LOGE(LNN_LEDGER, "lock mutex fail");
return false;
}
node = LnnGetNodeInfoById(networkId, CATEGORY_NETWORK_ID);
if (node == NULL) {
LNN_LOGE(LNN_LEDGER, "get node info fail");
goto EXIT;
}
if (LnnSetPtk(node, remotePtk) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set ptk fail");
goto EXIT;
}
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return true;
EXIT:
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return false;
}
int32_t LnnGetRemoteStrInfo(const char *networkId, InfoKey key, char *info, uint32_t len)
{
uint32_t i;

View File

@ -24,6 +24,7 @@
#include "anonymizer.h"
#include "bus_center_adapter.h"
#include "bus_center_manager.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_device_info_recovery.h"
#include "lnn_log.h"
#include "lnn_ohos_account.h"
@ -1085,6 +1086,156 @@ void LnnUpdateStateVersion()
return UpdateStateVersionAndStore();
}
static int32_t LlGetStaticCapLen(void *buf, uint32_t len)
{
if (buf == NULL || len > sizeof(int32_t)) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
*((int64_t *)buf) = g_localNetLedger.localInfo.staticCapLen;
return SOFTBUS_OK;
}
static int32_t LlUpdateStaticCapLen(const void *len)
{
if (len == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid length");
return SOFTBUS_INVALID_PARAM;
}
g_localNetLedger.localInfo.staticCapLen = *(int32_t *)len;
return SOFTBUS_OK;
}
int32_t LlUpdateStaticCapability(const void *staticCap)
{
if (staticCap == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
return LnnSetStaticCapability(info, (uint8_t *)staticCap, info->staticCapLen);
}
int32_t LlGetStaticCapability(void *buf, uint32_t len)
{
if (buf == NULL || len > STATIC_CAP_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
if (LnnGetStaticCapability(info, (uint8_t *)buf, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "get static cap fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t LlGetIrk(void *buf, uint32_t len)
{
if (buf == NULL || len == 0) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
if (memcpy_s(buf, len, info->rpaInfo.peerIrk, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy peerIrk fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t LlGetPubMac(void *buf, uint32_t len)
{
if (buf == NULL || len == 0) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
if (memcpy_s(buf, len, info->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy publicAddress fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t LlGetCipherInfoKey(void *buf, uint32_t len)
{
if (buf == NULL || len == 0) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
if (memcpy_s(buf, len, info->cipherInfo.key, SESSION_KEY_LENGTH) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipher key fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t LlGetCipherInfoIv(void *buf, uint32_t len)
{
if (buf == NULL || len == 0) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo *info = &g_localNetLedger.localInfo;
if (memcpy_s(buf, len, info->cipherInfo.iv, BROADCAST_IV_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipher iv fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t UpdateLocalIrk(const void *id)
{
if (id == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s((char *)g_localNetLedger.localInfo.rpaInfo.peerIrk, LFINDER_IRK_LEN, id, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy peerIrk fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t UpdateLocalPubMac(const void *id)
{
if (id == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s((char *)g_localNetLedger.localInfo.rpaInfo.publicAddress,
LFINDER_MAC_ADDR_LEN, id, LFINDER_MAC_ADDR_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy publicAddress fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t UpdateLocalCipherInfoKey(const void *id)
{
if (id == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s((char *)g_localNetLedger.localInfo.cipherInfo.key,
SESSION_KEY_LENGTH, id, SESSION_KEY_LENGTH) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipherInfo.key fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t UpdateLocalCipherInfoIv(const void *id)
{
if (id == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s((char *)g_localNetLedger.localInfo.cipherInfo.iv, BROADCAST_IV_LEN, id, BROADCAST_IV_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy cipherInfo.iv fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static LocalLedgerKey g_localKeyTable[] = {
{STRING_KEY_HICE_VERSION, VERSION_MAX_LEN, LlGetNodeSoftBusVersion, NULL},
{STRING_KEY_DEV_UDID, UDID_BUF_LEN, LlGetDeviceUdid, UpdateLocalDeviceUdid},
@ -1101,8 +1252,8 @@ static LocalLedgerKey g_localKeyTable[] = {
{STRING_KEY_MASTER_NODE_UDID, UDID_BUF_LEN, L1GetMasterNodeUdid, UpdateMasterNodeUdid},
{STRING_KEY_NODE_ADDR, SHORT_ADDRESS_MAX_LEN, LlGetNodeAddr, LlUpdateNodeAddr},
{STRING_KEY_P2P_MAC, MAC_LEN, LlGetP2pMac, UpdateP2pMac},
{ STRING_KEY_WIFI_CFG, WIFI_CFG_INFO_MAX_LEN, L1GetWifiCfg, UpdateWifiCfg},
{ STRING_KEY_CHAN_LIST_5G, CHANNEL_LIST_STR_LEN, L1GetChanList5g, UpdateChanList5g},
{STRING_KEY_WIFI_CFG, WIFI_CFG_INFO_MAX_LEN, L1GetWifiCfg, UpdateWifiCfg},
{STRING_KEY_CHAN_LIST_5G, CHANNEL_LIST_STR_LEN, L1GetChanList5g, UpdateChanList5g},
{STRING_KEY_P2P_GO_MAC, MAC_LEN, LlGetP2pGoMac, UpdateP2pGoMac},
{STRING_KEY_OFFLINE_CODE, OFFLINE_CODE_LEN, LlGetOffLineCode, LlUpdateLocalOffLineCode},
{STRING_KEY_EXTDATA, EXTDATA_LEN, LlGetExtData, LlUpdateLocalExtData},
@ -1117,12 +1268,18 @@ static LocalLedgerKey g_localKeyTable[] = {
{NUM_KEY_MASTER_NODE_WEIGHT, -1, L1GetMasterNodeWeight, UpdateMasgerNodeWeight},
{NUM_KEY_P2P_ROLE, -1, L1GetP2pRole, UpdateP2pRole},
{NUM_KEY_STATE_VERSION, -1, LlGetStateVersion, UpdateStateVersion},
{ NUM_KEY_STA_FREQUENCY, -1, L1GetStaFrequency, UpdateStaFrequency},
{NUM_KEY_STA_FREQUENCY, -1, L1GetStaFrequency, UpdateStaFrequency},
{NUM_KEY_TRANS_PROTOCOLS, sizeof(int64_t), LlGetSupportedProtocols, LlUpdateSupportedProtocols},
{NUM_KEY_DATA_CHANGE_FLAG, sizeof(int16_t), L1GetNodeDataChangeFlag, UpdateNodeDataChangeFlag},
{NUM_KEY_ACCOUNT_LONG, sizeof(int64_t), LocalGetNodeAccountId, LocalUpdateNodeAccountId},
{NUM_KEY_BLE_START_TIME, sizeof(int64_t), LocalGetNodeBleStartTime, LocalUpdateBleStartTime},
{NUM_KEY_STATIC_CAP_LEN, sizeof(int32_t), LlGetStaticCapLen, LlUpdateStaticCapLen},
{BYTE_KEY_IRK, LFINDER_IRK_LEN, LlGetIrk, UpdateLocalIrk},
{BYTE_KEY_PUB_MAC, LFINDER_MAC_ADDR_LEN, LlGetPubMac, UpdateLocalPubMac},
{BYTE_KEY_BROADCAST_CIPHER_KEY, SESSION_KEY_LENGTH, LlGetCipherInfoKey, UpdateLocalCipherInfoKey},
{BYTE_KEY_BROADCAST_CIPHER_IV, BROADCAST_IV_LEN, LlGetCipherInfoIv, UpdateLocalCipherInfoIv},
{BYTE_KEY_ACCOUNT_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount},
{BYTE_KEY_STATIC_CAPABILITY, STATIC_CAP_LEN, LlGetStaticCapability, LlUpdateStaticCapability},
};
int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
@ -1283,6 +1440,50 @@ static int32_t LnnFirstGetUdid(void)
return SOFTBUS_OK;
}
static int32_t LnnGenBroadcastCipherInfo(void)
{
if (LnnLoadLocalBroadcastCipherKey() == SOFTBUS_OK) {
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (LnnGetLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "get local info failed.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY,
broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set key error.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV,
broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set iv error.");
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_LEDGER, "load BroadcastCipherInfo success!");
return SOFTBUS_OK;
}
unsigned char cipherKey[SESSION_KEY_LENGTH] = {0};
unsigned char cipherIv[BROADCAST_IV_LEN] = {0};
if (SoftBusGenerateRandomArray(cipherKey, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "generate broadcast key error.");
return SOFTBUS_ERR;
}
if (SoftBusGenerateRandomArray(cipherIv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "generate broadcast iv error.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY, cipherKey, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set key error.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, cipherIv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set iv error.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnGetLocalNumInfo(InfoKey key, int32_t *info)
{
return LnnGetLocalInfo(key, (void*)info, sizeof(int32_t));
@ -1408,15 +1609,14 @@ int32_t LnnInitLocalLedger(void)
LNN_LOGE(LNN_LEDGER, "init local connect info error");
goto EXIT;
}
if (LnnInitLocalP2pInfo(nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init local p2p info error");
goto EXIT;
}
if (SoftBusMutexInit(&g_localNetLedger.lock, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "mutex init fail");
goto EXIT;
}
if (LnnInitLocalP2pInfo(nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "init local p2p info error");
goto EXIT;
}
if (SoftBusRegBusCenterVarDump(
(char *)SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO, &SoftBusDumpBusCenterLocalDeviceInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "SoftBusRegBusCenterVarDump regist fail");
@ -1425,6 +1625,11 @@ int32_t LnnInitLocalLedger(void)
if (LnnFirstGetUdid() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "first get udid fail, try again in one second");
}
if (LnnGenBroadcastCipherInfo() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "gen cipher fail");
return SOFTBUS_ERR;
}
g_localNetLedger.status = LL_INIT_SUCCESS;
return SOFTBUS_OK;
EXIT:

View File

@ -22,10 +22,13 @@
#include "bus_center_decision_center.h"
#include "bus_center_manager.h"
#include "lnn_bus_center_ipc.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_log.h"
#include "lnn_network_id.h"
#include "lnn_p2p_info.h"
#include "message_handler.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "softbus_def.h"
@ -252,6 +255,46 @@ void LnnNotifyDeviceVerified(const char *udid)
RemoveNotifyMessage(NOTIFY_NETWORKID_UPDATE);
}
static void UpdateBroadcastInfo()
{
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (LnnGetLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "get local info failed.");
return;
}
if (SoftBusGetSysTimeMs() < broadcastKey.endTime) {
LNN_LOGE(LNN_EVENT, "the broadcastKey don't need to update.");
return;
}
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, broadcastKey.udid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "get udid fail");
return;
}
if (SoftBusGenerateRandomArray(broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "generate broadcast key error.");
return;
}
if (SoftBusGenerateRandomArray(broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "generate broadcast iv error.");
return;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY,
broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "set key error.");
return;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV,
broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "set iv error.");
return;
}
if (LnnUpdateLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "update local broadcast key failed");
return;
}
}
void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info)
{
LnnOnlineStateEventInfo eventInfo;
@ -277,12 +320,24 @@ void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info)
}
if (!isOnline && onlineNodeNum == 0) {
LNN_LOGI(LNN_EVENT, "no online devices, post networkId update event");
UpdateBroadcastInfo();
RemoveNotifyMessage(NOTIFY_NETWORKID_UPDATE);
(void)PostNotifyMessageDelay(NOTIFY_NETWORKID_UPDATE, NETWORK_ID_UPDATE_DELAY_TIME);
}
if (isOnline) {
LNN_LOGI(LNN_EVENT, "online process, remove networkId update event");
RemoveNotifyMessage(NOTIFY_NETWORKID_UPDATE);
} else {
char peerUdid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(info->networkId, STRING_KEY_DEV_UDID, peerUdid, UDID_BUF_LEN)
!= SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "get udid error");
return;
}
if (UpdateLocalPtkIfValid(peerUdid) != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "leave lnn update fail");
return;
}
}
}

View File

@ -30,6 +30,9 @@ typedef enum {
LNN_FILE_ID_REMOTE_DEVICE,
LNN_FILE_ID_COMM_KEY,
LNN_FILE_ID_BROADCAST_KEY,
LNN_FILE_ID_PTK_KEY,
LNN_FILE_ID_IRK_KEY,
LNN_FILE_ID_BROADCAST_CIPHER,
LNN_FILE_ID_MAX
} LnnFileId;

View File

@ -24,6 +24,7 @@ extern "C" {
int32_t LnnGenLocalNetworkId(char *networkId, uint32_t len);
int32_t LnnGenLocalUuid(char *uuid, uint32_t len);
int32_t LnnGenLocalIrk(unsigned char *irk, uint32_t len);
#ifdef __cplusplus
}

View File

@ -29,6 +29,8 @@ typedef enum {
LNN_DATA_TYPE_REMOTE_DEVINFO,
LNN_DATA_TYPE_DEVICE_KEY,
LNN_DATA_TYPE_BLE_BROADCAST_KEY,
LNN_DATA_TYPE_PTK_KEY,
LNN_DATA_TYPE_LOCAL_BROADCAST_KEY,
} LnnDataType;
int32_t LnnSaveDeviceData(const char *data, LnnDataType dataType);

View File

@ -39,6 +39,9 @@ static FilePathInfo g_filePath[LNN_FILE_ID_MAX] = {
{ LNN_FILE_ID_REMOTE_DEVICE, "/dsoftbus/deviceinfo" },
{ LNN_FILE_ID_COMM_KEY, "/dsoftbus/devicecommkey" },
{ LNN_FILE_ID_BROADCAST_KEY, "/dsoftbus/broadcastkey" },
{ LNN_FILE_ID_PTK_KEY, "/dsoftbus/ptkkey" },
{ LNN_FILE_ID_IRK_KEY, "/dsoftbus/irk" },
{ LNN_FILE_ID_BROADCAST_CIPHER, "/dsoftbus/cipher" },
};
static int32_t InitStorageConfigPath(void)

View File

@ -22,6 +22,8 @@
#include "lnn_file_utils.h"
#include "lnn_log.h"
#include "lnn_node_info.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_file.h"
#include "softbus_bus_center.h"
#include "softbus_def.h"
@ -90,4 +92,52 @@ int32_t LnnGenLocalUuid(char *uuid, uint32_t len)
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t GetIrkFromFile(unsigned char *irk, uint32_t len)
{
int32_t rc;
char irkFilePath[SOFTBUS_MAX_PATH_LEN] = {0};
rc = LnnGetFullStoragePath(LNN_FILE_ID_IRK_KEY, irkFilePath, SOFTBUS_MAX_PATH_LEN);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "get irk save path fail");
return SOFTBUS_ERR;
}
if (SoftBusReadFullFile(irkFilePath, (char *)irk, len) != SOFTBUS_OK) {
if (SoftBusGenerateRandomArray(irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "generate irk id fail");
return SOFTBUS_ERR;
}
if (SoftBusWriteFile(irkFilePath, (char *)irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "write irk to file failed");
return SOFTBUS_ERR;
}
}
return SOFTBUS_OK;
}
int32_t LnnGenLocalIrk(unsigned char *irk, uint32_t len)
{
static bool isIrkGenerated = false;
static char locaIrk[LFINDER_IRK_LEN] = {0};
if (irk == NULL || len < LFINDER_IRK_LEN) {
return SOFTBUS_INVALID_PARAM;
}
if (!isIrkGenerated) {
if (GetIrkFromFile((unsigned char *)locaIrk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "get irk from file failed");
return SOFTBUS_ERR;
}
isIrkGenerated = true;
}
if (memcpy_s(irk, len, locaIrk, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_STATE, "copy irk id fail");
isIrkGenerated = false;
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}

View File

@ -46,6 +46,7 @@ if (defined(ohos_lite)) {
build_type = "static_library"
} else {
diff_deps = [
"$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$hilog_lite_deps_path",
"//build/lite/config/component/cJSON:cjson_shared",
@ -110,6 +111,7 @@ if (defined(ohos_lite)) {
defines += [ "SOFTBUS_SMALL_SYSTEM" ]
}
deps = [
"$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$dsoftbus_root_path/adapter:softbus_adapter",
]
@ -181,6 +183,8 @@ if (defined(ohos_lite)) {
public_configs = [ ":dsoftbus_utils_interface_L2" ]
public_deps = [
"$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
"$dsoftbus_dfx_path/event:softbus_dfx_event",
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$dsoftbus_root_path/adapter:softbus_adapter",
"//third_party/cJSON:cjson",
@ -196,7 +200,10 @@ if (defined(ohos_lite)) {
]
}
if (is_standard_system) {
external_deps = [ "hilog:libhilog" ]
external_deps = [
"hilog:libhilog",
"hisysevent:libhisysevent",
]
}
innerapi_tags = [ "platformsdk_indirect" ]
part_name = "dsoftbus"

View File

@ -0,0 +1,80 @@
# 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.
import("../dsoftbus_dfx.gni")
dsoftbus_root_path = "../../../.."
softbus_anonymizer_src = [ "src/anonymizer.c" ]
if (defined(ohos_lite)) {
if (ohos_kernel_type == "liteos_m") {
build_type = "static_library"
} else {
build_type = "shared_library"
}
config("dsoftbus_anonymizer_interface_lite") {
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$hilog_lite_include_path",
]
cflags = ohos_lite_cflags
cflags_cc = ohos_lite_cflags
}
target(build_type, "softbus_dfx_anonymizer") {
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
]
sources = softbus_anonymizer_src
deps = [ "$hilog_lite_deps_path" ]
public_configs = [ ":dsoftbus_anonymizer_interface_lite" ]
}
} else {
config("dsoftbus_anonymizer_interface_std") {
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
]
}
ohos_shared_library("softbus_dfx_anonymizer") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
"//third_party/bounds_checking_function/include",
]
sources = softbus_anonymizer_src
defines = [ "SOFTBUS_STANDARD_SYSTEM" ]
defines += [ "__STDC_FORMAT_MACROS" ]
if (is_asan) {
defines += [ "ASAN_BUILD" ]
}
public_configs = [ ":dsoftbus_anonymizer_interface_std" ]
deps = [
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"//third_party/bounds_checking_function:libsec_shared",
]
external_deps = [ "hilog:libhilog" ]
innerapi_tags = [ "platformsdk_indirect" ]
part_name = "dsoftbus"
subsystem_name = "communication"
}
}

View File

@ -0,0 +1,66 @@
# 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.
import("../dsoftbus_dfx.gni")
dsoftbus_root_path = "../../../.."
softbus_event_src = [
"src/conn_event.c",
"src/disc_event.c",
"src/lnn_event.c",
"src/softbus_event.c",
"src/trans_event.c",
]
if (!defined(ohos_lite)) {
config("dsoftbus_event_interface_std") {
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
]
}
ohos_shared_library("softbus_dfx_event") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
include_dirs = [
"$dsoftbus_dfx_path/interface/include",
"$dsoftbus_root_path/interfaces/kits/common",
"//third_party/bounds_checking_function/include",
"src",
]
sources = softbus_event_src
defines = [ "SOFTBUS_STANDARD_SYSTEM" ]
defines += [ "__STDC_FORMAT_MACROS" ]
if (is_asan) {
defines += [ "ASAN_BUILD" ]
}
public_configs = [ ":dsoftbus_event_interface_std" ]
deps = [
"$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"//third_party/bounds_checking_function:libsec_shared",
]
external_deps = [
"hilog:libhilog",
"hisysevent:libhisysevent",
]
innerapi_tags = [ "platformsdk_indirect" ]
part_name = "dsoftbus"
subsystem_name = "communication"
}
}

View File

@ -17,15 +17,14 @@
#include "softbus_event.h"
#define CONN_EVENT_NAME "CONN_EVENT"
void ConnEventInner(int32_t scene, int32_t stage, const char *func, const ConnEventExtra extra)
void ConnEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, ConnEventExtra extra)
{
SoftbusEventForm form = {
.eventName = CONN_EVENT_NAME,
.scene = scene,
.stage = stage,
.func = func,
.line = line,
.connExtra = extra,
};
SoftbusEventInner(EVENT_MODULE_CONN, form);

View File

@ -0,0 +1,95 @@
/*
* 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.
*/
#ifndef CONN_EVENT_CONVERTER_H
#define CONN_EVENT_CONVERTER_H
#include "softbus_event_converter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CONN_ASSIGNER(type, filedName, filed) \
static inline bool ConnAssigner##filedName( \
const char eventName[], HiSysEventParamType paramType, SoftbusEventForm form, HiSysEventParam *param) \
{ \
if (Assigner##type(form.connExtra.filed, &param) && CopyString(param->name, eventName)) { \
param->t = paramType; \
return true; \
} \
return false; \
}
CONN_ASSIGNER(Int32, Result, result)
CONN_ASSIGNER(Errcode, Errcode, errcode)
CONN_ASSIGNER(Int32, ConnectionId, connectionId)
CONN_ASSIGNER(Int32, RequestId, requestId)
CONN_ASSIGNER(Int32, LinkType, linkType)
CONN_ASSIGNER(Int32, AuthType, authType)
CONN_ASSIGNER(Int32, AuthId, authId)
CONN_ASSIGNER(String, LnnType, lnnType)
CONN_ASSIGNER(Int32, ExpectRole, expectRole)
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(String, PeerPort, peerPort)
CONN_ASSIGNER(String, CallerPkg, callerPkg)
CONN_ASSIGNER(String, CalleePkg, calleePkg)
#define CONN_ASSIGNER_SIZE 20 // Size of g_connAssigners
static HiSysEventParamAssigner g_connAssigners[] = {
{"STAGE_RES", HISYSEVENT_INT32, ConnAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, ConnAssignerErrcode },
{ "CONN_ID", HISYSEVENT_INT32, ConnAssignerConnectionId },
{ "REQ_ID", HISYSEVENT_INT32, ConnAssignerRequestId },
{ "LINK_TYPE", HISYSEVENT_INT32, ConnAssignerLinkType },
{ "AUTH_TYPE", HISYSEVENT_INT32, ConnAssignerAuthType },
{ "AUTH_ID", HISYSEVENT_INT32, ConnAssignerAuthId },
{ "LNN_TYPE", HISYSEVENT_STRING, ConnAssignerLnnType },
{ "EXPECT_ROLE", HISYSEVENT_INT32, ConnAssignerExpectRole },
{ "COST_TIME", HISYSEVENT_INT32, ConnAssignerCostTime },
{ "RSSI", HISYSEVENT_INT32, ConnAssignerRssi },
{ "CHLOAD", HISYSEVENT_INT32, ConnAssignerLoad },
{ "FREQ", HISYSEVENT_INT32, ConnAssignerFrequency },
{ "PEER_IP", HISYSEVENT_STRING, ConnAssignerPeerIp },
{ "PEER_BR_MAC", HISYSEVENT_STRING, ConnAssignerPeerBrMac },
{ "PEER_BLE_MAC", HISYSEVENT_STRING, ConnAssignerPeerBleMac },
{ "PEER_WIFI_MAC", HISYSEVENT_STRING, ConnAssignerPeerWifiMac },
{ "PEER_PORT", HISYSEVENT_STRING, ConnAssignerPeerPort },
{ "HOST_PKG", HISYSEVENT_STRING, ConnAssignerCallerPkg },
{ "TO_CALL_PKG", HISYSEVENT_STRING, ConnAssignerCalleePkg },
// Modification Note: remember updating CONN_ASSIGNER_SIZE
};
static inline void ConvertConnForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm form)
{
for (size_t i = 0; i < size; ++i) {
HiSysEventParamAssigner assigner = g_connAssigners[i];
if (!assigner.Assign(assigner.name, assigner.type, form, &params[i])) {
COMM_LOGE(COMM_DFX, "assign event fail, name=%s", assigner.name);
}
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // CONN_EVENT_CONVERTER_H

View File

@ -0,0 +1,97 @@
/*
* 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.
*/
#ifndef DISC_EVENT_CONVERTER_H
#define DISC_EVENT_CONVERTER_H
#include "softbus_event_converter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DISC_ASSIGNER(type, filedName, filed) \
static inline bool DiscAssigner##filedName( \
const char eventName[], HiSysEventParamType paramType, SoftbusEventForm form, HiSysEventParam *param) \
{ \
if (Assigner##type(form.discExtra.filed, &param) && CopyString(param->name, eventName)) { \
param->t = paramType; \
return true; \
} \
return false; \
}
DISC_ASSIGNER(Int32, Result, result)
DISC_ASSIGNER(Errcode, Errcode, errcode)
DISC_ASSIGNER(Int32, BroadcastType, broadcastType)
DISC_ASSIGNER(Int32, BroadcastFreq, broadcastFreq)
DISC_ASSIGNER(Int32, ScanType, scanType)
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(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(String, PeerPort, peerPort)
DISC_ASSIGNER(String, PeerUdid, peerUdid)
DISC_ASSIGNER(String, PeerNetworkId, peerNetworkId)
DISC_ASSIGNER(String, PeerDeviceType, peerDeviceType)
DISC_ASSIGNER(String, CallerPkg, callerPkg)
#define DISC_ASSIGNER_SIZE 21 // Size of g_discAssigners
static HiSysEventParamAssigner g_discAssigners[] = {
{"STAGE_RES", HISYSEVENT_INT32, DiscAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, DiscAssignerErrcode },
{ "BROADCAST_TYPE", HISYSEVENT_INT32, DiscAssignerBroadcastType },
{ "BROADCAST_FREQ", HISYSEVENT_INT32, DiscAssignerBroadcastFreq },
{ "SCAN_TYPE", HISYSEVENT_INT32, DiscAssignerScanType },
{ "SCAN_CYCLE", HISYSEVENT_STRING, DiscAssignerScanCycle },
{ "DISC_TYPE", HISYSEVENT_INT32, DiscAssignerDiscType },
{ "DISC_MODE", HISYSEVENT_INT32, DiscAssignerDiscMode },
{ "FIRST_DISCOVERY_TIME", HISYSEVENT_INT32, DiscAssignerCostTime },
{ "LOCAL_NET_ID", HISYSEVENT_STRING, DiscAssignerLocalNetworkId },
{ "LOCAL_UDID", HISYSEVENT_STRING, DiscAssignerLocalUdid },
{ "LOCAL_DEV_TYPE", HISYSEVENT_INT32, DiscAssignerLocalDeviceType},
{ "PEER_IP", HISYSEVENT_STRING, DiscAssignerPeerIp },
{ "PEER_BR_MAC", HISYSEVENT_STRING, DiscAssignerPeerBrMac },
{ "PEER_BLE_MAC", HISYSEVENT_STRING, DiscAssignerPeerBleMac },
{ "PEER_WIFI_MAC", HISYSEVENT_STRING, DiscAssignerPeerWifiMac },
{ "PEER_PORT", HISYSEVENT_INT32, DiscAssignerPeerPort },
{ "PEER_UDID", HISYSEVENT_STRING, DiscAssignerPeerUdid },
{ "PEER_NET_ID", HISYSEVENT_STRING, DiscAssignerPeerNetworkId },
{ "PEER_DEV_TYPE", HISYSEVENT_STRING, DiscAssignerPeerDeviceType },
{ "HOST_PKG", HISYSEVENT_STRING, DiscAssignerCallerPkg },
// Modification Note: remember updating DISC_ASSIGNER_SIZE
};
static inline void ConvertDiscForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm form)
{
for (size_t i = 0; i < size; ++i) {
HiSysEventParamAssigner assigner = g_discAssigners[i];
if (!assigner.Assign(assigner.name, assigner.type, form, &params[i])) {
COMM_LOGE(COMM_DFX, "assign event fail, name=%s", assigner.name);
}
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // DISC_EVENT_CONVERTER_H

View File

@ -0,0 +1,92 @@
/*
* 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.
*/
#ifndef LNN_EVENT_CONVERTER_H
#define LNN_EVENT_CONVERTER_H
#include "softbus_event_converter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LNN_ASSIGNER(type, filedName, filed) \
static inline bool LnnAssigner##filedName( \
const char eventName[], HiSysEventParamType paramType, SoftbusEventForm form, HiSysEventParam *param) \
{ \
if (Assigner##type(form.lnnExtra.filed, &param) && CopyString(param->name, eventName)) { \
param->t = paramType; \
return true; \
} \
return false; \
}
LNN_ASSIGNER(Int32, Result, result)
LNN_ASSIGNER(Errcode, Errcode, errcode)
LNN_ASSIGNER(Int32, ConnectionId, connectionId)
LNN_ASSIGNER(Int32, AuthType, authType)
LNN_ASSIGNER(Int32, AuthId, authId)
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(String, PeerPort, peerPort)
LNN_ASSIGNER(String, PeerUdid, peerUdid)
LNN_ASSIGNER(String, PeerNetworkId, peerNetworkId)
LNN_ASSIGNER(String, PeerDeviceType, peerDeviceType)
LNN_ASSIGNER(String, CallerPkg, callerPkg)
LNN_ASSIGNER(String, CalleePkg, calleePkg)
#define LNN_ASSIGNER_SIZE 19 // Size of g_connAssigners
static const HiSysEventParamAssigner g_lnnAssigners[] = {
{"STAGE_RES", HISYSEVENT_INT32, LnnAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, LnnAssignerErrcode },
{ "CONN_ID", HISYSEVENT_INT32, LnnAssignerConnectionId },
{ "AUTH_TYPE", HISYSEVENT_INT32, LnnAssignerAuthType },
{ "AUTH_ID", HISYSEVENT_INT32, LnnAssignerAuthId },
{ "LNN_TYPE", HISYSEVENT_INT32, LnnAssignerLnnType },
{ "ONLINE_NUM", HISYSEVENT_INT32, LnnAssignerOnlineNum },
{ "PEER_DEV_ABILITY", HISYSEVENT_INT32, LnnAssignerPeerDeviceAbility},
{ "PEER_DEV_INFO", HISYSEVENT_STRING, LnnAssignerPeerDeviceInfo },
{ "PEER_IP", HISYSEVENT_STRING, LnnAssignerPeerIp },
{ "PEER_BR_MAC", HISYSEVENT_STRING, LnnAssignerPeerBrMac },
{ "PEER_BLE_MAC", HISYSEVENT_STRING, LnnAssignerPeerBleMac },
{ "PEER_WIFI_MAC", HISYSEVENT_STRING, LnnAssignerPeerWifiMac },
{ "PEER_PORT", HISYSEVENT_INT32, LnnAssignerPeerPort },
{ "PEER_UDID", HISYSEVENT_STRING, LnnAssignerPeerUdid },
{ "PEER_NET_ID", HISYSEVENT_STRING, LnnAssignerPeerNetworkId },
{ "PEER_DEV_TYPE", HISYSEVENT_INT32, LnnAssignerPeerDeviceType },
{ "HOST_PKG", HISYSEVENT_STRING, LnnAssignerCallerPkg },
{ "TO_CALL_PKG", HISYSEVENT_STRING, LnnAssignerCalleePkg },
// Modification Note: remember updating LNN_ASSIGNER_SIZE
};
static inline void ConvertLnnForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm form)
{
for (size_t i = 0; i < size; ++i) {
HiSysEventParamAssigner assigner = g_lnnAssigners[i];
if (!assigner.Assign(assigner.name, assigner.type, form, &params[i])) {
COMM_LOGE(COMM_DFX, "assign event fail, name=%s", assigner.name);
}
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // LNN_EVENT_CONVERTER_H

View File

@ -0,0 +1,128 @@
/*
* 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.
*/
#ifndef SOFTBUS_EVENT_CONVERTER_H
#define SOFTBUS_EVENT_CONVERTER_H
#include <securec.h>
#include <string.h>
#include "comm_log.h"
#include "form/softbus_event_form.h"
#include "hisysevent_c.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INVALID_INT_VALUE 0
#define PARAM_STRING_MAX_LEN 256
typedef struct {
char name[MAX_LENGTH_OF_PARAM_NAME];
HiSysEventParamType type;
bool (*Assign)(const char[], HiSysEventParamType, SoftbusEventForm, HiSysEventParam *);
} HiSysEventParamAssigner;
static inline bool InitString(char **str)
{
*str = (char *)malloc(PARAM_STRING_MAX_LEN);
if (*str == NULL) {
COMM_LOGE(COMM_DFX, "malloc param string fail");
return false;
}
if (memset_s(*str, PARAM_STRING_MAX_LEN + 1, 0, PARAM_STRING_MAX_LEN) != EOK) {
COMM_LOGE(COMM_DFX, "memset_s param string fail");
return false;
}
return true;
}
static inline bool CopyString(char *destName, const char *srcName)
{
if (strcpy_s(destName, strlen(srcName) + 1, srcName) != EOK) {
COMM_LOGE(COMM_DFX, "strcpy_s param name fail, srcName=%s", srcName);
return false;
}
return true;
}
/* Used by ASSIGNER macros */
static inline bool AssignerInt32(int32_t value, HiSysEventParam **param)
{
if (value <= INVALID_INT_VALUE) {
(*param)->v.i32 = INVALID_INT_VALUE;
return false;
}
(*param)->v.i32 = value;
return true;
}
/* Used by ASSIGNER macros */
static inline bool AssignerString(const char *value, HiSysEventParam **param)
{
if (value == NULL || strlen(value) == 0) {
(*param)->v.s = NULL;
return false;
}
return InitString(&(*param)->v.s) && CopyString((*param)->v.s, value);
}
/* Used by ASSIGNER macros */
static inline bool AssignerErrcode(int32_t value, HiSysEventParam **param)
{
(*param)->v.i32 = value;
return true;
}
#define SOFTBUS_ASSIGNER(type, filedName, filed) \
static inline bool SoftbusAssigner##filedName( \
const char eventName[], HiSysEventParamType paramType, SoftbusEventForm form, HiSysEventParam *param) \
{ \
if (Assigner##type(form.filed, &param) && CopyString(param->name, eventName)) { \
param->t = paramType; \
return true; \
} \
return false; \
}
SOFTBUS_ASSIGNER(Int32, Scene, scene)
SOFTBUS_ASSIGNER(Int32, Stage, stage)
SOFTBUS_ASSIGNER(String, OrgPkg, orgPkg)
SOFTBUS_ASSIGNER(String, Func, func)
#define SOFTBUS_ASSIGNER_SIZE 4 // Size of g_softbusAssigners
static HiSysEventParamAssigner g_softbusAssigners[] = {
{"BIZ_SCENE", HISYSEVENT_INT32, SoftbusAssignerScene },
{ "BIZ_STAGE", HISYSEVENT_INT32, SoftbusAssignerStage },
{ "ORG_PKG", HISYSEVENT_STRING, SoftbusAssignerOrgPkg},
{ "FUNC", HISYSEVENT_STRING, SoftbusAssignerFunc },
// Modification Note: remember updating SOFTBUS_ASSIGNER_SIZE
};
static inline void ConvertSoftbusForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm form)
{
for (size_t i = 0; i < size; ++i) {
HiSysEventParamAssigner assigner = g_softbusAssigners[i];
if (!assigner.Assign(assigner.name, assigner.type, form, &params[i])) {
COMM_LOGE(COMM_DFX, "assign event fail, name=%s", assigner.name);
}
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // SOFTBUS_EVENT_CONVERTER_H

View File

@ -0,0 +1,95 @@
/*
* 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.
*/
#ifndef TRANS_EVENT_CONVERTER_H
#define TRANS_EVENT_CONVERTER_H
#include "softbus_event_converter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TRANS_ASSIGNER(type, filedName, filed) \
static inline bool TransAssigner##filedName( \
const char eventName[], HiSysEventParamType paramType, SoftbusEventForm form, HiSysEventParam *param) \
{ \
if (Assigner##type(form.transExtra.filed, &param) && CopyString(param->name, eventName)) { \
param->t = paramType; \
return true; \
} \
return false; \
}
TRANS_ASSIGNER(Int32, Result, result)
TRANS_ASSIGNER(Errcode, Errcode, errcode)
TRANS_ASSIGNER(String, SocketName, socketName)
TRANS_ASSIGNER(Int32, DataType, dataType)
TRANS_ASSIGNER(Int32, ChannelType, channelType)
TRANS_ASSIGNER(Int32, LaneId, laneId)
TRANS_ASSIGNER(Int32, PreferLinkType, preferLinkType)
TRANS_ASSIGNER(Int32, LaneTransType, laneTransType)
TRANS_ASSIGNER(Int32, ChannelId, channelId)
TRANS_ASSIGNER(Int32, RequestId, requestId)
TRANS_ASSIGNER(Int32, ConnectionId, connectionId)
TRANS_ASSIGNER(Int32, LinkType, linkType)
TRANS_ASSIGNER(Int32, AuthId, authId)
TRANS_ASSIGNER(Int32, SocketFd, socketFd)
TRANS_ASSIGNER(Int32, CostTime, costTime)
TRANS_ASSIGNER(Int32, ChannelScore, channelScore)
TRANS_ASSIGNER(Int32, PeerChannelId, peerChannelId)
TRANS_ASSIGNER(String, PeerNetworkId, peerNetworkId)
TRANS_ASSIGNER(String, CallerPkg, callerPkg)
TRANS_ASSIGNER(String, CalleePkg, calleePkg)
#define TRANS_ASSIGNER_SIZE 20 // Size of g_transAssigners
static const HiSysEventParamAssigner g_transAssigners[] = {
{"STAGE_RES", HISYSEVENT_INT32, TransAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, TransAssignerErrcode },
{ "SOCKET_NAME", HISYSEVENT_STRING, TransAssignerSocketName },
{ "DATA_TYPE", HISYSEVENT_INT32, TransAssignerDataType },
{ "LOGIC_CHAN_TYPE", HISYSEVENT_INT32, TransAssignerChannelType },
{ "LANE_ID", HISYSEVENT_INT32, TransAssignerLaneId },
{ "PREFER_LINK_TYPE", HISYSEVENT_INT32, TransAssignerPreferLinkType},
{ "LANE_TRANS_TYPE", HISYSEVENT_INT32, TransAssignerLaneTransType },
{ "CHAN_ID", HISYSEVENT_INT32, TransAssignerChannelId },
{ "REQ_ID", HISYSEVENT_INT32, TransAssignerRequestId },
{ "CONN_ID", HISYSEVENT_INT32, TransAssignerConnectionId },
{ "LINK_TYPE", HISYSEVENT_INT32, TransAssignerLinkType },
{ "AUTH_ID", HISYSEVENT_INT32, TransAssignerAuthId },
{ "SOCKET_FD", HISYSEVENT_INT32, TransAssignerSocketFd },
{ "COST_TIME", HISYSEVENT_INT32, TransAssignerCostTime },
{ "CHAN_SCORE", HISYSEVENT_INT32, TransAssignerChannelScore },
{ "PEER_CHAN_ID", HISYSEVENT_INT32, TransAssignerPeerChannelId },
{ "PEER_NET_ID", HISYSEVENT_STRING, TransAssignerPeerNetworkId },
{ "HOST_PKG", HISYSEVENT_STRING, TransAssignerCallerPkg },
{ "TO_CALL_PKG", HISYSEVENT_STRING, TransAssignerCalleePkg },
// Modification Note: remember updating TRANS_ASSIGNER_SIZE
};
static inline void ConvertTransForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm form)
{
for (size_t i = 0; i < size; ++i) {
HiSysEventParamAssigner assigner = g_transAssigners[i];
if (!assigner.Assign(assigner.name, assigner.type, form, &params[i])) {
COMM_LOGE(COMM_DFX, "assign event fail, name=%s", assigner.name);
}
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // TRANS_EVENT_CONVERTER_H

View File

@ -17,15 +17,14 @@
#include "softbus_event.h"
#define DISC_EVENT_NAME "DISC_EVENT"
void DiscEventInner(int32_t scene, int32_t stage, const char *func, const DiscEventExtra extra)
void DiscEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, DiscEventExtra extra)
{
SoftbusEventForm form = {
.eventName = DISC_EVENT_NAME,
.scene = scene,
.stage = stage,
.func = func,
.line = line,
.discExtra = extra,
};
SoftbusEventInner(EVENT_MODULE_DISC, form);

View File

@ -25,24 +25,19 @@
extern "C" {
#endif
typedef enum {
STAGE_RESULT_IDLE = 0,
STAGE_RESULT_OK = 1,
STAGE_RESULT_FAILED = 2,
STAGE_RESULT_CANCELED = 3,
STAGE_RESULT_UNKNOWN = 4,
} TransEventStageResult;
#define SOFTBUS_EVENT_DOMAIN "DSOFTBUS"
#define SOFTBUS_EVENT_PKG_NAME "dsoftbus"
#define SOFTBUS_EVENT_TYPE_BEHAVIOR 4
typedef struct {
int32_t scene; // BIZ_SCENE
int32_t stage; // BIZ_STAGE
int32_t eventType; // EVENT_TYPE
int32_t line; // CODE_LINE
const char *domain; // DOMAIN
const char *eventName; // EVENT_NAME
int32_t eventType; // EVENT_TYPE
const char *orgPkg; // ORG_PKG
const char *func; // FUNC
int32_t scene; // BIZ_SCENE
int32_t stage; // BIZ_STAGE
int32_t result; // STAGE_RES
int32_t errcode; // ERROR_CODE
union {
ConnEventExtra connExtra;
DiscEventExtra discExtra;

View File

@ -17,15 +17,14 @@
#include "softbus_event.h"
#define LNN_EVENT_NAME "LNN_EVENT"
void LnnEventInner(int32_t scene, int32_t stage, const char *func, const LnnEventExtra extra)
void LnnEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, LnnEventExtra extra)
{
SoftbusEventForm form = {
.eventName = LNN_EVENT_NAME,
.scene = scene,
.stage = stage,
.func = func,
.line = line,
.lnnExtra = extra,
};
SoftbusEventInner(EVENT_MODULE_LNN, form);

View File

@ -15,23 +15,115 @@
#include "softbus_event.h"
#define SOFTBUS_EVENT_DOMAIN "DSOFTBUS"
#define SOFTBUS_EVENT_PKG_NAME "dsoftbus"
#define SOFTBUS_EVENT_TYPE_BEHAVIOR 4
#include "comm_log.h"
#include "convert/conn_event_converter.h"
#include "convert/disc_event_converter.h"
#include "convert/lnn_event_converter.h"
#include "convert/trans_event_converter.h"
#include "hisysevent_c.h"
#define HISYSEVENT_WRITE_SUCCESS 0
static size_t GetValidParamSize(
const HiSysEventParam *params, size_t size, const HiSysEventParam *extraParams, size_t extraSize)
{
size_t validSize = 0;
for (size_t i = 0; i < size; ++i) {
if (params[i].t != HISYSEVENT_INVALID) {
validSize++;
}
}
for (size_t j = 0; j < extraSize; ++j) {
if (extraParams[j].t != HISYSEVENT_INVALID) {
validSize++;
}
}
return validSize;
}
static void ConstructHiSysEventParams(HiSysEventParam *eventParams, const HiSysEventParam *params, size_t size,
const HiSysEventParam *extraParams, size_t extraSize)
{
size_t index = 0;
for (size_t i = 0; i < size; ++i) {
if (params[i].t != HISYSEVENT_INVALID) {
eventParams[index++] = params[i];
}
}
for (size_t j = 0; j < extraSize; ++j) {
if (extraParams[j].t != HISYSEVENT_INVALID) {
eventParams[index++] = extraParams[j];
}
}
}
static void WriteHiSysEvent(
HiSysEventParam params[], size_t size, HiSysEventParam extraParams[], size_t extraSize, SoftbusEventForm form)
{
size_t validParamSize = GetValidParamSize(params, size, extraParams, extraSize);
HiSysEventParam eventParams[validParamSize];
ConstructHiSysEventParams(eventParams, params, size, extraParams, extraSize);
int32_t ret = HiSysEvent_Write(
form.func, form.line, form.domain, form.eventName, form.eventType, eventParams, validParamSize);
if (ret != HISYSEVENT_WRITE_SUCCESS) {
COMM_LOGE(COMM_DFX, "write to hisysevent failed, ret=%d", ret);
}
}
static void SoftbusEventParamsFree(HiSysEventParam params[], size_t size)
{
for (size_t i = 0; i < size; ++i) {
if (params[i].t == HISYSEVENT_STRING) {
free(params[i].v.s);
}
}
}
static void WriteSoftbusEvent(SoftbusEventModule module, SoftbusEventForm form)
{
HiSysEventParam params[SOFTBUS_ASSIGNER_SIZE] = { 0 };
ConvertSoftbusForm2Param(params, SOFTBUS_ASSIGNER_SIZE, form);
switch (module) {
case EVENT_MODULE_CONN: {
HiSysEventParam connParams[CONN_ASSIGNER_SIZE] = { 0 };
ConvertConnForm2Param(connParams, CONN_ASSIGNER_SIZE, form);
WriteHiSysEvent(params, SOFTBUS_ASSIGNER_SIZE, connParams, CONN_ASSIGNER_SIZE, form);
SoftbusEventParamsFree(connParams, CONN_ASSIGNER_SIZE);
break;
}
case EVENT_MODULE_DISC: {
HiSysEventParam discParams[DISC_ASSIGNER_SIZE] = { 0 };
ConvertDiscForm2Param(discParams, DISC_ASSIGNER_SIZE, form);
WriteHiSysEvent(params, SOFTBUS_ASSIGNER_SIZE, discParams, DISC_ASSIGNER_SIZE, form);
SoftbusEventParamsFree(discParams, DISC_ASSIGNER_SIZE);
break;
}
case EVENT_MODULE_LNN: {
HiSysEventParam lnnParams[LNN_ASSIGNER_SIZE] = { 0 };
ConvertLnnForm2Param(lnnParams, LNN_ASSIGNER_SIZE, form);
WriteHiSysEvent(params, SOFTBUS_ASSIGNER_SIZE, lnnParams, LNN_ASSIGNER_SIZE, form);
SoftbusEventParamsFree(lnnParams, LNN_ASSIGNER_SIZE);
break;
}
case EVENT_MODULE_TRANS: {
HiSysEventParam transParams[TRANS_ASSIGNER_SIZE] = { 0 };
ConvertTransForm2Param(transParams, TRANS_ASSIGNER_SIZE, form);
WriteHiSysEvent(params, SOFTBUS_ASSIGNER_SIZE, transParams, TRANS_ASSIGNER_SIZE, form);
SoftbusEventParamsFree(transParams, TRANS_ASSIGNER_SIZE);
break;
}
default: {
COMM_LOGW(COMM_DFX, "invalid module %d", (int32_t)module);
break;
}
}
SoftbusEventParamsFree(params, SOFTBUS_ASSIGNER_SIZE);
}
void SoftbusEventInner(SoftbusEventModule module, SoftbusEventForm form)
{
form.domain = SOFTBUS_EVENT_DOMAIN,
form.eventType = SOFTBUS_EVENT_TYPE_BEHAVIOR,
form.domain = SOFTBUS_EVENT_DOMAIN;
form.eventType = SOFTBUS_EVENT_TYPE_BEHAVIOR;
form.orgPkg = SOFTBUS_EVENT_PKG_NAME;
switch (module) {
case EVENT_MODULE_CONN:
case EVENT_MODULE_DISC:
case EVENT_MODULE_LNN:
case EVENT_MODULE_TRANS:
// Convert and write form to hisysevent
break;
default:
break;
}
WriteSoftbusEvent(module, form);
}

View File

@ -24,6 +24,11 @@
extern "C" {
#endif
#define CONN_EVENT_NAME "CONNECTION_BEHAVIOR"
#define DISC_EVENT_NAME "DISCOVER_BEHAVIOR"
#define LNN_EVENT_NAME "BUSCENTER_BEHAVIOR"
#define TRANS_EVENT_NAME "TRANSPORT_BEHAVIOR"
typedef enum {
EVENT_MODULE_CONN,
EVENT_MODULE_DISC,

View File

@ -17,15 +17,14 @@
#include "softbus_event.h"
#define TRANS_EVENT_NAME "TRANS_EVENT"
void TransEventInner(int32_t scene, int32_t stage, const char *func, const TransEventExtra extra)
void TransEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, TransEventExtra extra)
{
SoftbusEventForm form = {
.eventName = TRANS_EVENT_NAME,
.scene = scene,
.stage = stage,
.func = func,
.line = line,
.transExtra = extra,
};
SoftbusEventInner(EVENT_MODULE_TRANS, form);

View File

@ -22,28 +22,28 @@
extern "C" {
#endif
typedef enum {
COMM_SDK,
COMM_SVC,
COMM_INIT,
COMM_DFX,
COMM_EVENT,
COMM_VERIFY,
COMM_PERM,
COMM_SVC,
COMM_UTILS,
COMM_SDK,
COMM_TEST,
} CommLogLabelEnum;
/* Keep consistent with labels */
static const SoftBusLogLabel COMM_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{ COMM_INIT, 0xd005700, "CommInit" },
{ COMM_DFX, 0xd005701, "CommDfx" },
{ COMM_EVENT, 0xd005702, "CommEvent" },
{ COMM_VERIFY, 0xd005703, "CommVerify" },
{ COMM_PERM, 0xd005704, "CommPermission" },
{ COMM_SVC, 0xd005705, "CommService" },
{ COMM_UTILS, 0xd005706, "CommUtils" },
{ COMM_SDK, 0xd005707, "CommSdk" },
{ COMM_TEST, DOMAIN_ID_TEST, "CommTest" },
{COMM_SDK, 0xd005700, "CommSdk" },
{ COMM_SVC, 0xd005701, "CommSvc" },
{ COMM_INIT, 0xd005702, "CommInit" },
{ COMM_DFX, 0xd005703, "CommDfx" },
{ COMM_EVENT, 0xd005704, "CommEvent" },
{ COMM_VERIFY, 0xd005705, "CommVerify"},
{ COMM_PERM, 0xd005706, "CommPerm" },
{ COMM_UTILS, 0xd005707, "CommUtils" },
{ COMM_TEST, DOMAIN_ID_TEST, "CommTest" },
};
#define COMM_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, COMM_LABELS[label], ##__VA_ARGS__)

View File

@ -22,10 +22,16 @@
extern "C" {
#endif
#define CONN_EVENT(scene, stage, extra) ConnEventInner(scene, stage, __FUNCTION__, extra)
#define CONN_EVENT(scene, stage, extra) ConnEventInner(scene, stage, __FUNCTION__, __LINE__, extra)
#define CONN_ALARM(scene, extra) ConnAlarmInner(scene, __FUNCTION__, __LINE__, extra)
#define CONN_STATS(scene, extra) ConnStatsInner(scene, __FUNCTION__, __LINE__, extra)
#define CONN_AUDIT(scene, extra) ConnAuditInner(scene, __FUNCTION__, __LINE__, extra)
/* For inner use only */
void ConnEventInner(int32_t scene, int32_t stage, const char *func, ConnEventExtra extra);
void ConnEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, ConnEventExtra extra);
void ConnAlarmInner(int32_t scene, const char *func, int32_t line, ConnAlarmExtra extra);
void ConnStatsInner(int32_t scene, const char *func, int32_t line, ConnStatsExtra extra);
void ConnAuditInner(int32_t scene, const char *func, int32_t line, ConnAuditExtra extra);
#ifdef __cplusplus
}

View File

@ -16,7 +16,6 @@
#ifndef DSOFTBUS_CONN_LOG_H
#define DSOFTBUS_CONN_LOG_H
#include "anonymizer.h"
#include "softbus_log.h"
#ifdef __cplusplus
@ -28,6 +27,9 @@ typedef enum {
CONN_BR,
CONN_COMMON,
CONN_WIFI_DIRECT,
CONN_NEARBY,
CONN_BLE_DIRECT,
CONN_BROADCAST,
CONN_TEST,
} ConnLogLabelEnum;
@ -38,7 +40,10 @@ static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{CONN_BR, 0xd005762, "ConnBr"},
{CONN_COMMON, 0xd005763, "ConnCommon"},
{CONN_WIFI_DIRECT, 0xd005764, "ConnWD"},
{CONN_TEST, DOMAIN_ID_TEST, "ConnTest"},
{CONN_NEARBY, 0xd005765, "ConnNearby"},
{CONN_BLE_DIRECT, 0xd005766, "ConnBD"},
{CONN_BROADCAST, 0xd005767, "ConnBC"},
{CONN_TEST, DOMAIN_ID_TEST, "ConnTest"},
};
#define CONN_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, CONN_LABELS[label], ##__VA_ARGS__)
@ -51,10 +56,19 @@ static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGW, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGE, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGI(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGI, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGD, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGW, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGE, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGI(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGI, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGD, label, fmt, ##__VA_ARGS__)
#ifdef __cplusplus
}

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