Skip to content

Commit 3c92131

Browse files
committed
Begin work on address filtering
1 parent 872cff1 commit 3c92131

File tree

8 files changed

+459
-14
lines changed

8 files changed

+459
-14
lines changed

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ ieee802_3_miim = "0.7"
2828
cortex-m = "0.7"
2929
log = { version = "0.4", optional = true }
3030
defmt = { version = "0.3", optional = true }
31+
bitflags = "1.3.2"
32+
heapless = "0.7.16"
3133

3234
[dependencies.smoltcp]
3335
version = "0.8"
@@ -36,7 +38,7 @@ features = ["medium-ethernet", "proto-ipv4"]
3638
optional = true
3739

3840
[features]
39-
default = [ "defmt" ]
41+
default = ["defmt"]
4042
device-selected = []
4143
fence = []
4244

@@ -64,8 +66,8 @@ stm32f779 = ["stm32f7xx-hal/stm32f779", "device-selected", "fence"]
6466
smoltcp-phy = ["smoltcp"]
6567

6668
# Example features
67-
example-nucleo-pins = [ ]
68-
rtic-echo-example = [ "defmt", "smoltcp-phy", "smoltcp/defmt", "smoltcp/medium-ethernet", "smoltcp/socket-tcp" ]
69+
example-nucleo-pins = []
70+
rtic-echo-example = ["defmt", "smoltcp-phy", "smoltcp/defmt", "smoltcp/medium-ethernet", "smoltcp/socket-tcp"]
6971

7072
[dev-dependencies]
7173
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }

src/mac/frame_filtering/control.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// The type of frame filtering that the MAC should perform
2+
/// on received control frames,
3+
#[derive(Debug, Clone)]
4+
5+
pub enum ControlFrameFiltering {
6+
/// Prevent all control frames from reaching
7+
/// the application.
8+
BlockAll,
9+
/// Allow all control frames to reach the application,
10+
/// except for PAUSE control frames.
11+
NoPause,
12+
/// Allow all control frames to reach the application.
13+
AllowAll,
14+
/// Block control frames that do not pass the
15+
/// configured address filter, but allow those that do.
16+
AddressFilter,
17+
}
18+
19+
impl ControlFrameFiltering {
20+
/// Create a new [`ControlFrameFiltering`] that filters out
21+
/// all control frames.
22+
pub const fn new() -> Self {
23+
Self::BlockAll
24+
}
25+
}
26+
27+
impl Default for ControlFrameFiltering {
28+
fn default() -> Self {
29+
Self::new()
30+
}
31+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use heapless::Vec;
2+
3+
use super::MacAddressFilter;
4+
5+
/// The type of filtering that the MAC should apply to
6+
/// frames that are to be transmitted.
7+
#[derive(Debug, Clone)]
8+
pub struct DestinationAddressFiltering {
9+
/// Filtering to be performed based on perfect address matches.
10+
pub perfect_filtering: PerfectDestinationAddressFiltering,
11+
/// Enable or disable hash table filtering for destination
12+
/// addresses.
13+
pub hash_table_filtering: bool,
14+
}
15+
16+
impl DestinationAddressFiltering {
17+
/// Create a new [`DestinationAddressFiltering`] that does
18+
/// not filter any frames.
19+
pub const fn new() -> Self {
20+
Self {
21+
perfect_filtering: PerfectDestinationAddressFiltering::new(),
22+
hash_table_filtering: false,
23+
}
24+
}
25+
}
26+
27+
impl Default for DestinationAddressFiltering {
28+
fn default() -> Self {
29+
Self::new()
30+
}
31+
}
32+
33+
/// The type of destination address filtering that
34+
/// the MAC should apply to frames.
35+
#[derive(Debug, Clone)]
36+
37+
pub enum PerfectDestinationAddressFiltering {
38+
/// Filter frames by their Destination Address, based on
39+
/// the provided addresses.
40+
Normal(Vec<MacAddressFilter, 3>),
41+
/// Filter frames by their Destination Address, based on
42+
/// the inverse of the provided addresses.
43+
Inverse(Vec<MacAddressFilter, 3>),
44+
}
45+
46+
impl PerfectDestinationAddressFiltering {
47+
/// Create a new [`PerfectDestinationAddressFiltering`] that filters
48+
/// out all frames.
49+
pub const fn new() -> Self {
50+
Self::Normal(Vec::new())
51+
}
52+
}
53+
54+
impl Default for PerfectDestinationAddressFiltering {
55+
fn default() -> Self {
56+
Self::new()
57+
}
58+
}

src/mac/frame_filtering/hash_table.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[derive(Debug, Clone)]
2+
/// Configuration of the hash table used by the MAC for
3+
/// destination address filtering.
4+
pub struct HashTableValue {
5+
/// The low register of the hash table.
6+
pub low: u32,
7+
/// The high register of the hash table.
8+
pub high: u32,
9+
}
10+
11+
impl HashTableValue {
12+
/// Create a new hash table value that filters
13+
/// out all frames.
14+
pub const fn new() -> Self {
15+
Self { low: 0, high: 0 }
16+
}
17+
}
18+
19+
/// By default, the hash table is configured so that
20+
/// it filters out all frames.
21+
impl Default for HashTableValue {
22+
fn default() -> Self {
23+
Self::new()
24+
}
25+
}

0 commit comments

Comments
 (0)