0.01.00
dataset.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
35 #ifndef MESHCOP_DATASET_HPP_
36 #define MESHCOP_DATASET_HPP_
37 
38 #include "openthread-core-config.h"
39 
40 #include "common/locator.hpp"
41 #include "common/message.hpp"
42 #include "meshcop/meshcop_tlvs.hpp"
43 
44 namespace ot {
45 namespace MeshCoP {
46 
47 class Dataset
48 {
49  friend class DatasetLocal;
50 
51 public:
52  enum
53  {
54  kMaxSize = 256,
55  kMaxValueSize = 16,
56  };
57 
64  Dataset(const Tlv::Type aType);
65 
70  void Clear(void);
71 
78  Tlv *Get(Tlv::Type aType);
79 
86  const Tlv *Get(Tlv::Type aType) const;
87 
94  const uint8_t *GetBytes(void) const { return mTlvs; }
95 
100  void Get(otOperationalDataset &aDataset) const;
101 
108  uint16_t GetSize(void) const { return mLength; }
109 
116  uint32_t GetUpdateTime(void) const { return mUpdateTime; }
117 
124  const Timestamp *GetTimestamp(void) const;
125 
130  void SetTimestamp(const Timestamp &aTimestamp);
131 
141  otError Set(const Tlv &aTlv);
142 
154  otError Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength);
155 
167  otError Set(const Dataset &aDataset);
168 
169 #if OPENTHREAD_FTD
170 
178  otError Set(const otOperationalDataset &aDataset);
179 #endif
180 
187  void Remove(Tlv::Type aType);
188 
196  otError AppendMleDatasetTlv(Message &aMessage) const;
197 
198 private:
199  uint16_t GetSettingsKey(void);
200 
201  void Remove(uint8_t *aStart, uint8_t aLength);
202 
203  uint8_t mTlvs[kMaxSize];
204  uint32_t mUpdateTime;
205  uint16_t mLength;
206  Tlv::Type mType;
207 };
208 
209 } // namespace MeshCoP
210 } // namespace ot
211 
212 #endif // MESHCOP_DATASET_HPP_
Definition: cli.cpp:90
Dataset(const Tlv::Type aType)
This constructor initializes the object.
Definition: dataset.cpp:48
This file includes definitions for locator class for OpenThread objects.
const Timestamp * GetTimestamp(void) const
This method returns a reference to the Timestamp.
Definition: dataset.cpp:367
void Remove(Tlv::Type aType)
This method removes a TLV from the Dataset.
Definition: dataset.cpp:448
otError Set(const Tlv &aTlv)
This method sets a TLV in the Dataset.
Definition: dataset.cpp:406
Maximum size of MeshCoP Dataset (bytes)
Definition: dataset.hpp:54
This file includes definitions for generating and processing MeshCoP TLVs.
This class represents a message.
Definition: message.hpp:195
uint32_t GetUpdateTime(void) const
This method returns the local time the dataset was last updated.
Definition: dataset.hpp:116
const uint8_t * GetBytes(void) const
This method returns a pointer to the byte representation of the Dataset.
Definition: dataset.hpp:94
uint16_t GetSize(void) const
This method returns the Dataset size in bytes.
Definition: dataset.hpp:108
otError AppendMleDatasetTlv(Message &aMessage) const
This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
Definition: dataset.cpp:459
This file includes definitions for the message buffer pool and message buffers.
void Clear(void)
This method clears the Dataset.
Definition: dataset.cpp:56
Definition: dataset_local.hpp:47
This class implements MeshCoP TLV generation and parsing.
Definition: meshcop_tlvs.hpp:62
void SetTimestamp(const Timestamp &aTimestamp)
This method sets the Timestamp value.
Definition: dataset.cpp:388
Tlv * Get(Tlv::Type aType)
This method returns a pointer to the TLV.
Definition: dataset.cpp:61
This class implements Timestamp generation and parsing.
Definition: timestamp.hpp:56
This structure represents an Active or Pending Operational Dataset.
Definition: types.h:552
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
This file includes compile-time configuration constants for OpenThread.
Type
MeshCoP TLV Types.
Definition: meshcop_tlvs.hpp:69
Definition: dataset.hpp:47