Skip to content

Commit 3844d0c

Browse files
committed
Added doc comments for the entire public API.
1 parent 3ff0e23 commit 3844d0c

File tree

16 files changed

+147
-121
lines changed

16 files changed

+147
-121
lines changed

examples/Cargo.lock

Lines changed: 17 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

foa/Cargo.lock

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

foa/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
[package]
22
name = "foa"
3-
version = "0.1.0-alpha.0"
3+
version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
77
embassy-sync = "0.7.0"
88
embassy-futures = "0.1.1"
99

1010
esp-hal = "1.0.0-beta.1"
11-
# esp-wifi-hal = "0.1.2"
12-
# esp-wifi-hal = { git = "https://github.com/esp32-open-mac/esp-wifi-hal.git" }
13-
esp-wifi-hal = { path = "../../esp-wifi-hal/esp-wifi-hal" }
11+
esp-wifi-hal = "0.1.3"
1412
static_cell = "2.1.0"
1513
critical-section = "1.2.0"
1614
portable-atomic = "1.11.1"
1715
esp-config = "0.4.0"
1816
defmt-or-log = { version = "0.2.1", default-features = false }
1917
defmt = { version = "1.0.1", optional = true }
2018
embassy-time = "0.4.0"
21-
ieee80211 = { path = "../../../rust/ieee80211/" }
22-
# ieee80211 = { git = "https://github.com/Frostie314159/ieee80211-rs.git", branch = "crypto" }
2319
heapless = "0.8.0"
20+
ieee80211 = "0.5.7"
2421

2522
[build-dependencies]
2623
esp-config = { version = "0.4.0", features = ["build"] }

foa/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![deny(missing_docs)]
23
//! # Ferris-on-Air (FoA)
34
//! Ferris-on-Air is an asynchronous IEEE 802.11 MAC stack for the ESP32 series of chips. It is
45
//! build on top of [esp_wifi_hal], which is the driver for the Wi-Fi peripheral, and is based on
@@ -64,13 +65,16 @@ pub mod util;
6465
const RX_BUFFER_COUNT: usize = esp_config_int!(usize, "FOA_CONFIG_RX_BUFFER_COUNT");
6566
const RX_QUEUE_LEN: usize = esp_config_int!(usize, "FOA_CONFIG_RX_QUEUE_LEN");
6667
const TX_BUFFER_COUNT: usize = esp_config_int!(usize, "FOA_CONFIG_TX_BUFFER_COUNT");
67-
// This is fixed, so that interfaces can rely on the size of a TX buffer.
68+
/// The size of a [TxBuffer].
69+
///
70+
/// This is fixed, so that interfaces can rely on the size of a TX buffer.
6871
pub const TX_BUFFER_SIZE: usize = 1600;
6972

7073
/// A frame received from the driver.
7174
#[cfg(feature = "arc_buffers")]
7275
pub type ReceivedFrame<'res> = RxArcBuffer<'res>;
7376
#[cfg(not(feature = "arc_buffers"))]
77+
/// A frame received from the driver.
7478
pub type ReceivedFrame<'res> = BorrowedBuffer<'res>;
7579
/// A receiver to the RX queue of an interface.
7680
pub type RxQueueReceiver<'res> = DynamicReceiver<'res, ReceivedFrame<'res>>;
@@ -86,6 +90,10 @@ pub struct FoAResources {
8690
rx_queues: [Channel<NoopRawMutex, ReceivedFrame<'static>, RX_QUEUE_LEN>; WiFi::INTERFACE_COUNT],
8791
}
8892
impl FoAResources {
93+
/// Create new stack resources.
94+
///
95+
/// This has to be in internal RAM, since the DMA descriptors and buffers for the Wi-Fi driver
96+
/// have to be in internal RAM.
8997
pub fn new() -> Self {
9098
Self {
9199
wifi_resources: WiFiResources::new(),
@@ -124,6 +132,9 @@ impl<'res> VirtualInterface<'res> {
124132
) {
125133
(&mut self.interface_control, &mut self.rx_queue_receiver)
126134
}
135+
/// Reset the virtual interface.
136+
///
137+
/// This is releases any prior channel lock, resets all filters and clears the RX queue.
127138
pub fn reset(&mut self) {
128139
// We can't call clear on a DynamicReceiver, so this is the best we can do for now.
129140
// This isn't too bad, since this will only be called rarely and the RX queues shouldn't be

foa/src/util/operations/scan.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ use crate::{
88
};
99

1010
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
11+
/// This specifies the order in which channels should be scanned.
1112
pub enum ScanStrategy<'a> {
13+
/// Only a single channel should be scanned.
1214
Single(u8),
15+
/// Only the current channel should be scanned.
1316
CurrentChannel,
17+
/// Scan the channels in ascending order (i.e. 1-13).
1418
Linear,
1519
#[default]
20+
/// Scan the channels in groups of three non overlapping channels (i.e. 1, 6, 11, 2, 7, 12 etc.).
1621
NonOverlappingFirst,
22+
/// Use a custom channel sequence.
1723
Custom(&'a [u8]),
1824
}
1925

foa/src/util/rx_router.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ impl RxRouterQueue {
7878
///
7979
/// It is expected, that frames like beacons and probe responses will be matched for this operation.
8080
pub trait HasScanOperation: RxRouterOperation {
81+
/// Does a scan like router operation exist.
82+
///
83+
/// At the moment, the requirement for this is, that all beacon frames will be matched by
84+
/// that operation.
8185
const SCAN_OPERATION: Self;
8286
}
8387

@@ -100,12 +104,15 @@ pub trait RxRouterOperation: Clone + Copy {
100104

101105
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
102106
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
103-
/// Errors returned by the RX router.
104-
pub enum RxRouterError {
107+
/// Errors related to router operations.
108+
pub enum RxRouterOperationError {
109+
/// Another router operation is already in progress for this queue.
110+
///
111+
/// This does not mean, that the request operation is incompatible with that of the other
112+
/// queue. [Self::IncompatibleOperations] indicates this instead.
105113
OperationAlreadyInProgress,
114+
/// The requested operation is incompatible with the one on the other queue.
106115
IncompatibleOperations,
107-
QueueFull,
108-
InvalidFrame,
109116
}
110117

111118
/// Used for dynamic dispatch.
@@ -114,7 +121,7 @@ trait Router<'foa, Operation: RxRouterOperation> {
114121
fn receive(&self, router_queue: RxRouterQueue)
115122
-> DynamicReceiveFuture<'_, ReceivedFrame<'foa>>;
116123
//// Route a frame to a specific queue.
117-
fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterError>;
124+
fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterRoutingError>;
118125
/// Get the operation state for the specified [RxRouterQueue].
119126
fn operation_state(&self, router_queue: RxRouterQueue) -> &Cell<Option<Operation>>;
120127
/// Get the operation completion signal.
@@ -148,6 +155,15 @@ impl<const QUEUE_DEPTH: usize, O: RxRouterOperation> QueueState<'_, QUEUE_DEPTH,
148155
self.operation_state.get().is_some()
149156
}
150157
}
158+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
159+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
160+
/// An error related to the routing of a received frame.
161+
pub enum RxRouterRoutingError {
162+
/// The queue, that the frame was supposed to be routed to, is full.
163+
QueueFull,
164+
/// The frame could not parsed.
165+
InvalidFrame,
166+
}
151167

152168
/// The core of the RX router.
153169
///
@@ -215,11 +231,11 @@ impl<'foa, const QUEUE_DEPTH: usize, Operation: RxRouterOperation> Router<'foa,
215231
) -> DynamicReceiveFuture<'_, ReceivedFrame<'foa>> {
216232
self.queue_state(router_queue).queue.receive().into()
217233
}
218-
fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterError> {
234+
fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterRoutingError> {
219235
// Usually the RX handler will have already created a GenericFrame, however we can't
220236
// reasonably assume that, so we recreate it here and hope the compiler opimizes away.
221237
let Ok(generic_frame) = GenericFrame::new(frame.mpdu_buffer(), false) else {
222-
return Err(RxRouterError::InvalidFrame);
238+
return Err(RxRouterRoutingError::InvalidFrame);
223239
};
224240
let router_queue = if self
225241
.foreground_queue_state
@@ -239,7 +255,7 @@ impl<'foa, const QUEUE_DEPTH: usize, Operation: RxRouterOperation> Router<'foa,
239255
if self.queue_state(router_queue).queue.try_send(frame).is_ok() {
240256
Ok(())
241257
} else {
242-
Err(RxRouterError::QueueFull)
258+
Err(RxRouterRoutingError::QueueFull)
243259
}
244260
}
245261
fn operation_state(&self, router_queue: RxRouterQueue) -> &Cell<Option<Operation>> {
@@ -264,14 +280,17 @@ pub struct RxRouterInput<'foa, 'router, Operation: RxRouterOperation> {
264280

265281
impl<'foa, Operation: RxRouterOperation> RxRouterInput<'foa, '_, Operation> {
266282
/// Route the provided frame to the correct queue.
267-
pub fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterError> {
283+
pub fn route_frame(&self, frame: ReceivedFrame<'foa>) -> Result<(), RxRouterRoutingError> {
268284
self.rx_router.route_frame(frame)
269285
}
286+
/// Get the currently active operation for the specified [RxRouterQueue].
270287
pub fn operation(&self, router_queue: RxRouterQueue) -> Option<Operation> {
271288
self.rx_router.operation_state(router_queue).get()
272289
}
273290
}
274291
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
292+
/// The requested operation transition is not possible, due to it being incompatible with another
293+
/// currently active operation.
275294
pub struct TransitionNotPossibleError;
276295
/// A scoped router operation.
277296
///
@@ -329,16 +348,16 @@ impl<'foa, 'router, Operation: RxRouterOperation> RxRouterEndpoint<'foa, 'router
329348
self.rx_router.receive(self.router_queue)
330349
}
331350
/// Check if the operation can be started.
332-
fn can_start_operation(&self, operation: Operation) -> Result<(), RxRouterError> {
351+
fn can_start_operation(&self, operation: Operation) -> Result<(), RxRouterOperationError> {
333352
if let Some(opposing_operation) = self
334353
.rx_router
335354
.operation_state(self.router_queue.opposite())
336355
.get()
337356
{
338357
if !Operation::CONCORRUENT_OPERATIONS_SUPPORTED {
339-
Err(RxRouterError::OperationAlreadyInProgress)
358+
Err(RxRouterOperationError::OperationAlreadyInProgress)
340359
} else if !opposing_operation.compatible_with(&operation) {
341-
Err(RxRouterError::IncompatibleOperations)
360+
Err(RxRouterOperationError::IncompatibleOperations)
342361
} else {
343362
Ok(())
344363
}
@@ -370,7 +389,7 @@ impl<'foa, 'router, Operation: RxRouterOperation> RxRouterEndpoint<'foa, 'router
370389
pub fn try_start_operation<'endpoint>(
371390
&'endpoint mut self,
372391
operation: Operation,
373-
) -> Result<RxRouterScopedOperation<'foa, 'router, 'endpoint, Operation>, RxRouterError> {
392+
) -> Result<RxRouterScopedOperation<'foa, 'router, 'endpoint, Operation>, RxRouterOperationError> {
374393
self.can_start_operation(operation)?;
375394
self.start_operation_internal(operation);
376395
Ok(RxRouterScopedOperation { endpoint: self })

0 commit comments

Comments
 (0)