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