Skip to content

Commit 8e2445a

Browse files
committed
Add a basic FrameFiltering setup
1 parent cb3a443 commit 8e2445a

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/mac/frame_filtering/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ pub struct FrameFiltering {
8888
}
8989

9090
impl FrameFiltering {
91+
/// Create a new basic [`FrameFiltering`] that:
92+
/// * Does not filter out frames destined for `station_addr` or an address
93+
/// contained in `extra_address.
94+
/// * Does not filter out multicast frames.
95+
/// * Does not filter out broadcast frames.
96+
/// * Filters out all control frames.
97+
pub fn filter_destinations(station_addr: Mac, extra_addresses: Vec<Mac, 3>) -> Self {
98+
let extra_addrs = extra_addresses
99+
.into_iter()
100+
.map(|a| MacAddressFilter::new(a, MacAddressFilterMask::empty()))
101+
.collect();
102+
103+
FrameFiltering {
104+
address: station_addr,
105+
destination_address_filter: DestinationAddressFiltering {
106+
perfect_filtering: PerfectDestinationAddressFiltering::Normal(extra_addrs),
107+
hash_table_filtering: false,
108+
},
109+
source_address_filter: SourceAddressFiltering::Ignore,
110+
multicast_address_filter: MulticastAddressFiltering::PassAll,
111+
control_filter: ControlFrameFiltering::BlockAll,
112+
hash_table_value: HashTableValue::new(),
113+
filter_broadcast: false,
114+
receive_all: false,
115+
}
116+
}
117+
91118
fn configure(&self, eth_mac: &ETHERNET_MAC) {
92119
let FrameFiltering {
93120
address,
@@ -112,7 +139,7 @@ impl FrameFiltering {
112139
let empty_vec = Vec::new();
113140

114141
let (saf, saif, source_addrs) = match &source_address_filter {
115-
SourceAddressFiltering::PassAll => (false, false, &empty_vec),
142+
SourceAddressFiltering::Ignore => (false, false, &empty_vec),
116143
SourceAddressFiltering::Normal(addrs) => (true, false, addrs),
117144
SourceAddressFiltering::Inverse(addrs) => (true, true, addrs),
118145
};
@@ -243,6 +270,13 @@ pub struct MacAddressFilter {
243270
pub mask: MacAddressFilterMask,
244271
}
245272

273+
impl MacAddressFilter {
274+
/// Create a new MAC address filter.
275+
pub fn new(address: Mac, mask: MacAddressFilterMask) -> Self {
276+
Self { address, mask }
277+
}
278+
}
279+
246280
bitflags::bitflags! {
247281
/// A mask to be applied when comparing a [`MacAddressFilter`]
248282
/// to an incoming address.

src/mac/frame_filtering/source.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use super::MacAddressFilter;
77
#[derive(Debug, Clone)]
88

99
pub enum SourceAddressFiltering {
10-
/// All received frames are passed to the application,
11-
/// ignoring all frame filtering settings.
12-
PassAll,
10+
/// Source address filtering never fails.
11+
Ignore,
1312
/// Filter frames by their Source Address, based on
1413
/// the provided addresses.
1514
Normal(Vec<MacAddressFilter, 3>),

0 commit comments

Comments
 (0)