0.01.00
joiner.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 JOINER_HPP_
35 #define JOINER_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <openthread/joiner.h>
40 
41 #include "coap/coap.hpp"
42 #include "coap/coap_header.hpp"
43 #include "coap/coap_secure.hpp"
44 #include "common/crc16.hpp"
45 #include "common/locator.hpp"
46 #include "common/message.hpp"
47 #include "meshcop/dtls.hpp"
48 #include "meshcop/meshcop_tlvs.hpp"
49 #include "net/udp6.hpp"
50 
51 namespace ot {
52 
53 class ThreadNetif;
54 
55 namespace MeshCoP {
56 
57 class Joiner: public InstanceLocator
58 {
59 public:
66  Joiner(otInstance &aInstance);
67 
83  otError Start(const char *aPSKd, const char *aProvisioningUrl,
84  const char *aVendorName, const char *aVendorModel,
85  const char *aVendorSwVersion, const char *aVendorData,
86  otJoinerCallback aCallback, void *aContext);
87 
94  otError Stop(void);
95 
107  otJoinerState GetState(void) const;
108 
115  void GetJoinerId(Mac::ExtAddress &aJoinerId) const;
116 
117 private:
118  enum
119  {
120  kConfigExtAddressDelay = 100,
121  kTimeout = 4000,
122  kSpecificPriorityBonus = (1 << 9),
123  };
124 
125  struct JoinerRouter
126  {
127  Mac::ExtAddress mExtAddr;
128  uint16_t mPriority;
129  uint16_t mPanId;
130  uint16_t mJoinerUdpPort;
131  uint8_t mChannel;
132  };
133 
134  static void HandleDiscoverResult(otActiveScanResult *aResult, void *aContext);
135  void HandleDiscoverResult(otActiveScanResult *aResult);
136 
137  static void HandleTimer(Timer &aTimer);
138  void HandleTimer(void);
139 
140  void Close(void);
141  void Complete(otError aError);
142 
143  void AddJoinerRouter(JoinerRouter &aJoinerRouter);
144  otError TryNextJoin();
145 
146  static void HandleSecureCoapClientConnect(bool aConnected, void *aContext);
147  void HandleSecureCoapClientConnect(bool aConnected);
148 
149  void SendJoinerFinalize(void);
150  static void HandleJoinerFinalizeResponse(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
151  const otMessageInfo *aMessageInfo, otError aResult);
152  void HandleJoinerFinalizeResponse(Coap::Header *aHeader, Message *aMessage,
153  const Ip6::MessageInfo *aMessageInfo, otError aResult);
154 
155  static void HandleJoinerEntrust(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
156  const otMessageInfo *aMessageInfo);
157  void HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
158  void SendJoinerEntrustResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
159 
160  static Joiner &GetOwner(const Context &aContext);
161 
162  otJoinerState mState;
163 
164  otJoinerCallback mCallback;
165  void *mContext;
166 
167  uint16_t mCcitt;
168  uint16_t mAnsi;
169 
170  JoinerRouter mJoinerRouters[OPENTHREAD_CONFIG_MAX_JOINER_ROUTER_ENTRIES];
171 
172  const char *mVendorName;
173  const char *mVendorModel;
174  const char *mVendorSwVersion;
175  const char *mVendorData;
176 
177  TimerMilli mTimer;
178  Coap::Resource mJoinerEntrust;
179 };
180 
181 } // namespace MeshCoP
182 } // namespace ot
183 
184 #endif // JOINER_HPP_
This type represents all the static / global variables used by OpenThread allocated in one place...
Definition: openthread-instance.h:59
Definition: cli.cpp:90
This file includes definitions for using mbedTLS.
This class implements CoAP resource handling.
Definition: coap.hpp:200
otError Start(const char *aPSKd, const char *aProvisioningUrl, const char *aVendorName, const char *aVendorModel, const char *aVendorSwVersion, const char *aVendorData, otJoinerCallback aCallback, void *aContext)
This method starts the Joiner service.
This file includes definitions for CoAP client and server functionality.
This file includes definitions for locator class for OpenThread objects.
This file includes definitions for generating and processing CoAP headers.
Definition: joiner.hpp:57
This class implements message information for an IPv6 message.
Definition: socket.hpp:57
otJoinerState
This enumeration defines the Joiner State.
Definition: joiner.h:59
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
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.
otError Stop(void)
This method stops the Joiner service.
This file includes definitions for UDP/IPv6 sockets.
This file includes functions for the Thread Joiner role.
This structure represents an IEEE 802.15.4 Extended Address.
Definition: mac_frame.hpp:84
void(OTCALL * otJoinerCallback)(otError aError, void *aContext)
This function pointer is called to notify the completion of a join operation.
Definition: joiner.h:79
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 struct represents a received IEEE 802.15.4 Beacon.
Definition: types.h:522
This file includes definitions for the message buffer pool and message buffers.
This class implements locator for otInstance object.
Definition: locator.hpp:63
This structure represents a CoAP header.
Definition: coap.h:172
Joiner(otInstance &aInstance)
This constructor initializes the Joiner object.
This structure represents the local and peer IPv6 socket addresses.
Definition: types.h:436
void GetJoinerId(Mac::ExtAddress &aJoinerId) const
This method retrieves the Joiner ID.
otJoinerState GetState(void) const
This function returns the Joiner State.
This file includes definitions for the secure CoAP agent.
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
This file includes compile-time configuration constants for OpenThread.
This file includes definitions for CRC16 computations.