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

Signed-off-by: xingchu <weiqian22@huawei.com>
This commit is contained in:
xingchu 2024-10-23 02:19:10 +00:00 committed by Gitee
commit f3e8e59eef
115 changed files with 1726 additions and 604 deletions

View File

@ -70,6 +70,8 @@ bool JSON_AddBytesToObject(JsonObj *obj, const char *key, uint8_t *value, uint32
bool JSON_GetBytesFromObject(const JsonObj *obj, const char *key, uint8_t *value, uint32_t bufLen, uint32_t *size);
bool JSON_IsArrayExist(const JsonObj *obj, const char *key);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -370,4 +370,23 @@ bool JSON_GetBytesFromObject(const JsonObj *obj, const char *key, uint8_t *value
}
*size = bytes.size();
return true;
}
bool JSON_IsArrayExist(const JsonObj *obj, const char *key)
{
if (obj == nullptr || key == nullptr) {
COMM_LOGE(COMM_ADAPTER, "input invalid");
return false;
}
nlohmann::json *json = reinterpret_cast<nlohmann::json *>(obj->context);
if (json == nullptr) {
COMM_LOGE(COMM_ADAPTER, "invaild json param");
return false;
}
if (!json->contains(key)) {
COMM_LOGW(COMM_ADAPTER, "key does not exist");
return false;
}
nlohmann::json item = (*json)[key];
return item.is_array();
}

View File

@ -442,8 +442,8 @@ uint8_t *AssembleRspData(const SoftbusBroadcastPayload *data, uint16_t *dataLen)
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_BC_ADAPTER_PARSE_FAIL;
DISC_LOGW(DISC_BLE_ADAPTER, "parse flag failed");
return SOFTBUS_OK;
}
dst->data.flag = advData[index + 1];
dst->data.isSupportFlag = true;
@ -454,8 +454,8 @@ static int32_t ParseLocalName(const uint8_t *advData, uint8_t advLen, SoftBusBcS
uint8_t len)
{
if (index + 1 >= advLen) {
DISC_LOGE(DISC_BLE_ADAPTER, "parse local name failed");
return SOFTBUS_BC_ADAPTER_PARSE_FAIL;
DISC_LOGW(DISC_BLE_ADAPTER, "parse local name failed");
return SOFTBUS_OK;
}
if (memcpy_s(dst->localName, sizeof(dst->localName), &advData[index + 1], len - 1) != EOK) {
DISC_LOGE(DISC_BLE_ADAPTER, "copy local name failed");

View File

@ -30,6 +30,15 @@ extern "C" {
#define GROUP_TYPE_MESH (1 << 2)
#define GROUP_TYPE_COMPATIBLE (1 << 3)
#define SOFTBUS_AUTH_HICHAIN_LOCAL_IDENTITY_NOT_EXIST \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x040C)))
#define SOFTBUS_AUTH_HICHAIN_GROUP_NOT_EXIST \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x0607)))
#define SOFTBUS_AUTH_HICHAIN_NO_CANDIDATE_GROUP \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x0504)))
#define SOFTBUS_AUTH_HICHAIN_PROOF_MISMATCH \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x100D)))
typedef struct {
void (*onGroupCreated)(const char *groupId, int32_t groupType);
void (*onGroupDeleted)(const char *groupId, int32_t groupType);

View File

@ -34,12 +34,6 @@
#include "softbus_adapter_mem.h"
#define DELAY_AUTH_TIME (8 * 1000L)
#define SOFTBUS_AUTH_HICHAIN_LOCAL_IDENTITY_NOT_EXIST \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x040C)))
#define SOFTBUS_AUTH_HICHAIN_GROUP_NOT_EXIST \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x0607)))
#define SOFTBUS_AUTH_HICHAIN_NO_CANDIDATE_GROUP \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x0504)))
static AuthVerifyListener g_verifyListener = { 0 };
static GroupChangeListener g_groupChangeListener = { 0 };

View File

@ -25,6 +25,7 @@
#include "bus_center_manager.h"
#include "device_auth.h"
#include "lnn_event.h"
#include "lnn_net_builder.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_json_utils.h"
@ -46,7 +47,7 @@
#define ERRCODE_SHIFT_16BIT 16
#define ERRCODE_SHIFT_12BIT 12
#define ERRCODE_SHIFT_8BIT 8
#define SHORT_UDID_HASH_LEN 8
typedef struct {
char groupId[GROUPID_BUF_LEN];
@ -221,6 +222,42 @@ static DeviceAuthCallback g_hichainCallback = {
.onRequest = OnRequest
};
static int32_t GetUdidHash(const char *udid, char *udidHash)
{
if (udid == NULL || udidHash == NULL) {
AUTH_LOGE(AUTH_HICHAIN, "param error");
return SOFTBUS_INVALID_PARAM;
}
int32_t rc = SOFTBUS_OK;
uint8_t hash[UDID_HASH_LEN] = { 0 };
rc = SoftBusGenerateStrHash((uint8_t *)udid, strlen(udid), hash);
if (rc != SOFTBUS_OK) {
AUTH_LOGE(AUTH_HICHAIN, "generate udidhash fail");
return rc;
}
rc = ConvertBytesToHexString(udidHash, HB_SHORT_UDID_HASH_HEX_LEN + 1, hash, SHORT_UDID_HASH_LEN);
if (rc != SOFTBUS_OK) {
AUTH_LOGE(AUTH_HICHAIN, "convert bytes to string fail");
return rc;
}
return SOFTBUS_OK;
}
static void DeletePcRestrictNode(const char *udid)
{
char peerUdidHash[HB_SHORT_UDID_HASH_HEX_LEN + 1] = { 0 };
uint32_t count = 0;
char *anonyUdid = NULL;
Anonymize(udid, &anonyUdid);
if (GetUdidHash(udid, peerUdidHash) == SOFTBUS_OK &&
GetNodeFromPcRestrictMap(peerUdidHash, &count) == SOFTBUS_OK) {
DeleteNodeFromPcRestrictMap(peerUdidHash);
AUTH_LOGI(AUTH_HICHAIN, "delete restrict node success. udid=%{public}s", AnonymizeWrapper(anonyUdid));
}
AnonymizeFree(anonyUdid);
}
static int32_t ParseGroupInfo(const char *groupInfoStr, GroupInfo *groupInfo)
{
cJSON *msg = cJSON_Parse(groupInfoStr);
@ -279,6 +316,7 @@ static void OnDeviceBound(const char *udid, const char *groupInfo)
AnonymizeFree(anonyUdid);
if (info.groupType == AUTH_IDENTICAL_ACCOUNT_GROUP) {
AUTH_LOGI(AUTH_HICHAIN, "ignore same account udid");
DeletePcRestrictNode(udid);
return;
}
char localUdid[UDID_BUF_LEN] = { 0 };

View File

@ -39,6 +39,7 @@
#include "lnn_event.h"
#include "lnn_feature_capability.h"
#include "lnn_net_builder.h"
#include "lnn_net_builder_process.h"
#include "softbus_adapter_hitrace.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
@ -982,12 +983,29 @@ void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info)
NotifyAuthResult(authHandle, info);
}
static void GetPeerUdid(const AuthSessionInfo *info, int32_t reason)
{
if (reason == SOFTBUS_AUTH_HICHAIN_NO_CANDIDATE_GROUP || reason == SOFTBUS_AUTH_HICHAIN_PROOF_MISMATCH) {
LnnConnectionFsm *connFsm = FindConnectionFsmByRequestId(info->requestId);
if (connFsm == NULL || connFsm->isDead) {
AUTH_LOGE(AUTH_FSM, "can not find connection fsm. requestId=%{public}u", info->requestId);
return;
}
AUTH_LOGI(AUTH_FSM, "find connFsm success");
if (strcpy_s(connFsm->connInfo.infoReport.peerUdid, UDID_BUF_LEN, info->udid) != EOK) {
AUTH_LOGE(AUTH_FSM, "strcpy_s udid fail");
return;
}
}
}
void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason)
{
AUTH_CHECK_AND_RETURN_LOGE(info != NULL, AUTH_FSM, "auth session info is null");
AUTH_CHECK_AND_RETURN_LOGE(CheckAuthConnInfoType(&info->connInfo), AUTH_FSM, "connInfo type error");
AUTH_LOGE(AUTH_FSM, "SetAuthFailed: authSeq=%{public}" PRId64 ", requestId=%{public}u, reason=%{public}d", authSeq,
info->requestId, reason);
GetPeerUdid(info, reason);
AuthManager *auth = NULL;
if (info->isSavedSessionKey) {
int64_t authId = GetAuthIdByConnId(info->connId, info->isServer);

View File

@ -471,6 +471,21 @@ static AuthFsm *GetAuthFsmByConnInfo(const AuthConnInfo *connInfo, bool isServer
return NULL;
}
static void ProcessTimeoutErrorCode(AuthFsm *authFsm, int32_t *result)
{
AuthFsmStateIndex curState = authFsm->curState;
if (curState == STATE_SYNC_NEGOTIATION || curState == STATE_SYNC_DEVICE_ID) {
*result = SOFTBUS_AUTH_SYNC_DEVICEID_TIMEOUT;
} else if (curState == STATE_DEVICE_AUTH) {
*result = (authFsm->info.normalizedType == NORMALIZED_SUPPORT || authFsm->info.isSupportFastAuth) ?
SOFTBUS_AUTH_SAVE_SESSIONKEY_TIMEOUT : SOFTBUS_AUTH_HICHAIN_TIMEOUT;
} else if (curState == STATE_SYNC_DEVICE_INFO) {
*result = SOFTBUS_AUTH_SYNC_DEVICEINFO_TIMEOUT;
} else {
AUTH_LOGE(AUTH_FSM, "authFsm state error, curState=%{public}d", curState);
}
}
static void CompleteAuthSession(AuthFsm *authFsm, int32_t result)
{
SoftbusHitraceStart(SOFTBUS_HITRACE_ID_VALID, (uint64_t)authFsm->authSeq);
@ -500,6 +515,9 @@ static void CompleteAuthSession(AuthFsm *authFsm, int32_t result)
}
}
} else {
if (result == SOFTBUS_AUTH_TIMEOUT) {
ProcessTimeoutErrorCode(authFsm, &result);
}
LnnFsmRemoveMessage(&authFsm->fsm, FSM_MSG_AUTH_TIMEOUT);
if (!authFsm->info.isServer) {
NotifyNormalizeRequestFail(authFsm->authSeq, result);
@ -527,9 +545,11 @@ static void HandleCommonMsg(AuthFsm *authFsm, int32_t msgType, MessagePara *msgP
case FSM_MSG_AUTH_TIMEOUT:
AUTH_LOGE(AUTH_FSM, "auth fsm timeout. authSeq=%{public}" PRId64 "", authFsm->authSeq);
CompleteAuthSession(authFsm, SOFTBUS_AUTH_TIMEOUT);
HichainCancelRequest(authFsm->authSeq);
break;
case FSM_MSG_DEVICE_NOT_TRUSTED:
CompleteAuthSession(authFsm, SOFTBUS_AUTH_HICHAIN_NOT_TRUSTED);
HichainCancelRequest(authFsm->authSeq);
break;
case FSM_MSG_DEVICE_DISCONNECTED:
if (authFsm->info.isNodeInfoReceived && authFsm->info.isCloseAckReceived) {

View File

@ -82,6 +82,7 @@ typedef enum {
NUM_KEY_OS_TYPE,
NUM_KEY_AUTH_CAP,
NUM_KEY_CONN_SUB_FEATURE_CAPA,
NUM_KEY_HB_CAP,
NUM_KEY_END,
BOOL_KEY_BEGIN,
BOOL_KEY_TLV_NEGOTIATION = BOOL_KEY_BEGIN,

View File

@ -56,6 +56,8 @@ int32_t LnnIpcNotifyBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t t
int32_t LnnIpcNotifyNodeStatusChanged(void *info, uint32_t infoTypeLen, int32_t type);
int32_t LnnIpcLocalNetworkIdChanged(void);
int32_t LnnIpcNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen);
int32_t LnnIpcNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode);
int32_t LnnIpcNotifyTimeSyncResult(
const char *pkgName, int32_t pid, const void *info, uint32_t infoTypeLen, int32_t retCode);

View File

@ -209,6 +209,17 @@ int32_t LnnIpcNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t
return SOFTBUS_OK;
}
int32_t LnnIpcNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
(void)deviceId;
(void)deviceIdLen;
(void)deviceTypeId;
(void)errCode;
LNN_LOGI(LNN_EVENT, "not implement");
return SOFTBUS_OK;
}
int32_t LnnIpcNotifyTimeSyncResult(const char *pkgName, int32_t pid, const void *info,
uint32_t infoTypeLen, int32_t retCode)
{

View File

@ -468,6 +468,17 @@ int32_t LnnIpcNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t
return SOFTBUS_OK;
}
int32_t LnnIpcNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
(void)deviceId;
(void)deviceIdLen;
(void)deviceTypeId;
(void)errCode;
LNN_LOGI(LNN_EVENT, "not implement");
return SOFTBUS_OK;
}
int32_t LnnIpcNotifyTimeSyncResult(const char *pkgName, int32_t pid, const void *info,
uint32_t infoTypeLen, int32_t retCode)
{

View File

@ -41,6 +41,8 @@ int32_t ClinetOnNodeBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t t
int32_t ClientOnNodeStatusChanged(void *info, uint32_t infoTypeLen, int32_t type);
int32_t ClinetOnLocalNetworkIdChanged(void);
int32_t ClinetNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen);
int32_t ClientNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode);
int32_t ClientOnTimeSyncResult(
const char *pkgName, int32_t pid, const void *info, uint32_t infoTypeLen, int32_t retCode);
int32_t ClientOnPublishLNNResult(const char *pkgName, int32_t pid, int32_t publishId, int32_t reason);

View File

@ -44,6 +44,8 @@ public:
int32_t OnNodeStatusChanged(const char *pkgName, void *info, uint32_t infoTypeLen, int32_t type) override;
int32_t OnLocalNetworkIdChanged(const char *pkgName) override;
int32_t OnNodeDeviceTrustedChange(const char *pkgName, int32_t type, const char *msg, uint32_t msgLen) override;
int32_t OnHichainProofException(const char *pkgName, const char *deviceId, uint32_t deviceIdLen,
uint16_t deviceTypeId, int32_t errCode) override;
int32_t OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode) override;
void OnPublishLNNResult(int32_t publishId, int32_t reason) override;
void OnRefreshLNNResult(int32_t refreshId, int32_t reason) override;

View File

@ -125,6 +125,26 @@ int32_t ClinetNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t
return SOFTBUS_OK;
}
int32_t ClientNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
std::multimap<std::string, sptr<IRemoteObject>> proxyMap;
SoftbusClientInfoManager::GetInstance().GetSoftbusClientProxyMap(proxyMap);
const char *dmPkgName = "ohos.distributedhardware.devicemanager";
for (const auto proxy : proxyMap) {
if (strcmp(dmPkgName, proxy.first.c_str()) != 0) {
continue;
}
sptr<BusCenterClientProxy> clientProxy = new (std::nothrow) BusCenterClientProxy(proxy.second);
if (clientProxy == nullptr) {
LNN_LOGE(LNN_EVENT, "bus center client proxy is nullptr");
return SOFTBUS_ERR;
}
clientProxy->OnHichainProofException(proxy.first.c_str(), deviceId, deviceIdLen, deviceTypeId, errCode);
}
return SOFTBUS_OK;
}
int32_t ClientOnTimeSyncResult(const char *pkgName, int32_t pid, const void *info,
uint32_t infoTypeLen, int32_t retCode)
{

View File

@ -438,6 +438,52 @@ int32_t BusCenterClientProxy::OnNodeDeviceTrustedChange(const char *pkgName, int
return SOFTBUS_OK;
}
int32_t BusCenterClientProxy::OnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
if (pkgName == nullptr || deviceId == nullptr || deviceIdLen != UDID_BUF_LEN) {
LNN_LOGE(LNN_EVENT, "invalid parameters");
return SOFTBUS_INVALID_PARAM;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LNN_LOGE(LNN_EVENT, "remote is nullptr");
return SOFTBUS_IPC_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LNN_LOGE(LNN_EVENT, "write InterfaceToken failed!");
return SOFTBUS_IPC_ERR;
}
if (!data.WriteCString(pkgName)) {
LNN_LOGE(LNN_EVENT, "write pkgName failed");
return SOFTBUS_IPC_ERR;
}
if (!data.WriteUint32(deviceIdLen)) {
LNN_LOGE(LNN_EVENT, "write deviceId length failed");
return SOFTBUS_IPC_ERR;
}
if (!data.WriteRawData(deviceId, deviceIdLen)) {
LNN_LOGE(LNN_EVENT, "write deviceId failed");
return SOFTBUS_IPC_ERR;
}
if (!data.WriteUint16(deviceTypeId)) {
LNN_LOGE(LNN_EVENT, "write deviceTypeId failed");
return SOFTBUS_IPC_ERR;
}
if (!data.WriteInt32(errCode)) {
LNN_LOGE(LNN_EVENT, "write errcode failed");
return SOFTBUS_IPC_ERR;
}
MessageParcel reply;
MessageOption option = { MessageOption::TF_ASYNC };
if (remote->SendRequest(CLIENT_ON_HICHAIN_PROOF_EXCEPTION, data, reply, option) != 0) {
LNN_LOGE(LNN_EVENT, "send request failed");
return SOFTBUS_IPC_ERR;
}
return SOFTBUS_OK;
}
int32_t BusCenterClientProxy::OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -507,6 +507,12 @@ int32_t LnnIpcNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t
return ClinetNotifyDeviceTrustedChange(type, msg, msgLen);
}
int32_t LnnIpcNotifyHichainProofException(
const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
return ClientNotifyHichainProofException(deviceId, deviceIdLen, deviceTypeId, errCode);
}
int32_t LnnIpcNotifyTimeSyncResult(const char *pkgName, int32_t pid, const void *info,
uint32_t infoTypeLen, int32_t retCode)
{

View File

@ -113,6 +113,7 @@ typedef enum {
UPDATE_SCREEN_STATE_INFO,
UPDATE_BT_STATE_OPEN_INFO,
UPDATE_BT_STATE_CLOSE_INFO,
UPDATE_BR_TURN_ON_INFO,
UPDATE_HB_MAX_INFO,
} LnnHeartbeatUpdateInfoType;
@ -126,6 +127,7 @@ typedef struct {
int32_t preferChannel;
uint8_t shortUuid[HB_SHORT_UUID_LEN];
uint8_t hbVersion;
bool isScreenOn;
} HbRespData;
typedef enum {

View File

@ -342,6 +342,30 @@ static void HbDelaySetHighScanParam(void *para)
}
}
static void HbHandleBleStateChange(SoftBusBtState btState)
{
g_enableState = false;
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_BLE_TURN_ON, state=%{public}d", btState);
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_OPEN_INFO);
ClearAuthLimitMap();
ClearLnnBleReportExtraMap();
HbConditionChanged(false);
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetHighScanParam, NULL, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB async set high param fail");
}
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetNormalScanParam, NULL,
HB_START_DELAY_LEN + HB_SEND_RELAY_LEN_ONCE) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB async set normal param fail");
}
if (LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V3,
STRATEGY_HB_SEND_ADJUSTABLE_PERIOD, false) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat fail");
}
if (btState == SOFTBUS_BR_TURN_ON) {
LnnUpdateHeartbeatInfo(UPDATE_BR_TURN_ON_INFO);
}
}
static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
{
if (info == NULL || info->event != LNN_EVENT_BT_STATE_CHANGED) {
@ -354,19 +378,7 @@ static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
switch (btState) {
case SOFTBUS_BLE_TURN_ON:
case SOFTBUS_BR_TURN_ON:
g_enableState = false;
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_BLE_TURN_ON, state=%{public}d", btState);
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_OPEN_INFO);
ClearAuthLimitMap();
ClearLnnBleReportExtraMap();
HbConditionChanged(false);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetHighScanParam, NULL, 0);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetNormalScanParam, NULL,
HB_START_DELAY_LEN + HB_SEND_RELAY_LEN_ONCE);
if (LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V3,
STRATEGY_HB_SEND_ADJUSTABLE_PERIOD, false) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat fail");
}
HbHandleBleStateChange(btState);
break;
case SOFTBUS_BR_TURN_OFF:
if (SoftBusGetBtState() == BLE_DISABLE) {
@ -1237,6 +1249,10 @@ int32_t LnnTriggerDataLevelHeartbeat(void)
int32_t LnnTriggerDirectHeartbeat(const char *networkId, uint64_t timeout)
{
LNN_LOGD(LNN_HEART_BEAT, "LnnTriggerDirectHeartbeat");
if (networkId == NULL) {
LNN_LOGE(LNN_HEART_BEAT, "networkId is null");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = LnnStartHbByTypeAndStrategyDirectly(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_DIRECT,
false, networkId, timeout);
if (ret != SOFTBUS_OK) {

View File

@ -425,6 +425,21 @@ static void SetDeviceNetCapability(uint32_t *deviceInfoNetCapacity, HbRespData *
LNN_LOGI(LNN_HEART_BEAT, "capability change:%{public}u->%{public}u", oldNetCapa, *deviceInfoNetCapacity);
}
static int32_t SetDeviceScreenStatus(NodeInfo *nodeInfo, bool isScreenOn)
{
if (nodeInfo == NULL) {
LNN_LOGE(LNN_HEART_BEAT, "nodeInfo is null");
return SOFTBUS_INVALID_PARAM;
}
nodeInfo->isScreenOn = isScreenOn;
char *anonyDeviceUdid = NULL;
Anonymize(nodeInfo->deviceInfo.deviceUdid, &anonyDeviceUdid);
LNN_LOGI(LNN_HEART_BEAT, "udid=%{public}s, prepare to set screen status to %{public}s from hbResp",
AnonymizeWrapper(anonyDeviceUdid), isScreenOn ? "on" : "off");
AnonymizeFree(anonyDeviceUdid);
return SOFTBUS_OK;
}
static bool IsStateVersionChanged(
const HbRespData *hbResp, const NodeInfo *deviceInfo, int32_t *stateVersion, ConnectOnlineReason *connectReason)
{
@ -490,8 +505,7 @@ static bool IsNeedConnectOnLine(DeviceInfo *device, HbRespData *hbResp, ConnectO
LNN_LOGI(LNN_HEART_BEAT, "don't support ble direct online because resp data");
return true;
}
int32_t ret;
int32_t stateVersion;
int32_t ret, stateVersion;
NodeInfo deviceInfo;
(void)memset_s(&deviceInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (!IsLocalSupportBleDirectOnline()) {
@ -519,6 +533,7 @@ static bool IsNeedConnectOnLine(DeviceInfo *device, HbRespData *hbResp, ConnectO
}
(void)memset_s(&keyInfo, sizeof(AuthDeviceKeyInfo), 0, sizeof(AuthDeviceKeyInfo));
SetDeviceNetCapability(&deviceInfo.netCapacity, hbResp);
(void)SetDeviceScreenStatus(&deviceInfo, hbResp->isScreenOn);
if ((ret = LnnUpdateRemoteDeviceInfo(&deviceInfo)) != SOFTBUS_OK) {
*connectReason = UPDATE_REMOTE_DEVICE_INFO_FAILED;
LNN_LOGE(LNN_HEART_BEAT, "don't support ble direct online because update device info fail ret=%{public}d", ret);

View File

@ -141,6 +141,13 @@ typedef enum {
LANE_CHANNEL_BUTT,
} WdGuideType;
typedef enum {
RAW_LINK_CHECK_INVALID = -1,
RAW_LINK_CHECK_SUCCESS = 0,
RAW_LINK_CHECK_RETRY = 1,
RAW_LINK_CHECK_TIMEOUT = 2,
} CheckResultType;
typedef struct {
ListNode node;
uint32_t laneReqId;
@ -165,10 +172,10 @@ static SoftBusMutex g_rawLinkLock;
#define INVALID_P2P_REQUEST_ID (-1)
#define LANE_REQ_ID_TYPE_SHIFT 28
#define SHORT_RANGE_PTK_NOT_MATCH_CODE 4
#define BLE_TRIGGER_TIMEOUT 3000
#define BLE_TRIGGER_TIMEOUT 5000
#define SOFTBUS_LNN_PTK_NOT_MATCH (SOFTBUS_ERRNO(SHORT_DISTANCE_MAPPING_MODULE_CODE) + SHORT_RANGE_PTK_NOT_MATCH_CODE)
#define RAW_LINK_CHECK_DELAY (200)
#define RAW_LINK_CHECK_NUM (10)
#define RAW_LINK_CHECK_DELAY (200)
#define RAW_LINK_CHECK_NUM (10)
#define DFX_RECORD_LNN_LANE_SELECT_END(lnnLaneId, lnnConnReqId) \
do { \
@ -923,6 +930,81 @@ static void NotifyLinkSucc(AsyncResultType type, uint32_t requestId, LaneLinkInf
}
}
static int32_t AddRawLinkInfo(uint32_t p2pRequestId, int32_t linkId, LaneLinkInfo *linkInfo)
{
if (linkInfo == NULL) {
LNN_LOGE(LNN_LANE, "linkInfo invalid");
return SOFTBUS_INVALID_PARAM;
}
RawLinkInfoList *rawLinkInfo = (RawLinkInfoList *)SoftBusCalloc(sizeof(RawLinkInfoList));
if (rawLinkInfo == NULL) {
LNN_LOGE(LNN_LANE, "calloc rawLinkInfo fail");
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(&rawLinkInfo->laneLinkInfo, sizeof(LaneLinkInfo), linkInfo, sizeof(LaneLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo memcpy fail.");
SoftBusFree(rawLinkInfo);
return SOFTBUS_MEM_ERR;
}
rawLinkInfo->linkId = linkId;
rawLinkInfo->p2pRequestId = p2pRequestId;
rawLinkInfo->retryTime = RAW_LINK_CHECK_NUM;
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
SoftBusFree(rawLinkInfo);
return SOFTBUS_LOCK_ERR;
}
ListTailInsert(g_rawLinkList, &rawLinkInfo->node);
LNN_LOGI(LNN_LANE, "add rawLinkInfo success, requestId=%{public}u", p2pRequestId);
SoftBusMutexUnlock(&g_rawLinkLock);
return SOFTBUS_OK;
}
static int32_t GetRawLinkInfoByReqId(uint32_t p2pRequestId, RawLinkInfoList *rawLinkInfo)
{
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
return SOFTBUS_LOCK_ERR;
}
RawLinkInfoList *item = NULL;
RawLinkInfoList *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, g_rawLinkList, RawLinkInfoList, node) {
if (item->p2pRequestId == p2pRequestId) {
if (memcpy_s(rawLinkInfo, sizeof(RawLinkInfoList), item, sizeof(RawLinkInfoList)) != EOK) {
LNN_LOGE(LNN_LANE, "raw link info memcpy fail.");
SoftBusMutexUnlock(&g_rawLinkLock);
return SOFTBUS_MEM_ERR;
}
SoftBusMutexUnlock(&g_rawLinkLock);
return SOFTBUS_OK;
}
}
SoftBusMutexUnlock(&g_rawLinkLock);
LNN_LOGI(LNN_LANE, "raw link info not found, requestId=%{public}u.", p2pRequestId);
return SOFTBUS_LANE_NOT_FOUND;
}
static int32_t DelRawLinkInfoByReqId(uint32_t p2pRequestId)
{
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
return SOFTBUS_LOCK_ERR;
}
RawLinkInfoList *item = NULL;
RawLinkInfoList *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, g_rawLinkList, RawLinkInfoList, node) {
if (item->p2pRequestId == p2pRequestId) {
ListDelete(&item->node);
SoftBusFree(item);
SoftBusMutexUnlock(&g_rawLinkLock);
return SOFTBUS_OK;
}
}
SoftBusMutexUnlock(&g_rawLinkLock);
LNN_LOGI(LNN_LANE, "raw link info not found, requestId=%{public}u.", p2pRequestId);
return SOFTBUS_LANE_NOT_FOUND;
}
static int32_t CreateWDLinkInfo(uint32_t p2pRequestId, const struct WifiDirectLink *link, LaneLinkInfo *linkInfo)
{
if (link == NULL || linkInfo == NULL) {
@ -991,73 +1073,121 @@ static bool IsMetaAuthExist(const char *peerIp)
return isExist;
}
static void HandleRawLinkResultWithoutLock(uint32_t p2pRequestId, int32_t reason)
{
RawLinkInfoList rawLinkInfo;
(void)memset_s(&rawLinkInfo, sizeof(RawLinkInfoList), 0, sizeof(RawLinkInfoList));
int32_t ret = GetRawLinkInfoByReqId(p2pRequestId, &rawLinkInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get raw link info fail, requestId=%{public}u", p2pRequestId);
NotifyLinkFail(ASYNC_RESULT_P2P, p2pRequestId, ret);
DisconnectP2pWithoutAuthConn(p2pRequestId, rawLinkInfo.laneLinkInfo.linkInfo.rawWifiDirect.pid);
return;
}
if (reason == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "raw link info check succ, requestId=%{public}u", p2pRequestId);
(void)AddAuthSessionFlag(rawLinkInfo.laneLinkInfo.linkInfo.rawWifiDirect.peerIp, false);
NotifyLinkSucc(ASYNC_RESULT_P2P, rawLinkInfo.p2pRequestId, &rawLinkInfo.laneLinkInfo, rawLinkInfo.linkId);
return;
}
LNN_LOGI(LNN_LANE, "raw link info check fail, requestId=%{public}u, reason=%{public}d",
p2pRequestId, reason);
NotifyLinkFail(ASYNC_RESULT_P2P, rawLinkInfo.p2pRequestId, reason);
DisconnectP2pWithoutAuthConn(rawLinkInfo.p2pRequestId, rawLinkInfo.laneLinkInfo.linkInfo.rawWifiDirect.pid);
}
static void HandleRawLinkResult(RawLinkInfoList *rawLinkInfo, int32_t reason)
{
if (reason == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "raw link info check succ, requestId=%{public}u", rawLinkInfo->p2pRequestId);
(void)AddAuthSessionFlag(rawLinkInfo->laneLinkInfo.linkInfo.rawWifiDirect.peerIp, false);
NotifyLinkSucc(ASYNC_RESULT_P2P, rawLinkInfo->p2pRequestId, &rawLinkInfo->laneLinkInfo, rawLinkInfo->linkId);
SoftBusFree(rawLinkInfo);
return;
}
LNN_LOGI(LNN_LANE, "raw link info check fail, requestId=%{public}u, reason=%{public}d",
rawLinkInfo->p2pRequestId, reason);
NotifyLinkFail(ASYNC_RESULT_P2P, rawLinkInfo->p2pRequestId, reason);
DisconnectP2pWithoutAuthConn(rawLinkInfo->p2pRequestId, rawLinkInfo->laneLinkInfo.linkInfo.rawWifiDirect.pid);
SoftBusFree(rawLinkInfo);
}
static CheckResultType CheckAuthMetaResult(uint32_t p2pRequestId, RawLinkInfoList *rawLinkInfo)
{
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
HandleRawLinkResultWithoutLock(p2pRequestId, SOFTBUS_LOCK_ERR);
(void)DelRawLinkInfoByReqId(p2pRequestId);
return RAW_LINK_CHECK_INVALID;
}
RawLinkInfoList *item = NULL;
RawLinkInfoList *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, g_rawLinkList, RawLinkInfoList, node) {
if (p2pRequestId == item->p2pRequestId) {
if (memcpy_s(rawLinkInfo, sizeof(RawLinkInfoList), item, sizeof(RawLinkInfoList)) != EOK) {
LNN_LOGE(LNN_LANE, "raw link info memcpy fail.");
SoftBusMutexUnlock(&g_rawLinkLock);
return RAW_LINK_CHECK_INVALID;
}
LNN_LOGI(LNN_LANE, "check raw link info, time=%{public}d", item->retryTime);
if (item->retryTime > 0 && IsMetaAuthExist(item->laneLinkInfo.linkInfo.rawWifiDirect.peerIp)) {
SoftBusMutexUnlock(&g_rawLinkLock);
return RAW_LINK_CHECK_SUCCESS;
}
if (item->retryTime > 0 && !IsMetaAuthExist(item->laneLinkInfo.linkInfo.rawWifiDirect.peerIp)) {
item->retryTime--;
SoftBusMutexUnlock(&g_rawLinkLock);
return RAW_LINK_CHECK_RETRY;
}
if (item->retryTime <= 0) {
SoftBusMutexUnlock(&g_rawLinkLock);
return RAW_LINK_CHECK_TIMEOUT;
}
}
}
SoftBusMutexUnlock(&g_rawLinkLock);
LNN_LOGI(LNN_LANE, "raw link info not found, requestId=%{public}u.", p2pRequestId);
return RAW_LINK_CHECK_INVALID;
}
static void CheckRawLinkInfo(void *para)
{
RawLinkInfoList *rawLinkInfo = (RawLinkInfoList *)para;
if (rawLinkInfo == NULL) {
LNN_LOGE(LNN_LANE, "rawLinkInfo invalid");
uint32_t *p2pRequestId = (uint32_t *)para;
if (p2pRequestId == NULL) {
LNN_LOGE(LNN_LANE, "para invalid");
return;
}
LNN_LOGI(LNN_LANE, "check raw link info, requestId=%{public}u", rawLinkInfo->p2pRequestId);
RawLinkInfoList *item = NULL;
RawLinkInfoList *next = NULL;
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
ListDelete(&rawLinkInfo->node);
HandleRawLinkResult(rawLinkInfo, SOFTBUS_LOCK_ERR);
RawLinkInfoList rawLinkInfo;
(void)memset_s(&rawLinkInfo, sizeof(RawLinkInfoList), 0, sizeof(RawLinkInfoList));
CheckResultType ret = CheckAuthMetaResult(*p2pRequestId, &rawLinkInfo);
LNN_LOGI(LNN_LANE, "check raw link info, requestId=%{public}u, ret=%{public}d", *p2pRequestId, ret);
if (ret == RAW_LINK_CHECK_SUCCESS) {
HandleRawLinkResult(&rawLinkInfo, SOFTBUS_OK);
(void)DelRawLinkInfoByReqId(*p2pRequestId);
SoftBusFree(p2pRequestId);
return;
}
LIST_FOR_EACH_ENTRY_SAFE(item, next, g_rawLinkList, RawLinkInfoList, node) {
if (rawLinkInfo->p2pRequestId == item->p2pRequestId && item->retryTime >= 0) {
LNN_LOGI(LNN_LANE, "check raw link info, time=%{public}d", item->retryTime);
if (IsMetaAuthExist(item->laneLinkInfo.linkInfo.rawWifiDirect.peerIp)) {
ListDelete(&rawLinkInfo->node);
SoftBusMutexUnlock(&g_rawLinkLock);
HandleRawLinkResult(item, SOFTBUS_OK);
return;
}
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_LNN), CheckRawLinkInfo, (void *)rawLinkInfo,
RAW_LINK_CHECK_DELAY) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lnn async fail.");
ListDelete(&rawLinkInfo->node);
SoftBusMutexUnlock(&g_rawLinkLock);
HandleRawLinkResult(item, SOFTBUS_LANE_ASYNC_FAIL);
return;
}
item->retryTime--;
SoftBusMutexUnlock(&g_rawLinkLock);
return;
}
if (rawLinkInfo->p2pRequestId == item->p2pRequestId && item->retryTime < 0) {
LNN_LOGI(LNN_LANE, "raw link info time out, requestId=%{public}u", rawLinkInfo->p2pRequestId);
ListDelete(&rawLinkInfo->node);
SoftBusMutexUnlock(&g_rawLinkLock);
HandleRawLinkResult(item, SOFTBUS_OK);
if (ret == RAW_LINK_CHECK_RETRY) {
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_LNN), CheckRawLinkInfo, (void *)p2pRequestId,
RAW_LINK_CHECK_DELAY) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lnn async fail.");
HandleRawLinkResult(&rawLinkInfo, SOFTBUS_LANE_ASYNC_FAIL);
(void)DelRawLinkInfoByReqId(*p2pRequestId);
SoftBusFree(p2pRequestId);
return;
}
return;
}
LNN_LOGI(LNN_LANE, "raw link info not found, requestId=%{public}u", rawLinkInfo->p2pRequestId);
ListDelete(&rawLinkInfo->node);
SoftBusMutexUnlock(&g_rawLinkLock);
HandleRawLinkResult(rawLinkInfo, SOFTBUS_NOT_FIND);
if (ret == RAW_LINK_CHECK_TIMEOUT) {
LNN_LOGI(LNN_LANE, "check raw link info time out");
HandleRawLinkResult(&rawLinkInfo, SOFTBUS_OK);
(void)DelRawLinkInfoByReqId(*p2pRequestId);
SoftBusFree(p2pRequestId);
return;
}
LNN_LOGI(LNN_LANE, "raw link info check fail, requestId=%{public}u", *p2pRequestId);
HandleRawLinkResultWithoutLock(*p2pRequestId, ret);
(void)DelRawLinkInfoByReqId(*p2pRequestId);
SoftBusFree(p2pRequestId);
return;
}
@ -1068,34 +1198,27 @@ static int32_t NotifyRawLinkSucc(uint32_t p2pRequestId, const struct WifiDirectL
NotifyLinkSucc(ASYNC_RESULT_P2P, p2pRequestId, linkInfo, link->linkId);
return SOFTBUS_OK;
}
RawLinkInfoList *rawLinkInfo = (RawLinkInfoList *)SoftBusCalloc(sizeof(RawLinkInfoList));
if (rawLinkInfo == NULL) {
LNN_LOGE(LNN_LANE, "calloc rawLinkInfo fail");
if (AddRawLinkInfo(p2pRequestId, link->linkId, linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "linkInfo memcpy fail.");
return SOFTBUS_LANE_LIST_ERR;
}
uint32_t *requestId = (uint32_t *)SoftBusCalloc(sizeof(uint32_t));
if (requestId == NULL) {
LNN_LOGE(LNN_LANE, "calloc requestId fail");
(void)DelRawLinkInfoByReqId(p2pRequestId);
(void)AddAuthSessionFlag(link->remoteIp, false);
NotifyLinkSucc(ASYNC_RESULT_P2P, p2pRequestId, linkInfo, link->linkId);
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(&rawLinkInfo->laneLinkInfo, sizeof(LaneLinkInfo), linkInfo, sizeof(LaneLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkInfo memcpy fail.");
SoftBusFree(rawLinkInfo);
return SOFTBUS_MEM_ERR;
}
rawLinkInfo->linkId = link->linkId;
rawLinkInfo->p2pRequestId = p2pRequestId;
rawLinkInfo->retryTime = RAW_LINK_CHECK_NUM;
if (SoftBusMutexLock(&g_rawLinkLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock fail.");
SoftBusFree(rawLinkInfo);
return SOFTBUS_LOCK_ERR;
}
ListTailInsert(g_rawLinkList, &rawLinkInfo->node);
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_LNN), CheckRawLinkInfo, (void *)rawLinkInfo,
RAW_LINK_CHECK_DELAY) != SOFTBUS_OK) {
ListDelete(&rawLinkInfo->node);
SoftBusFree(rawLinkInfo);
*requestId = p2pRequestId;
if (LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_LNN), CheckRawLinkInfo, (void *)requestId,
RAW_LINK_CHECK_DELAY) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lnn async fail.");
SoftBusMutexUnlock(&g_rawLinkLock);
(void)DelRawLinkInfoByReqId(p2pRequestId);
SoftBusFree(requestId);
return SOFTBUS_LANE_ASYNC_FAIL;
}
SoftBusMutexUnlock(&g_rawLinkLock);
return SOFTBUS_OK;
}
@ -1118,7 +1241,7 @@ static void OnWifiDirectConnectSuccess(uint32_t p2pRequestId, const struct WifiD
p2pRequestId, linkInfo.type, link->linkId, link->isReuse);
if (linkInfo.type == LANE_HML_RAW && link->isReuse) {
ret = NotifyRawLinkSucc(p2pRequestId, link, &linkInfo);
if (ret != SOFTBUS_OK) {
if (ret != SOFTBUS_OK && ret != SOFTBUS_MALLOC_ERR) {
goto FAIL;
}
} else {
@ -1347,7 +1470,8 @@ static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason)
HandleGuideChannelAsyncFail(ASYNC_RESULT_P2P, p2pRequestId, reason);
return;
}
if (reason == SOFTBUS_CONN_CONNECT_GROUP_TIMEOUT || reason == SOFTBUS_CONN_HV2_BLE_TRIGGER_TIMEOUT) {
if (reason == SOFTBUS_CONN_HV3_WAIT_CONNECTION_TIMEOUT ||
reason == SOFTBUS_CONN_HV2_BLE_TRIGGER_TIMEOUT) {
HandleActionTriggerError(p2pRequestId);
}
LinkConflictType conflictType = GetConflictTypeWithErrcode(reason);
@ -2874,7 +2998,7 @@ static void LnnDestroyWifiDirectInfo(void)
return;
}
if (SoftBusMutexLock(&g_AuthTagLock) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lock list err");
LNN_LOGE(LNN_LANE, "lock session list fail");
return;
}
AuthSessionServer *sessionItem = NULL;
@ -2898,9 +3022,9 @@ static void LnnDestroyWifiDirectInfo(void)
ListDelete(&rawLinkItem->node);
SoftBusFree(rawLinkItem);
}
SoftBusMutexUnlock(&g_rawLinkLock);
SoftBusFree(g_rawLinkList);
g_rawLinkList = NULL;
SoftBusMutexUnlock(&g_rawLinkLock);
(void)SoftBusMutexDestroy(&g_rawLinkLock);
}

View File

@ -35,9 +35,9 @@ typedef struct {
int32_t LnnInitCipherKeyManager(void);
void LnnDeinitCipherKeyManager(void);
bool GetCipherKeyByNetworkId(const char *networkId, int32_t seq, uint32_t tableIndex, unsigned char *key,
bool GetCipherKeyByNetworkId(const char *networkId, int32_t seq, uint32_t tableIndex, AesCtrCipherKey *cipherkey,
int32_t keyLen);
bool GetLocalCipherKey(int32_t seq, uint32_t *tableIndex, unsigned char *key, int32_t keyLen);
bool GetLocalCipherKey(int32_t seq, uint32_t *tableIndex, AesCtrCipherKey *cipherkey, int32_t keyLen);
void LoadBleBroadcastKey(void);
bool IsCipherManagerFindKey(const char *udid);
bool PackCipherKeySyncMsg(void *json);

View File

@ -29,6 +29,7 @@
extern "C" {
#endif
LnnConnectionFsm *FindConnectionFsmByRequestId(uint32_t requestId);
int32_t FindRequestIdByAddr(ConnectionAddr *connetionAddr, uint32_t *requestId);
void NetBuilderMessageHandler(SoftBusMessage *msg);
LnnConnectionFsm *FindConnectionFsmByAddr(const ConnectionAddr *addr, bool isShort);

View File

@ -29,14 +29,23 @@ void LnnDeinitCipherKeyManager(void)
LNN_LOGI(LNN_INIT, "Deinit virtual lnn cipherkey manager");
}
bool GetCipherKeyByNetworkId(const char *networkId, int32_t seq, uint32_t tableIndex, unsigned char *key,
bool GetCipherKeyByNetworkId(const char *networkId, int32_t seq, uint32_t tableIndex, AesCtrCipherKey *cipherkey,
int32_t keyLen)
{
(void)networkId;
(void)seq;
(void)tableIndex;
(void)cipherkey;
(void)keyLen;
return true;
}
bool GetLocalCipherKey(int32_t seq, uint32_t *tableIndex, unsigned char *key, int32_t keyLen)
bool GetLocalCipherKey(int32_t seq, uint32_t *tableIndex, AesCtrCipherKey *cipherkey, int32_t keyLen)
{
(void)seq;
(void)tableIndex;
(void)cipherkey;
(void)keyLen;
return true;
}

View File

@ -78,8 +78,7 @@ typedef enum {
#define CONN_CODE_SHIFT 16
#define PC_DEV_TYPE "00C"
#define SOFTBUS_AUTH_HICHAIN_NO_CANDIDATE_GROUP \
(-(((SOFTBUS_SUB_SYSTEM) << 21) | ((AUTH_SUB_MODULE_CODE) << 16) | (0x0504)))
typedef enum {
FSM_MSG_TYPE_JOIN_LNN,
FSM_MSG_TYPE_AUTH_DONE,
@ -508,7 +507,7 @@ static int32_t GetUdidHashForDfx(char *localUdidHash, char *peerUdidHash, LnnCon
const NodeInfo *localInfo = LnnGetLocalNodeInfo();
if (localInfo == NULL) {
LNN_LOGE(LNN_BUILDER, "localInfo is NULL");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GET_LOCAL_NODE_INFO_ERR;
}
uint8_t hash[UDID_HASH_LEN] = { 0 };
rc = SoftBusGenerateStrHash((uint8_t *)localInfo->deviceInfo.deviceUdid, strlen(localInfo->deviceInfo.deviceUdid),
@ -767,6 +766,22 @@ static void GetConnectOnlineReason(LnnConntionInfo *connInfo, uint32_t *connOnli
*connOnlineReason, connectReason, peerReason, localReason);
}
static void NotifyProofExceptionEvent(const LnnConntionInfo *connInfo, int32_t reason, const char *peerDeviceType)
{
if ((reason == SOFTBUS_AUTH_HICHAIN_NO_CANDIDATE_GROUP || reason == SOFTBUS_AUTH_HICHAIN_PROOF_MISMATCH) &&
(strncmp(peerDeviceType, PC_DEV_TYPE, strlen(PC_DEV_TYPE)) == 0)) {
LnnNotifyHichainProofException(
connInfo->infoReport.peerUdid, UDID_BUF_LEN, (uint16_t)connInfo->infoReport.type, reason);
char *anonyUdid = NULL;
Anonymize(connInfo->infoReport.peerUdid, &anonyUdid);
LNN_LOGE(LNN_BUILDER,
"notify hichain proof exception event, udid=%{public}s, reason=%{public}d, type=%{public}hu",
AnonymizeWrapper(anonyUdid), reason, (uint16_t)connInfo->infoReport.type);
AnonymizeFree(anonyUdid);
}
}
static void DfxRecordLnnAddOnlineNodeEnd(LnnConntionInfo *connInfo, int32_t onlineNum, int32_t lnnType, int32_t reason)
{
LnnEventExtra extra = { 0 };
@ -793,6 +808,7 @@ static void DfxRecordLnnAddOnlineNodeEnd(LnnConntionInfo *connInfo, int32_t onli
extra.localDeviceType = dfxConnectInfo.localDeviceType;
extra.peerDeviceType = dfxConnectInfo.peerDeviceType;
extra.connOnlineReason = connOnlineReason;
NotifyProofExceptionEvent(connInfo, reason, extra.peerDeviceType);
if (connInfo->nodeInfo == NULL) {
DfxReportOnlineEvent(connInfo, reason, extra);
return;
@ -991,7 +1007,7 @@ static void CompleteLeaveLNN(LnnConnectionFsm *connFsm, const char *networkId, i
static int32_t OnJoinFail(LnnConnectionFsm *connFsm, int32_t retCode)
{
if (CheckDeadFlag(connFsm, true)) {
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_CONN_FSM_DEAD;
}
CompleteJoinLNN(connFsm, NULL, retCode);
return SOFTBUS_OK;
@ -1014,25 +1030,26 @@ static void FilterRetrieveDeviceInfo(NodeInfo *info)
static int32_t LnnRecoveryBroadcastKey()
{
int32_t ret = SOFTBUS_ERR;
if (LnnLoadLocalBroadcastCipherKey() != SOFTBUS_OK) {
int32_t ret = LnnLoadLocalBroadcastCipherKey();
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "load BroadcastCipherInfo fail");
return ret;
}
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
do {
if (LnnGetLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
ret = LnnGetLocalBroadcastCipherKey(&broadcastKey);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local info failed");
break;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY, broadcastKey.cipherInfo.key,
SESSION_KEY_LENGTH) != SOFTBUS_OK) {
ret = LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY, broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set key failed");
break;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, broadcastKey.cipherInfo.iv,
BROADCAST_IV_LEN) != SOFTBUS_OK) {
ret = LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set iv failed");
break;
}
@ -1079,7 +1096,7 @@ static int32_t BleDirectOnline(LnnConntionInfo *connInfo, AuthConnInfo *authConn
return SOFTBUS_OK;
}
}
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_BLE_DIRECT_FAILED;
}
static int32_t OnJoinLNN(LnnConnectionFsm *connFsm)
@ -1089,7 +1106,7 @@ static int32_t OnJoinLNN(LnnConnectionFsm *connFsm)
LnnConntionInfo *connInfo = &connFsm->connInfo;
if (CheckDeadFlag(connFsm, true)) {
NotifyJoinResult(connFsm, NULL, SOFTBUS_NETWORK_CONN_FSM_DEAD);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_CONN_FSM_DEAD;
}
LNN_CHECK_AND_RETURN_RET_LOGW(connInfo->authHandle.authId <= 0, SOFTBUS_OK, LNN_BUILDER,
"[id=%{public}u]join LNN is ongoing, waiting...", connFsm->id);
@ -1114,10 +1131,10 @@ static int32_t OnJoinLNN(LnnConnectionFsm *connFsm)
}
}
DfxRecordConnAuthStart(&authConn, connFsm, connInfo->requestId);
if (AuthStartVerify(&authConn, connInfo->requestId, LnnGetVerifyCallback(), AUTH_MODULE_LNN, true) != SOFTBUS_OK) {
rc = AuthStartVerify(&authConn, connInfo->requestId, LnnGetVerifyCallback(), AUTH_MODULE_LNN, true);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "auth verify device failed. [id=%{public}u]", connFsm->id);
CompleteJoinLNN(connFsm, NULL, SOFTBUS_ERR);
rc = SOFTBUS_ERR;
} else {
LnnFsmPostMessageDelay(&connFsm->fsm, FSM_MSG_TYPE_JOIN_LNN_TIMEOUT, NULL, JOIN_LNN_TIMEOUT_LEN);
rc = SOFTBUS_OK;
@ -1141,25 +1158,26 @@ static int32_t LnnFillConnInfo(LnnConntionInfo *connInfo)
nodeInfo->authChannelId[connInfo->addr.type][isAuthServer ? AUTH_AS_SERVER_SIDE : AUTH_AS_CLIENT_SIDE] =
(int32_t)connInfo->authHandle.authId;
nodeInfo->relation[connInfo->addr.type]++;
if (AuthGetVersion(connInfo->authHandle.authId, &version) != SOFTBUS_OK) {
int32_t ret = AuthGetVersion(connInfo->authHandle.authId, &version);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fill version fail");
return SOFTBUS_ERR;
return ret;
}
connInfo->version = version;
if (AuthGetDeviceUuid(connInfo->authHandle.authId, nodeInfo->uuid, sizeof(nodeInfo->uuid)) != SOFTBUS_OK ||
nodeInfo->uuid[0] == '\0') {
ret = AuthGetDeviceUuid(connInfo->authHandle.authId, nodeInfo->uuid, sizeof(nodeInfo->uuid));
if (ret != SOFTBUS_OK || nodeInfo->uuid[0] == '\0') {
LNN_LOGE(LNN_BUILDER, "fill uuid fail");
return SOFTBUS_ERR;
return ret;
}
if (connInfo->addr.type == CONNECTION_ADDR_ETH || connInfo->addr.type == CONNECTION_ADDR_WLAN) {
if (strcpy_s(nodeInfo->connectInfo.deviceIp, MAX_ADDR_LEN, connInfo->addr.info.ip.ip) != EOK) {
LNN_LOGE(LNN_BUILDER, "fill deviceIp fail");
return SOFTBUS_MEM_ERR;
return SOFTBUS_STRCPY_ERR;
}
}
if (strcpy_s(connInfo->peerNetworkId, sizeof(connInfo->peerNetworkId), nodeInfo->networkId) != EOK) {
LNN_LOGE(LNN_BUILDER, "fill networkId fail");
return SOFTBUS_MEM_ERR;
return SOFTBUS_STRCPY_ERR;
}
return SOFTBUS_OK;
}
@ -1235,7 +1253,7 @@ static int32_t OnAuthDone(LnnConnectionFsm *connFsm, int32_t *retCode)
}
if (CheckDeadFlag(connFsm, true)) {
SoftBusFree(retCode);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_CONN_FSM_DEAD;
}
LNN_LOGI(LNN_BUILDER,
@ -1562,11 +1580,11 @@ static int32_t SyncBrOffline(const LnnConnectionFsm *connFsm)
if (connFsm->connInfo.addr.type != CONNECTION_ADDR_BR) {
LNN_LOGI(LNN_BUILDER, "just br need send offline");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_LEAVE_OFFLINE;
}
if (!((connFsm->connInfo.flag & LNN_CONN_INFO_FLAG_LEAVE_REQUEST) != 0)) {
LNN_LOGI(LNN_BUILDER, "just leave lnn request need send offline");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_LEAVE_OFFLINE;
}
(void)LnnConvertDlId(connFsm->connInfo.peerNetworkId, CATEGORY_NETWORK_ID, CATEGORY_UUID, uuid, UUID_BUF_LEN);
code = LnnGetCnnCode(uuid, DISCOVERY_TYPE_BR);
@ -1580,7 +1598,7 @@ static int32_t SyncBrOffline(const LnnConnectionFsm *connFsm)
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_OFFLINE, connFsm->connInfo.peerNetworkId,
(uint8_t *)&combinedInt, sizeof(int32_t), LnnSyncOfflineComplete) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send sync offline fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SEND_SYNC_INFO_FAILED;
}
return SOFTBUS_OK;
}
@ -1688,11 +1706,11 @@ static int32_t InitConnectionStateMachine(LnnConnectionFsm *connFsm)
if (sprintf_s(connFsm->fsmName, LNN_CONNECTION_FSM_NAME_LEN, "LnnConnFsm-%u", connFsm->id) == -1) {
LNN_LOGE(LNN_BUILDER, "format lnn connection fsm name failed");
return SOFTBUS_ERR;
return SOFTBUS_SPRINTF_ERR;
}
if (LnnFsmInit(&connFsm->fsm, NULL, connFsm->fsmName, ConnectionFsmDinitCallback) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "init fsm failed");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_FSM_INIT_FAILED;
}
for (i = 0; i < STATE_NUM_MAX; ++i) {
LnnFsmAddState(&connFsm->fsm, &g_states[i]);
@ -1760,9 +1778,10 @@ int32_t LnnStartConnectionFsm(LnnConnectionFsm *connFsm)
LNN_LOGE(LNN_BUILDER, "connection fsm is null");
return SOFTBUS_INVALID_PARAM;
}
if (LnnFsmStart(&connFsm->fsm, g_states + STATE_AUTH_INDEX) != SOFTBUS_OK) {
int32_t ret = LnnFsmStart(&connFsm->fsm, g_states + STATE_AUTH_INDEX);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "start connection fsm failed. [id=%{public}u]", connFsm->id);
return SOFTBUS_ERR;
return ret;
}
LNN_LOGI(LNN_BUILDER, "connection fsm is starting. [id=%{public}u]", connFsm->id);
return SOFTBUS_OK;
@ -1775,9 +1794,10 @@ int32_t LnnStopConnectionFsm(LnnConnectionFsm *connFsm, LnnConnectionFsmStopCall
return SOFTBUS_INVALID_PARAM;
}
connFsm->stopCallback = callback;
if (LnnFsmStop(&connFsm->fsm) != SOFTBUS_OK) {
int32_t ret = LnnFsmStop(&connFsm->fsm);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "stop connection fsm failed. [id=%{public}u]", connFsm->id);
return SOFTBUS_ERR;
return ret;
}
return LnnFsmDeinit(&connFsm->fsm);
}
@ -1792,7 +1812,7 @@ int32_t LnnSendJoinRequestToConnFsm(LnnConnectionFsm *connFsm)
if ((connFsm->connInfo.addr.type == CONNECTION_ADDR_BLE || connFsm->connInfo.addr.type == CONNECTION_ADDR_BR) &&
SoftBusGetBtState() != BLE_ENABLE) {
LNN_LOGE(LNN_BUILDER, "send join request while bt is turn off");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_BLE_DISABLE;
}
return LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_JOIN_LNN, NULL);
}
@ -1814,7 +1834,7 @@ int32_t LnnSendAuthResultMsgToConnFsm(LnnConnectionFsm *connFsm, int32_t retCode
if (LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_AUTH_DONE, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post auth result message to connFsm fail");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_AUTH_SEND_FAIL;
}
return SOFTBUS_OK;
}
@ -1841,7 +1861,7 @@ int32_t LnnSendLeaveRequestToConnFsm(LnnConnectionFsm *connFsm)
{
if (!CheckInterfaceCommonArgs(connFsm, true)) {
LNN_LOGE(LNN_BUILDER, "connFsm is invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_LEAVE_LNN, NULL);
}
@ -1850,7 +1870,7 @@ int32_t LnnSendSyncOfflineFinishToConnFsm(LnnConnectionFsm *connFsm)
{
if (!CheckInterfaceCommonArgs(connFsm, true)) {
LNN_LOGE(LNN_BUILDER, "connFsm is invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_SYNC_OFFLINE_DONE, NULL);
}
@ -1859,7 +1879,7 @@ int32_t LnnSendNewNetworkOnlineToConnFsm(LnnConnectionFsm *connFsm)
{
if (!CheckInterfaceCommonArgs(connFsm, true)) {
LNN_LOGE(LNN_BUILDER, "connFsm is invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_INITIATE_ONLINE, NULL);
}

View File

@ -71,15 +71,8 @@ int32_t LnnInitNetLedger(void)
return SOFTBUS_OK;
}
static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
static bool IsCapacityChange(NodeInfo *info)
{
char softBusVersion[VERSION_MAX_LEN] = { 0 };
if (LnnGetLocalStrInfo(STRING_KEY_HICE_VERSION, softBusVersion, sizeof(softBusVersion)) == SOFTBUS_OK) {
if (strcmp(softBusVersion, info->softBusVersion) != 0) {
LNN_LOGW(LNN_LEDGER, "softbus version=%{public}s->%{public}s", softBusVersion, info->softBusVersion);
return true;
}
}
uint64_t softbusFeature = 0;
if (LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, &softbusFeature) == SOFTBUS_OK) {
if (softbusFeature != info->feature) {
@ -87,6 +80,35 @@ static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
return true;
}
}
uint32_t authCapacity = 0;
if (LnnGetLocalNumU32Info(NUM_KEY_AUTH_CAP, &authCapacity) == SOFTBUS_OK) {
if (authCapacity != info->authCapacity) {
LNN_LOGW(LNN_LEDGER, "authCapacity=%{public}d->%{public}d", info->authCapacity, authCapacity);
return true;
}
}
uint32_t heartbeatCapacity = 0;
if (LnnGetLocalNumU32Info(NUM_KEY_HB_CAP, &heartbeatCapacity) == SOFTBUS_OK) {
if (heartbeatCapacity != info->heartbeatCapacity) {
LNN_LOGW(LNN_LEDGER, "hbCapacity=%{public}d->%{public}d", info->heartbeatCapacity, heartbeatCapacity);
return true;
}
}
return false;
}
static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
{
if (IsCapacityChange(info)) {
return true;
}
char softBusVersion[VERSION_MAX_LEN] = { 0 };
if (LnnGetLocalStrInfo(STRING_KEY_HICE_VERSION, softBusVersion, sizeof(softBusVersion)) == SOFTBUS_OK) {
if (strcmp(softBusVersion, info->softBusVersion) != 0) {
LNN_LOGW(LNN_LEDGER, "softbus version=%{public}s->%{public}s", softBusVersion, info->softBusVersion);
return true;
}
}
char *anonyNewUuid = NULL;
char uuid[UUID_BUF_LEN] = { 0 };
if ((LnnGetLocalStrInfo(STRING_KEY_UUID, uuid, UUID_BUF_LEN) == SOFTBUS_OK) && (strcmp(uuid, info->uuid) != 0)) {
@ -102,13 +124,6 @@ static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
return true;
}
}
uint32_t authCapacity = 0;
if (LnnGetLocalNumU32Info(NUM_KEY_AUTH_CAP, &authCapacity) == SOFTBUS_OK) {
if (authCapacity != info->authCapacity) {
LNN_LOGW(LNN_LEDGER, "authCapacity=%{public}d->%{public}d", info->authCapacity, authCapacity);
return true;
}
}
int32_t level = 0;
if ((LnnGetLocalNumInfo(NUM_KEY_DEVICE_SECURITY_LEVEL, &level) == SOFTBUS_OK) &&
(level != info->deviceSecurityLevel)) {

View File

@ -720,6 +720,17 @@ static int32_t LlGetAuthCapability(void *buf, uint32_t len)
return SOFTBUS_OK;
}
static int32_t LlGetHbCapability(void *buf, uint32_t len)
{
NodeInfo *info = &g_localNetLedger.localInfo;
if (buf == NULL || len != sizeof(uint32_t)) {
LNN_LOGE(LNN_LEDGER, "buf of heartbeatCapacity is null");
return SOFTBUS_INVALID_PARAM;
}
*((int32_t *)buf) = info->heartbeatCapacity;
return SOFTBUS_OK;
}
static int32_t L1GetMasterNodeWeight(void *buf, uint32_t len)
{
NodeInfo *info = &g_localNetLedger.localInfo;
@ -1811,6 +1822,7 @@ static LocalLedgerKey g_localKeyTable[] = {
{NUM_KEY_DEV_TYPE_ID, -1, LlGetDeviceTypeId, NULL},
{NUM_KEY_OS_TYPE, -1, LlGetOsType, NULL},
{NUM_KEY_AUTH_CAP, -1, LlGetAuthCapability, NULL},
{NUM_KEY_HB_CAP, -1, LlGetHbCapability, NULL},
{NUM_KEY_MASTER_NODE_WEIGHT, -1, L1GetMasterNodeWeight, UpdateMasgerNodeWeight},
{NUM_KEY_P2P_ROLE, -1, L1GetP2pRole, UpdateP2pRole},
{NUM_KEY_STATE_VERSION, -1, LlGetStateVersion, UpdateStateVersion},

View File

@ -253,6 +253,7 @@ void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type);
void LnnNotifyNodeStatusChanged(NodeStatus *info, NodeStatusType type);
void LnnNotifyLocalNetworkIdChanged(void);
void LnnNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen);
void LnnNotifyHichainProofException(const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode);
void LnnNotifyMigrate(bool isOnline, NodeBasicInfo *info);
void LnnNotifyWlanStateChangeEvent(void *state);

View File

@ -459,6 +459,15 @@ void LnnNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen
(void)LnnIpcNotifyDeviceTrustedChange(type, msg, msgLen);
}
void LnnNotifyHichainProofException(const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
if (deviceId == NULL || deviceIdLen != UDID_BUF_LEN) {
LNN_LOGE(LNN_EVENT, "deviceId is invalid");
return;
}
(void)LnnIpcNotifyHichainProofException(deviceId, deviceIdLen, deviceTypeId, errCode);
}
void LnnNotifyJoinResult(ConnectionAddr *addr, const char *networkId, int32_t retCode)
{
if (addr == NULL) {

View File

@ -37,7 +37,7 @@ extern "C" {
CONN_ASSIGNER(Errcode, Result, result)
CONN_ASSIGNER(Errcode, Errcode, errcode)
CONN_ASSIGNER(Int32, ConnectionId, connectionId)
CONN_ASSIGNER(Int32, ConnReqId, requestId)
CONN_ASSIGNER(Errcode, ConnReqId, requestId)
CONN_ASSIGNER(Int32, LinkType, linkType)
CONN_ASSIGNER(Int32, AuthType, authType)
CONN_ASSIGNER(Int32, AuthId, authId)
@ -73,8 +73,15 @@ CONN_ASSIGNER(Errcode, IsRenegotiate, isRenegotiate)
CONN_ASSIGNER(Errcode, IsReuse, isReuse)
CONN_ASSIGNER(Uint64, NegotiateTime, negotiateTime)
CONN_ASSIGNER(Uint64, LinkTime, linkTime)
CONN_ASSIGNER(Errcode, OsType, osType)
CONN_ASSIGNER(AnonymizeString, LocalDeviceType, localDeviceType)
CONN_ASSIGNER(AnonymizeString, RemoteDeviceType, remoteDeviceType)
CONN_ASSIGNER(Errcode, P2pChannel, p2pChannel)
CONN_ASSIGNER(Errcode, HmlChannel, hmlChannel)
CONN_ASSIGNER(Errcode, StaChannel, staChannel)
CONN_ASSIGNER(Errcode, ApChannel, apChannel)
#define CONN_ASSIGNER_SIZE 39 // Size of g_connAssigners
#define CONN_ASSIGNER_SIZE 46 // Size of g_connAssigners
static HiSysEventParamAssigner g_connAssigners[] = {
{ "STAGE_RES", HISYSEVENT_INT32, ConnAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, ConnAssignerErrcode },
@ -115,7 +122,14 @@ static HiSysEventParamAssigner g_connAssigners[] = {
{ "IS_REUSE", HISYSEVENT_INT32, ConnAssignerIsReuse },
{ "NEGOTIATE_TIME", HISYSEVENT_UINT64, ConnAssignerNegotiateTime },
{ "LINK_TIME", HISYSEVENT_UINT64, ConnAssignerLinkTime },
// Modification Note: remember updating CONN_ASSIGNER_SIZE
{ "OS_TYPE", HISYSEVENT_INT32, ConnAssignerOsType },
{ "LOCAL_DEVICE_TYPE", HISYSEVENT_STRING, ConnAssignerLocalDeviceType },
{ "REMOTE_DEVICE_TYPE", HISYSEVENT_STRING, ConnAssignerRemoteDeviceType },
{ "P2P_CHANNEL", HISYSEVENT_INT32, ConnAssignerP2pChannel },
{ "HML_CHANNEL", HISYSEVENT_INT32, ConnAssignerHmlChannel },
{ "STA_CHANNEL", HISYSEVENT_INT32, ConnAssignerStaChannel },
{ "AP_CHANNEL", HISYSEVENT_INT32, ConnAssignerApChannel },
// Modification Note: remember updating CONN_ASSIGNER_SIZE
};
#define CONN_ALARM_ASSIGNER(type, fieldName, field) \

View File

@ -106,6 +106,10 @@ typedef struct {
int32_t osType; // OS_TYPE
const char *localDeviceType; // LOCAL_DEVICE_TYPE
const char *remoteDeviceType; // REMOTE_DEVICE_TYPE
int32_t p2pChannel; // P2P_CHAN
int32_t hmlChannel; // HML_CHAN
int32_t staChannel; // STA_CHAN
int32_t apChannel; // HOTSPOT_CHAN
} ConnEventExtra;
typedef enum {

View File

@ -149,6 +149,7 @@ typedef struct {
DeviceType type;
int32_t osType;
ConnectOnlineReason bleConnectReason;
char peerUdid[UDID_BUF_LEN];
} LnnDfxDeviceInfoReport;
typedef enum {

View File

@ -96,6 +96,7 @@ enum SoftBusFuncId {
CLIENT_ON_LEAVE_RESULT,
CLIENT_ON_LEAVE_METANODE_RESULT,
CLIENT_ON_NODE_DEVICE_TRUST_CHANGED,
CLIENT_ON_HICHAIN_PROOF_EXCEPTION,
CLIENT_ON_NODE_ONLINE_STATE_CHANGED,
CLIENT_ON_NODE_BASIC_INFO_CHANGED,
CLIENT_ON_NODE_STATUS_CHANGED,

View File

@ -401,7 +401,7 @@ static int32_t CheckPermissionAppInfo(const SoftBusPermissionEntry *pe,
return SOFTBUS_PERMISSION_DENIED;
}
static bool CheckDBinder(const char *sessionName)
bool CheckDBinder(const char *sessionName)
{
if (StrIsEmpty(sessionName)) {
return false;
@ -471,7 +471,7 @@ int32_t LoadPermissionJson(const char *fileName)
g_permissionEntryList->cnt++;
}
}
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
cJSON_Delete(jsonArray);
return SOFTBUS_OK;
}
@ -497,7 +497,7 @@ void DeinitPermissionJson(void)
while (!IsListEmpty(&g_permissionEntryList->list)) {
SoftBusPermissionEntry *item = LIST_ENTRY((&g_permissionEntryList->list)->next, SoftBusPermissionEntry, node);
if (item == NULL) {
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
COMM_LOGE(COMM_PERM, "get item is NULL");
return;
}
@ -505,7 +505,7 @@ void DeinitPermissionJson(void)
ListDelete(&item->node);
SoftBusFree(item);
}
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
DestroySoftBusList(g_permissionEntryList);
g_permissionEntryList = NULL;
}
@ -710,20 +710,20 @@ int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char
SoftBusMutexLock(&g_dynamicPermissionList->lock);
if (g_dynamicPermissionList->cnt >= DYNAMIC_PERMISSION_MAX_SIZE) {
COMM_LOGE(COMM_PERM, "dynamic permission reach the upper limit");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_NO_ENOUGH_DATA;
}
if (HaveGrantedPermission(sessionName)) {
COMM_LOGD(COMM_PERM, "dynamic permission already granted");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
SoftBusPermissionEntry *permissionEntry = (SoftBusPermissionEntry *)SoftBusCalloc(sizeof(SoftBusPermissionEntry));
if (permissionEntry == NULL) {
COMM_LOGE(COMM_PERM, "AddDynamicPermission malloc failed!");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_MALLOC_ERR;
}
@ -731,18 +731,19 @@ int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_PERM, "NewDynamicPermissionEntry failed. ret=%{public}d", ret);
SoftBusFree(permissionEntry);
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return ret;
}
ListNodeInsert(&g_dynamicPermissionList->list, &permissionEntry->node);
g_dynamicPermissionList->cnt++;
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
COMM_LOGD(COMM_PERM, "session dynamic permission granted. sessionName=%{public}s", AnonymizeWrapper(tmpName));
COMM_LOGD(COMM_PERM, "session dynamic permission granted. sessionName=%{public}s, count=%{public}d",
AnonymizeWrapper(tmpName), g_dynamicPermissionList->cnt);
AnonymizeFree(tmpName);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
@ -760,15 +761,15 @@ int32_t DeleteDynamicPermission(const char *sessionName)
ListDelete(&pe->node);
SoftBusFree(pe);
g_dynamicPermissionList->cnt--;
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
COMM_LOGI(COMM_PERM, "session dynamic permission deleted. sessionName=%{public}s",
AnonymizeWrapper(tmpName));
COMM_LOGI(COMM_PERM, "session dynamic permission deleted. sessionName=%{public}s, count=%{public}d",
AnonymizeWrapper(tmpName), g_dynamicPermissionList->cnt);
AnonymizeFree(tmpName);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
}
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_NOT_FIND;
}

View File

@ -75,6 +75,7 @@ int32_t InitDynamicPermission(void);
int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char *sessionName);
int32_t DeleteDynamicPermission(const char *sessionName);
int32_t CompareString(const char *src, const char *dest, bool regexp);
bool CheckDBinder(const char *sessionName);
#ifdef __cplusplus
#if __cplusplus

View File

@ -1457,7 +1457,7 @@ int32_t ConnBleKeepAlive(uint32_t connectionId, uint32_t requestId, uint32_t tim
int32_t ConnBleRemoveKeepAlive(uint32_t connectionId, uint32_t requestId)
{
ConnBleConnection *connection = ConnBleGetConnectionById(connectionId);
CONN_CHECK_AND_RETURN_RET_LOGE(connection != NULL, SOFTBUS_CONN_BLE_INTERNAL_ERR, CONN_BLE,
CONN_CHECK_AND_RETURN_RET_LOGD(connection != NULL, SOFTBUS_CONN_BLE_INTERNAL_ERR, CONN_BLE,
"connection not exist, connectionId=%{public}u", connectionId);
bool isExist = false;
ConnRemoveMsgFromLooper(
@ -1675,7 +1675,8 @@ static MsgHandlerCommand g_commands[] = {
static void BleManagerMsgHandler(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (msg->what != BLE_MGR_MSG_DATA_RECEIVED) {
if (msg->what != BLE_MGR_MSG_DATA_RECEIVED && msg->what != BLE_MGR_MSG_NEXT_CMD &&
msg->what != BLE_MGR_MSG_CONNECTION_CLOSED) {
CONN_LOGI(CONN_BLE, "ble msg looper recv msg=%{public}d, curState=%{public}s",
msg->what, g_bleManager.state->name());
}

View File

@ -176,7 +176,7 @@ int32_t ConnBleDequeueBlock(void **msg)
status = SOFTBUS_CONN_COND_WAIT_FAIL;
break;
}
CONN_LOGI(CONN_BLE, "ble queue wakeup.");
CONN_LOGD(CONN_BLE, "ble queue wakeup.");
} while (true);
if (isFull) {

View File

@ -1212,7 +1212,8 @@ static MsgHandlerCommand g_commands[] = {
static void BrManagerMsgHandler(SoftBusMessage *msg)
{
COMM_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BR, "msg is null");
if (msg->what != MSG_DATA_RECEIVED) {
if (msg->what != MSG_DATA_RECEIVED && msg->what != MSG_NEXT_CMD && msg->what != MSG_CONNECT_REQUEST &&
msg->what != MSG_CONNECTION_EXECEPTION && msg->what != MGR_DISCONNECT_REQUEST) {
CONN_LOGI(CONN_BR, "recvMsg=%{public}d, state=%{public}s", msg->what, g_brManager.state->name());
}
size_t commandSize = sizeof(g_commands) / sizeof(g_commands[0]);
@ -1599,10 +1600,14 @@ static bool BrCheckActiveConnection(const ConnectOption *option, bool needOccupy
CONN_CHECK_AND_RETURN_RET_LOGW(option != NULL, false, CONN_BR, "BrCheckActiveConnection: option is null");
CONN_CHECK_AND_RETURN_RET_LOGW(option->type == CONNECT_BR, false, CONN_BR,
"BrCheckActiveConnection: not br type, type=%{public}d", option->type);
char anomizeAddress[BT_MAC_LEN] = { 0 };
ConvertAnonymizeMacAddress(anomizeAddress, BT_MAC_LEN, option->brOption.brMac, BT_MAC_LEN);
ConnBrConnection *connection = ConnBrGetConnectionByAddr(option->brOption.brMac, option->brOption.sideType);
CONN_CHECK_AND_RETURN_RET_LOGW(
connection != NULL, false, CONN_BR, "BrCheckActiveConnection: connection is not exist");
connection != NULL, false, CONN_BR, "BrCheckActiveConnection: connection is not exist addr=%{public}s",
anomizeAddress);
bool isActive = (connection->state == BR_CONNECTION_STATE_CONNECTED);
if (isActive && needOccupy) {
ConnBrOccupy(connection);

View File

@ -58,7 +58,7 @@ static uint8_t *BrRecvDataParse(uint32_t connectionId, LimitedBuffer *buffer, in
}
uint32_t packLen = head->len + sizeof(ConnPktHead);
if (buffer->length < packLen) {
CONN_LOGI(CONN_BR, "recv incomplete packet, connId=%{public}u", connectionId);
CONN_LOGD(CONN_BR, "recv incomplete packet, connId=%{public}u", connectionId);
return NULL;
}
uint8_t *dataCopy = (uint8_t *)SoftBusCalloc(packLen);

View File

@ -1209,7 +1209,7 @@ static int32_t StartSelectThread(void)
(void)SoftBusMutexUnlock(&g_selectThreadState->lock);
WakeupSelectThread();
CONN_LOGW(CONN_COMMON,
CONN_LOGD(CONN_COMMON,
"select thread is already start, selectTrace=%{public}d, ctrlRfd=%{public}d, ctrlWfd=%{public}d, "
"referenceCount=%{public}d",
g_selectThreadState->traceId, g_selectThreadState->ctrlRfd, g_selectThreadState->ctrlWfd,

View File

@ -38,7 +38,6 @@
ConnectFuncInterface *g_connManager[CONNECT_TYPE_MAX] = { 0 };
static SoftBusList *g_listenerList = NULL;
static _Atomic bool g_isInited = false;
static SoftBusList *g_connTimeList = NULL;
#define SEC_TIME 1000LL
typedef struct TagConnListenerNode {
@ -47,109 +46,6 @@ typedef struct TagConnListenerNode {
ConnectCallback callback;
} ConnListenerNode;
typedef struct TagConnTimeNode {
uint32_t startTime;
ListNode node;
ConnectionInfo info;
} ConnTimeNode;
static int32_t AddConnTimeNode(const ConnectionInfo *info, ConnTimeNode *timeNode)
{
if (g_connTimeList == NULL) {
CONN_LOGE(CONN_COMMON, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
SoftBusSysTime now = { 0 };
SoftBusGetTime(&now);
timeNode->startTime = (uint32_t)now.sec * SEC_TIME + (uint32_t)now.usec / SEC_TIME;
if (memcpy_s(&(timeNode->info), sizeof(ConnectionInfo), info, sizeof(ConnectionInfo)) != EOK) {
CONN_LOGE(CONN_COMMON, "memcpy timenode failed");
return SOFTBUS_MEM_ERR;
}
if (SoftBusMutexLock(&g_connTimeList->lock) != 0) {
CONN_LOGE(CONN_COMMON, "lock mutex failed");
return SOFTBUS_LOCK_ERR;
}
ListAdd(&(g_connTimeList->list), &(timeNode->node));
(void)SoftBusMutexUnlock(&g_connTimeList->lock);
return SOFTBUS_OK;
}
static int32_t CompareConnectInfo(const ConnectionInfo *src, const ConnectionInfo *dst)
{
if (src->type != dst->type) {
return SOFTBUS_INVALID_PARAM;
}
switch (src->type) {
case CONNECT_BLE:
if (strcasecmp(src->bleInfo.bleMac, dst->bleInfo.bleMac) != 0) {
return SOFTBUS_STRCMP_ERR;
}
break;
case CONNECT_BR:
if (strcasecmp(src->brInfo.brMac, dst->brInfo.brMac) != 0) {
return SOFTBUS_STRCMP_ERR;
}
break;
case CONNECT_TCP:
if (strcasecmp(src->socketInfo.addr, dst->socketInfo.addr) != 0) {
return SOFTBUS_STRCMP_ERR;
}
break;
default:
return SOFTBUS_CONN_INTERNAL_ERR;
}
return SOFTBUS_OK;
}
static ConnTimeNode *GetConnTimeNode(const ConnectionInfo *info)
{
ConnTimeNode *listNode = NULL;
if (SoftBusMutexLock(&g_connTimeList->lock) != 0) {
CONN_LOGE(CONN_COMMON, "lock mutex failed");
return NULL;
}
LIST_FOR_EACH_ENTRY(listNode, &g_connTimeList->list, ConnTimeNode, node) {
if (listNode != NULL) {
if (CompareConnectInfo(&listNode->info, info) == SOFTBUS_OK) {
CONN_LOGD(CONN_COMMON, "find connect info success, ConnectType=%{public}d", listNode->info.type);
(void)SoftBusMutexUnlock(&g_connTimeList->lock);
return listNode;
}
}
}
(void)SoftBusMutexUnlock(&g_connTimeList->lock);
return NULL;
}
static void FreeConnTimeNode(ConnTimeNode *timeNode)
{
ConnTimeNode *removeNode = NULL;
ConnTimeNode *next = NULL;
if (g_connTimeList == NULL) {
CONN_LOGE(CONN_COMMON, "invalid param");
return;
}
if (SoftBusMutexLock(&g_connTimeList->lock) != 0) {
CONN_LOGE(CONN_COMMON, "lock mutex failed");
return;
}
LIST_FOR_EACH_ENTRY_SAFE(removeNode, next, &g_connTimeList->list, ConnTimeNode, node) {
if (removeNode->info.type == timeNode->info.type) {
if (CompareConnectInfo(&removeNode->info, &timeNode->info) == SOFTBUS_OK) {
CONN_LOGD(CONN_COMMON, "find connect info success, ConnectType=%{public}d", removeNode->info.type);
ListDelete(&(removeNode->node));
break;
}
}
}
(void)SoftBusMutexUnlock(&g_connTimeList->lock);
SoftBusFree(removeNode);
return;
}
static int32_t ModuleCheck(ConnModule moduleId)
{
ConnModule id[] = { MODULE_TRUST_ENGINE, MODULE_HICHAIN, MODULE_AUTH_SDK, MODULE_AUTH_CONNECTION,
@ -346,73 +242,6 @@ void ConnManagerRecvData(uint32_t connectionId, ConnModule moduleId, int64_t seq
listener.callback.OnDataReceived(connectionId, moduleId, seq, pkt, pktLen);
}
static void ReportConnectTime(const ConnectionInfo *info)
{
if (info == NULL) {
CONN_LOGW(CONN_COMMON, "info is null");
return;
}
ConnTimeNode *timeNode = GetConnTimeNode(info);
if (timeNode == NULL) {
CONN_LOGE(CONN_COMMON, "get timeNode failed");
} else {
FreeConnTimeNode(timeNode);
}
}
static void RecordStartTime(const ConnectOption *info)
{
ConnectionInfo conInfo = { 0 };
conInfo.type = info->type;
switch (info->type) {
case CONNECT_BR:
if (memcpy_s(&conInfo.brInfo.brMac, BT_MAC_LEN, info->brOption.brMac, BT_MAC_LEN) != EOK) {
CONN_LOGE(CONN_COMMON, "brMac memcpy failed");
return;
}
break;
case CONNECT_BLE:
if (memcpy_s(&conInfo.bleInfo.bleMac, BT_MAC_LEN, info->bleOption.bleMac, BT_MAC_LEN) != EOK) {
CONN_LOGE(CONN_COMMON, "bleMac memcpy failed");
return;
}
conInfo.bleInfo.protocol = info->bleOption.protocol;
conInfo.bleInfo.psm = info->bleOption.psm;
break;
case CONNECT_TCP:
if (memcpy_s(&conInfo.socketInfo.addr, MAX_SOCKET_ADDR_LEN, info->socketOption.addr, MAX_SOCKET_ADDR_LEN) !=
EOK) {
CONN_LOGE(CONN_COMMON, "addr memcpy failed");
return;
}
break;
default:
CONN_LOGW(CONN_COMMON, "do nothing");
break;
}
ConnTimeNode *timeNode = GetConnTimeNode(&conInfo);
if (timeNode == NULL) {
timeNode = (ConnTimeNode *)SoftBusCalloc(sizeof(ConnTimeNode));
if (timeNode == NULL) {
CONN_LOGE(CONN_COMMON, "malloc node failed");
} else if (AddConnTimeNode(&conInfo, timeNode) != SOFTBUS_OK) {
SoftBusFree(timeNode);
CONN_LOGE(CONN_COMMON, "AddConnTimeNode failed");
}
}
}
static int32_t InitTimeNodeList()
{
if (g_connTimeList == NULL) {
g_connTimeList = CreateSoftBusList();
if (g_connTimeList == NULL) {
CONN_LOGE(CONN_COMMON, "create list failed");
return SOFTBUS_CREATE_LIST_ERR;
}
}
return SOFTBUS_OK;
}
void ConnManagerConnected(uint32_t connectionId, const ConnectionInfo *info)
{
ConnListenerNode *node = NULL;
@ -430,7 +259,6 @@ void ConnManagerConnected(uint32_t connectionId, const ConnectionInfo *info)
listener->callback.OnConnected(connectionId, info);
}
SoftBusFree(node);
ReportConnectTime(info);
return;
}
@ -453,7 +281,6 @@ void ConnManagerReusedConnected(uint32_t connectionId, const ConnectionInfo *inf
}
}
SoftBusFree(node);
ReportConnectTime(info);
return;
}
@ -520,7 +347,6 @@ int32_t ConnConnectDevice(const ConnectOption *info, uint32_t requestId, const C
if (g_connManager[info->type]->ConnectDevice == NULL) {
return SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT;
}
RecordStartTime(info);
ConnEventExtra extra = {
.requestId = requestId,
.linkType = info->type,
@ -726,7 +552,6 @@ int32_t ConnServerInit(void)
return SOFTBUS_CREATE_LIST_ERR;
}
}
InitTimeNodeList();
CONN_CHECK_AND_RETURN_RET_LOGE(SoftBusMutexInit(&g_ReqLock, NULL) == SOFTBUS_OK,
SOFTBUS_CONN_INTERNAL_ERR, CONN_COMMON, "g_ReqLock init lock failed.");

View File

@ -32,6 +32,8 @@
#include "utils/wifi_direct_utils.h"
#include "wifi_direct_error_code.h"
#include "wifi_direct_defines.h"
#include "kits/c/wifi_hotspot.h"
#include "kits/c/wifi_event.h"
namespace OHOS::SoftBus {
static constexpr char DEFAULT_NET_MASK[] = "255.255.255.0";
@ -466,4 +468,15 @@ int P2pAdapter::GetCoexConflictCode(const char *ifName, int32_t channelId)
return getCoexConflictCodeHook_(ifName, channelId);
}
int P2pAdapter::GetApChannel()
{
auto hotSpotActive = IsHotspotActive();
CONN_CHECK_AND_RETURN_RET_LOGE(
hotSpotActive == WIFI_HOTSPOT_ACTIVE, CHANNEL_INVALID, CONN_WIFI_DIRECT, "hotspot not active");
HotspotConfig hotspotConfig;
auto ret = GetHotspotConfig(&hotspotConfig);
CONN_CHECK_AND_RETURN_RET_LOGI(ret == WIFI_SUCCESS, CHANNEL_INVALID, CONN_WIFI_DIRECT, "hotspot channel invalid");
return hotspotConfig.channelNum;
}
} // namespace OHOS::SoftBus

View File

@ -89,6 +89,7 @@ public:
using GetCoexConflictCodeHook = std::function<int(const char *, int32_t)>;
static void Register(const GetCoexConflictCodeHook &coexConflictor);
static int GetCoexConflictCode(const char *ifName, int32_t channelId);
static int GetApChannel();
private:
static constexpr int P2P_GROUP_CONFIG_INDEX_SSID = 0;

View File

@ -18,9 +18,9 @@
#include <functional>
#include <memory>
#include "connect_command.h"
#include "disconnect_command.h"
#include "force_disconnect_command.h"
#include "command/connect_command.h"
#include "command/disconnect_command.h"
#include "command/force_disconnect_command.h"
namespace OHOS::SoftBus {
class CommandFactory {

View File

@ -93,7 +93,7 @@ void ConnectCommand::OnSuccess(const WifiDirectLink &link) const
successCallback_(link);
return;
}
WifiDirectDfx::GetInstance().DfxRecord(true, SOFTBUS_OK, info_);
WifiDirectDfx::GetInstance().DfxRecord(true, SOFTBUS_OK, info_.info_);
if (callback_.onConnectSuccess != nullptr) {
callback_.onConnectSuccess(info_.info_.requestId, &link);
}
@ -112,7 +112,7 @@ void ConnectCommand::OnFailure(int32_t reason) const
failureCallback_(reason);
return;
}
WifiDirectDfx::GetInstance().DfxRecord(false, reason, info_);
WifiDirectDfx::GetInstance().DfxRecord(false, reason, info_.info_);
if (callback_.onConnectFailure != nullptr) {
callback_.onConnectFailure(info_.info_.requestId, reason);
}
@ -121,6 +121,9 @@ void ConnectCommand::OnFailure(int32_t reason) const
void ConnectCommand::PreferNegotiateChannel()
{
auto innerLink = LinkManager::GetInstance().GetReuseLink(info_.info_.connectType, remoteDeviceId_);
if (remoteDeviceId_.length() != (UUID_BUF_LEN - 1) && innerLink == nullptr) {
innerLink = LinkManager::GetInstance().GetReuseLink(remoteDeviceId_);
}
if (innerLink == nullptr || innerLink->GetNegotiateChannel() == nullptr) {
if (info_.info_.negoChannel.type == NEGO_CHANNEL_AUTH) {
CONN_LOGI(CONN_WIFI_DIRECT, "prefer input auth channel");
@ -143,4 +146,12 @@ bool ConnectCommand::IsSameCommand(const WifiDirectConnectInfo &info) const
{
return (info.requestId == info_.info_.requestId) && (info.pid == info_.info_.pid);
}
void ConnectCommand::ResetConnectType(WifiDirectConnectType connectType)
{
auto oldConnectType = info_.info_.connectType;
CONN_LOGI(
CONN_WIFI_DIRECT, "old connect type=%{public}d, new connect type=%{public}d", oldConnectType, connectType);
info_.info_.connectType = connectType;
}
} // namespace OHOS::SoftBus

View File

@ -58,12 +58,13 @@ public:
void SetRetryReason(ConnectCommandRetryReason reason) { retryReason_ = reason; }
ConnectCommandRetryReason GetRetryReason() const { return retryReason_; }
void OnSuccess(const WifiDirectLink &link) const;
void OnFailure(int32_t reason) const;
virtual void OnSuccess(const WifiDirectLink &link) const;
virtual void OnFailure(int32_t reason) const;
bool IsSameCommand(const WifiDirectConnectInfo &info) const;
void ResetConnectType(WifiDirectConnectType connectType);
protected:
ConnectInfo info_;
mutable ConnectInfo info_;
WifiDirectConnectCallback callback_;
SuccessCallback successCallback_;
FailureCallback failureCallback_;

View File

@ -22,6 +22,8 @@
#include "softbus_error_code.h"
#include "softbus_adapter_crypto.h"
#include "utils/wifi_direct_anonymous.h"
#include "data/interface_manager.h"
#include "data/link_manager.h"
namespace OHOS::SoftBus {
static constexpr int IP_SUFFIX_RANGE = 253;
@ -100,8 +102,13 @@ void P2pConnectState::OnP2pStateChangeEvent(P2pState state)
}
}
std::string P2pConnectState::CalculateGcIp(const std::string &goIpAddr)
std::string P2pConnectState::CalculateGcIp(const std::string &remoteMac)
{
CONN_CHECK_AND_RETURN_RET_LOGE(!remoteMac.empty(), "", CONN_WIFI_DIRECT, "remote mac is empty");
std::string goIpAddr;
LinkManager::GetInstance().ProcessIfPresent(remoteMac, [&goIpAddr](InnerLink &link) {
goIpAddr = link.GetRemoteIpv4();
});
CONN_CHECK_AND_RETURN_RET_LOGE(!goIpAddr.empty(), "", CONN_WIFI_DIRECT, "go ip is empty");
auto lastDotPos = goIpAddr.find_last_of('.');
CONN_CHECK_AND_RETURN_RET_LOGE(
@ -134,18 +141,28 @@ void P2pConnectState::PreprocessP2pConnectionChangeEvent(
return;
}
auto operation = std::dynamic_pointer_cast<P2pOperationWrapper<P2pConnectParam>>(operation_);
P2pEntity::GetInstance().Unlock();
if (operation == nullptr) {
CONN_LOGE(CONN_WIFI_DIRECT, "operation is null");
P2pEntity::GetInstance().Unlock();
return;
}
if (operation->content_.isNeedDhcp) {
std::string localIpStr;
if (P2pAdapter::GetIpAddress(localIpStr) == SOFTBUS_OK) {
P2pEntity::GetInstance().Unlock();
return;
}
localIpStr = CalculateGcIp(groupInfo->groupOwner.address);
if (localIpStr.empty()) {
CONN_LOGE(CONN_WIFI_DIRECT, "gc ip is empty");
P2pEntity::GetInstance().Unlock();
return;
}
localIpStr = CalculateGcIp(groupInfo->goIpAddr);
CONN_CHECK_AND_RETURN_LOGE(!localIpStr.empty(), CONN_WIFI_DIRECT, "calculate gc ip failed");
operation->content_.gcIp = localIpStr;
CONN_LOGI(CONN_WIFI_DIRECT, "calculated gc ip %{public}s", WifiDirectAnonymizeIp(localIpStr).c_str());
}
auto ret = P2pAdapter::P2pConfigGcIp(groupInfo->interface, operation->content_.gcIp);
P2pEntity::GetInstance().Unlock();
CONN_CHECK_AND_RETURN_LOGE(ret == SOFTBUS_OK, CONN_WIFI_DIRECT, "config gc ip failed, error=%d", ret);
}
@ -183,6 +200,32 @@ void P2pConnectState::OnTimeout()
P2pEntity::GetInstance().Unlock();
return;
}
do {
auto operation = std::dynamic_pointer_cast<P2pOperationWrapper<P2pConnectParam>>(operation_);
if (operation != nullptr && !operation->content_.isNeedDhcp) {
break;
}
auto groupInfo = std::make_shared<P2pAdapter::WifiDirectP2pGroupInfo>();
if (P2pAdapter::GetGroupInfo(*groupInfo) != SOFTBUS_OK) {
break;
}
auto gcIp = CalculateGcIp(groupInfo->groupOwner.address);
if (gcIp.empty()) {
break;
}
CONN_LOGI(CONN_WIFI_DIRECT, "calculated gc ip %{public}s", WifiDirectAnonymizeIp(gcIp).c_str());
if (P2pAdapter::P2pConfigGcIp(groupInfo->interface, gcIp) != SOFTBUS_OK) {
break;
}
P2pEntity::GetInstance().Unlock();
BroadcastParam param;
param.p2pLinkInfo.connectState = P2pConnectionState::P2P_CONNECTED;
param.groupInfo = groupInfo;
P2pBroadcast::GetInstance()->DispatchWorkHandler(
BroadcastReceiverAction::WIFI_P2P_CONNECTION_CHANGED_ACTION, param);
return;
} while (false);
ChangeState(P2pAvailableState::Instance(), nullptr);
operation_->promise_.set_value(P2pOperationResult(static_cast<int>(SOFTBUS_CONN_CONNECT_GROUP_TIMEOUT)));
operation_ = nullptr;

View File

@ -41,7 +41,7 @@ public:
private:
static constexpr int CONNECT_TIMEOUT_MS = 5000;
static constexpr int CONNECT_TIMEOUT_DHCP_MS = 15000;
static constexpr int CONNECT_TIMEOUT_DHCP_MS = 10000;
P2pConnectState();
std::string CalculateGcIp(const std::string &goIpAddr);

View File

@ -48,7 +48,15 @@ private:
bool chained_;
};
enum class ProcessorTerminateReason {
SUCCESS,
FAILURE,
RETRY,
};
struct ProcessorTerminate : public std::exception {
ProcessorTerminate(ProcessorTerminateReason reason = ProcessorTerminateReason::SUCCESS) : reason_(reason) {}
ProcessorTerminateReason reason_;
};
}
#endif

View File

@ -1657,15 +1657,11 @@ int P2pV1Processor::UpdateWhenConnectSuccess(std::string groupConfig, const Nego
CONN_CHECK_AND_RETURN_RET_LOGW(
ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "update interface failed, error=%{public}d", ret);
std::string remoteMac = msg.GetLegacyP2pMac();
std::string remoteIp = msg.GetLegacyP2pGoIp();
auto success = LinkManager::GetInstance().ProcessIfAbsent(
InnerLink::LinkType::P2P, msg.GetRemoteDeviceId(), [localMac, localIp, remoteMac, remoteIp](InnerLink &link) {
link.SetRemoteBaseMac(remoteMac);
link.SetLocalBaseMac(localMac);
link.SetRemoteIpv4(remoteIp);
link.SetLocalIpv4(localIp);
link.SetState(InnerLink::LinkState::CONNECTED);
});
auto success = LinkManager::GetInstance().ProcessIfPresent(remoteMac, [localMac, localIp](InnerLink &link) {
link.SetLocalBaseMac(localMac);
link.SetLocalIpv4(localIp);
link.SetState(InnerLink::LinkState::CONNECTED);
});
CONN_CHECK_AND_RETURN_RET_LOGW(
success, SOFTBUS_CONN_PV1_INTERNAL_ERR0R, CONN_WIFI_DIRECT, "update inner link failed");
WifiDirectUtils::SyncLnnInfoForP2p(WifiDirectUtils::ToWifiDirectRole(myRole), localMac, msg.GetLegacyP2pGoMac());
@ -1690,6 +1686,15 @@ int P2pV1Processor::ConnectGroup(const NegotiateMessage &msg, const std::shared_
int coexCode = P2pAdapter::GetCoexConflictCode(IF_NAME_P2P0, WifiDirectUtils::FrequencyToChannel(freq));
CONN_CHECK_AND_RETURN_RET_LOGE(
coexCode == SOFTBUS_OK, coexCode, CONN_WIFI_DIRECT, "coex conflict, errorcode=%{public}d", coexCode);
std::string remoteMac = msg.GetLegacyP2pMac();
std::string remoteIp = msg.GetLegacyP2pGoIp();
auto success = LinkManager::GetInstance().ProcessIfAbsent(
InnerLink::LinkType::P2P, msg.GetRemoteDeviceId(), [remoteMac, remoteIp](InnerLink &link) {
link.SetRemoteBaseMac(remoteMac);
link.SetRemoteIpv4(remoteIp);
});
CONN_CHECK_AND_RETURN_RET_LOGW(
success, SOFTBUS_CONN_PV1_INTERNAL_ERR0R, CONN_WIFI_DIRECT, "update inner link failed");
P2pAdapter::ConnectParam params {};
params.isNeedDhcp = IsNeedDhcp(gcIp, groupConfig);
params.groupConfig = groupConfig;

View File

@ -16,36 +16,34 @@
#include "wifi_direct_dfx.h"
#include "conn_log.h"
#include "duration_statistic.h"
#include "softbus_conn_interface.h"
#include "wifi_direct_utils.h"
#include "adapter/p2p_adapter.h"
namespace OHOS::SoftBus {
void WifiDirectDfx::DfxRecord(bool success, int32_t reason, const ConnectInfo &connectInfo)
void WifiDirectDfx::DfxRecord(bool success, int32_t reason, WifiDirectConnectInfo &connectInfo)
{
auto wifiDirectConnectInfo = connectInfo.info_;
if (success) {
DurationStatistic::GetInstance().Record(wifiDirectConnectInfo.requestId, TOTAL_END);
DurationStatistic::GetInstance().End(wifiDirectConnectInfo.requestId);
DurationStatistic::GetInstance().Clear(wifiDirectConnectInfo.requestId);
WifiDirectDfx::GetInstance().Clear(wifiDirectConnectInfo.requestId);
DurationStatistic::GetInstance().Record(connectInfo.requestId, TOTAL_END);
DurationStatistic::GetInstance().End(connectInfo.requestId);
ConnEventExtra extra = {
.result = EVENT_STAGE_RESULT_OK,
.requestId = static_cast<int32_t>(wifiDirectConnectInfo.requestId),
.frequency = wifiDirectConnectInfo.dfxInfo.frequency,
.requestId = static_cast<int32_t>(connectInfo.requestId),
.frequency = connectInfo.dfxInfo.frequency,
};
ReportConnEventExtra(extra, connectInfo);
DurationStatistic::GetInstance().Clear(connectInfo.requestId);
WifiDirectDfx::GetInstance().Clear(connectInfo.requestId);
} else {
DurationStatistic::GetInstance().Clear(wifiDirectConnectInfo.requestId);
WifiDirectDfx::GetInstance().Clear(wifiDirectConnectInfo.requestId);
ConnEventExtra extra = {
.result = EVENT_STAGE_RESULT_FAILED,
.errcode = reason,
.requestId = static_cast<int32_t>(wifiDirectConnectInfo.requestId),
.frequency = wifiDirectConnectInfo.dfxInfo.frequency,
.requestId = static_cast<int32_t>(connectInfo.requestId),
.frequency = connectInfo.dfxInfo.frequency,
};
ReportConnEventExtra(extra, connectInfo);
DurationStatistic::GetInstance().Clear(connectInfo.requestId);
WifiDirectDfx::GetInstance().Clear(connectInfo.requestId);
}
}
@ -61,10 +59,10 @@ void WifiDirectDfx::Clear(uint32_t requestId)
challengeCodeMap_.erase(requestId);
}
void WifiDirectDfx::ReportConnEventExtra(ConnEventExtra &extra, const ConnectInfo &info)
void WifiDirectDfx::ReportConnEventExtra(ConnEventExtra &extra, WifiDirectConnectInfo &wifiDirectConnectInfo)
{
CONN_LOGI(CONN_WIFI_DIRECT, "FillConnEventExtra enter");
auto wifiDirectConnectInfo = info.info_;
SetLinkType(wifiDirectConnectInfo);
enum StatisticLinkType type = wifiDirectConnectInfo.dfxInfo.linkType;
if (type == STATISTIC_P2P) {
extra.linkType = CONNECT_P2P;
@ -103,6 +101,25 @@ void WifiDirectDfx::ReportConnEventExtra(ConnEventExtra &extra, const ConnectInf
auto remoteDeviceType = WifiDirectUtils::GetDeviceType(wifiDirectConnectInfo.remoteNetworkId);
auto remoteDeviceTypeStr = std::to_string(remoteDeviceType);
extra.remoteDeviceType = remoteDeviceTypeStr.c_str();
extra.isRenegotiate = DurationStatistic::GetInstance().ReNegotiateFlag(requestId);
extra.staChannel = dfxInfo.staChannel;
extra.hmlChannel = dfxInfo.hmlChannel;
extra.p2pChannel = dfxInfo.p2pChannel;
extra.apChannel = dfxInfo.apChannel;
CONN_LOGI(CONN_WIFI_DIRECT, "sta=%{public}d, p2p=%{public}d, hml=%{public}d, ap=%{public}d", extra.staChannel,
extra.p2pChannel, extra.hmlChannel, extra.apChannel);
CONN_EVENT(EVENT_SCENE_CONNECT, EVENT_STAGE_CONNECT_END, extra);
}
void WifiDirectDfx::SetLinkType(WifiDirectConnectInfo &connectInfo)
{
if (connectInfo.connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P) {
connectInfo.dfxInfo.linkType = STATISTIC_P2P;
} else if (connectInfo.connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML) {
connectInfo.dfxInfo.linkType = STATISTIC_HML;
} else {
connectInfo.dfxInfo.linkType = STATISTIC_TRIGGER_HML;
}
CONN_LOGI(CONN_WIFI_DIRECT, "link type %{public}d", connectInfo.dfxInfo.linkType);
}
} // namespace OHOS::SoftBus

View File

@ -32,12 +32,13 @@ public:
static WifiDirectDfx instance;
return instance;
}
void DfxRecord(bool success, int32_t reason, const ConnectInfo &connectInfo);
void DfxRecord(bool success, int32_t reason, WifiDirectConnectInfo &connectInfo);
void Record(uint32_t requestId, uint16_t challengeCode);
void Clear(uint32_t requestId);
static void SetLinkType(WifiDirectConnectInfo &info);
private:
void ReportConnEventExtra(ConnEventExtra &extra, const ConnectInfo &connectInfo);
void ReportConnEventExtra(ConnEventExtra &extra, WifiDirectConnectInfo &connectInfo);
std::map<uint32_t, uint16_t> challengeCodeMap_;
std::recursive_mutex mutex_;

View File

@ -32,6 +32,7 @@
#include "command/processor_selector_factory.h"
#include "entity/entity_factory.h"
#include "auth_interface.h"
#include "utils/wifi_direct_dfx.h"
static std::atomic<uint32_t> g_requestId = 0;
static std::list<WifiDirectStatusListener> g_listeners;
@ -75,14 +76,7 @@ static void SetElementTypeExtra(struct WifiDirectConnectInfo *info, ConnEventExt
extra->peerIp = info->remoteMac;
info->dfxInfo.bootLinkType = STATISTIC_NONE;
if (info->connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_P2P) {
info->dfxInfo.linkType = STATISTIC_P2P;
} else if (info->connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML) {
info->dfxInfo.linkType = STATISTIC_HML;
} else {
info->dfxInfo.linkType = STATISTIC_TRIGGER_HML;
}
OHOS::SoftBus::WifiDirectDfx::SetLinkType(*info);
WifiDirectNegoChannelType type = info->negoChannel.type;
if (type == NEGO_CHANNEL_AUTH) {
SetBootLinkTypeByAuthHandle(*info);

View File

@ -155,7 +155,11 @@ struct WifiDirectDfxInfo {
int reuse;
int costTime;
uint16_t challengeCode;
int32_t frequency;
int frequency;
int staChannel;
int hmlChannel;
int p2pChannel;
int apChannel;
};
struct WifiDirectConnectInfo {

View File

@ -15,6 +15,7 @@
"gid" : ["dsoftbus", "system", "shell", "netsys_socket"],
"permission" : [
"ohos.permission.LOCATION",
"ohos.permission.APPROXIMATELY_LOCATION",
"ohos.permission.PERMISSION_USED_STATS",
"ohos.permission.GET_SENSITIVE_PERMISSIONS",
"ohos.permission.RECEIVER_STARTUP_COMPLETED",

View File

@ -16,6 +16,7 @@
"secon" : "u:r:softbus_server:s0",
"permission" : [
"ohos.permission.LOCATION",
"ohos.permission.APPROXIMATELY_LOCATION",
"ohos.permission.PERMISSION_USED_STATS",
"ohos.permission.GET_SENSITIVE_PERMISSIONS",
"ohos.permission.RECEIVER_STARTUP_COMPLETED",

View File

@ -17,6 +17,7 @@
#include "anonymizer.h"
#include "lnn_lane_link.h"
#include "permission_entry.h"
#include "securec.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
@ -98,7 +99,7 @@ bool TransSessionServerIsExist(const char *sessionName)
if (strcmp(pos->sessionName, sessionName) == 0) {
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGW(TRANS_CTRL, "session server is exist. sessionName=%{public}s", tmpName);
TRANS_LOGW(TRANS_CTRL, "session server is exist. sessionName=%{public}s", AnonymizeWrapper(tmpName));
(void)SoftBusMutexUnlock(&g_sessionServerList->lock);
AnonymizeFree(tmpName);
return true;
@ -118,7 +119,7 @@ static void ShowSessionServer(void)
LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &g_sessionServerList->list, SessionServer, node) {
Anonymize(pos->sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL,
"session server is exist. count=%{public}d, sessionName=%{public}s", count, tmpName);
"session server is exist. count=%{public}d, sessionName=%{public}s", count, AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
count++;
}
@ -206,7 +207,7 @@ int32_t TransSessionServerDelItem(const char *sessionName)
g_sessionServerList->cnt--;
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL, "destroy session server sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_CTRL, "destroy session server sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
}
(void)SoftBusMutexUnlock(&g_sessionServerList->lock);
@ -255,6 +256,10 @@ void TransDelItemByPackageName(const char *pkgName, int32_t pid)
}
LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &g_sessionServerList->list, SessionServer, node) {
if ((strcmp(pos->pkgName, pkgName) == 0) && (pos->pid == pid)) {
if (CheckDBinder(pos->sessionName)) {
// Remove RPC Permission when Client Process Exit
(void)DeleteDynamicPermission(pos->sessionName);
}
ListDelete(&pos->node);
g_sessionServerList->cnt--;
SoftBusFree(pos);
@ -297,7 +302,7 @@ int32_t TransGetPkgNameBySessionName(const char *sessionName, char *pkgName, uin
(void)SoftBusMutexUnlock(&g_sessionServerList->lock);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_CTRL, "not found sessionName=%{public}s.", tmpName);
TRANS_LOGE(TRANS_CTRL, "not found sessionName=%{public}s.", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_TRANS_SESSION_NAME_NO_EXIST;
}
@ -326,7 +331,7 @@ int32_t TransGetUidAndPid(const char *sessionName, int32_t *uid, int32_t *pid)
*uid = pos->uid;
*pid = pos->pid;
TRANS_LOGD(TRANS_CTRL, "sessionName=%{public}s, uid=%{public}d, pid=%{public}d",
tmpName, pos->uid, pos->pid);
AnonymizeWrapper(tmpName), pos->uid, pos->pid);
(void)SoftBusMutexUnlock(&g_sessionServerList->lock);
AnonymizeFree(tmpName);
return SOFTBUS_OK;
@ -334,7 +339,7 @@ int32_t TransGetUidAndPid(const char *sessionName, int32_t *uid, int32_t *pid)
}
(void)SoftBusMutexUnlock(&g_sessionServerList->lock);
TRANS_LOGE(TRANS_CTRL, "err: sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_CTRL, "err: sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_TRANS_GET_PID_FAILED;
}
@ -388,7 +393,8 @@ void TransOnLinkDown(const char *networkId, const char *uuid, const char *udid,
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
TRANS_LOGI(TRANS_CTRL,
"routeType=%{public}d, networkId=%{public}s connType=%{public}d", routeType, anonyNetworkId, connType);
"routeType=%{public}d, networkId=%{public}s connType=%{public}d", routeType,
AnonymizeWrapper(anonyNetworkId), connType);
AnonymizeFree(anonyNetworkId);
ListNode sessionServerList = {0};

View File

@ -96,7 +96,7 @@ int32_t TransCreateSessionServer(const char *pkgName, const char *sessionName, i
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL, "pkgName=%{public}s, sessionName=%{public}s, uid=%{public}d, pid=%{public}d",
pkgName, tmpName, uid, pid);
pkgName, AnonymizeWrapper(tmpName), uid, pid);
AnonymizeFree(tmpName);
SessionServer *newNode = (SessionServer *)SoftBusCalloc(sizeof(SessionServer));
if (newNode == NULL) {

View File

@ -184,6 +184,7 @@ static int32_t NotifyOpenAuthChannelSuccess(const AppInfo *appInfo, bool isServe
channelInfo.timeStart = appInfo->timeStart;
channelInfo.connectType = appInfo->connectType;
channelInfo.routeType = appInfo->routeType;
channelInfo.osType = appInfo->osType;
return g_cb->OnChannelOpened(appInfo->myData.pkgName, appInfo->myData.pid,
appInfo->myData.sessionName, &channelInfo);
}

View File

@ -280,7 +280,7 @@ int32_t TransCommonGetAppInfo(const SessionParam *param, AppInfo *appInfo)
TRANS_CHECK_AND_RETURN_RET_LOGE(appInfo != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "Invalid appInfo");
char *tmpId = NULL;
Anonymize(param->peerDeviceId, &tmpId);
TRANS_LOGI(TRANS_CTRL, "GetAppInfo, deviceId=%{public}s", tmpId);
TRANS_LOGI(TRANS_CTRL, "GetAppInfo, deviceId=%{public}s", AnonymizeWrapper(tmpId));
AnonymizeFree(tmpId);
appInfo->appType = APP_TYPE_NORMAL;
appInfo->myData.apiVersion = API_V2;

View File

@ -85,7 +85,7 @@ bool CheckSessionNameValidOnAuthChannel(const char *sessionName)
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_CTRL,
"auth channel sessionName invalid. sessionName=%{public}s", tmpName);
"auth channel sessionName invalid. sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return false;
}

View File

@ -97,7 +97,8 @@ static int32_t TransServerOnChannelOpened(const char *pkgName, int32_t pid, cons
if (state == CORE_SESSION_STATE_CANCELLING) {
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGW(TRANS_CTRL, "Cancel bind name=%{public}s, channelId=%{public}d", tmpName, channel->channelId);
TRANS_LOGW(TRANS_CTRL, "Cancel bind name=%{public}s, channelId=%{public}d",
AnonymizeWrapper(tmpName), channel->channelId);
AnonymizeFree(tmpName);
extra.result = EVENT_STAGE_RESULT_CANCELED;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
@ -245,7 +246,7 @@ static int32_t TransServerOnChannelBind(const char *pkgName, int32_t pid, int32_
Anonymize(pkgName, &anonymizePkgName);
TRANS_LOGI(TRANS_CTRL,
"trasn server on channel bind. pkgname=%{public}s, channelId=%{public}d, type=%{public}d",
anonymizePkgName, channelId, channelType);
AnonymizeWrapper(anonymizePkgName), channelId, channelType);
AnonymizeFree(anonymizePkgName);
return SOFTBUS_OK;
}

View File

@ -226,7 +226,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
Anonymize(param->sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL, "server TransOpenChannel, sessionName=%{public}s, socket=%{public}d, actionId=%{public}d, "
"isQosLane=%{public}d, isAsync=%{public}d",
tmpName, param->sessionId, param->actionId, param->isQosLane, param->isAsync);
AnonymizeWrapper(tmpName), param->sessionId, param->actionId, param->isQosLane, param->isAsync);
AnonymizeFree(tmpName);
int32_t ret = INVALID_CHANNEL_ID;
uint32_t laneHandle = INVALID_LANE_REQ_ID;
@ -261,7 +261,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
if (ret != SOFTBUS_OK) {
Anonymize(param->sessionName, &tmpName);
TRANS_LOGE(TRANS_CTRL, "Async get Lane failed, sessionName=%{public}s, sessionId=%{public}d",
tmpName, param->sessionId);
AnonymizeWrapper(tmpName), param->sessionId);
AnonymizeFree(tmpName);
if (ret != SOFTBUS_TRANS_STOP_BIND_BY_CANCEL) {
TransFreeLane(laneHandle, param->isQosLane, param->isAsync);
@ -284,7 +284,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
Anonymize(param->sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL,
"sessionName=%{public}s, socket=%{public}d, laneHandle=%{public}u, linkType=%{public}u.",
tmpName, param->sessionId, laneHandle, connInfo.type);
AnonymizeWrapper(tmpName), param->sessionId, laneHandle, connInfo.type);
AnonymizeFree(tmpName);
ret = TransGetConnectOptByConnInfo(&connInfo, &connOpt);
if (ret != SOFTBUS_OK) {

View File

@ -295,7 +295,7 @@ void TransLaneMgrDeathCallback(const char *pkgName, int32_t pid)
}
char *anonymizePkgName = NULL;
Anonymize(pkgName, &anonymizePkgName);
TRANS_LOGW(TRANS_CTRL, "pkgName=%{public}s, pid=%{public}d", anonymizePkgName, pid);
TRANS_LOGW(TRANS_CTRL, "pkgName=%{public}s, pid=%{public}d", AnonymizeWrapper(anonymizePkgName), pid);
AnonymizeFree(anonymizePkgName);
if (SoftBusMutexLock(&(g_channelLaneList->lock)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "lock failed");
@ -399,7 +399,8 @@ static void AnonymizeLogSessionNameWhenNotFound(const char *sessionName, int32_t
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(
TRANS_SVC, "socket info not found. sessionName=%{public}s, sessionId=%{public}d", tmpName, sessionId);
TRANS_SVC, "socket info not found. sessionName=%{public}s, sessionId=%{public}d",
AnonymizeWrapper(tmpName), sessionId);
AnonymizeFree(tmpName);
}
@ -444,7 +445,8 @@ int32_t TransAddSocketChannelInfo(
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(
TRANS_SVC, "socket lane info has existed. socketId=%{public}d, sessionName=%{public}s", sessionId, tmpName);
TRANS_SVC, "socket lane info has existed. socketId=%{public}d, sessionName=%{public}s",
sessionId, AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
SoftBusFree(newSocket);
(void)SoftBusMutexUnlock(&(g_socketChannelList->lock));
@ -552,7 +554,7 @@ int32_t TransDeleteSocketChannelInfoBySession(const char *sessionName, int32_t s
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL, "delete socket channel info, sessionName=%{public}s, sessionId=%{public}d",
tmpName, sessionId);
AnonymizeWrapper(tmpName), sessionId);
AnonymizeFree(tmpName);
return SOFTBUS_OK;
}

View File

@ -95,7 +95,7 @@ static int32_t NotifyNormalChannelOpened(int32_t channelId, const AppInfo *appIn
if (ret != SOFTBUS_OK) {
char *anonyUuid = NULL;
Anonymize(appInfo->peerData.deviceId, &anonyUuid);
TRANS_LOGE(TRANS_CTRL, "get info networkId fail, uuid=%{public}s", anonyUuid);
TRANS_LOGE(TRANS_CTRL, "get info networkId fail, uuid=%{public}s", AnonymizeWrapper(anonyUuid));
AnonymizeFree(anonyUuid);
return ret;
}
@ -306,7 +306,7 @@ int32_t OnProxyChannelOpenFailed(int32_t channelId, const AppInfo *appInfo, int3
Anonymize(appInfo->myData.sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL,
"proxy channel openfailed:sessionName=%{public}s, channelId=%{public}d, appType=%{public}d, errCode=%{public}d",
tmpName, channelId, appInfo->appType, errCode);
AnonymizeWrapper(tmpName), channelId, appInfo->appType, errCode);
AnonymizeFree(tmpName);
return TransProxyNotifyOpenFailedByType(appInfo, appInfo->appType, channelId, errCode);
}

View File

@ -1937,7 +1937,7 @@ void TransProxyDeathCallback(const char *pkgName, int32_t pid)
(pkgName != NULL && g_proxyChannelList != NULL), TRANS_CTRL, "pkgName or proxy channel list is null.");
char *anonymizePkgName = NULL;
Anonymize(pkgName, &anonymizePkgName);
TRANS_LOGW(TRANS_CTRL, "pkgName=%{public}s, pid=%{public}d", anonymizePkgName, pid);
TRANS_LOGW(TRANS_CTRL, "pkgName=%{public}s, pid=%{public}d", AnonymizeWrapper(anonymizePkgName), pid);
AnonymizeFree(anonymizePkgName);
ListNode destroyList;
ListInit(&destroyList);

View File

@ -85,7 +85,7 @@ static int32_t GetRemoteUdidByBtMac(const char *peerMac, char *udid, int32_t len
Anonymize(peerMac, &tmpMac);
int32_t ret = LnnGetNetworkIdByBtMac(peerMac, networkId, sizeof(networkId));
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "LnnGetNetworkIdByBtMac fail, peerMac=%{public}s", tmpMac);
TRANS_LOGE(TRANS_CTRL, "LnnGetNetworkIdByBtMac fail, peerMac=%{public}s", AnonymizeWrapper(tmpMac));
AnonymizeFree(tmpMac);
return ret;
}
@ -249,7 +249,7 @@ int32_t TransProxyParseMessage(char *data, int32_t len, ProxyMessage *msg, AuthH
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "TransProxyParseMessageHead fail!");
if ((msg->msgHead.cipher & ENCRYPTED) != 0) {
if (msg->dateLen < sizeof(uint32_t)) {
if (msg->dateLen <= 0 || (uint32_t)msg->dateLen < sizeof(uint32_t)) {
TRANS_LOGE(TRANS_CTRL, "The data length of the ProxyMessage is abnormal!");
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
}

View File

@ -246,7 +246,7 @@ static void SendFailToFlushDevice(SessionConn *conn)
if (conn->appInfo.routeType == WIFI_STA) {
char *tmpId = NULL;
Anonymize(conn->appInfo.peerData.deviceId, &tmpId);
TRANS_LOGE(TRANS_CTRL, "send data fail, do Authflushdevice deviceId=%{public}s", tmpId);
TRANS_LOGE(TRANS_CTRL, "send data fail, do Authflushdevice deviceId=%{public}s", AnonymizeWrapper(tmpId));
AnonymizeFree(tmpId);
if (AuthFlushDevice(conn->appInfo.peerData.deviceId) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "tcp flush failed, wifi will offline");
@ -411,6 +411,7 @@ static int32_t NotifyChannelOpened(int32_t channelId)
info.timeStart = conn.appInfo.timeStart;
info.linkType = conn.appInfo.linkType;
info.connectType = conn.appInfo.connectType;
info.osType = conn.appInfo.osType;
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
ret = TransTdcGetPkgName(conn.appInfo.myData.sessionName, pkgName, PKG_NAME_SIZE_MAX);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "get pkg name fail.");
@ -716,7 +717,7 @@ static void OpenDataBusRequestOutSessionName(const char *mySessionName, const ch
Anonymize(mySessionName, &tmpMyName);
Anonymize(peerSessionName, &tmpPeerName);
TRANS_LOGI(TRANS_CTRL, "OpenDataBusRequest: mySessionName=%{public}s, peerSessionName=%{public}s",
tmpMyName, tmpPeerName);
AnonymizeWrapper(tmpMyName), AnonymizeWrapper(tmpPeerName));
AnonymizeFree(tmpMyName);
AnonymizeFree(tmpPeerName);
}
@ -943,7 +944,7 @@ static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t se
char *tmpName = NULL;
Anonymize(conn->appInfo.myData.sessionName, &tmpName);
TRANS_LOGI(TRANS_CTRL,
"Request denied: session is not a meta session. sessionName=%{public}s", tmpName);
"Request denied: session is not a meta session. sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
(void)memset_s(conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey), 0, sizeof(conn->appInfo.sessionKey));
ReleaseSessionConn(conn);
@ -1003,7 +1004,7 @@ static int32_t ProcessMessage(int32_t channelId, uint32_t flags, uint64_t seq, c
Anonymize(appInfo.peerNetWorkId, &tmpNetWorkId);
Anonymize(appInfo.peerUdid, &tmpUdid);
TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d, peerNetWorkId=%{public}s, peerUdid=%{public}s, ret=%{public}d",
channelId, tmpNetWorkId, tmpUdid, ret);
channelId, AnonymizeWrapper(tmpNetWorkId), AnonymizeWrapper(tmpUdid), ret);
AnonymizeFree(tmpNetWorkId);
AnonymizeFree(tmpUdid);
return ret;
@ -1021,7 +1022,7 @@ static ServerDataBuf *TransSrvGetDataBufNodeById(int32_t channelId)
return item;
}
}
TRANS_LOGE(TRANS_CTRL, "srv tcp direct channel id not exist.");
TRANS_LOGE(TRANS_CTRL, "srv tcp direct channelId=%{public}d not exist.", channelId);
return NULL;
}
@ -1057,7 +1058,8 @@ static int32_t GetAuthIdByChannelInfo(int32_t channelId, uint64_t seq, uint32_t
}
char *tmpPeerIp = NULL;
Anonymize(appInfo.peerData.addr, &tmpPeerIp);
TRANS_LOGE(TRANS_CTRL, "channelId=%{public}d get remote uuid by Ip=%{public}s failed", channelId, tmpPeerIp);
TRANS_LOGE(TRANS_CTRL, "channelId=%{public}d get remote uuid by Ip=%{public}s failed",
channelId, AnonymizeWrapper(tmpPeerIp));
AnonymizeFree(tmpPeerIp);
authHandle->type = connInfo.type;
authHandle->authId = AuthGetIdByConnInfo(&connInfo, !fromAuthServer, false);
@ -1289,46 +1291,93 @@ static int32_t TransRecvTdcSocketData(int32_t channelId, char *buffer, int32_t b
ret == SOFTBUS_OK, SOFTBUS_TRANS_TCP_GET_SRV_DATA_FAILED, TRANS_CTRL, "get info failed, ret=%{public}d", ret);
TRANS_CHECK_AND_RETURN_RET_LOGE(len >= (size_t)bufferSize, SOFTBUS_TRANS_TCP_GET_SRV_DATA_FAILED, TRANS_CTRL,
"freeBufferLen=%{public}zu less than bufferSize=%{public}d. channelId=%{public}d", len, bufferSize, channelId);
int32_t recvLen = ConnRecvSocketData(fd, buffer, bufferSize, 0);
if (recvLen < 0) {
TRANS_LOGE(TRANS_CTRL, " recv tcp data fail, channelId=%{public}d, retLen=%{public}d.", channelId, recvLen);
return SOFTBUS_TRANS_TCP_GET_SRV_DATA_FAILED;
} else if (recvLen == 0) {
TRANS_LOGE(TRANS_CTRL, "recv tcp data fail, retLen=0, channelId=%{public}d", channelId);
return SOFTBUS_DATA_NOT_ENOUGH;
int32_t totalRecvLen = 0;
while (totalRecvLen < bufferSize) {
int32_t recvLen = ConnRecvSocketData(fd, buffer, bufferSize - totalRecvLen, 0);
if (recvLen < 0) {
TRANS_LOGE(TRANS_CTRL, "recv tcp data fail, channelId=%{public}d, retLen=%{public}d, total=%{public}d, "
"totalRecv=%{public}d", channelId, recvLen, bufferSize, totalRecvLen);
return SOFTBUS_TRANS_TCP_GET_SRV_DATA_FAILED;
} else if (recvLen == 0) {
TRANS_LOGE(TRANS_CTRL, "recv tcp data fail, retLen=0, channelId=%{public}d, total=%{public}d, "
"totalRecv=%{public}d", channelId, bufferSize, totalRecvLen);
return SOFTBUS_DATA_NOT_ENOUGH;
}
if (TransTdcUpdateDataBufWInfo(channelId, buffer, recvLen) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "update channel data buf failed. channelId=%{public}d", channelId);
return SOFTBUS_TRANS_UPDATE_DATA_BUF_FAILED;
}
buffer += recvLen;
totalRecvLen += recvLen;
}
if (TransTdcUpdateDataBufWInfo(channelId, buffer, bufferSize) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "update channel data buf failed. channelId=%{public}d", channelId);
return SOFTBUS_TRANS_UPDATE_DATA_BUF_FAILED;
return SOFTBUS_OK;
}
/*
* The negotiation message may be unpacked, and when obtaining the message,
* it is necessary to first check whether the buffer of the channel already has data.
*/
static int32_t TransReadDataLen(int32_t channelId, int32_t *pktDataLen, int32_t module, int32_t type)
{
if (g_tcpSrvDataList == NULL) {
TRANS_LOGE(TRANS_CTRL, "tcp srv data list empty channelId=%{public}d %{public}d.", channelId, module);
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_tcpSrvDataList->lock) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "lock failed channelId=%{public}d %{public}d.", channelId, module);
return SOFTBUS_LOCK_ERR;
}
ServerDataBuf *dataBuf = TransSrvGetDataBufNodeById(channelId);
if (dataBuf == NULL) {
(void)SoftBusMutexUnlock(&g_tcpSrvDataList->lock);
return SOFTBUS_TRANS_TCP_DATABUF_NOT_FOUND;
}
const uint32_t headSize = sizeof(TdcPacketHead);
uint32_t bufDataLen = dataBuf->w - dataBuf->data;
const uint32_t maxDataLen = dataBuf->size - headSize;
TdcPacketHead *pktHeadPtr = NULL;
// channel buffer already has header data
if (bufDataLen >= headSize) {
bufDataLen -= headSize;
pktHeadPtr = (TdcPacketHead *)(dataBuf->data);
// obtain the remaining length of data to be read
*pktDataLen = pktHeadPtr->dataLen - bufDataLen;
(void)SoftBusMutexUnlock(&g_tcpSrvDataList->lock);
return SOFTBUS_OK;
}
(void)SoftBusMutexUnlock(&g_tcpSrvDataList->lock);
TdcPacketHead pktHead;
(void)memset_s(&pktHead, sizeof(pktHead), 0, sizeof(pktHead));
int32_t ret = TransRecvTdcSocketData(channelId, (char *)&pktHead, headSize);
if (ret != SOFTBUS_OK) {
return ret;
}
UnpackTdcPacketHead(&pktHead);
if (pktHead.magicNumber != MAGIC_NUMBER || pktHead.dataLen > maxDataLen || pktHead.dataLen == 0) {
TRANS_LOGE(TRANS_CTRL, "invalid packet head module=%{public}d, channelId=%{public}d, type=%{public}d, "
"magic=%{public}x, len=%{public}d", module, channelId, type, pktHead.magicNumber, pktHead.dataLen);
return SOFTBUS_TRANS_UNPACK_PACKAGE_HEAD_FAILED;
}
*pktDataLen = pktHead.dataLen;
return SOFTBUS_OK;
}
int32_t TransTdcSrvRecvData(ListenerModule module, int32_t channelId, int32_t type)
{
int32_t headSize = sizeof(TdcPacketHead);
char *headBuf = (char *)SoftBusCalloc(headSize);
if (headBuf == NULL) {
TRANS_LOGE(TRANS_CTRL, "malloc failed. channelId=%{public}d, len=%{public}d", channelId, headSize);
return SOFTBUS_MALLOC_ERR;
}
int32_t ret = TransRecvTdcSocketData(channelId, headBuf, headSize);
if (ret != SOFTBUS_OK) {
SoftBusFree(headBuf);
return ret;
}
TdcPacketHead *pktHead = (TdcPacketHead *)headBuf;
UnpackTdcPacketHead(pktHead);
if (pktHead->magicNumber != MAGIC_NUMBER) {
TRANS_LOGE(TRANS_CTRL,
"srv recv invalid packet head listenerModule=%{public}d, channelId=%{public}d, type=%{public}d",
(int32_t)module, channelId, type);
SoftBusFree(headBuf);
return SOFTBUS_TRANS_UNPACK_PACKAGE_HEAD_FAILED;
}
int32_t dataSize = (int32_t)pktHead->dataLen;
SoftBusFree(headBuf);
int32_t dataSize = 0;
int32_t ret = TransReadDataLen(channelId, &dataSize, (int32_t)module, type);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_TRANS_TCP_GET_SRV_DATA_FAILED,
TRANS_CTRL, "read dataLen failed, ret=%{public}d", ret);
char *dataBuffer = (char *)SoftBusCalloc(dataSize);
if (dataBuffer == NULL) {

View File

@ -204,7 +204,7 @@ void StopP2pListenerByRemoteUuid(const char *peerUuid)
LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_p2pSessionInfo.peerDeviceInfoList->list, P2pListenerInfo, node) {
if (strcmp(item->peerUuid, peerUuid) == 0) {
ListDelete(&item->node);
TRANS_LOGI(TRANS_CTRL, "del p2p listener peerUuid=%{public}s node", anonymizePeerUuid);
TRANS_LOGI(TRANS_CTRL, "del p2p listener peerUuid=%{public}s node", AnonymizeWrapper(anonymizePeerUuid));
AnonymizeFree(anonymizePeerUuid);
SoftBusFree(item);
g_p2pSessionInfo.peerDeviceInfoList->cnt--;
@ -218,7 +218,7 @@ void StopP2pListenerByRemoteUuid(const char *peerUuid)
}
}
(void)SoftBusMutexUnlock(&g_p2pSessionInfo.peerDeviceInfoList->lock);
TRANS_LOGE(TRANS_CTRL, "not found peerUuid=%{public}s in peerDeviceInfoList", anonymizePeerUuid);
TRANS_LOGE(TRANS_CTRL, "not found peerUuid=%{public}s in peerDeviceInfoList", AnonymizeWrapper(anonymizePeerUuid));
AnonymizeFree(anonymizePeerUuid);
}
@ -408,7 +408,7 @@ static void AnonymizeIp(const char *ip, char *sessionIp, int32_t port)
Anonymize(ip, &temp);
Anonymize(sessionIp, &anonyP2pIp);
TRANS_LOGE(TRANS_CTRL, "param invalid g_p2pSessionPort=%{public}d, ip=%{public}s, g_p2pSessionIp=%{public}s",
port, temp, anonyP2pIp);
port, AnonymizeWrapper(temp), AnonymizeWrapper(anonyP2pIp));
AnonymizeFree(temp);
AnonymizeFree(anonyP2pIp);
}
@ -425,7 +425,7 @@ static void CheckAndAddPeerDeviceInfo(const char *peerUuid)
P2pListenerInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_p2pSessionInfo.peerDeviceInfoList->list, P2pListenerInfo, node) {
if (strncmp(item->peerUuid, peerUuid, UUID_BUF_LEN) == 0) {
TRANS_LOGD(TRANS_CTRL, "exit p2pListener with peerUuid=%{public}s", anonymizePeerUuid);
TRANS_LOGD(TRANS_CTRL, "exit p2pListener with peerUuid=%{public}s", AnonymizeWrapper(anonymizePeerUuid));
AnonymizeFree(anonymizePeerUuid);
return;
}

View File

@ -484,7 +484,8 @@ void TransTdcChannelInfoDeathCallback(const char *pkgName, int32_t pid)
{
char *anonymizePkgName = NULL;
Anonymize(pkgName, &anonymizePkgName);
TRANS_LOGI(TRANS_CTRL, "pkgName=%{public}s pid=%{public}d died, clean all resource", anonymizePkgName, pid);
TRANS_LOGI(TRANS_CTRL, "pkgName=%{public}s pid=%{public}d died, clean all resource",
AnonymizeWrapper(anonymizePkgName), pid);
AnonymizeFree(anonymizePkgName);
if (g_tcpChannelInfoList == NULL) {
TRANS_LOGE(TRANS_CTRL, "g_tcpChannelInfoList is null.");

View File

@ -1215,7 +1215,7 @@ void TransUdpDeathCallback(const char *pkgName, int32_t pid)
ListAdd(&destroyList, &tempNode->node);
char *anonymizePkgName = NULL;
Anonymize(pkgName, &anonymizePkgName);
TRANS_LOGW(TRANS_CTRL, "add pkgName=%{public}s, pid=%{public}d", anonymizePkgName, pid);
TRANS_LOGW(TRANS_CTRL, "add pkgName=%{public}s, pid=%{public}d", AnonymizeWrapper(anonymizePkgName), pid);
AnonymizeFree(anonymizePkgName);
}
}

View File

@ -494,6 +494,18 @@ typedef struct {
* @version 1.0
*/
void (*onNodeStatusChanged)(NodeStatusType type, NodeStatus *status);
/**
* @brief Called when the devices have non-consistent group relationship.
*
* @param deviceId The device id.
* @param deviceIdLen The device id length.
* @param deviceTypeId The device type id.
* @param errcode Indicates the result code.
*
* @since 1.0
* @version 1.0
*/
void (*onHichainProofException)(uint16_t deviceTypeId, int32_t errCode);
} INodeStateCb;
/**

View File

@ -477,6 +477,10 @@ enum SoftBusErrNo {
SOFTBUS_CHANNEL_AUTH_PACK_DATA_FAIL,
SOFTBUS_CHANNEL_AUTH_UNPACK_DATA_FAIL,
SOFTBUS_CHANNEL_AUTH_GET_INSTANCE_FAIL,
SOFTBUS_AUTH_SYNC_DEVICEID_TIMEOUT,
SOFTBUS_AUTH_HICHAIN_TIMEOUT,
SOFTBUS_AUTH_SAVE_SESSIONKEY_TIMEOUT,
SOFTBUS_AUTH_SYNC_DEVICEINFO_TIMEOUT,
/* errno begin: -((203 << 21) | (4 << 16) | 0xFFFF) */
SOFTBUS_NETWORK_ERR_BASE = SOFTBUS_ERRNO(LNN_SUB_MODULE_CODE),
@ -551,6 +555,10 @@ enum SoftBusErrNo {
SOFTBUS_NETWORK_PROXY_READINT_FAILED,
SOFTBUS_NETWORK_READRAWDATA_FAILED,
SOFTBUS_NETWORK_GET_ACCOUNT_INFO_FAILED,
SOFTBUS_NETWORK_SEND_SYNC_INFO_FAILED,
SOFTBUS_NETWORK_FSM_INIT_FAILED,
SOFTBUS_NETWORK_BLE_DISABLE,
SOFTBUS_NETWORK_BLE_DIRECT_FAILED,
SOFTBUS_NETWORK_LEDGER_INIT_FAILED,
SOFTBUS_NETWORK_MANAGER_INIT_FAILED,
SOFTBUS_NETWORK_BUILDER_INIT_FAILED,

View File

@ -62,6 +62,8 @@ int32_t LnnOnNodeBasicInfoChanged(const char *pkgName, void *info, int32_t type)
int32_t LnnOnNodeStatusChanged(const char *pkgName, void *info, int32_t type);
int32_t LnnOnLocalNetworkIdChanged(const char *pkgName);
int32_t LnnOnNodeDeviceTrustedChange(const char *pkgName, int32_t type, const char *msg, uint32_t msgLen);
int32_t LnnOnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode);
int32_t LnnOnTimeSyncResult(const void *info, int32_t retCode);
void LnnOnPublishLNNResult(int32_t publishId, int32_t reason);
void LnnOnRefreshLNNResult(int32_t refreshId, int32_t reason);

View File

@ -1296,6 +1296,51 @@ int32_t LnnOnNodeDeviceTrustedChange(const char *pkgName, int32_t type, const ch
return SOFTBUS_OK;
}
int32_t LnnOnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
(void)deviceId;
(void)deviceIdLen;
NodeStateCallbackItem *item = NULL;
ListNode dupList;
if (pkgName == NULL) {
LNN_LOGE(LNN_STATE, "pkgName is null");
return SOFTBUS_INVALID_PARAM;
}
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "lock auth restrict cb list in notify");
return SOFTBUS_LOCK_ERR;
}
ListInit(&dupList);
DuplicateNodeStateCbList(&dupList);
if (SoftBusMutexUnlock(&g_busCenterClient.lock) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "unlock auth restrict cb list in notify");
}
char *anonyPkgName = NULL;
char *anonyDeviceId = NULL;
Anonymize(pkgName, &anonyPkgName);
Anonymize(deviceId, &anonyDeviceId);
LIST_FOR_EACH_ENTRY(item, &dupList, NodeStateCallbackItem, node) {
if (((strcmp(item->pkgName, pkgName) == 0) || (strlen(pkgName) == 0)) &&
(item->cb.onHichainProofException) != NULL) {
item->cb.onHichainProofException(deviceTypeId, errCode);
LNN_LOGI(LNN_STATE,
"onHichainProofException, pkgName=%{public}s, deviceId=%{public}s, errCode=%{public}d, "
"type=%{public}hu",
AnonymizeWrapper(anonyPkgName), AnonymizeWrapper(anonyDeviceId), errCode, deviceTypeId);
}
}
AnonymizeFree(anonyPkgName);
AnonymizeFree(anonyDeviceId);
ClearNodeStateCbList(&dupList);
return SOFTBUS_OK;
}
int32_t LnnOnTimeSyncResult(const void *info, int32_t retCode)
{
TimeSyncCallbackItem *item = NULL;

View File

@ -63,6 +63,9 @@ public:
virtual int32_t OnNodeDeviceTrustedChange(const char *pkgName, int32_t type, const char *msg, uint32_t msgLen);
virtual int32_t OnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode);
virtual int32_t OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode);
virtual void OnPublishLNNResult(int32_t publishId, int32_t reason);

View File

@ -51,6 +51,8 @@ public:
int32_t OnNodeStatusChanged(const char *pkgName, void *info, uint32_t infoTypeLen, int32_t type) override;
int32_t OnLocalNetworkIdChanged(const char *pkgName) override;
int32_t OnNodeDeviceTrustedChange(const char *pkgName, int32_t type, const char *msg, uint32_t msgLen) override;
int32_t OnHichainProofException(const char *pkgName, const char *deviceId, uint32_t deviceIdLen,
uint16_t deviceTypeId, int32_t errCode) override;
int32_t OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode) override;
void OnPublishLNNResult(int32_t publishId, int32_t reason) override;
void OnRefreshLNNResult(int32_t refreshId, int32_t reason) override;
@ -74,6 +76,7 @@ private:
int32_t OnNodeStatusChangedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnLocalNetworkIdChangedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnNodeDeviceTrustedChangeInner(MessageParcel &data, MessageParcel &reply);
int32_t OnHichainProofExceptionInner(MessageParcel &data, MessageParcel &reply);
int32_t OnTimeSyncResultInner(MessageParcel &data, MessageParcel &reply);
int32_t OnPublishLNNResultInner(MessageParcel &data, MessageParcel &reply);
int32_t OnRefreshLNNResultInner(MessageParcel &data, MessageParcel &reply);

View File

@ -126,6 +126,18 @@ int32_t ISoftBusClient::OnNodeDeviceTrustedChange(const char *pkgName, int32_t t
return SOFTBUS_OK;
}
int32_t ISoftBusClient::OnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
(void)pkgName;
(void)deviceId;
(void)deviceIdLen;
(void)deviceTypeId;
(void)errCode;
COMM_LOGI(COMM_EVENT, "ipc default impl");
return SOFTBUS_OK;
}
int32_t ISoftBusClient::OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");

View File

@ -48,6 +48,7 @@ SoftBusClientStub::SoftBusClientStub()
memberFuncMap_[CLIENT_ON_NODE_STATUS_CHANGED] = &SoftBusClientStub::OnNodeStatusChangedInner;
memberFuncMap_[CLIENT_ON_LOCAL_NETWORK_ID_CHANGED] = &SoftBusClientStub::OnLocalNetworkIdChangedInner;
memberFuncMap_[CLIENT_ON_NODE_DEVICE_TRUST_CHANGED] = &SoftBusClientStub::OnNodeDeviceTrustedChangeInner;
memberFuncMap_[CLIENT_ON_HICHAIN_PROOF_EXCEPTION] = &SoftBusClientStub::OnHichainProofExceptionInner;
memberFuncMap_[CLIENT_ON_TIME_SYNC_RESULT] = &SoftBusClientStub::OnTimeSyncResultInner;
memberFuncMap_[CLIENT_ON_PUBLISH_LNN_RESULT] = &SoftBusClientStub::OnPublishLNNResultInner;
memberFuncMap_[CLIENT_ON_REFRESH_LNN_RESULT] = &SoftBusClientStub::OnRefreshLNNResultInner;
@ -540,6 +541,41 @@ int32_t SoftBusClientStub::OnNodeDeviceTrustedChangeInner(MessageParcel &data, M
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnHichainProofExceptionInner(MessageParcel &data, MessageParcel &reply)
{
const char *pkgName = data.ReadCString();
if (pkgName == nullptr || strlen(pkgName) == 0) {
COMM_LOGE(COMM_SDK, "Invalid package name, or length is zero");
return SOFTBUS_INVALID_PARAM;
}
uint32_t deviceIdLen = 0;
if (!data.ReadUint32(deviceIdLen) || deviceIdLen != UDID_BUF_LEN) {
COMM_LOGE(COMM_SDK, "read failed! deviceIdLen=%{public}u", deviceIdLen);
return SOFTBUS_TRANS_PROXY_READINT_FAILED;
}
char *deviceId = (char *)data.ReadRawData(deviceIdLen);
if (deviceId == nullptr) {
COMM_LOGE(COMM_SDK, "read deviceId failed!");
return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
}
uint16_t deviceTypeId = 0;
if (!data.ReadUint16(deviceTypeId)) {
COMM_LOGE(COMM_SDK, "read failed! deviceTypeId=%{public}hu", deviceTypeId);
return SOFTBUS_TRANS_PROXY_READINT_FAILED;
}
int32_t errCode = 0;
if (!data.ReadInt32(errCode)) {
COMM_LOGE(COMM_SDK, "read failed! errCode=%{public}d", errCode);
return SOFTBUS_TRANS_PROXY_READINT_FAILED;
}
int32_t retReply = OnHichainProofException(pkgName, deviceId, deviceIdLen, deviceTypeId, errCode);
if (!reply.WriteInt32(retReply)) {
COMM_LOGE(COMM_SDK, "OnHichainProofException write reply failed!");
return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
}
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnTimeSyncResultInner(MessageParcel &data, MessageParcel &reply)
{
uint32_t infoTypeLen;
@ -695,6 +731,12 @@ int32_t SoftBusClientStub::OnNodeDeviceTrustedChange(const char *pkgName, int32_
return LnnOnNodeDeviceTrustedChange(pkgName, type, msg, msgLen);
}
int32_t SoftBusClientStub::OnHichainProofException(
const char *pkgName, const char *deviceId, uint32_t deviceIdLen, uint16_t deviceTypeId, int32_t errCode)
{
return LnnOnHichainProofException(pkgName, deviceId, deviceIdLen, deviceTypeId, errCode);
}
int32_t SoftBusClientStub::OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode)
{
(void)infoTypeLen;

View File

@ -312,7 +312,7 @@ int32_t TransServerProxy::OpenAuthSession(const char *sessionName, const Connect
}
char *tmpName = nullptr;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "ServerIpcOpenAuthSession begin. sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "ServerIpcOpenAuthSession begin. sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {

View File

@ -97,6 +97,7 @@ typedef struct {
uint32_t dataConfig;
SocketLifecycleData lifecycle;
uint32_t actionId;
int32_t osType;
} SessionInfo;
typedef struct {
@ -286,6 +287,8 @@ void SocketServerStateUpdate(const char *sessionName);
int32_t ClientCancelAuthSessionTimer(int32_t sessionId);
int32_t ClientSetStatusClosingBySocket(int32_t socket, bool isClosing);
int32_t ClientGetChannelOsTypeBySessionId(int32_t sessionId, int32_t *osType);
#ifdef __cplusplus
}
#endif

View File

@ -28,6 +28,8 @@
#include "softbus_adapter_mem.h"
#include "trans_log.h"
#define OH_OS_TYPE 10
int CheckSendLen(int32_t channelId, int32_t channelType, unsigned int len, int32_t businessType)
{
uint32_t dataConfig = INVALID_DATA_CONFIG;
@ -79,11 +81,15 @@ int SendBytes(int sessionId, const void *data, unsigned int len)
TRANS_BYTES, "ClientGetChannelBySessionId fail, sessionId=%{public}d", sessionId);
int32_t businessType = BUSINESS_TYPE_BUTT;
int32_t osType = OH_OS_TYPE;
ret = ClientGetChannelBusinessTypeBySessionId(sessionId, &businessType);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret,
TRANS_BYTES, "ClientGetChannelBusinessTypeBySessionId fail, sessionId=%{public}d", sessionId);
ret = ClientGetChannelOsTypeBySessionId(sessionId, &osType);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret,
TRANS_BYTES, "ClientGetChannelOsTypeBySessionId fail, sessionId=%{public}d", sessionId);
if ((businessType != BUSINESS_TYPE_BYTE) && (businessType != BUSINESS_TYPE_NOT_CARE) &&
if ((osType == OH_OS_TYPE) && (businessType != BUSINESS_TYPE_BYTE) && (businessType != BUSINESS_TYPE_NOT_CARE) &&
(channelType != CHANNEL_TYPE_AUTH)) {
TRANS_LOGE(TRANS_BYTES,
"BusinessType no match, businessType=%{public}d, sessionId=%{public}d", businessType, sessionId);

View File

@ -59,6 +59,7 @@ static int32_t AcceptSessionAsServer(const char *sessionName, const ChannelInfo
session->crc = channel->crc;
session->dataConfig = channel->dataConfig;
session->isAsync = false;
session->osType = channel->osType;
session->lifecycle.sessionState = SESSION_STATE_CALLBACK_FINISHED;
if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, channel->peerSessionName) != EOK ||
strcpy_s(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX, channel->peerDeviceId) != EOK ||
@ -308,8 +309,8 @@ static void AnonymizeLogTransOnSessionOpenedInfo(const char *sessionName, const
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK,
"TransOnSessionOpened: sessionName=%{public}s, channelId=%{public}d, channelType=%{public}d, flag=%{public}d,"
"isServer=%{public}d, type=%{public}d, crc=%{public}d",
tmpName, channel->channelId, channel->channelType, flag, channel->isServer, channel->routeType, channel->crc);
"isServer=%{public}d, type=%{public}d, crc=%{public}d", AnonymizeWrapper(tmpName), channel->channelId,
channel->channelType, flag, channel->isServer, channel->routeType, channel->crc);
AnonymizeFree(tmpName);
}
@ -613,7 +614,7 @@ int32_t ClientTransIfChannelForSocket(const char *sessionName, bool *isSocket)
if (ret != SOFTBUS_OK) {
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "get session callback failed, sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_SDK, "get session callback failed, sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return ret;
}

View File

@ -163,8 +163,8 @@ static void ShowAllSessionInfo(void)
char *tmpName = NULL;
LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
Anonymize(serverNode->sessionName, &tmpName);
TRANS_LOGI(
TRANS_SDK, "client session server is exist. count=%{public}d, sessionName=%{public}s", count, tmpName);
TRANS_LOGI(TRANS_SDK, "client session server is exist. count=%{public}d, sessionName=%{public}s",
count, AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
count++;
if (IsListEmpty(&serverNode->sessionList)) {
@ -177,7 +177,7 @@ static void ShowAllSessionInfo(void)
TRANS_LOGI(TRANS_SDK,
"client session info is exist. sessionCount=%{public}d, peerSessionName=%{public}s, "
"channelId=%{public}d, channelType=%{public}d",
sessionCount, tmpPeerSessionName, sessionNode->channelId, sessionNode->channelType);
sessionCount, AnonymizeWrapper(tmpPeerSessionName), sessionNode->channelId, sessionNode->channelType);
AnonymizeFree(tmpPeerSessionName);
sessionCount++;
}
@ -254,13 +254,14 @@ int32_t TryDeleteEmptySessionServer(const char *pkgName, const char *sessionName
AnonymizeFree(tmpName);
return ret;
}
TRANS_LOGI(TRANS_SDK, "delete empty session server, sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "delete empty session server, sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_OK;
}
}
UnlockClientSessionServerList();
TRANS_LOGE(TRANS_SDK, "not found session server or session list is not empty, sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_SDK, "not found session server or session list is not empty, sessionName=%{public}s",
AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
}
@ -345,7 +346,7 @@ void SocketServerStateUpdate(const char *sessionName)
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "not found session server by sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_SDK, "not found session server by sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
UnlockClientSessionServerList();
}
@ -359,7 +360,8 @@ static void ShowClientSessionServer(void)
LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &g_clientSessionServerList->list, ClientSessionServer, node) {
Anonymize(pos->sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK,
"client session server is exist. count=%{public}d, sessionName=%{public}s", count, tmpName);
"client session server is exist. count=%{public}d, sessionName=%{public}s",
count, AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
count++;
}
@ -1123,6 +1125,7 @@ int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sess
sessionNode->algorithm = channel->algorithm;
sessionNode->crc = channel->crc;
sessionNode->isEncrypt = channel->isEncrypt;
sessionNode->osType = channel->osType;
*sessionId = sessionNode->sessionId;
if (channel->channelType == CHANNEL_TYPE_AUTH || !sessionNode->isEncrypt) {
ClientSetAuthSessionTimer(serverNode, sessionNode);
@ -1204,7 +1207,7 @@ int32_t ClientGetSessionCallbackByName(const char *sessionName, ISessionListener
UnlockClientSessionServerList();
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "not found session by sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_SDK, "not found session by sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
}
@ -1285,7 +1288,7 @@ void ClientTransOnLinkDown(const char *networkId, int32_t routeType)
}
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
TRANS_LOGD(TRANS_SDK, "routeType=%{public}d, networkId=%{public}s", routeType, anonyNetworkId);
TRANS_LOGD(TRANS_SDK, "routeType=%{public}d, networkId=%{public}s", routeType, AnonymizeWrapper(anonyNetworkId));
AnonymizeFree(anonyNetworkId);
ClientSessionServer *serverNode = NULL;
@ -1414,7 +1417,8 @@ int32_t ClientAddSocketServer(SoftBusSecType type, const char *pkgName, const ch
char *tmpName = NULL;
Anonymize(pkgName, &anonymizePkgName);
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "sessionName=%{public}s, pkgName=%{public}s", tmpName, anonymizePkgName);
TRANS_LOGE(TRANS_SDK, "sessionName=%{public}s, pkgName=%{public}s",
AnonymizeWrapper(tmpName), AnonymizeWrapper(anonymizePkgName));
AnonymizeFree(anonymizePkgName);
AnonymizeFree(tmpName);
return SOFTBUS_OK;
@ -1985,7 +1989,7 @@ int32_t ClientRawStreamEncryptDefOptGet(const char *sessionName, bool *isEncrypt
UnlockClientSessionServerList();
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "not found ClientSessionServer by sessionName=%{public}s", tmpName);
TRANS_LOGE(TRANS_SDK, "not found ClientSessionServer by sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return SOFTBUS_TRANS_SESSION_SERVER_NOT_FOUND;
}
@ -2442,3 +2446,28 @@ int32_t ClientCancelAuthSessionTimer(int32_t sessionId)
TRANS_LOGE(TRANS_SDK, "not found ishare auth session by sessionId=%{public}d", sessionId);
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
}
int32_t ClientGetChannelOsTypeBySessionId(int32_t sessionId, int32_t *osType)
{
if ((sessionId < 0) || (osType == NULL)) {
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = LockClientSessionServerList();
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "lock failed");
return ret;
}
ClientSessionServer *serverNode = NULL;
SessionInfo *sessionNode = NULL;
if (GetSessionById(sessionId, &serverNode, &sessionNode) != SOFTBUS_OK) {
UnlockClientSessionServerList();
TRANS_LOGE(TRANS_SDK, "session not found. sessionId=%{public}d", sessionId);
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
}
*osType = sessionNode->osType;
UnlockClientSessionServerList();
return SOFTBUS_OK;
}

View File

@ -111,7 +111,7 @@ int CreateSessionServer(const char *pkgName, const char *sessionName, const ISes
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "pkgName=%{public}s, sessionName=%{public}s", pkgName, tmpName);
TRANS_LOGI(TRANS_SDK, "pkgName=%{public}s, sessionName=%{public}s", pkgName, AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
if (InitSoftBus(pkgName) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "init softbus err");
@ -152,7 +152,7 @@ int RemoveSessionServer(const char *pkgName, const char *sessionName)
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "pkgName=%{public}s, sessionName=%{public}s", pkgName, tmpName);
TRANS_LOGI(TRANS_SDK, "pkgName=%{public}s, sessionName=%{public}s", pkgName, AnonymizeWrapper(tmpName));
int32_t ret = ServerIpcRemoveSessionServer(pkgName, sessionName);
if (ret != SOFTBUS_OK) {
@ -163,7 +163,8 @@ int RemoveSessionServer(const char *pkgName, const char *sessionName)
ret = ClientDeleteSessionServer(SEC_TYPE_CIPHERTEXT, sessionName);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "delete session server failed, sessionName=%{public}s, ret=%{public}d.", tmpName, ret);
TRANS_LOGE(TRANS_SDK, "delete session server failed, sessionName=%{public}s, ret=%{public}d.",
AnonymizeWrapper(tmpName), ret);
DeleteFileListener(sessionName);
AnonymizeFree(tmpName);
return ret;
@ -180,21 +181,21 @@ static int32_t CheckParamIsValid(const char *mySessionName, const char *peerSess
if (!IsValidString(mySessionName, SESSION_NAME_SIZE_MAX - 1)) {
char *tmpMyName = NULL;
Anonymize(mySessionName, &tmpMyName);
TRANS_LOGE(TRANS_SDK, "invalid mySessionName. tmpMyName=%{public}s", tmpMyName);
TRANS_LOGE(TRANS_SDK, "invalid mySessionName. tmpMyName=%{public}s", AnonymizeWrapper(tmpMyName));
AnonymizeFree(tmpMyName);
return SOFTBUS_TRANS_INVALID_SESSION_NAME;
}
if (!IsValidString(peerSessionName, SESSION_NAME_SIZE_MAX - 1)) {
char *tmpPeerName = NULL;
Anonymize(peerSessionName, &tmpPeerName);
TRANS_LOGE(TRANS_SDK, "invalid peerSessionName. tmpPeerName=%{public}s", tmpPeerName);
TRANS_LOGE(TRANS_SDK, "invalid peerSessionName. tmpPeerName=%{public}s", AnonymizeWrapper(tmpPeerName));
AnonymizeFree(tmpPeerName);
return SOFTBUS_TRANS_INVALID_SESSION_NAME;
}
if (!IsValidString(peerNetworkId, DEVICE_ID_SIZE_MAX - 1)) {
char *tmpPeerNetworkId = NULL;
Anonymize(peerNetworkId, &tmpPeerNetworkId);
TRANS_LOGE(TRANS_SDK, "invalid peerNetworkId. tmpPeerNetworkId=%{public}s", tmpPeerNetworkId);
TRANS_LOGE(TRANS_SDK, "invalid peerNetworkId. tmpPeerNetworkId=%{public}s", AnonymizeWrapper(tmpPeerNetworkId));
AnonymizeFree(tmpPeerNetworkId);
return SOFTBUS_INVALID_PARAM;
}
@ -221,7 +222,7 @@ static void PrintSessionName(const char *mySessionName, const char *peerSessionN
Anonymize(mySessionName, &tmpMyName);
Anonymize(peerSessionName, &tmpPeerName);
TRANS_LOGI(TRANS_SDK, "OpenSession: mySessionName=%{public}s, peerSessionName=%{public}s",
tmpMyName, tmpPeerName);
AnonymizeWrapper(tmpMyName), AnonymizeWrapper(tmpPeerName));
AnonymizeFree(tmpMyName);
AnonymizeFree(tmpPeerName);
}
@ -408,7 +409,7 @@ int OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo, int
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
int32_t sessionId;
int32_t ret = ClientAddAuthSession(sessionName, &sessionId);
@ -647,7 +648,7 @@ int SetFileReceiveListener(const char *pkgName, const char *sessionName,
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return TransSetFileReceiveListener(sessionName, recvListener, rootDir);
}
@ -665,7 +666,7 @@ int SetFileSendListener(const char *pkgName, const char *sessionName, const IFil
}
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return TransSetFileSendListener(sessionName, sendListener);
}

View File

@ -180,7 +180,7 @@ void DestroyClientSessionServer(ClientSessionServer *server, ListNode *destroyLi
ListDelete(&(server->node));
char *tmpName = NULL;
Anonymize(server->sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "destroy session server sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "destroy session server sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
SoftBusFree(server);
}
@ -495,7 +495,7 @@ SessionInfo *CreateNewSocketSession(const SessionParam *param)
char *anonySessionName = NULL;
Anonymize(param->peerSessionName, &anonySessionName);
TRANS_LOGI(TRANS_SDK, "strcpy peerName failed, peerName=%{public}s, peerNameLen=%{public}zu",
anonySessionName, strlen(param->peerSessionName));
AnonymizeWrapper(anonySessionName), strlen(param->peerSessionName));
AnonymizeFree(anonySessionName);
SoftBusFree(session);
return NULL;
@ -506,7 +506,7 @@ SessionInfo *CreateNewSocketSession(const SessionParam *param)
char *anonyNetworkId = NULL;
Anonymize(param->peerDeviceId, &anonyNetworkId);
TRANS_LOGI(TRANS_SDK, "strcpy peerDeviceId failed, peerDeviceId=%{public}s, peerDeviceIdLen=%{public}zu",
anonyNetworkId, strlen(param->peerDeviceId));
AnonymizeWrapper(anonyNetworkId), strlen(param->peerDeviceId));
AnonymizeFree(anonyNetworkId);
SoftBusFree(session);
return NULL;
@ -543,8 +543,8 @@ int32_t CheckBindSocketInfo(const SessionInfo *session)
Anonymize(session->info.peerSessionName, &anonySessionName);
Anonymize(session->info.peerDeviceId, &anonyNetworkId);
TRANS_LOGI(TRANS_SDK, "invalid peerName=%{public}s, peerNameLen=%{public}zu, peerNetworkId=%{public}s, "
"peerNetworkIdLen=%{public}zu", anonySessionName,
strlen(session->info.peerSessionName), anonyNetworkId, strlen(session->info.peerDeviceId));
"peerNetworkIdLen=%{public}zu", AnonymizeWrapper(anonySessionName), strlen(session->info.peerSessionName),
AnonymizeWrapper(anonyNetworkId), strlen(session->info.peerDeviceId));
AnonymizeFree(anonyNetworkId);
AnonymizeFree(anonySessionName);
return SOFTBUS_INVALID_PARAM;
@ -752,7 +752,7 @@ int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList)
int32_t ret = ServerIpcCreateSessionServer(infoNode->pkgName, infoNode->sessionName);
Anonymize(infoNode->sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s, pkgName=%{public}s, ret=%{public}d",
tmpName, infoNode->pkgName, ret);
AnonymizeWrapper(tmpName), infoNode->pkgName, ret);
AnonymizeFree(tmpName);
ListDelete(&infoNode->node);
SoftBusFree(infoNode);
@ -820,7 +820,7 @@ int32_t ClientGrantPermission(int uid, int pid, const char *busName)
}
char *tmpName = NULL;
Anonymize(busName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
int32_t ret = ServerIpcGrantPermission(uid, pid, busName);
if (ret != SOFTBUS_OK) {
@ -837,7 +837,7 @@ int32_t ClientRemovePermission(const char *busName)
}
char *tmpName = NULL;
Anonymize(busName, &tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
int32_t ret = ServerIpcRemovePermission(busName);
if (ret != SOFTBUS_OK) {

View File

@ -43,7 +43,7 @@ static int32_t CheckSocketInfoIsValid(const SocketInfo *info)
char *anonySessionName = NULL;
Anonymize(info->peerName, &anonySessionName);
TRANS_LOGI(TRANS_SDK, "strcpy peerName failed, peerName=%{public}s, peerNameLen=%{public}zu",
anonySessionName, strlen(info->peerName));
AnonymizeWrapper(anonySessionName), strlen(info->peerName));
AnonymizeFree(anonySessionName);
return SOFTBUS_INVALID_PARAM;
}
@ -52,7 +52,7 @@ static int32_t CheckSocketInfoIsValid(const SocketInfo *info)
char *anonyNetworkId = NULL;
Anonymize(info->peerNetworkId, &anonyNetworkId);
TRANS_LOGI(TRANS_SDK, "strcpy peerNetworkId failed, peerNetworkId=%{public}s, peerNetworkIdLen=%{public}zu",
anonyNetworkId, strlen(info->peerNetworkId));
AnonymizeWrapper(anonyNetworkId), strlen(info->peerNetworkId));
AnonymizeFree(anonyNetworkId);
return SOFTBUS_INVALID_PARAM;
}
@ -71,8 +71,8 @@ static void PrintSocketInfo(const SocketInfo *info)
Anonymize(info->pkgName, &tmpPkgName);
TRANS_LOGI(TRANS_SDK,
"Socket: mySessionName=%{public}s, peerSessionName=%{public}s, peerNetworkId=%{public}s, "
"pkgName=%{public}s, dataType=%{public}d",
tmpMyName, tmpPeerName, tmpPeerNetworkId, tmpPkgName, info->dataType);
"pkgName=%{public}s, dataType=%{public}d", AnonymizeWrapper(tmpMyName), AnonymizeWrapper(tmpPeerName),
AnonymizeWrapper(tmpPeerNetworkId), AnonymizeWrapper(tmpPkgName), info->dataType);
AnonymizeFree(tmpMyName);
AnonymizeFree(tmpPeerName);
AnonymizeFree(tmpPeerNetworkId);

View File

@ -342,7 +342,7 @@ int32_t ClientTransProxyOnChannelOpened(const char *sessionName, const ChannelIn
(void)ClientTransProxyDelChannelInfo(channel->channelId);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGE(TRANS_SDK, "notify session open fail, sessionName=%{public}s.", tmpName);
TRANS_LOGE(TRANS_SDK, "notify session open fail, sessionName=%{public}s.", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
return ret;
}

View File

@ -108,7 +108,7 @@ int32_t TransSetFileReceiveListener(const char *sessionName,
ListAdd(&(g_fileListener->list), &(fileNode->node));
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_FILE, "add sessionName=%{public}s", tmpName);
TRANS_LOGI(TRANS_FILE, "add sessionName=%{public}s", AnonymizeWrapper(tmpName));
AnonymizeFree(tmpName);
(void)SoftBusMutexUnlock(&(g_fileListener->lock));
return SOFTBUS_OK;
@ -233,7 +233,7 @@ int32_t TransSetSocketFileListener(const char *sessionName, SocketFileCallbackFu
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
TRANS_LOGI(TRANS_SDK, "set socket file listener ok, sessionName=%{public}s, isReceiver=%{public}d",
tmpName, isReceiver);
AnonymizeWrapper(tmpName), isReceiver);
AnonymizeFree(tmpName);
return SOFTBUS_OK;
}

View File

@ -60,17 +60,19 @@ ohos_unittest("LnnWifiServiceMonitorTest") {
deps = test_deps
external_deps = test_external_deps
external_deps += [
"ability_base:base",
"ability_base:want",
"ipc:ipc_core",
]
if (!defined(ohos_lite) && softbus_communication_wifi_feature == true) {
external_deps += [ "wifi:wifi_sdk" ]
external_deps += [
"ability_base:base",
"ability_base:want",
"ipc:ipc_core",
"wifi:wifi_sdk",
]
}
}
group("unittest") {
testonly = true
deps = [ ":LnnWifiServiceMonitorTest" ]
if (!defined(ohos_lite) && softbus_communication_wifi_feature == true) {
deps = [ ":LnnWifiServiceMonitorTest" ]
}
}

View File

@ -13,14 +13,15 @@
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <securec.h>
#include "bus_center_client_proxy.h"
#include "common_event_data.h"
#include "gtest/gtest.h"
#include "lnn_wifiservice_monitor.cpp"
#include "lnn_wifiservice_monitor_mock.cpp"
#include "common_event_data.h"
#include "softbus_wifi_api_adapter.h"
#include "softbus_errcode.h"
#include "bus_center_client_proxy.h"
namespace OHOS {
using namespace testing;
@ -57,6 +58,12 @@ void LnnWifiServiceMonitorTest::TearDown()
{
}
/**
* @tc.name: SoftbusBleUtilsTest_BtStatusToSoftBus
* @tc.desc: Verify the SetSoftBusWifiConnState function return value equal SOFTBUS_WIFI_UNKNOWN.
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiConnState_001, TestSize.Level1)
{
SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
@ -75,6 +82,12 @@ HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiConnSt
EXPECT_EQ(state, SOFTBUS_WIFI_UNKNOWN);
}
/**
* @tc.name: SoftbusBleUtilsTest_BtStatusToSoftBus
* @tc.desc: Verify the SetSoftBusWifiUseState function return value equal SOFTBUS_WIFI_UNKNOWN.
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiUseState_001, TestSize.Level1)
{
SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
@ -90,6 +103,12 @@ HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiUseSta
EXPECT_EQ(state, SOFTBUS_WIFI_UNKNOWN);
}
/**
* @tc.name: SoftbusBleUtilsTest_BtStatusToSoftBus
* @tc.desc: Verify the SetSoftBusWifiHotSpotState function return value equal SOFTBUS_WIFI_UNKNOWN.
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiHotSpotState_001, TestSize.Level1)
{
SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;

52
tests/core/adapter/unittest/lnn_ohos_account_test.cpp Executable file → Normal file
View File

@ -12,13 +12,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <gtest/gtest.h>
#include <string>
#include "softbus_common.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "lnn_ohos_account.h"
#include "lnn_ohos_account_mock.h"
#include "softbus_common.h"
#include "softbus_error_code.h"
using namespace std;
using namespace testing;
using namespace testing::ext;
using ::testing::Return;
@ -122,10 +126,12 @@ HWTEST_F(LNNOhosAccountTest, LNN_INIT_OHOS_ACCOUNT, TestSize.Level1)
*/
HWTEST_F(LNNOhosAccountTest, LNN_UPDATE_OHOS_ACCOUNT_001, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, LnnGetLocalByteInfo).WillOnce(Return(SOFTBUS_INVALID_PARAM));
NiceMock <LnnOhosAccountInterfaceMock> mocker;
ON_CALL(mocker, LnnGetLocalByteInfo).WillByDefault(Return(SOFTBUS_INVALID_PARAM));
EXPECT_CALL(mocker, SoftBusGenerateStrHash).Times(0);
LnnUpdateOhosAccount(true);
bool ret = LnnIsDefaultOhosAccount();
EXPECT_FALSE(ret);
}
/**
@ -136,11 +142,13 @@ HWTEST_F(LNNOhosAccountTest, LNN_UPDATE_OHOS_ACCOUNT_001, TestSize.Level1)
*/
HWTEST_F(LNNOhosAccountTest, LNN_UPDATE_OHOS_ACCOUNT_002, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, SoftBusGenerateStrHash).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_CALL(mocker, LnnGetLocalByteInfo).WillOnce(Return(SOFTBUS_OK));
NiceMock <LnnOhosAccountInterfaceMock> mocker;
ON_CALL(mocker, SoftBusGenerateStrHash).WillByDefault(Return(SOFTBUS_INVALID_PARAM));
ON_CALL(mocker, LnnGetLocalByteInfo).WillByDefault(Return(SOFTBUS_OK));
EXPECT_CALL(mocker, UpdateRecoveryDeviceInfoFromDb).Times(0);
LnnUpdateOhosAccount(true);
bool ret = LnnIsDefaultOhosAccount();
EXPECT_FALSE(ret);
}
/**
@ -151,24 +159,12 @@ HWTEST_F(LNNOhosAccountTest, LNN_UPDATE_OHOS_ACCOUNT_002, TestSize.Level1)
*/
HWTEST_F(LNNOhosAccountTest, LNN_ON_OHOS_ACCOUNT_LOGOUT_001, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, SoftBusGenerateStrHash).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
NiceMock <LnnOhosAccountInterfaceMock> mocker;
ON_CALL(mocker, SoftBusGenerateStrHash).WillByDefault(Return(SOFTBUS_INVALID_PARAM));
EXPECT_CALL(mocker, UpdateRecoveryDeviceInfoFromDb).Times(0);
LnnOnOhosAccountLogout();
}
/**
* @tc.name: LNN_ON_OHOS_ACCOUNT_LOGOUT_002
* @tc.desc: update db recovery fail
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNOhosAccountTest, LNN_ON_OHOS_ACCOUNT_LOGOUT_002, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, SoftBusGenerateStrHash).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mocker, UpdateRecoveryDeviceInfoFromDb).WillOnce(Return(SOFTBUS_NETWORK_NOT_INIT));
LnnOnOhosAccountLogout();
bool ret = LnnIsDefaultOhosAccount();
EXPECT_FALSE(ret);
}
/**
@ -179,8 +175,8 @@ HWTEST_F(LNNOhosAccountTest, LNN_ON_OHOS_ACCOUNT_LOGOUT_002, TestSize.Level1)
*/
HWTEST_F(LNNOhosAccountTest, LNN_IS_DEFAULT_OHOS_ACCOUNT_001, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, LnnGetLocalByteInfo).WillOnce(Return(SOFTBUS_INVALID_PARAM));
NiceMock <LnnOhosAccountInterfaceMock> mocker;
ON_CALL(mocker, LnnGetLocalByteInfo).WillByDefault(Return(SOFTBUS_INVALID_PARAM));
bool ret = LnnIsDefaultOhosAccount();
EXPECT_FALSE(ret);
}
@ -193,9 +189,9 @@ HWTEST_F(LNNOhosAccountTest, LNN_IS_DEFAULT_OHOS_ACCOUNT_001, TestSize.Level1)
*/
HWTEST_F(LNNOhosAccountTest, LNN_IS_DEFAULT_OHOS_ACCOUNT_002, TestSize.Level1)
{
LnnOhosAccountInterfaceMock mocker;
EXPECT_CALL(mocker, LnnGetLocalByteInfo).WillOnce(Return(SOFTBUS_OK));
EXPECT_CALL(mocker, SoftBusGenerateStrHash).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
NiceMock <LnnOhosAccountInterfaceMock> mocker;
ON_CALL(mocker, LnnGetLocalByteInfo).WillByDefault(Return(SOFTBUS_OK));
ON_CALL(mocker, SoftBusGenerateStrHash).WillByDefault(Return(SOFTBUS_INVALID_PARAM));
bool ret = LnnIsDefaultOhosAccount();
EXPECT_FALSE(ret);
}

View File

@ -112,7 +112,6 @@ HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest003, TestSiz
HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest004, TestSize.Level1)
{
NiceMock<SettingDataEventMonitorDepsInterfaceMock> SettingDataEventMonitorMock;
EXPECT_CALL(SettingDataEventMonitorMock, GetLooper(_)).WillOnce(Return(NULL));
int32_t ret = LnnInitDeviceNameMonitorImpl();
EXPECT_EQ(ret, SOFTBUS_OK);
}
@ -128,8 +127,6 @@ HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest005, TestSiz
NiceMock<SettingDataEventMonitorDepsInterfaceMock> SettingDataEventMonitorMock;
SoftBusLooper loop;
EXPECT_CALL(SettingDataEventMonitorMock, GetLooper(_)).WillRepeatedly(Return(&loop));
EXPECT_CALL(SettingDataEventMonitorMock, LnnAsyncCallbackHelper(_, _, _))
.WillOnce(Return(SOFTBUS_ERR));
int32_t ret = LnnInitDeviceNameMonitorImpl();
EXPECT_EQ(ret, SOFTBUS_OK);
}

View File

@ -126,5 +126,20 @@ int32_t SoftBusGetBtMacAddr(SoftBusBtAddr *mac)
{
return GetCommonInterface()->SoftBusGetBtMacAddr(mac);
}
int32_t GetNodeFromPcRestrictMap(const char *udidHash, uint32_t *count)
{
return GetCommonInterface()->GetNodeFromPcRestrictMap(udidHash, count);
}
void DeleteNodeFromPcRestrictMap(const char *udidHash)
{
return GetCommonInterface()->DeleteNodeFromPcRestrictMap(udidHash);
}
LnnConnectionFsm *FindConnectionFsmByRequestId(uint32_t requestId)
{
return GetCommonInterface()->FindConnectionFsmByRequestId(requestId);
}
}
} // namespace OHOS

View File

@ -25,6 +25,8 @@
#include "lnn_common_utils.h"
#include "lnn_feature_capability.h"
#include "lnn_lane_interface.h"
#include "lnn_net_builder.h"
#include "lnn_net_builder_process.h"
#include "lnn_ohos_account_adapter.h"
#include "lnn_node_info.h"
#include "softbus_adapter_bt_common.h"
@ -54,6 +56,9 @@ public:
virtual int32_t LnnRequestLeaveSpecific(const char *networkId, ConnectionAddrType addrType);
virtual int32_t LnnGetRemoteNumU64Info(const char *networkId, InfoKey key, uint64_t *info) = 0;
virtual int32_t SoftBusGetBtMacAddr(SoftBusBtAddr *mac) = 0;
virtual int32_t GetNodeFromPcRestrictMap(const char *udidHash, uint32_t *count) = 0;
virtual void DeleteNodeFromPcRestrictMap(const char *udidHash) = 0;
virtual LnnConnectionFsm *FindConnectionFsmByRequestId(uint32_t requestId) = 0;
};
class AuthCommonInterfaceMock : public AuthCommonInterface {
public:
@ -77,6 +82,9 @@ public:
MOCK_METHOD1(LnnNotifyLeaveLnnByAuthHandle, int32_t (AuthHandle *));
MOCK_METHOD2(LnnRequestLeaveSpecific, int32_t (const char *, ConnectionAddrType));
MOCK_METHOD1(SoftBusGetBtMacAddr, int32_t (SoftBusBtAddr *));
MOCK_METHOD2(GetNodeFromPcRestrictMap, int32_t (const char *, uint32_t *));
MOCK_METHOD1(DeleteNodeFromPcRestrictMap, void (const char *));
MOCK_METHOD1(FindConnectionFsmByRequestId, LnnConnectionFsm * (uint32_t));
};
} // namespace OHOS
#endif // AUTH_COMMON_MOCK_H

View File

@ -351,6 +351,7 @@ HWTEST_F(AuthSessionFsmTest, RECOVERY_NORMALIZED_DEVICE_KEY_TEST_001, TestSize.L
authFsm->info.normalizedKey = (SessionKey *)SoftBusMalloc(sizeof(SessionKey));
if (authFsm->info.normalizedKey == nullptr) {
SoftBusFree(authFsm);
return;
}
ret = RecoveryNormalizedDeviceKey(authFsm);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 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

View File

@ -111,7 +111,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_001, TestSize.Level1)
LaneQueryInfo query;
memset_s(&query, sizeof(LaneQueryInfo), 0, sizeof(LaneQueryInfo));
query.transType = LANE_T_BYTE;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
ret = LnnQueryLaneResource(&query, &qosInfo);
EXPECT_NE(ret, SOFTBUS_OK);
@ -142,7 +142,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_002, TestSize.Level1)
LaneQueryInfo query;
query.transType = LANE_T_BYTE;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
ret = QueryLaneResource(&query, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
@ -168,7 +168,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_003, TestSize.Level1)
QosInfo qosInfo = {0};
LaneQueryInfo query;
query.transType = LANE_T_MSG;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
qosInfo.minBW = LOW_BW;
int32_t ret = QueryLaneResource(&query, &qosInfo);
@ -192,7 +192,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_004, TestSize.Level1)
QosInfo qosInfo = {0};
LaneQueryInfo query;
query.transType = LANE_T_FILE;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
qosInfo.minBW = LOW_BW;
int32_t ret = QueryLaneResource(&query, &qosInfo);
@ -220,7 +220,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_005, TestSize.Level1)
QosInfo qosInfo = {0};
LaneQueryInfo query;
query.transType = LANE_T_RAW_STREAM;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
qosInfo.minBW = MID_BW;
int32_t ret = QueryLaneResource(&query, &qosInfo);
@ -248,7 +248,7 @@ HWTEST_F(LNNLaneQueryTest, LNN_QUERY_LANE_006, TestSize.Level1)
QosInfo qosInfo = {0};
LaneQueryInfo query;
query.transType = LANE_T_RAW_STREAM;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
qosInfo.minBW = 0;
int32_t ret = QueryLaneResource(&query, &qosInfo);
EXPECT_NE(ret, SOFTBUS_OK);
@ -491,9 +491,9 @@ HWTEST_F(LNNLaneQueryTest, LNN_QUERY_LANE_014, TestSize.Level1)
{
QosInfo qosInfo = {0};
LaneQueryInfo query;
memset_s(&query, sizeof(LaneQueryInfo), 0, sizeof(LaneQueryInfo));
(void)memset_s(&query, sizeof(LaneQueryInfo), 0, sizeof(LaneQueryInfo));
query.transType = LANE_T_MIX;
(void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
EXPECT_EQ(strncpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
int32_t ret = QueryByRequireLink(&query, &qosInfo);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = QueryByDefaultLink(&query);

View File

@ -3216,6 +3216,7 @@ HWTEST_F(LNNLaneMockTest, LNN_LANE_12, TestSize.Level1)
DEFAULT_QOSINFO_MIN_LATENCY, &allocInfo);
int32_t ret = laneManager->lnnAllocLane(laneReqId, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
CondWait();
}
/*

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