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