Skip to main content

JoinFilter

Struct JoinFilter 

Source
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

Source

pub const fn new() -> JoinFilter

A filter that forwards every join request, as a relay starts.

§Returns

The filter.

Source

pub const fn default_action(&self) -> FilterAction

Returns what happens to a join request no rule matches.

§Returns

Rule 0’s action.

Source

pub fn set_default(&mut self, action: FilterAction)

Sets what happens to a join request no rule matches.

§Arguments
  • action - rule 0’s action.
Source

pub fn rule(&self, index: u8) -> Option<FilterRule>

Returns a rule.

§Arguments
  • index - the rule, 1 to 15.
§Returns

The rule, or None for an empty index or one out of range.

Source

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, or None to remove it.
§Returns

false for index 0, which set_default sets, or past 15.

Source

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.

Source

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, as MacCommand::FilterListReq holds it.
§Returns

The FilterListAns to send back.

Trait Implementations§

Source§

impl Clone for JoinFilter

Source§

fn clone(&self) -> JoinFilter

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 Copy for JoinFilter

Source§

impl Debug for JoinFilter

Source§

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

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

impl Default for JoinFilter

Source§

fn default() -> JoinFilter

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

impl Eq for JoinFilter

Source§

impl Hash for JoinFilter

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for JoinFilter

Source§

fn eq(&self, other: &JoinFilter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for JoinFilter

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.