Skip to content

Commit 34f3c09

Browse files
committed
Add --interface argument
Allow the user to specify which network interface is creating the Wi-Fi hotspot on the host system It defaults to the wlan0, 10.0.0.1 setup of AA Wireless Dongle
1 parent 6f50dd6 commit 34f3c09

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ OPTIONS:
126126
-c, --connect <CONNECT> Auto-connect to saved phone or specified phone MAC address if
127127
provided
128128
-d, --debug Enable debug info
129+
-i, --interface Specify Wi-Fi Hotspot network interface
129130
-l, --legacy Enable legacy mode
130131
-h, --help Print help information
131132
-l, --logfile <LOGFILE> Log file path [default: /var/log/aa-proxy-rs.log]

src/bluetooth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const HSP_HS_UUID: Uuid = Uuid::from_u128(0x0000110800001000800000805f9b34fb);
3737
const HSP_AG_UUID: Uuid = Uuid::from_u128(0x0000111200001000800000805f9b34fb);
3838
const BT_ALIAS: &str = "WirelessAADongle";
3939

40-
const DEFAULT_WLAN_IFACE: &str = "wlan0";
4140
const DEFAULT_WLAN_ADDR: &str = "10.0.0.1";
4241

4342
const HOSTAPD_FILE: &str = "/etc/hostapd/hostapd.conf";
@@ -338,6 +337,7 @@ pub async fn bluetooth_stop(state: BluetoothState) -> Result<()> {
338337

339338
pub async fn bluetooth_setup_connection(
340339
advertise: bool,
340+
iface: &str,
341341
connect: Option<Address>,
342342
tcp_start: Arc<Notify>,
343343
) -> Result<BluetoothState> {
@@ -346,16 +346,16 @@ pub async fn bluetooth_setup_connection(
346346
let mut stage = 1;
347347
let mut started;
348348

349-
let mut wlan_iface = String::from(DEFAULT_WLAN_IFACE);
350349
let mut wlan_ip_addr = String::from(DEFAULT_WLAN_ADDR);
351350

352351
let (state, mut stream) = power_up_and_wait_for_connection(advertise, connect).await?;
353352

353+
354354
// Get UP interface and IP
355355
for ifa in netif::up().unwrap() {
356356
match ifa.name() {
357-
DEFAULT_WLAN_IFACE => {
358-
debug!("Found WLAN interface: {:?}", ifa);
357+
val if val == iface => {
358+
debug!("Found interface: {:?}", ifa);
359359
// IPv4 Address contains None scope_id, while IPv6 contains Some
360360
match ifa.scope_id() { None => {
361361
wlan_ip_addr = ifa.address().to_string();
@@ -391,7 +391,7 @@ pub async fn bluetooth_setup_connection(
391391
info.set_ssid(String::from(wlan_ssid));
392392
info.set_key(String::from(wlan_wpa_key));
393393
info!("{} 🛜 Sending Host SSID and Password: {}, {}", NAME, wlan_ssid, wlan_wpa_key);
394-
let bssid = mac_address::mac_address_by_name(&wlan_iface)
394+
let bssid = mac_address::mac_address_by_name(iface)
395395
.unwrap()
396396
.unwrap()
397397
.to_string();

src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ struct Args {
6464
long
6565
)]
6666
udc: Option<String>,
67+
68+
/// WLAN / Wi-Fi Hotspot interface
69+
#[clap(
70+
short,
71+
long,
72+
default_value = "wlan0"
73+
)]
74+
iface: String,
6775

6876
}
6977

@@ -113,6 +121,7 @@ fn logging_init(debug: bool, log_path: &PathBuf) {
113121
async fn tokio_main(
114122
advertise: bool,
115123
legacy: bool,
124+
iface: String,
116125
connect: Option<Address>,
117126
udc: Option<String>,
118127
need_restart: Arc<Notify>,
@@ -134,7 +143,7 @@ async fn tokio_main(
134143

135144
let bt_stop;
136145
loop {
137-
match bluetooth_setup_connection(advertise, connect, tcp_start.clone()).await {
146+
match bluetooth_setup_connection(advertise, &iface, connect, tcp_start.clone()).await {
138147
Ok(state) => {
139148
// we're ready, gracefully shutdown bluetooth in task
140149
bt_stop = tokio::spawn(async move { bluetooth_stop(state).await });
@@ -211,6 +220,7 @@ fn main() {
211220
tokio_main(
212221
args.advertise,
213222
args.legacy,
223+
args.iface,
214224
args.connect,
215225
args.udc,
216226
need_restart,

0 commit comments

Comments
 (0)