• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2024, 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 #include "nexus_node.hpp"
30 #include "nexus_utils.hpp"
31 
32 namespace ot {
33 namespace Nexus {
34 
Form(void)35 void Node::Form(void)
36 {
37     MeshCoP::Dataset::Info datasetInfo;
38 
39     SuccessOrQuit(datasetInfo.GenerateRandom(*this));
40     Get<MeshCoP::ActiveDatasetManager>().SaveLocal(datasetInfo);
41 
42     Get<ThreadNetif>().Up();
43     SuccessOrQuit(Get<Mle::MleRouter>().Start());
44 }
45 
Join(Node & aNode,JoinMode aJoinMode)46 void Node::Join(Node &aNode, JoinMode aJoinMode)
47 {
48     MeshCoP::Dataset dataset;
49     Mle::DeviceMode  mode(0);
50 
51     switch (aJoinMode)
52     {
53     case kAsFed:
54         SuccessOrQuit(Get<Mle::MleRouter>().SetRouterEligible(false));
55         OT_FALL_THROUGH;
56 
57     case kAsFtd:
58         mode.Set(Mle::DeviceMode::kModeRxOnWhenIdle | Mle::DeviceMode::kModeFullThreadDevice |
59                  Mle::DeviceMode::kModeFullNetworkData);
60         break;
61     case kAsMed:
62         mode.Set(Mle::DeviceMode::kModeRxOnWhenIdle | Mle::DeviceMode::kModeFullNetworkData);
63         break;
64     case kAsSed:
65         mode.Set(Mle::DeviceMode::kModeFullNetworkData);
66         break;
67     }
68 
69     SuccessOrQuit(Get<Mle::Mle>().SetDeviceMode(mode));
70 
71     SuccessOrQuit(aNode.Get<MeshCoP::ActiveDatasetManager>().Read(dataset));
72     Get<MeshCoP::ActiveDatasetManager>().SaveLocal(dataset);
73 
74     Get<ThreadNetif>().Up();
75     SuccessOrQuit(Get<Mle::MleRouter>().Start());
76 }
77 
AllowList(Node & aNode)78 void Node::AllowList(Node &aNode)
79 {
80     SuccessOrQuit(Get<Mac::Filter>().AddAddress(aNode.Get<Mac::Mac>().GetExtAddress()));
81     Get<Mac::Filter>().SetMode(Mac::Filter::kModeAllowlist);
82 }
83 
UnallowList(Node & aNode)84 void Node::UnallowList(Node &aNode) { Get<Mac::Filter>().RemoveAddress(aNode.Get<Mac::Mac>().GetExtAddress()); }
85 
86 } // namespace Nexus
87 } // namespace ot
88