Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Binding] Improve binding validation and disable connection on init #23749

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
81e3c92
Ability to notify specific binding and disable connection on init
ReneJosefsen Nov 24, 2022
2b54aa7
Aligned param naming
ReneJosefsen Nov 24, 2022
56f3a7b
Fixes from restyle
ReneJosefsen Nov 24, 2022
0a726c5
Missing restyle
ReneJosefsen Nov 24, 2022
d7ddc84
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Dec 6, 2022
c691db5
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Dec 14, 2022
b2420fb
Changed member name and added documentation
ReneJosefsen Jan 5, 2023
1de95a6
Updated validation in bindings and removed AtIndex function
ReneJosefsen Jan 10, 2023
c399cc7
Added missing include file
ReneJosefsen Jan 10, 2023
d6c5e46
Fixed missing emberAfContainsClient by using other available functions
ReneJosefsen Jan 10, 2023
8f79591
Added check of emberAfFindEndpointType in case it returns nullptr
ReneJosefsen Jan 10, 2023
644b9ef
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Jan 10, 2023
e8262ca
Reintroduced emberAfContainsClient and reverted bindings to use this
ReneJosefsen Jan 10, 2023
43bd36c
Enabled onOff client on all-clusters-app to fix failing tests
ReneJosefsen Jan 11, 2023
b48c053
Fixed spelling error and added notify if not list operation
ReneJosefsen Jan 12, 2023
529d358
Update src/app/clusters/bindings/bindings.cpp
ReneJosefsen Jan 12, 2023
4517aae
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Jan 18, 2023
35abfa9
Try to fix CI failure
ReneJosefsen Jan 18, 2023
a3761b1
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Jan 18, 2023
3bb0c7c
Merge branch 'master' into rjosefsen/update-binding-manager
ReneJosefsen Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions src/app/clusters/bindings/BindingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ CHIP_ERROR BindingManager::Init(const BindingManagerInitParams & params)
}
else
{
for (const EmberBindingTableEntry & entry : BindingTable::GetInstance())
if (params.establishConnectionOnInit)
{
if (entry.type == EMBER_UNICAST_BINDING)
for (const EmberBindingTableEntry & entry : BindingTable::GetInstance())
{
// The CASE connection can also fail if the unicast peer is offline.
// There is recovery mechanism to retry connection on-demand so ignore error.
(void) UnicastBindingCreated(entry.fabricIndex, entry.nodeId);
if (entry.type == EMBER_UNICAST_BINDING)
{
// The CASE connection can also fail if the unicast peer is offline.
// There is recovery mechanism to retry connection on-demand so ignore error.
(void) UnicastBindingCreated(entry.fabricIndex, entry.nodeId);
}
}
}
}
Expand Down Expand Up @@ -201,4 +204,39 @@ CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, Cluste
return error;
}

CHIP_ERROR BindingManager::NotifyBoundClusterAtIndexChanged(EndpointId endpoint, ClusterId cluster, uint8_t bindingIndex,
void * context)
{
VerifyOrReturnError(mInitParams.mFabricTable != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mBoundDeviceChangedHandler, CHIP_NO_ERROR);

CHIP_ERROR error = CHIP_NO_ERROR;
auto * bindingContext = mPendingNotificationMap.NewPendingNotificationContext(context);
VerifyOrReturnError(bindingContext != nullptr, CHIP_ERROR_NO_MEMORY);

bindingContext->IncrementConsumersNumber();

EmberBindingTableEntry entry = BindingTable::GetInstance().GetAt(bindingIndex);

if (entry.local == endpoint && (!entry.clusterId.HasValue() || entry.clusterId.Value() == cluster))
{
if (entry.type == EMBER_UNICAST_BINDING)
{
error = mPendingNotificationMap.AddPendingNotification(bindingIndex, bindingContext);
SuccessOrExit(error);
error = EstablishConnection(ScopedNodeId(entry.nodeId, entry.fabricIndex));
SuccessOrExit(error);
}
else if (entry.type == EMBER_MULTICAST_BINDING)
{
mBoundDeviceChangedHandler(entry, nullptr, bindingContext->GetContext());
}
}

exit:
bindingContext->DecrementConsumersNumber();

return error;
}

} // namespace chip
13 changes: 13 additions & 0 deletions src/app/clusters/bindings/BindingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct BindingManagerInitParams
FabricTable * mFabricTable = nullptr;
CASESessionManager * mCASESessionManager = nullptr;
PersistentStorageDelegate * mStorage = nullptr;
bool establishConnectionOnInit = true;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down Expand Up @@ -118,6 +119,18 @@ class BindingManager
*/
CHIP_ERROR NotifyBoundClusterChanged(EndpointId endpoint, ClusterId cluster, void * context);

/*
* Notify a cluster change to a specific bound device associated with the (endpoint, cluster) tuple.
ReneJosefsen marked this conversation as resolved.
Show resolved Hide resolved
*
* For a unicast bindings with an active session and multicast bindings, the BoundDeviceChangedHandler
* will be called before the function returns.
*
* For unicast bindings without an active session, the notification will be queued and a new session will
* be initiated. The BoundDeviceChangedHandler will be called once the session is established.
*
*/
CHIP_ERROR NotifyBoundClusterAtIndexChanged(EndpointId endpoint, ClusterId cluster, uint8_t bindingIndex, void * context);

static BindingManager & GetInstance() { return sBindingManager; }

private:
Expand Down