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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for non-volatile storage of settings.
*/
#ifndef SETTINGS_HPP_
#define SETTINGS_HPP_
#include "openthread-core-config.h"
#include "common/encoding.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "mac/mac_types.hpp"
#include "utils/flash.hpp"
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
#include "utils/slaac_address.hpp"
#endif
namespace ot {
namespace MeshCoP {
class Dataset;
}
class SettingsDriver : public InstanceLocator, private NonCopyable
{
public:
/**
* Constructor.
*/
explicit SettingsDriver(Instance &aInstance);
/**
* This method initializes the settings storage driver.
*
*/
void Init(void);
/**
* This method deinitializes the settings driver.
*
*/
void Deinit(void);
/**
* This method adds a value to @p aKey.
*
* @param[in] aKey The key associated with the value.
* @param[in] aValue A pointer to where the new value of the setting should be read from.
* MUST NOT be NULL if @p aValueLength is non-zero.
* @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero.
*
* @retval OT_ERROR_NONE The value was added.
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
*
*/
otError Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
/**
* This method removes a value from @p aKey.
*
* @param[in] aKey The key associated with the value.
* @param[in] aIndex The index of the value to be removed.
* If set to -1, all values for @p aKey will be removed.
*
* @retval OT_ERROR_NONE The given key and index was found and removed successfully.
* @retval OT_ERROR_NOT_FOUND The given key or index was not found.
*
*/
otError Delete(uint16_t aKey, int aIndex);
/**
* This method fetches the value identified by @p aKey.
*
* @param[in] aKey The key associated with the requested value.
* @param[in] aIndex The index of the specific item to get.
* @param[out] aValue A pointer to where the value of the setting should be written.
* May be NULL if just testing for the presence or length of a key.
* @param[inout] aValueLength A pointer to the length of the value.
* When called, this should point to an integer containing the maximum bytes that
* can be written to @p aValue.
* At return, the actual length of the setting is written.
* May be NULL if performing a presence check.
*
* @retval OT_ERROR_NONE The value was fetched successfully.
* @retval OT_ERROR_NOT_FOUND The key was not found.
*
*/
otError Get(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) const;
/**
* This method sets or replaces the value identified by @p aKey.
*
* If there was more than one value previously associated with @p aKey, then they are all deleted and replaced with
* this single entry.
*
* @param[in] aKey The key associated with the value.
* @param[in] aValue A pointer to where the new value of the setting should be read from.
* MUST NOT be NULL if @p aValueLength is non-zero.
* @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero.
*
* @retval OT_ERROR_NONE The value was changed.
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
*
*/
otError Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
/**
* This method remves all values.
*
*/
void Wipe(void);
#if OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE
private:
Flash mFlash;
#endif
};
/**
* This class defines the base class used by `Settings` and `Settings::ChildInfoIterator`.
*
* This class provides structure definitions for different settings keys.
*
*/
class SettingsBase : public InstanceLocator, private NonCopyable
{
public:
/**
* Rules for updating existing value structures.
*
* 1. Modifying existing key value fields in settings MUST only be
* done by appending new fields. Existing fields MUST NOT be
* deleted or modified in any way.
*
* 2. To support backward compatibility (rolling back to an older
* software version), code reading and processing key values MUST
* process key values that have longer length. Additionally, newer
* versions MUST update/maintain values in existing key value
* fields.
*
* 3. To support forward compatibility (rolling forward to a newer
* software version), code reading and processing key values MUST
* process key values that have shorter length.
*
* 4. New Key IDs may be defined in the future with the understanding
* that such key values are not backward compatible.
*
*/
/**
* This structure represents the device's own network information for settings storage.
*
*/
OT_TOOL_PACKED_BEGIN
class NetworkInfo
{
public:
/**
* This method clears the struct object (setting all the fields to zero).
*
*/
void Init(void)
{
memset(this, 0, sizeof(*this));
SetVersion(OT_THREAD_VERSION_1_1);
}
/**
* This method returns the Thread role.
*
* @returns The Thread role.
*
*/
uint8_t GetRole(void) const { return mRole; }
/**
* This method sets the Thread role.
*
* @param[in] aRole The Thread Role.
*
*/
void SetRole(uint8_t aRole) { mRole = aRole; }
/**
* This method returns the Thread device mode.
*
* @returns the Thread device mode.
*
*/
uint8_t GetDeviceMode(void) const { return mDeviceMode; }
/**
* This method sets the Thread device mode.
*
* @param[in] aDeviceMode The Thread device mode.
*
*/
void SetDeviceMode(uint8_t aDeviceMode) { mDeviceMode = aDeviceMode; }
/**
* This method returns the RLOC16.
*
* @returns The RLOC16.
*
*/
uint16_t GetRloc16(void) const { return Encoding::LittleEndian::HostSwap16(mRloc16); }
/**
* This method sets the RLOC16.
*
* @param[in] aRloc16 The RLOC16.
*
*/
void SetRloc16(uint16_t aRloc16) { mRloc16 = Encoding::LittleEndian::HostSwap16(aRloc16); }
/**
* This method returns the key sequence.
*
* @returns The key sequence.
*
*/
uint32_t GetKeySequence(void) const { return Encoding::LittleEndian::HostSwap32(mKeySequence); }
/**
* This method sets the key sequence.
*
* @param[in] aKeySequence The key sequence.
*
*/
void SetKeySequence(uint32_t aKeySequence) { mKeySequence = Encoding::LittleEndian::HostSwap32(aKeySequence); }
/**
* This method returns the MLE frame counter.
*
* @returns The MLE frame counter.
*
*/
uint32_t GetMleFrameCounter(void) const { return Encoding::LittleEndian::HostSwap32(mMleFrameCounter); }
/**
* This method sets the MLE frame counter.
*
* @param[in] aMleFrameCounter The MLE frame counter.
*
*/
void SetMleFrameCounter(uint32_t aMleFrameCounter)
{
mMleFrameCounter = Encoding::LittleEndian::HostSwap32(aMleFrameCounter);
}
/**
* This method returns the MAC frame counter.
*
* @returns The MAC frame counter.
*
*/
uint32_t GetMacFrameCounter(void) const { return Encoding::LittleEndian::HostSwap32(mMacFrameCounter); }
/**
* This method sets the MAC frame counter.
*
* @param[in] aMacFrameCounter The MAC frame counter.
*
*/
void SetMacFrameCounter(uint32_t aMacFrameCounter)
{
mMacFrameCounter = Encoding::LittleEndian::HostSwap32(aMacFrameCounter);
}
/**
* This method returns the previous partition ID.
*
* @returns The previous partition ID.
*
*/
uint32_t GetPreviousPartitionId(void) const { return Encoding::LittleEndian::HostSwap32(mPreviousPartitionId); }
/**
* This method sets the previous partition id.
*
* @param[in] aPreviousPartitionId The previous partition ID.
*
*/
void SetPreviousPartitionId(uint32_t aPreviousPartitionId)
{
mPreviousPartitionId = Encoding::LittleEndian::HostSwap32(aPreviousPartitionId);
}
/**
* This method returns the extended address.
*
* @returns The extended address.
*
*/
const Mac::ExtAddress &GetExtAddress(void) const { return mExtAddress; }
/**
* This method sets the extended address.
*
* @param[in] aExtAddress The extended address.
*
*/
void SetExtAddress(const Mac::ExtAddress &aExtAddress) { mExtAddress = aExtAddress; }
/**
* This method returns the Mesh Local Interface Identifier.
*
* @returns The Mesh Local Interface Identifier.
*
*/
const uint8_t *GetMeshLocalIid(void) const { return mMlIid; }
/**
* This method sets the Mesh Local Interface Identifier.
*
* @param[in] aMeshLocalIid The Mesh Local Interface Identifier.
*
*/
void SetMeshLocalIid(const uint8_t *aMeshLocalIid) { memcpy(mMlIid, aMeshLocalIid, sizeof(mMlIid)); }
/**
* This method returns the Thread version.
*
* @returns The Thread version.
*
*/
uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); }
/**
* This method sets the Thread version.
*
* @param[in] aVersion The Thread version.
*
*/
void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); }
private:
uint8_t mRole; ///< Current Thread role.
uint8_t mDeviceMode; ///< Device mode setting.
uint16_t mRloc16; ///< RLOC16
uint32_t mKeySequence; ///< Key Sequence
uint32_t mMleFrameCounter; ///< MLE Frame Counter
uint32_t mMacFrameCounter; ///< MAC Frame Counter
uint32_t mPreviousPartitionId; ///< PartitionId
Mac::ExtAddress mExtAddress; ///< Extended Address
uint8_t mMlIid[OT_IP6_IID_SIZE]; ///< IID from ML-EID
uint16_t mVersion; ///< Version
} OT_TOOL_PACKED_END;
/**
* This structure represents the parent information for settings storage.
*
*/
OT_TOOL_PACKED_BEGIN
class ParentInfo
{
public:
/**
* This method clears the struct object (setting all the fields to zero).
*
*/
void Init(void)
{
memset(this, 0, sizeof(*this));
SetVersion(OT_THREAD_VERSION_1_1);
}
/**
* This method returns the extended address.
*
* @returns The extended address.
*
*/
const Mac::ExtAddress &GetExtAddress(void) const { return mExtAddress; }
/**
* This method sets the extended address.
*
* @param[in] aExtAddress The extended address.
*
*/
void SetExtAddress(const Mac::ExtAddress &aExtAddress) { mExtAddress = aExtAddress; }
/**
* This method returns the Thread version.
*
* @returns The Thread version.
*
*/
uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); }
/**
* This method sets the Thread version.
*
* @param[in] aVersion The Thread version.
*
*/
void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); }
private:
Mac::ExtAddress mExtAddress; ///< Extended Address
uint16_t mVersion; ///< Version
} OT_TOOL_PACKED_END;
/**
* This structure represents the child information for settings storage.
*
*/
OT_TOOL_PACKED_BEGIN
class ChildInfo
{
public:
/**
* This method clears the struct object (setting all the fields to zero).
*
*/
void Init(void)
{
memset(this, 0, sizeof(*this));
SetVersion(OT_THREAD_VERSION_1_1);
}
/**
* This method returns the extended address.
*
* @returns The extended address.
*
*/
const Mac::ExtAddress &GetExtAddress(void) const { return mExtAddress; }
/**
* This method sets the extended address.
*
* @param[in] aExtAddress The extended address.
*
*/
void SetExtAddress(const Mac::ExtAddress &aExtAddress) { mExtAddress = aExtAddress; }
/**
* This method returns the child timeout.
*
* @returns The child timeout.
*
*/
uint32_t GetTimeout(void) const { return Encoding::LittleEndian::HostSwap32(mTimeout); }
/**
* This method sets the child timeout.
*
* @param[in] aTimeout The child timeout.
*
*/
void SetTimeout(uint32_t aTimeout) { mTimeout = Encoding::LittleEndian::HostSwap32(aTimeout); }
/**
* This method returns the RLOC16.
*
* @returns The RLOC16.
*
*/
uint16_t GetRloc16(void) const { return Encoding::LittleEndian::HostSwap16(mRloc16); }
/**
* This method sets the RLOC16.
*
* @param[in] aRloc16 The RLOC16.
*
*/
void SetRloc16(uint16_t aRloc16) { mRloc16 = Encoding::LittleEndian::HostSwap16(aRloc16); }
/**
* This method returns the Thread device mode.
*
* @returns The Thread device mode.
*
*/
uint8_t GetMode(void) const { return mMode; }
/**
* This method sets the Thread device mode.
*
* @param[in] aRloc16 The Thread device mode.
*
*/
void SetMode(uint8_t aMode) { mMode = aMode; }
/**
* This method returns the Thread version.
*
* @returns The Thread version.
*
*/
uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); }
/**
* This method sets the Thread version.
*
* @param[in] aVersion The Thread version.
*
*/
void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); }
private:
Mac::ExtAddress mExtAddress; ///< Extended Address
uint32_t mTimeout; ///< Timeout
uint16_t mRloc16; ///< RLOC16
uint8_t mMode; ///< The MLE device mode
uint16_t mVersion; ///< Version
} OT_TOOL_PACKED_END;
/**
* This enumeration defines the keys of settings.
*
*/
enum Key
{
kKeyActiveDataset = 0x0001, ///< Active Operational Dataset
kKeyPendingDataset = 0x0002, ///< Pending Operational Dataset
kKeyNetworkInfo = 0x0003, ///< Thread network information
kKeyParentInfo = 0x0004, ///< Parent information
kKeyChildInfo = 0x0005, ///< Child information
kKeyReserved = 0x0006, ///< Reserved (previously auto-start)
kKeySlaacIidSecretKey = 0x0007, ///< Secret key used by SLAAC module for generating semantically opaque IID
};
protected:
explicit SettingsBase(Instance &aInstance)
: InstanceLocator(aInstance)
{
}
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_UTIL != 0)
void LogNetworkInfo(const char *aAction, const NetworkInfo &aNetworkInfo) const;
void LogParentInfo(const char *aAction, const ParentInfo &aParentInfo) const;
void LogChildInfo(const char *aAction, const ChildInfo &aChildInfo) const;
#else
void LogNetworkInfo(const char *, const NetworkInfo &) const {}
void LogParentInfo(const char *, const ParentInfo &) const {}
void LogChildInfo(const char *, const ChildInfo &) const {}
#endif
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_WARN) && (OPENTHREAD_CONFIG_LOG_UTIL != 0)
void LogFailure(otError aError, const char *aAction, bool aIsDelete) const;
#else
void LogFailure(otError, const char *, bool) const {}
#endif
};
/**
* This class defines methods related to non-volatile storage of settings.
*
*/
class Settings : public SettingsBase
{
public:
/**
* This constructor initializes a `Settings` object.
*
* @param[in] aInstance A reference to the OpenThread instance.
*
*/
explicit Settings(Instance &aInstance)
: SettingsBase(aInstance)
{
}
/**
* This method initializes the platform settings (non-volatile) module.
*
* This should be called before any other method from this class.
*
*/
void Init(void);
/**
* This method de-initializes the platform settings (non-volatile) module.
*
* This method should be called when OpenThread instance is no longer in use.
*
*/
void Deinit(void);
/**
* This method removes all settings from the non-volatile store.
*
*/
void Wipe(void);
/**
* This method saves the Operational Dataset (active or pending).
*
* @param[in] aIsActive Indicates whether Dataset is active or pending.
* @param[in] aDataset A reference to a `Dataset` object to be saved.
*
* @retval OT_ERROR_NONE Successfully saved the Dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset);
/**
* This method reads the Operational Dataset (active or pending).
*
* @param[in] aIsActive Indicates whether Dataset is active or pending.
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Dataset.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const;
/**
* This method deletes the Operational Dataset (active/pending) from settings.
*
* @param[in] aIsActive Indicates whether Dataset is active or pending.
*
* @retval OT_ERROR_NONE Successfully deleted the Dataset.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError DeleteOperationalDataset(bool aIsActive);
/**
* This method saves Network Info.
*
* @param[in] aNetworkInfo A reference to a `NetworkInfo` structure to be saved.
*
* @retval OT_ERROR_NONE Successfully saved Network Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError SaveNetworkInfo(const NetworkInfo &aNetworkInfo);
/**
* This method reads Network Info.
*
* @param[out] aNetworkInfo A reference to a `NetworkInfo` structure to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Network Info.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError ReadNetworkInfo(NetworkInfo &aNetworkInfo) const;
/**
* This method deletes Network Info from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError DeleteNetworkInfo(void);
/**
* This method saves Parent Info.
*
* @param[in] aParentInfo A reference to a `ParentInfo` structure to be saved.
*
* @retval OT_ERROR_NONE Successfully saved Parent Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError SaveParentInfo(const ParentInfo &aParentInfo);
/**
* This method reads Parent Info.
*
* @param[out] aParentInfo A reference to a `ParentInfo` structure to output the read content.
*
* @retval OT_ERROR_NONE Successfully read the Parent Info.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError ReadParentInfo(ParentInfo &aParentInfo) const;
/**
* This method deletes Parent Info from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError DeleteParentInfo(void);
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
/**
* This method saves the SLAAC IID secret key.
*
* @param[in] aKey The SLAAC IID secret key.
*
* @retval OT_ERROR_NONE Successfully saved the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError SaveSlaacIidSecretKey(const Utils::Slaac::IidSecretKey &aKey)
{
return Save(kKeySlaacIidSecretKey, &aKey, sizeof(Utils::Slaac::IidSecretKey));
}
/**
* This method reads the SLAAC IID secret key.
*
* @param[out] aKey A reference to a SLAAC IID secret key to output the read value.
*
* @retval OT_ERROR_NONE Successfully read the value.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError ReadSlaacIidSecretKey(Utils::Slaac::IidSecretKey &aKey)
{
uint16_t length = sizeof(aKey);
return Read(kKeySlaacIidSecretKey, &aKey, length);
}
/**
* This method deletes the SLAAC IID secret key value from settings.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError DeleteSlaacIidSecretKey(void) { return Delete(kKeySlaacIidSecretKey); }
#endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
/**
* This method adds a Child Info entry to settings.
*
* @note Child Info is a list-based settings property and can contain multiple entries.
*
* @param[in] aChildInfo A reference to a `ChildInfo` structure to be saved/added.
*
* @retval OT_ERROR_NONE Successfully saved the Child Info in settings.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError AddChildInfo(const ChildInfo &aChildInfo);
/**
* This method deletes all Child Info entries from the settings.
*
* @note Child Info is a list-based settings property and can contain multiple entries.
*
* @retval OT_ERROR_NONE Successfully deleted the value.
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError DeleteChildInfo(void);
/**
* This class defines an iterator to access all Child Info entries in the settings.
*
*/
class ChildInfoIterator : public SettingsBase
{
public:
/**
* This constructor initializes a `ChildInfoInterator` object.
*
* @param[in] aInstance A reference to the OpenThread instance.
*
*/
explicit ChildInfoIterator(Instance &aInstance);
/**
* This method resets the iterator to start from the first Child Info entry in the list.
*
*/
void Reset(void);
/**
* This method indicates whether there are no more Child Info entries in the list (iterator has reached end of
* the list), or the current entry is valid.
*
* @retval TRUE There are no more entries in the list (reached end of the list).
* @retval FALSE The current entry is valid.
*
*/
bool IsDone(void) const { return mIsDone; }
/**
* This method advances the iterator to move to the next Child Info entry in the list (if any).
*
*/
void Advance(void);
/**
* This method overloads operator `++` (pre-increment) to advance the iterator to move to the next Child Info
* entry in the list (if any).
*
*/
void operator++(void) { Advance(); }
/**
* This method overloads operator `++` (post-increment) to advance the iterator to move to the next Child Info
* entry in the list (if any).
*
*/
void operator++(int) { Advance(); }
/**
* This method gets the Child Info corresponding to the current iterator entry in the list.
*
* @note This method should be used only if `IsDone()` is returning FALSE indicating that the iterator is
* pointing to a valid entry.
*
* @returns A reference to `ChildInfo` structure corresponding to current iterator entry.
*
*/
const ChildInfo &GetChildInfo(void) const { return mChildInfo; }
/**
* This method deletes the current Child Info entry.
*
* @retval OT_ERROR_NONE The entry was deleted successfully.
* @retval OT_ERROR_INVALID_STATE The entry is not valid (iterator has reached end of list).
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
*
*/
otError Delete(void);
private:
void Read(void);
ChildInfo mChildInfo;
uint16_t mIndex;
bool mIsDone;
};
private:
otError Read(Key aKey, void *aBuffer, uint16_t &aSize) const;
otError Save(Key aKey, const void *aValue, uint16_t aSize);
otError Add(Key aKey, const void *aValue, uint16_t aSize);
otError Delete(Key aKey);
};
} // namespace ot
#endif // SETTINGS_HPP_