2 * Copyright (c) 2017, The OpenThread Authors.
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.
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.
31 * This file includes definitions for NCP service.
34 #ifndef OTBR_AGENT_NCP_OPENTHREAD_HPP_
35 #define OTBR_AGENT_NCP_OPENTHREAD_HPP_
40 #include <openthread/backbone_router_ftd.h>
41 #include <openthread/cli.h>
42 #include <openthread/instance.h>
43 #include <openthread/openthread-system.h>
46 #include "agent/thread_helper.hpp"
52 * This interface defines NCP Controller functionality.
55 class ControllerOpenThread : public Controller
59 * This constructor initializes this object.
61 * @param[in] aInterfaceName A string of the NCP interface name.
62 * @param[in] aRadioUrl The URL describes the radio chip.
63 * @param[in] aBackboneInterfaceName The Backbone network interface name.
66 ControllerOpenThread(const char *aInterfaceName, const char *aRadioUrl, const char *aBackboneInterfaceName);
69 * This method initalize the NCP controller.
71 * @retval OTBR_ERROR_NONE Successfully initialized NCP controller.
74 otbrError Init(void) override;
77 * This method get mInstance pointer.
79 * @retval the pointer of mInstance.
82 otInstance *GetInstance(void) { return mInstance; }
85 * This method gets the thread functionality helper.
87 * @retval the pointer to the helper object.
90 otbr::agent::ThreadHelper *GetThreadHelper(void) { return mThreadHelper.get(); }
93 * This method updates the fd_set to poll.
95 * @param[inout] aMainloop A reference to OpenThread mainloop context.
98 void UpdateFdSet(otSysMainloopContext &aMainloop) override;
101 * This method performs the Thread processing.
103 * @param[in] aMainloop A reference to OpenThread mainloop context.
106 void Process(const otSysMainloopContext &aMainloop) override;
109 * This method request the event.
111 * @param[in] aEvent The event id to request.
113 * @retval OTBR_ERROR_NONE Successfully requested the event.
114 * @retval OTBR_ERROR_ERRNO Failed to request the event.
117 otbrError RequestEvent(int aEvent) override;
120 * This method posts a task to the timer
122 * @param[in] aTimePoint The timepoint to trigger the task.
123 * @param[in] aTask The task function.
126 void PostTimerTask(std::chrono::steady_clock::time_point aTimePoint, const std::function<void(void)> &aTask);
129 * This method registers a reset handler.
131 * @param[in] aHandler The handler function.
134 void RegisterResetHandler(std::function<void(void)> aHandler);
136 ~ControllerOpenThread(void) override;
139 static void HandleStateChanged(otChangedFlags aFlags, void *aContext)
141 static_cast<ControllerOpenThread *>(aContext)->HandleStateChanged(aFlags);
143 void HandleStateChanged(otChangedFlags aFlags);
145 static void HandleBackboneRouterDomainPrefixEvent(void * aContext,
146 otBackboneRouterDomainPrefixEvent aEvent,
147 const otIp6Prefix * aDomainPrefix);
148 void HandleBackboneRouterDomainPrefixEvent(otBackboneRouterDomainPrefixEvent aEvent,
149 const otIp6Prefix * aDomainPrefix);
151 static void HandleBackboneRouterNdProxyEvent(void * aContext,
152 otBackboneRouterNdProxyEvent aEvent,
153 const otIp6Address * aAddress);
154 void HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress);
156 static void HandleBackboneRouterMulticastListenerEvent(void * aContext,
157 otBackboneRouterMulticastListenerEvent aEvent,
158 const otIp6Address * aAddress);
159 void HandleBackboneRouterMulticastListenerEvent(otBackboneRouterMulticastListenerEvent aEvent,
160 const otIp6Address * aAddress);
162 otInstance *mInstance;
164 otPlatformConfig mConfig;
165 std::unique_ptr<otbr::agent::ThreadHelper> mThreadHelper;
166 std::multimap<std::chrono::steady_clock::time_point, std::function<void(void)>> mTimers;
167 std::vector<std::function<void(void)>> mResetHandlers;
173 #endif // OTBR_AGENT_NCP_OPENTHREAD_HPP_