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