From f9ef8211560301645a25659ac013cdafe4200b26 Mon Sep 17 00:00:00 2001 From: erestu Date: Thu, 21 Nov 2024 17:28:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=8F=E8=AE=AE=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: erestu --- .../dfile/core/nstackx_dfile_frame.c | 103 ++++++++++++++---- 1 file changed, 81 insertions(+), 22 deletions(-) diff --git a/components/nstackx/nstackx_core/dfile/core/nstackx_dfile_frame.c b/components/nstackx/nstackx_core/dfile/core/nstackx_dfile_frame.c index 553d103a7..952e923c0 100644 --- a/components/nstackx/nstackx_core/dfile/core/nstackx_dfile_frame.c +++ b/components/nstackx/nstackx_core/dfile/core/nstackx_dfile_frame.c @@ -598,6 +598,85 @@ static uint8_t IsSettingFrameMtuAndTypeValid(const SettingFrame *netSettingFrame return NSTACKX_TRUE; } +static void DecodeSettingFrameDfxPayload(uint16_t payloadLength, SettingFrame *netSettingFrame, + SettingFrame *hostSettingFrame) +{ + if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + + sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) + + sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) + + sizeof(hostSettingFrame->capsCheck))) { + if (strnlen(netSettingFrame->productVersion, VERSION_STR_LEN) == VERSION_STR_LEN) { + (void)memset_s(hostSettingFrame->productVersion, VERSION_STR_LEN, 0, VERSION_STR_LEN); + DFILE_LOGD(TAG, "DFX, remote productVersion is wrong"); + } else { + DFILE_LOGD(TAG, "DFX, remote productVersion: %s", netSettingFrame->productVersion); + if (strncpy_s(hostSettingFrame->productVersion, VERSION_STR_LEN, + netSettingFrame->productVersion, strlen(netSettingFrame->productVersion)) != 0) { + DFILE_LOGW(TAG, "DFX, Decode strncpy ProductVersion fail"); + } + } + } + + if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + + sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) + + sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) + + sizeof(hostSettingFrame->capsCheck) + sizeof(hostSettingFrame->productVersion))) { + hostSettingFrame->isSupport160M = netSettingFrame->isSupport160M; + DFILE_LOGD(TAG, "DFX, DecodeSettingFrame, isSupport160M:%d", hostSettingFrame->isSupport160M); + } +} + +static void DecodeSettingFrameInner(uint16_t payloadLength, SettingFrame *netSettingFrame, + SettingFrame *hostSettingFrame) +{ + size_t hostFrameLength = 0; + + hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion); + hostSettingFrame->abmCapability = ntohl(netSettingFrame->abmCapability); + hostFrameLength += sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + + sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->capability = ntohl(netSettingFrame->capability); + } + hostFrameLength += sizeof(hostSettingFrame->capability); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->dataFrameSize = ntohl(netSettingFrame->dataFrameSize); + } + hostFrameLength += sizeof(hostSettingFrame->dataFrameSize); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->capsCheck = ntohl(netSettingFrame->capsCheck); + } + + /* DFX */ + DecodeSettingFrameDfxPayload(payloadLength, netSettingFrame, hostSettingFrame); + hostFrameLength += sizeof(hostSettingFrame->capsCheck) + sizeof(hostSettingFrame->productVersion) + + sizeof(hostSettingFrame->isSupport160M); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->isSupportMtp = netSettingFrame->isSupportMtp; + hostSettingFrame->mtpPort = netSettingFrame->mtpPort; + } + hostFrameLength += sizeof(hostSettingFrame->isSupportMtp) + sizeof(hostSettingFrame->mtpPort); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->headerEnc = netSettingFrame->headerEnc; + } + hostFrameLength += sizeof(hostSettingFrame->headerEnc); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->mtpCapability = ntohl(netSettingFrame->mtpCapability); + } + hostFrameLength += sizeof(hostSettingFrame->mtpCapability); + + if (payloadLength > hostFrameLength) { + hostSettingFrame->cipherCapability = ntohl(netSettingFrame->cipherCapability); + } + hostFrameLength += sizeof(hostSettingFrame->cipherCapability); +} + static int32_t DFileCheckSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSettingFrame) { if (netSettingFrame->header.sessionId != 0 || netSettingFrame->header.transId != 0) { @@ -629,6 +708,7 @@ int32_t DecodeSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSett hostSettingFrame->header.sessionId = netSettingFrame->header.sessionId; hostSettingFrame->mtu = ntohs(netSettingFrame->mtu); hostSettingFrame->connType = ntohs(netSettingFrame->connType); + if (payloadLength == sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType)) { /* * In this condition, this netSettingFrame is from an old version and doesn't have the member dFileVersion. @@ -643,28 +723,7 @@ int32_t DecodeSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSett hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion); hostSettingFrame->abmCapability = 0; } else { - hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion); - hostSettingFrame->abmCapability = ntohl(netSettingFrame->abmCapability); - if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + - sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability))) { - hostSettingFrame->capability = ntohl(netSettingFrame->capability); - } - if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + - sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) + - sizeof(hostSettingFrame->capability))) { - hostSettingFrame->dataFrameSize = ntohl(netSettingFrame->dataFrameSize); - } - if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + - sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) + - sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize))) { - hostSettingFrame->capsCheck = ntohl(netSettingFrame->capsCheck); - } - if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) + - sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) + - sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) + - sizeof(hostSettingFrame->capsCheck))) { - hostSettingFrame->cipherCapability = ntohl(netSettingFrame->cipherCapability); - } + DecodeSettingFrameInner(payloadLength, netSettingFrame, hostSettingFrame); } DFILE_LOGI(TAG, "local version is %u, remote version is %u capability 0x%x dataFrameSize %u capsCheck 0x%x " "cipherCaps 0x%x",