# Border Agent Tracker

# Border Agent Tracker

This module includes APIs for the Border Agent Tracker.

## Summary

The Border Agent Tracker discovers and tracks Border Agents on the infrastructure link by browsing for the `_meshcop._udp` mDNS service.

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga903a0cfe1ab67024f2d8f57f44da9c44` | typedef `struct https://openthread.io/reference/struct/ot-border-agent-tracker-agent-info` Represents information about a discovered Border Agent. |
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga825286ee4ff7abf95e82dc8d5bcb7a02` | typedef `struct https://openthread.io/reference/struct/ot-border-agent-tracker-iterator` Represents an iterator to iterate through the discovered Border Agents. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1gabc53b0fa8f0ba8053f9e05b3528a3527(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-border-agent-tracker-iterator *aIterator, https://openthread.io/reference/struct/ot-border-agent-tracker-agent-info *aAgentInfo)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Gets the information for the next discovered Border Agent. |
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga2dcb1a2193003f096e571cce8f2efc16(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-border-agent-tracker-iterator *aIterator)` | `void` Initializes a Border Agent Tracker iterator. |
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga93faed8c13fa8043d4c941961c0e0f0a(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `bool` Indicates whether the Border Agent Tracker is running. |
| `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga8c2381734a39a4ea2164617d2dd594fe(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, bool aEnable)` | `void` Enables or disables the Border Agent Tracker. |

| ### Structs ||
|---|---|
| [otBorderAgentTrackerAgentInfo](https://openthread.io/reference/struct/ot-border-agent-tracker-agent-info) | Represents information about a discovered Border Agent. |
| [otBorderAgentTrackerIterator](https://openthread.io/reference/struct/ot-border-agent-tracker-iterator) | Represents an iterator to iterate through the discovered Border Agents. |

## Typedefs

### otBorderAgentTrackerAgentInfo

```
struct otBorderAgentTrackerAgentInfo otBorderAgentTrackerAgentInfo
```
Represents information about a discovered Border Agent.

To ensure consistent `mMsecSinceDiscovered` and `mMsecSinceLastChange` time calculations, the iterator's initialization time is stored within the iterator when `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga2dcb1a2193003f096e571cce8f2efc16` is called. The time values in this struct are calculated relative to the iterator's initialization time.

### otBorderAgentTrackerIterator

```
struct otBorderAgentTrackerIterator otBorderAgentTrackerIterator
```
Represents an iterator to iterate through the discovered Border Agents.

The fields in this struct are for OpenThread internal use only and MUST NOT be accessed or modified by the caller.

An iterator MUST be initialized using `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga2dcb1a2193003f096e571cce8f2efc16` before it is used.

## Functions

### otBorderAgentTrackerGetNextAgent

```
otError otBorderAgentTrackerGetNextAgent(
  otInstance *aInstance,
  otBorderAgentTrackerIterator *aIterator,
  otBorderAgentTrackerAgentInfo *aAgentInfo
)
```
Gets the information for the next discovered Border Agent.

Requires `OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE`.

The iterator initialization time is used to determine the `mMsecSinceDiscovered` and `mMsecSinceLastChange` in the `https://openthread.io/reference/struct/ot-border-agent-tracker-agent-info`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in,out] aIterator` | A pointer to the iterator. An iterator MUST be initialized using `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga2dcb1a2193003f096e571cce8f2efc16` before it is used. | | `[out] aAgentInfo` | A pointer to an `https://openthread.io/reference/struct/ot-border-agent-tracker-agent-info` struct to populate. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully retrieved the information for the next agent. | | `OT_ERROR_NOT_FOUND` | No more agents were found. | |

### otBorderAgentTrackerInitIterator

```
void otBorderAgentTrackerInitIterator(
  otInstance *aInstance,
  otBorderAgentTrackerIterator *aIterator
)
```
Initializes a Border Agent Tracker iterator.

Requires `OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE`.

An iterator MUST be initialized before being used.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aIterator` | A pointer to the iterator to initialize. | |

### otBorderAgentTrackerIsRunning

```
bool otBorderAgentTrackerIsRunning(
  otInstance *aInstance
)
```
Indicates whether the Border Agent Tracker is running.

Requires `OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE`.

The tracker can be enabled by the user (via `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga8c2381734a39a4ea2164617d2dd594fe`) or by the OpenThread stack itself. The tracker is considered running if it is enabled by either entity AND the underlying DNS-SD (mDNS) is ready. This means that `https://openthread.io/reference/group/api-border-agent-tracker#group__api-border-agent-tracker_1ga93faed8c13fa8043d4c941961c0e0f0a` may not return `TRUE` immediately after a call to `otBorderAgentTrackerSetEnabled(true)`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | |
| Return Values | |---|---| | `TRUE` | If the tracker is running. | | `FALSE` | If the tracker is not running. | |

### otBorderAgentTrackerSetEnabled

```
void otBorderAgentTrackerSetEnabled(
  otInstance *aInstance,
  bool aEnable
)
```
Enables or disables the Border Agent Tracker.

Requires `OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE`.

When enabled, the tracker browses for the `_meshcop._udp` mDNS service to discover and track Border Agents on the infra-if network.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aEnable` | TRUE to enable the Border Agent Tracker, FALSE to disable it. | |

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).