From 6a20702717b84f55b0dcc1a92b5866b73ffeb415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20St=C3=BCrmer?= Date: Sun, 26 Oct 2025 07:14:56 +0100 Subject: [PATCH] chore:add MLME primities --- Cargo.toml | 4 +++ src/mac/mlme/mod.rs | 6 +++++ src/mac/mlme/scan.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/mac/mod.rs | 1 + 4 files changed, 75 insertions(+) create mode 100644 src/mac/mlme/mod.rs create mode 100644 src/mac/mlme/scan.rs diff --git a/Cargo.toml b/Cargo.toml index 6b159d3..a51b388 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,10 @@ default-features = false optional = true features = [ "derive" ] +[dependencies.heapless] +version = "0.9.1" +default-features = false + [dev-dependencies] rand = "0.8.3" diff --git a/src/mac/mlme/mod.rs b/src/mac/mlme/mod.rs new file mode 100644 index 0000000..1e94cc3 --- /dev/null +++ b/src/mac/mlme/mod.rs @@ -0,0 +1,6 @@ +//! Partial implementation of the IEEE 802.15.4 MAC Layer Management Entity (MLME) +//! +//! The main types in this module provide structures and functions for handling +//! MLME service primitives, managing MAC layer state, and coordinating +//! MAC management operations such as association, scanning, and synchronization. +pub mod scan; diff --git a/src/mac/mlme/scan.rs b/src/mac/mlme/scan.rs new file mode 100644 index 0000000..9c93a37 --- /dev/null +++ b/src/mac/mlme/scan.rs @@ -0,0 +1,64 @@ +//! This contains MLME-Scan.request, .confirm and .indication +use heapless::Vec; + +/// 7.1.11.1 - MLME-SCAN.request +/// is used to initiate a channel scan over a given list of channels. +pub struct MlmeScanRequest { + /// Indicates the type of scan performed + pub scan_type: ScanType, + /// indicate which channels are to be scanne + pub channels: u32, + /// value used to calculate the length of time to spend scanning each channel for ED, active, and passive scans. + pub scan_duration: u8, +} + +/// 7.1.11.2 - MLME-SCAN.confirm +/// defines the scan primitive +pub struct MlmeScanConfirm { + /// The status of the scan request. + pub status: ScanStatus, + /// Indicates if the type of scan performed + pub scan_type: ScanType, + /// Channels not scanned (bitmask) + pub unscanned_channels: u32, + /// Number of results in lists + pub result_list_size: u8, + /// list of energy measurements, one for each channel searched during an ED scan. + pub energy_detect_list: Option>, + /// Beacons found during scan + pub pan_descriptor_list: Option>, +} + +/// 7.1.11.2.1 +pub enum ScanType { + /// FFD only + EnergyDetection = 0x00, + /// FFD only + Active = 0x01, + /// passive scan + Passive = 0x02, + /// orphan scan + Orphan = 0x03, +} + +/// 7.1.11.1.3 +pub enum ScanStatus { + /// requested scan was successful + Success, + /// limit reached + LimitReached, + /// primitive is not supported or is out of range + InvalidParameter, +} + +/// Table 41 +pub struct PanDescriptor { + /// The address of the coordinator as specified in the received beacon frame. + pub coord_addr: u64, + /// The PAN identifier of the coordinator as specified in the received beacon frame. + pub coord_pan_id: u16, + /// The current logical channel occupied by the network. + pub channel: u8, + /// The LQ at which the network beacon was received. + pub link_quality: u8, +} diff --git a/src/mac/mod.rs b/src/mac/mod.rs index 51ed3e5..b8ce1ba 100644 --- a/src/mac/mod.rs +++ b/src/mac/mod.rs @@ -3,6 +3,7 @@ pub mod beacon; pub mod command; pub mod frame; +pub mod mlme; pub use frame::header::{ Address, AddressMode, ExtendedAddress, FrameType, FrameVersion, Header,