0.01.00
leader.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 
34 #ifndef MESHCOP_LEADER_HPP_
35 #define MESHCOP_LEADER_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include "coap/coap.hpp"
40 #include "common/locator.hpp"
41 #include "common/timer.hpp"
42 #include "meshcop/meshcop_tlvs.hpp"
43 #include "net/udp6.hpp"
44 #include "thread/mle.hpp"
45 
46 namespace ot {
47 namespace MeshCoP {
48 
51 {
52 public:
53  uint8_t GetLength(void) const {
54  return sizeof(Tlv) + mBorderAgentLocator.GetLength() +
55  sizeof(Tlv) + mCommissionerSessionId.GetLength() +
56  sizeof(Tlv) + mSteeringData.GetLength();
57  }
58 
59  BorderAgentLocatorTlv mBorderAgentLocator;
60  CommissionerSessionIdTlv mCommissionerSessionId;
61  SteeringDataTlv mSteeringData;
63 
64 class Leader: public InstanceLocator
65 {
66 public:
73  Leader(otInstance &aInstance);
74 
84  otError SendDatasetChanged(const Ip6::Address &aAddress);
85 
95  otError SetDelayTimerMinimal(uint32_t aDelayTimerMinimal);
96 
103  uint32_t GetDelayTimerMinimal(void) const;
104 
109  void SetEmptyCommissionerData(void);
110 
111 private:
112  enum
113  {
114  kTimeoutLeaderPetition = 50,
115  };
116 
117  static void HandleTimer(Timer &aTimer);
118  void HandleTimer(void);
119 
120  static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
121  const otMessageInfo *aMessageInfo);
122  void HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
123  otError SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
124  StateTlv::State aState);
125 
126  static void HandleKeepAlive(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
127  const otMessageInfo *aMessageInfo);
128  void HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
129  otError SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
130  StateTlv::State aState);
131 
132  static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
133 
134  void ResignCommissioner(void);
135 
136  static Leader &GetOwner(const Context &aContext);
137 
138  Coap::Resource mPetition;
139  Coap::Resource mKeepAlive;
140  TimerMilli mTimer;
141 
142  uint32_t mDelayTimerMinimal;
143 
144  CommissionerIdTlv mCommissionerId;
145  uint16_t mSessionId;
146 };
147 
148 } // namespace MeshCoP
149 } // namespace ot
150 
151 #endif // MESHCOP_LEADER_HPP_
This type represents all the static / global variables used by OpenThread allocated in one place...
Definition: openthread-instance.h:59
This class implements Border Agent Locator TLV generation and parsing.
Definition: meshcop_tlvs.hpp:662
Definition: cli.cpp:90
This file includes definitions for MLE functionality required by the Thread Child, Router, and Leader roles.
This class implements CoAP resource handling.
Definition: coap.hpp:200
This class implements an IPv6 address object.
Definition: ip6_address.hpp:60
State
State values.
Definition: meshcop_tlvs.hpp:915
This file includes definitions for CoAP client and server functionality.
This file includes definitions for locator class for OpenThread objects.
Definition: leader.hpp:50
This class implements message information for an IPv6 message.
Definition: socket.hpp:57
This type points to an OpenThread message buffer.
Definition: types.h:479
This class implements CoAP header generation and parsing.
Definition: coap_header.hpp:72
#define OT_TOOL_PACKED_BEGIN
Compiler-specific indication that a class or struct must be byte packed.
Definition: toolchain.h:170
This class implements a timer.
Definition: timer.hpp:69
This class implements the millisecond timer.
Definition: timer.hpp:145
This file includes definitions for generating and processing MeshCoP TLVs.
This file includes definitions for UDP/IPv6 sockets.
This class implements definitions for maintaining a pointer to arbitrary context information.
Definition: context.hpp:61
This class represents a message.
Definition: message.hpp:195
This class implements the Commissioner ID TLV generation and parsing.
Definition: meshcop_tlvs.hpp:705
Definition: leader.hpp:64
This class implements locator for otInstance object.
Definition: locator.hpp:63
This file includes definitions for the multiplexed timer service.
This structure represents a CoAP header.
Definition: coap.h:172
#define OT_TOOL_PACKED_END
Compiler-specific indication at the end of a byte packed class or struct.
Definition: toolchain.h:172
This structure represents the local and peer IPv6 socket addresses.
Definition: types.h:436
This class implements MeshCoP TLV generation and parsing.
Definition: meshcop_tlvs.hpp:62
This class implements Steering Data TLV generation and parsing.
Definition: meshcop_tlvs.hpp:551
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
uint8_t GetLength(void) const
This method returns the Length value.
Definition: tlvs.hpp:89
This file includes compile-time configuration constants for OpenThread.
This class implements Commissioner Session ID TLV generation and parsing.
Definition: meshcop_tlvs.hpp:757