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>
impl<const N: usize> NetworkStore<N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
An empty store — what a factory-fresh Wi-Fi or Thread interface has.
Sourcepub fn entries(&self) -> &[NetworkInfo]
pub fn entries(&self) -> &[NetworkInfo]
The entries, in precedence order.
Sourcepub fn add_or_update(&mut self, id: &[u8]) -> Result<u8, NetworkStatus>
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.
Sourcepub fn remove(&mut self, id: &[u8]) -> Result<u8, NetworkStatus>
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.
Sourcepub fn reorder(&mut self, id: &[u8], to: u8) -> Result<u8, NetworkStatus>
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”.
Sourcepub fn set_connected(&mut self, id: &[u8]) -> Result<(), NetworkStatus>
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.
Sourcepub fn set_all_disconnected(&mut self)
pub fn set_all_disconnected(&mut self)
Marks every entry disconnected — what a failed ConnectNetwork leaves behind.
Sourcepub fn snapshot(&mut self)
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.
Sourcepub fn restore(&mut self)
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.
Sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Drops the snapshot, keeping the current list — what CommissioningComplete does.
Sourcepub fn seed(&mut self, id: &[u8], connected: bool) -> Result<(), NetworkStatus>
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)”.