Skip to content

Commit 5970ae1

Browse files
committed
2 parents a37d03d + 0da50e9 commit 5970ae1

31 files changed

+4220
-159
lines changed

config/telink/chip-module/Kconfig.defaults

-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ config CHIP_WIFI
304304
select NET_IPV6_ND # enable Neighbor Discovery to handle Router Advertisements
305305
select NET_IPV6_NBR_CACHE
306306
select NET_STATISTICS_USER_API
307-
# select NET_IPV4 # TODO: remove IPv4 when IPv6 will be ready (see CHIP_IPV4)
308-
# select NET_CONFIG_NEED_IPV4
309-
# select NET_DHCPV4
310307

311308
if CHIP_WIFI
312309

docs/guides/fabric_synchronization_guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ KVS
127127
Pair the Light Example with node ID 3 using its payload number:
128128

129129
```
130-
pairing already-discovered 3 20202021 <ip> 5540
130+
pairing already-discovered 3 20202021 <ip> 5543
131131
```
132132

133133
After the device is successfully added, you will observe the following on

examples/platform/telink/common/src/AppTaskCommon.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,9 @@ void AppTaskCommon::InitPwms()
414414

415415
void AppTaskCommon::LinkPwms(PwmManager & pwmManager)
416416
{
417-
#if CONFIG_WS2812_STRIP || \
418-
CONFIG_BOARD_TLSR9118BDK40D // TLSR9118BDK40D EVK buttons located on 4th PWM channel (see tlsr9118bdk40d.overlay)
417+
#if CONFIG_BOARD_TLSR9118BDK40D // TLSR9118BDK40D EVK supports only 1 PWM channel connected to LED
418+
pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0);
419+
#elif CONFIG_WS2812_STRIP
419420
pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0);
420421
pwmManager.linkPwm(PwmManager::EAppPwm_Green, 1);
421422
pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 2);

src/app/WriteHandler.cpp

+39-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "messaging/ExchangeContext.h"
2019
#include <app/AppConfig.h>
2120
#include <app/AttributeAccessInterfaceRegistry.h>
2221
#include <app/InteractionModelEngine.h>
@@ -28,6 +27,7 @@
2827
#include <app/util/MatterCallbacks.h>
2928
#include <app/util/ember-compatibility-functions.h>
3029
#include <credentials/GroupDataProvider.h>
30+
#include <lib/support/CodeUtils.h>
3131
#include <lib/support/TypeTraits.h>
3232
#include <protocols/interaction_model/StatusCode.h>
3333

@@ -62,7 +62,7 @@ void WriteHandler::Close()
6262
// successful.
6363
DeliverFinalListWriteEnd(false /* wasSuccessful */);
6464
mExchangeCtx.Release();
65-
mSuppressResponse = false;
65+
mStateFlags.Clear(StateBits::kSuppressResponse);
6666
MoveToState(State::Uninitialized);
6767
}
6868

@@ -106,7 +106,7 @@ Status WriteHandler::OnWriteRequest(Messaging::ExchangeContext * apExchangeConte
106106
Status status = HandleWriteRequestMessage(apExchangeContext, std::move(aPayload), aIsTimedWrite);
107107

108108
// The write transaction will be alive only when the message was handled successfully and there are more chunks.
109-
if (!(status == Status::Success && mHasMoreChunks))
109+
if (!(status == Status::Success && mStateFlags.Has(StateBits::kHasMoreChunks)))
110110
{
111111
Close();
112112
}
@@ -142,7 +142,7 @@ CHIP_ERROR WriteHandler::OnMessageReceived(Messaging::ExchangeContext * apExchan
142142
if (status == Status::Success)
143143
{
144144
// We have no more chunks, the write response has been sent in HandleWriteRequestMessage, so close directly.
145-
if (!mHasMoreChunks)
145+
if (!mStateFlags.Has(StateBits::kHasMoreChunks))
146146
{
147147
Close();
148148
}
@@ -184,8 +184,8 @@ CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMes
184184
VerifyOrExit(mExchangeCtx, err = CHIP_ERROR_INCORRECT_STATE);
185185
mExchangeCtx->UseSuggestedResponseTimeout(app::kExpectedIMProcessingTime);
186186
err = mExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteResponse, std::move(packet),
187-
mHasMoreChunks ? Messaging::SendMessageFlags::kExpectResponse
188-
: Messaging::SendMessageFlags::kNone);
187+
mStateFlags.Has(StateBits::kHasMoreChunks) ? Messaging::SendMessageFlags::kExpectResponse
188+
: Messaging::SendMessageFlags::kNone);
189189
SuccessOrExit(err);
190190

191191
MoveToState(State::Sending);
@@ -212,7 +212,7 @@ void WriteHandler::DeliverListWriteEnd(const ConcreteAttributePath & aPath, bool
212212

213213
void WriteHandler::DeliverFinalListWriteEnd(bool writeWasSuccessful)
214214
{
215-
if (mProcessingAttributePath.HasValue() && mProcessingAttributeIsList)
215+
if (mProcessingAttributePath.HasValue() && mStateFlags.Has(StateBits::kProcessingAttributeIsList))
216216
{
217217
DeliverListWriteEnd(mProcessingAttributePath.Value(), writeWasSuccessful);
218218
}
@@ -221,7 +221,8 @@ void WriteHandler::DeliverFinalListWriteEnd(bool writeWasSuccessful)
221221

222222
CHIP_ERROR WriteHandler::DeliverFinalListWriteEndForGroupWrite(bool writeWasSuccessful)
223223
{
224-
VerifyOrReturnError(mProcessingAttributePath.HasValue() && mProcessingAttributeIsList, CHIP_NO_ERROR);
224+
VerifyOrReturnError(mProcessingAttributePath.HasValue() && mStateFlags.Has(StateBits::kProcessingAttributeIsList),
225+
CHIP_NO_ERROR);
225226

226227
Credentials::GroupDataProvider::GroupEndpoint mapping;
227228
Credentials::GroupDataProvider * groupDataProvider = Credentials::GetGroupDataProvider();
@@ -321,18 +322,20 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataIBs(TLV::TLVReader & aAttributeData
321322
continue;
322323
}
323324

324-
if (ShouldReportListWriteEnd(mProcessingAttributePath, mProcessingAttributeIsList, dataAttributePath))
325+
if (ShouldReportListWriteEnd(mProcessingAttributePath, mStateFlags.Has(StateBits::kProcessingAttributeIsList),
326+
dataAttributePath))
325327
{
326-
DeliverListWriteEnd(mProcessingAttributePath.Value(), mAttributeWriteSuccessful);
328+
DeliverListWriteEnd(mProcessingAttributePath.Value(), mStateFlags.Has(StateBits::kAttributeWriteSuccessful));
327329
}
328330

329-
if (ShouldReportListWriteBegin(mProcessingAttributePath, mProcessingAttributeIsList, dataAttributePath))
331+
if (ShouldReportListWriteBegin(mProcessingAttributePath, mStateFlags.Has(StateBits::kProcessingAttributeIsList),
332+
dataAttributePath))
330333
{
331334
DeliverListWriteBegin(dataAttributePath);
332-
mAttributeWriteSuccessful = true;
335+
mStateFlags.Set(StateBits::kAttributeWriteSuccessful);
333336
}
334337

335-
mProcessingAttributeIsList = dataAttributePath.IsListOperation();
338+
mStateFlags.Set(StateBits::kProcessingAttributeIsList, dataAttributePath.IsListOperation());
336339
mProcessingAttributePath.SetValue(dataAttributePath);
337340

338341
DataModelCallbacks::GetInstance()->AttributeOperation(DataModelCallbacks::OperationType::Write,
@@ -370,9 +373,9 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataIBs(TLV::TLVReader & aAttributeData
370373

371374
SuccessOrExit(err);
372375

373-
if (!mHasMoreChunks)
376+
if (!mStateFlags.Has(StateBits::kHasMoreChunks))
374377
{
375-
DeliverFinalListWriteEnd(mAttributeWriteSuccessful);
378+
DeliverFinalListWriteEnd(mStateFlags.Has(StateBits::kAttributeWriteSuccessful));
376379
}
377380

378381
exit:
@@ -426,8 +429,8 @@ CHIP_ERROR WriteHandler::ProcessGroupAttributeDataIBs(TLV::TLVReader & aAttribut
426429
iterator = groupDataProvider->IterateEndpoints(fabric);
427430
VerifyOrExit(iterator != nullptr, err = CHIP_ERROR_NO_MEMORY);
428431

429-
bool shouldReportListWriteEnd =
430-
ShouldReportListWriteEnd(mProcessingAttributePath, mProcessingAttributeIsList, dataAttributePath);
432+
bool shouldReportListWriteEnd = ShouldReportListWriteEnd(
433+
mProcessingAttributePath, mStateFlags.Has(StateBits::kProcessingAttributeIsList), dataAttributePath);
431434
bool shouldReportListWriteBegin = false; // This will be set below.
432435

433436
const EmberAfAttributeMetadata * attributeMetadata = nullptr;
@@ -457,7 +460,8 @@ CHIP_ERROR WriteHandler::ProcessGroupAttributeDataIBs(TLV::TLVReader & aAttribut
457460
dataAttributePath.mEndpointId, dataAttributePath.mListOp,
458461
dataAttributePath.mListIndex);
459462
shouldReportListWriteBegin =
460-
ShouldReportListWriteBegin(mProcessingAttributePath, mProcessingAttributeIsList, pathForCheckingListWriteBegin);
463+
ShouldReportListWriteBegin(mProcessingAttributePath, mStateFlags.Has(StateBits::kProcessingAttributeIsList),
464+
pathForCheckingListWriteBegin);
461465
}
462466

463467
if (shouldReportListWriteEnd)
@@ -498,11 +502,10 @@ CHIP_ERROR WriteHandler::ProcessGroupAttributeDataIBs(TLV::TLVReader & aAttribut
498502
DataModelCallbacks::GetInstance()->AttributeOperation(DataModelCallbacks::OperationType::Write,
499503
DataModelCallbacks::OperationOrder::Pre, dataAttributePath);
500504
err = WriteSingleClusterData(subjectDescriptor, dataAttributePath, tmpDataReader, this);
501-
502505
if (err != CHIP_NO_ERROR)
503506
{
504507
ChipLogError(DataManagement,
505-
"WriteSingleClusterData Endpoint=%u Cluster=" ChipLogFormatMEI " Attribute =" ChipLogFormatMEI
508+
"WriteClusterData Endpoint=%u Cluster=" ChipLogFormatMEI " Attribute =" ChipLogFormatMEI
506509
" failed: %" CHIP_ERROR_FORMAT,
507510
mapping.endpoint_id, ChipLogValueMEI(dataAttributePath.mClusterId),
508511
ChipLogValueMEI(dataAttributePath.mAttributeId), err.Format());
@@ -512,7 +515,7 @@ CHIP_ERROR WriteHandler::ProcessGroupAttributeDataIBs(TLV::TLVReader & aAttribut
512515
}
513516

514517
dataAttributePath.mEndpointId = kInvalidEndpointId;
515-
mProcessingAttributeIsList = dataAttributePath.IsListOperation();
518+
mStateFlags.Set(StateBits::kProcessingAttributeIsList, dataAttributePath.IsListOperation());
516519
mProcessingAttributePath.SetValue(dataAttributePath);
517520
iterator->Release();
518521
}
@@ -557,24 +560,33 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload,
557560
#if CHIP_CONFIG_IM_PRETTY_PRINT
558561
writeRequestParser.PrettyPrint();
559562
#endif
560-
err = writeRequestParser.GetSuppressResponse(&mSuppressResponse);
563+
bool boolValue;
564+
565+
boolValue = mStateFlags.Has(StateBits::kSuppressResponse);
566+
err = writeRequestParser.GetSuppressResponse(&boolValue);
561567
if (err == CHIP_END_OF_TLV)
562568
{
563569
err = CHIP_NO_ERROR;
564570
}
565571
SuccessOrExit(err);
572+
mStateFlags.Set(StateBits::kSuppressResponse, boolValue);
566573

567-
err = writeRequestParser.GetTimedRequest(&mIsTimedRequest);
574+
boolValue = mStateFlags.Has(StateBits::kIsTimedRequest);
575+
err = writeRequestParser.GetTimedRequest(&boolValue);
568576
SuccessOrExit(err);
577+
mStateFlags.Set(StateBits::kIsTimedRequest, boolValue);
569578

570-
err = writeRequestParser.GetMoreChunkedMessages(&mHasMoreChunks);
579+
boolValue = mStateFlags.Has(StateBits::kHasMoreChunks);
580+
err = writeRequestParser.GetMoreChunkedMessages(&boolValue);
571581
if (err == CHIP_ERROR_END_OF_TLV)
572582
{
573583
err = CHIP_NO_ERROR;
574584
}
575585
SuccessOrExit(err);
586+
mStateFlags.Set(StateBits::kHasMoreChunks, boolValue);
576587

577-
if (mHasMoreChunks && (mExchangeCtx->IsGroupExchangeContext() || mIsTimedRequest))
588+
if (mStateFlags.Has(StateBits::kHasMoreChunks) &&
589+
(mExchangeCtx->IsGroupExchangeContext() || mStateFlags.Has(StateBits::kIsTimedRequest)))
578590
{
579591
// Sanity check: group exchange context should only have one chunk.
580592
// Also, timed requests should not have more than one chunk.
@@ -584,7 +596,7 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload,
584596
err = writeRequestParser.GetWriteRequests(&AttributeDataIBsParser);
585597
SuccessOrExit(err);
586598

587-
if (mIsTimedRequest != aIsTimedWrite)
599+
if (mStateFlags.Has(StateBits::kIsTimedRequest) != aIsTimedWrite)
588600
{
589601
// The message thinks it should be part of a timed interaction but it's
590602
// not, or vice versa.
@@ -641,7 +653,7 @@ CHIP_ERROR WriteHandler::AddStatusInternal(const ConcreteDataAttributePath & aPa
641653

642654
if (!aStatus.IsSuccess())
643655
{
644-
mAttributeWriteSuccessful = false;
656+
mStateFlags.Clear(StateBits::kAttributeWriteSuccessful);
645657
}
646658

647659
ReturnErrorOnFailure(writeResponses.GetError());

src/app/WriteHandler.h

+32-18
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
*/
1818

1919
#pragma once
20+
21+
#include <app/AppConfig.h>
2022
#include <app/AttributeAccessToken.h>
2123
#include <app/AttributePathParams.h>
2224
#include <app/InteractionModelDelegatePointers.h>
2325
#include <app/MessageDef/WriteResponseMessage.h>
2426
#include <lib/core/CHIPCore.h>
2527
#include <lib/core/TLVDebug.h>
28+
#include <lib/support/BitFlags.h>
2629
#include <lib/support/CodeUtils.h>
2730
#include <lib/support/DLLUtil.h>
2831
#include <lib/support/logging/CHIPLogging.h>
@@ -68,9 +71,11 @@ class WriteHandler : public Messaging::ExchangeDelegate
6871
*
6972
* @param[in] apWriteHandlerDelegate A Valid pointer to the WriteHandlerDelegate.
7073
*
74+
* @retval #CHIP_ERROR_INVALID_ARGUMENT on invalid pointers
7175
* @retval #CHIP_ERROR_INCORRECT_STATE If the state is not equal to
7276
* kState_NotInitialized.
7377
* @retval #CHIP_NO_ERROR On success.
78+
*
7479
*/
7580
CHIP_ERROR Init(WriteHandlerDelegate * apWriteHandlerDelegate);
7681

@@ -115,7 +120,7 @@ class WriteHandler : public Messaging::ExchangeDelegate
115120
/**
116121
* Check whether the WriteRequest we are handling is a timed write.
117122
*/
118-
bool IsTimedWrite() const { return mIsTimedRequest; }
123+
bool IsTimedWrite() const { return mStateFlags.Has(StateBits::kIsTimedRequest); }
119124

120125
bool MatchesExchangeContext(Messaging::ExchangeContext * apExchangeContext) const
121126
{
@@ -136,7 +141,7 @@ class WriteHandler : public Messaging::ExchangeDelegate
136141

137142
private:
138143
friend class TestWriteInteraction;
139-
enum class State
144+
enum class State : uint8_t
140145
{
141146
Uninitialized = 0, // The handler has not been initialized
142147
Initialized, // The handler has been initialized and is ready
@@ -172,30 +177,14 @@ class WriteHandler : public Messaging::ExchangeDelegate
172177

173178
CHIP_ERROR AddStatusInternal(const ConcreteDataAttributePath & aPath, const StatusIB & aStatus);
174179

175-
private:
176180
// ExchangeDelegate
177181
CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader,
178182
System::PacketBufferHandle && aPayload) override;
179183
void OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext) override;
180184

181185
Messaging::ExchangeHolder mExchangeCtx;
182186
WriteResponseMessage::Builder mWriteResponseBuilder;
183-
State mState = State::Uninitialized;
184-
bool mIsTimedRequest = false;
185-
bool mSuppressResponse = false;
186-
bool mHasMoreChunks = false;
187187
Optional<ConcreteAttributePath> mProcessingAttributePath;
188-
bool mProcessingAttributeIsList = false;
189-
// We record the Status when AddStatus is called to determine whether all data of a list write is accepted.
190-
// This value will be used by DeliverListWriteEnd and DeliverFinalListWriteEnd but it won't be used by group writes based on the
191-
// fact that the errors that won't be delivered to AttributeAccessInterface are:
192-
// (1) Attribute not found
193-
// (2) Access control failed
194-
// (3) Write request to a read-only attribute
195-
// (4) Data version mismatch
196-
// (5) Not using timed write.
197-
// Where (1)-(3) will be consistent among the whole list write request, while (4) and (5) are not appliable to group writes.
198-
bool mAttributeWriteSuccessful = false;
199188
Optional<AttributeAccessToken> mACLCheckCache = NullOptional;
200189

201190
// This may be a "fake" pointer or a real delegate pointer, depending
@@ -205,6 +194,31 @@ class WriteHandler : public Messaging::ExchangeDelegate
205194
// set to the global InteractionModelEngine and the size of this
206195
// member is 1 byte.
207196
InteractionModelDelegatePointer<WriteHandlerDelegate> mDelegate;
197+
198+
// bit level enums to save storage for this object. InteractionModelEngine maintains
199+
// several of these objects, so every bit of storage multiplies storage usage.
200+
enum class StateBits : uint8_t
201+
{
202+
kIsTimedRequest = 0x01,
203+
kSuppressResponse = 0x02,
204+
kHasMoreChunks = 0x04,
205+
kProcessingAttributeIsList = 0x08,
206+
// We record the Status when AddStatus is called to determine whether all data of a list write is accepted.
207+
// This value will be used by DeliverListWriteEnd and DeliverFinalListWriteEnd but it won't be used by group writes based on
208+
// the fact that the errors that won't be delivered to AttributeAccessInterface are:
209+
// (1) Attribute not found
210+
// (2) Access control failed
211+
// (3) Write request to a read-only attribute
212+
// (4) Data version mismatch
213+
// (5) Not using timed write.
214+
// Where (1)-(3) will be consistent among the whole list write request, while (4) and (5) are not appliable to group
215+
// writes.
216+
kAttributeWriteSuccessful = 0x10,
217+
};
218+
219+
BitFlags<StateBits> mStateFlags;
220+
State mState = State::Uninitialized;
208221
};
222+
209223
} // namespace app
210224
} // namespace chip

src/include/platform/ThreadStackManager.h

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class ThreadStackManager
105105
CHIP_ERROR GetAndLogThreadTopologyFull();
106106
CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf);
107107
CHIP_ERROR GetExternalIPv6Address(chip::Inet::IPAddress & addr);
108+
CHIP_ERROR GetThreadVersion(uint16_t & version);
108109
CHIP_ERROR GetPollPeriod(uint32_t & buf);
109110

110111
CHIP_ERROR SetThreadProvision(ByteSpan aDataset);
@@ -444,6 +445,11 @@ inline CHIP_ERROR ThreadStackManager::GetExternalIPv6Address(chip::Inet::IPAddre
444445
return static_cast<ImplClass *>(this)->_GetExternalIPv6Address(addr);
445446
}
446447

448+
inline CHIP_ERROR ThreadStackManager::GetThreadVersion(uint16_t & version)
449+
{
450+
return static_cast<ImplClass *>(this)->_GetThreadVersion(version);
451+
}
452+
447453
inline CHIP_ERROR ThreadStackManager::GetPollPeriod(uint32_t & buf)
448454
{
449455
return static_cast<ImplClass *>(this)->_GetPollPeriod(buf);

src/platform/Linux/NetworkCommissioningThreadDriver.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ ThreadCapabilities LinuxThreadDriver::GetSupportedThreadFeatures()
211211

212212
uint16_t LinuxThreadDriver::GetThreadVersion()
213213
{
214-
// TODO https://github.com/project-chip/connectedhomeip/issues/30602
215-
// Needs to be implemented with DBUS io.openthread.BorderRouter Thread API
216-
return 0;
214+
uint16_t version = 0;
215+
ThreadStackMgrImpl().GetThreadVersion(version);
216+
return version;
217217
}
218218

219219
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

src/platform/Linux/ThreadStackManagerImpl.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ CHIP_ERROR ThreadStackManagerImpl::_GetExternalIPv6Address(chip::Inet::IPAddress
563563
return CHIP_ERROR_NOT_IMPLEMENTED;
564564
}
565565

566+
CHIP_ERROR ThreadStackManagerImpl::_GetThreadVersion(uint16_t & version)
567+
{
568+
// TODO https://github.com/project-chip/connectedhomeip/issues/30602
569+
// Needs to be implemented with DBUS io.openthread.BorderRouter Thread API
570+
return CHIP_ERROR_NOT_IMPLEMENTED;
571+
}
572+
566573
CHIP_ERROR ThreadStackManagerImpl::_GetPollPeriod(uint32_t & buf)
567574
{
568575
// TODO: Remove Weave legacy APIs

0 commit comments

Comments
 (0)