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 the d-bus object of OpenThread service. 32 */ 33 34 #ifndef OTBR_DBUS_THREAD_OBJECT_HPP_ 35 #define OTBR_DBUS_THREAD_OBJECT_HPP_ 36 37 #include <string> 38 39 #include <openthread/link.h> 40 41 #include "dbus/server/dbus_object.hpp" 42 #include "mdns/mdns.hpp" 43 #include "ncp/ncp_openthread.hpp" 44 45 namespace otbr { 46 namespace DBus { 47 48 /** 49 * @addtogroup border-router-dbus-server 50 * 51 * @brief 52 * This module includes the <a href="dbus-api.html">dbus server api</a>. 53 * 54 * @{ 55 * @} 56 * 57 */ 58 59 class DBusAgent; 60 61 class DBusThreadObject : public DBusObject 62 { 63 public: 64 /** 65 * This constructor of dbus thread object. 66 * 67 * @param[in] aConnection The dbus connection. 68 * @param[in] aInterfaceName The dbus interface name. 69 * @param[in] aNcp The ncp controller 70 * @param[in] aPublisher The Mdns::Publisher 71 * 72 */ 73 DBusThreadObject(DBusConnection * aConnection, 74 const std::string & aInterfaceName, 75 otbr::Ncp::ControllerOpenThread *aNcp, 76 Mdns::Publisher * aPublisher); 77 78 otbrError Init(void) override; 79 80 void RegisterGetPropertyHandler(const std::string & aInterfaceName, 81 const std::string & aPropertyName, 82 const PropertyHandlerType &aHandler) override; 83 84 private: 85 void DeviceRoleHandler(otDeviceRole aDeviceRole); 86 void ActiveDatasetChangeHandler(const otOperationalDatasetTlvs &aDatasetTlvs); 87 void NcpResetHandler(void); 88 89 void ScanHandler(DBusRequest &aRequest); 90 void EnergyScanHandler(DBusRequest &aRequest); 91 void AttachHandler(DBusRequest &aRequest); 92 void AttachAllNodesToHandler(DBusRequest &aRequest); 93 void DetachHandler(DBusRequest &aRequest); 94 void LeaveHandler(DBusRequest &aRequest); 95 void FactoryResetHandler(DBusRequest &aRequest); 96 void ResetHandler(DBusRequest &aRequest); 97 void JoinerStartHandler(DBusRequest &aRequest); 98 void JoinerStopHandler(DBusRequest &aRequest); 99 void PermitUnsecureJoinHandler(DBusRequest &aRequest); 100 void AddOnMeshPrefixHandler(DBusRequest &aRequest); 101 void RemoveOnMeshPrefixHandler(DBusRequest &aRequest); 102 void AddExternalRouteHandler(DBusRequest &aRequest); 103 void RemoveExternalRouteHandler(DBusRequest &aRequest); 104 void UpdateMeshCopTxtHandler(DBusRequest &aRequest); 105 void GetPropertiesHandler(DBusRequest &aRequest); 106 107 void IntrospectHandler(DBusRequest &aRequest); 108 109 otError SetMeshLocalPrefixHandler(DBusMessageIter &aIter); 110 otError SetLegacyUlaPrefixHandler(DBusMessageIter &aIter); 111 otError SetLinkModeHandler(DBusMessageIter &aIter); 112 otError SetActiveDatasetTlvsHandler(DBusMessageIter &aIter); 113 otError SetRadioRegionHandler(DBusMessageIter &aIter); 114 115 otError GetLinkModeHandler(DBusMessageIter &aIter); 116 otError GetDeviceRoleHandler(DBusMessageIter &aIter); 117 otError GetNetworkNameHandler(DBusMessageIter &aIter); 118 otError GetPanIdHandler(DBusMessageIter &aIter); 119 otError GetExtPanIdHandler(DBusMessageIter &aIter); 120 otError GetEui64Handler(DBusMessageIter &aIter); 121 otError GetChannelHandler(DBusMessageIter &aIter); 122 otError GetNetworkKeyHandler(DBusMessageIter &aIter); 123 otError GetCcaFailureRateHandler(DBusMessageIter &aIter); 124 otError GetLinkCountersHandler(DBusMessageIter &aIter); 125 otError GetIp6CountersHandler(DBusMessageIter &aIter); 126 otError GetSupportedChannelMaskHandler(DBusMessageIter &aIter); 127 otError GetRloc16Handler(DBusMessageIter &aIter); 128 otError GetExtendedAddressHandler(DBusMessageIter &aIter); 129 otError GetRouterIdHandler(DBusMessageIter &aIter); 130 otError GetLeaderDataHandler(DBusMessageIter &aIter); 131 otError GetNetworkDataHandler(DBusMessageIter &aIter); 132 otError GetStableNetworkDataHandler(DBusMessageIter &aIter); 133 otError GetLocalLeaderWeightHandler(DBusMessageIter &aIter); 134 otError GetChannelMonitorSampleCountHandler(DBusMessageIter &aIter); 135 otError GetChannelMonitorAllChannelQualities(DBusMessageIter &aIter); 136 otError GetChildTableHandler(DBusMessageIter &aIter); 137 otError GetNeighborTableHandler(DBusMessageIter &aIter); 138 otError GetPartitionIDHandler(DBusMessageIter &aIter); 139 otError GetInstantRssiHandler(DBusMessageIter &aIter); 140 otError GetRadioTxPowerHandler(DBusMessageIter &aIter); 141 otError GetExternalRoutesHandler(DBusMessageIter &aIter); 142 otError GetOnMeshPrefixesHandler(DBusMessageIter &aIter); 143 otError GetActiveDatasetTlvsHandler(DBusMessageIter &aIter); 144 otError GetRadioRegionHandler(DBusMessageIter &aIter); 145 otError GetSrpServerInfoHandler(DBusMessageIter &aIter); 146 otError GetMdnsTelemetryInfoHandler(DBusMessageIter &aIter); 147 otError GetDnssdCountersHandler(DBusMessageIter &aIter); 148 otError GetOtHostVersionHandler(DBusMessageIter &aIter); 149 otError GetOtRcpVersionHandler(DBusMessageIter &aIter); 150 otError GetThreadVersionHandler(DBusMessageIter &aIter); 151 otError GetRadioSpinelMetricsHandler(DBusMessageIter &aIter); 152 otError GetRcpInterfaceMetricsHandler(DBusMessageIter &aIter); 153 otError GetUptimeHandler(DBusMessageIter &aIter); 154 otError GetRadioCoexMetrics(DBusMessageIter &aIter); 155 156 void ReplyScanResult(DBusRequest &aRequest, otError aError, const std::vector<otActiveScanResult> &aResult); 157 void ReplyEnergyScanResult(DBusRequest &aRequest, otError aError, const std::vector<otEnergyScanResult> &aResult); 158 159 otbr::Ncp::ControllerOpenThread * mNcp; 160 std::unordered_map<std::string, PropertyHandlerType> mGetPropertyHandlers; 161 otbr::Mdns::Publisher * mPublisher; 162 }; 163 164 } // namespace DBus 165 } // namespace otbr 166 167 #endif // OTBR_DBUS_THREAD_OBJECT_HPP_ 168