pub struct JoinFilter { /* private fields */ }Expand description
A relay’s join request filter: a default action and up to fifteen rules, decided by the longest prefix that matches, TS011-1.0.1 section 8.6.
§Examples
The filter of TS011-1.0.1 appendix 3, which forwards one manufacturer’s devices, filters one JoinEUI of theirs except for a range of DevEUIs, filters one device in that range, and filters everyone else:
use pamoja_lorawan::relay::{FilterAction, FilterRule, JoinFilter};
let join_eui = [0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF, 0xAB, 0xCD];
let range = [0x12, 0x34, 0x56, 0x78, 0x28, 0x37, 0x46];
let mut filter = JoinFilter::new();
filter.set_default(FilterAction::Filter);
let rules = [
FilterRule::new(&join_eui[..3], FilterAction::Forward),
FilterRule::new(&join_eui, FilterAction::Filter),
FilterRule::new(&[&join_eui[..], &range[..]].concat(), FilterAction::Forward),
FilterRule::new(&[&join_eui[..], &range[..], &[0x48]].concat(), FilterAction::Filter),
];
for (index, rule) in (1..).zip(rules) {
assert!(filter.set_rule(index, rule));
}
assert_eq!(
filter.decide(&join_eui, &[0x12, 0x34, 0x56, 0x78, 0x28, 0x37, 0x46, 0x46]),
FilterAction::Forward,
"inside the range",
);
assert_eq!(
filter.decide(&join_eui, &[0x12, 0x34, 0x56, 0x78, 0x28, 0x37, 0x46, 0x48]),
FilterAction::Filter,
"the one device filtered out of it",
);Implementations§
Source§impl JoinFilter
impl JoinFilter
Sourcepub const fn new() -> JoinFilter
pub const fn new() -> JoinFilter
Sourcepub const fn default_action(&self) -> FilterAction
pub const fn default_action(&self) -> FilterAction
Sourcepub fn set_default(&mut self, action: FilterAction)
pub fn set_default(&mut self, action: FilterAction)
Sourcepub fn rule(&self, index: u8) -> Option<FilterRule>
pub fn rule(&self, index: u8) -> Option<FilterRule>
Sourcepub fn set_rule(&mut self, index: u8, rule: Option<FilterRule>) -> bool
pub fn set_rule(&mut self, index: u8, rule: Option<FilterRule>) -> bool
Sets or removes a rule.
§Arguments
index- the rule, 1 to 15.rule- the rule, orNoneto remove it.
§Returns
false for index 0, which set_default sets, or past 15.
Sourcepub fn decide(&self, join_eui: &[u8; 8], dev_eui: &[u8; 8]) -> FilterAction
pub fn decide(&self, join_eui: &[u8; 8], dev_eui: &[u8; 8]) -> FilterAction
Decides what happens to a join request, by the longest rule that matches it.
Of two matching rules of the same length, the one at the higher index decides.
§Arguments
join_eui- the request’s JoinEUI, most significant byte first.dev_eui- its DevEUI, most significant byte first.
§Returns
Forward or filter.
Sourcepub fn apply(
&mut self,
index: u8,
action: u8,
eui_len: u8,
eui: &[u8; 16],
) -> MacCommand
pub fn apply( &mut self, index: u8, action: u8, eui_len: u8, eui: &[u8; 16], ) -> MacCommand
Takes a FilterListReq and answers it, TS011-1.0.1 section 10.3.
Rule 0 takes an empty prefix with forward or filter. Rules 1 to 15 take a prefix with forward or filter to set a rule, and an empty prefix with action 0 to remove one. Anything else changes nothing and is refused.
§Arguments
index- the rule.action- the coded action, table 48.eui_len- the prefix length the request gave.eui- the prefix, most significant first, asMacCommand::FilterListReqholds it.
§Returns
The FilterListAns to send back.
Trait Implementations§
Source§impl Clone for JoinFilter
impl Clone for JoinFilter
Source§fn clone(&self) -> JoinFilter
fn clone(&self) -> JoinFilter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more