From 643afe09e8905c98f7b34dd8a1ec3a36b3d19802 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 20 Apr 2021 17:53:09 +0100 Subject: [PATCH] Set txpower w/ iw, persist value in UI --- includes/hostapd.php | 18 +++++++++++++++++- templates/hostapd/advanced.php | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index b87b1e67..8ed66946 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -32,6 +32,10 @@ function DisplayHostAPDConfig() exec("iw reg get | awk '/country / { sub(/:/,\"\",$2); print $2 }'", $country_code); + $cmd = "iw dev ".$_SESSION['ap_interface']." info | awk '$1==\"txpower\" {print $2}'"; + exec($cmd, $txpower); + $txpower = intval($txpower[0]); + if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['SaveHostAPDSettings'])) { SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status); @@ -62,7 +66,7 @@ function DisplayHostAPDConfig() } exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig); - exec('iwgetid '. $_POST['interface']. ' -r', $wifiNetworkID); + exec('iwgetid '. $_POST['interface'].' -r', $wifiNetworkID); if (!empty($wifiNetworkID[0])) { $managedModeEnabled = true; } @@ -90,6 +94,17 @@ function DisplayHostAPDConfig() if (!isset($arrConfig['country_code']) && isset($country_code[0])) { $arrConfig['country_code'] = $country_code[0]; } + // set txpower with iw if value is non-default ('auto') + if (isset($_POST['txpower']) && ($_POST['txpower'] != 'auto')) { + $sdBm = $_POST['txpower'] * 100; + exec('sudo /sbin/iw dev '.$_POST['interface'].' set txpower fixed '.$sdBm, $return); + $status->addMessage('Setting transmit power to '.$_POST['txpower'].' dBm.', 'success'); + $txpower = $_POST['txpower']; + } elseif ($_POST['txpower'] == 'auto') { + exec('sudo /sbin/iw dev '.$_POST['interface'].' set txpower auto', $return); + $status->addMessage('Setting transmit power to '.$_POST['txpower'].'.', 'success'); + $txpower = $_POST['txpower']; + } echo renderTemplate( "hostapd", compact( @@ -104,6 +119,7 @@ function DisplayHostAPDConfig() "arrSecurity", "arrEncType", "arrTxPower", + "txpower", "arrHostapdConf" ) ); diff --git a/templates/hostapd/advanced.php b/templates/hostapd/advanced.php index 579e166c..447623f8 100644 --- a/templates/hostapd/advanced.php +++ b/templates/hostapd/advanced.php @@ -1,4 +1,3 @@ -' . var_export($arrTxPower, true) . ''; ?>

@@ -58,7 +57,7 @@ ">