Skip to content

Commit c972171

Browse files
Fix custom CSR response.
1 parent 578ede4 commit c972171

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

examples/platform/linux/testing/CustomCSRResponse.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ using namespace chip;
2828
using namespace chip::app;
2929
using namespace chip::app::Clusters::OperationalCredentials::Commands;
3030

31-
#if 0
3231
constexpr size_t kMaxResponseLength = 900;
3332
constexpr size_t kCSRNonceLength = 32;
3433

@@ -145,7 +144,8 @@ namespace app {
145144
namespace DataModel {
146145

147146
template <>
148-
CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const CSRResponse::Type & responseData)
147+
CHIP_ERROR EncodeResponseCommandPayload(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex accessingFabricIndex,
148+
const CSRResponse::Type & responseData)
149149
{
150150
auto tag1 = TLV::ContextTag(CSRResponse::Fields::kNOCSRElements);
151151
auto tag2 = TLV::ContextTag(CSRResponse::Fields::kAttestationSignature);
@@ -163,5 +163,3 @@ CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const CSRResponse::Type
163163
} // namespace DataModel
164164
} // namespace app
165165
} // namespace chip
166-
167-
#endif

src/app/CommandHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class CommandHandler
304304

305305
CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex aAccessingFabricIndex) const final
306306
{
307-
return mValue.Encode(writer, tag, aAccessingFabricIndex);
307+
return EncodeResponseCommandPayload(writer, tag, aAccessingFabricIndex, mValue);
308308
}
309309

310310
CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const final

src/app/data-model/Encode.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ CHIP_ERROR EncodeForRead(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex acce
253253
#pragma GCC diagnostic pop
254254
}
255255

256+
/**
257+
* @brief
258+
*
259+
* Encodes a response command payload. This is a templated function to allow
260+
* specializations to be created as needed to customize the behavior.
261+
*/
262+
template <typename PayloadType>
263+
CHIP_ERROR EncodeResponseCommandPayload(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex accessingFabricIndex,
264+
const PayloadType & payload)
265+
{
266+
return payload.Encode(writer, tag, accessingFabricIndex);
267+
}
268+
256269
} // namespace DataModel
257270
} // namespace app
258271
} // namespace chip

0 commit comments

Comments
 (0)