• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 definitions for d-bus client API.
32  */
33 
34 #ifndef OTBR_THREAD_API_DBUS_HPP_
35 #define OTBR_THREAD_API_DBUS_HPP_
36 
37 #include "openthread-br/config.h"
38 
39 #include <functional>
40 
41 #include <dbus/dbus.h>
42 
43 #include "common/types.hpp"
44 #include "dbus/common/constants.hpp"
45 #include "dbus/common/error.hpp"
46 #include "dbus/common/types.hpp"
47 
48 namespace otbr {
49 namespace DBus {
50 
51 bool IsThreadActive(DeviceRole aRole);
52 
53 class ThreadApiDBus
54 {
55 public:
56     using DeviceRoleHandler = std::function<void(DeviceRole)>;
57     using ScanHandler       = std::function<void(const std::vector<ActiveScanResult> &)>;
58     using EnergyScanHandler = std::function<void(const std::vector<EnergyScanResult> &)>;
59     using OtResultHandler   = std::function<void(ClientError)>;
60 
61     /**
62      * The constructor of a d-bus object.
63      *
64      * Will use the default interfacename
65      *
66      * @param[in] aConnection  The dbus connection.
67      *
68      */
69     ThreadApiDBus(DBusConnection *aConnection);
70 
71     /**
72      * The constructor of a d-bus object.
73      *
74      * @param[in] aConnection     The dbus connection.
75      * @param[in] aInterfaceName  The network interface name.
76      *
77      */
78     ThreadApiDBus(DBusConnection *aConnection, const std::string &aInterfaceName);
79 
80     /**
81      * This method adds a callback for device role change.
82      *
83      * @param[in] aHandler  The device role handler.
84      *
85      */
86     void AddDeviceRoleHandler(const DeviceRoleHandler &aHandler);
87 
88     /**
89      * This method permits unsecure join on port.
90      *
91      * @param[in] aPort     The port number.
92      * @param[in] aSeconds  The timeout to close the port, 0 for never close.
93      *
94      * @retval ERROR_NONE  Successfully performed the dbus function call
95      * @retval ERROR_DBUS  dbus encode/decode error
96      * @retval ...         OpenThread defined error value otherwise
97      *
98      */
99     ClientError PermitUnsecureJoin(uint16_t aPort, uint32_t aSeconds);
100 
101     /**
102      * This method performs a Thread network scan.
103      *
104      * @param[in] aHandler  The scan result handler.
105      *
106      * @retval ERROR_NONE  Successfully performed the dbus function call
107      * @retval ERROR_DBUS  dbus encode/decode error
108      * @retval ...         OpenThread defined error value otherwise
109      *
110      */
111     ClientError Scan(const ScanHandler &aHandler);
112 
113     /**
114      * This method performs an IEEE 802.15.4 Energy Scan.
115      *
116      * @param[in] aScanDuration  The duration for the scan for each channel, in milliseconds. Note that maximum value
117      *                           for the duration is currently 65535. If it's the duration is larger than that, the
118      *                           handler will get an INVALID_ARGS error code.
119      * @param[in] aHandler       The energy scan result handler.
120      *
121      * @retval ERROR_NONE  Successfully performed the dbus function call
122      * @retval ERROR_DBUS  dbus encode/decode error
123      * @retval ...         OpenThread defined error value otherwise
124      *
125      */
126     ClientError EnergyScan(uint32_t aScanDuration, const EnergyScanHandler &aHandler);
127 
128     /**
129      * This method attaches the device to the Thread network.
130      * @param[in] aNetworkName  The network name.
131      * @param[in] aPanId        The pan id, UINT16_MAX for random.
132      * @param[in] aExtPanId     The extended pan id, UINT64_MAX for random.
133      * @param[in] aNetworkKey   The network key, empty for random.
134      * @param[in] aPSKc         The pre-shared commissioner key, empty for random.
135      * @param[in] aChannelMask  A bitmask for valid channels, will random select one.
136      * @param[in] aHandler      The attach result handler.
137      *
138      * @retval ERROR_NONE  Successfully performed the dbus function call
139      * @retval ERROR_DBUS  dbus encode/decode error
140      * @retval ...         OpenThread defined error value otherwise
141      *
142      */
143     ClientError Attach(const std::string          &aNetworkName,
144                        uint16_t                    aPanId,
145                        uint64_t                    aExtPanId,
146                        const std::vector<uint8_t> &aNetworkKey,
147                        const std::vector<uint8_t> &aPSKc,
148                        uint32_t                    aChannelMask,
149                        const OtResultHandler      &aHandler);
150 
151     /**
152      * This method attaches the device to the Thread network.
153      *
154      * The network parameters will be set with the active dataset under this
155      * circumstance.
156      *
157      * @param[in] aHandler  The attach result handler.
158      *
159      * @retval ERROR_NONE  Successfully performed the dbus function call
160      * @retval ERROR_DBUS  dbus encode/decode error
161      * @retval ...         OpenThread defined error value otherwise
162      *
163      */
164     ClientError Attach(const OtResultHandler &aHandler);
165 
166     /**
167      * This method detaches the device from the Thread network.
168      *
169      * @retval ERROR_NONE  Successfully performed the dbus function call
170      * @retval ERROR_DBUS  dbus encode/decode error
171      * @retval ...         OpenThread defined error value otherwise
172      *
173      */
174     ClientError Detach(const OtResultHandler &aHandler);
175 
176     /**
177      * This method attaches the device to the specified Thread network.
178      *
179      * If the device has already attached to a network, send a request to migrate the existing network.
180      *
181      * @param[in] aDataset  The Operational Dataset that contains parameter values of the Thread network to attach
182      *                      to. It must have a valid Delay Timer and Pending Timestamp.
183      *
184      * @retval ERROR_NONE              Successfully requested the Thread network migration.
185      * @retval ERROR_DBUS              D-Bus encode/decode error.
186      * @retval OT_ERROR_REJECTED       The request was rejected by the leader.
187      * @retval OT_ERROR_FAILED         Failed to send the request.
188      * @retval OT_ERROR_INVALID_STATE  The device is attaching.
189      * @retval OT_ERROR_INVALID_ARGS   Arguments are invalid.
190      * @retval OT_ERROR_BUSY           There is an ongoing request.
191      *
192      */
193     ClientError AttachAllNodesTo(const std::vector<uint8_t> &aDataset);
194 
195     /**
196      * This method performs a factory reset.
197      *
198      * @param[in] aHandler  The reset result handler.
199      *
200      * @retval ERROR_NONE  Successfully performed the dbus function call
201      * @retval ERROR_DBUS  dbus encode/decode error
202      * @retval ...         OpenThread defined error value otherwise
203      *
204      */
205     ClientError FactoryReset(const OtResultHandler &aHandler);
206 
207     /**
208      * This method performs a soft reset.
209      *
210      * @retval ERROR_NONE  Successfully performed the dbus function call
211      * @retval ERROR_DBUS  dbus encode/decode error
212      * @retval ...         OpenThread defined error value otherwise
213      *
214      */
215     ClientError Reset(void);
216 
217     /**
218      * This method triggers a thread join process.
219      *
220      * @note The joiner start and the attach proccesses are exclusive
221      *
222      * @param[in] aPskd             The pre-shared key for device.
223      * @param[in] aProvisioningUrl  The provision url.
224      * @param[in] aVendorName       The vendor name.
225      * @param[in] aVendorModel      The vendor model.
226      * @param[in] aVendorSwVersion  The vendor software version.
227      * @param[in] aVendorData       The vendor custom data.
228      * @param[in] aHandler          The join result handler.
229      *
230      * @retval ERROR_NONE  Successfully performed the dbus function call
231      * @retval ERROR_DBUS  dbus encode/decode error
232      * @retval ...         OpenThread defined error value otherwise
233      *
234      */
235     ClientError JoinerStart(const std::string     &aPskd,
236                             const std::string     &aProvisioningUrl,
237                             const std::string     &aVendorName,
238                             const std::string     &aVendorModel,
239                             const std::string     &aVendorSwVersion,
240                             const std::string     &aVendorData,
241                             const OtResultHandler &aHandler);
242 
243     /**
244      * This method stops the joiner process
245      *
246      * @retval ERROR_NONE  Successfully performed the dbus function call
247      * @retval ERROR_DBUS  dbus encode/decode error
248      * @retval ...         OpenThread defined error value otherwise
249      *
250      */
251     ClientError JoinerStop(void);
252 
253     /**
254      * This method adds a on-mesh address prefix.
255      *
256      * @param[in] aPrefix  The address prefix.
257      *
258      * @retval ERROR_NONE  Successfully performed the dbus function call
259      * @retval ERROR_DBUS  dbus encode/decode error
260      * @retval ...         OpenThread defined error value otherwise
261      *
262      */
263     ClientError AddOnMeshPrefix(const OnMeshPrefix &aPrefix);
264 
265     /**
266      * This method removes a on-mesh address prefix.
267      *
268      * @param[in] aPrefix  The address prefix.
269      *
270      * @retval ERROR_NONE  Successfully performed the dbus function call
271      * @retval ERROR_DBUS  dbus encode/decode error
272      * @retval ...         OpenThread defined error value otherwise
273      *
274      */
275     ClientError RemoveOnMeshPrefix(const Ip6Prefix &aPrefix);
276 
277     /**
278      * This method adds an external route.
279      *
280      * @param[in] aExternalroute  The external route config
281      *
282      * @retval ERROR_NONE  Successfully performed the dbus function call
283      * @retval ERROR_DBUS  dbus encode/decode error
284      * @retval ...         OpenThread defined error value otherwise
285      *
286      */
287     ClientError AddExternalRoute(const ExternalRoute &aExternalRoute);
288 
289     /**
290      * This method removes an external route.
291      *
292      * @param[in] aPrefix  The route prefix.
293      *
294      * @retval ERROR_NONE  Successfully performed the dbus function call
295      * @retval ERROR_DBUS  dbus encode/decode error
296      * @retval ...         OpenThread defined error value otherwise
297      *
298      */
299     ClientError RemoveExternalRoute(const Ip6Prefix &aPrefix);
300 
301     /**
302      * This method sets the mesh-local prefix.
303      *
304      * @param[in] aPrefix The address prefix.
305      *
306      * @retval ERROR_NONE  Successfully performed the dbus function call
307      * @retval ERROR_DBUS  dbus encode/decode error
308      * @retval ...         OpenThread defined error value otherwise
309      *
310      */
311     ClientError SetMeshLocalPrefix(const std::array<uint8_t, OTBR_IP6_PREFIX_SIZE> &aPrefix);
312 
313     /**
314      * This method sets the active operational dataset.
315      *
316      * @param[out] aDataset  The active operational dataset
317      *
318      * @retval ERROR_NONE  Successfully performed the dbus function call
319      * @retval ERROR_DBUS  dbus encode/decode error
320      * @retval ...         OpenThread defined error value otherwise
321      *
322      */
323     ClientError SetActiveDatasetTlvs(const std::vector<uint8_t> &aDataset);
324 
325     /**
326      * This method sets the feature flag list data.
327      *
328      * @param[out] aFeatureFlagListData  The feature flag list proto serialized
329      *                                   byte data (see proto/feature_flag.proto)
330      *
331      * @retval ERROR_NONE  Successfully performed the dbus function call
332      * @retval ERROR_DBUS  dbus encode/decode error
333      * @retval ...         OpenThread defined error value otherwise
334      *
335      */
336     ClientError SetFeatureFlagListData(const std::vector<uint8_t> &aFeatureFlagListData);
337 
338     /**
339      * This method sets the link operating mode.
340      *
341      * @param[in] aConfig  The operating mode config.
342      *
343      * @retval ERROR_NONE  Successfully performed the dbus function call
344      * @retval ERROR_DBUS  dbus encode/decode error
345      * @retval ...         OpenThread defined error value otherwise
346      *
347      */
348     ClientError SetLinkMode(const LinkModeConfig &aConfig);
349 
350     /**
351      * This method sets the radio region.
352      *
353      * @param[in] aRadioRegion  The radio region.
354      *
355      * @retval ERROR_NONE  Successfully performed the dbus function call
356      * @retval ERROR_DBUS  dbus encode/decode error
357      * @retval ...         OpenThread defined error value otherwise
358      *
359      */
360     ClientError SetRadioRegion(const std::string &aRadioRegion);
361 
362     /**
363      * This method sets the NAT64 switch.
364      *
365      * @param[in] aEnable  A boolean to enable/disable the NAT64.
366      *
367      * @retval ERROR_NONE  Successfully performed the dbus function call
368      * @retval ERROR_DBUS  dbus encode/decode error
369      * @retval ...         OpenThread defined error value otherwise
370      *
371      */
372     ClientError SetNat64Enabled(bool aEnabled);
373 
374     /**
375      * This method gets the link operating mode.
376      *
377      * @param[out] aConfig  The operating mode config.
378      *
379      * @retval ERROR_NONE  Successfully performed the dbus function call
380      * @retval ERROR_DBUS  dbus encode/decode error
381      * @retval ...         OpenThread defined error value otherwise
382      *
383      */
384     ClientError GetLinkMode(LinkModeConfig &aConfig);
385 
386     /**
387      * This method gets the current device role.
388      *
389      * @param[out] aDeviceRole  The device role
390      *
391      * @retval ERROR_NONE  Successfully performed the dbus function call
392      * @retval ERROR_DBUS  dbus encode/decode error
393      * @retval ...         OpenThread defined error value otherwise
394      *
395      */
396     ClientError GetDeviceRole(DeviceRole &aDeviceRole);
397 
398     /**
399      * This method gets the network name.
400      *
401      * @param[out] aName  The network name.
402      *
403      * @retval ERROR_NONE  Successfully performed the dbus function call
404      * @retval ERROR_DBUS  dbus encode/decode error
405      * @retval ...         OpenThread defined error value otherwise
406      *
407      */
408     ClientError GetNetworkName(std::string &aName);
409 
410     /**
411      * This method gets the network pan id.
412      *
413      * @param[out] aPanId  The pan id.
414      *
415      * @retval ERROR_NONE  Successfully performed the dbus function call
416      * @retval ERROR_DBUS  dbus encode/decode error
417      * @retval ...         OpenThread defined error value otherwise
418      *
419      */
420     ClientError GetPanId(uint16_t &aPanId);
421 
422     /**
423      * This method gets the extended pan id.
424      *
425      * @param[out] aExtPanId  The extended pan id.
426      *
427      * @retval ERROR_NONE  Successfully performed the dbus function call
428      * @retval ERROR_DBUS  dbus encode/decode error
429      * @retval ...         OpenThread defined error value otherwise
430      *
431      */
432     ClientError GetExtPanId(uint64_t &aExtPanId);
433 
434     /**
435      * This method gets the extended pan id.
436      *
437      * @param[out] aChannel  The extended pan id.
438      *
439      * @retval ERROR_NONE  Successfully performed the dbus function call
440      * @retval ERROR_DBUS  dbus encode/decode error
441      * @retval ...         OpenThread defined error value otherwise
442      *
443      */
444     ClientError GetChannel(uint16_t &aChannel);
445 
446     /**
447      * This method gets the network network key.
448      *
449      * @param[out] aNetworkKey  The network network key.
450      *
451      * @retval ERROR_NONE  Successfully performed the dbus function call
452      * @retval ERROR_DBUS  dbus encode/decode error
453      * @retval ...         OpenThread defined error value otherwise
454      *
455      */
456     ClientError GetNetworkKey(std::vector<uint8_t> &aNetworkKey);
457 
458     /**
459      * This method gets the Clear Channel Assessment failure rate.
460      *
461      * @param[out] aFailureRate  The failure rate.
462      *
463      * @retval ERROR_NONE  Successfully performed the dbus function call
464      * @retval ERROR_DBUS  dbus encode/decode error
465      * @retval ...         OpenThread defined error value otherwise
466      *
467      */
468     ClientError GetCcaFailureRate(uint16_t &aFailureRate);
469 
470     /**
471      * This method gets the mac level statistics counters.
472      *
473      * @param[out] aCounters  The statistic counters.
474      *
475      * @retval ERROR_NONE  Successfully performed the dbus function call
476      * @retval ERROR_DBUS  dbus encode/decode error
477      * @retval ...         OpenThread defined error value otherwise
478      *
479      */
480     ClientError GetLinkCounters(MacCounters &aCounters); // For telemetry
481 
482     /**
483      * This method gets the ip level statistics counters.
484      *
485      * @param[out] aCounters  The statistic counters.
486      *
487      * @retval ERROR_NONE  Successfully performed the dbus function call
488      * @retval ERROR_DBUS  dbus encode/decode error
489      * @retval ...         OpenThread defined error value otherwise
490      *
491      */
492     ClientError GetIp6Counters(IpCounters &aCounters); // For telemetry
493 
494     /**
495      * This method gets the supported channel mask.
496      *
497      * @param[out] aChannelMask  The channel mask.
498      *
499      * @retval ERROR_NONE  Successfully performed the dbus function call
500      * @retval ERROR_DBUS  dbus encode/decode error
501      * @retval ...         OpenThread defined error value otherwise
502      *
503      */
504     ClientError GetSupportedChannelMask(uint32_t &aChannelMask);
505 
506     /**
507      * This method gets the preferred channel mask.
508      *
509      * @param[out] aChannelMask  The channel mask.
510      *
511      * @retval ERROR_NONE  Successfully performed the dbus function call
512      * @retval ERROR_DBUS  dbus encode/decode error
513      * @retval ...         OpenThread defined error value otherwise
514      *
515      */
516     ClientError GetPreferredChannelMask(uint32_t &aChannelMask);
517 
518     /**
519      * This method gets the Thread routing locator
520      *
521      * @param[out] aRloc16  The routing locator
522      *
523      * @retval ERROR_NONE  Successfully performed the dbus function call
524      * @retval ERROR_DBUS  dbus encode/decode error
525      * @retval ...         OpenThread defined error value otherwise
526      *
527      */
528     ClientError GetRloc16(uint16_t &aRloc16);
529 
530     /**
531      * This method gets 802.15.4 extended address
532      *
533      * @param[out] aExtendedAddress  The extended address
534      *
535      * @retval ERROR_NONE  Successfully performed the dbus function call
536      * @retval ERROR_DBUS  dbus encode/decode error
537      * @retval ...         OpenThread defined error value otherwise
538      *
539      */
540     ClientError GetExtendedAddress(uint64_t &aExtendedAddress);
541 
542     /**
543      * This method gets the node's router id.
544      *
545      * @param[out] aRouterId  The router id.
546      *
547      * @retval ERROR_NONE              Successfully performed the dbus function call.
548      * @retval ERROR_DBUS              dbus encode/decode error.
549      * @retval OT_ERROR_INVALID_STATE  The node is not a router.
550      * @retval ...                     OpenThread defined error value otherwise.
551      *
552      */
553     ClientError GetRouterId(uint8_t &aRouterId);
554 
555     /**
556      * This method gets the network's leader data.
557      *
558      * @param[out] aLeaderData  The leader data.
559      *
560      * @retval ERROR_NONE  Successfully performed the dbus function call
561      * @retval ERROR_DBUS  dbus encode/decode error
562      * @retval ...         OpenThread defined error value otherwise
563      *
564      */
565     ClientError GetLeaderData(LeaderData &aLeaderData);
566 
567     /**
568      * This method gets the network data.
569      *
570      * @param[out] aNetworkData  The network data.
571      *
572      * @retval ERROR_NONE  Successfully performed the dbus function call
573      * @retval ERROR_DBUS  dbus encode/decode error
574      * @retval ...         OpenThread defined error value otherwise
575      *
576      */
577     ClientError GetNetworkData(std::vector<uint8_t> &aNetworkData);
578 
579     /**
580      * This method gets the stable network data.
581      *
582      * @param[out] aNetworkData  The stable network data.
583      *
584      * @retval ERROR_NONE  Successfully performed the dbus function call
585      * @retval ERROR_DBUS  dbus encode/decode error
586      * @retval ...         OpenThread defined error value otherwise
587      *
588      */
589     ClientError GetStableNetworkData(std::vector<uint8_t> &aNetworkData);
590 
591     /**
592      * This method gets the node's local leader weight.
593      *
594      * @param[out] aWeight  The local leader weight.
595      *
596      * @retval ERROR_NONE  Successfully performed the dbus function call
597      * @retval ERROR_DBUS  dbus encode/decode error
598      * @retval ...         OpenThread defined error value otherwise
599      *
600      */
601     ClientError GetLocalLeaderWeight(uint8_t &aWeight);
602 
603     /**
604      * This method gets the channel monitor sample count.
605      *
606      * @param[out] aSampleCount  The channel monitor sample count.
607      *
608      * @retval ERROR_NONE  Successfully performed the dbus function call
609      * @retval ERROR_DBUS  dbus encode/decode error
610      * @retval ...         OpenThread defined error value otherwise
611      *
612      */
613     ClientError GetChannelMonitorSampleCount(uint32_t &aSampleCount);
614 
615     /**
616      * This method gets the channel qualities
617      *
618      * @param[out] aChannelQualities  The channel qualities.
619      *
620      * @retval ERROR_NONE  Successfully performed the dbus function call
621      * @retval ERROR_DBUS  dbus encode/decode error
622      * @retval ...         OpenThread defined error value otherwise
623      *
624      */
625     ClientError GetChannelMonitorAllChannelQualities(std::vector<ChannelQuality> &aChannelQualities);
626 
627     /**
628      * This method gets the child table.
629      *
630      * @param[out] aChildTable  The child table.
631      *
632      * @retval ERROR_NONE  Successfully performed the dbus function call
633      * @retval ERROR_DBUS  dbus encode/decode error
634      * @retval ...         OpenThread defined error value otherwise
635      *
636      */
637     ClientError GetChildTable(std::vector<ChildInfo> &aChildTable);
638 
639     /**
640      * This method gets the neighbor table.
641      *
642      * @param[out] aNeighborTable  The neighbor table.
643      *
644      * @retval ERROR_NONE  Successfully performed the dbus function call
645      * @retval ERROR_DBUS  dbus encode/decode error
646      * @retval ...         OpenThread defined error value otherwise
647      *
648      */
649     ClientError GetNeighborTable(std::vector<NeighborInfo> &aNeighborTable);
650 
651     /**
652      * This method gets the network's parition id.
653      *
654      * @param[out] aPartitionId  The partition id.
655      *
656      * @retval ERROR_NONE  Successfully performed the dbus function call
657      * @retval ERROR_DBUS  dbus encode/decode error
658      * @retval ...         OpenThread defined error value otherwise
659      *
660      */
661     ClientError GetPartitionId(uint32_t &aPartitionId);
662 
663     /**
664      * This method gets the rssi of the latest packet.
665      *
666      * @param[out] aRssi  The rssi of the latest packet.
667      *
668      * @retval ERROR_NONE  Successfully performed the dbus function call
669      * @retval ERROR_DBUS  dbus encode/decode error
670      * @retval ...         OpenThread defined error value otherwise
671      *
672      */
673     ClientError GetInstantRssi(int8_t &aRssi);
674 
675     /**
676      * This method gets the radio transmit power.
677      *
678      * @param[out] aTxPower  The radio transmit power.
679      *
680      * @retval ERROR_NONE  Successfully performed the dbus function call
681      * @retval ERROR_DBUS  dbus encode/decode error
682      * @retval ...         OpenThread defined error value otherwise
683      *
684      */
685     ClientError GetRadioTxPower(int8_t &aTxPower);
686 
687     /**
688      * This method gets the external route table
689      *
690      * @param[out] aExternalRoutes  The external route table
691      *
692      * @retval ERROR_NONE  Successfully performed the dbus function call
693      * @retval ERROR_DBUS  dbus encode/decode error
694      * @retval ...         OpenThread defined error value otherwise
695      *
696      */
697     ClientError GetExternalRoutes(std::vector<ExternalRoute> &aExternalRoutes);
698 
699     /**
700      * This method gets the on-mesh prefixes
701      *
702      * @param[out] aOnMeshPrefixes  The on-mesh prefixes
703      *
704      * @retval ERROR_NONE  Successfully performed the dbus function call
705      * @retval ERROR_DBUS  dbus encode/decode error
706      * @retval ...         OpenThread defined error value otherwise
707      *
708      */
709     ClientError GetOnMeshPrefixes(std::vector<OnMeshPrefix> &aOnMeshPrefixes);
710 
711     /**
712      * This method gets the active operational dataset
713      *
714      * @param[out] aDataset  The active operational dataset
715      *
716      * @retval ERROR_NONE  Successfully performed the dbus function call
717      * @retval ERROR_DBUS  dbus encode/decode error
718      * @retval ...         OpenThread defined error value otherwise
719      *
720      */
721     ClientError GetActiveDatasetTlvs(std::vector<uint8_t> &aDataset);
722 
723     /**
724      * This method gets the pending operational dataset
725      *
726      * @param[out] aDataset  The pending operational dataset
727      *
728      * @retval ERROR_NONE  Successfully performed the dbus function call
729      * @retval ERROR_DBUS  dbus encode/decode error
730      * @retval ...         OpenThread defined error value otherwise
731      *
732      */
733     ClientError GetPendingDatasetTlvs(std::vector<uint8_t> &aDataset);
734 
735     /**
736      * This method gets the feature flag list proto serialized byte data.
737      *
738      * @param[out] aFeatureFlagListData  The feature flag list proto serialized
739      *                                   byte data (see proto/feature_flag.proto)
740      *
741      * @retval ERROR_NONE  Successfully performed the dbus function call
742      * @retval ERROR_DBUS  dbus encode/decode error
743      * @retval ...         OpenThread defined error value otherwise
744      *
745      */
746     ClientError GetFeatureFlagListData(std::vector<uint8_t> &aFeatureFlagListData);
747 
748     /**
749      * This method gets the radio region.
750      *
751      * @param[out] aRadioRegion  The radio region.
752      *
753      * @retval ERROR_NONE  Successfully performed the dbus function call
754      * @retval ERROR_DBUS  dbus encode/decode error
755      * @retval ...         OpenThread defined error value otherwise
756      *
757      */
758     ClientError GetRadioRegion(std::string &aRadioRegion);
759 
760     /**
761      * This method gets the SRP server information.
762      *
763      * @param[out] aSrpServerInfo  The SRP server information.
764      *
765      * @retval ERROR_NONE  Successfully performed the dbus function call
766      * @retval ERROR_DBUS  dbus encode/decode error
767      * @retval ...         OpenThread defined error value otherwise
768      *
769      */
770     ClientError GetSrpServerInfo(SrpServerInfo &aSrpServerInfo);
771 
772 #if OTBR_ENABLE_TREL
773     /**
774      * This method gets the TREL information.
775      *
776      * @param[out] aTrelInfo  The TREL information.
777      *
778      * @retval ERROR_NONE  Successfully performed the dbus function call
779      * @retval ERROR_DBUS  dbus encode/decode error
780      * @retval ...         OpenThread defined error value otherwise
781      *
782      */
783     ClientError GetTrelInfo(TrelInfo &aTrelInfo);
784 #endif
785 
786     /**
787      * This method gets the MDNS telemetry information.
788      *
789      * @param[out] aMdnsTelemetryInfo  The MDNS telemetry information.
790      *
791      * @retval ERROR_NONE  Successfully performed the dbus function call
792      * @retval ERROR_DBUS  dbus encode/decode error
793      * @retval ...         OpenThread defined error value otherwise
794      *
795      */
796     ClientError GetMdnsTelemetryInfo(MdnsTelemetryInfo &aMdnsTelemetryInfo);
797 
798 #if OTBR_ENABLE_DNSSD_DISCOVERY_PROXY
799     /**
800      * This method gets the DNS-SD counters.
801      *
802      * @param[out] aDnssdCounters  The DNS-SD counters.
803      *
804      * @retval ERROR_NONE  Successfully performed the dbus function call
805      * @retval ERROR_DBUS  dbus encode/decode error
806      * @retval ...         OpenThread defined error value otherwise
807      *
808      */
809     ClientError GetDnssdCounters(DnssdCounters &aDnssdCounters);
810 #endif
811 
812     /**
813      * This method returns the network interface name the client is bound to.
814      *
815      * @returns The network interface name.
816      *
817      */
818     std::string GetInterfaceName(void);
819 
820     /**
821      * This method sets multiple vendor-specific entries for the TXT record of the MeshCoP service.
822      *
823      * @note
824      * - The @p aUpdate must contain all vendor-specific TXT entries you want to update. The latest call will supersede
825      * previous calls.
826      * - If @p aUpdate contains thread-specific entries like 'nn', 'at', the whole update will be rejected.
827      * - If @p aUpdate contains a key which is already published in TXT record, it will be updated according to @p
828      * aUpdate.
829      *
830      * @param[in] aUpdate  The updated key-value entries.
831      *
832      * @retval ERROR_NONE  Successfully performed the dbus function call
833      * @retval ERROR_DBUS  dbus encode/decode error
834      * @retval ...         OpenThread defined error value otherwise
835      *
836      */
837     ClientError UpdateVendorMeshCopTxtEntries(std::vector<TxtEntry> &aUpdate);
838 
839     /**
840      * This method gets the state of NAT64.
841      *
842      * @param[out] aState  The NAT64 state of each components.
843      *
844      * @retval ERROR_NONE  Successfully performed the dbus function call
845      * @retval ERROR_DBUS  dbus encode/decode error
846      * @retval ...         OpenThread defined error value otherwise
847      *
848      */
849     ClientError GetNat64State(Nat64ComponentState &aState);
850 
851     /**
852      * This method gets the active NAT64 mappings.
853      *
854      * @param[out] aMappings  The active NAT64 mappings.
855      *
856      * @retval ERROR_NONE  Successfully performed the dbus function call
857      * @retval ERROR_DBUS  dbus encode/decode error
858      * @retval ...         OpenThread defined error value otherwise
859      *
860      */
861     ClientError GetNat64Mappings(std::vector<Nat64AddressMapping> &aMappings);
862 
863     /**
864      * This method gets the NAT64 traffic counters.
865      *
866      * @param[out] aCounters  The NAT64 traffic counters.
867      *
868      * @retval ERROR_NONE  Successfully performed the dbus function call
869      * @retval ERROR_DBUS  dbus encode/decode error
870      * @retval ...         OpenThread defined error value otherwise
871      *
872      */
873     ClientError GetNat64ProtocolCounters(Nat64ProtocolCounters &aCounters);
874 
875     /**
876      * This method gets the NAT64 error counters.
877      *
878      * @param[out] aCounters  The NAT64 error counters.
879      *
880      * @retval ERROR_NONE  Successfully performed the dbus function call
881      * @retval ERROR_DBUS  dbus encode/decode error
882      * @retval ...         OpenThread defined error value otherwise
883      *
884      */
885     ClientError GetNat64ErrorCounters(Nat64ErrorCounters &aCounters);
886 
887     /**
888      * This method gets the telemetry data proto serialized byte data.
889      *
890      * @param[out] aTelemetryData  The telemetry data proto serialized
891      *                             byte data (see proto/thread_telemetry.proto)
892      *
893      * @retval ERROR_NONE  Successfully performed the dbus function call
894      * @retval ERROR_DBUS  dbus encode/decode error
895      * @retval ...         OpenThread defined error value otherwise
896      *
897      */
898     ClientError GetTelemetryData(std::vector<uint8_t> &aTelemetryData);
899 
900     /**
901      * This method gets the capabilities data proto serialized byte data.
902      *
903      * @param[out] aCapabilities The capabilities proto serialized byte data
904      *                           (see proto/capabilities.proto)
905      *
906      * @retval ERROR_NONE  Successfully performed the dbus function call
907      * @retval ERROR_DBUS  dbus encode/decode error
908      * @retval ...         OpenThread defined error value otherwise
909      *
910      */
911     ClientError GetCapabilities(std::vector<uint8_t> &aCapabilities);
912 
913 private:
914     ClientError CallDBusMethodSync(const std::string &aMethodName);
915     ClientError CallDBusMethodAsync(const std::string &aMethodName, DBusPendingCallNotifyFunction aFunction);
916 
917     template <typename ArgType> ClientError CallDBusMethodSync(const std::string &aMethodName, const ArgType &aArgs);
918 
919     template <typename ArgType>
920     ClientError CallDBusMethodAsync(const std::string            &aMethodName,
921                                     const ArgType                &aArgs,
922                                     DBusPendingCallNotifyFunction aFunction);
923 
924     template <typename ValType> ClientError SetProperty(const std::string &aPropertyName, const ValType &aValue);
925 
926     template <typename ValType> ClientError GetProperty(const std::string &aPropertyName, ValType &aValue);
927 
928     ClientError              SubscribeDeviceRoleSignal(void);
929     static DBusHandlerResult sDBusMessageFilter(DBusConnection *aConnection, DBusMessage *aMessage, void *aData);
930     DBusHandlerResult        DBusMessageFilter(DBusConnection *aConnection, DBusMessage *aMessage);
931 
932     template <void (ThreadApiDBus::*Handler)(DBusPendingCall *aPending)>
933     static void sHandleDBusPendingCall(DBusPendingCall *aPending, void *aThreadApiDBus);
934 
935     void        AttachPendingCallHandler(DBusPendingCall *aPending);
936     void        DetachPendingCallHandler(DBusPendingCall *aPending);
937     void        FactoryResetPendingCallHandler(DBusPendingCall *aPending);
938     void        JoinerStartPendingCallHandler(DBusPendingCall *aPending);
939     static void sScanPendingCallHandler(DBusPendingCall *aPending, void *aThreadApiDBus);
940     void        ScanPendingCallHandler(DBusPendingCall *aPending);
941     void        EnergyScanPendingCallHandler(DBusPendingCall *aPending);
942 
EmptyFree(void *)943     static void EmptyFree(void *)
944     {
945     }
946 
947     std::string mInterfaceName;
948 
949     DBusConnection *mConnection;
950 
951     ScanHandler       mScanHandler;
952     EnergyScanHandler mEnergyScanHandler;
953     OtResultHandler   mAttachHandler;
954     OtResultHandler   mDetachHandler;
955     OtResultHandler   mFactoryResetHandler;
956     OtResultHandler   mJoinerHandler;
957 
958     std::vector<DeviceRoleHandler> mDeviceRoleHandlers;
959 };
960 
961 } // namespace DBus
962 } // namespace otbr
963 
964 #endif // OTBR_THREAD_API_DBUS_HPP_
965