From 25de5f7ea90debf5e4b16ae0f1732eda798b959e Mon Sep 17 00:00:00 2001 From: liangjunhao Date: Sat, 23 Aug 2025 11:11:27 +0800 Subject: [PATCH] fix: test Signed-off-by: liangjunhao --- .../include/softbus_message_open_channel.h | 8 + .../common/include/trans_lane_pending_ctl.h | 1 + .../common/src/softbus_message_open_channel.c | 176 +++++++++++++++++- .../common/src/trans_channel_limit.c | 4 + .../common/src/trans_lane_pending_ctl.c | 120 ++++++++++-- .../manager/src/trans_channel_manager.c | 28 ++- .../include/trans_tcp_direct_manager.h | 1 + .../tcp_direct/src/trans_tcp_direct_json.c | 1 + .../src/trans_tcp_direct_listener.c | 18 +- .../tcp_direct/src/trans_tcp_direct_message.c | 58 ++++-- .../tcp_direct/src/trans_tcp_direct_p2p.c | 1 + .../include/trans_udp_negotiation_exchange.h | 4 + .../src/trans_udp_negotiation.c | 56 ++++-- .../src/trans_udp_negotiation_exchange.c | 164 ++++++++++++++++ .../bus_center/bus_center_info_key_struct.h | 1 + .../common/trans_lane_pending_test.cpp | 36 ++-- .../manager/mock/trans_manager_mock.cpp | 4 +- .../manager/mock/trans_manager_mock.h | 4 +- .../trans_tcp_direct_message_append_test.cpp | 14 +- 19 files changed, 619 insertions(+), 80 deletions(-) diff --git a/core/transmission/trans_channel/common/include/softbus_message_open_channel.h b/core/transmission/trans_channel/common/include/softbus_message_open_channel.h index 979f232003..49eb730004 100644 --- a/core/transmission/trans_channel/common/include/softbus_message_open_channel.h +++ b/core/transmission/trans_channel/common/include/softbus_message_open_channel.h @@ -88,6 +88,14 @@ int32_t UnpackReplyErrCode(const cJSON *msg, int32_t *errCode); char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen); +int32_t UnpackExternalDeviceRequest(const cJSON *msg, AppInfo *appInfo); + +char *PackExternalDeviceRequest(const AppInfo *appInfo, int64_t requestId); + +int32_t UnpackExternalDeviceReply(const cJSON *msg, AppInfo *appInfo); + +char *PackExternalDeviceReply(const AppInfo *appInfo); + #ifdef __cplusplus } #endif // __cplusplus diff --git a/core/transmission/trans_channel/common/include/trans_lane_pending_ctl.h b/core/transmission/trans_channel/common/include/trans_lane_pending_ctl.h index 7c8250794c..d626b0f3ae 100644 --- a/core/transmission/trans_channel/common/include/trans_lane_pending_ctl.h +++ b/core/transmission/trans_channel/common/include/trans_lane_pending_ctl.h @@ -34,6 +34,7 @@ void TransFreeLanePendingDeinit(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, const AppInfo *appInfo); int32_t TransAsyncGetLaneInfo( const SessionParam *param, uint32_t *laneHandle, uint64_t callingTokenId, int64_t timeStart); int32_t TransGetLaneInfoByOption(const LaneRequestOption *requestOption, LaneConnInfo *connInfo, diff --git a/core/transmission/trans_channel/common/src/softbus_message_open_channel.c b/core/transmission/trans_channel/common/src/softbus_message_open_channel.c index 3450072323..26346b2331 100644 --- a/core/transmission/trans_channel/common/src/softbus_message_open_channel.c +++ b/core/transmission/trans_channel/common/src/softbus_message_open_channel.c @@ -524,4 +524,178 @@ char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen) } *outLen = dataLen + FAST_DATA_HEAD_SIZE; return buf; -} \ No newline at end of file +} + +static int32_t PackExternalDeviceJsonObiect(const AppInfo *appInfo, cJSON *json, unsigned char *encodeSessionKey) +{ + // TODO ljh code参数似乎没用 + if (!AddNumberToJsonObject(json, CODE, CODE_OPEN_CHANNEL) || + !AddNumberToJsonObject(json, API_VERSION, appInfo->myData.apiVersion) || + !AddStringToJsonObject(json, BUS_NAME, appInfo->peerData.sessionName) || + !AddStringToJsonObject(json, SESSION_KEY, (char *)encodeSessionKey) || + !AddNumberToJsonObject(json, MTU_SIZE, (int32_t)appInfo->myData.dataConfig)) { + return SOFTBUS_PARSE_JSON_ERR; + } + + if (!AddNumberToJsonObject(json, TRANS_CAPABILITY, (int32_t)appInfo->channelCapability)) { + return SOFTBUS_PARSE_JSON_ERR; + } + + if (appInfo->myData.apiVersion != API_V1 && + (!AddStringToJsonObject(json, PKG_NAME, appInfo->myData.pkgName) || + !AddStringToJsonObject(json, CLIENT_BUS_NAME, appInfo->myData.sessionName) || + !AddNumberToJsonObject(json, MSG_ROUTE_TYPE, appInfo->routeType))) { + return SOFTBUS_PARSE_JSON_ERR; + } + (void)AddStringToJsonObject(json, DEVICE_ID, appInfo->myData.deviceId); + (void)AddNumberToJsonObject(json, BUSINESS_TYPE, appInfo->businessType); + (void)AddNumberToJsonObject(json, TRANS_FLAGS, TRANS_FLAG_HAS_CHANNEL_AUTH); + return SOFTBUS_OK; +} + +char *PackExternalDeviceRequest(const AppInfo *appInfo, int64_t requestId) +{ + if (appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param."); + return NULL; + } + + cJSON *json = cJSON_CreateObject(); + if (json == NULL) { + TRANS_LOGE(TRANS_CTRL, "Cannot create cJSON object"); + return NULL; + } + + unsigned char encodeSessionKey[BASE64KEY] = {0}; + size_t keyLen = 0; + int32_t ret = SoftBusBase64Encode(encodeSessionKey, BASE64KEY, + &keyLen, (unsigned char *)appInfo->sessionKey, SESSION_KEY_LENGTH); + if (ret != SOFTBUS_OK) { + cJSON_Delete(json); + return NULL; + } + ret = PackExternalDeviceJsonObiect(appInfo, json, encodeSessionKey); + (void)memset_s(encodeSessionKey, sizeof(encodeSessionKey), 0, sizeof(encodeSessionKey)); + if (ret != SOFTBUS_OK) { + cJSON_Delete(json); + return NULL; + } + char *data = cJSON_PrintUnformatted(json); + if (data == NULL) { + TRANS_LOGW(TRANS_CTRL, "cJSON_PrintUnformatted failed"); + } + cJSON_Delete(json); + return data; +} + +int32_t UnpackExternalDeviceRequest(const cJSON *msg, AppInfo *appInfo) +{ + if (msg == NULL || appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param"); + return SOFTBUS_INVALID_PARAM; + } + char sessionKey[BASE64KEY] = { 0 }; + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, SESSION_KEY, sessionKey, sizeof(sessionKey)), + SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get sessionKey."); + size_t len = 0; + if (strlen(sessionKey) != 0) { + int32_t ret = SoftBusBase64Decode((unsigned char *)appInfo->sessionKey, SESSION_KEY_LENGTH, &len, + (unsigned char *)sessionKey, strlen(sessionKey)); + (void)memset_s(sessionKey, sizeof(sessionKey), 0, sizeof(sessionKey)); + if (len != SESSION_KEY_LENGTH) { + TRANS_LOGE(TRANS_CTRL, "Failed to decode sessionKey ret=%{public}d, len=%{public}zu", ret, len); + return SOFTBUS_PARSE_JSON_ERR; + } + } + + int32_t apiVersion = API_V1; + (void)GetJsonObjectNumberItem(msg, API_VERSION, &apiVersion); + appInfo->peerData.apiVersion = (ApiVersion)apiVersion; + + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, BUS_NAME, (appInfo->myData.sessionName), + SESSION_NAME_SIZE_MAX), SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get sessionName."); + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectNumberItem(msg, MTU_SIZE, (int32_t *)&(appInfo->peerData.dataConfig)), + SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get mtu size."); + + uint32_t remoteCapability = 0; + (void)GetJsonObjectNumberItem(msg, TRANS_CAPABILITY, (int32_t *)&remoteCapability); + appInfo->channelCapability = remoteCapability & TRANS_CHANNEL_CAPABILITY; + + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, PKG_NAME, (appInfo->peerData.pkgName), + PKG_NAME_SIZE_MAX), SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get pkgName."); + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, CLIENT_BUS_NAME, (appInfo->peerData.sessionName), + SESSION_NAME_SIZE_MAX), SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get client sessionName."); + + int32_t routeType = WIFI_STA; + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectNumberItem(msg, MSG_ROUTE_TYPE, &routeType), + SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get routeType."); + appInfo->routeType = (RouteType)routeType; + + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, DEVICE_ID, appInfo->peerData.deviceId, + DEVICE_ID_SIZE_MAX), SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get deviceId."); + if (!GetJsonObjectNumberItem(msg, BUSINESS_TYPE, (int32_t *)&appInfo->businessType)) { + appInfo->businessType = BUSINESS_TYPE_NOT_CARE; + } + int32_t transFlag = TRANS_FLAG_HAS_CHANNEL_AUTH; + (void)GetJsonObjectNumberItem(msg, TRANS_FLAGS, &transFlag); + appInfo->peerData.userId = INVALID_USER_ID; + return SOFTBUS_OK; +} + +char *PackExternalDeviceReply(const AppInfo *appInfo) +{ + if (appInfo == NULL) { + TRANS_LOGE(TRANS_CTRL, "invalid param"); + return NULL; + } + cJSON *json = cJSON_CreateObject(); + if (json == NULL) { + return NULL; + } + char *data = NULL; + if (!AddNumberToJsonObject(json, CODE, CODE_OPEN_CHANNEL) || + !AddNumberToJsonObject(json, API_VERSION, appInfo->myData.apiVersion)|| + !AddStringToJsonObject(json, DEVICE_ID, appInfo->myData.deviceId) || + !AddNumberToJsonObject(json, TRANS_CAPABILITY, appInfo->channelCapability) || + !AddNumberToJsonObject(json, MTU_SIZE, appInfo->myData.dataConfig) || + !AddStringToJsonObject(json, PKG_NAME, appInfo->myData.pkgName)) { + TRANS_LOGE(TRANS_CTRL, "Failed to add trans data size"); + cJSON_Delete(json); + return NULL; + } + + data = cJSON_PrintUnformatted(json); + if (data == NULL) { + TRANS_LOGW(TRANS_CTRL, "cJSON_PrintUnformatted failed"); + } + cJSON_Delete(json); + return data; +} + +int32_t UnpackExternalDeviceReply(const cJSON *msg, AppInfo *appInfo) +{ + if (msg == NULL || appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param"); + return SOFTBUS_INVALID_PARAM; + } + int32_t apiVersion = API_V1; + (void)GetJsonObjectNumberItem(msg, API_VERSION, &apiVersion); + appInfo->peerData.apiVersion = (ApiVersion)apiVersion; + + char uuid[DEVICE_ID_SIZE_MAX] = { 0 }; + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, DEVICE_ID, uuid, DEVICE_ID_SIZE_MAX), + SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get deviceId."); + if (strcmp(uuid, appInfo->peerData.deviceId) != 0) { + TRANS_LOGE(TRANS_CTRL, "Invalid uuid"); + return SOFTBUS_TRANS_INVALID_UUID; + } + if (!GetJsonObjectNumberItem(msg, TRANS_CAPABILITY, (int32_t *)&(appInfo->channelCapability))) { + appInfo->channelCapability = 0; + } + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectNumberItem(msg, MTU_SIZE, (int32_t *)&(appInfo->peerData.dataConfig)), + SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get mtu size."); + TRANS_CHECK_AND_RETURN_RET_LOGE(GetJsonObjectStringItem(msg, PKG_NAME, (appInfo->peerData.pkgName), + PKG_NAME_SIZE_MAX), SOFTBUS_PARSE_JSON_ERR, TRANS_CTRL, "Failed to get pkgName."); + return SOFTBUS_OK; +} + diff --git a/core/transmission/trans_channel/common/src/trans_channel_limit.c b/core/transmission/trans_channel/common/src/trans_channel_limit.c index 02621bde86..80df9891fc 100644 --- a/core/transmission/trans_channel/common/src/trans_channel_limit.c +++ b/core/transmission/trans_channel/common/src/trans_channel_limit.c @@ -42,6 +42,10 @@ static const SessionWhiteList g_sessionWhiteList[] = { .sessionName = "IShareAuthSession", .regexp = false, }, + { + .sessionName = "IShareEcologyAuthSession", + .regexp = false, + }, { .sessionName = "com.huawei.devicemanager.resident", .regexp = false, diff --git a/core/transmission/trans_channel/common/src/trans_lane_pending_ctl.c b/core/transmission/trans_channel/common/src/trans_lane_pending_ctl.c index c692921762..5b6fd1a548 100644 --- a/core/transmission/trans_channel/common/src/trans_lane_pending_ctl.c +++ b/core/transmission/trans_channel/common/src/trans_lane_pending_ctl.c @@ -18,6 +18,7 @@ #include #include "access_control.h" +#include "softbus_app_info.h" #include "auth_interface.h" #include "bus_center_manager.h" #include "common_list.h" @@ -871,6 +872,7 @@ static void TransOnAsyncLaneSuccess(uint32_t laneHandle, const LaneConnInfo *con TransFreeLane(laneHandle, param.isQosLane, true); return; } + // TODO 调用LnnGetOsTypeBynetworkId拿到ostype存到appinfo中 ret = CreateAppInfoByParam(laneHandle, ¶m, appInfo); if (ret != SOFTBUS_OK) { TRANS_LOGE(TRANS_SVC, "CreateAppInfoByParam failed"); @@ -1577,9 +1579,9 @@ int32_t TransAsyncGetLaneInfoByOption(const SessionParam *param, const LaneReque } int32_t TransAsyncGetLaneInfoByQos(const SessionParam *param, const LaneAllocInfo *allocInfo, - uint32_t *laneHandle, uint64_t callingTokenId, int64_t timeStart) + uint32_t *laneHandle, const AppInfo *appInfo) { - if (param == NULL || allocInfo == NULL || laneHandle == NULL) { + if (param == NULL || allocInfo == NULL || laneHandle == NULL || appInfo == NULL) { TRANS_LOGE(TRANS_SVC, "async get lane info param error."); return SOFTBUS_INVALID_PARAM; } @@ -1590,7 +1592,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, timeStart); + int32_t ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, appInfo->callingTokenId, appInfo->timeStart); if (ret != SOFTBUS_OK) { TRANS_LOGE( TRANS_SVC, "add laneHandle=%{public}u to async pending list failed, ret=%{public}d", *laneHandle, ret); @@ -1626,27 +1628,102 @@ int32_t TransAsyncGetLaneInfoByQos(const SessionParam *param, const LaneAllocInf return SOFTBUS_OK; } -int32_t TransAsyncGetLaneInfo( - const SessionParam *param, uint32_t *laneHandle, uint64_t callingTokenId, int64_t timeStart) +static int32_t GetAllocInfoExtBySessionParam(const SessionParam *param, LaneAllocInfoExt *allocInfo) +{ + allocInfo->type = LANE_TYPE_TRANS; + if (memcpy_s(allocInfo->commInfo.networkId, NETWORK_ID_BUF_LEN, param->peerDeviceId, NETWORK_ID_BUF_LEN) != EOK) { + TRANS_LOGE(TRANS_SVC, "memcpy networkId failed."); + return SOFTBUS_MEM_ERR; + } + allocInfo->commInfo.transType = (LaneTransType)TransGetLaneTransTypeBySession(param); + if (allocInfo->commInfo.transType == LANE_T_BUTT) { + return SOFTBUS_TRANS_INVALID_SESSION_TYPE; + } + allocInfo->linkList.linkTypeNum = 1; + allocInfo->linkList.linkType[0] = LANE_P2P; + allocInfo->commInfo.isVirtualLink = false; + return SOFTBUS_OK; +} + +int32_t TransAsyncGetLaneInfoByExt(const SessionParam *param, uint32_t *laneHandle, const AppInfo *appInfo) { - if (param == NULL || laneHandle == NULL) { + if (param == NULL || appInfo == NULL || laneHandle == NULL) { TRANS_LOGE(TRANS_SVC, "async get lane info param error."); return SOFTBUS_INVALID_PARAM; } - int32_t ret = SOFTBUS_OK; - LaneAllocInfo allocInfo; - (void)memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo)); - ret = GetAllocInfoBySessionParam(param, &allocInfo); + LaneAllocInfoExt allocInfo; + (void)memset_s(&allocInfo, sizeof(LaneAllocInfoExt), 0, sizeof(LaneAllocInfoExt)); + int32_t ret = GetAllocInfoExtBySessionParam(param, &allocInfo); + TRANS_CHECK_AND_RETURN_RET_LOGE( + ret == SOFTBUS_OK, SOFTBUS_TRANS_GET_LANE_INFO_ERR, TRANS_SVC, "get lane info failed."); + TRANS_CHECK_AND_RETURN_RET_LOGE( + GetLaneManager() != NULL, SOFTBUS_TRANS_GET_LANE_INFO_ERR, TRANS_SVC, "GetLaneManager is null"); + 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); + TransUpdateSocketChannelLaneInfoBySession( + param->sessionName, param->sessionId, *laneHandle, param->isQosLane, param->isAsync); + ret = TransAddAsyncLaneReqFromPendingList(*laneHandle, param, appInfo->callingTokenId, appInfo->timeStart); if (ret != SOFTBUS_OK) { - TRANS_LOGE(TRANS_SVC, "get alloc Info failed. laneHandle=%{public}u, ret=%{public}d", *laneHandle, ret); + TRANS_LOGE( + TRANS_SVC, "add laneHandle=%{public}u to async pending list failed, ret=%{public}d", *laneHandle, ret); + TransFreeLane(*laneHandle, true, true); return ret; } - ret = TransAsyncGetLaneInfoByQos(param, &allocInfo, laneHandle, callingTokenId, timeStart); + LaneAllocListener allocListener; + allocListener.onLaneAllocSuccess = TransOnAsyncLaneSuccess; + allocListener.onLaneAllocFail = TransOnAsyncLaneFail; + allocListener.onLaneFreeSuccess = TransOnLaneFreeSuccess; + allocListener.onLaneFreeFail = TransOnLaneFreeFail; + allocListener.onLaneQosEvent = TransOnLaneQosEvent; + TRANS_CHECK_AND_RETURN_RET_LOGE(GetLaneManager()->lnnAllocLane != NULL, SOFTBUS_TRANS_GET_LANE_INFO_ERR, + TRANS_SVC, "lnnAllocLane is null"); + ret = GetLaneManager()->lnnAllocLaneExt(*laneHandle, &allocInfo, &allocListener); 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 + TRANS_LOGE(TRANS_SVC, "trans request lane failed, ret=%{public}d", ret); + (void)TransDelLaneReqFromPendingList(*laneHandle, true); return ret; } + CoreSessionState state = CORE_SESSION_STATE_INIT; + TransGetSocketChannelStateBySession(param->sessionName, param->sessionId, &state); + if (state == CORE_SESSION_STATE_CANCELLING) { + CancelLaneOnWaitLaneState(*laneHandle, param->isQosLane); + (void)TransDelLaneReqFromPendingList(*laneHandle, true); + return SOFTBUS_TRANS_STOP_BIND_BY_CANCEL; + } + TransSetSocketChannelStateBySession(param->sessionName, param->sessionId, CORE_SESSION_STATE_WAIT_LANE); + return SOFTBUS_OK; +} + +int32_t TransAsyncGetLaneInfo(const SessionParam *param, uint32_t *laneHandle, const AppInfo *appInfo) +{ + if (param == NULL || laneHandle == NULL || appInfo == NULL) { + TRANS_LOGE(TRANS_SVC, "async get lane info param error."); + return SOFTBUS_INVALID_PARAM; + } + int32_t ret = SOFTBUS_OK; + if (appInfo->osType == HA_OS_TYPE) { + ret = TransAsyncGetLaneInfoByExt(param, laneHandle, appInfo); + if (ret != SOFTBUS_OK) { + TRANS_LOGE(TRANS_SVC, "get lane info by allocInfo failed, ret=%{public}d", ret); + *laneHandle = INVALID_LANE_REQ_ID; + return ret; + } + } else { + LaneAllocInfo allocInfo; + (void)memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo)); + ret = GetAllocInfoBySessionParam(param, &allocInfo); + if (ret != SOFTBUS_OK) { + TRANS_LOGE(TRANS_SVC, "get alloc Info failed. laneHandle=%{public}u, ret=%{public}d", *laneHandle, ret); + return ret; + } + ret = TransAsyncGetLaneInfoByQos(param, &allocInfo, laneHandle, appInfo); + 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 + return ret; + } + } return SOFTBUS_OK; } @@ -1766,6 +1843,19 @@ static int32_t SetUsbConnInfo(const UsbConnInfo *connInfo, ConnectOption *connOp return SOFTBUS_OK; } +static int32_t SetP2pExtConnInfo(const P2pConnInfo *p2pInfo, ConnectOption *connOpt) +{ + TRANS_LOGI(TRANS_SVC, "set p2pExt conn info."); + connOpt->type = CONNECT_P2P; + if (strcpy_s(connOpt->socketOption.addr, sizeof(connOpt->socketOption.addr), p2pInfo->peerIp) != EOK) { + TRANS_LOGE(TRANS_SVC, "set p2p localIp err"); + return SOFTBUS_STRCPY_ERR; + } + connOpt->socketOption.protocol = LNN_PROTOCOL_IP; + connOpt->socketOption.port = -1; + return SOFTBUS_OK; +} + int32_t TransGetConnectOptByConnInfo(const LaneConnInfo *info, ConnectOption *connOpt) { if (info == NULL || connOpt == NULL) { @@ -1790,6 +1880,8 @@ int32_t TransGetConnectOptByConnInfo(const LaneConnInfo *info, ConnectOption *co return SetUsbConnInfo(&(info->connInfo.usb), connOpt); } else if (info->type == LANE_SLE_DIRECT) { return SetSleDirectConnInfo(&(info->connInfo.sleDirect), connOpt); + } else if (info->type == LANE_P2P_EXT) { + return SetP2pExtConnInfo(&(info->connInfo.p2p), connOpt); } TRANS_LOGE(TRANS_SVC, "get conn opt err: type=%{public}d", info->type); diff --git a/core/transmission/trans_channel/manager/src/trans_channel_manager.c b/core/transmission/trans_channel/manager/src/trans_channel_manager.c index d701e666a8..18fe8cd9c7 100644 --- a/core/transmission/trans_channel/manager/src/trans_channel_manager.c +++ b/core/transmission/trans_channel/manager/src/trans_channel_manager.c @@ -70,6 +70,8 @@ #define BIT_NUM 8 #define REPORT_UDP_INFO_SIZE 4 #define ACCESS_INFO_PARAM_NUM 3 +#define EXTERNAL_DEVICE_UDID_HASH_LEN 6 +#define EXTERNAL_DEVICE_ISHARE_NAME "IShareEcologyAuthSession" static int32_t g_allocTdcChannelId = MAX_PROXY_CHANNEL_ID; static SoftBusMutex g_myIdLock; @@ -429,6 +431,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo) SoftBusHitraceChainEnd(); return ret; } + GetOsTypeByNetworkId(param->peerDeviceId, &appInfo->osType); NodeInfo nodeInfo; (void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo)); int32_t peerRet = LnnGetRemoteNodeInfoById(appInfo->peerNetWorkId, CATEGORY_NETWORK_ID, &nodeInfo); @@ -441,7 +444,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo) extra.sessionId = param->sessionId; TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra); if (param->isQosLane) { - ret = TransAsyncGetLaneInfo(param, &laneHandle, appInfo->callingTokenId, appInfo->timeStart); + ret = TransAsyncGetLaneInfo(param, &laneHandle, appInfo); if (ret != SOFTBUS_OK) { Anonymize(param->sessionName, &tmpName); TRANS_LOGE(TRANS_CTRL, "Async get Lane failed, sessionName=%{public}s, sessionId=%{public}d", @@ -546,6 +549,26 @@ EXIT_CANCEL: return SOFTBUS_TRANS_STOP_BIND_BY_CANCEL; } +static int32_t TransGetLocalDeviceId(const char *mySessionName, AppInfo *appInfo) +{ + char LocalUdid[UDID_BUF_LEN] = {0}; + int32_t ret = LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, LocalUdid, UDID_BUF_LEN); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "get local udid failed."); + if (strcmp(mySessionName, EXTERNAL_DEVICE_ISHARE_NAME) == 0) { + uint8_t udidHash[SHA_256_HASH_LEN] = { 0 }; + ret = SoftBusGenerateStrHash((unsigned char *)LocalUdid, strlen(LocalUdid), (unsigned char *)udidHash); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "generate udid hash fail."); + ret = memcpy_s( + appInfo->myData.deviceId, sizeof(appInfo->myData.deviceId), udidHash, EXTERNAL_DEVICE_UDID_HASH_LEN); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == EOK, ret, TRANS_CTRL, "strcpy fail."); + } else { + ret = strcpy_s( + appInfo->myData.deviceId, sizeof(appInfo->myData.deviceId), localUdid); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == EOK, ret, TRANS_CTRL, "strcpy fail."); + } + return SOFTBUS_OK; +} + static AppInfo *GetAuthAppInfo(const char *mySessionName) { TRANS_LOGD(TRANS_CTRL, "enter."); @@ -564,8 +587,7 @@ static AppInfo *GetAuthAppInfo(const char *mySessionName) TRANS_LOGE(TRANS_CTRL, "GetAuthAppInfo GetUidAndPid failed"); goto EXIT_ERR; } - if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, appInfo->myData.deviceId, - sizeof(appInfo->myData.deviceId)) != SOFTBUS_OK) { + if (TransGetLocalDeviceId(mySessionName, appInfo) != SOFTBUS_OK) { TRANS_LOGE(TRANS_CTRL, "GetAuthAppInfo get deviceId failed"); goto EXIT_ERR; } diff --git a/core/transmission/trans_channel/tcp_direct/include/trans_tcp_direct_manager.h b/core/transmission/trans_channel/tcp_direct/include/trans_tcp_direct_manager.h index 32567c63e8..f4e17f886f 100644 --- a/core/transmission/trans_channel/tcp_direct/include/trans_tcp_direct_manager.h +++ b/core/transmission/trans_channel/tcp_direct/include/trans_tcp_direct_manager.h @@ -40,6 +40,7 @@ extern "C" { #define FLAG_ENHANCE_P2P 32 #define FLAG_SESSION_KEY 64 #define FLAG_SLE 64 +#define FLAG_EXTERNAL_DEVICE 128 #define AUTH_CONN_SERVER_SIDE 0x01 typedef struct { diff --git a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_json.c b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_json.c index ec28aba51d..428c658689 100644 --- a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_json.c +++ b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_json.c @@ -61,6 +61,7 @@ char *VerifyP2pPack(const char *myIp, int32_t myPort, const char *peerIp, Protoc TRANS_LOGE(TRANS_CTRL, "create object failed"); return NULL; } + // 传入一个ostype 判断ios就不传peerip if (peerIp != NULL) { AddStringToJsonObject(json, PEER_IP, peerIp); } diff --git a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_listener.c b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_listener.c index 6b91fdbabd..ec49e00e7b 100644 --- a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_listener.c +++ b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_listener.c @@ -101,8 +101,13 @@ static int32_t TransPostBytes(SessionConn *conn, bool isAuthServer, uint32_t cip if (isAuthServer) { seq |= AUTH_CONN_SERVER_SIDE; } - - char *bytes = PackRequest(&conn->appInfo, conn->req); + // TODO 判断ostype是ios 就打包新的报文 + char *bytes = NULL; + if (conn->appInfo.osType == HA_OS_TYPE) { + bytes = PackExternalDeviceRequest(&conn->appInfo, conn->req); + } else { + bytes = PackRequest(&conn->appInfo, conn->req); + } if (bytes == NULL) { TRANS_LOGE(TRANS_CTRL, "Pack Request failed channelId=%{public}d, fd=%{public}d", @@ -117,7 +122,12 @@ static int32_t TransPostBytes(SessionConn *conn, bool isAuthServer, uint32_t cip .dataLen = strlen(bytes), /* reset after encrypt */ }; if (conn->isMeta) { - packetHead.flags |= FLAG_AUTH_META; + if (conn->appInfo.osType == HA_OS_TYPE) { + packetHead.flags |= (FLAG_EXTERNAL_DEVICE + FLAG_AUTH_META); + } else { + packetHead.flags |= FLAG_AUTH_META; + } + } int32_t ret = TransTdcPostBytes(conn->channelId, &packetHead, bytes); cJSON_free(bytes); @@ -143,7 +153,7 @@ static int32_t StartVerifySession(SessionConn *conn) SetSessionKeyByChanId(conn->channelId, conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey)); bool isAuthServer = false; uint32_t cipherFlag = FLAG_WIFI; - bool isLegacyOs = IsPeerDeviceLegacyOs(conn->appInfo.osType); + bool isLegacyOs = IsPeerDeviceLegacyOs(conn->appInfo.osType); if (GetCipherFlagByAuthId(conn->authHandle, &cipherFlag, &isAuthServer, isLegacyOs)) { TRANS_LOGE(TRANS_CTRL, "get cipher flag failed channelId=%{public}d, fd=%{public}d", diff --git a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_message.c b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_message.c index 221b893097..2be733f42c 100644 --- a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_message.c +++ b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_message.c @@ -66,6 +66,7 @@ #define MAX_ERRDESC_LEN 128 #define NCM_DEVICE_TYPE "ncm0" #define NCM_HOST_TYPE "wwan0" +#define ISHARE_PKG_NAME "ohos.InterConnection.iShare" typedef struct { int32_t channelType; @@ -502,7 +503,7 @@ static int32_t NotifyChannelOpened(int32_t channelId) info.isFastData = true; } TransGetLaneIdByChannelId(channelId, &info.laneId); - GetOsTypeByNetworkId(info.peerDeviceId, &info.osType); + // GetOsTypeByNetworkId(info.peerDeviceId, &info.osType); info.isSupportTlv = GetCapabilityBit(conn.appInfo.channelCapability, TRANS_CAPABILITY_TLV_OFFSET); ret = TransTdcOnChannelOpened(pkgName, pid, conn.appInfo.myData.sessionName, &info); ClearAppInfoSessionKey(&conn.appInfo); @@ -684,7 +685,7 @@ static int32_t TransTdcProcessDataConfig(AppInfo *appInfo) } // the channel open failed while be notified when function OpenDataBusReply return ERR -static int32_t OpenDataBusReply(int32_t channelId, uint64_t seq, const cJSON *reply) +static int32_t OpenDataBusReply(int32_t channelId, uint64_t seq, const cJSON *reply, uint32_t flags) { (void)seq; TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d, seq=%{public}" PRIu64, channelId, seq); @@ -704,10 +705,16 @@ static int32_t OpenDataBusReply(int32_t channelId, uint64_t seq, const cJSON *re } uint16_t fastDataSize = 0; - 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 = SOFTBUS_OK; + if ((flags & FLAG_EXTERNAL_DEVICE) != 0) { + ret = UnpackExternalDeviceReply(reply, &conn.appInfo); + } else { + ret = UnpackReply(reply, &conn.appInfo, &fastDataSize); + } + TRANS_CHECK_AND_RETURN_RET_LOGE( + ret == SOFTBUS_OK, SOFTBUS_TRANS_UNPACK_REPLY_FAILED, TRANS_CTRL, "UnpackReply failed"); - int32_t ret = TransTdcProcessDataConfig(&conn.appInfo); + 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); @@ -751,7 +758,13 @@ static int32_t TransTdcPostReplyMsg(int32_t channelId, uint64_t seq, uint32_t fl static int32_t OpenDataBusRequestReply(const AppInfo *appInfo, int32_t channelId, uint64_t seq, uint32_t flags) { - char *reply = PackReply(appInfo); + // TODO + char *reply = NULL; + if (appInfo->osType == HA_OS_TYPE) { + reply = PackExternalDeviceReply(appInfo); + } else { + reply = PackReply(appInfo); + } if (reply == NULL) { TRANS_LOGE(TRANS_CTRL, "get pack reply err"); return SOFTBUS_TRANS_GET_PACK_REPLY_FAILED; @@ -796,7 +809,7 @@ static void OpenDataBusRequestOutSessionName(const char *mySessionName, const ch AnonymizeFree(tmpPeerName); } -static SessionConn *GetSessionConnFromDataBusRequest(int32_t channelId, const cJSON *request) +static SessionConn *GetSessionConnFromDataBusRequest(int32_t channelId, const cJSON *request, uint32_t flags) { SessionConn *conn = (SessionConn *)SoftBusCalloc(sizeof(SessionConn)); if (conn == NULL) { @@ -808,8 +821,15 @@ static SessionConn *GetSessionConnFromDataBusRequest(int32_t channelId, const cJ TRANS_LOGE(TRANS_CTRL, "get session conn failed"); return NULL; } - if (UnpackRequest(request, &conn->appInfo) != SOFTBUS_OK) { - (void)memset_s(conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey), 0, sizeof(conn->appInfo.sessionKey)); + int32_t ret = SOFTBUS_OK; + if ((flags & FLAG_EXTERNAL_DEVICE) != 0) { + ret = UnpackExternalDeviceRequest(request, &conn->appInfo); + } else { + ret = UnpackRequest(request, &conn->appInfo); + } + if (ret != SOFTBUS_OK) { + (void)memset_s( + conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey), 0, sizeof(conn->appInfo.sessionKey)); SoftBusFree(conn); TRANS_LOGE(TRANS_CTRL, "UnpackRequest error"); return NULL; @@ -1053,20 +1073,22 @@ static int32_t HandleDataBusReply( static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t seq, const cJSON *request) { TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d, seq=%{public}" PRIu64, channelId, seq); - SessionConn *conn = GetSessionConnFromDataBusRequest(channelId, request); + SessionConn *conn = GetSessionConnFromDataBusRequest(channelId, request, flags); TRANS_CHECK_AND_RETURN_RET_LOGE(conn != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "conn is null"); - + if ((flags & FLAG_EXTERNAL_DEVICE) != 0) { + char pkgName[PKG_NAME_SIZE_MAX] = { 0 }; + int32_t ret = TransTdcGetPkgName(conn->appInfo.myData.sessionName, pkgName, PKG_NAME_SIZE_MAX); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "get pkg name fail."); + if (strcmp(pkgName, ISHARE_PKG_NAME) != 0) { + TRANS_LOGE(TRANS_CTRL, "not supporting access"); + return SOFTBUS_TRANS_QUERY_PERMISSION_FAILED; + } + } TransEventExtra extra; char peerUuid[DEVICE_ID_SIZE_MAX] = { 0 }; NodeInfo nodeInfo; (void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo)); ReportTransEventExtra(&extra, channelId, conn, &nodeInfo, peerUuid); - - if ((flags & FLAG_AUTH_META) != 0) { - TRANS_LOGE(TRANS_CTRL, "not support meta auth."); - ReleaseSessionConn(conn); - return SOFTBUS_FUNC_NOT_SUPPORT; - } char errDesc[MAX_ERRDESC_LEN] = { 0 }; int32_t errCode = TransTdcFillAppInfoAndNotifyChannel(&conn->appInfo, channelId, errDesc); if (errCode != SOFTBUS_OK) { @@ -1091,7 +1113,7 @@ static int32_t ProcessMessage(int32_t channelId, uint32_t flags, uint64_t seq, c return SOFTBUS_PARSE_JSON_ERR; } if (flags & FLAG_REPLY) { - ret = OpenDataBusReply(channelId, seq, json); + ret = OpenDataBusReply(channelId, seq, json, flags); } else { ret = OpenDataBusRequest(channelId, flags, seq, json); } diff --git a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_p2p.c b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_p2p.c index bef2b4ec31..8cd99ffffc 100644 --- a/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_p2p.c +++ b/core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_p2p.c @@ -657,6 +657,7 @@ static int32_t OpenAuthConn(const char *uuid, uint32_t reqId, bool isMeta, Conne ret = AuthGetHmlConnInfo(uuid, &auth, isMeta); } if (ret != SOFTBUS_OK && type == CONNECT_P2P) { + // TODO 判断如果是p2p且ostype是ios 则 调用AuthGetIosConnInfo 当前不需要 调试时候观察 TRANS_LOGI(TRANS_CTRL, "get AuthConnInfo, linkType=%{public}d", type); ret = AuthGetP2pConnInfo(uuid, &auth, isMeta); } diff --git a/core/transmission/trans_channel/udp_negotiation/include/trans_udp_negotiation_exchange.h b/core/transmission/trans_channel/udp_negotiation/include/trans_udp_negotiation_exchange.h index 61ff3975b3..741ea4251f 100644 --- a/core/transmission/trans_channel/udp_negotiation/include/trans_udp_negotiation_exchange.h +++ b/core/transmission/trans_channel/udp_negotiation/include/trans_udp_negotiation_exchange.h @@ -31,6 +31,10 @@ int32_t TransPackRequestUdpInfo(cJSON *msg, const AppInfo *appInfo); int32_t TransPackReplyUdpInfo(cJSON *msg, const AppInfo *appInfo); int32_t TransPackReplyErrInfo(cJSON *msg, int errCode, const char* errDesc); bool IsIShareSession(const char *sessionName); +int32_t TransPackExtDeviceRequestInfo(cJSON *msg, const AppInfo *appInfo); +int32_t TransUnpackExtDeviceRequestInfo(const cJSON *msg, AppInfo *appInfo); +int32_t TransPackExtDeviceReplyInfo(cJSON *msg, const AppInfo *appInfo); +int32_t TransUnpackExtDeviceReplyInfo(const cJSON *msg, AppInfo *appInfo); #ifdef __cplusplus } diff --git a/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation.c b/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation.c index 1ba6e71754..fb6ef9b554 100644 --- a/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation.c +++ b/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation.c @@ -60,6 +60,7 @@ #define ISHARE_SESSION_NAME "IShare*" #define CLONE_SESSION_NAME "IShare_" +#define ISHARE_PKG_NAME "ohos.InterConnection.iShare" static int64_t g_seq = 0; static uint64_t g_channelIdFlagBitsMap = 0; @@ -369,7 +370,7 @@ static int32_t CheckAndGenerateSinkSessionKey(AppInfo *appInfo) { int32_t osType = 0; (void)GetOsTypeByNetworkId(appInfo->peerNetWorkId, &osType); - if (osType != OH_OS_TYPE) { + if (osType != HA_OS_TYPE) { DisableCapabilityBit(&appInfo->channelCapability, TRANS_CHANNEL_SINK_GENERATE_KEY_OFFSET); } if (GetCapabilityBit(appInfo->channelCapability, TRANS_CHANNEL_SINK_GENERATE_KEY_OFFSET)) { @@ -548,7 +549,12 @@ static int32_t SendReplyUdpInfo(AppInfo *appInfo, AuthHandle authHandle, int64_t cJSON *replyMsg = cJSON_CreateObject(); TRANS_CHECK_AND_RETURN_RET_LOGE(replyMsg != NULL, SOFTBUS_CREATE_JSON_ERR, TRANS_CTRL, "create cjson object failed."); - int32_t ret = TransPackReplyUdpInfo(replyMsg, appInfo); + int32_t ret = SOFTBUS_OK; + if (appInfo->osType == HA_OS_TYPE) { + ret = TransPackExtDeviceReplyInfo(replyMsg, appInfo); + } else { + ret = TransPackReplyUdpInfo(replyMsg, appInfo); + } if (ret != SOFTBUS_OK) { TRANS_LOGE(TRANS_CTRL, "pack request udp info failed."); cJSON_Delete(replyMsg); @@ -604,7 +610,17 @@ static void TransSetUdpConnectTypeByAuthType(int32_t *connectType, AuthHandle au static int32_t ParseRequestAppInfo(AuthHandle authHandle, const cJSON *msg, AppInfo *appInfo) { - int32_t ret = TransUnpackRequestUdpInfo(msg, appInfo); + int32_t ret = SOFTBUS_OK; + int32_t osType = 0; + // TODO ljh 调组网获取ostype 然后用来解报文 和判断pkgName是不是被允许三方调用的 + ret = SetPeerDeviceIdByAuth(authHandle, appInfo); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_PEER_PROC_ERR, TRANS_CTRL, "set deviceId failed."); + GetOsTypeByNetworkId(appInfo->peerNetWorkId, &osType); + if (osType == HA_OS_TYPE) { + ret = TransUnpackExtDeviceRequestInfo(msg, appInfo); + } else { + ret = TransUnpackRequestUdpInfo(msg, appInfo); + } TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "unpack request udp info failed."); appInfo->myHandleId = -1; @@ -613,17 +629,19 @@ static int32_t ParseRequestAppInfo(AuthHandle authHandle, const cJSON *msg, AppI appInfo->myData.pkgName, PKG_NAME_SIZE_MAX); TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_TRANS_PEER_SESSION_NOT_CREATED, TRANS_CTRL, "get pkgName failed, ret=%{public}d", ret); - + if (osType == HA_OS_TYPE) { + if (strcmp(appInfo->myData.pkgName, ISHARE_PKG_NAME) != 0) { + TRANS_LOGE(TRANS_CTRL, "osType=%{public}d not supporting access", osType); + return SOFTBUS_TRANS_QUERY_PERMISSION_FAILED; + } + } ret = g_channelCb->GetUidAndPidBySessionName(appInfo->myData.sessionName, &appInfo->myData.uid, &appInfo->myData.pid); TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_TRANS_PEER_SESSION_NOT_CREATED, TRANS_CTRL, "get uid and pid failed, ret=%{public}d", ret); if (appInfo->callingTokenId != TOKENID_NOT_SET) { - (void)LnnGetNetworkIdByUuid(appInfo->peerData.deviceId, appInfo->peerNetWorkId, NETWORK_ID_BUF_LEN); - int32_t osType = 0; - GetOsTypeByNetworkId(appInfo->peerNetWorkId, &osType); - if (osType != OH_OS_TYPE) { + if (appInfo->osType != OH_OS_TYPE) { TRANS_LOGI(TRANS_CTRL, "not support acl check osType=%{public}d", osType); } else if (GetCapabilityBit(appInfo->channelCapability, TRANS_CHANNEL_ACL_CHECK_OFFSET)) { ret = TransCheckServerAccessControl(appInfo); @@ -643,9 +661,6 @@ static int32_t ParseRequestAppInfo(AuthHandle authHandle, const cJSON *msg, AppI TransSetUdpConnectTypeByAuthType(&appInfo->connectType, authHandle); - ret = SetPeerDeviceIdByAuth(authHandle, appInfo); - TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_PEER_PROC_ERR, TRANS_CTRL, "set deviceId failed."); - char localIp[IP_LEN] = { 0 }; if (appInfo->udpConnType == UDP_CONN_TYPE_WIFI) { appInfo->routeType = WIFI_STA; @@ -710,7 +725,13 @@ static void TransOnExchangeUdpInfoReply(AuthHandle authHandle, int64_t seq, cons ProcessAbnormalUdpChannelState(&(channel.info), errCode, true); return; } - int32_t ret = TransUnpackReplyUdpInfo(msg, &(channel.info)); + // TODO ljh 判断ostype + int32_t ret = SOFTBUS_OK; + if (channel.info.osType == HA_OS_TYPE) { + ret = TransUnpackExtDeviceReplyInfo(msg, &(channel.info)); + } else { + ret = TransUnpackReplyUdpInfo(msg, &(channel.info)); + } if (ret != SOFTBUS_OK) { TRANS_LOGE(TRANS_CTRL, "unpack reply udp info fail channelId=%{public}" PRId64, channel.info.myData.channelId); ProcessAbnormalUdpChannelState(&(channel.info), ret, true); @@ -832,8 +853,14 @@ static int32_t StartExchangeUdpInfo(UdpChannelInfo *channel, AuthHandle authHand TRANS_LOGE(TRANS_CTRL, "create cjson object failed."); return SOFTBUS_MEM_ERR; } - - if (TransPackRequestUdpInfo(requestMsg, &(channel->info)) != SOFTBUS_OK) { + // TODO ljh 判断是三方 + int32_t ret = SOFTBUS_AUTH_REG_DATA_FAIL; + if (channel->info.osType == HA_OS_TYPE) { + ret = TransPackExtDeviceRequestInfo(requestMsg, &(channel->info)); + } else { + ret = TransPackRequestUdpInfo(requestMsg, &(channel->info)); + } + if (ret != SOFTBUS_OK) { TRANS_LOGE(TRANS_CTRL, "pack request udp info failed."); cJSON_Delete(requestMsg); return SOFTBUS_TRANS_UDP_PACK_INFO_FAILED; @@ -851,7 +878,6 @@ static int32_t StartExchangeUdpInfo(UdpChannelInfo *channel, AuthHandle authHand .len = strlen(msgStr) + 1, .data = (const uint8_t *)msgStr, }; - int32_t ret = SOFTBUS_AUTH_REG_DATA_FAIL; ret = AuthPostTransData(authHandle, &dataInfo); if (ret != SOFTBUS_OK) { TRANS_LOGE(TRANS_CTRL, "AuthPostTransData failed."); diff --git a/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation_exchange.c b/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation_exchange.c index 1404770658..2197d79e5b 100644 --- a/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation_exchange.c +++ b/core/transmission/trans_channel/udp_negotiation/src/trans_udp_negotiation_exchange.c @@ -300,3 +300,167 @@ int32_t TransPackReplyErrInfo(cJSON *msg, int errCode, const char* errDesc) return SOFTBUS_OK; } + +int32_t TransPackExtDeviceRequestInfo(cJSON *msg, const AppInfo *appInfo) +{ + TRANS_LOGI(TRANS_CTRL, "pack request udp info in negotiation."); + if (msg == NULL || appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param."); + return SOFTBUS_INVALID_PARAM; + } + + switch (appInfo->udpChannelOptType) { + case TYPE_UDP_CHANNEL_OPEN: + (void)AddNumber64ToJsonObject(msg, "MY_CHANNEL_ID", appInfo->myData.channelId); + (void)AddStringToJsonObject(msg, "MY_IP", appInfo->myData.addr); + (void)AddStringToJsonObject(msg, "DEVICE_ID", appInfo->myData.deviceId); + 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."); + return SOFTBUS_TRANS_INVALID_CHANNEL_TYPE; + } + char encodeSessionKey[BASE64_SESSION_KEY_LEN] = {0}; + size_t len = 0; + int32_t ret = SoftBusBase64Encode((unsigned char*)encodeSessionKey, BASE64_SESSION_KEY_LEN, &len, + (unsigned char*)appInfo->sessionKey, sizeof(appInfo->sessionKey)); + TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_DECRYPT_ERR, TRANS_CTRL, "mbedtls decode failed."); + (void)AddStringToJsonObject(msg, "SESSION_KEY", encodeSessionKey); + (void)AddNumberToJsonObject(msg, "CODE", getCodeType(appInfo)); + (void)AddNumberToJsonObject(msg, "API_VERSION", appInfo->myData.apiVersion); + (void)AddNumberToJsonObject(msg, "BUSINESS_TYPE", appInfo->businessType); + (void)AddNumberToJsonObject(msg, "STREAM_TYPE", appInfo->streamType); + (void)AddNumberToJsonObject(msg, "CHANNEL_TYPE", appInfo->udpChannelOptType); + (void)AddNumberToJsonObject(msg, "UDP_CONN_TYPE", appInfo->udpConnType); + + (void)AddStringToJsonObject(msg, "BUS_NAME", appInfo->peerData.sessionName); + (void)AddStringToJsonObject(msg, "CLIENT_BUS_NAME", appInfo->myData.sessionName); + (void)AddStringToJsonObject(msg, "PKG_NAME", appInfo->myData.pkgName); + (void)AddNumberToJsonObject(msg, "TRANS_CAPABILITY", (int32_t)appInfo->channelCapability); + (void)memset_s(encodeSessionKey, sizeof(encodeSessionKey), 0, sizeof(encodeSessionKey)); + return SOFTBUS_OK; +} + +int32_t TransUnpackExtDeviceRequestInfo(const cJSON *msg, AppInfo *appInfo) +{ + TRANS_LOGI(TRANS_CTRL, "unpack external device request udp info in negotiation."); + 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); + if (strlen((char *)encodeSessionKey) != 0) { + int32_t ret = SoftBusBase64Decode((unsigned char *)appInfo->sessionKey, sizeof(appInfo->sessionKey), &len, + (unsigned char *)encodeSessionKey, strlen((char *)encodeSessionKey)); + (void)memset_s(encodeSessionKey, sizeof(encodeSessionKey), 0, sizeof(encodeSessionKey)); + 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)GetJsonObjectNumberItem(msg, "CHANNEL_TYPE", (int32_t *)&(appInfo->udpChannelOptType)); + switch (appInfo->udpChannelOptType) { + case TYPE_UDP_CHANNEL_OPEN: + (void)GetJsonObjectNumber64Item(msg, "MY_CHANNEL_ID", &(appInfo->peerData.channelId)); + (void)GetJsonObjectStringItem(msg, "MY_IP", appInfo->peerData.addr, sizeof(appInfo->peerData.addr)); + (void)GetJsonObjectStringItem(msg, "DEVICE_ID", appInfo->peerData.deviceId, UUID_BUF_LEN); + 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 == INVALID_CHANNEL_ID) { + (void)TransUdpGetChannelIdByAddr(appInfo); + } + break; + default: + TRANS_LOGE(TRANS_CTRL, "invalid udp channel type."); + return SOFTBUS_TRANS_INVALID_CHANNEL_TYPE; + } + (void)GetJsonObjectNumberItem(msg, "API_VERSION", (int32_t *)&(appInfo->peerData.apiVersion)); + (void)GetJsonObjectNumberItem(msg, "BUSINESS_TYPE", (int32_t *)&(appInfo->businessType)); + (void)GetJsonObjectNumberItem(msg, "STREAM_TYPE", (int32_t *)&(appInfo->streamType)); + (void)GetJsonObjectNumberItem(msg, "UDP_CONN_TYPE", (int32_t *)&(appInfo->udpConnType)); + (void)GetJsonObjectStringItem(msg, "BUS_NAME", appInfo->myData.sessionName, SESSION_NAME_SIZE_MAX); + (void)GetJsonObjectStringItem(msg, "CLIENT_BUS_NAME", appInfo->peerData.sessionName, SESSION_NAME_SIZE_MAX); + (void)GetJsonObjectStringItem(msg, "PKG_NAME", appInfo->peerData.pkgName, PKG_NAME_SIZE_MAX); + int code = CODE_EXCHANGE_UDP_INFO; + (void)GetJsonObjectNumberItem(msg, "CODE", &code); + if ((code == CODE_FILE_TRANS_UDP) && (getCodeType(appInfo) == CODE_FILE_TRANS_UDP)) { + appInfo->fileProtocol = APP_INFO_UDP_FILE_PROTOCOL; + } + uint32_t remoteCapability = 0; + (void)GetJsonObjectNumberItem(msg, "TRANS_CAPABILITY", (int32_t *)&remoteCapability); + appInfo->channelCapability = remoteCapability & TRANS_CHANNEL_CAPABILITY; + appInfo->peerData.userId = INVALID_USER_ID; + return SOFTBUS_OK; +} + +int32_t TransPackExtDeviceReplyInfo(cJSON *msg, const AppInfo *appInfo) +{ + TRANS_LOGI(TRANS_CTRL, "pack reply udp info in negotiation."); + if (msg == NULL || appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param."); + return SOFTBUS_INVALID_PARAM; + } + + switch (appInfo->udpChannelOptType) { + case TYPE_UDP_CHANNEL_OPEN: + (void)AddNumber64ToJsonObject(msg, "MY_CHANNEL_ID", appInfo->myData.channelId); + (void)AddNumberToJsonObject(msg, "MY_PORT", appInfo->myData.port); + (void)AddStringToJsonObject(msg, "MY_IP", appInfo->myData.addr); + break; + case TYPE_UDP_CHANNEL_CLOSE: + break; + default: + TRANS_LOGE(TRANS_CTRL, "invalid udp channel type."); + return SOFTBUS_TRANS_INVALID_CHANNEL_TYPE; + } + + (void)AddNumberToJsonObject(msg, "CODE", getCodeType(appInfo)); + (void)AddStringToJsonObject(msg, "PKG_NAME", appInfo->myData.pkgName); + (void)AddNumberToJsonObject(msg, "BUSINESS_TYPE", appInfo->businessType); + (void)AddNumberToJsonObject(msg, "STREAM_TYPE", appInfo->streamType); + (void)AddNumberToJsonObject(msg, "API_VERSION", (int32_t)appInfo->myData.apiVersion); + (void)AddNumberToJsonObject(msg, "TRANS_CAPABILITY", (int32_t)appInfo->channelCapability); + return SOFTBUS_OK; +} + +int32_t TransUnpackExtDeviceReplyInfo(const cJSON *msg, AppInfo *appInfo) +{ + TRANS_LOGI(TRANS_CTRL, "unpack reply udp info in negotiation."); + if (msg == NULL || appInfo == NULL) { + TRANS_LOGW(TRANS_CTRL, "invalid param."); + return SOFTBUS_INVALID_PARAM; + } + + switch (appInfo->udpChannelOptType) { + case TYPE_UDP_CHANNEL_OPEN: + (void)GetJsonObjectNumber64Item(msg, "MY_CHANNEL_ID", &(appInfo->peerData.channelId)); + (void)GetJsonObjectNumberItem(msg, "MY_PORT", &(appInfo->peerData.port)); + (void)GetJsonObjectStringItem(msg, "MY_IP", appInfo->peerData.addr, sizeof(appInfo->peerData.addr)); + break; + case TYPE_UDP_CHANNEL_CLOSE: + break; + default: + TRANS_LOGE(TRANS_CTRL, "invalid udp channel type."); + return SOFTBUS_TRANS_INVALID_CHANNEL_TYPE; + } + int code = CODE_EXCHANGE_UDP_INFO; + (void)GetJsonObjectNumberItem(msg, "CODE", &code); + if ((code == CODE_FILE_TRANS_UDP) && (getCodeType(appInfo) == CODE_FILE_TRANS_UDP)) { + appInfo->fileProtocol = APP_INFO_UDP_FILE_PROTOCOL; + } + (void)GetJsonObjectStringItem(msg, "PKG_NAME", appInfo->peerData.pkgName, PKG_NAME_SIZE_MAX); + (void)GetJsonObjectNumberItem(msg, "BUSINESS_TYPE", (int*)&(appInfo->businessType)); + (void)GetJsonObjectNumberItem(msg, "API_VERSION", (int32_t *)&(appInfo->peerData.apiVersion)); + (void)GetJsonObjectNumberItem(msg, "STREAM_TYPE", (int32_t *)&(appInfo->streamType)); + if (!GetJsonObjectNumberItem(msg, "TRANS_CAPABILITY", (int32_t *)&(appInfo->channelCapability))) { + appInfo->channelCapability = 0; + } + return SOFTBUS_OK; +} + diff --git a/interfaces/kits/bus_center/bus_center_info_key_struct.h b/interfaces/kits/bus_center/bus_center_info_key_struct.h index 6a3550c9a2..c579b7e3ca 100644 --- a/interfaces/kits/bus_center/bus_center_info_key_struct.h +++ b/interfaces/kits/bus_center/bus_center_info_key_struct.h @@ -27,6 +27,7 @@ extern "C" { #define MAC_LEN 18 #define OH_OS_TYPE 10 #define HO_OS_TYPE 11 +#define EXTRANAL_OS_TYPE 12 typedef enum { WLAN_IF = 0, diff --git a/tests/core/transmission/trans_channel/common/trans_lane_pending_test.cpp b/tests/core/transmission/trans_channel/common/trans_lane_pending_test.cpp index 0e96fd30b9..1c959aeab5 100644 --- a/tests/core/transmission/trans_channel/common/trans_lane_pending_test.cpp +++ b/tests/core/transmission/trans_channel/common/trans_lane_pending_test.cpp @@ -542,12 +542,14 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfoByQos001, TestSize.Level1) { SessionParam param; LaneAllocInfo allocInfo; + AppInfo appInfo; + (void)memset_s(&appInfo, sizeof(AppInfo), 0, sizeof(AppInfo)); uint32_t laneHandle; - int32_t ret = TransAsyncGetLaneInfoByQos(nullptr, &allocInfo, &laneHandle, 0, 0); + int32_t ret = TransAsyncGetLaneInfoByQos(nullptr, &allocInfo, &laneHandle, &appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - ret = TransAsyncGetLaneInfoByQos(¶m, nullptr, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfoByQos(¶m, nullptr, &laneHandle, &appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - ret = TransAsyncGetLaneInfoByQos(¶m, &allocInfo, nullptr, 0, 0); + ret = TransAsyncGetLaneInfoByQos(¶m, &allocInfo, nullptr, &appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); } @@ -563,19 +565,21 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfoByQos001, TestSize.Level1) ASSERT_TRUE(newParam != nullptr); LaneAllocInfo allocInfo; uint32_t laneHandle; + AppInfo appInfo; + (void)memset_s(&appInfo, sizeof(AppInfo), 0, sizeof(AppInfo)); NiceMock TransLanePendingMock; EXPECT_CALL(TransLanePendingMock, GetLaneManager).WillOnce(Return(nullptr)); - int32_t ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, 0, 0); + int32_t ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_TRANS_GET_LANE_INFO_ERR, ret); EXPECT_CALL(TransLanePendingMock, GetLaneManager).WillRepeatedly(Return(&g_LaneManagerApplyFail)); - ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_TRANS_GET_LANE_INFO_ERR, ret); SoftBusList *tmpList = g_asyncReqLanePendingList; g_asyncReqLanePendingList = nullptr; EXPECT_CALL(TransLanePendingMock, GetLaneManager).WillRepeatedly(Return(&g_LaneManager)); - ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); g_asyncReqLanePendingList = tmpList; @@ -585,7 +589,7 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfoByQos001, TestSize.Level1) ret = TransAddSocketChannelInfo(TEST_NEW_SESSION_NAME, TEST_NEW_SESSION_ID, TEST_NEW_CHANNEL_ID, channelType, state); EXPECT_EQ(SOFTBUS_OK, ret); - ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_TRANS_STOP_BIND_BY_CANCEL, ret); ret = TransDeleteSocketChannelInfoBySession(TEST_NEW_SESSION_NAME, TEST_NEW_SESSION_ID); EXPECT_EQ(SOFTBUS_OK, ret); @@ -594,7 +598,7 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfoByQos001, TestSize.Level1) ret = TransAddSocketChannelInfo(TEST_NEW_SESSION_NAME, TEST_NEW_SESSION_ID, TEST_NEW_CHANNEL_ID, channelType, state); EXPECT_EQ(SOFTBUS_OK, ret); - ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfoByQos(newParam, &allocInfo, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_OK, ret); ret = TransDeleteSocketChannelInfoBySession(TEST_NEW_SESSION_NAME, TEST_NEW_SESSION_ID); EXPECT_EQ(SOFTBUS_OK, ret); @@ -1350,13 +1354,15 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfo001, TestSize.Level1) { SessionParam param; uint32_t laneHandle; - int32_t ret = TransAsyncGetLaneInfo(nullptr, nullptr, 0, 0); + AppInfo appInfo; + (void)memset_s(&appInfo, sizeof(AppInfo), 0, sizeof(AppInfo)); + int32_t ret = TransAsyncGetLaneInfo(nullptr, nullptr, appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - ret = TransAsyncGetLaneInfo(¶m, nullptr, 0, 0); + ret = TransAsyncGetLaneInfo(¶m, nullptr, appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - ret = TransAsyncGetLaneInfo(nullptr, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfo(nullptr, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); } @@ -1373,7 +1379,9 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfo002, TestSize.Level1) EXPECT_CALL(TransLanePendingMock, TransGetLaneTransTypeBySession).WillOnce(Return(LANE_T_BUTT)); SessionParam *param = TestCreateSessionParamWithPara(SESSION_NAME_PHONEPAD); ASSERT_TRUE(param != nullptr); - int32_t ret = TransAsyncGetLaneInfo(param, &laneHandle, 0, 0); + AppInfo appInfo; + (void)memset_s(&appInfo, sizeof(AppInfo), 0, sizeof(AppInfo)); + int32_t ret = TransAsyncGetLaneInfo(param, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_TRANS_INVALID_SESSION_TYPE, ret); EXPECT_CALL(TransLanePendingMock, TransGetLaneTransTypeBySession).WillRepeatedly(Return(LANE_T_MSG)); @@ -1381,7 +1389,7 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfo002, TestSize.Level1) EXPECT_CALL(TransLanePendingMock, LnnHasDiscoveryType).WillRepeatedly(Return(true)); EXPECT_CALL(TransLanePendingMock, LnnGetRemoteStrInfo).WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(TransLanePendingMock, TransGetUidAndPid).WillRepeatedly(Return(SOFTBUS_OK)); - ret = TransAsyncGetLaneInfo(param, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfo(param, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_TRANS_GET_LANE_INFO_ERR, ret); int32_t channelType = CHANNEL_TYPE_TCP_DIRECT; @@ -1391,7 +1399,7 @@ HWTEST_F(TransLanePendingTest, TransAsyncGetLaneInfo002, TestSize.Level1) ret = TransAddSocketChannelInfo(TEST_SESSION_NAME, TEST_SESSION_ID, TEST_CHANNEL_ID, channelType, state); EXPECT_EQ(SOFTBUS_OK, ret); - ret = TransAsyncGetLaneInfo(param, &laneHandle, 0, 0); + ret = TransAsyncGetLaneInfo(param, &laneHandle, appInfo); EXPECT_EQ(SOFTBUS_OK, ret); ret = TransDeleteSocketChannelInfoBySession(TEST_SESSION_NAME, TEST_SESSION_ID); diff --git a/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.cpp b/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.cpp index e15eef4f59..8ec6c8d244 100644 --- a/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.cpp +++ b/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.cpp @@ -62,9 +62,9 @@ int32_t TransCommonGetAppInfo(const SessionParam *param, AppInfo *appInfo) } int32_t TransAsyncGetLaneInfo( - const SessionParam *param, uint32_t *laneHandle, uint64_t callingTokenId, int64_t timeStart) + const SessionParam *param, uint32_t *laneHandle, const AppInfo *appInfo) { - return GetTransManagerInterface()->TransAsyncGetLaneInfo(param, laneHandle, callingTokenId, timeStart); + return GetTransManagerInterface()->TransAsyncGetLaneInfo(param, laneHandle, appInfo); } int32_t TransGetLaneInfo(const SessionParam *param, LaneConnInfo *connInfo, uint32_t *laneHandle) diff --git a/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.h b/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.h index 13fb6ddfdc..99ac771a53 100644 --- a/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.h +++ b/tests/core/transmission/trans_channel/manager/mock/trans_manager_mock.h @@ -38,7 +38,7 @@ public: virtual uint64_t TransAclGetFirstTokenID() = 0; virtual int32_t TransCommonGetAppInfo(const SessionParam *param, AppInfo *appInfo) = 0; virtual int32_t TransAsyncGetLaneInfo( - const SessionParam *param, uint32_t *laneHandle, uint32_t callingTokenId, int64_t timeStart) = 0; + const SessionParam *param, uint32_t *laneHandle, const AppInfo *appInfo) = 0; virtual int32_t TransGetLaneInfo(const SessionParam *param, LaneConnInfo *connInfo, uint32_t *laneHandle) = 0; virtual int32_t TransGetConnectOptByConnInfo(const LaneConnInfo *info, ConnectOption *connOpt) = 0; virtual int32_t TransOpenChannelProc( @@ -58,7 +58,7 @@ public: MOCK_METHOD2(ConnGetConnectionInfo, int32_t (uint32_t, ConnectionInfo *)); MOCK_METHOD0(TransAclGetFirstTokenID, uint64_t ()); MOCK_METHOD2(TransCommonGetAppInfo, int32_t (const SessionParam *, AppInfo *)); - MOCK_METHOD4(TransAsyncGetLaneInfo, int32_t (const SessionParam *, uint32_t *, uint32_t, int64_t)); + MOCK_METHOD3(TransAsyncGetLaneInfo, int32_t (const SessionParam *, uint32_t *, const AppInfo *)); MOCK_METHOD3(TransGetLaneInfo, int32_t (const SessionParam *, LaneConnInfo *, uint32_t *)); MOCK_METHOD2(TransGetConnectOptByConnInfo, int32_t (const LaneConnInfo *, ConnectOption *)); MOCK_METHOD4(TransOpenChannelProc, int32_t (ChannelType, AppInfo *, const ConnectOption *, int32_t *)); diff --git a/tests/core/transmission/trans_channel/tcp_direct/unittest/trans_tcp_direct_message_append_test.cpp b/tests/core/transmission/trans_channel/tcp_direct/unittest/trans_tcp_direct_message_append_test.cpp index 85a468fae6..08fbecb675 100644 --- a/tests/core/transmission/trans_channel/tcp_direct/unittest/trans_tcp_direct_message_append_test.cpp +++ b/tests/core/transmission/trans_channel/tcp_direct/unittest/trans_tcp_direct_message_append_test.cpp @@ -886,7 +886,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest001, TestSize.Leve uint64_t seq = TEST_SEQ; cJSON *reply = cJSON_CreateObject(); - int32_t ret = OpenDataBusReply(channelId, seq, reply); + int32_t ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_TRANS_GET_SESSION_CONN_FAILED); cJSON_Delete(reply); } @@ -909,7 +909,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest002, TestSize.Leve NiceMock TcpMessageMock; EXPECT_CALL(TcpMessageMock, UnpackReplyErrCode).WillOnce(Return(SOFTBUS_OK)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_OK); TransDelSessionConnById(channelId); @@ -935,7 +935,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest003, TestSize.Leve NiceMock TcpMessageMock; EXPECT_CALL(TcpMessageMock, UnpackReplyErrCode).WillOnce(Return(SOFTBUS_MEM_ERR)); EXPECT_CALL(TcpMessageMock, UnpackReply).WillOnce(Return(SOFTBUS_MEM_ERR)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_TRANS_UNPACK_REPLY_FAILED); TransDelSessionConnById(channelId); @@ -962,7 +962,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest004, TestSize.Leve EXPECT_CALL(TcpMessageMock, UnpackReplyErrCode).WillOnce(Return(SOFTBUS_MEM_ERR)); EXPECT_CALL(TcpMessageMock, UnpackReply).WillOnce(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_MEM_ERR)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_MEM_ERR); TransDelSessionConnById(channelId); @@ -990,7 +990,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest005, TestSize.Leve EXPECT_CALL(TcpMessageMock, UnpackReply).WillOnce(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SetAppInfoById).WillRepeatedly(Return(SOFTBUS_MEM_ERR)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_MEM_ERR); EXPECT_CALL(TcpMessageMock, UnpackReplyErrCode).WillRepeatedly(Return(SOFTBUS_MEM_ERR)); @@ -998,7 +998,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest005, TestSize.Leve EXPECT_CALL(TcpMessageMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SetAppInfoById).WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, GetErrCodeBySocketErr).WillRepeatedly(Return(SOFTBUS_CONN_SOCKET_EINTR)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(SOFTBUS_ENCRYPT_ERR, ret); TransDelSessionConnById(channelId); @@ -1027,7 +1027,7 @@ HWTEST_F(TransTcpDirectMessageAppendTest, OpenDataBusReplyTest006, TestSize.Leve EXPECT_CALL(TcpMessageMock, UnpackReply).WillOnce(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(TcpMessageMock, SetAppInfoById).WillRepeatedly(Return(SOFTBUS_OK)); - ret = OpenDataBusReply(channelId, seq, reply); + ret = OpenDataBusReply(channelId, seq, reply, 0); EXPECT_EQ(ret, SOFTBUS_TRANS_GET_P2P_INFO_FAILED); TransDelSessionConnById(channelId); -- Gitee