mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-12-19 15:56:47 +00:00
Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master
Signed-off-by: guowen <guowen31@huawei.com>
This commit is contained in:
commit
070969df13
@ -268,6 +268,12 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
}
|
||||
innerapi_tags = [ "platformsdk_indirect" ]
|
||||
|
||||
install_images = [
|
||||
system_base_dir,
|
||||
updater_base_dir,
|
||||
]
|
||||
|
||||
part_name = "dsoftbus"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -25,13 +25,12 @@
|
||||
#define SOFTBUS_BLE_GATT_H
|
||||
|
||||
#include "softbus_broadcast_adapter_interface.h"
|
||||
#include "softbus_broadcast_adapter_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
void softbus_ble_adapter_init(void);
|
||||
void SoftbusBleAdapterInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file softbus_ble_utils.h
|
||||
* @brief ble utils
|
||||
*
|
||||
* @since 4.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_BLE_UTILS_H
|
||||
#define SOFTBUS_BLE_UTILS_H
|
||||
|
||||
#include "softbus_broadcast_adapter_interface.h"
|
||||
#include "c_header/ohos_bt_gatt.h"
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
int32_t BtStatusToSoftBus(BtStatus btStatus);
|
||||
|
||||
void SoftbusAdvParamToBt(const SoftbusBroadcastParam *src, BleAdvParams *dst);
|
||||
|
||||
void BtScanResultToSoftbus(const BtScanResultData *src, SoftBusBcScanResult *dst);
|
||||
|
||||
void SoftbusFilterToBt(BleScanNativeFilter *nativeFilter, const SoftBusBcScanFilter *filter, uint8_t filterSize);
|
||||
|
||||
void FreeBtFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize);
|
||||
|
||||
void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize);
|
||||
|
||||
int GetBtScanMode(uint16_t scanInterval, uint16_t scanWindow);
|
||||
|
||||
uint8_t *AssembleAdvData(const SoftbusBroadcastData *data, uint16_t *dataLen);
|
||||
|
||||
uint8_t *AssembleRspData(const SoftbusBroadcastPayload *data, uint16_t *dataLen);
|
||||
|
||||
int32_t ParseScanResult(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst);
|
||||
|
||||
void DumpSoftbusAdapterData(const char *description, uint8_t *data, uint16_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SOFTBUS_BLE_UTILS_H */
|
@ -14,7 +14,804 @@
|
||||
*/
|
||||
|
||||
#include "softbus_ble_gatt.h"
|
||||
#include "softbus_adapter_thread.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_broadcast_type.h"
|
||||
#include "softbus_error_code.h"
|
||||
#include "softbus_ble_utils.h"
|
||||
#include "disc_log.h"
|
||||
#include <stdatomic.h>
|
||||
#include <string.h>
|
||||
|
||||
void softbus_ble_adapter_init(void)
|
||||
#define GATT_ADV_MAX_NUM 16
|
||||
#define GATT_SCAN_MAX_NUM 2
|
||||
#define LP_BT_UUID "43d4a49f-604d-45b5-9302-4ddbbfd538fd"
|
||||
#define LP_DELIVERY_MODE_REPLY 0xF0
|
||||
#define LP_ADV_DURATION_MS 0
|
||||
#define SCAN_CHANNEL_0 0
|
||||
#define SCAN_CHANNEL_1 1
|
||||
|
||||
static atomic_bool g_init = false;
|
||||
static atomic_bool g_bcCbReg = false;
|
||||
static SoftBusMutex g_advLock = {0};
|
||||
static SoftBusMutex g_scannerLock = {0};
|
||||
|
||||
typedef struct {
|
||||
int32_t advId;
|
||||
bool isUsed;
|
||||
bool isAdvertising;
|
||||
SoftbusBroadcastCallback *advCallback;
|
||||
} AdvChannel;
|
||||
|
||||
typedef struct {
|
||||
int32_t scannerId;
|
||||
bool isUsed;
|
||||
bool isScanning;
|
||||
SoftbusScanCallback *scanCallback;
|
||||
} ScanChannel;
|
||||
|
||||
static AdvChannel g_advChannel[GATT_ADV_MAX_NUM];
|
||||
static ScanChannel g_scanChannel[GATT_SCAN_MAX_NUM];
|
||||
|
||||
static int32_t Init(void)
|
||||
{
|
||||
if (g_init) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already inited");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
g_init = true;
|
||||
if (SoftBusMutexInit(&g_advLock, NULL) != SOFTBUS_OK) {
|
||||
g_init = false;
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "g_advLock init failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SoftBusMutexInit(&g_scannerLock, NULL) != SOFTBUS_OK) {
|
||||
SoftBusMutexDestroy(&g_advLock);
|
||||
g_init = false;
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "g_scannerLock init failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "init success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t DeInit(void)
|
||||
{
|
||||
if (!g_init) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already deinited");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
g_init = false;
|
||||
SoftBusMutexDestroy(&g_advLock);
|
||||
SoftBusMutexDestroy(&g_scannerLock);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "deinit success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void WrapperAdvEnableCallback(int advId, int status)
|
||||
{
|
||||
int32_t ret = BtStatusToSoftBus((BtStatus)status);
|
||||
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
|
||||
continue;
|
||||
}
|
||||
AdvChannel *advChannel = &g_advChannel[channelId];
|
||||
if (advChannel->advId != advId || !advChannel->isUsed) {
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
continue;
|
||||
}
|
||||
advChannel->isAdvertising = (ret == SOFTBUS_BC_STATUS_SUCCESS);
|
||||
if (!advChannel->isAdvertising) {
|
||||
advChannel->advId = -1;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (advChannel->advCallback != NULL && advChannel->advCallback->OnStartBroadcastingCallback != NULL) {
|
||||
advChannel->advCallback->OnStartBroadcastingCallback(channelId, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperAdvDisableCallback(int advId, int status)
|
||||
{
|
||||
int32_t ret = BtStatusToSoftBus((BtStatus)status);
|
||||
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
|
||||
continue;
|
||||
}
|
||||
AdvChannel *advChannel = &g_advChannel[channelId];
|
||||
if (advChannel->advId != advId || !advChannel->isUsed) {
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
continue;
|
||||
}
|
||||
advChannel->isAdvertising = false;
|
||||
advChannel->advId = -1;
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (advChannel->advCallback != NULL && advChannel->advCallback->OnStopBroadcastingCallback != NULL) {
|
||||
advChannel->advCallback->OnStopBroadcastingCallback(channelId, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperAdvSetDataCallback(int advId, int status)
|
||||
{
|
||||
int32_t ret = BtStatusToSoftBus((BtStatus)status);
|
||||
for (uint32_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
|
||||
continue;
|
||||
}
|
||||
AdvChannel *advChannel = &g_advChannel[channelId];
|
||||
if (advChannel->advId != advId || !advChannel->isUsed) {
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (advChannel->advCallback != NULL && advChannel->advCallback->OnSetBroadcastingCallback != NULL) {
|
||||
advChannel->advCallback->OnSetBroadcastingCallback(channelId, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperAdvUpdateDataCallback(int advId, int status)
|
||||
{
|
||||
int32_t ret = BtStatusToSoftBus((BtStatus)status);
|
||||
for (uint32_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "lock adv failed, advId: %u, bt-advId: %d", channelId, advId);
|
||||
continue;
|
||||
}
|
||||
AdvChannel *advChannel = &g_advChannel[channelId];
|
||||
if (advChannel->advId != advId || !advChannel->isUsed) {
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %u, bt-advId: %d, status: %d", channelId, advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (advChannel->advCallback != NULL && advChannel->advCallback->OnUpdateBroadcastingCallback != NULL) {
|
||||
advChannel->advCallback->OnUpdateBroadcastingCallback(channelId, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static BtGattCallbacks g_softbusGattCb = {
|
||||
.advEnableCb = WrapperAdvEnableCallback,
|
||||
.advDisableCb = WrapperAdvDisableCallback,
|
||||
.advDataCb = WrapperAdvSetDataCallback,
|
||||
.advUpdateCb = WrapperAdvUpdateDataCallback,
|
||||
};
|
||||
|
||||
static int32_t RegisterAdvCallback(int32_t *advId, const SoftbusBroadcastCallback *cb)
|
||||
{
|
||||
if (advId == NULL || cb == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv param is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
for (uint8_t channelId = 0; channelId < GATT_ADV_MAX_NUM; channelId++) {
|
||||
if (g_advChannel[channelId].isUsed) {
|
||||
continue;
|
||||
}
|
||||
if (!g_bcCbReg) {
|
||||
if (BleGattRegisterCallbacks(&g_softbusGattCb) != OHOS_BT_STATUS_SUCCESS) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "register failed, advId: %u", channelId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_bcCbReg = true;
|
||||
}
|
||||
g_advChannel[channelId].advId = -1;
|
||||
g_advChannel[channelId].isUsed = true;
|
||||
g_advChannel[channelId].isAdvertising = false;
|
||||
g_advChannel[channelId].advCallback = (SoftbusBroadcastCallback *)cb;
|
||||
*advId = channelId;
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "register success, advId: %u", channelId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "no available adv channel");
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static int32_t UnRegisterAdvCallback(int32_t advId)
|
||||
{
|
||||
if (advId < 0 || advId >= GATT_ADV_MAX_NUM) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "invalid advId: %d", advId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, advId: %d", advId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!g_advChannel[advId].isUsed) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already unregistered, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
|
||||
g_advChannel[advId].advId = -1;
|
||||
g_advChannel[advId].isUsed = false;
|
||||
g_advChannel[advId].isAdvertising = false;
|
||||
g_advChannel[advId].advCallback = NULL;
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void WrapperScanResultCallback(uint8_t channelId, BtScanResultData *data)
|
||||
{
|
||||
if (data == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scan result data is null, scannerId: %u", channelId);
|
||||
return;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
|
||||
return;
|
||||
}
|
||||
ScanChannel *scanChannel = &g_scanChannel[channelId];
|
||||
if (!scanChannel->isUsed || !scanChannel->isScanning) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
|
||||
channelId, scanChannel->scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return;
|
||||
}
|
||||
SoftBusBcScanResult scanResult = {};
|
||||
BtScanResultToSoftbus(data, &scanResult);
|
||||
|
||||
if (ParseScanResult(data->advData, data->advLen, &scanResult) != SOFTBUS_OK) {
|
||||
SoftBusFree(scanResult.data.bcData.payload);
|
||||
SoftBusFree(scanResult.data.rspData.payload);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return;
|
||||
}
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnReportScanDataCallback != NULL) {
|
||||
scanChannel->scanCallback->OnReportScanDataCallback(channelId, &scanResult);
|
||||
}
|
||||
SoftBusFree(scanResult.data.bcData.payload);
|
||||
SoftBusFree(scanResult.data.rspData.payload);
|
||||
}
|
||||
|
||||
static void WrapperScanStateChangeCallback(uint8_t channelId, int32_t resultCode, bool isStartScan)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
|
||||
return;
|
||||
}
|
||||
ScanChannel *scanChannel = &g_scanChannel[channelId];
|
||||
if (!scanChannel->isUsed) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
|
||||
channelId, scanChannel->scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, resultCode: %d, isStartScan: %d",
|
||||
channelId, scanChannel->scannerId, resultCode, isStartScan);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnScanStateChanged != NULL) {
|
||||
scanChannel->scanCallback->OnScanStateChanged(resultCode, isStartScan);
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperLpDeviceInfoCallback(uint8_t channelId, BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", channelId);
|
||||
return;
|
||||
}
|
||||
ScanChannel *scanChannel = &g_scanChannel[channelId];
|
||||
if (!scanChannel->isUsed) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %u, bt-scannerId: %d",
|
||||
channelId, scanChannel->scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return;
|
||||
}
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
if (scanChannel->scanCallback != NULL && scanChannel->scanCallback->OnLpDeviceInfoCallback != NULL) {
|
||||
SoftbusBroadcastUuid bcUuid;
|
||||
bcUuid.uuid = (uint8_t *)uuid->uuid;
|
||||
bcUuid.uuidLen = (uint8_t)uuid->uuidLen;
|
||||
scanChannel->scanCallback->OnLpDeviceInfoCallback(&bcUuid, type, data, dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperScanResultCallback0(BtScanResultData *data)
|
||||
{
|
||||
WrapperScanResultCallback(SCAN_CHANNEL_0, data);
|
||||
}
|
||||
|
||||
static void WrapperScanResultCallback1(BtScanResultData *data)
|
||||
{
|
||||
WrapperScanResultCallback(SCAN_CHANNEL_1, data);
|
||||
}
|
||||
|
||||
static void WrapperScanStateChangeCallback0(int32_t resultCode, bool isStartScan)
|
||||
{
|
||||
WrapperScanStateChangeCallback(SCAN_CHANNEL_0, resultCode, isStartScan);
|
||||
}
|
||||
|
||||
static void WrapperScanStateChangeCallback1(int32_t resultCode, bool isStartScan)
|
||||
{
|
||||
WrapperScanStateChangeCallback(SCAN_CHANNEL_1, resultCode, isStartScan);
|
||||
}
|
||||
|
||||
static void WrapperLpDeviceInfoCallback0(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
|
||||
{
|
||||
WrapperLpDeviceInfoCallback(SCAN_CHANNEL_0, uuid, type, data, dataSize);
|
||||
}
|
||||
|
||||
static void WrapperLpDeviceInfoCallback1(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
|
||||
{
|
||||
WrapperLpDeviceInfoCallback(SCAN_CHANNEL_1, uuid, type, data, dataSize);
|
||||
}
|
||||
|
||||
static BleScanCallbacks g_softbusBleScanCb[GATT_SCAN_MAX_NUM] = {
|
||||
{
|
||||
.scanResultCb = WrapperScanResultCallback0,
|
||||
.scanStateChangeCb = WrapperScanStateChangeCallback0,
|
||||
.lpDeviceInfoCb = WrapperLpDeviceInfoCallback0,
|
||||
},
|
||||
{
|
||||
.scanResultCb = WrapperScanResultCallback1,
|
||||
.scanStateChangeCb = WrapperScanStateChangeCallback1,
|
||||
.lpDeviceInfoCb = WrapperLpDeviceInfoCallback1,
|
||||
}
|
||||
};
|
||||
|
||||
static BleScanCallbacks *GetAdapterScanCallback(uint8_t channelId)
|
||||
{
|
||||
return &g_softbusBleScanCb[channelId];
|
||||
}
|
||||
|
||||
static int32_t RegisterScanCallback(int32_t *scannerId, const SoftbusScanCallback *cb)
|
||||
{
|
||||
if (scannerId == NULL || cb == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scan param is null");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
for (uint8_t channelId = 0; channelId < GATT_SCAN_MAX_NUM; channelId++) {
|
||||
if (g_scanChannel[channelId].isUsed) {
|
||||
continue;
|
||||
}
|
||||
if (BleRegisterScanCallbacks(GetAdapterScanCallback(channelId),
|
||||
&g_scanChannel[channelId].scannerId) != OHOS_BT_STATUS_SUCCESS) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "register callback failed, scannerId: %u", channelId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_scanChannel[channelId].isUsed = true;
|
||||
g_scanChannel[channelId].isScanning = false;
|
||||
g_scanChannel[channelId].scanCallback = (SoftbusScanCallback *)cb;
|
||||
*scannerId = channelId;
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %u, bt-scannerId: %d", channelId, g_scanChannel[channelId].scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "no available scan channel");
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static int32_t UnRegisterScanCallback(int32_t scannerId)
|
||||
{
|
||||
if (scannerId < 0 || scannerId >= GATT_SCAN_MAX_NUM) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scannerId is invalid: %d", scannerId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %u", scannerId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!g_scanChannel[scannerId].isUsed) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already unregistered, scannerId: %d, bt-scannerId: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
int32_t ret = BleDeregisterScanCallbacks(g_scanChannel[scannerId].scannerId);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, result: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId, ret);
|
||||
g_scanChannel[scannerId].scannerId = -1;
|
||||
g_scanChannel[scannerId].isUsed = false;
|
||||
g_scanChannel[scannerId].isScanning = false;
|
||||
g_scanChannel[scannerId].scanCallback = NULL;
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool CheckAdvChannelInUsed(int32_t advId)
|
||||
{
|
||||
if (advId < 0 || advId >= GATT_ADV_MAX_NUM) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "invalid advId: %d", advId);
|
||||
return false;
|
||||
}
|
||||
if (!g_advChannel[advId].isUsed) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t StartBleAdv(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
|
||||
{
|
||||
BleAdvParams advParam = {};
|
||||
SoftbusAdvParamToBt(param, &advParam);
|
||||
StartAdvRawData advRawData = {};
|
||||
advRawData.advData = (unsigned char *)AssembleAdvData(data, (uint16_t *)&advRawData.advDataLen);
|
||||
if (advRawData.advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advId: %d, bt-advId: %d",
|
||||
advId, g_advChannel[advId].advId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
advRawData.rspDataLen = 0;
|
||||
advRawData.rspData = NULL;
|
||||
if (data->rspData.payloadLen > 0 && data->rspData.payload != NULL) {
|
||||
advRawData.rspData = (unsigned char *)AssembleRspData(&data->rspData, (uint16_t *)&advRawData.rspDataLen);
|
||||
if (advRawData.rspData == NULL) {
|
||||
SoftBusFree(advRawData.advData);
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advId: %d, bt-advId: %d",
|
||||
advId, g_advChannel[advId].advId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
DumpSoftbusAdapterData("mgr pkg:", advRawData.advData, advRawData.advDataLen);
|
||||
int32_t ret = BleStartAdvEx(&g_advChannel[advId].advId, advRawData, advParam);
|
||||
SoftBusFree(advRawData.advData);
|
||||
SoftBusFree(advRawData.rspData);
|
||||
return (ret == OHOS_BT_STATUS_SUCCESS) ? SOFTBUS_OK : SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static int32_t StartAdv(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
|
||||
{
|
||||
if (param == NULL || data == NULL || data->bcData.payloadLen == 0 || data->bcData.payload == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "invalid adv param, advId: %d", advId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, advId: %d", advId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckAdvChannelInUsed(advId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (g_advChannel[advId].isAdvertising) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "already started, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int32_t ret = StartBleAdv(advId, param, data);
|
||||
g_advChannel[advId].isAdvertising = (ret == SOFTBUS_OK);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t StopAdv(int32_t advId)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckAdvChannelInUsed(advId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!g_advChannel[advId].isAdvertising) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already stopped, advId: %d, bt-advId: %d", advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
int32_t ret = BleStopAdv(g_advChannel[advId].advId);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
g_advChannel[advId].isAdvertising = false;
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
if (ret != OHOS_BT_STATUS_SUCCESS) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t SetAdvData(int32_t advId, const SoftbusBroadcastData *data)
|
||||
{
|
||||
if (data == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "data is null, advId: %d", advId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckAdvChannelInUsed(advId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used, advId: %d", advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!g_advChannel[advId].isAdvertising) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not advertising, advId: %d, bt-advId: %d",
|
||||
advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
StartAdvRawData advRawData = {};
|
||||
advRawData.advData = (unsigned char *)AssembleAdvData(data, (uint16_t *)&advRawData.advDataLen);
|
||||
if (advRawData.advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advId: %d, bt-advId: %d",
|
||||
advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
advRawData.rspDataLen = 0;
|
||||
advRawData.rspData = NULL;
|
||||
if (data->rspData.payloadLen > 0 && data->rspData.payload != NULL) {
|
||||
advRawData.rspData = (unsigned char *)AssembleRspData(&data->rspData, (uint16_t *)&advRawData.rspDataLen);
|
||||
if (advRawData.rspData == NULL) {
|
||||
SoftBusFree(advRawData.advData);
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advId: %d, bt-advId: %d",
|
||||
advId, g_advChannel[advId].advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
int32_t ret = BtStatusToSoftBus(BleSetAdvData(g_advChannel[advId].advId, advRawData));
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
SoftBusFree(advRawData.advData);
|
||||
SoftBusFree(advRawData.rspData);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t UpdateAdvData(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
|
||||
{
|
||||
if (StopAdv(advId) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "update adv data failed, advId: %d", advId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "update adv data, advId: %d", advId);
|
||||
return StartAdv(advId, param, data);
|
||||
}
|
||||
|
||||
static bool CheckScanChannelInUsed(int32_t scannerId)
|
||||
{
|
||||
if (scannerId < 0 || scannerId >= GATT_SCAN_MAX_NUM) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "invalid scannerId: %d", scannerId);
|
||||
return false;
|
||||
}
|
||||
if (!g_scanChannel[scannerId].isUsed) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d", scannerId, g_scanChannel[scannerId].scannerId);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t StartScan(int32_t scannerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
|
||||
int32_t filterSize)
|
||||
{
|
||||
if (param == NULL || scanFilter == NULL || filterSize <= 0) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "invalid param, scannerId: %d", scannerId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckScanChannelInUsed(scannerId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used, scannerId: %d", scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (g_scanChannel[scannerId].isScanning) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "already scanning, scannerId: %d, bt-scannerId: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BleScanNativeFilter *nativeFilter =
|
||||
(BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * filterSize);
|
||||
if (nativeFilter == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "malloc native filter failed, scannerId: %d, bt-scannerId: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
SoftbusFilterToBt(nativeFilter, scanFilter, filterSize);
|
||||
DumpBleScanFilter(nativeFilter, filterSize);
|
||||
BleScanConfigs scanConfig = {};
|
||||
scanConfig.scanMode = GetBtScanMode(param->scanInterval, param->scanWindow);
|
||||
scanConfig.phy = (int)param->scanPhy;
|
||||
int32_t ret = BleStartScanEx(g_scanChannel[scannerId].scannerId, &scanConfig, nativeFilter, (uint32_t)filterSize);
|
||||
g_scanChannel[scannerId].isScanning = (ret == OHOS_BT_STATUS_SUCCESS);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, ret: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId, ret);
|
||||
FreeBtFilter(nativeFilter, filterSize);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
if (ret != OHOS_BT_STATUS_SUCCESS) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t StopScan(int32_t scannerId)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckScanChannelInUsed(scannerId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used: %d", scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!g_scanChannel[scannerId].isScanning) {
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "already stopped, scannerId: %d, bt-scannerId: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
int32_t ret = BleStopScan(g_scanChannel[scannerId].scannerId);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "stop scan, scannerId: %d, bt-scannerId: %d, ret: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId, ret);
|
||||
g_scanChannel[scannerId].isScanning = false;
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
if (ret != OHOS_BT_STATUS_SUCCESS) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool IsLpAvailable(void)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "is lp available");
|
||||
return IsLpDeviceAvailable();
|
||||
}
|
||||
|
||||
static bool SetLpParam(const SoftBusLpBroadcastParam *bcParam, const SoftBusLpScanParam *scanParam)
|
||||
{
|
||||
BleScanConfigs scanConfig = {};
|
||||
scanConfig.scanMode = GetBtScanMode(scanParam->scanParam.scanInterval, scanParam->scanParam.scanWindow);
|
||||
BtLpDeviceParam lpParam = {};
|
||||
lpParam.scanConfig = &scanConfig;
|
||||
lpParam.rawData.advData = (unsigned char *)AssembleAdvData(&bcParam->advData,
|
||||
(uint16_t *)&lpParam.rawData.advDataLen);
|
||||
if (lpParam.rawData.advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble adv data failed, advHandle: %d", bcParam->advHandle);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (bcParam->advData.rspData.payloadLen > 0 && bcParam->advData.rspData.payload != NULL) {
|
||||
lpParam.rawData.rspData = (unsigned char *)AssembleRspData(&bcParam->advData.rspData,
|
||||
(uint16_t *)&lpParam.rawData.rspDataLen);
|
||||
if (lpParam.rawData.rspData == NULL) {
|
||||
SoftBusFree(lpParam.rawData.advData);
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "assemble rsp data failed, advHandle: %d", bcParam->advHandle);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
lpParam.filter = (BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * scanParam->filterSize);
|
||||
if (lpParam.filter == NULL) {
|
||||
SoftBusFree(lpParam.rawData.advData);
|
||||
SoftBusFree(lpParam.rawData.rspData);
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "malloc native filter failed, advHandle: %d", bcParam->advHandle);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
SoftbusFilterToBt(lpParam.filter, scanParam->filter, scanParam->filterSize);
|
||||
lpParam.filterSize = (unsigned int)scanParam->filterSize;
|
||||
SoftbusAdvParamToBt(&bcParam->advParam, &lpParam.advParam);
|
||||
BtUuid btUuid = {};
|
||||
btUuid.uuid = LP_BT_UUID;
|
||||
btUuid.uuidLen = (unsigned char)strlen(LP_BT_UUID);
|
||||
lpParam.uuid = btUuid;
|
||||
lpParam.activeDeviceInfo = NULL;
|
||||
lpParam.activeDeviceSize = 0;
|
||||
lpParam.deliveryMode = LP_DELIVERY_MODE_REPLY;
|
||||
lpParam.advHandle = bcParam->advHandle;
|
||||
lpParam.duration = LP_ADV_DURATION_MS;
|
||||
int32_t ret = SetLpDeviceParam(&lpParam);
|
||||
FreeBtFilter(lpParam.filter, scanParam->filterSize);
|
||||
SoftBusFree(lpParam.rawData.advData);
|
||||
SoftBusFree(lpParam.rawData.rspData);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advHandle: %d, ret: %d", bcParam->advHandle, ret);
|
||||
return (ret == OHOS_BT_STATUS_SUCCESS) ? true : false;
|
||||
}
|
||||
|
||||
static int32_t GetBroadcastHandle(int32_t advId, int32_t *bcHandle)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock adv failed, advId: %d", advId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckAdvChannelInUsed(advId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "adv is not in used: %d", advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int32_t ret = GetAdvHandle(g_advChannel[advId].advId, bcHandle);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t EnableSyncDataToLp(void)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "enable sync data to lp");
|
||||
return EnableSyncDataToLpDevice();
|
||||
}
|
||||
|
||||
static int32_t DisableSyncDataToLp(void)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "disable sync data to lp");
|
||||
return DisableSyncDataToLpDevice();
|
||||
}
|
||||
|
||||
static int32_t SetScanReportChannelToLp(int32_t scannerId, bool enable)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_scannerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "lock failed, scannerId: %d", scannerId);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (!CheckScanChannelInUsed(scannerId)) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "scanner is not in used: %d", scannerId);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int32_t ret = SetScanReportChannelToLpDevice(g_scanChannel[scannerId].scannerId, enable);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "scannerId: %d, bt-scannerId: %d, ret: %d",
|
||||
scannerId, g_scanChannel[scannerId].scannerId, ret);
|
||||
SoftBusMutexUnlock(&g_scannerLock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t SetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window,
|
||||
int32_t interval, int32_t bcHandle)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "advHandle: %d", bcHandle);
|
||||
return SetLpDeviceAdvParam(duration, maxExtAdvEvents, window, interval, bcHandle);
|
||||
}
|
||||
|
||||
void SoftbusBleAdapterInit(void)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "SoftbusBleAdapterInit");
|
||||
static SoftbusBroadcastMediumInterface interface = {
|
||||
.Init = Init,
|
||||
.DeInit = DeInit,
|
||||
.RegisterBroadcaster = RegisterAdvCallback,
|
||||
.UnRegisterBroadcaster = UnRegisterAdvCallback,
|
||||
.RegisterScanListener = RegisterScanCallback,
|
||||
.UnRegisterScanListener = UnRegisterScanCallback,
|
||||
.StartBroadcasting = StartAdv,
|
||||
.StopBroadcasting = StopAdv,
|
||||
.SetBroadcastingData = SetAdvData,
|
||||
.UpdateBroadcasting = UpdateAdvData,
|
||||
.StartScan = StartScan,
|
||||
.StopScan = StopScan,
|
||||
.IsLpDeviceAvailable = IsLpAvailable,
|
||||
.SetAdvFilterParam = SetLpParam,
|
||||
.GetBroadcastHandle = GetBroadcastHandle,
|
||||
.EnableSyncDataToLpDevice = EnableSyncDataToLp,
|
||||
.DisableSyncDataToLpDevice = DisableSyncDataToLp,
|
||||
.SetScanReportChannelToLpDevice = SetScanReportChannelToLp,
|
||||
.SetLpDeviceParam = SetLpAdvParam,
|
||||
};
|
||||
if (RegisterBroadcastMediumFunction(BROADCAST_MEDIUM_TYPE_BLE, &interface) != 0) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "Register gatt interface failed.");
|
||||
}
|
||||
}
|
@ -0,0 +1,474 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_ble_utils.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_broadcast_type.h"
|
||||
#include "softbus_error_code.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "softbus_broadcast_utils.h"
|
||||
#include "disc_log.h"
|
||||
#include <securec.h>
|
||||
|
||||
#define UUID_LEN 2
|
||||
#define UUID_MASK_LEN 2
|
||||
#define ID_LEN 2
|
||||
|
||||
int32_t BtStatusToSoftBus(BtStatus btStatus)
|
||||
{
|
||||
switch (btStatus) {
|
||||
case OHOS_BT_STATUS_SUCCESS:
|
||||
return SOFTBUS_BC_STATUS_SUCCESS;
|
||||
case OHOS_BT_STATUS_FAIL:
|
||||
return SOFTBUS_BC_STATUS_FAIL;
|
||||
case OHOS_BT_STATUS_NOT_READY:
|
||||
return SOFTBUS_BC_STATUS_NOT_READY;
|
||||
case OHOS_BT_STATUS_NOMEM:
|
||||
return SOFTBUS_BC_STATUS_NOMEM;
|
||||
case OHOS_BT_STATUS_BUSY:
|
||||
return SOFTBUS_BC_STATUS_BUSY;
|
||||
case OHOS_BT_STATUS_DONE:
|
||||
return SOFTBUS_BC_STATUS_DONE;
|
||||
case OHOS_BT_STATUS_UNSUPPORTED:
|
||||
return SOFTBUS_BC_STATUS_UNSUPPORTED;
|
||||
case OHOS_BT_STATUS_PARM_INVALID:
|
||||
return SOFTBUS_BC_STATUS_PARM_INVALID;
|
||||
case OHOS_BT_STATUS_UNHANDLED:
|
||||
return SOFTBUS_BC_STATUS_UNHANDLED;
|
||||
case OHOS_BT_STATUS_AUTH_FAILURE:
|
||||
return SOFTBUS_BC_STATUS_AUTH_FAILURE;
|
||||
case OHOS_BT_STATUS_RMT_DEV_DOWN:
|
||||
return SOFTBUS_BC_STATUS_RMT_DEV_DOWN;
|
||||
case OHOS_BT_STATUS_AUTH_REJECTED:
|
||||
return SOFTBUS_BC_STATUS_AUTH_REJECTED;
|
||||
default:
|
||||
return SOFTBUS_BC_STATUS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t SoftbusAdvDataTypeToBt(uint16_t advType)
|
||||
{
|
||||
switch (advType) {
|
||||
case BC_DATA_TYPE_SERVICE:
|
||||
return SERVICE_BC_TYPE;
|
||||
case BC_DATA_TYPE_MANUFACTURER:
|
||||
return MANUFACTURE_BC_TYPE;
|
||||
default:
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t BtAdvTypeToSoftbus(uint16_t advType)
|
||||
{
|
||||
switch (advType) {
|
||||
case SERVICE_BC_TYPE:
|
||||
return BC_DATA_TYPE_SERVICE;
|
||||
case MANUFACTURE_BC_TYPE:
|
||||
return BC_DATA_TYPE_MANUFACTURER;
|
||||
default:
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
static BleAdvFilter SoftbusAdvFilterToBt(uint8_t advFilter)
|
||||
{
|
||||
switch (advFilter) {
|
||||
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY:
|
||||
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
|
||||
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY:
|
||||
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY;
|
||||
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST:
|
||||
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST;
|
||||
case SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST:
|
||||
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST;
|
||||
default:
|
||||
return OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
|
||||
}
|
||||
}
|
||||
|
||||
static BleAdvType SoftbusAdvTypeToBt(uint8_t advType)
|
||||
{
|
||||
switch (advType) {
|
||||
case SOFTBUS_BC_ADV_IND:
|
||||
return OHOS_BLE_ADV_IND;
|
||||
case SOFTBUS_BC_ADV_DIRECT_IND_HIGH:
|
||||
return OHOS_BLE_ADV_DIRECT_IND_HIGH;
|
||||
case SOFTBUS_BC_ADV_SCAN_IND:
|
||||
return OHOS_BLE_ADV_SCAN_IND;
|
||||
case SOFTBUS_BC_ADV_NONCONN_IND:
|
||||
return OHOS_BLE_ADV_NONCONN_IND;
|
||||
case SOFTBUS_BC_ADV_DIRECT_IND_LOW:
|
||||
return OHOS_BLE_ADV_DIRECT_IND_LOW;
|
||||
default:
|
||||
return OHOS_BLE_ADV_IND;
|
||||
}
|
||||
}
|
||||
|
||||
void SoftbusAdvParamToBt(const SoftbusBroadcastParam *src, BleAdvParams *dst)
|
||||
{
|
||||
if (memcpy_s(dst->peerAddr.addr, SOFTBUS_ADDR_MAC_LEN, src->peerAddr.addr, SOFTBUS_ADDR_MAC_LEN) != EOK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "copy peer addr failed");
|
||||
}
|
||||
dst->minInterval = src->minInterval;
|
||||
dst->maxInterval = src->maxInterval;
|
||||
dst->advType = SoftbusAdvTypeToBt(src->advType);
|
||||
dst->ownAddrType = (unsigned char)src->ownAddrType;
|
||||
dst->peerAddrType = (unsigned char)src->peerAddrType;
|
||||
dst->channelMap = src->channelMap;
|
||||
dst->advFilterPolicy = SoftbusAdvFilterToBt(src->advFilterPolicy);
|
||||
dst->txPower = src->txPower;
|
||||
dst->duration = src->duration;
|
||||
}
|
||||
|
||||
static uint8_t BtScanEventTypeToSoftbus(unsigned char eventType)
|
||||
{
|
||||
switch (eventType) {
|
||||
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE:
|
||||
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED:
|
||||
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_CONNECTABLE:
|
||||
return SOFTBUS_BC_EVT_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_CONNECTABLE_DIRECTED:
|
||||
return SOFTBUS_BC_EVT_CONNECTABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_SCANNABLE:
|
||||
return SOFTBUS_BC_EVT_SCANNABLE;
|
||||
case OHOS_BLE_EVT_SCANNABLE_DIRECTED:
|
||||
return SOFTBUS_BC_EVT_SCANNABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE:
|
||||
return SOFTBUS_BC_EVT_LEGACY_NON_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_SCANNABLE:
|
||||
return SOFTBUS_BC_EVT_LEGACY_SCANNABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_CONNECTABLE:
|
||||
return SOFTBUS_BC_EVT_LEGACY_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED:
|
||||
return SOFTBUS_BC_EVT_LEGACY_CONNECTABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN:
|
||||
return SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN;
|
||||
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV:
|
||||
return SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV;
|
||||
default:
|
||||
return SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t BtScanDataStatusToSoftbus(unsigned char dataStatus)
|
||||
{
|
||||
switch (dataStatus) {
|
||||
case OHOS_BLE_DATA_COMPLETE:
|
||||
return SOFTBUS_BC_DATA_COMPLETE;
|
||||
case OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME:
|
||||
return SOFTBUS_BC_DATA_INCOMPLETE_MORE_TO_COME;
|
||||
case OHOS_BLE_DATA_INCOMPLETE_TRUNCATED:
|
||||
return SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED;
|
||||
default:
|
||||
return SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t BtScanAddrTypeToSoftbus(unsigned char addrType)
|
||||
{
|
||||
switch (addrType) {
|
||||
case OHOS_BLE_PUBLIC_DEVICE_ADDRESS:
|
||||
return SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS;
|
||||
case OHOS_BLE_RANDOM_DEVICE_ADDRESS:
|
||||
return SOFTBUS_BC_RANDOM_DEVICE_ADDRESS;
|
||||
case OHOS_BLE_PUBLIC_IDENTITY_ADDRESS:
|
||||
return SOFTBUS_BC_PUBLIC_IDENTITY_ADDRESS;
|
||||
case OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS:
|
||||
return SOFTBUS_BC_RANDOM_STATIC_IDENTITY_ADDRESS;
|
||||
case OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS:
|
||||
return SOFTBUS_BC_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
|
||||
case OHOS_BLE_NO_ADDRESS:
|
||||
return SOFTBUS_BC_NO_ADDRESS;
|
||||
default:
|
||||
return SOFTBUS_BC_NO_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t BtScanPhyTypeToSoftbus(unsigned char phyType)
|
||||
{
|
||||
switch (phyType) {
|
||||
case OHOS_BLE_SCAN_PHY_NO_PACKET:
|
||||
return SOFTBUS_BC_SCAN_PHY_NO_PACKET;
|
||||
case OHOS_BLE_SCAN_PHY_1M:
|
||||
return SOFTBUS_BC_SCAN_PHY_1M;
|
||||
case OHOS_BLE_SCAN_PHY_2M:
|
||||
return SOFTBUS_BC_SCAN_PHY_2M;
|
||||
case OHOS_BLE_SCAN_PHY_CODED:
|
||||
return SOFTBUS_BC_SCAN_PHY_CODED;
|
||||
default:
|
||||
return SOFTBUS_BC_SCAN_PHY_NO_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
void BtScanResultToSoftbus(const BtScanResultData *src, SoftBusBcScanResult *dst)
|
||||
{
|
||||
dst->eventType = BtScanEventTypeToSoftbus(src->eventType);
|
||||
dst->dataStatus = BtScanDataStatusToSoftbus(src->dataStatus);
|
||||
dst->addrType = BtScanAddrTypeToSoftbus(src->addrType);
|
||||
if (memcpy_s(dst->addr.addr, SOFTBUS_ADDR_MAC_LEN, src->addr.addr, SOFTBUS_ADDR_MAC_LEN) != EOK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "copy addr failed");
|
||||
}
|
||||
dst->primaryPhy = BtScanPhyTypeToSoftbus(src->primaryPhy);
|
||||
dst->secondaryPhy = BtScanPhyTypeToSoftbus(src->secondaryPhy);
|
||||
dst->advSid = (uint8_t)src->advSid;
|
||||
dst->txPower = (int8_t)src->txPower;
|
||||
dst->rssi = (int8_t)src->rssi;
|
||||
}
|
||||
|
||||
void SoftbusFilterToBt(BleScanNativeFilter *nativeFilter, const SoftBusBcScanFilter *filter, uint8_t filterSize)
|
||||
{
|
||||
while (filterSize-- > 0) {
|
||||
(nativeFilter + filterSize)->address = (char *)(filter + filterSize)->address;
|
||||
(nativeFilter + filterSize)->deviceName = (char *)(filter + filterSize)->deviceName;
|
||||
(nativeFilter + filterSize)->manufactureData = (unsigned char *)(filter + filterSize)->manufactureData;
|
||||
(nativeFilter + filterSize)->manufactureDataLength =
|
||||
(unsigned int)(filter + filterSize)->manufactureDataLength;
|
||||
(nativeFilter + filterSize)->manufactureDataMask = (unsigned char *)(filter + filterSize)->manufactureDataMask;
|
||||
(nativeFilter + filterSize)->manufactureId = (unsigned short)(filter + filterSize)->manufactureId;
|
||||
|
||||
if ((filter + filterSize)->serviceData == NULL || (filter + filterSize)->serviceDataMask == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// serviceData = uuid + serviceData, serviceDataMask = 0xFFFF + serviceDataMask
|
||||
uint16_t serviceUuid = (filter + filterSize)->serviceUuid;
|
||||
uint16_t serviceDataLen = (filter + filterSize)->serviceDataLength + 2;
|
||||
uint8_t *serviceData = (uint8_t *)SoftBusCalloc(serviceDataLen);
|
||||
if (serviceData == NULL) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "malloc service data failed");
|
||||
continue;
|
||||
}
|
||||
serviceData[0] = serviceUuid & BC_BYTE_MASK;
|
||||
serviceData[1] = (serviceUuid >> BC_SHIFT_BIT) & BC_BYTE_MASK;
|
||||
if (memcpy_s(serviceData + UUID_LEN, serviceDataLen - UUID_LEN, (filter + filterSize)->serviceData,
|
||||
serviceDataLen - UUID_LEN) != EOK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "copy service data failed");
|
||||
}
|
||||
uint8_t *serviceDataMask = (uint8_t *)SoftBusCalloc(serviceDataLen);
|
||||
if (serviceDataMask == NULL) {
|
||||
SoftBusFree(serviceData);
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "malloc service data mask failed");
|
||||
continue;
|
||||
}
|
||||
serviceDataMask[0] = BC_BYTE_MASK;
|
||||
serviceDataMask[1] = BC_BYTE_MASK;
|
||||
if (memcpy_s(serviceDataMask + UUID_MASK_LEN, serviceDataLen - UUID_MASK_LEN,
|
||||
(filter + filterSize)->serviceDataMask, serviceDataLen - UUID_MASK_LEN) != EOK) {
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "copy service data mask failed");
|
||||
}
|
||||
(nativeFilter + filterSize)->serviceData = (unsigned char *)serviceData;
|
||||
(nativeFilter + filterSize)->serviceDataLength = (unsigned int)serviceDataLen;
|
||||
(nativeFilter + filterSize)->serviceDataMask = (unsigned char *)serviceDataMask;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeBtFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize)
|
||||
{
|
||||
while (filterSize-- > 0) {
|
||||
SoftBusFree((nativeFilter + filterSize)->serviceData);
|
||||
SoftBusFree((nativeFilter + filterSize)->serviceDataMask);
|
||||
}
|
||||
SoftBusFree(nativeFilter);
|
||||
}
|
||||
|
||||
void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, int32_t filterSize)
|
||||
{
|
||||
while (filterSize-- > 0) {
|
||||
uint32_t len = (nativeFilter + filterSize)->serviceDataLength;
|
||||
if (len == 0) {
|
||||
continue;
|
||||
}
|
||||
uint32_t hexLen = HEXIFY_LEN(len);
|
||||
char *serviceData = (char *)SoftBusCalloc(sizeof(char) * hexLen);
|
||||
if (serviceData == NULL) {
|
||||
continue;
|
||||
}
|
||||
char *serviceDataMask = (char *)SoftBusCalloc(sizeof(char) * hexLen);
|
||||
if (serviceDataMask == NULL) {
|
||||
SoftBusFree(serviceData);
|
||||
continue;
|
||||
}
|
||||
(void)ConvertBytesToHexString(serviceData, hexLen, (nativeFilter + filterSize)->serviceData, len);
|
||||
(void)ConvertBytesToHexString(serviceDataMask, hexLen, (nativeFilter + filterSize)->serviceDataMask, len);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "BLE Scan Filter size:%d [serviceData:%s, serviceDataMask:%s]",
|
||||
filterSize, serviceData, serviceDataMask);
|
||||
SoftBusFree(serviceData);
|
||||
SoftBusFree(serviceDataMask);
|
||||
}
|
||||
}
|
||||
|
||||
int GetBtScanMode(uint16_t scanInterval, uint16_t scanWindow)
|
||||
{
|
||||
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P2 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P2) {
|
||||
return OHOS_BLE_SCAN_MODE_OP_P2_60_3000;
|
||||
}
|
||||
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P10 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P10) {
|
||||
return OHOS_BLE_SCAN_MODE_OP_P10_60_600;
|
||||
}
|
||||
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P25 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P25) {
|
||||
return OHOS_BLE_SCAN_MODE_OP_P25_60_240;
|
||||
}
|
||||
if (scanInterval == SOFTBUS_BC_SCAN_INTERVAL_P100 && scanWindow == SOFTBUS_BC_SCAN_WINDOW_P100) {
|
||||
return OHOS_BLE_SCAN_MODE_OP_P100_1000_1000;
|
||||
}
|
||||
return OHOS_BLE_SCAN_MODE_LOW_POWER;
|
||||
}
|
||||
|
||||
uint8_t *AssembleAdvData(const SoftbusBroadcastData *data, uint16_t *dataLen)
|
||||
{
|
||||
uint16_t payloadLen = (data->bcData.payloadLen > BC_DATA_MAX_LEN) ? BC_DATA_MAX_LEN : data->bcData.payloadLen;
|
||||
uint16_t len = data->isSupportFlag ? payloadLen + BC_HEAD_LEN : payloadLen + BC_HEAD_LEN - BC_FLAG_LEN;
|
||||
uint8_t *advData = (uint8_t *)SoftBusCalloc(len);
|
||||
if (advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "malloc adv data failed");
|
||||
return NULL;
|
||||
}
|
||||
int8_t offset = -BC_FLAG_LEN;
|
||||
if (data->isSupportFlag) {
|
||||
advData[IDX_BC_FLAG_BYTE_LEN] = BC_FLAG_BYTE_LEN;
|
||||
advData[IDX_BC_FLAG_AD_TYPE] = BC_FLAG_AD_TYPE;
|
||||
advData[IDX_BC_FLAG_AD_DATA] = data->flag;
|
||||
offset += BC_FLAG_LEN;
|
||||
}
|
||||
advData[IDX_PACKET_LEN + offset] = payloadLen + BC_HEAD_LEN - BC_FLAG_LEN - 1;
|
||||
advData[IDX_BC_TYPE + offset] = SoftbusAdvDataTypeToBt(data->bcData.type);
|
||||
uint16_t payloadId = data->bcData.id;
|
||||
advData[IDX_BC_UUID + offset] = (uint8_t)(payloadId & BC_BYTE_MASK);
|
||||
advData[IDX_BC_UUID + offset + 1] = (uint8_t)((payloadId >> BC_SHIFT_BIT) & BC_BYTE_MASK);
|
||||
|
||||
if (memcpy_s(&advData[BC_HEAD_LEN + offset], payloadLen, data->bcData.payload, payloadLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "copy adv payload failed");
|
||||
SoftBusFree(advData);
|
||||
return NULL;
|
||||
}
|
||||
*dataLen = len;
|
||||
return advData;
|
||||
}
|
||||
|
||||
uint8_t *AssembleRspData(const SoftbusBroadcastPayload *data, uint16_t *dataLen)
|
||||
{
|
||||
uint16_t payloadLen = (data->payloadLen > RSP_DATA_MAX_LEN) ? RSP_DATA_MAX_LEN : data->payloadLen;
|
||||
uint16_t len = payloadLen + RSP_HEAD_LEN;
|
||||
uint8_t *rspData = (uint8_t *)SoftBusCalloc(len);
|
||||
if (rspData == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "malloc rsp data failed");
|
||||
return NULL;
|
||||
}
|
||||
rspData[IDX_RSP_PACKET_LEN] = payloadLen + RSP_HEAD_LEN - 1;
|
||||
rspData[IDX_RSP_TYPE] = SoftbusAdvDataTypeToBt(data->type);
|
||||
uint16_t payloadId = data->id;
|
||||
rspData[IDX_RSP_UUID] = (uint8_t)(payloadId & BC_BYTE_MASK);
|
||||
rspData[IDX_RSP_UUID + 1] = (uint8_t)((payloadId >> BC_SHIFT_BIT) & BC_BYTE_MASK);
|
||||
|
||||
if (memcpy_s(&rspData[RSP_HEAD_LEN], payloadLen, data->payload, payloadLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "copy rsp payload failed");
|
||||
SoftBusFree(rspData);
|
||||
return NULL;
|
||||
}
|
||||
*dataLen = len;
|
||||
return rspData;
|
||||
}
|
||||
|
||||
static int32_t ParseFlag(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst, uint8_t index)
|
||||
{
|
||||
if (index + 1 >= advLen) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "parse flag failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
dst->data.flag = advData[index + 1];
|
||||
dst->data.isSupportFlag = true;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ParseLocalName(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst, uint8_t index,
|
||||
uint8_t len)
|
||||
{
|
||||
if (index + 1 >= advLen) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "parse local name failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(dst->localName, sizeof(dst->localName), &advData[index + 1], len - 1) != EOK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "copy local name failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ParseScanResult(const uint8_t *advData, uint8_t advLen, SoftBusBcScanResult *dst)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
bool isRsp = false;
|
||||
while (index < advLen) {
|
||||
uint8_t len = advData[index];
|
||||
if (len == 0) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
if (index + len >= advLen || index + 1 >= advLen) {
|
||||
break;
|
||||
}
|
||||
uint8_t type = advData[++index];
|
||||
if (type == BC_FLAG_AD_TYPE && ParseFlag(advData, advLen, dst, index) != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
} else if (type == SHORTENED_LOCAL_NAME_BC_TYPE || type == LOCAL_NAME_BC_TYPE) {
|
||||
if (ParseLocalName(advData, advLen, dst, index, len) != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
} else {
|
||||
if (type != SERVICE_BC_TYPE && type != MANUFACTURE_BC_TYPE) {
|
||||
index += len;
|
||||
DISC_LOGW(DISC_BLE_ADAPTER, "unsupported adv type: %u", type);
|
||||
continue;
|
||||
}
|
||||
SoftbusBroadcastPayload *data = isRsp ? &dst->data.rspData : &dst->data.bcData;
|
||||
data->payloadLen = len - ID_LEN - 1;
|
||||
if (data->payloadLen <= 0 || index + ID_LEN + 1 >= advLen) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "parse payload failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
data->payload = (uint8_t *)SoftBusCalloc(data->payloadLen);
|
||||
if (data->payload == NULL) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "malloc payload failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
isRsp = !isRsp;
|
||||
data->type = BtAdvTypeToSoftbus(type);
|
||||
data->id = ((uint16_t)advData[index + ID_LEN] << BC_SHIFT_BIT) | (uint16_t)advData[index + ID_LEN - 1];
|
||||
if (memcpy_s(data->payload, data->payloadLen, &advData[index + ID_LEN + 1], data->payloadLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE_ADAPTER, "copy payload failed");
|
||||
}
|
||||
}
|
||||
index += len;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void DumpSoftbusAdapterData(const char *description, uint8_t *data, uint16_t len)
|
||||
{
|
||||
DISC_CHECK_AND_RETURN_LOGE(description != NULL, DISC_BLE_ADAPTER, "data is null!");
|
||||
DISC_CHECK_AND_RETURN_LOGE(len != 0, DISC_BLE_ADAPTER, "len is 0!");
|
||||
DISC_CHECK_AND_RETURN_LOGE(data != NULL, DISC_BLE_ADAPTER, "data is null!");
|
||||
|
||||
int32_t hexLen = HEXIFY_LEN(len);
|
||||
char *softbusData = (char *)SoftBusCalloc(sizeof(char) * hexLen);
|
||||
DISC_CHECK_AND_RETURN_LOGE(softbusData != NULL, DISC_BLE_ADAPTER, "malloc failed!");
|
||||
|
||||
(void)ConvertBytesToHexString(softbusData, hexLen, data, len);
|
||||
DISC_LOGI(DISC_BLE_ADAPTER, "%s softbusData:%s", description, softbusData);
|
||||
|
||||
SoftBusFree(softbusData);
|
||||
}
|
@ -77,7 +77,7 @@ typedef struct {
|
||||
int32_t (*SetBroadcastingData)(int32_t advId, const SoftbusBroadcastData *data);
|
||||
int32_t (*UpdateBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data);
|
||||
int32_t (*StartScan)(int32_t scannerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
|
||||
uint8_t filterSize);
|
||||
int32_t filterSize);
|
||||
int32_t (*StopScan)(int32_t scannerId);
|
||||
bool (*IsLpDeviceAvailable)(void);
|
||||
bool (*SetAdvFilterParam)(const SoftBusLpBroadcastParam *bcParam, const SoftBusLpScanParam *scanParam);
|
||||
|
@ -246,7 +246,7 @@ int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_
|
||||
* @since 4.1
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t GetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t *filterNum);
|
||||
int32_t GetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *filterNum);
|
||||
|
||||
/**
|
||||
* @brief Check whether available resources are available by using the bcid
|
||||
|
@ -87,6 +87,7 @@ typedef enum {
|
||||
SRV_TYPE_SHARE, // The service type is share discovery.
|
||||
SRV_TYPE_APPROACH, // The service type is approach discovery.
|
||||
SRV_TYPE_SH, // The service type is sensorhub.
|
||||
SRV_TYPE_FAST_OFFLINE, // The service type is fast offline.
|
||||
SRV_TYPE_BUTT,
|
||||
} BaseServiceType;
|
||||
|
||||
@ -396,8 +397,7 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
BcScanParams scanParam;
|
||||
BcScanFilter *filter;
|
||||
uint8_t filterSize;
|
||||
int32_t listenerId;
|
||||
} LpScanParam;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -33,8 +33,8 @@ extern "C"{
|
||||
#define MEDIUM_NUM_MAX 2
|
||||
|
||||
// max broadcasting and scan limit
|
||||
#define BC_NUM_MAX 9
|
||||
#define SCAN_NUM_MAX 9
|
||||
#define BC_NUM_MAX 16
|
||||
#define SCAN_NUM_MAX 16
|
||||
|
||||
#define BC_DATA_MAX_LEN 24
|
||||
#define RSP_DATA_MAX_LEN 27
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,9 @@ adapter_ble_inc = [
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/common",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/interface",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/include",
|
||||
]
|
||||
adapter_ble_src = [
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c",
|
||||
@ -25,7 +28,20 @@ adapter_ble_src = [
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/adapter_bt_utils.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/softbus_adapter_bt_common.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/src/softbus_ble_utils.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/manager/src/softbus_broadcast_mgr.c",
|
||||
]
|
||||
|
||||
if (dsoftbus_feature_ex_kits) {
|
||||
import(
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/adapter/common/net/bluetooth/broadcast/adapter/ble/adapter_ble_enhance.gni")
|
||||
|
||||
adapter_ble_inc += adapter_ble_enhance_inc
|
||||
adapter_ble_src += adapter_ble_enhance_src
|
||||
} else {
|
||||
adapter_ble_src += [ "$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/src/softbus_ble_gatt.c" ]
|
||||
}
|
||||
|
||||
adapter_net_br_src = [ "$dsoftbus_root_path/adapter/common/net/bluetooth/common/softbus_adapter_bt_common.c" ]
|
||||
adapter_ble_external_deps = [ "bluetooth:btframework" ]
|
||||
if (defined(ohos_lite)) {
|
||||
|
@ -172,6 +172,12 @@ if (defined(ohos_lite)) {
|
||||
"//third_party/openssl:libcrypto_shared",
|
||||
]
|
||||
innerapi_tags = [ "platformsdk_indirect" ]
|
||||
|
||||
install_images = [
|
||||
system_base_dir,
|
||||
updater_base_dir,
|
||||
]
|
||||
|
||||
part_name = "dsoftbus"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ static void ParseBusinessType(const cJSON *data, DeviceInfo *dev)
|
||||
item = cJSON_GetObjectItemCaseSensitive(data, JSON_BUSINESS_TYPE);
|
||||
if (item == NULL) {
|
||||
dev->businessType = NSTACKX_BUSINESS_TYPE_NULL;
|
||||
DFINDER_LOGW(TAG, "Cannot get businessType json");
|
||||
DFINDER_LOGD(TAG, "Cannot get businessType json");
|
||||
return;
|
||||
}
|
||||
if (!cJSON_IsNumber(item) || (item->valuedouble < 0)) {
|
||||
@ -377,7 +377,7 @@ static void ParseBusinessDataJsonData(const cJSON *data, DeviceInfo *dev, uint8_
|
||||
cJSON *item = NULL;
|
||||
item = cJSON_GetObjectItemCaseSensitive(data, JSON_BUSINESS_DATA);
|
||||
if (item == NULL) {
|
||||
DFINDER_LOGE(TAG, "Cannot get businessData json");
|
||||
DFINDER_LOGD(TAG, "Cannot get businessData json");
|
||||
return;
|
||||
}
|
||||
if (!cJSON_IsString(item)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -15,15 +15,12 @@
|
||||
|
||||
#include "wrapper_br_interface.h"
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gap.h"
|
||||
#include "c_header/ohos_bt_spp.h"
|
||||
#include "c_header/ohos_bt_socket.h"
|
||||
#include "securec.h"
|
||||
#include "conn_log.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "string.h"
|
||||
|
||||
@ -106,6 +103,7 @@ static int32_t Accept(int32_t serverFd)
|
||||
CONN_LOGI(CONN_BR, "[Accept remote device to connect, and serverFd = %d]", serverFd);
|
||||
int32_t ret = SppServerAccept(serverFd);
|
||||
if (ret == BT_SPP_INVALID_ID) {
|
||||
CONN_LOGE(CONN_BR, "Accept spp server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return ret;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <securec.h>
|
||||
@ -27,7 +26,6 @@
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_feature_config.h"
|
||||
#include "softbus_utils.h"
|
||||
@ -109,7 +107,7 @@ int32_t GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len)
|
||||
switch (key) {
|
||||
case COMM_DEVICE_KEY_DEVNAME:
|
||||
LNN_LOGI(LNN_STATE, "set default devicename in netledger init");
|
||||
if (strncpy_s(value, len, DEFAULT_DEVICE_NAME, strlen(DEFAULT_DEVICE_NAME)) != EOK) {
|
||||
if (strcpy_s(value, len, DEFAULT_DEVICE_NAME) != EOK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
break;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <securec.h>
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "softbus_adapter_crypto.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_utils.h"
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "securec.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#define ACCOUNT_STRTOLL_BASE 10
|
||||
static const int32_t ACCOUNT_STRTOLL_BASE = 10;
|
||||
#define DEFAULT_ACCOUNT_NAME "ohosAnonymousName"
|
||||
|
||||
int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len)
|
||||
|
@ -19,12 +19,15 @@
|
||||
|
||||
int32_t GetOsAccountId(char *id, uint32_t idLen, uint32_t *len)
|
||||
{
|
||||
(void)id;
|
||||
(void)idLen;
|
||||
(void)len;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int64_t GetCurrentAccount(void)
|
||||
{
|
||||
return 0;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t GetActiveOsAccountIds(void)
|
||||
|
@ -38,10 +38,10 @@ namespace OHOS {
|
||||
namespace BusCenter {
|
||||
static const std::string SETTINGS_DATA_BASE_URI =
|
||||
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
|
||||
static const std::string SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
|
||||
static const std::string SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD";
|
||||
static const std::string SETTINGS_DATA_FIELD_VALUE = "VALUE";
|
||||
static const std::string PREDICATES_STRING = "settings.general.device_name";
|
||||
static constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
|
||||
static constexpr const char *SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD";
|
||||
static constexpr const char *SETTINGS_DATA_FIELD_VALUE = "VALUE";
|
||||
static constexpr const char *PREDICATES_STRING = "settings.general.device_name";
|
||||
std::shared_ptr<DataShare::DataShareHelper> g_dataShareHelper;
|
||||
static const uint32_t SOFTBUS_SA_ID = 4700;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "lnn_ohos_account.h"
|
||||
#include "lnn_settingdata_event_monitor.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
import("../../dsoftbus.gni")
|
||||
import("../common/dfx/dsoftbus_dfx.gni")
|
||||
device_profile_common_path =
|
||||
"//foundation/deviceprofile/device_info_manager/common"
|
||||
device_profile_interfaces_path =
|
||||
"//foundation/deviceprofile/device_info_manager/interfaces"
|
||||
AUTH_SERVER_DEFINES = []
|
||||
if (dsoftbus_feature_auth_account == true) {
|
||||
AUTH_SERVER_DEFINES += [ "AUTH_ACCOUNT" ]
|
||||
@ -106,10 +110,10 @@ if (defined(ohos_lite)) {
|
||||
} else {
|
||||
auth_server_inc += [
|
||||
"//base/security/device_auth/interfaces/inner_api",
|
||||
"//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core/include",
|
||||
"//foundation/deviceprofile/device_info_manager/common/include/interfaces/",
|
||||
"//foundation/deviceprofile/device_info_manager/common/include/constants",
|
||||
"//foundation/deviceprofile/device_info_manager/common/include/utils",
|
||||
"${device_profile_interfaces_path}/innerkits/core/include",
|
||||
"${device_profile_common_path}/include/interfaces/",
|
||||
"${device_profile_common_path}/include/constants",
|
||||
"${device_profile_common_path}include/utils",
|
||||
]
|
||||
auth_server_src +=
|
||||
[ "$authentication_path/src/auth_hichain_system_ability_monitor.cpp" ]
|
||||
|
@ -23,7 +23,7 @@ static const uint32_t SOFTBUS_SA_ID = 4700;
|
||||
static DeviceProfileChangeListener g_deviceProfileChange = { 0 };
|
||||
|
||||
namespace OHOS {
|
||||
namespace AuthtoDp {
|
||||
namespace AuthToDeviceProfile {
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
|
||||
AuthDeviceProfileListener::AuthDeviceProfileListener()
|
||||
@ -147,7 +147,7 @@ static void RegisterToDpHelper(void)
|
||||
int32_t subscribeRes = DistributedDeviceProfileClient::GetInstance().SubscribeDeviceProfile(subscribeInfo);
|
||||
AUTH_LOGI(AUTH_INIT, "GetCharacteristicProfile subscribeRes %d", subscribeRes);
|
||||
}
|
||||
} // namespace AuthtoDp
|
||||
} // namespace AuthToDeviceProfile
|
||||
} // namespace OHOS
|
||||
|
||||
void RegisterToDp(DeviceProfileChangeListener *deviceProfilePara)
|
||||
@ -157,5 +157,5 @@ void RegisterToDp(DeviceProfileChangeListener *deviceProfilePara)
|
||||
return;
|
||||
}
|
||||
g_deviceProfileChange = *deviceProfilePara;
|
||||
OHOS::AuthtoDp::RegisterToDpHelper();
|
||||
OHOS::AuthToDeviceProfile::RegisterToDpHelper();
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
#include "service_profile.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AuthtoDp {
|
||||
namespace AuthToDeviceProfile {
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
|
||||
class AuthDeviceProfileListener : public ProfileChangeListenerStub {
|
||||
@ -45,6 +45,6 @@ public:
|
||||
int32_t OnCharacteristicProfileUpdate(
|
||||
const CharacteristicProfile &oldProfile, const CharacteristicProfile &newProfile);
|
||||
};
|
||||
} // namespace AuthtoDp
|
||||
} // namespace AuthToDeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -23,7 +23,7 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool IsPotentialTrustedDeviceDp(const char *deviceId);
|
||||
bool IsPotentialTrustedDeviceDp(const char *deviceIdHash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -91,7 +91,6 @@ int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, co
|
||||
int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len);
|
||||
int32_t AuthSessionHandleDeviceNotTrusted(const char *udid);
|
||||
int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId);
|
||||
AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq);
|
||||
AuthFsm *GetAuthFsmByConnId(uint64_t connId, bool isServer);
|
||||
void AuthSessionFsmExit(void);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -131,9 +131,11 @@ static int32_t CustomFunc(const SoftBusMessage *msg, void *param)
|
||||
CHECK_NULL_PTR_RETURN_VALUE(param, SOFTBUS_ERR);
|
||||
EventRemoveInfo *info = (EventRemoveInfo *)param;
|
||||
if (msg->what != (int32_t)info->event) {
|
||||
AUTH_LOGE(AUTH_CONN, "msg->what and event inequality");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (info->cmpFunc == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "cmpFunc is null");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return info->cmpFunc(msg->obj, info->param);
|
||||
@ -185,13 +187,16 @@ bool GetConfigSupportAsServer(void)
|
||||
uint8_t *DupMemBuffer(const uint8_t *buf, uint32_t size)
|
||||
{
|
||||
if (buf == NULL || size == 0) {
|
||||
AUTH_LOGE(AUTH_CONN, "param err");
|
||||
return NULL;
|
||||
}
|
||||
uint8_t *dup = (uint8_t *)SoftBusMalloc(size);
|
||||
if (dup == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "malloc err");
|
||||
return NULL;
|
||||
}
|
||||
if (memcpy_s(dup, size, buf, size) != EOK) {
|
||||
AUTH_LOGE(AUTH_CONN, "memcpy err");
|
||||
SoftBusFree(dup);
|
||||
return NULL;
|
||||
}
|
||||
@ -406,5 +411,6 @@ int32_t GetPeerUdidByNetworkId(const char *networkId, char *udid)
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
AUTH_LOGE(AUTH_CONN, "info or deviceUdid is null");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
@ -23,12 +23,11 @@
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "lnn_event.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_socket.h"
|
||||
#include "softbus_base_listener.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
|
||||
#define AUTH_CONN_DATA_HEAD_SIZE 24
|
||||
#define AUTH_CONN_CONNECT_TIMEOUT_MS 10000
|
||||
@ -101,9 +100,10 @@ int32_t GetFd(uint64_t connId)
|
||||
{
|
||||
return (int32_t)(connId & MASK_UINT64_L32);
|
||||
}
|
||||
|
||||
|
||||
void UpdateFd(uint64_t *connId, int32_t id)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(connId);
|
||||
*connId &= MASK_UINT64_H32;
|
||||
*connId |= (((uint64_t)id) & MASK_UINT64_L32);
|
||||
}
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include "lnn_secure_storage.h"
|
||||
#include "softbus_adapter_crypto.h"
|
||||
#include "softbus_adapter_thread.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "softbus_log_old.h"
|
||||
#include "softbus_utils.h"
|
||||
|
||||
@ -402,6 +402,10 @@ void AuthRemoveDeviceKey(const char *udidHash, int32_t keyType)
|
||||
|
||||
void AuthRemoveDeviceKeyByUdid(const char *udidOrHash)
|
||||
{
|
||||
if (udidOrHash == NULL) {
|
||||
AUTH_LOGE(AUTH_KEY, "param err");
|
||||
return;
|
||||
}
|
||||
char *anonyUdid = NULL;
|
||||
Anonymize(udidOrHash, &anonyUdid);
|
||||
AUTH_LOGE(AUTH_KEY, "remove device key, udid=%s", anonyUdid);
|
||||
@ -418,7 +422,7 @@ void AuthRemoveDeviceKeyByUdid(const char *udidOrHash)
|
||||
}
|
||||
while (LnnMapHasNext(it)) {
|
||||
it = LnnMapNext(it);
|
||||
if (it ==NULL || it->node->value == NULL) {
|
||||
if (it == NULL || it->node == NULL) {
|
||||
break;
|
||||
}
|
||||
AuthDeviceCommonKey *deviceKey = (AuthDeviceCommonKey *)it->node->value;
|
||||
@ -464,6 +468,7 @@ int32_t AuthFindDeviceKey(const char *udidHash, int32_t keyType, AuthDeviceKeyIn
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (KeyLock() != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_KEY, "keyLock fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
AuthDeviceCommonKey *data = (AuthDeviceCommonKey *)LnnMapGet(&g_deviceKeyMap, (const char *)keyStr);
|
||||
@ -500,7 +505,7 @@ static bool AuthParseDeviceKey(const char *deviceKey)
|
||||
}
|
||||
int32_t arraySize = cJSON_GetArraySize(json);
|
||||
if (arraySize <= 0) {
|
||||
AUTH_LOGE(AUTH_KEY, "no valid deviceKey");
|
||||
AUTH_LOGE(AUTH_KEY, "invalid deviceKey log");
|
||||
cJSON_Delete(json);
|
||||
return false;
|
||||
}
|
||||
@ -521,7 +526,7 @@ static bool AuthParseDeviceKey(const char *deviceKey)
|
||||
void AuthUpdateKeyIndex(const char *udidHash, int32_t keyType, int64_t index, bool isServer)
|
||||
{
|
||||
if (udidHash == NULL) {
|
||||
AUTH_LOGW(AUTH_KEY, "update fail");
|
||||
AUTH_LOGE(AUTH_KEY, "udidiHash log update fail");
|
||||
return;
|
||||
}
|
||||
char keyStr[MAP_KEY_LEN] = {0};
|
||||
@ -534,6 +539,10 @@ void AuthUpdateKeyIndex(const char *udidHash, int32_t keyType, int64_t index, bo
|
||||
return;
|
||||
}
|
||||
AuthDeviceCommonKey *data = (AuthDeviceCommonKey *)LnnMapGet(&g_deviceKeyMap, (const char *)keyStr);
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_KEY, "data is nullptr");
|
||||
return;
|
||||
}
|
||||
data->keyInfo.keyIndex = index;
|
||||
data->keyInfo.isServerSide = isServer;
|
||||
KeyUnlock();
|
||||
@ -566,7 +575,7 @@ void AuthLoadDeviceKey(void)
|
||||
AUTH_LOGD(AUTH_KEY, "load deviceKey finish");
|
||||
}
|
||||
|
||||
void AUthClearDeviceKey(void)
|
||||
void AuthClearDeviceKey(void)
|
||||
{
|
||||
/*need aging mechanism*/
|
||||
LnnMapDelete(&g_deviceKeyMap);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -22,9 +22,8 @@
|
||||
#include "auth_hichain_adapter.h"
|
||||
#include "auth_log.h"
|
||||
#include "auth_session_fsm.h"
|
||||
#include "device_auth.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "device_auth_defines.h"
|
||||
#include "device_auth.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_json_utils.h"
|
||||
@ -32,6 +31,7 @@
|
||||
#define AUTH_APPID "softbus_auth"
|
||||
#define GROUPID_BUF_LEN 65
|
||||
#define KEY_LENGTH 16 /* Note: WinPc's special nearby only support 128 bits key */
|
||||
#define ONTRANSMIT_MAX_DATA_BUFFER_LEN 5120 /* 5 × 1024 */
|
||||
|
||||
typedef struct {
|
||||
char groupId[GROUPID_BUF_LEN];
|
||||
@ -75,6 +75,8 @@ static char *GenDeviceLevelParam(const char *udid, const char *uid, bool isClien
|
||||
|
||||
static bool OnTransmit(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(len <= ONTRANSMIT_MAX_DATA_BUFFER_LEN, false, AUTH_HICHAIN,
|
||||
"data len is invalid, len=%u", len);
|
||||
AUTH_LOGI(AUTH_HICHAIN, "hichain OnTransmit: authSeq=%" PRId64 ", len=%u", authSeq, len);
|
||||
if (AuthSessionPostAuthData(authSeq, data, len) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_HICHAIN, "hichain OnTransmit fail: authSeq=%" PRId64, authSeq);
|
||||
@ -181,6 +183,7 @@ static void OnGroupCreated(const char *groupInfo)
|
||||
return;
|
||||
}
|
||||
GroupInfo info;
|
||||
(void)memset_s(&info, sizeof(GroupInfo), 0, sizeof(GroupInfo));
|
||||
if (ParseGroupInfo(groupInfo, &info) != SOFTBUS_OK) {
|
||||
return;
|
||||
}
|
||||
@ -209,6 +212,7 @@ static void OnGroupDeleted(const char *groupInfo)
|
||||
return;
|
||||
}
|
||||
GroupInfo info;
|
||||
(void)memset_s(&info, sizeof(GroupInfo), 0, sizeof(GroupInfo));
|
||||
if (ParseGroupInfo(groupInfo, &info) != SOFTBUS_OK) {
|
||||
return;
|
||||
}
|
||||
@ -256,7 +260,7 @@ int32_t RegTrustDataChangeListener(const TrustDataChangeListener *listener)
|
||||
void UnregTrustDataChangeListener(void)
|
||||
{
|
||||
int32_t ret = UnregChangeListener(AUTH_APPID);
|
||||
if (ret != 0) {
|
||||
if (ret != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_HICHAIN, "hichain unRegDataChangeListener err=%d", ret);
|
||||
}
|
||||
(void)memset_s(&g_dataChangeListener, sizeof(TrustDataChangeListener), 0, sizeof(TrustDataChangeListener));
|
||||
@ -286,6 +290,7 @@ int32_t HichainStartAuth(int64_t authSeq, const char *udid, const char *uid)
|
||||
int32_t HichainProcessData(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_HICHAIN, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = ProcessAuthData(authSeq, data, len, &g_hichainCallback);
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
#include "auth_hichain_adapter.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "auth_common.h"
|
||||
#include "auth_hichain.h"
|
||||
@ -81,6 +79,8 @@ int32_t RegChangeListener(const char *appId, DataChangeListener *listener)
|
||||
|
||||
int32_t UnregChangeListener(const char *appId)
|
||||
{
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(appId != NULL, SOFTBUS_INVALID_PARAM, AUTH_HICHAIN,
|
||||
"appId is null");
|
||||
const DeviceGroupManager *gmInstance = GetGmInstance();
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(gmInstance != NULL, SOFTBUS_ERR, AUTH_HICHAIN,
|
||||
"hichain GetGmInstance failed");
|
||||
@ -286,6 +286,7 @@ uint32_t HichainGetJoinedGroups(int32_t groupType)
|
||||
|
||||
void CancelRequest(int64_t authReqId, const char *appId)
|
||||
{
|
||||
AUTH_CHECK_AND_RETURN_LOGE(appId != NULL, AUTH_HICHAIN, "appId is null");
|
||||
if (g_hichain == NULL) {
|
||||
g_hichain = InitHichain();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -124,6 +124,10 @@ static void NotifyTransDisconnected(int64_t authId)
|
||||
int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback,
|
||||
bool isMeta)
|
||||
{
|
||||
if (info == NULL || callback == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "info or callback is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (isMeta) {
|
||||
return AuthMetaOpenConn(info, requestId, callback);
|
||||
}
|
||||
@ -188,7 +192,7 @@ int32_t AuthRestoreAuthManager(const char *udidHash,
|
||||
const AuthConnInfo *connInfo, int32_t requestId, NodeInfo *nodeInfo, int64_t *authId)
|
||||
{
|
||||
if (udidHash == NULL || connInfo == NULL || nodeInfo == NULL || authId == NULL) {
|
||||
AUTH_LOGW(AUTH_CONN, "restore manager fail because para error");
|
||||
AUTH_LOGE(AUTH_CONN, "restore manager fail because para error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
// get device key
|
||||
@ -367,7 +371,7 @@ TrustedReturnType AuthHasTrustedRelation(void)
|
||||
return TRUSTED_RELATION_IGNORE;
|
||||
}
|
||||
SoftBusFree(udidArray);
|
||||
AUTH_LOGD(AUTH_CONN, "auth get trusted relation num=%d", num);
|
||||
AUTH_LOGD(AUTH_CONN, "auth get trusted relation num=%u", num);
|
||||
return (num != 0) ? TRUSTED_RELATION_YES : TRUSTED_RELATION_NO;
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,14 @@
|
||||
#include "auth_session_message.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "lnn_heartbeat_ctrl.h"
|
||||
#include "lnn_app_bind_interface.h"
|
||||
#include "lnn_decision_db.h"
|
||||
#include "lnn_feature_capability.h"
|
||||
#include "lnn_heartbeat_ctrl.h"
|
||||
#include "lnn_net_builder.h"
|
||||
#include "softbus_adapter_hitrace.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "lnn_feature_capability.h"
|
||||
#include "lnn_net_builder.h"
|
||||
|
||||
#define MAX_AUTH_VALID_PERIOD (30 * 60 * 1000L) /* 30 mins */
|
||||
#define SCHEDULE_UPDATE_SESSION_KEY_PERIOD ((5 * 60 + 30) * 60 * 1000L) /* 5 hour 30 mins */
|
||||
@ -56,7 +56,7 @@ static bool g_regDataChangeListener = false;
|
||||
/* Auth Manager */
|
||||
AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
AuthManager *auth = (AuthManager *)SoftBusMalloc(sizeof(AuthManager));
|
||||
AuthManager *auth = (AuthManager *)SoftBusCalloc(sizeof(AuthManager));
|
||||
if (auth == NULL) {
|
||||
AUTH_LOGW(AUTH_FSM, "malloc AuthManager fail");
|
||||
return NULL;
|
||||
@ -79,8 +79,7 @@ AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
|
||||
} else {
|
||||
ListTailInsert(&g_authClientList, &auth->node);
|
||||
}
|
||||
AUTH_LOGI(AUTH_FSM, "create auth manager, side=%s, authId=%" PRId64,
|
||||
GetAuthSideStr(auth->isServer), auth->authId);
|
||||
AUTH_LOGI(AUTH_FSM, "create auth manager, side=%s, authId=%" PRId64, GetAuthSideStr(auth->isServer), auth->authId);
|
||||
return auth;
|
||||
}
|
||||
|
||||
@ -103,7 +102,7 @@ static AuthManager *DupAuthManager(const AuthManager *auth)
|
||||
|
||||
void DelAuthManager(AuthManager *auth, bool removeAuthFromList)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(auth);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(auth != NULL, AUTH_FSM, "auth is null");
|
||||
if (removeAuthFromList) {
|
||||
char *anonyUdid = NULL;
|
||||
Anonymize(auth->udid, &anonyUdid);
|
||||
@ -203,6 +202,8 @@ static AuthManager *FindAuthManagerByAuthId(int64_t authId)
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_LOGE(AUTH_FSM, "auth manager[%" PRId64 "] not found", authId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -272,14 +273,16 @@ static int32_t UpdateAuthManagerByAuthId(
|
||||
|
||||
static ConnectionAddrType ConvertAuthLinkTypeToConnect(AuthLinkType type)
|
||||
{
|
||||
if (type == AUTH_LINK_TYPE_WIFI) {
|
||||
return CONNECTION_ADDR_WLAN;
|
||||
} else if (type == AUTH_LINK_TYPE_BLE) {
|
||||
return CONNECTION_ADDR_BLE;
|
||||
} else if (type == AUTH_LINK_TYPE_BR) {
|
||||
return CONNECTION_ADDR_BR;
|
||||
switch (type) {
|
||||
case AUTH_LINK_TYPE_WIFI:
|
||||
return CONNECTION_ADDR_WLAN;
|
||||
case AUTH_LINK_TYPE_BLE:
|
||||
return CONNECTION_ADDR_BLE;
|
||||
case AUTH_LINK_TYPE_BR:
|
||||
return CONNECTION_ADDR_BR;
|
||||
default:
|
||||
return CONNECTION_ADDR_MAX;
|
||||
}
|
||||
return CONNECTION_ADDR_MAX;
|
||||
}
|
||||
|
||||
void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index)
|
||||
@ -289,8 +292,8 @@ void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index)
|
||||
}
|
||||
AuthManager *auth = FindAuthManagerByAuthId(authId);
|
||||
if (auth == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "auth manager already removed, authId=%" PRId64, authId);
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGI(AUTH_CONN, "auth manager already removed, authId=%" PRId64, authId);
|
||||
return;
|
||||
}
|
||||
RemoveSessionkeyByIndex(&auth->sessionKeyList, index);
|
||||
@ -472,8 +475,7 @@ static int64_t GetAuthIdByConnInfo(const AuthConnInfo *connInfo, bool isServer)
|
||||
}
|
||||
AuthManager *auth = FindAuthManagerByConnInfo(connInfo, isServer);
|
||||
if (auth == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "auth manager not found, connType=%d, side=%s", connInfo->type,
|
||||
GetAuthSideStr(isServer));
|
||||
AUTH_LOGE(AUTH_CONN, "auth manager not found, connType=%d, side=%s", connInfo->type, GetAuthSideStr(isServer));
|
||||
ReleaseAuthLock();
|
||||
return AUTH_INVALID_ID;
|
||||
}
|
||||
@ -501,7 +503,8 @@ static int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo)
|
||||
/* Get lastest authId */
|
||||
int64_t authId = AUTH_INVALID_ID;
|
||||
uint64_t maxVerifyTime = 0;
|
||||
for (uint32_t i = 0; i < sizeof(auth) / sizeof(auth[0]); i++) {
|
||||
uint32_t authMgrNum = sizeof(auth) / sizeof(auth[0]);
|
||||
for (uint32_t i = 0; i < authMgrNum; i++) {
|
||||
if (auth[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
@ -518,10 +521,10 @@ static int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo)
|
||||
int32_t AuthManagerSetSessionKey(int64_t authSeq, const AuthSessionInfo *info,
|
||||
const SessionKey *sessionKey, bool isConnect)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(sessionKey, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_LOGI(AUTH_FSM, "SetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u",
|
||||
authSeq, GetAuthSideStr(info->isServer), info->requestId);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(sessionKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "sessionKey is NULL");
|
||||
AUTH_LOGI(AUTH_FSM, "SetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
|
||||
GetAuthSideStr(info->isServer), info->requestId);
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -575,13 +578,12 @@ int32_t AuthManagerSetSessionKey(int64_t authSeq, const AuthSessionInfo *info,
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
||||
int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(sessionKey, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_LOGI(AUTH_FSM, "GetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u",
|
||||
authSeq, GetAuthSideStr(info->isServer), info->requestId);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(sessionKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "sessionKey is NULL");
|
||||
AUTH_LOGI(AUTH_FSM, "GetSessionKey: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
|
||||
GetAuthSideStr(info->isServer), info->requestId);
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -605,6 +607,7 @@ static void NotifyDeviceVerifyPassed(int64_t authId, const NodeInfo *nodeInfo)
|
||||
{
|
||||
AuthManager *auth = GetAuthManagerByAuthId(authId);
|
||||
if (auth == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "get auth manager failed");
|
||||
return;
|
||||
}
|
||||
if (auth->connInfo.type == AUTH_LINK_TYPE_P2P) {
|
||||
@ -724,8 +727,7 @@ static int32_t StartVerifyDevice(uint32_t requestId, const AuthConnInfo *connInf
|
||||
return SOFTBUS_AUTH_INNER_ERR;
|
||||
}
|
||||
if (waitNum > 1) {
|
||||
AUTH_LOGI(AUTH_CONN, "wait last verify request complete, waitNum=%u, requestId=%u",
|
||||
waitNum, requestId);
|
||||
AUTH_LOGI(AUTH_CONN, "wait last verify request complete, waitNum=%u, requestId=%u", waitNum, requestId);
|
||||
SoftbusHitraceStop();
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
@ -829,6 +831,7 @@ static int32_t ComplementConnectionInfoIfNeed(AuthManager *auth, const char *udi
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (udid == NULL || strlen(udid) == 0) {
|
||||
AUTH_LOGE(AUTH_FSM, "invalid udid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = SoftBusGenerateStrHash((unsigned char *)udid, strlen(udid),
|
||||
@ -839,9 +842,9 @@ static int32_t ComplementConnectionInfoIfNeed(AuthManager *auth, const char *udi
|
||||
void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
int64_t authId;
|
||||
CHECK_NULL_PTR_RETURN_VOID(info);
|
||||
AUTH_LOGI(AUTH_FSM, "SetAuthPassed: authSeq=%" PRId64 ", side=%s, requestId=%u",
|
||||
authSeq, GetAuthSideStr(info->isServer), info->requestId);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "info is null");
|
||||
AUTH_LOGI(AUTH_FSM, "SetAuthPassed: authSeq=%" PRId64 ", side=%s, requestId=%u", authSeq,
|
||||
GetAuthSideStr(info->isServer), info->requestId);
|
||||
|
||||
if (!RequireAuthLock()) {
|
||||
return;
|
||||
@ -849,16 +852,16 @@ void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
|
||||
AuthManager *auth = FindAuthManagerByConnInfo(&info->connInfo, info->isServer);
|
||||
if (auth == NULL) {
|
||||
PrintAuthConnInfo(&info->connInfo);
|
||||
AUTH_LOGE(AUTH_FSM, "auth manager not found, connType=%d, side=%s",
|
||||
info->connInfo.type, GetAuthSideStr(info->isServer));
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGE(AUTH_FSM, "auth manager not found, connType=%d, side=%s", info->connInfo.type,
|
||||
GetAuthSideStr(info->isServer));
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ret = ComplementConnectionInfoIfNeed(auth, info->nodeInfo.deviceInfo.deviceUdid);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "complement auth connection info failed, authSeq=%" PRId64 ", error=%d", authSeq, ret);
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGE(AUTH_FSM, "complement auth connection info failed, authSeq=%" PRId64 ", error=%d", authSeq, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -881,8 +884,9 @@ void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
|
||||
|
||||
void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason)
|
||||
{
|
||||
AUTH_LOGE(AUTH_FSM, "SetAuthFailed: authSeq=%" PRId64 ", requestId=%u, reason=%d",
|
||||
authSeq, info->requestId, reason);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "auth session info is null");
|
||||
AUTH_LOGE(
|
||||
AUTH_FSM, "SetAuthFailed: authSeq=%" PRId64 ", requestId=%u, reason=%d", authSeq, info->requestId, reason);
|
||||
AuthManager *auth = GetAuthManagerByConnInfo(&info->connInfo, info->isServer);
|
||||
if (auth != NULL && auth->hasAuthPassed) {
|
||||
AUTH_LOGE(AUTH_FSM, "update session key fail, authId=%" PRId64, auth->authId);
|
||||
@ -903,7 +907,7 @@ void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int3
|
||||
|
||||
static void HandleBleDisconnectDelay(const void *para)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(para);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(para != NULL, AUTH_FSM, "para is null");
|
||||
uint64_t connId = *((uint64_t *)para);
|
||||
DisconnectAuthDevice(&connId);
|
||||
}
|
||||
@ -915,6 +919,7 @@ static void BleDisconnectDelay(uint64_t connId, uint64_t delayMs)
|
||||
|
||||
void AuthManagerSetAuthFinished(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "auth session info is null");
|
||||
AUTH_LOGI(AUTH_FSM, "SetAuthFinished: authSeq=%" PRId64 ", requestId=%u", authSeq, info->requestId);
|
||||
if (info->isServer) {
|
||||
AUTH_LOGI(AUTH_FSM, "SERVER: wait client close connection");
|
||||
@ -969,7 +974,7 @@ static void HandleBleConnectResult(uint32_t requestId, int64_t authId, uint64_t
|
||||
AUTH_LOGI(AUTH_CONN, "get request info failed, requestId=%u", requestId);
|
||||
return;
|
||||
}
|
||||
AuthManager inAuth = {.connId = connId };
|
||||
AuthManager inAuth = { .connId = connId };
|
||||
if (UpdateAuthManagerByAuthId(authId, SetAuthConnId, &inAuth) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "set auth connId fail, requestId=%u", requestId);
|
||||
return;
|
||||
@ -1076,8 +1081,8 @@ static void FlushDeviceProcess(const AuthConnInfo *connInfo, bool isServer)
|
||||
AuthManager *auth = FindAuthManagerByConnInfo(connInfo, isServer);
|
||||
if (auth == NULL) {
|
||||
PrintAuthConnInfo(connInfo);
|
||||
AUTH_LOGI(AUTH_FSM, "auth manager not found");
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGE(AUTH_FSM, "auth manager not found");
|
||||
return;
|
||||
}
|
||||
if (PostVerifyDeviceMessage(auth, FLAG_REPLY) == SOFTBUS_OK) {
|
||||
@ -1130,7 +1135,6 @@ static void HandleCloseAckData(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void HandleConnectionData(
|
||||
uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, const AuthDataHead *head, const uint8_t *data)
|
||||
{
|
||||
@ -1196,7 +1200,7 @@ static void OnDataReceived(
|
||||
|
||||
static void HandleDisconnectedEvent(const void *para)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(para);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(para != NULL, AUTH_FSM, "para is null");
|
||||
uint64_t connId = *((uint64_t *)para);
|
||||
uint32_t num = 0;
|
||||
uint64_t dupConnId = connId;
|
||||
@ -1267,13 +1271,13 @@ void AuthHandleLeaveLNN(int64_t authId)
|
||||
}
|
||||
AuthManager *auth = FindAuthManagerByAuthId(authId);
|
||||
if (auth == NULL) {
|
||||
AUTH_LOGI(AUTH_FSM, "auth manager not found, authId=%" PRId64, authId);
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGE(AUTH_FSM, "auth manager not found, authId=%" PRId64, authId);
|
||||
return;
|
||||
}
|
||||
if (!auth->hasAuthPassed) {
|
||||
AUTH_LOGI(AUTH_FSM, "auth pass = false, don't need to leave");
|
||||
ReleaseAuthLock();
|
||||
AUTH_LOGI(AUTH_FSM, "auth pass = false, don't need to leave");
|
||||
return;
|
||||
}
|
||||
if (auth->connInfo.type == AUTH_LINK_TYPE_WIFI) {
|
||||
@ -1324,7 +1328,7 @@ static int32_t TryGetBrConnInfo(const char *uuid, AuthConnInfo *connInfo)
|
||||
return SOFTBUS_AUTH_GET_BR_CONN_INFO_FAIL;
|
||||
}
|
||||
if (((local & (1 << BIT_BR)) == 0) || ((remote & (1 << BIT_BR)) == 0)) {
|
||||
AUTH_LOGI(AUTH_CONN, "can't support BR");
|
||||
AUTH_LOGW(AUTH_CONN, "can't support BR");
|
||||
return SOFTBUS_AUTH_GET_BR_CONN_INFO_FAIL;
|
||||
}
|
||||
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_BT_MAC, connInfo->info.brInfo.brMac, BT_MAC_LEN) != SOFTBUS_OK ||
|
||||
@ -1343,7 +1347,8 @@ int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo)
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
AuthLinkType linkList[] = { AUTH_LINK_TYPE_WIFI, AUTH_LINK_TYPE_BR, AUTH_LINK_TYPE_BLE };
|
||||
for (uint32_t i = 0; i < sizeof(linkList) / sizeof(linkList[0]); i++) {
|
||||
uint32_t linkTypeNum = sizeof(linkList) / sizeof(linkList[0]);
|
||||
for (uint32_t i = 0; i < linkTypeNum; i++) {
|
||||
if (GetAuthConnInfoByUuid(uuid, linkList[i], connInfo) != SOFTBUS_OK) {
|
||||
continue;
|
||||
}
|
||||
@ -1373,7 +1378,6 @@ bool AuthDeviceCheckConnInfo(const char *uuid, AuthLinkType type, bool checkConn
|
||||
return checkConnection ? CheckActiveAuthConnection(&connInfo) : true;
|
||||
}
|
||||
|
||||
|
||||
int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback)
|
||||
{
|
||||
if (info == NULL || !CheckAuthConnCallback(callback)) {
|
||||
@ -1443,6 +1447,7 @@ int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo)
|
||||
head.module = dataInfo->module;
|
||||
head.seq = dataInfo->seq;
|
||||
head.flag = dataInfo->flag;
|
||||
head.len = 0;
|
||||
uint8_t *encData = NULL;
|
||||
if (EncryptInner(&auth->sessionKeyList, dataInfo->data, dataInfo->len, &encData, &head.len) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_KEY, "encrypt trans data fail");
|
||||
@ -1463,6 +1468,7 @@ int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo)
|
||||
int32_t RegGroupChangeListener(const GroupChangeListener *listener)
|
||||
{
|
||||
if (listener == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "listener is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
g_groupChangeListener.onGroupCreated = listener->onGroupCreated;
|
||||
@ -1600,7 +1606,6 @@ uint32_t AuthGetDecryptSize(uint32_t inLen)
|
||||
return inLen - OVERHEAD_LEN;
|
||||
}
|
||||
|
||||
|
||||
int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen)
|
||||
{
|
||||
if (inData == NULL || inLen == 0 || outData == NULL || outLen == NULL || *outLen < AuthGetEncryptSize(inLen)) {
|
||||
@ -1620,7 +1625,6 @@ int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen,
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
||||
int32_t AuthDeviceDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen)
|
||||
{
|
||||
if (inData == NULL || inLen == 0 || outData == NULL || outLen == NULL || *outLen < AuthGetDecryptSize(inLen)) {
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include "auth_request.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "auth_common.h"
|
||||
#include "auth_log.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
@ -35,7 +33,7 @@ static AuthRequest *FindAuthRequestByRequestId(uint64_t requestId)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint32_t GetAuthRequestWaitNum(AuthRequest *request)
|
||||
static uint32_t GetAuthRequestWaitNum(const AuthRequest *request)
|
||||
{
|
||||
uint32_t num = 0;
|
||||
AuthRequest *item = NULL;
|
||||
@ -67,7 +65,7 @@ static uint32_t GetAuthRequestWaitNum(AuthRequest *request)
|
||||
|
||||
uint32_t AddAuthRequest(const AuthRequest *request)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(request, 0);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, 0, AUTH_CONN, "request is NULL");
|
||||
AuthRequest *newRequest = SoftBusCalloc(sizeof(AuthRequest));
|
||||
if (newRequest == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "malloc AuthRequest fail");
|
||||
@ -86,7 +84,7 @@ uint32_t AddAuthRequest(const AuthRequest *request)
|
||||
|
||||
int32_t GetAuthRequest(uint32_t requestId, AuthRequest *request)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -102,9 +100,10 @@ int32_t GetAuthRequest(uint32_t requestId, AuthRequest *request)
|
||||
|
||||
int32_t GetAuthRequestNoLock(uint32_t requestId, AuthRequest *request)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
|
||||
AuthRequest *item = FindAuthRequestByRequestId(requestId);
|
||||
if (item == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "find auth request failed");
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
*request = *item;
|
||||
@ -113,8 +112,8 @@ int32_t GetAuthRequestNoLock(uint32_t requestId, AuthRequest *request)
|
||||
|
||||
int32_t FindAuthRequestByConnInfo(const AuthConnInfo *connInfo, AuthRequest *request)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(request, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "connInfo is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(request != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "request is NULL");
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -134,7 +133,7 @@ int32_t FindAuthRequestByConnInfo(const AuthConnInfo *connInfo, AuthRequest *req
|
||||
|
||||
int32_t FindAndDelAuthRequestByConnInfo(uint32_t requestId, const AuthConnInfo *connInfo)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "connInfo is NULL");
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -195,9 +194,11 @@ void ClearAuthRequest(void)
|
||||
bool CheckVerifyCallback(const AuthVerifyCallback *verifyCb)
|
||||
{
|
||||
if (verifyCb == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "verifyCb is null");
|
||||
return false;
|
||||
}
|
||||
if (verifyCb->onVerifyPassed == NULL || verifyCb->onVerifyFailed == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "onVerifyPassed or onVerifyFailed is null");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -206,9 +207,11 @@ bool CheckVerifyCallback(const AuthVerifyCallback *verifyCb)
|
||||
bool CheckAuthConnCallback(const AuthConnCallback *connCb)
|
||||
{
|
||||
if (connCb == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "connCb is null");
|
||||
return false;
|
||||
}
|
||||
if (connCb->onConnOpened == NULL || connCb->onConnOpenFailed == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "onConnOpened or onConnOpenFailed is null");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -218,9 +221,11 @@ void PerformVerifyCallback(uint32_t requestId, int32_t result, int64_t authId, c
|
||||
{
|
||||
AuthRequest request;
|
||||
if (GetAuthRequest(requestId, &request) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "get auth request failed");
|
||||
return;
|
||||
}
|
||||
if (!CheckVerifyCallback(&request.verifyCb)) {
|
||||
AUTH_LOGE(AUTH_CONN, "check verifyCb failed");
|
||||
return;
|
||||
}
|
||||
if (result == SOFTBUS_OK) {
|
||||
@ -234,9 +239,11 @@ void PerformAuthConnCallback(uint32_t requestId, int32_t result, int64_t authId)
|
||||
{
|
||||
AuthRequest request;
|
||||
if (GetAuthRequest(requestId, &request) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "get auth request failed");
|
||||
return;
|
||||
}
|
||||
if (!CheckAuthConnCallback(&request.connCb)) {
|
||||
AUTH_LOGE(AUTH_CONN, "check connCb failed");
|
||||
return;
|
||||
}
|
||||
if (result == SOFTBUS_OK) {
|
||||
|
@ -545,7 +545,7 @@ static int32_t ClientSetExchangeIdType(AuthFsm *authFsm)
|
||||
{
|
||||
AuthSessionInfo *info = &authFsm->info;
|
||||
if (info->idType == EXCHANGE_FAIL) {
|
||||
AUTH_LOGI(AUTH_FSM, "fsm switch to reauth due to not find networkId");
|
||||
AUTH_LOGE(AUTH_FSM, "fsm switch to reauth due to not find networkId");
|
||||
info->idType = EXCHANHE_UDID;
|
||||
LnnFsmTransactState(&authFsm->fsm, g_states + STATE_SYNC_DEVICE_ID);
|
||||
return SOFTBUS_ERR;
|
||||
@ -553,7 +553,7 @@ static int32_t ClientSetExchangeIdType(AuthFsm *authFsm)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void HandleMsgRecvDeviceId(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgRecvDeviceId(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
int32_t ret;
|
||||
AuthSessionInfo *info = &authFsm->info;
|
||||
@ -633,7 +633,7 @@ static bool SyncDevIdStateProcess(FsmStateMachine *fsm, int32_t msgType, void *p
|
||||
return true;
|
||||
}
|
||||
|
||||
static void HandleMsgRecvAuthData(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgRecvAuthData(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
LnnEventExtra lnnEventExtra = {0};
|
||||
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
|
||||
@ -655,7 +655,7 @@ static void HandleMsgRecvAuthData(AuthFsm *authFsm, MessagePara *para)
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
|
||||
static int32_t TrySyncDeviceInfo(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
switch (info->connInfo.type) {
|
||||
case AUTH_LINK_TYPE_WIFI:
|
||||
@ -674,7 +674,7 @@ static int32_t TrySyncDeviceInfo(int64_t authSeq, AuthSessionInfo *info)
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgSaveSessionKey(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
|
||||
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_EXCHANGE_CIPHER, lnnEventExtra);
|
||||
@ -706,14 +706,14 @@ static void HandleMsgSaveSessionKey(AuthFsm *authFsm, MessagePara *para)
|
||||
LnnFsmTransactState(&authFsm->fsm, g_states + STATE_SYNC_DEVICE_INFO);
|
||||
}
|
||||
|
||||
static void HandleMsgAuthError(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgAuthError(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
int32_t result = *((int32_t *)(para->data));
|
||||
AUTH_LOGE(AUTH_FSM, "auth fsm[%" PRId64"] handle hichain error, reason=%d", authFsm->authSeq, result);
|
||||
CompleteAuthSession(authFsm, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
|
||||
}
|
||||
|
||||
static void HandleMsgRecvDevInfoEarly(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgRecvDevInfoEarly(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
AUTH_LOGI(AUTH_FSM, "auth fsm[%" PRId64 "] recv device info early, save it", authFsm->authSeq);
|
||||
AuthSessionInfo *info = &authFsm->info;
|
||||
@ -789,7 +789,7 @@ static bool DeviceAuthStateProcess(FsmStateMachine *fsm, int32_t msgType, void *
|
||||
return true;
|
||||
}
|
||||
|
||||
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, MessagePara *para)
|
||||
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, const MessagePara *para)
|
||||
{
|
||||
LnnEventExtra lnnEventExtra = { .result = EVENT_STAGE_RESULT_OK };
|
||||
AuthSessionInfo *info = &authFsm->info;
|
||||
@ -895,7 +895,7 @@ static bool SyncDevInfoStateProcess(FsmStateMachine *fsm, int32_t msgType, void
|
||||
return true;
|
||||
}
|
||||
|
||||
AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq)
|
||||
static AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq)
|
||||
{
|
||||
AuthFsm *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, &g_authFsmList, AuthFsm, node) {
|
||||
@ -1008,7 +1008,7 @@ static void SetAuthStartTime(AuthFsm *authFsm)
|
||||
int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId,
|
||||
uint64_t connId, const AuthConnInfo *connInfo, bool isServer, bool isFastAuth)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(connInfo, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(connInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "connInfo is NULL");
|
||||
if (!RequireAuthLock()) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -1033,6 +1033,7 @@ int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId,
|
||||
int32_t AuthSessionProcessDevIdData(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsm(FSM_MSG_RECV_DEVICE_ID, authSeq, data, len);
|
||||
@ -1053,6 +1054,7 @@ int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t l
|
||||
int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsm(FSM_MSG_RECV_AUTH_DATA, authSeq, data, len);
|
||||
@ -1061,6 +1063,7 @@ int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_
|
||||
int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size)
|
||||
{
|
||||
if (udid == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "udid is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
AuthSessionInfo info = {0};
|
||||
@ -1077,6 +1080,7 @@ int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size)
|
||||
int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len)
|
||||
{
|
||||
if (key == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "key is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsm(FSM_MSG_SAVE_SESSION_KEY, authSeq, key, len);
|
||||
@ -1095,6 +1099,7 @@ int32_t AuthSessionHandleAuthError(int64_t authSeq, int32_t reason)
|
||||
int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsm(FSM_MSG_RECV_DEVICE_INFO, authSeq, data, len);
|
||||
@ -1103,6 +1108,7 @@ int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint
|
||||
int32_t AuthSessionProcessCloseAck(int64_t authSeq, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsm(FSM_MSG_RECV_CLOSE_ACK, authSeq, data, len);
|
||||
@ -1112,6 +1118,7 @@ int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, co
|
||||
uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsmByConnId(FSM_MSG_RECV_DEVICE_INFO, connId, isServer, data, len);
|
||||
@ -1121,6 +1128,7 @@ int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const
|
||||
uint32_t len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return PostMessageToAuthFsmByConnId(FSM_MSG_RECV_CLOSE_ACK, connId, isServer, data, len);
|
||||
@ -1129,6 +1137,7 @@ int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const
|
||||
int32_t AuthSessionHandleDeviceNotTrusted(const char *udid)
|
||||
{
|
||||
if (udid == NULL || udid[0] == '\0') {
|
||||
AUTH_LOGE(AUTH_FSM, "invalid udid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (!RequireAuthLock()) {
|
||||
|
@ -55,19 +55,20 @@ static void RemoveOldKey(SessionKeyList *list)
|
||||
|
||||
void InitSessionKeyList(SessionKeyList *list)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(list);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
|
||||
ListInit(list);
|
||||
}
|
||||
|
||||
int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(srcList, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(dstList, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(srcList != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "srcList is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(dstList != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "dstList is NULL");
|
||||
SessionKeyItem *item = NULL;
|
||||
SessionKeyItem *newItem = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, srcList, SessionKeyItem, node) {
|
||||
newItem = (SessionKeyItem *)DupMemBuffer((uint8_t *)item, sizeof(SessionKeyItem));
|
||||
if (newItem == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "malloc newItem fail");
|
||||
DestroySessionKeyList(dstList);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
@ -78,7 +79,7 @@ int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList
|
||||
|
||||
void DestroySessionKeyList(SessionKeyList *list)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(list);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
|
||||
SessionKeyItem *item = NULL;
|
||||
SessionKeyItem *next = NULL;
|
||||
LIST_FOR_EACH_ENTRY_SAFE(item, next, list, SessionKeyItem, node) {
|
||||
@ -90,14 +91,14 @@ void DestroySessionKeyList(SessionKeyList *list)
|
||||
|
||||
bool HasSessionKey(const SessionKeyList *list)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(list, false);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, false, AUTH_FSM, "list is NULL");
|
||||
return !IsListEmpty(list);
|
||||
}
|
||||
|
||||
int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
|
||||
AUTH_LOGD(AUTH_FSM, "keyLen=%d", key->len);
|
||||
SessionKeyItem *item = (SessionKeyItem *)SoftBusMalloc(sizeof(SessionKeyItem));
|
||||
if (item == NULL) {
|
||||
@ -118,9 +119,9 @@ int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key
|
||||
|
||||
int32_t GetLatestSessionKey(const SessionKeyList *list, int32_t *index, SessionKey *key)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(index, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(index != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "index is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
|
||||
if (IsListEmpty((const ListNode *)list)) {
|
||||
AUTH_LOGE(AUTH_FSM, "session key list is empty");
|
||||
return SOFTBUS_ERR;
|
||||
@ -142,8 +143,8 @@ int32_t GetLatestSessionKey(const SessionKeyList *list, int32_t *index, SessionK
|
||||
|
||||
int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, SessionKey *key)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(list, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(key, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(list != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "list is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(key != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "key is NULL");
|
||||
SessionKeyItem *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
|
||||
if (item->index != index) {
|
||||
@ -163,7 +164,7 @@ int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, SessionK
|
||||
|
||||
void RemoveSessionkeyByIndex(SessionKeyList *list, int32_t index)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(list);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
|
||||
bool isFind = false;
|
||||
SessionKeyItem *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
|
||||
@ -192,7 +193,6 @@ int32_t EncryptData(const SessionKeyList *list, const uint8_t *inData, uint32_t
|
||||
SessionKey sessionKey;
|
||||
if (GetLatestSessionKey(list, &index, &sessionKey) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "get key fail");
|
||||
AUTH_LOGD(AUTH_FSM, "keyLen=%d", sessionKey.len);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
/* pack key index */
|
||||
@ -295,7 +295,7 @@ int32_t DecryptInner(const SessionKeyList *list, const uint8_t *inData, uint32_t
|
||||
/* For Debug */
|
||||
void DumpSessionkeyList(const SessionKeyList *list)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(list);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(list != NULL, AUTH_FSM, "list is NULL");
|
||||
uint32_t keyNum = 0;
|
||||
SessionKeyItem *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
|
||||
@ -308,7 +308,7 @@ void DumpSessionkeyList(const SessionKeyList *list)
|
||||
|
||||
static void HandleUpdateSessionKeyEvent(const void *obj)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VOID(obj);
|
||||
AUTH_CHECK_AND_RETURN_LOGE(obj != NULL, AUTH_FSM, "obj is NULL");
|
||||
int64_t authId = *(int64_t *)(obj);
|
||||
AUTH_LOGI(AUTH_FSM, "update session key begin, authId=%" PRId64, authId);
|
||||
AuthManager *auth = GetAuthManagerByAuthId(authId);
|
||||
@ -324,8 +324,8 @@ static void HandleUpdateSessionKeyEvent(const void *obj)
|
||||
|
||||
static int32_t RemoveUpdateSessionKeyFunc(const void *obj, void *para)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(obj, SOFTBUS_ERR);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(para, SOFTBUS_ERR);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(obj != NULL, SOFTBUS_ERR, AUTH_FSM, "obj is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(para != NULL, SOFTBUS_ERR, AUTH_FSM, "para is NULL");
|
||||
int64_t authId = *(int64_t *)(obj);
|
||||
if (authId == *(int64_t *)(para)) {
|
||||
AUTH_LOGI(AUTH_FSM, "remove update session key event, authId=%" PRId64, authId);
|
||||
|
@ -209,8 +209,7 @@ static void OptInt(const JsonObj *json, const char * const key, int *target, int
|
||||
*target = defaultValue;
|
||||
}
|
||||
|
||||
static void OptInt64(const JsonObj *json, const char * const key,
|
||||
int64_t *target, int64_t defaultValue)
|
||||
static void OptInt64(const JsonObj *json, const char * const key, int64_t *target, int64_t defaultValue)
|
||||
{
|
||||
if (JSON_GetInt64FromOject(json, key, target)) {
|
||||
return;
|
||||
@ -281,8 +280,7 @@ static bool GetUdidOrShortHash(const AuthSessionInfo *info, char *udidBuf, uint3
|
||||
AUTH_LOGE(AUTH_FSM, "GetAuthRequest fail");
|
||||
return false;
|
||||
}
|
||||
return (memcpy_s(udidBuf, bufLen, request.connInfo.info.bleInfo.deviceIdHash,
|
||||
UDID_SHORT_HASH_HEX_STR) == EOK);
|
||||
return (memcpy_s(udidBuf, bufLen, request.connInfo.info.bleInfo.deviceIdHash, UDID_SHORT_HASH_HEX_STR) == EOK);
|
||||
}
|
||||
AUTH_LOGD(AUTH_FSM, "udid len=%d, connInfo type=%d", strlen(info->udid), info->connInfo.type);
|
||||
return false;
|
||||
@ -324,14 +322,14 @@ static void PackFastAuth(JsonObj *obj, AuthSessionInfo *info, const NodeInfo *lo
|
||||
return;
|
||||
}
|
||||
if (PackFastAuthValue(obj, &deviceCommKey) != SOFTBUS_OK) {
|
||||
(void)memset_s(&deviceCommKey, sizeof(AuthDeviceKeyInfo), 0, sizeof(AuthDeviceKeyInfo));
|
||||
info->isSupportFastAuth = false;
|
||||
return;
|
||||
}
|
||||
(void)memset_s(&deviceCommKey, sizeof(AuthDeviceKeyInfo), 0, sizeof(AuthDeviceKeyInfo));
|
||||
}
|
||||
|
||||
static void ParseFastAuthValue(AuthSessionInfo *info, const char *encryptedFastAuth,
|
||||
AuthDeviceKeyInfo *deviceKey)
|
||||
static void ParseFastAuthValue(AuthSessionInfo *info, const char *encryptedFastAuth, AuthDeviceKeyInfo *deviceKey)
|
||||
{
|
||||
uint8_t fastAuthBytes[ENCRYPTED_FAST_AUTH_MAX_LEN] = {0};
|
||||
if (ConvertHexStringToBytes(fastAuthBytes, ENCRYPTED_FAST_AUTH_MAX_LEN,
|
||||
@ -415,6 +413,7 @@ static void PackCompressInfo(JsonObj *obj, const NodeInfo *info)
|
||||
static void PackWifiSinglePassInfo(JsonObj *obj, const AuthSessionInfo *info)
|
||||
{
|
||||
if (info->connInfo.type != AUTH_LINK_TYPE_WIFI) {
|
||||
AUTH_LOGE(AUTH_FSM, "link type is not wifi");
|
||||
return;
|
||||
}
|
||||
uint8_t hash[SHA_256_HASH_LEN] = {0};
|
||||
@ -487,8 +486,7 @@ static char *PackDeviceIdJson(const AuthSessionInfo *info)
|
||||
AUTH_LOGI(AUTH_FSM, "exchangeIdType=%d, udid=%s", info->idType, anonyUdid);
|
||||
AnonymizeFree(anonyUdid);
|
||||
}
|
||||
if (!JSON_AddStringToObject(obj, DATA_TAG, uuid) ||
|
||||
!JSON_AddInt32ToObject(obj, DATA_BUF_SIZE_TAG, PACKET_SIZE) ||
|
||||
if (!JSON_AddStringToObject(obj, DATA_TAG, uuid) || !JSON_AddInt32ToObject(obj, DATA_BUF_SIZE_TAG, PACKET_SIZE) ||
|
||||
!JSON_AddInt32ToObject(obj, SOFTBUS_VERSION_TAG, info->version) ||
|
||||
!JSON_AddInt32ToObject(obj, EXCHANGE_ID_TYPE, info->idType)) {
|
||||
AUTH_LOGE(AUTH_FSM, "add msg body fail");
|
||||
@ -519,7 +517,7 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
|
||||
SoftBusSockAddrIn addr = {0};
|
||||
SocketAddr socketAddr;
|
||||
int32_t rc = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&addr);
|
||||
if (rc != 0) {
|
||||
if (rc != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "fd=%d, GetPerrName rc=%d", socketFd, rc);
|
||||
return true;
|
||||
}
|
||||
@ -531,11 +529,11 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
|
||||
uint8_t hash[SHA_256_HASH_LEN] = {0};
|
||||
rc = SoftBusGenerateStrHash((const unsigned char *)socketAddr.addr, strlen(socketAddr.addr), hash);
|
||||
if (rc != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "generate hash failed rc=%d", rc);
|
||||
return true;
|
||||
}
|
||||
char socketIpHash[SHA_256_HEX_HASH_LEN] = {0};
|
||||
if (ConvertBytesToUpperCaseHexString(socketIpHash, SHA_256_HEX_HASH_LEN,
|
||||
hash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
|
||||
char socketIpHash[SHA_256_HEX_HASH_LEN] = { 0 };
|
||||
if (ConvertBytesToUpperCaseHexString(socketIpHash, SHA_256_HEX_HASH_LEN, hash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
|
||||
return true;
|
||||
}
|
||||
if (strcmp(devIpHash, socketIpHash) == 0) {
|
||||
@ -548,7 +546,7 @@ static bool UnpackWifiSinglePassInfo(JsonObj *obj, AuthSessionInfo *info)
|
||||
static int32_t UnPackBtDeviceIdV1(AuthSessionInfo *info, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (!info->isServer) {
|
||||
AUTH_LOGE(AUTH_FSM, "invalid bt deviceId msg");
|
||||
AUTH_LOGE(AUTH_FSM, "is not server");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (memcpy_s(info->udid, UDID_BUF_LEN, data, len) != EOK) { // data:StandardCharsets.UTF_8
|
||||
@ -696,9 +694,8 @@ static int32_t UnpackDeviceIdJson(const char *msg, uint32_t len, AuthSessionInfo
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (info->connInfo.type != AUTH_LINK_TYPE_WIFI) {
|
||||
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = {0};
|
||||
OptString(obj, SUPPORT_INFO_COMPRESS, compressParse,
|
||||
PARSE_UNCOMPRESS_STRING_BUFF_LEN, FALSE_STRING_TAG);
|
||||
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = { 0 };
|
||||
OptString(obj, SUPPORT_INFO_COMPRESS, compressParse, PARSE_UNCOMPRESS_STRING_BUFF_LEN, FALSE_STRING_TAG);
|
||||
SetCompressFlag(compressParse, &info->isSupportCompress);
|
||||
}
|
||||
UnpackFastAuth(obj, info);
|
||||
@ -1051,7 +1048,7 @@ static void UnpackCommon(const JsonObj *json, NodeInfo *info, SoftBusVersion ver
|
||||
OptInt64(json, ACCOUNT_ID, &info->accountId, 0);
|
||||
OptInt(json, NODE_WEIGHT, &info->masterWeight, DEFAULT_NODE_WEIGHT);
|
||||
|
||||
//IS_SUPPORT_TCP_HEARTBEAT
|
||||
// IS_SUPPORT_TCP_HEARTBEAT
|
||||
OptInt64(json, NEW_CONN_CAP, (int64_t *)&info->netCapacity, -1);
|
||||
if (info->netCapacity == (uint32_t)-1) {
|
||||
(void)JSON_GetInt64FromOject(json, CONN_CAP, (int64_t *)&info->netCapacity);
|
||||
@ -1105,7 +1102,7 @@ static void AddDiscoveryType(JsonObj *json, const char *remoteUuid)
|
||||
}
|
||||
char networkId[NETWORK_ID_BUF_LEN] = {0};
|
||||
if (LnnGetNetworkIdByUuid(remoteUuid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
|
||||
AUTH_LOGI(AUTH_FSM, "networkId not found by uuid, maybe first online");
|
||||
AUTH_LOGE(AUTH_FSM, "networkId not found by uuid, maybe first online");
|
||||
return;
|
||||
}
|
||||
uint32_t discoveryType = 0;
|
||||
@ -1182,8 +1179,7 @@ static int32_t UnpackBt(const JsonObj *json, NodeInfo *info, SoftBusVersion vers
|
||||
static int32_t PackWiFi(JsonObj *json, const NodeInfo *info, SoftBusVersion version, bool isMetaAuth)
|
||||
{
|
||||
AUTH_LOGD(AUTH_FSM, "devIp %d", strlen(info->connectInfo.deviceIp));
|
||||
if (!JSON_AddInt32ToObject(json, CODE, CODE_VERIFY_IP) ||
|
||||
!JSON_AddInt32ToObject(json, BUS_MAX_VERSION, BUS_V2) ||
|
||||
if (!JSON_AddInt32ToObject(json, CODE, CODE_VERIFY_IP) || !JSON_AddInt32ToObject(json, BUS_MAX_VERSION, BUS_V2) ||
|
||||
!JSON_AddInt32ToObject(json, BUS_MIN_VERSION, BUS_V1) ||
|
||||
!JSON_AddInt32ToObject(json, AUTH_PORT, LnnGetAuthPort(info)) ||
|
||||
!JSON_AddInt32ToObject(json, SESSION_PORT, LnnGetSessionPort(info)) ||
|
||||
@ -1285,7 +1281,7 @@ static int32_t PackDeviceInfoBtV1(JsonObj *json, const NodeInfo *info, bool isMe
|
||||
|
||||
static int32_t UnpackDeviceInfoBtV1(const JsonObj *json, NodeInfo *info)
|
||||
{
|
||||
char deviceType[DEVICE_TYPE_BUF_LEN] = {0};
|
||||
char deviceType[DEVICE_TYPE_BUF_LEN] = { 0 };
|
||||
if (!JSON_GetStringFromOject(json, DEVICE_NAME, info->deviceInfo.deviceName, DEVICE_NAME_BUF_LEN) ||
|
||||
!JSON_GetStringFromOject(json, DEVICE_TYPE, deviceType, DEVICE_TYPE_BUF_LEN) ||
|
||||
!JSON_GetStringFromOject(json, DEVICE_UDID, info->deviceInfo.deviceUdid, UDID_BUF_LEN) ||
|
||||
@ -1314,12 +1310,17 @@ static int32_t UnpackDeviceInfoBtV1(const JsonObj *json, NodeInfo *info)
|
||||
}
|
||||
if (strcpy_s(info->networkId, NETWORK_ID_BUF_LEN, info->uuid) != EOK) {
|
||||
AUTH_LOGE(AUTH_FSM, "strcpy networkId fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
char *PackDeviceInfoMessage(int32_t linkType, SoftBusVersion version, bool isMetaAuth, const char *remoteUuid)
|
||||
{
|
||||
if (remoteUuid == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "remoteUuid is null");
|
||||
return NULL;
|
||||
}
|
||||
AUTH_LOGI(AUTH_FSM, "connType=%d", linkType);
|
||||
const NodeInfo *info = LnnGetLocalNodeInfo();
|
||||
if (info == NULL) {
|
||||
@ -1365,8 +1366,7 @@ static void UpdatePeerDeviceName(NodeInfo *peerNodeInfo)
|
||||
if (strlen(peerNodeInfo->deviceInfo.unifiedName) != 0 &&
|
||||
strcmp(peerNodeInfo->deviceInfo.unifiedName, peerNodeInfo->deviceInfo.unifiedDefaultName) != 0) {
|
||||
ret = strcpy_s(deviceName, DEVICE_NAME_BUF_LEN, peerNodeInfo->deviceInfo.unifiedName);
|
||||
} else if (strlen(peerNodeInfo->deviceInfo.nickName) == 0 ||
|
||||
localInfo->accountId == peerNodeInfo->accountId) {
|
||||
} else if (strlen(peerNodeInfo->deviceInfo.nickName) == 0 || localInfo->accountId == peerNodeInfo->accountId) {
|
||||
ret = strcpy_s(deviceName, DEVICE_NAME_BUF_LEN, peerNodeInfo->deviceInfo.unifiedDefaultName);
|
||||
} else {
|
||||
LnnGetDeviceDisplayName(peerNodeInfo->deviceInfo.nickName,
|
||||
@ -1385,8 +1385,8 @@ static void UpdatePeerDeviceName(NodeInfo *peerNodeInfo)
|
||||
|
||||
int32_t UnpackDeviceInfoMessage(const DevInfoData *devInfo, NodeInfo *nodeInfo, bool isMetaAuth)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(devInfo, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(nodeInfo, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(devInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "devInfo is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(nodeInfo != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "nodeInfo is NULL");
|
||||
AUTH_LOGI(AUTH_FSM, "connType=%d", devInfo->linkType);
|
||||
JsonObj *json = JSON_Parse(devInfo->msg, devInfo->len);
|
||||
if (json == NULL) {
|
||||
@ -1489,7 +1489,7 @@ static int32_t PostDeviceIdNew(int64_t authSeq, const AuthSessionInfo *info)
|
||||
|
||||
int32_t PostDeviceIdMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
if (info->version == SOFTBUS_OLD_V1) {
|
||||
return PostDeviceIdV1(authSeq, info);
|
||||
} else {
|
||||
@ -1499,11 +1499,9 @@ int32_t PostDeviceIdMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
|
||||
int32_t ProcessDeviceIdMessage(AuthSessionInfo *info, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
|
||||
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) &&
|
||||
(len == DEVICE_ID_STR_LEN) &&
|
||||
(info->isServer)) {
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
|
||||
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) && (len == DEVICE_ID_STR_LEN) && (info->isServer)) {
|
||||
info->version = SOFTBUS_OLD_V1;
|
||||
return UnPackBtDeviceIdV1(info, data, len);
|
||||
}
|
||||
@ -1520,13 +1518,15 @@ static void GetSessionKeyList(int64_t authSeq, const AuthSessionInfo *info, Sess
|
||||
}
|
||||
if (AddSessionKey(list, TO_INT32(authSeq), &sessionKey) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "add session key fail");
|
||||
(void)memset_s(&sessionKey, sizeof(SessionKey), 0, sizeof(SessionKey));
|
||||
return;
|
||||
}
|
||||
(void)memset_s(&sessionKey, sizeof(SessionKey), 0, sizeof(SessionKey));
|
||||
}
|
||||
|
||||
int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
char *msg = PackDeviceInfoMessage(info->connInfo.type, info->version, false, info->uuid);
|
||||
if (msg == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "pack device info fail");
|
||||
@ -1543,7 +1543,7 @@ int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
compressFlag = FLAG_COMPRESS_DEVICE_INFO;
|
||||
AUTH_LOGI(AUTH_FSM, "deviceInfo compress finish");
|
||||
}
|
||||
AUTH_LOGI(AUTH_FSM, "after compress, datalen=%d", compressLen);
|
||||
AUTH_LOGI(AUTH_FSM, "after compress, datalen=%u", compressLen);
|
||||
}
|
||||
uint8_t *inputData = NULL;
|
||||
uint32_t inputLen;
|
||||
@ -1593,8 +1593,8 @@ int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
|
||||
int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
|
||||
uint8_t *msg = NULL;
|
||||
uint32_t msgSize = 0;
|
||||
SessionKeyList sessionKeyList;
|
||||
@ -1606,7 +1606,7 @@ int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const u
|
||||
uint8_t *decompressData = NULL;
|
||||
uint32_t decompressLen = 0;
|
||||
if ((info->connInfo.type != AUTH_LINK_TYPE_WIFI) && info->isSupportCompress) {
|
||||
AUTH_LOGI(AUTH_FSM, "before decompress, msgSize=%d", msgSize);
|
||||
AUTH_LOGI(AUTH_FSM, "before decompress, msgSize=%u", msgSize);
|
||||
if (DataDecompress((uint8_t *)msg, msgSize, &decompressData, &decompressLen) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_FSM, "data decompress fail");
|
||||
SoftBusFree(msg);
|
||||
@ -1637,7 +1637,7 @@ int32_t ProcessDeviceInfoMessage(int64_t authSeq, AuthSessionInfo *info, const u
|
||||
|
||||
int32_t PostCloseAckMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
const char *msg = "";
|
||||
AuthDataHead head = {
|
||||
.dataType = DATA_TYPE_CLOSE_ACK,
|
||||
@ -1655,8 +1655,8 @@ int32_t PostCloseAckMessage(int64_t authSeq, const AuthSessionInfo *info)
|
||||
|
||||
int32_t PostHichainAuthMessage(int64_t authSeq, const AuthSessionInfo *info, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(info, SOFTBUS_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "info is NULL");
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(data != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "data is NULL");
|
||||
AuthDataHead head = {
|
||||
.dataType = DATA_TYPE_AUTH,
|
||||
.module = MODULE_AUTH_SDK,
|
||||
@ -1678,8 +1678,7 @@ static char *PackVerifyDeviceMessage(const char *uuid)
|
||||
AUTH_LOGE(AUTH_FSM, "create json fail");
|
||||
return NULL;
|
||||
}
|
||||
if (!JSON_AddInt32ToObject(obj, CODE, CODE_VERIFY_DEVICE) ||
|
||||
!JSON_AddStringToObject(obj, DEVICE_ID, uuid)) {
|
||||
if (!JSON_AddInt32ToObject(obj, CODE, CODE_VERIFY_DEVICE) || !JSON_AddStringToObject(obj, DEVICE_ID, uuid)) {
|
||||
AUTH_LOGE(AUTH_FSM, "add uuid fail");
|
||||
JSON_Delete(obj);
|
||||
return NULL;
|
||||
@ -1730,7 +1729,7 @@ bool IsFlushDevicePacket(const AuthConnInfo *connInfo, const AuthDataHead *head,
|
||||
|
||||
int32_t PostVerifyDeviceMessage(const AuthManager *auth, int32_t flagRelay)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(auth, SOFTBUS_INVALID_PARAM);
|
||||
AUTH_CHECK_AND_RETURN_RET_LOGE(auth != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "auth is NULL");
|
||||
char *msg = PackVerifyDeviceMessage(auth->uuid);
|
||||
if (msg == NULL) {
|
||||
AUTH_LOGE(AUTH_FSM, "pack verify device msg fail");
|
||||
|
@ -151,6 +151,7 @@ typedef struct {
|
||||
bool p2pOnly;
|
||||
ProtocolType acceptableProtocols;
|
||||
int32_t pid;
|
||||
bool isWithQos;
|
||||
//OldInfo
|
||||
char peerBleMac[MAX_MAC_LEN];
|
||||
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'
|
||||
|
@ -17,28 +17,18 @@
|
||||
#define LNN_TRANS_LANE_H
|
||||
|
||||
#include "lnn_lane_assign.h"
|
||||
#include "lnn_lane_link.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
MSG_TYPE_LANE_TRIGGER_LINK = 0,
|
||||
MSG_TYPE_LANE_LINK_SUCCESS,
|
||||
MSG_TYPE_LANE_LINK_FAIL,
|
||||
MSG_TYPE_LANE_LINK_EXCEPTION,
|
||||
MSG_TYPE_DELAY_DESTROY_LINK,
|
||||
MSG_TYPE_LANE_DETECT_TIMEOUT,
|
||||
MSG_TYPE_RELIABILITY_TIME,
|
||||
} LaneMsgType;
|
||||
|
||||
LaneInterface *TransLaneGetInstance(void);
|
||||
int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt);
|
||||
int32_t LnnLanePostMsgToHandler(int32_t msgType, uint64_t param1, uint64_t param2,
|
||||
void *obj, uint64_t delayMillis);
|
||||
int32_t GetTransOptionByLaneId(uint32_t laneId, TransOption *reqInfo);
|
||||
int32_t PostDetectTimeoutMessage(uint32_t detectId, uint64_t delayMillis);
|
||||
int32_t PostReliabilityTimeMessage(void);
|
||||
void RemoveDetectTimeoutMessage(uint32_t detectId);
|
||||
int32_t PostDelayDestroyMessage(uint32_t laneId, LaneResource *resourseItem, uint64_t delayMillis);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -179,10 +179,12 @@ int32_t AddLaneResourceItem(const LaneResource *inputResource)
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (CreateResourceItem(inputResource, resourceItem) != SOFTBUS_OK) {
|
||||
SoftBusFree(resourceItem);
|
||||
LNN_LOGE(LNN_LANE, "create resourceItem fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LaneLock() != SOFTBUS_OK) {
|
||||
SoftBusFree(resourceItem);
|
||||
LNN_LOGE(LNN_LANE, "lane lock fail");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -198,6 +200,25 @@ int32_t AddLaneResourceItem(const LaneResource *inputResource)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t StartDelayDestroyLink(uint32_t laneId, LaneResource *item)
|
||||
{
|
||||
LaneResource *resourceItem = (LaneResource *)SoftBusMalloc(sizeof(LaneResource));
|
||||
if (resourceItem == NULL) {
|
||||
LNN_LOGE(LNN_LANE, "resourceItem malloc fail");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s(resourceItem, sizeof(LaneResource), item, sizeof(LaneResource)) != EOK) {
|
||||
LNN_LOGE(LNN_LANE, "memcpy LaneResource error");
|
||||
SoftBusFree(resourceItem);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
if (PostDelayDestroyMessage(laneId, resourceItem, DELAY_DESTROY_LANE_TIME) != SOFTBUS_OK) {
|
||||
SoftBusFree(resourceItem);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t DelLaneResourceItemWithDelay(LaneResource *resourceItem, uint32_t laneId, bool *isDelayDestroy)
|
||||
{
|
||||
if (resourceItem == NULL || isDelayDestroy == NULL) {
|
||||
@ -210,9 +231,9 @@ int32_t DelLaneResourceItemWithDelay(LaneResource *resourceItem, uint32_t laneId
|
||||
}
|
||||
LaneResource* item = LaneResourceIsExist(resourceItem);
|
||||
if (item != NULL) {
|
||||
LNN_LOGI(LNN_LANE, "link=%d ref=%d", item->type, item->laneRef);
|
||||
if (item->type == LANE_HML && item->laneRef == 1) {
|
||||
if (LnnLanePostMsgToHandler(MSG_TYPE_DELAY_DESTROY_LINK, laneId, *isDelayDestroy, item,
|
||||
DELAY_DESTROY_LANE_TIME) == SOFTBUS_OK) {
|
||||
if (StartDelayDestroyLink(laneId, item) == SOFTBUS_OK) {
|
||||
*isDelayDestroy = true;
|
||||
LaneUnlock();
|
||||
return SOFTBUS_OK;
|
||||
@ -324,10 +345,12 @@ int32_t AddLinkInfoItem(const LaneLinkInfo *inputLinkInfo)
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (CreateLinkInfoItem(inputLinkInfo, linkInfoItem) != SOFTBUS_OK) {
|
||||
SoftBusFree(linkInfoItem);
|
||||
LNN_LOGE(LNN_LANE, "create linkInfoItem fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LaneLock() != SOFTBUS_OK) {
|
||||
SoftBusFree(linkInfoItem);
|
||||
LNN_LOGE(LNN_LANE, "lane lock fail");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -703,6 +726,22 @@ static int32_t LaneLinkOfBleReuse(uint32_t reqId, const LinkRequest *reqInfo, co
|
||||
return LaneLinkOfBleReuseCommon(reqId, reqInfo, callback, BLE_GATT);
|
||||
}
|
||||
|
||||
static int32_t LaneLinkSetBleMac(const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
|
||||
{
|
||||
NodeInfo node;
|
||||
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
|
||||
if (LnnGetRemoteNodeInfoById(reqInfo->peerNetworkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "can not find node");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (node.bleMacRefreshSwitch == 0 && strlen(node.connectInfo.bleMacAddr) > 0) {
|
||||
if (strcpy_s(linkInfo->linkInfo.ble.bleMac, BT_MAC_LEN, node.connectInfo.bleMacAddr) == EOK) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
|
||||
{
|
||||
LaneLinkInfo linkInfo;
|
||||
@ -712,8 +751,10 @@ static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const L
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
if (strlen(linkInfo.linkInfo.ble.bleMac) == 0) {
|
||||
LNN_LOGE(LNN_LANE, "get peerBleMac error");
|
||||
return SOFTBUS_ERR;
|
||||
if (LaneLinkSetBleMac(reqInfo, &linkInfo) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "get peerBleMac error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
char peerUdid[UDID_BUF_LEN] = {0};
|
||||
if (LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_DEV_UDID, peerUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
|
||||
|
@ -62,6 +62,7 @@ typedef struct {
|
||||
bool networkDelegate;
|
||||
bool p2pOnly;
|
||||
uint32_t bandWidth;
|
||||
bool isWithQos;
|
||||
} P2pRequestInfo;
|
||||
|
||||
typedef struct {
|
||||
@ -362,11 +363,12 @@ static int32_t GetP2pLinkReqParamByChannelRequetId(
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
|
||||
if (item->p2pInfo.p2pOnly) {
|
||||
wifiDirectInfo->connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P;
|
||||
} else {
|
||||
if (item->p2pInfo.isWithQos) {
|
||||
wifiDirectInfo->connectType = ((item->laneRequestInfo.laneType == LANE_HML) ?
|
||||
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P);
|
||||
} else {
|
||||
wifiDirectInfo->connectType = item->p2pInfo.p2pOnly ? WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P :
|
||||
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
|
||||
}
|
||||
item->p2pInfo.p2pRequestId = p2pRequestId;
|
||||
item->proxyChannelInfo.channelId = channelId;
|
||||
@ -407,11 +409,12 @@ static int32_t GetP2pLinkReqParamByAuthId(uint32_t authRequestId, int32_t p2pReq
|
||||
}
|
||||
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
|
||||
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
|
||||
if (item->p2pInfo.p2pOnly) {
|
||||
wifiDirectInfo->connectType = WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P;
|
||||
} else {
|
||||
if (item->p2pInfo.isWithQos) {
|
||||
wifiDirectInfo->connectType = ((item->laneRequestInfo.laneType == LANE_HML) ?
|
||||
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P);
|
||||
} else {
|
||||
wifiDirectInfo->connectType = item->p2pInfo.p2pOnly ? WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P :
|
||||
WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
|
||||
}
|
||||
item->p2pInfo.p2pRequestId = p2pRequestId;
|
||||
LinkUnlock();
|
||||
@ -617,6 +620,25 @@ static void OnAuthConnOpenFailed(uint32_t authRequestId, int32_t reason)
|
||||
NotifyLinkFail(ASYNC_RESULT_AUTH, authRequestId, reason);
|
||||
}
|
||||
|
||||
static int32_t updataP2pLinkReq(P2pLinkReqList *p2pReqInfo, uint32_t laneLinkReqId)
|
||||
{
|
||||
TransOption reqInfo = {0};
|
||||
if (GetTransOptionByLaneId(laneLinkReqId, &reqInfo) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "get TransReqInfo fail, laneId=%d", laneLinkReqId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (reqInfo.isWithQos) {
|
||||
p2pReqInfo->p2pInfo.bandWidth = reqInfo.qosRequire.minBW;
|
||||
p2pReqInfo->p2pInfo.isWithQos = true;
|
||||
} else {
|
||||
p2pReqInfo->p2pInfo.bandWidth = 0;
|
||||
p2pReqInfo->p2pInfo.isWithQos = false;
|
||||
}
|
||||
LNN_LOGI(LNN_LANE, "wifidirect conn, bandWidth=%d isWithQos=%d laneId=%d",
|
||||
p2pReqInfo->p2pInfo.bandWidth, p2pReqInfo->p2pInfo.isWithQos, laneLinkReqId);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t AddConnRequestItem(uint32_t authRequestId, int32_t p2pRequestId, uint32_t laneLinkReqId,
|
||||
const LinkRequest *request, int32_t channelRequestId, const LaneLinkCb *callback)
|
||||
{
|
||||
@ -634,11 +656,9 @@ static int32_t AddConnRequestItem(uint32_t authRequestId, int32_t p2pRequestId,
|
||||
SoftBusFree(item);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
QosInfo qosOpt = {0};
|
||||
if (GetQosInfoByLaneId(laneLinkReqId, &qosOpt) != SOFTBUS_OK) {
|
||||
item->p2pInfo.bandWidth = 0;
|
||||
} else {
|
||||
item->p2pInfo.bandWidth = qosOpt.minBW;
|
||||
if (updataP2pLinkReq(item, laneLinkReqId) != SOFTBUS_OK) {
|
||||
SoftBusFree(item);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
item->laneRequestInfo.laneLinkReqId = laneLinkReqId;
|
||||
item->laneRequestInfo.pid = request->pid;
|
||||
|
@ -208,6 +208,7 @@ static int32_t WlanDetectReliability(uint32_t lnnReqId, const LaneLinkInfo *lane
|
||||
}
|
||||
infoItem->linkInfo.wlanDetect.wlanFd = fd;
|
||||
if (SoftBusMutexLock(&g_laneDetectList.lock) != SOFTBUS_OK) {
|
||||
ConnShutdownSocket(fd);
|
||||
SoftBusFree(infoItem);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -215,6 +216,7 @@ static int32_t WlanDetectReliability(uint32_t lnnReqId, const LaneLinkInfo *lane
|
||||
ListTailInsert(&g_laneDetectList.list, &infoItem->node);
|
||||
SoftBusMutexUnlock(&g_laneDetectList.lock);
|
||||
if (AddLaneTriggerAndTimeOut(fd, infoItem->laneDetectId) != SOFTBUS_OK) {
|
||||
ConnShutdownSocket(fd);
|
||||
DelLaneDetectInfo(infoItem->laneDetectId);
|
||||
LNN_LOGI(LNN_LANE, "wlan add trigger and timrout msg fail, lnnReqId=%u", infoItem->laneDetectId);
|
||||
return SOFTBUS_ERR;
|
||||
|
@ -239,24 +239,38 @@ static void SwapListNode(LaneLinkType *left, LaneLinkType *right)
|
||||
*right = tmp;
|
||||
}
|
||||
|
||||
static int32_t AdjustLanePriority(LaneLinkType *resList, int32_t *resListScore, uint32_t resNum)
|
||||
static int32_t AdjustLanePriority(const char *networkId, const LaneSelectParam *request,
|
||||
LaneLinkType *resList, uint32_t resNum)
|
||||
{
|
||||
int32_t resListScore[LANE_LINK_TYPE_BUTT];
|
||||
(void)memset_s(resListScore, sizeof(resListScore), INVALID_LINK, sizeof(resListScore));
|
||||
if (GetListScore(networkId, request->expectedBw, resList, resListScore, resNum) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "get linklist score fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if ((resListScore[LANE_WLAN_2P4G] == INVALID_LINK && resListScore[LANE_WLAN_5G] == INVALID_LINK) ||
|
||||
resListScore[LANE_P2P] == INVALID_LINK) {
|
||||
LNN_LOGI(LNN_LANE, "resList no change");
|
||||
(resListScore[LANE_P2P] == INVALID_LINK && resListScore[LANE_HML] == INVALID_LINK)) {
|
||||
LNN_LOGI(LNN_LANE, "linklist does not require any changes");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
uint32_t idxWlan = LANE_LINK_TYPE_BUTT;
|
||||
uint32_t idxP2p = LANE_LINK_TYPE_BUTT;
|
||||
for (uint32_t i = 0; i < resNum; ++i) {
|
||||
if (resList[i] == LANE_P2P) {
|
||||
idxP2p = i;
|
||||
} else if (resList[i] == LANE_WLAN_2P4G || resList[i] == LANE_WLAN_5G) {
|
||||
idxWlan = (idxWlan == LANE_LINK_TYPE_BUTT) ? i : idxWlan;
|
||||
if (resList[i] == LANE_WLAN_2P4G || resList[i] == LANE_WLAN_5G) {
|
||||
idxWlan = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (resListScore[resList[idxWlan]] < UNACCEPT_SCORE && idxWlan < idxP2p) {
|
||||
SwapListNode(&resList[idxWlan], &resList[idxP2p]);
|
||||
if (resListScore[resList[idxWlan]] >= UNACCEPT_SCORE) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
for (uint32_t j = idxWlan; j < resNum; ++j) {
|
||||
if (resList[j] == LANE_HML || resList[j] == LANE_P2P) {
|
||||
SwapListNode(&resList[idxWlan], &resList[j]);
|
||||
idxWlan = j;
|
||||
}
|
||||
}
|
||||
for (uint32_t k = 0; k < resNum; ++k) {
|
||||
LNN_LOGD(LNN_LANE, "adjusted linklist , priority link=%d, score=%d", resList[k], resListScore[resList[k]]);
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
@ -282,20 +296,10 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
|
||||
*listNum = 0;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
int32_t resListScore[LANE_LINK_TYPE_BUTT];
|
||||
(void)memset_s(resListScore, sizeof(resListScore), INVALID_LINK, sizeof(resListScore));
|
||||
if (GetListScore(networkId, request->expectedBw, resList, resListScore, resNum) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "get resListScore fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (AdjustLanePriority(resList, resListScore, resNum) != SOFTBUS_OK) {
|
||||
if (AdjustLanePriority(networkId, request, resList, resNum) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "AdjustLanePriority fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
for (uint32_t i = 0; i < resNum; ++i) {
|
||||
LNN_LOGD(LNN_LANE, "adjusted list is LaneLinkType=%d, score=%d", resList[i], resListScore[resList[i]]);
|
||||
}
|
||||
|
||||
recommendList->linkTypeNum = resNum;
|
||||
for (uint32_t i = 0; i < resNum; i++) {
|
||||
@ -305,27 +309,6 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t LanePrioritization(LanePreferredLinkList *recommendList, const uint16_t *laneScore)
|
||||
{
|
||||
(void)recommendList;
|
||||
(void)laneScore;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool GetLaneScore(const char *networkId, LaneLinkType linkType, uint16_t *score)
|
||||
{
|
||||
if (!IsLinkTypeValid(linkType)) {
|
||||
return false;
|
||||
}
|
||||
LinkAttribute *linkAttr = GetLinkAttrByLinkType(linkType);
|
||||
if ((linkAttr == NULL) || (!linkAttr->available)) {
|
||||
return false;
|
||||
}
|
||||
uint32_t expectedBw = 0;
|
||||
score[linkType] = linkAttr->GetLinkScore(networkId, expectedBw);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *request,
|
||||
LanePreferredLinkList *recommendList)
|
||||
{
|
||||
@ -351,19 +334,16 @@ int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *req
|
||||
}
|
||||
}
|
||||
recommendList->linkTypeNum = 0;
|
||||
uint16_t laneScore[LANE_LINK_TYPE_BUTT] = {0};
|
||||
for (uint32_t i = 0; i < laneLinkList.linkTypeNum; i++) {
|
||||
if (!GetLaneScore(networkId, laneLinkList.linkType[i], laneScore)) {
|
||||
LNN_LOGE(LNN_LANE, "link=%d get lane score fail", laneLinkList.linkType[i]);
|
||||
continue;
|
||||
}
|
||||
recommendList->linkType[recommendList->linkTypeNum] = laneLinkList.linkType[i];
|
||||
LNN_LOGI(LNN_LANE, "expect linklist the %u priority link=%d",
|
||||
recommendList->linkTypeNum, laneLinkList.linkType[i]);
|
||||
recommendList->linkTypeNum++;
|
||||
}
|
||||
|
||||
if (LanePrioritization(recommendList, laneScore) != SOFTBUS_OK) {
|
||||
if (AdjustLanePriority(networkId, request, recommendList->linkType,
|
||||
recommendList->linkTypeNum) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "AdjustLanePriority fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
|
@ -41,13 +41,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 LOW_BW (384 * 1024)
|
||||
#define HIGH_BW (160 * 1024 * 1024)
|
||||
#define COC_DIRECT_LATENCY 1200
|
||||
#define BR_LATENCY 2500
|
||||
#define WLAN_LATENCY 800
|
||||
#define P2P_LATENCY 1600
|
||||
#define BLE_LATENCY 1500
|
||||
#define HML_LATENCY 1500
|
||||
#define BR_REUSE_LATENCY 1000
|
||||
|
||||
|
||||
int32_t GetWlanLinkedFrequency(void)
|
||||
@ -393,20 +395,21 @@ static int32_t g_laneLatency[LANE_LINK_TYPE_BUTT] = {
|
||||
[LANE_WLAN_2P4G] = WLAN_LATENCY,
|
||||
[LANE_WLAN_5G] = WLAN_LATENCY,
|
||||
[LANE_COC_DIRECT] = COC_DIRECT_LATENCY,
|
||||
[LANE_BLE] = BLE_LATENCY,
|
||||
};
|
||||
|
||||
static uint32_t g_laneBandWidth[BW_TYPE_BUTT][LANE_LINK_TYPE_BUTT + 1] = {
|
||||
[HIGH_BAND_WIDTH] = {LANE_P2P, LANE_LINK_TYPE_BUTT},
|
||||
[MIDDLE_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_LINK_TYPE_BUTT},
|
||||
[LOW_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_COC_DIRECT, LANE_LINK_TYPE_BUTT},
|
||||
[MIDDLE_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_LINK_TYPE_BUTT},
|
||||
[LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_COC_DIRECT, LANE_LINK_TYPE_BUTT},
|
||||
};
|
||||
|
||||
static uint32_t g_retryLaneList[BW_TYPE_BUTT][LANE_LINK_TYPE_BUTT + 1] = {
|
||||
[HIGH_BAND_WIDTH] = {LANE_P2P, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_LINK_TYPE_BUTT},
|
||||
[MIDDLE_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_P2P,
|
||||
LANE_BR, LANE_LINK_TYPE_BUTT},
|
||||
[LOW_BAND_WIDTH] = {LANE_HML, LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_P2P, LANE_COC_DIRECT,
|
||||
LANE_BR, LANE_LINK_TYPE_BUTT},
|
||||
[MIDDLE_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_P2P, LANE_BR,
|
||||
LANE_LINK_TYPE_BUTT},
|
||||
[LOW_BAND_WIDTH] = {LANE_WLAN_5G, LANE_WLAN_2P4G, LANE_HML, LANE_P2P, LANE_COC_DIRECT,
|
||||
LANE_BR, LANE_BLE, LANE_LINK_TYPE_BUTT},
|
||||
};
|
||||
|
||||
static bool IsLinkTypeValid(LaneLinkType type)
|
||||
@ -454,16 +457,14 @@ static void DecideOptimalLinks(const char *networkId, const LaneSelectParam *req
|
||||
{
|
||||
uint32_t minBandWidth = request->qosRequire.minBW;
|
||||
uint32_t minLaneLatency = request->qosRequire.minLaneLatency;
|
||||
if (minBandWidth == 0) {
|
||||
minBandWidth = LOW_BW;
|
||||
}
|
||||
if (minLaneLatency == 0) {
|
||||
minLaneLatency = BR_LATENCY;
|
||||
LNN_LOGI(LNN_LANE, "minLaneLatency is zero, cancel decide optimal link");
|
||||
return;
|
||||
}
|
||||
int32_t bandWidthType;
|
||||
if (minBandWidth >= HIGH_BW) {
|
||||
bandWidthType = HIGH_BAND_WIDTH;
|
||||
} else if (minBandWidth >= LOW_BW) {
|
||||
} else if (minBandWidth > LOW_BW) {
|
||||
bandWidthType = MIDDLE_BAND_WIDTH;
|
||||
} else {
|
||||
bandWidthType = LOW_BAND_WIDTH;
|
||||
@ -493,22 +494,39 @@ static bool isLaneExist(LaneLinkType *linkList, LaneLinkType laneType)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void GetAllLinksWithBw(const char *networkId, int32_t bandWidthType, const LaneSelectParam *request,
|
||||
LaneLinkType *linkList, uint32_t *linksNum)
|
||||
{
|
||||
for (uint32_t i = 0; i < (LANE_LINK_TYPE_BUTT + 1); i++) {
|
||||
if (g_retryLaneList[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
|
||||
break;
|
||||
}
|
||||
if (IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
|
||||
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
|
||||
linkList[(*linksNum)++] = g_retryLaneList[bandWidthType][i];
|
||||
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", g_retryLaneList[bandWidthType][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DecideRetryLinks(const char *networkId, const LaneSelectParam *request,
|
||||
LaneLinkType *linkList, uint32_t *linksNum)
|
||||
{
|
||||
uint32_t minBandWidth = request->qosRequire.minBW;
|
||||
uint32_t maxLaneLatency = request->qosRequire.maxLaneLatency;
|
||||
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) {
|
||||
} else if (minBandWidth > LOW_BW) {
|
||||
bandWidthType = MIDDLE_BAND_WIDTH;
|
||||
} else {
|
||||
bandWidthType = LOW_BAND_WIDTH;
|
||||
}
|
||||
if (maxLaneLatency == 0) {
|
||||
LNN_LOGI(LNN_LANE, "maxLaneLatency is zero, get all retry link");
|
||||
GetAllLinksWithBw(networkId, bandWidthType, request, linkList, linksNum);
|
||||
return;
|
||||
}
|
||||
int32_t retryTime;
|
||||
if (*linksNum == 0) {
|
||||
LNN_LOGI(LNN_LANE, "optimal links num=0");
|
||||
@ -521,14 +539,40 @@ static void DecideRetryLinks(const char *networkId, const LaneSelectParam *reque
|
||||
if (g_retryLaneList[bandWidthType][i] == LANE_LINK_TYPE_BUTT) {
|
||||
break;
|
||||
}
|
||||
if (IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
|
||||
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i]) &&
|
||||
retryTime - g_laneLatency[g_retryLaneList[bandWidthType][i]] >= 0) {
|
||||
if (retryTime - g_laneLatency[g_retryLaneList[bandWidthType][i]] >= 0 &&
|
||||
IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
|
||||
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
|
||||
retryTime -= g_laneLatency[g_retryLaneList[bandWidthType][i]];
|
||||
linkList[(*linksNum)++] = g_retryLaneList[bandWidthType][i];
|
||||
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", g_retryLaneList[bandWidthType][i]);
|
||||
}
|
||||
}
|
||||
if (bandWidthType == LOW_BAND_WIDTH &&
|
||||
IsValidLane(networkId, LANE_BR, request->transType) && !isLaneExist(linkList, LANE_BR)) {
|
||||
linkList[(*linksNum)++] = LANE_BR;
|
||||
LNN_LOGI(LNN_LANE, "decide retry linkType=%d", LANE_BR);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsSupportBrReuse(const char *peerNetWorkId)
|
||||
{
|
||||
ConnectOption connOpt;
|
||||
(void)memset_s(&connOpt, sizeof(ConnectOption), 0, sizeof(ConnectOption));
|
||||
connOpt.type = CONNECT_BR;
|
||||
if (LnnGetRemoteStrInfo(peerNetWorkId, STRING_KEY_BT_MAC, connOpt.brOption.brMac, BT_MAC_LEN) != SOFTBUS_OK ||
|
||||
connOpt.brOption.brMac[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
return CheckActiveConnection(&connOpt);
|
||||
}
|
||||
|
||||
static void UpdataLaneLatency(const char *peerNetWorkId)
|
||||
{
|
||||
if (IsSupportBrReuse(peerNetWorkId)) {
|
||||
g_laneLatency[LANE_BR] = BR_REUSE_LATENCY;
|
||||
} else {
|
||||
g_laneLatency[LANE_BR] = BR_LATENCY;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *request, LanePreferredLinkList *recommendList)
|
||||
@ -539,6 +583,7 @@ int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *reques
|
||||
LaneLinkType linkList[LANE_LINK_TYPE_BUTT];
|
||||
(void)memset_s(linkList, sizeof(linkList), -1, sizeof(linkList));
|
||||
uint32_t linksNum = 0;
|
||||
UpdataLaneLatency(networkId);
|
||||
DecideOptimalLinks(networkId, request, linkList, &linksNum);
|
||||
DecideRetryLinks(networkId, request, linkList, &linksNum);
|
||||
for (uint32_t i = 0; i < linksNum; i++) {
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "lnn_lane_common.h"
|
||||
#include "lnn_lane_def.h"
|
||||
#include "lnn_lane_interface.h"
|
||||
#include "lnn_lane_link.h"
|
||||
#include "lnn_lane_model.h"
|
||||
#include "lnn_lane_select.h"
|
||||
#include "lnn_log.h"
|
||||
@ -39,6 +38,16 @@
|
||||
|
||||
#define DETECT_LANE_TIMELINESS 2000
|
||||
|
||||
typedef enum {
|
||||
MSG_TYPE_LANE_TRIGGER_LINK = 0,
|
||||
MSG_TYPE_LANE_LINK_SUCCESS,
|
||||
MSG_TYPE_LANE_LINK_FAIL,
|
||||
MSG_TYPE_LANE_LINK_EXCEPTION,
|
||||
MSG_TYPE_DELAY_DESTROY_LINK,
|
||||
MSG_TYPE_LANE_DETECT_TIMEOUT,
|
||||
MSG_TYPE_RELIABILITY_TIME,
|
||||
} LaneMsgType;
|
||||
|
||||
typedef struct {
|
||||
ListNode node;
|
||||
uint32_t laneId;
|
||||
@ -275,6 +284,7 @@ static int32_t StartTriggerLink(uint32_t laneId, TransOption *transRequest, cons
|
||||
if (newItem == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
newItem->info.isWithQos = true;
|
||||
if (Lock() != SOFTBUS_OK) {
|
||||
SoftBusFree(newItem);
|
||||
return SOFTBUS_ERR;
|
||||
@ -363,6 +373,7 @@ static int32_t Alloc(uint32_t laneId, const LaneRequestOption *request, const IL
|
||||
SoftBusFree(recommendLinkList);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
newItem->info.isWithQos = false;
|
||||
if (Lock() != SOFTBUS_OK) {
|
||||
SoftBusFree(newItem);
|
||||
SoftBusFree(recommendLinkList);
|
||||
@ -404,7 +415,9 @@ static int32_t FreeLaneLink(uint32_t laneId, LaneResource *laneResourceInfo, boo
|
||||
Unlock();
|
||||
DelLinkInfoItem(laneId);
|
||||
if (isDelayDestroy) {
|
||||
LNN_LOGI(LNN_LANE, "laneId=%u, delayDestroy finished", laneId);
|
||||
DelLaneResourceItem(laneResourceInfo);
|
||||
SoftBusFree(laneResourceInfo);
|
||||
}
|
||||
DestroyLink(item->info.networkId, laneId, item->type, item->info.pid);
|
||||
UnbindLaneId(laneId, item);
|
||||
@ -413,6 +426,11 @@ static int32_t FreeLaneLink(uint32_t laneId, LaneResource *laneResourceInfo, boo
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
}
|
||||
DelLinkInfoItem(laneId);
|
||||
if (isDelayDestroy) {
|
||||
DelLaneResourceItem(laneResourceInfo);
|
||||
SoftBusFree(laneResourceInfo);
|
||||
}
|
||||
Unlock();
|
||||
FreeLaneId(laneId);
|
||||
return SOFTBUS_OK;
|
||||
@ -686,6 +704,7 @@ static void HandleDelayDestroyLink(SoftBusMessage *msg)
|
||||
uint32_t laneId = (uint32_t)msg->arg1;
|
||||
bool isDelayDestroy = (bool)msg->arg2;
|
||||
LaneResource *resourceItem = (LaneResource*)msg->obj;
|
||||
LNN_LOGI(LNN_LANE, "handle delay destory message, laneId=%u", laneId);
|
||||
FreeLaneLink(laneId, resourceItem, isDelayDestroy);
|
||||
}
|
||||
|
||||
@ -816,9 +835,9 @@ LaneInterface *TransLaneGetInstance(void)
|
||||
return &g_transLaneObject;
|
||||
}
|
||||
|
||||
int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt)
|
||||
int32_t GetTransOptionByLaneId(uint32_t laneId, TransOption *reqInfo)
|
||||
{
|
||||
if (qosOpt == NULL || laneId == INVALID_LANE_ID) {
|
||||
if (reqInfo == NULL || laneId == INVALID_LANE_ID) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (Lock() != SOFTBUS_OK) {
|
||||
@ -827,7 +846,11 @@ int32_t GetQosInfoByLaneId(uint32_t laneId, QosInfo *qosOpt)
|
||||
TransReqInfo *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, &g_requestList->list, TransReqInfo, node) {
|
||||
if (item->laneId == laneId) {
|
||||
*qosOpt = item->info.qosRequire;
|
||||
if (memcpy_s(reqInfo, sizeof(TransOption), &item->info, sizeof(TransOption)) != EOK) {
|
||||
LNN_LOGE(LNN_LANE, "memcpy TransReqInfo fail");
|
||||
Unlock();
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
Unlock();
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
@ -865,4 +888,10 @@ void RemoveDetectTimeoutMessage(uint32_t detectId)
|
||||
int32_t PostReliabilityTimeMessage(void)
|
||||
{
|
||||
return LnnLanePostMsgToHandler(MSG_TYPE_RELIABILITY_TIME, 0, 0, NULL, DETECT_LANE_TIMELINESS);
|
||||
}
|
||||
|
||||
int32_t PostDelayDestroyMessage(uint32_t laneId, LaneResource *resourseItem, uint64_t delayMillis)
|
||||
{
|
||||
LNN_LOGI(LNN_LANE, "post dely destory message, laneId=%u", laneId);
|
||||
return LnnLanePostMsgToHandler(MSG_TYPE_DELAY_DESTROY_LINK, laneId, true, resourseItem, delayMillis);
|
||||
}
|
@ -531,6 +531,10 @@ static void NightModeChangeEventHandler(const LnnEventBasicInfo *info)
|
||||
if (g_nightOnCache == NULL) {
|
||||
LNN_LOGD(LNN_BUILDER, "init g_nightOnCache");
|
||||
g_nightOnCache = (ListNode *)SoftBusMalloc(sizeof(ListNode));
|
||||
if (g_nightOnCache == NULL) {
|
||||
LNN_LOGE(LNN_BUILDER, "malloc g_nightOnCache fail");
|
||||
return;
|
||||
}
|
||||
ListInit(g_nightOnCache);
|
||||
}
|
||||
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
|
||||
|
@ -203,6 +203,12 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
}
|
||||
innerapi_tags = [ "platformsdk_indirect" ]
|
||||
|
||||
install_images = [
|
||||
system_base_dir,
|
||||
updater_base_dir,
|
||||
]
|
||||
|
||||
part_name = "dsoftbus"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -74,6 +74,12 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
innerapi_tags = [ "platformsdk_indirect" ]
|
||||
|
||||
install_images = [
|
||||
system_base_dir,
|
||||
updater_base_dir,
|
||||
]
|
||||
|
||||
part_name = "dsoftbus"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ static void AnonymizeUdid(const char *udid, char **anonymizedUdid)
|
||||
}
|
||||
if (memset_s(*anonymizedUdid, ANONYMIZED_UDID_LEN + 1, 0, ANONYMIZED_UDID_LEN + 1) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset_s *anonymizedStr fail");
|
||||
free(*anonymizedUdid);
|
||||
return;
|
||||
}
|
||||
// Reserve 5 chars at head, concat with two wildcards, and 5 chars at tail
|
||||
@ -74,7 +73,6 @@ static void AnonymizeUdid(const char *udid, char **anonymizedUdid)
|
||||
(ANONYMIZED_UDID_LEN - RESERVED_LEN - strlen(WILDCARDS) + 1), (udid + strlen(udid) - RESERVED_LEN),
|
||||
RESERVED_LEN) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "strncpy_s *anonymizedUdid fail");
|
||||
free(*anonymizedUdid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,12 +86,10 @@ static void AnonymizeMac(const char *mac, char **anonymizedMac)
|
||||
}
|
||||
if (memset_s(*anonymizedMac, anonymizedMacLen + 1, 0, anonymizedMacLen + 1) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset_s *anonymizedStr fail");
|
||||
free(*anonymizedMac);
|
||||
return;
|
||||
}
|
||||
if (strcpy_s(*anonymizedMac, anonymizedMacLen + 1, mac) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "strcpy_s *anonymizedMac fail");
|
||||
free(*anonymizedMac);
|
||||
return;
|
||||
}
|
||||
// Anonymize the forth and fifth parts of the mac address
|
||||
@ -113,12 +109,10 @@ static void AnonymizeIp(const char *ip, char **anonymizedIp)
|
||||
}
|
||||
if (memset_s(*anonymizedIp, anonymizedIpLen + 1, 0, anonymizedIpLen + 1) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset_s *anonymizedIp fail");
|
||||
free(*anonymizedIp);
|
||||
return;
|
||||
}
|
||||
if (strcpy_s(*anonymizedIp, anonymizedIpLen + 1, ip) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "strcpy_s *anonymizedIp fail");
|
||||
free(*anonymizedIp);
|
||||
return;
|
||||
}
|
||||
// Anonymize the last part of ip address
|
||||
@ -160,7 +154,6 @@ static void AnonymizeString(char **anonymizedStr, size_t length, const char *fmt
|
||||
va_end(args);
|
||||
if (ret < 0) {
|
||||
COMM_LOGE(COMM_DFX, "vsprintf_s *anonymizedStr fail");
|
||||
free(*anonymizedStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INVALID_INT_VALUE 0
|
||||
#define PARAM_STRING_VALUE_MAX_LEN 256
|
||||
#define INVALID_INT_VALUE 0
|
||||
#define PARAM_STRING_VALUE_MAX_LEN 256
|
||||
#define PARAM_LONG_STRING_VALUE_MAX_LEN (256 * 1024)
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_LENGTH_OF_PARAM_NAME];
|
||||
@ -81,6 +82,17 @@ static inline bool AssignerString(const char *value, HiSysEventParam **param)
|
||||
CopyString((*param)->v.s, value, PARAM_STRING_VALUE_MAX_LEN);
|
||||
}
|
||||
|
||||
/* Used by ASSIGNER macros */
|
||||
static inline bool AssignerLongString(const char *value, HiSysEventParam **param)
|
||||
{
|
||||
if (value == NULL || strlen(value) == 0) {
|
||||
(*param)->v.s = NULL;
|
||||
return false;
|
||||
}
|
||||
return InitString(&(*param)->v.s, PARAM_LONG_STRING_VALUE_MAX_LEN) &&
|
||||
CopyString((*param)->v.s, value, PARAM_LONG_STRING_VALUE_MAX_LEN);
|
||||
}
|
||||
|
||||
/* Used by ASSIGNER macros */
|
||||
static inline bool AssignerErrcode(int32_t value, HiSysEventParam **param)
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ STATS_ASSIGNER(Int32, DeviceOfflineTimes, deviceOfflineTimes)
|
||||
STATS_ASSIGNER(Int32, LaneScoreOverTimes, laneScoreOverTimes)
|
||||
STATS_ASSIGNER(Int32, ActivationRate, activationRate)
|
||||
STATS_ASSIGNER(Int32, DetectionTimes, detectionTimes)
|
||||
STATS_ASSIGNER(String, SuccessRateDetail, successRateDetail)
|
||||
STATS_ASSIGNER(LongString, SuccessRateDetail, successRateDetail)
|
||||
|
||||
#define STATS_ASSIGNER_SIZE 12 // Size of g_statsAssigners
|
||||
static HiSysEventParamAssigner g_statsAssigners[] = {
|
||||
|
@ -119,7 +119,7 @@ int32_t SoftBusAlarmHiDumperInit(void)
|
||||
int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_ALARM_MODULE_NAME, SOFTBUS_ALARM_MODULE_HELP,
|
||||
&SoftBusAlarmDumpHander);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
COMM_LOGE(COMM_INIT, "SoftBusRegAlarmDumpCb registe fail");
|
||||
COMM_LOGE(COMM_DFX, "SoftBusRegAlarmDumpCb registe fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ void SoftBusTransDumpRunningSession(int fd, TransDumpLaneLinkType type, AppInfo*
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t SoftBusTransDumpHanderInit()
|
||||
int32_t SoftBusTransDumpHanderInit(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void SoftBusHiDumperTransDeInit()
|
||||
void SoftBusHiDumperTransDeInit(void)
|
||||
{
|
||||
}
|
||||
|
@ -205,11 +205,11 @@ static void GetLocalTime(char* time, uint64_t timestamp)
|
||||
(void)strftime(time, SOFTBUS_ALARM_TIME_LEN, "%Y-%m-%d %H:%M:%S", tmInfo);
|
||||
}
|
||||
|
||||
static void ConnStatsLinkType(int32_t linkType, bool success)
|
||||
static void ConnStatsLinkType(int32_t linkTypePara, bool success)
|
||||
{
|
||||
int32_t linkType = linkTypePara;
|
||||
if (linkType < CONNECT_TCP || linkType >= CONNECT_TYPE_MAX) {
|
||||
COMM_LOGE(COMM_DFX, "linkType:%d is unexpected.", linkType);
|
||||
return;
|
||||
linkType = SOFTBUS_ZERO;
|
||||
}
|
||||
g_connStatsInfo.linkTypeTotal[linkType]++;
|
||||
if (success) {
|
||||
@ -253,11 +253,11 @@ static void OnCompleteConn(int32_t reason, int32_t total)
|
||||
g_isConnQueryEnd = true;
|
||||
}
|
||||
|
||||
static void LnnStatsAuthLinkType(int32_t authLinkType, bool success)
|
||||
static void LnnStatsAuthLinkType(int32_t authLinkTypePara, bool success)
|
||||
{
|
||||
int32_t authLinkType = authLinkTypePara;
|
||||
if (authLinkType < AUTH_LINK_TYPE_WIFI || authLinkType >= AUTH_LINK_TYPE_MAX) {
|
||||
COMM_LOGE(COMM_DFX, "authLinkType:%d is unexpected.", authLinkType);
|
||||
return;
|
||||
authLinkType = SOFTBUS_ZERO;
|
||||
}
|
||||
g_lnnStatsInfo.authLinkTypeTotal[authLinkType]++;
|
||||
if (success) {
|
||||
@ -323,23 +323,11 @@ static void OnCompleteLnn(int32_t reason, int32_t total)
|
||||
g_isLnnQueryEnd = true;
|
||||
}
|
||||
|
||||
static void TransStatsSuccessDetail(int32_t scene, int32_t stage, int32_t stageRes, const char *socketName,
|
||||
int32_t linkType)
|
||||
static void TransStatsSuccessDetail(bool success, const char *socketName, int32_t linkTypePara)
|
||||
{
|
||||
if (stageRes == EVENT_STAGE_RESULT_OK &&
|
||||
(scene != EVENT_SCENE_OPEN_CHANNEL || stage != EVENT_STAGE_OPEN_CHANNEL_END)) {
|
||||
return;
|
||||
}
|
||||
if (stageRes == EVENT_STAGE_RESULT_FAILED && scene != EVENT_SCENE_OPEN_CHANNEL) {
|
||||
return;
|
||||
}
|
||||
if (socketName == NULL || strlen(socketName) == 0) {
|
||||
COMM_LOGE(COMM_DFX, "socketName is NULL or length is 0");
|
||||
return;
|
||||
}
|
||||
int linkType = linkTypePara;
|
||||
if (linkType < CONNECT_TCP || linkType >= CONNECT_TYPE_MAX) {
|
||||
COMM_LOGE(COMM_DFX, "linkType:%d is unexpected.", linkType);
|
||||
return;
|
||||
linkType = SOFTBUS_ZERO;
|
||||
}
|
||||
|
||||
char keyStr[SESSION_NAME_SIZE_MAX + 3] = {0};
|
||||
@ -358,27 +346,28 @@ static void TransStatsSuccessDetail(int32_t scene, int32_t stage, int32_t stageR
|
||||
TransStatsSuccessRateDetail newResult;
|
||||
newResult.successTotal = 0;
|
||||
newResult.total = 1;
|
||||
if (stageRes == EVENT_STAGE_RESULT_OK) {
|
||||
if (success) {
|
||||
newResult.successTotal = 1;
|
||||
}
|
||||
if (LnnMapSet(&g_transStatsInfo.sessionNameLinkTypeMap, keyStr, (const void *)&newResult,
|
||||
sizeof(TransStatsSuccessRateDetail)) != SOFTBUS_OK) {
|
||||
COMM_LOGE(COMM_DFX, "insert socketName:%s fail", socketName);
|
||||
COMM_LOGE(COMM_DFX, "insert keyStr:%s fail", keyStr);
|
||||
}
|
||||
TransMapUnlock();
|
||||
return;
|
||||
}
|
||||
data->total++;
|
||||
if (stageRes == EVENT_STAGE_RESULT_OK) {
|
||||
if (success) {
|
||||
data->successTotal++;
|
||||
}
|
||||
TransMapUnlock();
|
||||
}
|
||||
|
||||
static void TransStats(int32_t scene, int32_t stage, int32_t stageRes)
|
||||
static void TransStats(int32_t scene, int32_t stage, int32_t stageRes, const char *socketName, int32_t linkType)
|
||||
{
|
||||
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
|
||||
&& stageRes == EVENT_STAGE_RESULT_OK) {
|
||||
TransStatsSuccessDetail(true, socketName, linkType);
|
||||
g_transStatsInfo.openSessionSuccessTotal++;
|
||||
g_transStatsInfo.currentParaSessionNum++;
|
||||
return;
|
||||
@ -386,6 +375,7 @@ static void TransStats(int32_t scene, int32_t stage, int32_t stageRes)
|
||||
|
||||
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
|
||||
&& stageRes == EVENT_STAGE_RESULT_FAILED) {
|
||||
TransStatsSuccessDetail(false, socketName, linkType);
|
||||
g_transStatsInfo.openSessionFailTotal++;
|
||||
return;
|
||||
}
|
||||
@ -427,10 +417,9 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
|
||||
continue;
|
||||
}
|
||||
|
||||
TransStats(scene, stage, stageRes);
|
||||
char* socketName = GetStringValueByRecord(&srcRecord[i], SOCKET_KEY_NAME);
|
||||
int32_t linkType = GetInt32ValueByRecord(&srcRecord[i], LINK_TYPE_NAME);
|
||||
TransStatsSuccessDetail(scene, stage, stageRes, socketName, linkType);
|
||||
TransStats(scene, stage, stageRes, socketName, linkType);
|
||||
cJSON_free(socketName);
|
||||
if (scene == EVENT_SCENE_CLOSE_CHANNEL_ACTIVE && stage == EVENT_STAGE_CLOSE_CHANNEL &&
|
||||
stageRes == EVENT_STAGE_RESULT_OK && g_transStatsInfo.currentParaSessionNum > 0) {
|
||||
@ -441,7 +430,7 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
|
||||
maxParaSessionNum : g_transStatsInfo.currentParaSessionNum;
|
||||
|
||||
int32_t timeConsuming = GetInt32ValueByRecord(&srcRecord[i], TIME_CONSUMING_NAME);
|
||||
if (timeConsuming != SOFTBUS_ERR) {
|
||||
if (timeConsuming != SOFTBUS_ERR && stageRes == EVENT_STAGE_RESULT_OK) {
|
||||
g_transStatsInfo.delayTimeTotal += timeConsuming;
|
||||
g_transStatsInfo.delayNum++;
|
||||
}
|
||||
@ -593,7 +582,7 @@ void FillConnSuccessRateDetail(cJSON *connObj)
|
||||
COMM_LOGE(COMM_DFX, "%s json is add to root fail", MODULE_NAME_CONN);
|
||||
return;
|
||||
}
|
||||
for (int i = CONNECT_TCP; i < CONNECT_TYPE_MAX; i++) {
|
||||
for (int i = SOFTBUS_ZERO; i < CONNECT_TYPE_MAX; i++) {
|
||||
float rate = 0;
|
||||
if (g_connStatsInfo.linkTypeTotal[i] > 0) {
|
||||
rate = 1.0 * g_connStatsInfo.linkTypeSuccessTotal[i] / g_connStatsInfo.linkTypeTotal[i] * RATE_HUNDRED;
|
||||
@ -615,7 +604,7 @@ void FillAuthSuccessRateDetail(cJSON *authObj)
|
||||
COMM_LOGE(COMM_DFX, "%s json is add to root fail", MODULE_NAME_AUTH);
|
||||
return;
|
||||
}
|
||||
for (int i = AUTH_LINK_TYPE_WIFI; i < AUTH_LINK_TYPE_MAX; i++) {
|
||||
for (int i = SOFTBUS_ZERO; i < AUTH_LINK_TYPE_MAX; i++) {
|
||||
float rate = 0;
|
||||
if (g_lnnStatsInfo.authLinkTypeTotal[i] > 0) {
|
||||
rate =
|
||||
@ -677,11 +666,11 @@ static void SoftBusProcessStatsQueryData(SoftBusStatsResult* result)
|
||||
result->laneScoreOverTimes = g_transStatsInfo.laneScoreOverTimes;
|
||||
result->detectionTimes = g_transStatsInfo.detectionTimes;
|
||||
|
||||
if (memset_s(&g_connStatsInfo, sizeof(g_connStatsInfo), 0, sizeof(g_connStatsInfo)) != SOFTBUS_OK) {
|
||||
if (memset_s(&g_connStatsInfo, sizeof(g_connStatsInfo), 0, sizeof(g_connStatsInfo)) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset g_connStatsInfo fail!");
|
||||
return;
|
||||
}
|
||||
if (memset_s(&g_lnnStatsInfo, sizeof(g_lnnStatsInfo), 0, sizeof(g_lnnStatsInfo)) != SOFTBUS_OK) {
|
||||
if (memset_s(&g_lnnStatsInfo, sizeof(g_lnnStatsInfo), 0, sizeof(g_lnnStatsInfo)) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset g_lnnStatsInfo fail!");
|
||||
return;
|
||||
}
|
||||
@ -690,7 +679,7 @@ static void SoftBusProcessStatsQueryData(SoftBusStatsResult* result)
|
||||
}
|
||||
LnnMapDelete(&g_transStatsInfo.sessionNameLinkTypeMap);
|
||||
TransMapUnlock();
|
||||
if (memset_s(&g_transStatsInfo, sizeof(g_transStatsInfo), 0, sizeof(g_transStatsInfo)) != SOFTBUS_OK) {
|
||||
if (memset_s(&g_transStatsInfo, sizeof(g_transStatsInfo), 0, sizeof(g_transStatsInfo)) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset g_transStatsInfo fail!");
|
||||
return;
|
||||
}
|
||||
@ -766,8 +755,9 @@ int32_t SoftBusQueryAlarmInfo(int time, int type, SoftBusAlarmEvtResult* result)
|
||||
}
|
||||
g_alarmEvtResult.recordSize = 0;
|
||||
if (memset_s(g_alarmEvtResult.records, sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT, 0,
|
||||
sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT) != SOFTBUS_OK) {
|
||||
sizeof(AlarmRecord) * MAX_NUM_OF_EVENT_RESULT) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "memset g_alarmEvtResult records fail!");
|
||||
(void)SoftBusMutexUnlock(&g_alarmQueryLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SoftBusEventQueryInfo(time, &g_queryAlarmParam[type]);
|
||||
@ -824,10 +814,10 @@ static int32_t InitDumperUtilMutexLock(void)
|
||||
static void UpdateSysEventQueryParam(HiSysEventQueryParam* param, char* eventName)
|
||||
{
|
||||
HiSysEventQueryRule* queryRule = ¶m->queryRules[SOFTBUS_ZERO];
|
||||
if (strcpy_s(queryRule->domain, MAX_LENGTH_OF_EVENT_DOMAIN, SOFTBUS_EVENT_DOMAIN) != SOFTBUS_OK) {
|
||||
if (strcpy_s(queryRule->domain, MAX_LENGTH_OF_EVENT_DOMAIN, SOFTBUS_EVENT_DOMAIN) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "UpdateSysEventQueryParam copy domain fail");
|
||||
}
|
||||
if (strcpy_s(queryRule->eventList[SOFTBUS_ZERO], MAX_LENGTH_OF_EVENT_NAME, eventName) != SOFTBUS_OK) {
|
||||
if (strcpy_s(queryRule->eventList[SOFTBUS_ZERO], MAX_LENGTH_OF_EVENT_NAME, eventName) != EOK) {
|
||||
COMM_LOGE(COMM_DFX, "UpdateSysEventQueryParam copy domain fail");
|
||||
}
|
||||
queryRule->eventListSize = SOFTBUS_ONE;
|
||||
@ -835,7 +825,7 @@ static void UpdateSysEventQueryParam(HiSysEventQueryParam* param, char* eventNam
|
||||
param->eventSize = SOFTBUS_ONE;
|
||||
}
|
||||
|
||||
static void InitSoftBusQueryEventParam()
|
||||
static void InitSoftBusQueryEventParam(void)
|
||||
{
|
||||
HiSysEventQueryParam* connParam = &g_queryStatsParam[SOFTBUS_CONNECTION_STATS_TYPE];
|
||||
UpdateSysEventQueryParam(connParam, CONN_EVENT_NAME);
|
||||
@ -962,7 +952,7 @@ static int32_t CreateAndQueryMsgDelay(SoftBusLooper* looper, HandleMessageFunc c
|
||||
static void QueryStatisticInfoPeriod(SoftBusMessage* msg)
|
||||
{
|
||||
QueryStatisticInfo(msg);
|
||||
CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_DEFAULT), QueryStatisticInfoPeriod, DAY_TIME);
|
||||
CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_HANDLE_FILE), QueryStatisticInfoPeriod, DAY_TIME);
|
||||
}
|
||||
|
||||
int32_t SoftBusHidumperUtilInit(void)
|
||||
@ -982,7 +972,7 @@ int32_t SoftBusHidumperUtilInit(void)
|
||||
}
|
||||
InitSoftBusQueryEventParam();
|
||||
g_isDumperInit = true;
|
||||
if (CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_DEFAULT), QueryStatisticInfoPeriod, DAY_TIME) != SOFTBUS_OK) {
|
||||
if (CreateAndQueryMsgDelay(GetLooper(LOOP_TYPE_HANDLE_FILE), QueryStatisticInfoPeriod, DAY_TIME) != SOFTBUS_OK) {
|
||||
COMM_LOGE(COMM_DFX, "CreateAndQueryMsgDelay fail");
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -1001,6 +991,7 @@ void SoftBusHidumperUtilDeInit(void)
|
||||
LnnMapDelete(&g_transStatsInfo.sessionNameLinkTypeMap);
|
||||
TransMapUnlock();
|
||||
SoftBusMutexDestroy(&g_transMapLock);
|
||||
g_isTransMapInit = false;
|
||||
SoftBusMutexDestroy(&g_statsQueryLock);
|
||||
SoftBusMutexDestroy(&g_alarmQueryLock);
|
||||
SoftBusMutexDestroy(&g_connOnQueryLock);
|
||||
|
@ -58,10 +58,14 @@ static const SoftBusLogLabel DISC_LABELS[MODULE_DOMAIN_MAX_LEN] = {
|
||||
#define DISC_LOGI(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_INFO, DISC_LABELS[label], ##__VA_ARGS__)
|
||||
#define DISC_LOGD(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_DEBUG, DISC_LABELS[label], ##__VA_ARGS__)
|
||||
|
||||
#define DISC_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGD, label, fmt, ##__VA_ARGS__)
|
||||
#define DISC_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGW, label, fmt, ##__VA_ARGS__)
|
||||
#define DISC_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGE, label, fmt, ##__VA_ARGS__)
|
||||
#define DISC_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_LOG_INNER(cond, DISC_LOGD, label, fmt, ##__VA_ARGS__)
|
||||
#define DISC_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_LOG_INNER(cond, DISC_LOGW, label, fmt, ##__VA_ARGS__)
|
||||
#define DISC_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
|
||||
|
@ -63,6 +63,8 @@ static const SoftBusLogLabel TRANS_LABELS[MODULE_DOMAIN_MAX_LEN] = {
|
||||
CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGW, label, fmt, ##__VA_ARGS__)
|
||||
#define TRANS_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGE, label, fmt, ##__VA_ARGS__)
|
||||
#define TRANS_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
|
||||
CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGD, label, fmt, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -71,6 +71,12 @@ if (defined(ohos_lite)) {
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
innerapi_tags = [ "platformsdk_indirect" ]
|
||||
|
||||
install_images = [
|
||||
system_base_dir,
|
||||
updater_base_dir,
|
||||
]
|
||||
|
||||
part_name = "dsoftbus"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ enum LooperType {
|
||||
LOOP_TYPE_BR_SEND,
|
||||
LOOP_TYPE_BR_RECV,
|
||||
LOOP_TYPE_P2P,
|
||||
LOOP_TYPE_LANE
|
||||
LOOP_TYPE_LANE,
|
||||
LOOP_TYPE_HANDLE_FILE
|
||||
};
|
||||
|
||||
SoftBusLooper *GetLooper(int looper);
|
||||
|
@ -468,7 +468,8 @@ static struct LoopConfigItem g_loopConfig[] = {
|
||||
{LOOP_TYPE_BR_SEND, NULL},
|
||||
{LOOP_TYPE_BR_RECV, NULL},
|
||||
{LOOP_TYPE_P2P, NULL},
|
||||
{LOOP_TYPE_LANE, NULL}
|
||||
{LOOP_TYPE_LANE, NULL},
|
||||
{LOOP_TYPE_HANDLE_FILE, NULL}
|
||||
};
|
||||
|
||||
SoftBusLooper *GetLooper(int type)
|
||||
@ -558,10 +559,17 @@ int LooperInit(void)
|
||||
{
|
||||
SoftBusLooper *looper = CreateNewLooper("BusCenter");
|
||||
if (!looper) {
|
||||
COMM_LOGE(COMM_UTILS, "init looper fail.");
|
||||
COMM_LOGE(COMM_UTILS, "init BusCenter looper fail.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SetLooper(LOOP_TYPE_DEFAULT, looper);
|
||||
|
||||
SoftBusLooper *handleFileLooper = CreateNewLooper("HandleFile");
|
||||
if (!handleFileLooper) {
|
||||
COMM_LOGE(COMM_UTILS, "init HandleFile looper fail.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SetLooper(LOOP_TYPE_HANDLE_FILE, handleFileLooper);
|
||||
COMM_LOGI(COMM_UTILS, "init looper success.");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
21
core/common/security/permission/include/access_control.h
Normal file
21
core/common/security/permission/include/access_control.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 ACCESS_CONTROL_H
|
||||
#define ACCESS_CONTROL_H
|
||||
|
||||
int32_t TransCheckAccessControl(const char *peerDeviceId);
|
||||
|
||||
#endif /* ACCESS_CONTROL_H */
|
@ -46,5 +46,18 @@ if (defined(ohos_lite)) {
|
||||
"$dsoftbus_core_path/common/security/permission/$os_type/softbus_permission.cpp",
|
||||
]
|
||||
softbus_permission_deps = [ "//third_party/cJSON:cjson" ]
|
||||
softbus_permission_external_deps += [ "c_utils:utils" ]
|
||||
softbus_permission_external_deps += [
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
]
|
||||
if (!defined(global_parts_info) ||
|
||||
defined(global_parts_info.deviceprofile_device_info_manager)) {
|
||||
softbus_permission_external_deps += [
|
||||
"device_info_manager:distributed_device_profile_common",
|
||||
"device_info_manager:distributed_device_profile_sdk",
|
||||
]
|
||||
softbus_permission_src += [ "$dsoftbus_core_path/common/security/permission/standard/access_control.cpp" ]
|
||||
} else {
|
||||
softbus_permission_src += [ "$dsoftbus_core_path/common/security/permission/standard/access_control_virtual.cpp" ]
|
||||
}
|
||||
}
|
||||
|
79
core/common/security/permission/standard/access_control.cpp
Normal file
79
core/common/security/permission/standard/access_control.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <securec.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "access_control_profile.h"
|
||||
#include "anonymizer.h"
|
||||
#include "bus_center_info_key.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "comm_log.h"
|
||||
#include "distributed_device_profile_client.h"
|
||||
#include "distributed_device_profile_enums.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log_old.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
int32_t TransCheckAccessControl(const char *peerDeviceId)
|
||||
{
|
||||
if (peerDeviceId == nullptr) {
|
||||
COMM_LOGE(COMM_PERM, "peerDeviceId is null");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
uint64_t firstCallingid = GetFirstCallerTokenID();
|
||||
COMM_LOGI(COMM_PERM, "FirstCaller:%" PRIu64 "", firstCallingid);
|
||||
if (firstCallingid == 0) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
char *tmpName = nullptr;
|
||||
Anonymize(peerDeviceId, &tmpName);
|
||||
COMM_LOGI(COMM_PERM, "peerDeviceId:%s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
|
||||
char deviceId[UDID_BUF_LEN] = {0};
|
||||
if (LnnGetRemoteStrInfo(peerDeviceId, STRING_KEY_DEV_UDID, deviceId, sizeof(deviceId)) != SOFTBUS_OK) {
|
||||
COMM_LOGE(COMM_PERM, "LnnGetRemoteStrInfo udid failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
Anonymize(deviceId, &tmpName);
|
||||
COMM_LOGI(COMM_PERM, "deviceId:%s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
|
||||
std::string active = std::to_string(static_cast<int>(Status::ACTIVE));
|
||||
std::vector<AccessControlProfile> profile;
|
||||
std::map<std::string, std::string> parms;
|
||||
std::string firstTokenIdStr = std::to_string(firstCallingid);
|
||||
parms.insert({{"tokenId", firstTokenIdStr}, {"trustDeviceId", deviceId}, {"status", active}});
|
||||
|
||||
int32_t ret = DistributedDeviceProfileClient::GetInstance().GetAccessControlProfile(parms, profile);
|
||||
COMM_LOGI(COMM_PERM, "profile size:%d ret:%d", profile.size(), ret);
|
||||
if (profile.empty()) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
for (auto &item : profile) {
|
||||
COMM_LOGI(COMM_PERM, "GetBindLevel:%d GetBindType:%d", item.GetBindLevel(), item.GetBindType());
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 "stdint.h"
|
||||
#include "access_control.h"
|
||||
#include "softbus_error_code.h"
|
||||
|
||||
int32_t TransCheckAccessControl(const char *peerDeviceId)
|
||||
{
|
||||
(void)peerDeviceId;
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ble_protocol_interface_factory.h"
|
||||
#include "conn_log.h"
|
||||
#include "softbus_common.h"
|
||||
#include "softbus_conn_ble_connection.h"
|
||||
#include "softbus_conn_ble_client.h"
|
||||
@ -38,6 +39,7 @@ static BleUnifyInterface g_bleUnifyInterface[BLE_PROTOCOL_MAX] = {
|
||||
const BleUnifyInterface *ConnBleGetUnifyInterface(BleProtocolType type)
|
||||
{
|
||||
if (type != BLE_GATT) {
|
||||
CONN_LOGE(CONN_BLE, "Failed to return type.");
|
||||
return NULL;
|
||||
}
|
||||
return &g_bleUnifyInterface[type];
|
||||
|
@ -15,7 +15,8 @@
|
||||
|
||||
#include "softbus_conn_ble_client.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include <securec.h>
|
||||
|
||||
#include "conn_log.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_adapter_ble_gatt_client.h"
|
||||
@ -24,8 +25,6 @@
|
||||
#include "softbus_conn_ble_manager.h"
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_type_def.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "legacy_ble_channel.h"
|
||||
#include "conn_event.h"
|
||||
@ -400,6 +399,7 @@ static void BleGattcRegisterNotificationCallback(int32_t underlayerHandle, int32
|
||||
SoftBusFree(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t SwitchNotifacatedHandler(
|
||||
enum ConnBleConnectionState state, const CommonStatusContext *ctx, ConnBleConnection *connection)
|
||||
{
|
||||
@ -422,6 +422,7 @@ static int32_t SwitchNotifacatedHandler(
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void NotificatedMsgHandler(const CommonStatusContext *ctx)
|
||||
{
|
||||
GattServiceType serviceId = GATT_SERVICE_TYPE_UNKOWN;
|
||||
|
@ -20,9 +20,7 @@
|
||||
#include "conn_log.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_conn_ble_client.h"
|
||||
#include "softbus_conn_ble_manager.h"
|
||||
#include "softbus_conn_ble_server.h"
|
||||
#include "softbus_conn_ble_trans.h"
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_datahead_transform.h"
|
||||
@ -98,7 +96,6 @@ ConnBleConnection *ConnBleCreateConnection(
|
||||
return NULL;
|
||||
}
|
||||
connection->sequence = 0;
|
||||
|
||||
connection->buffer.seq = 0;
|
||||
connection->buffer.total = 0;
|
||||
ListInit(&connection->buffer.packets);
|
||||
@ -117,7 +114,6 @@ ConnBleConnection *ConnBleCreateConnection(
|
||||
// ble connection need exchange connection reference even if establish first time, so the init value is 0
|
||||
connection->connectionRc = 0;
|
||||
connection->objectRc = 1;
|
||||
|
||||
connection->retrySearchServiceCnt = 0;
|
||||
|
||||
SoftBusBtUuid serviceUuid = {
|
||||
@ -299,7 +295,7 @@ int32_t ConnBleDisconnectNow(ConnBleConnection *connection, enum ConnBleDisconne
|
||||
const BleUnifyInterface *interface = ConnBleGetUnifyInterface(connection->protocol);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(interface != NULL, SOFTBUS_ERR, CONN_BLE,
|
||||
"ble connection disconnect failed, protocol not support");
|
||||
CONN_LOGW(CONN_BLE, "receive ble disconnect now, connId=%u, side=%d, reason=%d", connection->connectionId,
|
||||
CONN_LOGI(CONN_BLE, "receive ble disconnect now, connId=%u, side=%d, reason=%d", connection->connectionId,
|
||||
connection->side, reason);
|
||||
ConnRemoveMsgFromLooper(
|
||||
&g_bleConnectionAsyncHandler, MSG_CONNECTION_IDLE_DISCONNECT_TIMEOUT, connection->connectionId, 0, NULL);
|
||||
@ -311,7 +307,6 @@ int32_t ConnBleDisconnectNow(ConnBleConnection *connection, enum ConnBleDisconne
|
||||
return interface->bleServerDisconnect(connection);
|
||||
}
|
||||
|
||||
|
||||
static void OnDisconnectedDataFinished(uint32_t connectionId, int32_t error)
|
||||
{
|
||||
if (error != SOFTBUS_OK) {
|
||||
@ -329,6 +324,7 @@ int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, uint16_t challe
|
||||
{
|
||||
int32_t status = SoftBusMutexLock(&connection->lock);
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "Lock faild, err=%d", status);
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
int32_t underlayerHandle = connection->underlayerHandle;
|
||||
@ -441,7 +437,7 @@ int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *js
|
||||
uint32_t dataLen = 0;
|
||||
int64_t seq = ConnBlePackCtlMessage(ctx, &data, &dataLen);
|
||||
if (seq < 0) {
|
||||
CONN_LOGI(CONN_BLE, "connId=%u, pack reply message faild, err=%d", connection->connectionId, (int32_t)seq);
|
||||
CONN_LOGE(CONN_BLE, "connId=%u, pack reply message faild, err=%d", connection->connectionId, (int32_t)seq);
|
||||
return (int32_t)seq;
|
||||
}
|
||||
status = ConnBlePostBytesInner(connection->connectionId, data, dataLen, 0, flag, MODULE_CONNECTION, seq, NULL);
|
||||
@ -812,9 +808,8 @@ void BleOnServerStarted(BleProtocolType protocol, int32_t status)
|
||||
"on server start event handle failed, try to lock failed");
|
||||
g_serverCoordination.status[protocol] = status;
|
||||
g_serverCoordination.actual =
|
||||
(g_serverCoordination.status[BLE_GATT] == SOFTBUS_OK && g_serverCoordination.status[BLE_COC] == SOFTBUS_OK ?
|
||||
BLE_SERVER_STATE_STARTED :
|
||||
BLE_SERVER_STATE_STOPPED);
|
||||
((g_serverCoordination.status[BLE_GATT] == SOFTBUS_OK) && (g_serverCoordination.status[BLE_COC] == SOFTBUS_OK ?
|
||||
BLE_SERVER_STATE_STARTED : BLE_SERVER_STATE_STOPPED));
|
||||
if (g_serverCoordination.expect != g_serverCoordination.actual) {
|
||||
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
|
||||
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
|
||||
@ -831,8 +826,7 @@ void BleOnServerClosed(BleProtocolType protocol, int32_t status)
|
||||
g_serverCoordination.status[protocol] = status;
|
||||
g_serverCoordination.actual =
|
||||
(g_serverCoordination.status[BLE_GATT] == SOFTBUS_OK && g_serverCoordination.status[BLE_COC] == SOFTBUS_OK ?
|
||||
BLE_SERVER_STATE_STOPPED :
|
||||
BLE_SERVER_STATE_STARTED);
|
||||
BLE_SERVER_STATE_STOPPED : BLE_SERVER_STATE_STARTED);
|
||||
if (g_serverCoordination.expect != g_serverCoordination.actual) {
|
||||
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
|
||||
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
|
||||
|
@ -220,6 +220,7 @@ static int32_t NewRequest(ConnBleRequest **outRequest, const ConnBleConnectReque
|
||||
{
|
||||
ConnBleRequest *request = (ConnBleRequest *)SoftBusCalloc(sizeof(ConnBleRequest));
|
||||
if (request == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "request calloc faild");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
ListInit(&request->node);
|
||||
@ -236,6 +237,7 @@ static int32_t NewDevice(ConnBleDevice **outDevice, const ConnBleConnectRequestC
|
||||
{
|
||||
ConnBleDevice *device = (ConnBleDevice *)SoftBusCalloc(sizeof(ConnBleDevice));
|
||||
if (device == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "device calloc faild");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
ListInit(&device->node);
|
||||
@ -275,6 +277,7 @@ static int32_t ConvertCtxToDevice(ConnBleDevice **outDevice, const ConnBleConnec
|
||||
ConnBleRequest *request = NULL;
|
||||
int32_t status = NewRequest(&request, ctx);
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "newrequest is failed, err=%d", status);
|
||||
return status;
|
||||
}
|
||||
ConnBleDevice *device = NULL;
|
||||
|
@ -14,8 +14,6 @@
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_list.h"
|
||||
#include "securec.h"
|
||||
@ -25,9 +23,7 @@
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_conn_manager.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_queue.h"
|
||||
#include "softbus_type_def.h"
|
||||
|
||||
static LIST_HEAD(g_bleQueueList);
|
||||
static SoftBusMutex g_bleQueueLock;
|
||||
@ -87,6 +83,7 @@ int32_t ConnBleEnqueueNonBlock(const void *msg)
|
||||
SendQueueNode *queueNode = (SendQueueNode *)msg;
|
||||
int32_t priority = GetPriority(queueNode->flag);
|
||||
if (SoftBusMutexLock(&g_bleQueueLock) != EOK) {
|
||||
CONN_LOGE(CONN_BLE, "Lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
bool isListEmpty = true;
|
||||
@ -139,6 +136,7 @@ int32_t ConnBleDequeueBlock(void **msg)
|
||||
ConnectionQueue *item = NULL;
|
||||
ConnectionQueue *next = NULL;
|
||||
if (msg == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "msg is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_bleQueueLock) != EOK) {
|
||||
@ -182,9 +180,11 @@ int32_t ConnBleDequeueBlock(void **msg)
|
||||
int32_t ConnBleInitSendQueue(void)
|
||||
{
|
||||
if (SoftBusMutexInit(&g_bleQueueLock, NULL) != 0) {
|
||||
CONN_LOGE(CONN_INIT, "Mutex Init failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SoftBusCondInit(&g_sendWaitCond) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_INIT, "cond Init failed");
|
||||
(void)SoftBusMutexDestroy(&g_bleQueueLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include "softbus_conn_ble_manager.h"
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_type_def.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "legacy_ble_channel.h"
|
||||
|
||||
@ -1488,7 +1486,7 @@ int32_t ConnGattInitServerModule(SoftBusLooper *looper,
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(looper != NULL, SOFTBUS_INVALID_PARAM, CONN_INIT,
|
||||
"init ble server failed, invalid param, looper is null");
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(listener != NULL, SOFTBUS_INVALID_PARAM, CONN_INIT,
|
||||
"init ble server failed, invalid param, listener is null");
|
||||
"init ble server failed, invalid param, listener onServerStarted is null");
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(listener->onServerStarted != NULL, SOFTBUS_INVALID_PARAM, CONN_INIT,
|
||||
"init ble server failed, invalid param, listener is null");
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(listener->onServerClosed != NULL, SOFTBUS_INVALID_PARAM, CONN_INIT,
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_datahead_transform.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
static const int32_t MTU_HEADER_SIZE = 3;
|
||||
static const size_t BLE_TRANS_HEADER_SIZE = sizeof(BleTransHeader);
|
||||
|
@ -19,10 +19,8 @@
|
||||
|
||||
#include "bus_center_decision_center.h"
|
||||
#include "conn_log.h"
|
||||
#include "lnn_distributed_net_ledger.h"
|
||||
#include "lnn_node_info.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_adapter_crypto.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_timer.h"
|
||||
#include "softbus_conn_ble_manager.h"
|
||||
|
@ -14,21 +14,15 @@
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "softbus_conn_br_pending_packet.h"
|
||||
|
||||
#include "common_list.h"
|
||||
#include "conn_log.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_conn_br_connection.h"
|
||||
#include "softbus_conn_br_trans.h"
|
||||
#include "softbus_conn_manager.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_type_def.h"
|
||||
|
||||
typedef struct {
|
||||
ListNode node;
|
||||
@ -117,6 +111,7 @@ int32_t ConnBrGetBrPendingPacket(uint32_t id, int64_t seq, uint32_t waitMillis,
|
||||
{
|
||||
#define USECTONSEC 1000LL
|
||||
if (data == NULL || SoftBusMutexLock(&g_pendingLock) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BR, "Lock failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
PendingPacket *pending = NULL;
|
||||
|
@ -15,19 +15,14 @@
|
||||
#include "softbus_conn_br_send_queue.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_list.h"
|
||||
#include "conn_log.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_conn_manager.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_queue.h"
|
||||
#include "softbus_type_def.h"
|
||||
|
||||
static LIST_HEAD(g_brQueueList);
|
||||
static SoftBusMutex g_brQueueLock;
|
||||
|
@ -21,11 +21,9 @@
|
||||
#include "softbus_conn_br_pending_packet.h"
|
||||
#include "softbus_conn_br_send_queue.h"
|
||||
#include "softbus_conn_common.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
#include "softbus_conn_manager.h"
|
||||
#include "softbus_datahead_transform.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "conn_event.h"
|
||||
|
||||
|
@ -83,13 +83,14 @@ static int32_t ShutdownBaseListener(SoftbusListenerNode *node);
|
||||
static int32_t StartSelectThread(void);
|
||||
static int32_t StopSelectThread(void);
|
||||
static void WakeupSelectThread(void);
|
||||
static SoftbusListenerNode *CreateSpecifiedListenerModule(ListenerModule module);
|
||||
|
||||
static SoftBusMutex g_listenerListLock = { 0 };
|
||||
static SoftbusListenerNode *g_listenerList[UNUSE_BUTT] = { 0 };
|
||||
static SoftBusMutex g_selectThreadStateLock = { 0 };
|
||||
static SelectThreadState *g_selectThreadState = NULL;
|
||||
|
||||
static SoftbusListenerNode *GetListenerNode(ListenerModule module)
|
||||
static SoftbusListenerNode *GetListenerNodeCommon(ListenerModule module, bool create)
|
||||
{
|
||||
int32_t status = SoftBusMutexLock(&g_listenerListLock);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGE(status == SOFTBUS_OK, NULL, CONN_COMMON,
|
||||
@ -98,7 +99,13 @@ static SoftbusListenerNode *GetListenerNode(ListenerModule module)
|
||||
SoftbusListenerNode *node = g_listenerList[module];
|
||||
do {
|
||||
if (node == NULL) {
|
||||
break;
|
||||
if (create) {
|
||||
node = CreateSpecifiedListenerModule(module);
|
||||
}
|
||||
if (node == NULL) {
|
||||
break;
|
||||
}
|
||||
g_listenerList[module] = node;
|
||||
}
|
||||
status = SoftBusMutexLock(&node->lock);
|
||||
if (status != SOFTBUS_OK) {
|
||||
@ -114,6 +121,16 @@ static SoftbusListenerNode *GetListenerNode(ListenerModule module)
|
||||
return node;
|
||||
}
|
||||
|
||||
static SoftbusListenerNode *GetListenerNode(ListenerModule module)
|
||||
{
|
||||
return GetListenerNodeCommon(module, false);
|
||||
}
|
||||
|
||||
static SoftbusListenerNode *GetOrCreateListenerNode(ListenerModule module)
|
||||
{
|
||||
return GetListenerNodeCommon(module, true);
|
||||
}
|
||||
|
||||
static void RemoveListenerNode(SoftbusListenerNode *node)
|
||||
{
|
||||
int32_t status = SoftBusMutexLock(&g_listenerListLock);
|
||||
@ -196,31 +213,6 @@ static SoftbusListenerNode *CreateSpecifiedListenerModule(ListenerModule module)
|
||||
return node;
|
||||
}
|
||||
|
||||
static int32_t CreateStaticModulesUnsafe(void)
|
||||
{
|
||||
ListenerModule module = 0;
|
||||
for (; module < LISTENER_MODULE_DYNAMIC_START; module++) {
|
||||
SoftbusListenerNode *node = CreateSpecifiedListenerModule(module);
|
||||
if (node == NULL) {
|
||||
CONN_LOGW(CONN_COMMON, "create static module failed: create module listener node failed, module=%d",
|
||||
module);
|
||||
goto CLEANUP;
|
||||
}
|
||||
CONN_LOGI(CONN_COMMON, "create static module, create module listener node success, module=%d", module);
|
||||
g_listenerList[module] = node;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
CLEANUP:
|
||||
for (ListenerModule i = module - 1; i >= 0; i--) {
|
||||
SoftbusListenerNode *node = g_listenerList[i];
|
||||
g_listenerList[i] = NULL;
|
||||
// cleanup
|
||||
ReturnListenerNode(&node);
|
||||
CONN_LOGI(CONN_COMMON, "create static module failed: clean up listener node done, module=%d", module);
|
||||
}
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
int32_t InitBaseListener(void)
|
||||
{
|
||||
// stop select thread need re-enter lock
|
||||
@ -254,7 +246,6 @@ int32_t InitBaseListener(void)
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
(void)memset_s(g_listenerList, sizeof(g_listenerList), 0, sizeof(g_listenerList));
|
||||
status = CreateStaticModulesUnsafe();
|
||||
(void)SoftBusMutexUnlock(&g_listenerListLock);
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_INIT, "init base listener failed: create static module listener failed, error=%d",
|
||||
@ -334,7 +325,7 @@ int32_t StartBaseClient(ListenerModule module, const SoftbusBaseListener *listen
|
||||
|
||||
CONN_LOGI(CONN_COMMON, "receive start base client listener request, module=%d", module);
|
||||
|
||||
SoftbusListenerNode *node = GetListenerNode(module);
|
||||
SoftbusListenerNode *node = GetOrCreateListenerNode(module);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(node != NULL, SOFTBUS_NOT_FIND, CONN_COMMON,
|
||||
"start base client listener failed: get listener node failed, dynamic module forgot register "
|
||||
"first? or static module start before base listener init? module=%d",
|
||||
@ -453,7 +444,7 @@ int32_t StartBaseListener(const LocalListenerInfo *info, const SoftbusBaseListen
|
||||
|
||||
ListenerModule module = info->socketOption.moduleId;
|
||||
CONN_LOGI(CONN_COMMON, "receive start base listener request, module=%d", module);
|
||||
SoftbusListenerNode *node = GetListenerNode(module);
|
||||
SoftbusListenerNode *node = GetOrCreateListenerNode(module);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(node != NULL, SOFTBUS_NOT_FIND, CONN_COMMON,
|
||||
"start base listener failed: get listener node failed, dynamic module should register first, module=%d",
|
||||
module);
|
||||
|
@ -416,7 +416,7 @@ void ConnManagerConnected(uint32_t connectionId, const ConnectionInfo *info)
|
||||
|
||||
int32_t num = GetAllListener(&node);
|
||||
if (num == 0 || node == NULL) {
|
||||
CONN_LOGE(CONN_COMMON, "get node failed connId=%u", connectionId);
|
||||
CONN_LOGE(CONN_COMMON, "get node failed, connId=%u", connectionId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ void ConnManagerReusedConnected(uint32_t connectionId, const ConnectionInfo *inf
|
||||
|
||||
int32_t num = GetAllListener(&node);
|
||||
if (num == 0 || node == NULL) {
|
||||
CONN_LOGE(CONN_COMMON, "get node failed connId=%u", connectionId);
|
||||
CONN_LOGE(CONN_COMMON, "get node failed, connId=%u", connectionId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -458,7 +458,7 @@ void ConnManagerDisconnected(uint32_t connectionId, const ConnectionInfo *info)
|
||||
|
||||
int32_t num = GetAllListener(&node);
|
||||
if (num == 0 || node == NULL) {
|
||||
CONN_LOGE(CONN_COMMON, "get node failed connId=%u", connectionId);
|
||||
CONN_LOGE(CONN_COMMON, "get node failed, connId=%u", connectionId);
|
||||
return;
|
||||
}
|
||||
for (int32_t i = 0; i < num; i++) {
|
||||
@ -472,7 +472,7 @@ void ConnManagerDisconnected(uint32_t connectionId, const ConnectionInfo *info)
|
||||
int32_t ConnSetConnectCallback(ConnModule moduleId, const ConnectCallback *callback)
|
||||
{
|
||||
if (ModuleCheck(moduleId) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_COMMON, "module check failed moduleId=%d", moduleId);
|
||||
CONN_LOGE(CONN_COMMON, "module check failed, moduleId=%d", moduleId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "wifi_direct_processor_factory.h"
|
||||
#include "processor/p2p_v1_processor.h"
|
||||
#include "wifi_direct_negotiator.h"
|
||||
|
||||
static struct WifiDirectProcessor* CreateProcessor(enum WifiDirectProcessorType type)
|
||||
{
|
||||
|
@ -90,6 +90,7 @@ static bool ReadData(struct WifiDirectProtocol *base, struct InfoContainerKeyPro
|
||||
return false;
|
||||
}
|
||||
if (self->size - self->readPos < self->format.tagSize + self->format.lengthSize) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "size sub readPos invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
static struct WifiDirectTlvProtocol* NewWifiDirectTlvProtocol(void)
|
||||
{
|
||||
struct WifiDirectTlvProtocol *self = (struct WifiDirectTlvProtocol*)SoftBusCalloc(sizeof(*self));
|
||||
if (self) {
|
||||
if (self != NULL) {
|
||||
if (!WifiDirectTlvProtocolConstructor(self)) {
|
||||
SoftBusFree(self);
|
||||
self = NULL;
|
||||
@ -33,7 +33,7 @@ static struct WifiDirectTlvProtocol* NewWifiDirectTlvProtocol(void)
|
||||
static struct WifiDirectJsonProtocol* NewWifiDirectJsonProtocol(void)
|
||||
{
|
||||
struct WifiDirectJsonProtocol *self = (struct WifiDirectJsonProtocol*)SoftBusCalloc(sizeof(*self));
|
||||
if (self) {
|
||||
if (self != NULL) {
|
||||
if (!WifiDirectJsonProtocolConstructor(self)) {
|
||||
SoftBusFree(self);
|
||||
self = NULL;
|
||||
|
@ -180,6 +180,10 @@ static int32_t GetInterfaceIpString(const char *interface, char *ipString, int32
|
||||
|
||||
int32_t IpAddrToString(uint32_t addr, char *addrString, size_t addrStringSize)
|
||||
{
|
||||
if (addrString == NULL) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
addr = ntohl(addr);
|
||||
const char *ret = inet_ntop(AF_INET, &addr, addrString, addrStringSize);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(ret, SOFTBUS_ERR, CONN_WIFI_DIRECT, "inet_ntop failed");
|
||||
|
@ -75,25 +75,25 @@ static void Calculate(void)
|
||||
|
||||
uint64_t start = self->timePoints[TP_P2P_CONNECT_START];
|
||||
uint64_t end = self->timePoints[TP_P2P_CONNECT_END];
|
||||
if (end && start) {
|
||||
if (end != 0 && start != 0) {
|
||||
self->timeCosts[TC_TOTAL] = end - start;
|
||||
}
|
||||
|
||||
start = self->timePoints[TP_P2P_CREATE_GROUP_START];
|
||||
end = self->timePoints[TP_P2P_CREATE_GROUP_END];
|
||||
if (end && start) {
|
||||
if (end != 0 && start != 0) {
|
||||
self->timeCosts[TC_CREATE_GROUP] = end - start;
|
||||
}
|
||||
|
||||
start = self->timePoints[TP_P2P_CONNECT_GROUP_START];
|
||||
end = self->timePoints[TP_P2P_CONNECT_GROUP_END];
|
||||
if (end && start) {
|
||||
if (end != 0 && start != 0) {
|
||||
self->timeCosts[TC_CONNECT_GROUP] = end - start;
|
||||
}
|
||||
|
||||
start = self->timePoints[TP_P2P_GET_WIFI_CONFIG_START];
|
||||
end = self->timePoints[TP_P2P_GET_WIFI_CONFIG_END];
|
||||
if (end && start) {
|
||||
if (end != 0 && start != 0) {
|
||||
self->timeCosts[TC_GET_WIFI_CONFIG] = end - start;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "wifi_direct_work_queue.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include "conn_log.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_error_code.h"
|
||||
@ -28,12 +28,13 @@ struct WifiDirectWork {
|
||||
static void DeleteMessage(SoftBusMessage *msg)
|
||||
{
|
||||
SoftBusFree(msg->obj);
|
||||
SoftBusFree(msg);
|
||||
}
|
||||
|
||||
static SoftBusMessage* NewMessage(struct WifiDirectWork *work)
|
||||
{
|
||||
SoftBusMessage *msg = SoftBusCalloc(sizeof(*msg));
|
||||
if (!msg) {
|
||||
if (msg == NULL) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@ -47,7 +48,7 @@ static void ScheduleWork(struct WifiDirectWork *work)
|
||||
{
|
||||
struct WifiDirectWorkQueue *self = GetWifiDirectWorkQueue();
|
||||
SoftBusMessage *msg = NewMessage(work);
|
||||
if (msg) {
|
||||
if (msg != NULL) {
|
||||
SoftBusLooper *looper = self->handler.looper;
|
||||
looper->PostMessage(looper, msg);
|
||||
}
|
||||
@ -57,7 +58,7 @@ static void ScheduleDelayWork(struct WifiDirectWork *work, int64_t timeMs)
|
||||
{
|
||||
struct WifiDirectWorkQueue *self = GetWifiDirectWorkQueue();
|
||||
SoftBusMessage *msg = NewMessage(work);
|
||||
if (msg) {
|
||||
if (msg != NULL) {
|
||||
SoftBusLooper *looper = self->handler.looper;
|
||||
looper->PostMessageDelay(looper, msg, timeMs);
|
||||
}
|
||||
@ -96,7 +97,7 @@ static struct WifiDirectWorkQueue g_queue = {
|
||||
struct WifiDirectWork* ObtainWifiDirectWork(WorkFunction function, void *data)
|
||||
{
|
||||
struct WifiDirectWork *work = SoftBusCalloc(sizeof(*work));
|
||||
if (!work) {
|
||||
if (work == NULL) {
|
||||
return work;
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ int32_t WifiDirectWorkQueueInit(void)
|
||||
{
|
||||
CONN_LOGI(CONN_INIT, "init enter");
|
||||
SoftBusLooper *looper = CreateNewLooper("WDWQLooper");
|
||||
if (!looper) {
|
||||
if (looper == NULL) {
|
||||
CONN_LOGE(CONN_INIT, "create looper failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ static int32_t HandleMessageFromProcessor(struct NegotiateMessage *msg)
|
||||
struct WifiDirectNegotiator *self = GetWifiDirectNegotiator();
|
||||
|
||||
int32_t ret = SOFTBUS_OK;
|
||||
if (msg) {
|
||||
if (msg != NULL) {
|
||||
msg->dump(msg, 0);
|
||||
struct WifiDirectNegotiateChannel *channel = msg->getPointer(msg, NM_KEY_NEGO_CHANNEL, NULL);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(channel != NULL, SOFTBUS_ERR, CONN_WIFI_DIRECT, "channel is null");
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "disc_log.h"
|
||||
#include "disc_manager.h"
|
||||
#include "disc_share_ble.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#define DISPATCHER_SIZE 3
|
||||
|
@ -13,13 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "disc_ble.h"
|
||||
#include "disc_ble_dispatcher.h"
|
||||
#include "disc_manager.h"
|
||||
#include "disc_share_ble.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "stddef.h"
|
||||
|
||||
static int32_t Publish(const PublishOption *option)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define INT32_MAX_BIT_NUM 32
|
||||
#define MAX_CAP_NUM (CAPABILITY_NUM * INT32_MAX_BIT_NUM)
|
||||
|
||||
#define BLE_SCAN_FILTER_LEN 7
|
||||
#define BLE_SCAN_FILTER_LEN 5
|
||||
#define CUST_DATA_MAX_LEN 14
|
||||
#define SOFTBUS_BLE_CLIENT_ID 0x1
|
||||
|
||||
|
@ -71,7 +71,7 @@ int32_t DiscBleGetDeviceIdHash(unsigned char *devIdHash, uint32_t len);
|
||||
int32_t DiscBleGetShortUserIdHash(unsigned char *hashStr, uint32_t len);
|
||||
|
||||
int32_t AssembleTLV(BroadcastData *broadcastData, unsigned char dataType, const void *data, uint32_t dataLen);
|
||||
int32_t GetDeviceInfoFromDisAdvData(DeviceWrapper *info, const unsigned char *data, uint32_t dataLen);
|
||||
int32_t GetDeviceInfoFromDisAdvData(DeviceWrapper *device, const uint8_t *data, uint32_t dataLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -35,6 +35,8 @@
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_range.h"
|
||||
#include "softbus_bitmap.h"
|
||||
#include "softbus_broadcast_manager.h"
|
||||
#include "softbus_broadcast_utils.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_hidumper_disc.h"
|
||||
@ -76,7 +78,6 @@
|
||||
#define BlE_ADVERTISER "bleAdvertiser"
|
||||
#define RECV_MESSAGE_INFO "recvMessageInfo"
|
||||
|
||||
static int32_t g_bleScannerId = -1;
|
||||
typedef enum {
|
||||
PUBLISH_ACTIVE_SERVICE,
|
||||
PUBLISH_PASSIVE_SERVICE,
|
||||
@ -149,10 +150,10 @@ typedef struct {
|
||||
} BleOption;
|
||||
|
||||
static ScanSetting g_scanTable[FREQ_BUTT] = {
|
||||
{SOFTBUS_BLE_SCAN_WINDOW_P2, SOFTBUS_BLE_SCAN_INTERVAL_P2},
|
||||
{SOFTBUS_BLE_SCAN_WINDOW_P10, SOFTBUS_BLE_SCAN_INTERVAL_P10},
|
||||
{SOFTBUS_BLE_SCAN_WINDOW_P25, SOFTBUS_BLE_SCAN_INTERVAL_P25},
|
||||
{SOFTBUS_BLE_SCAN_WINDOW_P100, SOFTBUS_BLE_SCAN_INTERVAL_P100}
|
||||
{SOFTBUS_BC_SCAN_WINDOW_P2, SOFTBUS_BC_SCAN_INTERVAL_P2},
|
||||
{SOFTBUS_BC_SCAN_WINDOW_P10, SOFTBUS_BC_SCAN_INTERVAL_P10},
|
||||
{SOFTBUS_BC_SCAN_WINDOW_P25, SOFTBUS_BC_SCAN_INTERVAL_P25},
|
||||
{SOFTBUS_BC_SCAN_WINDOW_P100, SOFTBUS_BC_SCAN_INTERVAL_P100}
|
||||
};
|
||||
|
||||
static DiscInnerCallback *g_discBleInnerCb = NULL;
|
||||
@ -160,8 +161,8 @@ static DiscBleInfo g_bleInfoManager[BLE_INFO_COUNT];
|
||||
static SoftBusMutex g_bleInfoLock = {0};
|
||||
static DiscBleAdvertiser g_bleAdvertiser[NUM_ADVERTISER];
|
||||
static bool g_isScanning = false;
|
||||
static SoftBusHandler g_discBleHandler = {0};
|
||||
static RecvMessageInfo g_recvMessageInfo = {0};
|
||||
static SoftBusHandler g_discBleHandler = {};
|
||||
static RecvMessageInfo g_recvMessageInfo = {};
|
||||
static DiscBleListener g_bleListener = {
|
||||
.stateListenerId = -1,
|
||||
.scanListenerId = -1
|
||||
@ -234,7 +235,7 @@ static void DeConvertBitMap(unsigned int *dstCap, unsigned int *srcCap, int nums
|
||||
SoftbusBitmapSet(dstCap, bleCapability);
|
||||
}
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "old= %u, new= %u", *srcCap, *dstCap);
|
||||
DISC_LOGD(DISC_BLE, "old= %u, new= %u", *srcCap, *dstCap);
|
||||
}
|
||||
|
||||
static void UpdateInfoManager(int adv, bool needUpdate)
|
||||
@ -309,30 +310,29 @@ static bool CheckScanner(void)
|
||||
return scanCapBit != 0;
|
||||
}
|
||||
|
||||
static int32_t ScanFilter(const SoftBusBleScanResult *scanResultData)
|
||||
static int32_t ScanFilter(const BroadcastReportInfo *reportInfo)
|
||||
{
|
||||
uint32_t advLen = scanResultData->advLen;
|
||||
uint8_t *advData = scanResultData->advData;
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(scanResultData->dataStatus == SOFTBUS_BLE_DATA_COMPLETE, SOFTBUS_INVALID_PARAM,
|
||||
DISC_BLE, "dataStatus[%u] is invalid", scanResultData->dataStatus);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(advLen >= (POS_TLV + ADV_HEAD_LEN), SOFTBUS_INVALID_PARAM, DISC_BLE,
|
||||
uint32_t advLen = reportInfo->packet.bcData.payloadLen;
|
||||
uint8_t *advData = reportInfo->packet.bcData.payload;
|
||||
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->dataStatus == SOFTBUS_BLE_DATA_COMPLETE, SOFTBUS_ERR, DISC_BLE,
|
||||
"dataStatus[%u] is invalid", reportInfo->dataStatus);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData != NULL, SOFTBUS_ERR, DISC_BLE, "advData is null", advLen);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advLen >= POS_TLV, SOFTBUS_ERR, DISC_BLE,
|
||||
"advLen[%u] is too short, less than adv header length", advLen);
|
||||
|
||||
uint32_t broadcastAdvLen = advData[POS_PACKET_LENGTH];
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(broadcastAdvLen >= (ADV_HEAD_LEN + RSP_HEAD_LEN - 1), SOFTBUS_INVALID_PARAM,
|
||||
DISC_BLE, "broadcastAdvLen[%u] is too short, less than adv header length", broadcastAdvLen);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advLen > (POS_PACKET_LENGTH + broadcastAdvLen + 1), SOFTBUS_INVALID_PARAM,
|
||||
DISC_BLE, "advLen[%u] is too short, less than adv packet length", advLen);
|
||||
uint32_t broadcastRspLen = advData[POS_PACKET_LENGTH + broadcastAdvLen + 1];
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advLen >= (POS_PACKET_LENGTH + broadcastAdvLen + 1 + broadcastRspLen + 1),
|
||||
SOFTBUS_INVALID_PARAM, DISC_BLE, "advLen[%u] is too short, less than adv+rsp packet length", advLen);
|
||||
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData[POS_UUID] == (uint8_t)(BLE_UUID & BYTE_MASK), SOFTBUS_INVALID_PARAM,
|
||||
DISC_BLE, "uuid low byte[%hhu] is invalid", advData[POS_UUID]);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData[POS_UUID + 1] == (uint8_t)((BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK),
|
||||
SOFTBUS_INVALID_PARAM, DISC_BLE, "uuid high byte[%hhu] is invalid", advData[POS_UUID + 1]);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData[POS_VERSION + ADV_HEAD_LEN] == BLE_VERSION, SOFTBUS_INVALID_PARAM,
|
||||
DISC_BLE, "adv version[%hhu] is invalid", advData[POS_VERSION + ADV_HEAD_LEN]);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->packet.bcData.type == BC_DATA_TYPE_SERVICE, SOFTBUS_ERR, DISC_BLE,
|
||||
"type [%u] is invalid", reportInfo->packet.bcData.type);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->packet.bcData.id == BLE_UUID, SOFTBUS_ERR, DISC_BLE,
|
||||
"uuid [%u] is invalid", reportInfo->packet.bcData.id);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData[POS_VERSION] == BLE_VERSION, SOFTBUS_ERR, DISC_BLE,
|
||||
"adv version[%hhu] is invalid", advData[POS_VERSION]);
|
||||
if (reportInfo->packet.rspData.payload != NULL && reportInfo->packet.rspData.payloadLen != 0) {
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->packet.rspData.type == BC_DATA_TYPE_MANUFACTURER, SOFTBUS_ERR, DISC_BLE,
|
||||
"type [%u] is invalid", reportInfo->packet.rspData.type);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->packet.rspData.id == COMPANY_ID, SOFTBUS_ERR, DISC_BLE,
|
||||
"companyId [%u] is invalid", reportInfo->packet.rspData.id);
|
||||
}
|
||||
|
||||
if (!CheckScanner()) {
|
||||
DISC_LOGI(DISC_BLE, "no need to scan");
|
||||
@ -342,13 +342,13 @@ static int32_t ScanFilter(const SoftBusBleScanResult *scanResultData)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void ProcessDisConPacket(const uint8_t *advData, uint32_t advLen, DeviceInfo *foundInfo)
|
||||
static void ProcessDisConPacket(const BroadcastReportInfo *reportInfo, DeviceInfo *foundInfo)
|
||||
{
|
||||
DeviceWrapper device = {
|
||||
.info = foundInfo,
|
||||
.power = SOFTBUS_ILLEGAL_BLE_POWER
|
||||
};
|
||||
if (GetDeviceInfoFromDisAdvData(&device, advData, advLen) != SOFTBUS_OK) {
|
||||
if (GetDeviceInfoFromDisAdvData(&device, (uint8_t *)reportInfo, sizeof(BroadcastReportInfo)) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "GetDeviceInfoFromDisAdvData failed");
|
||||
return;
|
||||
}
|
||||
@ -360,7 +360,8 @@ static void ProcessDisConPacket(const uint8_t *advData, uint32_t advLen, DeviceI
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&g_bleInfoLock);
|
||||
char key[SHA_HASH_LEN];
|
||||
if (SoftBusGenerateStrHash(advData, advLen, (uint8_t *)key) != SOFTBUS_OK) {
|
||||
if (SoftBusGenerateStrHash(reportInfo->packet.bcData.payload, reportInfo->packet.bcData.payloadLen,
|
||||
(uint8_t *)key) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "GenerateStrHash failed");
|
||||
return;
|
||||
}
|
||||
@ -446,14 +447,13 @@ static int32_t RangeDevice(DeviceInfo *device, char rssi, int8_t power)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void ProcessDisNonPacket(const uint8_t *advData, uint32_t advLen, char rssi,
|
||||
DeviceInfo *foundInfo)
|
||||
static void ProcessDisNonPacket(const BroadcastReportInfo *reportInfo, char rssi, DeviceInfo *foundInfo)
|
||||
{
|
||||
DeviceWrapper device = {
|
||||
.info = foundInfo,
|
||||
.power = SOFTBUS_ILLEGAL_BLE_POWER
|
||||
};
|
||||
if (GetDeviceInfoFromDisAdvData(&device, advData, advLen) != SOFTBUS_OK) {
|
||||
if (GetDeviceInfoFromDisAdvData(&device, (uint8_t *)reportInfo, sizeof(BroadcastReportInfo)) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "GetDeviceInfoFromDisAdvData failed");
|
||||
return;
|
||||
}
|
||||
@ -496,43 +496,44 @@ static void ProcessDisNonPacket(const uint8_t *advData, uint32_t advLen, char rs
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessDistributePacket(const SoftBusBleScanResult *scanResultData)
|
||||
static void ProcessDistributePacket(const BroadcastReportInfo *reportInfo)
|
||||
{
|
||||
uint32_t advLen = scanResultData->advLen;
|
||||
uint8_t *advData = scanResultData->advData;
|
||||
uint32_t advLen = reportInfo->packet.bcData.payloadLen;
|
||||
uint8_t *advData = reportInfo->packet.bcData.payload;
|
||||
DeviceInfo foundInfo;
|
||||
|
||||
if (advData == NULL || advLen <= POS_BUSINESS_EXTENSION) {
|
||||
DISC_LOGE(DISC_BLE, "scan report data null,len=[%d]", advLen);
|
||||
return;
|
||||
}
|
||||
(void)memset_s(&foundInfo, sizeof(foundInfo), 0, sizeof(foundInfo));
|
||||
foundInfo.addrNum = 1;
|
||||
foundInfo.addr[0].type = CONNECTION_ADDR_BLE;
|
||||
if (memcpy_s(foundInfo.addr[0].info.ble.bleMac, BT_ADDR_LEN, scanResultData->addr.addr, BT_ADDR_LEN) != EOK) {
|
||||
if (memcpy_s(foundInfo.addr[0].info.ble.bleMac, BT_ADDR_LEN, reportInfo->addr.addr, BC_ADDR_MAC_LEN) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy_s failed");
|
||||
return;
|
||||
}
|
||||
if ((advData[POS_BUSINESS_EXTENSION + ADV_HEAD_LEN] & BIT_HEART_BIT) != 0) {
|
||||
if ((advData[POS_BUSINESS_EXTENSION] & BIT_HEART_BIT) != 0) {
|
||||
return;
|
||||
}
|
||||
if ((advData[POS_BUSINESS_EXTENSION + ADV_HEAD_LEN] & BIT_CON) != 0) {
|
||||
ProcessDisConPacket(advData, advLen, &foundInfo);
|
||||
if ((advData[POS_BUSINESS_EXTENSION] & BIT_CON) != 0) {
|
||||
ProcessDisConPacket(reportInfo, &foundInfo);
|
||||
} else {
|
||||
ProcessDisNonPacket(advData, advLen, scanResultData->rssi, &foundInfo);
|
||||
ProcessDisNonPacket(reportInfo, reportInfo->rssi, &foundInfo);
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool IsDistributedBusiness(const uint8_t *data)
|
||||
{
|
||||
return data[POS_BUSINESS + ADV_HEAD_LEN] == DISTRIBUTE_BUSINESS;
|
||||
}
|
||||
|
||||
static void BleScanResultCallback(int listenerId, const SoftBusBleScanResult *scanResultData)
|
||||
static void BleScanResultCallback(int listenerId, const BroadcastReportInfo *reportInfo)
|
||||
{
|
||||
(void)listenerId;
|
||||
DISC_CHECK_AND_RETURN_LOGW(scanResultData != NULL, DISC_BLE, "scan result is null");
|
||||
DISC_CHECK_AND_RETURN_LOGW(scanResultData->advData != NULL, DISC_BLE, "scan result advData is null");
|
||||
DISC_CHECK_AND_RETURN_LOGE(ScanFilter(scanResultData) == SOFTBUS_OK, DISC_BLE, "scan filter failed");
|
||||
DISC_CHECK_AND_RETURN_LOGW(listenerId == g_bleListener.scanListenerId, DISC_BLE, "listenerId not match");
|
||||
DISC_CHECK_AND_RETURN_LOGW(reportInfo != NULL, DISC_BLE, "scan result is null");
|
||||
DISC_CHECK_AND_RETURN_LOGD(ScanFilter(reportInfo) == SOFTBUS_OK, DISC_BLE, "scan filter failed");
|
||||
|
||||
uint8_t *advData = scanResultData->advData;
|
||||
if (IsDistributedBusiness(advData)) {
|
||||
ProcessDistributePacket(scanResultData);
|
||||
uint8_t *advData = reportInfo->packet.bcData.payload;
|
||||
if ((reportInfo->packet.bcData.id == BLE_UUID) && (advData[POS_BUSINESS] == DISTRIBUTE_BUSINESS)) {
|
||||
SignalingMsgPrint("ble adv rcv", advData, reportInfo->packet.bcData.payloadLen, DISC_BLE);
|
||||
ProcessDistributePacket(reportInfo);
|
||||
} else {
|
||||
DISC_LOGI(DISC_BLE, "ignore other business");
|
||||
}
|
||||
@ -576,19 +577,17 @@ static void BleOnStateChanged(int32_t listenerId, int32_t state)
|
||||
}
|
||||
}
|
||||
|
||||
static SoftBusAdvCallback g_advCallback = {
|
||||
.AdvEnableCallback = BleAdvEnableCallback,
|
||||
.AdvDisableCallback = BleAdvDisableCallback,
|
||||
.AdvDataCallback = BleAdvDataCallback,
|
||||
.AdvUpdateCallback = BleAdvUpdateCallback,
|
||||
.LpDeviceInfoCallback = NULL
|
||||
static BroadcastCallback g_advCallback = {
|
||||
.OnStartBroadcastingCallback = BleAdvEnableCallback,
|
||||
.OnStopBroadcastingCallback = BleAdvDisableCallback,
|
||||
.OnSetBroadcastingCallback = BleAdvDataCallback,
|
||||
.OnUpdateBroadcastingCallback = BleAdvUpdateCallback,
|
||||
};
|
||||
|
||||
static SoftBusScanListener g_scanListener = {
|
||||
.OnScanStart = BleOnScanStart,
|
||||
.OnScanStop = BleOnScanStop,
|
||||
.OnScanResult = BleScanResultCallback,
|
||||
.OnScanStateChanged = NULL
|
||||
static ScanCallback g_scanListener = {
|
||||
.OnStartScanCallback = BleOnScanStart,
|
||||
.OnStopScanCallback = BleOnScanStop,
|
||||
.OnReportScanDataCallback = BleScanResultCallback,
|
||||
};
|
||||
|
||||
static SoftBusBtStateListener g_stateChangedListener = {
|
||||
@ -654,6 +653,7 @@ static int32_t GetNonDeviceInfo(DeviceInfo *info)
|
||||
if (DiscBleGetDeviceIdHash((uint8_t *)info->devId, DISC_MAX_DEVICE_ID_LEN) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "get deviceId failed");
|
||||
}
|
||||
|
||||
if (DiscBleGetDeviceName(info->devName) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "get deviceName failed");
|
||||
}
|
||||
@ -680,61 +680,66 @@ static int32_t GetNonDeviceInfo(DeviceInfo *info)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t BuildBleConfigAdvData(SoftBusBleAdvData *advData, const BroadcastData *broadcastData)
|
||||
static int32_t BuildBleConfigAdvData(BroadcastPacket *packet, const BroadcastData *broadcastData)
|
||||
{
|
||||
if (advData == NULL || broadcastData == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
if (packet->bcData.payload != NULL || packet->rspData.payload != NULL) {
|
||||
SoftBusFree(packet->bcData.payload);
|
||||
SoftBusFree(packet->rspData.payload);
|
||||
packet->bcData.payload = NULL;
|
||||
packet->rspData.payload = NULL;
|
||||
}
|
||||
advData->advData = (uint8_t *)SoftBusCalloc(ADV_DATA_MAX_LEN + ADV_HEAD_LEN);
|
||||
if (advData->advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "malloc failed");
|
||||
packet->bcData.payload = (uint8_t *)SoftBusCalloc(ADV_DATA_MAX_LEN);
|
||||
if (packet->bcData.payload == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "malloc serviceData failed");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
advData->scanRspData = (uint8_t *)SoftBusCalloc(RESP_DATA_MAX_LEN + RSP_HEAD_LEN);
|
||||
if (advData->scanRspData == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "malloc failed");
|
||||
SoftBusFree(advData->advData);
|
||||
advData->advData = NULL;
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
unsigned short advLength = (broadcastData->dataLen > ADV_DATA_MAX_LEN) ? ADV_DATA_MAX_LEN : broadcastData->dataLen;
|
||||
advData->advLength = advLength + ADV_HEAD_LEN;
|
||||
advData->advData[POS_FLAG_BYTE_LEN] = FLAG_BYTE_LEN;
|
||||
advData->advData[POS_FLAG_AD_TYPE] = FLAG_AD_TYPE;
|
||||
advData->advData[POS_FLAG_AD_DATA] = FLAG_AD_DATA;
|
||||
advData->advData[POS_AD_TYPE] = AD_TYPE;
|
||||
advData->advData[POS_UUID] = (char)(BLE_UUID & BYTE_MASK);
|
||||
advData->advData[POS_UUID + 1] = (char)((BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK);
|
||||
advData->advData[POS_PACKET_LENGTH] = advData->advLength - POS_PACKET_LENGTH - 1;
|
||||
DISC_LOGI(DISC_BLE, "advData->advLength=%d advLength=%d", advData->advLength, advLength);
|
||||
if (memcpy_s(&advData->advData[ADV_HEAD_LEN], advLength, broadcastData->data.advData, advLength) != EOK) {
|
||||
|
||||
packet->isSupportFlag = true;
|
||||
packet->flag = FLAG_AD_DATA;
|
||||
packet->bcData.type = BC_DATA_TYPE_SERVICE;
|
||||
packet->bcData.id = BLE_UUID;
|
||||
packet->bcData.payloadLen = (broadcastData->dataLen > ADV_DATA_MAX_LEN) ? ADV_DATA_MAX_LEN : broadcastData->dataLen;
|
||||
if (memcpy_s(&packet->bcData.payload[0], ADV_DATA_MAX_LEN, broadcastData->data.advData,
|
||||
packet->bcData.payloadLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy err");
|
||||
SoftBusFree(packet->bcData.payload);
|
||||
packet->bcData.payload = NULL;
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
advData->scanRspLength = broadcastData->dataLen - advLength + RSP_HEAD_LEN;
|
||||
advData->scanRspData[POS_RSP_TYPE] = RSP_TYPE;
|
||||
advData->scanRspData[POS_COMPANY_ID] = COMPANY_ID & BYTE_MASK;
|
||||
advData->scanRspData[POS_COMPANY_ID + 1] = (COMPANY_ID >> BYTE_SHIFT_BIT) & BYTE_MASK;
|
||||
if (advData->scanRspLength > RSP_HEAD_LEN) {
|
||||
if (memcpy_s(&advData->scanRspData[RSP_HEAD_LEN], RESP_DATA_MAX_LEN,
|
||||
broadcastData->data.rspData, advData->scanRspLength - RSP_HEAD_LEN) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy err");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
|
||||
packet->rspData.payloadLen = broadcastData->dataLen - packet->bcData.payloadLen;
|
||||
if (packet->rspData.payloadLen == 0) {
|
||||
packet->rspData.payload = NULL;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
advData->scanRspData[POS_RSP_LENGTH] = advData->scanRspLength - POS_RSP_LENGTH - 1;
|
||||
DISC_LOGI(DISC_BLE, "advData->scanRspLength=%d POS_RSP_LENGTH=%d",
|
||||
advData->scanRspLength, advData->scanRspData[POS_RSP_LENGTH]);
|
||||
|
||||
packet->rspData.payload = (uint8_t *)SoftBusCalloc(RESP_DATA_MAX_LEN);
|
||||
if (packet->rspData.payload == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "malloc failed");
|
||||
SoftBusFree(packet->bcData.payload);
|
||||
packet->bcData.payload = NULL;
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
packet->rspData.type = BC_DATA_TYPE_MANUFACTURER;
|
||||
packet->rspData.id = COMPANY_ID;
|
||||
if (memcpy_s(&packet->rspData.payload[0], RESP_DATA_MAX_LEN, broadcastData->data.rspData,
|
||||
packet->rspData.payloadLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy err");
|
||||
SoftBusFree(packet->bcData.payload);
|
||||
SoftBusFree(packet->rspData.payload);
|
||||
packet->bcData.payload = NULL;
|
||||
packet->rspData.payload = NULL;
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
|
||||
DISC_LOGI(DISC_BLE, "packet->rspData.payloadLen=%d", packet->rspData.payloadLen);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void DestroyBleConfigAdvData(SoftBusBleAdvData *advData)
|
||||
static void DestroyBleConfigAdvData(BroadcastPacket *packet)
|
||||
{
|
||||
if (advData == NULL) {
|
||||
return;
|
||||
}
|
||||
SoftBusFree(advData->advData);
|
||||
SoftBusFree(advData->scanRspData);
|
||||
SoftBusFree(packet->bcData.payload);
|
||||
SoftBusFree(packet->rspData.payload);
|
||||
}
|
||||
|
||||
static void AssembleNonOptionalTlv(DeviceInfo *info, BroadcastData *broadcastData)
|
||||
@ -807,20 +812,20 @@ static int32_t GetBroadcastData(DeviceInfo *info, int32_t advId, BroadcastData *
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void BuildAdvParam(SoftBusBleAdvParams *advParam)
|
||||
static void BuildAdvParam(BroadcastParam *advParam)
|
||||
{
|
||||
advParam->minInterval = ADV_INTERNAL;
|
||||
advParam->maxInterval = ADV_INTERNAL;
|
||||
advParam->advType = SOFTBUS_BLE_ADV_IND;
|
||||
advParam->ownAddrType = SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS;
|
||||
advParam->peerAddrType = SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS;
|
||||
advParam->advType = SOFTBUS_BC_ADV_IND;
|
||||
advParam->ownAddrType = SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS;
|
||||
advParam->peerAddrType = SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS;
|
||||
advParam->channelMap = BLE_CHANNLE_MAP;
|
||||
advParam->txPower = BLE_ADV_TX_POWER_DEFAULT;
|
||||
}
|
||||
|
||||
static int32_t StartAdvertiser(int32_t adv)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
DiscBleAdvertiser *advertiser = &g_bleAdvertiser[adv];
|
||||
if (advertiser->isAdvertising) {
|
||||
if (GetNeedUpdateAdvertiser(adv)) {
|
||||
@ -842,32 +847,29 @@ static int32_t StartAdvertiser(int32_t adv)
|
||||
DISC_LOGE(DISC_BLE, "get broadcast data failed");
|
||||
return SOFTBUS_DISCOVER_BLE_GET_BROADCAST_DATA_FAIL;
|
||||
}
|
||||
SoftBusBleAdvData advData = {0};
|
||||
if (BuildBleConfigAdvData(&advData, &broadcastData) != SOFTBUS_OK) {
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
BroadcastPacket packet = {};
|
||||
if (BuildBleConfigAdvData(&packet, &broadcastData) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "BuildBleConfigAdvData failed");
|
||||
return SOFTBUS_DISCOVER_BLE_BUILD_CONFIG_ADV_DATA_FAIL;
|
||||
}
|
||||
SoftBusBleAdvParams advParam = {0};
|
||||
BroadcastParam advParam = {};
|
||||
BuildAdvParam(&advParam);
|
||||
if (SoftBusSetAdvData(adv, &advData) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "set ble adv adv=%d data failed", adv);
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
SignalingMsgPrint("ble adv send", (uint8_t *)packet.bcData.payload, (uint8_t)packet.bcData.payloadLen,
|
||||
DISC_BLE);
|
||||
DiscEventExtra discEventExtra = { .broadcastType = BLE };
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
if (SoftBusStartAdv(advertiser->channel, &advParam) != SOFTBUS_OK) {
|
||||
|
||||
if (StartBroadcasting(advertiser->channel, &advParam, &packet) != SOFTBUS_OK) {
|
||||
discEventExtra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
discEventExtra.errcode = SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
DestroyBleConfigAdvData(&packet);
|
||||
DISC_LOGE(DISC_BLE, "start adv adv=%d failed", adv);
|
||||
return SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
|
||||
}
|
||||
UpdateInfoManager(adv, false);
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
DestroyBleConfigAdvData(&packet);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -880,7 +882,7 @@ static int32_t StopAdvertiser(int32_t adv)
|
||||
}
|
||||
DiscEventExtra discEventExtra = { .broadcastType = BLE, .result = EVENT_STAGE_RESULT_OK };
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
if (SoftBusStopAdv(advertiser->channel) != SOFTBUS_OK) {
|
||||
if (StopBroadcasting(advertiser->channel) != SOFTBUS_OK) {
|
||||
discEventExtra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
discEventExtra.errcode = SOFTBUS_DISCOVER_END_BROADCAST_FAIL;
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
@ -902,30 +904,30 @@ static int32_t UpdateAdvertiser(int32_t adv)
|
||||
DISC_LOGE(DISC_BLE, "advertiser adv=%d GetConDeviceInfo failed", adv);
|
||||
return StopAdvertiser(adv);
|
||||
}
|
||||
BroadcastData broadcastData;
|
||||
BroadcastData broadcastData = {};
|
||||
if (GetBroadcastData(&advertiser->deviceInfo, adv, &broadcastData) != SOFTBUS_OK) {
|
||||
return SOFTBUS_DISCOVER_BLE_GET_BROADCAST_DATA_FAIL;
|
||||
}
|
||||
SoftBusBleAdvData advData = {0};
|
||||
if (BuildBleConfigAdvData(&advData, &broadcastData) != SOFTBUS_OK) {
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
|
||||
BroadcastPacket packet = {};
|
||||
if (BuildBleConfigAdvData(&packet, &broadcastData) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "BuildBleConfigAdvData failed");
|
||||
return SOFTBUS_DISCOVER_BLE_BUILD_CONFIG_ADV_DATA_FAIL;
|
||||
}
|
||||
SoftBusBleAdvParams advParam = {0};
|
||||
BroadcastParam advParam = {};
|
||||
BuildAdvParam(&advParam);
|
||||
DiscEventExtra discEventExtra = { .broadcastType = BLE };
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
if (SoftBusUpdateAdv(advertiser->channel, &advData, &advParam) != SOFTBUS_OK) {
|
||||
if (UpdateBroadcasting(advertiser->channel, &advParam, &packet) != SOFTBUS_OK) {
|
||||
discEventExtra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
discEventExtra.errcode = SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
|
||||
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, discEventExtra);
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
DestroyBleConfigAdvData(&packet);
|
||||
DISC_LOGE(DISC_BLE, "UpdateAdv failed");
|
||||
return SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
|
||||
}
|
||||
UpdateInfoManager(adv, false);
|
||||
DestroyBleConfigAdvData(&advData);
|
||||
DestroyBleConfigAdvData(&packet);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -934,13 +936,13 @@ static void InitScanner(void)
|
||||
g_isScanning = false;
|
||||
}
|
||||
|
||||
static int32_t GetScannerParam(int32_t freq, SoftBusBleScanParams *scanParam)
|
||||
static int32_t GetScannerParam(int32_t freq, BcScanParams *scanParam)
|
||||
{
|
||||
scanParam->scanInterval = (uint16_t)g_scanTable[freq].scanInterval;
|
||||
scanParam->scanWindow = (uint16_t)g_scanTable[freq].scanWindow;
|
||||
scanParam->scanType = SOFTBUS_BLE_SCAN_TYPE_ACTIVE;
|
||||
scanParam->scanPhy = SOFTBUS_BLE_SCAN_PHY_1M;
|
||||
scanParam->scanFilterPolicy = SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL;
|
||||
scanParam->scanType = SOFTBUS_BC_SCAN_TYPE_ACTIVE;
|
||||
scanParam->scanPhy = SOFTBUS_BC_SCAN_PHY_1M;
|
||||
scanParam->scanFilterPolicy = SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -955,7 +957,7 @@ static void StartScaner(void)
|
||||
DISC_LOGI(DISC_BLE, "scanner already start, no need start again");
|
||||
return;
|
||||
}
|
||||
SoftBusBleScanParams scanParam;
|
||||
BcScanParams scanParam;
|
||||
int32_t maxFreq = GetMaxExchangeFreq();
|
||||
DiscEventExtra discEventExtra = { .scanType = BLE };
|
||||
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, discEventExtra);
|
||||
@ -966,7 +968,7 @@ static void StartScaner(void)
|
||||
DISC_LOGE(DISC_BLE, "GetScannerParam failed");
|
||||
return;
|
||||
}
|
||||
if (SoftBusStartScan(g_bleListener.scanListenerId, g_bleScannerId, &scanParam) != SOFTBUS_OK) {
|
||||
if (StartScan(g_bleListener.scanListenerId, &scanParam) != SOFTBUS_OK) {
|
||||
discEventExtra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
discEventExtra.errcode = SOFTBUS_DISCOVER_START_SCAN_FAIL;
|
||||
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, discEventExtra);
|
||||
@ -984,7 +986,7 @@ static int32_t StopScaner(void)
|
||||
}
|
||||
DiscEventExtra discEventExtra = { .scanType = BLE, .result = EVENT_STAGE_RESULT_OK };
|
||||
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, discEventExtra);
|
||||
if (SoftBusStopScan(g_bleListener.scanListenerId, g_bleScannerId) != SOFTBUS_OK) {
|
||||
if (StopScan(g_bleListener.scanListenerId) != SOFTBUS_OK) {
|
||||
discEventExtra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
discEventExtra.errcode = SOFTBUS_DISCOVER_END_SCAN_FAIL;
|
||||
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, discEventExtra);
|
||||
@ -1268,12 +1270,21 @@ static DiscoveryBleDispatcherInterface g_discBleDispatcherInterface = {
|
||||
|
||||
static int32_t InitAdvertiser(void)
|
||||
{
|
||||
int32_t conChannel = SoftBusGetAdvChannel(&g_advCallback, &g_bleScannerId, false);
|
||||
int32_t nonChannel = SoftBusGetAdvChannel(&g_advCallback, &g_bleScannerId, false);
|
||||
int32_t conChannel = -1;
|
||||
int32_t nonChannel = -1;
|
||||
int32_t ret = RegisterBroadcaster(SRV_TYPE_DIS, &conChannel, &g_advCallback);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "register broadcaster con fail");
|
||||
|
||||
ret = RegisterBroadcaster(SRV_TYPE_DIS, &nonChannel, &g_advCallback);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_INIT, "register broadcaster non fail");
|
||||
(void)UnRegisterBroadcaster(conChannel);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (conChannel < 0 || nonChannel < 0) {
|
||||
DISC_LOGE(DISC_INIT, "get adv channel failed");
|
||||
(void)SoftBusReleaseAdvChannel(conChannel);
|
||||
(void)SoftBusReleaseAdvChannel(nonChannel);
|
||||
DISC_LOGE(DISC_INIT, "register broadcaster con[%d]-non[%d] fail", conChannel, nonChannel);
|
||||
(void)UnRegisterBroadcaster(conChannel);
|
||||
(void)UnRegisterBroadcaster(nonChannel);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
DISC_LOGI(DISC_INIT, "conChannel=%d nonChannel=%d", conChannel, nonChannel);
|
||||
@ -1311,59 +1322,59 @@ static void DiscBleInitSubscribe(void)
|
||||
|
||||
static void StartActivePublish(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
(void)StartAdvertiser(NON_ADV_ID);
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static void StartPassivePublish(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (g_bleAdvertiser[NON_ADV_ID].isAdvertising) {
|
||||
DISC_LOGI(DISC_BLE, "UpdateAdvertiser %d", NON_ADV_ID);
|
||||
UpdateAdvertiser(NON_ADV_ID);
|
||||
}
|
||||
StartScaner();
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static void StartActiveDiscovery(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (StartAdvertiser(CON_ADV_ID) == SOFTBUS_OK) {
|
||||
StartScaner();
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static void StartPassiveDiscovery(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
StartScaner();
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static void Recovery(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
(void)StartAdvertiser(CON_ADV_ID);
|
||||
(void)StartAdvertiser(NON_ADV_ID);
|
||||
StartScaner();
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static void BleDiscTurnOff(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
(void)StopAdvertiser(NON_ADV_ID);
|
||||
(void)StopAdvertiser(CON_ADV_ID);
|
||||
(void)StopScaner();
|
||||
DISC_LOGI(DISC_BLE, "end");
|
||||
DISC_LOGD(DISC_BLE, "end");
|
||||
}
|
||||
|
||||
static int32_t ReplyPassiveNonBroadcast(void)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
SoftBusMessage *msg = CreateBleHandlerMsg(REPLY_PASSIVE_NON_BROADCAST, 0, 0, NULL);
|
||||
if (msg == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
@ -1374,7 +1385,7 @@ static int32_t ReplyPassiveNonBroadcast(void)
|
||||
|
||||
static int32_t MessageRemovePredicate(const SoftBusMessage *msg, void *args)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
uintptr_t key = (uintptr_t)args;
|
||||
if (msg->what == PROCESS_TIME_OUT && msg->arg1 == key) {
|
||||
DISC_LOGI(DISC_BLE, "find key");
|
||||
@ -1411,7 +1422,7 @@ static int32_t MatchRecvMessage(const uint32_t *publishInfoMap, uint32_t *capBit
|
||||
|
||||
static void StartTimeout(const char *key)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (SoftBusMutexLock(&g_recvMessageInfo.lock) != 0) {
|
||||
DISC_LOGE(DISC_BLE, "lock failed");
|
||||
return;
|
||||
@ -1432,7 +1443,7 @@ static void StartTimeout(const char *key)
|
||||
|
||||
static void RemoveTimeout(const char *key)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (SoftBusMutexLock(&g_recvMessageInfo.lock) != 0) {
|
||||
DISC_LOGE(DISC_BLE, "lock failed");
|
||||
return;
|
||||
@ -1461,7 +1472,7 @@ static uint32_t RecvMsgAggregateCap(void)
|
||||
|
||||
static int32_t AddRecvMessage(const char *key, const uint32_t *capBitMap, bool needBrMac)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (SoftBusMutexLock(&g_recvMessageInfo.lock) != 0) {
|
||||
DISC_LOGE(DISC_BLE, "lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
@ -1504,7 +1515,7 @@ static int32_t AddRecvMessage(const char *key, const uint32_t *capBitMap, bool n
|
||||
|
||||
static void RemoveRecvMessage(uint64_t key)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
if (SoftBusMutexLock(&g_recvMessageInfo.lock) != 0) {
|
||||
DISC_LOGE(DISC_BLE, "lock failed");
|
||||
return;
|
||||
@ -1540,7 +1551,7 @@ static void ClearRecvMessage(void)
|
||||
|
||||
static void ProcessTimeout(SoftBusMessage *msg)
|
||||
{
|
||||
DISC_LOGI(DISC_BLE, "enter");
|
||||
DISC_LOGD(DISC_BLE, "enter");
|
||||
RemoveRecvMessage(msg->arg1);
|
||||
UpdateAdvertiser(NON_ADV_ID);
|
||||
}
|
||||
@ -1605,9 +1616,9 @@ static int32_t DiscBleLooperInit(void)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void DiscFreeBleScanFilter(SoftBusBleScanFilter *filter)
|
||||
static void DiscFreeBleScanFilter(BcScanFilter *filter)
|
||||
{
|
||||
if (filter) {
|
||||
if (filter != NULL) {
|
||||
SoftBusFree(filter->serviceData);
|
||||
SoftBusFree(filter->serviceDataMask);
|
||||
SoftBusFree(filter);
|
||||
@ -1616,7 +1627,7 @@ static void DiscFreeBleScanFilter(SoftBusBleScanFilter *filter)
|
||||
|
||||
static void DiscBleSetScanFilter(int32_t listenerId)
|
||||
{
|
||||
SoftBusBleScanFilter *filter = (SoftBusBleScanFilter *)SoftBusCalloc(sizeof(SoftBusBleScanFilter));
|
||||
BcScanFilter *filter = (BcScanFilter *)SoftBusCalloc(sizeof(BcScanFilter));
|
||||
DISC_CHECK_AND_RETURN_LOGW(filter != NULL, DISC_BLE, "malloc filter failed");
|
||||
|
||||
filter->serviceData = (uint8_t *)SoftBusCalloc(BLE_SCAN_FILTER_LEN);
|
||||
@ -1627,17 +1638,14 @@ static void DiscBleSetScanFilter(int32_t listenerId)
|
||||
return;
|
||||
}
|
||||
|
||||
filter->serviceUuid = BLE_UUID;
|
||||
filter->serviceDataLength = BLE_SCAN_FILTER_LEN;
|
||||
filter->serviceData[0] = BLE_UUID & BYTE_MASK;
|
||||
filter->serviceData[1] = (BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK;
|
||||
filter->serviceData[UUID_LEN + POS_VERSION] = BLE_VERSION;
|
||||
filter->serviceData[UUID_LEN + POS_BUSINESS] = DISTRIBUTE_BUSINESS;
|
||||
filter->serviceDataMask[0] = BYTE_MASK;
|
||||
filter->serviceDataMask[1] = BYTE_MASK;
|
||||
filter->serviceDataMask[UUID_LEN + POS_VERSION] = BYTE_MASK;
|
||||
filter->serviceDataMask[UUID_LEN + POS_BUSINESS] = BYTE_MASK;
|
||||
filter->serviceData[POS_VERSION] = BLE_VERSION;
|
||||
filter->serviceData[POS_BUSINESS] = DISTRIBUTE_BUSINESS;
|
||||
filter->serviceDataMask[POS_VERSION] = BYTE_MASK;
|
||||
filter->serviceDataMask[POS_BUSINESS] = BYTE_MASK;
|
||||
|
||||
if (SoftBusSetScanFilter(listenerId, filter, 1) != SOFTBUS_OK) {
|
||||
if (SetScanFilter(listenerId, filter, 1) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "set scan filter failed");
|
||||
DiscFreeBleScanFilter(filter);
|
||||
}
|
||||
@ -1645,7 +1653,8 @@ static void DiscBleSetScanFilter(int32_t listenerId)
|
||||
|
||||
static int32_t InitBleListener(void)
|
||||
{
|
||||
g_bleListener.scanListenerId = SoftBusAddScanListener(&g_scanListener, &g_bleScannerId, false);
|
||||
int32_t ret = RegisterScanListener(SRV_TYPE_DIS, &g_bleListener.scanListenerId, &g_scanListener);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "register scanner listener fail");
|
||||
g_bleListener.stateListenerId = SoftBusAddBtStateListener(&g_stateChangedListener);
|
||||
if (g_bleListener.stateListenerId < 0 || g_bleListener.scanListenerId < 0) {
|
||||
return SOFTBUS_ERR;
|
||||
@ -1674,6 +1683,10 @@ DiscoveryBleDispatcherInterface *DiscSoftBusBleInit(DiscInnerCallback *callback)
|
||||
DiscBleInitPublish();
|
||||
DiscBleInitSubscribe();
|
||||
InitScanner();
|
||||
if (InitBroadcastMgr() != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_INIT, "init broadcast mgr failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (DiscBleLooperInit() != SOFTBUS_OK || InitBleListener() != SOFTBUS_OK || InitAdvertiser() != SOFTBUS_OK) {
|
||||
DiscSoftBusBleDeinit();
|
||||
@ -1709,8 +1722,8 @@ static void RecvMessageDeinit(void)
|
||||
|
||||
static void AdvertiserDeinit(void)
|
||||
{
|
||||
(void)SoftBusReleaseAdvChannel(g_bleAdvertiser[CON_ADV_ID].channel);
|
||||
(void)SoftBusReleaseAdvChannel(g_bleAdvertiser[NON_ADV_ID].channel);
|
||||
(void)UnRegisterBroadcaster(g_bleAdvertiser[CON_ADV_ID].channel);
|
||||
(void)UnRegisterBroadcaster(g_bleAdvertiser[NON_ADV_ID].channel);
|
||||
for (uint32_t index = 0; index < NUM_ADVERTISER; index++) {
|
||||
(void)memset_s(&g_bleAdvertiser[index], sizeof(DiscBleAdvertiser), 0x0, sizeof(DiscBleAdvertiser));
|
||||
}
|
||||
@ -1719,8 +1732,7 @@ static void AdvertiserDeinit(void)
|
||||
static void BleListenerDeinit(void)
|
||||
{
|
||||
(void)SoftBusRemoveBtStateListener(g_bleListener.stateListenerId);
|
||||
(void)SoftBusRemoveScanListener(g_bleListener.scanListenerId);
|
||||
(void)SoftBusDeregisterScanCallbacks(g_bleScannerId);
|
||||
(void)UnRegisterScanListener(g_bleListener.scanListenerId);
|
||||
}
|
||||
|
||||
static void DiscBleInfoDeinit(void)
|
||||
@ -1740,6 +1752,7 @@ void DiscSoftBusBleDeinit(void)
|
||||
RecvMessageDeinit();
|
||||
DiscBleInfoDeinit();
|
||||
AdvertiserDeinit();
|
||||
DeInitBroadcastMgr();
|
||||
}
|
||||
|
||||
static int32_t BleInfoDump(int fd)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "bus_center_manager.h"
|
||||
#include "cJSON.h"
|
||||
#include "disc_ble_constant.h"
|
||||
#include "softbus_broadcast_type.h"
|
||||
#include "disc_log.h"
|
||||
#include "lnn_device_info.h"
|
||||
#include "securec.h"
|
||||
@ -305,7 +306,7 @@ static int32_t ParseCustData(DeviceWrapper *device, const uint8_t *data, const u
|
||||
|
||||
static int32_t ParseRecvTlvs(DeviceWrapper *device, const uint8_t *data, uint32_t dataLen)
|
||||
{
|
||||
uint32_t curLen = POS_TLV + ADV_HEAD_LEN;
|
||||
uint32_t curLen = 0;
|
||||
int32_t ret = SOFTBUS_OK;
|
||||
while (curLen < dataLen) {
|
||||
uint8_t type = (data[curLen] & DATA_TYPE_MASK) >> BYTE_SHIFT;
|
||||
@ -353,50 +354,49 @@ int32_t GetDeviceInfoFromDisAdvData(DeviceWrapper *device, const uint8_t *data,
|
||||
{
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(device != NULL && device->info != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE,
|
||||
"device is invalid");
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(data != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "data=NULL is invalid");
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(dataLen != 0, SOFTBUS_INVALID_PARAM, DISC_BLE, "dataLen=0 is invalid");
|
||||
BroadcastReportInfo *reportInfo = (BroadcastReportInfo *)data;
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(reportInfo != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "reportInfo=NULL is invalid");
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(dataLen == sizeof(BroadcastReportInfo), SOFTBUS_INVALID_PARAM, DISC_BLE,
|
||||
"bcData.payload=NULL is invalid");
|
||||
DISC_CHECK_AND_RETURN_RET_LOGW(
|
||||
reportInfo->packet.bcData.payload != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "payload=NULL is invalid");
|
||||
uint16_t bcLen = reportInfo->packet.bcData.payloadLen;
|
||||
uint16_t rspLen = reportInfo->packet.rspData.payloadLen;
|
||||
if (bcLen > ADV_DATA_MAX_LEN || bcLen < POS_TLV || rspLen > RESP_DATA_MAX_LEN) {
|
||||
DISC_LOGE(DISC_BLE, "get discovery adv data fail");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint8_t *serviceData = reportInfo->packet.bcData.payload;
|
||||
if (memcpy_s(device->info->accountHash, SHORT_USER_ID_HASH_LEN,
|
||||
&data[POS_USER_ID_HASH + ADV_HEAD_LEN], SHORT_USER_ID_HASH_LEN) != EOK) {
|
||||
&serviceData[POS_USER_ID_HASH], SHORT_USER_ID_HASH_LEN) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "copy accountHash failed");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
device->info->capabilityBitmap[0] = data[POS_CAPABLITY + ADV_HEAD_LEN];
|
||||
// ble scan data consists of multiple ADStructures
|
||||
// ADStructure format: <length (1 octet)> <type (1 octet)> <data(length octect - 1)>
|
||||
// More info about ADStructure, please ref Generic Access Profile Specification
|
||||
// We only use Flag(0x01) + ServiceData(0x16) + Manufacture(0xff) in order, so we should join them together
|
||||
// before parse
|
||||
uint32_t scanRspPtr = 0;
|
||||
uint32_t scanRspTlvLen = 0;
|
||||
uint32_t nextAdsPtr = FLAG_BYTE_LEN + 1 + data[POS_PACKET_LENGTH] + 1;
|
||||
while (nextAdsPtr + 1 < dataLen) {
|
||||
if (data[nextAdsPtr + 1] == RSP_TYPE) {
|
||||
scanRspPtr = nextAdsPtr;
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(data[scanRspPtr] >= (RSP_HEAD_LEN - 1), SOFTBUS_ERR, DISC_BLE,
|
||||
"rspLen[%hhu] is less than rsp head length", data[scanRspPtr]);
|
||||
scanRspTlvLen = data[scanRspPtr] - (RSP_HEAD_LEN - 1);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(scanRspPtr + data[scanRspPtr] + 1 <= dataLen, SOFTBUS_ERR, DISC_BLE,
|
||||
"curScanLen(%u) > dataLen(%u)", scanRspPtr + data[scanRspPtr] + 1, dataLen);
|
||||
break;
|
||||
}
|
||||
nextAdsPtr += data[nextAdsPtr] + 1;
|
||||
device->info->capabilityBitmap[0] = serviceData[POS_CAPABLITY];
|
||||
|
||||
uint32_t bcTlvLen = reportInfo->packet.bcData.payloadLen - POS_TLV;
|
||||
|
||||
if (bcTlvLen == 0) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
uint32_t advLen = FLAG_BYTE_LEN + 1 + data[POS_PACKET_LENGTH] + 1;
|
||||
uint8_t *copyData = SoftBusCalloc(advLen + scanRspTlvLen + 1);
|
||||
uint8_t *copyData = SoftBusCalloc(bcTlvLen + rspLen);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(copyData != NULL, SOFTBUS_MEM_ERR, DISC_BLE, "malloc failed.");
|
||||
if (memcpy_s(copyData, advLen, data, advLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy_s adv failed, advLen: %u", advLen);
|
||||
if (memcpy_s(copyData, bcTlvLen, &serviceData[POS_TLV], bcTlvLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy_s adv failed, bcTlvLen: %u", bcTlvLen);
|
||||
SoftBusFree(copyData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
if (scanRspTlvLen != 0) {
|
||||
if (memcpy_s(copyData + advLen, scanRspTlvLen, data + scanRspPtr + RSP_HEAD_LEN, scanRspTlvLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy_s scan resp failed, advLen: %u, scanRspTlvLen: %u.", advLen, scanRspTlvLen);
|
||||
|
||||
if (rspLen > 0 && reportInfo->packet.rspData.payload != NULL) {
|
||||
if (memcpy_s(copyData + bcTlvLen, rspLen, reportInfo->packet.rspData.payload, rspLen) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "memcpy_s rsp data failed, rspLen: %u", rspLen);
|
||||
SoftBusFree(copyData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
}
|
||||
int32_t ret = ParseRecvTlvs(device, copyData, advLen + scanRspTlvLen);
|
||||
|
||||
int32_t ret = ParseRecvTlvs(device, copyData, bcTlvLen + rspLen);
|
||||
SoftBusFree(copyData);
|
||||
return ret;
|
||||
}
|
||||
|
@ -267,13 +267,13 @@ static void FreeDiscInfo(DiscInfo *info, const ServiceType type)
|
||||
static bool IsInnerModule(const DiscInfo *infoNode)
|
||||
{
|
||||
for (uint32_t i = 0; i < MODULE_MAX; i++) {
|
||||
DISC_LOGI(DISC_CONTROL, "%s", infoNode->item->packageName);
|
||||
DISC_LOGD(DISC_CONTROL, "%s", infoNode->item->packageName);
|
||||
if (strcmp(infoNode->item->packageName, g_discModuleMap[i]) == 0) {
|
||||
DISC_LOGI(DISC_CONTROL, "true");
|
||||
DISC_LOGD(DISC_CONTROL, "true");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
DISC_LOGI(DISC_CONTROL, "false");
|
||||
DISC_LOGD(DISC_CONTROL, "false");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "softbus_server_stub.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "access_control.h"
|
||||
#include "access_token.h"
|
||||
#include "comm_log.h"
|
||||
#include "discovery_service.h"
|
||||
@ -577,6 +578,14 @@ static void ReadQosInfo(MessageParcel& data, SessionParam ¶m)
|
||||
}
|
||||
}
|
||||
|
||||
static void ReadSessionInfo(MessageParcel& data, SessionParam ¶m)
|
||||
{
|
||||
param.sessionName = data.ReadCString();
|
||||
param.peerSessionName = data.ReadCString();
|
||||
param.peerDeviceId = data.ReadCString();
|
||||
param.groupId = data.ReadCString();
|
||||
}
|
||||
|
||||
int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
COMM_LOGI(COMM_SVC, "enter");
|
||||
@ -590,10 +599,7 @@ int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &
|
||||
int64_t timeStart = 0;
|
||||
int64_t timediff = 0;
|
||||
SoftBusOpenSessionStatus isSucc = SOFTBUS_EVT_OPEN_SESSION_FAIL;
|
||||
param.sessionName = data.ReadCString();
|
||||
param.peerSessionName = data.ReadCString();
|
||||
param.peerDeviceId = data.ReadCString();
|
||||
param.groupId = data.ReadCString();
|
||||
ReadSessionInfo(data, param);
|
||||
ReadSessionAttrs(data, &getAttr);
|
||||
param.attr = &getAttr;
|
||||
ReadQosInfo(data, param);
|
||||
@ -603,6 +609,10 @@ int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &
|
||||
retReply = SOFTBUS_INVALID_PARAM;
|
||||
goto EXIT;
|
||||
}
|
||||
if (TransCheckAccessControl(param.peerDeviceId) != SOFTBUS_OK) {
|
||||
retReply = SOFTBUS_PERMISSION_DENIED;
|
||||
goto EXIT;
|
||||
}
|
||||
if (CheckOpenSessionPermission(¶m) != SOFTBUS_OK) {
|
||||
SoftbusReportTransErrorEvt(SOFTBUS_PERMISSION_DENIED);
|
||||
retReply = SOFTBUS_PERMISSION_DENIED;
|
||||
|
@ -111,13 +111,12 @@ char *PackRequest(const AppInfo *appInfo)
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
if (appInfo->fastTransDataSize > 0) {
|
||||
if (PackFirstData(appInfo, json) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "pack first data failed");
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
if (appInfo->fastTransDataSize > 0 && PackFirstData(appInfo, json) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "pack first data failed");
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char encodeSessionKey[BASE64KEY] = {0};
|
||||
size_t keyLen = 0;
|
||||
int32_t ret = SoftBusBase64Encode(encodeSessionKey, BASE64KEY, &keyLen, (unsigned char*)appInfo->sessionKey,
|
||||
@ -126,26 +125,25 @@ char *PackRequest(const AppInfo *appInfo)
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
if (!AddNumberToJsonObject(json, CODE, CODE_OPEN_CHANNEL) ||
|
||||
bool addBRet = (!AddNumberToJsonObject(json, CODE, CODE_OPEN_CHANNEL) ||
|
||||
!AddNumberToJsonObject(json, API_VERSION, appInfo->myData.apiVersion) ||
|
||||
!AddStringToJsonObject(json, BUS_NAME, appInfo->peerData.sessionName) ||
|
||||
!AddStringToJsonObject(json, GROUP_ID, appInfo->groupId) ||
|
||||
!AddNumberToJsonObject(json, UID, appInfo->myData.uid) ||
|
||||
!AddNumberToJsonObject(json, PID, appInfo->myData.pid) ||
|
||||
!AddStringToJsonObject(json, SESSION_KEY, (char*)encodeSessionKey) ||
|
||||
!AddNumberToJsonObject(json, MTU_SIZE, (int)appInfo->myData.dataConfig)) {
|
||||
!AddNumberToJsonObject(json, MTU_SIZE, (int)appInfo->myData.dataConfig));
|
||||
if (addBRet) {
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
char *authState = (char*)appInfo->myData.authState;
|
||||
if (appInfo->myData.apiVersion != API_V1) {
|
||||
if (!AddStringToJsonObject(json, PKG_NAME, appInfo->myData.pkgName) ||
|
||||
!AddStringToJsonObject(json, CLIENT_BUS_NAME, appInfo->myData.sessionName) ||
|
||||
!AddStringToJsonObject(json, AUTH_STATE, authState) ||
|
||||
!AddNumberToJsonObject(json, MSG_ROUTE_TYPE, appInfo->routeType)) {
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
if (appInfo->myData.apiVersion != API_V1 && (!AddStringToJsonObject(json, PKG_NAME, appInfo->myData.pkgName) ||
|
||||
!AddStringToJsonObject(json, CLIENT_BUS_NAME, appInfo->myData.sessionName) ||
|
||||
!AddStringToJsonObject(json, AUTH_STATE, authState) ||
|
||||
!AddNumberToJsonObject(json, MSG_ROUTE_TYPE, appInfo->routeType))) {
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
(void)AddNumberToJsonObject(json, BUSINESS_TYPE, appInfo->businessType);
|
||||
(void)AddNumberToJsonObject(json, AUTO_CLOSE_TIME, appInfo->autoCloseTime);
|
||||
|
@ -345,7 +345,10 @@ void TransOnLinkDown(const char *networkId, const char *uuid, const char *udid,
|
||||
if (networkId == NULL || g_sessionServerList == NULL) {
|
||||
return;
|
||||
}
|
||||
TRANS_LOGI(TRANS_CTRL, "routeType=%d", routeType);
|
||||
char *anonyNetworkId = NULL;
|
||||
Anonymize(networkId, &anonyNetworkId);
|
||||
TRANS_LOGI(TRANS_CTRL, "routeType=%d, networkId=%s", routeType, anonyNetworkId);
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
|
||||
ListNode sessionServerList = {0};
|
||||
ListInit(&sessionServerList);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -65,12 +65,12 @@ static void DelAuthChannelInfoByAuthId(int32_t authId);
|
||||
|
||||
static int32_t GetAuthChannelInfoByChanId(int32_t channelId, AuthChannelInfo *dstInfo)
|
||||
{
|
||||
if (dstInfo == NULL || g_authChannelList == NULL) {
|
||||
if (g_authChannelList == NULL) {
|
||||
TRANS_LOGE(TRANS_SVC, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != 0) {
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
@ -180,7 +180,7 @@ static int32_t NotifyOnDataReceived(int32_t authId, const void *data, uint32_t l
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
TransReceiveData receiveData;
|
||||
receiveData.data = (void*)data;
|
||||
receiveData.data = (void *)data;
|
||||
receiveData.dataLen = len;
|
||||
receiveData.dataType = TRANS_SESSION_BYTES;
|
||||
|
||||
@ -190,9 +190,6 @@ static int32_t NotifyOnDataReceived(int32_t authId, const void *data, uint32_t l
|
||||
|
||||
static int32_t CopyPeerAppInfo(AppInfo *recvAppInfo, AppInfo *channelAppInfo)
|
||||
{
|
||||
if (recvAppInfo == NULL || channelAppInfo == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (memcpy_s(channelAppInfo->peerData.deviceId, DEVICE_ID_SIZE_MAX,
|
||||
recvAppInfo->peerData.deviceId, DEVICE_ID_SIZE_MAX) != EOK ||
|
||||
memcpy_s(recvAppInfo->myData.deviceId, DEVICE_ID_SIZE_MAX,
|
||||
@ -210,9 +207,6 @@ static int32_t CopyPeerAppInfo(AppInfo *recvAppInfo, AppInfo *channelAppInfo)
|
||||
|
||||
static int32_t OnRequsetUpdateAuthChannel(int32_t authId, AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
AuthChannelInfo *item = NULL;
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != 0) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
@ -243,6 +237,7 @@ static int32_t OnRequsetUpdateAuthChannel(int32_t authId, AppInfo *appInfo)
|
||||
}
|
||||
if (CopyPeerAppInfo(appInfo, &item->appInfo) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "CopyPeerAppInfo failed");
|
||||
ListDelete(&item->node);
|
||||
SoftBusFree(item);
|
||||
SoftBusMutexUnlock(&g_authChannelList->lock);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
@ -258,7 +253,8 @@ static const ConfigTypeMap g_configTypeMap[] = {
|
||||
|
||||
static int32_t FindConfigType(int32_t channelType, int32_t businessType)
|
||||
{
|
||||
for (uint32_t i = 0; i < sizeof(g_configTypeMap) / sizeof(ConfigTypeMap); i++) {
|
||||
uint32_t size = (uint32_t)(sizeof(g_configTypeMap) / sizeof(g_configTypeMap[0]));
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
if ((g_configTypeMap[i].channelType == channelType) && (g_configTypeMap[i].businessType == businessType)) {
|
||||
return g_configTypeMap[i].configType;
|
||||
}
|
||||
@ -294,6 +290,7 @@ static int32_t TransAuthFillDataConfig(AppInfo *appInfo)
|
||||
if (appInfo->peerData.dataConfig != 0) {
|
||||
uint32_t localDataConfig = 0;
|
||||
if (TransGetLocalConfig(CHANNEL_TYPE_AUTH, appInfo->businessType, &localDataConfig) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "get local config failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
appInfo->myData.dataConfig = MIN(localDataConfig, appInfo->peerData.dataConfig);
|
||||
@ -331,7 +328,7 @@ static void OnRecvAuthChannelRequest(int32_t authId, const char *data, int32_t l
|
||||
}
|
||||
ret = AuthGetUidAndPidBySessionName(appInfo.myData.sessionName, &appInfo.myData.uid, &appInfo.myData.pid);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "AuthGetUidAndPidBySessionName failed");
|
||||
TRANS_LOGE(TRANS_SVC, "auth get id by sessionName failed");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
ret = TransAuthFillDataConfig(&appInfo);
|
||||
@ -417,9 +414,9 @@ static void OnRecvAuthChannelReply(int32_t authId, const char *data, int32_t len
|
||||
return;
|
||||
EXIT_ERR:
|
||||
AuthCloseChannel(authId);
|
||||
DelAuthChannelInfoByChanId(info.appInfo.myData.channelId);
|
||||
(void)NotifyOpenAuthChannelFailed(info.appInfo.myData.pkgName, info.appInfo.myData.pid,
|
||||
info.appInfo.myData.channelId, ret);
|
||||
DelAuthChannelInfoByChanId((int32_t)(info.appInfo.myData.channelId));
|
||||
(void)NotifyOpenAuthChannelFailed((const char *)(info.appInfo.myData.pkgName),
|
||||
(int32_t)(info.appInfo.myData.pid), (int32_t)(info.appInfo.myData.channelId), ret);
|
||||
}
|
||||
|
||||
static void OnAuthChannelDataRecv(int32_t authId, const AuthChannelData *data)
|
||||
@ -430,9 +427,9 @@ static void OnAuthChannelDataRecv(int32_t authId, const AuthChannelData *data)
|
||||
}
|
||||
|
||||
if (data->flag == AUTH_CHANNEL_REQ) {
|
||||
OnRecvAuthChannelRequest(authId, (const char *)data->data, data->len);
|
||||
OnRecvAuthChannelRequest(authId, (const char *)data->data, (int32_t)data->len);
|
||||
} else if (data->flag == AUTH_CHANNEL_REPLY) {
|
||||
OnRecvAuthChannelReply(authId, (const char *)data->data, data->len);
|
||||
OnRecvAuthChannelReply(authId, (const char *)data->data, (int32_t)data->len);
|
||||
} else {
|
||||
TRANS_LOGE(TRANS_SVC, "auth channel flags err, authId=%d", authId);
|
||||
}
|
||||
@ -456,9 +453,9 @@ static void OnDisconnect(int32_t authId)
|
||||
return;
|
||||
}
|
||||
TRANS_LOGI(TRANS_SVC, "recv authId=%d channel disconnect event.", authId);
|
||||
DelAuthChannelInfoByChanId(dstInfo.appInfo.myData.channelId);
|
||||
(void)NofifyCloseAuthChannel(dstInfo.appInfo.myData.pkgName, dstInfo.appInfo.myData.pid,
|
||||
dstInfo.appInfo.myData.channelId);
|
||||
DelAuthChannelInfoByChanId((int32_t)(dstInfo.appInfo.myData.channelId));
|
||||
(void)NofifyCloseAuthChannel((const char *)dstInfo.appInfo.myData.pkgName,
|
||||
(int32_t)dstInfo.appInfo.myData.pid, (int32_t)dstInfo.appInfo.myData.channelId);
|
||||
}
|
||||
|
||||
static int32_t GetAppInfo(const char *sessionName, int32_t channelId, AppInfo *appInfo, bool isClient)
|
||||
@ -473,7 +470,7 @@ static int32_t GetAppInfo(const char *sessionName, int32_t channelId, AppInfo *a
|
||||
appInfo->myData.apiVersion = API_V2;
|
||||
appInfo->peerData.apiVersion = API_V2;
|
||||
appInfo->autoCloseTime = 0;
|
||||
if ((!IsNoPkgNameSession(sessionName)) || (isClient)) {
|
||||
if (!IsNoPkgNameSession(sessionName) || isClient) {
|
||||
if (TransGetUidAndPid(sessionName, &appInfo->myData.uid, &appInfo->myData.pid) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "TransGetUidAndPid failed");
|
||||
return SOFTBUS_ERR;
|
||||
@ -489,10 +486,11 @@ static int32_t GetAppInfo(const char *sessionName, int32_t channelId, AppInfo *a
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strcpy_s(appInfo->myData.sessionName, sizeof(appInfo->myData.sessionName), sessionName) != EOK) {
|
||||
TRANS_LOGE(TRANS_SVC, "copy sessionName failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
appInfo->peerData.apiVersion = API_V2;
|
||||
if (strcpy_s(appInfo->peerData.sessionName, sizeof(appInfo->peerData.sessionName), sessionName) != 0) {
|
||||
if (strcpy_s(appInfo->peerData.sessionName, sizeof(appInfo->peerData.sessionName), sessionName) != EOK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (TransGetLocalConfig(appInfo->channelType, appInfo->businessType, &appInfo->myData.dataConfig) != SOFTBUS_OK) {
|
||||
@ -527,7 +525,7 @@ static void DelAuthChannelInfoByChanId(int32_t channelId)
|
||||
if (g_authChannelList == NULL) {
|
||||
return;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != 0) {
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != SOFTBUS_OK) {
|
||||
return;
|
||||
}
|
||||
AuthChannelInfo *item = NULL;
|
||||
@ -548,7 +546,7 @@ static void DelAuthChannelInfoByAuthId(int32_t authId)
|
||||
if (g_authChannelList == NULL) {
|
||||
return;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != 0) {
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != SOFTBUS_OK) {
|
||||
return;
|
||||
}
|
||||
AuthChannelInfo *item = NULL;
|
||||
@ -621,6 +619,8 @@ void TransAuthDeinit(void)
|
||||
{
|
||||
UnregAuthChannelListener(MODULE_AUTH_CHANNEL);
|
||||
UnregAuthChannelListener(MODULE_AUTH_MSG);
|
||||
DestroySoftBusList(g_authChannelList);
|
||||
g_authChannelList = NULL;
|
||||
g_cb = NULL;
|
||||
}
|
||||
|
||||
@ -637,15 +637,15 @@ static int32_t TransPostAuthChannelMsg(const AppInfo *appInfo, int32_t authId, i
|
||||
}
|
||||
if (TransAuthChannelMsgPack(msg, appInfo) != SOFTBUS_OK) {
|
||||
cJSON_Delete(msg);
|
||||
TRANS_LOGE(TRANS_SVC, "tran channel msg pack failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
char *data = cJSON_PrintUnformatted(msg);
|
||||
cJSON_Delete(msg);
|
||||
if (data == NULL) {
|
||||
TRANS_LOGE(TRANS_SVC, "json failed");
|
||||
cJSON_Delete(msg);
|
||||
return SOFTBUS_PARSE_JSON_ERR;
|
||||
}
|
||||
cJSON_Delete(msg);
|
||||
|
||||
AuthChannelData channelData = {
|
||||
.module = MODULE_AUTH_CHANNEL,
|
||||
@ -718,6 +718,7 @@ int32_t TransOpenAuthMsgChannel(const char *sessionName, const ConnectOption *co
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strcpy_s(channel->appInfo.reqId, REQ_ID_SIZE_MAX, reqId) != EOK) {
|
||||
SoftBusFree(channel);
|
||||
TRANS_LOGE(TRANS_SVC, "TransOpenAuthMsgChannel strcpy_s reqId failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -725,7 +726,7 @@ int32_t TransOpenAuthMsgChannel(const char *sessionName, const ConnectOption *co
|
||||
SoftBusFree(channel);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
*channelId = channel->appInfo.myData.channelId;
|
||||
*channelId = (int32_t)channel->appInfo.myData.channelId;
|
||||
int32_t authId = AuthOpenChannel(connOpt->socketOption.addr, connOpt->socketOption.port);
|
||||
if (authId < 0) {
|
||||
TRANS_LOGE(TRANS_SVC, "AuthOpenChannel failed");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -16,7 +16,6 @@
|
||||
#include "trans_auth_message.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_utils.h"
|
||||
@ -40,7 +39,7 @@ int32_t TransAuthChannelMsgPack(cJSON *msg, const AppInfo *appInfo)
|
||||
!AddStringToJsonObject(msg, "SRC_BUS_NAME", appInfo->myData.sessionName) ||
|
||||
!AddStringToJsonObject(msg, "DST_BUS_NAME", appInfo->peerData.sessionName) ||
|
||||
!AddStringToJsonObject(msg, "REQ_ID", appInfo->reqId) ||
|
||||
!AddNumberToJsonObject(msg, "MTU_SIZE", appInfo->myData.dataConfig)) {
|
||||
!AddNumberToJsonObject(msg, "MTU_SIZE", (int)appInfo->myData.dataConfig)) {
|
||||
TRANS_LOGE(TRANS_SVC, "failed");
|
||||
return SOFTBUS_PARSE_JSON_ERR;
|
||||
}
|
||||
@ -81,7 +80,6 @@ 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)
|
||||
{
|
||||
(void)maxLen;
|
||||
if (errMsg == NULL || cJsonStr == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
@ -97,16 +95,14 @@ int32_t TransAuthChannelErrorPack(int32_t errcode, const char *errMsg, char *cJs
|
||||
return SOFTBUS_PARSE_JSON_ERR;
|
||||
}
|
||||
char *data = cJSON_PrintUnformatted(obj);
|
||||
cJSON_Delete(obj);
|
||||
if (data == NULL) {
|
||||
cJSON_Delete(obj);
|
||||
return SOFTBUS_PARSE_JSON_ERR;
|
||||
}
|
||||
if (memcpy_s(cJsonStr, ERR_MSG_MAX_LEN, data, strlen(data)) != EOK) {
|
||||
cJSON_Delete(obj);
|
||||
if (memcpy_s(cJsonStr, maxLen, data, strlen(data)) != EOK) {
|
||||
cJSON_free(data);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
cJSON_Delete(obj);
|
||||
cJSON_free(data);
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include <securec.h>
|
||||
#include "auth_interface.h"
|
||||
#include "bus_center_info_key.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "common_list.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
@ -84,7 +83,7 @@ void TransReqLanePendingDeinit(void)
|
||||
|
||||
static int32_t TransDelLaneReqFromPendingList(uint32_t laneId)
|
||||
{
|
||||
TRANS_LOGI(TRANS_SVC, "del tran request from pending laneId=%u.", laneId);
|
||||
TRANS_LOGD(TRANS_SVC, "del tran request from pending laneId=%u.", laneId);
|
||||
if (g_reqLanePendingList == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "lane request list hasn't init.");
|
||||
return SOFTBUS_ERR;
|
||||
@ -128,7 +127,6 @@ static int32_t TransAddLaneReqFromPendingList(uint32_t laneId)
|
||||
item->laneId = laneId;
|
||||
item->bSucc = false;
|
||||
item->isFinished = false;
|
||||
(void)memset_s(&(item->connInfo), sizeof(LaneConnInfo), 0, sizeof(LaneConnInfo));
|
||||
|
||||
if (SoftBusMutexLock(&g_reqLanePendingList->lock) != SOFTBUS_OK) {
|
||||
SoftBusFree(item);
|
||||
@ -259,7 +257,7 @@ static LaneTransType GetStreamLaneType(int32_t streamType)
|
||||
|
||||
LaneTransType TransGetLaneTransTypeBySession(const SessionParam *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
if (param == NULL || param->attr == NULL) {
|
||||
return LANE_T_BUTT;
|
||||
}
|
||||
int32_t type = param->attr->dataType;
|
||||
@ -518,10 +516,6 @@ int32_t TransGetLaneInfoByOption(bool isQosLane, const LaneRequestOption *reques
|
||||
}
|
||||
|
||||
*laneId = GetLaneManager()->applyLaneId(LANE_TYPE_TRANS);
|
||||
if (*laneId <= 0) {
|
||||
TRANS_LOGE(TRANS_SVC, "trans apply lane failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (TransAddLaneReqToPendingAndWaiting(isQosLane, *laneId, requestOption) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "trans add lane to pending list failed.");
|
||||
return SOFTBUS_ERR;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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
|
||||
@ -296,21 +296,21 @@ EXIT_ERR:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ChannelType TransGetChannelType(const SessionParam *param, const LaneConnInfo *connInfo)
|
||||
static ChannelType TransGetChannelType(const SessionParam *param, const int32_t type)
|
||||
{
|
||||
LaneTransType transType = TransGetLaneTransTypeBySession(param);
|
||||
if (transType == LANE_T_BUTT) {
|
||||
return CHANNEL_TYPE_BUTT;
|
||||
}
|
||||
|
||||
if (connInfo->type == LANE_BR || connInfo->type == LANE_BLE || connInfo->type == LANE_BLE_DIRECT ||
|
||||
connInfo->type == LANE_COC || connInfo->type == LANE_COC_DIRECT) {
|
||||
if (type == LANE_BR || type == LANE_BLE || type == LANE_BLE_DIRECT ||
|
||||
type == LANE_COC || type == LANE_COC_DIRECT) {
|
||||
return CHANNEL_TYPE_PROXY;
|
||||
} else if (transType == LANE_T_FILE || transType == LANE_T_COMMON_VIDEO || transType == LANE_T_COMMON_VOICE ||
|
||||
transType == LANE_T_RAW_STREAM) {
|
||||
return CHANNEL_TYPE_UDP;
|
||||
} else if ((transType == LANE_T_MSG) && (connInfo->type != LANE_P2P) && (connInfo->type != LANE_P2P_REUSE) &&
|
||||
(connInfo->type != LANE_HML)) {
|
||||
} else if ((transType == LANE_T_MSG) && (type != LANE_P2P) && (type != LANE_P2P_REUSE) &&
|
||||
(type != LANE_HML)) {
|
||||
return CHANNEL_TYPE_PROXY;
|
||||
}
|
||||
return CHANNEL_TYPE_TCP_DIRECT;
|
||||
@ -383,11 +383,11 @@ static int TransGetLocalConfig(int32_t channelType, int32_t businessType, uint32
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void FillAppInfo(AppInfo *appInfo, ConnectOption *connOpt, const SessionParam *param,
|
||||
TransInfo *transInfo, LaneConnInfo *connInfo)
|
||||
static void FillAppInfo(AppInfo *appInfo, const SessionParam *param,
|
||||
TransInfo *transInfo, int32_t type)
|
||||
{
|
||||
transInfo->channelType = TransGetChannelType(param, connInfo);
|
||||
appInfo->linkType = connInfo->type;
|
||||
transInfo->channelType = TransGetChannelType(param, type);
|
||||
appInfo->linkType = type;
|
||||
appInfo->channelType = transInfo->channelType;
|
||||
(void)TransGetLocalConfig(appInfo->channelType, appInfo->businessType, &appInfo->myData.dataConfig);
|
||||
}
|
||||
@ -412,6 +412,10 @@ static void TransOpenChannelSetModule(int32_t channelType, ConnectOption *connOp
|
||||
|
||||
int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
|
||||
{
|
||||
if (param == NULL || transInfo == NULL) {
|
||||
TRANS_LOGE(TRANS_CTRL, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
TRANS_LOGI(TRANS_CTRL, "server TransOpenChannel");
|
||||
int64_t timeStart = GetSoftbusRecordTimeMillis();
|
||||
transInfo->channelId = INVALID_CHANNEL_ID;
|
||||
@ -451,7 +455,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
|
||||
SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - timeStart);
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
FillAppInfo(appInfo, &connOpt, param, transInfo, &connInfo);
|
||||
FillAppInfo(appInfo, param, transInfo, connInfo.type);
|
||||
TransOpenChannelSetModule(transInfo->channelType, &connOpt);
|
||||
TRANS_LOGI(TRANS_CTRL, "laneId=%u get channelType=%u.", laneId, transInfo->channelType);
|
||||
errCode = TransOpenChannelProc((ChannelType)transInfo->channelType, appInfo, &connOpt,
|
||||
@ -576,6 +580,7 @@ int32_t TransOpenAuthChannel(const char *sessionName, const ConnectOption *connO
|
||||
}
|
||||
if (strcpy_s(appInfo->reqId, REQ_ID_SIZE_MAX, reqId) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "strcpy_s reqId failed");
|
||||
SoftBusFree(appInfo);
|
||||
return INVALID_CHANNEL_ID;
|
||||
}
|
||||
if (TransProxyOpenProxyChannel(appInfo, connOpt, &channelId) != SOFTBUS_OK) {
|
||||
|
@ -137,7 +137,7 @@ void TransLaneMgrDeinit(void)
|
||||
int32_t TransLaneMgrAddLane(int32_t channelId, int32_t channelType, LaneConnInfo *connInfo,
|
||||
uint32_t laneId, AppInfoData *myData)
|
||||
{
|
||||
if (g_channelLaneList == NULL) {
|
||||
if (g_channelLaneList == NULL || connInfo == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
@ -167,10 +167,10 @@ int32_t TransLaneMgrAddLane(int32_t channelId, int32_t channelType, LaneConnInfo
|
||||
TransLaneInfo *laneItem = NULL;
|
||||
LIST_FOR_EACH_ENTRY(laneItem, &(g_channelLaneList->list), TransLaneInfo, node) {
|
||||
if (laneItem->channelId == channelId && laneItem->channelType == channelType) {
|
||||
TRANS_LOGI(TRANS_SVC,
|
||||
"trans lane info has exited.channelId=%d, channelType=%d", channelId, channelType);
|
||||
SoftBusFree(newLane);
|
||||
(void)SoftBusMutexUnlock(&(g_channelLaneList->lock));
|
||||
TRANS_LOGI(TRANS_SVC,
|
||||
"trans lane info has existed.channelId=%d, channelType=%d", channelId, channelType);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -16,7 +16,6 @@
|
||||
|
||||
#include "lnn_distributed_net_ledger.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_app_info.h"
|
||||
#include "softbus_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -25,7 +25,6 @@
|
||||
#include "softbus_proxychannel_manager.h"
|
||||
#include "softbus_proxychannel_message.h"
|
||||
#include "softbus_proxychannel_transceiver.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "trans_log.h"
|
||||
#include "trans_event.h"
|
||||
|
||||
@ -56,7 +55,7 @@ int32_t TransProxySendInnerMessage(ProxyChannelInfo *info, const char *payLoad,
|
||||
|
||||
static int32_t SetCipherOfHandshakeMsg(uint32_t channelId, uint8_t *cipher)
|
||||
{
|
||||
int64_t authId = TransProxyGetAuthId(channelId);
|
||||
int64_t authId = TransProxyGetAuthId((int32_t)channelId);
|
||||
if (authId == AUTH_INVALID_ID) {
|
||||
TRANS_LOGE(TRANS_CTRL, "get authId fail");
|
||||
return SOFTBUS_ERR;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user