Skip to content

Commit

Permalink
airmon-ng.linux: use default channels supported by hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroChaos- committed Dec 22, 2023
1 parent 02c1370 commit 9175b8e
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions scripts/airmon-ng.linux
Expand Up @@ -59,10 +59,10 @@ if [ -n "${3}" ];then
CH="${3}"
else
printf "\nYou have entered an invalid channel or frequency \"%s\" which will be ignored\n" "${3}"
CH="default"
CH="0"
fi
else
CH="default"
CH="0"
fi

#TODO LIST
Expand Down Expand Up @@ -636,50 +636,53 @@ startwlIface() {
setChannelMac80211() {
setLink "${1}" up
i=0
if [ "${CH}" = "default" ]; then
if [ "${DRIVER}" = "wil6210" ]; then
#wil6210 doesn't support setting by channel afaict, so set band 3 / 60GHz channel 1 by freq
CH="58320"
else
# everyone else defaults to channel 1
CH="1"
fi
elif [ "${DRIVER}" = "wil6210" ] && [ "${CH}" -lt "58320" ]; then
printf "wil6210 doesn't support setting by channel, please specify a frequency\n"
exit 1
fi

if [ -n "${CH}" ]; then
if [ "${CH}" -lt 900 ]; then
# if channel is less than 900 assume it's a channel and try to set it as a channel
# wil6210 driver doesn't support setting by channel afaict so jump it to the else
if [ "${CH}" -lt 900 ] && [ "${DRIVER}" != "wil6210" ]; then
if [ -r "/sys/class/net/$1/phy80211/name" ]; then
channel_list="$(iw phy "$(cat "/sys/class/net/${1}/phy80211/name")" channels 2>&1 | awk -F'[][]' '$2{print $2}')"
hardware_valid_channel=1
for i in $channel_list; do
if [ "${CH}" = "0" ]; then
# channel 0 means default, default means set first supported channel
CH="${i}"
hardware_valid_channel=0
break
fi
if [ "${CH}" = "${i}" ]; then
hardware_valid_channel=0
break
fi
last_chan="${i}"
done
if [ "${hardware_valid_channel}" = "1" ]; then
printf "Channel %s does not appear to be supported by %s hardware, defaulting to channel 3.\n\n" "${CH}" "${1}"
CH=3
printf "Channel %s does not appear to be supported by %s hardware, defaulting to known valid channel %s\n\n" "${CH}" "${1}" "${last_chan}"
CH="${last_chan}"
fi
fi
IW_ERROR="$(iw dev "${1}" set channel "${CH}" 2>&1)"
# channel is 900 or over, assume it's a frequency and set it as such
else
if [ -r "/sys/class/net/$1/phy80211/name" ]; then
frequency_list="$(iw phy "$(cat "/sys/class/net/${1}/phy80211/name")" channels 2>&1 | sed -nr 's/.*( |^)([0-9]+) MHz .*/\2/p')"
hardware_valid_freq=1
for i in $frequency_list; do
if [ "${CH}" = "0" ]; then
# channel 0 means default, default means set first supported freq
CH="${i}"
hardware_valid_channel=0
break
fi
if [ "${CH}" = "${i}" ]; then
hardware_valid_freq=0
break
fi
print
last_freq="${i}"
done
if [ "${hardware_valid_freq}" = "1" ]; then
printf "Frequency %s does not appear to be supported by %s hardware, defaulting to 2422 Mhz.\n\n" "${CH}" "${1}"
CH="2422"
printf "Frequency %s does not appear to be supported by %s hardware, defaulting to known valid freq %s Mhz\n\n" "${CH}" "${1}" "${last_freq}"
CH="${last_freq}"
fi
fi
IW_ERROR="$(iw dev "${1}" set freq "${CH}" 2>&1)"
Expand Down

0 comments on commit 9175b8e

Please sign in to comment.