Skip to content

Commit cbb1148

Browse files
committed
Adjust storage and processing in SystemPacketBuffer
and associated code for large payloads. Extend uint16_t type variables to uint32_t at applicable places.
1 parent f63b505 commit cbb1148

24 files changed

+170
-166
lines changed

src/ble/BtpEngine.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle &&
310310
// mRxFragnentSize may be smaller than the characteristic size. Make sure
311311
// we're not truncating to a data length smaller than what we have already consumed.
312312
VerifyOrExit(reader.OctetsRead() <= mRxFragmentSize, err = BLE_ERROR_REASSEMBLER_INCORRECT_STATE);
313-
data->SetDataLength(chip::min(data->DataLength(), mRxFragmentSize));
313+
data->SetDataLength(chip::min(data->DataLength(), static_cast<uint32_t>(mRxFragmentSize)));
314314

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

379379
if (padding > 0)
380380
{
@@ -456,7 +456,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
456456

457457
mTxBuf = std::move(data);
458458
mTxState = kState_InProgress;
459-
mTxLength = mTxBuf->DataLength();
459+
mTxLength = static_cast<uint16_t>(mTxBuf->DataLength());
460460

461461
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
462462
PrintBufDebug(mTxBuf);

src/inet/TCPEndPoint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void TCPEndPoint::DriveReceiving()
333333
{
334334
// Acknowledgement is done after handling the buffers to allow the
335335
// application processing to throttle flow.
336-
uint16_t ackLength = mRcvQueue->TotalLength();
336+
uint32_t ackLength = mRcvQueue->TotalLength();
337337
CHIP_ERROR err = OnDataReceived(this, std::move(mRcvQueue));
338338
if (err != CHIP_NO_ERROR)
339339
{

src/inet/TCPEndPoint.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
274274
* received. The operational semantics are undefined if \c len is larger
275275
* than the total outstanding unacknowledged received data.
276276
*/
277-
virtual CHIP_ERROR AckReceive(uint16_t len) = 0;
277+
virtual CHIP_ERROR AckReceive(uint32_t len) = 0;
278278

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

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

452452
/**
453453
* The endpoint's message text transmission event handling function

src/inet/TCPEndPointImplLwIP.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void TCPEndPointImplLwIP::DoCloseImpl(CHIP_ERROR err, State oldState)
503503
}
504504
}
505505

506-
CHIP_ERROR TCPEndPointImplLwIP::AckReceive(uint16_t len)
506+
CHIP_ERROR TCPEndPointImplLwIP::AckReceive(uint32_t len)
507507
{
508508
VerifyOrReturnError(IsConnected(), CHIP_ERROR_INCORRECT_STATE);
509509
CHIP_ERROR res = CHIP_NO_ERROR;

src/inet/TCPEndPointImplLwIP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TCPEndPointImplLwIP : public TCPEndPoint, public EndPointStateLwIP
5151
CHIP_ERROR EnableNoDelay() override;
5252
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
5353
CHIP_ERROR DisableKeepAlive() override;
54-
CHIP_ERROR AckReceive(uint16_t len) override;
54+
CHIP_ERROR AckReceive(uint32_t len) override;
5555
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
5656
void TCPUserTimeoutHandler() override;
5757
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT

src/inet/TCPEndPointImplOpenThread.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ CHIP_ERROR TCPEndPointImplOT::DisableKeepAlive()
5454
{
5555
return CHIP_ERROR_NOT_IMPLEMENTED;
5656
}
57-
CHIP_ERROR TCPEndPointImplOT::AckReceive(uint16_t len)
57+
CHIP_ERROR TCPEndPointImplOT::AckReceive(uint32_t len)
5858
{
5959
return CHIP_ERROR_NOT_IMPLEMENTED;
6060
}

src/inet/TCPEndPointImplOpenThread.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TCPEndPointImplOT : public TCPEndPoint, public EndPointStateOpenThread
4646
CHIP_ERROR EnableNoDelay() override;
4747
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
4848
CHIP_ERROR DisableKeepAlive() override;
49-
CHIP_ERROR AckReceive(uint16_t len) override;
49+
CHIP_ERROR AckReceive(uint32_t len) override;
5050
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
5151
void TCPUserTimeoutHandler() override;
5252
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT

src/inet/TCPEndPointImplSockets.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ CHIP_ERROR TCPEndPointImplSockets::DisableKeepAlive()
441441
return CHIP_NO_ERROR;
442442
}
443443

444-
CHIP_ERROR TCPEndPointImplSockets::AckReceive(uint16_t len)
444+
CHIP_ERROR TCPEndPointImplSockets::AckReceive(uint32_t len)
445445
{
446446
VerifyOrReturnError(IsConnected(), CHIP_ERROR_INCORRECT_STATE);
447447

@@ -483,7 +483,7 @@ CHIP_ERROR TCPEndPointImplSockets::DriveSendingImpl()
483483

484484
while (!mSendQueue.IsNull())
485485
{
486-
uint16_t bufLen = mSendQueue->DataLength();
486+
uint32_t bufLen = mSendQueue->DataLength();
487487

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

@@ -502,8 +502,8 @@ CHIP_ERROR TCPEndPointImplSockets::DriveSendingImpl()
502502
break;
503503
}
504504

505-
// Cast is safe because bufLen is uint16_t.
506-
uint16_t lenSent = static_cast<uint16_t>(lenSentRaw);
505+
// Cast is safe because bufLen is uint32_t.
506+
uint32_t lenSent = static_cast<uint32_t>(lenSentRaw);
507507

508508
// Mark the connection as being active.
509509
MarkActive();
@@ -948,10 +948,10 @@ void TCPEndPointImplSockets::ReceiveData()
948948
{
949949
VerifyOrDie(rcvLen > 0);
950950
size_t newDataLength = rcvBuf->DataLength() + static_cast<size_t>(rcvLen);
951-
VerifyOrDie(CanCastTo<uint16_t>(newDataLength));
951+
VerifyOrDie(CanCastTo<uint32_t>(newDataLength));
952952
if (isNewBuf)
953953
{
954-
rcvBuf->SetDataLength(static_cast<uint16_t>(newDataLength));
954+
rcvBuf->SetDataLength(static_cast<uint32_t>(newDataLength));
955955
rcvBuf.RightSize();
956956
if (mRcvQueue.IsNull())
957957
{
@@ -964,7 +964,7 @@ void TCPEndPointImplSockets::ReceiveData()
964964
}
965965
else
966966
{
967-
rcvBuf->SetDataLength(static_cast<uint16_t>(newDataLength), mRcvQueue);
967+
rcvBuf->SetDataLength(static_cast<uint32_t>(newDataLength), mRcvQueue);
968968
}
969969
}
970970
}

src/inet/TCPEndPointImplSockets.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TCPEndPointImplSockets : public TCPEndPoint, public EndPointStateSockets
4646
CHIP_ERROR EnableNoDelay() override;
4747
CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) override;
4848
CHIP_ERROR DisableKeepAlive() override;
49-
CHIP_ERROR AckReceive(uint16_t len) override;
49+
CHIP_ERROR AckReceive(uint32_t len) override;
5050
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
5151
void TCPUserTimeoutHandler() override;
5252
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT

src/inet/tests/TestInetLayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static void HandleTCPConnectionClosed(TCPEndPoint * aEndPoint, CHIP_ERROR aError
569569
}
570570
}
571571

572-
static void HandleTCPDataSent(TCPEndPoint * aEndPoint, uint16_t len) {}
572+
static void HandleTCPDataSent(TCPEndPoint * aEndPoint, uint32_t len) {}
573573

574574
static CHIP_ERROR HandleTCPDataReceived(TCPEndPoint * aEndPoint, PacketBufferHandle && aBuffer)
575575
{

src/inet/tests/TestInetLayerCommon.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ bool WasSuccessful(const TestStatus & aTestStatus)
123123
return (lStatus);
124124
}
125125

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

@@ -135,9 +135,9 @@ static void FillDataBufferPattern(uint8_t * aBuffer, uint16_t aLength, uint16_t
135135
}
136136
}
137137

138-
static bool CheckDataBufferPattern(const uint8_t * aBuffer, uint16_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
138+
static bool CheckDataBufferPattern(const uint8_t * aBuffer, uint32_t aLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
139139
{
140-
for (uint16_t i = aPatternStartOffset; i < aLength; i++)
140+
for (uint32_t i = aPatternStartOffset; i < aLength; i++)
141141
{
142142
const uint8_t lValue = aBuffer[i];
143143

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

159-
static PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
159+
static PacketBufferHandle MakeDataBuffer(uint32_t aDesiredLength, uint16_t aPatternStartOffset, uint8_t aFirstValue)
160160
{
161161
VerifyOrReturnError(aPatternStartOffset <= aDesiredLength, PacketBufferHandle());
162162

@@ -244,7 +244,7 @@ static bool HandleDataReceived(const PacketBufferHandle & aBuffer, TransferStats
244244

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

250250
if (aCheckBuffer && !CheckDataBufferPattern(p, lDataLength, aPatternStartOffset, aFirstValue))

src/lib/core/tests/TestTLV.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void TestBufferContents(nlTestSuite * inSuite, const System::PacketBufferHandle
277277
System::PacketBufferHandle buf = buffer.Retain();
278278
while (!buf.IsNull())
279279
{
280-
uint16_t len = buf->DataLength();
280+
uint32_t len = buf->DataLength();
281281
NL_TEST_ASSERT(inSuite, len <= expectedLen);
282282

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

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

29962996
// Repeatedly write and read a TLV encoding to a chain of PacketBuffers. Use progressively larger

src/protocols/secure_channel/CASESession.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg)
15711571
TLV::TLVType containerType = TLV::kTLVType_Structure;
15721572

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

15761576
constexpr size_t kCaseOverheadForFutureTbeData = 128;
15771577

0 commit comments

Comments
 (0)