// Copyright 2024 Google, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at: // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] // TODO(b/203002625) - since rustc 1.53, bindgen causes UB warnings // Remove this once bindgen figures out how to do this correctly #![allow(deref_nullptr)] //! FFI bindings to hostapd for Linux, macOS, and Windows. //! //! This module allows interaction with hostapd's core functionalities directly from Rust code. //! //! ## Usage //! //! This module provides a function to start the hostapd process and includes platform-specific bindings. //! //! ### `run_hostapd_main` //! //! This function allows you to run the main hostapd process. //! //! ``` //! use std::ffi::CString; //! use hostapd_rs::hostapd_sys; // Import the module //! //! fn main() { //! let mut args = vec![CString::new("hostapd").unwrap()]; //! args.push(CString::new("/path/to/hostapd.conf").unwrap()); //! // Include any other args //! let argv: Vec<*const std::os::raw::c_char> = args.iter().map(|arg| arg.as_ptr()).collect(); //! //! unsafe { //! hostapd_sys::run_hostapd_main(argv.len() as i32, argv.as_ptr()); //! } //! } //! ``` //! //! ### Platform-Specific Bindings //! //! This module provides bindings automatically generated by `rust-bindgen` for the following platforms: //! //! * **Linux (`linux/bindings.rs`)** //! * **macOS (`macos/bindings.rs`)** //! * **Windows (`windows/bindings.rs`)** //! //! These bindings expose constants, structures, and functions specific to each platform, allowing //! you to interact with the underlying hostapd implementation. //! //! **Example (Linux):** //! //! This example demonstrates how to access the active Pairwise Transient Key (PTK) from hostapd on Linux. //! //! ``` //! # #[cfg(target_os = "linux")] //! # fn main() { //! use hostapd_rs::hostapd_sys; // Import the module //! use hostapd_sys::get_active_ptk; //! //! unsafe { //! let ptk = get_active_ptk(); //! // Process the PTK data //! } //! # } //! # #[cfg(not(target_os = "linux"))] //! # fn main() {} //! ``` #[cfg(target_os = "linux")] include!("linux/bindings.rs"); #[cfg(target_os = "macos")] include!("macos/bindings.rs"); #[cfg(target_os = "windows")] include!("windows/bindings.rs"); extern "C" { pub fn run_hostapd_main( argc: ::std::os::raw::c_int, argv: *const *const std::os::raw::c_char, ) -> ::std::os::raw::c_int; }