Skip to main content

NetworkStore

Struct NetworkStore 

Source
pub struct NetworkStore<const N: usize> { /* private fields */ }
Expand description

The Networks attribute: an ordered, fixed-capacity list where position is precedence.

§11.9.6.2: “The order of configurations in the list reflects precedence. That is, any time the Node attempts to connect to the network it SHALL attempt to do so using the configurations in Networks Attribute in the order as they appear in the list. The order of list items SHALL only be modified by the AddOrUpdateThreadNetwork, AddOrUpdateWiFiNetwork and ReorderNetwork commands.”

So this is a Vec, not a map: every operation states exactly what it does to the order, and an implementation that sorted or re-hashed would silently change which access point a device prefers.

N is MaxNetworks (§11.9.6.1), “the maximum number of network configuration entries that can be added, based on available device resources”.

Implementations§

Source§

impl<const N: usize> NetworkStore<N>

Source

pub const fn new() -> Self

An empty store — what a factory-fresh Wi-Fi or Thread interface has.

Source

pub const fn capacity(&self) -> usize

MaxNetworks (§11.9.6.1).

Source

pub fn entries(&self) -> &[NetworkInfo]

The entries, in precedence order.

Source

pub fn position(&self, id: &[u8]) -> Option<usize>

The position of id, if it is configured.

Source

pub fn add_or_update(&mut self, id: &[u8]) -> Result<u8, NetworkStatus>

AddOrUpdateWiFiNetwork / AddOrUpdateThreadNetwork, as §11.9.7.5 defines them.

If validation of all parameters has succeeded, this command SHALL append the configuration at the end of the existing list in the Networks attribute, making this new network the one with least priority.

and, for an update:

this command SHALL update the existing entry indexed by NetworkID in the Networks attribute, keeping existing position within the list.

Returns the 0-based index for the NetworkConfigResponse.

Source

pub fn remove(&mut self, id: &[u8]) -> Result<u8, NetworkStatus>

RemoveNetwork (§11.9.7.6).

The relative order of the entries in the Networks attribute SHALL remain unchanged, except for the removal of the requested network configuration.

Returns the index the entry had, which is what the response reports.

Source

pub fn reorder(&mut self, id: &[u8], to: u8) -> Result<u8, NetworkStatus>

ReorderNetwork (§11.9.7.10).

The entry selected SHALL be inserted at the new position in the list. All other entries, if any exist, SHALL be moved to allow the insertion, in a way that they all retain their existing relative order between each other, with the exception of the newly re-ordered entry.

A remove-then-insert, which is exactly that sentence: everything between the old and new position shifts by one and nothing else changes. Re-ordering to the position an entry already holds “SHALL be considered as a success and yield no visible changes”.

Source

pub fn set_connected(&mut self, id: &[u8]) -> Result<(), NetworkStatus>

Marks id connected and every other entry disconnected (§11.9.7.8).

On successful connection, the entry associated with the given Network configuration in the Networks attribute SHALL indicate its Connected field set to true, and all other entries, if any exist, SHALL indicate their Connected field set to false.

Source

pub fn set_all_disconnected(&mut self)

Marks every entry disconnected — what a failed ConnectNetwork leaves behind.

Source

pub fn snapshot(&mut self)

Records the list as it stands, for §11.10.7.2.2 step 5.

Called when the fail-safe is armed. Idempotent within one period: a second ArmFailSafe re-arms the same context, so the state to revert to is still the one from before the first.

Source

pub fn restore(&mut self)

Reverts to the snapshot — §11.10.7.2.2 step 5, “Reset the configuration of all Network Commissioning Networks attribute to their state prior to the Fail-Safe being armed”.

Without this, a commissioner that half-configured a network and walked away leaves the device pointed at an access point it cannot reach, with no way back.

Source

pub fn commit(&mut self)

Drops the snapshot, keeping the current list — what CommissioningComplete does.

Source

pub fn seed(&mut self, id: &[u8], connected: bool) -> Result<(), NetworkStatus>

Seeds the list with an entry that cannot be added or removed.

§11.9.6.2: “Ethernet networks SHALL be automatically populated by the cluster server. Ethernet Network Commissioning Cluster instances SHALL always have exactly one NetworkInfoStruct instance in their Networks attribute. There SHALL be no way to add, update or remove Ethernet network configurations to those Cluster instances.” The id is “Network interface instance name at operating system (or equivalent unique name)”.

Trait Implementations§

Source§

impl<const N: usize> Clone for NetworkStore<N>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for NetworkStore<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for NetworkStore<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Forget for NetworkStore<N>

§

impl<const N: usize> Freeze for NetworkStore<N>

§

impl<const N: usize> Move for NetworkStore<N>

§

impl<const N: usize> RefUnwindSafe for NetworkStore<N>

§

impl<const N: usize> Send for NetworkStore<N>
where VecInner<NetworkInfo, usize, VecStorageInner<[MaybeUninit<NetworkInfo>; N]>>: Send, Option<VecInner<NetworkInfo, usize, VecStorageInner<[MaybeUninit<NetworkInfo>; N]>>>: Send,

§

impl<const N: usize> Sync for NetworkStore<N>
where VecInner<NetworkInfo, usize, VecStorageInner<[MaybeUninit<NetworkInfo>; N]>>: Sync, Option<VecInner<NetworkInfo, usize, VecStorageInner<[MaybeUninit<NetworkInfo>; N]>>>: Sync,

§

impl<const N: usize> Unpin for NetworkStore<N>

§

impl<const N: usize> UnsafeUnpin for NetworkStore<N>

§

impl<const N: usize> UnwindSafe for NetworkStore<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.