From f96b655276f572641cb58188b1a7a28df8b73e6c Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sun, 19 Jun 2011 16:41:42 +0200 Subject: Move wpa_supplicant based list_networks() function to 8021x module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Oudompheng --- src/8021x | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/wireless | 44 -------------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/8021x b/src/8021x index fea7c39..0c3a8c2 100644 --- a/src/8021x +++ b/src/8021x @@ -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 diff --git a/src/wireless b/src/wireless index 71713e7..b5ae141 100644 --- a/src/wireless +++ b/src/wireless @@ -72,50 +72,6 @@ find_ap() { return 1 } -# 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 -p /run/wpa_supplicant -i "$INTERFACE" scan &> /dev/null - sleep 2.5 - wpa_cli -p /run/wpa_supplicant -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 -} - set_rf_state() { local INTERFACE="$1" state="$2" RFKILL_NAME="$3" -- cgit v1.2.3-24-g4f1b