Skip to main content

Crate kawaiifi

Crate kawaiifi 

Source
Expand description

kawaiifi is a Wi-Fi scanning library for Linux, macOS, and Windows.

It discovers local Basic Service Sets (BSSs) and reports their SSID, BSSID, signal strength, channel, channel width, security protocols, and information elements (IEs).

§Obtaining a Wi-Fi Interface

Use default_interface to get the first available interface.

use kawaiifi::Interface;

let interface: Interface = kawaiifi::default_interface()?.ok_or("No Wi-Fi interface found")?;

Use interfaces to get all available interfaces.

use kawaiifi::Interface;

let interfaces: Vec<Interface> = kawaiifi::interfaces()?;

Some Interface properties are platform-specific.

#[cfg(target_os = "linux")]
println!("Index: {}", interface.index());

#[cfg(target_os = "macos")]
println!("Noise: {} dBm", interface.noise_dbm());

#[cfg(target_os = "windows")]
println!("Description: {}", interface.description());

§Triggering a Wi-Fi Scan

Blocking scans are triggered using Interface::scan_blocking.

use kawaiifi::Scan;

let scan: Scan = interface.scan_blocking()?;

Asynchronous scans are triggered using Interface::scan.

let scan = interface.scan().await?;

§Accessing BSS Data

Scan contains a list of BSSs that are accessed through Scan::bss_list.

use kawaiifi::Bss;

let bss_list: &[Bss] = scan.bss_list();
println!("Found {} BSS(s)", bss_list.len());

Bss exposes common properties that are available on all platforms.

println!("BSSID: {:?}", bss.bssid());
println!("SSID: {:?}", bss.ssid());
println!("Frequency: {} MHz", bss.frequency_mhz());
println!("Band: {}", bss.band());
println!("Channel: {}", bss.channel_number());
println!("Channel Width: {}", bss.channel_width());
println!("Signal: {} dBm", bss.signal_dbm());
println!("Security: {}", bss.security_protocols());
println!("Wi-Fi Protocols: {}", bss.wifi_protocols());
println!("Wi-Fi Amendments: {}", bss.wifi_amendments());
println!("Max Rate: {} Mbps", bss.max_rate_mbps());

Some Bss properties are platform-specific.

#[cfg(target_os = "linux")]
println!("Status: {:?}", bss.status());

#[cfg(target_os = "macos")]
println!("Noise: {} dBm", bss.noise_dbm());

#[cfg(target_os = "windows")]
println!("Link Quality: {}", bss.link_quality());

§Accessing Information Elements

Bss contains a list of 802.11 Information Elements (IEs) that are accessed through Bss::ies.

use kawaiifi::Ie;

let ies: &[Ie] = bss.ies();
println!("Found {} IE(s)", ies.len());

Ie exposes basic properties such as the information element’s name, ID, and a summary.

println!("IE: {} ({}) - {}", ie.name(), ie.id, ie.summary());

Ie also exposes the information element’s underlying data through Ie::data.

use kawaiifi::IeData;

match &ie.data {
    IeData::Ssid(ssid) => println!("SSID: {}", ssid.to_string_lossy()),
    IeData::DsParameterSet(ds) => println!("Channel: {}", ds.current_channel),
    IeData::Tim(tim) => println!("DTIM Period: {}", tim.dtim_period),
    IeData::VhtCapabilities(vht_caps) => {
        println!("Max MPDU Length: {}", vht_caps.vht_capabilities_info.maximum_mpdu_length)
    }
    _ => {}
}

Re-exports§

pub use ies::Ie;
pub use ies::IeData;

Modules§

ies
Wi-Fi Information Element (IE) parsing and serialization.

Structs§

Bss
A basic service set (BSS).
CapabilityInfo
The 802.11 capability information flags advertised in beacon and probe response frames.
ChannelWidths
A set of Wi-Fi channel widths.
Interface
A Wi-Fi interface obtained via nl80211.
Scan
Results of a Wi-Fi scan operation.
ScanFlags
Flags that control scan behavior and indicate scan characteristics.
SecurityProtocols
A set of SecurityProtocol flags indicating which security protocols a BSS supports.
WifiAmendments
A set of WifiAmendment flags indicating which 802.11 amendments a BSS supports.
WifiProtocols
A set of WifiProtocol flags indicating which 802.11 protocol generations a BSS supports.

Enums§

Band
A Wi-Fi frequency band.
BssStatus
The status of a BSS. Based on nl80211_bss_status from linux/include/uapi/linux/nl80211.h
BusType
The bus type used to connect a Wi-Fi adapter to the system.
ChannelWidth
A Wi-Fi channel width.
InterfaceError
Errors that can occur while enumerating Wi-Fi interfaces.
ScanError
Errors that can occur while scanning for Wi-Fi networks on Linux.
SecurityProtocol
A Wi-Fi security protocol.
WifiAmendment
An 802.11 amendment supported by a BSS.
WifiProtocol
An 802.11 Wi-Fi protocol generation supported by a BSS.

Functions§

default_interface
Returns the first available Wi-Fi interface.
interfaces
Returns all available Wi-Fi interfaces on the system.