• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //! let mut args = vec![CString::new("hostapd").unwrap()];
39 //! args.push(CString::new("/path/to/hostapd.conf").unwrap());
40 //! // Include any other args
41 //! let argv: Vec<*const std::os::raw::c_char> = args.iter().map(|arg| arg.as_ptr()).collect();
42 //!
43 //! unsafe {
44 //!     hostapd_sys::run_hostapd_main(argv.len() as i32, argv.as_ptr());
45 //! }
46 //! ```
47 //!
48 //! ### Platform-Specific Bindings
49 //!
50 //! This module provides bindings automatically generated by `rust-bindgen` for the following platforms:
51 //!
52 //! * **Linux (`linux/bindings.rs`)**
53 //! * **macOS (`macos/bindings.rs`)**
54 //! * **Windows (`windows/bindings.rs`)**
55 //!
56 //! These bindings expose constants, structures, and functions specific to each platform, allowing
57 //! you to interact with the underlying hostapd implementation.
58 //!
59 //! **Example (Linux):**
60 //!
61 //! This example demonstrates how to access the active Pairwise Transient Key (PTK) from hostapd on Linux.
62 //!
63 //! ```
64 //! # #[cfg(target_os = "linux")]
65 //! # fn main() {
66 //! use hostapd_rs::hostapd_sys; // Import the module
67 //! use hostapd_sys::get_active_ptk;
68 //!
69 //! unsafe {
70 //!     let ptk = get_active_ptk();
71 //!     // Process the PTK data
72 //! }
73 //! # }
74 //! # #[cfg(not(target_os = "linux"))]
75 //! # fn main() {}
76 //! ```
77 
78 #![allow(missing_docs)]
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