diff --git a/sdk/libsoftbus_client_map b/sdk/libsoftbus_client_map index ee02fe8ce..24b1822c9 100644 --- a/sdk/libsoftbus_client_map +++ b/sdk/libsoftbus_client_map @@ -381,6 +381,7 @@ "ClientGetSessionCallbackAdapterByName"; "ClientGetSessionCallbackAdapterById"; "ClientGetPeerSocketInfoById"; + "ClientGetSessionNameByChannelId"; "TransSetSocketFileListener"; "EvaluateQos"; "GetMtuSize"; @@ -487,4 +488,4 @@ }; local: *; -}; \ No newline at end of file +}; diff --git a/sdk/transmission/session/include/client_trans_session_manager.h b/sdk/transmission/session/include/client_trans_session_manager.h index 0d315f195..b3b5abcd1 100644 --- a/sdk/transmission/session/include/client_trans_session_manager.h +++ b/sdk/transmission/session/include/client_trans_session_manager.h @@ -177,6 +177,8 @@ int32_t ClientGetPeerSocketInfoById(int32_t sessionId, PeerSocketInfo *peerSocke bool IsSessionExceedLimit(); int32_t ClientResetIdleTimeoutById(int32_t sessionId); + +int32_t ClientGetSessionNameByChannelId(int32_t channelId, int32_t channelType, char *sessionName, int32_t len); #ifdef __cplusplus } #endif diff --git a/sdk/transmission/session/src/client_trans_session_manager.c b/sdk/transmission/session/src/client_trans_session_manager.c index c5c03786b..ade8421d5 100644 --- a/sdk/transmission/session/src/client_trans_session_manager.c +++ b/sdk/transmission/session/src/client_trans_session_manager.c @@ -2230,4 +2230,43 @@ int32_t ClientResetIdleTimeoutById(int32_t sessionId) (void)SoftBusMutexUnlock(&g_clientSessionServerList->lock); TRANS_LOGE(TRANS_SDK, "not found session by sessionId=%{public}d", sessionId); return SOFTBUS_NOT_FIND; -} \ No newline at end of file +} + +int32_t ClientGetSessionNameByChannelId(int32_t channelId, int32_t channelType, char *sessionName, int32_t len) +{ + if (channelId < 0 || sessionName == NULL || len <= 0 || len > SESSION_NAME_SIZE_MAX) { + TRANS_LOGW(TRANS_SDK, "Invalid param"); + return SOFTBUS_INVALID_PARAM; + } + + if (g_clientSessionServerList == NULL) { + TRANS_LOGE(TRANS_INIT, "entry list not init"); + return SOFTBUS_TRANS_SESSION_SERVER_NOINIT; + } + + ClientSessionServer *serverNode = NULL; + SessionInfo *sessionNode = NULL; + + if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) { + TRANS_LOGE(TRANS_SDK, "lock failed"); + return SOFTBUS_LOCK_ERR; + } + + LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) { + if (IsListEmpty(&serverNode->sessionList)) { + continue; + } + + LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) { + if (sessionNode->channelId == channelId && sessionNode->channelType == (ChannelType)channelType) { + (void)memcpy_s(sessionName, len, serverNode->sessionName, len); + (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock)); + return SOFTBUS_OK; + } + } + } + + (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock)); + TRANS_LOGE(TRANS_SDK, "not found session with channelId=%{public}d", channelId); + return SOFTBUS_ERR; +} diff --git a/sdk/transmission/trans_channel/tcp_direct/src/client_trans_tcp_direct_message.c b/sdk/transmission/trans_channel/tcp_direct/src/client_trans_tcp_direct_message.c index 5ed0fd229..a9982df3b 100644 --- a/sdk/transmission/trans_channel/tcp_direct/src/client_trans_tcp_direct_message.c +++ b/sdk/transmission/trans_channel/tcp_direct/src/client_trans_tcp_direct_message.c @@ -19,6 +19,7 @@ #include "client_trans_tcp_direct_callback.h" #include "client_trans_tcp_direct_manager.h" +#include "client_trans_session_manager.h" #include "common_list.h" #include "softbus_adapter_crypto.h" #include "softbus_adapter_mem.h" @@ -37,6 +38,7 @@ #define MIN_BUF_LEN (1024 + DATA_EXTEND_LEN) #define BYTE_TOS 0x60 +#define COLLABORATE_BYTE_TOS 0x80 #define MESSAGE_TOS 0xC0 typedef struct { @@ -160,6 +162,14 @@ static char *TransTdcPackData(const TcpDirectChannelInfo *channel, const char *d return buf; } +static bool CheckCollaborationSessionName(const char *sessionName) +{ + if (strstr(sessionName, "ohos.collaborationcenter") != NULL) { + return true; + } + return false; +} + static int32_t TransTdcProcessPostData(const TcpDirectChannelInfo *channel, const char *data, uint32_t len, int32_t flags) { @@ -174,7 +184,16 @@ static int32_t TransTdcProcessPostData(const TcpDirectChannelInfo *channel, cons SoftBusFree(buf); return SOFTBUS_ENCRYPT_ERR; } + char sessionName[SESSION_NAME_SIZE_MAX + 1] = { 0 }; + if (ClientGetSessionNameByChannelId(channel->channelId, channel->detail.channelType, + sessionName, SESSION_NAME_SIZE_MAX)) { + TRANS_LOGE(TRANS_SDK, "failed to get sessionName, channelId=%{public}d", channel->channelId); + return SOFTBUS_ERR; + } uint32_t tos = (flags == FLAG_BYTES) ? BYTE_TOS : MESSAGE_TOS; + if (CheckCollaborationSessionName(sessionName)) { + tos = (flags == FLAG_BYTES) ? COLLABORATE_BYTE_TOS : MESSAGE_TOS; + } if (SetIpTos(channel->detail.fd, tos) != SOFTBUS_OK) { SoftBusFree(buf); return SOFTBUS_TCP_SOCKET_ERR;