Skip to content

Commit

Permalink
Pull request project-chip#1155: MATTER-2434: Fixes command failure on…
Browse files Browse the repository at this point in the history
… OTBR restart

Squashed commit of the following:

commit 238b5e03107d77b8431b5e7a3983d23e7512cf4b
Author: Suhas Shankar <[email protected]>
Date:   Tue Sep 19 16:54:24 2023 +0530

    Fixed build issue

commit b130f40c47a6a3afd514a808a73f7e8e256f1693
Author: Suhas Shankar <[email protected]>
Date:   Mon Sep 18 19:11:10 2023 +0530

    Fixes command failure on OTBR restart
  • Loading branch information
su-shanka authored and jmartinez-silabs committed Apr 25, 2024
1 parent 745b86c commit e11f51f
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#ifndef MPC_SENDABLE_COMMAND
#define MPC_SENDABLE_COMMAND

#define MPC_MAX_COMMAND_RETRY 1

namespace mpc {
using namespace chip;

Expand Down Expand Up @@ -102,13 +105,25 @@ class SendableCommand
}
Platform::Delete(ctx);
};
Controller::InvokeCommandRequest(&exchangeMgr, sessionHandle, ctx->m_endpoint_id, ctx->mCommand, onSuccess, onFailure);
auto err = Controller::InvokeCommandRequest(&exchangeMgr, sessionHandle, ctx->m_endpoint_id, ctx->mCommand,
onSuccess, onFailure);
// Retry immediately in-case of synchronous send failure (possibly internal failure such as stale session)
if (err != CHIP_NO_ERROR && ctx->mRetryCount++ < MPC_MAX_COMMAND_RETRY) {
Server::GetInstance().GetCASESessionManager()->FindOrEstablishSession(sessionHandle->GetPeer(),
&ctx->mOnConnectedCallback, &ctx->mOnConnectionFailureCallback);
}
};

static void onConnectFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
{
SendableCommand<T> * ctx = static_cast<SendableCommand<T> *>(context);
ChipLogError(NotSpecified, "Connection Failed: %" CHIP_ERROR_FORMAT, error.Format());

if (ctx->mRetryCount++ < MPC_MAX_COMMAND_RETRY) {
Server::GetInstance().GetCASESessionManager()->FindOrEstablishSession(peerId,
&ctx->mOnConnectedCallback, &ctx->mOnConnectionFailureCallback);
return;
}
if (ctx->mSendDone.HasValue())
{
ctx->mSendDone.Value()(error, peerId);
Expand All @@ -118,6 +133,7 @@ class SendableCommand

T mCommand;
EndpointId m_endpoint_id;
uint8_t mRetryCount = 0;
Callback::Callback<OnDeviceConnected> mOnConnectedCallback;
Callback::Callback<OnDeviceConnectionFailure> mOnConnectionFailureCallback;
Optional<SendDoneCallback> mSendDone;
Expand Down

0 comments on commit e11f51f

Please sign in to comment.