Skip to content

Commit c024e4f

Browse files
ksperling-applebzbarsky-applekiel-apple
authored
Implement Thread Network Directory server (#34343)
* Update Thread Network Directory cluster definition - Use octstr[8] for ExtendedPanID fields - Add ActiveTimestamp to ThreadNetworkStruct - Remove NetworkChanged event PreferredExtendedPanID is nullable, so the uint64 representation is not suitable because the value 0xFFF... is disallowed as a null marker. Change all related attributes / fields to octstr[8] to be consistent. Also add the cluster to the relevant meta-data files. See CHIP-Specifications/connectedhomeip-spec#10019 * zap_regen_all * Implement Thread Network Directory server Also add it to the network-manager example app. * Apply suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> Co-authored-by: Kiel Oleson <kielo@apple.com> * Apply suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Remove stale zap generated files * Address review comments Remove DefaultInstance() and weak cluster init function and instead provide a DefaultThreadNetworkDirectoryServer sub-class that's easy to instantiate with the default storage implementation. Roll back in-memory state on persistent storage failure and add tests for this. Add documentation about ByteSpan lifetimes in OperationalDataset class. Add comments to MTRDemuxingStorage.mm * Use emberAf...ClusterInitCallback (not ...Server) * Address review comments * Avoid conversion warning --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> Co-authored-by: Kiel Oleson <kielo@apple.com>
1 parent 2eb95ca commit c024e4f

File tree

70 files changed

+1788
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1788
-721
lines changed

examples/network-manager-app/linux/main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
*/
1717

1818
#include <AppMain.h>
19+
#include <app/clusters/thread-network-directory-server/thread-network-directory-server.h>
1920
#include <app/clusters/wifi-network-management-server/wifi-network-management-server.h>
2021
#include <lib/core/CHIPSafeCasts.h>
22+
#include <lib/support/CodeUtils.h>
2123
#include <lib/support/Span.h>
2224

25+
#include <optional>
26+
2327
using namespace chip;
2428
using namespace chip::app;
2529
using namespace chip::app::Clusters;
@@ -32,6 +36,13 @@ ByteSpan ByteSpanFromCharSpan(CharSpan span)
3236
return ByteSpan(Uint8::from_const_char(span.data()), span.size());
3337
}
3438

39+
std::optional<DefaultThreadNetworkDirectoryServer> gThreadNetworkDirectoryServer;
40+
void emberAfThreadNetworkDirectoryClusterInitCallback(chip::EndpointId endpoint)
41+
{
42+
VerifyOrDie(!gThreadNetworkDirectoryServer);
43+
gThreadNetworkDirectoryServer.emplace(endpoint).Init();
44+
}
45+
3546
int main(int argc, char * argv[])
3647
{
3748
if (ChipLinuxAppInit(argc, argv) != 0)

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

+62
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,51 @@ cluster WiFiNetworkManagement = 1105 {
11951195
command access(invoke: administer) NetworkPassphraseRequest(): NetworkPassphraseResponse = 0;
11961196
}
11971197

1198+
/** Manages the names and credentials of Thread networks visible to the user. */
1199+
cluster ThreadNetworkDirectory = 1107 {
1200+
revision 1;
1201+
1202+
struct ThreadNetworkStruct {
1203+
octet_string<8> extendedPanID = 0;
1204+
char_string<16> networkName = 1;
1205+
int16u channel = 2;
1206+
int64u activeTimestamp = 3;
1207+
}
1208+
1209+
attribute access(read: manage, write: manage) nullable octet_string<8> preferredExtendedPanID = 0;
1210+
readonly attribute access(read: operate) ThreadNetworkStruct threadNetworks[] = 1;
1211+
readonly attribute int8u threadNetworkTableSize = 2;
1212+
readonly attribute command_id generatedCommandList[] = 65528;
1213+
readonly attribute command_id acceptedCommandList[] = 65529;
1214+
readonly attribute event_id eventList[] = 65530;
1215+
readonly attribute attrib_id attributeList[] = 65531;
1216+
readonly attribute bitmap32 featureMap = 65532;
1217+
readonly attribute int16u clusterRevision = 65533;
1218+
1219+
request struct AddNetworkRequest {
1220+
octet_string<254> operationalDataset = 0;
1221+
}
1222+
1223+
request struct RemoveNetworkRequest {
1224+
octet_string<8> extendedPanID = 0;
1225+
}
1226+
1227+
request struct GetOperationalDatasetRequest {
1228+
octet_string<8> extendedPanID = 0;
1229+
}
1230+
1231+
response struct OperationalDatasetResponse = 3 {
1232+
octet_string<254> operationalDataset = 0;
1233+
}
1234+
1235+
/** Adds an entry to the ThreadNetworks list. */
1236+
timed command access(invoke: manage) AddNetwork(AddNetworkRequest): DefaultSuccess = 0;
1237+
/** Removes an entry from the ThreadNetworks list. */
1238+
timed command access(invoke: manage) RemoveNetwork(RemoveNetworkRequest): DefaultSuccess = 1;
1239+
/** Retrieves a Thread Operational Dataset from the ThreadNetworks list. */
1240+
timed command GetOperationalDataset(GetOperationalDatasetRequest): OperationalDatasetResponse = 2;
1241+
}
1242+
11981243
endpoint 0 {
11991244
device type ma_rootdevice = 22, version 1;
12001245

@@ -1473,6 +1518,23 @@ endpoint 1 {
14731518
handle command NetworkPassphraseRequest;
14741519
handle command NetworkPassphraseResponse;
14751520
}
1521+
1522+
server cluster ThreadNetworkDirectory {
1523+
callback attribute preferredExtendedPanID;
1524+
callback attribute threadNetworks;
1525+
callback attribute threadNetworkTableSize;
1526+
callback attribute generatedCommandList;
1527+
callback attribute acceptedCommandList;
1528+
callback attribute eventList;
1529+
callback attribute attributeList;
1530+
ram attribute featureMap default = 0;
1531+
ram attribute clusterRevision default = 1;
1532+
1533+
handle command AddNetwork;
1534+
handle command RemoveNetwork;
1535+
handle command GetOperationalDataset;
1536+
handle command OperationalDatasetResponse;
1537+
}
14761538
}
14771539

14781540

examples/network-manager-app/network-manager-common/network-manager-app.zap

+188
Original file line numberDiff line numberDiff line change
@@ -3349,6 +3349,194 @@
33493349
"reportableChange": 0
33503350
}
33513351
]
3352+
},
3353+
{
3354+
"name": "Thread Network Directory",
3355+
"code": 1107,
3356+
"mfgCode": null,
3357+
"define": "THREAD_NETWORK_DIRECTORY_CLUSTER",
3358+
"side": "server",
3359+
"enabled": 1,
3360+
"commands": [
3361+
{
3362+
"name": "AddNetwork",
3363+
"code": 0,
3364+
"mfgCode": null,
3365+
"source": "client",
3366+
"isIncoming": 1,
3367+
"isEnabled": 1
3368+
},
3369+
{
3370+
"name": "RemoveNetwork",
3371+
"code": 1,
3372+
"mfgCode": null,
3373+
"source": "client",
3374+
"isIncoming": 1,
3375+
"isEnabled": 1
3376+
},
3377+
{
3378+
"name": "GetOperationalDataset",
3379+
"code": 2,
3380+
"mfgCode": null,
3381+
"source": "client",
3382+
"isIncoming": 1,
3383+
"isEnabled": 1
3384+
},
3385+
{
3386+
"name": "OperationalDatasetResponse",
3387+
"code": 3,
3388+
"mfgCode": null,
3389+
"source": "server",
3390+
"isIncoming": 0,
3391+
"isEnabled": 1
3392+
}
3393+
],
3394+
"attributes": [
3395+
{
3396+
"name": "PreferredExtendedPanID",
3397+
"code": 0,
3398+
"mfgCode": null,
3399+
"side": "server",
3400+
"type": "octet_string",
3401+
"included": 1,
3402+
"storageOption": "External",
3403+
"singleton": 0,
3404+
"bounded": 0,
3405+
"defaultValue": null,
3406+
"reportable": 1,
3407+
"minInterval": 1,
3408+
"maxInterval": 65534,
3409+
"reportableChange": 0
3410+
},
3411+
{
3412+
"name": "ThreadNetworks",
3413+
"code": 1,
3414+
"mfgCode": null,
3415+
"side": "server",
3416+
"type": "array",
3417+
"included": 1,
3418+
"storageOption": "External",
3419+
"singleton": 0,
3420+
"bounded": 0,
3421+
"defaultValue": null,
3422+
"reportable": 1,
3423+
"minInterval": 1,
3424+
"maxInterval": 65534,
3425+
"reportableChange": 0
3426+
},
3427+
{
3428+
"name": "ThreadNetworkTableSize",
3429+
"code": 2,
3430+
"mfgCode": null,
3431+
"side": "server",
3432+
"type": "int8u",
3433+
"included": 1,
3434+
"storageOption": "External",
3435+
"singleton": 0,
3436+
"bounded": 0,
3437+
"defaultValue": null,
3438+
"reportable": 1,
3439+
"minInterval": 1,
3440+
"maxInterval": 65534,
3441+
"reportableChange": 0
3442+
},
3443+
{
3444+
"name": "GeneratedCommandList",
3445+
"code": 65528,
3446+
"mfgCode": null,
3447+
"side": "server",
3448+
"type": "array",
3449+
"included": 1,
3450+
"storageOption": "External",
3451+
"singleton": 0,
3452+
"bounded": 0,
3453+
"defaultValue": null,
3454+
"reportable": 1,
3455+
"minInterval": 1,
3456+
"maxInterval": 65534,
3457+
"reportableChange": 0
3458+
},
3459+
{
3460+
"name": "AcceptedCommandList",
3461+
"code": 65529,
3462+
"mfgCode": null,
3463+
"side": "server",
3464+
"type": "array",
3465+
"included": 1,
3466+
"storageOption": "External",
3467+
"singleton": 0,
3468+
"bounded": 0,
3469+
"defaultValue": null,
3470+
"reportable": 1,
3471+
"minInterval": 1,
3472+
"maxInterval": 65534,
3473+
"reportableChange": 0
3474+
},
3475+
{
3476+
"name": "EventList",
3477+
"code": 65530,
3478+
"mfgCode": null,
3479+
"side": "server",
3480+
"type": "array",
3481+
"included": 1,
3482+
"storageOption": "External",
3483+
"singleton": 0,
3484+
"bounded": 0,
3485+
"defaultValue": null,
3486+
"reportable": 1,
3487+
"minInterval": 1,
3488+
"maxInterval": 65534,
3489+
"reportableChange": 0
3490+
},
3491+
{
3492+
"name": "AttributeList",
3493+
"code": 65531,
3494+
"mfgCode": null,
3495+
"side": "server",
3496+
"type": "array",
3497+
"included": 1,
3498+
"storageOption": "External",
3499+
"singleton": 0,
3500+
"bounded": 0,
3501+
"defaultValue": null,
3502+
"reportable": 1,
3503+
"minInterval": 1,
3504+
"maxInterval": 65534,
3505+
"reportableChange": 0
3506+
},
3507+
{
3508+
"name": "FeatureMap",
3509+
"code": 65532,
3510+
"mfgCode": null,
3511+
"side": "server",
3512+
"type": "bitmap32",
3513+
"included": 1,
3514+
"storageOption": "RAM",
3515+
"singleton": 0,
3516+
"bounded": 0,
3517+
"defaultValue": "0",
3518+
"reportable": 1,
3519+
"minInterval": 1,
3520+
"maxInterval": 65534,
3521+
"reportableChange": 0
3522+
},
3523+
{
3524+
"name": "ClusterRevision",
3525+
"code": 65533,
3526+
"mfgCode": null,
3527+
"side": "server",
3528+
"type": "int16u",
3529+
"included": 1,
3530+
"storageOption": "RAM",
3531+
"singleton": 0,
3532+
"bounded": 0,
3533+
"defaultValue": "1",
3534+
"reportable": 1,
3535+
"minInterval": 1,
3536+
"maxInterval": 65534,
3537+
"reportableChange": 0
3538+
}
3539+
]
33523540
}
33533541
]
33543542
}

scripts/rules.matterlint

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ load "../src/app/zap-templates/zcl/data-model/chip/thermostat-user-interface-con
9494
load "../src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml";
9595
load "../src/app/zap-templates/zcl/data-model/chip/thread-border-router-management-cluster.xml";
9696
load "../src/app/zap-templates/zcl/data-model/chip/thread-network-diagnostics-cluster.xml";
97+
load "../src/app/zap-templates/zcl/data-model/chip/thread-network-directory-cluster.xml";
9798
load "../src/app/zap-templates/zcl/data-model/chip/time-format-localization-cluster.xml";
9899
load "../src/app/zap-templates/zcl/data-model/chip/time-synchronization-cluster.xml";
99100
load "../src/app/zap-templates/zcl/data-model/chip/timer-cluster.xml";

src/app/AttributeAccessInterface.h

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ class AttributeAccessInterface
149149
(!mEndpointId.HasValue() || !aOther.mEndpointId.HasValue() || mEndpointId.Value() == aOther.mEndpointId.Value());
150150
}
151151

152+
protected:
153+
Optional<EndpointId> GetEndpointId() { return mEndpointId; }
154+
152155
private:
153156
Optional<EndpointId> mEndpointId;
154157
ClusterId mClusterId;

src/app/CommandHandlerInterface.h

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ class CommandHandlerInterface
226226
}
227227
}
228228

229+
Optional<EndpointId> GetEndpointId() { return mEndpointId; }
230+
229231
private:
230232
Optional<EndpointId> mEndpointId;
231233
ClusterId mClusterId;

src/app/chip_data_model.gni

+8
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ template("chip_data_model") {
390390
"${_app_root}/clusters/${cluster}/thread-network-diagnostics-provider.cpp",
391391
"${_app_root}/clusters/${cluster}/thread-network-diagnostics-provider.h",
392392
]
393+
} else if (cluster == "thread-network-directory-server") {
394+
sources += [
395+
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
396+
"${_app_root}/clusters/${cluster}/${cluster}.h",
397+
"${_app_root}/clusters/${cluster}/DefaultThreadNetworkDirectoryStorage.cpp",
398+
"${_app_root}/clusters/${cluster}/DefaultThreadNetworkDirectoryStorage.h",
399+
"${_app_root}/clusters/${cluster}/ThreadNetworkDirectoryStorage.h",
400+
]
393401
} else {
394402
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
395403
}

0 commit comments

Comments
 (0)