xref: /aosp_15_r20/tools/netsim/rust/daemon/src/wifi/hostapd.rs (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
1*cf78ab8cSAndroid Build Coastguard Worker // Copyright 2024 Google LLC
2*cf78ab8cSAndroid Build Coastguard Worker //
3*cf78ab8cSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*cf78ab8cSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*cf78ab8cSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*cf78ab8cSAndroid Build Coastguard Worker //
7*cf78ab8cSAndroid Build Coastguard Worker //     https://www.apache.org/licenses/LICENSE-2.0
8*cf78ab8cSAndroid Build Coastguard Worker //
9*cf78ab8cSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*cf78ab8cSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*cf78ab8cSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*cf78ab8cSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*cf78ab8cSAndroid Build Coastguard Worker // limitations under the License.
14*cf78ab8cSAndroid Build Coastguard Worker 
15*cf78ab8cSAndroid Build Coastguard Worker /// Hostapd Interface for Network Simulation
16*cf78ab8cSAndroid Build Coastguard Worker use bytes::Bytes;
17*cf78ab8cSAndroid Build Coastguard Worker pub use hostapd_rs::hostapd::Hostapd;
18*cf78ab8cSAndroid Build Coastguard Worker use netsim_common::util::os_utils::get_discovery_directory;
19*cf78ab8cSAndroid Build Coastguard Worker use netsim_proto::config::HostapdOptions as ProtoHostapdOptions;
20*cf78ab8cSAndroid Build Coastguard Worker use std::sync::mpsc;
21*cf78ab8cSAndroid Build Coastguard Worker 
hostapd_run(_opt: ProtoHostapdOptions, tx: mpsc::Sender<Bytes>) -> anyhow::Result<Hostapd>22*cf78ab8cSAndroid Build Coastguard Worker pub fn hostapd_run(_opt: ProtoHostapdOptions, tx: mpsc::Sender<Bytes>) -> anyhow::Result<Hostapd> {
23*cf78ab8cSAndroid Build Coastguard Worker     // Create hostapd.conf under discovery directory
24*cf78ab8cSAndroid Build Coastguard Worker     let config_path = get_discovery_directory().join("hostapd.conf");
25*cf78ab8cSAndroid Build Coastguard Worker     let mut hostapd = Hostapd::new(tx, true, config_path);
26*cf78ab8cSAndroid Build Coastguard Worker     hostapd.run();
27*cf78ab8cSAndroid Build Coastguard Worker     Ok(hostapd)
28*cf78ab8cSAndroid Build Coastguard Worker }
29