xref: /aosp_15_r20/external/ot-br-posix/src/utils/thread_helper.hpp (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1*4a64e381SAndroid Build Coastguard Worker /*
2*4a64e381SAndroid Build Coastguard Worker  *    Copyright (c) 2020, The OpenThread Authors.
3*4a64e381SAndroid Build Coastguard Worker  *    All rights reserved.
4*4a64e381SAndroid Build Coastguard Worker  *
5*4a64e381SAndroid Build Coastguard Worker  *    Redistribution and use in source and binary forms, with or without
6*4a64e381SAndroid Build Coastguard Worker  *    modification, are permitted provided that the following conditions are met:
7*4a64e381SAndroid Build Coastguard Worker  *    1. Redistributions of source code must retain the above copyright
8*4a64e381SAndroid Build Coastguard Worker  *       notice, this list of conditions and the following disclaimer.
9*4a64e381SAndroid Build Coastguard Worker  *    2. Redistributions in binary form must reproduce the above copyright
10*4a64e381SAndroid Build Coastguard Worker  *       notice, this list of conditions and the following disclaimer in the
11*4a64e381SAndroid Build Coastguard Worker  *       documentation and/or other materials provided with the distribution.
12*4a64e381SAndroid Build Coastguard Worker  *    3. Neither the name of the copyright holder nor the
13*4a64e381SAndroid Build Coastguard Worker  *       names of its contributors may be used to endorse or promote products
14*4a64e381SAndroid Build Coastguard Worker  *       derived from this software without specific prior written permission.
15*4a64e381SAndroid Build Coastguard Worker  *
16*4a64e381SAndroid Build Coastguard Worker  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*4a64e381SAndroid Build Coastguard Worker  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*4a64e381SAndroid Build Coastguard Worker  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*4a64e381SAndroid Build Coastguard Worker  *    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20*4a64e381SAndroid Build Coastguard Worker  *    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*4a64e381SAndroid Build Coastguard Worker  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*4a64e381SAndroid Build Coastguard Worker  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*4a64e381SAndroid Build Coastguard Worker  *    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*4a64e381SAndroid Build Coastguard Worker  *    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*4a64e381SAndroid Build Coastguard Worker  *    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*4a64e381SAndroid Build Coastguard Worker  *    POSSIBILITY OF SUCH DAMAGE.
27*4a64e381SAndroid Build Coastguard Worker  */
28*4a64e381SAndroid Build Coastguard Worker 
29*4a64e381SAndroid Build Coastguard Worker /**
30*4a64e381SAndroid Build Coastguard Worker  * @file
31*4a64e381SAndroid Build Coastguard Worker  *   This file includes definitions for Thread helper.
32*4a64e381SAndroid Build Coastguard Worker  */
33*4a64e381SAndroid Build Coastguard Worker 
34*4a64e381SAndroid Build Coastguard Worker #ifndef OTBR_THREAD_HELPER_HPP_
35*4a64e381SAndroid Build Coastguard Worker #define OTBR_THREAD_HELPER_HPP_
36*4a64e381SAndroid Build Coastguard Worker 
37*4a64e381SAndroid Build Coastguard Worker #include "openthread-br/config.h"
38*4a64e381SAndroid Build Coastguard Worker 
39*4a64e381SAndroid Build Coastguard Worker #include <chrono>
40*4a64e381SAndroid Build Coastguard Worker #include <functional>
41*4a64e381SAndroid Build Coastguard Worker #include <map>
42*4a64e381SAndroid Build Coastguard Worker #include <random>
43*4a64e381SAndroid Build Coastguard Worker #include <string>
44*4a64e381SAndroid Build Coastguard Worker #include <vector>
45*4a64e381SAndroid Build Coastguard Worker 
46*4a64e381SAndroid Build Coastguard Worker #include <openthread/border_routing.h>
47*4a64e381SAndroid Build Coastguard Worker #include <openthread/instance.h>
48*4a64e381SAndroid Build Coastguard Worker #include <openthread/ip6.h>
49*4a64e381SAndroid Build Coastguard Worker #include <openthread/jam_detection.h>
50*4a64e381SAndroid Build Coastguard Worker #include <openthread/joiner.h>
51*4a64e381SAndroid Build Coastguard Worker #include <openthread/netdata.h>
52*4a64e381SAndroid Build Coastguard Worker #include <openthread/thread.h>
53*4a64e381SAndroid Build Coastguard Worker #include "mdns/mdns.hpp"
54*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_TELEMETRY_DATA_API
55*4a64e381SAndroid Build Coastguard Worker #include "proto/thread_telemetry.pb.h"
56*4a64e381SAndroid Build Coastguard Worker #endif
57*4a64e381SAndroid Build Coastguard Worker 
58*4a64e381SAndroid Build Coastguard Worker namespace otbr {
59*4a64e381SAndroid Build Coastguard Worker namespace Ncp {
60*4a64e381SAndroid Build Coastguard Worker class RcpHost;
61*4a64e381SAndroid Build Coastguard Worker }
62*4a64e381SAndroid Build Coastguard Worker } // namespace otbr
63*4a64e381SAndroid Build Coastguard Worker 
64*4a64e381SAndroid Build Coastguard Worker namespace otbr {
65*4a64e381SAndroid Build Coastguard Worker namespace agent {
66*4a64e381SAndroid Build Coastguard Worker 
67*4a64e381SAndroid Build Coastguard Worker /**
68*4a64e381SAndroid Build Coastguard Worker  * This class implements Thread helper.
69*4a64e381SAndroid Build Coastguard Worker  */
70*4a64e381SAndroid Build Coastguard Worker class ThreadHelper
71*4a64e381SAndroid Build Coastguard Worker {
72*4a64e381SAndroid Build Coastguard Worker public:
73*4a64e381SAndroid Build Coastguard Worker     using DeviceRoleHandler       = std::function<void(otDeviceRole)>;
74*4a64e381SAndroid Build Coastguard Worker     using ScanHandler             = std::function<void(otError, const std::vector<otActiveScanResult> &)>;
75*4a64e381SAndroid Build Coastguard Worker     using EnergyScanHandler       = std::function<void(otError, const std::vector<otEnergyScanResult> &)>;
76*4a64e381SAndroid Build Coastguard Worker     using ResultHandler           = std::function<void(otError)>;
77*4a64e381SAndroid Build Coastguard Worker     using AttachHandler           = std::function<void(otError, int64_t)>;
78*4a64e381SAndroid Build Coastguard Worker     using UpdateMeshCopTxtHandler = std::function<void(std::map<std::string, std::vector<uint8_t>>)>;
79*4a64e381SAndroid Build Coastguard Worker     using DatasetChangeHandler    = std::function<void(const otOperationalDatasetTlvs &)>;
80*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DHCP6_PD
81*4a64e381SAndroid Build Coastguard Worker     using Dhcp6PdStateCallback = std::function<void(otBorderRoutingDhcp6PdState)>;
82*4a64e381SAndroid Build Coastguard Worker #endif
83*4a64e381SAndroid Build Coastguard Worker 
84*4a64e381SAndroid Build Coastguard Worker     /**
85*4a64e381SAndroid Build Coastguard Worker      * The constructor of a Thread helper.
86*4a64e381SAndroid Build Coastguard Worker      *
87*4a64e381SAndroid Build Coastguard Worker      * @param[in] aInstance  The Thread instance.
88*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHost      The Thread controller.
89*4a64e381SAndroid Build Coastguard Worker      */
90*4a64e381SAndroid Build Coastguard Worker     ThreadHelper(otInstance *aInstance, otbr::Ncp::RcpHost *aHost);
91*4a64e381SAndroid Build Coastguard Worker 
92*4a64e381SAndroid Build Coastguard Worker     /**
93*4a64e381SAndroid Build Coastguard Worker      * This method adds a callback for device role change.
94*4a64e381SAndroid Build Coastguard Worker      *
95*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler  The device role handler.
96*4a64e381SAndroid Build Coastguard Worker      */
97*4a64e381SAndroid Build Coastguard Worker     void AddDeviceRoleHandler(DeviceRoleHandler aHandler);
98*4a64e381SAndroid Build Coastguard Worker 
99*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DHCP6_PD
100*4a64e381SAndroid Build Coastguard Worker     /**
101*4a64e381SAndroid Build Coastguard Worker      * This method adds a callback for DHCPv6 PD state change.
102*4a64e381SAndroid Build Coastguard Worker      *
103*4a64e381SAndroid Build Coastguard Worker      * @param[in] aCallback  The DHCPv6 PD state change callback.
104*4a64e381SAndroid Build Coastguard Worker      */
105*4a64e381SAndroid Build Coastguard Worker     void SetDhcp6PdStateCallback(Dhcp6PdStateCallback aCallback);
106*4a64e381SAndroid Build Coastguard Worker #endif
107*4a64e381SAndroid Build Coastguard Worker 
108*4a64e381SAndroid Build Coastguard Worker     /**
109*4a64e381SAndroid Build Coastguard Worker      * This method adds a callback for active dataset change.
110*4a64e381SAndroid Build Coastguard Worker      *
111*4a64e381SAndroid Build Coastguard Worker      * @param[in]  aHandler   The active dataset change handler.
112*4a64e381SAndroid Build Coastguard Worker      */
113*4a64e381SAndroid Build Coastguard Worker     void AddActiveDatasetChangeHandler(DatasetChangeHandler aHandler);
114*4a64e381SAndroid Build Coastguard Worker 
115*4a64e381SAndroid Build Coastguard Worker     /**
116*4a64e381SAndroid Build Coastguard Worker      * This method permits unsecure join on port.
117*4a64e381SAndroid Build Coastguard Worker      *
118*4a64e381SAndroid Build Coastguard Worker      * @param[in] aPort     The port number.
119*4a64e381SAndroid Build Coastguard Worker      * @param[in] aSeconds  The timeout to close the port, 0 for never close.
120*4a64e381SAndroid Build Coastguard Worker      *
121*4a64e381SAndroid Build Coastguard Worker      * @returns The error value of underlying OpenThread api calls.
122*4a64e381SAndroid Build Coastguard Worker      */
123*4a64e381SAndroid Build Coastguard Worker     otError PermitUnsecureJoin(uint16_t aPort, uint32_t aSeconds);
124*4a64e381SAndroid Build Coastguard Worker 
125*4a64e381SAndroid Build Coastguard Worker     /**
126*4a64e381SAndroid Build Coastguard Worker      * This method performs a Thread network scan.
127*4a64e381SAndroid Build Coastguard Worker      *
128*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler  The scan result handler.
129*4a64e381SAndroid Build Coastguard Worker      */
130*4a64e381SAndroid Build Coastguard Worker     void Scan(ScanHandler aHandler);
131*4a64e381SAndroid Build Coastguard Worker 
132*4a64e381SAndroid Build Coastguard Worker     /**
133*4a64e381SAndroid Build Coastguard Worker      * This method performs an IEEE 802.15.4 Energy Scan.
134*4a64e381SAndroid Build Coastguard Worker      *
135*4a64e381SAndroid Build Coastguard Worker      * @param[in] aScanDuration  The duration for the scan, in milliseconds.
136*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler       The scan result handler.
137*4a64e381SAndroid Build Coastguard Worker      */
138*4a64e381SAndroid Build Coastguard Worker     void EnergyScan(uint32_t aScanDuration, EnergyScanHandler aHandler);
139*4a64e381SAndroid Build Coastguard Worker 
140*4a64e381SAndroid Build Coastguard Worker     /**
141*4a64e381SAndroid Build Coastguard Worker      * This method attaches the device to the Thread network.
142*4a64e381SAndroid Build Coastguard Worker      *
143*4a64e381SAndroid Build Coastguard Worker      * @note The joiner start and the attach proccesses are exclusive
144*4a64e381SAndroid Build Coastguard Worker      *
145*4a64e381SAndroid Build Coastguard Worker      * @param[in] aNetworkName  The network name.
146*4a64e381SAndroid Build Coastguard Worker      * @param[in] aPanId        The pan id, UINT16_MAX for random.
147*4a64e381SAndroid Build Coastguard Worker      * @param[in] aExtPanId     The extended pan id, UINT64_MAX for random.
148*4a64e381SAndroid Build Coastguard Worker      * @param[in] aNetworkKey   The network key, empty for random.
149*4a64e381SAndroid Build Coastguard Worker      * @param[in] aPSKc         The pre-shared commissioner key, empty for random.
150*4a64e381SAndroid Build Coastguard Worker      * @param[in] aChannelMask  A bitmask for valid channels, will random select one.
151*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler      The attach result handler.
152*4a64e381SAndroid Build Coastguard Worker      */
153*4a64e381SAndroid Build Coastguard Worker     void Attach(const std::string          &aNetworkName,
154*4a64e381SAndroid Build Coastguard Worker                 uint16_t                    aPanId,
155*4a64e381SAndroid Build Coastguard Worker                 uint64_t                    aExtPanId,
156*4a64e381SAndroid Build Coastguard Worker                 const std::vector<uint8_t> &aNetworkKey,
157*4a64e381SAndroid Build Coastguard Worker                 const std::vector<uint8_t> &aPSKc,
158*4a64e381SAndroid Build Coastguard Worker                 uint32_t                    aChannelMask,
159*4a64e381SAndroid Build Coastguard Worker                 AttachHandler               aHandler);
160*4a64e381SAndroid Build Coastguard Worker 
161*4a64e381SAndroid Build Coastguard Worker     /**
162*4a64e381SAndroid Build Coastguard Worker      * This method detaches the device from the Thread network.
163*4a64e381SAndroid Build Coastguard Worker      *
164*4a64e381SAndroid Build Coastguard Worker      * @returns The error value of underlying OpenThread API calls.
165*4a64e381SAndroid Build Coastguard Worker      */
166*4a64e381SAndroid Build Coastguard Worker     otError Detach(void);
167*4a64e381SAndroid Build Coastguard Worker 
168*4a64e381SAndroid Build Coastguard Worker     /**
169*4a64e381SAndroid Build Coastguard Worker      * This method attaches the device to the Thread network.
170*4a64e381SAndroid Build Coastguard Worker      *
171*4a64e381SAndroid Build Coastguard Worker      * @note The joiner start and the attach proccesses are exclusive, and the
172*4a64e381SAndroid Build Coastguard Worker      *       network parameter will be set through the active dataset.
173*4a64e381SAndroid Build Coastguard Worker      *
174*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler  The attach result handler.
175*4a64e381SAndroid Build Coastguard Worker      */
176*4a64e381SAndroid Build Coastguard Worker     void Attach(AttachHandler aHandler);
177*4a64e381SAndroid Build Coastguard Worker 
178*4a64e381SAndroid Build Coastguard Worker     /**
179*4a64e381SAndroid Build Coastguard Worker      * This method makes all nodes in the current network attach to the network specified by the dataset TLVs.
180*4a64e381SAndroid Build Coastguard Worker      *
181*4a64e381SAndroid Build Coastguard Worker      * @param[in] aDatasetTlvs  The dataset TLVs.
182*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler      The result handler.
183*4a64e381SAndroid Build Coastguard Worker      */
184*4a64e381SAndroid Build Coastguard Worker     void AttachAllNodesTo(const std::vector<uint8_t> &aDatasetTlvs, AttachHandler aHandler);
185*4a64e381SAndroid Build Coastguard Worker 
186*4a64e381SAndroid Build Coastguard Worker     /**
187*4a64e381SAndroid Build Coastguard Worker      * This method resets the OpenThread stack.
188*4a64e381SAndroid Build Coastguard Worker      *
189*4a64e381SAndroid Build Coastguard Worker      * @returns The error value of underlying OpenThread api calls.
190*4a64e381SAndroid Build Coastguard Worker      */
191*4a64e381SAndroid Build Coastguard Worker     otError Reset(void);
192*4a64e381SAndroid Build Coastguard Worker 
193*4a64e381SAndroid Build Coastguard Worker     /**
194*4a64e381SAndroid Build Coastguard Worker      * This method triggers a thread join process.
195*4a64e381SAndroid Build Coastguard Worker      *
196*4a64e381SAndroid Build Coastguard Worker      * @note The joiner start and the attach proccesses are exclusive
197*4a64e381SAndroid Build Coastguard Worker      *
198*4a64e381SAndroid Build Coastguard Worker      * @param[in] aPskd             The pre-shared key for device.
199*4a64e381SAndroid Build Coastguard Worker      * @param[in] aProvisioningUrl  The provision url.
200*4a64e381SAndroid Build Coastguard Worker      * @param[in] aVendorName       The vendor name.
201*4a64e381SAndroid Build Coastguard Worker      * @param[in] aVendorModel      The vendor model.
202*4a64e381SAndroid Build Coastguard Worker      * @param[in] aVendorSwVersion  The vendor software version.
203*4a64e381SAndroid Build Coastguard Worker      * @param[in] aVendorData       The vendor custom data.
204*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler          The join result handler.
205*4a64e381SAndroid Build Coastguard Worker      */
206*4a64e381SAndroid Build Coastguard Worker     void JoinerStart(const std::string &aPskd,
207*4a64e381SAndroid Build Coastguard Worker                      const std::string &aProvisioningUrl,
208*4a64e381SAndroid Build Coastguard Worker                      const std::string &aVendorName,
209*4a64e381SAndroid Build Coastguard Worker                      const std::string &aVendorModel,
210*4a64e381SAndroid Build Coastguard Worker                      const std::string &aVendorSwVersion,
211*4a64e381SAndroid Build Coastguard Worker                      const std::string &aVendorData,
212*4a64e381SAndroid Build Coastguard Worker                      ResultHandler      aHandler);
213*4a64e381SAndroid Build Coastguard Worker 
214*4a64e381SAndroid Build Coastguard Worker     /**
215*4a64e381SAndroid Build Coastguard Worker      * This method tries to restore the network after reboot
216*4a64e381SAndroid Build Coastguard Worker      *
217*4a64e381SAndroid Build Coastguard Worker      * @returns The error value of underlying OpenThread api calls.
218*4a64e381SAndroid Build Coastguard Worker      */
219*4a64e381SAndroid Build Coastguard Worker     otError TryResumeNetwork(void);
220*4a64e381SAndroid Build Coastguard Worker 
221*4a64e381SAndroid Build Coastguard Worker     /**
222*4a64e381SAndroid Build Coastguard Worker      * This method returns the underlying OpenThread instance.
223*4a64e381SAndroid Build Coastguard Worker      *
224*4a64e381SAndroid Build Coastguard Worker      * @returns The underlying instance.
225*4a64e381SAndroid Build Coastguard Worker      */
GetInstance(void)226*4a64e381SAndroid Build Coastguard Worker     otInstance *GetInstance(void)
227*4a64e381SAndroid Build Coastguard Worker     {
228*4a64e381SAndroid Build Coastguard Worker         return mInstance;
229*4a64e381SAndroid Build Coastguard Worker     }
230*4a64e381SAndroid Build Coastguard Worker 
231*4a64e381SAndroid Build Coastguard Worker     /**
232*4a64e381SAndroid Build Coastguard Worker      * This method handles OpenThread state changed notification.
233*4a64e381SAndroid Build Coastguard Worker      *
234*4a64e381SAndroid Build Coastguard Worker      * @param[in] aFlags    A bit-field indicating specific state that has changed.  See `OT_CHANGED_*` definitions.
235*4a64e381SAndroid Build Coastguard Worker      */
236*4a64e381SAndroid Build Coastguard Worker     void StateChangedCallback(otChangedFlags aFlags);
237*4a64e381SAndroid Build Coastguard Worker 
238*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DBUS_SERVER
239*4a64e381SAndroid Build Coastguard Worker     /**
240*4a64e381SAndroid Build Coastguard Worker      * This method sets a callback for calls of UpdateVendorMeshCopTxtEntries D-Bus API.
241*4a64e381SAndroid Build Coastguard Worker      *
242*4a64e381SAndroid Build Coastguard Worker      * @param[in] aHandler  The handler on MeshCoP TXT changes.
243*4a64e381SAndroid Build Coastguard Worker      */
SetUpdateMeshCopTxtHandler(UpdateMeshCopTxtHandler aHandler)244*4a64e381SAndroid Build Coastguard Worker     void SetUpdateMeshCopTxtHandler(UpdateMeshCopTxtHandler aHandler)
245*4a64e381SAndroid Build Coastguard Worker     {
246*4a64e381SAndroid Build Coastguard Worker         mUpdateMeshCopTxtHandler = std::move(aHandler);
247*4a64e381SAndroid Build Coastguard Worker     }
248*4a64e381SAndroid Build Coastguard Worker 
249*4a64e381SAndroid Build Coastguard Worker     /**
250*4a64e381SAndroid Build Coastguard Worker      * This method handles MeshCoP TXT updates done by UpdateVendorMeshCopTxtEntries D-Bus API.
251*4a64e381SAndroid Build Coastguard Worker      *
252*4a64e381SAndroid Build Coastguard Worker      * @param[in] aUpdate  The key-value pairs to be updated in the TXT record.
253*4a64e381SAndroid Build Coastguard Worker      */
254*4a64e381SAndroid Build Coastguard Worker     void OnUpdateMeshCopTxt(std::map<std::string, std::vector<uint8_t>> aUpdate);
255*4a64e381SAndroid Build Coastguard Worker #endif
256*4a64e381SAndroid Build Coastguard Worker 
257*4a64e381SAndroid Build Coastguard Worker     void DetachGracefully(ResultHandler aHandler);
258*4a64e381SAndroid Build Coastguard Worker 
259*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_TELEMETRY_DATA_API
260*4a64e381SAndroid Build Coastguard Worker     /**
261*4a64e381SAndroid Build Coastguard Worker      * This method populates the telemetry data with best effort. The best effort means, for a given
262*4a64e381SAndroid Build Coastguard Worker      * telemetry, if its retrieval has error, it is left unpopulated and the process continues to
263*4a64e381SAndroid Build Coastguard Worker      * retrieve the remaining telemetries instead of the immediately return. The error code
264*4a64e381SAndroid Build Coastguard Worker      * OT_ERRROR_FAILED will be returned if there is one or more error(s) happened in the process.
265*4a64e381SAndroid Build Coastguard Worker      *
266*4a64e381SAndroid Build Coastguard Worker      * @param[in] aPublisher     The Mdns::Publisher to provide MDNS telemetry if it is not `nullptr`.
267*4a64e381SAndroid Build Coastguard Worker      * @param[in] telemetryData  The telemetry data to be populated.
268*4a64e381SAndroid Build Coastguard Worker      *
269*4a64e381SAndroid Build Coastguard Worker      * @retval OTBR_ERROR_NONE  There is no error happened in the process.
270*4a64e381SAndroid Build Coastguard Worker      * @retval OT_ERRROR_FAILED There is one or more error(s) happened in the process.
271*4a64e381SAndroid Build Coastguard Worker      */
272*4a64e381SAndroid Build Coastguard Worker     otError RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadnetwork::TelemetryData &telemetryData);
273*4a64e381SAndroid Build Coastguard Worker #endif // OTBR_ENABLE_TELEMETRY_DATA_API
274*4a64e381SAndroid Build Coastguard Worker 
275*4a64e381SAndroid Build Coastguard Worker     /**
276*4a64e381SAndroid Build Coastguard Worker      * This method logs OpenThread action result.
277*4a64e381SAndroid Build Coastguard Worker      *
278*4a64e381SAndroid Build Coastguard Worker      * @param[in] aAction  The action OpenThread performs.
279*4a64e381SAndroid Build Coastguard Worker      * @param[in] aError   The action result.
280*4a64e381SAndroid Build Coastguard Worker      */
281*4a64e381SAndroid Build Coastguard Worker     static void LogOpenThreadResult(const char *aAction, otError aError);
282*4a64e381SAndroid Build Coastguard Worker 
283*4a64e381SAndroid Build Coastguard Worker     /**
284*4a64e381SAndroid Build Coastguard Worker      * This method validates and updates a pending dataset do Thread network migration.
285*4a64e381SAndroid Build Coastguard Worker      *
286*4a64e381SAndroid Build Coastguard Worker      * This method validates that:
287*4a64e381SAndroid Build Coastguard Worker      * 1. the given dataset doesn't contain a meshcop Pending Timestamp TLV or a meshcop Delay Timer TLV.
288*4a64e381SAndroid Build Coastguard Worker      * 2. the given dataset has sufficient space to append a Pending Timestamp TLV and a Delay Timer TLV.
289*4a64e381SAndroid Build Coastguard Worker      *
290*4a64e381SAndroid Build Coastguard Worker      * If it's valid, the method will append a meshcop Pending Timestamp TLV with value being the current unix
291*4a64e381SAndroid Build Coastguard Worker      * timestamp and a meshcop Delay Timer TLV with value being @p aDelayMilli.
292*4a64e381SAndroid Build Coastguard Worker      *
293*4a64e381SAndroid Build Coastguard Worker      * @param[in/out] aDatasetTlvs  The dataset to validate and process in TLVs format.
294*4a64e381SAndroid Build Coastguard Worker      * @param[in]     aDelayMilli   The delay time for migration in milliseconds.
295*4a64e381SAndroid Build Coastguard Worker      *
296*4a64e381SAndroid Build Coastguard Worker      * @retval OT_ERROR_NONE          Dataset is valid to do Thread network migration.
297*4a64e381SAndroid Build Coastguard Worker      * @retval OT_ERROR_INVALID_ARGS  Dataset is invalid to do Thread network migration.
298*4a64e381SAndroid Build Coastguard Worker      */
299*4a64e381SAndroid Build Coastguard Worker     static otError ProcessDatasetForMigration(otOperationalDatasetTlvs &aDatasetTlvs, uint32_t aDelayMilli);
300*4a64e381SAndroid Build Coastguard Worker 
301*4a64e381SAndroid Build Coastguard Worker private:
302*4a64e381SAndroid Build Coastguard Worker     static void ActiveScanHandler(otActiveScanResult *aResult, void *aThreadHelper);
303*4a64e381SAndroid Build Coastguard Worker     void        ActiveScanHandler(otActiveScanResult *aResult);
304*4a64e381SAndroid Build Coastguard Worker 
305*4a64e381SAndroid Build Coastguard Worker     static void EnergyScanCallback(otEnergyScanResult *aResult, void *aThreadHelper);
306*4a64e381SAndroid Build Coastguard Worker     void        EnergyScanCallback(otEnergyScanResult *aResult);
307*4a64e381SAndroid Build Coastguard Worker 
308*4a64e381SAndroid Build Coastguard Worker     static void JoinerCallback(otError aError, void *aThreadHelper);
309*4a64e381SAndroid Build Coastguard Worker     void        JoinerCallback(otError aResult);
310*4a64e381SAndroid Build Coastguard Worker 
311*4a64e381SAndroid Build Coastguard Worker     static void MgmtSetResponseHandler(otError aResult, void *aContext);
312*4a64e381SAndroid Build Coastguard Worker     void        MgmtSetResponseHandler(otError aResult);
313*4a64e381SAndroid Build Coastguard Worker 
314*4a64e381SAndroid Build Coastguard Worker     static void DetachGracefullyCallback(void *aContext);
315*4a64e381SAndroid Build Coastguard Worker     void        DetachGracefullyCallback(void);
316*4a64e381SAndroid Build Coastguard Worker 
317*4a64e381SAndroid Build Coastguard Worker     void    RandomFill(void *aBuf, size_t size);
318*4a64e381SAndroid Build Coastguard Worker     uint8_t RandomChannelFromChannelMask(uint32_t aChannelMask);
319*4a64e381SAndroid Build Coastguard Worker 
320*4a64e381SAndroid Build Coastguard Worker     void ActiveDatasetChangedCallback(void);
321*4a64e381SAndroid Build Coastguard Worker 
322*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DHCP6_PD
323*4a64e381SAndroid Build Coastguard Worker     static void BorderRoutingDhcp6PdCallback(otBorderRoutingDhcp6PdState aState, void *aThreadHelper);
324*4a64e381SAndroid Build Coastguard Worker     void        BorderRoutingDhcp6PdCallback(otBorderRoutingDhcp6PdState aState);
325*4a64e381SAndroid Build Coastguard Worker #endif
326*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_TELEMETRY_DATA_API
327*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_BORDER_ROUTING
328*4a64e381SAndroid Build Coastguard Worker     void RetrieveInfraLinkInfo(threadnetwork::TelemetryData::InfraLinkInfo &aInfraLinkInfo);
329*4a64e381SAndroid Build Coastguard Worker     void RetrieveExternalRouteInfo(threadnetwork::TelemetryData::ExternalRoutes &aExternalRouteInfo);
330*4a64e381SAndroid Build Coastguard Worker #endif
331*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DHCP6_PD
332*4a64e381SAndroid Build Coastguard Worker     void RetrievePdInfo(threadnetwork::TelemetryData::WpanBorderRouter *aWpanBorderRouter);
333*4a64e381SAndroid Build Coastguard Worker     void RetrieveHashedPdPrefix(std::string *aHashedPdPrefix);
334*4a64e381SAndroid Build Coastguard Worker     void RetrievePdProcessedRaInfo(threadnetwork::TelemetryData::PdProcessedRaInfo *aPdProcessedRaInfo);
335*4a64e381SAndroid Build Coastguard Worker #endif
336*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_BORDER_AGENT
337*4a64e381SAndroid Build Coastguard Worker     void RetrieveBorderAgentInfo(threadnetwork::TelemetryData::BorderAgentInfo *aBorderAgentInfo);
338*4a64e381SAndroid Build Coastguard Worker #endif
339*4a64e381SAndroid Build Coastguard Worker #endif // OTBR_ENABLE_TELEMETRY_DATA_API
340*4a64e381SAndroid Build Coastguard Worker 
341*4a64e381SAndroid Build Coastguard Worker     otInstance *mInstance;
342*4a64e381SAndroid Build Coastguard Worker 
343*4a64e381SAndroid Build Coastguard Worker     otbr::Ncp::RcpHost *mHost;
344*4a64e381SAndroid Build Coastguard Worker 
345*4a64e381SAndroid Build Coastguard Worker     ScanHandler                     mScanHandler;
346*4a64e381SAndroid Build Coastguard Worker     std::vector<otActiveScanResult> mScanResults;
347*4a64e381SAndroid Build Coastguard Worker     EnergyScanHandler               mEnergyScanHandler;
348*4a64e381SAndroid Build Coastguard Worker     std::vector<otEnergyScanResult> mEnergyScanResults;
349*4a64e381SAndroid Build Coastguard Worker 
350*4a64e381SAndroid Build Coastguard Worker     std::vector<DeviceRoleHandler>    mDeviceRoleHandlers;
351*4a64e381SAndroid Build Coastguard Worker     std::vector<DatasetChangeHandler> mActiveDatasetChangeHandlers;
352*4a64e381SAndroid Build Coastguard Worker 
353*4a64e381SAndroid Build Coastguard Worker     std::map<uint16_t, size_t> mUnsecurePortRefCounter;
354*4a64e381SAndroid Build Coastguard Worker 
355*4a64e381SAndroid Build Coastguard Worker     bool mWaitingMgmtSetResponse =
356*4a64e381SAndroid Build Coastguard Worker         false; // During waiting for mgmt set response, calls to AttachHandler by StateChangedCallback will be ignored
357*4a64e381SAndroid Build Coastguard Worker     int64_t       mAttachDelayMs = 0;
358*4a64e381SAndroid Build Coastguard Worker     AttachHandler mAttachHandler;
359*4a64e381SAndroid Build Coastguard Worker     ResultHandler mJoinerHandler;
360*4a64e381SAndroid Build Coastguard Worker 
361*4a64e381SAndroid Build Coastguard Worker     ResultHandler mDetachGracefullyHandler = nullptr;
362*4a64e381SAndroid Build Coastguard Worker 
363*4a64e381SAndroid Build Coastguard Worker     otOperationalDatasetTlvs mAttachPendingDatasetTlvs = {};
364*4a64e381SAndroid Build Coastguard Worker 
365*4a64e381SAndroid Build Coastguard Worker     std::random_device mRandomDevice;
366*4a64e381SAndroid Build Coastguard Worker 
367*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DHCP6_PD
368*4a64e381SAndroid Build Coastguard Worker     Dhcp6PdStateCallback mDhcp6PdCallback;
369*4a64e381SAndroid Build Coastguard Worker #endif
370*4a64e381SAndroid Build Coastguard Worker 
371*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_DBUS_SERVER
372*4a64e381SAndroid Build Coastguard Worker     UpdateMeshCopTxtHandler mUpdateMeshCopTxtHandler;
373*4a64e381SAndroid Build Coastguard Worker #endif
374*4a64e381SAndroid Build Coastguard Worker 
375*4a64e381SAndroid Build Coastguard Worker #if OTBR_ENABLE_TELEMETRY_DATA_API && (OTBR_ENABLE_NAT64 || OTBR_ENABLE_DHCP6_PD)
376*4a64e381SAndroid Build Coastguard Worker     static constexpr uint8_t kNat64PdCommonHashSaltLength = 16;
377*4a64e381SAndroid Build Coastguard Worker     uint8_t                  mNat64PdCommonSalt[kNat64PdCommonHashSaltLength];
378*4a64e381SAndroid Build Coastguard Worker #endif
379*4a64e381SAndroid Build Coastguard Worker };
380*4a64e381SAndroid Build Coastguard Worker 
381*4a64e381SAndroid Build Coastguard Worker } // namespace agent
382*4a64e381SAndroid Build Coastguard Worker } // namespace otbr
383*4a64e381SAndroid Build Coastguard Worker 
384*4a64e381SAndroid Build Coastguard Worker #endif // OTBR_THREAD_HELPER_HPP_
385