mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 00:39:52 +00:00
commit
586328143e
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user