Skip to content

Commit

Permalink
Merge 864b170 into 0840ca6
Browse files Browse the repository at this point in the history
  • Loading branch information
pidarped authored Jul 17, 2024
2 parents 0840ca6 + 864b170 commit 1351080
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ CHIP_ERROR DnssdServer::AdvertiseOperational()
AddICDKeyToAdvertisement(advertiseParameters);
#endif

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
advertiseParameters.SetTCPSupportModes(chip::Dnssd::TCPModeAdvertise::kTCPClientServer);
#endif
auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance();

ChipLogProgress(Discovery, "Advertise operational node " ChipLogFormatX64 "-" ChipLogFormatX64,
Expand Down
1 change: 1 addition & 0 deletions src/app/server/Dnssd.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DLL_EXPORT DnssdServer : public ICDStateObserver

void SetICDManager(ICDManager * manager) { mICDManager = manager; };
#endif

/// Start operational advertising
CHIP_ERROR AdvertiseOperational();

Expand Down
17 changes: 12 additions & 5 deletions src/lib/dnssd/Advertiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ enum class ICDModeAdvertise : uint8_t
kLIT, // The ICD is currently operating as a LIT. ICD=1 in DNS-SD key/value pairs.
};

enum class TCPModeAdvertise : uint16_t
{
kNone = 0, // The device does not support TCP.
kTCPClient = 1 << 1, // The device supports the TCP client.
kTCPServer = 1 << 2, // The device supports the TCP server.
kTCPClientServer = (kTCPClient | kTCPServer), // The device supports both the TCP client and server.
};

template <class Derived>
class BaseAdvertisingParams
{
Expand Down Expand Up @@ -102,13 +110,12 @@ class BaseAdvertisingParams
}
const std::optional<ReliableMessageProtocolConfig> & GetLocalMRPConfig() const { return mLocalMRPConfig; }

// NOTE: The SetTcpSupported API is deprecated and not compliant with 1.3. T flag should not be set.
Derived & SetTcpSupported(std::optional<bool> tcpSupported)
Derived & SetTCPSupportModes(TCPModeAdvertise tcpSupportModes)
{
mTcpSupported = tcpSupported;
mTcpSupportModes = tcpSupportModes;
return *reinterpret_cast<Derived *>(this);
}
std::optional<bool> GetTcpSupported() const { return mTcpSupported; }
TCPModeAdvertise GetTCPSupportModes() const { return mTcpSupportModes; }

Derived & SetICDModeToAdvertise(ICDModeAdvertise operatingMode)
{
Expand All @@ -124,7 +131,7 @@ class BaseAdvertisingParams
uint8_t mMacStorage[kMaxMacSize] = {};
size_t mMacLength = 0;
std::optional<ReliableMessageProtocolConfig> mLocalMRPConfig;
std::optional<bool> mTcpSupported;
TCPModeAdvertise mTcpSupportModes = TCPModeAdvertise::kNone;
ICDModeAdvertise mICDModeAdvertise = ICDModeAdvertise::kNone;
};

Expand Down
6 changes: 3 additions & 3 deletions src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
}
}

if (const auto & tcpSupported = params.GetTcpSupported(); tcpSupported.has_value())
if (params.GetTCPSupportModes() != TCPModeAdvertise::kNone)
{
size_t writtenCharactersNumber =
static_cast<size_t>(snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf), "T=%d", *tcpSupported));
size_t writtenCharactersNumber = static_cast<size_t>(snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf),
"T=%d", static_cast<int>(params.GetTCPSupportModes())));
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.tcpSupportedBuf)),
CHIP_ERROR_INVALID_STRING_LENGTH);
txtFields[numTxtFields++] = storage.tcpSupportedBuf;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/dnssd/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ CHIP_ERROR CopyTxtRecord(TxtFieldKey key, char * buffer, size_t bufferLen, const
switch (key)
{
case TxtFieldKey::kTcpSupported:
return CopyTextRecordValue(buffer, bufferLen, params.GetTcpSupported());
VerifyOrReturnError(params.GetTCPSupportModes() != TCPModeAdvertise::kNone, CHIP_ERROR_UNINITIALIZED);
return CopyTextRecordValue(buffer, bufferLen, to_underlying(params.GetTCPSupportModes()));
case TxtFieldKey::kSessionIdleInterval:
#if CHIP_CONFIG_ENABLE_ICD_SERVER
// A ICD operating as a LIT should not advertise its slow polling interval
Expand Down

0 comments on commit 1351080

Please sign in to comment.