#[cfg(feature = "incremental-backend-experiment")]
use crate::IncrementalRunnerDiagnostics;
use crate::{BlockingRunnerDiagnostics, EventDiagnostics};
#[cfg(feature = "incremental-embassy-wait")]
use hisi_rf_ws63::Ws63IncrementalWaitDiagnostics;
use hisi_rf_ws63::{
BlockingBackendMetrics, DataPathDiagnostics, DhcpDiagnostics, L2ProtocolDiagnostics,
ResourceReport, RxQueueDiagnostics, ScanDiagnostics,
};
pub const RADIO_DIAGNOSTICS_SCHEMA: &str = "hisi-rf-radio-diagnostics/v8";
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RunnerDiagnosticsSnapshot {
Blocking(BlockingRunnerDiagnostics),
#[cfg(feature = "incremental-backend-experiment")]
Incremental(IncrementalRunnerDiagnostics),
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct WaitDiagnosticsSnapshot {
pub active: bool,
pub backend_signals: u32,
pub l2_rx_signals: u32,
pub waker_notifications: u32,
pub poll_calls: u32,
pub pending_polls: u32,
pub ready_polls: u32,
pub timer_ready_polls: u32,
}
#[cfg(feature = "incremental-embassy-wait")]
impl From<Ws63IncrementalWaitDiagnostics> for WaitDiagnosticsSnapshot {
fn from(value: Ws63IncrementalWaitDiagnostics) -> Self {
Self {
active: true,
backend_signals: value.backend_signals,
l2_rx_signals: value.l2_rx_signals,
waker_notifications: value.waker_notifications,
poll_calls: value.poll_calls,
pending_polls: value.pending_polls,
ready_polls: value.ready_polls,
timer_ready_polls: value.timer_ready_polls,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RadioDiagnosticsSnapshot {
pub schema: &'static str,
pub error_schema: &'static str,
pub resources: ResourceReport,
pub runner: RunnerDiagnosticsSnapshot,
pub control: BlockingRunnerDiagnostics,
pub wait: WaitDiagnosticsSnapshot,
pub events: EventDiagnostics,
pub blocking_calls: BlockingBackendMetrics,
pub scan: ScanDiagnostics,
pub rx_queue: RxQueueDiagnostics,
pub dhcp: DhcpDiagnostics,
pub l2_protocol: L2ProtocolDiagnostics,
pub data_path: DataPathDiagnostics,
}
impl RadioDiagnosticsSnapshot {
#[cfg(not(feature = "incremental-backend-experiment"))]
pub(crate) fn blocking(
controller: &crate::WifiController,
device: &hisi_rf_ws63::WifiDevice,
resources: ResourceReport,
) -> Self {
Self {
schema: RADIO_DIAGNOSTICS_SCHEMA,
error_schema: crate::DIAGNOSTIC_SCHEMA,
resources,
runner: RunnerDiagnosticsSnapshot::Blocking(controller.blocking_runner_diagnostics()),
control: controller.blocking_runner_diagnostics(),
wait: WaitDiagnosticsSnapshot::default(),
events: controller.event_diagnostics(),
blocking_calls: hisi_rf_ws63::blocking_backend_metrics(),
scan: hisi_rf_ws63::upstream_supplicant_scan_diagnostics(),
rx_queue: device.rx_queue_diagnostics(),
dhcp: device.dhcp_diagnostics(),
l2_protocol: device.l2_protocol_diagnostics(),
data_path: device.data_path_diagnostics(),
}
}
#[cfg(all(
feature = "incremental-backend-experiment",
feature = "incremental-embassy-wait"
))]
pub(crate) fn incremental(
controller: &crate::WifiController,
device: &hisi_rf_ws63::WifiDevice,
resources: ResourceReport,
) -> Self {
Self {
schema: RADIO_DIAGNOSTICS_SCHEMA,
error_schema: crate::DIAGNOSTIC_SCHEMA,
resources,
runner: RunnerDiagnosticsSnapshot::Incremental(
controller.incremental_runner_diagnostics(),
),
control: controller.blocking_runner_diagnostics(),
wait: hisi_rf_ws63::incremental_wait_diagnostics().into(),
events: controller.event_diagnostics(),
blocking_calls: hisi_rf_ws63::blocking_backend_metrics(),
scan: hisi_rf_ws63::upstream_supplicant_scan_diagnostics(),
rx_queue: device.rx_queue_diagnostics(),
dhcp: device.dhcp_diagnostics(),
l2_protocol: device.l2_protocol_diagnostics(),
data_path: device.data_path_diagnostics(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn schema_references_existing_error_and_resource_truth() {
assert_eq!(RADIO_DIAGNOSTICS_SCHEMA, "hisi-rf-radio-diagnostics/v8");
assert_eq!(crate::DIAGNOSTIC_SCHEMA, "hisi-rf-error/v3");
let report = hisi_rf_ws63::resource_report::<
hisi_rf_ws63::SelectedProfile,
{ crate::EVENT_CAPACITY },
>();
assert_eq!(report.schema, "hisi-rf-resource-report/v10");
#[cfg(feature = "wpa2-personal")]
assert!(report.runtime_resources_calibrated);
#[cfg(feature = "wpa3-personal")]
assert!(!report.runtime_resources_calibrated);
}
#[cfg(feature = "incremental-embassy-wait")]
#[test]
fn wait_snapshot_is_a_lossless_secret_free_projection() {
let raw = Ws63IncrementalWaitDiagnostics {
backend_signals: 1,
l2_rx_signals: 2,
waker_notifications: 3,
poll_calls: 4,
pending_polls: 5,
ready_polls: 6,
timer_ready_polls: 7,
};
let snapshot = WaitDiagnosticsSnapshot::from(raw);
assert!(snapshot.active);
assert_eq!(snapshot.backend_signals, 1);
assert_eq!(snapshot.l2_rx_signals, 2);
assert_eq!(snapshot.waker_notifications, 3);
assert_eq!(snapshot.poll_calls, 4);
assert_eq!(snapshot.pending_polls, 5);
assert_eq!(snapshot.ready_polls, 6);
assert_eq!(snapshot.timer_ready_polls, 7);
}
}