• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2022, 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 
29 /**
30  * @file
31  *   This file includes definitions for managing the Extended PAN ID.
32  */
33 
34 #ifndef MESHCOP_EXTENDED_PANID_HPP_
35 #define MESHCOP_EXTENDED_PANID_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <openthread/dataset.h>
40 
41 #include "common/as_core_type.hpp"
42 #include "common/clearable.hpp"
43 #include "common/equatable.hpp"
44 #include "common/locator.hpp"
45 #include "common/non_copyable.hpp"
46 #include "common/string.hpp"
47 
48 namespace ot {
49 namespace MeshCoP {
50 
51 /**
52  * Represents an Extended PAN Identifier.
53  */
54 OT_TOOL_PACKED_BEGIN
55 class ExtendedPanId : public otExtendedPanId, public Equatable<ExtendedPanId>, public Clearable<ExtendedPanId>
56 {
57 public:
58     static constexpr uint16_t kInfoStringSize = 17; ///< Max chars for the info string (`ToString()`).
59 
60     /**
61      * Defines the fixed-length `String` object returned from `ToString()`.
62      */
63     typedef String<kInfoStringSize> InfoString;
64 
65     /**
66      * Converts an address to a string.
67      *
68      * @returns An `InfoString` containing the string representation of the Extended PAN Identifier.
69      */
70     InfoString ToString(void) const;
71 
72 } OT_TOOL_PACKED_END;
73 
74 class ExtendedPanIdManager : public InstanceLocator, private NonCopyable
75 {
76 public:
77     /**
78      * Constructor.
79      *
80      * @param[in]  aInstance  A reference to the OpenThread instance.
81      */
82     explicit ExtendedPanIdManager(Instance &aInstance);
83 
84     /**
85      * Returns the Extended PAN Identifier.
86      *
87      * @returns The Extended PAN Identifier.
88      */
GetExtPanId(void) const89     const ExtendedPanId &GetExtPanId(void) const { return mExtendedPanId; }
90 
91     /**
92      * Sets the Extended PAN Identifier.
93      *
94      * @param[in]  aExtendedPanId  The Extended PAN Identifier.
95      */
96     void SetExtPanId(const ExtendedPanId &aExtendedPanId);
97 
98 private:
99     static const otExtendedPanId sExtendedPanidInit;
100 
101     ExtendedPanId mExtendedPanId;
102 };
103 
104 } // namespace MeshCoP
105 
106 DefineCoreType(otExtendedPanId, MeshCoP::ExtendedPanId);
107 
108 } // namespace ot
109 
110 #endif // MESHCOP_EXTENDED_PANID_HPP_
111