From c5f692263d7733edcbe773cf3cb071817b0e6ce6 Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 18:05:07 +1000 Subject: [PATCH] Fixed function getWifiInterface for rpi0W. The old version would get 'wifi_client_interface' and 'ap_interface' reversed when rpi0W is used in AP-STA mode. This commit fixes the issue. --- includes/wifi_functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index c4ec7c60..c2c432d2 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -53,7 +53,7 @@ function nearbyWifiStations(&$networks, $cached = true) $scan_results = cache( $cacheKey, function () { - exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan', $output, $returnval); sleep(3); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); @@ -146,6 +146,14 @@ function getWifiInterface() $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + $client_iface = $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + + // specifically for rpi0W in AP-STA mode, the above check ends up with the interfaces + // crossed over (wifi_client_interface vs 'ap_interface'), because the second interface (uap0) is + // created by raspap and used as the access point. + if ($iface == "wlan0" && $client_iface = "uap0" && ($arrHostapdConf['WifiAPEnable'] ?? 0)){ + $_SESSION['wifi_client_interface'] = $iface; + $_SESSION['ap_interface'] = $client_iface; + } }