Skip to main content

Crate corewlan

Crate corewlan 

Source
Expand description

§corewlan

Safe Rust bindings for Apple’s CoreWLAN framework on macOS.

Status: v0.2 ships the full class-based CoreWLAN surface across CWWiFiClient, CWInterface, CWChannel, CWNetwork, CWConfiguration, CWMutableConfiguration, CWNetworkProfile, CWMutableNetworkProfile, and CWSecurity, backed by a Swift bridge built with SwiftPM.

§Highlights

  • Shared and ephemeral CWWiFiClient access.
  • Read-only CWInterface, CWNetwork, CWChannel, CWConfiguration, and CWNetworkProfile snapshots.
  • Mutable configuration/profile builders via CWMutableConfiguration and CWMutableNetworkProfile.
  • Interface mutators for power, channel, keys, association, enterprise association, and configuration commits.
  • Rust delegate registration for CWEventDelegate notifications.
  • Typed wrappers for CoreWLAN enums, cipher flags, keychain utilities, error codes, and notification constants.

§Quick start

use corewlan::prelude::*;

fn main() -> Result<()> {
    let client = WiFiClient::shared()?;

    for name in client.interface_names() {
        println!("wifi interface: {name}");
    }

    if let Some(interface) = client.interface() {
        println!("ssid = {:?}", interface.ssid());
        println!("rssi = {} dBm", interface.rssi_value());
        println!("rate = {:.1} Mbps", interface.transmit_rate());

        if let Some(configuration) = interface.configuration() {
            println!("preferred networks = {}", configuration.network_profiles().len());
        }
    }

    Ok(())
}

§Examples

cargo run --example 01_smoke
cargo run --example 02_wifi_client_events
cargo run --example 07_mutable_configuration

The crate ships one numbered example per logical CoreWLAN area; see examples/ for the full list.

§Notes

  • Interface::scan_for_networks_* wrappers call the blocking CoreWLAN scan APIs.
  • Interface::cached_scan_results() only returns the existing scan cache and does not initiate a scan.
  • SSID, BSSID, and country-code values may be unavailable without Location Services authorization.
  • Association, power, key, and configuration commit APIs may require administrator privileges or Wi-Fi entitlements; the corresponding tests are marked #[ignore].

§Coverage and verification

  • API audit: COVERAGE.md
  • Validation command set:
    • cargo clippy --all-targets -- -D warnings
    • cargo test
    • for ex in examples/*.rs; do cargo run --example "$(basename "$ex" .rs)"; done

§License

Licensed under either of Apache-2.0 or MIT at your option.


§API documentation

Safe Rust bindings for Apple’s CoreWLAN framework on macOS.

Re-exports§

pub use channel::Channel;
pub use client::DelegateRegistration;
pub use client::WiFiClient;
pub use client::WiFiClientEventDelegate;
pub use configuration::Configuration;
pub use error::CoreWlanError;
pub use error::Result;
pub use interface::Interface;
pub use mutable_configuration::MutableConfiguration;
pub use mutable_network_profile::MutableNetworkProfile;
pub use network::Network;
pub use network_profile::NetworkProfile;
pub use security::bssid_did_change_notification;
pub use security::copy_eap_identity_list;
pub use security::copy_wifi_eap_identity;
pub use security::country_code_did_change_notification;
pub use security::delete_wifi_eap_username_and_password;
pub use security::delete_wifi_password;
pub use security::error_domain;
pub use security::find_wifi_eap_username_and_password;
pub use security::find_wifi_password;
pub use security::merge_networks;
pub use security::mode_did_change_notification;
pub use security::power_did_change_notification;
pub use security::scan_cache_did_update_notification;
pub use security::set_wifi_eap_identity;
pub use security::set_wifi_eap_username_and_password;
pub use security::set_wifi_password;
pub use security::ssid_did_change_notification;
pub use security::Authorization;
pub use security::ChannelBand;
pub use security::ChannelWidth;
pub use security::CipherKeyFlags;
pub use security::ErrorCode;
pub use security::EventType;
pub use security::IbssModeSecurity;
pub use security::Identity;
pub use security::InterfaceMode;
pub use security::KeychainDomain;
pub use security::PhyMode;
pub use security::Security;

Modules§

channel
CWChannel wrapper.
client
CWWiFiClient wrapper.
configuration
CWConfiguration wrapper.
error
Errors returned by the corewlan crate.
ffi
Raw FFI declarations for the bridged CoreWLAN surface.
interface
CWInterface wrapper.
mutable_configuration
CWMutableConfiguration wrapper.
mutable_network_profile
CWMutableNetworkProfile wrapper.
network
CWNetwork wrapper.
network_profile
CWNetworkProfile wrapper.
prelude
Common imports.
profile
Backwards-compatible re-exports for CWNetworkProfile.
security
Type wrappers, utility helpers, and constants for CoreWLAN and related security objects.
types
Backwards-compatible re-exports for CoreWLAN enum wrappers.