Skip to content

Commit

Permalink
[dbus] add Join and SetThreadEnabled method to Dbus RCP (#2690)
Browse files Browse the repository at this point in the history
This commit adds DBus methods 'Join' and 'SetThreadEnabled' under RCP
mode.

The background is to support these basic methods for both NCP & RCP
mode so that we can write some test scripts that work for both NCP &
RCP mode. For the long term, we also try to let NCP & RCP support the
same DBus interfaces.
  • Loading branch information
Irving-cl authored Feb 5, 2025
1 parent 8bdb068 commit b555318
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dbus/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define OTBR_DBUS_ENERGY_SCAN_METHOD "EnergyScan"
#define OTBR_DBUS_ATTACH_METHOD "Attach"
#define OTBR_DBUS_DETACH_METHOD "Detach"
#define OTBR_DBUS_SET_THREAD_ENABLED_METHOD "SetThreadEnabled"
#define OTBR_DBUS_JOIN_METHOD "Join"
#define OTBR_DBUS_FACTORY_RESET_METHOD "FactoryReset"
#define OTBR_DBUS_RESET_METHOD "Reset"
Expand Down
50 changes: 50 additions & 0 deletions src/dbus/server/dbus_thread_object_rcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ otbrError DBusThreadObjectRcp::Init(void)
std::bind(&DBusThreadObjectRcp::UpdateMeshCopTxtHandler, this, _1));
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_GET_PROPERTIES_METHOD,
std::bind(&DBusThreadObjectRcp::GetPropertiesHandler, this, _1));
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_SET_THREAD_ENABLED_METHOD,
std::bind(&DBusThreadObjectRcp::SetThreadEnabledHandler, this, _1));
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_JOIN_METHOD,
std::bind(&DBusThreadObjectRcp::JoinHandler, this, _1));
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_LEAVE_NETWORK_METHOD,
std::bind(&DBusThreadObjectRcp::LeaveNetworkHandler, this, _1));
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_SET_NAT64_ENABLED_METHOD,
Expand Down Expand Up @@ -1759,6 +1763,52 @@ void DBusThreadObjectRcp::ActiveDatasetChangeHandler(const otOperationalDatasetT
SignalPropertyChanged(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_ACTIVE_DATASET_TLVS, value);
}

void DBusThreadObjectRcp::SetThreadEnabledHandler(DBusRequest &aRequest)
{
otError error = OT_ERROR_NONE;
bool enable = false;
auto args = std::tie(enable);

SuccessOrExit(DBusMessageToTuple(*aRequest.GetMessage(), args), error = OT_ERROR_INVALID_ARGS);

mHost.SetThreadEnabled(enable, [aRequest](otError aError, const std::string &aErrorInfo) mutable {
OT_UNUSED_VARIABLE(aErrorInfo);
aRequest.ReplyOtResult(aError);
});

exit:
if (error != OT_ERROR_NONE)
{
aRequest.ReplyOtResult(error);
}
}

void DBusThreadObjectRcp::JoinHandler(DBusRequest &aRequest)
{
std::vector<uint8_t> dataset;
otOperationalDatasetTlvs activeOpDatasetTlvs;
otError error = OT_ERROR_NONE;

auto args = std::tie(dataset);

SuccessOrExit(DBusMessageToTuple(*aRequest.GetMessage(), args), error = OT_ERROR_INVALID_ARGS);

VerifyOrExit(dataset.size() <= sizeof(activeOpDatasetTlvs.mTlvs), error = OT_ERROR_INVALID_ARGS);
std::copy(dataset.begin(), dataset.end(), activeOpDatasetTlvs.mTlvs);
activeOpDatasetTlvs.mLength = dataset.size();

mHost.Join(activeOpDatasetTlvs, [aRequest](otError aError, const std::string &aErrorInfo) mutable {
OT_UNUSED_VARIABLE(aErrorInfo);
aRequest.ReplyOtResult(aError);
});

exit:
if (error != OT_ERROR_NONE)
{
aRequest.ReplyOtResult(error);
}
}

void DBusThreadObjectRcp::LeaveNetworkHandler(DBusRequest &aRequest)
{
constexpr int kExitCodeShouldRestart = 7;
Expand Down
2 changes: 2 additions & 0 deletions src/dbus/server/dbus_thread_object_rcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class DBusThreadObjectRcp : public DBusObject
void AddExternalRouteHandler(DBusRequest &aRequest);
void RemoveExternalRouteHandler(DBusRequest &aRequest);
void UpdateMeshCopTxtHandler(DBusRequest &aRequest);
void SetThreadEnabledHandler(DBusRequest &aRequest);
void JoinHandler(DBusRequest &aRequest);
void GetPropertiesHandler(DBusRequest &aRequest);
void LeaveNetworkHandler(DBusRequest &aRequest);
void SetNat64Enabled(DBusRequest &aRequest);
Expand Down

0 comments on commit b555318

Please sign in to comment.