From dc7d25c0b9c192ce5d8e140dd1e480bdee5a44a4 Mon Sep 17 00:00:00 2001 From: Ruixi Zhou Date: Fri, 7 Jun 2024 18:04:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E4=BF=A1=E9=81=93=E5=92=8Cphy?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D=E6=97=B6=E6=A0=B9=E6=8D=AE=E4=BF=A1?= =?UTF-8?q?=E9=81=93=E8=87=AA=E5=8A=A8=E8=AE=BE=E7=BD=AEphy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ruixi Zhou --- files/wfb-gs.init | 4 ++-- files/wfb-gs_wifi.default.uci | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/files/wfb-gs.init b/files/wfb-gs.init index d5e5524..2fa7cb2 100644 --- a/files/wfb-gs.init +++ b/files/wfb-gs.init @@ -36,8 +36,8 @@ start_service() { config_get bandwidth config bandwidth config_get mode config mode - [ -z $wiphy_index ] && { sh /rom/etc/uci-defaults/91_wfb-gs_wifi; sleep 10; config_load "${CONFFILE}"; config_get wiphy_index config wiphy_index; } - [[ "$(iw dev phy${wiphy_index}-wfb info | grep channel | cut -d \ -f 2)" == "$channel" && "$(iw dev phy${wiphy_index}-wfb info | grep channel | cut -d \ -f 6)" == "$bandwidth" ]] || { sh /rom/etc/uci-defaults/91_wfb-gs_wifi; sleep 10; } + [[ -d /sys/class/ieee80211/phy${wiphy_index} && "$(iw dev phy${wiphy_index}-wfb info | grep channel | cut -d \ -f 2,6)" == "${channel} ${bandwidth}" ]] || { + sh /rom/etc/uci-defaults/91_wfb-gs_wifi; sleep 10; config_load "${CONFFILE}"; config_get wiphy_index config wiphy_index; } [[ -d /sys/class/net/usb0 || "$mode" == "multicast" ]] || ip_gs=$ip_pc procd_open_instance diff --git a/files/wfb-gs_wifi.default.uci b/files/wfb-gs_wifi.default.uci index af28fb7..7a9689b 100644 --- a/files/wfb-gs_wifi.default.uci +++ b/files/wfb-gs_wifi.default.uci @@ -2,23 +2,23 @@ . /lib/functions.sh config_load wfb-gs -config_get wiphy_index config wiphy_index config_get channel config channel config_get bandwidth config bandwidth -[ -z $wiphy_index ] && { +config_get wiphy_index config wiphy_index + +[[ -d /sys/class/ieee80211/phy$wiphy_index && "$(iw phy phy$wiphy_index info | grep "MHz \[$channel\]")" == "*MHz \[$channel\]*" ]] || { + wiphy_index="" for phy in $(ls /sys/class/ieee80211); do [[ "$(iw phy $phy info | grep "MHz \[$channel\]")" == "*MHz \[$channel\]*" ]] && { wiphy_index=${phy:0-1}; break; } done - uci set wfb-gs.config.wiphy_index="$wiphy_index" - logger -t wfb-gs "Auto set to $phy according to the channel ${channel}." -} -[[ "$(iw phy phy$wiphy_index info | grep "MHz \[$channel\]")" == "*MHz \[$channel\]*" ]] || { -logger -t wfb-gs "phy${wiphy_index} does not support channel ${channel}!" -logger -t wfb-gs "Check wiphy_index and channel settings in /etc/config/wfb-gs." -logger -t wfb-gs "Set wiphy_index to blank for auto detect." -logger -t wfb-gs "Restart wfb-gs to make the configuration take effect." -exit 1 + if [ -z $wiphy_index ]; then + logger -t wfb-gs "Channel $channel is not supported by router!" + exit 1 + else + logger -t wfb-gs "Auto set wiphy to $phy according to channel ${channel}." + fi } + uci -q batch << EOT del wireless.default_radio$wiphy_index.network del wireless.default_radio$wiphy_index.encryption @@ -28,6 +28,7 @@ uci -q batch << EOT set wireless.default_radio$wiphy_index.mode='monitor' set wireless.default_radio$wiphy_index.ssid='wfb' set wireless.default_radio$wiphy_index.ifname='phy$wiphy_index-wfb' + set wfb-gs.config.wiphy_index='$wiphy_index' del wireless.radio$wiphy_index.disabled='1' EOT uci commit