Skip to content

Commit 5583006

Browse files
vivien-applepull[bot]
authored andcommitted
[GeneralCommissioning] Return response data on general commissioning command success instead of just a status code (#13321)
1 parent 9367fff commit 5583006

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/app/clusters/general-commissioning-server/general-commissioning-server.cpp

+37-19
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ using namespace chip::app::Clusters::GeneralCommissioning;
4040
using namespace chip::app::Clusters::GeneralCommissioning::Attributes;
4141
using namespace chip::DeviceLayer;
4242

43+
#define CheckSuccess(expr, code) \
44+
do \
45+
{ \
46+
if (!::chip::ChipError::IsSuccess(expr)) \
47+
{ \
48+
LogErrorOnFailure(commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::code)); \
49+
return true; \
50+
} \
51+
} while (false)
52+
4353
namespace {
4454

4555
class GeneralCommissioningAttrAccess : public AttributeAccessInterface
@@ -102,29 +112,37 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler *
102112
const app::ConcreteCommandPath & commandPath,
103113
const Commands::ArmFailSafe::DecodableType & commandData)
104114
{
105-
auto expiryLengthSeconds = System::Clock::Seconds16(commandData.expiryLengthSeconds);
115+
DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
116+
CheckSuccess(server->ArmFailSafe(System::Clock::Seconds16(commandData.expiryLengthSeconds)), Failure);
106117

107-
CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr().ArmFailSafe(expiryLengthSeconds);
108-
emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
118+
Commands::ArmFailSafeResponse::Type response;
119+
response.errorCode = GeneralCommissioningError::kOk;
120+
response.debugText = CharSpan("", 0);
121+
CheckSuccess(commandObj->AddResponseData(commandPath, response), Failure);
109122

110123
return true;
111124
}
112125

113-
/**
114-
* Pass fabric and nodeId of commissioner to DeviceControlSvr.
115-
* This allows device to send messages back to commissioner.
116-
* Once bindings are implemented, this may no longer be needed.
117-
*/
118126
bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
119127
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
120128
const Commands::CommissioningComplete::DecodableType & commandData)
121129
{
122-
SessionHandle handle = commandObj->GetExchangeContext()->GetSessionHandle();
123-
DeviceLayer::DeviceControlServer::DeviceControlSvr().SetFabricIndex(handle.GetFabricIndex());
124-
DeviceLayer::DeviceControlServer::DeviceControlSvr().SetPeerNodeId(handle.GetPeerNodeId());
130+
DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
125131

126-
CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr().CommissioningComplete();
127-
emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
132+
/*
133+
* Pass fabric and nodeId of commissioner to DeviceControlSvr.
134+
* This allows device to send messages back to commissioner.
135+
* Once bindings are implemented, this may no longer be needed.
136+
*/
137+
server->SetFabricIndex(commandObj->GetExchangeContext()->GetSessionHandle().GetFabricIndex());
138+
server->SetPeerNodeId(commandObj->GetExchangeContext()->GetSessionHandle().GetPeerNodeId());
139+
140+
CheckSuccess(server->CommissioningComplete(), Failure);
141+
142+
Commands::CommissioningCompleteResponse::Type response;
143+
response.errorCode = GeneralCommissioningError::kOk;
144+
response.debugText = CharSpan("", 0);
145+
CheckSuccess(commandObj->AddResponseData(commandPath, response), Failure);
128146

129147
return true;
130148
}
@@ -133,13 +151,13 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH
133151
const app::ConcreteCommandPath & commandPath,
134152
const Commands::SetRegulatoryConfig::DecodableType & commandData)
135153
{
136-
auto & location = commandData.location;
137-
auto & countryCode = commandData.countryCode;
138-
auto & breadcrumb = commandData.breadcrumb;
139-
140-
CHIP_ERROR err = DeviceLayer::DeviceControlServer::DeviceControlSvr().SetRegulatoryConfig(location, countryCode, breadcrumb);
154+
DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
155+
CheckSuccess(server->SetRegulatoryConfig(commandData.location, commandData.countryCode, commandData.breadcrumb), Failure);
141156

142-
emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
157+
Commands::SetRegulatoryConfigResponse::Type response;
158+
response.errorCode = GeneralCommissioningError::kOk;
159+
response.debugText = CharSpan("", 0);
160+
CheckSuccess(commandObj->AddResponseData(commandPath, response), Failure);
143161

144162
return true;
145163
}

0 commit comments

Comments
 (0)