Skip to content

Commit 1006580

Browse files
jepenven-silabspull[bot]
authored andcommitted
[Group] Fix Group Write Attribute sending and receiving path (#12052)
* Fix Group Write Attribute sending and receiving * Apply PR comments
1 parent b55d7e9 commit 1006580

File tree

7 files changed

+204
-13
lines changed

7 files changed

+204
-13
lines changed

src/app/InteractionModelEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
424424
}
425425

426426
exit:
427-
if (status != Protocols::InteractionModel::Status::Success)
427+
if (status != Protocols::InteractionModel::Status::Success && !apExchangeContext->IsGroupExchangeContext())
428428
{
429429
err = StatusResponse::SendStatusResponse(status, apExchangeContext, false /*aExpectResponse*/);
430430
}

src/app/WriteHandler.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ CHIP_ERROR WriteHandler::OnWriteRequest(Messaging::ExchangeContext * apExchangeC
6060

6161
err = ProcessWriteRequest(std::move(aPayload));
6262
SuccessOrExit(err);
63-
err = SendWriteResponse();
63+
64+
// Do not send response on Group Write
65+
if (!apExchangeContext->IsGroupExchangeContext())
66+
{
67+
err = SendWriteResponse();
68+
}
6469

6570
exit:
6671
Shutdown();
@@ -110,6 +115,8 @@ CHIP_ERROR WriteHandler::SendWriteResponse()
110115
CHIP_ERROR WriteHandler::ProcessAttributeDataIBs(TLV::TLVReader & aAttributeDataIBsReader)
111116
{
112117
CHIP_ERROR err = CHIP_NO_ERROR;
118+
VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INTERNAL);
119+
113120
while (CHIP_NO_ERROR == (err = aAttributeDataIBsReader.Next()))
114121
{
115122
chip::TLV::TLVReader dataReader;
@@ -131,9 +138,19 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataIBs(TLV::TLVReader & aAttributeData
131138
{
132139
err = CHIP_NO_ERROR;
133140
}
141+
if (mpExchangeCtx->IsGroupExchangeContext())
142+
{
143+
// TODO retrieve Endpoint ID with GroupDataProvider using GroupId and FabricId
144+
// Issue 11075
134145

135-
err = attributePath.GetEndpoint(&(clusterInfo.mEndpointId));
136-
SuccessOrExit(err);
146+
// Using endpoint 0 for test purposes
147+
clusterInfo.mEndpointId = 0;
148+
}
149+
else
150+
{
151+
err = attributePath.GetEndpoint(&(clusterInfo.mEndpointId));
152+
SuccessOrExit(err);
153+
}
137154

138155
err = attributePath.GetCluster(&(clusterInfo.mClusterId));
139156
SuccessOrExit(err);
@@ -210,6 +227,7 @@ CHIP_ERROR WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayl
210227

211228
err = writeRequestParser.GetWriteRequests(&AttributeDataIBsParser);
212229
SuccessOrExit(err);
230+
213231
AttributeDataIBsParser.GetReader(&AttributeDataIBsReader);
214232
err = ProcessAttributeDataIBs(AttributeDataIBsReader);
215233

src/app/tests/suites/TestGroupMessaging.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,18 @@ tests:
3333
- label: "Read back Attribute"
3434
command: "readAttribute"
3535
attribute: "location"
36-
disabled: true
3736
response:
3837
value: "us"
3938

4039
- label: "Restore initial location value"
4140
command: "writeAttribute"
4241
attribute: "location"
4342
groupId: "1234"
44-
disabled: true
4543
arguments:
4644
value: ""
4745

4846
- label: "Read back Attribute"
4947
command: "readAttribute"
5048
attribute: "location"
51-
disabled: true
5249
response:
5350
value: ""

src/darwin/Framework/CHIPTests/CHIPClustersTests.m

+70
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/messaging/ExchangeContext.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
159159
}
160160

161161
{
162+
// ExchangeContext for group are supposed to always be Initiator
163+
if (IsGroupExchangeContext() && !IsInitiator())
164+
{
165+
return CHIP_ERROR_INTERNAL;
166+
}
167+
162168
// Create a new scope for `err`, to avoid shadowing warning previous `err`.
163169
CHIP_ERROR err = mDispatch->SendMessage(mSession.Value(), mExchangeId, IsInitiator(), GetReliableMessageContext(),
164170
reliableTransmissionRequested, protocolId, msgType, std::move(msgBuf));
@@ -445,8 +451,12 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload
445451
MessageHandled();
446452
});
447453

448-
ReturnErrorOnFailure(
449-
mDispatch->OnMessageReceived(messageCounter, payloadHeader, peerAddress, msgFlags, GetReliableMessageContext()));
454+
// TODO : Remove this bypass for group as to perform the MessagePermitted function Issue # 12101
455+
if (!IsGroupExchangeContext())
456+
{
457+
ReturnErrorOnFailure(
458+
mDispatch->OnMessageReceived(messageCounter, payloadHeader, peerAddress, msgFlags, GetReliableMessageContext()));
459+
}
450460

451461
if (IsAckPending() && !mDelegate)
452462
{

src/transport/SessionManager.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ CHIP_ERROR SessionManager::PrepareMessage(SessionHandle sessionHandle, PayloadHe
131131
{
132132
return CHIP_ERROR_INTERNAL;
133133
}
134+
// TODO #11911 Update SecureMessageCodec::Encrypt for Group
135+
ReturnErrorOnFailure(payloadHeader.EncodeBeforeData(message));
134136

135137
#if CHIP_PROGRESS_LOGGING
136138
destination = sessionHandle.GetPeerNodeId();
@@ -414,7 +416,7 @@ void SessionManager::SecureUnicastMessageDispatch(const PacketHeader & packetHea
414416

415417
if (msg.IsNull())
416418
{
417-
ChipLogError(Inet, "Secure transport received NULL packet, discarding");
419+
ChipLogError(Inet, "Secure transport received Unicast NULL packet, discarding");
418420
return;
419421
}
420422

@@ -485,9 +487,9 @@ void SessionManager::SecureGroupMessageDispatch(const PacketHeader & packetHeade
485487
FabricIndex fabricIndex = 0; // TODO : remove initialization once GroupDataProvider->Decrypt is implemented
486488
// Credentials::GroupDataProvider * groups = Credentials::GetGroupDataProvider();
487489

488-
if (!msg.IsNull())
490+
if (msg.IsNull())
489491
{
490-
ChipLogError(Inet, "Secure transport received NULL packet, discarding");
492+
ChipLogError(Inet, "Secure transport received Groupcast NULL packet, discarding");
491493
return;
492494
}
493495

@@ -503,6 +505,8 @@ void SessionManager::SecureGroupMessageDispatch(const PacketHeader & packetHeade
503505
// VerifyOrExit(CHIP_NO_ERROR == groups->DecryptMessage(packetHeader, payloadHeader, msg),
504506
// ChipLogError(Inet, "Secure transport received group message, but failed to decode it, discarding"));
505507

508+
ReturnOnFailure(payloadHeader.DecodeAndConsume(msg));
509+
506510
// MCSP check
507511
if (packetHeader.IsValidMCSPMsg())
508512
{

zzz_generated/chip-tool/zap-generated/test/Commands.h

+93-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)