diff options
Diffstat (limited to 'src/8021x')
-rw-r--r-- | src/8021x | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -50,6 +50,50 @@ stop_wpa() fi } +# Return a filename containing a list of network APs and ESSIDs found (sorted by decreasing signal strength) +# list_networks interface +list_networks() { + wpa_supplicant_scan_info "$1" 1,5 +} + +wpa_supplicant_scan_info() { + local INTERFACE="$1" fields="$2" essids + # temp file used, as keeping ESSID's with spaces in their name in arrays + # is hard, obscure and kinda nasty. This is simpler and clearer. + + [[ -z "$INTERFACE" ]] && return 1 + essids=$(mktemp --tmpdir essid.XXXXXXXX) + + wpa_supplicant -B -i"$INTERFACE" -Dnl80211,wext -C/run/wpa_supplicant -P/run/wpa_supplicant.pid || return 1 + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + sleep 2.5 + $WPA_CLI -i "$INTERFACE" scan_results | + grep -v "^Selected" | + grep -v "^bssid" | + sort -rn -k3 | + sort -u -k5 | + sort -rn -k3 | + cut -f"$fields" > "$essids" + + # Fields are tab delimited + # Remove extraneous output from wpa_cli + # Sort by strength + # Remove duplicates + # Re-sort by strength as the removal disorders the list + # Cut to the AP/essid fields only + + kill "$(cat /run/wpa_supplicant.pid)" + + # File of 0 length, ie. no ssid's. + if [[ ! -s "$essids" ]]; then + rm -f "$essids" + return 1 + fi + + echo $essids + return 0 +} + # Requires already loaded profile make_wpa_config_file() { local interface=$1 |