Skip to content

Commit

Permalink
当信道和phy不匹配时根据信道自动设置phy
Browse files Browse the repository at this point in the history
Signed-off-by: Ruixi Zhou <[email protected]>
  • Loading branch information
zhouruixi committed Jun 7, 2024
1 parent f82002a commit dc7d25c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions files/wfb-gs.init
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions files/wfb-gs_wifi.default.uci
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dc7d25c

Please sign in to comment.