From 24d48b93ab76e255145edf097ebcb84ba70d5cb1 Mon Sep 17 00:00:00 2001 From: James Rayner Date: Mon, 7 Sep 2009 21:48:31 +1000 Subject: Generalise wpa_supplicant scan information --- src/wireless | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'src/wireless') diff --git a/src/wireless b/src/wireless index e778627..f63f7e1 100644 --- a/src/wireless +++ b/src/wireless @@ -35,7 +35,7 @@ find_essid() { # if results were non-null, process them and exit 0 echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID" ) - fi && { + fi && { scanned=1 report_debug find_essid "\"$found\"" # we only bother with at most 5 successful scans @@ -86,10 +86,10 @@ find_ap() { # list_networks interface list_networks() { - local INTERFACE="$1" essids try=0 RETRIES=20 res scanned - # temp file used, as keeping ESSID's with spaces in their name in arrays + local INTERFACE="$1" 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) @@ -103,7 +103,7 @@ list_networks() sort -rn -k3 | sort -u -k5 | sort -rn -k3 | - cut -f1,5 > "$essids" + cut -f1,5 > "$essids" # Fields are tab delimited # Remove extraneous output from wpa_cli @@ -111,9 +111,9 @@ list_networks() # Remove duplicates # Re-sort by strength as the removal disorders the list # Cut to the AP/essid fields only - + kill $(cat /var/run/wpa_supplicant.pid) - + # File of 0 length, ie. no ssid's. if [[ ! -s "$essids" ]]; then rm -f "$essids" @@ -123,4 +123,48 @@ list_networks() echo $essids return 0 } + +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 -Dwext -C/var/run/wpa_supplicant -P/var/run/wpa_supplicant.pid + 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 /var/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 +} + # vim: set ts=4 et sw=4 ft=sh: + -- cgit v1.2.3-24-g4f1b