@@ -492,10 +492,11 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
492
492
CHIP_ERROR err = CHIP_NO_ERROR;
493
493
chip::System::PacketBufferTLVWriter reportDataWriter;
494
494
ReportDataMessage::Builder reportDataBuilder;
495
- chip::System::PacketBufferHandle bufHandle = System::PacketBufferHandle::New (chip::app:: kMaxSecureSduLengthBytes ) ;
495
+ chip::System::PacketBufferHandle bufHandle = nullptr ;
496
496
uint16_t reservedSize = 0 ;
497
497
bool hasMoreChunks = false ;
498
498
bool needCloseReadHandler = false ;
499
+ size_t maxSduSize = 0 ;
499
500
500
501
// Reserved size for the MoreChunks boolean flag, which takes up 1 byte for the control tag and 1 byte for the context tag.
501
502
const uint32_t kReservedSizeForMoreChunksFlag = 1 + 1 ;
@@ -512,11 +513,17 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
512
513
513
514
VerifyOrExit (apReadHandler != nullptr , err = CHIP_ERROR_INVALID_ARGUMENT);
514
515
VerifyOrExit (apReadHandler->GetSession () != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
516
+
517
+ // Depending on whether the session supports large payload or not, the
518
+ // appropriate max size would be returned for the Report buffer.
519
+ maxSduSize = apReadHandler->GetReportBufferMaxSize ();
520
+
521
+ bufHandle = System::PacketBufferHandle::New (maxSduSize);
515
522
VerifyOrExit (!bufHandle.IsNull (), err = CHIP_ERROR_NO_MEMORY);
516
523
517
- if (bufHandle->AvailableDataLength () > kMaxSecureSduLengthBytes )
524
+ if (bufHandle->AvailableDataLength () > maxSduSize )
518
525
{
519
- reservedSize = static_cast <uint16_t >(bufHandle->AvailableDataLength () - kMaxSecureSduLengthBytes );
526
+ reservedSize = static_cast <uint16_t >(bufHandle->AvailableDataLength () - maxSduSize );
520
527
}
521
528
522
529
reportDataWriter.Init (std::move (bufHandle));
0 commit comments