Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2347485

Browse files
ksperling-applepull[bot]
authored andcommittedSep 11, 2024
Get plumbing in place for TBRM cluster certification tests (#34696)
* Add TBRM cluster to network-manager-app and add TC_TBRM_2_1 script Also fix some GN dependency issues. The TBRM delegate is currently a crude mock. * zap_regen_all
1 parent 6051639 commit 2347485

File tree

12 files changed

+513
-11
lines changed

12 files changed

+513
-11
lines changed
 

‎examples/network-manager-app/linux/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ executable("matter-network-manager-app") {
1919
sources = [
2020
"include/CHIPProjectAppConfig.h",
2121
"main.cpp",
22+
"tbrm.cpp",
2223
]
2324

2425
deps = [
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <app/clusters/thread-border-router-management-server/thread-border-router-management-server.h>
19+
#include <app/server/Server.h>
20+
#include <lib/core/CHIPEncoding.h>
21+
#include <lib/support/CodeUtils.h>
22+
#include <lib/support/Span.h>
23+
#include <lib/support/ThreadOperationalDataset.h>
24+
#include <platform/CHIPDeviceLayer.h>
25+
26+
#include <optional>
27+
28+
using namespace chip;
29+
using namespace chip::literals;
30+
using namespace chip::app;
31+
using namespace chip::app::Clusters;
32+
33+
namespace {
34+
class FakeBorderRouterDelegate final : public ThreadBorderRouterManagement::Delegate
35+
{
36+
CHIP_ERROR Init(AttributeChangeCallback * attributeChangeCallback) override
37+
{
38+
mAttributeChangeCallback = attributeChangeCallback;
39+
return CHIP_NO_ERROR;
40+
}
41+
42+
bool GetPanChangeSupported() override { return true; }
43+
44+
void GetBorderRouterName(MutableCharSpan & borderRouterName) override
45+
{
46+
CopyCharSpanToMutableCharSpan("netman-br"_span, borderRouterName);
47+
}
48+
49+
CHIP_ERROR GetBorderAgentId(MutableByteSpan & borderAgentId) override
50+
{
51+
static constexpr uint8_t kBorderAgentId[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
52+
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
53+
VerifyOrReturnError(borderAgentId.size() == 16, CHIP_ERROR_INVALID_ARGUMENT);
54+
return CopySpanToMutableSpan(ByteSpan(kBorderAgentId), borderAgentId);
55+
}
56+
57+
uint16_t GetThreadVersion() override { return /* Thread 1.3.1 */ 5; }
58+
59+
bool GetInterfaceEnabled() override { return !mActiveDataset.IsEmpty(); }
60+
61+
CHIP_ERROR GetDataset(Thread::OperationalDataset & dataset, DatasetType type) override
62+
{
63+
Thread::OperationalDataset * source;
64+
switch (type)
65+
{
66+
case DatasetType::kActive:
67+
source = &mActiveDataset;
68+
break;
69+
case DatasetType::kPending:
70+
source = &mPendingDataset;
71+
break;
72+
default:
73+
return CHIP_ERROR_INVALID_ARGUMENT;
74+
}
75+
VerifyOrReturnError(!source->IsEmpty(), CHIP_ERROR_NOT_FOUND);
76+
return dataset.Init(source->AsByteSpan());
77+
}
78+
79+
void SetActiveDataset(const Thread::OperationalDataset & activeDataset, uint32_t sequenceNum,
80+
ActivateDatasetCallback * callback) override
81+
{
82+
if (mActivateDatasetCallback != nullptr)
83+
{
84+
callback->OnActivateDatasetComplete(sequenceNum, CHIP_ERROR_INCORRECT_STATE);
85+
return;
86+
}
87+
88+
CHIP_ERROR err = mActiveDataset.Init(activeDataset.AsByteSpan());
89+
if (err != CHIP_NO_ERROR)
90+
{
91+
callback->OnActivateDatasetComplete(sequenceNum, err);
92+
return;
93+
}
94+
95+
mActivateDatasetCallback = callback;
96+
mActivateDatasetSequence = sequenceNum;
97+
DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(3000), CompleteDatasetActivation, this);
98+
}
99+
100+
CHIP_ERROR CommitActiveDataset() override { return CHIP_NO_ERROR; }
101+
CHIP_ERROR RevertActiveDataset() override { return CHIP_ERROR_NOT_IMPLEMENTED; }
102+
CHIP_ERROR SetPendingDataset(const Thread::OperationalDataset & pendingDataset) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
103+
104+
private:
105+
static void CompleteDatasetActivation(System::Layer *, void * context)
106+
{
107+
auto * self = static_cast<FakeBorderRouterDelegate *>(context);
108+
auto * callback = self->mActivateDatasetCallback;
109+
auto sequenceNum = self->mActivateDatasetSequence;
110+
self->mActivateDatasetCallback = nullptr;
111+
callback->OnActivateDatasetComplete(sequenceNum, CHIP_NO_ERROR);
112+
}
113+
114+
AttributeChangeCallback * mAttributeChangeCallback;
115+
Thread::OperationalDataset mActiveDataset;
116+
Thread::OperationalDataset mPendingDataset;
117+
118+
ActivateDatasetCallback * mActivateDatasetCallback = nullptr;
119+
uint32_t mActivateDatasetSequence;
120+
};
121+
122+
FakeBorderRouterDelegate gBorderRouterDelegate{};
123+
} // namespace
124+
125+
std::optional<ThreadBorderRouterManagement::ServerInstance> gThreadBorderRouterManagementServer;
126+
void emberAfThreadBorderRouterManagementClusterInitCallback(EndpointId endpoint)
127+
{
128+
VerifyOrDie(!gThreadBorderRouterManagementServer);
129+
gThreadBorderRouterManagementServer.emplace(endpoint, &gBorderRouterDelegate, Server::GetInstance().GetFailSafeContext())
130+
.Init();
131+
}

‎examples/network-manager-app/network-manager-common/network-manager-app.matter

+62
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,49 @@ provisional cluster WiFiNetworkManagement = 1105 {
14911491
command access(invoke: manage) NetworkPassphraseRequest(): NetworkPassphraseResponse = 0;
14921492
}
14931493

1494+
/** Manage the Thread network of Thread Border Router */
1495+
provisional cluster ThreadBorderRouterManagement = 1106 {
1496+
revision 1;
1497+
1498+
bitmap Feature : bitmap32 {
1499+
kPANChange = 0x1;
1500+
}
1501+
1502+
provisional readonly attribute char_string<63> borderRouterName = 0;
1503+
provisional readonly attribute octet_string<254> borderAgentID = 1;
1504+
provisional readonly attribute int16u threadVersion = 2;
1505+
provisional readonly attribute boolean interfaceEnabled = 3;
1506+
provisional readonly attribute nullable int64u activeDatasetTimestamp = 4;
1507+
readonly attribute command_id generatedCommandList[] = 65528;
1508+
readonly attribute command_id acceptedCommandList[] = 65529;
1509+
readonly attribute event_id eventList[] = 65530;
1510+
readonly attribute attrib_id attributeList[] = 65531;
1511+
readonly attribute bitmap32 featureMap = 65532;
1512+
readonly attribute int16u clusterRevision = 65533;
1513+
1514+
response struct DatasetResponse = 2 {
1515+
octet_string<254> dataset = 0;
1516+
}
1517+
1518+
request struct SetActiveDatasetRequestRequest {
1519+
octet_string<254> activeDataset = 0;
1520+
optional int64u breadcrumb = 1;
1521+
}
1522+
1523+
request struct SetPendingDatasetRequestRequest {
1524+
octet_string<254> pendingDataset = 0;
1525+
}
1526+
1527+
/** Command to request the active operational dataset of the Thread network to which the border router is connected. This command must be sent over a valid CASE session */
1528+
command access(invoke: manage) GetActiveDatasetRequest(): DatasetResponse = 0;
1529+
/** Command to request the pending dataset of the Thread network to which the border router is connected. This command must be sent over a valid CASE session */
1530+
command access(invoke: manage) GetPendingDatasetRequest(): DatasetResponse = 1;
1531+
/** Command to set or update the active Dataset of the Thread network to which the Border Router is connected. */
1532+
command access(invoke: manage) SetActiveDatasetRequest(SetActiveDatasetRequestRequest): DefaultSuccess = 3;
1533+
/** Command set or update the pending Dataset of the Thread network to which the Border Router is connected. */
1534+
command access(invoke: manage) SetPendingDatasetRequest(SetPendingDatasetRequestRequest): DefaultSuccess = 4;
1535+
}
1536+
14941537
/** Manages the names and credentials of Thread networks visible to the user. */
14951538
provisional cluster ThreadNetworkDirectory = 1107 {
14961539
revision 1;
@@ -1816,6 +1859,25 @@ endpoint 1 {
18161859
handle command NetworkPassphraseResponse;
18171860
}
18181861

1862+
server cluster ThreadBorderRouterManagement {
1863+
callback attribute borderRouterName;
1864+
callback attribute borderAgentID;
1865+
callback attribute threadVersion;
1866+
callback attribute interfaceEnabled;
1867+
callback attribute activeDatasetTimestamp;
1868+
callback attribute generatedCommandList;
1869+
callback attribute acceptedCommandList;
1870+
callback attribute eventList;
1871+
callback attribute attributeList;
1872+
callback attribute featureMap;
1873+
ram attribute clusterRevision default = 1;
1874+
1875+
handle command GetActiveDatasetRequest;
1876+
handle command GetPendingDatasetRequest;
1877+
handle command DatasetResponse;
1878+
handle command SetActiveDatasetRequest;
1879+
}
1880+
18191881
server cluster ThreadNetworkDirectory {
18201882
callback attribute preferredExtendedPanID;
18211883
callback attribute threadNetworks;

0 commit comments

Comments
 (0)
Please sign in to comment.