[spinel] return error from SaveFrame if not enough space is available (#9244)

This commit is contained in:
hemanth-silabs
2023-07-05 10:01:22 -07:00
committed by GitHub
parent 6736ef2676
commit 4eace79c98
2 changed files with 25 additions and 11 deletions
+19 -6
View File
@@ -309,14 +309,27 @@ public:
*
* Saved frame can be retrieved later using `GetNextSavedFrame()`.
*
* @retval OT_ERROR_NONE Successfully saved the buffer and prepared the write pointer for the next frame.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space.
*/
void SaveFrame(void)
otError SaveFrame(void)
{
Encoding::LittleEndian::WriteUint16(GetSkipLength() + GetLength(), mWriteFrameStart + kHeaderTotalLengthOffset);
mWriteFrameStart = mWritePointer;
IgnoreError(SetSkipLength(0));
mWritePointer = GetFrame();
mRemainingLength = static_cast<uint16_t>(mBuffer + kSize - mWritePointer);
otError error = OT_ERROR_NONE;
// If the next header will overflow the buffer, we can't save the frame.
if (!CanWrite(kHeaderSize))
{
error = OT_ERROR_NO_BUFS;
}
else
{
Encoding::LittleEndian::WriteUint16(GetSkipLength() + GetLength(),
mWriteFrameStart + kHeaderTotalLengthOffset);
mWriteFrameStart = mWritePointer;
IgnoreError(SetSkipLength(0));
}
return error;
}
/**
+6 -5
View File
@@ -530,13 +530,14 @@ void RadioSpinel<InterfaceType>::HandleNotification(SpinelInterface::RxFrameBuff
}
exit:
if (shouldSaveFrame)
{
aFrameBuffer.SaveFrame();
}
else
if (!shouldSaveFrame || aFrameBuffer.SaveFrame() != OT_ERROR_NONE)
{
aFrameBuffer.DiscardFrame();
if (shouldSaveFrame)
{
otLogCritPlat("RX Spinel buffer full, dropped incoming frame");
}
}
UpdateParseErrorCount(error);