Expand description
§OpenThread API Module
This module contains (mostly) type-safe versions of the OpenThread API, excluding the platform API.
§Type Safety
Full type safety for an API which wasn’t created for type safety is hard. There are some
operations which feel like they should be fully safe but are ultimately marked as unsafe
because it might be possible to abuse in some way that causes undefined behavior.
§Types
Each enum, struct, or object in the OpenThread C API is associated with a safe Rust equivalent. For example:
§Ownership
Some OpenThread API objects, like otsys::otInstance
and
otsys::otMessage
have hidden implementations and explicit ownership
transfer. That means we must have a notation which is capable of both “owned” instances
and “borrowed” references.
The rust equivalent of passing around a pointer to one of thse
objects would be to pass around a reference: otInstance*
becomes a &ot::Instance
.
Owned instances are “boxed” into a ot::Box
, so an owned otInstance*
would become
a ot::Box<ot::Instance>
, or a OtInstanceBox
for short. When the box
goes out of scope, the appropriate OpenThread C finalization API is called.
§Singleton/Multiple OpenThread Instances
OpenThread can be compiled to either only support a singleton instance or to support multiple independent OpenThread instances.
Currently, this crate only supports a singleton OpenThread instance. Attempting to create more than one OpenThread instance at a time will result in a runtime panic.
§Traits
The OpenThread API is broken down into “modules” of functionality containing types and related methods. Similarly, this Rust interface breaks down functionality into traits. This allows parts of the OpenThread API to be substituted with mocked versions for unit testing.
§Callbacks
In most cases, you register a callback by passing a closure to the appropriate callback registration API.
§Platform Implementations
This crate doesn’t directly provide the platform implementations for OpenThread—that needs to come from either a separate library or the program which is using this crate.
Re-exports§
pub use message::Message;
pub use message::MessageBuffer;
Modules§
- message
- Module for all things related to OpenThread messages.
Structs§
- Active
Scan Result - This structure holds information about a network beacon discovered during an active scan.
- Address
Origin - Type representing the origin of an address
- Backbone
Router Multicast Listener Info - Functional equivalent of
otsys::otBackboneRouterMUlticastListenerInfo
. - BadSystem
Time - Error type for when a system time cannot be converted to a timestamp.
- Border
Router Config - Functional equivalent of
otsys::otBorderRouterConfig
. - Border
Routing Counters - This structure represents border routing counters.
- Border
Routing Dhcp6 PdState Changed Stream - Stream for getting state changed events.
- Border
Routing Prefix Table Entry - Represents an entry from the discovered prefix table.
Functional equivalent of
otsys::otBorderRoutingPrefixTableEntry
. - Box
- A box for owning pointers to opaque types vended from the OpenThread API.
- Changed
Flags - Channel
Mask - Type representing a set of radio channels.
- Channel
OutOf Range - Error type for when a given channel index is out of range.
- DnsTxt
Entry - Functional equivalent of
otsys::otDnsTxtEntry
. - DnsTxt
Entry Iterator - Functional equivalent of
otsys::otDnsTxtEntryIterator
. - Dnssd
Counters - This structure represents DNS-SD server counters.
- Dnssd
Query - Functional equivalent of
otDnssdQuery
- Dnssd
Query Iterator - Iterator type for DNS-SD Queries
- Energy
Scan Result - This structure holds information about energy levels detected on a channel.
- ExtAddress
- Data type representing a EUI64 address.
Functional equivalent of
otsys::otExtAddress
. - Extended
PanId - Data type representing an extended PAN-ID.
Functional equivalent of
otsys::otExtendedPanId
. - External
Route Config - Data type representing an external route configuration.
Functional equivalent of
otsys::otExternalRouteConfig
. - Instance
- OpenThread instance.
- Ip4Cidr
- Data type representing an IPv4 CIDR.
- Ip6Address
Info - Data type representing IPv6 address information.
- Ip6Network
Prefix - Data type representing a 64-bit IPv6 network prefix.
- Ip6Prefix
- IPv6 subnet prefix with an arbitrary prefix length.
Functional equivalent of
otsys::otIp6Prefix
. - IpCounters
- This structure represents the IP layer counters.
- Leader
Data - This structure represents the Thread Leader Data.
- Link
Metrics Values - Represents the result (value) for a Link Metrics query.
- Link
Mode Config - Link Mode Config.
Functional equivalent of
otsys::otLinkModeConfig
. - Local
External Route Iterator - Iterator type for external routes.
- Local
OnMesh Prefix Iterator - Iterator type for on-mesh prefixes.
- MacCounters
- This structure represents the MAC layer counters.
- Malformed
OrNo Bufs - Error type for when an IPv6 header is malformed or there are no buffers to allocate.
- Meshcop
TlvIterator - An iterator type for parsing OpenThread TLV data.
- Multicast
Listener Iterator - Iterator type for multicast listeners.
- Nat64
Address Mapping - NAT64 Address Mapping, which is part of NAT64 telemetry
- Nat64
Address Mapping Iterator - NAT64 Address Mapping iterator
- Nat64
Counters - Represents the counters for NAT64
- Nat64
Error Counters - Represents the error counters for NAT64
- Nat64
Protocol Counters - Counters for sum of all protocols for NAT64
- Neighbor
Info - This structure holds diagnostic information for a neighboring Thread node.
- Neighbor
Info Iterator - Iterator type for neighbor info
- Netif
Address - Data type representing IPv6 address from a network interface.
Functional equivalent of
otsys::otNetifAddress
. - Netif
Address Iterator - Iterates over the
NetifAddress
structs fromIp6::ip6_get_unicast_addresses()
. - Network
Key - Network Key.
Functional equivalent of
otsys::otNetworkKey
. - Network
Name - Network Name.
Functional equivalent of
otsys::otNetworkName
. - NoBufs
- Error type for when there are no buffers to allocate.
- Null
Platform - Platform instance which does nothing.
- Operational
Dataset - Functional equivalent of
otsys::otOperationalDataset
. - Operational
Dataset Tlvs - Functional equivalent of
otsys::otOperationalDatasetTlvs
. - Packets
AndBytes - This structure represents counters for packets and bytes.
- Parse
Error - Error type for when there is some sort of parsing error.
- PdProcessed
RaInfo - This structure represents border routing counters.
- Plat
DnsUpstream Query - This structure represents the DNS Upstream Query context.
- Plat
Trel Peer Info - Functional equivalent of
otsys::otPlatTrelPeerInfo
. - Pskc
- PSKC. Functional equivalent of
otsys::otPskc
. - Radio
Coex Metrics - This structure represents radio coexistence metrics.
- Radio
Region - Represents a radio regulatory region/domain.
- Router
Info - Functional equivalent of
otsys::otRouterInfo
. - Scope
- Type representing an IPv6 scope, as represented on IPv6 multicast addresses.
- Security
Policy - Functional equivalent of
otsys::otSecurityPolicy
. - Sock
Addr - Functional equivalent of
otsys::otSockAddr
. - SrpServer
Host - This opaque type (only used by reference) represents a SRP host.
- SrpServer
Host Iterator - Iterates over the available SRP server hosts. See [
SrpServer::srp_server_get_hosts
]. - SrpServer
Lease Info - This structure represents the SRP Server Lease Info.
- SrpServer
Response Counters - This structure represents SRP server response counters.
- SrpServer
Service - This opaque type (only used by reference) represents a SRP service.
- SrpServer
Service Iterator - Iterates over all the available SRP services.
- SrpServer
Service Subtype Iterator - Iterates over all the available SRP services subtypes.
- SrpServer
Service Update Id - The ID of a SRP service update transaction on the SRP Server.
- State
Changed Stream - Stream for getting state changed events.
- Tasklets
Stream - Provides an asynchronous interface to
ot::Tasklets
. - Timestamp
- Type representing a Thread timestamp.
- Trel
Counters - This structure represents the Thread TREL counters.
- UdpSocket
- Functional equivalent of
otsys::otUdpSocket
. - UdpSocket
Iterator - Iterates over the available UDP sockets. See
Udp::udp_get_sockets
. - Upstream
DnsCounters - Represents the count of queries, responses, failures handled by upstream DNS server
- Wrong
Size - Error type for when a slice is not the correct size.
Enums§
- Backbone
Router Multicast Listener Event - Represents a Thread device role.
- Border
Agent State - Represents the thread joiner state.
- Border
Routing Dhcp6 PdState - This enumeration represents the state of DHCPv6 Prefix Delegation State.
- Device
Role - Represents a Thread device role.
- Dnssd
Query Type - Represents the type of a DNS query
- Error
- Error type for OpenThread calls. Functional equivalent of
otsys::otError
. - Icmp6
Echo Mode - Functional equivalent of
otsys::otIcmp6EchoMode
. - Joiner
State - Represents the thread joiner state.
- LogLevel
- Logging Level.
Functional equivalent of
otsys::otLogLevel
. - LogRegion
- Logging Region.
Functional equivalent of
otsys::otLogRegion
. - Meshcop
Tlv - Represents a type-length-value (TLV) item.
- Nat64
State - Represents a NAT64 Translator State.
- Netif
Identifier - This enumeration defines the OpenThread network interface identifiers.
- Route
Preference - Route Preference, as defined in RFC4191 Section 2.1.
- SrpServer
Address Mode - Represents the SRP server address mode.
- SrpServer
State - Represents the SRP server state.
- Thread
Version - Represents the thread version
Constants§
- DECIBELS_
UNSPECIFIED - Unspecified power
- IP6_
PREFIX_ BITSIZE - Functional equivalent of
otsys::OT_IP6_PREFIX_BITSIZE
. - MAX_
CHILD_ ID - The largest child ID supported by OpenThread, 511.
- MAX_
NET_ DATA_ LEN - The maximum length of Thread network data, in bytes.
- MAX_
NUM_ CHANNELS - The maximum number of individual channels that can be referenced by this API.
- NETIF_
INDEX_ UNSPECIFIED - Unspecified network index.
- ROUTER_
ID_ OFFSET - The bit offset to the router ID in an RLOC16.
- TREL_
DNSSD_ SERVICE_ NAME - DNS-SD Service Name for TREL
- TREL_
DNSSD_ SERVICE_ NAME_ WITH_ DOT - DNS-SD Service Name for TREL, with a dot at the end.
Traits§
- Backbone
Router - Methods from the OpenThread “Backbone Router” Module. Currently only multicast routing related methods are added.
- Border
Agent - Methods from the OpenThread “Border Agent” Module.
- Border
Router - Methods from the OpenThread “Border Router” Module.
- Boxable
- Trait for OpenThread Rust types for which an owned opaque instance is kept in a [
ot::Box<>
]. - Cli
- Methods from the OpenThread “CLI” Module.
- Dataset
- Methods from the OpenThread “OperationalDataset” Module.
- DnsUpstream
- DnsUpstream callback from platform to OT
- Dnssd
- Methods from the OpenThread DNS-SD Server Module.
- Dnssd
Ext - Extension trait for the trait
Dnssd
. - Infra
Interface - Methods from the “Platform Infrastructure Interface” group [1]
- Instance
Interface - Trait implemented by all OpenThread instances.
- Into
OtError - Trait for converting types into
otError
values. - Ip6
- Methods from the OpenThread “IPv6” Module.
- Joiner
- Methods from the OpenThread “Joiner” Module.
- Link
- Methods from the OpenThread “Link” Module.
- Link
Metrics - Methods from the “Link Metrics “ group [1]
- Nat64
- Methods from the OpenThread “NAT64” Module.
- NetData
- Methods from the OpenThread “NetData” Module.
- OtCastable
- Trait used to indicate that the implementing type can be efficiently
converted into a reference to the original OpenThread type identified by
Self::OtType
. - Plat
Trel - Platform methods from the OpenThread TREL Module.
- Platform
- Trait for OpenThread platform implementations.
- Process
Poll Async - Trait that provides the [
process_poll()
] method. - Radio
- Methods from the OpenThread “Radio” Module.
- Reset
- Reset-related methods from the OpenThread “Instance” Module.
- SrpServer
- Server Methods from the OpenThread SRP Module.
- State
- State-change-related methods from the OpenThread “Instance” Module.
- Tasklets
- Methods from the OpenThread “Tasklets” Module.
- Tasklets
Stream Ext - Trait used to wrap around a mutex that polls internally without needing to externally unlock the mutex.
- Thread
- Methods from the OpenThread “Thread General” Module.
- TlvIterator
Ext - Extension trait for adding
tlvs()
method to&[u8]
. - Transparent
- Trait used to indicate that the implementing type can be used by value and converted to/from the associated OpenThread type by value.
- Trel
- Methods from the OpenThread TREL Module.
- Udp
- Methods from the OpenThread “UDP” Module.
- Uptime
- Uptime-related methods from the OpenThread “Instance” Module.
Functions§
- dns_
txt_ flatten - Converts a iterator of strings into a single string separated with
[
DNSSD_TXT_SEPARATOR_STR
]. - get_
logging_ level - Get the logging level.
- get_
thread_ version - Returns the version of the Thread specification that OpenThread
is configured to use. This is the safe equivalent of
otsys::otThreadGetVersion()
. - get_
thread_ version_ str - Returns a
'static
-scoped string slice describing the version of the Thread specification that is currently in use. - get_
version_ string - Returns the OpenThread version string. This is the safe equivalent of
otsys::otGetVersionString()
. - parse_
label_ from_ subtype_ service_ name - Functional equivalent of
otsys::otSrpServerParseSubTypeServiceName
. - rloc16_
to_ child_ id - Extracts the child ID from an RLOC16.
- rloc16_
to_ router_ id - Extracts the router ID from an RLOC16.
- set_
logging_ level - Changes the logging level.
Type Aliases§
- Channel
Index - Channel index value. Identifies an individual radio channel for transmitting and receiving.
- Decibels
- Type for representing decibels, such as RSSI or transmit power.
- Ip4Address
- IPv4 address type
- Ip6Address
- IPv6 Address Type. Functional equivalent of
otsys::otIp6Address
. - Mesh
Local Prefix - Mesh-Local Prefix.
- Netif
Index - Network Interface Identifier.
- PanId
- 802.15.4 PAN Identifier. Same type as
otsys::otPanId
. - Result
- Type returned by OpenThread calls.
- Short
Address - 802.15.4 Short Address. Same type as
otsys::otShortAddress
.