Created
November 1, 2022 23:28
-
-
Save TBK/8be32056b3d75b09f35351c0aac93214 to your computer and use it in GitHub Desktop.
Script to extract and convert associated on frequencies to channel numbers from a wpa_supplicant log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: TBK | |
# Email: [email protected] | |
# SPDX-License-Identifier: GPL-2.0-only | |
# Version: 0.0.1 | |
# Description: Tool to extract and nicely present channels that wpa_supplicant has associated on | |
# Usage: ./associated_freqs.sh | |
if [ -f wpa_supplicant.log ]; then | |
# Grab all lines with frequencies that has been associated on | Reduce it to the frequency | Sort | Remove duplicates | |
grep -E "^.*nl80211: Associated on.*$" wpa_supplicant.log | cut -d " " -f5-6 | sort | uniq > associated_frequencies.txt | |
# Original code - https://github.com/torvalds/linux/blob/master/net/wireless/util.c#L141 | |
ieee80211_freq_mhz_to_channel() { | |
freq="$1" | |
# see 802.11 17.3.8.3.2 and Annex J | |
if [ "$freq" -eq 2484 ]; then | |
return 14 | |
elif [ "$freq" -lt 2484 ]; then | |
return $(((freq - 2407) / 5)) | |
elif [ "$freq" -ge 4910 ] && [ "$freq" -le 4980 ]; then | |
return $(((freq - 4000) / 5)) | |
elif [ "$freq" -lt 5925 ]; then | |
return $(((freq - 5000) / 5)) | |
elif [ "$freq" -eq 5935 ]; then | |
return 2 | |
elif [ "$freq" -le 45000 ]; then | |
# DMG band lower limit | |
# see 802.11ax D6.1 27.3.22.2 | |
return $(((freq - 5950) / 5)) | |
elif [ "$freq" -ge 58320 ] && [ "$freq" -le 70200 ]; then | |
return $(((freq - 56160) / 2160)) | |
else | |
return 0 | |
fi | |
} | |
# Debug | |
#ieee80211_freq_mhz_to_channel 2484 | |
#echo "Should return 14 - $?" | |
# Time to style the result | |
rm -f associated_frequencies-tmp.txt | |
channels="" | |
while read l; do | |
f=$(printf "$l" | cut -d " " -f1) | |
ieee80211_freq_mhz_to_channel "$f" | |
channel="$?" | |
channels="${channels}${channels:+,}$channel" | |
printf "%s MHz - %s\n" "$f" "$channel" >> associated_frequencies-tmp.txt | |
done < associated_frequencies.txt | |
## Add string of the channels that can be used in wpa_sup config directly | |
printf "\n\nChannels: %s\n" "$channels" >> associated_frequencies-tmp.txt | |
rm -f associated_frequencies.txt | |
mv associated_frequencies-tmp.txt associated_frequencies.txt | |
printf '\nContent of associated_frequencies.txt:\n' | |
cat associated_frequencies.txt | |
exit 0 | |
else | |
printf 'Wooh! wpa_supplicant.log needs to be present!\n' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment