Skip to content

Commit bc47623

Browse files
committed
Miscellaneous fixes for ifdefs, large payload flag, marking session with connection, etc.
1 parent e2d5f67 commit bc47623

28 files changed

+326
-136
lines changed

src/app/CASESessionManager.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Cal
3535
,
3636
uint8_t attemptCount, Callback::Callback<OnDeviceConnectionRetry> * onRetry
3737
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
38+
, bool forLargePayload
3839
)
3940
{
4041
ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = [%d:" ChipLogFormatX64 "]", peerId.GetFabricIndex(),
@@ -66,7 +67,7 @@ void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Cal
6667
}
6768
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
6869

69-
session->Connect(onConnection, onFailure);
70+
session->Connect(onConnection, onFailure, forLargePayload);
7071
}
7172

7273
void CASESessionManager::ReleaseSessionsForFabric(FabricIndex fabricIndex)
@@ -82,7 +83,16 @@ void CASESessionManager::ReleaseAllSessions()
8283
CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
8384
{
8485
ReturnErrorOnFailure(mConfig.sessionInitParams.Validate());
85-
auto optionalSessionHandle = FindExistingSession(peerId);
86+
auto optionalSessionHandle = FindExistingSession(peerId, false);
87+
ReturnErrorCodeIf(!optionalSessionHandle.HasValue(), CHIP_ERROR_NOT_CONNECTED);
88+
addr = optionalSessionHandle.Value()->AsSecureSession()->GetPeerAddress();
89+
return CHIP_NO_ERROR;
90+
}
91+
92+
CHIP_ERROR CASESessionManager::GetPeerAddressForLargePayloadSession(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
93+
{
94+
ReturnErrorOnFailure(mConfig.sessionInitParams.Validate());
95+
auto optionalSessionHandle = FindExistingSession(peerId, true);
8696
ReturnErrorCodeIf(!optionalSessionHandle.HasValue(), CHIP_ERROR_NOT_CONNECTED);
8797
addr = optionalSessionHandle.Value()->AsSecureSession()->GetPeerAddress();
8898
return CHIP_NO_ERROR;
@@ -118,10 +128,11 @@ OperationalSessionSetup * CASESessionManager::FindExistingSessionSetup(const Sco
118128
return mConfig.sessionSetupPool->FindSessionSetup(peerId, forAddressUpdate);
119129
}
120130

121-
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId) const
131+
Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNodeId & peerId, const bool forLargePayload) const
122132
{
123133
return mConfig.sessionInitParams.sessionManager->FindSecureSessionForNode(peerId,
124-
MakeOptional(Transport::SecureSession::Type::kCASE));
134+
MakeOptional(Transport::SecureSession::Type::kCASE),
135+
forLargePayload);
125136
}
126137

127138
void CASESessionManager::ReleaseSession(OperationalSessionSetup * session)

src/app/CASESessionManager.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CASESessionManager : public OperationalSessionReleaseDelegate, public Sess
8585
,
8686
uint8_t attemptCount = 1, Callback::Callback<OnDeviceConnectionRetry> * onRetry = nullptr
8787
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
88+
, bool forLargePayload = false
8889
);
8990

9091
void ReleaseSessionsForFabric(FabricIndex fabricIndex);
@@ -101,6 +102,8 @@ class CASESessionManager : public OperationalSessionReleaseDelegate, public Sess
101102
*/
102103
CHIP_ERROR GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr);
103104

105+
CHIP_ERROR GetPeerAddressForLargePayloadSession(const ScopedNodeId & peerId, Transport::PeerAddress & addr);
106+
104107
//////////// OperationalSessionReleaseDelegate Implementation ///////////////
105108
void ReleaseSession(OperationalSessionSetup * device) override;
106109

@@ -110,7 +113,7 @@ class CASESessionManager : public OperationalSessionReleaseDelegate, public Sess
110113
private:
111114
OperationalSessionSetup * FindExistingSessionSetup(const ScopedNodeId & peerId, bool forAddressUpdate = false) const;
112115

113-
Optional<SessionHandle> FindExistingSession(const ScopedNodeId & peerId) const;
116+
Optional<SessionHandle> FindExistingSession(const ScopedNodeId & peerId, const bool forLargePayload = false) const;
114117

115118
CASESessionManagerConfig mConfig;
116119
};

src/app/OperationalSessionSetup.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ bool OperationalSessionSetup::AttachToExistingSecureSession()
7777
false);
7878

7979
auto sessionHandle =
80-
mInitParams.sessionManager->FindSecureSessionForNode(mPeerId, MakeOptional(Transport::SecureSession::Type::kCASE));
80+
mInitParams.sessionManager->FindSecureSessionForNode(mPeerId, MakeOptional(Transport::SecureSession::Type::kCASE),
81+
mSessionForLargePayload);
8182
if (!sessionHandle.HasValue())
8283
return false;
8384

@@ -92,11 +93,13 @@ bool OperationalSessionSetup::AttachToExistingSecureSession()
9293
}
9394

9495
void OperationalSessionSetup::Connect(Callback::Callback<OnDeviceConnected> * onConnection,
95-
Callback::Callback<OnDeviceConnectionFailure> * onFailure)
96+
Callback::Callback<OnDeviceConnectionFailure> * onFailure,
97+
bool forLargePayload)
9698
{
9799
CHIP_ERROR err = CHIP_NO_ERROR;
98100
bool isConnected = false;
99101

102+
mSessionForLargePayload = forLargePayload;
100103
//
101104
// Always enqueue our user provided callbacks into our callback list.
102105
// If anything goes wrong below, we'll trigger failures (including any queued from
@@ -278,9 +281,13 @@ CHIP_ERROR OperationalSessionSetup::EstablishConnection(const ReliableMessagePro
278281
mCASEClient = mClientPool->Allocate();
279282
ReturnErrorCodeIf(mCASEClient == nullptr, CHIP_ERROR_NO_MEMORY);
280283

281-
#if CHIP_CONFIG_TCP_SUPPORT_ENABLED
282-
mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp);
283-
#endif // CHIP_CONFIG_TCP_SUPPORT_ENABLED
284+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
285+
// TODO: Combine LargePayload flag with DNS-SD advertisements from peer
286+
if (mSessionForLargePayload)
287+
{
288+
mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp);
289+
}
290+
#endif
284291

285292
CHIP_ERROR err = mCASEClient->EstablishSession(mInitParams, mPeerId, mDeviceAddress, config, this);
286293
if (err != CHIP_NO_ERROR)

src/app/OperationalSessionSetup.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate,
189189
* `onFailure` may be called before the Connect call returns, for error
190190
* cases that are detected synchronously (e.g. inability to start an address
191191
* lookup).
192+
*
193+
* `forLargePayload` is set to true when the session needs to be established
194+
* over a transport that allows large payloads to be transferred, e.g., TCP.
192195
*/
193-
void Connect(Callback::Callback<OnDeviceConnected> * onConnection, Callback::Callback<OnDeviceConnectionFailure> * onFailure);
196+
void Connect(Callback::Callback<OnDeviceConnected> * onConnection, Callback::Callback<OnDeviceConnectionFailure> * onFailure,
197+
bool forLargePayload = false);
194198

195199
bool IsForAddressUpdate() const { return mPerformingAddressUpdate; }
196200

@@ -274,6 +278,8 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate,
274278

275279
bool mPerformingAddressUpdate = false;
276280

281+
bool mSessionForLargePayload = false;
282+
277283
#if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
278284
// When we TryNextResult on the resolver, it will synchronously call back
279285
// into our OnNodeAddressResolved when it succeeds. We need to track

src/app/server/Server.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ using chip::Transport::BleListenParameters;
6767
#endif
6868
using chip::Transport::PeerAddress;
6969
using chip::Transport::UdpListenParameters;
70+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
71+
using chip::Transport::TcpListenParameters;
72+
#endif
7073

7174
namespace {
7275

@@ -197,6 +200,12 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
197200
#if CONFIG_NETWORK_LAYER_BLE
198201
,
199202
BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer())
203+
#endif
204+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
205+
,
206+
TcpListenParameters(DeviceLayer::TCPEndPointManager())
207+
.SetAddressType(IPAddressType::kIPv6)
208+
.SetListenPort(mOperationalServicePort)
200209
#endif
201210
);
202211

src/app/server/Server.h

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ namespace chip {
7575

7676
inline constexpr size_t kMaxBlePendingPackets = 1;
7777

78+
inline constexpr size_t kMaxTcpActiveConnectionCount = CHIP_CONFIG_DEVICE_MAX_ACTIVE_TCP_CONNECTIONS;
79+
80+
inline constexpr size_t kMaxTcpPendingPackets = CHIP_CONFIG_MAX_TCP_PENDING_PACKETS;
81+
7882
//
7983
// NOTE: Please do not alter the order of template specialization here as the logic
8084
// in the Server impl depends on this.
@@ -87,6 +91,10 @@ using ServerTransportMgr = chip::TransportMgr<chip::Transport::UDP
8791
#if CONFIG_NETWORK_LAYER_BLE
8892
,
8993
chip::Transport::BLE<kMaxBlePendingPackets>
94+
#endif
95+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
96+
,
97+
chip::Transport::TCP<kMaxTcpActiveConnectionCount, kMaxTcpPendingPackets>
9098
#endif
9199
>;
92100

src/controller/CHIPDeviceController.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)
452452
.SetAddressType(Inet::IPAddressType::kIPv4)
453453
.SetListenPort(static_cast<uint16_t>(mUdcListenPort))
454454
#endif // INET_CONFIG_ENABLE_IPV4
455+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
456+
,
457+
Transport::TcpListenParameters(mSystemState->TCPEndPointManager())
458+
.SetAddressType(IPAddressType::kIPv6)
459+
.SetListenPort(static_cast<uint16_t>(mUdcListenPort))
460+
#endif
455461
));
456462

457463
mUdcServer = chip::Platform::New<UserDirectedCommissioningServer>();

src/controller/CHIPDeviceController.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ using namespace chip::Protocols::UserDirectedCommissioning;
8484

8585
inline constexpr uint16_t kNumMaxActiveDevices = CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES;
8686

87+
inline constexpr size_t kMaxUdcTransportTcpActiveConnectionCount = CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS;
88+
89+
inline constexpr size_t kMaxUdcTransportTcpPendingPackets = CHIP_CONFIG_MAX_TCP_PENDING_PACKETS;
90+
8791
// Raw functions for cluster callbacks
8892
void OnBasicFailure(void * context, CHIP_ERROR err);
8993
void OnBasicSuccess(void * context, const chip::app::DataModel::NullObjectType &);
@@ -234,7 +238,8 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
234238
chip::Callback::Callback<OnDeviceConnectionFailure> * onFailure)
235239
{
236240
VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE);
237-
mSystemState->CASESessionMgr()->FindOrEstablishSession(ScopedNodeId(peerNodeId, GetFabricIndex()), onConnection, onFailure);
241+
mSystemState->CASESessionMgr()->FindOrEstablishSession(ScopedNodeId(peerNodeId, GetFabricIndex()), onConnection, onFailure,
242+
1, nullptr, false);
238243
return CHIP_NO_ERROR;
239244
}
240245

@@ -374,6 +379,11 @@ using UdcTransportMgr = TransportMgr<Transport::UDP /* IPv6 */
374379
#if INET_CONFIG_ENABLE_IPV4
375380
,
376381
Transport::UDP /* IPv4 */
382+
#endif
383+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
384+
,
385+
Transport::TCP<kMaxUdcTransportTcpActiveConnectionCount,
386+
kMaxUdcTransportTcpPendingPackets>
377387
#endif
378388
>;
379389
#endif

src/controller/CHIPDeviceControllerFactory.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
164164
#if CONFIG_NETWORK_LAYER_BLE
165165
,
166166
Transport::BleListenParameters(stateParams.bleLayer)
167+
#endif
168+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
169+
,
170+
Transport::TcpListenParameters(stateParams.tcpEndPointManager)
171+
.SetAddressType(IPAddressType::kIPv6)
172+
.SetListenPort(params.listenPort)
167173
#endif
168174
));
169175

src/controller/CHIPDeviceControllerSystemState.h

+9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ namespace chip {
5656

5757
inline constexpr size_t kMaxDeviceTransportBlePendingPackets = 1;
5858

59+
inline constexpr size_t kMaxDeviceTransportTcpActiveConnectionCount = CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS;
60+
61+
inline constexpr size_t kMaxDeviceTransportTcpPendingPackets = CHIP_CONFIG_MAX_TCP_PENDING_PACKETS;
62+
5963
using DeviceTransportMgr = TransportMgr<Transport::UDP /* IPv6 */
6064
#if INET_CONFIG_ENABLE_IPV4
6165
,
@@ -64,6 +68,11 @@ using DeviceTransportMgr = TransportMgr<Transport::UDP /* IPv6 */
6468
#if CONFIG_NETWORK_LAYER_BLE
6569
,
6670
Transport::BLE<kMaxDeviceTransportBlePendingPackets> /* BLE */
71+
#endif
72+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
73+
,
74+
Transport::TCP<kMaxDeviceTransportTcpActiveConnectionCount,
75+
kMaxDeviceTransportTcpPendingPackets>
6776
#endif
6877
>;
6978

src/include/platform/internal/GenericPlatformManagerImpl.ipp

+14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_InitChipStack()
8989
}
9090
SuccessOrExit(err);
9191

92+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
93+
// Initialize the CHIP TCP layer.
94+
err = TCPEndPointManager()->Init(SystemLayer());
95+
if (err != CHIP_NO_ERROR)
96+
{
97+
ChipLogError(DeviceLayer, "TCP initialization failed: %" CHIP_ERROR_FORMAT, err.Format());
98+
}
99+
SuccessOrExit(err);
100+
#endif
101+
92102
// TODO Perform dynamic configuration of the core CHIP objects based on stored settings.
93103

94104
// Initialize the CHIP BLE manager.
@@ -132,6 +142,10 @@ void GenericPlatformManagerImpl<ImplClass>::_Shutdown()
132142
ChipLogError(DeviceLayer, "Inet Layer shutdown");
133143
UDPEndPointManager()->Shutdown();
134144

145+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
146+
TCPEndPointManager()->Shutdown();
147+
#endif
148+
135149
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
136150
ChipLogError(DeviceLayer, "BLE shutdown");
137151
BLEMgr().Shutdown();

src/lib/core/CHIPConfig.h

+43-6
Original file line numberDiff line numberDiff line change
@@ -1635,13 +1635,50 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
16351635
#endif
16361636

16371637
/**
1638-
* @def CHIP_CONFIG_TCP_SUPPORT_ENABLED
1639-
* @brief
1640-
* Enable (1) or disable (0) support for TCP as a transport protocol for
1641-
* operational communications.
1638+
* @def CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS
1639+
*
1640+
* @brief Maximum Number of TCP connections a controller can simultaneously have
1641+
*/
1642+
#ifndef CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS
1643+
#define CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS 16
1644+
#endif
1645+
1646+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT && CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_TCP_CONNECTIONS < 1
1647+
#error \
1648+
"If TCP is enabled, the controller needs to support at least 1 TCP connection"
1649+
#endif
1650+
1651+
/**
1652+
* @def CHIP_CONFIG_DEVICE_MAX_ACTIVE_TCP_CONNECTIONS
1653+
*
1654+
* @brief Maximum Number of TCP connections a device can simultaneously have
1655+
*/
1656+
#ifndef CHIP_CONFIG_DEVICE_MAX_ACTIVE_TCP_CONNECTIONS
1657+
#define CHIP_CONFIG_DEVICE_MAX_ACTIVE_TCP_CONNECTIONS 8
1658+
#endif
1659+
1660+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT && CHIP_CONFIG_DEVICE_MAX_ACTIVE_TCP_CONNECTIONS < 1
1661+
#error \
1662+
"If TCP is enabled, the device needs to support at least 1 TCP connection"
1663+
#endif
1664+
1665+
/**
1666+
* @def CHIP_CONFIG_MAX_TCP_PENDING_PACKETS
1667+
*
1668+
* @brief Maximum Number of outstanding pending packets in the queue before a TCP connection
1669+
* needs to be established
1670+
*/
1671+
#ifndef CHIP_CONFIG_MAX_TCP_PENDING_PACKETS
1672+
#define CHIP_CONFIG_MAX_TCP_PENDING_PACKETS 4
1673+
#endif
1674+
1675+
/**
1676+
* @def CHIP_CONFIG_MAX_TCP_PAYLOAD_SIZE_BYTES
1677+
*
1678+
* @brief Maximum payload size of a message over a TCP connection
16421679
*/
1643-
#ifndef CHIP_CONFIG_TCP_SUPPORT_ENABLED
1644-
#define CHIP_CONFIG_TCP_SUPPORT_ENABLED (INET_CONFIG_ENABLE_TCP_ENDPOINT)
1680+
#ifndef CHIP_CONFIG_MAX_TCP_PAYLOAD_SIZE_BYTES
1681+
#define CHIP_CONFIG_MAX_TCP_PAYLOAD_SIZE_BYTES 1000000
16451682
#endif
16461683

16471684
/**

0 commit comments

Comments
 (0)