Skip to content

Commit

Permalink
[thread host] add ThreadHost data properties for BorderAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
Irving-cl committed Dec 10, 2024
1 parent 8bae59b commit 997610c
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/border_agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,12 @@ void AppendBbrTxtEntries(otInstance &aInstance, StateBitmap aState, Mdns::Publis
}
#endif

void AppendActiveTimestampTxtEntry(otInstance &aInstance, Mdns::Publisher::TxtList &aTxtList)
void AppendActiveTimestampTxtEntry(Ncp::ThreadHost &aHost, Mdns::Publisher::TxtList &aTxtList)
{
otError error;
otOperationalDataset activeDataset;

if ((error = otDatasetGetActive(&aInstance, &activeDataset)) != OT_ERROR_NONE)
if ((error = aHost.GetDatasetActive(activeDataset)) != OT_ERROR_NONE)
{
otbrLogWarning("Failed to get active dataset: %s", otThreadErrorToString(error));
}
Expand Down Expand Up @@ -513,9 +513,9 @@ void BorderAgent::PublishMeshCopService(void)
StateBitmap state;
uint32_t stateUint32;
otInstance *instance = mHost.GetInstance();
const otExtendedPanId *extPanId = otThreadGetExtendedPanId(instance);
const otExtAddress *extAddr = otLinkGetExtendedAddress(instance);
const char *networkName = otThreadGetNetworkName(instance);
const otExtendedPanId *extPanId = mHost.GetExtendedPanId();
const otExtAddress *extAddr = mHost.GetExtendedAddress();
const char *networkName = mHost.GetNetworkName();
Mdns::Publisher::TxtList txtList{{"rv", "1"}};
Mdns::Publisher::TxtData txtData;
int port;
Expand Down Expand Up @@ -569,7 +569,7 @@ void BorderAgent::PublishMeshCopService(void)
{
uint32_t partitionId;

AppendActiveTimestampTxtEntry(*instance, txtList);
AppendActiveTimestampTxtEntry(mHost, txtList);
partitionId = otThreadGetPartitionId(instance);
txtList.emplace_back("pt", reinterpret_cast<uint8_t *>(&partitionId), sizeof(partitionId));
}
Expand Down
34 changes: 34 additions & 0 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ uint32_t NcpNetworkProperties::GetPartitionId(void) const
return 0;
}

const otExtendedPanId *NcpNetworkProperties::GetExtendedPanId(void) const
{
// TODO: Implement the method under NCP mode.
return nullptr;
}

const otExtAddress *NcpNetworkProperties::GetExtendedAddress(void) const
{
// TODO: Implement the method under NCP mode.
return nullptr;
}

const char *NcpNetworkProperties::GetNetworkName(void) const
{
// TODO: Implement the method under NCP mode.
return nullptr;
}

void NcpNetworkProperties::SetDatasetActiveTlvs(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs)
{
mDatasetActiveTlvs.mLength = aActiveOpDatasetTlvs.mLength;
Expand All @@ -91,6 +109,22 @@ void NcpNetworkProperties::GetDatasetPendingTlvs(otOperationalDatasetTlvs &aData
OTBR_UNUSED_VARIABLE(aDatasetTlvs);
}

otError NcpNetworkProperties::GetDatasetActive(otOperationalDataset &aDataset) const
{
otError error = OT_ERROR_NONE;

if (mDatasetActiveTlvs.mLength == 0)
{
error = OT_ERROR_NOT_FOUND;
}
else
{
error = otDatasetParseTlvs(&mDatasetActiveTlvs, &aDataset);
}

return error;
}

// ===================================== NcpHost ======================================

NcpHost::NcpHost(const char *aInterfaceName, const char *aBackboneInterfaceName, bool aDryRun)
Expand Down
14 changes: 9 additions & 5 deletions src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ class NcpNetworkProperties : virtual public NetworkProperties, public PropsObser
explicit NcpNetworkProperties(void);

// NetworkProperties methods
otDeviceRole GetDeviceRole(void) const override;
bool Ip6IsEnabled(void) const override;
uint32_t GetPartitionId(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
void GetDatasetPendingTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
otDeviceRole GetDeviceRole(void) const override;
bool Ip6IsEnabled(void) const override;
uint32_t GetPartitionId(void) const override;
const otExtendedPanId *GetExtendedPanId(void) const override;
const otExtAddress *GetExtendedAddress(void) const override;
const char *GetNetworkName(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
otError GetDatasetActive(otOperationalDataset &aDataset) const override;
void GetDatasetPendingTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;

private:
// PropsObserver methods
Expand Down
20 changes: 20 additions & 0 deletions src/ncp/rcp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ uint32_t OtNetworkProperties::GetPartitionId(void) const
return otThreadGetPartitionId(mInstance);
}

const otExtendedPanId *OtNetworkProperties::GetExtendedPanId(void) const
{
return otThreadGetExtendedPanId(mInstance);
}

const otExtAddress *OtNetworkProperties::GetExtendedAddress(void) const
{
return otLinkGetExtendedAddress(mInstance);
}

const char *OtNetworkProperties::GetNetworkName(void) const
{
return otThreadGetNetworkName(mInstance);
}

void OtNetworkProperties::GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const
{
otError error = otDatasetGetActiveTlvs(mInstance, &aDatasetTlvs);
Expand All @@ -100,6 +115,11 @@ void OtNetworkProperties::GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatase
}
}

otError OtNetworkProperties::GetDatasetActive(otOperationalDataset &aDataset) const
{
return otDatasetGetActive(mInstance, &aDataset);
}

void OtNetworkProperties::GetDatasetPendingTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const
{
otError error = otDatasetGetPendingTlvs(mInstance, &aDatasetTlvs);
Expand Down
14 changes: 9 additions & 5 deletions src/ncp/rcp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ class OtNetworkProperties : virtual public NetworkProperties
explicit OtNetworkProperties(void);

// NetworkProperties methods
otDeviceRole GetDeviceRole(void) const override;
bool Ip6IsEnabled(void) const override;
uint32_t GetPartitionId(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
void GetDatasetPendingTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
otDeviceRole GetDeviceRole(void) const override;
bool Ip6IsEnabled(void) const override;
uint32_t GetPartitionId(void) const override;
const otExtendedPanId *GetExtendedPanId(void) const override;
const otExtAddress *GetExtendedAddress(void) const override;
const char *GetNetworkName(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;
otError GetDatasetActive(otOperationalDataset &aDataset) const override;
void GetDatasetPendingTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;

// Set the otInstance
void SetInstance(otInstance *aInstance);
Expand Down
31 changes: 31 additions & 0 deletions src/ncp/thread_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,44 @@ class NetworkProperties
*/
virtual uint32_t GetPartitionId(void) const = 0;

/**
* Returns the extended Pan ID.
*
* @returns The extended Pan ID.
*/
virtual const otExtendedPanId *GetExtendedPanId(void) const = 0;

/**
* Returns the extended address.
*
* @returns The extended address.
*/
virtual const otExtAddress *GetExtendedAddress(void) const = 0;

/**
* Returns the network name.
*
* @returns The network name.
*/
virtual const char *GetNetworkName(void) const = 0;

/**
* Returns the active operational dataset tlvs.
*
* @param[out] aDatasetTlvs A reference to where the Active Operational Dataset will be placed.
*/
virtual void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const = 0;

/**
* Returns the active operational dataset.
*
* @param[out] aDataset A reference to where the Active Operational Dataset will be placed.
*
* @retval OT_ERROR_NONE Successfully retrieved the Active Operational Dataset.
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
*/
virtual otError GetDatasetActive(otOperationalDataset &aDataset) const = 0;

/**
* Returns the pending operational dataset tlvs.
*
Expand Down

0 comments on commit 997610c

Please sign in to comment.