Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / src / backbone_router / backbone_agent.hpp
1 /*
2  *    Copyright (c) 2020, 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 definition for Thread Backbone agent.
32  */
33
34 #ifndef BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
35 #define BACKBONE_ROUTER_BACKBONE_AGENT_HPP_
36
37 #include <openthread/backbone_router_ftd.h>
38
39 #include "agent/instance_params.hpp"
40 #include "agent/ncp_openthread.hpp"
41 #include "backbone_router/nd_proxy.hpp"
42
43 namespace otbr {
44 namespace BackboneRouter {
45
46 /**
47  * @addtogroup border-router-backbone
48  *
49  * @brief
50  *   This module includes definition for Thread Backbone agent.
51  *
52  * @{
53  */
54
55 /**
56  * This class implements Thread Backbone agent functionality.
57  *
58  */
59 class BackboneAgent
60 {
61 public:
62     /**
63      * This constructor intiializes the `BackboneAgent` instance.
64      *
65      * @param[in] aNcp  The Thread instance.
66      *
67      */
68     BackboneAgent(otbr::Ncp::ControllerOpenThread &aNcp);
69
70     /**
71      * This method initializes the Backbone agent.
72      *
73      */
74     void Init(void);
75
76     /**
77      * This method updates the fd_set and timeout for mainloop.
78      *
79      * @param[inout]    aReadFdSet      A reference to fd_set for polling read.
80      * @param[inout]    aWriteFdSet     A reference to fd_set for polling read.
81      * @param[inout]    aErrorFdSet     A reference to fd_set for polling error.
82      * @param[inout]    aMaxFd          A reference to the current max fd in @p aReadFdSet and @p aWriteFdSet.
83      * @param[inout]    aTimeout        A reference to the timeout.
84      *
85      */
86     void UpdateFdSet(fd_set & aReadFdSet,
87                      fd_set & aWriteFdSet,
88                      fd_set & aErrorFdSet,
89                      int &    aMaxFd,
90                      timeval &aTimeout) const;
91
92     /**
93      * This method performs border agent processing.
94      *
95      * @param[in]   aReadFdSet   A reference to read file descriptors.
96      * @param[in]   aWriteFdSet  A reference to write file descriptors.
97      * @param[in]   aErrorFdSet  A reference to error file descriptors.
98      *
99      */
100     void Process(const fd_set &aReadFdSet, const fd_set &aWriteFdSet, const fd_set &aErrorFdSet);
101
102 private:
103     void        OnBecomePrimary(void);
104     void        OnResignPrimary(void);
105     bool        IsPrimary(void) const { return mBackboneRouterState == OT_BACKBONE_ROUTER_STATE_PRIMARY; }
106     static void HandleBackboneRouterState(void *aContext, int aEvent, va_list aArguments);
107     void        HandleBackboneRouterState(void);
108     static void HandleBackboneRouterDomainPrefixEvent(void *aContext, int aEvent, va_list aArguments);
109     void        HandleBackboneRouterDomainPrefixEvent(otBackboneRouterDomainPrefixEvent aEvent,
110                                                       const otIp6Prefix *               aDomainPrefix);
111     static void HandleBackboneRouterNdProxyEvent(void *aContext, int aEvent, va_list aArguments);
112     void        HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress);
113
114     static const char *StateToString(otBackboneRouterState aState);
115
116     otbr::Ncp::ControllerOpenThread &mNcp;
117     otBackboneRouterState            mBackboneRouterState;
118     NdProxyManager                   mNdProxyManager;
119     Ip6Prefix                        mDomainPrefix;
120 };
121
122 /**
123  * @}
124  */
125
126 } // namespace BackboneRouter
127 } // namespace otbr
128
129 #endif // BACKBONE_ROUTER_BACKBONE_AGENT_HPP_