From 3e23e0bd0c85bfd053fbaccba84c421449049b02 Mon Sep 17 00:00:00 2001 From: garywill Date: Sat, 26 Jul 2025 10:17:26 +0800 Subject: [PATCH 1/2] refractor freq to channel function (for 2.4G, 5G, 6G) --- lnxrouter | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lnxrouter b/lnxrouter index f55d6ec..2c97e62 100755 --- a/lnxrouter +++ b/lnxrouter @@ -640,20 +640,26 @@ can_transmit_to_channel() { fi } -# taken from iw/util.c ieee80211_frequency_to_channel() { local FREQ=$1 - if [[ $FREQ -eq 2484 ]]; then + + # 2.4G + if [[ $FREQ -ge 2412 && $FREQ -le 2472 ]]; then # 2.4 GHz band: Channels 1-13 (2412~2472 MHz) + echo $(( (FREQ - 2407) / 5 )) + elif [[ $FREQ -eq 2484 ]]; then # 2.4 GHz Channel 14 (2484 MHz, Japan only) echo 14 - elif [[ $FREQ -lt 2484 ]]; then - echo $(( ($FREQ - 2407) / 5 )) - elif [[ $FREQ -ge 4910 && $FREQ -le 4980 ]]; then - echo $(( ($FREQ - 4000) / 5 )) - elif [[ $FREQ -le 45000 ]]; then - echo $(( ($FREQ - 5000) / 5 )) - elif [[ $FREQ -ge 58320 && $FREQ -le 64800 ]]; then - echo $(( ($FREQ - 56160) / 2160 )) - else + + # 5G + elif [[ $FREQ -ge 5160 && $FREQ -le 5885 ]]; then # 5 GHz band: Standard Channels 36-165 (5180~5825 MHz) (extra: 32, 169-177) + echo $(( (FREQ - 5000) / 5 )) + + # 6G + elif [[ $FREQ -ge 5955 && $FREQ -le 7115 ]]; then # 6 GHz band: Channels 1-233 (5955~7115 MHz), Wi-Fi 6E/7 + echo $(( (FREQ - 5950) / 5 )) + elif [[ $FREQ -eq 5935 ]]; then # 6 GHz band: Special case for 5935 MHz (Channel 2, rare) + echo 2 + + else # Frequency not in supported Wi-Fi bands (2.4/5/6 GHz) echo 0 fi } @@ -2217,7 +2223,7 @@ fi # judge channel availability after changing country code if [[ $WIFI_IFACE ]] ; then - can_transmit_to_channel "${AP_IFACE}" ${CHANNEL} || die "Your adapter can not transmit to channel ${CHANNEL}, frequency band ${FREQ_BAND}GHz." + can_transmit_to_channel "${AP_IFACE}" ${CHANNEL} || die "Your adapter can not transmit to channel ${CHANNEL}, frequency band ${FREQ_BAND}GHz. (Tips: 1. Check usable channels: 'iw phy info'. 2. Check country code then check again. )" fi [[ $WIFI_IFACE ]] && write_hostapd_conf From 702c4f28f5f8cee1d08a18557b9793bafb5d2926 Mon Sep 17 00:00:00 2001 From: garywill Date: Sat, 26 Jul 2025 10:40:12 +0800 Subject: [PATCH 2/2] global variable PHY --- lnxrouter | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lnxrouter b/lnxrouter index 2c97e62..fecd7eb 100755 --- a/lnxrouter +++ b/lnxrouter @@ -213,6 +213,7 @@ define_global_variables(){ QR=0 # show wifi qr # script variables + PHY= VWIFI_IFACE= # virtual wifi interface name, if created VIRT_NAME= # name to use for virtual interface if --virt-name is used AP_IFACE= # can be VWIFI_IFACE or WIFI_IFACE @@ -582,7 +583,6 @@ get_interface_phy_device() { # only for wifi interface return 0 fi done - echo "Failed to get phy interface" >&2 return 1 } @@ -1663,9 +1663,14 @@ daemonizing_check(){ #============================ check_wifi_settings() { + PHY="$(get_interface_phy_device "$WIFI_IFACE")" + if [[ -z "$PHY" ]]; then + echo "ERROR: Can't get phy of wifi interface '$WIFI_IFACE' (Did you spell the interface name right?)" >&2 + exit 1 + fi if ! ( which iw > /dev/null 2>&1 && iw dev "$WIFI_IFACE" info > /dev/null 2>&1 ); then - echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ... (Did you spell the interface name right?)" >&2 + echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ..." >&2 USE_IWCONFIG=1 fi @@ -2138,10 +2143,8 @@ start_dnsmasq() { } check_rfkill_unblock_wifi() { - local PHY if which rfkill > /dev/null 2>&1 ; then - PHY=$(get_interface_phy_device "${SUBNET_IFACE}") - [[ -n $PHY ]] && rfkill unblock $(rfkill | grep "$PHY" | awk '{print $1}') >/dev/null 2>&1 + rfkill unblock $(rfkill | grep "$PHY" | awk '{print $1}') >/dev/null 2>&1 fi } @@ -2223,7 +2226,7 @@ fi # judge channel availability after changing country code if [[ $WIFI_IFACE ]] ; then - can_transmit_to_channel "${AP_IFACE}" ${CHANNEL} || die "Your adapter can not transmit to channel ${CHANNEL}, frequency band ${FREQ_BAND}GHz. (Tips: 1. Check usable channels: 'iw phy info'. 2. Check country code then check again. )" + can_transmit_to_channel "${AP_IFACE}" ${CHANNEL} || die "Your adapter can not transmit to channel ${CHANNEL}, frequency band ${FREQ_BAND}GHz. (Tips: 1. Check usable channels: 'iw phy $PHY info'. 2. Check country code then check again. )" fi [[ $WIFI_IFACE ]] && write_hostapd_conf