1 // Copyright 2024 Google, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #![allow(non_upper_case_globals)] 16 #![allow(non_camel_case_types)] 17 #![allow(non_snake_case)] 18 // TODO(b/203002625) - since rustc 1.53, bindgen causes UB warnings 19 // Remove this once bindgen figures out how to do this correctly 20 #![allow(deref_nullptr)] 21 22 //! FFI bindings to hostapd for Linux, macOS, and Windows. 23 //! 24 //! This module allows interaction with hostapd's core functionalities directly from Rust code. 25 //! 26 //! ## Usage 27 //! 28 //! This module provides a function to start the hostapd process and includes platform-specific bindings. 29 //! 30 //! ### `run_hostapd_main` 31 //! 32 //! This function allows you to run the main hostapd process. 33 //! 34 //! ``` 35 //! use std::ffi::CString; 36 //! use hostapd_rs::hostapd_sys; // Import the module 37 //! 38 //! fn main() { 39 //! let mut args = vec![CString::new("hostapd").unwrap()]; 40 //! args.push(CString::new("/path/to/hostapd.conf").unwrap()); 41 //! // Include any other args 42 //! let argv: Vec<*const std::os::raw::c_char> = args.iter().map(|arg| arg.as_ptr()).collect(); 43 //! 44 //! unsafe { 45 //! hostapd_sys::run_hostapd_main(argv.len() as i32, argv.as_ptr()); 46 //! } 47 //! } 48 //! ``` 49 //! 50 //! ### Platform-Specific Bindings 51 //! 52 //! This module provides bindings automatically generated by `rust-bindgen` for the following platforms: 53 //! 54 //! * **Linux (`linux/bindings.rs`)** 55 //! * **macOS (`macos/bindings.rs`)** 56 //! * **Windows (`windows/bindings.rs`)** 57 //! 58 //! These bindings expose constants, structures, and functions specific to each platform, allowing 59 //! you to interact with the underlying hostapd implementation. 60 //! 61 //! **Example (Linux):** 62 //! 63 //! This example demonstrates how to access the active Pairwise Transient Key (PTK) from hostapd on Linux. 64 //! 65 //! ``` 66 //! # #[cfg(target_os = "linux")] 67 //! # fn main() { 68 //! use hostapd_rs::hostapd_sys; // Import the module 69 //! use hostapd_sys::get_active_ptk; 70 //! 71 //! unsafe { 72 //! let ptk = get_active_ptk(); 73 //! // Process the PTK data 74 //! } 75 //! # } 76 //! # #[cfg(not(target_os = "linux"))] 77 //! # fn main() {} 78 //! ``` 79 80 #[cfg(target_os = "linux")] 81 include!("linux/bindings.rs"); 82 83 #[cfg(target_os = "macos")] 84 include!("macos/bindings.rs"); 85 86 #[cfg(target_os = "windows")] 87 include!("windows/bindings.rs"); 88 89 extern "C" { run_hostapd_main( argc: ::std::os::raw::c_int, argv: *const *const std::os::raw::c_char, ) -> ::std::os::raw::c_int90 pub fn run_hostapd_main( 91 argc: ::std::os::raw::c_int, 92 argv: *const *const std::os::raw::c_char, 93 ) -> ::std::os::raw::c_int; 94 } 95