-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy paththread-network-diagnostics-provider.cpp
851 lines (753 loc) · 32.3 KB
/
thread-network-diagnostics-provider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "thread-network-diagnostics-provider.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/Encode.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>
#if (CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK)
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#if CHIP_DEVICE_CONFIG_THREAD_FTD
#include <openthread/thread_ftd.h>
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
#endif // (CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK)
using namespace chip::DeviceLayer;
namespace chip {
namespace app {
namespace Clusters {
namespace ThreadNetworkDiagnostics {
/*
* @brief Get runtime value from the thread network based on the given attribute ID.
* The info is encoded via the AttributeValueEncoder.
*
* @param attributeId Id of the attribute for the requested info.
* @param aEncoder Encoder to encode the attribute value.
*
* @return CHIP_NO_ERROR = Succes.
* CHIP_ERROR_NOT_IMPLEMENTED = Runtime value for this attribute not yet available to send as reply
* Use standard read.
* CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE = Is not a Runtime readable attribute. Use standard read
* All other errors should be treated as a read error and reported as such.
*
* @note This function implementation can compile in 3 different outcomes
* (1) CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK:
* - Generic implementation fetching the valid thread network data from the thread stack and encoding it respectively to
* the attributeID received.
* (2) CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK:
* - Encode a NULL value for nullable attributes or 0 for the others.
* - Devices using the ot-br-posix dbus stack have not yet provided the API to fetch the needed thread informations.
* (3) None of the conditions above
* - returns CHIP_ERROR_NOT_IMPLEMENTED.
*/
CHIP_ERROR WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder)
{
CHIP_ERROR err;
#if (CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK)
otInstance * otInst = ThreadStackMgrImpl().OTInstance();
if (!otDatasetIsCommissioned(otInst))
{
// For the following nullable attributes of the cluster, encodeNull since
// thread instance cannot provide the relevant data when it is not currently configured.
//
// Note that RoutingRole is nullable but not listed here as thread provides
// valid data even when disabled or detached
switch (attributeId)
{
case Attributes::Channel::Id:
case Attributes::NetworkName::Id:
case Attributes::PanId::Id:
case Attributes::ExtendedPanId::Id:
case Attributes::MeshLocalPrefix::Id:
case Attributes::PartitionId::Id:
case Attributes::Weighting::Id:
case Attributes::DataVersion::Id:
case Attributes::StableDataVersion::Id:
case Attributes::LeaderRouterId::Id:
case Attributes::ActiveTimestamp::Id:
case Attributes::PendingTimestamp::Id:
case Attributes::Delay::Id:
case Attributes::SecurityPolicy::Id:
case Attributes::ChannelPage0Mask::Id:
case Attributes::OperationalDatasetComponents::Id:
return encoder.EncodeNull();
}
}
switch (attributeId)
{
case Attributes::Channel::Id: {
uint16_t channel = otLinkGetChannel(otInst);
err = encoder.Encode(channel);
}
break;
case Attributes::RoutingRole::Id: {
using ThreadNetworkDiagnostics::RoutingRoleEnum;
RoutingRoleEnum routingRole;
otDeviceRole otRole = otThreadGetDeviceRole(otInst);
if (otRole == OT_DEVICE_ROLE_DISABLED)
{
routingRole = RoutingRoleEnum::kUnspecified;
}
else if (otRole == OT_DEVICE_ROLE_DETACHED)
{
routingRole = RoutingRoleEnum::kUnassigned;
}
else if (otRole == OT_DEVICE_ROLE_ROUTER)
{
routingRole = RoutingRoleEnum::kRouter;
}
else if (otRole == OT_DEVICE_ROLE_LEADER)
{
routingRole = RoutingRoleEnum::kLeader;
}
else if (otRole == OT_DEVICE_ROLE_CHILD)
{
otLinkModeConfig linkMode = otThreadGetLinkMode(otInst);
if (linkMode.mRxOnWhenIdle)
{
routingRole = RoutingRoleEnum::kEndDevice;
#if CHIP_DEVICE_CONFIG_THREAD_FTD
if (otThreadIsRouterEligible(otInst))
{
routingRole = RoutingRoleEnum::kReed;
}
#endif
}
else
{
routingRole = RoutingRoleEnum::kSleepyEndDevice;
}
}
err = encoder.Encode(routingRole);
}
break;
case Attributes::NetworkName::Id: {
const char * networkName = otThreadGetNetworkName(otInst);
err = encoder.Encode(CharSpan::fromCharString(networkName));
}
break;
case Attributes::PanId::Id: {
uint16_t panId = otLinkGetPanId(otInst);
err = encoder.Encode(panId);
}
break;
case Attributes::ExtendedPanId::Id: {
const otExtendedPanId * pExtendedPanid = otThreadGetExtendedPanId(otInst);
err = encoder.Encode(Encoding::BigEndian::Get64(pExtendedPanid->m8));
}
break;
case Attributes::MeshLocalPrefix::Id: {
uint8_t meshLocaPrefix[OT_MESH_LOCAL_PREFIX_SIZE + 1] = { 0 }; // + 1 to encode prefix Len in the octstr
const otMeshLocalPrefix * pMeshLocalPrefix = otThreadGetMeshLocalPrefix(otInst);
meshLocaPrefix[0] = OT_IP6_PREFIX_BITSIZE;
memcpy(&meshLocaPrefix[1], pMeshLocalPrefix->m8, OT_MESH_LOCAL_PREFIX_SIZE);
err = encoder.Encode(ByteSpan(meshLocaPrefix));
}
break;
case Attributes::OverrunCount::Id: {
uint64_t overrunCount = 0; // mOverrunCount;
err = encoder.Encode(overrunCount);
}
break;
case Attributes::NeighborTable::Id: {
err = encoder.EncodeList([otInst](const auto & aEncoder) -> CHIP_ERROR {
constexpr uint16_t kFrameErrorRate100Percent = 0xffff;
constexpr uint16_t kMessageErrorRate100Percent = 0xffff;
otNeighborInfo neighInfo;
otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT;
while (otThreadGetNextNeighborInfo(otInst, &iterator, &neighInfo) == OT_ERROR_NONE)
{
Structs::NeighborTableStruct::Type neighborTable;
app::DataModel::Nullable<int8_t> averageRssi;
app::DataModel::Nullable<int8_t> lastRssi;
if (neighInfo.mAverageRssi == OT_RADIO_RSSI_INVALID)
{
averageRssi.SetNull();
}
else
{
// Thread average calculation already restrict mAverageRssi to be between -128 and 0
averageRssi.SetNonNull(neighInfo.mAverageRssi);
}
if (neighInfo.mLastRssi == OT_RADIO_RSSI_INVALID)
{
lastRssi.SetNull();
}
else
{
lastRssi.SetNonNull(std::min(static_cast<int8_t>(0), neighInfo.mLastRssi));
}
neighborTable.averageRssi = averageRssi;
neighborTable.lastRssi = lastRssi;
neighborTable.extAddress = Encoding::BigEndian::Get64(neighInfo.mExtAddress.m8);
neighborTable.age = neighInfo.mAge;
neighborTable.rloc16 = neighInfo.mRloc16;
neighborTable.linkFrameCounter = neighInfo.mLinkFrameCounter;
neighborTable.mleFrameCounter = neighInfo.mMleFrameCounter;
neighborTable.lqi = neighInfo.mLinkQualityIn;
neighborTable.frameErrorRate =
static_cast<uint8_t>((static_cast<uint32_t>(neighInfo.mFrameErrorRate) * 100) / kFrameErrorRate100Percent);
neighborTable.messageErrorRate =
static_cast<uint8_t>((static_cast<uint32_t>(neighInfo.mMessageErrorRate) * 100) / kMessageErrorRate100Percent);
neighborTable.rxOnWhenIdle = neighInfo.mRxOnWhenIdle;
neighborTable.fullThreadDevice = neighInfo.mFullThreadDevice;
neighborTable.fullNetworkData = neighInfo.mFullNetworkData;
neighborTable.isChild = neighInfo.mIsChild;
ReturnErrorOnFailure(aEncoder.Encode(neighborTable));
}
return CHIP_NO_ERROR;
});
}
break;
case Attributes::RouteTable::Id: {
err = encoder.EncodeList([otInst](const auto & aEncoder) -> CHIP_ERROR {
otRouterInfo routerInfo;
#if CHIP_DEVICE_CONFIG_THREAD_FTD
uint8_t maxRouterId = otThreadGetMaxRouterId(otInst);
for (uint8_t i = 0; i <= maxRouterId; i++)
{
if (otThreadGetRouterInfo(otInst, i, &routerInfo) == OT_ERROR_NONE)
{
Structs::RouteTableStruct::Type routeTable;
routeTable.extAddress = Encoding::BigEndian::Get64(routerInfo.mExtAddress.m8);
routeTable.rloc16 = routerInfo.mRloc16;
routeTable.routerId = routerInfo.mRouterId;
routeTable.nextHop = routerInfo.mNextHop;
routeTable.pathCost = routerInfo.mPathCost;
routeTable.LQIIn = routerInfo.mLinkQualityIn;
routeTable.LQIOut = routerInfo.mLinkQualityOut;
routeTable.age = routerInfo.mAge;
routeTable.allocated = routerInfo.mAllocated;
routeTable.linkEstablished = routerInfo.mLinkEstablished;
ReturnErrorOnFailure(aEncoder.Encode(routeTable));
}
}
// Returning empty list with no error in case thread network is not up
return CHIP_NO_ERROR;
#else // OPENTHREAD_MTD
otError otErr = otThreadGetParentInfo(otInst, &routerInfo);
ReturnErrorOnFailure(Internal::MapOpenThreadError(otErr));
Structs::RouteTableStruct::Type routeTable;
routeTable.extAddress = Encoding::BigEndian::Get64(routerInfo.mExtAddress.m8);
routeTable.rloc16 = routerInfo.mRloc16;
routeTable.routerId = routerInfo.mRouterId;
routeTable.nextHop = routerInfo.mNextHop;
routeTable.pathCost = routerInfo.mPathCost;
routeTable.LQIIn = routerInfo.mLinkQualityIn;
routeTable.LQIOut = routerInfo.mLinkQualityOut;
routeTable.age = routerInfo.mAge;
routeTable.allocated = routerInfo.mAllocated;
routeTable.linkEstablished = routerInfo.mLinkEstablished;
ReturnErrorOnFailure(aEncoder.Encode(routeTable));
return CHIP_NO_ERROR;
#endif
});
}
break;
case Attributes::PartitionId::Id: {
uint32_t partitionId = otThreadGetPartitionId(otInst);
err = encoder.Encode(partitionId);
}
break;
case Attributes::Weighting::Id: {
uint8_t weight = otThreadGetLeaderWeight(otInst);
err = encoder.Encode(weight);
}
break;
case Attributes::DataVersion::Id: {
uint8_t dataVersion = otNetDataGetVersion(otInst);
err = encoder.Encode(dataVersion);
}
break;
case Attributes::StableDataVersion::Id: {
uint8_t stableVersion = otNetDataGetStableVersion(otInst);
err = encoder.Encode(stableVersion);
}
break;
case Attributes::LeaderRouterId::Id: {
uint8_t leaderRouterId = otThreadGetLeaderRouterId(otInst);
err = encoder.Encode(leaderRouterId);
}
break;
case Attributes::DetachedRoleCount::Id: {
uint16_t detachedRole = otThreadGetMleCounters(otInst)->mDetachedRole;
err = encoder.Encode(detachedRole);
}
break;
case Attributes::ChildRoleCount::Id: {
uint16_t childRole = otThreadGetMleCounters(otInst)->mChildRole;
err = encoder.Encode(childRole);
}
break;
case Attributes::RouterRoleCount::Id: {
uint16_t routerRole = otThreadGetMleCounters(otInst)->mRouterRole;
err = encoder.Encode(routerRole);
}
break;
case Attributes::LeaderRoleCount::Id: {
uint16_t leaderRole = otThreadGetMleCounters(otInst)->mLeaderRole;
err = encoder.Encode(leaderRole);
}
break;
case Attributes::AttachAttemptCount::Id: {
uint16_t attachAttempts = otThreadGetMleCounters(otInst)->mAttachAttempts;
err = encoder.Encode(attachAttempts);
}
break;
case Attributes::PartitionIdChangeCount::Id: {
uint16_t partitionIdChanges = otThreadGetMleCounters(otInst)->mPartitionIdChanges;
err = encoder.Encode(partitionIdChanges);
}
break;
case Attributes::BetterPartitionAttachAttemptCount::Id: {
uint16_t betterPartitionAttachAttempts = otThreadGetMleCounters(otInst)->mBetterPartitionAttachAttempts;
err = encoder.Encode(betterPartitionAttachAttempts);
}
break;
case Attributes::ParentChangeCount::Id: {
uint16_t parentChanges = otThreadGetMleCounters(otInst)->mParentChanges;
err = encoder.Encode(parentChanges);
}
break;
case Attributes::TxTotalCount::Id: {
uint32_t txTotal = otLinkGetCounters(otInst)->mTxTotal;
err = encoder.Encode(txTotal);
}
break;
case Attributes::TxUnicastCount::Id: {
uint32_t txUnicast = otLinkGetCounters(otInst)->mTxUnicast;
err = encoder.Encode(txUnicast);
}
break;
case Attributes::TxBroadcastCount::Id: {
uint32_t txBroadcast = otLinkGetCounters(otInst)->mTxBroadcast;
err = encoder.Encode(txBroadcast);
}
break;
case Attributes::TxAckRequestedCount::Id: {
uint32_t txAckRequested = otLinkGetCounters(otInst)->mTxAckRequested;
err = encoder.Encode(txAckRequested);
}
break;
case Attributes::TxAckedCount::Id: {
uint32_t txAcked = otLinkGetCounters(otInst)->mTxAcked;
err = encoder.Encode(txAcked);
}
break;
case Attributes::TxNoAckRequestedCount::Id: {
uint32_t txNoAckRequested = otLinkGetCounters(otInst)->mTxNoAckRequested;
err = encoder.Encode(txNoAckRequested);
}
break;
case Attributes::TxDataCount::Id: {
uint32_t txData = otLinkGetCounters(otInst)->mTxData;
err = encoder.Encode(txData);
}
break;
case Attributes::TxDataPollCount::Id: {
uint32_t txDataPoll = otLinkGetCounters(otInst)->mTxDataPoll;
err = encoder.Encode(txDataPoll);
}
break;
case Attributes::TxBeaconCount::Id: {
uint32_t txBeacon = otLinkGetCounters(otInst)->mTxBeacon;
err = encoder.Encode(txBeacon);
}
break;
case Attributes::TxBeaconRequestCount::Id: {
uint32_t txBeaconRequest = otLinkGetCounters(otInst)->mTxBeaconRequest;
err = encoder.Encode(txBeaconRequest);
}
break;
case Attributes::TxOtherCount::Id: {
uint32_t txOther = otLinkGetCounters(otInst)->mTxOther;
err = encoder.Encode(txOther);
}
break;
case Attributes::TxRetryCount::Id: {
uint32_t txRetry = otLinkGetCounters(otInst)->mTxRetry;
err = encoder.Encode(txRetry);
}
break;
case Attributes::TxDirectMaxRetryExpiryCount::Id: {
uint32_t txDirectMaxRetryExpiry = otLinkGetCounters(otInst)->mTxDirectMaxRetryExpiry;
err = encoder.Encode(txDirectMaxRetryExpiry);
}
break;
case Attributes::TxIndirectMaxRetryExpiryCount::Id: {
uint32_t txIndirectMaxRetryExpiry = otLinkGetCounters(otInst)->mTxIndirectMaxRetryExpiry;
err = encoder.Encode(txIndirectMaxRetryExpiry);
}
break;
case Attributes::TxErrCcaCount::Id: {
uint32_t txErrCca = otLinkGetCounters(otInst)->mTxErrCca;
err = encoder.Encode(txErrCca);
}
break;
case Attributes::TxErrAbortCount::Id: {
uint32_t TxErrAbort = otLinkGetCounters(otInst)->mTxErrAbort;
err = encoder.Encode(TxErrAbort);
}
break;
case Attributes::TxErrBusyChannelCount::Id: {
uint32_t TxErrBusyChannel = otLinkGetCounters(otInst)->mTxErrBusyChannel;
err = encoder.Encode(TxErrBusyChannel);
}
break;
case Attributes::RxTotalCount::Id: {
uint32_t rxTotal = otLinkGetCounters(otInst)->mRxTotal;
err = encoder.Encode(rxTotal);
}
break;
case Attributes::RxUnicastCount::Id: {
uint32_t rxUnicast = otLinkGetCounters(otInst)->mRxUnicast;
err = encoder.Encode(rxUnicast);
}
break;
case Attributes::RxBroadcastCount::Id: {
uint32_t rxBroadcast = otLinkGetCounters(otInst)->mRxBroadcast;
err = encoder.Encode(rxBroadcast);
}
break;
case Attributes::RxDataCount::Id: {
uint32_t rxData = otLinkGetCounters(otInst)->mRxData;
err = encoder.Encode(rxData);
}
break;
case Attributes::RxDataPollCount::Id: {
uint32_t rxDataPoll = otLinkGetCounters(otInst)->mRxDataPoll;
err = encoder.Encode(rxDataPoll);
}
break;
case Attributes::RxBeaconCount::Id: {
uint32_t rxBeacon = otLinkGetCounters(otInst)->mRxBeacon;
err = encoder.Encode(rxBeacon);
}
break;
case Attributes::RxBeaconRequestCount::Id: {
uint32_t rxBeaconRequest = otLinkGetCounters(otInst)->mRxBeaconRequest;
err = encoder.Encode(rxBeaconRequest);
}
break;
case Attributes::RxOtherCount::Id: {
uint32_t rxOther = otLinkGetCounters(otInst)->mRxOther;
err = encoder.Encode(rxOther);
}
break;
case Attributes::RxAddressFilteredCount::Id: {
uint32_t rxAddressFiltered = otLinkGetCounters(otInst)->mRxAddressFiltered;
err = encoder.Encode(rxAddressFiltered);
}
break;
case Attributes::RxDestAddrFilteredCount::Id: {
uint32_t rxDestAddrFiltered = otLinkGetCounters(otInst)->mRxDestAddrFiltered;
err = encoder.Encode(rxDestAddrFiltered);
}
break;
case Attributes::RxDuplicatedCount::Id: {
uint32_t rxDuplicated = otLinkGetCounters(otInst)->mRxDuplicated;
err = encoder.Encode(rxDuplicated);
}
break;
case Attributes::RxErrNoFrameCount::Id: {
uint32_t rxErrNoFrame = otLinkGetCounters(otInst)->mRxErrNoFrame;
err = encoder.Encode(rxErrNoFrame);
}
break;
case Attributes::RxErrUnknownNeighborCount::Id: {
uint32_t rxErrUnknownNeighbor = otLinkGetCounters(otInst)->mRxErrUnknownNeighbor;
err = encoder.Encode(rxErrUnknownNeighbor);
}
break;
case Attributes::RxErrInvalidSrcAddrCount::Id: {
uint32_t rxErrInvalidSrcAddr = otLinkGetCounters(otInst)->mRxErrInvalidSrcAddr;
err = encoder.Encode(rxErrInvalidSrcAddr);
}
break;
case Attributes::RxErrSecCount::Id: {
uint32_t rxErrSec = otLinkGetCounters(otInst)->mRxErrSec;
err = encoder.Encode(rxErrSec);
}
break;
case Attributes::RxErrFcsCount::Id: {
uint32_t rxErrFcs = otLinkGetCounters(otInst)->mRxErrFcs;
err = encoder.Encode(rxErrFcs);
}
break;
case Attributes::RxErrOtherCount::Id: {
uint32_t rxErrOther = otLinkGetCounters(otInst)->mRxErrOther;
err = encoder.Encode(rxErrOther);
}
break;
case Attributes::ActiveTimestamp::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
uint64_t activeTimestamp = (activeDataset.mActiveTimestamp.mSeconds << 16) | (activeDataset.mActiveTimestamp.mTicks << 1) |
activeDataset.mActiveTimestamp.mAuthoritative;
err = encoder.Encode(activeTimestamp);
}
break;
case Attributes::PendingTimestamp::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
uint64_t pendingTimestamp = (activeDataset.mPendingTimestamp.mSeconds << 16) |
(activeDataset.mPendingTimestamp.mTicks << 1) | activeDataset.mPendingTimestamp.mAuthoritative;
err = encoder.Encode(pendingTimestamp);
}
break;
case Attributes::Delay::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
uint32_t delay = activeDataset.mDelay;
err = encoder.Encode(delay);
}
break;
case Attributes::SecurityPolicy::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
Structs::SecurityPolicy::Type securityPolicy;
static_assert(sizeof(securityPolicy) == sizeof(activeDataset.mSecurityPolicy),
"securityPolicy Struct do not match otSecurityPolicy");
uint16_t policyAsInts[2];
static_assert(sizeof(policyAsInts) == sizeof(activeDataset.mSecurityPolicy),
"We're missing some members of otSecurityPolicy?");
memcpy(&policyAsInts, &activeDataset.mSecurityPolicy, sizeof(policyAsInts));
securityPolicy.rotationTime = policyAsInts[0];
securityPolicy.flags = policyAsInts[1];
err = encoder.Encode(securityPolicy);
}
break;
case Attributes::ChannelPage0Mask::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
// In the resultant Octet string, the most significant bit of the left-most byte indicates channel 0
// We have to bitswap the entire uint32_t before converting to octet string
uint32_t bitSwappedChannelMask = 0;
for (int i = 0, j = 31; i < 32; i++, j--)
{
bitSwappedChannelMask |= ((activeDataset.mChannelMask >> j) & 1) << i;
}
uint8_t buffer[sizeof(uint32_t)] = { 0 };
Encoding::BigEndian::Put32(buffer, bitSwappedChannelMask);
err = encoder.Encode(ByteSpan(buffer));
}
break;
case Attributes::OperationalDatasetComponents::Id: {
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(otInst, &activeDataset);
VerifyOrReturnError(otErr == OT_ERROR_NONE, Internal::MapOpenThreadError(otErr));
Structs::OperationalDatasetComponents::Type OpDatasetComponents;
OpDatasetComponents.activeTimestampPresent = activeDataset.mComponents.mIsActiveTimestampPresent;
OpDatasetComponents.pendingTimestampPresent = activeDataset.mComponents.mIsPendingTimestampPresent;
OpDatasetComponents.masterKeyPresent = activeDataset.mComponents.mIsNetworkKeyPresent;
OpDatasetComponents.networkNamePresent = activeDataset.mComponents.mIsNetworkNamePresent;
OpDatasetComponents.extendedPanIdPresent = activeDataset.mComponents.mIsExtendedPanIdPresent;
OpDatasetComponents.meshLocalPrefixPresent = activeDataset.mComponents.mIsMeshLocalPrefixPresent;
OpDatasetComponents.delayPresent = activeDataset.mComponents.mIsDelayPresent;
OpDatasetComponents.panIdPresent = activeDataset.mComponents.mIsPanIdPresent;
OpDatasetComponents.channelPresent = activeDataset.mComponents.mIsChannelPresent;
OpDatasetComponents.pskcPresent = activeDataset.mComponents.mIsPskcPresent;
OpDatasetComponents.securityPolicyPresent = activeDataset.mComponents.mIsSecurityPolicyPresent;
OpDatasetComponents.channelMaskPresent = activeDataset.mComponents.mIsChannelMaskPresent;
err = encoder.Encode(OpDatasetComponents);
}
break;
case Attributes::ActiveNetworkFaultsList::Id: {
// activeNetworkFaults are not tracked by the thread stack nor the ThreadStackManager.
// Encode an emptyList to indicate there are currently no active faults.
err = encoder.EncodeEmptyList();
}
break;
default: {
err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
break;
}
#elif (CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK)
switch (attributeId)
{
case Attributes::NeighborTable::Id:
case Attributes::RouteTable::Id:
case Attributes::ActiveNetworkFaultsList::Id:
err = encoder.EncodeEmptyList();
break;
case Attributes::Channel::Id:
case Attributes::RoutingRole::Id:
case Attributes::NetworkName::Id:
case Attributes::PanId::Id:
case Attributes::ExtendedPanId::Id:
case Attributes::MeshLocalPrefix::Id:
case Attributes::PartitionId::Id:
case Attributes::Weighting::Id:
case Attributes::DataVersion::Id:
case Attributes::StableDataVersion::Id:
case Attributes::LeaderRouterId::Id:
case Attributes::ActiveTimestamp::Id:
case Attributes::PendingTimestamp::Id:
case Attributes::Delay::Id:
case Attributes::ChannelPage0Mask::Id:
case Attributes::SecurityPolicy::Id:
case Attributes::OperationalDatasetComponents::Id:
err = encoder.EncodeNull();
break;
case Attributes::OverrunCount::Id:
err = encoder.Encode(static_cast<uint64_t>(0));
break;
case Attributes::DetachedRoleCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::ChildRoleCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::RouterRoleCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::LeaderRoleCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::AttachAttemptCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::PartitionIdChangeCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::BetterPartitionAttachAttemptCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::ParentChangeCount::Id:
err = encoder.Encode(static_cast<uint16_t>(0));
break;
case Attributes::TxTotalCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxUnicastCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxBroadcastCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxAckRequestedCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxAckedCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxNoAckRequestedCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxDataCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxDataPollCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxBeaconCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxBeaconRequestCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxOtherCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxRetryCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxDirectMaxRetryExpiryCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxIndirectMaxRetryExpiryCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxErrCcaCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxErrAbortCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::TxErrBusyChannelCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxTotalCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxUnicastCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxBroadcastCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxDataCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxDataPollCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxBeaconCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxBeaconRequestCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxOtherCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxAddressFilteredCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxDestAddrFilteredCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxDuplicatedCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrNoFrameCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrUnknownNeighborCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrInvalidSrcAddrCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrSecCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrFcsCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
case Attributes::RxErrOtherCount::Id:
err = encoder.Encode(static_cast<uint32_t>(0));
break;
default:
err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
break;
}
#else
err = CHIP_ERROR_NOT_IMPLEMENTED;
#endif // (CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_USES_OTBR_POSIX_DBUS_STACK)
return err;
}
} // namespace ThreadNetworkDiagnostics
} // namespace Clusters
} // namespace app
} // namespace chip