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-05-27 15:17:28 +00:00 committed by Gitee
commit e874b78ffc
184 changed files with 4298 additions and 1367 deletions

View File

@ -81,7 +81,18 @@ static void ProcessLwipEvent(struct HdfSBuf *data)
static void ProcessWlanEvent(struct HdfSBuf *data)
{
LnnNotifyWlanStateChangeEvent(SOFTBUS_WIFI_UNKNOWN);
SoftBusWifiState *notifyState = (SoftBusWifiState *)SoftBusMalloc(sizeof(SoftBusWifiState));
if (notifyState == NULL) {
LNN_LOGE(LNN_EVENT, "notifyState malloc err");
return;
}
*notifyState = SOFTBUS_WIFI_UNKNOWN;
int32_t ret = LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), LnnNotifyWlanStateChangeEvent,
(void *)notifyState);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "async notify wifi state err, ret=%{public}d", ret);
SoftBusFree(notifyState);
}
}
static int32_t OnReceiveDriverEvent(

View File

@ -48,6 +48,8 @@ void LnnDeinitProductMonitorImpl(void);
void LnnDeinitDriverMonitorImpl(void);
void LnnDeInitNetlinkMonitorImpl(void);
#ifdef __cplusplus
}
#endif

View File

@ -37,6 +37,8 @@
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
#include "softbus_adapter_thread.h"
#include "softbus_base_listener.h"
#include "softbus_socket.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -47,6 +49,8 @@
#define DEFAULT_NETLINK_RECVBUF (32 * 1024)
static int32_t g_netlinkFd = -1;
static int32_t CreateNetlinkSocket(void)
{
int32_t sockFd;
@ -143,67 +147,81 @@ static void ProcessLinkEvent(struct nlmsghdr *nlh)
}
}
static void *NetlinkMonitorThread(void *para)
static int32_t NetlinkOnDataEvent(ListenerModule module, int32_t events, int32_t fd)
{
(void)para;
LNN_LOGI(LNN_BUILDER, "netlink monitor thread start");
int32_t sockFd = CreateNetlinkSocket();
if (sockFd < 0) {
LNN_LOGE(LNN_BUILDER, "create netlink socket failed");
return NULL;
if (module != NETLINK || events != SOFTBUS_SOCKET_IN || fd < 0) {
LNN_LOGE(LNN_BUILDER, "listening fail, moudle=%{public}d, events=%{public}d", module, events);
return SOFTBUS_INVALID_PARAM;
}
uint8_t *buffer = (uint8_t *)SoftBusCalloc(DEFAULT_NETLINK_RECVBUF * sizeof(uint8_t));
if (buffer == NULL) {
SoftBusSocketClose(sockFd);
return NULL;
LNN_LOGE(LNN_BUILDER, "malloc fail.");
return SOFTBUS_MALLOC_ERR;
}
while (true) {
(void)memset_s(buffer, DEFAULT_NETLINK_RECVBUF, 0, DEFAULT_NETLINK_RECVBUF);
int32_t len = SoftBusSocketRecv(sockFd, buffer, DEFAULT_NETLINK_RECVBUF, 0);
if (len < 0 && len == SOFTBUS_ADAPTER_SOCKET_EINTR) {
continue;
}
if (len < 0) {
LNN_LOGE(LNN_BUILDER, "recv netlink socket error");
break;
}
if (len < (int32_t)sizeof(struct nlmsghdr)) {
LNN_LOGE(LNN_BUILDER, "recv buffer not enough");
continue;
}
struct nlmsghdr *nlh = (struct nlmsghdr *)buffer;
while (NLMSG_OK(nlh, len) && nlh->nlmsg_type != NLMSG_DONE) {
LNN_LOGD(LNN_BUILDER, "nlmsg_type=%{public}d", nlh->nlmsg_type);
switch (nlh->nlmsg_type) {
case RTM_NEWADDR:
case RTM_DELADDR:
ProcessAddrEvent(nlh);
break;
case RTM_NEWLINK:
case RTM_DELLINK:
ProcessLinkEvent(nlh);
break;
default:
break;
}
nlh = NLMSG_NEXT(nlh, len);
}
struct nlmsghdr *nlh = NULL;
int32_t len = SoftBusSocketRecv(fd, buffer, DEFAULT_NETLINK_RECVBUF, 0);
if (len < 0 || len == SOFTBUS_ADAPTER_SOCKET_EINTR || len < (int32_t)sizeof(struct nlmsghdr)) {
LNN_LOGE(LNN_BUILDER, "recv netlink socket error");
SoftBusFree(buffer);
return SOFTBUS_SOCKET_EXCEPTION;
}
nlh = (struct nlmsghdr *)buffer;
while (NLMSG_OK(nlh, len) && nlh->nlmsg_type != NLMSG_DONE) {
LNN_LOGD(LNN_BUILDER, "nlmsg_type=%{public}d", nlh->nlmsg_type);
switch (nlh->nlmsg_type) {
case RTM_NEWADDR:
case RTM_DELADDR:
ProcessAddrEvent(nlh);
break;
case RTM_NEWLINK:
case RTM_DELLINK:
ProcessLinkEvent(nlh);
break;
default:
break;
}
nlh = NLMSG_NEXT(nlh, len);
}
SoftBusSocketClose(sockFd);
SoftBusFree(buffer);
LNN_LOGI(LNN_BUILDER, "netlink monitor thread exit");
return NULL;
return SOFTBUS_OK;
}
static int32_t NetlinkOnConnectEvent(ListenerModule module, int32_t cfd, const ConnectOption *clientAddr)
{
(void)module;
(void)cfd;
(void)clientAddr;
LNN_LOGD(LNN_BUILDER, "ignore this event");
return SOFTBUS_OK;
}
int32_t LnnInitNetlinkMonitorImpl(void)
{
SoftBusThread tid;
SoftBusThreadAttr threadAttr;
SoftBusThreadAttrInit(&threadAttr);
threadAttr.taskName = "NetMonitor_Tsk";
if (SoftBusThreadCreate(&tid, &threadAttr, NetlinkMonitorThread, NULL) != 0) {
LNN_LOGE(LNN_INIT, "create ip change monitor thread failed");
SoftbusBaseListener listener = {
.onConnectEvent = NetlinkOnConnectEvent,
.onDataEvent = NetlinkOnDataEvent,
};
if (StartBaseClient(NETLINK, &listener) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "listening fail, moudle=%{public}d ", NETLINK);
return SOFTBUS_ERR;
}
int32_t sockFd = CreateNetlinkSocket();
if (sockFd < 0) {
LNN_LOGE(LNN_BUILDER, "create netlink socket failed");
return SOFTBUS_ERR;
}
g_netlinkFd = sockFd;
if (AddTrigger(NETLINK, sockFd, READ_TRIGGER) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "AddTrigger fail.");
SoftBusSocketClose(sockFd);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
void LnnDeInitNetlinkMonitorImpl(void)
{
if (g_netlinkFd > 0) {
SoftBusSocketClose(g_netlinkFd);
}
}

View File

@ -111,7 +111,18 @@ void WifiServiceMonitor::OnReceiveEvent(const CommonEventData &data)
SetSoftBusWifiHotSpotState(code, &state);
}
if (state != SOFTBUS_WIFI_UNKNOWN) {
LnnNotifyWlanStateChangeEvent(state);
SoftBusWifiState *notifyState = (SoftBusWifiState *)SoftBusMalloc(sizeof(SoftBusWifiState));
if (notifyState == NULL) {
LNN_LOGE(LNN_BUILDER, "notifyState malloc err");
return;
}
*notifyState = state;
int32_t ret = LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), LnnNotifyWlanStateChangeEvent,
(void *)notifyState);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "async notify wifi state err, ret=%{public}d", ret);
SoftBusFree(notifyState);
}
}
}

View File

@ -24,6 +24,7 @@
#include "kits/c/wifi_device.h"
#include "kits/c/wifi_hid2d.h"
#include "kits/c/wifi_p2p.h"
#include "kits/c/wifi_state.h"
static int32_t ConvertSoftBusWifiConfFromWifiDev(const WifiDeviceConfig *sourceWifiConf, SoftBusWifiDevConf *wifiConf)
{
@ -416,4 +417,43 @@ bool SoftBusIsWifiActive(void)
return true;
}
return false;
}
SoftBusWifiDetailState SoftBusGetWifiState(void)
{
WifiDetailState wifiState;
if (GetWifiDetailState(&wifiState) != WIFI_SUCCESS) {
LNN_LOGE(LNN_STATE, "GetWifiDetailState failed");
return SOFTBUS_WIFI_STATE_UNKNOWN;
}
LNN_LOGI(LNN_STATE, "wifiState=%{public}d", wifiState);
switch (wifiState) {
case STATE_INACTIVE:
return SOFTBUS_WIFI_STATE_INACTIVE;
case STATE_ACTIVATED:
return SOFTBUS_WIFI_STATE_ACTIVED;
case STATE_ACTIVATING:
return SOFTBUS_WIFI_STATE_ACTIVATING;
case STATE_DEACTIVATING:
return SOFTBUS_WIFI_STATE_DEACTIVATING;
case STATE_SEMI_ACTIVATING:
return SOFTBUS_WIFI_STATE_SEMIACTIVATING;
case STATE_SEMI_ACTIVE:
return SOFTBUS_WIFI_STATE_SEMIACTIVE;
default:
break;
}
return SOFTBUS_WIFI_STATE_UNKNOWN;
}
bool SoftBusIsWifiP2pEnabled(void)
{
enum P2pState state;
if (GetP2pEnableStatus(&state) != WIFI_SUCCESS) {
LNN_LOGE(LNN_STATE, "GetP2pEnableStatus failed");
return false;
}
LNN_LOGI(LNN_STATE, "P2pState=%{public}d", state);
return state == P2P_STATE_STARTED;
}

View File

@ -102,3 +102,13 @@ bool SoftBusIsWifiActive(void)
{
return true;
}
SoftBusWifiDetailState SoftBusGetWifiState(void)
{
return SOFTBUS_WIFI_STATE_ACTIVED;
}
bool SoftBusIsWifiP2pEnabled(void)
{
return true;
}

View File

@ -101,6 +101,16 @@ typedef enum SoftBusP2pDeviceStatus {
SOFTBUS_API_WIFI_PDS_UNAVAILABLE
} SoftBusP2pDeviceStatus;
typedef enum SoftBusWifiDetailState {
SOFTBUS_WIFI_STATE_UNKNOWN = -1,
SOFTBUS_WIFI_STATE_INACTIVE,
SOFTBUS_WIFI_STATE_ACTIVED,
SOFTBUS_WIFI_STATE_ACTIVATING,
SOFTBUS_WIFI_STATE_DEACTIVATING,
SOFTBUS_WIFI_STATE_SEMIACTIVATING,
SOFTBUS_WIFI_STATE_SEMIACTIVE,
} SoftBusWifiDetailState;
typedef struct SoftBusWifiP2pWfdInfo {
int32_t wfdEnabled; /* 0: false, 1: true */
int32_t deviceInfo;
@ -151,6 +161,8 @@ bool SoftBusHasWifiDirectCapability(void);
bool SoftBusIsWifiTripleMode(void);
char* SoftBusGetWifiInterfaceCoexistCap(void);
bool SoftBusIsWifiActive(void);
SoftBusWifiDetailState SoftBusGetWifiState(void);
bool SoftBusIsWifiP2pEnabled(void);
#ifdef __cplusplus
}

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef DSOFTBUS_KV_STORE_LNN_KV_ADAPTER_WRAPPER_H
#define DSOFTBUS_KV_STORE_LNN_KV_ADAPTER_WRAPPER_H
#ifndef LNN_KV_ADAPTER_WRAPPER_H
#define LNN_KV_ADAPTER_WRAPPER_H
#include "lnn_data_cloud_sync.h"
#ifdef __cplusplus
@ -23,6 +23,9 @@ extern "C" {
#endif
int32_t LnnCreateKvAdapter(int32_t *dbId, const char *appId, int32_t appIdLen, const char *storeId, int32_t storeIdLen);
int32_t LnnDestroyKvAdapter(int32_t dbId);
void LnnRegisterDataChangeListener(int32_t dbId, const char *appId, int32_t appIdLen, const char *storeId,
int32_t storeIdLen);
void LnnUnRegisterDataChangeListener(int32_t dbId);
int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *value, int32_t valueLen);
int32_t LnnPutDBDataBatch(int32_t dbId, const CloudSyncInfo *localInfo);
int32_t LnnDeleteDBData(int32_t dbId, const char *key, int32_t keyLen);
@ -34,4 +37,4 @@ int32_t LnnCloudSync(int32_t dbId);
};
#endif
#endif // DSOFTBUS_KV_STORE_LNN_KV_ADAPTER_WRAPPER_H
#endif //LNN_KV_ADAPTER_WRAPPER_H

View File

@ -14,6 +14,7 @@
*/
#include <cstring>
#include <securec.h>
#include <string>
#include "lnn_kv_adapter_wrapper.h"
@ -21,7 +22,10 @@
#include "lnn_kv_adapter.h"
#include "lnn_kv_data_change_listener.h"
#include "lnn_log.h"
#include "lnn_node_info.h"
#include "softbus_errcode.h"
#include "softbus_def.h"
#include "softbus_utils.h"
using namespace OHOS;
using namespace OHOS::DistributedKv;
@ -43,6 +47,7 @@ int32_t LnnCreateKvAdapter(int32_t *dbId, const char *appId, int32_t appIdLen, c
{
if (dbId == nullptr || appId == nullptr || appIdLen < MIN_STRING_LEN || appIdLen > MAX_STRING_LEN ||
storeId == nullptr || storeIdLen < MIN_STRING_LEN || storeIdLen > MAX_STRING_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
std::string appIdStr(appId, appIdLen);
@ -50,7 +55,7 @@ int32_t LnnCreateKvAdapter(int32_t *dbId, const char *appId, int32_t appIdLen, c
std::shared_ptr<KVAdapter> kvAdapter = nullptr;
{
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
kvAdapter = std::make_shared<KVAdapter>(appIdStr, storeIdStr, std::make_shared<KvDataChangeListener>());
kvAdapter = std::make_shared<KVAdapter>(appIdStr, storeIdStr);
int32_t initRet = kvAdapter->Init();
if (initRet != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "kvAdapter init failed, ret=%{public}d", initRet);
@ -70,6 +75,7 @@ int32_t LnnDestroyKvAdapter(int32_t dbId)
{
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
auto kvAdapter = FindKvStorePtr(dbId);
@ -108,6 +114,7 @@ int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (key == nullptr || keyLen < MIN_STRING_LEN || keyLen > MAX_STRING_LEN || value == nullptr ||
valueLen < MIN_STRING_LEN || valueLen > MAX_STRING_LEN || dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
std::string keyStr(key, keyLen);
@ -134,6 +141,7 @@ int32_t LnnDeleteDBData(int32_t dbId, const char *key, int32_t keyLen)
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (key == nullptr || keyLen < MIN_STRING_LEN || keyLen > MAX_STRING_LEN || dbId < MIN_DBID_COUNT ||
dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
std::string keyStr(key, keyLen);
@ -160,6 +168,7 @@ int32_t LnnGetDBData(int32_t dbId, const char *key, int32_t keyLen, char **value
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (value == nullptr || key == nullptr || keyLen < MIN_STRING_LEN || keyLen > MAX_STRING_LEN ||
dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
std::string keyStr(key, keyLen);
@ -179,7 +188,7 @@ int32_t LnnGetDBData(int32_t dbId, const char *key, int32_t keyLen, char **value
LNN_LOGE(LNN_LEDGER, "strdup failed");
return SOFTBUS_MALLOC_ERR;
}
LNN_LOGI(LNN_LEDGER, "kvAdapter get success, dbId=%{public}d", dbId);
LNN_LOGD(LNN_LEDGER, "kvAdapter get success, dbId=%{public}d", dbId);
return SOFTBUS_OK;
}
@ -190,6 +199,7 @@ int32_t LnnDeleteDBDataByPrefix(int32_t dbId, const char *keyPrefix, int32_t key
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (keyPrefix == nullptr || keyPrefixLen < MIN_STRING_LEN || keyPrefixLen > MAX_STRING_LEN ||
dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
std::string keyPrefixStr(keyPrefix, keyPrefixLen);
@ -212,19 +222,22 @@ int32_t LnnPutDBDataBatch(int32_t dbId, const CloudSyncInfo *localInfo)
{
int32_t putBatchRet;
{
LNN_LOGI(LNN_LEDGER, "call");
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (localInfo == nullptr || dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGE(LNN_LEDGER, "invalid param, dbId=%{public}d", dbId);
return SOFTBUS_INVALID_PARAM;
}
std::map<std::string, std::string> values;
BasicCloudSyncInfoToMap(localInfo, values);
ComplexCloudSyncInfoToMap(localInfo, values);
auto kvAdapter = FindKvStorePtr(dbId);
if (kvAdapter == nullptr) {
LNN_LOGE(LNN_LEDGER, "kvAdapter is not exist, dbId=%{public}d", dbId);
return SOFTBUS_NOT_FIND;
}
BasicCloudSyncInfoToMap(localInfo, values);
ComplexCloudSyncInfoToMap(localInfo, values);
putBatchRet = kvAdapter->PutBatch(values);
values.clear();
}
if (putBatchRet != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "kvAdapter putBatch failed, ret=%{public}d", putBatchRet);
@ -284,6 +297,47 @@ void BasicCloudSyncInfoToMap(const CloudSyncInfo *localInfo, std::map<std::strin
values[keyPrefix + DEVICE_INFO_P2P_MAC_ADDR] = localInfo->p2pMac + stateVersionStr;
}
static int32_t CipherAndRpaInfoToMap(const CloudSyncInfo *localInfo, std::map<std::string, std::string> &values,
const std::string &keyPrefix, const std::string &stateVersionStr)
{
char cipherKey[SESSION_KEY_STR_LEN] = { 0 };
char cipherIv[BROADCAST_IV_STR_LEN] = { 0 };
char peerIrk[LFINDER_IRK_STR_LEN] = { 0 };
char pubMac[LFINDER_MAC_ADDR_STR_LEN] = { 0 };
if (ConvertBytesToHexString(cipherKey, SESSION_KEY_STR_LEN, localInfo->cipherKey, SESSION_KEY_LENGTH) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert cipherkey to string fail.");
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
if (ConvertBytesToHexString(cipherIv, BROADCAST_IV_STR_LEN, localInfo->cipherIv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert cipheriv to string fail.");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
if (ConvertBytesToHexString(peerIrk, LFINDER_IRK_STR_LEN, localInfo->peerIrk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert peerIrk to string fail.");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
if (ConvertBytesToHexString(pubMac, LFINDER_MAC_ADDR_STR_LEN, localInfo->publicAddress, LFINDER_MAC_ADDR_LEN) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert publicAddress to string fail.");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
(void)memset_s(peerIrk, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
values[keyPrefix + DEVICE_INFO_DEVICE_IRK] = peerIrk + stateVersionStr;
values[keyPrefix + DEVICE_INFO_DEVICE_PUB_MAC] = pubMac + stateVersionStr;
values[keyPrefix + DEVICE_INFO_BROADCAST_CIPHER_KEY] = cipherKey + stateVersionStr;
values[keyPrefix + DEVICE_INFO_BROADCAST_CIPHER_IV] = cipherIv + stateVersionStr;
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
(void)memset_s(peerIrk, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
return SOFTBUS_OK;
}
void ComplexCloudSyncInfoToMap(const CloudSyncInfo *localInfo, std::map<std::string, std::string> &values)
{
if (localInfo == nullptr) {
@ -293,32 +347,62 @@ void ComplexCloudSyncInfoToMap(const CloudSyncInfo *localInfo, std::map<std::str
std::string keyPrefix = std::to_string(localInfo->accountId) + SEPARATOR + localInfo->deviceUdid + SEPARATOR;
std::string stateVersionStr = SEPARATOR + std::to_string(localInfo->stateVersion);
char peerIrkStr[LFINDER_IRK_LEN];
for (int32_t i = 0; i < LFINDER_IRK_LEN; i++) {
peerIrkStr[i] = static_cast<char>(localInfo->peerIrk[i]);
char remotePtkStr[PTK_DEFAULT_LEN + 1] = {0};
for (int32_t i = 0; i < PTK_DEFAULT_LEN; i++) {
remotePtkStr[i] = static_cast<char>(localInfo->remotePtk[i]);
}
values[keyPrefix + DEVICE_INFO_DEVICE_IRK] = peerIrkStr + stateVersionStr;
char publicAddressStr[LFINDER_MAC_ADDR_LEN];
for (int32_t i = 0; i < LFINDER_MAC_ADDR_LEN; i++) {
publicAddressStr[i] = static_cast<char>(localInfo->publicAddress[i]);
}
values[keyPrefix + DEVICE_INFO_DEVICE_PUB_MAC] = publicAddressStr + stateVersionStr;
values[keyPrefix + DEVICE_INFO_PTK] = localInfo->remotePtk + stateVersionStr;
values[keyPrefix + DEVICE_INFO_PTK] = remotePtkStr + stateVersionStr;
values[keyPrefix + DEVICE_INFO_JSON_KEY_TABLE_MIAN] = localInfo->tableMain + stateVersionStr;
values[keyPrefix + DEVICE_INFO_JSON_KEY_TOTAL_LIFE] = std::to_string(localInfo->lifeTotal) + stateVersionStr;
values[keyPrefix + DEVICE_INFO_JSON_KEY_TIMESTAMP_BEGIN] =
std::to_string(localInfo->curBeginTime) + stateVersionStr;
values[keyPrefix + DEVICE_INFO_JSON_KEY_CURRENT_INDEX] = std::to_string(localInfo->currentIndex) + stateVersionStr;
char cipherKeyStr[SESSION_KEY_LENGTH];
for (int32_t i = 0; i < SESSION_KEY_LENGTH; i++) {
cipherKeyStr[i] = static_cast<char>(localInfo->cipherKey[i]);
}
values[keyPrefix + DEVICE_INFO_BROADCAST_CIPHER_KEY] = cipherKeyStr + stateVersionStr;
char cipherIvStr[BROADCAST_IV_LEN];
for (int32_t i = 0; i < BROADCAST_IV_LEN; i++) {
cipherIvStr[i] = static_cast<char>(localInfo->cipherIv[i]);
}
values[keyPrefix + DEVICE_INFO_BROADCAST_CIPHER_IV] = cipherIvStr + stateVersionStr;
values[keyPrefix + DEVICE_INFO_DISTRIBUTED_SWITCH] =
(localInfo->distributedSwitch ? "true" : "false") + stateVersionStr;
if (CipherAndRpaInfoToMap(localInfo, values, keyPrefix, stateVersionStr) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert cipher and rpa info to map fail");
}
}
void LnnRegisterDataChangeListener(int32_t dbId, const char *appId, int32_t appIdLen, const char *storeId,
int32_t storeIdLen)
{
int32_t status;
{
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (dbId < MIN_DBID_COUNT || dbId >= g_dbId || appId == nullptr || appIdLen < MIN_STRING_LEN ||
appIdLen > MAX_STRING_LEN || storeId == nullptr || storeIdLen < MIN_STRING_LEN ||
storeIdLen > MAX_STRING_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return;
}
std::string appIdStr(appId, appIdLen);
std::string storeIdStr(storeId, storeIdLen);
auto kvAdapter = FindKvStorePtr(dbId);
if (kvAdapter == nullptr) {
LNN_LOGE(LNN_LEDGER, "kvAdapter is not exist, dbId=%{public}d", dbId);
return;
}
status = kvAdapter->RegisterDataChangeListener(std::make_shared<KvDataChangeListener>(appIdStr, storeIdStr));
}
if (status != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "RegisterDataChangeListener failed");
return;
}
LNN_LOGI(LNN_LEDGER, "RegisterDataChangeListener success");
}
void LnnUnRegisterDataChangeListener(int32_t dbId)
{
std::lock_guard<std::mutex> lock(g_kvAdapterWrapperMutex);
if (dbId < MIN_DBID_COUNT || dbId >= g_dbId) {
LNN_LOGI(LNN_LEDGER, "Invalid dbId ");
return;
}
auto kvAdapter = FindKvStorePtr(dbId);
if (kvAdapter == nullptr) {
LNN_LOGE(LNN_LEDGER, "kvAdapter is not exist, dbId=%{public}d", dbId);
return;
}
kvAdapter->DeRegisterDataChangeListener();
}

View File

@ -23,13 +23,13 @@ int32_t LnnCreateKvAdapter(int32_t *dbId, const char *appId, int32_t appIdLen, c
(void)appIdLen;
(void)storeId;
(void)storeIdLen;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnDestroyKvAdapter(int32_t dbId)
{
(void)dbId;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *value, int32_t valueLen)
@ -39,7 +39,7 @@ int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *
(void)keyLen;
(void)value;
(void)valueLen;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnDeleteDBData(int32_t dbId, const char *key, int32_t keyLen)
@ -47,7 +47,7 @@ int32_t LnnDeleteDBData(int32_t dbId, const char *key, int32_t keyLen)
(void)dbId;
(void)key;
(void)keyLen;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnGetDBData(int32_t dbId, const char *key, int32_t keyLen, char **value)
@ -56,7 +56,7 @@ int32_t LnnGetDBData(int32_t dbId, const char *key, int32_t keyLen, char **value
(void)key;
(void)keyLen;
(void)value;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnDeleteDBDataByPrefix(int32_t dbId, const char *keyPrefix, int32_t keyPrefixLen)
@ -64,18 +64,32 @@ int32_t LnnDeleteDBDataByPrefix(int32_t dbId, const char *keyPrefix, int32_t key
(void)dbId;
(void)keyPrefix;
(void)keyPrefixLen;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnPutDBDataBatch(int32_t dbId, const CloudSyncInfo *localInfo)
{
(void)dbId;
(void)localInfo;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnCloudSync(int32_t dbId)
{
(void)dbId;
return SOFTBUS_OK;
return SOFTBUS_NOT_IMPLEMENT;
}
void LnnRegisterDataChangeListener(int32_t dbId, const char *appId, int32_t appIdLen, const char *storeId,
int32_t storeIdLen)
{
(void)dbId;
(void)appId;
(void)appIdLen;
(void)storeId;
(void)storeIdLen;
}
void LnnUnRegisterDataChangeListener(int32_t dbId)
{
(void)dbId;
}

View File

@ -26,8 +26,7 @@
namespace OHOS {
class KVAdapter {
public:
KVAdapter(const std::string &appId, const std::string &storeId,
const std::shared_ptr<DistributedKv::KvStoreObserver> &dataChangeListener);
KVAdapter(const std::string &appId, const std::string &storeId);
virtual ~KVAdapter();
int32_t Init();
@ -39,12 +38,13 @@ public:
int32_t Get(const std::string &key, std::string &value);
int32_t DeleteKvStore();
int32_t CloudSync();
int32_t RegisterDataChangeListener(const std::shared_ptr<DistributedKv::KvStoreObserver> &dataChangeListener);
void DeRegisterDataChangeListener();
static void CloudSyncCallback(DistributedKv::ProgressDetail &&detail);
private:
DistributedKv::Status GetKvStorePtr();
int32_t DeleteKvStorePtr();
int32_t RegisterDataChangeListener();
int32_t UnRegisterDataChangeListener();
int32_t DeleteDataChangeListener();

View File

@ -23,7 +23,7 @@
namespace OHOS {
class KvDataChangeListener : public DistributedKv::KvStoreObserver {
public:
KvDataChangeListener();
KvDataChangeListener(const std::string &appId, const std::string &storeId);
~KvDataChangeListener();
void OnChange(const DistributedKv::DataOrigin &origin, Keys &&keys) override;
@ -35,6 +35,10 @@ private:
void HandleUpdateChange(const std::vector<DistributedKv::Entry> &updateRecords);
void HandleDeleteChange(const std::vector<DistributedKv::Entry> &deleteRecords);
std::string GetKeyPrefix(const std::string &key);
private:
std::string appId_;
std::string storeId_;
};
} // namespace OHOS
#endif // LNN_KV_DATA_CHANGE_LISTENER_H

View File

@ -20,7 +20,6 @@
#include <vector>
#include "anonymizer.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_kv_adapter.h"
#include "lnn_log.h"
#include "lnn_parameter_utils.h"
@ -31,18 +30,16 @@ namespace OHOS {
using namespace OHOS::DistributedKv;
namespace {
constexpr int32_t MAX_STRING_LEN = 4096;
constexpr int32_t MAX_INIT_RETRY_TIMES = 30;
constexpr int32_t INIT_RETRY_SLEEP_INTERVAL = 500 * 1000; // 500ms
constexpr int32_t MAX_INIT_RETRY_TIMES = 3;
constexpr int32_t INIT_RETRY_SLEEP_INTERVAL = 100 * 1000; // 100ms
constexpr int32_t MAX_MAP_SIZE = 10000;
const std::string DATABASE_DIR = "/data/service/el1/public/database/dsoftbus";
} // namespace
KVAdapter::KVAdapter(const std::string &appId, const std::string &storeId,
const std::shared_ptr<DistributedKv::KvStoreObserver> &dataChangeListener)
KVAdapter::KVAdapter(const std::string &appId, const std::string &storeId)
{
this->appId_.appId = appId;
this->storeId_.storeId = storeId;
this->dataChangeListener_ = dataChangeListener;
LNN_LOGI(LNN_LEDGER, "KVAdapter Constructor Success, appId: %{public}s, storeId: %{public}s", appId.c_str(),
storeId.c_str());
}
@ -54,7 +51,7 @@ KVAdapter::~KVAdapter()
int32_t KVAdapter::Init()
{
LNN_LOGI(LNN_LEDGER, "Init kvAdapter, storeId: %s", storeId_.storeId.c_str());
LNN_LOGI(LNN_LEDGER, "Init kvAdapter, storeId: %{public}s", storeId_.storeId.c_str());
int32_t tryTimes = MAX_INIT_RETRY_TIMES;
int64_t beginTime = GetTickCount();
while (tryTimes > 0) {
@ -62,11 +59,11 @@ int32_t KVAdapter::Init()
if (kvStorePtr_ && status == DistributedKv::Status::SUCCESS) {
int64_t endTime = GetTickCount();
LNN_LOGI(LNN_LEDGER, "Init KvStorePtr Success, spend %{public}" PRId64 " ms", endTime - beginTime);
RegisterDataChangeListener();
return SOFTBUS_OK;
}
LNN_LOGI(LNN_LEDGER, "CheckKvStore, left times: %{public}d, status: %{public}d", tryTimes, status);
if (status == DistributedKv::Status::SECURITY_LEVEL_ERROR) {
LNN_LOGE(LNN_LEDGER, "This db security level error, remove and rebuild it");
DeleteKvStore();
}
if (status == DistributedKv::Status::STORE_META_CHANGED) {
@ -82,19 +79,23 @@ int32_t KVAdapter::Init()
int32_t KVAdapter::DeInit()
{
LNN_LOGI(LNN_LEDGER, "DBAdapter DeInit");
UnRegisterDataChangeListener();
DeleteDataChangeListener();
DeleteKvStorePtr();
return SOFTBUS_OK;
}
int32_t KVAdapter::RegisterDataChangeListener()
int32_t KVAdapter::RegisterDataChangeListener(
const std::shared_ptr<DistributedKv::KvStoreObserver> &dataChangeListener)
{
LNN_LOGI(LNN_LEDGER, "Register db data change listener");
if (!IsCloudSyncEnabled()) {
LNN_LOGW(LNN_LEDGER, "not support cloud sync");
return SOFTBUS_ERR;
}
if (dataChangeListener == nullptr) {
LNN_LOGE(LNN_LEDGER, "dataChangeListener is null");
return SOFTBUS_INVALID_PARAM;
}
this->dataChangeListener_ = dataChangeListener;
{
std::lock_guard<std::mutex> lock(kvAdapterMutex_);
if (kvStorePtr_ == nullptr) {
@ -160,14 +161,7 @@ int32_t KVAdapter::Put(const std::string &key, const std::string &value)
DistributedKv::Key kvKey(key);
DistributedKv::Value oldV;
if (kvStorePtr_->Get(kvKey, oldV) == DistributedKv::Status::SUCCESS && oldV.ToString() == value) {
char *anonyKey = nullptr;
char *anonyValue = nullptr;
Anonymize(key.c_str(), &anonyKey);
Anonymize(value.c_str(), &anonyValue);
LNN_LOGI(LNN_LEDGER, "The key-value pair already exists. key=%{public}s, value=%{public}s", anonyKey,
anonyValue);
AnonymizeFree(anonyKey);
AnonymizeFree(anonyValue);
LNN_LOGI(LNN_LEDGER, "The key-value pair already exists.");
return SOFTBUS_OK;
}
DistributedKv::Value kvValue(value);
@ -200,14 +194,6 @@ int32_t KVAdapter::PutBatch(const std::map<std::string, std::string> &values)
for (auto item : values) {
kvKey = item.first;
if (kvStorePtr_->Get(kvKey, oldV) == DistributedKv::Status::SUCCESS && oldV.ToString() == item.second) {
char *anonyKey = nullptr;
char *anonyValue = nullptr;
Anonymize(item.first.c_str(), &anonyKey);
Anonymize(item.second.c_str(), &anonyValue);
LNN_LOGI(LNN_LEDGER, "The key-value pair already exists. key=%{public}s, value=%{public}s", anonyKey,
anonyValue);
AnonymizeFree(anonyKey);
AnonymizeFree(anonyValue);
continue;
}
Entry entry;
@ -222,7 +208,7 @@ int32_t KVAdapter::PutBatch(const std::map<std::string, std::string> &values)
status = kvStorePtr_->PutBatch(entries);
}
if (status != DistributedKv::Status::SUCCESS) {
LNN_LOGE(LNN_LEDGER, "PutBatch kv to db failed, ret=%d", status);
LNN_LOGE(LNN_LEDGER, "PutBatch kv to db failed, ret=%{public}d", status);
return SOFTBUS_KV_PUT_DB_FAIL;
}
LNN_LOGI(LNN_LEDGER, "KVAdapter PutBatch succeed");
@ -302,7 +288,7 @@ int32_t KVAdapter::Get(const std::string &key, std::string &value)
if (status != DistributedKv::Status::SUCCESS) {
anonyKey = nullptr;
Anonymize(key.c_str(), &anonyKey);
LNN_LOGE(LNN_LEDGER, "Get data from kv failed, key: %{public}s", anonyKey);
LNN_LOGE(LNN_LEDGER, "Get data from kv failed, key=%{public}s", anonyKey);
AnonymizeFree(anonyKey);
return SOFTBUS_KV_GET_DB_FAIL;
}
@ -397,7 +383,7 @@ void KVAdapter::CloudSyncCallback(DistributedKv::ProgressDetail &&detail)
}
if (progress == DistributedKv::Progress::SYNC_FINISH && code != DistributedKv::Status::SUCCESS) {
LNN_LOGI(LNN_LEDGER,
"cloud sync failed, code: %{public}d, upload.total=%{public}u, upload.success=%{public}u, "
"cloud sync failed, code=%{public}d, upload.total=%{public}u, upload.success=%{public}u, "
"upload.failed=%{public}u, upload.untreated=%{public}u, download.total=%{public}u, "
"download.success=%{public}u, download.failed=%{public}u, download.untreated=%{public}u",
code, detail.details.upload.total, detail.details.upload.success, detail.details.upload.failed,
@ -406,4 +392,11 @@ void KVAdapter::CloudSyncCallback(DistributedKv::ProgressDetail &&detail)
}
}
void KVAdapter::DeRegisterDataChangeListener()
{
LNN_LOGI(LNN_LEDGER, "call!");
UnRegisterDataChangeListener();
DeleteDataChangeListener();
}
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include <cinttypes>
#include <cstring>
#include <thread>
#include "anonymizer.h"
#include "lnn_data_cloud_sync.h"
@ -27,16 +28,14 @@
namespace OHOS {
namespace {
const std::string APP_ID = "dsoftbus";
const std::string STORE_ID = "dsoftbus_kv_db";
constexpr int32_t APP_ID_LEN = 8;
constexpr int32_t STORE_ID_LEN = 14;
constexpr int32_t MAX_DB_RECORD_SIZE = 10000;
} // namespace
KvDataChangeListener::KvDataChangeListener()
KvDataChangeListener::KvDataChangeListener(const std::string &appId, const std::string &storeId)
{
LNN_LOGI(LNN_LEDGER, "construct!");
this->appId_ = appId;
this->storeId_ = storeId;
}
KvDataChangeListener::~KvDataChangeListener()
@ -46,28 +45,31 @@ KvDataChangeListener::~KvDataChangeListener()
void KvDataChangeListener::OnChange(const DistributedKv::DataOrigin &origin, Keys &&keys)
{
LNN_LOGI(LNN_LEDGER, "Cloud data change.store=%{public}s", origin.store.c_str());
std::vector<DistributedKv::Entry> insertRecords = ConvertCloudChangeDataToEntries(keys[ChangeOp::OP_INSERT]);
if (!insertRecords.empty() && insertRecords.size() <= MAX_DB_RECORD_SIZE) {
HandleAddChange(insertRecords);
}
std::vector<DistributedKv::Entry> updateRecords = ConvertCloudChangeDataToEntries(keys[ChangeOp::OP_UPDATE]);
if (!updateRecords.empty() && updateRecords.size() <= MAX_DB_RECORD_SIZE) {
SelectChangeType(updateRecords);
}
std::vector<std::string> delKeys = keys[ChangeOp::OP_DELETE];
if (!delKeys.empty() && delKeys.size() <= MAX_DB_RECORD_SIZE) {
std::vector<DistributedKv::Entry> deleteRecords;
for (const auto &key : delKeys) {
DistributedKv::Entry entry;
DistributedKv::Key kvKey(key);
entry.key = kvKey;
deleteRecords.emplace_back(entry);
auto autoSyncTask = [this, origin, keys]() {
LNN_LOGI(LNN_LEDGER, "Cloud data change.store=%{public}s", origin.store.c_str());
std::vector<DistributedKv::Entry> insertRecords = ConvertCloudChangeDataToEntries(keys[ChangeOp::OP_INSERT]);
if (!insertRecords.empty() && insertRecords.size() <= MAX_DB_RECORD_SIZE) {
SelectChangeType(insertRecords);
}
HandleDeleteChange(deleteRecords);
}
std::vector<DistributedKv::Entry> updateRecords = ConvertCloudChangeDataToEntries(keys[ChangeOp::OP_UPDATE]);
if (!updateRecords.empty() && updateRecords.size() <= MAX_DB_RECORD_SIZE) {
SelectChangeType(updateRecords);
}
std::vector<std::string> delKeys = keys[ChangeOp::OP_DELETE];
if (!delKeys.empty() && delKeys.size() <= MAX_DB_RECORD_SIZE) {
std::vector<DistributedKv::Entry> deleteRecords;
for (const auto &key : delKeys) {
DistributedKv::Entry entry;
DistributedKv::Key kvKey(key);
entry.key = kvKey;
deleteRecords.emplace_back(entry);
}
HandleDeleteChange(deleteRecords);
}
};
std::thread(autoSyncTask).detach();
}
std::vector<DistributedKv::Entry> KvDataChangeListener::ConvertCloudChangeDataToEntries(
@ -75,7 +77,7 @@ std::vector<DistributedKv::Entry> KvDataChangeListener::ConvertCloudChangeDataTo
{
int32_t dbId = 0;
char *anonyKey = nullptr;
LnnCreateKvAdapter(&dbId, APP_ID.c_str(), APP_ID_LEN, STORE_ID.c_str(), STORE_ID_LEN);
LnnCreateKvAdapter(&dbId, appId_.c_str(), appId_.length(), storeId_.c_str(), storeId_.length());
LNN_LOGI(LNN_LEDGER, "call! dbId=%{public}d", dbId);
std::vector<DistributedKv::Entry> entries;
if (keys.empty()) {

View File

@ -87,6 +87,7 @@ int32_t AuthDevicePostTransData(AuthHandle authHandle, const AuthTransData *data
void AuthDeviceCloseConn(AuthHandle authHandle);
int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo);
int32_t AuthDeviceGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo);
int32_t AuthDeviceGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo);
/*check whether AUTH device is exist or not*/
bool AuthDeviceCheckConnInfo(const char* uuid, AuthLinkType type, bool checkConnection);

View File

@ -176,6 +176,7 @@ int32_t AuthPostTransData(AuthHandle authHandle, const AuthTransData *dataInfo);
void AuthCloseConn(AuthHandle authHandle);
int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta);
int32_t AuthGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta);
int32_t AuthGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta);
int32_t AuthGetLatestAuthSeqList(const char *udid, int64_t *seqList, uint32_t num);
int32_t AuthGetLatestAuthSeqListByType(const char *udid, int64_t *seqList, uint64_t *authVerifyTime,
DiscoveryType type);

View File

@ -263,7 +263,16 @@ static void OnDeviceBound(const char *udid, const char *groupInfo)
AUTH_LOGW(AUTH_HICHAIN, "invalid udid");
return;
}
AUTH_LOGI(AUTH_HICHAIN, "hichain onDeviceBound");
char *anonyUdid = NULL;
Anonymize(udid, &anonyUdid);
AUTH_LOGI(AUTH_HICHAIN, "hichain onDeviceBound, udid=%{public}s", anonyUdid);
AnonymizeFree(anonyUdid);
char localUdid[UDID_BUF_LEN] = { 0 };
LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN);
if (strcmp(localUdid, udid) == 0) {
AUTH_LOGI(AUTH_HICHAIN, "ignore local udid");
return;
}
if (g_dataChangeListener.onDeviceBound != NULL) {
g_dataChangeListener.onDeviceBound(udid, groupInfo);
}

View File

@ -62,6 +62,10 @@ static ModuleListener g_moduleListener[] = {
{
.module = MODULE_P2P_NETWORKING_SYNC,
.listener = { NULL, NULL },
},
{
.module = MODULE_AUTH_SYNC_INFO,
.listener = { NULL, NULL },
}
};
@ -296,6 +300,14 @@ int32_t AuthGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta
return AuthDeviceGetP2pConnInfo(uuid, connInfo);
}
int32_t AuthGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta)
{
if (isMeta) {
return AUTH_INVALID_ID;
}
return AuthDeviceGetHmlConnInfo(uuid, connInfo);
}
/* for ProxyChannel & P2P TcpDirectchannel */
void AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta, AuthHandle *authHandle)
{

View File

@ -615,20 +615,20 @@ static int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo, bool judg
}
static int32_t ProcessSessionKey(SessionKeyList *list, const SessionKey *key, AuthSessionInfo *info,
bool isOldKey, int32_t *index)
bool isOldKey, int64_t *peerAuthSeq)
{
if (info->normalizedType == NORMALIZED_SUPPORT) {
if (SetSessionKeyAuthLinkType(list, info->normalizedIndex, info->connInfo.type) == SOFTBUS_OK) {
AUTH_LOGI(AUTH_FSM, "index is alread exist");
return SOFTBUS_OK;
}
*index = info->normalizedIndex;
*peerAuthSeq = info->normalizedIndex;
}
if (AddSessionKey(list, *index, key, info->connInfo.type, isOldKey) != SOFTBUS_OK) {
if (AddSessionKey(list, TO_INT32(*peerAuthSeq), key, info->connInfo.type, isOldKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "failed to add a sessionKey");
return SOFTBUS_ERR;
}
AUTH_LOGI(AUTH_FSM, "add session key index=%{public}d, new type=%{public}d", *index, info->connInfo.type);
AUTH_LOGI(AUTH_FSM, "add key index=%{public}d, new type=%{public}d", TO_INT32(*peerAuthSeq), info->connInfo.type);
return SOFTBUS_OK;
}
@ -657,7 +657,8 @@ static AuthManager *GetExistAuthManager(int64_t authSeq, const AuthSessionInfo *
return auth;
}
static AuthManager *GetDeviceAuthManager(int64_t authSeq, const AuthSessionInfo *info, bool *isNewCreated)
static AuthManager *GetDeviceAuthManager(int64_t authSeq, const AuthSessionInfo *info, bool *isNewCreated,
int64_t lastAuthSeq)
{
AuthManager *auth = FindAuthManagerByConnInfo(&info->connInfo, info->isServer);
if (auth != NULL && auth->connInfo[info->connInfo.type].type != 0) {
@ -683,7 +684,7 @@ static AuthManager *GetDeviceAuthManager(int64_t authSeq, const AuthSessionInfo
}
}
auth->connId[info->connInfo.type] = info->connId;
auth->lastAuthSeq[info->connInfo.type] = authSeq;
auth->lastAuthSeq[info->connInfo.type] = lastAuthSeq;
auth->lastVerifyTime = GetCurrentTimeMs();
auth->lastActiveTime = GetCurrentTimeMs();
return auth;
@ -778,7 +779,7 @@ int32_t AuthDirectOnlineCreateAuthManager(int64_t authSeq, const AuthSessionInfo
}
bool isNewCreated = false;
AuthManager *auth = GetDeviceAuthManager(authSeq, info, &isNewCreated);
AuthManager *auth = GetDeviceAuthManager(authSeq, info, &isNewCreated, authSeq);
if (auth == NULL) {
AUTH_LOGE(AUTH_FSM, "auth manager does not exist.");
ReleaseAuthLock();
@ -800,9 +801,9 @@ int32_t AuthManagerSetSessionKey(int64_t authSeq, AuthSessionInfo *info, const S
AUTH_CHECK_AND_RETURN_RET_LOGE(sessionKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_FSM, "sessionKey is NULL");
AUTH_CHECK_AND_RETURN_RET_LOGE(CheckAuthConnInfoType(&info->connInfo), SOFTBUS_INVALID_PARAM,
AUTH_FSM, "connInfo type error");
int32_t sessionKeyIndex = TO_INT32(authSeq);
int64_t sessionKeyIndex = authSeq;
if ((info->isSupportFastAuth) && (info->version <= SOFTBUS_OLD_V2)) {
sessionKeyIndex = TO_INT32(info->oldIndex);
sessionKeyIndex = info->oldIndex;
}
authSeq = isConnect ? authSeq : GenSeq(info->isServer);
AUTH_LOGI(AUTH_FSM, "SetSessionKey: authSeq=%{public}" PRId64 ", side=%{public}s, requestId=%{public}u", authSeq,
@ -816,7 +817,7 @@ int32_t AuthManagerSetSessionKey(int64_t authSeq, AuthSessionInfo *info, const S
return SOFTBUS_OK;
}
bool isNewCreated = false;
AuthManager *auth = GetDeviceAuthManager(authSeq, info, &isNewCreated);
AuthManager *auth = GetDeviceAuthManager(authSeq, info, &isNewCreated, sessionKeyIndex);
if (auth == NULL) {
AUTH_LOGE(AUTH_FSM, "auth manager does not exist.");
ReleaseAuthLock();
@ -836,12 +837,12 @@ int32_t AuthManagerSetSessionKey(int64_t authSeq, AuthSessionInfo *info, const S
}
int32_t ret = SOFTBUS_OK;
if (!isConnect) {
ret = SetSessionKeyAvailable(&auth->sessionKeyList, sessionKeyIndex);
ret = SetSessionKeyAvailable(&auth->sessionKeyList, TO_INT32(sessionKeyIndex));
auth->hasAuthPassed = true;
}
AUTH_LOGI(AUTH_FSM,
"authId=%{public}" PRId64 ", authSeq=%{public}" PRId64 ", index=%{public}d, lastVerifyTime=%{public}" PRId64,
auth->authId, authSeq, sessionKeyIndex, auth->lastVerifyTime);
auth->authId, authSeq, TO_INT32(sessionKeyIndex), auth->lastVerifyTime);
ReleaseAuthLock();
return ret;
}
@ -2202,6 +2203,19 @@ int32_t GetAuthLinkTypeList(const char *networkId, AuthLinkTypeList *linkTypeLis
}
int32_t AuthDeviceGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo)
{
if (uuid == NULL || uuid[0] == '\0' || connInfo == NULL) {
AUTH_LOGE(AUTH_CONN, "invalid uuid or connInfo");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = GetAuthConnInfoByUuid(uuid, AUTH_LINK_TYPE_P2P, connInfo);
if (ret == SOFTBUS_OK) {
AUTH_LOGI(AUTH_CONN, "select auth type=%{public}d", AUTH_LINK_TYPE_P2P);
}
return ret;
}
int32_t AuthDeviceGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo)
{
if (uuid == NULL || uuid[0] == '\0' || connInfo == NULL) {
AUTH_LOGE(AUTH_CONN, "invalid uuid or connInfo");

View File

@ -30,6 +30,8 @@
#include "bus_center_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_event.h"
#include "lnn_feature_capability.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_hitrace.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
@ -368,7 +370,8 @@ static void ReportAuthResultEvt(AuthFsm *authFsm, int32_t result)
}
return;
} else if (result == SOFTBUS_AUTH_SYNC_DEVID_FAIL || result == SOFTBUS_AUTH_SYNC_DEVINFO_FAIL ||
result == SOFTBUS_AUTH_UNPACK_DEVINFO_FAIL || result == SOFTBUS_AUTH_SEND_FAIL) {
result == SOFTBUS_AUTH_UNPACK_DEVINFO_FAIL || result == SOFTBUS_AUTH_SEND_FAIL ||
result == SOFTBUS_AUTH_NOT_SUPPORT_THREE_STATE) {
stage = AUTH_EXCHANGE_STAGE;
} else if (result == SOFTBUS_AUTH_DEVICE_DISCONNECTED) {
stage = AUTH_CONNECT_STAGE;
@ -961,6 +964,21 @@ static bool DeviceAuthStateProcess(FsmStateMachine *fsm, int32_t msgType, void *
return true;
}
static int32_t HandleCloseAckMessage(AuthFsm *authFsm, const AuthSessionInfo *info)
{
if ((SoftBusGetBrState() == BR_DISABLE) && (info->nodeInfo.feature & 1 << BIT_SUPPORT_THREE_STATE) == 0) {
AUTH_LOGE(AUTH_FSM, "peer not support three state");
CompleteAuthSession(authFsm, SOFTBUS_AUTH_NOT_SUPPORT_THREE_STATE);
return SOFTBUS_ERR;
}
if (PostCloseAckMessage(authFsm->authSeq, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "post close ack fail");
CompleteAuthSession(authFsm, SOFTBUS_AUTH_SEND_FAIL);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, const MessagePara *para)
{
AuthSessionInfo *info = &authFsm->info;
@ -997,9 +1015,8 @@ static void HandleMsgRecvDeviceInfo(AuthFsm *authFsm, const MessagePara *para)
TryFinishAuthSession(authFsm);
return;
}
if (PostCloseAckMessage(authFsm->authSeq, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "post close ack fail");
CompleteAuthSession(authFsm, SOFTBUS_AUTH_SEND_FAIL);
if (HandleCloseAckMessage(authFsm, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "handle close ack fail");
return;
}
if (info->isCloseAckReceived) {

View File

@ -952,7 +952,7 @@ static int32_t VerifyExchangeIdTypeAndInfo(AuthSessionInfo *info, int32_t idType
if (idType == EXCHANGE_NETWORKID) {
if (GetPeerUdidByNetworkId(info->udid, peerUdid) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get peer udid fail, peer networkId=%s", anonyUdid);
AUTH_LOGE(AUTH_FSM, "get peer udid fail, peer networkId=%{public}s", anonyUdid);
info->idType = EXCHANGE_FAIL;
(void)memset_s(info->udid, sizeof(info->udid), 0, sizeof(info->udid));
} else {
@ -961,7 +961,7 @@ static int32_t VerifyExchangeIdTypeAndInfo(AuthSessionInfo *info, int32_t idType
info->idType = EXCHANGE_FAIL;
return SOFTBUS_MEM_ERR;
}
AUTH_LOGE(AUTH_FSM, "get peer udid success, peer udid=%s", anonyUdid);
AUTH_LOGE(AUTH_FSM, "get peer udid success, peer udid=%{public}s", anonyUdid);
info->idType = EXCHANGE_NETWORKID;
}
}

View File

@ -131,6 +131,14 @@ int32_t AuthGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t AuthGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta)
{
(void)uuid;
(void)connInfo;
(void)isMeta;
return SOFTBUS_NOT_IMPLEMENT;
}
void AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta, AuthHandle *authHandle)
{
(void)uuid;

View File

@ -95,6 +95,7 @@ typedef enum {
BYTE_KEY_BROADCAST_CIPHER_IV,
BYTE_KEY_UDID_HASH,
BYTE_KEY_END,
INFO_KEY_MAX,
} InfoKey;
#ifdef __cplusplus

View File

@ -84,7 +84,7 @@ typedef struct {
void (*deinit)(void);
} LnnHeartbeatMediumMgr;
int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param);
int32_t LnnHbMediumMgrSetParam(void *param);
int32_t LnnHbMediumMgrSendBegin(LnnHeartbeatSendBeginData *custData);
int32_t LnnHbMediumMgrSendEnd(LnnHeartbeatSendEndData *custData);
int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type);

View File

@ -34,7 +34,7 @@ extern "C" {
#define HB_TIME_FACTOR (1000LL)
#define HB_START_DELAY_LEN (10 * HB_TIME_FACTOR)
#define HB_CLOUD_SYNC_DELAY_LEN (20 * HB_TIME_FACTOR)
#define HB_CLOUD_SYNC_DELAY_LEN (10 * HB_TIME_FACTOR)
#define HB_SEND_ONCE_LEN (10 * HB_TIME_FACTOR)
#define HB_SEND_RELAY_LEN (2 * HB_TIME_FACTOR)
#define HB_CHECK_DELAY_LEN HB_SEND_ONCE_LEN
@ -115,6 +115,7 @@ typedef struct {
#define P2P_GO (1 << 1)
#define P2P_GC (1 << 2)
#define ENABLE_WIFI_CAP (1 << 3)
#define DISABLE_BR_CAP (1 << 4)
typedef struct {
int32_t (*onDataLevelChanged)(const char *networkId, const DataLevelInfo *dataLevelInfo);

View File

@ -31,6 +31,7 @@
#include "lnn_device_info_recovery.h"
#include "lnn_deviceinfo_to_profile.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_feature_capability.h"
#include "lnn_heartbeat_strategy.h"
#include "lnn_heartbeat_utils.h"
#include "lnn_local_net_ledger.h"
@ -39,6 +40,7 @@
#include "lnn_net_builder.h"
#include "lnn_network_manager.h"
#include "lnn_ohos_account.h"
#include "lnn_parameter_utils.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_mem.h"
@ -102,7 +104,8 @@ static bool IsHeartbeatEnable(void)
if ((g_hbConditionState.lockState == SOFTBUS_SCREEN_LOCK_UNKNOWN) && IsActiveOsAccountUnlocked()) {
g_hbConditionState.lockState = SOFTBUS_SCREEN_UNLOCK;
}
bool isBtOn = g_hbConditionState.btState == SOFTBUS_BLE_TURN_ON || g_hbConditionState.btState == SOFTBUS_BR_TURN_ON;
bool isBtOn = ((g_hbConditionState.btState != SOFTBUS_BLE_TURN_OFF) &&
(g_hbConditionState.btState != SOFTBUS_BT_UNKNOWN));
bool isScreenUnlock = g_hbConditionState.lockState == SOFTBUS_SCREEN_UNLOCK;
bool isLogIn = g_hbConditionState.accountState == SOFTBUS_ACCOUNT_LOG_IN;
bool isBackground = g_hbConditionState.backgroundState == SOFTBUS_USER_BACKGROUND;
@ -258,6 +261,36 @@ void LnnRequestBleDiscoveryProcess(int32_t strategy, int64_t timeout)
}
}
static int32_t HbHandleLeaveLnn(void)
{
int32_t i;
int32_t infoNum;
NodeBasicInfo *info = NULL;
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "get online node info failed");
return SOFTBUS_ERR;
}
if (info == NULL || infoNum == 0) {
LNN_LOGE(LNN_HEART_BEAT, "get online node is 0");
return SOFTBUS_ERR;
}
int32_t ret;
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
for (i = 0; i < infoNum; ++i) {
ret = LnnGetRemoteNodeInfoById(info[i].networkId, CATEGORY_NETWORK_ID, &nodeInfo);
if (ret != SOFTBUS_OK) {
continue;
}
if ((nodeInfo.feature & (1 << BIT_SUPPORT_THREE_STATE)) == 0 && SoftBusGetBrState() == BR_DISABLE) {
LNN_LOGI(LNN_HEART_BEAT, "peer don't support three state and local br off");
LnnRequestLeaveSpecific(info[i].networkId, CONNECTION_ADDR_BLE);
}
}
SoftBusFree(info);
return SOFTBUS_OK;
}
static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
{
if (info == NULL || info->event != LNN_EVENT_BT_STATE_CHANGED) {
@ -269,7 +302,9 @@ static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
g_hbConditionState.btState = btState;
switch (btState) {
case SOFTBUS_BLE_TURN_ON:
LNN_LOGI(LNN_HEART_BEAT, "HB handle 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();
@ -279,6 +314,20 @@ static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat fail");
}
break;
case SOFTBUS_BR_TURN_OFF:
if (SoftBusGetBtState() == BLE_DISABLE) {
LNN_LOGE(LNN_HEART_BEAT, "ble is off");
return;
}
g_enableState = false;
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_BR_TURN_OFF, state=%{public}d", btState);
(void)HbHandleLeaveLnn();
HbConditionChanged(false);
if (LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_ADJUSTABLE_PERIOD, false) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat fail");
}
break;
case SOFTBUS_BLE_TURN_OFF:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_BLE_TURN_OFF");
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_CLOSE_INFO);
@ -411,32 +460,38 @@ static void HbDelayConditionChanged(void *para)
{
(void)para;
LNN_LOGI(LNN_HEART_BEAT, "HB delay handle condition changed");
LNN_LOGI(LNN_HEART_BEAT, "HB handle delay condition changed");
LnnUpdateSendInfoStrategy(UPDATE_HB_ACCOUNT_INFO);
LnnHbOnTrustedRelationIncreased(AUTH_IDENTICAL_ACCOUNT_GROUP);
HbConditionChanged(false);
}
static int32_t HbTryCloudSync(void)
static void HbTryCloudSync(void *para)
{
(void)para;
NodeInfo info;
int32_t ret = SOFTBUS_ERR;
if (LnnIsDefaultOhosAccount()) {
LNN_LOGW(LNN_HEART_BEAT, "HB accountId is null, no need sync");
return SOFTBUS_ERR;
}
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetLocalNodeInfoSafe(&info) != SOFTBUS_OK || LnnSaveLocalDeviceInfo(&info) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB save local device info fail");
return SOFTBUS_ERR;
}
int32_t ret = LnnLedgerAllDataSyncToDB(&info);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB sync to cloud fail");
} else {
LNN_LOGI(LNN_HEART_BEAT, "HB sync to cloud end");
}
return ret;
LNN_LOGI(LNN_HEART_BEAT, "HB handle delay cloud sync");
do {
if (LnnIsDefaultOhosAccount()) {
LNN_LOGW(LNN_HEART_BEAT, "HB accountId is null, no need sync");
break;
}
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetLocalNodeInfoSafe(&info) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB save local device info fail");
break;
}
ret = LnnLedgerAllDataSyncToDB(&info);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB sync to cloud fail");
} else {
LNN_LOGI(LNN_HEART_BEAT, "HB sync to cloud end");
}
} while (false);
LnnAsyncCallbackDelayHelper(
GetLooper(LOOP_TYPE_DEFAULT), HbDelayConditionChanged, NULL, ret == SOFTBUS_OK ? HB_CLOUD_SYNC_DELAY_LEN : 0);
}
static void HbScreenLockChangeEventHandler(const LnnEventBasicInfo *info)
@ -458,8 +513,8 @@ static void HbScreenLockChangeEventHandler(const LnnEventBasicInfo *info)
case SOFTBUS_SCREEN_UNLOCK:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_SCREEN_UNLOCK");
LnnUpdateOhosAccount(false);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelayConditionChanged, NULL,
HbTryCloudSync() == SOFTBUS_OK ? HB_START_DELAY_LEN : 0);
LnnAsyncCallbackDelayHelper(
GetLooper(LOOP_TYPE_DEFAULT), HbTryCloudSync, NULL, IsCloudSyncEnabled() ? HB_CLOUD_SYNC_DELAY_LEN : 0);
break;
case SOFTBUS_SCREEN_LOCK:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_SCREEN_LOCK");
@ -482,8 +537,8 @@ static void HbAccountStateChangeEventHandler(const LnnEventBasicInfo *info)
case SOFTBUS_ACCOUNT_LOG_IN:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_ACCOUNT_LOG_IN");
LnnUpdateOhosAccount(false);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelayConditionChanged, NULL,
HbTryCloudSync() == SOFTBUS_OK ? HB_CLOUD_SYNC_DELAY_LEN : 0);
LnnAsyncCallbackDelayHelper(
GetLooper(LOOP_TYPE_DEFAULT), HbTryCloudSync, NULL, IsCloudSyncEnabled() ? HB_CLOUD_SYNC_DELAY_LEN : 0);
break;
case SOFTBUS_ACCOUNT_LOG_OUT:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_ACCOUNT_LOG_OUT");
@ -524,7 +579,7 @@ static void HbDifferentAccountEventHandler(const LnnEventBasicInfo *info)
}
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
SoftBusDifferentAccountState difAccountState = (SoftBusDifferentAccountState)event->status;
if (difAccountState == LNN_EVENT_DIF_ACCOUNT_DEV_CHANGED) {
if ((LnnEventType)difAccountState == LNN_EVENT_DIF_ACCOUNT_DEV_CHANGED) {
HbConditionChanged(false);
}
}
@ -606,26 +661,28 @@ static void HbLpEventHandler(const LnnEventBasicInfo *info)
LNN_LOGE(LNN_HEART_BEAT, "lp report evt handler get invalid param");
return;
}
int32_t ret;
const LnnLpReportEvent *event = (const LnnLpReportEvent *)info;
SoftBusLpEventType type = (SoftBusLpEventType)event->type;
switch (type) {
case SOFTBUS_MSDP_MOVEMENT_AND_STATIONARY:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_MSDP_MOVEMENT_AND_STATIONARY");
int32_t ret = LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_SINGLE, false);
ret = LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_SINGLE, false);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat failed, ret=%{public}d", ret);
return;
}
break;
default:
LNN_LOGE(LNN_HEART_BEAT, "lp evt handler get invalid type = %{public}d", type);
LNN_LOGE(LNN_HEART_BEAT, "lp evt handler get invalid type=%{public}d", type);
return;
}
}
static void HbTryRecoveryNetwork(void)
{
if (SoftBusGetBtState() == BLE_ENABLE) {
g_hbConditionState.btState = SOFTBUS_BR_TURN_ON;
g_hbConditionState.btState = SOFTBUS_BLE_TURN_ON;
}
if (!LnnIsDefaultOhosAccount()) {
g_hbConditionState.accountState = SOFTBUS_ACCOUNT_LOG_IN;
@ -705,7 +762,7 @@ int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType ad
anonyNetworkId, timeStamp);
AnonymizeFree(anonyNetworkId);
if (SoftBusGetBtState() == BLE_ENABLE) {
g_hbConditionState.btState = SOFTBUS_BR_TURN_ON;
g_hbConditionState.btState = SOFTBUS_BLE_TURN_ON;
}
return SOFTBUS_OK;
}
@ -819,7 +876,8 @@ int32_t LnnShiftLNNGearWithoutPkgName(const char *callerId, const GearMode *mode
return SOFTBUS_ERR;
}
int32_t ret;
NodeInfo nodeInfo = { 0 };
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
for (i = 0; i < infoNum; ++i) {
ret = LnnGetRemoteNodeInfoById(info[i].networkId, CATEGORY_NETWORK_ID, &nodeInfo);
if (ret != SOFTBUS_OK || !LnnHasDiscoveryType(&nodeInfo, DISCOVERY_TYPE_WIFI)) {
@ -894,7 +952,7 @@ static int32_t LnnHbSubscribeTask(void)
{
(void)memset_s(&g_dcTask, sizeof(DcTask), 0, sizeof(DcTask));
g_dcTask.preferredSystem = TASK_RULE_SYSTEM;
g_dcTask.optimizeStrategy = (void *)LnnHbMediumMgrSetParam;
g_dcTask.optimizeStrategy = LnnHbMediumMgrSetParam;
return LnnDcSubscribe(&g_dcTask);
}

View File

@ -669,7 +669,7 @@ static int32_t OnSetMediumParam(FsmStateMachine *fsm, int32_t msgType, void *par
LNN_LOGE(LNN_HEART_BEAT, "set medium param get invalid param");
return SOFTBUS_INVALID_PARAM;
}
ret = LnnHbMediumMgrSetParam((const LnnHeartbeatMediumParam *)para);
ret = LnnHbMediumMgrSetParam(para);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "set medium param process fail, ret=%{public}d", ret);
}
@ -1065,7 +1065,7 @@ static int32_t InitHeartbeatFsm(LnnHeartbeatFsm *hbFsm)
LNN_LOGE(LNN_HEART_BEAT, "format fsm name fail");
return SOFTBUS_ERR;
}
SoftBusLooper *looper = CreateNewLooper("Heartbeat_Lp");
SoftBusLooper *looper = GetLooper(LOOP_TYPE_LNN);
if (looper == NULL) {
LNN_LOGE(LNN_HEART_BEAT, "create looper fail");
return SOFTBUS_ERR;

View File

@ -43,6 +43,7 @@
#include "lnn_parameter_utils.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_timer.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -156,12 +157,22 @@ static void UpdateOnlineInfoNoConnection(const char *networkId, HbRespData *hbRe
uint32_t oldNetCapa = nodeInfo.netCapacity;
if ((hbResp->capabiltiy & ENABLE_WIFI_CAP) != 0) {
(void)LnnSetNetCapability(&nodeInfo.netCapacity, BIT_WIFI);
} else {
(void)LnnClearNetCapability(&nodeInfo.netCapacity, BIT_WIFI);
(void)LnnClearNetCapability(&nodeInfo.netCapacity, BIT_WIFI_5G);
(void)LnnClearNetCapability(&nodeInfo.netCapacity, BIT_WIFI_24G);
}
if ((hbResp->capabiltiy & P2P_GO) != 0 || (hbResp->capabiltiy & P2P_GC) != 0) {
(void)LnnSetNetCapability(&nodeInfo.netCapacity, BIT_WIFI_P2P);
} else {
(void)LnnClearNetCapability(&nodeInfo.netCapacity, BIT_WIFI_P2P);
}
if ((hbResp->capabiltiy & DISABLE_BR_CAP) != 0) {
(void)LnnClearNetCapability(&nodeInfo.netCapacity, BIT_BR);
} else {
(void)LnnSetNetCapability(&nodeInfo.netCapacity, BIT_BR);
}
(void)LnnSetNetCapability(&nodeInfo.netCapacity, BIT_BLE);
(void)LnnSetNetCapability(&nodeInfo.netCapacity, BIT_BR);
if (oldNetCapa == nodeInfo.netCapacity) {
LNN_LOGD(LNN_HEART_BEAT, "capa not change, don't update devInfo");
return;
@ -170,6 +181,11 @@ static void UpdateOnlineInfoNoConnection(const char *networkId, HbRespData *hbRe
LNN_LOGE(LNN_HEART_BEAT, "update net capability fail");
return;
}
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGI(LNN_HEART_BEAT, "networkId=%{public}s capability change:%{public}u->%{public}u", anonyNetworkId,
oldNetCapa, nodeInfo.netCapacity);
AnonymizeFree(anonyNetworkId);
}
static int32_t HbGetOnlineNodeByRecvInfo(
@ -346,15 +362,38 @@ static bool IsLocalSupportBleDirectOnline()
return true;
}
static bool IsLocalSupportThreeState()
{
uint64_t localFeatureCap = 0;
if (LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, &localFeatureCap) != SOFTBUS_OK) {
LNN_LOGW(LNN_HEART_BEAT, "build ble broadcast, get local feature cap failed");
return false;
}
if ((localFeatureCap & (1 << BIT_SUPPORT_THREE_STATE)) == 0) {
return false;
}
return true;
}
static void SetDeviceNetCapability(uint32_t *deviceInfoNetCapacity, HbRespData *hbResp)
{
if ((hbResp->capabiltiy & ENABLE_WIFI_CAP) != 0) {
(void)LnnSetNetCapability(deviceInfoNetCapacity, BIT_WIFI);
} else {
(void)LnnClearNetCapability(deviceInfoNetCapacity, BIT_WIFI);
(void)LnnClearNetCapability(deviceInfoNetCapacity, BIT_WIFI_5G);
(void)LnnClearNetCapability(deviceInfoNetCapacity, BIT_WIFI_24G);
}
if ((hbResp->capabiltiy & DISABLE_BR_CAP) != 0) {
(void)LnnClearNetCapability(deviceInfoNetCapacity, BIT_BR);
} else {
(void)LnnSetNetCapability(deviceInfoNetCapacity, BIT_BR);
}
if ((hbResp->capabiltiy & P2P_GO) != 0 || (hbResp->capabiltiy & P2P_GC)) {
(void)LnnSetNetCapability(deviceInfoNetCapacity, BIT_WIFI_P2P);
} else {
(void)LnnClearNetCapability(deviceInfoNetCapacity, BIT_WIFI_P2P);
}
(void)LnnSetNetCapability(deviceInfoNetCapacity, BIT_BR);
(void)LnnSetNetCapability(deviceInfoNetCapacity, BIT_BLE);
}
@ -422,6 +461,28 @@ static bool HbIsRepeatedReAuthRequest(LnnHeartbeatRecvInfo *storedInfo, uint64_t
return false;
}
static bool HbIsValidJoinLnnRequest(DeviceInfo *device, HbRespData *hbResp)
{
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (!IsLocalSupportThreeState()) {
LNN_LOGI(LNN_HEART_BEAT, "local don't support three state");
return true;
}
if (LnnRetrieveDeviceInfo(device->devId, &nodeInfo) != SOFTBUS_OK) {
LNN_LOGI(LNN_HEART_BEAT, "retrieve device info failed");
return true;
}
if ((nodeInfo.feature & (1 << BIT_SUPPORT_THREE_STATE)) == 0 && SoftBusGetBrState() == BR_DISABLE) {
char *anonyUdid = NULL;
Anonymize(device->devId, &anonyUdid);
LNN_LOGI(LNN_HEART_BEAT, "peer udidHash=%{public}s don't support three state and local br off", anonyUdid);
AnonymizeFree(anonyUdid);
return false;
}
return true;
}
static uint64_t GetNowTime()
{
SoftBusSysTime times = { 0 };
@ -644,6 +705,10 @@ static int32_t HbNotifyReceiveDevice(DeviceInfo *device, const LnnHeartbeatWeigh
(void)SoftBusMutexUnlock(&g_hbRecvList->lock);
return SOFTBUS_NETWORK_HEARTBEAT_REPEATED;
}
if (!HbIsValidJoinLnnRequest(device, hbResp)) {
(void)SoftBusMutexUnlock(&g_hbRecvList->lock);
return SOFTBUS_ERR;
}
(void)SoftBusMutexUnlock(&g_hbRecvList->lock);
bool isConnect = IsNeedConnectOnLine(device, hbResp);
if (isConnect && !device->isOnline) {
@ -1036,7 +1101,7 @@ void LnnHbMediumMgrDeinit(void)
HbDeinitRecvList();
}
int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param)
int32_t LnnHbMediumMgrSetParam(void *param)
{
int32_t id, ret;
@ -1044,18 +1109,19 @@ int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param)
LNN_LOGE(LNN_HEART_BEAT, "set medium param get invalid param");
return SOFTBUS_INVALID_PARAM;
}
id = LnnConvertHbTypeToId(param->type);
LnnHeartbeatMediumParam *mediumParam = (LnnHeartbeatMediumParam *)param;
id = LnnConvertHbTypeToId(mediumParam->type);
if (id == HB_INVALID_TYPE_ID) {
LNN_LOGE(LNN_HEART_BEAT, "set medium param convert type fail");
return SOFTBUS_ERR;
}
if (g_hbMeidumMgr[id] == NULL || g_hbMeidumMgr[id]->onSetMediumParam == NULL) {
LNN_LOGW(LNN_HEART_BEAT, "not support heartbeat type=%{public}d", param->type);
LNN_LOGW(LNN_HEART_BEAT, "not support heartbeat type=%{public}d", mediumParam->type);
return SOFTBUS_NOT_IMPLEMENT;
}
ret = g_hbMeidumMgr[id]->onSetMediumParam(param);
ret = g_hbMeidumMgr[id]->onSetMediumParam((const LnnHeartbeatMediumParam *)mediumParam);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "set medium param fail, type=%{public}d, ret=%{public}d", param->type, ret);
LNN_LOGE(LNN_HEART_BEAT, "set medium param fail, type=%{public}d, ret=%{public}d", mediumParam->type, ret);
return ret;
}
return SOFTBUS_OK;

View File

@ -30,6 +30,7 @@ typedef enum {
LANE_BW_20M,
LANE_BW_40M,
LANE_BW_80M,
LANE_BW_80P80M,
LANE_BW_160M,
LANE_BW_BUTT = 0xFF,
} LaneBandwidth;

View File

@ -106,6 +106,11 @@ typedef struct {
void (*OnLaneLinkFail)(uint32_t reqId, int32_t reason, LaneLinkType linkType);
} LaneLinkCb;
inline int32_t ErrCodeFilter(const int32_t errCode, const int32_t exceptErrCode)
{
return ((errCode > SOFTBUS_PUBLIC_ERR_BASE) && (errCode < SOFTBUS_TRANS_ERR_BASE)) ? exceptErrCode : errCode;
}
int32_t InitLaneLink(void);
void DeinitLaneLink(void);
int32_t BuildLink(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *cb);

View File

@ -131,7 +131,7 @@ static int32_t GetCtrlReqInfo(uint32_t laneHandle, CtrlReqInfo *reqInfo)
}
}
Unlock();
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
static void DeleteCtrlRequestNode(uint32_t laneHandle)
@ -220,13 +220,13 @@ static void CtrlLinkSuccess(uint32_t laneHandle, LaneLinkType linkType, const La
char localUdid[UDID_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid fail, laneHandle=%{public}u", laneHandle);
CtrlLinkFail(laneHandle, SOFTBUS_ERR, linkType);
CtrlLinkFail(laneHandle, SOFTBUS_LANE_GET_LEDGER_INFO_ERR, linkType);
return;
}
uint64_t laneId = GenerateLaneId(localUdid, linkInfo->peerUdid, linkInfo->type);
if (laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "generate laneId fail, laneHandle=%{public}u", laneHandle);
CtrlLinkFail(laneHandle, SOFTBUS_ERR, linkType);
CtrlLinkFail(laneHandle, SOFTBUS_LANE_ID_GENERATE_FAIL, linkType);
return;
}
int32_t ret = AddLaneResourceToPool(linkInfo, laneId, false);
@ -307,27 +307,30 @@ static int32_t CtrlTriggerLink(uint32_t laneHandle)
if (reqInfo == NULL) {
LNN_LOGE(LNN_LANE, "get lane reqInfo fail");
Unlock();
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
LaneLinkCb linkCb = {
.OnLaneLinkSuccess = CtrlLinkSuccess,
.OnLaneLinkFail = CtrlLinkFail,
};
LinkRequest requestInfo = {0};
int32_t ret = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
do {
if (CreateLinkRequestNode(&reqInfo->allocInfo, &requestInfo) != SOFTBUS_OK) {
ret = CreateLinkRequestNode(&reqInfo->allocInfo, &requestInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "Create LinkRequestNode fail.");
break;
}
requestInfo.linkType = reqInfo->linkList.linkType[reqInfo->linkListIdx];
reqInfo->linkListIdx++;
Unlock();
if (BuildLink(&requestInfo, laneHandle, &linkCb) == SOFTBUS_OK) {
ret = BuildLink(&requestInfo, laneHandle, &linkCb);
if (ret == SOFTBUS_OK) {
return SOFTBUS_OK;
}
} while (false);
linkCb.OnLaneLinkFail(laneHandle, SOFTBUS_ERR, requestInfo.linkType);
return SOFTBUS_ERR;
linkCb.OnLaneLinkFail(laneHandle, ret, requestInfo.linkType);
return ret;
}
static int32_t AllocCtrlLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
@ -335,21 +338,23 @@ static int32_t AllocCtrlLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo
AuthLinkTypeList authList;
if (memset_s(&authList, sizeof(AuthLinkTypeList), 0, sizeof(AuthLinkTypeList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s authList fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (GetAuthLinkTypeList(allocInfo->networkId, &authList) != SOFTBUS_OK) {
int32_t ret = GetAuthLinkTypeList(allocInfo->networkId, &authList);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get authList fail");
return SOFTBUS_ERR;
return ret;
}
LanePreferredLinkList request;
if (memset_s(&request, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s request fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (ConvertAuthLinkToLaneLink(&authList, &request) != SOFTBUS_OK) {
ret = ConvertAuthLinkToLaneLink(&authList, &request);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "convert authLink to laneLink fail");
return SOFTBUS_ERR;
return ret;
}
LanePreferredLinkList *recommendLinkList = (LanePreferredLinkList *)SoftBusCalloc(sizeof(LanePreferredLinkList));
if (recommendLinkList == NULL) {
@ -357,11 +362,11 @@ static int32_t AllocCtrlLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo
return SOFTBUS_MALLOC_ERR;
}
recommendLinkList->linkTypeNum = 0;
if (SelectAuthLane(allocInfo->networkId, &request, recommendLinkList) != SOFTBUS_OK ||
recommendLinkList->linkTypeNum == 0) {
ret = SelectAuthLane(allocInfo->networkId, &request, recommendLinkList);
if (ret != SOFTBUS_OK || recommendLinkList->linkTypeNum == 0) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "no abailable link resources, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
return ret;
}
for (uint32_t i = 0; i < recommendLinkList->linkTypeNum; ++i) {
LNN_LOGI(LNN_LANE, "auth expect recommendLinkList nums=%{public}u, priority=%{public}u, link=%{public}u",
@ -370,12 +375,13 @@ static int32_t AllocCtrlLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo
if (CreateCtrlReqNode(laneHandle, allocInfo, listener, recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "create ctrlReqInfo node fail.");
return SOFTBUS_ERR;
return SOFTBUS_LANE_LIST_ERR;
}
if (CtrlTriggerLink(laneHandle) != SOFTBUS_OK) {
ret = CtrlTriggerLink(laneHandle);
if (ret != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "trigger link fail, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -386,10 +392,11 @@ static int32_t CtrlAlloc(uint32_t laneHandle, const LaneAllocInfo *allocInfo, co
LNN_LOGE(LNN_LANE, "param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (AllocCtrlLane(laneHandle, allocInfo, listener) != SOFTBUS_OK) {
int32_t ret = AllocCtrlLane(laneHandle, allocInfo, listener);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc valid lane fail, laneHandle=%{public}u", laneHandle);
FreeLaneReqId(laneHandle);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -440,11 +447,11 @@ static int32_t FreeLaneLink(uint32_t laneHandle, uint64_t laneId)
LaneResource resourceItem;
(void)memset_s(&resourceItem, sizeof(LaneResource), 0, sizeof(LaneResource));
if (FindLaneResourceByLaneId(laneId, &resourceItem) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LANE_RESOURCE_NOT_FOUND;
}
char networkId[NETWORK_ID_BUF_LEN] = { 0 };
if (LnnGetNetworkIdByUdid(resourceItem.link.peerUdid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
DestroyLink(networkId, laneHandle, resourceItem.link.type);
DelLaneResourceByLaneId(laneId, false);

View File

@ -204,12 +204,12 @@ void UnregisterLaneIdListener(const ILaneIdStateListener *listener)
static int32_t GetAllLaneIdListener(ILaneIdStateListener **listener, uint32_t *listenerNum)
{
if (Lock() != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
if (g_laneListenerList.cnt == 0) {
Unlock();
LNN_LOGE(LNN_LANE, "laneIdListener num is zero");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
uint32_t num = g_laneListenerList.cnt;
*listener = (ILaneIdStateListener *)SoftBusCalloc(sizeof(ILaneIdStateListener) * num);
@ -375,10 +375,10 @@ static int32_t CheckLaneObject(uint32_t laneReqId, LaneType *type)
*type = laneReqId >> LANE_REQ_ID_TYPE_SHIFT;
if (*type >= LANE_TYPE_BUTT) {
LNN_LOGE(LNN_LANE, "laneType invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (g_laneObject[*type] == NULL) {
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return SOFTBUS_OK;
}
@ -470,7 +470,7 @@ int32_t LnnFreeLane(uint32_t laneReqId)
int32_t result = g_laneObject[type]->freeLane(laneReqId);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "freeLane fail, result=%{public}d", result);
return SOFTBUS_ERR;
return result;
}
return SOFTBUS_OK;
}
@ -518,22 +518,22 @@ int32_t InitLane(void)
{
if (InitLaneModel() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "[InitLane]init laneModel fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
if (InitLaneLink() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "[InitLane]init laneLink fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
if (InitLaneListener() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "[InitLane]init laneListener fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
if (LaneDelayInit() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "[InitLane]laneDelayInit fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexInit(&g_laneMutex, NULL) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
g_laneIdListener.OnLaneIdEnabled = LaneIdEnabled;
g_laneIdListener.OnLaneIdDisabled = LaneIdDisabled;

View File

@ -35,7 +35,7 @@ static int32_t BrInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
connInfo->type = LANE_BR;
if (memcpy_s(connInfo->connInfo.br.brMac, BT_MAC_LEN,
linkInfo->linkInfo.br.brMac, BT_MAC_LEN) != EOK) {
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
profile->linkType = LANE_BR;
return SOFTBUS_OK;
@ -47,12 +47,12 @@ static int32_t BleInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
if (memcpy_s(connInfo->connInfo.ble.bleMac, BT_MAC_LEN,
linkInfo->linkInfo.ble.bleMac, BT_MAC_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy btMac fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(connInfo->connInfo.ble.deviceIdHash, UDID_HASH_LEN,
linkInfo->linkInfo.ble.deviceIdHash, UDID_HASH_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy udidHash fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
connInfo->connInfo.ble.protoType = linkInfo->linkInfo.ble.protoType;
connInfo->connInfo.ble.psm = linkInfo->linkInfo.ble.psm;
@ -66,7 +66,7 @@ static int32_t P2pInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
if (memcpy_s(&connInfo->connInfo.p2p, sizeof(P2pConnInfo),
&linkInfo->linkInfo.p2p.connInfo, sizeof(P2pConnInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy P2pConnInfo fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
profile->linkType = LANE_P2P;
profile->bw = linkInfo->linkInfo.p2p.bw;
@ -80,7 +80,7 @@ static int32_t HmlInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
if (memcpy_s(&connInfo->connInfo.p2p, sizeof(P2pConnInfo),
&linkInfo->linkInfo.p2p.connInfo, sizeof(P2pConnInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy P2pConnInfo fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
profile->linkType = LANE_HML;
profile->bw = linkInfo->linkInfo.p2p.bw;
@ -102,7 +102,7 @@ static int32_t Wlan2P4GInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *conn
if (memcpy_s(&connInfo->connInfo.wlan, sizeof(WlanConnInfo),
&linkInfo->linkInfo.wlan.connInfo, sizeof(WlanConnInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy WlanConnInfo fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
profile->linkType = LANE_WLAN_2P4G;
profile->bw = linkInfo->linkInfo.wlan.bw;
@ -116,7 +116,7 @@ static int32_t Wlan5GInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connIn
if (memcpy_s(&connInfo->connInfo.wlan, sizeof(WlanConnInfo),
&linkInfo->linkInfo.wlan.connInfo, sizeof(WlanConnInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy WlanConnInfo fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
profile->linkType = LANE_WLAN_5G;
profile->bw = linkInfo->linkInfo.wlan.bw;
@ -129,7 +129,7 @@ static int32_t BleDirectInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *con
if (strcpy_s(connInfo->connInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN,
linkInfo->linkInfo.bleDirect.networkId) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy networkId fail");
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
connInfo->type = LANE_BLE_DIRECT;
connInfo->connInfo.bleDirect.protoType = linkInfo->linkInfo.bleDirect.protoType;
@ -143,12 +143,12 @@ static int32_t CocInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
if (memcpy_s(connInfo->connInfo.ble.bleMac, BT_MAC_LEN,
linkInfo->linkInfo.ble.bleMac, BT_MAC_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy bleMac fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(connInfo->connInfo.ble.deviceIdHash, UDID_HASH_LEN,
linkInfo->linkInfo.ble.deviceIdHash, UDID_HASH_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy deviceIdHash fail");
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
connInfo->connInfo.ble.psm = linkInfo->linkInfo.ble.psm;
profile->linkType = LANE_COC;
@ -173,11 +173,11 @@ int32_t LaneInfoProcess(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, La
{
if ((linkInfo == NULL) || (connInfo == NULL) || (profile == NULL)) {
LNN_LOGE(LNN_LANE, "laneInfoProcess param invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if ((linkInfo->type >= LANE_LINK_TYPE_BUTT) || (g_funcList[linkInfo->type] == NULL)) {
LNN_LOGE(LNN_LANE, "unsupport linkType=%{public}d", linkInfo->type);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return g_funcList[linkInfo->type](linkInfo, connInfo, profile);
}
@ -187,11 +187,12 @@ int32_t LnnCreateData(Map *map, uint32_t key, const void *value, uint32_t valueS
char keyStr[UINT_TO_STR_MAX_LEN] = {0};
if (sprintf_s(keyStr, UINT_TO_STR_MAX_LEN, "%u", key) < 0) {
LNN_LOGE(LNN_LANE, "convert dataType fail");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (LnnMapSet(map, (const char *)keyStr, value, valueSize) != SOFTBUS_OK) {
int32_t ret = LnnMapSet(map, (const char *)keyStr, value, valueSize);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "save data fail");
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}

View File

@ -405,7 +405,7 @@ int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, Lane
Anonymize(peerUdid, &anonyPeerUdid);
LNN_LOGE(LNN_LANE, "no find lane resource by linktype=%{public}d, peerUdid=%{public}s", type, anonyPeerUdid);
AnonymizeFree(anonyPeerUdid);
return SOFTBUS_LANE_RESOURCE_NOT_FIND;
return SOFTBUS_LANE_RESOURCE_NOT_FOUND;
}
int32_t FindLaneResourceByLinkAddr(const LaneLinkInfo *info, LaneResource *resource)
@ -421,7 +421,7 @@ int32_t FindLaneResourceByLinkAddr(const LaneLinkInfo *info, LaneResource *resou
if (item == NULL) {
LNN_LOGE(LNN_LANE, "no found lane resource by link info");
LaneUnlock();
return SOFTBUS_ERR;
return SOFTBUS_LANE_RESOURCE_NOT_FOUND;
}
if (memcpy_s(resource, sizeof(LaneResource), item, sizeof(LaneResource)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy lane resource fail");
@ -456,7 +456,7 @@ int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resource)
}
LaneUnlock();
LNN_LOGE(LNN_LANE, "no found lane resource by laneId=%{public}" PRIu64 "", laneId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_RESOURCE_NOT_FOUND;
}
static int32_t LaneLinkOfBr(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
@ -806,7 +806,7 @@ static int32_t LaneLinkOfP2pReuse(uint32_t reqId, const LinkRequest *reqInfo, co
uint16_t port;
if (!LaneGetP2PReuseMac(reqInfo->peerNetworkId, ipAddr, MAX_SOCKET_ADDR_LEN, &port)) {
LNN_LOGE(LNN_LANE, "p2p resue get addr failed");
return SOFTBUS_LANE_NOT_FIND;
return SOFTBUS_LANE_NOT_FOUND;
}
linkInfo.linkInfo.wlan.connInfo.protocol = LNN_PROTOCOL_IP;
linkInfo.linkInfo.wlan.connInfo.port = port;
@ -823,7 +823,7 @@ static int32_t GetWlanLinkedAttribute(int32_t *channel, bool *is5GBand, bool *is
int32_t ret = LnnGetWlanLinkedInfo(&info);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "LnnGetWlanLinkedInfo fail, ret=%{public}d", ret);
return SOFTBUS_ERR;
return ret;
}
*isConnected = info.isConnected;
*is5GBand = (info.band != 1);
@ -862,13 +862,13 @@ static ProtocolType LnnLaneSelectProtocol(LnnNetIfType ifType, const char *netWo
int ret = LnnGetRemoteNodeInfoById(netWorkId, CATEGORY_NETWORK_ID, &remoteNodeInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "no such network id");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
const NodeInfo *localNode = LnnGetLocalNodeInfo();
if (localNode == NULL) {
LNN_LOGE(LNN_LANE, "get local node info failed!");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
struct SelectProtocolReq req = {
@ -900,7 +900,7 @@ static ProtocolType LnnLaneSelectProtocol(LnnNetIfType ifType, const char *netWo
static int32_t FillWlanLinkInfo(ProtocolType protocol, const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
{
int32_t ret = SOFTBUS_LANE_DETECT_FAIL;
int32_t ret = SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
int32_t port = 0;
if (reqInfo->transType == LANE_T_MSG) {
ret = LnnGetRemoteNumInfo(reqInfo->peerNetworkId, NUM_KEY_PROXY_PORT, &port);
@ -983,7 +983,7 @@ static int32_t LaneLinkOfWlan(uint32_t reqId, const LinkRequest *reqInfo, const
ret = LaneDetectReliability(reqId, &linkInfo, callback);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane detect reliability fail, laneReqId=%{public}u", reqId);
return ret;
return ErrCodeFilter(ret, SOFTBUS_LANE_DETECT_FAIL);
}
return SOFTBUS_OK;
}
@ -1101,7 +1101,7 @@ int32_t InitLaneLink(void)
LaneInitP2pAddrList();
if (SoftBusMutexInit(&g_laneResource.lock, NULL) != SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "lane resource mutex init fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
ListInit(&g_laneResource.list);
g_laneResource.cnt = 0;

View File

@ -152,7 +152,7 @@ static int32_t GetPreferAuthConnInfo(const char *networkId, AuthConnInfo *connIn
LNN_LOGE(LNN_LANE, "get peer uuid fail");
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
int32_t ret = AuthGetP2pConnInfo(uuid, connInfo, isMetaAuth);
int32_t ret = AuthGetHmlConnInfo(uuid, connInfo, isMetaAuth);
if (ret != SOFTBUS_OK) {
ret = AuthGetPreferConnInfo(uuid, connInfo, isMetaAuth);
}
@ -242,7 +242,7 @@ static int32_t GetP2pLinkDownParam(uint32_t authRequestId, uint32_t p2pRequestId
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "request item not found, authRequestId=%{public}u", authRequestId);
return SOFTBUS_LANE_NOT_FIND;
return SOFTBUS_LANE_NOT_FOUND;
}
static void DelP2pLinkedByAuthReqId(uint32_t authRequestId)
@ -466,7 +466,7 @@ static int32_t GetP2pLinkReqByReqId(AsyncResultType type, uint32_t requestId, P2
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "P2pLinkReq item not found, type=%{public}d, requestId=%{public}u.", type, requestId);
return SOFTBUS_LANE_NOT_FIND;
return SOFTBUS_LANE_NOT_FOUND;
}
static int32_t DelP2pLinkReqByReqId(AsyncResultType type, uint32_t requestId)
@ -524,7 +524,7 @@ static int32_t GetGuideInfo(uint32_t laneReqId, LaneLinkType linkType, WdGuideIn
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "guideInfo not found, laneReqId=%{public}u, linkType=%{public}d.", laneReqId, linkType);
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
static void DelGuideInfoItem(uint32_t laneReqId, LaneLinkType linkType)
@ -645,7 +645,8 @@ static int32_t CreateWDLinkInfo(uint32_t p2pRequestId, const struct WifiDirectLi
} else {
linkInfo->type = LANE_P2P;
}
linkInfo->linkInfo.p2p.bw = LANE_BW_RANDOM;
LNN_LOGI(LNN_LANE, "bandWidth=%{public}d", link->bandWidth);
linkInfo->linkInfo.p2p.bw = (LaneBandwidth)link->bandWidth;
if (strcpy_s(linkInfo->linkInfo.p2p.connInfo.localIp, IP_LEN, link->localIp) != EOK ||
strcpy_s(linkInfo->linkInfo.p2p.connInfo.peerIp, IP_LEN, link->remoteIp) != EOK) {
LNN_LOGE(LNN_LANE, "strcpy localIp fail");
@ -730,7 +731,7 @@ static void HandleGuideChannelRetry(uint32_t laneReqId, LaneLinkType linkType, i
return;
FAIL:
DelGuideInfoItem(laneReqId, linkType);
callback.OnLaneLinkFail(laneReqId, reason, linkType);
callback.OnLaneLinkFail(laneReqId, ErrCodeFilter(reason, SOFTBUS_LANE_GUIDE_BUILD_FAIL), linkType);
}
static void HandleGuideChannelAsyncFail(AsyncResultType type, uint32_t requestId, int32_t reason)
@ -857,7 +858,7 @@ static int32_t AddP2pLinkReqItem(AsyncResultType type, uint32_t requestId, uint3
LaneType laneType;
if (ParseLaneTypeByLaneReqId(laneReqId, &laneType) != SOFTBUS_OK) {
SoftBusFree(item);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
if (laneType == LANE_TYPE_TRANS && UpdateP2pLinkReq(item, laneReqId) != SOFTBUS_OK) {
SoftBusFree(item);
@ -1046,6 +1047,7 @@ static int32_t GetAuthTriggerLinkReqParamByAuthHandle(uint32_t authRequestId, ui
LNN_LOGE(LNN_LANE, "get remote wifidirect addr fail");
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->pid = item->laneRequestInfo.pid;
int32_t ret = strcpy_s(wifiDirectInfo->remoteNetworkId, sizeof(wifiDirectInfo->remoteNetworkId),
item->laneRequestInfo.networkId);
@ -1164,6 +1166,17 @@ static int32_t OpenBleTriggerToConn(const LinkRequest *request, uint32_t laneReq
}
struct WifiDirectConnectInfo wifiDirectInfo;
(void)memset_s(&wifiDirectInfo, sizeof(wifiDirectInfo), 0, sizeof(wifiDirectInfo));
TransReqInfo reqInfo;
(void)memset_s(&reqInfo, sizeof(TransReqInfo), 0, sizeof(TransReqInfo));
if (GetTransReqInfoByLaneReqId(laneReqId, &reqInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get TransReqInfo fail, laneReqId=%{public}d", laneReqId);
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
if (reqInfo.isWithQos) {
wifiDirectInfo.bandWidth = reqInfo.allocInfo.qosRequire.minBW;
} else {
wifiDirectInfo.bandWidth = 0;
}
wifiDirectInfo.requestId = GetWifiDirectManager()->getRequestId();
int32_t ret = AddP2pLinkReqItem(ASYNC_RESULT_P2P, wifiDirectInfo.requestId, laneReqId, request, callback);
LNN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, LNN_LANE, "add new connect node failed");
@ -1410,12 +1423,12 @@ static int32_t LnnSelectDirectLink(uint32_t laneReqId, LaneLinkType linkType)
(void)memset_s(&guideInfo, sizeof(WdGuideInfo), -1, sizeof(WdGuideInfo));
if (GetGuideInfo(laneReqId, linkType, &guideInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get guide channel info fail.");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
if (guideInfo.guideIdx >= guideInfo.guideNum) {
LNN_LOGE(LNN_LANE, "all guide channel type have been tried.");
DelGuideInfoItem(laneReqId, linkType);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
WdGuideType guideType = guideInfo.guideList[guideInfo.guideIdx];
LNN_LOGI(LNN_LANE, "build guide channel, laneReqId=%{public}u, guideType=%{public}d.", laneReqId, guideType);
@ -1439,7 +1452,7 @@ static int32_t SelectGuideChannel(const LinkRequest *request, uint32_t laneReqId
if (GetGuideChannelInfo(request->peerNetworkId, request->linkType, guideChannelList,
&guideChannelNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add guideChannelList faile, LinkType=%{public}d", request->linkType);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_NO_AVAILABLE_LINK;
}
for (uint32_t i = 0; i < guideChannelNum; i++) {
LNN_LOGI(LNN_LANE, "add guideChannelType=%{public}d", guideChannelList[i]);
@ -1460,7 +1473,7 @@ static int32_t SelectGuideChannel(const LinkRequest *request, uint32_t laneReqId
guideInfo.guideIdx = 0;
if (AddGuideInfoItem(&guideInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add guide channel info fail.");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
BuildGuideChannel(laneReqId, request->linkType);
return SOFTBUS_OK;
@ -1497,7 +1510,7 @@ static int32_t InitGuideChannelLooper(void)
g_guideChannelHandler.looper = GetLooper(LOOP_TYPE_LNN);
if (g_guideChannelHandler.looper == NULL) {
LNN_LOGE(LNN_LANE, "init p2pLooper fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
return SOFTBUS_OK;
}
@ -1506,11 +1519,11 @@ static int32_t LnnP2pInit(void)
{
if (InitGuideChannelLooper() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "init looper fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexInit(&g_p2pLinkMutex, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "mutex init fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
g_p2pLinkList = (ListNode *)SoftBusMalloc(sizeof(ListNode));
if (g_p2pLinkList == NULL) {
@ -1652,4 +1665,4 @@ void LnnDestroyP2p(void)
g_guideInfoList = NULL;
LinkUnlock();
(void)SoftBusMutexDestroy(&g_p2pLinkMutex);
}
}

View File

@ -172,7 +172,7 @@ static int32_t FindLaneBusinessInfoByLinkInfo(const LaneLinkInfo *laneLinkInfo,
char localUdid[UDID_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
uint64_t laneId = GenerateLaneId(localUdid, laneLinkInfo->peerUdid, laneLinkInfo->type);
if (LaneListenerLock() != SOFTBUS_OK) {
@ -226,7 +226,7 @@ static int32_t FindLaneListenerInfoByLaneType(LaneType type, LaneListenerInfo *l
if (item == NULL) {
LaneListenerUnlock();
LNN_LOGE(LNN_LANE, "lane listener is not exist");
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
laneListenerInfo->type = item->type;
laneListenerInfo->listener = item->listener;
@ -244,9 +244,10 @@ int32_t LaneLinkupNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInfo)
(void)memset_s(&profile, sizeof(LaneProfile), 0, sizeof(LaneProfile));
LaneConnInfo laneConnInfo;
(void)memset_s(&laneConnInfo, sizeof(LaneConnInfo), 0, sizeof(LaneConnInfo));
if (LaneInfoProcess(laneLinkInfo, &laneConnInfo, &profile) != SOFTBUS_OK) {
int32_t ret = LaneInfoProcess(laneLinkInfo, &laneConnInfo, &profile);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "laneInfo proc fail");
return SOFTBUS_ERR;
return ret;
}
LaneListenerInfo listenerList[LANE_TYPE_BUTT];
(void)memset_s(listenerList, sizeof(listenerList), 0, sizeof(listenerList));
@ -263,7 +264,7 @@ int32_t LaneLinkupNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInfo)
char localUdid[UDID_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
uint64_t laneId = GenerateLaneId(localUdid, peerUdid, laneLinkInfo->type);
for (uint32_t i = 0; i < LANE_TYPE_BUTT; i++) {
@ -329,7 +330,7 @@ static int32_t GetStateNotifyInfo(const char *peerIp, const char *peerUuid, Lane
laneLinkInfo->type = (strncmp(peerIp, HML_IP_PREFIX, HML_IP_PREFIX_LEN) == 0) ? LANE_HML : LANE_P2P;
if (strncpy_s(laneLinkInfo->linkInfo.p2p.connInfo.peerIp, IP_LEN, peerIp, IP_LEN) != EOK) {
LNN_LOGE(LNN_STATE, "strncpy peerIp fail");
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
NodeInfo nodeInfo;
@ -339,11 +340,11 @@ static int32_t GetStateNotifyInfo(const char *peerIp, const char *peerUuid, Lane
Anonymize(peerUuid, &anonyUuid);
LNN_LOGE(LNN_STATE, "get remote nodeinfo failed, peerUuid=%{public}s", anonyUuid);
AnonymizeFree(anonyUuid);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (strncpy_s(laneLinkInfo->peerUdid, UDID_BUF_LEN, nodeInfo.deviceInfo.deviceUdid, UDID_BUF_LEN) != EOK) {
LNN_LOGE(LNN_STATE, "copy peerudid fail");
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
return SOFTBUS_OK;
}
@ -529,7 +530,7 @@ int32_t InitLaneListener(void)
{
if (SoftBusMutexInit(&g_laneStateListenerMutex, NULL) != SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "g_laneStateListenerMutex init fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
ListInit(&g_laneListenerList);

View File

@ -107,7 +107,7 @@ static int32_t AddLaneModel(uint64_t laneId, uint32_t profileId, LaneProfile *la
{
if (ModelLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
LaneModel *laneModel = (LaneModel *)LnnReadData(&g_profileMap, profileId);
if (laneModel != NULL) {
@ -121,12 +121,13 @@ static int32_t AddLaneModel(uint64_t laneId, uint32_t profileId, LaneProfile *la
if (memcpy_s(&newModel.profile, sizeof(LaneProfile), laneProfile, sizeof(LaneProfile)) != EOK) {
LNN_LOGE(LNN_LANE, "addLaneModel memcpy fail");
ModelUnlock();
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (LnnCreateData(&g_profileMap, profileId, &newModel, sizeof(LaneModel)) != SOFTBUS_OK) {
int32_t ret = LnnCreateData(&g_profileMap, profileId, &newModel, sizeof(LaneModel));
if (ret != SOFTBUS_OK) {
ModelUnlock();
return SOFTBUS_ERR;
return ret;
}
laneModel = (LaneModel *)LnnReadData(&g_profileMap, profileId);
if (laneModel != NULL) {
@ -141,7 +142,7 @@ int32_t BindLaneIdToProfile(uint64_t laneId, LaneProfile *profile)
{
if (profile == NULL) {
LNN_LOGE(LNN_LANE, "profile is null");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LaneGenerateParam param;
param.linkType = profile->linkType;
@ -149,8 +150,9 @@ int32_t BindLaneIdToProfile(uint64_t laneId, LaneProfile *profile)
param.priority = profile->priority;
uint32_t profileId = GenerateLaneProfileId(&param);
profile->serialNum = profileId;
if (AddLaneModel(laneId, profileId, profile) != SOFTBUS_OK) {
return SOFTBUS_ERR;
int32_t ret = AddLaneModel(laneId, profileId, profile);
if (ret != SOFTBUS_OK) {
return ret;
}
return SOFTBUS_OK;
}
@ -177,21 +179,21 @@ int32_t GetLaneProfile(uint32_t profileId, LaneProfile *profile)
{
if (profile == NULL) {
LNN_LOGE(LNN_LANE, "profile is null");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (ModelLock() != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
LaneModel *laneModel = (LaneModel *)LnnReadData(&g_profileMap, profileId);
if (laneModel == NULL) {
ModelUnlock();
LNN_LOGE(LNN_LANE, "read laneModel fail");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (memcpy_s(profile, sizeof(LaneProfile), &laneModel->profile, sizeof(LaneProfile)) != EOK) {
LNN_LOGE(LNN_LANE, "profile memcpy fail");
ModelUnlock();
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
ModelUnlock();
return SOFTBUS_OK;
@ -201,24 +203,24 @@ int32_t GetLaneIdList(uint32_t profileId, uint64_t **laneIdList, uint32_t *listS
{
if (ModelLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
LaneModel *laneModel = (LaneModel *)LnnReadData(&g_profileMap, profileId);
if (laneModel == NULL) {
ModelUnlock();
LNN_LOGE(LNN_LANE, "read laneModel fail");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (laneModel->ref == 0) {
LNN_LOGE(LNN_LANE, "ref count is zero");
ModelUnlock();
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
*laneIdList = (uint64_t *)SoftBusCalloc(sizeof(uint64_t) * laneModel->ref);
if (*laneIdList == NULL) {
LNN_LOGE(LNN_LANE, "laneIdList malloc fail");
ModelUnlock();
return SOFTBUS_ERR;
return SOFTBUS_MALLOC_ERR;
}
uint32_t cnt = 0;
LaneIdInfo *infoNode = NULL;
@ -248,7 +250,7 @@ int32_t InitLaneModel(void)
LnnMapInit(&g_profileMap);
if (SoftBusMutexInit(&g_laneModelMutex, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "laneModel mutex init fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
return SOFTBUS_OK;
}

View File

@ -103,7 +103,7 @@ static int32_t GetLaneResource(LaneTransType transType, LaneLinkType *optLink, u
break;
default:
LNN_LOGE(LNN_LANE, "lane type is not supported, transType=%{public}d", transType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
*linkNum = 0;
if (memcpy_s(optLink, optLinkMaxNum * sizeof(LaneLinkType), defaultLink, sizeof(defaultLink)) != EOK) {
@ -134,7 +134,7 @@ static int32_t BrLinkState(const char *networkId)
uint32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (!(local & (1 << BIT_BR))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%{public}u", local);
@ -153,7 +153,7 @@ static int32_t BleLinkState(const char *networkId)
uint32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (!(local & (1 << BIT_BLE))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%{public}u", local);
@ -176,16 +176,16 @@ static int32_t WlanLinkState(const char *networkId)
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get remote node info fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) && !LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
LNN_LOGE(LNN_LANE, "peer node not wifi online");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
uint32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (!(local & (1 << BIT_WIFI))) {
LNN_LOGE(LNN_LANE, "local wifi close, local=%{public}u", local);
@ -206,13 +206,14 @@ static int32_t P2pLinkState(const char *networkId)
LNN_LOGE(LNN_LANE, "not support wifi direct");
return SOFTBUS_P2P_NOT_SUPPORT;
}
if (!SoftBusIsWifiActive()) {
if (SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_INACTIVE ||
SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_DEACTIVATING) {
return SOFTBUS_WIFI_OFF;
}
uint32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (((local & (1 << BIT_WIFI_P2P)) == 0) || ((remote & (1 << BIT_WIFI_P2P)) == 0)) {
LNN_LOGE(LNN_LANE, "p2p capa disable, local=%{public}u, remote=%{public}u", local, remote);
@ -233,7 +234,8 @@ static int32_t HmlLinkState(const char *networkId)
LNN_LOGE(LNN_LANE, "not support wifi direct");
return SOFTBUS_HML_NOT_SUPPORT;
}
if (!SoftBusIsWifiActive()) {
if (SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_INACTIVE ||
SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_DEACTIVATING) {
return SOFTBUS_WIFI_OFF;
}
@ -246,7 +248,7 @@ static int32_t HmlLinkState(const char *networkId)
bool result = false;
if (LnnGetRemoteBoolInfo(networkId, BOOL_KEY_TLV_NEGOTIATION, &result) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get remote feature failed");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (!result) {
@ -278,11 +280,11 @@ static int32_t IsValidLaneLink(const char *networkId, LaneLinkType linkType)
}
if (!g_linkState[linkType].available) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%{public}d", linkType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (g_linkState[linkType].QueryLink == NULL) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%{public}d", linkType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
return g_linkState[linkType].QueryLink(networkId);
}
@ -307,13 +309,13 @@ static int32_t QueryByRequireLink(const LaneQueryInfo *queryInfo, const QosInfo
bool isHighBand = false;
if (!isHighRequire(qosInfo, &isHighBand)) {
LNN_LOGE(LNN_LANE, "set param failed");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
int32_t ret = SOFTBUS_ERR;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, isHighBand) != SOFTBUS_OK) {
int32_t ret = GetLaneResource(queryInfo->transType, optLink, &linkNum, isHighBand);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return ret;
}
@ -332,11 +334,11 @@ static int32_t QueryByDefaultLink(const LaneQueryInfo *queryInfo)
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, false) != SOFTBUS_OK) {
int32_t ret = GetLaneResource(queryInfo->transType, optLink, &linkNum, false);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return SOFTBUS_ERR;
return ret;
}
int32_t ret = SOFTBUS_ERR;
for (uint32_t i = 0; i < linkNum; i++) {
ret = IsValidLaneLink(queryInfo->networkId, optLink[i]);
if (ret == SOFTBUS_OK) {
@ -353,14 +355,12 @@ int32_t QueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo
LNN_LOGE(LNN_LANE, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_ERR;
if (qosInfo->minBW > 0) {
LNN_LOGI(LNN_LANE, "Query lane by prefer linklist, transType=%{public}d, minBW=%{public}d",
queryInfo->transType, qosInfo->minBW);
ret = QueryByRequireLink(queryInfo, qosInfo);
return QueryByRequireLink(queryInfo, qosInfo);
} else {
LNN_LOGI(LNN_LANE, "Query lane by default linklist, transType=%{public}d", queryInfo->transType);
ret = QueryByDefaultLink(queryInfo);
return QueryByDefaultLink(queryInfo);
}
return ret;
}

View File

@ -68,7 +68,7 @@ static int32_t GetSameLaneDetectInfo(LaneDetectInfo *infoItem)
}
}
SoftBusMutexUnlock(&g_laneDetectList.lock);
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
static int32_t ClientConnectTcp(LaneDetectInfo *infoItem)
@ -88,7 +88,7 @@ static int32_t ClientConnectTcp(LaneDetectInfo *infoItem)
}
int32_t fd = ConnOpenClientSocket(&option, BIND_ADDR_ALL, true);
if (fd < 0) {
return SOFTBUS_CONN_FAIL;
return SOFTBUS_TCPCONNECTION_SOCKET_ERR;
}
return fd;
}
@ -128,7 +128,7 @@ static int32_t GetLaneDetectInfoByWlanFd(uint32_t fd, LaneDetectInfo *infoItem)
}
}
SoftBusMutexUnlock(&g_laneDetectList.lock);
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
static int32_t AddLaneTriggerAndTimeOut(int32_t fd, uint32_t detectId)
@ -284,7 +284,7 @@ static int32_t LaneDetectOnDataEvent(ListenerModule module, int32_t events, int3
LNN_LOGE(LNN_LANE, "wlan detect info not found by fd=%{public}d", fd);
(void)DelTrigger(LANE, fd, WRITE_TRIGGER);
ConnShutdownSocket(fd);
return SOFTBUS_LANE_NOT_FIND;
return SOFTBUS_LANE_NOT_FOUND;
}
LNN_LOGI(LNN_LANE, "wlan connect success, detectId=%{public}u, fd=%{public}d", requestItem.laneDetectId, fd);
(void)DelTrigger(LANE, fd, WRITE_TRIGGER);
@ -313,7 +313,7 @@ int32_t LaneDetectReliability(uint32_t laneReqId, const LaneLinkInfo *laneInfo,
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGI(LNN_LANE, "lane detect start, linktype=%{public}d, laneReqId=%{public}u", laneInfo->type, laneReqId);
int32_t result = SOFTBUS_ERR;
int32_t result = SOFTBUS_LANE_DETECT_FAIL;
switch (laneInfo->type) {
case LANE_WLAN_2P4G:
case LANE_WLAN_5G:
@ -338,7 +338,7 @@ void NotifyDetectTimeout(uint32_t detectId)
LIST_FOR_EACH_ENTRY_SAFE(item, next, &detectInfoList, LaneDetectInfo, node) {
LNN_LOGI(LNN_LANE, "Detect time out, link=%{public}d, laneReqId=%{public}u, detectId=%{public}u",
item->link.type, item->laneReqId, item->laneDetectId);
item->cb.OnLaneLinkFail(item->laneReqId, SOFTBUS_LANE_DETECT_FAIL, item->link.type);
item->cb.OnLaneLinkFail(item->laneReqId, SOFTBUS_LANE_DETECT_TIMEOUT, item->link.type);
ListDelete(&item->node);
SoftBusFree(item);
}
@ -350,12 +350,13 @@ int32_t InitLaneReliability(void)
.onConnectEvent = LaneDetectOnConnectEvent,
.onDataEvent = LaneDetectOnDataEvent,
};
if (StartBaseClient(LANE, &listener) != SOFTBUS_OK) {
int32_t ret = StartBaseClient(LANE, &listener);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "listening fail, moudle=%{public}d ", LANE);
return SOFTBUS_ERR;
return ret;
}
if (SoftBusMutexInit(&g_laneDetectList.lock, NULL) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
ListInit(&g_laneDetectList.list);
g_laneDetectList.cnt = 0;

View File

@ -33,7 +33,7 @@ void LnnDeinitScore(void)
int32_t LnnGetWlanLinkedInfo(LnnWlanLinkedInfo *info)
{
(void)info;
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
int32_t LnnGetCurrChannelScore(int32_t channelId)

View File

@ -58,6 +58,7 @@ static void GetMsgDefaultLink(LaneLinkType *linkList, uint32_t *listNum)
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
linkList[(*listNum)++] = LANE_COC_DIRECT;
}
static void GetBytesDefaultLink(LaneLinkType *linkList, uint32_t *listNum)
@ -66,6 +67,7 @@ static void GetBytesDefaultLink(LaneLinkType *linkList, uint32_t *listNum)
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
linkList[(*listNum)++] = LANE_COC_DIRECT;
}
static int32_t GetLaneDefaultLink(LaneTransType transType, LaneLinkType *optLink, uint32_t *linkNum)
@ -91,7 +93,7 @@ static int32_t GetLaneDefaultLink(LaneTransType transType, LaneLinkType *optLink
break;
default:
LNN_LOGE(LNN_LANE, "lane type is not supported. type=%{public}d", transType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
*linkNum = 0;
if (memcpy_s(optLink, optLinkMaxNum * sizeof(LaneLinkType), defaultLink, sizeof(defaultLink)) != EOK) {
@ -250,10 +252,9 @@ static int32_t AdjustLanePriority(const char *networkId, const LaneSelectParam *
{
int32_t resListScore[LANE_LINK_TYPE_BUTT];
(void)memset_s(resListScore, sizeof(resListScore), INVALID_LINK, sizeof(resListScore));
int32_t ret = GetListScore(networkId, request->expectedBw, resList, resListScore, resNum);
if (ret != SOFTBUS_OK) {
if (GetListScore(networkId, request->expectedBw, resList, resListScore, resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get linklist score fail");
return ret;
return SOFTBUS_LANE_GET_LINK_SCORE_ERR;
}
if ((resListScore[LANE_WLAN_2P4G] == INVALID_LINK && resListScore[LANE_WLAN_5G] == INVALID_LINK) ||
(resListScore[LANE_P2P] == INVALID_LINK && resListScore[LANE_HML] == INVALID_LINK)) {
@ -379,7 +380,7 @@ static int32_t AddRecommendLinkType(LanePreferredLinkList *setRecommendLinkList,
{
if ((*linkNum) < 0 || (*linkNum) >= LANE_LINK_TYPE_BUTT) {
LNN_LOGE(LNN_LANE, "enum out of bounds");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
setRecommendLinkList->linkType[(*linkNum)++] = linkType;
setRecommendLinkList->linkTypeNum = *linkNum;
@ -419,7 +420,7 @@ int32_t SelectExpectLaneByParameter(LanePreferredLinkList *setRecommendLinkList)
LNN_LOGI(LNN_LANE, "ble_only = on");
return SOFTBUS_OK;
} else {
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
}
@ -509,8 +510,7 @@ static bool IsAuthReuseWifiDirect(const char *networkId, LaneLinkType linkType)
}
}
int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *request,
LanePreferredLinkList *recommendList)
int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *request, LanePreferredLinkList *recommendList)
{
if ((networkId == NULL) || (request == NULL) || (recommendList == NULL)) {
return SOFTBUS_INVALID_PARAM;

View File

@ -394,7 +394,7 @@ static int32_t TriggerLinkWithQos(uint32_t laneReqId, const LaneAllocInfo *alloc
linkNode->linkList = recommendLinkList;
linkNode->pid = allocInfo->pid;
linkNode->networkDelegate = allocInfo->extendInfo.networkDelegate;
linkNode->p2pErrCode = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
linkNode->p2pErrCode = SOFTBUS_LANE_BUILD_LINK_TIMEOUT;
linkNode->acceptableProtocols = allocInfo->acceptableProtocols;
linkNode->startTime = SoftBusGetSysTimeMs();
linkNode->restTime = allocInfo->qosRequire.maxLaneLatency != 0 ?
@ -456,16 +456,18 @@ static int32_t AllocValidLane(uint32_t laneReqId, uint64_t allocLaneId, const La
recommendLinkList->linkTypeNum = 0;
if (SelectExpectLaneByParameter(recommendLinkList) == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "SelectExpectLaneByParameter succ, laneReqId=%{public}u", laneReqId);
} else if (SelectExpectLanesByQos((const char *)allocInfo->networkId, &selectParam,
recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "selectExpectLanesByQos fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_LANE_SELECT_FAIL;
} else {
int32_t ret = SelectExpectLanesByQos((const char *)allocInfo->networkId, &selectParam, recommendLinkList);
if (ret != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "selectExpectLanesByQos fail, laneReqId=%{public}u", laneReqId);
return ErrCodeFilter(ret, SOFTBUS_LANE_SELECT_FAIL);
}
}
if (recommendLinkList->linkTypeNum == 0) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "no available link resources, laneReqId=%{public}u", laneReqId);
return SOFTBUS_LANE_SELECT_FAIL;
return SOFTBUS_LANE_NO_AVAILABLE_LINK;
}
for (uint32_t i = 0; i < recommendLinkList->linkTypeNum; i++) {
LNN_LOGI(LNN_LANE, "expect linklist nums=%{public}u, priority=%{public}u, link=%{public}u",
@ -475,7 +477,7 @@ static int32_t AllocValidLane(uint32_t laneReqId, uint64_t allocLaneId, const La
if (ret != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "trigger link fail, laneReqId=%{public}u", laneReqId);
return ret;
return ErrCodeFilter(ret, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
}
return SOFTBUS_OK;
}
@ -708,11 +710,11 @@ static int32_t FreeLaneLink(uint32_t laneReqId, uint64_t laneId)
LaneResource resourceItem;
(void)memset_s(&resourceItem, sizeof(LaneResource), 0, sizeof(LaneResource));
if (FindLaneResourceByLaneId(laneId, &resourceItem) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LANE_RESOURCE_NOT_FOUND;
}
char networkId[NETWORK_ID_BUF_LEN] = { 0 };
if (LnnGetNetworkIdByUdid(resourceItem.link.peerUdid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
DestroyLink(networkId, laneReqId, resourceItem.link.type);
DelLaneResourceByLaneId(laneId, false);
@ -723,7 +725,7 @@ static int32_t CancelLane(uint32_t laneReqId)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
TransReqInfo *item = NULL;
TransReqInfo *next = NULL;
@ -871,10 +873,10 @@ static void NotifyLaneAllocFail(uint32_t laneReqId, int32_t reason)
}
LNN_LOGE(LNN_LANE, "Notify laneAlloc fail, laneReqId=%{public}u, reason=%{public}d", laneReqId, reason);
if (reqInfo.isWithQos) {
reqInfo.listener.onLaneAllocFail(laneReqId, reason);
reqInfo.listener.onLaneAllocFail(laneReqId, ErrCodeFilter(reason, SOFTBUS_LANE_BUILD_LINK_FAIL));
FreeLaneReqId(laneReqId);
} else {
reqInfo.extraInfo.listener.onLaneRequestFail(laneReqId, reason);
reqInfo.extraInfo.listener.onLaneRequestFail(laneReqId, ErrCodeFilter(reason, SOFTBUS_LANE_BUILD_LINK_FAIL));
}
DeleteRequestNode(laneReqId);
}
@ -944,7 +946,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
Unlock();
return;
}
int32_t ret = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
int32_t ret = SOFTBUS_LANE_BUILD_LINK_FAIL;
do {
ret = CreateLinkRequestNode(nodeInfo, &requestInfo);
if (ret != SOFTBUS_OK) {
@ -962,6 +964,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
return;
}
} while (false);
ret = ErrCodeFilter(ret, SOFTBUS_LANE_BUILD_LINK_FAIL);
linkCb.OnLaneLinkFail(laneReqId, ret, requestInfo.linkType);
}
@ -1174,7 +1177,13 @@ static void LaneLinkSuccess(SoftBusMessage *msg)
}
}
static bool IsNeedNotifyFail(uint32_t laneReqId, int32_t reason, int32_t *failReason)
static bool IsWifiDirectErrCode(const int32_t errCode)
{
return ((errCode >= ERROR_WIFI_DIRECT_END && errCode <= ERROR_BASE) ||
(errCode >= V1_ERROR_END && errCode <= V1_ERROR_START)) ? true : false;
}
static bool IsNeedNotifyFail(uint32_t laneReqId, int32_t reason, LaneLinkType failLinkType, int32_t *failReason)
{
bool notifyFail = false;
if (Lock() != SOFTBUS_OK) {
@ -1187,9 +1196,8 @@ static bool IsNeedNotifyFail(uint32_t laneReqId, int32_t reason, int32_t *failRe
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
return true;
}
if ((reason >= ERROR_WIFI_DIRECT_END && reason <= ERROR_BASE) ||
(reason >= V1_ERROR_END && reason <= V1_ERROR_START) || nodeInfo->linkRetryIdx == 1) {
nodeInfo->p2pErrCode = reason;
if (IsWifiDirectErrCode(reason) || failLinkType == nodeInfo->linkList->linkType[0]) {
nodeInfo->p2pErrCode = IsWifiDirectErrCode(nodeInfo->p2pErrCode) ? nodeInfo->p2pErrCode : reason;
}
*failReason = nodeInfo->p2pErrCode;
uint64_t costTime = SoftBusGetSysTimeMs() - nodeInfo->startTime;
@ -1275,7 +1283,7 @@ static void LaneLinkFail(SoftBusMessage *msg)
RemoveLinkTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLinkSucc(laneReqId);
DeleteLaneLinkNode(laneReqId);
} else if (IsNeedNotifyFail(laneReqId, reason, &failReason)) {
} else if (IsNeedNotifyFail(laneReqId, reason, linkType, &failReason)) {
RemoveLinkTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLaneAllocFail(laneReqId, failReason);
DeleteLaneLinkNode(laneReqId);
@ -1410,7 +1418,7 @@ static int32_t InitLooper(void)
g_laneLoopHandler.looper = GetLooper(LOOP_TYPE_LNN);
if (g_laneLoopHandler.looper == NULL) {
LNN_LOGE(LNN_LANE, "transLane init looper fail");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
return SOFTBUS_OK;
}
@ -1490,7 +1498,7 @@ int32_t GetTransReqInfoByLaneReqId(uint32_t laneReqId, TransReqInfo *reqInfo)
}
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
TransReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_requestList->list, TransReqInfo, node) {
@ -1498,14 +1506,14 @@ int32_t GetTransReqInfoByLaneReqId(uint32_t laneReqId, TransReqInfo *reqInfo)
if (memcpy_s(reqInfo, sizeof(TransReqInfo), item, sizeof(TransReqInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy TransReqInfo fail");
Unlock();
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
Unlock();
return SOFTBUS_OK;
}
}
Unlock();
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FOUND;
}
int32_t PostDetectTimeoutMessage(uint32_t detectId, uint64_t delayMillis)
@ -1518,13 +1526,13 @@ static int32_t RemoveDetectTimeout(const SoftBusMessage *msg, void *data)
{
uint32_t *detectId = (uint32_t *)data;
if (msg->what != MSG_TYPE_LANE_DETECT_TIMEOUT) {
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (msg->arg1 == *detectId) {
LNN_LOGE(LNN_LANE, "remove detect timeout message success. detectId=%{public}u", *detectId);
return SOFTBUS_OK;
}
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
void RemoveDetectTimeoutMessage(uint32_t detectId)
@ -1565,10 +1573,11 @@ int32_t PostLaneStateChangeMessage(LaneState state, const char *peerUdid, const
LNN_LOGE(LNN_LANE, "memcpy laneLinkInfo fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_STATE_CHANGE, 0, 0, stateNotifyInfo, 0) != SOFTBUS_OK) {
int32_t ret = LnnLanePostMsgToHandler(MSG_TYPE_LANE_STATE_CHANGE, 0, 0, stateNotifyInfo, 0);
if (ret != SOFTBUS_OK) {
SoftBusFree(stateNotifyInfo);
LNN_LOGE(LNN_LANE, "post lane state change msg fail");
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -1580,7 +1589,7 @@ static int32_t RemoveDelayDestroy(const SoftBusMessage *msg, void *data)
LNN_LOGI(LNN_LANE, "remove delay destroy message succ, laneId=%{public}" PRIu64 "", *laneId);
return SOFTBUS_OK;
}
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
void RemoveDelayDestroyMessage(uint64_t laneId)

View File

@ -60,6 +60,14 @@ typedef enum {
STATE_NUM_MAX,
} ConnFsmStateIndex;
typedef enum {
ONLINE_TYPE_INVALID = 1,
ONLINE_TYPE_WIFI = 2,
ONLINE_TYPE_BLE = 3,
ONLINE_TYPE_BLE_THREE_STATE = 4,
ONLINE_TYPE_BR = 5,
} OnlineType;
#define JOIN_LNN_TIMEOUT_LEN (15 * 1000UL)
#define LEAVE_LNN_TIMEOUT_LEN (5 * 1000UL)
@ -410,6 +418,32 @@ static void SetLnnConnNodeInfo(
connInfo->nodeInfo->deviceInfo.deviceUdid, connInfo->addr.type, relation[connInfo->addr.type], true);
}
static int32_t DfxRecordLnnOnlineType(const NodeInfo *info)
{
if (info == NULL) {
return ONLINE_TYPE_INVALID;
}
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_WIFI)) {
return ONLINE_TYPE_WIFI;
}
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_BR)) {
return ONLINE_TYPE_BR;
}
if (LnnHasDiscoveryType(info, DISCOVERY_TYPE_BLE)) {
uint32_t local;
if (LnnGetLocalNumU32Info(NUM_KEY_NET_CAP, &local) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get cap fail");
return ONLINE_TYPE_INVALID;
}
if (((local & (1 << BIT_BR)) == 0) || (info->netCapacity & (1 << BIT_BR)) == 0) {
return ONLINE_TYPE_BLE_THREE_STATE;
} else {
return ONLINE_TYPE_BLE;
}
}
return ONLINE_TYPE_INVALID;
}
static void GetLnnOnlineType(bool isNeedConnect, ConnectionAddrType type, int32_t *lnnType)
{
if (!isNeedConnect && type == CONNECTION_ADDR_BLE) {
@ -586,6 +620,15 @@ static void DfxReportOnlineEvent(LnnConntionInfo *connInfo, int32_t reason, LnnE
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_END, extra);
}
static void SetOnlineType(int32_t reason, NodeInfo *nodeInfo, LnnEventExtra extra)
{
if (reason == SOFTBUS_OK) {
extra.onlineType = DfxRecordLnnOnlineType(nodeInfo);
} else {
extra.onlineType = ONLINE_TYPE_INVALID;
}
}
static void DfxRecordLnnAddOnlineNodeEnd(LnnConntionInfo *connInfo, int32_t onlineNum, int32_t lnnType, int32_t reason)
{
LnnEventExtra extra = { 0 };
@ -606,6 +649,7 @@ static void DfxRecordLnnAddOnlineNodeEnd(LnnConntionInfo *connInfo, int32_t onli
DfxReportOnlineEvent(connInfo, reason, extra);
return;
}
SetOnlineType(reason, connInfo->nodeInfo, extra);
char netWorkId[NETWORK_ID_BUF_LEN] = { 0 };
if (strcpy_s(netWorkId, NETWORK_ID_BUF_LEN, connInfo->nodeInfo->networkId) != EOK) {
LNN_LOGE(LNN_BUILDER, "strcpy_s netWorkId fail");

View File

@ -193,31 +193,33 @@ static int32_t ConvertNodeInfoToCloudSyncInfo(CloudSyncInfo *cloudSyncInfo, cons
static int32_t DBCipherInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName, const char *value, size_t valueLength)
{
if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_KEY) == 0) {
if (memcpy_s((char *)cacheInfo->cipherInfo.key, SESSION_KEY_LENGTH, value, SESSION_KEY_LENGTH) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:memcpy_s cipherkey fail");
return SOFTBUS_MEM_ERR;
if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_KEY) == 0 && valueLength < SESSION_KEY_STR_LEN) {
if (ConvertHexStringToBytes((unsigned char *)cacheInfo->cipherInfo.key, SESSION_KEY_LENGTH, value,
valueLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert cipherkey to bytes fail. cipher info sync to cache fail");
return SOFTBUS_KV_CONVERT_BYTES_FAILED;
}
} else if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_IV) == 0) {
if (memcpy_s((char *)cacheInfo->cipherInfo.iv, BROADCAST_IV_LEN, value, BROADCAST_IV_LEN) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:memcpy_s cipheriv fail");
return SOFTBUS_MEM_ERR;
} else if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_IV) == 0 && valueLength < BROADCAST_IV_STR_LEN) {
if (ConvertHexStringToBytes((unsigned char *)cacheInfo->cipherInfo.iv, BROADCAST_IV_LEN, value,
valueLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert cipheriv to bytes fail. cipher info sync to cache fail");
return SOFTBUS_KV_CONVERT_BYTES_FAILED;
}
} else if (strcmp(fieldName, DEVICE_INFO_JSON_KEY_TABLE_MIAN) == 0 && valueLength < BLE_BROADCAST_IV_LEN + 1) {
LNN_LOGI(LNN_BUILDER, "cipher table mian info no need update into nodeinfo");
LNN_LOGD(LNN_BUILDER, "cipher table mian info no need update into nodeinfo");
} else if (strcmp(fieldName, DEVICE_INFO_JSON_KEY_TOTAL_LIFE) == 0) {
LNN_LOGI(LNN_BUILDER, "cipher total life info no need update into nodeinfo");
LNN_LOGD(LNN_BUILDER, "cipher total life info no need update into nodeinfo");
} else if (strcmp(fieldName, DEVICE_INFO_JSON_KEY_TIMESTAMP_BEGIN) == 0) {
LNN_LOGI(LNN_BUILDER, "cipher timestamp begin info no need update into nodeinfo");
LNN_LOGD(LNN_BUILDER, "cipher timestamp begin info no need update into nodeinfo");
} else if (strcmp(fieldName, DEVICE_INFO_JSON_KEY_CURRENT_INDEX) == 0) {
LNN_LOGI(LNN_BUILDER, "cipher current index info no need update into nodeinfo");
LNN_LOGD(LNN_BUILDER, "cipher current index info no need update into nodeinfo");
} else if (strcmp(fieldName, DEVICE_INFO_DISTRIBUTED_SWITCH) == 0) {
LNN_LOGI(LNN_BUILDER, "distributed switch info no need update into nodeinfo");
LNN_LOGD(LNN_BUILDER, "distributed switch info no need update into nodeinfo");
} else {
LNN_LOGE(LNN_BUILDER, "fail:cipher info %{public}s valuelength over range", fieldName);
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGI(LNN_BUILDER, "success.");
LNN_LOGD(LNN_BUILDER, "success.");
return SOFTBUS_OK;
}
@ -228,6 +230,7 @@ static int32_t DBDeviceNameInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName,
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s devicename fail");
return SOFTBUS_STRCPY_ERR;
}
LNN_LOGI(LNN_BUILDER, "success. deviceName=%{public}s", cacheInfo->deviceInfo.deviceName);
} else if (strcmp(fieldName, DEVICE_INFO_UNIFIED_DEVICE_NAME) == 0 && valueLength < DEVICE_NAME_BUF_LEN) {
if (strcpy_s(cacheInfo->deviceInfo.unifiedName, DEVICE_NAME_BUF_LEN, value) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s unifiedname fail");
@ -257,6 +260,10 @@ static int32_t DBDeviceBasicInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s deviceUdid fail");
return SOFTBUS_STRCPY_ERR;
}
char *anonyUdid = NULL;
Anonymize(cacheInfo->deviceInfo.deviceUdid, &anonyUdid);
LNN_LOGI(LNN_BUILDER, "success, udid=%{public}s", anonyUdid);
AnonymizeFree(anonyUdid);
} else if (strcmp(fieldName, DEVICE_INFO_DEVICE_TYPE) == 0) {
cacheInfo->deviceInfo.deviceTypeId = atoi(value);
} else if (strcmp(fieldName, DEVICE_INFO_OS_TYPE) == 0) {
@ -271,11 +278,15 @@ static int32_t DBDeviceBasicInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s uuid fail");
return SOFTBUS_STRCPY_ERR;
}
char *anoyUuid = NULL;
Anonymize(cacheInfo->uuid, &anoyUuid);
LNN_LOGI(LNN_BUILDER, "success, uuid=%{public}s", anoyUuid);
AnonymizeFree(anoyUuid);
} else if (DBDeviceNameInfoSyncToCache(cacheInfo, fieldName, value, valueLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:DB device name info sync to cache fail");
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_BUILDER, "success.");
LNN_LOGD(LNN_BUILDER, "success.");
return SOFTBUS_OK;
}
@ -318,16 +329,17 @@ static int32_t DBConnectMacInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName,
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s p2pMac fail");
return SOFTBUS_STRCPY_ERR;
}
} else if (strcmp(fieldName, DEVICE_INFO_DEVICE_IRK) == 0) {
if (memcpy_s((char *)cacheInfo->rpaInfo.peerIrk, LFINDER_IRK_LEN, value, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:memcpy_s peerIrk fail");
return SOFTBUS_MEM_ERR;
} else if (strcmp(fieldName, DEVICE_INFO_DEVICE_IRK) == 0 && valueLength < LFINDER_IRK_STR_LEN) {
if (ConvertHexStringToBytes((unsigned char *)cacheInfo->rpaInfo.peerIrk, LFINDER_IRK_LEN, value,
valueLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert peerIrk to bytes fail. rpa info sync to cache fail");
return SOFTBUS_KV_CONVERT_BYTES_FAILED;
}
} else if (strcmp(fieldName, DEVICE_INFO_DEVICE_PUB_MAC) == 0) {
if (memcpy_s((char *)cacheInfo->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN, value, LFINDER_MAC_ADDR_LEN) !=
EOK) {
LNN_LOGE(LNN_BUILDER, "fail:memcpy_s publicAddress fail");
return SOFTBUS_MEM_ERR;
} else if (strcmp(fieldName, DEVICE_INFO_DEVICE_PUB_MAC) == 0 && valueLength < LFINDER_MAC_ADDR_STR_LEN) {
if (ConvertHexStringToBytes((unsigned char *)cacheInfo->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN, value,
valueLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert publicAddress to bytes fail. rpa info sync to cache fail");
return SOFTBUS_KV_CONVERT_BYTES_FAILED;
}
} else {
LNN_LOGE(LNN_BUILDER, "fail:connect info %{public}s valuelength over range", fieldName);
@ -543,7 +555,7 @@ static int32_t SplitString(char splitKey[SPLIT_KEY_NUM][SPLIT_MAX_LEN], char spl
static int32_t HandleDBAddChangeInternal(const char *key, const char *value, NodeInfo *cacheInfo)
{
LNN_LOGI(LNN_BUILDER, "enter.");
LNN_LOGD(LNN_BUILDER, "enter.");
if (key == NULL || value == NULL) {
LNN_LOGE(LNN_BUILDER, "fail:invalid param");
return SOFTBUS_INVALID_PARAM;
@ -581,6 +593,7 @@ static int32_t HandleDBAddChangeInternal(const char *key, const char *value, Nod
LNN_LOGE(LNN_BUILDER, "fail:DB data change batch sync to cache fail");
return SOFTBUS_ERR;
}
cacheInfo->localStateVersion = localCaheInfo.stateVersion;
return SOFTBUS_OK;
}
@ -689,11 +702,14 @@ static int32_t HandleDBUpdateInternal(
newInfo.localStateVersion = localStateVersion;
if (LnnSaveRemoteDeviceInfo(&newInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:Lnn save remote device info fail");
(void)memset_s(&newInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
}
(void)memset_s(&newInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
}
if (cacheInfo.stateVersion > stateVersion && stateVersion != 1) {
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
}
LNN_LOGI(LNN_BUILDER, "update peer stateVersion=%{public}d->%{public}d, localStateVersion=%{public}d->%{public}d",
@ -702,6 +718,7 @@ static int32_t HandleDBUpdateInternal(
UpdateInfoToLedger(&cacheInfo, deviceUdid, fieldName, trueValue);
cacheInfo.localStateVersion = localStateVersion;
(void)LnnSaveRemoteDeviceInfo(&cacheInfo);
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
}
@ -725,12 +742,6 @@ static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
LNN_LOGE(LNN_BUILDER, "get info from splitkey error");
return SOFTBUS_ERR;
}
char trueValue[SPLIT_MAX_LEN] = { 0 };
if (strcpy_s(trueValue, SPLIT_MAX_LEN, splitValue[0]) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s true value fail.");
return SOFTBUS_STRCPY_ERR;
}
NodeInfo localCaheInfo = { 0 };
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local cache node info fail");
@ -739,9 +750,15 @@ static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
if (strcmp(deviceUdid, localCaheInfo.deviceInfo.deviceUdid) == 0) {
return SOFTBUS_OK;
}
char trueValue[SPLIT_MAX_LEN] = { 0 };
if (strcpy_s(trueValue, SPLIT_MAX_LEN, splitValue[0]) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s true value fail.");
return SOFTBUS_STRCPY_ERR;
}
if (HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, stateVersion, localCaheInfo.stateVersion) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "handle DB update change internal fail");
(void)memset_s(trueValue, strlen(trueValue), 0, strlen(trueValue));
return SOFTBUS_ERR;
}
char *anonyDeviceUdid = NULL;
@ -753,11 +770,13 @@ static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
anonyDeviceUdid, fieldName, anonyTrueValue, stateVersion);
AnonymizeFree(anonyDeviceUdid);
AnonymizeFree(anonyTrueValue);
(void)memset_s(trueValue, strlen(trueValue), 0, strlen(trueValue));
return SOFTBUS_OK;
}
static int32_t HandleDBDeleteChangeInternal(const char *key, const char *value)
{
(void)value;
if (key == NULL) {
LNN_LOGE(LNN_BUILDER, "fail:invalid param key");
return SOFTBUS_INVALID_PARAM;
@ -825,17 +844,37 @@ int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int3
if (HandleDBAddChangeInternal(key[i], value[i], &cacheInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:handle db data add change internal fail");
FreeKeyAndValue(key, value, keySize);
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
}
}
FreeKeyAndValue(key, value, keySize);
(void)LnnSaveRemoteDeviceInfo(&cacheInfo);
LNN_LOGI(LNN_BUILDER, "success. stateVersion=%{public}d", cacheInfo.stateVersion);
if (LnnUpdateDistributedNodeInfo(&cacheInfo, cacheInfo.deviceInfo.deviceUdid) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:Cache info add sync to Ledger fail");
char udidHash[UDID_HASH_HEX_LEN + 1] = { 0 };
if (LnnGenerateHexStringHash((const unsigned char *)cacheInfo.deviceInfo.deviceUdid, udidHash, UDID_HASH_HEX_LEN) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "Generate UDID HexStringHash fail");
return SOFTBUS_ERR;
}
NodeInfo oldCacheInfo = { 0 };
if (LnnRetrieveDeviceInfo(udidHash, &oldCacheInfo) == SOFTBUS_OK &&
oldCacheInfo.stateVersion > cacheInfo.stateVersion) {
LNN_LOGE(LNN_BUILDER,
"fail: sync info is older, oldCacheInfo.stateVersion=%{public}d, cacheInfo.stateVersion=%{public}d",
oldCacheInfo.stateVersion, cacheInfo.stateVersion);
return SOFTBUS_ERR;
}
(void)LnnSaveRemoteDeviceInfo(&cacheInfo);
char *anonyUdid = NULL;
Anonymize(cacheInfo.deviceInfo.deviceUdid, &anonyUdid);
LNN_LOGI(LNN_BUILDER, "success. udid=%{public}s, stateVersion=%{public}d, localStateVersion=%{public}d,", anonyUdid,
cacheInfo.stateVersion, cacheInfo.localStateVersion);
AnonymizeFree(anonyUdid);
if (LnnUpdateDistributedNodeInfo(&cacheInfo, cacheInfo.deviceInfo.deviceUdid) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:Cache info add sync to Ledger fail");
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
}
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
}
@ -865,7 +904,7 @@ int32_t LnnDBDataChangeSyncToCache(const char *key, const char *value, ChangeTyp
LNN_LOGE(LNN_BUILDER, "changeType is invalid");
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGI(LNN_BUILDER, "success.");
LNN_LOGD(LNN_BUILDER, "success.");
return SOFTBUS_OK;
}
@ -939,7 +978,7 @@ int32_t LnnLedgerAllDataSyncToDB(const NodeInfo *info)
LNN_LOGE(LNN_BUILDER, "fail:data batch sync to DB fail, errorcode=%{public}d", ret);
return ret;
}
LNN_LOGI(LNN_BUILDER, "success. stateVersion=%{public}d", syncInfo.stateVersion);
LNN_LOGI(LNN_BUILDER, "sync all data to db success. stateVersion=%{public}d", syncInfo.stateVersion);
ret = LnnCloudSync(dbId);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:data batch cloud sync fail, errorcode=%{public}d", ret);
@ -984,6 +1023,7 @@ void LnnInitCloudSyncModule(void)
LNN_LOGE(LNN_BUILDER, "Lnn Init Cloud Sync Module fail");
return;
}
LnnRegisterDataChangeListener(dbId, APPID, strlen(APPID), STOREID, strlen(STOREID));
g_dbId = dbId;
}
@ -991,6 +1031,7 @@ void LnnDeInitCloudSyncModule(void)
{
LNN_LOGI(LNN_BUILDER, "enter.");
int32_t dbId = g_dbId;
LnnUnRegisterDataChangeListener(dbId);
if (LnnDestroyKvAdapter(dbId) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "DeInit Cloud Sync module fail");
}

View File

@ -117,8 +117,8 @@ static void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, con
}
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGI(LNN_BUILDER, "recv device name changed. msg=%{public}s, networkId=%{public}s",
(char *)msg, anonyNetworkId);
LNN_LOGI(LNN_BUILDER, "recv device name changed. deviceName=%{public}s, networkId=%{public}s",
deviceName, anonyNetworkId);
AnonymizeFree(anonyNetworkId);
if (LnnConvertDlId(networkId, CATEGORY_NETWORK_ID, CATEGORY_UDID, udid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "convert networkId to udid fail");

View File

@ -627,6 +627,12 @@ static void DfxRecordLnnAuthStart(const AuthConnInfo *connInfo, const JoinLnnMsg
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH, extra);
}
static bool IsConnFsmFlagOnline(LnnConnectionFsm *connFsm, bool needReportFailure)
{
connFsm->connInfo.flag |= (needReportFailure ? LNN_CONN_INFO_FLAG_JOIN_REQUEST : LNN_CONN_INFO_FLAG_JOIN_AUTO);
return (connFsm->connInfo.flag & LNN_CONN_INFO_FLAG_ONLINE) != 0;
}
static int32_t TrySendJoinLNNRequest(const JoinLnnMsgPara *para, bool needReportFailure, bool isShort)
{
int32_t ret = SOFTBUS_OK;
@ -647,8 +653,7 @@ static int32_t TrySendJoinLNNRequest(const JoinLnnMsgPara *para, bool needReport
SoftBusFree((void *)para);
return ret;
}
connFsm->connInfo.flag |= (needReportFailure ? LNN_CONN_INFO_FLAG_JOIN_REQUEST : LNN_CONN_INFO_FLAG_JOIN_AUTO);
if ((connFsm->connInfo.flag & LNN_CONN_INFO_FLAG_ONLINE) != 0) {
if (IsConnFsmFlagOnline(connFsm, needReportFailure)) {
if (connFsm->connInfo.addr.type == CONNECTION_ADDR_WLAN || connFsm->connInfo.addr.type == CONNECTION_ADDR_ETH) {
char uuid[UUID_BUF_LEN] = {0};
(void)LnnConvertDlId(connFsm->connInfo.peerNetworkId, CATEGORY_NETWORK_ID, CATEGORY_UUID,
@ -2229,20 +2234,26 @@ static void UpdateLocalNetCapability(void)
}
int btState = SoftBusGetBtState();
if (btState == BLE_ENABLE) {
LNN_LOGI(LNN_INIT, "bluetooth state is on");
(void)LnnSetNetCapability(&netCapability, BIT_BR);
LNN_LOGI(LNN_INIT, "ble state is on");
(void)LnnSetNetCapability(&netCapability, BIT_BLE);
} else if (btState == BLE_DISABLE) {
LNN_LOGI(LNN_INIT, "bluetooth state is off");
(void)LnnClearNetCapability(&netCapability, BIT_BR);
LNN_LOGI(LNN_INIT, "ble state is off");
(void)LnnClearNetCapability(&netCapability, BIT_BLE);
}
int brState = SoftBusGetBrState();
if (brState == BR_ENABLE) {
LNN_LOGI(LNN_INIT, "br state is on");
(void)LnnSetNetCapability(&netCapability, BIT_BR);
} else if (brState == BR_DISABLE) {
LNN_LOGI(LNN_INIT, "br state is off");
(void)LnnClearNetCapability(&netCapability, BIT_BR);
}
bool isWifiActive = SoftBusIsWifiActive();
LNN_LOGI(LNN_INIT, "wifi state: %s", isWifiActive ? "true" : "false");
if (!isWifiActive) {
(void)LnnClearNetCapability(&netCapability, BIT_WIFI);
(void)LnnClearNetCapability(&netCapability, BIT_WIFI_P2P);
(void)LnnClearNetCapability(&netCapability, BIT_WIFI_24G);
(void)LnnClearNetCapability(&netCapability, BIT_WIFI_5G);
} else {
@ -2259,6 +2270,11 @@ static void UpdateLocalNetCapability(void)
}
}
if (SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_INACTIVE ||
SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_DEACTIVATING) {
(void)LnnClearNetCapability(&netCapability, BIT_WIFI_P2P);
}
if (LnnSetLocalNumInfo(NUM_KEY_NET_CAP, netCapability) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "set cap to local ledger fail");
}

View File

@ -23,12 +23,15 @@
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_deviceinfo_to_profile.h"
#include "lnn_feature_capability.h"
#include "lnn_heartbeat_strategy.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_net_capability.h"
#include "lnn_node_info.h"
#include "lnn_net_builder.h"
#include "lnn_sync_info_manager.h"
#include "softbus_adapter_bt_common.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_wifi_api_adapter.h"
@ -41,7 +44,6 @@
#define BITLEN 4
#define STRING_INTERFACE_BUFFER_LEN 16
static SoftBusWifiState g_wifiState = SOFTBUS_WIFI_UNKNOWN;
static bool g_isWifiDirectSupported = false;
static bool g_isApCoexistSupported = false;
static bool g_isWifiEnable = false;
@ -167,6 +169,27 @@ static bool IsNeedToSend(NodeInfo *nodeInfo, uint32_t type)
}
}
static void DoSendCapability(NodeInfo nodeInfo, NodeBasicInfo netInfo, uint8_t *msg, uint32_t netCapability,
uint32_t type)
{
int32_t ret = SOFTBUS_OK;
if (IsNeedToSend(&nodeInfo, type)) {
if (!IsFeatureSupport(nodeInfo.feature, BIT_CLOUD_SYNC_DEVICE_INFO)) {
ret = LnnSendSyncInfoMsg(LNN_INFO_TYPE_CAPABILITY, netInfo.networkId, msg, MSG_LEN, NULL);
} else {
if (type == ((1 << (uint32_t)DISCOVERY_TYPE_BLE) | (1 << (uint32_t)DISCOVERY_TYPE_BR))) {
ret = LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_SINGLE, false);
} else {
ret = LnnSendSyncInfoMsg(LNN_INFO_TYPE_CAPABILITY, netInfo.networkId, msg, MSG_LEN, NULL);
}
}
LNN_LOGE(LNN_BUILDER,
"sync cap info ret=%{public}d, deviceName=%{public}s.", ret, netInfo.deviceName);
} else if ((type & (1 << (uint32_t)DISCOVERY_TYPE_WIFI)) != 0 && !LnnHasCapability(netCapability, BIT_BLE)) {
LnnSendP2pSyncInfoMsg(netInfo.networkId, netCapability);
}
}
static void SendNetCapabilityToRemote(uint32_t netCapability, uint32_t type)
{
uint8_t *msg = ConvertCapabilityToMsg(netCapability);
@ -194,13 +217,7 @@ static void SendNetCapabilityToRemote(uint32_t netCapability, uint32_t type)
if (LnnGetRemoteNodeInfoById(netInfo[i].networkId, CATEGORY_NETWORK_ID, &nodeInfo) != SOFTBUS_OK) {
continue;
}
if (IsNeedToSend(&nodeInfo, type)) {
int32_t ret = LnnSendSyncInfoMsg(LNN_INFO_TYPE_CAPABILITY, netInfo[i].networkId, msg, MSG_LEN, NULL);
LNN_LOGE(LNN_BUILDER,
"sync network info ret=%{public}d, deviceName=%{public}s.", ret, netInfo[i].deviceName);
} else if ((type & (1 << (uint32_t)DISCOVERY_TYPE_WIFI)) != 0 && !LnnHasCapability(netCapability, BIT_BLE)) {
LnnSendP2pSyncInfoMsg(netInfo[i].networkId, netCapability);
}
DoSendCapability(nodeInfo, netInfo[i], msg, netCapability, type);
}
SoftBusFree(netInfo);
SoftBusFree(msg);
@ -264,6 +281,16 @@ static void LnnClearNetBandCapability(uint32_t *capability)
}
}
static void LnnSetP2pNetCapability(uint32_t *capability)
{
if (SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_INACTIVE ||
SoftBusGetWifiState() == SOFTBUS_WIFI_STATE_DEACTIVATING) {
(void)LnnClearNetCapability(capability, BIT_WIFI_P2P);
} else {
(void)LnnSetNetCapability(capability, BIT_WIFI_P2P);
}
}
static void GetNetworkCapability(SoftBusWifiState wifiState, uint32_t *capability, bool *needSync)
{
switch (wifiState) {
@ -290,9 +317,7 @@ static void GetNetworkCapability(SoftBusWifiState wifiState, uint32_t *capabilit
g_isWifiEnable = false;
if (!g_isApEnable) {
LnnClearNetworkCapability(capability);
if (!GetWifiDirectManager()->isWifiP2pEnabled()) {
(void)LnnClearNetCapability(capability, BIT_WIFI_P2P);
}
LnnSetP2pNetCapability(capability);
}
*needSync = true;
break;
@ -330,10 +355,6 @@ static void WifiStateEventHandler(const LnnEventBasicInfo *info)
return;
}
LNN_LOGI(LNN_BUILDER, "WifiStateEventHandler WifiState=%{public}d", wifiState);
if (g_wifiState == wifiState) {
return;
}
g_wifiState = wifiState;
bool needSync = false;
GetNetworkCapability(wifiState, &netCapability, &needSync);
WifiStateProcess(netCapability, needSync);
@ -357,10 +378,14 @@ static void BtStateChangeEventHandler(const LnnEventBasicInfo *info)
switch (btState) {
case SOFTBUS_BR_TURN_ON:
(void)LnnSetNetCapability(&netCapability, BIT_BR);
break;
case SOFTBUS_BLE_TURN_ON:
(void)LnnSetNetCapability(&netCapability, BIT_BLE);
break;
case SOFTBUS_BR_TURN_OFF:
(void)LnnClearNetCapability(&netCapability, BIT_BR);
break;
case SOFTBUS_BLE_TURN_OFF:
(void)LnnClearNetCapability(&netCapability, BIT_BLE);
isSend = true;
break;

View File

@ -22,6 +22,7 @@
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_feature_capability.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_secure_storage.h"
@ -163,6 +164,23 @@ static int32_t LnnParseWifiDirectAddrMsg(const char *msg, char *wifiDirectAddr,
return SOFTBUS_OK;
}
static bool IsNeedSyncP2pInfo(const NodeInfo *localInfo, const NodeBasicInfo *info)
{
int32_t osType = 0;
// rk need to sync
if (!IsFeatureSupport(localInfo->feature, BIT_WIFI_DIRECT_TLV_NEGOTIATION)) {
return true;
}
if (LnnGetOsTypeByNetworkId(info->networkId, &osType) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get remote osType fail");
}
if (osType != OH_OS_TYPE) {
LNN_LOGE(LNN_BUILDER, "remote osType is %{public}d, need sync p2pinfo", osType);
return true;
}
return false;
}
static void ProcessSyncP2pInfo(void *para)
{
(void)para;
@ -195,7 +213,8 @@ static void ProcessSyncP2pInfo(void *para)
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_P2P_INFO, info[i].networkId, (uint8_t *)msg, len, NULL) != SOFTBUS_OK) {
if (IsNeedSyncP2pInfo(localInfo, &info[i]) &&
LnnSendSyncInfoMsg(LNN_INFO_TYPE_P2P_INFO, info[i].networkId, (uint8_t *)msg, len, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "sync p2p info fail. deviceName=%{public}s", info[i].deviceName);
}
}
@ -235,7 +254,13 @@ static void ProcessSyncWifiDirectAddr(void *para)
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_WIFI_DIRECT, info[i].networkId, (uint8_t *)msg, len, NULL) != SOFTBUS_OK) {
int32_t osType = 0;
if (LnnGetOsTypeByNetworkId(info[i].networkId, &osType) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get remote osType fail");
}
if (osType != OH_OS_TYPE &&
LnnSendSyncInfoMsg(LNN_INFO_TYPE_WIFI_DIRECT, info[i].networkId, (uint8_t *)msg, len, NULL)
!= SOFTBUS_OK) {
char *anonyNetworkId = NULL;
Anonymize(info[i].networkId, &anonyNetworkId);
LNN_LOGE(LNN_BUILDER, "sync wifidirect addr fail. anonyNetworkId=%{public}s", anonyNetworkId);

View File

@ -25,6 +25,7 @@
#include "common_list.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_feature_capability.h"
#include "lnn_net_builder.h"
#include "lnn_log.h"
#include "message_handler.h"
@ -33,6 +34,7 @@
#include "softbus_adapter_thread.h"
#include "softbus_adapter_timer.h"
#include "softbus_bus_center.h"
#include "softbus_conn_interface.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_transmission_interface.h"
@ -104,8 +106,9 @@ static void ClearSyncChannelInfo(void)
static SyncChannelInfo *FindSyncChannelInfoByNetworkId(const char *networkId)
{
SyncChannelInfo *item = NULL;
SyncChannelInfo *next = NULL;
LIST_FOR_EACH_ENTRY(item, &g_syncInfoManager.channelInfoList, SyncChannelInfo, node) {
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_syncInfoManager.channelInfoList, SyncChannelInfo, node) {
if (strcmp(item->networkId, networkId) == 0) {
return item;
}
@ -116,8 +119,9 @@ static SyncChannelInfo *FindSyncChannelInfoByNetworkId(const char *networkId)
static SyncChannelInfo *FindSyncChannelInfoByChannelId(int32_t channelId)
{
SyncChannelInfo *item = NULL;
SyncChannelInfo *next = NULL;
LIST_FOR_EACH_ENTRY(item, &g_syncInfoManager.channelInfoList, SyncChannelInfo, node) {
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_syncInfoManager.channelInfoList, SyncChannelInfo, node) {
if (item->clientChannelId == channelId || item->serverChannelId == channelId) {
return item;
}
@ -681,6 +685,59 @@ static void OnLnnOnlineStateChange(const LnnEventBasicInfo *info)
}
}
static void OnWifiDirectSyncMsgRecv(AuthHandle authHandle, const AuthTransData *data)
{
LnnSyncInfoType type;
LnnSyncInfoMsgHandler handler;
char networkId[NETWORK_ID_BUF_LEN] = {0};
if (data == NULL) {
LNN_LOGE(LNN_BUILDER, "recv null data, authId=%{public}" PRId64, authHandle.authId);
return;
}
LNN_LOGI(LNN_BUILDER, "recv sync info msg. type=%{public}d, authId=%{public}" PRId64 ", len=%{public}u",
(LnnSyncInfoType)(*(int32_t *)data->data), authHandle.authId, data->len);
if (data->len <= MSG_HEAD_LEN || data->len > MAX_SYNC_INFO_MSG_LEN) {
LNN_LOGE(LNN_BUILDER, "invalid msg. len=%{public}u", data->len);
return;
}
AuthManager *auth = GetAuthManagerByAuthId(authHandle.authId);
if (auth == NULL) {
return;
}
char *anonyUdid = NULL;
Anonymize(auth->udid, &anonyUdid);
LNN_LOGI(LNN_BUILDER, "udid=%{public}s", anonyUdid);
AnonymizeFree(anonyUdid);
if (LnnGetNetworkIdByUdid(auth->udid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "LnnGetNetworkIdByUdid fail");
DelAuthManager(auth, false);
return;
}
DelAuthManager(auth, false);
type = (LnnSyncInfoType)(*(int32_t *)data->data);
if (type < 0 || type >= LNN_INFO_TYPE_COUNT) {
LNN_LOGE(LNN_BUILDER, "received data is exception, type=%{public}d", type);
return;
}
if (SoftBusMutexLock(&g_syncInfoManager.lock) != 0) {
LNN_LOGE(LNN_BUILDER, "sync info lock fail");
return;
}
handler = g_syncInfoManager.handlers[type];
if (handler == NULL) {
(void)SoftBusMutexUnlock(&g_syncInfoManager.lock);
return;
}
(void)SoftBusMutexUnlock(&g_syncInfoManager.lock);
handler(type, networkId, &data->data[MSG_HEAD_LEN], data->len - MSG_HEAD_LEN);
}
static void OnWifiDirectSyncAuthClose(AuthHandle authHandle)
{
LNN_LOGW(LNN_BUILDER, "authId=%{public}" PRId64, authHandle.authId);
}
int32_t LnnInitSyncInfoManager(void)
{
int32_t i;
@ -689,6 +746,15 @@ int32_t LnnInitSyncInfoManager(void)
for (i = 0; i < LNN_INFO_TYPE_COUNT; ++i) {
g_syncInfoManager.handlers[i] = NULL;
}
AuthTransListener wifiDirectSyncCb = {
.onDataReceived = OnWifiDirectSyncMsgRecv,
.onDisconnected = OnWifiDirectSyncAuthClose,
};
if (RegAuthTransListener(MODULE_AUTH_SYNC_INFO, &wifiDirectSyncCb) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "reg auth lister fail");
return SOFTBUS_ERR;
}
if (LnnRegisterEventHandler(LNN_EVENT_NODE_ONLINE_STATE_CHANGED, OnLnnOnlineStateChange) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "reg online lister fail");
return SOFTBUS_ERR;
@ -719,7 +785,8 @@ void LnnDeinitSyncInfoManager(void)
g_syncInfoManager.handlers[i] = NULL;
}
UnregAuthTransListener(MODULE_P2P_NETWORKING_SYNC);
LnnRegisterEventHandler(LNN_EVENT_NODE_ONLINE_STATE_CHANGED, OnLnnOnlineStateChange);
LnnUnregisterEventHandler(LNN_EVENT_NODE_ONLINE_STATE_CHANGED, OnLnnOnlineStateChange);
UnregAuthTransListener(MODULE_AUTH_SYNC_INFO);
ClearSyncChannelInfo();
SoftBusMutexDestroy(&g_syncInfoManager.lock);
}
@ -829,6 +896,7 @@ static int32_t SendSyncInfoByNewChannel(const char *networkId, SyncInfoMsg *msg)
static int32_t TrySendSyncInfoMsg(const char *networkId, SyncInfoMsg *msg)
{
LNN_LOGI(LNN_BUILDER, "begin send sync info");
SyncChannelInfo *info = NULL;
if (SoftBusMutexLock(&g_syncInfoManager.lock) != 0) {
LNN_LOGE(LNN_BUILDER, "send sync info lock fail");
@ -862,21 +930,134 @@ static int32_t TrySendSyncInfoMsg(const char *networkId, SyncInfoMsg *msg)
return SOFTBUS_OK;
}
static int32_t GetWifiDirectAuthByNetworkId(const char *networkId, AuthHandle *authHandle)
{
char uuid[UUID_BUF_LEN] = {0};
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
(void)LnnConvertDlId(networkId, CATEGORY_NETWORK_ID, CATEGORY_UUID, uuid, UUID_BUF_LEN);
AuthDeviceGetLatestIdByUuid(uuid, AUTH_LINK_TYPE_ENHANCED_P2P, authHandle);
if (authHandle->authId != AUTH_INVALID_ID) {
LNN_LOGI(LNN_BUILDER, "find wifidirect authHandle, networkId=%{public}s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_OK;
}
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
static int32_t TrySendSyncInfoMsgByAuth(const char *networkId, SyncInfoMsg *msg)
{
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
AuthHandle authHandle = {
.authId = AUTH_INVALID_ID
};
if (GetWifiDirectAuthByNetworkId(networkId, &authHandle) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get authHandle fail, networkId=%{public}s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
}
AnonymizeFree(anonyNetworkId);
LNN_LOGI(LNN_BUILDER, "send sync info, authId=%{public}" PRId64 ", datalen=%{public}u",
authHandle.authId, msg->dataLen);
AuthTransData dataInfo = {
.module = MODULE_AUTH_SYNC_INFO,
.flag = 0,
.seq = 0,
.len = msg->dataLen,
.data = msg->data,
};
if (AuthPostTransData(authHandle, &dataInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "auth post data fail");
return SOFTBUS_ERR;
}
if (msg->complete != NULL) {
msg->complete((LnnSyncInfoType)(*(uint32_t *)msg->data), networkId, &msg->data[MSG_HEAD_LEN],
msg->dataLen - MSG_HEAD_LEN);
}
return SOFTBUS_OK;
}
static int32_t GetFeatureCap(const char *networkId, uint64_t *local, uint64_t *remote)
{
int32_t ret = LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, local);
if (ret != SOFTBUS_OK || *local == 0) {
LNN_LOGE(LNN_BUILDER, "get local cap fail, ret=%{public}d, local=%{public}" PRIu64, ret, *local);
return SOFTBUS_ERR;
}
ret = LnnGetRemoteNumU64Info(networkId, NUM_KEY_FEATURE_CAPA, remote);
if (ret != SOFTBUS_OK || *remote == 0) {
LNN_LOGE(LNN_BUILDER, "get remote cap fail, ret=%{public}d, remote=%{public}" PRIu64, ret, *remote);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static bool IsNeedSyncByAuth(const char *networkId)
{
uint32_t localCap;
uint32_t remoteCap;
if (LnnGetLocalNumU32Info(NUM_KEY_NET_CAP, &localCap) != SOFTBUS_OK ||
LnnGetRemoteNumU32Info(networkId, NUM_KEY_NET_CAP, &remoteCap) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get cap fail");
return false;
}
if (((localCap & (1 << BIT_WIFI_P2P)) == 0) || ((remoteCap & (1 << BIT_WIFI_P2P)) == 0)) {
LNN_LOGI(LNN_BUILDER, "not support p2p");
return false;
}
uint64_t local = 0;
uint64_t remote = 0;
if (GetFeatureCap(networkId, &local, &remote) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get feature fail");
return false;
}
if ((local & (1 << BIT_BLE_TRIGGER_CONNECTION)) == 0 || (remote & (1 << BIT_BLE_TRIGGER_CONNECTION)) == 0) {
LNN_LOGI(LNN_BUILDER, "not support wifi direct");
return false;
}
NodeInfo node;
(void)memset_s(&node, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &node) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get remote node info fail");
return false;
}
if (LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) || LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
LNN_LOGI(LNN_BUILDER, "peer node is wifi online");
return false;
}
if ((localCap & (1 << BIT_BR)) && (remoteCap & (1 << BIT_BR))) {
LNN_LOGI(LNN_BUILDER, "both support br");
return false;
}
LNN_LOGI(LNN_BUILDER, "need sync info by auth");
return true;
}
int32_t LnnSendSyncInfoMsg(LnnSyncInfoType type, const char *networkId,
const uint8_t *msg, uint32_t len, LnnSyncInfoMsgComplete complete)
{
SyncInfoMsg *syncMsg = NULL;
int32_t rc;
LNN_LOGI(LNN_BUILDER, "send sync info msg for type=%{public}d, len=%{public}d", type, len);
if (type >= LNN_INFO_TYPE_COUNT || networkId == NULL || msg == NULL) {
LNN_LOGE(LNN_BUILDER, "invalid sync info msg param");
return SOFTBUS_INVALID_PARAM;
}
SyncInfoMsg *syncMsg = NULL;
LNN_LOGI(LNN_BUILDER, "send sync info msg. type=%{public}d, len=%{public}d", type, len);
syncMsg = CreateSyncInfoMsg(type, msg, len, complete);
if (syncMsg == NULL) {
return SOFTBUS_ERR;
}
int32_t rc = TrySendSyncInfoMsg(networkId, syncMsg);
if (IsNeedSyncByAuth(networkId)) {
rc = TrySendSyncInfoMsgByAuth(networkId, syncMsg);
if (rc == SOFTBUS_OK) {
SoftBusFree(syncMsg);
return rc;
}
}
rc = TrySendSyncInfoMsg(networkId, syncMsg);
if (rc != SOFTBUS_OK) {
SoftBusFree(syncMsg);
}

View File

@ -39,6 +39,7 @@ typedef enum {
BIT_BLE_DIRECT_CONNECT_CAPABILITY,
BIT_SUPPORT_NEGO_P2P_BY_CHANNEL_CAPABILITY,
BIT_BLE_TRIGGER_CONNECTION,
BIT_SUPPORT_THREE_STATE,
BIT_CLOUD_SYNC_DEVICE_INFO,
BIT_FEATURE_COUNT,
} FeatureCapability;

View File

@ -119,7 +119,7 @@ static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
return false;
}
static void LnnRestoreLocalDeviceInfo()
static void RestoreLocalDeviceInfo(void)
{
LNN_LOGI(LNN_LEDGER, "restore local device info enter");
if (LnnLoadLocalDeviceInfo() != SOFTBUS_OK) {
@ -127,8 +127,9 @@ static void LnnRestoreLocalDeviceInfo()
const NodeInfo *temp = LnnGetLocalNodeInfo();
if (LnnSaveLocalDeviceInfo(temp) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "save local device info fail");
} else {
LNN_LOGI(LNN_LEDGER, "save local device info success");
}
LNN_LOGI(LNN_LEDGER, "save local device info success");
} else {
NodeInfo info;
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
@ -177,7 +178,7 @@ int32_t LnnInitNetLedgerDelay(void)
LNN_LOGE(LNN_LEDGER, "delay init decision db fail");
return SOFTBUS_ERR;
}
LnnRestoreLocalDeviceInfo();
RestoreLocalDeviceInfo();
return SOFTBUS_OK;
}
@ -188,7 +189,7 @@ void LnnDeinitNetLedger(void)
LnnDeinitLocalLedger();
LnnDeinitHuksInterface();
LnnDeinitMetaNodeExtLedger();
LnnDeInitCloudSyncModule();
LnnDeInitCloudSyncModule();
}
static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *info, uint32_t infoLen)
@ -325,25 +326,21 @@ int32_t LnnSetDataLevel(const DataLevel *dataLevel)
LNN_LOGE(LNN_LEDGER, "Set data dynamic level failed");
return SOFTBUS_ERR;
}
uint16_t staticLevel = dataLevel->staticLevel;
if (LnnSetLocalNumU16Info(NUM_KEY_DATA_STATIC_LEVEL, staticLevel) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "Set data static level failed");
return SOFTBUS_ERR;
}
uint32_t switchLevel = dataLevel->switchLevel;
if (LnnSetLocalNumU32Info(NUM_KEY_DATA_SWITCH_LEVEL, switchLevel) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "Set data switch level faield");
return SOFTBUS_ERR;
}
uint16_t switchLength = dataLevel->switchLength;
if (LnnSetLocalNumU16Info(NUM_KEY_DATA_SWITCH_LENGTH, switchLength) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "Set data switch length failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}

View File

@ -3366,8 +3366,11 @@ void LnnRefreshDeviceOnlineStateAndDevIdInfo(const char *pkgName, DeviceInfo *de
(void)pkgName;
RefreshDeviceOnlineStateInfo(device, addtions);
if (device->devId[0] != '\0') {
char *anoyUdidHash = NULL;
Anonymize(device->devId, &anoyUdidHash);
LNN_LOGI(LNN_LEDGER, "device found. medium=%{public}d, udidhash=%{public}s, onlineStatus=%{public}d",
addtions->medium, device->devId, device->isOnline);
addtions->medium, anoyUdidHash, device->isOnline);
AnonymizeFree(anoyUdidHash);
}
}

View File

@ -48,7 +48,7 @@ const NodeInfo *LnnGetLocalNodeInfo(void);
int32_t LnnGetLocalNodeInfoSafe(NodeInfo *info);
int32_t LnnUpdateLocalNetworkId(const void *id);
int32_t LnnUpdateLocalNetworkIdTime(int64_t time);
void LnnUpdateStateVersion();
void LnnUpdateStateVersion(void);
#ifdef __cplusplus
}

View File

@ -62,28 +62,18 @@ typedef struct {
static LocalNetLedger g_localNetLedger;
static void UpdateStateVersionAndStore(void)
static void UpdateStateVersionAndStore(InfoKey key)
{
int32_t ret;
g_localNetLedger.localInfo.stateVersion++;
if (g_localNetLedger.localInfo.stateVersion > MAX_STATE_VERSION) {
g_localNetLedger.localInfo.stateVersion = 1;
}
LNN_LOGI(LNN_LEDGER, "local stateVersion=%{public}d",
LNN_LOGI(LNN_LEDGER, "key=%{public}d changed, update local stateVersion=%{public}d", key,
g_localNetLedger.localInfo.stateVersion);
if ((ret = LnnSaveLocalDeviceInfo(&g_localNetLedger.localInfo)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "update local store fail");
}
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return;
}
char value[STATE_VERSION_VALUE_LENGTH] = {0};
(void)sprintf_s(value, STATE_VERSION_VALUE_LENGTH, "%d", g_localNetLedger.localInfo.stateVersion);
if (LnnLedgerDataChangeSyncToDB(DEVICE_INFO_STATE_VERSION, value, strlen(value)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger state version change sync to cloud failed");
}
}
static int32_t LlGetNodeSoftBusVersion(void *buf, uint32_t len)
@ -327,31 +317,33 @@ static int32_t LocalUpdateNodeAccountId(const void *buf)
int64_t accountId = 0;
if (LnnGetAccountIdFromLocalCache(&accountId) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "get accountid info from cache fail");
LNN_LOGE(LNN_LEDGER, "get accountId info from cache fail");
}
if (accountId == *((int64_t *)buf) && *((int64_t *)buf) != 0) {
LNN_LOGI(LNN_LEDGER, "no new accountid login");
LNN_LOGI(LNN_LEDGER, "no new accountId login");
info->accountId = *((int64_t *)buf);
return SOFTBUS_OK;
}
if (info->accountId == 0) {
if (*((int64_t *)buf) == 0) {
LNN_LOGI(LNN_LEDGER, "no accountid login, default is 0");
LNN_LOGI(LNN_LEDGER, "no accountId login, default is 0");
return SOFTBUS_OK;
}
LNN_LOGI(LNN_LEDGER, "accountid login");
LNN_LOGI(LNN_LEDGER, "accountId login");
info->accountId = *((int64_t *)buf);
info->stateVersion++;
UpdateStateVersionAndStore(NUM_KEY_ACCOUNT_LONG);
return SOFTBUS_OK;
}
if (*((int64_t *)buf) == 0) {
LNN_LOGI(LNN_LEDGER, "accountid logout");
LNN_LOGI(LNN_LEDGER, "accountId logout");
info->accountId = *((int64_t *)buf);
LnnSaveLocalDeviceInfo(info);
return SOFTBUS_OK;
}
LNN_LOGI(LNN_LEDGER, "accountId changed, accountId=%{public}" PRId64 "->%{public}" PRId64, info->accountId,
*((int64_t *)buf));
info->accountId = *((int64_t *)buf);
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(NUM_KEY_ACCOUNT_LONG);
return SOFTBUS_OK;
}
@ -1041,7 +1033,7 @@ static int32_t UpdateLocalDeviceName(const void *name)
LNN_LOGE(LNN_LEDGER, "set device name fail");
return SOFTBUS_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(STRING_KEY_DEV_NAME);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
@ -1065,7 +1057,7 @@ static int32_t UpdateUnifiedName(const void *name)
DEVICE_NAME_BUF_LEN, (char *)name) != EOK) {
return SOFTBUS_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(STRING_KEY_DEV_UNIFIED_NAME);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
@ -1089,7 +1081,7 @@ static int32_t UpdateUnifiedDefaultName(const void *name)
DEVICE_NAME_BUF_LEN, (char *)name) != EOK) {
return SOFTBUS_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(STRING_KEY_DEV_UNIFIED_DEFAULT_NAME);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
@ -1113,7 +1105,7 @@ static int32_t UpdateNickName(const void *name)
DEVICE_NAME_BUF_LEN, (char *)name) != EOK) {
return SOFTBUS_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(STRING_KEY_DEV_NICK_NAME);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
@ -1133,7 +1125,7 @@ int32_t LnnUpdateLocalNetworkIdTime(int64_t time)
return SOFTBUS_LOCK_ERR;
}
g_localNetLedger.localInfo.networkIdTimestamp = time;
LNN_LOGE(LNN_LEDGER, "update local networkId timeStamp=%{public}" PRId64, time);
LNN_LOGI(LNN_LEDGER, "update local networkId timeStamp=%{public}" PRId64, time);
SoftBusMutexUnlock(&g_localNetLedger.lock);
return SOFTBUS_OK;
}
@ -1148,7 +1140,7 @@ static int32_t UpdateLocalNetworkId(const void *id)
g_localNetLedger.localInfo.networkIdTimestamp = SoftBusGetSysTimeMs();
LNN_LOGI(LNN_LEDGER, "networkId change, reset networkId=%{public}s, networkIdTimestamp=%{public}" PRId64,
anonyNetworkId, g_localNetLedger.localInfo.networkIdTimestamp);
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(STRING_KEY_NETWORKID);
AnonymizeFree(anonyNetworkId);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
@ -1405,15 +1397,30 @@ int32_t LlUpdateNodeAddr(const void *addr)
int32_t LnnUpdateLocalNetworkId(const void *id)
{
if (SoftBusMutexLock(&g_localNetLedger.lock) != 0) {
LNN_LOGE(LNN_LEDGER, "lock mutex fail");
return SOFTBUS_LOCK_ERR;
}
if (ModifyId(g_localNetLedger.localInfo.networkId, NETWORK_ID_BUF_LEN, (char *)id) != SOFTBUS_OK) {
SoftBusMutexUnlock(&g_localNetLedger.lock);
return SOFTBUS_ERR;
}
SoftBusMutexUnlock(&g_localNetLedger.lock);
return SOFTBUS_OK;
}
void LnnUpdateStateVersion()
void LnnUpdateStateVersion(void)
{
return UpdateStateVersionAndStore();
UpdateStateVersionAndStore(INFO_KEY_MAX);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return;
}
char value[STATE_VERSION_VALUE_LENGTH] = { 0 };
(void)sprintf_s(value, STATE_VERSION_VALUE_LENGTH, "%d", g_localNetLedger.localInfo.stateVersion);
if (LnnLedgerDataChangeSyncToDB(DEVICE_INFO_STATE_VERSION, value, strlen(value)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger state version change sync to cloud failed");
}
}
static int32_t LlGetStaticCapLen(void *buf, uint32_t len)
@ -1457,7 +1464,7 @@ static int32_t LlUpdateDeviceSecurityLevel(const void *buf)
return SOFTBUS_OK;
}
int32_t LlUpdateStaticCapability(const void *staticCap)
static int32_t LlUpdateStaticCapability(const void *staticCap)
{
if (staticCap == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
@ -1467,7 +1474,7 @@ int32_t LlUpdateStaticCapability(const void *staticCap)
return LnnSetStaticCapability(info, (uint8_t *)staticCap, info->staticCapLen);
}
int32_t LlGetStaticCapability(void *buf, uint32_t len)
static int32_t LlGetStaticCapability(void *buf, uint32_t len)
{
if (buf == NULL || len > STATIC_CAP_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
@ -1481,7 +1488,7 @@ int32_t LlGetStaticCapability(void *buf, uint32_t len)
return SOFTBUS_OK;
}
int32_t LlGetUdidHash(void *buf, uint32_t len)
static int32_t LlGetUdidHash(void *buf, uint32_t len)
{
if (buf == NULL || len < UDID_HASH_LEN) {
LNN_LOGE(LNN_LEDGER, "invalid param");
@ -1595,18 +1602,21 @@ static int32_t UpdateLocalCipherInfoKey(const void *id)
LNN_LOGE(LNN_LEDGER, "memcpy cipherInfo.key fail");
return SOFTBUS_MEM_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(BYTE_KEY_BROADCAST_CIPHER_KEY);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
}
char value[SESSION_KEY_LENGTH + 1] = {0};
for (int32_t i = 0; i < SESSION_KEY_LENGTH; i++) {
value[i] = (char)(g_localNetLedger.localInfo.cipherInfo.key[i]);
char value[SESSION_KEY_STR_LEN] = { 0 };
if (ConvertBytesToHexString(value, SESSION_KEY_STR_LEN,
g_localNetLedger.localInfo.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert cipher key to string fail.");
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
if (LnnLedgerDataChangeSyncToDB(DEVICE_INFO_BROADCAST_CIPHER_KEY, value, strlen(value)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger cipher key change sync to cloud failed");
}
(void)memset_s(value, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
return SOFTBUS_OK;
}
@ -1620,18 +1630,21 @@ static int32_t UpdateLocalCipherInfoIv(const void *id)
LNN_LOGE(LNN_LEDGER, "memcpy cipherInfo.iv fail");
return SOFTBUS_MEM_ERR;
}
UpdateStateVersionAndStore();
UpdateStateVersionAndStore(BYTE_KEY_BROADCAST_CIPHER_IV);
if (g_localNetLedger.localInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need update to cloud");
return SOFTBUS_OK;
}
char value[BROADCAST_IV_LEN + 1] = {0};
for (int32_t i = 0; i < BROADCAST_IV_LEN; i++) {
value[i] = (char)(g_localNetLedger.localInfo.cipherInfo.iv[i]);
char value[BROADCAST_IV_STR_LEN] = { 0 };
if (ConvertBytesToHexString(value, BROADCAST_IV_STR_LEN,
g_localNetLedger.localInfo.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "convert cipher iv to string fail.");
return SOFTBUS_KV_CONVERT_STRING_FAILED;
}
if (LnnLedgerDataChangeSyncToDB(DEVICE_INFO_BROADCAST_CIPHER_IV, value, strlen(value)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger cipher iv change sync to cloud failed");
}
(void)memset_s(value, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
return SOFTBUS_OK;
}

View File

@ -53,6 +53,7 @@ static LnnDeinitEventMonitorImpl g_monitorImplDeinit[MONITOR_IMPL_MAX_TYPE] = {
LnnDeinitBtStateMonitorImpl,
LnnDeinitProductMonitorImpl,
LnnDeinitDriverMonitorImpl,
LnnDeInitNetlinkMonitorImpl,
};
int32_t LnnInitEventMonitor(void)

View File

@ -237,7 +237,7 @@ void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info);
void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type);
void LnnNotifyMigrate(bool isOnline, NodeBasicInfo *info);
void LnnNotifyWlanStateChangeEvent(SoftBusWifiState state);
void LnnNotifyWlanStateChangeEvent(void *state);
void LnnNotifyScreenStateChangeEvent(SoftBusScreenState state);
void LnnNotifyDifferentAccountChangeEvent(void *state);
void LnnNotifyBtStateChangeEvent(void *state);

View File

@ -62,25 +62,6 @@ static void LeaveSpecificBrNetwork(const char *addr)
}
LNN_LOGI(LNN_STATE, "leave br network finished");
}
static void LeaveSpecificBrBleNetwork(const char *addr)
{
char networkId[NETWORK_ID_BUF_LEN] = { 0 };
if (LnnGetNetworkIdByBtMac(addr, networkId, sizeof(networkId)) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "networkId not found by addr");
return;
}
int32_t ret = LnnRequestLeaveSpecific(networkId, CONNECTION_ADDR_BR);
if (ret != SOFTBUS_OK) {
LNN_LOGW(LNN_STATE, "leave br network failed, ret=%{public}d", ret);
}
ret = LnnRequestLeaveSpecific(networkId, CONNECTION_ADDR_BLE);
if (ret != SOFTBUS_OK) {
LNN_LOGW(LNN_STATE, "leave ble nework failed, ret=%{public}d", ret);
}
LNN_LOGI(LNN_STATE, "leave br and ble network finished");
}
static void HandleBrConnectException(const ConnectOption *option, int32_t errorCode)
{
@ -110,7 +91,7 @@ static void HandleBrConnectException(const ConnectOption *option, int32_t errorC
if ((target->errorCode == HCI_ERR_BR_CONN_PAGE_TIMEOUT && target->count >= BR_PAGETIMEOUT_OFFLINE_COUNT) ||
(target->errorCode == HCI_ERR_BR_CONN_PEER_NOT_SUPORT_SDP_RECODE &&
target->count >= BR_SDP_NOT_SUPORT_OFFLINE_COUNT)) {
LeaveSpecificBrBleNetwork(option->brOption.brMac);
LeaveSpecificBrNetwork(option->brOption.brMac);
ListDelete(&target->node);
SoftBusFree(target);
g_exceptionConnMgr.connections->cnt--;

View File

@ -451,14 +451,22 @@ void LnnNotifyTimeSyncResult(const char *pkgName, int32_t pid, const TimeSyncRes
LnnIpcNotifyTimeSyncResult(pkgName, pid, info, sizeof(TimeSyncResultInfo), retCode);
}
void LnnNotifyWlanStateChangeEvent(SoftBusWifiState state)
void LnnNotifyWlanStateChangeEvent(void *state)
{
if (state < SOFTBUS_WIFI_CONNECTED || state > SOFTBUS_WIFI_UNKNOWN) {
LNN_LOGE(LNN_EVENT, "bad state=%{public}d", state);
if (state == NULL) {
LNN_LOGE(LNN_EVENT, "state is empty");
return;
}
LnnMonitorWlanStateChangedEvent event = {.basic.event = LNN_EVENT_WIFI_STATE_CHANGED, .status = state};
SoftBusWifiState *wifiState = (SoftBusWifiState *)state;
if (*wifiState < SOFTBUS_WIFI_CONNECTED || *wifiState > SOFTBUS_WIFI_UNKNOWN) {
LNN_LOGE(LNN_EVENT, "bad wifiState=%{public}d", *wifiState);
SoftBusFree(wifiState);
return;
}
LnnMonitorWlanStateChangedEvent event = {.basic.event = LNN_EVENT_WIFI_STATE_CHANGED,
.status = (uint8_t)(*wifiState)};
NotifyEvent((const LnnEventBasicInfo *)&event);
SoftBusFree(wifiState);
}
void LnnNotifyScreenStateChangeEvent(SoftBusScreenState state)
@ -693,7 +701,7 @@ void LnnNotifyNetworkIdChangeEvent(const char *networkId)
int32_t LnnInitBusCenterEvent(void)
{
int32_t i;
SoftBusLooper *looper = CreateNewLooper("LnnNotify_Lp");
SoftBusLooper *looper = CreateNewLooper("Notify_Lp");
if (looper == NULL) {
LNN_LOGE(LNN_EVENT, "create notify looper fail");
return SOFTBUS_ERR;

View File

@ -47,6 +47,7 @@ LNN_ASSIGNER(Int32, AuthCostTime, authCostTime)
LNN_ASSIGNER(Int32, LnnType, lnnType)
LNN_ASSIGNER(Int32, OnlineNum, onlineNum)
LNN_ASSIGNER(Int32, PeerDeviceAbility, peerDeviceAbility)
LNN_ASSIGNER(Int32, OnlineType, onlineType)
LNN_ASSIGNER(String, PeerDeviceInfo, peerDeviceInfo)
LNN_ASSIGNER(AnonymizeString, PeerIp, peerIp)
LNN_ASSIGNER(AnonymizeString, PeerBrMac, peerBrMac)
@ -61,7 +62,7 @@ LNN_ASSIGNER(AnonymizeString, PeerUdidHash, peerUdidHash)
LNN_ASSIGNER(String, CallerPkg, callerPkg)
LNN_ASSIGNER(String, CalleePkg, calleePkg)
#define LNN_ASSIGNER_SIZE 26 // Size of g_connAssigners
#define LNN_ASSIGNER_SIZE 27 // Size of g_connAssigners
static const HiSysEventParamAssigner g_lnnAssigners[] = {
{ "STAGE_RES", HISYSEVENT_INT32, LnnAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, LnnAssignerErrcode },
@ -76,6 +77,7 @@ static const HiSysEventParamAssigner g_lnnAssigners[] = {
{ "LNN_TYPE", HISYSEVENT_INT32, LnnAssignerLnnType },
{ "ONLINE_NUM", HISYSEVENT_INT32, LnnAssignerOnlineNum },
{ "PEER_DEV_ABILITY", HISYSEVENT_INT32, LnnAssignerPeerDeviceAbility},
{ "ONLINE_TYPE", HISYSEVENT_INT32, LnnAssignerOnlineType },
{ "PEER_DEV_INFO", HISYSEVENT_STRING, LnnAssignerPeerDeviceInfo },
{ "PEER_IP", HISYSEVENT_STRING, LnnAssignerPeerIp },
{ "PEER_BR_MAC", HISYSEVENT_STRING, LnnAssignerPeerBrMac },

View File

@ -92,6 +92,7 @@ typedef struct {
int32_t lnnType; // LNN_TYPE
int32_t onlineNum; // ONLINE_NUM
int32_t peerDeviceAbility; // PEER_DEV_ABILITY
int32_t onlineType; // ONLINE_TYPE
const char *peerDeviceInfo; // PEER_DEV_INFO
const char *peerIp; // PEER_IP
const char *peerBrMac; // PEER_BR_MAC

View File

@ -48,7 +48,7 @@
#define MAX_NODE_STATE_CB_CNT 10
#define MAX_LNN_CONNECTION_CNT 30
#define LNN_SUPPORT_CAPBILITY 62
#define LNN_SUPPORT_FEATURE 0x77C2
#define LNN_SUPPORT_FEATURE 0x177C2
#define AUTH_ABILITY_COLLECTION 0
#define ADAPTER_LOG_LEVEL 0
#ifndef DEFAULT_STORAGE_PATH

View File

@ -55,6 +55,7 @@
#define ONE_BYTE_SIZE 8
static void *g_timerId = NULL;
static bool g_timerOpen = false;
static TimerFunCallback g_timerFunList[SOFTBUS_MAX_TIMER_FUN_NUM] = {0};
static bool g_signalingMsgSwitch = false;
@ -112,6 +113,18 @@ static void HandleTimeoutFun(void)
g_timerFunList[i]();
}
}
if (!g_timerOpen) {
(void)SoftBusDeleteTimer(g_timerId);
g_timerId = NULL;
return;
}
(void)SoftBusDeleteTimer(g_timerId);
g_timerId = SoftBusCreateTimer(&g_timerId, TIMER_TYPE_ONCE);
if (SoftBusStartTimer(g_timerId, TIMER_TIMEOUT) != SOFTBUS_OK) {
COMM_LOGE(COMM_UTILS, "start timer failed.");
(void)SoftBusDeleteTimer(g_timerId);
g_timerId = NULL;
}
}
int32_t SoftBusTimerInit(void)
@ -120,22 +133,22 @@ int32_t SoftBusTimerInit(void)
return SOFTBUS_OK;
}
SetTimerFunc(HandleTimeoutFun);
g_timerId = SoftBusCreateTimer(&g_timerId, TIMER_TYPE_PERIOD);
g_timerId = SoftBusCreateTimer(&g_timerId, TIMER_TYPE_ONCE);
if (SoftBusStartTimer(g_timerId, TIMER_TIMEOUT) != SOFTBUS_OK) {
COMM_LOGE(COMM_UTILS, "start timer failed.");
(void)SoftBusDeleteTimer(g_timerId);
g_timerId = NULL;
return SOFTBUS_ERR;
}
g_timerOpen = true;
COMM_LOGI(COMM_UTILS, "softbus timer start");
return SOFTBUS_OK;
}
void SoftBusTimerDeInit(void)
{
if (g_timerId != NULL) {
(void)SoftBusDeleteTimer(g_timerId);
g_timerId = NULL;
}
COMM_LOGI(COMM_UTILS, "softbus timer stop");
g_timerOpen = false;
}
int32_t ConvertBytesToUpperCaseHexString(char *outBuf, uint32_t outBufLen, const unsigned char * inBuf,

View File

@ -47,6 +47,7 @@ typedef enum {
MODULE_PKG_VERIFY = 20,
MODULE_META_AUTH = 21,
MODULE_P2P_NEGO = 22,
MODULE_AUTH_SYNC_INFO = 23,
MODULE_BLE_NET = 100,
MODULE_BLE_CONN = 101,
MODULE_NIP_BR_CHANNEL = 201,
@ -86,6 +87,7 @@ typedef enum {
DIRECT_CHANNEL_SERVER_HML_START,
DIRECT_CHANNEL_SERVER_HML_END = DIRECT_CHANNEL_SERVER_HML_START + HML_INDEX,
LANE,
NETLINK,
LISTENER_MODULE_DYNAMIC_START,
LISTENER_MODULE_DYNAMIC_END = LISTENER_MODULE_DYNAMIC_START + CONN_DYNAMIC_LISTENER_MODULE_COUNT,

View File

@ -55,9 +55,6 @@ ohos_static_library("wifi_direct") {
if (dsoftbus_feature_conn_p2p == true &&
softbus_communication_wifi_feature == true) {
sanitize = {
ubsan = true
integer_overflow = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false

View File

@ -108,6 +108,11 @@ void ConnectCommand::PreferNegotiateChannel()
info_.channel_ = innerLink->GetNegotiateChannel();
}
bool ConnectCommand::IsSameCommand(const WifiDirectConnectInfo &info)
{
return (info.requestId == info_.info_.requestId) && (info.pid == info_.info_.pid);
}
void ConnectCommand::DfxRecord(bool isSuccess, WifiDirectErrorCode reason) const
{
if (isSuccess) {

View File

@ -47,6 +47,7 @@ public:
void OnSuccess(const WifiDirectLink &link) const;
void OnFailure(WifiDirectErrorCode reason) const;
bool IsSameCommand(const WifiDirectConnectInfo &info);
protected:
ConnectInfo info_;

View File

@ -179,7 +179,7 @@ std::vector<uint8_t> WifiDirectUtils::GetLocalPtk(const std::string &remoteNetwo
std::vector<uint8_t> WifiDirectUtils::GetRemotePtk(const std::string &remoteNetworkId)
{
std::vector<uint8_t> result;
uint8_t ptkBytes[PTK_DEFAULT_LEN] = { 0 };
uint8_t ptkBytes[PTK_DEFAULT_LEN] {};
int32_t ret = LnnGetRemoteByteInfo(remoteNetworkId.c_str(), BYTE_KEY_REMOTE_PTK, ptkBytes, sizeof(ptkBytes));
CONN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, result, CONN_WIFI_DIRECT, "get remote ptk failed");
result.insert(result.end(), ptkBytes, ptkBytes + PTK_128BIT_LEN);
@ -398,11 +398,26 @@ WifiDirectRole WifiDirectUtils::ToWifiDirectRole(LinkInfo::LinkMode mode)
void WifiDirectUtils::ShowLinkInfoList(const std::string &banana, const std::vector<LinkInfo> &inkList)
{
CONN_LOGI(CONN_WIFI_DIRECT, "banana=%{public}s", banana.c_str());
int count = 0;
for (const auto &info : inkList) {
CONN_LOGI(CONN_WIFI_DIRECT, "%{public}s[%{public}d]: name=%{public}s, mode=%{public}d", banana.c_str(), count,
info.GetLocalInterface().c_str(), info.GetLocalLinkMode());
count++;
}
}
for (const LinkInfo &info : inkList) {
CONN_LOGI(CONN_WIFI_DIRECT, "interface=%{public}s, mode=%{public}d", info.GetLocalInterface().c_str(),
static_cast<int>(info.GetLocalLinkMode()));
enum WifiDirectBandWidth WifiDirectUtils::BandWidthNumberToEnum(int bandWidth)
{
return bandWidth >= BAND_WIDTH_160M_NUMBER ? BAND_WIDTH_160M : BAND_WIDTH_80M;
}
int WifiDirectUtils::BandWidthEnumToNumber(WifiDirectBandWidth bandWidth)
{
switch (bandWidth) {
case BAND_WIDTH_160M:
return BAND_WIDTH_160M_NUMBER;
default:
return BAND_WIDTH_80M_NUMBER;
}
}
} // namespace OHOS::SoftBus

View File

@ -79,6 +79,11 @@ public:
static WifiDirectRole ToWifiDirectRole(LinkInfo::LinkMode mode);
static void ShowLinkInfoList(const std::string &banana, const std::vector<LinkInfo> &inkList);
static constexpr int BAND_WIDTH_80M_NUMBER = 80 << 20;
static constexpr int BAND_WIDTH_160M_NUMBER = 160 << 20;
static WifiDirectBandWidth BandWidthNumberToEnum(int bandWidth);
static int BandWidthEnumToNumber(WifiDirectBandWidth bandWidth);
};
}

View File

@ -47,6 +47,12 @@ public:
GetSender().Send(content);
}
void SetProcessor(std::shared_ptr<WifiDirectProcessor> processor)
{
std::lock_guard lock(processorLock_);
processor_ = processor;
}
WifiDirectEventDispatcher WaitEvent();
protected:

View File

@ -124,12 +124,6 @@ static int32_t ConnectDevice(struct WifiDirectConnectInfo *info, struct WifiDire
int32_t ret = OHOS::SoftBus::WifiDirectRoleOption::GetInstance().GetExpectedRole(
info->remoteNetworkId, info->connectType, info->expectApiRole, info->isStrict);
CONN_CHECK_AND_RETURN_RET_LOGW(ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get expected role failed");
CONN_LOGI(CONN_WIFI_DIRECT,
"requestId=%{public}d, pid=%{public}d, type=%{public}d, expectRole=0x%{public}x",
info->requestId,
info->pid,
info->connectType,
info->expectApiRole);
ret = OHOS::SoftBus::WifiDirectSchedulerFactory::GetInstance().GetScheduler().ConnectDevice(*info, *callback);
extra.errcode = ret;
extra.result = (ret == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
@ -137,6 +131,12 @@ static int32_t ConnectDevice(struct WifiDirectConnectInfo *info, struct WifiDire
return ret;
}
static int32_t CancelConnectDevice(const struct WifiDirectConnectInfo *info)
{
CONN_CHECK_AND_RETURN_RET_LOGW(info != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "info is null");
return OHOS::SoftBus::WifiDirectSchedulerFactory::GetInstance().GetScheduler().CancelConnectDevice(*info);
}
static int32_t DisconnectDevice(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback)
{
CONN_CHECK_AND_RETURN_RET_LOGW(info != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "info is null");
@ -323,7 +323,7 @@ static void NotifyDisconnectedForSink(
bool IsNegotiateChannelNeeded(const char *remoteNetworkId, enum WifiDirectLinkType linkType)
{
CONN_CHECK_AND_RETURN_RET_LOGE(remoteNetworkId != NULL, true, CONN_WIFI_DIRECT, "remote networkid is null");
CONN_CHECK_AND_RETURN_RET_LOGE(remoteNetworkId != nullptr, true, CONN_WIFI_DIRECT, "remote networkid is null");
auto remoteUuid = OHOS::SoftBus::WifiDirectUtils::NetworkIdToUuid(remoteNetworkId);
CONN_CHECK_AND_RETURN_RET_LOGE(!remoteUuid.empty(), true, CONN_WIFI_DIRECT, "get remote uuid failed");
@ -367,6 +367,7 @@ static struct WifiDirectManager g_manager = {
.allocateListenerModuleId = AllocateListenerModuleId,
.freeListenerModuleId = FreeListenerModuleId,
.connectDevice = ConnectDevice,
.cancelConnectDevice = CancelConnectDevice,
.disconnectDevice = DisconnectDevice,
.registerStatusListener = RegisterStatusListener,
.prejudgeAvailability = PrejudgeAvailability,

View File

@ -38,6 +38,7 @@ struct WifiDirectManager {
void (*freeListenerModuleId)(int32_t moduleId);
int32_t (*connectDevice)(struct WifiDirectConnectInfo *info, struct WifiDirectConnectCallback *callback);
int32_t (*cancelConnectDevice)(const struct WifiDirectConnectInfo *info);
int32_t (*disconnectDevice)(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback);
void (*registerStatusListener)(struct WifiDirectStatusListener *listener);
int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType);

View File

@ -26,9 +26,11 @@ int WifiDirectScheduler::ConnectDevice(const WifiDirectConnectInfo &info, const
bool markRetried)
{
CONN_LOGI(CONN_WIFI_DIRECT,
"requestId=%{public}d pid=%{public}d type=%{public}d networkId=%{public}s remoteUuid=%{public}s",
"requestId=%{public}d pid=%{public}d type=%{public}d networkId=%{public}s remoteUuid=%{public}s "
"expectRole=0x%{public}x, bw=%{public}d, ipaddrType=%{public}d",
info.requestId, info.pid, info.connectType, WifiDirectAnonymizeDeviceId(info.remoteNetworkId).c_str(),
WifiDirectAnonymizeDeviceId(WifiDirectUtils::NetworkIdToUuid(info.remoteNetworkId)).c_str());
WifiDirectAnonymizeDeviceId(WifiDirectUtils::NetworkIdToUuid(info.remoteNetworkId)).c_str(),
info.expectApiRole, info.bandWidth, info.ipAddrType);
auto command = CommandFactory::GetInstance().CreateConnectCommand(info, callback);
command->SetRetried(markRetried);
@ -41,6 +43,21 @@ int WifiDirectScheduler::ConnectDevice(const WifiDirectConnectInfo &info, const
return ret;
}
int WifiDirectScheduler::CancelConnectDevice(const WifiDirectConnectInfo &info)
{
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}d pid=%{public}d", info.requestId, info.pid);
std::lock_guard commandLock(commandLock_);
for (auto itc = commandList_.begin(); itc != commandList_.end(); itc++) {
auto connectCommand = std::dynamic_pointer_cast<ConnectCommand>(*itc);
if (connectCommand != nullptr && connectCommand->IsSameCommand(info)) {
commandList_.erase(itc);
return SOFTBUS_OK;
}
}
return SOFTBUS_NOT_FIND;
}
int WifiDirectScheduler::ConnectDevice(const std::shared_ptr<ConnectCommand> &command, bool markRetried)
{
return ConnectDevice(command->GetConnectInfo().info_, command->GetConnectCallback(), markRetried);

View File

@ -39,6 +39,7 @@ public:
int ConnectDevice(const WifiDirectConnectInfo &info, const WifiDirectConnectCallback &callback,
bool markRetried = false);
int ConnectDevice(const std::shared_ptr<ConnectCommand> &command, bool markRetried = false);
int CancelConnectDevice(const WifiDirectConnectInfo &info);
int DisconnectDevice(WifiDirectDisconnectInfo &info, WifiDirectDisconnectCallback &callback);
template<typename Command>

View File

@ -75,12 +75,23 @@ enum WifiDirectLinkType {
WIFI_DIRECT_LINK_TYPE_HML,
};
enum WifiDirectBandWidth {
BAND_WIDTH_RANDOM = 0x0,
BAND_WIDTH_20M,
BAND_WIDTH_40M,
BAND_WIDTH_80M,
BAND_WIDTH_80P80M,
BAND_WIDTH_160M,
BAND_WIDTH_BUTT = 0xFF,
};
struct WifiDirectLink {
int32_t linkId;
char localIp[IP_STR_MAX_LEN];
char remoteIp[IP_STR_MAX_LEN];
int32_t remotePort;
enum WifiDirectLinkType linkType;
enum WifiDirectBandWidth bandWidth;
};
enum WifiDirectNegoChannelType {
@ -127,15 +138,13 @@ struct WifiDirectConnectInfo {
int32_t pid;
enum WifiDirectConnectType connectType;
struct WifiDirectNegotiateChannel negoChannel;
bool paralle;
uint32_t expectApiRole;
bool isStrict;
char remoteNetworkId[NETWORK_ID_BUF_LEN];
char remoteMac[MAC_ADDR_STR_LEN];
bool isNetworkDelegate;
uint32_t bandWidth;
int32_t bandWidth;
enum IpAddrType ipAddrType;
uint32_t custom;
enum StatisticLinkType linkType;
enum StatisticBootLinkType bootLinkType;

View File

@ -28,6 +28,7 @@ extern "C" {
#define MSG_FLAG_REQUEST 0
#define MES_FLAG_REPLY 1
#define TRAFFIC_LEN 32
#define UNKNOW_OS_TYPE 1 /* peer osType unknow */
typedef struct {
const char *sessionName;

View File

@ -21,8 +21,9 @@
#include "softbus_utils.h"
#include "trans_log.h"
#define TIME_OUT 20
#define MSG_TIMEOUT_S 20
#define UDP_TIMEOUT_US (150 * 1000)
#define MAX_US (1 * 1000 * 1000)
typedef struct {
ListNode node;
@ -112,69 +113,70 @@ static void ReleasePendingItem(PendingPktInfo *item)
SoftBusFree(item);
}
int32_t ProcPendingPacket(int32_t channelId, int32_t seqNum, int type)
static void FormalizeTimeFormat(SoftBusSysTime *outTime, int32_t type)
{
SoftBusSysTime now;
SoftBusGetTime(&now);
outTime->sec = (type == PENDING_TYPE_UDP) ? now.sec : now.sec + MSG_TIMEOUT_S;
outTime->usec = (type == PENDING_TYPE_UDP) ? now.usec + UDP_TIMEOUT_US : now.usec;
while (outTime->usec >= MAX_US) {
outTime->usec -= MAX_US;
outTime->sec += 1;
TRANS_LOGI(TRANS_SVC,
"us over limit, after formalize, us=%{public}" PRId64 "sec=%{public}" PRId64, outTime->usec, outTime->sec);
}
}
int32_t ProcPendingPacket(int32_t channelId, int32_t seqNum, int32_t type)
{
int32_t ret = IsPendingListTypeLegal(type);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "type illegal. type=%{public}d", type);
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_SVC, "type=%{public}d illegal", type);
PendingPktInfo *item = NULL;
SoftBusList *pendingList = g_pendingList[type];
if (pendingList == NULL) {
TRANS_LOGE(TRANS_INIT, "pending type list not inited. type=%{public}d", type);
return SOFTBUS_TRANS_TDC_PENDINGLIST_NOT_FOUND;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(pendingList != NULL, SOFTBUS_TRANS_TDC_PENDINGLIST_NOT_FOUND, TRANS_SVC,
"type=%{public}d pending list not init", type);
SoftBusMutexLock(&pendingList->lock);
LIST_FOR_EACH_ENTRY(item, &pendingList->list, PendingPktInfo, node)
{
ret = SoftBusMutexLock(&pendingList->lock);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, TRANS_SVC, "pending list lock failed");
PendingPktInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &pendingList->list, PendingPktInfo, node) {
if (item->seq == seqNum && item->channelId == channelId) {
TRANS_LOGW(TRANS_SVC, "PendingPacket already Created");
SoftBusMutexUnlock(&pendingList->lock);
(void)SoftBusMutexUnlock(&pendingList->lock);
return SOFTBUS_TRANS_TDC_CHANNEL_ALREADY_PENDING;
}
}
item = CreatePendingItem(channelId, seqNum);
if (item == NULL) {
SoftBusMutexUnlock(&pendingList->lock);
(void)SoftBusMutexUnlock(&pendingList->lock);
return SOFTBUS_MALLOC_ERR;
}
ListAdd(&pendingList->list, &item->node);
TRANS_LOGI(TRANS_SVC, "add channelId=%{public}d", item->channelId);
pendingList->cnt++;
SoftBusMutexUnlock(&pendingList->lock);
(void)SoftBusMutexUnlock(&pendingList->lock);
SoftBusSysTime outtime;
SoftBusSysTime now;
SoftBusGetTime(&now);
if (type == PENDING_TYPE_UDP) {
outtime.sec = now.sec;
outtime.usec = now.usec + UDP_TIMEOUT_US;
} else {
outtime.sec = now.sec + TIME_OUT;
outtime.usec = now.usec;
}
SoftBusMutexLock(&item->lock);
while (item->status == PACKAGE_STATUS_PENDING && TimeBefore(&outtime)) {
SoftBusCondWait(&item->cond, &item->lock, &outtime);
}
SoftBusSysTime outTime;
FormalizeTimeFormat(&outTime, type);
ret = SOFTBUS_OK;
if (item->status != PACKAGE_STATUS_FINISHED) {
ret = SOFTBUS_TIMOUT;
ret = SoftBusMutexLock(&item->lock);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, TRANS_SVC, "pending item lock failed");
while (item->status == PACKAGE_STATUS_PENDING && TimeBefore(&outTime)) {
SoftBusCondWait(&item->cond, &item->lock, &outTime);
}
SoftBusMutexUnlock(&item->lock);
ret = (item->status == PACKAGE_STATUS_FINISHED) ? SOFTBUS_OK : SOFTBUS_TIMOUT;
(void)SoftBusMutexUnlock(&item->lock);
SoftBusMutexLock(&pendingList->lock);
ret = SoftBusMutexLock(&pendingList->lock);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, TRANS_SVC, "pending list lock failed");
ListDelete(&item->node);
TRANS_LOGI(TRANS_SVC, "delete channelId=%{public}d", item->channelId);
pendingList->cnt--;
SoftBusMutexUnlock(&pendingList->lock);
(void)SoftBusMutexUnlock(&pendingList->lock);
ReleasePendingItem(item);
return ret;
return SOFTBUS_OK;
}
int32_t SetPendingPacket(int32_t channelId, int32_t seqNum, int type)

View File

@ -442,7 +442,7 @@ static void OnRecvAuthChannelReply(int32_t authId, const char *data, int32_t len
.channelType = CHANNEL_TYPE_AUTH,
.authId = authId,
.linkType = info.connOpt.type,
.osType = info.appInfo.osType
.osType = (info.appInfo.osType < 0) ? UNKNOW_OS_TYPE : info.appInfo.osType,
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
int32_t ret = TransAuthChannelMsgUnpack(data, &info.appInfo, len);

View File

@ -34,7 +34,8 @@ void TransAsyncReqLanePendingDeinit(void);
int32_t TransGetConnectOptByConnInfo(const LaneConnInfo *info, ConnectOption *connOpt);
int32_t TransGetLaneInfo(const SessionParam *param, LaneConnInfo *connInfo, uint32_t *laneHandle);
int32_t TransAsyncGetLaneInfo(const SessionParam *param, uint32_t *laneHandle, uint32_t callingTokenId);
int32_t TransAsyncGetLaneInfo(
const SessionParam *param, uint32_t *laneHandle, uint32_t callingTokenId, int64_t timeStart);
int32_t TransGetLaneInfoByOption(const LaneRequestOption *requestOption, LaneConnInfo *connInfo, uint32_t *laneHandle);
int32_t TransGetLaneInfoByQos(const LaneAllocInfo *allocInfo, LaneConnInfo *connInfo, uint32_t *laneHandle);
bool TransGetAuthTypeByNetWorkId(const char *peerNetWorkId);

View File

@ -62,6 +62,7 @@ typedef struct {
SessionParam param;
uint32_t callingTokenId; // used for transmission access control
uint32_t firstTokenId; // used for dfx connection success rate
int64_t timeStart;
} TransReqLaneItem;
static SoftBusList *g_reqLanePendingList = NULL;
@ -328,7 +329,7 @@ static int32_t CopyAsyncReqItemSessionParam(const SessionParam *source, SessionP
}
static int32_t TransAddAsyncLaneReqFromPendingList(uint32_t laneHandle, const SessionParam *param,
uint32_t callingTokenId)
uint32_t callingTokenId, int64_t timeStart)
{
if (g_asyncReqLanePendingList == NULL) {
TRANS_LOGE(TRANS_SVC, "lane pending list no init.");
@ -346,6 +347,7 @@ static int32_t TransAddAsyncLaneReqFromPendingList(uint32_t laneHandle, const Se
item->isFinished = false;
item->callingTokenId = callingTokenId;
item->firstTokenId = TransACLGetFirstTokenID();
item->timeStart = timeStart;
if (CopyAsyncReqItemSessionParam(param, &(item->param)) != SOFTBUS_OK) {
DestroyAsyncReqItemParam(&(item->param));
SoftBusFree(item);
@ -400,7 +402,7 @@ static int32_t TransGetLaneReqItemByLaneHandle(uint32_t laneHandle, bool *bSucc,
}
static int32_t TransGetLaneReqItemParamByLaneHandle(
uint32_t laneHandle, SessionParam *param, uint32_t *callingTokenId, uint32_t *firstTokenId)
uint32_t laneHandle, SessionParam *param, uint32_t *callingTokenId, uint32_t *firstTokenId, int64_t *timeStart)
{
if (param == NULL) {
TRANS_LOGE(TRANS_SVC, "param err.");
@ -422,6 +424,7 @@ static int32_t TransGetLaneReqItemParamByLaneHandle(
if (firstTokenId != NULL) {
*firstTokenId = item->firstTokenId;
}
*timeStart = item->timeStart;
if (memcpy_s(param, sizeof(SessionParam), &(item->param), sizeof(SessionParam)) != EOK) {
(void)SoftBusMutexUnlock(&(g_asyncReqLanePendingList->lock));
TRANS_LOGE(TRANS_SVC, "copy session param failed.");
@ -491,13 +494,12 @@ static void RecordFailOpenSessionKpi(AppInfo *appInfo, LaneConnInfo *connInfo, i
static void TransAsyncOpenChannelProc(uint32_t laneHandle, SessionParam *param, AppInfo *appInfo,
TransEventExtra *extra, LaneConnInfo *connInnerInfo)
{
int64_t timeStart = GetSoftbusRecordTimeMillis();
TransInfo transInfo = { .channelId = INVALID_CHANNEL_ID, .channelType = CHANNEL_TYPE_BUTT};
ConnectOption connOpt;
(void)memset_s(&connOpt, sizeof(ConnectOption), 0, sizeof(ConnectOption));
int32_t ret = TransGetConnectOptByConnInfo(connInnerInfo, &connOpt);
if (ret != SOFTBUS_OK) {
RecordFailOpenSessionKpi(appInfo, connInnerInfo, timeStart);
RecordFailOpenSessionKpi(appInfo, connInnerInfo, appInfo->timeStart);
goto EXIT_ERR;
}
ret = LnnGetRemoteStrInfo(appInfo->peerNetWorkId, STRING_KEY_MASTER_NODE_UDID,
@ -507,7 +509,7 @@ static void TransAsyncOpenChannelProc(uint32_t laneHandle, SessionParam *param,
goto EXIT_ERR;
}
extra->peerUdid = appInfo->peerUdid;
extra->osType = appInfo->osType;
extra->osType = (appInfo->osType < 0) ? UNKNOW_OS_TYPE : appInfo->osType;
appInfo->connectType = connOpt.type;
extra->linkType = connOpt.type;
FillAppInfo(appInfo, param, &transInfo, connInnerInfo);
@ -516,7 +518,7 @@ static void TransAsyncOpenChannelProc(uint32_t laneHandle, SessionParam *param,
ret = TransOpenChannelProc((ChannelType)transInfo.channelType, appInfo, &connOpt, &(transInfo.channelId));
if (ret != SOFTBUS_OK) {
SoftbusReportTransErrorEvt(SOFTBUS_TRANS_CREATE_CHANNEL_ERR);
RecordFailOpenSessionKpi(appInfo, connInnerInfo, timeStart);
RecordFailOpenSessionKpi(appInfo, connInnerInfo, appInfo->timeStart);
goto EXIT_ERR;
}
TransUpdateSocketChannelInfoBySession(
@ -524,7 +526,7 @@ static void TransAsyncOpenChannelProc(uint32_t laneHandle, SessionParam *param,
ret = ClientIpcSetChannelInfo(
appInfo->myData.pkgName, param->sessionName, param->sessionId, &transInfo, appInfo->myData.pid);
if (ret != SOFTBUS_OK) {
RecordFailOpenSessionKpi(appInfo, connInnerInfo, timeStart);
RecordFailOpenSessionKpi(appInfo, connInnerInfo, appInfo->timeStart);
TransCommonCloseChannel(NULL, transInfo.channelId, transInfo.channelType);
goto EXIT_ERR;
}
@ -534,13 +536,13 @@ static void TransAsyncOpenChannelProc(uint32_t laneHandle, SessionParam *param,
TransFreeLane(laneHandle, param->isQosLane);
} else if (TransLaneMgrAddLane(transInfo.channelId, transInfo.channelType, connInnerInfo,
laneHandle, param->isQosLane, &(appInfo->myData)) != SOFTBUS_OK) {
RecordFailOpenSessionKpi(appInfo, connInnerInfo, timeStart);
RecordFailOpenSessionKpi(appInfo, connInnerInfo, appInfo->timeStart);
TransCommonCloseChannel(NULL, transInfo.channelId, transInfo.channelType);
goto EXIT_ERR;
}
return;
EXIT_ERR:
TransBuildTransOpenChannelEndEvent(extra, &transInfo, timeStart, ret);
TransBuildTransOpenChannelEndEvent(extra, &transInfo, appInfo->timeStart, ret);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, *extra);
TransAlarmExtra extraAlarm;
TransBuildTransAlarmEvent(&extraAlarm, appInfo, ret);
@ -574,7 +576,8 @@ static void TransOnAsyncLaneSuccess(uint32_t laneHandle, const LaneConnInfo *con
SessionParam param;
uint32_t callingTokenId = TOKENID_NOT_SET;
uint32_t firstTokenId = TOKENID_NOT_SET;
int32_t ret = TransGetLaneReqItemParamByLaneHandle(laneHandle, &param, &callingTokenId, &firstTokenId);
int64_t timeStart = 0;
int32_t ret = TransGetLaneReqItemParamByLaneHandle(laneHandle, &param, &callingTokenId, &firstTokenId, &timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "get lane req item failed. laneHandle=%{public}u, ret=%{public}d", laneHandle, ret);
(void)TransDelLaneReqFromPendingList(laneHandle, true);
@ -592,7 +595,6 @@ static void TransOnAsyncLaneSuccess(uint32_t laneHandle, const LaneConnInfo *con
TRANS_SVC, "cancel state laneHandle=%{public}u, laneId=%{public}" PRId64, laneHandle, connInfo->laneId);
TransFreeLane(laneHandle, param.isQosLane);
BuildTransEventExtra(&extra, &param, laneHandle, transType, SOFTBUS_TRANS_STOP_BIND_BY_CANCEL);
extra.linkType = tmpConnInfo.type;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_SELECT_LANE, extra);
(void)TransDelLaneReqFromPendingList(laneHandle, true);
(void)TransDeleteSocketChannelInfoBySession(param.sessionName, param.sessionId);
@ -600,14 +602,14 @@ static void TransOnAsyncLaneSuccess(uint32_t laneHandle, const LaneConnInfo *con
}
TransSetSocketChannelStateBySession(param.sessionName, param.sessionId, CORE_SESSION_STATE_LAN_COMPLETE);
AppInfo *appInfo = TransCommonGetAppInfo(&param);
TRANS_CHECK_AND_RETURN_LOGW(!(appInfo == NULL), TRANS_SVC, "GetAppInfo is null.");
TRANS_CHECK_AND_RETURN_LOGW(appInfo != NULL, TRANS_SVC, "GetAppInfo is null.");
appInfo->callingTokenId = callingTokenId;
appInfo->timeStart = timeStart;
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
int32_t peerRet = LnnGetRemoteNodeInfoById(appInfo->peerNetWorkId, CATEGORY_NETWORK_ID, &nodeInfo);
TransBuildTransOpenChannelStartEvent(&extra, appInfo, &nodeInfo, peerRet);
TransAsyncSetFirstTokenInfo(firstTokenId, appInfo, &extra);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra);
TransAsyncOpenChannelProc(laneHandle, &param, appInfo, &extra, &tmpConnInfo);
TransFreeAppInfo(appInfo);
(void)TransDelLaneReqFromPendingList(laneHandle, true);
@ -618,7 +620,9 @@ static void TransOnAsyncLaneFail(uint32_t laneHandle, int32_t reason)
TRANS_LOGI(TRANS_SVC, "request failed, laneHandle=%{public}u, reason=%{public}d", laneHandle, reason);
SessionParam param;
uint32_t callingTokenId = TOKENID_NOT_SET;
int32_t ret = TransGetLaneReqItemParamByLaneHandle(laneHandle, &param, &callingTokenId, NULL);
TransInfo transInfo = { .channelId = INVALID_CHANNEL_ID, .channelType = CHANNEL_TYPE_BUTT};
int64_t timeStart = 0;
int32_t ret = TransGetLaneReqItemParamByLaneHandle(laneHandle, &param, &callingTokenId, NULL, &timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "get lane req item failed. laneHandle=%{public}u, ret=%{public}d", laneHandle, ret);
(void)TransDelLaneReqFromPendingList(laneHandle, true);
@ -626,17 +630,20 @@ static void TransOnAsyncLaneFail(uint32_t laneHandle, int32_t reason)
}
LaneTransType transType = (LaneTransType)TransGetLaneTransTypeBySession(&param);
TransEventExtra extra;
BuildTransEventExtra(&extra, &param, laneHandle, transType, SOFTBUS_ERR);
BuildTransEventExtra(&extra, &param, laneHandle, transType, reason);
extra.linkType = LANE_LINK_TYPE_BUTT;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_SELECT_LANE, extra);
AppInfo *appInfo = TransCommonGetAppInfo(&param);
TRANS_CHECK_AND_RETURN_LOGW(!(appInfo == NULL), TRANS_SVC, "GetAppInfo is null.");
TRANS_CHECK_AND_RETURN_LOGW(appInfo != NULL, TRANS_SVC, "GetAppInfo is null.");
appInfo->callingTokenId = callingTokenId;
appInfo->timeStart = timeStart;
CallBackOpenChannelFailed(&param, appInfo, reason);
if (!param.isQosLane) {
TransFreeLane(laneHandle, param.isQosLane);
}
(void)TransDelLaneReqFromPendingList(laneHandle, true);
TransBuildTransOpenChannelEndEvent(&extra, &transInfo, appInfo->timeStart, reason);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
TransFreeAppInfo(appInfo);
(void)TransDeleteSocketChannelInfoBySession(param.sessionName, param.sessionId);
}
@ -1049,10 +1056,9 @@ int32_t TransGetLaneInfoByOption(const LaneRequestOption *requestOption, LaneCon
TRANS_CHECK_AND_RETURN_RET_LOGE(GetLaneManager()->lnnGetLaneHandle != NULL, SOFTBUS_TRANS_GET_LANE_INFO_ERR,
TRANS_SVC, "lnnGetLaneHandle is null");
*laneHandle = GetLaneManager()->lnnGetLaneHandle(LANE_TYPE_TRANS);
if (TransAddLaneReqToPendingAndWaiting(*laneHandle, requestOption) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "trans add lane to pending list failed.");
return SOFTBUS_ERR;
}
int32_t ret = TransAddLaneReqToPendingAndWaiting(*laneHandle, requestOption);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_SVC, "trans add lane to pending list failed.");
bool bSuccess = false;
int32_t errCode = SOFTBUS_ERR;
if (TransGetLaneReqItemByLaneHandle(*laneHandle, &bSuccess, connInfo, &errCode) != SOFTBUS_OK) {
@ -1147,7 +1153,7 @@ int32_t TransGetLaneInfo(const SessionParam *param, LaneConnInfo *connInfo, uint
}
int32_t TransAsyncGetLaneInfoByOption(const SessionParam *param, const LaneRequestOption *requestOption,
uint32_t *laneHandle, uint32_t callingTokenId)
uint32_t *laneHandle, uint32_t callingTokenId, int64_t timeStart)
{
if (param == NULL || requestOption == NULL || laneHandle == NULL) {
TRANS_LOGE(TRANS_SVC, "async get lane info param error.");
@ -1160,7 +1166,7 @@ int32_t TransAsyncGetLaneInfoByOption(const SessionParam *param, const LaneReque
*laneHandle = GetLaneManager()->lnnGetLaneHandle(LANE_TYPE_TRANS);
TransUpdateSocketChannelLaneInfoBySession(
param->sessionName, param->sessionId, *laneHandle, param->isQosLane, param->isAsync);
int32_t ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, callingTokenId);
int32_t ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, callingTokenId, timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(
TRANS_SVC, "add laneHandle=%{public}u to async pending list failed, ret=%{public}d", *laneHandle, ret);
@ -1187,7 +1193,7 @@ int32_t TransAsyncGetLaneInfoByOption(const SessionParam *param, const LaneReque
}
int32_t TransAsyncGetLaneInfoByQos(const SessionParam *param, const LaneAllocInfo *allocInfo,
uint32_t *laneHandle, uint32_t callingTokenId)
uint32_t *laneHandle, uint32_t callingTokenId, int64_t timeStart)
{
if (param == NULL || allocInfo == NULL || laneHandle == NULL) {
TRANS_LOGE(TRANS_SVC, "async get lane info param error.");
@ -1200,7 +1206,7 @@ int32_t TransAsyncGetLaneInfoByQos(const SessionParam *param, const LaneAllocInf
*laneHandle = GetLaneManager()->lnnGetLaneHandle(LANE_TYPE_TRANS);
TransUpdateSocketChannelLaneInfoBySession(
param->sessionName, param->sessionId, *laneHandle, param->isQosLane, param->isAsync);
int32_t ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, callingTokenId);
int32_t ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, callingTokenId, timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(
TRANS_SVC, "add laneHandle=%{public}u to async pending list failed, ret=%{public}d", *laneHandle, ret);
@ -1229,7 +1235,8 @@ int32_t TransAsyncGetLaneInfoByQos(const SessionParam *param, const LaneAllocInf
return SOFTBUS_OK;
}
int32_t TransAsyncGetLaneInfo(const SessionParam *param, uint32_t *laneHandle, uint32_t callingTokenId)
int32_t TransAsyncGetLaneInfo(
const SessionParam *param, uint32_t *laneHandle, uint32_t callingTokenId, int64_t timeStart)
{
if (param == NULL || laneHandle == NULL) {
TRANS_LOGE(TRANS_SVC, "async get lane info param error.");
@ -1244,7 +1251,7 @@ int32_t TransAsyncGetLaneInfo(const SessionParam *param, uint32_t *laneHandle, u
TRANS_LOGE(TRANS_SVC, "get request option failed. laneHandle=%{public}u, ret=%{public}d", *laneHandle, ret);
return ret;
}
ret = TransAsyncGetLaneInfoByOption(param, &requestOption, laneHandle, callingTokenId);
ret = TransAsyncGetLaneInfoByOption(param, &requestOption, laneHandle, callingTokenId, timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "get lane info by option failed, ret=%{public}d", ret);
return ret;
@ -1257,7 +1264,7 @@ int32_t TransAsyncGetLaneInfo(const SessionParam *param, uint32_t *laneHandle, u
TRANS_LOGE(TRANS_SVC, "get alloc Info failed. laneHandle=%{public}u, ret=%{public}d", *laneHandle, ret);
return ret;
}
ret = TransAsyncGetLaneInfoByQos(param, &allocInfo, laneHandle, callingTokenId);
ret = TransAsyncGetLaneInfoByQos(param, &allocInfo, laneHandle, callingTokenId, timeStart);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "get lane info by allocInfo failed, ret=%{public}d", ret);
*laneHandle = INVALID_LANE_REQ_ID; // qos lane failed no need free lane again

View File

@ -53,7 +53,7 @@ static int32_t TransServerOnChannelOpened(const char *pkgName, int32_t pid, cons
.result = EVENT_STAGE_RESULT_OK,
.callerPkg = pkgName,
.socketName = sessionName,
.osType = osType,
.osType = (osType < 0) ? UNKNOW_OS_TYPE : osType,
.peerUdid = peerUdid
};
CoreSessionState state = CORE_SESSION_STATE_INIT;

View File

@ -213,9 +213,19 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
ret = TransAddSocketChannelInfo(
param->sessionName, param->sessionId, INVALID_CHANNEL_ID, CHANNEL_TYPE_UNDEFINED, CORE_SESSION_STATE_INIT);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "Add socket channel record failed.");
AppInfo *appInfo = TransCommonGetAppInfo(param);
TRANS_CHECK_AND_RETURN_RET_LOGW(appInfo != NULL, INVALID_CHANNEL_ID, TRANS_CTRL, "GetAppInfo is null.");
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
int32_t peerRet = LnnGetRemoteNodeInfoById(appInfo->peerNetWorkId, CATEGORY_NETWORK_ID, &nodeInfo);
TransEventExtra extra;
(void)memset_s(&extra, sizeof(TransEventExtra), 0, sizeof(TransEventExtra));
TransBuildTransOpenChannelStartEvent(&extra, appInfo, &nodeInfo, peerRet);
TransSetFirstTokenInfo(appInfo, &extra);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra);
if (param->isAsync) {
uint32_t callingTokenId = TransACLGetCallingTokenID();
ret = TransAsyncGetLaneInfo(param, &laneHandle, callingTokenId);
ret = TransAsyncGetLaneInfo(param, &laneHandle, callingTokenId, appInfo->timeStart);
if (ret != SOFTBUS_OK) {
Anonymize(param->sessionName, &tmpName);
TRANS_LOGE(TRANS_CTRL, "Async get Lane failed, sessionName=%{public}s, sessionId=%{public}d",
@ -226,24 +236,14 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
}
(void)TransDeleteSocketChannelInfoBySession(param->sessionName, param->sessionId);
}
TransFreeAppInfo(appInfo);
return ret;
}
int64_t timeStart = GetSoftbusRecordTimeMillis();
transInfo->channelId = INVALID_CHANNEL_ID;
transInfo->channelType = CHANNEL_TYPE_BUTT;
LaneConnInfo connInfo;
ConnectOption connOpt;
(void)memset_s(&connOpt, sizeof(ConnectOption), 0, sizeof(ConnectOption));
AppInfo *appInfo = TransCommonGetAppInfo(param);
TRANS_CHECK_AND_RETURN_RET_LOGW(!(appInfo == NULL), INVALID_CHANNEL_ID, TRANS_CTRL, "GetAppInfo is null.");
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
int32_t peerRet = LnnGetRemoteNodeInfoById(appInfo->peerNetWorkId, CATEGORY_NETWORK_ID, &nodeInfo);
TransEventExtra extra;
(void)memset_s(&extra, sizeof(TransEventExtra), 0, sizeof(TransEventExtra));
TransBuildTransOpenChannelStartEvent(&extra, appInfo, &nodeInfo, peerRet);
TransSetFirstTokenInfo(appInfo, &extra);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra);
ret = TransGetLaneInfo(param, &connInfo, &laneHandle);
if (ret != SOFTBUS_OK) {
SoftbusReportTransErrorEvt(SOFTBUS_TRANS_GET_LANE_INFO_ERR);
@ -257,7 +257,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
ret = TransGetConnectOptByConnInfo(&connInfo, &connOpt);
if (ret != SOFTBUS_OK) {
SoftbusRecordOpenSessionKpi(appInfo->myData.pkgName, connInfo.type,
SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - timeStart);
SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - appInfo->timeStart);
goto EXIT_ERR;
}
appInfo->connectType = connOpt.type;
@ -275,7 +275,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
if (ret != SOFTBUS_OK) {
SoftbusReportTransErrorEvt(SOFTBUS_TRANS_CREATE_CHANNEL_ERR);
SoftbusRecordOpenSessionKpi(appInfo->myData.pkgName,
appInfo->linkType, SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - timeStart);
appInfo->linkType, SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - appInfo->timeStart);
goto EXIT_ERR;
}
TransUpdateSocketChannelInfoBySession(
@ -288,7 +288,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
} else if (TransLaneMgrAddLane(transInfo->channelId, transInfo->channelType, &connInfo,
laneHandle, param->isQosLane, &appInfo->myData) != SOFTBUS_OK) {
SoftbusRecordOpenSessionKpi(appInfo->myData.pkgName,
appInfo->linkType, SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - timeStart);
appInfo->linkType, SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - appInfo->timeStart);
TransCloseChannel(NULL, transInfo->channelId, transInfo->channelType);
goto EXIT_ERR;
}
@ -297,7 +297,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
transInfo->channelId, transInfo->channelType);
return SOFTBUS_OK;
EXIT_ERR:
TransBuildTransOpenChannelEndEvent(&extra, transInfo, timeStart, ret);
TransBuildTransOpenChannelEndEvent(&extra, transInfo, appInfo->timeStart, ret);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
TransAlarmExtra extraAlarm;
TransBuildTransAlarmEvent(&extraAlarm, appInfo, ret);
@ -310,7 +310,7 @@ EXIT_ERR:
TRANS_LOGE(TRANS_SVC, "server TransOpenChannel err, ret=%{public}d", ret);
return ret;
EXIT_CANCEL:
TransBuildTransOpenChannelCancelEvent(&extra, transInfo, timeStart, SOFTBUS_TRANS_STOP_BIND_BY_CANCEL);
TransBuildTransOpenChannelCancelEvent(&extra, transInfo, appInfo->timeStart, SOFTBUS_TRANS_STOP_BIND_BY_CANCEL);
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
TransFreeAppInfo(appInfo);
TransFreeLane(laneHandle, param->isQosLane);

View File

@ -134,7 +134,7 @@ int32_t OnProxyChannelOpened(int32_t channelId, const AppInfo *appInfo, unsigned
.errcode = ret,
.result = (ret == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED
};
extra.osType = appInfo->osType;
extra.osType = (appInfo->osType < 0) ? UNKNOW_OS_TYPE : appInfo->osType;
extra.peerUdid = appInfo->peerUdid;
if (!isServer) {
extra.peerUdid = appInfo->appType == APP_TYPE_AUTH ? appInfo->peerData.deviceId : NULL;
@ -204,7 +204,7 @@ int32_t OnProxyChannelOpenFailed(int32_t channelId, const AppInfo *appInfo, int3
.callerPkg = appInfo->myData.pkgName,
.socketName = appInfo->myData.sessionName,
.peerUdid = appInfo->peerUdid,
.osType = appInfo->osType,
.osType = (appInfo->osType < 0) ? UNKNOW_OS_TYPE : appInfo->osType,
.result = EVENT_STAGE_RESULT_FAILED
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
@ -292,6 +292,10 @@ static int32_t TransProxyGetAppInfo(const char *sessionName, const char *peerNet
TRANS_LOGE(TRANS_CTRL, "strcpy_s peer sessionName failed");
return SOFTBUS_STRCPY_ERR;
}
if (strcpy_s(appInfo->peerNetWorkId, sizeof(appInfo->peerNetWorkId), peerNetworkId) != EOK) {
TRANS_LOGE(TRANS_CTRL, "strcpy_s peerNetworkId failed");
return SOFTBUS_STRCPY_ERR;
}
ret = LnnGetRemoteStrInfo(peerNetworkId, STRING_KEY_UUID,
appInfo->peerData.deviceId, sizeof(appInfo->peerData.deviceId));

View File

@ -680,6 +680,7 @@ static inline void TransProxyProcessErrMsg(ProxyChannelInfo *info, int32_t errCo
}
if ((info->appInfo.appType == APP_TYPE_NORMAL) || (info->appInfo.appType == APP_TYPE_AUTH)) {
TransProxyDelChanByChanId(info->channelId);
(void)TransProxyOpenProxyChannelFail(info->channelId, &(info->appInfo), errCode);
}
}
@ -708,7 +709,7 @@ static int32_t TransProxyGetAppInfo(int16_t myId, AppInfo *appInfo)
return SOFTBUS_ERR;
}
static int32_t TransProxyGetReqId(int32_t myId, int32_t *reqId)
static int32_t TransProxyGetReqIdAndStatus(int32_t myId, int32_t *reqId, int8_t *status)
{
TRANS_CHECK_AND_RETURN_RET_LOGE(
g_proxyChannelList != NULL, SOFTBUS_NO_INIT, TRANS_CTRL, "proxy channel list not init");
@ -719,6 +720,7 @@ static int32_t TransProxyGetReqId(int32_t myId, int32_t *reqId)
LIST_FOR_EACH_ENTRY(item, &g_proxyChannelList->list, ProxyChannelInfo, node) {
if (item->myId == myId) {
*reqId = item->reqId;
*status = item->status;
(void)SoftBusMutexUnlock(&g_proxyChannelList->lock);
return SOFTBUS_OK;
}
@ -1307,7 +1309,7 @@ void TransProxyProcessResetMsg(const ProxyMessage *msg)
return;
}
if (TransProxyGetReqId(info->myId, &info->reqId) != SOFTBUS_OK) {
if (TransProxyGetReqIdAndStatus(info->myId, &info->reqId, &info->status) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "fail to get conn reqId");
SoftBusFree(info);
return;

View File

@ -52,7 +52,7 @@ static void OnSessionOpenFailProc(const SessionConn *node, int32_t errCode)
.linkType = node->appInfo.connectType,
.costTime = (int32_t)timeDiff,
.errcode = errCode,
.osType = node->appInfo.osType,
.osType = (node->appInfo.osType < 0) ? UNKNOW_OS_TYPE : node->appInfo.osType,
.peerUdid = node->appInfo.peerUdid,
.result = EVENT_STAGE_RESULT_FAILED
};
@ -236,6 +236,7 @@ void TransTdcDeathCallback(const char *pkgName, int32_t pid)
TRANS_LOGI(TRANS_CTRL, "delete pkgName = %{public}s, pid = %{public}d", pkgName, pid);
sessionList->cnt--;
DelTrigger(item->listenMod, item->appInfo.fd, RW_TRIGGER);
ConnShutdownSocket(item->appInfo.fd);
SoftBusFree(item);
continue;
}

View File

@ -467,7 +467,7 @@ int32_t NotifyChannelOpenFailed(int32_t channelId, int32_t errCode)
.linkType = conn.appInfo.connectType,
.costTime = timediff,
.errcode = errCode,
.osType = conn.appInfo.osType,
.osType = (conn.appInfo.osType < 0) ? UNKNOW_OS_TYPE : (conn.appInfo.osType),
.peerUdid = conn.appInfo.peerUdid,
.result = EVENT_STAGE_RESULT_FAILED
};
@ -604,11 +604,9 @@ static int32_t OpenDataBusReply(int32_t channelId, uint64_t seq, const cJSON *re
TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d", channelId);
SessionConn conn;
(void)memset_s(&conn, sizeof(SessionConn), 0, sizeof(SessionConn));
if (GetSessionConnById(channelId, &conn) == NULL) {
TRANS_LOGE(TRANS_CTRL, "notify channel open failed, get tdcInfo is null");
return SOFTBUS_TRANS_GET_SESSION_CONN_FAILED;
}
int errCode = SOFTBUS_OK;
TRANS_CHECK_AND_RETURN_RET_LOGE(GetSessionConnById(channelId, &conn) != NULL,
SOFTBUS_TRANS_GET_SESSION_CONN_FAILED, TRANS_CTRL, "notify channel open failed, get tdcInfo is null");
int32_t errCode = SOFTBUS_OK;
if (UnpackReplyErrCode(reply, &errCode) == SOFTBUS_OK) {
TransEventExtra extra = {
.socketName = NULL,
@ -617,49 +615,31 @@ static int32_t OpenDataBusReply(int32_t channelId, uint64_t seq, const cJSON *re
.callerPkg = NULL,
.channelId = channelId,
.errcode = errCode,
.result = EVENT_STAGE_RESULT_FAILED
};
.result = EVENT_STAGE_RESULT_FAILED };
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
TRANS_LOGE(TRANS_CTRL, "receive err reply msg");
if (NotifyChannelOpenFailed(channelId, errCode) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "channel open failed");
return SOFTBUS_ERR;
}
int32_t status = NotifyChannelOpenFailed(channelId, errCode);
TRANS_CHECK_AND_RETURN_RET_LOGE(status == SOFTBUS_OK, status, TRANS_CTRL, "channel open failed.");
return errCode;
}
uint16_t fastDataSize = 0;
if (UnpackReply(reply, &conn.appInfo, &fastDataSize) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "UnpackReply failed");
return SOFTBUS_TRANS_UNPACK_REPLY_FAILED;
}
int32_t ret = SOFTBUS_ERR;
ret = TransTdcProcessDataConfig(&conn.appInfo);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "Trans Tdc process data config failed.");
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(UnpackReply(reply, &conn.appInfo, &fastDataSize) == SOFTBUS_OK,
SOFTBUS_TRANS_UNPACK_REPLY_FAILED, TRANS_CTRL, "UnpackReply failed");
int32_t ret = TransTdcProcessDataConfig(&conn.appInfo);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "Trans Tdc process data config failed.");
ret = SetAppInfoById(channelId, &conn.appInfo);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "set app info by id failed.");
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "set app info by id failed.");
if ((fastDataSize > 0 && (conn.appInfo.fastTransDataSize == fastDataSize)) || conn.appInfo.fastTransDataSize == 0) {
ret = NotifyChannelOpened(channelId);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "notify channel open failed");
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "notify channel open failed");
} else {
ret = TransTdcPostFisrtData(&conn);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "tdc send fast data failed");
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "tdc send fast data failed");
ret = NotifyChannelOpened(channelId);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "notify channel open failed");
return ret;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "notify channel open failed");
}
TransEventExtra extra = {
.socketName = NULL,

View File

@ -25,6 +25,7 @@
#include "softbus_adapter_mem.h"
#include "softbus_base_listener.h"
#include "softbus_conn_common.h"
#include "softbus_conn_interface.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_proxychannel_pipeline.h"
@ -410,17 +411,24 @@ static void OnAuthConnOpenFailed(uint32_t requestId, int32_t reason)
TRANS_LOGW(TRANS_CTRL, "ok");
}
static int32_t OpenAuthConn(const char *uuid, uint32_t reqId, bool isMeta)
static int32_t OpenAuthConn(const char *uuid, uint32_t reqId, bool isMeta, ConnectType type)
{
TRANS_LOGI(TRANS_CTRL, "reqId=%{public}u", reqId);
AuthConnInfo auth;
(void)memset_s(&auth, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
AuthConnCallback cb;
(void)memset_s(&cb, sizeof(AuthConnCallback), 0, sizeof(AuthConnCallback));
int32_t ret = AuthGetP2pConnInfo(uuid, &auth, isMeta);
if (ret != SOFTBUS_OK && AuthGetPreferConnInfo(uuid, &auth, isMeta) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "get auth info fail");
return SOFTBUS_ERR;
int32_t ret = SOFTBUS_ERR;
if (type == CONNECT_HML) {
TRANS_LOGI(TRANS_CTRL, "get AuthConnInfo, linkType=%{public}d", type);
ret = AuthGetHmlConnInfo(uuid, &auth, isMeta);
}
if (ret != SOFTBUS_OK && type == CONNECT_P2P) {
TRANS_LOGI(TRANS_CTRL, "get AuthConnInfo, linkType=%{public}d", type);
ret = AuthGetP2pConnInfo(uuid, &auth, isMeta);
}
if (ret != SOFTBUS_OK) {
ret = AuthGetPreferConnInfo(uuid, &auth, isMeta);
}
cb.onConnOpened = OnAuthConnOpened;
cb.onConnOpenFailed = OnAuthConnOpenFailed;
@ -760,9 +768,9 @@ static void OnAuthChannelClose(AuthHandle authHandle)
}
static int32_t OpenNewAuthConn(const AppInfo *appInfo, SessionConn *conn,
int32_t newChannelId, uint32_t requestId)
int32_t newChannelId, ConnectType type)
{
int32_t ret = OpenAuthConn(appInfo->peerData.deviceId, requestId, conn->isMeta);
int32_t ret = OpenAuthConn(appInfo->peerData.deviceId, conn->requestId, conn->isMeta, type);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "OpenP2pDirectChannel open auth conn fail");
return ret;
@ -812,7 +820,7 @@ static int32_t TransProxyGetAuthId(SessionConn *conn)
}
static int32_t StartVerifyP2pInfo(const AppInfo *appInfo, SessionConn *conn)
static int32_t StartVerifyP2pInfo(const AppInfo *appInfo, SessionConn *conn, ConnectType type)
{
int32_t ret = SOFTBUS_ERR;
int32_t newChannelId = conn->channelId;
@ -822,7 +830,10 @@ static int32_t StartVerifyP2pInfo(const AppInfo *appInfo, SessionConn *conn)
uint32_t requestId = AuthGenRequestId();
conn->status = TCP_DIRECT_CHANNEL_STATUS_AUTH_CHANNEL;
conn->requestId = requestId;
ret = OpenNewAuthConn(appInfo, conn, newChannelId, conn->requestId);
if (type == CONNECT_P2P_REUSE) {
type = (strncmp(appInfo->myData.addr, HML_IP_PREFIX, NETWORK_ID_LEN) == 0) ? CONNECT_HML : CONNECT_P2P;
}
ret = OpenNewAuthConn(appInfo, conn, newChannelId, type);
} else {
ret = TransProxyReuseByChannelId(pipeLineChannelId);
if (ret != SOFTBUS_OK) {
@ -894,7 +905,6 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
}
SessionConn *conn = NULL;
int32_t ret = SOFTBUS_ERR;
conn = CreateNewSessinConn(DIRECT_CHANNEL_SERVER_P2P, false);
if (conn == NULL) {
TRANS_LOGE(TRANS_CTRL, "create new sessin conn fail");
@ -925,14 +935,12 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
TRANS_LOGE(TRANS_CTRL, "start listener fail");
return ret;
}
uint64_t seq = TransTdcGetNewSeqId();
if (seq == INVALID_SEQ_ID) {
FreeFastTransData(&(conn->appInfo));
SoftBusFree(conn);
return SOFTBUS_ERR;
}
conn->req = (int64_t)seq;
conn->isMeta = TransGetAuthTypeByNetWorkId(appInfo->peerNetWorkId);
ret = TransTdcAddSessionConn(conn);
@ -941,7 +949,7 @@ int32_t OpenP2pDirectChannel(const AppInfo *appInfo, const ConnectOption *connIn
SoftBusFree(conn);
return ret;
}
ret = StartVerifyP2pInfo(appInfo, conn);
ret = StartVerifyP2pInfo(appInfo, conn, connInfo->type);
if (ret != SOFTBUS_OK) {
TransDelSessionConnById(conn->channelId);
TRANS_LOGE(TRANS_CTRL, "StartVerifyP2pInfo fail, ret=%{public}d", ret);

View File

@ -68,6 +68,7 @@ void TransUpdateUdpChannelInfo(int64_t seq, const AppInfo *appInfo);
UdpChannelInfo *TransGetChannelObj(int32_t channelId);
int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo);
int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo);
#ifdef __cplusplus
}

View File

@ -516,3 +516,34 @@ int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo)
TRANS_LOGE(TRANS_CTRL, "udp channel not found. channelId=%{public}d", channelId);
return SOFTBUS_NOT_FIND;
}
int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo)
{
if (appInfo == NULL) {
TRANS_LOGE(TRANS_INIT, "Invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (g_udpChannelMgr == NULL) {
TRANS_LOGE(TRANS_INIT, "udp channel manager hasn't init.");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&(g_udpChannelMgr->lock)) != SOFTBUS_OK) {
return SOFTBUS_LOCK_ERR;
}
UdpChannelInfo *udpChannelNode = NULL;
LIST_FOR_EACH_ENTRY(udpChannelNode, &(g_udpChannelMgr->list), UdpChannelInfo, node) {
if (udpChannelNode->info.peerData.channelId == appInfo->peerData.channelId) {
if (strcmp(udpChannelNode->info.peerData.addr, appInfo->peerData.addr) == EOK) {
appInfo->myData.channelId = udpChannelNode->info.myData.channelId;
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
return SOFTBUS_OK;
}
}
}
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
TRANS_LOGE(TRANS_CTRL, "not found peerChannelId and addr");
return SOFTBUS_NOT_FIND;
}

View File

@ -85,7 +85,7 @@ void ReleaseUdpChannelId(int32_t channelId)
return;
}
uint32_t id = (uint32_t)channelId;
g_channelIdFlagBitsMap &= (~(ID_USED << id));
g_channelIdFlagBitsMap &= (~(ID_USED << (uint64_t)id));
SoftBusMutexUnlock(&g_udpNegLock);
}
@ -190,7 +190,7 @@ int32_t NotifyUdpChannelOpenFailed(const AppInfo *info, int32_t errCode)
.linkType = info->connectType,
.costTime = timediff,
.errcode = errCode,
.osType = info->osType,
.osType = (info->osType < 0) ? UNKNOW_OS_TYPE : info->osType,
.peerUdid = info->peerUdid,
.result = EVENT_STAGE_RESULT_FAILED
};
@ -838,6 +838,9 @@ static int32_t UdpOpenAuthConn(const char *peerUdid, uint32_t requestId, bool is
int32_t ret = SOFTBUS_ERR;
if (linkType == LANE_HML || linkType == LANE_P2P_REUSE) {
TRANS_LOGI(TRANS_CTRL, "get AuthConnInfo, linkType=%{public}d", linkType);
ret = AuthGetHmlConnInfo(peerUdid, &auth, isMeta);
}
if (ret != SOFTBUS_OK && (linkType == LANE_P2P || linkType == LANE_P2P_REUSE)) {
ret = AuthGetP2pConnInfo(peerUdid, &auth, isMeta);
}
if (ret != SOFTBUS_OK) {

View File

@ -22,6 +22,7 @@
#include "softbus_errcode.h"
#include "softbus_json_utils.h"
#include "trans_log.h"
#include "trans_udp_channel_manager.h"
#define BASE64_SESSION_KEY_LEN 45
typedef enum {
@ -99,19 +100,16 @@ int32_t TransUnpackReplyUdpInfo(const cJSON *msg, AppInfo *appInfo)
int32_t TransUnpackRequestUdpInfo(const cJSON *msg, AppInfo *appInfo)
{
TRANS_LOGI(TRANS_CTRL, "unpack request udp info in negotiation.");
if (msg == NULL || appInfo == NULL) {
TRANS_LOGW(TRANS_CTRL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
TRANS_CHECK_AND_RETURN_RET_LOGW(msg != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "Invalid param");
TRANS_CHECK_AND_RETURN_RET_LOGW(appInfo != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "Invalid param");
unsigned char encodeSessionKey[BASE64_SESSION_KEY_LEN] = {0};
size_t len = 0;
(void)GetJsonObjectStringItem(msg, "SESSION_KEY", (char*)encodeSessionKey, BASE64_SESSION_KEY_LEN);
int32_t ret = SoftBusBase64Decode((unsigned char*)appInfo->sessionKey, sizeof(appInfo->sessionKey), &len,
(unsigned char*)encodeSessionKey, strlen((char*)encodeSessionKey));
if (len != sizeof(appInfo->sessionKey) || ret != 0) {
TRANS_LOGE(TRANS_CTRL, "mbedtls decode failed.");
return SOFTBUS_DECRYPT_ERR;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(len == sizeof(appInfo->sessionKey),
SOFTBUS_DECRYPT_ERR, TRANS_CTRL, "mbedtls decode failed.");
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == 0, SOFTBUS_DECRYPT_ERR, TRANS_CTRL, "mbedtls decode failed.");
(void)GetJsonObjectStringItem(msg, "PKG_NAME", appInfo->peerData.pkgName, PKG_NAME_SIZE_MAX);
(void)GetJsonObjectStringItem(msg, "BUS_NAME", appInfo->myData.sessionName, SESSION_NAME_SIZE_MAX);
@ -142,6 +140,11 @@ int32_t TransUnpackRequestUdpInfo(const cJSON *msg, AppInfo *appInfo)
break;
case TYPE_UDP_CHANNEL_CLOSE:
(void)GetJsonObjectNumber64Item(msg, "PEER_CHANNEL_ID", &(appInfo->myData.channelId));
(void)GetJsonObjectNumber64Item(msg, "MY_CHANNEL_ID", &(appInfo->peerData.channelId));
(void)GetJsonObjectStringItem(msg, "MY_IP", appInfo->peerData.addr, sizeof(appInfo->peerData.addr));
if (appInfo->myData.channelId == 0) {
(void)TransUdpGetChannelIdByAddr(appInfo);
}
break;
default:
TRANS_LOGE(TRANS_CTRL, "invalid udp channel type.");
@ -166,6 +169,8 @@ int32_t TransPackRequestUdpInfo(cJSON *msg, const AppInfo *appInfo)
break;
case TYPE_UDP_CHANNEL_CLOSE:
(void)AddNumber64ToJsonObject(msg, "PEER_CHANNEL_ID", appInfo->peerData.channelId);
(void)AddNumber64ToJsonObject(msg, "MY_CHANNEL_ID", appInfo->myData.channelId);
(void)AddStringToJsonObject(msg, "MY_IP", appInfo->myData.addr);
break;
default:
TRANS_LOGE(TRANS_CTRL, "invalid udp channel type.");

View File

@ -136,6 +136,7 @@ BUSCENTER_BEHAVIOR:
LNN_TYPE: { type: INT32, desc: lnn type }
ONLINE_NUM: { type: INT32, desc: current online device num }
PEER_DEV_ABILITY: { type: INT32, desc: peer device ability }
ONLINE_TYPE: { type: INT32, desc: online type }
PEER_DEV_INFO: { type: STRING, desc: peer device lnn info }
PEER_IP: { type: STRING, desc: peer device ip }
PEER_BR_MAC: { type: STRING, desc: peer device br mac }

View File

@ -328,6 +328,7 @@ enum SoftBusErrNo {
SOFTBUS_AUTH_START_ERR,
SOFTBUS_AUTH_EXCHANGE_DEVICE_INFO_START_ERR,
SOFTBUS_AUTH_NOT_SUPPORT_NORMALIZE,
SOFTBUS_AUTH_NOT_SUPPORT_THREE_STATE,
SOFTBUS_AUTH_SESSION_KEY_INVALID,
SOFTBUS_AUTH_SESSION_KEY_TOO_OLD,
@ -380,6 +381,8 @@ enum SoftBusErrNo {
SOFTBUS_KV_UNREGISTER_SYNC_LISTENER_FAILED,
SOFTBUS_KV_REGISTER_DATA_LISTENER_FAILED,
SOFTBUS_KV_UNREGISTER_DATA_LISTENER_FAILED,
SOFTBUS_KV_CONVERT_STRING_FAILED,
SOFTBUS_KV_CONVERT_BYTES_FAILED,
/* errno begin: -((203 << 21) | (4 << 16) | (1 << 12) | 0x0FFF) */
SOFTBUS_LANE_ERR_BASE = SOFTBUS_SUB_ERRNO(LNN_SUB_MODULE_CODE, LNN_LANE_MODULE_CODE),
@ -389,8 +392,16 @@ enum SoftBusErrNo {
SOFTBUS_LANE_DETECT_FAIL,
SOFTBUS_LANE_ID_GENERATE_FAIL,
SOFTBUS_LANE_GUIDE_BUILD_FAIL,
SOFTBUS_LANE_NOT_FIND,
SOFTBUS_LANE_RESOURCE_NOT_FIND,
SOFTBUS_LANE_NOT_FOUND,
SOFTBUS_LANE_RESOURCE_NOT_FOUND,
SOFTBUS_LANE_NO_AVAILABLE_LINK,
SOFTBUS_LANE_GET_LINK_SCORE_ERR,
SOFTBUS_LANE_BUILD_LINK_FAIL,
SOFTBUS_LANE_BUILD_LINK_TIMEOUT,
SOFTBUS_LANE_DETECT_TIMEOUT,
SOFTBUS_LANE_GUIDE_NO_AVAILABLE_LINK,
SOFTBUS_LANE_RESULT_REPORT_ERR,
SOFTBUS_LANE_LIST_ERR,
/* errno begin: -((203 << 21) | (2 << 16) | 0xFFFF) */
SOFTBUS_CONN_ERR_BASE = SOFTBUS_ERRNO(CONN_SUB_MODULE_CODE),

View File

@ -126,6 +126,10 @@ target(build_type, "softbus_client") {
"ipc:ipc_single",
]
}
if (defined(global_parts_info) &&
defined(global_parts_info.hiviewdfx_hicollie)) {
external_deps += [ "hicollie:libhicollie" ]
}
innerapi_tags = [ "platformsdk_indirect" ]
part_name = "dsoftbus"
subsystem_name = "communication"

View File

@ -504,6 +504,10 @@
"UpdateChannelStatistics";
"SetTimer";
"CancelTimer";
"RegistDirSchema";
"UnregistDirSchema";
"TransRegistDirSchema";
"TransUnRegistDirSchema";
extern "C++" {
OHOS::StreamAdaptor*;
Communication::SoftBus*;

View File

@ -27,6 +27,7 @@
#include "trans_log.h"
#define DFX_TIMERS_S 15
#define RETRY_GET_INFO_TIMES_MS 300
static IClientSessionCallBack g_sessionCb;
@ -273,7 +274,7 @@ NO_SANITIZE("cfi") int32_t TransOnSessionOpened(const char *sessionName, const C
} else {
ret = ClientEnableSessionByChannelId(channel, &sessionId);
if (ret == SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND) {
SoftBusSleepMs(300); // avoid set channel info later than sesssion opened callback
SoftBusSleepMs(RETRY_GET_INFO_TIMES_MS); // avoid set channel info later than sesssion opened callback
ret = ClientEnableSessionByChannelId(channel, &sessionId);
}
}

View File

@ -460,13 +460,15 @@ void NotifyAuthSuccess(int sessionId)
}
}
static int32_t CheckSessionIsOpened(int32_t sessionId)
static int32_t CheckSessionIsOpened(int32_t sessionId, bool isCancelCheck)
{
#define SESSION_STATUS_CHECK_MAX_NUM 100
#define SESSION_STATUS_CANCEL_CHECK_MAX_NUM 25
#define SESSION_CHECK_PERIOD 200000
int32_t checkMaxNum = isCancelCheck ? SESSION_STATUS_CANCEL_CHECK_MAX_NUM : SESSION_STATUS_CHECK_MAX_NUM;
int32_t i = 0;
SessionEnableStatus enableStatus = ENABLE_STATUS_INIT;
while (i < SESSION_STATUS_CHECK_MAX_NUM) {
while (i < checkMaxNum) {
if (ClientGetChannelBySessionId(sessionId, NULL, NULL, &enableStatus) != SOFTBUS_OK) {
return SOFTBUS_TRANS_SESSION_GET_CHANNEL_FAILED;
}
@ -512,7 +514,7 @@ int OpenSessionSync(const char *mySessionName, const char *peerSessionName, cons
if (ret != SOFTBUS_OK) {
if (ret == SOFTBUS_TRANS_SESSION_REPEATED) {
TRANS_LOGI(TRANS_SDK, "session already opened");
CheckSessionIsOpened(sessionId);
CheckSessionIsOpened(sessionId, false);
return OpenSessionWithExistSession(sessionId, isEnabled);
}
TRANS_LOGE(TRANS_SDK, "add session err: ret=%{public}d", ret);
@ -534,7 +536,7 @@ int OpenSessionSync(const char *mySessionName, const char *peerSessionName, cons
return SOFTBUS_TRANS_SESSION_SET_CHANNEL_FAILED;
}
ret = CheckSessionIsOpened(sessionId);
ret = CheckSessionIsOpened(sessionId, false);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "CheckSessionIsOpened err: ret=%{public}d", ret);
(void)ClientDeleteSession(sessionId);
@ -1154,7 +1156,7 @@ void ClientShutdown(int32_t socket, int32_t cancelReason)
lifecycle.sessionState == SESSION_STATE_CALLBACK_FINISHED) {
if (lifecycle.sessionState == SESSION_STATE_OPENED) {
TRANS_LOGI(TRANS_SDK, "This socket state is opened, socket=%{public}d", socket);
CheckSessionIsOpened(socket);
CheckSessionIsOpened(socket, true);
}
TRANS_LOGI(TRANS_SDK, "This socket state is callback finish, socket=%{public}d", socket);
int32_t channelId = INVALID_CHANNEL_ID;

View File

@ -55,7 +55,9 @@ if (defined(ohos_lite)) {
"$dsoftbus_root_path/sdk/transmission/session/cpp/src/session_mock.cpp",
"$dsoftbus_root_path/sdk/transmission/session/cpp/src/session_service_impl.cpp",
]
if (is_standard_system) {
if (defined(global_parts_info) &&
defined(global_parts_info.hiviewdfx_hicollie)) {
trans_session_sdk_src += [ "$dsoftbus_root_path/sdk/transmission/session/cpp/src/session_set_timer.cpp" ]
} else {
trans_session_sdk_src += [ "$dsoftbus_root_path/sdk/transmission/session/cpp/src/session_set_timer_virtual.c" ]

View File

@ -1050,19 +1050,13 @@ EXIT_ERR:
static int32_t FileToFrameAndSendFile(SendListenerInfo *sendInfo, const char *sourceFile, const char *destFile)
{
#define RETRY_READ_LOCK_TIMES 2
if (sendInfo == NULL) {
TRANS_LOGW(TRANS_FILE, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
if (CheckDestFilePathValid(destFile) == false) {
TRANS_CHECK_AND_RETURN_RET_LOGE(sendInfo != NULL, SOFTBUS_INVALID_PARAM, TRANS_FILE, "invalid param.");
if (!CheckDestFilePathValid(destFile)) {
TRANS_LOGE(TRANS_FILE, "dest path is wrong. channelId=%{public}d", sendInfo->channelId);
return SOFTBUS_FILE_ERR;
}
char *absSrcPath = (char *)SoftBusCalloc(PATH_MAX + 1);
if (absSrcPath == NULL) {
TRANS_LOGE(TRANS_FILE, "calloc absFullDir fail");
return SOFTBUS_FILE_ERR;
}
TRANS_CHECK_AND_RETURN_RET_LOGE(absSrcPath != NULL, SOFTBUS_MALLOC_ERR, TRANS_FILE, "calloc absFullDir failed");
if (GetAndCheckRealPath(sourceFile, absSrcPath) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "get src abs file fail. channelId=%{public}d", sendInfo->channelId);
SoftBusFree(absSrcPath);
@ -1329,33 +1323,9 @@ static void ReleaseSendListenerInfo(SendListenerInfo *sendInfo)
DelSendListenerInfo(sendInfo);
}
int32_t ProxyChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt)
static void HandleFileSendingProcess(
int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt)
{
TRANS_LOGI(TRANS_FILE, "proxy send file trans start");
if ((fileCnt == 0) || (fileCnt > MAX_SEND_FILE_NUM)) {
TRANS_LOGE(TRANS_FILE, "sendfile arg filecnt=%{public}d error", fileCnt);
return SOFTBUS_INVALID_PARAM;
}
if (sFileList == NULL || !IsValidFileString(sFileList, fileCnt, MAX_FILE_PATH_NAME_LEN)) {
TRANS_LOGE(TRANS_FILE, "sendfile invalid arg sFileList");
return SOFTBUS_INVALID_PARAM;
}
if (dFileList == NULL || !IsValidFileString(dFileList, fileCnt, MAX_FILE_PATH_NAME_LEN)) {
TRANS_LOGE(TRANS_FILE, "sendfile invalid arg dFileList");
return SOFTBUS_INVALID_PARAM;
}
ProxyFileMutexLock *sessionLock = GetSessionFileLock(channelId);
if (sessionLock == NULL) {
TRANS_LOGE(TRANS_FILE, "proxy send file get file lock failed");
return SOFTBUS_LOCK_ERR;
}
if (SoftBusMutexLock(&sessionLock->sendLock) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "proxy send file lock file mutex failed");
DelSessionFileLock(sessionLock);
return SOFTBUS_LOCK_ERR;
}
SendListenerInfo *sendInfo = NULL;
int32_t ret = SOFTBUS_FILE_ERR;
do {
@ -1394,10 +1364,35 @@ int32_t ProxyChannelSendFile(int32_t channelId, const char *sFileList[], const c
ReleaseSendListenerInfo(sendInfo);
sendInfo = NULL;
}
}
int32_t ProxyChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt)
{
TRANS_LOGI(TRANS_FILE, "proxy send file trans start");
if (fileCnt == 0 || fileCnt > MAX_SEND_FILE_NUM) {
TRANS_LOGE(TRANS_FILE, "sendfile arg filecnt=%{public}u error", fileCnt);
return SOFTBUS_INVALID_PARAM;
}
if (sFileList == NULL || !IsValidFileString(sFileList, fileCnt, MAX_FILE_PATH_NAME_LEN)) {
TRANS_LOGE(TRANS_FILE, "sendfile invalid arg sFileList");
return SOFTBUS_INVALID_PARAM;
}
if (dFileList == NULL || !IsValidFileString(dFileList, fileCnt, MAX_FILE_PATH_NAME_LEN)) {
TRANS_LOGE(TRANS_FILE, "sendfile invalid arg dFileList");
return SOFTBUS_INVALID_PARAM;
}
ProxyFileMutexLock *sessionLock = GetSessionFileLock(channelId);
TRANS_CHECK_AND_RETURN_RET_LOGE(sessionLock != NULL, SOFTBUS_LOCK_ERR, TRANS_FILE, "get file lock failed");
if (SoftBusMutexLock(&sessionLock->sendLock) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "proxy send file lock file mutex failed");
DelSessionFileLock(sessionLock);
return SOFTBUS_LOCK_ERR;
}
HandleFileSendingProcess(channelId, sFileList, dFileList, fileCnt);
(void)SoftBusMutexUnlock(&sessionLock->sendLock);
DelSessionFileLock(sessionLock);
return ret;
return SOFTBUS_OK;
}
static bool CheckRecvFileExist(const char *absFullPath)
@ -1708,6 +1703,25 @@ static FileRecipientInfo *GetRecipientInfo(int32_t sessionId)
return recipient;
}
static void HandleFileTransferCompletion(FileRecipientInfo *recipient, int32_t sessionId, SingleFileInfo *file)
{
TRANS_CHECK_AND_RETURN_LOGE(recipient != NULL && file != NULL, TRANS_FILE, "recipient or file invalid.");
if (recipient->fileListener.socketRecvCallback != NULL) {
const char *fileList[] = { file->filePath };
FileEvent event = {
.type = FILE_EVENT_RECV_START,
.files = fileList,
.fileCnt = 1,
.bytesProcessed = file->fileSize,
.bytesTotal = file->fileSize,
.UpdateRecvPath = NULL,
};
recipient->fileListener.socketRecvCallback(sessionId, &event);
} else if (recipient->fileListener.recvListener.OnReceiveFileStarted != NULL) {
recipient->fileListener.recvListener.OnReceiveFileStarted(sessionId, file->filePath, 1);
}
}
static int32_t CreateFileFromFrame(int32_t sessionId, int32_t channelId, const FileFrame *fileFrame)
{
FileRecipientInfo *recipient = GetRecipientInCreateFileRef(sessionId, channelId);
@ -1730,20 +1744,7 @@ static int32_t CreateFileFromFrame(int32_t sessionId, int32_t channelId, const F
TRANS_LOGE(TRANS_FILE, "put to recv files failed. sessionId=%{public}u", recipient->sessionId);
goto EXIT_ERR;
}
if (recipient->fileListener.socketRecvCallback != NULL) {
const char *fileList[] = { file->filePath };
FileEvent event = {
.type = FILE_EVENT_RECV_START,
.files = fileList,
.fileCnt = 1,
.bytesProcessed = file->fileSize,
.bytesTotal = file->fileSize,
.UpdateRecvPath = NULL,
};
recipient->fileListener.socketRecvCallback(sessionId, &event);
} else if (recipient->fileListener.recvListener.OnReceiveFileStarted != NULL) {
recipient->fileListener.recvListener.OnReceiveFileStarted(sessionId, file->filePath, 1);
}
HandleFileTransferCompletion(recipient, sessionId, file);
ReleaseRecipientRef(recipient);
SoftBusFree(file);
if (recipient->crc == APP_INFO_FILE_FEATURES_SUPPORT) {
@ -1794,21 +1795,12 @@ static int32_t WriteEmptyFrame(SingleFileInfo *fileInfo, int32_t count)
return SOFTBUS_OK;
}
static int32_t ProcessOneFrameCRC(const FileFrame *frame, uint32_t dataLen, SingleFileInfo *fileInfo)
static int32_t ProcessFileFrameSequence(uint64_t *fileOffset, const FileFrame *frame, SingleFileInfo *fileInfo)
{
if ((frame == NULL) || (fileInfo == NULL)) {
TRANS_LOGW(TRANS_FILE, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
uint32_t seq = frame->seq;
if (seq < 1 || seq >= fileInfo->startSeq + FILE_SEND_ACK_INTERVAL) {
return SOFTBUS_FILE_ERR;
}
uint64_t fileOffset = 0;
uint32_t bit = seq % FILE_SEND_ACK_INTERVAL;
uint32_t bit = frame->seq % FILE_SEND_ACK_INTERVAL;
bit = ((bit == 0) ? (FILE_SEND_ACK_INTERVAL - 1) : (bit - 1));
if (seq >= fileInfo->startSeq) {
int64_t seqDiff = (int32_t)(seq - fileInfo->seq - 1);
if (frame->seq >= fileInfo->startSeq) {
int64_t seqDiff = (int32_t)(frame->seq - fileInfo->seq - 1);
if (seqDiff > INT32_MAX) {
TRANS_LOGE(TRANS_FILE, "seqDiff overflow");
return SOFTBUS_INVALID_NUM;
@ -1818,8 +1810,8 @@ static int32_t ProcessOneFrameCRC(const FileFrame *frame, uint32_t dataLen, Sing
TRANS_LOGE(TRANS_FILE, "Data overflow");
return SOFTBUS_INVALID_NUM;
}
int64_t bytesToWrite = seqDiff * (int64_t)fileInfo->oneFrameLen;
if (MAX_FILE_SIZE < bytesToWrite) {
int64_t bytesToWrite = (int64_t)seqDiff * (int64_t)fileInfo->oneFrameLen;
if (bytesToWrite > MAX_FILE_SIZE) {
TRANS_LOGE(
TRANS_FILE, "WriteEmptyFrame bytesToWrite is too large, bytesToWrite=%{public}" PRIu64, bytesToWrite);
return SOFTBUS_FILE_ERR;
@ -1831,21 +1823,36 @@ static int32_t ProcessOneFrameCRC(const FileFrame *frame, uint32_t dataLen, Sing
uint32_t ret = WriteEmptyFrame(fileInfo, (int32_t)seqDiff);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_FILE, "write frame failed");
if ((seq >= fileInfo->preStartSeq + FILE_SEND_ACK_INTERVAL + WAIT_FRAME_ACK_TIMEOUT_COUNT - 1) ||
(frame->frameType == TRANS_SESSION_FILE_LAST_FRAME && seq > FILE_SEND_ACK_INTERVAL)) {
if ((frame->seq >= fileInfo->preStartSeq + FILE_SEND_ACK_INTERVAL + WAIT_FRAME_ACK_TIMEOUT_COUNT - 1) ||
(frame->frameType == TRANS_SESSION_FILE_LAST_FRAME && frame->seq > FILE_SEND_ACK_INTERVAL)) {
if ((fileInfo->preSeqResult & FILE_SEND_ACK_RESULT_SUCCESS) != FILE_SEND_ACK_RESULT_SUCCESS) {
TRANS_LOGE(TRANS_FILE, "recv file fail. frame loss");
return SOFTBUS_FILE_ERR;
}
}
fileInfo->seq = seq;
fileOffset = fileInfo->fileOffset;
fileInfo->seq = frame->seq;
*fileOffset = fileInfo->fileOffset;
fileInfo->seqResult |= 0x01 << bit;
} else {
TRANS_LOGI(TRANS_FILE, "recv retrans file frame");
fileOffset = (seq - 1) * fileInfo->oneFrameLen;
*fileOffset = (frame->seq - 1) * fileInfo->oneFrameLen;
fileInfo->preSeqResult |= 0x01 << bit;
}
return SOFTBUS_OK;
}
static int32_t ProcessOneFrameCRC(const FileFrame *frame, uint32_t dataLen, SingleFileInfo *fileInfo)
{
TRANS_CHECK_AND_RETURN_RET_LOGE(
(frame != NULL && fileInfo != NULL), SOFTBUS_INVALID_PARAM, TRANS_FILE, "invalid param");
if (frame->seq < 1 || frame->seq >= fileInfo->startSeq + FILE_SEND_ACK_INTERVAL) {
return SOFTBUS_FILE_ERR;
}
uint64_t fileOffset = 0;
if (ProcessFileFrameSequence(&fileOffset, frame, fileInfo) != SOFTBUS_OK) {
return SOFTBUS_FILE_ERR;
}
uint32_t frameDataLength = dataLen - FRAME_DATA_SEQ_OFFSET;
@ -1865,7 +1872,7 @@ static int32_t ProcessOneFrameCRC(const FileFrame *frame, uint32_t dataLen, Sing
TRANS_LOGE(TRANS_FILE, "pwrite file failed");
return SOFTBUS_FILE_ERR;
}
if (seq >= fileInfo->startSeq) {
if (frame->seq >= fileInfo->startSeq) {
fileInfo->fileOffset += (uint64_t)writeLength;
if (fileInfo->fileOffset > MAX_FILE_SIZE) {
TRANS_LOGE(TRANS_FILE, "file is too large, offset=%{public}" PRIu64, fileInfo->fileOffset);
@ -1913,24 +1920,9 @@ static int32_t ProcessOneFrame(const FileFrame *fileFrame, uint32_t dataLen, int
return SOFTBUS_OK;
}
static int32_t WriteFrameToFile(int32_t sessionId, const FileFrame *fileFrame)
static int32_t UpdateFileReceptionStatus(
SingleFileInfo *fileInfo, FileRecipientInfo *recipient, const FileFrame *fileFrame, int32_t sessionId)
{
FileRecipientInfo *recipient = GetRecipientInProcessRef(sessionId);
if (recipient == NULL) {
TRANS_LOGE(TRANS_FILE, "get recipient in process ref fail");
return SOFTBUS_NOT_FIND;
}
int32_t result = SOFTBUS_FILE_ERR;
SingleFileInfo *fileInfo = &recipient->recvFileInfo;
uint32_t dataLen;
if (UnpackFileDataFrame(recipient, (FileFrame *)fileFrame, &dataLen) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "unpack file data frame fail");
goto EXIT_ERR;
}
if (ProcessOneFrame(fileFrame, dataLen, recipient->crc, fileInfo) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "write one frame error");
goto EXIT_ERR;
}
fileInfo->timeOut = 0;
if (recipient->fileListener.socketRecvCallback != NULL) {
const char *fileList[] = { fileInfo->filePath };
@ -1953,7 +1945,7 @@ static int32_t WriteFrameToFile(int32_t sessionId, const FileFrame *fileFrame)
TRANS_LOGI(TRANS_FILE, "process last frame, seq=%{public}u", fileFrame->seq);
SetRecipientRecvState(recipient, TRANS_FILE_RECV_IDLE_STATE);
if (SoftBusMutexLock(&g_recvFileInfoLock.lock) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "mutex lock fail");
TRANS_LOGE(TRANS_FILE, "mutex lock failed");
return SOFTBUS_LOCK_ERR;
}
(void)FileUnLock(fileInfo->fileFd);
@ -1962,6 +1954,31 @@ static int32_t WriteFrameToFile(int32_t sessionId, const FileFrame *fileFrame)
(void)SoftBusMutexUnlock(&g_recvFileInfoLock.lock);
}
}
return SOFTBUS_OK;
}
static int32_t WriteFrameToFile(int32_t sessionId, const FileFrame *fileFrame)
{
FileRecipientInfo *recipient = GetRecipientInProcessRef(sessionId);
if (recipient == NULL) {
TRANS_LOGE(TRANS_FILE, "get recipient in process ref failed");
return SOFTBUS_NOT_FIND;
}
int32_t result = SOFTBUS_FILE_ERR;
SingleFileInfo *fileInfo = &recipient->recvFileInfo;
uint32_t dataLen;
if (UnpackFileDataFrame(recipient, (FileFrame *)fileFrame, &dataLen) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "unpack file data frame failed");
goto EXIT_ERR;
}
if (ProcessOneFrame(fileFrame, dataLen, recipient->crc, fileInfo) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "write one frame error");
goto EXIT_ERR;
}
if (UpdateFileReceptionStatus(fileInfo, recipient, fileFrame, sessionId) != SOFTBUS_OK) {
return SOFTBUS_FILE_ERR;
}
ReleaseRecipientRef(recipient);
return SOFTBUS_OK;
EXIT_ERR:

View File

@ -30,6 +30,7 @@ typedef struct {
const char name[SCHEMA_MAX_LENGTH];
int (*OpenFd)(const char *filename, int32_t flag, int32_t mode);
int (*CloseFd)(int32_t fd);
int (*RemoveFd)(const char *pathName);
} FileSchema;
typedef struct {

View File

@ -557,11 +557,33 @@ bool VtpStreamSocket::Connect(const IpAndPort &remote)
return true;
}
bool VtpStreamSocket::EncryptStreamPacket(std::unique_ptr<IStream> stream, std::unique_ptr<char[]> &data, ssize_t &len)
{
StreamPacketizer packet(streamType_, std::move(stream));
auto plainData = packet.PacketizeStream();
if (plainData == nullptr) {
TRANS_LOGE(TRANS_STREAM, "PacketizeStream failed");
return false;
}
len = packet.GetPacketLen() + GetEncryptOverhead();
TRANS_LOGD(TRANS_STREAM, "packetLen=%{public}zd, encryptOverhead=%{public}zd",
packet.GetPacketLen(), GetEncryptOverhead());
data = std::make_unique<char[]>(len + FRAME_HEADER_LEN);
ssize_t encLen = Encrypt(plainData.get(), packet.GetPacketLen(), data.get() + FRAME_HEADER_LEN, len);
if (encLen != len) {
TRANS_LOGE(TRANS_STREAM, "encrypted failed, dataLen=%{public}zd, encLen=%{public}zd", len, encLen);
return false;
}
InsertBufferLength(len, FRAME_HEADER_LEN, reinterpret_cast<uint8_t *>(data.get()));
len += FRAME_HEADER_LEN;
return true;
}
bool VtpStreamSocket::Send(std::unique_ptr<IStream> stream)
{
TRANS_LOGD(TRANS_STREAM,
"send in... streamType=%{public}d, dataSize=%{public}zd, extSize=%{public}zd", streamType_,
stream->GetBufferLen(), stream->GetExtBufferLen());
TRANS_LOGD(TRANS_STREAM, "send in... streamType=%{public}d, dataSize=%{public}zd, extSize=%{public}zd",
streamType_, stream->GetBufferLen(), stream->GetExtBufferLen());
if (!isBlocked_) {
isBlocked_ = true;
@ -586,24 +608,9 @@ bool VtpStreamSocket::Send(std::unique_ptr<IStream> stream)
TRANS_LOGE(TRANS_STREAM, "streamFrameInfo is null");
return false;
}
StreamPacketizer packet(streamType_, std::move(stream));
auto plainData = packet.PacketizeStream();
if (plainData == nullptr) {
TRANS_LOGE(TRANS_STREAM, "PacketizeStream failed");
if (!EncryptStreamPacket(std::move(stream), data, len)) {
return false;
}
len = packet.GetPacketLen() + GetEncryptOverhead();
TRANS_LOGD(TRANS_STREAM, "packetLen=%{public}zd, encryptOverhead=%{public}zd", packet.GetPacketLen(),
GetEncryptOverhead());
data = std::make_unique<char[]>(len + FRAME_HEADER_LEN);
ssize_t encLen = Encrypt(plainData.get(), packet.GetPacketLen(), data.get() + FRAME_HEADER_LEN, len);
if (encLen != len) {
TRANS_LOGE(TRANS_STREAM, "encrypted failed, dataLen=%{public}zd, encLen=%{public}zd", len, encLen);
return false;
}
InsertBufferLength(len, FRAME_HEADER_LEN, reinterpret_cast<uint8_t *>(data.get()));
len += FRAME_HEADER_LEN;
FrameInfo frameInfo;
ConvertStreamFrameInfo2FrameInfo(&frameInfo, streamFrameInfo);

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