From c5f692263d7733edcbe773cf3cb071817b0e6ce6 Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 18:05:07 +1000 Subject: [PATCH 1/3] 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; + } } From ed09f9b9da9f427ca20005bcdcf4dfd2b433b70f Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 19:02:33 +1000 Subject: [PATCH 2/3] Cleaned up some debugging code identified when comparing PR. --- includes/wifi_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index c2c432d2..040de215 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', $output, $returnval); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); sleep(3); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); From 12b69590daf274c8bb72a5fd8f12b4c3325ff510 Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 10:45:27 +0000 Subject: [PATCH 3/3] Removed some band-aid fixes of incorrect client/ap interface identification function. --- includes/hostapd.php | 2 ++ includes/wifi_functions.php | 4 ++-- templates/configure_client.php | 9 +++------ templates/dashboard.php | 8 +++----- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 79b3ad02..9b698480 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -130,6 +130,8 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $status->addMessage('Attempting to set channel outside of permitted range', 'danger'); $good_input = false; } + + $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); // Check for Bridged AP mode checkbox $bridgedEnable = 0; diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 040de215..5b994dae 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -146,12 +146,12 @@ 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); - $client_iface = $_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)){ + if ($client_iface == "uap0" && ($arrHostapdConf['WifiAPEnable'] ?? 0)){ $_SESSION['wifi_client_interface'] = $iface; $_SESSION['ap_interface'] = $client_iface; } diff --git a/templates/configure_client.php b/templates/configure_client.php index afb3aeb3..567d858a 100755 --- a/templates/configure_client.php +++ b/templates/configure_client.php @@ -1,10 +1,7 @@