Skip to content

Commit

Permalink
Adjust storage and processing in SystemPacketBuffer
Browse files Browse the repository at this point in the history
and associated code for large payloads.

Extend uint16_t type variables to uint32_t at applicable
places.
  • Loading branch information
pidarped committed Jan 30, 2024
1 parent f63b505 commit cbb1148
Show file tree
Hide file tree
Showing 24 changed files with 170 additions and 166 deletions.
6 changes: 3 additions & 3 deletions src/ble/BtpEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle &&
// mRxFragnentSize may be smaller than the characteristic size. Make sure
// we're not truncating to a data length smaller than what we have already consumed.
VerifyOrExit(reader.OctetsRead() <= mRxFragmentSize, err = BLE_ERROR_REASSEMBLER_INCORRECT_STATE);
data->SetDataLength(chip::min(data->DataLength(), mRxFragmentSize));
data->SetDataLength(chip::min(data->DataLength(), static_cast<uint32_t>(mRxFragmentSize)));

// Now mark the bytes we consumed as consumed.
data->ConsumeHead(static_cast<uint16_t>(reader.OctetsRead()));
Expand Down Expand Up @@ -374,7 +374,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle &&
if (rx_flags.Has(HeaderFlags::kEndMessage))
{
// Trim remainder, if any, of the received packet buffer based on sender-specified length of reassembled message.
int padding = mRxBuf->DataLength() - mRxLength;
uint32_t padding = mRxBuf->DataLength() - mRxLength;

if (padding > 0)
{
Expand Down Expand Up @@ -456,7 +456,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s

mTxBuf = std::move(data);
mTxState = kState_InProgress;
mTxLength = mTxBuf->DataLength();
mTxLength = static_cast<uint16_t>(mTxBuf->DataLength());

ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
PrintBufDebug(mTxBuf);
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void TCPEndPoint::DriveReceiving()
{
// Acknowledgement is done after handling the buffers to allow the
// application processing to throttle flow.
uint16_t ackLength = mRcvQueue->TotalLength();
uint32_t ackLength = mRcvQueue->TotalLength();
CHIP_ERROR err = OnDataReceived(this, std::move(mRcvQueue));
if (err != CHIP_NO_ERROR)
{
Expand Down
6 changes: 3 additions & 3 deletions src/inet/TCPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
* received. The operational semantics are undefined if \c len is larger
* than the total outstanding unacknowledged received data.
*/
virtual CHIP_ERROR AckReceive(uint16_t len) = 0;
virtual CHIP_ERROR AckReceive(uint32_t len) = 0;

/**
* @brief Set the receive queue, for testing.
Expand All @@ -301,7 +301,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
* @brief Extract the length of the unacknowledged receive data.
*
* @return Number of bytes in the receive queue that have not yet been
* acknowledged with <tt>AckReceive(uint16_t len)</tt>.
* acknowledged with <tt>AckReceive(uint32_t len)</tt>.
*/
uint32_t PendingReceiveLength();

Expand Down Expand Up @@ -447,7 +447,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
* is the length of the message text added to the TCP transmit window,
* which are eligible for sending by the underlying network stack.
*/
typedef void (*OnDataSentFunct)(TCPEndPoint * endPoint, uint16_t len);
typedef void (*OnDataSentFunct)(TCPEndPoint * endPoint, uint32_t len);

/**
* The endpoint's message text transmission event handling function
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPointImplLwIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void TCPEndPointImplLwIP::DoCloseImpl(CHIP_ERROR err, State oldState)
}
}

CHIP_ERROR TCPEndPointImplLwIP::AckReceive(uint16_t len)
CHIP_ERROR TCPEndPointImplLwIP::AckReceive(uint32_t len)
{
VerifyOrReturnError(IsConnected(), CHIP_ERROR_INCORRECT_STATE);
CHIP_ERROR res = CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPointImplLwIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TCPEndPointImplLwIP : public TCPEndPoint, public EndPointStateLwIP
CHIP_ERROR EnableNoDelay() override;
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
CHIP_ERROR DisableKeepAlive() override;
CHIP_ERROR AckReceive(uint16_t len) override;
CHIP_ERROR AckReceive(uint32_t len) override;
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
void TCPUserTimeoutHandler() override;
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPointImplOpenThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CHIP_ERROR TCPEndPointImplOT::DisableKeepAlive()
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR TCPEndPointImplOT::AckReceive(uint16_t len)
CHIP_ERROR TCPEndPointImplOT::AckReceive(uint32_t len)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPointImplOpenThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TCPEndPointImplOT : public TCPEndPoint, public EndPointStateOpenThread
CHIP_ERROR EnableNoDelay() override;
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
CHIP_ERROR DisableKeepAlive() override;
CHIP_ERROR AckReceive(uint16_t len) override;
CHIP_ERROR AckReceive(uint32_t len) override;
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
void TCPUserTimeoutHandler() override;
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
Expand Down
14 changes: 7 additions & 7 deletions src/inet/TCPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ CHIP_ERROR TCPEndPointImplSockets::DisableKeepAlive()
return CHIP_NO_ERROR;
}

CHIP_ERROR TCPEndPointImplSockets::AckReceive(uint16_t len)
CHIP_ERROR TCPEndPointImplSockets::AckReceive(uint32_t len)
{
VerifyOrReturnError(IsConnected(), CHIP_ERROR_INCORRECT_STATE);

Expand Down Expand Up @@ -483,7 +483,7 @@ CHIP_ERROR TCPEndPointImplSockets::DriveSendingImpl()

while (!mSendQueue.IsNull())
{
uint16_t bufLen = mSendQueue->DataLength();
uint32_t bufLen = mSendQueue->DataLength();

ssize_t lenSentRaw = send(mSocket, mSendQueue->Start(), bufLen, sendFlags);

Expand All @@ -502,8 +502,8 @@ CHIP_ERROR TCPEndPointImplSockets::DriveSendingImpl()
break;
}

// Cast is safe because bufLen is uint16_t.
uint16_t lenSent = static_cast<uint16_t>(lenSentRaw);
// Cast is safe because bufLen is uint32_t.
uint32_t lenSent = static_cast<uint32_t>(lenSentRaw);

// Mark the connection as being active.
MarkActive();
Expand Down Expand Up @@ -948,10 +948,10 @@ void TCPEndPointImplSockets::ReceiveData()
{
VerifyOrDie(rcvLen > 0);
size_t newDataLength = rcvBuf->DataLength() + static_cast<size_t>(rcvLen);
VerifyOrDie(CanCastTo<uint16_t>(newDataLength));
VerifyOrDie(CanCastTo<uint32_t>(newDataLength));
if (isNewBuf)
{
rcvBuf->SetDataLength(static_cast<uint16_t>(newDataLength));
rcvBuf->SetDataLength(static_cast<uint32_t>(newDataLength));
rcvBuf.RightSize();
if (mRcvQueue.IsNull())
{
Expand All @@ -964,7 +964,7 @@ void TCPEndPointImplSockets::ReceiveData()
}
else
{
rcvBuf->SetDataLength(static_cast<uint16_t>(newDataLength), mRcvQueue);
rcvBuf->SetDataLength(static_cast<uint32_t>(newDataLength), mRcvQueue);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPointImplSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TCPEndPointImplSockets : public TCPEndPoint, public EndPointStateSockets
CHIP_ERROR EnableNoDelay() override;
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
CHIP_ERROR DisableKeepAlive() override;
CHIP_ERROR AckReceive(uint16_t len) override;
CHIP_ERROR AckReceive(uint32_t len) override;
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
void TCPUserTimeoutHandler() override;
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
Expand Down
2 changes: 1 addition & 1 deletion src/inet/tests/TestInetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ static void HandleTCPConnectionClosed(TCPEndPoint * aEndPoint, CHIP_ERROR aError
}
}

static void HandleTCPDataSent(TCPEndPoint * aEndPoint, uint16_t len) {}
static void HandleTCPDataSent(TCPEndPoint * aEndPoint, uint32_t len) {}

static CHIP_ERROR HandleTCPDataReceived(TCPEndPoint * aEndPoint, PacketBufferHandle && aBuffer)
{
Expand Down
12 changes: 6 additions & 6 deletions src/inet/tests/TestInetLayerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ bool WasSuccessful(const TestStatus & aTestStatus)
return (lStatus);
}

static void FillDataBufferPattern(uint8_t * aBuffer, uint16_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
static void FillDataBufferPattern(uint8_t * aBuffer, uint32_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
{
for (uint16_t i = aPatternStartOffset; i < aLength; i++)
for (uint32_t i = aPatternStartOffset; i < aLength; i++)
{
const uint8_t lValue = static_cast<uint8_t>(aFirstValue & 0xFF);

Expand All @@ -135,9 +135,9 @@ static void FillDataBufferPattern(uint8_t * aBuffer, uint16_t aLength, uint16_t
}
}

static bool CheckDataBufferPattern(const uint8_t * aBuffer, uint16_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
static bool CheckDataBufferPattern(const uint8_t * aBuffer, uint32_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
{
for (uint16_t i = aPatternStartOffset; i < aLength; i++)
for (uint32_t i = aPatternStartOffset; i < aLength; i++)
{
const uint8_t lValue = aBuffer[i];

Expand All @@ -156,7 +156,7 @@ static bool CheckDataBufferPattern(const uint8_t * aBuffer, uint16_t aLength, ui
return true;
}

static PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
static PacketBufferHandle MakeDataBuffer(uint32_t aDesiredLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
{
VerifyOrReturnError(aPatternStartOffset <= aDesiredLength, PacketBufferHandle());

Expand Down Expand Up @@ -244,7 +244,7 @@ static bool HandleDataReceived(const PacketBufferHandle & aBuffer, TransferStats

for (PacketBufferHandle lBuffer = aBuffer.Retain(); !lBuffer.IsNull(); lBuffer.Advance())
{
const uint16_t lDataLength = lBuffer->DataLength();
const uint32_t lDataLength = lBuffer->DataLength();
const uint8_t * const p = lBuffer->Start();

if (aCheckBuffer && !CheckDataBufferPattern(p, lDataLength, aPatternStartOffset, aFirstValue))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/tests/TestTLV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void TestBufferContents(nlTestSuite * inSuite, const System::PacketBufferHandle
System::PacketBufferHandle buf = buffer.Retain();
while (!buf.IsNull())
{
uint16_t len = buf->DataLength();
uint32_t len = buf->DataLength();
NL_TEST_ASSERT(inSuite, len <= expectedLen);

NL_TEST_ASSERT(inSuite, memcmp(buf->Start(), expectedVal, len) == 0);
Expand Down Expand Up @@ -2990,7 +2990,7 @@ void CheckBufferOverflow(nlTestSuite * inSuite, void * inContext)
System::PacketBufferTLVReader reader;

System::PacketBufferHandle buf = System::PacketBufferHandle::New(sizeof(Encoding1), 0);
uint16_t maxDataLen = buf->MaxDataLength();
uint32_t maxDataLen = buf->MaxDataLength();
uint16_t reserve = static_cast<uint16_t>((sizeof(Encoding1) < maxDataLen) ? (maxDataLen - sizeof(Encoding1)) + 2 : 0);

// Repeatedly write and read a TLV encoding to a chain of PacketBuffers. Use progressively larger
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg)
TLV::TLVType containerType = TLV::kTLVType_Structure;

const uint8_t * buf = msg->Start();
const uint16_t bufLen = msg->DataLength();
const uint32_t bufLen = msg->DataLength();

constexpr size_t kCaseOverheadForFutureTbeData = 128;

Expand Down
Loading

0 comments on commit cbb1148

Please sign in to comment.